Index: src/ports/SkFontHost_win.cpp |
=================================================================== |
--- src/ports/SkFontHost_win.cpp (revision 10894) |
+++ src/ports/SkFontHost_win.cpp (working copy) |
@@ -118,7 +118,7 @@ |
} |
static void make_canonical(LOGFONT* lf) { |
- lf->lfHeight = -2048; |
+ lf->lfHeight = -12; |
reed1
2013/10/18 13:53:46
Lets add a comment for this (new) magic value -- i
bungeman-skia
2013/10/23 22:20:03
This already got set back to -64 for other reasons
|
lf->lfQuality = CLEARTYPE_QUALITY;//PROOF_QUALITY; |
lf->lfCharSet = DEFAULT_CHARSET; |
// lf->lfClipPrecision = 64; |
@@ -266,6 +266,8 @@ |
SkAdvancedTypefaceMetrics::PerGlyphInfo, |
const uint32_t*, uint32_t) const SK_OVERRIDE; |
virtual void onGetFontDescriptor(SkFontDescriptor*, bool*) const SK_OVERRIDE; |
+ virtual int onCharsToGlyphs(const void* chars, Encoding encoding, |
+ uint16_t glyphs[], int glyphCount) const SK_OVERRIDE; |
virtual int onCountGlyphs() const SK_OVERRIDE; |
virtual int onGetUPEM() const SK_OVERRIDE; |
virtual SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const SK_OVERRIDE; |
@@ -2019,6 +2021,109 @@ |
return stream; |
} |
+static SkUnichar next_utf8(const void** chars) { |
+ return SkUTF8_NextUnichar((const char**)chars); |
+} |
+ |
+static SkUnichar next_utf16(const void** chars) { |
+ return SkUTF16_NextUnichar((const uint16_t**)chars); |
+} |
+ |
+static SkUnichar next_utf32(const void** chars) { |
+ const SkUnichar** uniChars = (const SkUnichar**)chars; |
+ SkUnichar uni = **uniChars; |
+ *uniChars += 1; |
+ return uni; |
+} |
+ |
+typedef SkUnichar (*EncodingProc)(const void**); |
+ |
+static EncodingProc find_encoding_proc(SkTypeface::Encoding enc) { |
+ static const EncodingProc gProcs[] = { |
+ next_utf8, next_utf16, next_utf32 |
+ }; |
+ SkASSERT((size_t)enc < SK_ARRAY_COUNT(gProcs)); |
+ return gProcs[enc]; |
+} |
+ |
+static uint16_t charToGlyph(HDC hdc, SkUnichar uni) { |
+ uint16_t index = 0; |
+ WCHAR c[2]; |
+ // TODO(ctguil): Support characters that generate more than one glyph. |
+ if (SkUTF16_FromUnichar(uni, (uint16_t*)c) == 1) { |
+ // Type1 fonts fail with uniscribe API. Use GetGlyphIndices for plane 0. |
+ SkAssertResult(GetGlyphIndicesW(hdc, c, 1, &index, 0)); |
+ } else { |
+ // Use uniscribe to detemine glyph index for non-BMP characters. |
+ // Need to add extra item to SCRIPT_ITEM to work around a bug in older |
+ // windows versions. https://bugzilla.mozilla.org/show_bug.cgi?id=366643 |
+ SCRIPT_ITEM si[2 + 1]; |
+ int items; |
+ SkAssertResult( |
+ SUCCEEDED(ScriptItemize(c, 2, 2, NULL, NULL, si, &items))); |
+ |
+ WORD log[2]; |
+ SCRIPT_VISATTR vsa; |
+ SCRIPT_CACHE scriptCache = NULL; |
+ int glyphs; |
+ SkAssertResult(SUCCEEDED(ScriptShape( |
+ hdc, &scriptCache, c, 2, 1, &si[0].a, &index, log, &vsa, &glyphs))); |
+ if (scriptCache) { |
+ ::ScriptFreeCache(&scriptCache); |
+ } |
+ } |
+ return index; |
+} |
+ |
+class SkAutoHDC { |
+public: |
+ SkAutoHDC(const LOGFONT& lf) |
+ : fHdc(::CreateCompatibleDC(NULL)) |
+ , fFont(::CreateFontIndirect(&lf)) |
+ , fSavefont((HFONT)SelectObject(fHdc, fFont)) |
+ { } |
+ ~SkAutoHDC() { |
+ SelectObject(fHdc, fSavefont); |
+ DeleteObject(fFont); |
+ DeleteDC(fHdc); |
+ } |
+ operator HDC() { return fHdc; } |
+private: |
+ HDC fHdc; |
+ HFONT fFont; |
+ HFONT fSavefont; |
+}; |
+ |
+int LogFontTypeface::onCharsToGlyphs(const void* chars, Encoding encoding, |
+ uint16_t glyphs[], int glyphCount) const |
+{ |
+ EncodingProc next_uni_proc = find_encoding_proc(encoding); |
+ |
+ SkAutoHDC hdc(fLogFont); |
+ |
+ if (NULL == glyphs) { |
+ for (int i = 0; i < glyphCount; ++i) { |
+ const SkUnichar c = next_uni_proc(&chars); |
+ UINT16 glyphIndex = charToGlyph(hdc, c); |
+ if (0 == glyphIndex) { |
+ return i; |
+ } |
+ } |
+ return glyphCount; |
+ } |
+ |
+ int first = glyphCount; |
+ for (int i = 0; i < glyphCount; ++i) { |
+ const SkUnichar c = next_uni_proc(&chars); |
+ UINT16 glyphIndex = charToGlyph(hdc, c); |
+ glyphs[i] = glyphIndex; |
+ if (0 == glyphIndex && i < first) { |
+ first = i; |
+ } |
+ } |
+ return first; |
+} |
+ |
int LogFontTypeface::onCountGlyphs() const { |
HDC hdc = ::CreateCompatibleDC(NULL); |
HFONT font = CreateFontIndirect(&fLogFont); |