Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
Placement Class Reference

Public Member Functions

 Placement (const Config *conf, SkDocument *doc)
 
void WriteLine (const SkShaper &shaper, const char *text, size_t textBytes)
 

Detailed Description

Definition at line 148 of file using_skia_and_harfbuzz.cpp.

Constructor & Destructor Documentation

◆ Placement()

Placement::Placement ( const Config conf,
SkDocument doc 
)
inline

Definition at line 150 of file using_skia_and_harfbuzz.cpp.

151 : config(conf), document(doc), pageCanvas(nullptr) {
152 white_paint.setColor(SK_ColorWHITE);
153 glyph_paint.setColor(SK_ColorBLACK);
154 glyph_paint.setAntiAlias(true);
156 font.setSubpixel(true);
158 }
constexpr SkColor SK_ColorBLACK
Definition: SkColor.h:103
constexpr SkColor SK_ColorWHITE
Definition: SkColor.h:122
#define SkDoubleToScalar(x)
Definition: SkScalar.h:64
void setSubpixel(bool subpixel)
Definition: SkFont.cpp:109
void setEdging(Edging edging)
Definition: SkFont.cpp:121
void setSize(SkScalar textSize)
Definition: SkFont.cpp:129
@ kSubpixelAntiAlias
glyph positioned in pixel using transparency
void setColor(SkColor color)
Definition: SkPaint.cpp:119
void setAntiAlias(bool aa)
Definition: SkPaint.h:170
DoubleOption font_size

Member Function Documentation

◆ WriteLine()

void Placement::WriteLine ( const SkShaper shaper,
const char *  text,
size_t  textBytes 
)
inline

Definition at line 160 of file using_skia_and_harfbuzz.cpp.

160 {
161 SkTextBlobBuilderRunHandler textBlobBuilder(text, {0, 0});
162
163 const SkBidiIterator::Level defaultLevel = SkBidiIterator::kLTR;
164 std::unique_ptr<SkShaper::BiDiRunIterator> bidi =
165 SkShapers::unicode::BidiRunIterator(get_unicode(), text, textBytes, defaultLevel);
166 SkASSERT(bidi);
167
168 std::unique_ptr<SkShaper::LanguageRunIterator> language =
170 SkASSERT(language);
171
172 std::unique_ptr<SkShaper::ScriptRunIterator> script =
175
176 std::unique_ptr<SkShaper::FontRunIterator> fontRuns =
178 SkASSERT(fontRuns);
179
180 const SkScalar width = config->page_width.value - 2 * config->left_margin.value;
181 shaper.shape(text,
182 textBytes,
183 *fontRuns,
184 *bidi,
185 *script,
186 *language,
187 nullptr,
188 0,
189 width,
190 &textBlobBuilder);
191 SkPoint endPoint = textBlobBuilder.endPoint();
192 sk_sp<const SkTextBlob> blob = textBlobBuilder.makeBlob();
193 // If we don't have a page, or if we're not at the start of the page and the blob won't fit
194 if (!pageCanvas ||
195 (current_y > config->line_spacing_ratio.value * config->font_size.value &&
196 current_y + endPoint.y() > config->page_height.value)
197 ) {
198 if (pageCanvas) {
199 document->endPage();
200 }
201 pageCanvas = document->beginPage(
204 pageCanvas->drawPaint(white_paint);
205 current_x = config->left_margin.value;
206 current_y = config->line_spacing_ratio.value * config->font_size.value;
207 }
208 pageCanvas->drawTextBlob(
209 blob.get(), SkDoubleToScalar(current_x),
210 SkDoubleToScalar(current_y), glyph_paint);
211 // Advance to the next line.
212 current_y += endPoint.y() + config->line_spacing_ratio.value * config->font_size.value;
213 }
#define SkASSERT(cond)
Definition: SkAssert.h:116
sk_sp< SkUnicode > get_unicode()
uint8_t Level
Definition: SkUnicode.h:46
void drawPaint(const SkPaint &paint)
Definition: SkCanvas.cpp:1668
void drawTextBlob(const SkTextBlob *blob, SkScalar x, SkScalar y, const SkPaint &paint)
Definition: SkCanvas.cpp:2484
SkCanvas * beginPage(SkScalar width, SkScalar height, const SkRect *content=nullptr)
Definition: SkDocument.cpp:32
void endPage()
Definition: SkDocument.cpp:45
static sk_sp< SkFontMgr > RefEmpty()
Definition: SkFontMgr.cpp:154
static std::unique_ptr< FontRunIterator > MakeFontMgrRunIterator(const char *utf8, size_t utf8Bytes, const SkFont &font, sk_sp< SkFontMgr > fallback)
Definition: SkShaper.cpp:187
static std::unique_ptr< LanguageRunIterator > MakeStdLanguageRunIterator(const char *utf8, size_t utf8Bytes)
Definition: SkShaper.cpp:204
virtual void shape(const char *utf8, size_t utf8Bytes, const SkFont &srcFont, bool leftToRight, SkScalar width, RunHandler *) const =0
T * get() const
Definition: SkRefCnt.h:303
float SkScalar
Definition: extension.cpp:12
std::u16string text
SKSHAPER_API std::unique_ptr< SkShaper::ScriptRunIterator > ScriptRunIterator(const char *utf8, size_t utf8Bytes)
SKSHAPER_API std::unique_ptr< SkShaper::BiDiRunIterator > BidiRunIterator(sk_sp< SkUnicode > unicode, const char *utf8, size_t utf8Bytes, uint8_t bidiLevel)
int32_t width
DoubleOption line_spacing_ratio
DoubleOption page_width
DoubleOption page_height
DoubleOption left_margin
constexpr float y() const
Definition: SkPoint_impl.h:187

The documentation for this class was generated from the following file: