OLD | NEW |
---|---|
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 #include "SkAdvancedTypefaceMetrics.h" | 9 #include "SkAdvancedTypefaceMetrics.h" |
10 #include "SkBase64.h" | 10 #include "SkBase64.h" |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
111 call_ensure_accessible(lf); | 111 call_ensure_accessible(lf); |
112 if (0 == GetTextFace(deviceContext, fontNameLen, fontName.get())) { | 112 if (0 == GetTextFace(deviceContext, fontNameLen, fontName.get())) { |
113 fontName[0] = 0; | 113 fontName[0] = 0; |
114 } | 114 } |
115 } | 115 } |
116 | 116 |
117 tchar_to_skstring(fontName.get(), familyName); | 117 tchar_to_skstring(fontName.get(), familyName); |
118 } | 118 } |
119 | 119 |
120 static void make_canonical(LOGFONT* lf) { | 120 static void make_canonical(LOGFONT* lf) { |
121 lf->lfHeight = -2048; | 121 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
| |
122 lf->lfQuality = CLEARTYPE_QUALITY;//PROOF_QUALITY; | 122 lf->lfQuality = CLEARTYPE_QUALITY;//PROOF_QUALITY; |
123 lf->lfCharSet = DEFAULT_CHARSET; | 123 lf->lfCharSet = DEFAULT_CHARSET; |
124 // lf->lfClipPrecision = 64; | 124 // lf->lfClipPrecision = 64; |
125 } | 125 } |
126 | 126 |
127 static SkTypeface::Style get_style(const LOGFONT& lf) { | 127 static SkTypeface::Style get_style(const LOGFONT& lf) { |
128 unsigned style = 0; | 128 unsigned style = 0; |
129 if (lf.lfWeight >= FW_BOLD) { | 129 if (lf.lfWeight >= FW_BOLD) { |
130 style |= SkTypeface::kBold; | 130 style |= SkTypeface::kBold; |
131 } | 131 } |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
259 } | 259 } |
260 | 260 |
261 protected: | 261 protected: |
262 virtual SkStream* onOpenStream(int* ttcIndex) const SK_OVERRIDE; | 262 virtual SkStream* onOpenStream(int* ttcIndex) const SK_OVERRIDE; |
263 virtual SkScalerContext* onCreateScalerContext(const SkDescriptor*) const SK _OVERRIDE; | 263 virtual SkScalerContext* onCreateScalerContext(const SkDescriptor*) const SK _OVERRIDE; |
264 virtual void onFilterRec(SkScalerContextRec*) const SK_OVERRIDE; | 264 virtual void onFilterRec(SkScalerContextRec*) const SK_OVERRIDE; |
265 virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics( | 265 virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics( |
266 SkAdvancedTypefaceMetrics::PerGlyphInfo, | 266 SkAdvancedTypefaceMetrics::PerGlyphInfo, |
267 const uint32_t*, uint32_t) const SK_OVERRIDE; | 267 const uint32_t*, uint32_t) const SK_OVERRIDE; |
268 virtual void onGetFontDescriptor(SkFontDescriptor*, bool*) const SK_OVERRIDE ; | 268 virtual void onGetFontDescriptor(SkFontDescriptor*, bool*) const SK_OVERRIDE ; |
269 virtual int onCharsToGlyphs(const void* chars, Encoding encoding, | |
270 uint16_t glyphs[], int glyphCount) const SK_OVER RIDE; | |
269 virtual int onCountGlyphs() const SK_OVERRIDE; | 271 virtual int onCountGlyphs() const SK_OVERRIDE; |
270 virtual int onGetUPEM() const SK_OVERRIDE; | 272 virtual int onGetUPEM() const SK_OVERRIDE; |
271 virtual SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const SK_ OVERRIDE; | 273 virtual SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const SK_ OVERRIDE; |
272 virtual int onGetTableTags(SkFontTableTag tags[]) const SK_OVERRIDE; | 274 virtual int onGetTableTags(SkFontTableTag tags[]) const SK_OVERRIDE; |
273 virtual size_t onGetTableData(SkFontTableTag, size_t offset, | 275 virtual size_t onGetTableData(SkFontTableTag, size_t offset, |
274 size_t length, void* data) const SK_OVERRIDE; | 276 size_t length, void* data) const SK_OVERRIDE; |
275 virtual SkTypeface* onRefMatchingStyle(Style) const SK_OVERRIDE; | 277 virtual SkTypeface* onRefMatchingStyle(Style) const SK_OVERRIDE; |
276 }; | 278 }; |
277 | 279 |
278 class FontMemResourceTypeface : public LogFontTypeface { | 280 class FontMemResourceTypeface : public LogFontTypeface { |
(...skipping 1733 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2012 } | 2014 } |
2013 } | 2015 } |
2014 | 2016 |
2015 SelectObject(hdc, savefont); | 2017 SelectObject(hdc, savefont); |
2016 DeleteObject(font); | 2018 DeleteObject(font); |
2017 DeleteDC(hdc); | 2019 DeleteDC(hdc); |
2018 | 2020 |
2019 return stream; | 2021 return stream; |
2020 } | 2022 } |
2021 | 2023 |
2024 static SkUnichar next_utf8(const void** chars) { | |
2025 return SkUTF8_NextUnichar((const char**)chars); | |
2026 } | |
2027 | |
2028 static SkUnichar next_utf16(const void** chars) { | |
2029 return SkUTF16_NextUnichar((const uint16_t**)chars); | |
2030 } | |
2031 | |
2032 static SkUnichar next_utf32(const void** chars) { | |
2033 const SkUnichar** uniChars = (const SkUnichar**)chars; | |
2034 SkUnichar uni = **uniChars; | |
2035 *uniChars += 1; | |
2036 return uni; | |
2037 } | |
2038 | |
2039 typedef SkUnichar (*EncodingProc)(const void**); | |
2040 | |
2041 static EncodingProc find_encoding_proc(SkTypeface::Encoding enc) { | |
2042 static const EncodingProc gProcs[] = { | |
2043 next_utf8, next_utf16, next_utf32 | |
2044 }; | |
2045 SkASSERT((size_t)enc < SK_ARRAY_COUNT(gProcs)); | |
2046 return gProcs[enc]; | |
2047 } | |
2048 | |
2049 static uint16_t charToGlyph(HDC hdc, SkUnichar uni) { | |
2050 uint16_t index = 0; | |
2051 WCHAR c[2]; | |
2052 // TODO(ctguil): Support characters that generate more than one glyph. | |
2053 if (SkUTF16_FromUnichar(uni, (uint16_t*)c) == 1) { | |
2054 // Type1 fonts fail with uniscribe API. Use GetGlyphIndices for plane 0. | |
2055 SkAssertResult(GetGlyphIndicesW(hdc, c, 1, &index, 0)); | |
2056 } else { | |
2057 // Use uniscribe to detemine glyph index for non-BMP characters. | |
2058 // Need to add extra item to SCRIPT_ITEM to work around a bug in older | |
2059 // windows versions. https://bugzilla.mozilla.org/show_bug.cgi?id=366643 | |
2060 SCRIPT_ITEM si[2 + 1]; | |
2061 int items; | |
2062 SkAssertResult( | |
2063 SUCCEEDED(ScriptItemize(c, 2, 2, NULL, NULL, si, &items))); | |
2064 | |
2065 WORD log[2]; | |
2066 SCRIPT_VISATTR vsa; | |
2067 SCRIPT_CACHE scriptCache = NULL; | |
2068 int glyphs; | |
2069 SkAssertResult(SUCCEEDED(ScriptShape( | |
2070 hdc, &scriptCache, c, 2, 1, &si[0].a, &index, log, &vsa, &glyphs))); | |
2071 if (scriptCache) { | |
2072 ::ScriptFreeCache(&scriptCache); | |
2073 } | |
2074 } | |
2075 return index; | |
2076 } | |
2077 | |
2078 class SkAutoHDC { | |
2079 public: | |
2080 SkAutoHDC(const LOGFONT& lf) | |
2081 : fHdc(::CreateCompatibleDC(NULL)) | |
2082 , fFont(::CreateFontIndirect(&lf)) | |
2083 , fSavefont((HFONT)SelectObject(fHdc, fFont)) | |
2084 { } | |
2085 ~SkAutoHDC() { | |
2086 SelectObject(fHdc, fSavefont); | |
2087 DeleteObject(fFont); | |
2088 DeleteDC(fHdc); | |
2089 } | |
2090 operator HDC() { return fHdc; } | |
2091 private: | |
2092 HDC fHdc; | |
2093 HFONT fFont; | |
2094 HFONT fSavefont; | |
2095 }; | |
2096 | |
2097 int LogFontTypeface::onCharsToGlyphs(const void* chars, Encoding encoding, | |
2098 uint16_t glyphs[], int glyphCount) const | |
2099 { | |
2100 EncodingProc next_uni_proc = find_encoding_proc(encoding); | |
2101 | |
2102 SkAutoHDC hdc(fLogFont); | |
2103 | |
2104 if (NULL == glyphs) { | |
2105 for (int i = 0; i < glyphCount; ++i) { | |
2106 const SkUnichar c = next_uni_proc(&chars); | |
2107 UINT16 glyphIndex = charToGlyph(hdc, c); | |
2108 if (0 == glyphIndex) { | |
2109 return i; | |
2110 } | |
2111 } | |
2112 return glyphCount; | |
2113 } | |
2114 | |
2115 int first = glyphCount; | |
2116 for (int i = 0; i < glyphCount; ++i) { | |
2117 const SkUnichar c = next_uni_proc(&chars); | |
2118 UINT16 glyphIndex = charToGlyph(hdc, c); | |
2119 glyphs[i] = glyphIndex; | |
2120 if (0 == glyphIndex && i < first) { | |
2121 first = i; | |
2122 } | |
2123 } | |
2124 return first; | |
2125 } | |
2126 | |
2022 int LogFontTypeface::onCountGlyphs() const { | 2127 int LogFontTypeface::onCountGlyphs() const { |
2023 HDC hdc = ::CreateCompatibleDC(NULL); | 2128 HDC hdc = ::CreateCompatibleDC(NULL); |
2024 HFONT font = CreateFontIndirect(&fLogFont); | 2129 HFONT font = CreateFontIndirect(&fLogFont); |
2025 HFONT savefont = (HFONT)SelectObject(hdc, font); | 2130 HFONT savefont = (HFONT)SelectObject(hdc, font); |
2026 | 2131 |
2027 unsigned int glyphCount = calculateGlyphCount(hdc, fLogFont); | 2132 unsigned int glyphCount = calculateGlyphCount(hdc, fLogFont); |
2028 | 2133 |
2029 SelectObject(hdc, savefont); | 2134 SelectObject(hdc, savefont); |
2030 DeleteObject(font); | 2135 DeleteObject(font); |
2031 DeleteDC(hdc); | 2136 DeleteDC(hdc); |
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2368 SkTypeface* SkFontHost::CreateTypefaceFromStream(SkStream* stream) { | 2473 SkTypeface* SkFontHost::CreateTypefaceFromStream(SkStream* stream) { |
2369 return create_from_stream(stream); | 2474 return create_from_stream(stream); |
2370 } | 2475 } |
2371 | 2476 |
2372 #endif | 2477 #endif |
2373 | 2478 |
2374 extern SkFontMgr* SkFontMgr_New_GDI(); | 2479 extern SkFontMgr* SkFontMgr_New_GDI(); |
2375 SkFontMgr* SkFontMgr_New_GDI() { | 2480 SkFontMgr* SkFontMgr_New_GDI() { |
2376 return SkNEW(SkFontMgrGDI); | 2481 return SkNEW(SkFontMgrGDI); |
2377 } | 2482 } |
OLD | NEW |