Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | List of all members
SkShaper_CoreText Class Reference
Inheritance diagram for SkShaper_CoreText:
SkShaper

Public Member Functions

 SkShaper_CoreText ()
 
- Public Member Functions inherited from SkShaper
 SkShaper ()
 
virtual ~SkShaper ()
 

Private Member Functions

void shape (const char *utf8, size_t utf8Bytes, const SkFont &srcFont, bool leftToRight, SkScalar width, RunHandler *) const override
 
void shape (const char *utf8, size_t utf8Bytes, FontRunIterator &, BiDiRunIterator &, ScriptRunIterator &, LanguageRunIterator &, SkScalar width, RunHandler *) const override
 
void shape (const char *utf8, size_t utf8Bytes, FontRunIterator &, BiDiRunIterator &, ScriptRunIterator &, LanguageRunIterator &, const Feature *, size_t featureSize, SkScalar width, RunHandler *) const override
 

Additional Inherited Members

- Static Public Member Functions inherited from SkShaper
static std::unique_ptr< SkShaperMakePrimitive ()
 
static std::unique_ptr< SkShaperMake (sk_sp< SkFontMgr > fallback=nullptr)
 
static void PurgeCaches ()
 
static std::unique_ptr< FontRunIteratorMakeFontMgrRunIterator (const char *utf8, size_t utf8Bytes, const SkFont &font, sk_sp< SkFontMgr > fallback)
 
