Flutter Engine
The Flutter Engine
Classes | Typedefs | Functions
SkPlainTextEditor Namespace Reference

Classes

class  Editor
 
struct  ShapeResult
 
struct  Span
 
class  StringSlice
 

Typedefs

using StringView = Span< const char >
 

Functions

ShapeResult Shape (const char *ut8text, size_t textByteLen, const SkFont &font, sk_sp< SkFontMgr > fontMgr, const char *locale, float width)
 

Typedef Documentation

◆ StringView

using SkPlainTextEditor::StringView = typedef Span<const char>

Definition at line 16 of file stringview.h.

Function Documentation

◆ Shape()

ShapeResult SkPlainTextEditor::Shape ( const char *  ut8text,
size_t  textByteLen,
const SkFont font,
sk_sp< SkFontMgr fontMgr,
const char *  locale,
float  width 
)

Definition at line 301 of file shape.cpp.

307{
309 if (SkUTF::CountUTF8(utf8Text, textByteLen) < 0) {
310 utf8Text = nullptr;
311 textByteLen = 0;
312 }
313 std::unique_ptr<SkShaper> shaper = nullptr;
314#if defined(SK_SHAPER_HARFBUZZ_AVAILABLE) && defined(SK_SHAPER_UNICODE_AVAILABLE)
315 auto unicode = get_unicode();
317#else
319#endif
320 SkASSERT(shaper);
321
322 float height = font.getSpacing();
323 RunHandler runHandler(utf8Text, textByteLen);
324 if (textByteLen) {
325 result.glyphBounds.resize(textByteLen);
326 for (SkRect& c : result.glyphBounds) {
327 c = SkRect{-FLT_MAX, -FLT_MAX, -FLT_MAX, -FLT_MAX};
328 }
329 runHandler.setRunCallback(set_character_bounds, result.glyphBounds.data());
330
331 static constexpr uint8_t kBidiLevelLTR = 0;
332 std::unique_ptr<SkShaper::BiDiRunIterator> bidi = nullptr;
333#if defined(SK_SHAPER_HARFBUZZ_AVAILABLE) && defined(SK_SHAPER_UNICODE_AVAILABLE)
335 unicode, utf8Text, textByteLen, kBidiLevelLTR);
336#endif
337 if (!bidi) {
338 bidi = std::make_unique<SkShaper::TrivialBiDiRunIterator>(kBidiLevelLTR, textByteLen);
339 }
340 SkASSERT(bidi);
341
342 std::unique_ptr<SkShaper::LanguageRunIterator> language =
343 SkShaper::MakeStdLanguageRunIterator(utf8Text, textByteLen);
344 SkASSERT(language);
345
346 std::unique_ptr<SkShaper::ScriptRunIterator> script =
347 SkShaper::MakeScriptRunIterator(utf8Text, textByteLen, SkSetFourByteTag('Z','z','z','z'));
349
350 std::unique_ptr<SkShaper::FontRunIterator> fontRuns =
351 SkShaper::MakeFontMgrRunIterator(utf8Text, textByteLen, font, fontMgr);
352 SkASSERT(fontRuns);
353
354 shaper->shape(utf8Text,
355 textByteLen,
356 *fontRuns,
357 *bidi,
358 *script,
359 *language,
360 nullptr,
361 0,
362 width,
363 &runHandler);
364 if (runHandler.lineEndOffsets().size() > 1) {
365 result.lineBreakOffsets = runHandler.lineEndOffsets();
366 SkASSERT(result.lineBreakOffsets.size() > 0);
367 result.lineBreakOffsets.pop_back();
368 }
369 height = std::max(height, runHandler.endPoint().y());
370 result.blob = runHandler.makeBlob();
371 }
372 result.glyphBounds.push_back(runHandler.finalRect(font));
373 result.verticalAdvance = (int)ceilf(height);
374 result.wordBreaks = GetUtf8WordBoundaries(utf8Text, textByteLen, locale);
375 return result;
376}
#define SkASSERT(cond)
Definition: SkAssert.h:116
sk_sp< SkUnicode > get_unicode()
static constexpr SkFourByteTag SkSetFourByteTag(char a, char b, char c, char d)
Definition: SkTypes.h:167
static std::unique_ptr< ScriptRunIterator > MakeScriptRunIterator(const char *utf8, size_t utf8Bytes, SkFourByteTag script)
Definition: SkShaper.cpp:68
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
sk_sp< SkFontMgr > fontMgr
Definition: examples.cpp:32
GAsyncResult * result
static float max(float r, float g, float b)
Definition: hsl.cpp:49
SKSHAPER_API std::unique_ptr< SkShaper > ShaperDrivenWrapper(sk_sp< SkUnicode > unicode, sk_sp< SkFontMgr > fallback)
SKSHAPER_API std::unique_ptr< SkShaper > PrimitiveText()
SKSHAPER_API std::unique_ptr< SkShaper::BiDiRunIterator > BidiRunIterator(sk_sp< SkUnicode > unicode, const char *utf8, size_t utf8Bytes, uint8_t bidiLevel)
SK_SPI int CountUTF8(const char *utf8, size_t byteLength)
Definition: SkUTF.cpp:47
font
Font Metadata and Metrics.
int32_t height
int32_t width
static void set_character_bounds(void *context, const char *utf8Text, size_t utf8TextBytes, size_t glyphCount, const SkGlyphID *glyphs, const SkPoint *positions, const uint32_t *clusters, const SkFont &font)
Definition: shape.cpp:225
std::vector< bool > GetUtf8WordBoundaries(const char *begin, size_t byteCount, const char *locale)