diff options
author | Hal Canary <halcanary@google.com> | 2018-05-09 11:50:34 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-05-09 18:00:35 +0000 |
commit | 46cc3dabaff7daa6b57e3c33997153d986219579 (patch) | |
tree | 809ca0d62fddcbd3b378d0a4d330692ebd58748d /src/ports/SkFontHost_mac.cpp | |
parent | 06d374694a515d064a26e6c5391bce9a0c5c8aa0 (diff) |
Revert "Revert "SkAdvancedTypefaceMetrics: factor out GlyphToUnicode""
This reverts commit 97c1108607584b6050a6880d6ce22846e4913a92.
Change-Id: Ic3c6addc64ced39766bbee3e10b4d88faf61ba2f
Reviewed-on: https://skia-review.googlesource.com/127021
Reviewed-by: Hal Canary <halcanary@google.com>
Commit-Queue: Hal Canary <halcanary@google.com>
Diffstat (limited to 'src/ports/SkFontHost_mac.cpp')
-rw-r--r-- | src/ports/SkFontHost_mac.cpp | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/src/ports/SkFontHost_mac.cpp b/src/ports/SkFontHost_mac.cpp index 8047c4352f..3cc51d43f6 100644 --- a/src/ports/SkFontHost_mac.cpp +++ b/src/ports/SkFontHost_mac.cpp @@ -719,6 +719,7 @@ protected: const SkDescriptor*) const override; void onFilterRec(SkScalerContextRec*) const override; void onGetFontDescriptor(SkFontDescriptor*, bool*) const override; + void getGlyphToUnicodeMap(SkUnichar*) const override; std::unique_ptr<SkAdvancedTypefaceMetrics> onGetAdvancedMetrics() const override; int onCharsToGlyphs(const void* chars, Encoding, uint16_t glyphs[], int glyphCount) const override; @@ -1605,9 +1606,7 @@ static sk_sp<SkTypeface> create_from_dataProvider(UniqueCFRef<CGDataProviderRef> // Iterate through the font in this case. The existing caller caches the result, // so the performance impact isn't too bad. static void populate_glyph_to_unicode_slow(CTFontRef ctFont, CFIndex glyphCount, - SkTDArray<SkUnichar>* glyphToUnicode) { - glyphToUnicode->setCount(SkToInt(glyphCount)); - SkUnichar* out = glyphToUnicode->begin(); + SkUnichar* out) { sk_bzero(out, glyphCount * sizeof(SkUnichar)); UniChar unichar = 0; while (glyphCount > 0) { @@ -1628,7 +1627,8 @@ static void populate_glyph_to_unicode_slow(CTFontRef ctFont, CFIndex glyphCount, // Unicode code points that require conjugate pairs in utf16 are not // supported. static void populate_glyph_to_unicode(CTFontRef ctFont, CFIndex glyphCount, - SkTDArray<SkUnichar>* glyphToUnicode) { + SkUnichar* glyphToUnicode) { + sk_bzero(glyphToUnicode, sizeof(SkUnichar) * glyphCount); UniqueCFRef<CFCharacterSetRef> charSet(CTFontCopyCharacterSet(ctFont)); if (!charSet) { populate_glyph_to_unicode_slow(ctFont, glyphCount, glyphToUnicode); @@ -1651,9 +1651,7 @@ static void populate_glyph_to_unicode(CTFontRef ctFont, CFIndex glyphCount, length = 8192; } const UInt8* bits = CFDataGetBytePtr(bitmap.get()); - glyphToUnicode->setCount(SkToInt(glyphCount)); - SkUnichar* out = glyphToUnicode->begin(); - sk_bzero(out, glyphCount * sizeof(SkUnichar)); + sk_bzero(glyphToUnicode, glyphCount * sizeof(SkUnichar)); for (int i = 0; i < length; i++) { int mask = bits[i]; if (!mask) { @@ -1663,7 +1661,7 @@ static void populate_glyph_to_unicode(CTFontRef ctFont, CFIndex glyphCount, CGGlyph glyph; UniChar unichar = static_cast<UniChar>((i << 3) + j); if (mask & (1 << j) && CTFontGetGlyphsForCharacters(ctFont, &unichar, &glyph, 1)) { - out[glyph] = unichar; + glyphToUnicode[glyph] = unichar; } } } @@ -1681,6 +1679,14 @@ static void CFStringToSkString(CFStringRef src, SkString* dst) { dst->resize(strlen(dst->c_str())); } +void SkTypeface_Mac::getGlyphToUnicodeMap(SkUnichar* dstArray) const { + AUTO_CG_LOCK(); + UniqueCFRef<CTFontRef> ctFont = + ctfont_create_exact_copy(fFontRef.get(), CTFontGetUnitsPerEm(fFontRef.get()), nullptr); + CFIndex glyphCount = CTFontGetGlyphCount(ctFont.get()); + populate_glyph_to_unicode(ctFont.get(), glyphCount, dstArray); +} + std::unique_ptr<SkAdvancedTypefaceMetrics> SkTypeface_Mac::onGetAdvancedMetrics() const { AUTO_CG_LOCK(); @@ -1710,10 +1716,6 @@ std::unique_ptr<SkAdvancedTypefaceMetrics> SkTypeface_Mac::onGetAdvancedMetrics( } } - CFIndex glyphCount = CTFontGetGlyphCount(ctFont.get()); - - populate_glyph_to_unicode(ctFont.get(), glyphCount, &info->fGlyphToUnicode); - SkOTTableOS2_V4::Type fsType; if (sizeof(fsType) == this->getTableData(SkTEndian_SwapBE32(SkOTTableOS2::TAG), offsetof(SkOTTableOS2_V4, fsType), |