static std::unique_ptr< SkShaper::FontRunIteratorMakeFontMgrRunIterator (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< BiDiRunIteratorMakeBiDiRunIterator (const char *utf8, size_t utf8Bytes, uint8_t bidiLevel)
 
static std::unique_ptr< ScriptRunIteratorMakeScriptRunIterator (const char *utf8, size_t utf8Bytes, SkFourByteTag script)
 
static std::unique_ptr< LanguageRunIteratorMakeStdLanguageRunIterator (const char *utf8, size_t utf8Bytes)
 

Detailed Description

Definition at line 33 of file SkShaper_coretext.cpp.

Constructor & Destructor Documentation

◆ SkShaper_CoreText()

SkShaper_CoreText::SkShaper_CoreText ( )
inline

Definition at line 35 of file SkShaper_coretext.cpp.

35{}

Member Function Documentation

◆ shape() [1/3]

void SkShaper_CoreText::shape ( const char *  utf8,
size_t  utf8Bytes,
const SkFont srcFont,
bool  leftToRight,
SkScalar  width,
RunHandler handler 
) const
overrideprivatevirtual

Implements SkShaper.

Definition at line 173 of file SkShaper_coretext.cpp.

178 {
179 std::unique_ptr<FontRunIterator> fontRuns(
180 MakeFontMgrRunIterator(utf8, utf8Bytes, font, nullptr));
181 if (!fontRuns) {
182 return;
183 }
184 // bidi, script, and lang are all unused so we can construct them with empty data.
185 TrivialBiDiRunIterator bidi{0, 0};
186 TrivialScriptRunIterator script{0, 0};
187 TrivialLanguageRunIterator lang{nullptr, 0};
188 return this->shape(utf8, utf8Bytes, *fontRuns, bidi, script, lang, nullptr, 0, width, handler);
189}
void shape(const char *utf8, size_t utf8Bytes, const SkFont &srcFont, bool leftToRight, SkScalar width, RunHandler *) const override
static std::unique_ptr< FontRunIterator > MakeFontMgrRunIterator(const char *utf8, size_t utf8Bytes, const SkFont &font, sk_sp< SkFontMgr > fallback)
Definition SkShaper.cpp:187
int32_t width

◆ shape() [2/3]

void SkShaper_CoreText::shape ( const char *  utf8,
size_t  utf8Bytes,
FontRunIterator fontRuns,
BiDiRunIterator ,
ScriptRunIterator ,
LanguageRunIterator ,
const Feature ,
size_t  featureSize,
SkScalar  width,
RunHandler handler 
) const
overrideprivatevirtual

Implements SkShaper.

Definition at line 192 of file SkShaper_coretext.cpp.

201 {
202 SkFont font;
203 if (!fontRuns.atEnd()) {
204 fontRuns.consume();
205 font = fontRuns.currentFont();
206 }
207 SkASSERT(font.getTypeface());
208
209 SkUniqueCFRef<CFStringRef> textString(
210 CFStringCreateWithBytes(kCFAllocatorDefault, (const uint8_t*)utf8, utf8Bytes,
211 kCFStringEncodingUTF8, false));
212
213 UTF16ToUTF8IndicesMap utf8IndicesMap;
214 if (!utf8IndicesMap.setUTF8(utf8, utf8Bytes)) {
215 return;
216 }
217
218 SkUniqueCFRef<CTFontRef> ctfont = create_ctfont_from_font(font);
219
220 SkUniqueCFRef<CFMutableDictionaryRef> attr(
221 CFDictionaryCreateMutable(kCFAllocatorDefault, 0,
222 &kCFTypeDictionaryKeyCallBacks,
223 &kCFTypeDictionaryValueCallBacks));
224 CFDictionaryAddValue(attr.get(), kCTFontAttributeName, ctfont.get());
225 if ((false)) {
226 // trying to see what these affect
228 dict_add_double(attr.get(), kCTKernAttributeName, 0.0);
229 }
230
231 SkUniqueCFRef<CFAttributedStringRef> attrString(
232 CFAttributedStringCreate(kCFAllocatorDefault, textString.get(), attr.get()));
233
234 SkUniqueCFRef<CTTypesetterRef> typesetter(
235 CTTypesetterCreateWithAttributedString(attrString.get()));
236
237 // We have to compute RunInfos in a loop, and then reuse them in a 2nd loop,
238 // so we store them in an array (we reuse the array's storage for each line).
239 std::vector<SkFont> fontStorage;
240 std::vector<SkShaper::RunHandler::RunInfo> infos;
241
242 LineBreakIter iter(typesetter.get(), width);
243 while (SkUniqueCFRef<CTLineRef> line = iter.nextLine()) {
244 CFArrayRef run_array = CTLineGetGlyphRuns(line.get());
245 CFIndex runCount = CFArrayGetCount(run_array);
246 if (runCount == 0) {
247 continue;
248 }
249 handler->beginLine();
250 fontStorage.clear();
251 fontStorage.reserve(runCount); // ensure the refs won't get invalidated
252 infos.clear();
253 for (CFIndex j = 0; j < runCount; ++j) {
254 CTRunRef run = (CTRunRef)CFArrayGetValueAtIndex(run_array, j);
255 CFIndex runGlyphs = CTRunGetGlyphCount(run);
256
257 SkASSERT(sizeof(CGGlyph) == sizeof(uint16_t));
258
259 AutoSTArray<4096, CGSize> advances(runGlyphs);
260 CTRunGetAdvances(run, {0, runGlyphs}, advances.data());
261 SkScalar adv = 0;
262 for (CFIndex k = 0; k < runGlyphs; ++k) {
263 adv += advances[k].width;
264 }
265
266 CFRange cfRange = CTRunGetStringRange(run);
267 auto range = utf8IndicesMap.mapRange(cfRange.location, cfRange.length);
268
269 fontStorage.push_back(run_to_font(run, font));
270 infos.push_back({
271 fontStorage.back(), // info just stores a ref to the font
272 0, // need fBidiLevel
273 {adv, 0},
274 (size_t)runGlyphs,
275 {range.first, range.second},
276 });
277 handler->runInfo(infos.back());
278 }
279 handler->commitRunInfo();
280
281 // Now loop through again and fill in the buffers
282 SkScalar lineAdvance = 0;
283 for (CFIndex j = 0; j < runCount; ++j) {
284 const auto& info = infos[j];
285 auto buffer = handler->runBuffer(info);
286
287 CTRunRef run = (CTRunRef)CFArrayGetValueAtIndex(run_array, j);
288 CFIndex runGlyphs = info.glyphCount;
289 SkASSERT(CTRunGetGlyphCount(run) == (CFIndex)info.glyphCount);
290
291 CTRunGetGlyphs(run, {0, runGlyphs}, buffer.glyphs);
292
293 AutoSTArray<4096, CGPoint> positions(runGlyphs);
294 CTRunGetPositions(run, {0, runGlyphs}, positions.data());
296 if (buffer.clusters) {
297 indices.reset(runGlyphs);
298 CTRunGetStringIndices(run, {0, runGlyphs}, indices.data());
299 }
300
301 for (CFIndex k = 0; k < runGlyphs; ++k) {
302 buffer.positions[k] = {
303 buffer.point.fX + SkScalarFromCGFloat(positions[k].x) - lineAdvance,
304 buffer.point.fY,
305 };
306 if (buffer.offsets) {
307 buffer.offsets[k] = {0, 0}; // offset relative to the origin for this glyph
308 }
309 if (buffer.clusters) {
310 buffer.clusters[k] = utf8IndicesMap.mapIndex(indices[k]);
311 }
312 }
313 handler->commitRunBuffer(info);
314 lineAdvance += info.fAdvance.fX;
315 }
316 handler->commitLine();
317 }
318}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
#define SkASSERT(cond)
Definition SkAssert.h:116
static void dict_add_double(CFMutableDictionaryRef d, const void *name, double value)
static SkUniqueCFRef< CTFontRef > create_ctfont_from_font(const SkFont &font)
const CFStringRef kCTTracking_AttributeName
static SkFont run_to_font(CTRunRef run, const SkFont &orig)
const T * data() const
float SkScalar
Definition extension.cpp:12
static const uint8_t buffer[]
double x
font
Font Metadata and Metrics.
Definition run.py:1

◆ shape() [3/3]

void SkShaper_CoreText::shape ( const char *  utf8,
size_t  utf8Bytes,
FontRunIterator font,
BiDiRunIterator bidi,
ScriptRunIterator script,
LanguageRunIterator lang,
SkScalar  width,
RunHandler handler 
) const
overrideprivatevirtual

Implements SkShaper.

Definition at line 162 of file SkShaper_coretext.cpp.

169 {
170 return this->shape(utf8, utf8Bytes, font, bidi, script, lang, nullptr, 0, width, handler);
171}

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