aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/ports/SkFontHost_win.cpp
diff options
context:
space:
mode:
authorGravatar Hal Canary <halcanary@google.com>2018-04-10 11:27:48 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-05-09 14:24:45 +0000
commit1c2bcd8b14e029a70e88b1e81acd29553cab0d1c (patch)
tree723a0c85100bcb59590bd2e46fc5eb5c10472406 /src/ports/SkFontHost_win.cpp
parenta2595f925596aca234d4ac4e35da689ef13cc27c (diff)
SkAdvancedTypefaceMetrics: factor out GlyphToUnicode
Change-Id: Iedce8c1ea2c405d5ab64ccac353970d5cd2b9d63 Reviewed-on: https://skia-review.googlesource.com/126507 Commit-Queue: Hal Canary <halcanary@google.com> Reviewed-by: Ben Wagner <bungeman@google.com>
Diffstat (limited to 'src/ports/SkFontHost_win.cpp')
-rw-r--r--src/ports/SkFontHost_win.cpp30
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;