10#ifdef SK_BUILD_FOR_MAC
11#import <ApplicationServices/ApplicationServices.h>
14#ifdef SK_BUILD_FOR_IOS
15#include <CoreText/CoreText.h>
16#include <CoreText/CTFontManager.h>
17#include <CoreGraphics/CoreGraphics.h>
18#include <CoreFoundation/CoreFoundation.h>
37#if !defined(SK_DISABLE_LEGACY_SKSHAPER_FUNCTIONS)
38 void shape(
const char*
utf8,
size_t utf8Bytes,
42 RunHandler*)
const override;
44 void shape(
const char*
utf8,
size_t utf8Bytes,
50 RunHandler*)
const override;
53 void shape(
const char*
utf8,
size_t utf8Bytes,
58 const Feature*,
size_t featureSize,
60 RunHandler*)
const override;
65 CTTypesetterRef fTypesetter;
75 CFRange stringRange {fStart, CTTypesetterSuggestLineBreak(fTypesetter, fStart, fWidth)};
76 if (stringRange.length == 0) {
79 fStart += stringRange.length;
80 return SkUniqueCFRef<CTLineRef>(CTTypesetterCreateLine(fTypesetter, stringRange));
85 SkUniqueCFRef<CFNumberRef> number(
86 CFNumberCreate(kCFAllocatorDefault, kCFNumberDoubleType, &
value));
87 CFDictionaryAddValue(
d,
name, number.get());
91 auto typeface =
font.getTypeface();
92 auto ctfont = SkTypeface_GetCTFontRef(typeface);
96 return SkUniqueCFRef<CTFontRef>(
97 CTFontCreateCopyWithAttributes(ctfont,
font.getSize(),
nullptr,
nullptr));
101 CFDictionaryRef attr = CTRunGetAttributes(
run);
102 CTFontRef ct = (CTFontRef)CFDictionaryGetValue(attr, kCTFontAttributeName);
104 SkDebugf(
"no ctfont in Run Attributes\n");
110 font.setTypeface(SkMakeTypefaceFromCTFont(ct));
115class UTF16ToUTF8IndicesMap {
120 bool setUTF8(
const char*
utf8,
size_t size) {
123 if (!SkTFitsIn<int32_t>(
size)) {
124 SkDEBUGF(
"UTF16ToUTF8IndicesMap: text too long");
130 SkDEBUGF(
"UTF16ToUTF8IndicesMap: Invalid utf8 input");
135 fUtf16ToUtf8Indices = std::vector<size_t>(utf16Size + 1);
136 auto utf16 = fUtf16ToUtf8Indices.begin();
138 while (utf8Begin < utf8End) {
139 *utf16 = utf8Begin -
utf8;
147 size_t mapIndex(
size_t index)
const {
148 SkASSERT(index < fUtf16ToUtf8Indices.size());
149 return fUtf16ToUtf8Indices[index];
152 std::pair<size_t, size_t> mapRange(
size_t start,
size_t size)
const {
153 auto utf8Start = mapIndex(
start);
154 return {utf8Start, mapIndex(
start +
size) - utf8Start};
157 std::vector<size_t> fUtf16ToUtf8Indices;
164#if !defined(SK_DISABLE_LEGACY_SKSHAPER_FUNCTIONS)
165void SkShaper_CoreText::shape(
const char*
utf8,
167 FontRunIterator&
font,
168 BiDiRunIterator& bidi,
170 LanguageRunIterator&
lang,
172 RunHandler* handler)
const {
176void SkShaper_CoreText::shape(
const char*
utf8,
181 RunHandler* handler)
const {
182 std::unique_ptr<FontRunIterator> fontRuns(
190 TrivialLanguageRunIterator
lang{
nullptr, 0};
191 return this->shape(
utf8, utf8Bytes, *fontRuns, bidi,
script,
lang,
nullptr, 0,
width, handler);
195void SkShaper_CoreText::shape(
const char*
utf8,
197 FontRunIterator& fontRuns,
200 LanguageRunIterator&,
204 RunHandler* handler)
const {
206 if (!fontRuns.atEnd()) {
208 font = fontRuns.currentFont();
211 SkUniqueCFRef<CFStringRef> textString(
212 CFStringCreateWithBytes(kCFAllocatorDefault, (
const uint8_t*)
utf8, utf8Bytes,
213 kCFStringEncodingUTF8,
false));
215 UTF16ToUTF8IndicesMap utf8IndicesMap;
216 if (!utf8IndicesMap.setUTF8(
utf8, utf8Bytes)) {
225 SkUniqueCFRef<CFMutableDictionaryRef> attr(
226 CFDictionaryCreateMutable(kCFAllocatorDefault, 0,
227 &kCFTypeDictionaryKeyCallBacks,
228 &kCFTypeDictionaryValueCallBacks));
229 CFDictionaryAddValue(attr.get(), kCTFontAttributeName, ctfont.get());
236 SkUniqueCFRef<CFAttributedStringRef> attrString(
237 CFAttributedStringCreate(kCFAllocatorDefault, textString.get(), attr.get()));
239 SkUniqueCFRef<CTTypesetterRef> typesetter(
240 CTTypesetterCreateWithAttributedString(attrString.get()));
244 std::vector<SkFont> fontStorage;
245 std::vector<SkShaper::RunHandler::RunInfo> infos;
248 while (SkUniqueCFRef<CTLineRef>
line = iter.nextLine()) {
249 CFArrayRef run_array = CTLineGetGlyphRuns(
line.get());
250 CFIndex runCount = CFArrayGetCount(run_array);
254 handler->beginLine();
256 fontStorage.reserve(runCount);
258 for (CFIndex j = 0; j < runCount; ++j) {
259 CTRunRef
run = (CTRunRef)CFArrayGetValueAtIndex(run_array, j);
260 CFIndex runGlyphs = CTRunGetGlyphCount(
run);
262 SkASSERT(
sizeof(CGGlyph) ==
sizeof(uint16_t));
265 CTRunGetAdvances(
run, {0, runGlyphs}, advances.data());
267 for (CFIndex k = 0; k < runGlyphs; ++k) {
268 adv += advances[k].width;
271 CFRange cfRange = CTRunGetStringRange(
run);
272 auto range = utf8IndicesMap.mapRange(cfRange.location, cfRange.length);
280 {range.first, range.second},
282 handler->runInfo(infos.back());
284 handler->commitRunInfo();
288 for (CFIndex j = 0; j < runCount; ++j) {
289 const auto&
info = infos[j];
292 CTRunRef
run = (CTRunRef)CFArrayGetValueAtIndex(run_array, j);
293 CFIndex runGlyphs =
info.glyphCount;
296 CTRunGetGlyphs(
run, {0, runGlyphs},
buffer.glyphs);
299 CTRunGetPositions(
run, {0, runGlyphs}, positions.data());
302 indices.
reset(runGlyphs);
303 CTRunGetStringIndices(
run, {0, runGlyphs}, indices.
data());
306 for (CFIndex k = 0; k < runGlyphs; ++k) {
308 buffer.point.fX + SkScalarFromCGFloat(positions[k].
x) - lineAdvance,
312 buffer.offsets[k] = {0, 0};
315 buffer.clusters[k] = utf8IndicesMap.mapIndex(indices[k]);
318 handler->commitRunBuffer(
info);
319 lineAdvance +=
info.fAdvance.fX;
321 handler->commitLine();
326std::unique_ptr<SkShaper>
CoreText() {
return std::make_unique<SkShaper_CoreText>(); }
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
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)
LineBreakIter(CTTypesetterRef ts, SkScalar width)
SkUniqueCFRef< CTLineRef > nextLine()
static std::unique_ptr< FontRunIterator > MakeFontMgrRunIterator(const char *utf8, size_t utf8Bytes, const SkFont &font, sk_sp< SkFontMgr > fallback)
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE auto & d
SKSHAPER_API std::unique_ptr< SkShaper > CoreText()
SKSHAPER_API std::unique_ptr< SkShaper::ScriptRunIterator > ScriptRunIterator(const char *utf8, size_t utf8Bytes)
SKSHAPER_API std::unique_ptr< SkShaper::BiDiRunIterator > TrivialBiDiRunIterator(size_t utf8Bytes, uint8_t bidiLevel)
SKSHAPER_API std::unique_ptr< SkShaper::ScriptRunIterator > TrivialScriptRunIterator(size_t utf8Bytes, SkFourByteTag scriptTag)
SK_SPI int UTF8ToUTF16(uint16_t dst[], int dstCapacity, const char src[], size_t srcByteLength)
SK_SPI SkUnichar NextUTF8(const char **ptr, const char *end)
SK_SPI size_t ToUTF16(SkUnichar uni, uint16_t utf16[2]=nullptr)
DEF_SWITCHES_START aot vmservice shared library name
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
font
Font Metadata and Metrics.