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_win.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_win.cpp')
-rw-r--r-- | src/ports/SkFontHost_win.cpp | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/src/ports/SkFontHost_win.cpp b/src/ports/SkFontHost_win.cpp index 35a0a74b22..f1da8053f2 100644 --- a/src/ports/SkFontHost_win.cpp +++ b/src/ports/SkFontHost_win.cpp @@ -261,6 +261,7 @@ protected: SkScalerContext* onCreateScalerContext(const SkScalerContextEffects&, const SkDescriptor*) const override; void onFilterRec(SkScalerContextRec*) const override; + void getGlyphToUnicodeMap(SkUnichar*) const override; std::unique_ptr<SkAdvancedTypefaceMetrics> onGetAdvancedMetrics() const override; void onGetFontDescriptor(SkFontDescriptor*, bool*) const override; int onCharsToGlyphs(const void* chars, Encoding encoding, @@ -362,7 +363,8 @@ void SkLOGFONTFromTypeface(const SkTypeface* face, LOGFONT* lf) { // require parsing the TTF cmap table (platform 4, encoding 12) directly instead // of calling GetFontUnicodeRange(). static void populate_glyph_to_unicode(HDC fontHdc, const unsigned glyphCount, - SkTDArray<SkUnichar>* glyphToUnicode) { + SkUnichar* glyphToUnicode) { + sk_bzero(glyphToUnicode, sizeof(SkUnichar) * glyphCount); DWORD glyphSetBufferSize = GetFontUnicodeRanges(fontHdc, nullptr); if (!glyphSetBufferSize) { return; @@ -375,8 +377,6 @@ static void populate_glyph_to_unicode(HDC fontHdc, const unsigned glyphCount, return; } - glyphToUnicode->setCount(glyphCount); - memset(glyphToUnicode->begin(), 0, glyphCount * sizeof(SkUnichar)); for (DWORD i = 0; i < glyphSet->cRanges; ++i) { // There is no guarantee that within a Unicode range, the corresponding // glyph id in a font file are continuous. So, even if we have ranges, @@ -399,9 +399,8 @@ static void populate_glyph_to_unicode(HDC fontHdc, const unsigned glyphCount, // unlikely to have collisions since glyph reuse happens mostly for // different Unicode pages. for (USHORT j = 0; j < count; ++j) { - if (glyph[j] != 0xffff && glyph[j] < glyphCount && - (*glyphToUnicode)[glyph[j]] == 0) { - (*glyphToUnicode)[glyph[j]] = chars[j]; + if (glyph[j] != 0xFFFF && glyph[j] < glyphCount && glyphToUnicode[glyph[j]] == 0) { + glyphToUnicode[glyph[j]] = chars[j]; } } } @@ -1707,6 +1706,23 @@ void LogFontTypeface::onGetFontDescriptor(SkFontDescriptor* desc, *isLocalStream = this->fSerializeAsStream; } +void LogFontTypeface::getGlyphToUnicodeMap(SkUnichar* dstArray) const { + HDC hdc = ::CreateCompatibleDC(nullptr); + HFONT font = CreateFontIndirect(&fLogFont); + HFONT savefont = (HFONT)SelectObject(hdc, font); + LOGFONT lf = fLogFont; + HFONT designFont = CreateFontIndirect(&lf); + SelectObject(hdc, designFont); + + unsigned int glyphCount = calculateGlyphCount(hdc, fLogFont); + populate_glyph_to_unicode(hdc, glyphCount, dstArray); + + SelectObject(hdc, savefont); + DeleteObject(designFont); + DeleteObject(font); + DeleteDC(hdc); +} + std::unique_ptr<SkAdvancedTypefaceMetrics> LogFontTypeface::onGetAdvancedMetrics() const { LOGFONT lf = fLogFont; std::unique_ptr<SkAdvancedTypefaceMetrics> info(nullptr); @@ -1757,8 +1773,6 @@ std::unique_ptr<SkAdvancedTypefaceMetrics> LogFontTypeface::onGetAdvancedMetrics } } - populate_glyph_to_unicode(hdc, glyphCount, &(info->fGlyphToUnicode)); - if (glyphCount > 0 && (otm.otmTextMetrics.tmPitchAndFamily & TMPF_TRUETYPE)) { info->fType = SkAdvancedTypefaceMetrics::kTrueType_Font; |