8 #ifndef SkShaper_DEFINED
9 #define SkShaper_DEFINED
20 #if !defined(SKSHAPER_IMPLEMENTATION)
21 #define SKSHAPER_IMPLEMENTATION 0
24 #if !defined(SKSHAPER_API)
25 #if defined(SKSHAPER_DLL)
27 #if SKSHAPER_IMPLEMENTATION
28 #define SKSHAPER_API __declspec(dllexport)
30 #define SKSHAPER_API __declspec(dllimport)
33 #define SKSHAPER_API __attribute__((visibility("default")))
47 #ifdef SK_SHAPER_HARFBUZZ_AVAILABLE
48 static std::unique_ptr<SkShaper> MakeShaperDrivenWrapper(
sk_sp<SkFontMgr> =
nullptr);
49 static std::unique_ptr<SkShaper> MakeShapeThenWrap(
sk_sp<SkFontMgr> =
nullptr);
50 static std::unique_ptr<SkShaper> MakeShapeDontWrapOrReorder(std::unique_ptr<SkUnicode> unicode,
52 static void PurgeHarfBuzzCache();
54 #ifdef SK_SHAPER_CORETEXT_AVAILABLE
55 static std::unique_ptr<SkShaper> MakeCoreText();
101 template <
typename RunIteratorSub
class>
102 class TrivialRunIterator :
public RunIteratorSubclass {
104 static_assert(std::is_base_of<RunIterator, RunIteratorSubclass>::value,
"");
105 TrivialRunIterator(
size_t utf8Bytes) : fEnd(utf8Bytes), fAtEnd(fEnd == 0) {}
106 void consume()
override { SkASSERT(!fAtEnd); fAtEnd =
true; }
107 size_t endOfCurrentRun()
const override {
return fAtEnd ? fEnd : 0; }
108 bool atEnd()
const override {
return fAtEnd; }
115 static std::unique_ptr<FontRunIterator>
118 static std::unique_ptr<SkShaper::FontRunIterator>
126 : TrivialRunIterator(utf8Bytes), fFont(font) {}
132 static std::unique_ptr<BiDiRunIterator>
134 #if defined(SK_SHAPER_UNICODE_AVAILABLE)
135 static std::unique_ptr<BiDiRunIterator>
136 MakeSkUnicodeBidiRunIterator(SkUnicode* unicode,
const char* utf8,
size_t utf8Bytes, uint8_t bidiLevel);
137 static std::unique_ptr<BiDiRunIterator>
138 MakeIcuBiDiRunIterator(
const char* utf8,
size_t utf8Bytes, uint8_t bidiLevel);
143 : TrivialRunIterator(utf8Bytes), fBidiLevel(bidiLevel) {}
149 static std::unique_ptr<ScriptRunIterator>
151 #if defined(SK_SHAPER_HARFBUZZ_AVAILABLE)
152 static std::unique_ptr<ScriptRunIterator>
153 MakeSkUnicodeHbScriptRunIterator(
const char* utf8,
size_t utf8Bytes);
154 static std::unique_ptr<ScriptRunIterator>
155 MakeSkUnicodeHbScriptRunIterator(
const char* utf8,
size_t utf8Bytes,
SkFourByteTag script);
157 static std::unique_ptr<ScriptRunIterator>
158 MakeHbIcuScriptRunIterator(
const char* utf8,
size_t utf8Bytes);
163 : TrivialRunIterator(utf8Bytes), fScript(script) {}
169 static std::unique_ptr<LanguageRunIterator>
174 : TrivialRunIterator(utf8Bytes), fLanguage(language) {}
185 constexpr
Range() : fBegin(0), fSize(0) {}
186 constexpr
Range(
size_t begin,
size_t size) : fBegin(begin), fSize(size) {}
189 constexpr
size_t begin()
const {
return fBegin; }
190 constexpr
size_t end()
const {
return begin() + size(); }
191 constexpr
size_t size()
const {
return fSize; }
230 virtual void shape(
const char* utf8,
size_t utf8Bytes,
236 virtual void shape(
const char* utf8,
size_t utf8Bytes,
244 virtual void shape(
const char* utf8,
size_t utf8Bytes,
249 const Feature* features,
size_t featuresSize,
264 : fUtf8Text(utf8Text)
278 char const *
const fUtf8Text;
285 SkPoint fCurrentPosition;
float SkScalar
Definition: SkScalar.h:14
#define SKSHAPER_API
Definition: SkShaper.h:36
uint16_t SkGlyphID
16 bit unsigned integer to hold a glyph index
Definition: SkTypes.h:171
uint32_t SkFourByteTag
Definition: SkTypes.h:158
Definition: SkFontMgr.h:36
Definition: SkFontStyle.h:16
SkFont controls options applied when drawing and measuring text.
Definition: SkFont.h:36
Definition: SkShaper.h:78
virtual uint8_t currentLevel() const =0
The unicode bidi embedding level (even ltr, odd rtl)
Definition: SkShaper.h:74
virtual const SkFont & currentFont() const =0
Definition: SkShaper.h:88
virtual const char * currentLanguage() const =0
Should be BCP-47, c locale names may also work.
Definition: SkShaper.h:180
virtual void commitRunBuffer(const RunInfo &)=0
Called after each runBuffer is filled out.
virtual void beginLine()=0
Called when beginning a line.
virtual void commitLine()=0
Called when ending a line.
virtual ~RunHandler()=default
virtual void commitRunInfo()=0
Called after all runInfo calls for a line.
virtual void runInfo(const RunInfo &)=0
Called once for each run in a line.
virtual Buffer runBuffer(const RunInfo &)=0
Called for each run in a line after commitRunInfo.
Definition: SkShaper.h:64
virtual bool atEnd() const =0
Return true if consume should no longer be called.
virtual void consume()=0
Set state to that of current run and move iterator to end of that run.
virtual size_t endOfCurrentRun() const =0
Offset to one past the last (utf8) element in the current run.
virtual ~RunIterator()=default
Definition: SkShaper.h:83
virtual SkFourByteTag currentScript() const =0
Should be iso15924 codes.
Definition: SkShaper.h:140
TrivialBiDiRunIterator(uint8_t bidiLevel, size_t utf8Bytes)
Definition: SkShaper.h:142
uint8_t currentLevel() const override
Definition: SkShaper.h:144
Definition: SkShaper.h:123
TrivialFontRunIterator(const SkFont &font, size_t utf8Bytes)
Definition: SkShaper.h:125
const SkFont & currentFont() const override
Definition: SkShaper.h:127
Definition: SkShaper.h:171
TrivialLanguageRunIterator(const char *language, size_t utf8Bytes)
Definition: SkShaper.h:173
const char * currentLanguage() const override
Definition: SkShaper.h:175
Definition: SkShaper.h:160
SkFourByteTag currentScript() const override
Definition: SkShaper.h:164
TrivialScriptRunIterator(SkFourByteTag script, size_t utf8Bytes)
Definition: SkShaper.h:162
Definition: SkShaper.h:44
static std::unique_ptr< SkShaper::FontRunIterator > MakeFontMgrRunIterator(const char *utf8, size_t utf8Bytes, const SkFont &font, sk_sp< SkFontMgr > fallback, const char *requestName, SkFontStyle requestStyle, const SkShaper::LanguageRunIterator *)
static std::unique_ptr< LanguageRunIterator > MakeStdLanguageRunIterator(const char *utf8, size_t utf8Bytes)
static std::unique_ptr< ScriptRunIterator > MakeScriptRunIterator(const char *utf8, size_t utf8Bytes, SkFourByteTag script)
static std::unique_ptr< FontRunIterator > MakeFontMgrRunIterator(const char *utf8, size_t utf8Bytes, const SkFont &font, sk_sp< SkFontMgr > fallback)
virtual void shape(const char *utf8, size_t utf8Bytes, FontRunIterator &, BiDiRunIterator &, ScriptRunIterator &, LanguageRunIterator &, const Feature *features, size_t featuresSize, SkScalar width, RunHandler *) const =0
static std::unique_ptr< BiDiRunIterator > MakeBiDiRunIterator(const char *utf8, size_t utf8Bytes, uint8_t bidiLevel)
static std::unique_ptr< SkShaper > MakePrimitive()
virtual void shape(const char *utf8, size_t utf8Bytes, const SkFont &srcFont, bool leftToRight, SkScalar width, RunHandler *) const =0
static void PurgeCaches()
static std::unique_ptr< SkShaper > Make(sk_sp< SkFontMgr >=nullptr)
virtual void shape(const char *utf8, size_t utf8Bytes, FontRunIterator &, BiDiRunIterator &, ScriptRunIterator &, LanguageRunIterator &, SkScalar width, RunHandler *) const =0
Light weight class for managing strings.
Definition: SkString.h:118
Helper for shaping text directly into a SkTextBlob.
Definition: SkShaper.h:261
SkPoint endPoint()
Definition: SkShaper.h:267
void commitLine() override
Called when ending a line.
sk_sp< SkTextBlob > makeBlob()
void beginLine() override
Called when beginning a line.
void commitRunInfo() override
Called after all runInfo calls for a line.
void runInfo(const RunInfo &) override
Called once for each run in a line.
void commitRunBuffer(const RunInfo &) override
Called after each runBuffer is filled out.
Buffer runBuffer(const RunInfo &) override
Called for each run in a line after commitRunInfo.
SkTextBlobBuilderRunHandler(const char *utf8Text, SkPoint offset)
Definition: SkShaper.h:263
Helper class for constructing SkTextBlob.
Definition: SkTextBlob.h:290
Definition: SkShaper.h:93
uint32_t value
Definition: SkShaper.h:95
size_t start
Definition: SkShaper.h:96
SkFourByteTag tag
Definition: SkShaper.h:94
size_t end
Definition: SkShaper.h:97
Definition: SkShaper.h:202
SkGlyphID * glyphs
Definition: SkShaper.h:203
SkPoint point
Definition: SkShaper.h:208
uint32_t * clusters
Definition: SkShaper.h:207
SkPoint * positions
Definition: SkShaper.h:204
SkPoint * offsets
Definition: SkShaper.h:206
Definition: SkShaper.h:184
constexpr size_t size() const
Definition: SkShaper.h:191
constexpr size_t begin() const
Definition: SkShaper.h:189
size_t fBegin
Definition: SkShaper.h:187
constexpr size_t end() const
Definition: SkShaper.h:190
size_t fSize
Definition: SkShaper.h:188
constexpr Range(size_t begin, size_t size)
Definition: SkShaper.h:186
constexpr Range()
Definition: SkShaper.h:185
Definition: SkShaper.h:194
uint8_t fBidiLevel
Definition: SkShaper.h:196
const SkFont & fFont
Definition: SkShaper.h:195
SkVector fAdvance
Definition: SkShaper.h:197
size_t glyphCount
Definition: SkShaper.h:198
Range utf8Range
Definition: SkShaper.h:199