SkFontHost_win.cpp revision 3c996f8a15e5d8fada9550d978e9b5344b81d276
1ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com 2ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com/* 3ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Copyright 2006 The Android Open Source Project 4ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * 5ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Use of this source code is governed by a BSD-style license that can be 6ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * found in the LICENSE file. 7ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com */ 8ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com 9ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com#include "SkAdvancedTypefaceMetrics.h" 10a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com#include "SkBase64.h" 111bfe01d06b896eca94c80d9af9a6bb30216b5e42bungeman@google.com#include "SkColorPriv.h" 12a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com#include "SkData.h" 13a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com#include "SkDescriptor.h" 14e70f798ebca1a66f0b568fa46065ebbad9a13b2fbungeman@google.com#include "SkFontDescriptor.h" 15a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com#include "SkFontHost.h" 16bbe50131413098bffed9186660c41f047d881596bungeman@google.com#include "SkGlyph.h" 1727f74aab32123e6f021359061149966fa4ca5a62bungeman@google.com#include "SkHRESULT.h" 1897efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com#include "SkMaskGamma.h" 197bdd614a1940935d3badeb54f7aae75d76ea830dbungeman@google.com#include "SkOTTable_maxp.h" 20a980269c2498836101146adc729ef780fb89824ebungeman@google.com#include "SkOTTable_name.h" 21a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com#include "SkOTUtils.h" 2227889877c0e3c909dd4afd7b5e7b1d58cbf61ae6reed@google.com#include "SkPath.h" 23b10b51f64dbd1cf44571a1eedb412378702d8cd4bungeman@google.com#include "SkSFNTHeader.h" 24ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com#include "SkStream.h" 25a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com#include "SkString.h" 2605a729ff90f75ac013873742ee0e4ae7e5e6e415bungeman@google.com#include "SkTemplates.h" 27ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com#include "SkThread.h" 28ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com#include "SkTypeface_win.h" 2959d2f63583512b47df579e80f1ae39c74fad5f3ereed@google.com#include "SkTypefaceCache.h" 30ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com#include "SkUtils.h" 31ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com 32a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com#include "SkTypes.h" 33a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com#include <tchar.h> 34a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com#include <usp10.h> 35a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com#include <objbase.h> 36ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com 37f210f505ffffccc15ae5e91f8ccb9763ba7fc152reed@google.comstatic void (*gEnsureLOGFONTAccessibleProc)(const LOGFONT&); 38f210f505ffffccc15ae5e91f8ccb9763ba7fc152reed@google.com 39f210f505ffffccc15ae5e91f8ccb9763ba7fc152reed@google.comvoid SkTypeface_SetEnsureLOGFONTAccessibleProc(void (*proc)(const LOGFONT&)) { 40f210f505ffffccc15ae5e91f8ccb9763ba7fc152reed@google.com gEnsureLOGFONTAccessibleProc = proc; 41f210f505ffffccc15ae5e91f8ccb9763ba7fc152reed@google.com} 42f210f505ffffccc15ae5e91f8ccb9763ba7fc152reed@google.com 43055180cb9c47c87e5ee8c9fa6d3f6a6079ad6f35reed@google.comstatic void call_ensure_accessible(const LOGFONT& lf) { 44055180cb9c47c87e5ee8c9fa6d3f6a6079ad6f35reed@google.com if (gEnsureLOGFONTAccessibleProc) { 45055180cb9c47c87e5ee8c9fa6d3f6a6079ad6f35reed@google.com gEnsureLOGFONTAccessibleProc(lf); 46055180cb9c47c87e5ee8c9fa6d3f6a6079ad6f35reed@google.com } 47055180cb9c47c87e5ee8c9fa6d3f6a6079ad6f35reed@google.com} 48055180cb9c47c87e5ee8c9fa6d3f6a6079ad6f35reed@google.com 49055180cb9c47c87e5ee8c9fa6d3f6a6079ad6f35reed@google.com/////////////////////////////////////////////////////////////////////////////// 50055180cb9c47c87e5ee8c9fa6d3f6a6079ad6f35reed@google.com 516f5df48c1d07295b75c1955a69142fb5e66b8647reed@google.com// always packed xxRRGGBB 526f5df48c1d07295b75c1955a69142fb5e66b8647reed@google.comtypedef uint32_t SkGdiRGB; 536f5df48c1d07295b75c1955a69142fb5e66b8647reed@google.com 54a767fa06ca28be9df1ff6e08a299e0bec839a2dcreed@google.com// define this in your Makefile or .gyp to enforce AA requests 55a767fa06ca28be9df1ff6e08a299e0bec839a2dcreed@google.com// which GDI ignores at small sizes. This flag guarantees AA 56a767fa06ca28be9df1ff6e08a299e0bec839a2dcreed@google.com// for rotated text, regardless of GDI's notions. 57a767fa06ca28be9df1ff6e08a299e0bec839a2dcreed@google.com//#define SK_ENFORCE_ROTATED_TEXT_AA_ON_WINDOWS 58a767fa06ca28be9df1ff6e08a299e0bec839a2dcreed@google.com 5982a34d83f646d069ef2d1d7b649d0a0b1829d62freed@google.comstatic bool isLCD(const SkScalerContext::Rec& rec) { 6082a34d83f646d069ef2d1d7b649d0a0b1829d62freed@google.com return SkMask::kLCD16_Format == rec.fMaskFormat || 6182a34d83f646d069ef2d1d7b649d0a0b1829d62freed@google.com SkMask::kLCD32_Format == rec.fMaskFormat; 6282a34d83f646d069ef2d1d7b649d0a0b1829d62freed@google.com} 6382a34d83f646d069ef2d1d7b649d0a0b1829d62freed@google.com 64a767fa06ca28be9df1ff6e08a299e0bec839a2dcreed@google.comstatic bool bothZero(SkScalar a, SkScalar b) { 65a767fa06ca28be9df1ff6e08a299e0bec839a2dcreed@google.com return 0 == a && 0 == b; 66a767fa06ca28be9df1ff6e08a299e0bec839a2dcreed@google.com} 67a767fa06ca28be9df1ff6e08a299e0bec839a2dcreed@google.com 68a767fa06ca28be9df1ff6e08a299e0bec839a2dcreed@google.com// returns false if there is any non-90-rotation or skew 69a767fa06ca28be9df1ff6e08a299e0bec839a2dcreed@google.comstatic bool isAxisAligned(const SkScalerContext::Rec& rec) { 70a767fa06ca28be9df1ff6e08a299e0bec839a2dcreed@google.com return 0 == rec.fPreSkewX && 71a767fa06ca28be9df1ff6e08a299e0bec839a2dcreed@google.com (bothZero(rec.fPost2x2[0][1], rec.fPost2x2[1][0]) || 72a767fa06ca28be9df1ff6e08a299e0bec839a2dcreed@google.com bothZero(rec.fPost2x2[0][0], rec.fPost2x2[1][1])); 73a767fa06ca28be9df1ff6e08a299e0bec839a2dcreed@google.com} 74a767fa06ca28be9df1ff6e08a299e0bec839a2dcreed@google.com 75a767fa06ca28be9df1ff6e08a299e0bec839a2dcreed@google.comstatic bool needToRenderWithSkia(const SkScalerContext::Rec& rec) { 76a767fa06ca28be9df1ff6e08a299e0bec839a2dcreed@google.com#ifdef SK_ENFORCE_ROTATED_TEXT_AA_ON_WINDOWS 77a767fa06ca28be9df1ff6e08a299e0bec839a2dcreed@google.com // What we really want to catch is when GDI will ignore the AA request and give 78a767fa06ca28be9df1ff6e08a299e0bec839a2dcreed@google.com // us BW instead. Smallish rotated text is one heuristic, so this code is just 79a767fa06ca28be9df1ff6e08a299e0bec839a2dcreed@google.com // an approximation. We shouldn't need to do this for larger sizes, but at those 80a767fa06ca28be9df1ff6e08a299e0bec839a2dcreed@google.com // sizes, the quality difference gets less and less between our general 81a767fa06ca28be9df1ff6e08a299e0bec839a2dcreed@google.com // scanconverter and GDI's. 82a767fa06ca28be9df1ff6e08a299e0bec839a2dcreed@google.com if (SkMask::kA8_Format == rec.fMaskFormat && !isAxisAligned(rec)) { 83a767fa06ca28be9df1ff6e08a299e0bec839a2dcreed@google.com return true; 84a767fa06ca28be9df1ff6e08a299e0bec839a2dcreed@google.com } 85a767fa06ca28be9df1ff6e08a299e0bec839a2dcreed@google.com#endif 860abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com return rec.getHinting() == SkPaint::kNo_Hinting || rec.getHinting() == SkPaint::kSlight_Hinting; 87a767fa06ca28be9df1ff6e08a299e0bec839a2dcreed@google.com} 88a767fa06ca28be9df1ff6e08a299e0bec839a2dcreed@google.com 89ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.comusing namespace skia_advanced_typeface_metrics_utils; 90ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com 91a65a681d43a8e9f5d8726a389832e957b07ee16breed@google.comstatic void tchar_to_skstring(const TCHAR t[], SkString* s) { 92484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com#ifdef UNICODE 93484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com size_t sSize = WideCharToMultiByte(CP_UTF8, 0, t, -1, NULL, 0, NULL, NULL); 94484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com s->resize(sSize); 95484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com WideCharToMultiByte(CP_UTF8, 0, t, -1, s->writable_str(), sSize, NULL, NULL); 96484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com#else 97484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com s->set(t); 98484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com#endif 99484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com} 100484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com 101a980269c2498836101146adc729ef780fb89824ebungeman@google.comstatic void dcfontname_to_skstring(HDC deviceContext, const LOGFONT& lf, SkString* familyName) { 102a980269c2498836101146adc729ef780fb89824ebungeman@google.com int fontNameLen; //length of fontName in TCHARS. 103a980269c2498836101146adc729ef780fb89824ebungeman@google.com if (0 == (fontNameLen = GetTextFace(deviceContext, 0, NULL))) { 104a980269c2498836101146adc729ef780fb89824ebungeman@google.com call_ensure_accessible(lf); 105a980269c2498836101146adc729ef780fb89824ebungeman@google.com if (0 == (fontNameLen = GetTextFace(deviceContext, 0, NULL))) { 106a980269c2498836101146adc729ef780fb89824ebungeman@google.com fontNameLen = 0; 107a980269c2498836101146adc729ef780fb89824ebungeman@google.com } 108a980269c2498836101146adc729ef780fb89824ebungeman@google.com } 109a980269c2498836101146adc729ef780fb89824ebungeman@google.com 110a980269c2498836101146adc729ef780fb89824ebungeman@google.com SkAutoSTArray<LF_FULLFACESIZE, TCHAR> fontName(fontNameLen+1); 111a980269c2498836101146adc729ef780fb89824ebungeman@google.com if (0 == GetTextFace(deviceContext, fontNameLen, fontName.get())) { 112a980269c2498836101146adc729ef780fb89824ebungeman@google.com call_ensure_accessible(lf); 113a980269c2498836101146adc729ef780fb89824ebungeman@google.com if (0 == GetTextFace(deviceContext, fontNameLen, fontName.get())) { 114a980269c2498836101146adc729ef780fb89824ebungeman@google.com fontName[0] = 0; 115a980269c2498836101146adc729ef780fb89824ebungeman@google.com } 116a980269c2498836101146adc729ef780fb89824ebungeman@google.com } 117a980269c2498836101146adc729ef780fb89824ebungeman@google.com 118a980269c2498836101146adc729ef780fb89824ebungeman@google.com tchar_to_skstring(fontName.get(), familyName); 119a980269c2498836101146adc729ef780fb89824ebungeman@google.com} 120a980269c2498836101146adc729ef780fb89824ebungeman@google.com 121ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.comstatic void make_canonical(LOGFONT* lf) { 12253cbb0baac09e60e7633c15301a29a83afb1a8debungeman@google.com lf->lfHeight = -64; 12359d2f63583512b47df579e80f1ae39c74fad5f3ereed@google.com lf->lfQuality = CLEARTYPE_QUALITY;//PROOF_QUALITY; 12459d2f63583512b47df579e80f1ae39c74fad5f3ereed@google.com lf->lfCharSet = DEFAULT_CHARSET; 12582a34d83f646d069ef2d1d7b649d0a0b1829d62freed@google.com// lf->lfClipPrecision = 64; 12659d2f63583512b47df579e80f1ae39c74fad5f3ereed@google.com} 12759d2f63583512b47df579e80f1ae39c74fad5f3ereed@google.com 12890d812b77ab025d5fd01dab904287f5c5bf56228bungeman@google.comstatic SkTypeface::Style get_style(const LOGFONT& lf) { 12959d2f63583512b47df579e80f1ae39c74fad5f3ereed@google.com unsigned style = 0; 13059d2f63583512b47df579e80f1ae39c74fad5f3ereed@google.com if (lf.lfWeight >= FW_BOLD) { 13159d2f63583512b47df579e80f1ae39c74fad5f3ereed@google.com style |= SkTypeface::kBold; 13259d2f63583512b47df579e80f1ae39c74fad5f3ereed@google.com } 13359d2f63583512b47df579e80f1ae39c74fad5f3ereed@google.com if (lf.lfItalic) { 13459d2f63583512b47df579e80f1ae39c74fad5f3ereed@google.com style |= SkTypeface::kItalic; 13559d2f63583512b47df579e80f1ae39c74fad5f3ereed@google.com } 13690d812b77ab025d5fd01dab904287f5c5bf56228bungeman@google.com return static_cast<SkTypeface::Style>(style); 13759d2f63583512b47df579e80f1ae39c74fad5f3ereed@google.com} 13859d2f63583512b47df579e80f1ae39c74fad5f3ereed@google.com 13959d2f63583512b47df579e80f1ae39c74fad5f3ereed@google.comstatic void setStyle(LOGFONT* lf, SkTypeface::Style style) { 14059d2f63583512b47df579e80f1ae39c74fad5f3ereed@google.com lf->lfWeight = (style & SkTypeface::kBold) != 0 ? FW_BOLD : FW_NORMAL ; 14159d2f63583512b47df579e80f1ae39c74fad5f3ereed@google.com lf->lfItalic = ((style & SkTypeface::kItalic) != 0); 142ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com} 143ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com 144ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.comstatic inline FIXED SkFixedToFIXED(SkFixed x) { 145ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com return *(FIXED*)(&x); 146ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com} 147a0319f6d071bb8298e56ace043ea6c623fb358f7bungeman@google.comstatic inline SkFixed SkFIXEDToFixed(FIXED x) { 148a0319f6d071bb8298e56ace043ea6c623fb358f7bungeman@google.com return *(SkFixed*)(&x); 149a0319f6d071bb8298e56ace043ea6c623fb358f7bungeman@google.com} 150ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com 151ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.comstatic inline FIXED SkScalarToFIXED(SkScalar x) { 152ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com return SkFixedToFIXED(SkScalarToFixed(x)); 153ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com} 154ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com 1557bdd614a1940935d3badeb54f7aae75d76ea830dbungeman@google.comstatic unsigned calculateGlyphCount(HDC hdc, const LOGFONT& lf) { 1567bdd614a1940935d3badeb54f7aae75d76ea830dbungeman@google.com TEXTMETRIC textMetric; 1577bdd614a1940935d3badeb54f7aae75d76ea830dbungeman@google.com if (0 == GetTextMetrics(hdc, &textMetric)) { 1587bdd614a1940935d3badeb54f7aae75d76ea830dbungeman@google.com textMetric.tmPitchAndFamily = TMPF_VECTOR; 1597bdd614a1940935d3badeb54f7aae75d76ea830dbungeman@google.com call_ensure_accessible(lf); 1607bdd614a1940935d3badeb54f7aae75d76ea830dbungeman@google.com GetTextMetrics(hdc, &textMetric); 1617bdd614a1940935d3badeb54f7aae75d76ea830dbungeman@google.com } 1627bdd614a1940935d3badeb54f7aae75d76ea830dbungeman@google.com 1637bdd614a1940935d3badeb54f7aae75d76ea830dbungeman@google.com if (!(textMetric.tmPitchAndFamily & TMPF_VECTOR)) { 1647bdd614a1940935d3badeb54f7aae75d76ea830dbungeman@google.com return textMetric.tmLastChar; 1657bdd614a1940935d3badeb54f7aae75d76ea830dbungeman@google.com } 1667bdd614a1940935d3badeb54f7aae75d76ea830dbungeman@google.com 167ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com // The 'maxp' table stores the number of glyphs at offset 4, in 2 bytes. 168ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com uint16_t glyphs; 1697bdd614a1940935d3badeb54f7aae75d76ea830dbungeman@google.com if (GDI_ERROR != GetFontData(hdc, SkOTTableMaximumProfile::TAG, 4, &glyphs, sizeof(glyphs))) { 170ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com return SkEndian_SwapBE16(glyphs); 171ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com } 1725aa937b300475c956bfad0c34a6daa71d166f6factguil@chromium.org 173ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com // Binary search for glyph count. 174ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com static const MAT2 mat2 = {{0, 1}, {0, 0}, {0, 0}, {0, 1}}; 175ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com int32_t max = SK_MaxU16 + 1; 176ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com int32_t min = 0; 177ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com GLYPHMETRICS gm; 178ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com while (min < max) { 179ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com int32_t mid = min + ((max - min) / 2); 180ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com if (GetGlyphOutlineW(hdc, mid, GGO_METRICS | GGO_GLYPH_INDEX, &gm, 0, 181ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com NULL, &mat2) == GDI_ERROR) { 182ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com max = mid; 183ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com } else { 184ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com min = mid + 1; 185ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com } 186ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com } 187ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com SkASSERT(min == max); 188ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com return min; 189ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com} 190ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com 1917bdd614a1940935d3badeb54f7aae75d76ea830dbungeman@google.comstatic unsigned calculateUPEM(HDC hdc, const LOGFONT& lf) { 1927bdd614a1940935d3badeb54f7aae75d76ea830dbungeman@google.com TEXTMETRIC textMetric; 1937bdd614a1940935d3badeb54f7aae75d76ea830dbungeman@google.com if (0 == GetTextMetrics(hdc, &textMetric)) { 1947bdd614a1940935d3badeb54f7aae75d76ea830dbungeman@google.com textMetric.tmPitchAndFamily = TMPF_VECTOR; 1957bdd614a1940935d3badeb54f7aae75d76ea830dbungeman@google.com call_ensure_accessible(lf); 1967bdd614a1940935d3badeb54f7aae75d76ea830dbungeman@google.com GetTextMetrics(hdc, &textMetric); 1977bdd614a1940935d3badeb54f7aae75d76ea830dbungeman@google.com } 1987bdd614a1940935d3badeb54f7aae75d76ea830dbungeman@google.com 1997bdd614a1940935d3badeb54f7aae75d76ea830dbungeman@google.com if (!(textMetric.tmPitchAndFamily & TMPF_VECTOR)) { 2007bdd614a1940935d3badeb54f7aae75d76ea830dbungeman@google.com return textMetric.tmMaxCharWidth; 2017bdd614a1940935d3badeb54f7aae75d76ea830dbungeman@google.com } 2027bdd614a1940935d3badeb54f7aae75d76ea830dbungeman@google.com 2037bdd614a1940935d3badeb54f7aae75d76ea830dbungeman@google.com OUTLINETEXTMETRIC otm; 2047bdd614a1940935d3badeb54f7aae75d76ea830dbungeman@google.com unsigned int otmRet = GetOutlineTextMetrics(hdc, sizeof(otm), &otm); 2057bdd614a1940935d3badeb54f7aae75d76ea830dbungeman@google.com if (0 == otmRet) { 2067bdd614a1940935d3badeb54f7aae75d76ea830dbungeman@google.com call_ensure_accessible(lf); 2077bdd614a1940935d3badeb54f7aae75d76ea830dbungeman@google.com otmRet = GetOutlineTextMetrics(hdc, sizeof(otm), &otm); 2087bdd614a1940935d3badeb54f7aae75d76ea830dbungeman@google.com } 2097bdd614a1940935d3badeb54f7aae75d76ea830dbungeman@google.com 2107bdd614a1940935d3badeb54f7aae75d76ea830dbungeman@google.com return (0 == otmRet) ? 0 : otm.otmEMSquare; 2117bdd614a1940935d3badeb54f7aae75d76ea830dbungeman@google.com} 2127bdd614a1940935d3badeb54f7aae75d76ea830dbungeman@google.com 213ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.comclass LogFontTypeface : public SkTypeface { 214ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.compublic: 215cb1bbb375aa4fdd099dc60302ca1712f04607782bungeman@google.com LogFontTypeface(SkTypeface::Style style, SkFontID fontID, const LOGFONT& lf, bool serializeAsStream = false) : 216cb1bbb375aa4fdd099dc60302ca1712f04607782bungeman@google.com SkTypeface(style, fontID, false), fLogFont(lf), fSerializeAsStream(serializeAsStream) { 217cb1bbb375aa4fdd099dc60302ca1712f04607782bungeman@google.com 218cb1bbb375aa4fdd099dc60302ca1712f04607782bungeman@google.com // If the font has cubic outlines, it will not be rendered with ClearType. 219cb1bbb375aa4fdd099dc60302ca1712f04607782bungeman@google.com HFONT font = CreateFontIndirect(&lf); 220cb1bbb375aa4fdd099dc60302ca1712f04607782bungeman@google.com 221cb1bbb375aa4fdd099dc60302ca1712f04607782bungeman@google.com HDC deviceContext = ::CreateCompatibleDC(NULL); 222cb1bbb375aa4fdd099dc60302ca1712f04607782bungeman@google.com HFONT savefont = (HFONT)SelectObject(deviceContext, font); 223cb1bbb375aa4fdd099dc60302ca1712f04607782bungeman@google.com 224cb1bbb375aa4fdd099dc60302ca1712f04607782bungeman@google.com TEXTMETRIC textMetric; 225cb1bbb375aa4fdd099dc60302ca1712f04607782bungeman@google.com if (0 == GetTextMetrics(deviceContext, &textMetric)) { 226055180cb9c47c87e5ee8c9fa6d3f6a6079ad6f35reed@google.com call_ensure_accessible(lf); 227cb1bbb375aa4fdd099dc60302ca1712f04607782bungeman@google.com if (0 == GetTextMetrics(deviceContext, &textMetric)) { 228cb1bbb375aa4fdd099dc60302ca1712f04607782bungeman@google.com textMetric.tmPitchAndFamily = TMPF_TRUETYPE; 229cb1bbb375aa4fdd099dc60302ca1712f04607782bungeman@google.com } 230cb1bbb375aa4fdd099dc60302ca1712f04607782bungeman@google.com } 231cb1bbb375aa4fdd099dc60302ca1712f04607782bungeman@google.com if (deviceContext) { 232cb1bbb375aa4fdd099dc60302ca1712f04607782bungeman@google.com ::SelectObject(deviceContext, savefont); 233cb1bbb375aa4fdd099dc60302ca1712f04607782bungeman@google.com ::DeleteDC(deviceContext); 234cb1bbb375aa4fdd099dc60302ca1712f04607782bungeman@google.com } 235cb1bbb375aa4fdd099dc60302ca1712f04607782bungeman@google.com if (font) { 236cb1bbb375aa4fdd099dc60302ca1712f04607782bungeman@google.com ::DeleteObject(font); 237cb1bbb375aa4fdd099dc60302ca1712f04607782bungeman@google.com } 238cb1bbb375aa4fdd099dc60302ca1712f04607782bungeman@google.com 239fe74765f0d302669ae49e68074492bdfe0ce6e6fbungeman@google.com // The fixed pitch bit is set if the font is *not* fixed pitch. 240fe74765f0d302669ae49e68074492bdfe0ce6e6fbungeman@google.com this->setIsFixedPitch((textMetric.tmPitchAndFamily & TMPF_FIXED_PITCH) == 0); 241fe74765f0d302669ae49e68074492bdfe0ce6e6fbungeman@google.com 242cb1bbb375aa4fdd099dc60302ca1712f04607782bungeman@google.com // Used a logfont on a memory context, should never get a device font. 243cb1bbb375aa4fdd099dc60302ca1712f04607782bungeman@google.com // Therefore all TMPF_DEVICE will be PostScript (cubic) fonts. 244cb1bbb375aa4fdd099dc60302ca1712f04607782bungeman@google.com fCanBeLCD = !((textMetric.tmPitchAndFamily & TMPF_VECTOR) && 245cb1bbb375aa4fdd099dc60302ca1712f04607782bungeman@google.com (textMetric.tmPitchAndFamily & TMPF_DEVICE)); 246cb1bbb375aa4fdd099dc60302ca1712f04607782bungeman@google.com } 247ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com 24859d2f63583512b47df579e80f1ae39c74fad5f3ereed@google.com LOGFONT fLogFont; 249e70f798ebca1a66f0b568fa46065ebbad9a13b2fbungeman@google.com bool fSerializeAsStream; 250cb1bbb375aa4fdd099dc60302ca1712f04607782bungeman@google.com bool fCanBeLCD; 251ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com 25259d2f63583512b47df579e80f1ae39c74fad5f3ereed@google.com static LogFontTypeface* Create(const LOGFONT& lf) { 25390d812b77ab025d5fd01dab904287f5c5bf56228bungeman@google.com SkTypeface::Style style = get_style(lf); 25459d2f63583512b47df579e80f1ae39c74fad5f3ereed@google.com SkFontID fontID = SkTypefaceCache::NewFontID(); 25559d2f63583512b47df579e80f1ae39c74fad5f3ereed@google.com return new LogFontTypeface(style, fontID, lf); 256ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com } 2570da48618a758ef46c2174bdc1eaeb6dd8a693a2ereed@google.com 258055180cb9c47c87e5ee8c9fa6d3f6a6079ad6f35reed@google.com static void EnsureAccessible(const SkTypeface* face) { 259055180cb9c47c87e5ee8c9fa6d3f6a6079ad6f35reed@google.com call_ensure_accessible(static_cast<const LogFontTypeface*>(face)->fLogFont); 260055180cb9c47c87e5ee8c9fa6d3f6a6079ad6f35reed@google.com } 261055180cb9c47c87e5ee8c9fa6d3f6a6079ad6f35reed@google.com 2620da48618a758ef46c2174bdc1eaeb6dd8a693a2ereed@google.comprotected: 2630042b9c2a2e6fe954cdfbcd5a5b7449cdf41a4c3reed@google.com virtual SkStream* onOpenStream(int* ttcIndex) const SK_OVERRIDE; 2640da48618a758ef46c2174bdc1eaeb6dd8a693a2ereed@google.com virtual SkScalerContext* onCreateScalerContext(const SkDescriptor*) const SK_OVERRIDE; 2650da48618a758ef46c2174bdc1eaeb6dd8a693a2ereed@google.com virtual void onFilterRec(SkScalerContextRec*) const SK_OVERRIDE; 2662689f615e364dc48ad73826564f5b13d2329179dreed@google.com virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics( 2672689f615e364dc48ad73826564f5b13d2329179dreed@google.com SkAdvancedTypefaceMetrics::PerGlyphInfo, 2682689f615e364dc48ad73826564f5b13d2329179dreed@google.com const uint32_t*, uint32_t) const SK_OVERRIDE; 2695526ede94a2fc58bcf6b578b12a29f6addad776dreed@google.com virtual void onGetFontDescriptor(SkFontDescriptor*, bool*) const SK_OVERRIDE; 2703c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com virtual int onCharsToGlyphs(const void* chars, Encoding encoding, 2713c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com uint16_t glyphs[], int glyphCount) const SK_OVERRIDE; 2727bdd614a1940935d3badeb54f7aae75d76ea830dbungeman@google.com virtual int onCountGlyphs() const SK_OVERRIDE; 2737bdd614a1940935d3badeb54f7aae75d76ea830dbungeman@google.com virtual int onGetUPEM() const SK_OVERRIDE; 274839702b61934914118ec557dd641be322eba3b5fbungeman@google.com virtual SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const SK_OVERRIDE; 275b10b51f64dbd1cf44571a1eedb412378702d8cd4bungeman@google.com virtual int onGetTableTags(SkFontTableTag tags[]) const SK_OVERRIDE; 276b10b51f64dbd1cf44571a1eedb412378702d8cd4bungeman@google.com virtual size_t onGetTableData(SkFontTableTag, size_t offset, 277b10b51f64dbd1cf44571a1eedb412378702d8cd4bungeman@google.com size_t length, void* data) const SK_OVERRIDE; 27830ddd615c447fed73286151b463af20d309c85f1reed@google.com virtual SkTypeface* onRefMatchingStyle(Style) const SK_OVERRIDE; 279ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com}; 280ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com 281a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.comclass FontMemResourceTypeface : public LogFontTypeface { 282a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.compublic: 283a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com /** 284a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com * Takes ownership of fontMemResource. 285a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com */ 286a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com FontMemResourceTypeface(SkTypeface::Style style, SkFontID fontID, const LOGFONT& lf, HANDLE fontMemResource) : 287cb1bbb375aa4fdd099dc60302ca1712f04607782bungeman@google.com LogFontTypeface(style, fontID, lf, true), fFontMemResource(fontMemResource) { 288e70f798ebca1a66f0b568fa46065ebbad9a13b2fbungeman@google.com } 289a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com 290a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com HANDLE fFontMemResource; 291a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com 292a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com /** 293a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com * The created FontMemResourceTypeface takes ownership of fontMemResource. 294a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com */ 295a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com static FontMemResourceTypeface* Create(const LOGFONT& lf, HANDLE fontMemResource) { 296a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com SkTypeface::Style style = get_style(lf); 297a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com SkFontID fontID = SkTypefaceCache::NewFontID(); 298a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com return new FontMemResourceTypeface(style, fontID, lf, fontMemResource); 299a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com } 300a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com 301a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.comprotected: 302a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com virtual void weak_dispose() const SK_OVERRIDE { 303a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com RemoveFontMemResourceEx(fFontMemResource); 304a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com //SkTypefaceCache::Remove(this); 305a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com INHERITED::weak_dispose(); 306a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com } 307a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com 308a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.comprivate: 309a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com typedef LogFontTypeface INHERITED; 310a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com}; 311a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com 312ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.comstatic const LOGFONT& get_default_font() { 313ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com static LOGFONT gDefaultFont; 314ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com return gDefaultFont; 315ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com} 316ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com 31759d2f63583512b47df579e80f1ae39c74fad5f3ereed@google.comstatic bool FindByLogFont(SkTypeface* face, SkTypeface::Style requestedStyle, void* ctx) { 318a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com LogFontTypeface* lface = static_cast<LogFontTypeface*>(face); 31959d2f63583512b47df579e80f1ae39c74fad5f3ereed@google.com const LOGFONT* lf = reinterpret_cast<const LOGFONT*>(ctx); 320ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com 321a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com return lface && 322a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com get_style(lface->fLogFont) == requestedStyle && 32359d2f63583512b47df579e80f1ae39c74fad5f3ereed@google.com !memcmp(&lface->fLogFont, lf, sizeof(LOGFONT)); 32459d2f63583512b47df579e80f1ae39c74fad5f3ereed@google.com} 32559d2f63583512b47df579e80f1ae39c74fad5f3ereed@google.com 32659d2f63583512b47df579e80f1ae39c74fad5f3ereed@google.com/** 32759d2f63583512b47df579e80f1ae39c74fad5f3ereed@google.com * This guy is public. It first searches the cache, and if a match is not found, 32859d2f63583512b47df579e80f1ae39c74fad5f3ereed@google.com * it creates a new face. 32959d2f63583512b47df579e80f1ae39c74fad5f3ereed@google.com */ 33059d2f63583512b47df579e80f1ae39c74fad5f3ereed@google.comSkTypeface* SkCreateTypefaceFromLOGFONT(const LOGFONT& origLF) { 33159d2f63583512b47df579e80f1ae39c74fad5f3ereed@google.com LOGFONT lf = origLF; 33259d2f63583512b47df579e80f1ae39c74fad5f3ereed@google.com make_canonical(&lf); 333ee51d1a6e43615ae640410013c36d2d9873e6aa5bungeman@google.com SkTypeface* face = SkTypefaceCache::FindByProcAndRef(FindByLogFont, &lf); 334ee51d1a6e43615ae640410013c36d2d9873e6aa5bungeman@google.com if (NULL == face) { 33559d2f63583512b47df579e80f1ae39c74fad5f3ereed@google.com face = LogFontTypeface::Create(lf); 33690d812b77ab025d5fd01dab904287f5c5bf56228bungeman@google.com SkTypefaceCache::Add(face, get_style(lf)); 33759d2f63583512b47df579e80f1ae39c74fad5f3ereed@google.com } 33859d2f63583512b47df579e80f1ae39c74fad5f3ereed@google.com return face; 339ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com} 340ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com 341db77a6a9a9bef7033aca9dffa99d52be1f51f8d9reed@google.com/** 342a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com * The created SkTypeface takes ownership of fontMemResource. 343a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com */ 344a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.comSkTypeface* SkCreateFontMemResourceTypefaceFromLOGFONT(const LOGFONT& origLF, HANDLE fontMemResource) { 345a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com LOGFONT lf = origLF; 346a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com make_canonical(&lf); 347a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com FontMemResourceTypeface* face = FontMemResourceTypeface::Create(lf, fontMemResource); 348a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com SkTypefaceCache::Add(face, get_style(lf), false); 349a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com return face; 350a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com} 351a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com 352a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com/** 353db77a6a9a9bef7033aca9dffa99d52be1f51f8d9reed@google.com * This guy is public 354db77a6a9a9bef7033aca9dffa99d52be1f51f8d9reed@google.com */ 355db77a6a9a9bef7033aca9dffa99d52be1f51f8d9reed@google.comvoid SkLOGFONTFromTypeface(const SkTypeface* face, LOGFONT* lf) { 356db77a6a9a9bef7033aca9dffa99d52be1f51f8d9reed@google.com if (NULL == face) { 357db77a6a9a9bef7033aca9dffa99d52be1f51f8d9reed@google.com *lf = get_default_font(); 358db77a6a9a9bef7033aca9dffa99d52be1f51f8d9reed@google.com } else { 359a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com *lf = static_cast<const LogFontTypeface*>(face)->fLogFont; 360db77a6a9a9bef7033aca9dffa99d52be1f51f8d9reed@google.com } 361db77a6a9a9bef7033aca9dffa99d52be1f51f8d9reed@google.com} 362db77a6a9a9bef7033aca9dffa99d52be1f51f8d9reed@google.com 3636744d498fcbbbcf503ec80c4d43dd8f118a88597vandebo@chromium.org// Construct Glyph to Unicode table. 3646744d498fcbbbcf503ec80c4d43dd8f118a88597vandebo@chromium.org// Unicode code points that require conjugate pairs in utf16 are not 3656744d498fcbbbcf503ec80c4d43dd8f118a88597vandebo@chromium.org// supported. 3666744d498fcbbbcf503ec80c4d43dd8f118a88597vandebo@chromium.org// TODO(arthurhsu): Add support for conjugate pairs. It looks like that may 3676744d498fcbbbcf503ec80c4d43dd8f118a88597vandebo@chromium.org// require parsing the TTF cmap table (platform 4, encoding 12) directly instead 3686744d498fcbbbcf503ec80c4d43dd8f118a88597vandebo@chromium.org// of calling GetFontUnicodeRange(). 3696744d498fcbbbcf503ec80c4d43dd8f118a88597vandebo@chromium.orgstatic void populate_glyph_to_unicode(HDC fontHdc, const unsigned glyphCount, 3706744d498fcbbbcf503ec80c4d43dd8f118a88597vandebo@chromium.org SkTDArray<SkUnichar>* glyphToUnicode) { 3716744d498fcbbbcf503ec80c4d43dd8f118a88597vandebo@chromium.org DWORD glyphSetBufferSize = GetFontUnicodeRanges(fontHdc, NULL); 3726744d498fcbbbcf503ec80c4d43dd8f118a88597vandebo@chromium.org if (!glyphSetBufferSize) { 3736744d498fcbbbcf503ec80c4d43dd8f118a88597vandebo@chromium.org return; 3746744d498fcbbbcf503ec80c4d43dd8f118a88597vandebo@chromium.org } 3756744d498fcbbbcf503ec80c4d43dd8f118a88597vandebo@chromium.org 3766744d498fcbbbcf503ec80c4d43dd8f118a88597vandebo@chromium.org SkAutoTDeleteArray<BYTE> glyphSetBuffer(new BYTE[glyphSetBufferSize]); 3776744d498fcbbbcf503ec80c4d43dd8f118a88597vandebo@chromium.org GLYPHSET* glyphSet = 3786744d498fcbbbcf503ec80c4d43dd8f118a88597vandebo@chromium.org reinterpret_cast<LPGLYPHSET>(glyphSetBuffer.get()); 3796744d498fcbbbcf503ec80c4d43dd8f118a88597vandebo@chromium.org if (GetFontUnicodeRanges(fontHdc, glyphSet) != glyphSetBufferSize) { 3806744d498fcbbbcf503ec80c4d43dd8f118a88597vandebo@chromium.org return; 3816744d498fcbbbcf503ec80c4d43dd8f118a88597vandebo@chromium.org } 3826744d498fcbbbcf503ec80c4d43dd8f118a88597vandebo@chromium.org 3836744d498fcbbbcf503ec80c4d43dd8f118a88597vandebo@chromium.org glyphToUnicode->setCount(glyphCount); 3846744d498fcbbbcf503ec80c4d43dd8f118a88597vandebo@chromium.org memset(glyphToUnicode->begin(), 0, glyphCount * sizeof(SkUnichar)); 3856744d498fcbbbcf503ec80c4d43dd8f118a88597vandebo@chromium.org for (DWORD i = 0; i < glyphSet->cRanges; ++i) { 3866744d498fcbbbcf503ec80c4d43dd8f118a88597vandebo@chromium.org // There is no guarantee that within a Unicode range, the corresponding 3876744d498fcbbbcf503ec80c4d43dd8f118a88597vandebo@chromium.org // glyph id in a font file are continuous. So, even if we have ranges, 3886744d498fcbbbcf503ec80c4d43dd8f118a88597vandebo@chromium.org // we can't just use the first and last entry of the range to compute 3896744d498fcbbbcf503ec80c4d43dd8f118a88597vandebo@chromium.org // result. We need to enumerate them one by one. 3906744d498fcbbbcf503ec80c4d43dd8f118a88597vandebo@chromium.org int count = glyphSet->ranges[i].cGlyphs; 3916744d498fcbbbcf503ec80c4d43dd8f118a88597vandebo@chromium.org SkAutoTArray<WCHAR> chars(count + 1); 3926744d498fcbbbcf503ec80c4d43dd8f118a88597vandebo@chromium.org chars[count] = 0; // termintate string 3936744d498fcbbbcf503ec80c4d43dd8f118a88597vandebo@chromium.org SkAutoTArray<WORD> glyph(count); 3946744d498fcbbbcf503ec80c4d43dd8f118a88597vandebo@chromium.org for (USHORT j = 0; j < count; ++j) { 3956744d498fcbbbcf503ec80c4d43dd8f118a88597vandebo@chromium.org chars[j] = glyphSet->ranges[i].wcLow + j; 3966744d498fcbbbcf503ec80c4d43dd8f118a88597vandebo@chromium.org } 3976744d498fcbbbcf503ec80c4d43dd8f118a88597vandebo@chromium.org GetGlyphIndicesW(fontHdc, chars.get(), count, glyph.get(), 3986744d498fcbbbcf503ec80c4d43dd8f118a88597vandebo@chromium.org GGI_MARK_NONEXISTING_GLYPHS); 3996744d498fcbbbcf503ec80c4d43dd8f118a88597vandebo@chromium.org // If the glyph ID is valid, and the glyph is not mapped, then we will 4006744d498fcbbbcf503ec80c4d43dd8f118a88597vandebo@chromium.org // fill in the char id into the vector. If the glyph is mapped already, 4016744d498fcbbbcf503ec80c4d43dd8f118a88597vandebo@chromium.org // skip it. 4026744d498fcbbbcf503ec80c4d43dd8f118a88597vandebo@chromium.org // TODO(arthurhsu): better improve this. e.g. Get all used char ids from 4036744d498fcbbbcf503ec80c4d43dd8f118a88597vandebo@chromium.org // font cache, then generate this mapping table from there. It's 4046744d498fcbbbcf503ec80c4d43dd8f118a88597vandebo@chromium.org // unlikely to have collisions since glyph reuse happens mostly for 4056744d498fcbbbcf503ec80c4d43dd8f118a88597vandebo@chromium.org // different Unicode pages. 4066744d498fcbbbcf503ec80c4d43dd8f118a88597vandebo@chromium.org for (USHORT j = 0; j < count; ++j) { 4076744d498fcbbbcf503ec80c4d43dd8f118a88597vandebo@chromium.org if (glyph[j] != 0xffff && glyph[j] < glyphCount && 4086744d498fcbbbcf503ec80c4d43dd8f118a88597vandebo@chromium.org (*glyphToUnicode)[glyph[j]] == 0) { 4096744d498fcbbbcf503ec80c4d43dd8f118a88597vandebo@chromium.org (*glyphToUnicode)[glyph[j]] = chars[j]; 4106744d498fcbbbcf503ec80c4d43dd8f118a88597vandebo@chromium.org } 4116744d498fcbbbcf503ec80c4d43dd8f118a88597vandebo@chromium.org } 4126744d498fcbbbcf503ec80c4d43dd8f118a88597vandebo@chromium.org } 4136744d498fcbbbcf503ec80c4d43dd8f118a88597vandebo@chromium.org} 4146744d498fcbbbcf503ec80c4d43dd8f118a88597vandebo@chromium.org 41599edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com////////////////////////////////////////////////////////////////////////////////////// 41699edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com 41799edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.comstatic int alignTo32(int n) { 41899edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com return (n + 31) & ~31; 41999edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com} 42099edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com 42199edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.comstruct MyBitmapInfo : public BITMAPINFO { 42299edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com RGBQUAD fMoreSpaceForColors[1]; 42399edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com}; 42499edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com 42599edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.comclass HDCOffscreen { 42699edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.compublic: 42799edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com HDCOffscreen() { 42899edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com fFont = 0; 42999edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com fDC = 0; 43099edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com fBM = 0; 43199edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com fBits = NULL; 43299edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com fWidth = fHeight = 0; 43399edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com fIsBW = false; 43499edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com } 43599edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com 43699edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com ~HDCOffscreen() { 43799edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com if (fDC) { 43899edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com DeleteDC(fDC); 43999edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com } 44099edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com if (fBM) { 44199edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com DeleteObject(fBM); 44299edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com } 44399edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com } 44499edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com 44599edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com void init(HFONT font, const XFORM& xform) { 44699edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com fFont = font; 44799edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com fXform = xform; 44899edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com } 44999edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com 45097efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com const void* draw(const SkGlyph&, bool isBW, size_t* srcRBPtr); 45199edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com 45299edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.comprivate: 45399edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com HDC fDC; 45499edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com HBITMAP fBM; 45599edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com HFONT fFont; 45699edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com XFORM fXform; 45799edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com void* fBits; // points into fBM 45899edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com int fWidth; 45999edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com int fHeight; 46099edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com bool fIsBW; 46199edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com}; 46299edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com 463754e4ebd10d7353ce55be7dfe0a417e502ef4047reed@google.comconst void* HDCOffscreen::draw(const SkGlyph& glyph, bool isBW, 46497efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com size_t* srcRBPtr) { 46584e22d847fc84727bc220947162363ee1fe068fcreed@google.com // Can we share the scalercontext's fDDC, so we don't need to create 46684e22d847fc84727bc220947162363ee1fe068fcreed@google.com // a separate fDC here? 46799edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com if (0 == fDC) { 46899edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com fDC = CreateCompatibleDC(0); 46999edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com if (0 == fDC) { 47099edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com return NULL; 47199edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com } 47299edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com SetGraphicsMode(fDC, GM_ADVANCED); 47399edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com SetBkMode(fDC, TRANSPARENT); 47499edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com SetTextAlign(fDC, TA_LEFT | TA_BASELINE); 47599edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com SelectObject(fDC, fFont); 47697efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com 47797efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com COLORREF color = 0x00FFFFFF; 478b58a639b2fbe919489654bb506efdb024a308a8ebsalomon@google.com SkDEBUGCODE(COLORREF prev =) SetTextColor(fDC, color); 47997efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com SkASSERT(prev != CLR_INVALID); 48099edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com } 48199edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com 48299edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com if (fBM && (fIsBW != isBW || fWidth < glyph.fWidth || fHeight < glyph.fHeight)) { 48399edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com DeleteObject(fBM); 48499edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com fBM = 0; 48599edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com } 486754e4ebd10d7353ce55be7dfe0a417e502ef4047reed@google.com fIsBW = isBW; 48799edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com 48899edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com fWidth = SkMax32(fWidth, glyph.fWidth); 48999edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com fHeight = SkMax32(fHeight, glyph.fHeight); 49099edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com 49199edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com int biWidth = isBW ? alignTo32(fWidth) : fWidth; 49299edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com 49399edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com if (0 == fBM) { 49499edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com MyBitmapInfo info; 49599edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com sk_bzero(&info, sizeof(info)); 49699edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com if (isBW) { 49799edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com RGBQUAD blackQuad = { 0, 0, 0, 0 }; 49899edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com RGBQUAD whiteQuad = { 0xFF, 0xFF, 0xFF, 0 }; 49999edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com info.bmiColors[0] = blackQuad; 50099edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com info.bmiColors[1] = whiteQuad; 50199edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com } 50299edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com info.bmiHeader.biSize = sizeof(info.bmiHeader); 50399edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com info.bmiHeader.biWidth = biWidth; 50499edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com info.bmiHeader.biHeight = fHeight; 50599edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com info.bmiHeader.biPlanes = 1; 50699edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com info.bmiHeader.biBitCount = isBW ? 1 : 32; 50799edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com info.bmiHeader.biCompression = BI_RGB; 50899edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com if (isBW) { 50999edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com info.bmiHeader.biClrUsed = 2; 51099edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com } 51199edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com fBM = CreateDIBSection(fDC, &info, DIB_RGB_COLORS, &fBits, 0, 0); 51299edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com if (0 == fBM) { 51399edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com return NULL; 51499edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com } 51599edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com SelectObject(fDC, fBM); 51699edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com } 51799edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com 51899edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com // erase 51999edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com size_t srcRB = isBW ? (biWidth >> 3) : (fWidth << 2); 52099edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com size_t size = fHeight * srcRB; 52197efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com memset(fBits, 0, size); 52299edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com 52399edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com XFORM xform = fXform; 52499edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com xform.eDx = (float)-glyph.fLeft; 52599edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com xform.eDy = (float)-glyph.fTop; 52699edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com SetWorldTransform(fDC, &xform); 52799edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com 52899edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com uint16_t glyphID = glyph.getGlyphID(); 52939698b1bd71fd54c7c44ae8d7224afdaf93c0ddabungeman@google.com BOOL ret = ExtTextOutW(fDC, 0, 0, ETO_GLYPH_INDEX, NULL, reinterpret_cast<LPCWSTR>(&glyphID), 1, NULL); 53099edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com GdiFlush(); 53139698b1bd71fd54c7c44ae8d7224afdaf93c0ddabungeman@google.com if (0 == ret) { 53239698b1bd71fd54c7c44ae8d7224afdaf93c0ddabungeman@google.com return NULL; 53339698b1bd71fd54c7c44ae8d7224afdaf93c0ddabungeman@google.com } 53499edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com *srcRBPtr = srcRB; 53599edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com // offset to the start of the image 53699edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com return (const char*)fBits + (fHeight - glyph.fHeight) * srcRB; 53799edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com} 53899edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com 539b8a5c618d2e18d71707ae4dcafbe5153d7ff427freed@google.com////////////////////////////////////////////////////////////////////////////// 5400abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com#define BUFFERSIZE (1 << 13) 54159d2f63583512b47df579e80f1ae39c74fad5f3ereed@google.com 54230ddd615c447fed73286151b463af20d309c85f1reed@google.comclass SkScalerContext_GDI : public SkScalerContext { 543ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.compublic: 54430ddd615c447fed73286151b463af20d309c85f1reed@google.com SkScalerContext_GDI(SkTypeface*, const SkDescriptor* desc); 54530ddd615c447fed73286151b463af20d309c85f1reed@google.com virtual ~SkScalerContext_GDI(); 546ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com 54784e22d847fc84727bc220947162363ee1fe068fcreed@google.com // Returns true if the constructor was able to complete all of its 54884e22d847fc84727bc220947162363ee1fe068fcreed@google.com // initializations (which may include calling GDI). 54984e22d847fc84727bc220947162363ee1fe068fcreed@google.com bool isValid() const; 55084e22d847fc84727bc220947162363ee1fe068fcreed@google.com 551ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.comprotected: 55297efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com virtual unsigned generateGlyphCount() SK_OVERRIDE; 55397efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com virtual uint16_t generateCharToGlyph(SkUnichar uni) SK_OVERRIDE; 55497efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com virtual void generateAdvance(SkGlyph* glyph) SK_OVERRIDE; 55597efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com virtual void generateMetrics(SkGlyph* glyph) SK_OVERRIDE; 556a76de72a6036da0a6b051b14411b80941971f881bungeman@google.com virtual void generateImage(const SkGlyph& glyph) SK_OVERRIDE; 55797efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com virtual void generatePath(const SkGlyph& glyph, SkPath* path) SK_OVERRIDE; 558a76de72a6036da0a6b051b14411b80941971f881bungeman@google.com virtual void generateFontMetrics(SkPaint::FontMetrics* mX, 559a76de72a6036da0a6b051b14411b80941971f881bungeman@google.com SkPaint::FontMetrics* mY) SK_OVERRIDE; 56099edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com 561ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.comprivate: 5620abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com DWORD getGDIGlyphPath(const SkGlyph& glyph, UINT flags, 5630abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com SkAutoSTMalloc<BUFFERSIZE, uint8_t>* glyphbuf); 5640abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com 56599edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com HDCOffscreen fOffscreen; 5660abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com /** fGsA is the non-rotational part of total matrix without the text height scale. 5670abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com * Used to find the magnitude of advances. 5680abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com */ 5690abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com MAT2 fGsA; 5706a774a1f266070f304199ee31b8d1f4c0138b6cfbungeman@google.com /** The total matrix without the textSize. */ 571ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com MAT2 fMat22; 5726a774a1f266070f304199ee31b8d1f4c0138b6cfbungeman@google.com /** Scales font to EM size. */ 5736a774a1f266070f304199ee31b8d1f4c0138b6cfbungeman@google.com MAT2 fHighResMat22; 574ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com HDC fDDC; 575ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com HFONT fSavefont; 576ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com HFONT fFont; 577ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com SCRIPT_CACHE fSC; 578ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com int fGlyphCount; 5791dd17a133f4fa5c5a0c752e6b9a6f7af6f329fb8reed@google.com 5806a774a1f266070f304199ee31b8d1f4c0138b6cfbungeman@google.com /** The total matrix which also removes EM scale. */ 5811dd17a133f4fa5c5a0c752e6b9a6f7af6f329fb8reed@google.com SkMatrix fHiResMatrix; 5820abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com /** fG_inv is the inverse of the rotational part of the total matrix. 5830abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com * Used to set the direction of advances. 5840abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com */ 5850abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com SkMatrix fG_inv; 586a0319f6d071bb8298e56ace043ea6c623fb358f7bungeman@google.com enum Type { 587a0319f6d071bb8298e56ace043ea6c623fb358f7bungeman@google.com kTrueType_Type, kBitmap_Type, 588a0319f6d071bb8298e56ace043ea6c623fb358f7bungeman@google.com } fType; 589a0319f6d071bb8298e56ace043ea6c623fb358f7bungeman@google.com TEXTMETRIC fTM; 590ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com}; 591ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com 592ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.comstatic FIXED float2FIXED(float x) { 593ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com return SkFixedToFIXED(SkFloatToFixed(x)); 594ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com} 595ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com 59682a34d83f646d069ef2d1d7b649d0a0b1829d62freed@google.comstatic BYTE compute_quality(const SkScalerContext::Rec& rec) { 59782a34d83f646d069ef2d1d7b649d0a0b1829d62freed@google.com switch (rec.fMaskFormat) { 59882a34d83f646d069ef2d1d7b649d0a0b1829d62freed@google.com case SkMask::kBW_Format: 59982a34d83f646d069ef2d1d7b649d0a0b1829d62freed@google.com return NONANTIALIASED_QUALITY; 60082a34d83f646d069ef2d1d7b649d0a0b1829d62freed@google.com case SkMask::kLCD16_Format: 60182a34d83f646d069ef2d1d7b649d0a0b1829d62freed@google.com case SkMask::kLCD32_Format: 60282a34d83f646d069ef2d1d7b649d0a0b1829d62freed@google.com return CLEARTYPE_QUALITY; 60382a34d83f646d069ef2d1d7b649d0a0b1829d62freed@google.com default: 6048351aabbfe82a76a698fa2bde00d33c1174518cdreed@google.com if (rec.fFlags & SkScalerContext::kGenA8FromLCD_Flag) { 6058351aabbfe82a76a698fa2bde00d33c1174518cdreed@google.com return CLEARTYPE_QUALITY; 6068351aabbfe82a76a698fa2bde00d33c1174518cdreed@google.com } else { 6078351aabbfe82a76a698fa2bde00d33c1174518cdreed@google.com return ANTIALIASED_QUALITY; 6088351aabbfe82a76a698fa2bde00d33c1174518cdreed@google.com } 60982a34d83f646d069ef2d1d7b649d0a0b1829d62freed@google.com } 61082a34d83f646d069ef2d1d7b649d0a0b1829d62freed@google.com} 61182a34d83f646d069ef2d1d7b649d0a0b1829d62freed@google.com 61230ddd615c447fed73286151b463af20d309c85f1reed@google.comSkScalerContext_GDI::SkScalerContext_GDI(SkTypeface* rawTypeface, 6130da48618a758ef46c2174bdc1eaeb6dd8a693a2ereed@google.com const SkDescriptor* desc) 614055180cb9c47c87e5ee8c9fa6d3f6a6079ad6f35reed@google.com : SkScalerContext(rawTypeface, desc) 615055180cb9c47c87e5ee8c9fa6d3f6a6079ad6f35reed@google.com , fDDC(0) 616055180cb9c47c87e5ee8c9fa6d3f6a6079ad6f35reed@google.com , fSavefont(0) 61784e22d847fc84727bc220947162363ee1fe068fcreed@google.com , fFont(0) 618055180cb9c47c87e5ee8c9fa6d3f6a6079ad6f35reed@google.com , fSC(0) 61905a729ff90f75ac013873742ee0e4ae7e5e6e415bungeman@google.com , fGlyphCount(-1) 62005a729ff90f75ac013873742ee0e4ae7e5e6e415bungeman@google.com{ 621055180cb9c47c87e5ee8c9fa6d3f6a6079ad6f35reed@google.com LogFontTypeface* typeface = reinterpret_cast<LogFontTypeface*>(rawTypeface); 622055180cb9c47c87e5ee8c9fa6d3f6a6079ad6f35reed@google.com 623ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com fDDC = ::CreateCompatibleDC(NULL); 62484e22d847fc84727bc220947162363ee1fe068fcreed@google.com if (!fDDC) { 62584e22d847fc84727bc220947162363ee1fe068fcreed@google.com return; 62684e22d847fc84727bc220947162363ee1fe068fcreed@google.com } 6271dd17a133f4fa5c5a0c752e6b9a6f7af6f329fb8reed@google.com SetGraphicsMode(fDDC, GM_ADVANCED); 628ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com SetBkMode(fDDC, TRANSPARENT); 62927e21fe577211c1c40cbf40d0385b02c69d04522skia.committer@gmail.com 6300abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com SkPoint h = SkPoint::Make(SK_Scalar1, 0); 6310abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com // A is the total matrix. 6320abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com SkMatrix A; 6330abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com fRec.getSingleMatrix(&A); 6340abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com A.mapPoints(&h, 1); 6350abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com 6360abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com // Find the Given's matrix [[c, -s],[s, c]] which rotates the baseline vector h 6370abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com // (where the baseline is mapped to) to the positive horizontal axis. 6380abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com const SkScalar& a = h.fX; 6390abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com const SkScalar& b = h.fY; 6400abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com SkScalar c, s; 6410abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com if (0 == b) { 6420abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com c = SkDoubleToScalar(_copysign(SK_Scalar1, a)); 6430abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com s = 0; 6440abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com } else if (0 == a) { 6450abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com c = 0; 6460abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com s = SkDoubleToScalar(-_copysign(SK_Scalar1, b)); 6470abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com } else if (SkScalarAbs(b) > SkScalarAbs(a)) { 6480abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com SkScalar t = a / b; 6490abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com SkScalar u = SkDoubleToScalar(_copysign(SkScalarSqrt(SK_Scalar1 + t*t), b)); 6500abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com s = -1 / u; 6510abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com c = -s * t; 6520abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com } else { 6530abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com SkScalar t = b / a; 6540abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com SkScalar u = SkDoubleToScalar(_copysign(SkScalarSqrt(SK_Scalar1 + t*t), a)); 6550abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com c = 1 / u; 6560abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com s = -c * t; 6570abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com } 6580abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com 6590abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com // G is the Given's Matrix for A (rotational matrix such that GA[0][1] == 0). 6600abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com SkMatrix G; 6610abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com G.setAll(c, -s, 0, 6620abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com s, c, 0, 6630abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com 0, 0, SkScalarToPersp(SK_Scalar1)); 6640abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com 6650abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com // GA is the matrix A with rotation removed. 6660abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com SkMatrix GA(G); 6670abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com GA.preConcat(A); 6680abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com 66911ba3199f3edc7883ada4fd941d231f8f4883720bungeman@google.com // realTextSize is the actual device size we want (as opposed to the size the user requested). 67011ba3199f3edc7883ada4fd941d231f8f4883720bungeman@google.com // gdiTextSide is the size we request from GDI. 6710abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com // If the scale is negative, this means the matrix will do the flip anyway. 67211ba3199f3edc7883ada4fd941d231f8f4883720bungeman@google.com SkScalar realTextSize = SkScalarAbs(GA.get(SkMatrix::kMScaleY)); 67311ba3199f3edc7883ada4fd941d231f8f4883720bungeman@google.com SkScalar gdiTextSize = SkScalarRoundToScalar(realTextSize); 67411ba3199f3edc7883ada4fd941d231f8f4883720bungeman@google.com if (gdiTextSize == 0) { 67511ba3199f3edc7883ada4fd941d231f8f4883720bungeman@google.com gdiTextSize = SK_Scalar1; 6760abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com } 6770abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com 67811ba3199f3edc7883ada4fd941d231f8f4883720bungeman@google.com // When not hinting, remove only the gdiTextSize scale which will be applied by GDI. 67911ba3199f3edc7883ada4fd941d231f8f4883720bungeman@google.com // When GDI hinting, remove the entire Y scale to prevent 'subpixel' metrics. 68011ba3199f3edc7883ada4fd941d231f8f4883720bungeman@google.com SkScalar scale = (fRec.getHinting() == SkPaint::kNo_Hinting || 68111ba3199f3edc7883ada4fd941d231f8f4883720bungeman@google.com fRec.getHinting() == SkPaint::kSlight_Hinting) 68211ba3199f3edc7883ada4fd941d231f8f4883720bungeman@google.com ? SkScalarInvert(gdiTextSize) 68311ba3199f3edc7883ada4fd941d231f8f4883720bungeman@google.com : SkScalarInvert(realTextSize); 68411ba3199f3edc7883ada4fd941d231f8f4883720bungeman@google.com 6850abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com // sA is the total matrix A without the textSize (so GDI knows the text size separately). 6860abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com // When this matrix is used with GetGlyphOutline, no further processing is needed. 6870abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com SkMatrix sA(A); 6880abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com sA.preScale(scale, scale); //remove text size 6890abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com 6900abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com // GsA is the non-rotational part of A without the text height scale. 6910abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com // This is what is used to find the magnitude of advances. 6920abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com SkMatrix GsA(GA); 6930abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com GsA.preScale(scale, scale); //remove text size, G is rotational so reorders with the scale. 6940abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com 6950abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com fGsA.eM11 = SkScalarToFIXED(GsA.get(SkMatrix::kMScaleX)); 6960abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com fGsA.eM12 = SkScalarToFIXED(-GsA.get(SkMatrix::kMSkewY)); // This should be ~0. 6970abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com fGsA.eM21 = SkScalarToFIXED(-GsA.get(SkMatrix::kMSkewX)); 6980abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com fGsA.eM22 = SkScalarToFIXED(GsA.get(SkMatrix::kMScaleY)); 6990abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com 7000abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com // fG_inv is G inverse, which is fairly simple since G is 2x2 rotational. 7010abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com fG_inv.setAll(G.get(SkMatrix::kMScaleX), -G.get(SkMatrix::kMSkewX), G.get(SkMatrix::kMTransX), 7020abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com -G.get(SkMatrix::kMSkewY), G.get(SkMatrix::kMScaleY), G.get(SkMatrix::kMTransY), 7030abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com G.get(SkMatrix::kMPersp0), G.get(SkMatrix::kMPersp1), G.get(SkMatrix::kMPersp2)); 704ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com 705055180cb9c47c87e5ee8c9fa6d3f6a6079ad6f35reed@google.com LOGFONT lf = typeface->fLogFont; 70611ba3199f3edc7883ada4fd941d231f8f4883720bungeman@google.com lf.lfHeight = -SkScalarTruncToInt(gdiTextSize); 70782a34d83f646d069ef2d1d7b649d0a0b1829d62freed@google.com lf.lfQuality = compute_quality(fRec); 708ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com fFont = CreateFontIndirect(&lf); 70984e22d847fc84727bc220947162363ee1fe068fcreed@google.com if (!fFont) { 71084e22d847fc84727bc220947162363ee1fe068fcreed@google.com return; 71184e22d847fc84727bc220947162363ee1fe068fcreed@google.com } 7121dd17a133f4fa5c5a0c752e6b9a6f7af6f329fb8reed@google.com 713ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com fSavefont = (HFONT)SelectObject(fDDC, fFont); 714a767fa06ca28be9df1ff6e08a299e0bec839a2dcreed@google.com 715a0319f6d071bb8298e56ace043ea6c623fb358f7bungeman@google.com if (0 == GetTextMetrics(fDDC, &fTM)) { 716055180cb9c47c87e5ee8c9fa6d3f6a6079ad6f35reed@google.com call_ensure_accessible(lf); 717a0319f6d071bb8298e56ace043ea6c623fb358f7bungeman@google.com if (0 == GetTextMetrics(fDDC, &fTM)) { 718a0319f6d071bb8298e56ace043ea6c623fb358f7bungeman@google.com fTM.tmPitchAndFamily = TMPF_TRUETYPE; 719a0319f6d071bb8298e56ace043ea6c623fb358f7bungeman@google.com } 720a0319f6d071bb8298e56ace043ea6c623fb358f7bungeman@google.com } 721a0319f6d071bb8298e56ace043ea6c623fb358f7bungeman@google.com // Used a logfont on a memory context, should never get a device font. 72290b7e386cab251db78152f18adfd54e019b8dc10bungeman@google.com // Therefore all TMPF_DEVICE will be PostScript fonts. 72390b7e386cab251db78152f18adfd54e019b8dc10bungeman@google.com 72490b7e386cab251db78152f18adfd54e019b8dc10bungeman@google.com // If TMPF_VECTOR is set, one of TMPF_TRUETYPE or TMPF_DEVICE must be set, 72590b7e386cab251db78152f18adfd54e019b8dc10bungeman@google.com // otherwise we have a vector FON, which we don't support. 72690b7e386cab251db78152f18adfd54e019b8dc10bungeman@google.com // This was determined by testing with Type1 PFM/PFB and OpenTypeCFF OTF, 72790b7e386cab251db78152f18adfd54e019b8dc10bungeman@google.com // as well as looking at Wine bugs and sources. 72890b7e386cab251db78152f18adfd54e019b8dc10bungeman@google.com SkASSERT(!(fTM.tmPitchAndFamily & TMPF_VECTOR) || 72990b7e386cab251db78152f18adfd54e019b8dc10bungeman@google.com (fTM.tmPitchAndFamily & (TMPF_TRUETYPE | TMPF_DEVICE))); 73090b7e386cab251db78152f18adfd54e019b8dc10bungeman@google.com 731d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com XFORM xform; 73290b7e386cab251db78152f18adfd54e019b8dc10bungeman@google.com if (fTM.tmPitchAndFamily & TMPF_VECTOR) { 733a0319f6d071bb8298e56ace043ea6c623fb358f7bungeman@google.com // Truetype or PostScript. 734a0319f6d071bb8298e56ace043ea6c623fb358f7bungeman@google.com // Stroked FON also gets here (TMPF_VECTOR), but we don't handle it. 73530ddd615c447fed73286151b463af20d309c85f1reed@google.com fType = SkScalerContext_GDI::kTrueType_Type; 736a0319f6d071bb8298e56ace043ea6c623fb358f7bungeman@google.com 737d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com // fPost2x2 is column-major, left handed (y down). 738d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com // XFORM 2x2 is row-major, left handed (y down). 7390abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com xform.eM11 = SkScalarToFloat(sA.get(SkMatrix::kMScaleX)); 7400abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com xform.eM12 = SkScalarToFloat(sA.get(SkMatrix::kMSkewY)); 7410abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com xform.eM21 = SkScalarToFloat(sA.get(SkMatrix::kMSkewX)); 7420abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com xform.eM22 = SkScalarToFloat(sA.get(SkMatrix::kMScaleY)); 743d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com xform.eDx = 0; 744d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com xform.eDy = 0; 745d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com 746d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com // MAT2 is row major, right handed (y up). 747d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com fMat22.eM11 = float2FIXED(xform.eM11); 748d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com fMat22.eM12 = float2FIXED(-xform.eM12); 749d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com fMat22.eM21 = float2FIXED(-xform.eM21); 750d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com fMat22.eM22 = float2FIXED(xform.eM22); 751a0319f6d071bb8298e56ace043ea6c623fb358f7bungeman@google.com 752a0319f6d071bb8298e56ace043ea6c623fb358f7bungeman@google.com if (needToRenderWithSkia(fRec)) { 753a0319f6d071bb8298e56ace043ea6c623fb358f7bungeman@google.com this->forceGenerateImageFromPath(); 754a0319f6d071bb8298e56ace043ea6c623fb358f7bungeman@google.com } 755a0319f6d071bb8298e56ace043ea6c623fb358f7bungeman@google.com 75611ba3199f3edc7883ada4fd941d231f8f4883720bungeman@google.com // Create a hires matrix if we need linear metrics. 7570abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com if (this->isSubpixel()) { 7580abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com OUTLINETEXTMETRIC otm; 7590abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com UINT success = GetOutlineTextMetrics(fDDC, sizeof(otm), &otm); 7600abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com if (0 == success) { 7610abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com call_ensure_accessible(lf); 7620abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com success = GetOutlineTextMetrics(fDDC, sizeof(otm), &otm); 7630abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com } 7640abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com if (0 != success) { 76511ba3199f3edc7883ada4fd941d231f8f4883720bungeman@google.com SkScalar upem = SkIntToScalar(otm.otmEMSquare); 7666a774a1f266070f304199ee31b8d1f4c0138b6cfbungeman@google.com 76711ba3199f3edc7883ada4fd941d231f8f4883720bungeman@google.com SkScalar gdiTextSizeToEMScale = upem / gdiTextSize; 76811ba3199f3edc7883ada4fd941d231f8f4883720bungeman@google.com fHighResMat22.eM11 = float2FIXED(gdiTextSizeToEMScale); 7696a774a1f266070f304199ee31b8d1f4c0138b6cfbungeman@google.com fHighResMat22.eM12 = float2FIXED(0); 7706a774a1f266070f304199ee31b8d1f4c0138b6cfbungeman@google.com fHighResMat22.eM21 = float2FIXED(0); 77111ba3199f3edc7883ada4fd941d231f8f4883720bungeman@google.com fHighResMat22.eM22 = float2FIXED(gdiTextSizeToEMScale); 7726a774a1f266070f304199ee31b8d1f4c0138b6cfbungeman@google.com 77311ba3199f3edc7883ada4fd941d231f8f4883720bungeman@google.com SkScalar removeEMScale = SkScalarInvert(upem); 7746a774a1f266070f304199ee31b8d1f4c0138b6cfbungeman@google.com fHiResMatrix = A; 77511ba3199f3edc7883ada4fd941d231f8f4883720bungeman@google.com fHiResMatrix.preScale(removeEMScale, removeEMScale); 7760abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com } 7770abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com } 7780abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com 779a0319f6d071bb8298e56ace043ea6c623fb358f7bungeman@google.com } else { 780a0319f6d071bb8298e56ace043ea6c623fb358f7bungeman@google.com // Assume bitmap 78130ddd615c447fed73286151b463af20d309c85f1reed@google.com fType = SkScalerContext_GDI::kBitmap_Type; 782a0319f6d071bb8298e56ace043ea6c623fb358f7bungeman@google.com 783d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com xform.eM11 = 1.0f; 784d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com xform.eM12 = 0.0f; 785d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com xform.eM21 = 0.0f; 786d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com xform.eM22 = 1.0f; 787d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com xform.eDx = 0.0f; 788d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com xform.eDy = 0.0f; 789a0319f6d071bb8298e56ace043ea6c623fb358f7bungeman@google.com 790d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com // fPost2x2 is column-major, left handed (y down). 791d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com // MAT2 is row major, right handed (y up). 792a0319f6d071bb8298e56ace043ea6c623fb358f7bungeman@google.com fMat22.eM11 = SkScalarToFIXED(fRec.fPost2x2[0][0]); 793d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com fMat22.eM12 = SkScalarToFIXED(-fRec.fPost2x2[1][0]); 794a0319f6d071bb8298e56ace043ea6c623fb358f7bungeman@google.com fMat22.eM21 = SkScalarToFIXED(-fRec.fPost2x2[0][1]); 795d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com fMat22.eM22 = SkScalarToFIXED(fRec.fPost2x2[1][1]); 796a767fa06ca28be9df1ff6e08a299e0bec839a2dcreed@google.com } 79799edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com 798d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com fOffscreen.init(fFont, xform); 799ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com} 800ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com 80130ddd615c447fed73286151b463af20d309c85f1reed@google.comSkScalerContext_GDI::~SkScalerContext_GDI() { 802ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com if (fDDC) { 803ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com ::SelectObject(fDDC, fSavefont); 804ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com ::DeleteDC(fDDC); 805ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com } 806ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com if (fFont) { 807ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com ::DeleteObject(fFont); 808ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com } 809ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com if (fSC) { 810ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com ::ScriptFreeCache(&fSC); 811ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com } 812ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com} 813ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com 81430ddd615c447fed73286151b463af20d309c85f1reed@google.combool SkScalerContext_GDI::isValid() const { 81584e22d847fc84727bc220947162363ee1fe068fcreed@google.com return fDDC && fFont; 81684e22d847fc84727bc220947162363ee1fe068fcreed@google.com} 81784e22d847fc84727bc220947162363ee1fe068fcreed@google.com 81830ddd615c447fed73286151b463af20d309c85f1reed@google.comunsigned SkScalerContext_GDI::generateGlyphCount() { 819ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com if (fGlyphCount < 0) { 8207bdd614a1940935d3badeb54f7aae75d76ea830dbungeman@google.com fGlyphCount = calculateGlyphCount( 8217bdd614a1940935d3badeb54f7aae75d76ea830dbungeman@google.com fDDC, static_cast<const LogFontTypeface*>(this->getTypeface())->fLogFont); 822ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com } 823ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com return fGlyphCount; 824ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com} 825ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com 82633346487cbb64134d7204abe32d9318c1b511aa8bungeman@google.comuint16_t SkScalerContext_GDI::generateCharToGlyph(SkUnichar utf32) { 827ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com uint16_t index = 0; 82833346487cbb64134d7204abe32d9318c1b511aa8bungeman@google.com WCHAR utf16[2]; 829ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com // TODO(ctguil): Support characters that generate more than one glyph. 83033346487cbb64134d7204abe32d9318c1b511aa8bungeman@google.com if (SkUTF16_FromUnichar(utf32, (uint16_t*)utf16) == 1) { 831ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com // Type1 fonts fail with uniscribe API. Use GetGlyphIndices for plane 0. 8327bd141dce43ea3405bc60c9c84e6f910b851b079skia.committer@gmail.com 83333346487cbb64134d7204abe32d9318c1b511aa8bungeman@google.com /** Real documentation for GetGlyphIndiciesW: 83433346487cbb64134d7204abe32d9318c1b511aa8bungeman@google.com * 83533346487cbb64134d7204abe32d9318c1b511aa8bungeman@google.com * When GGI_MARK_NONEXISTING_GLYPHS is not specified and a character does not map to a 83633346487cbb64134d7204abe32d9318c1b511aa8bungeman@google.com * glyph, then the 'default character's glyph is returned instead. The 'default character' 83733346487cbb64134d7204abe32d9318c1b511aa8bungeman@google.com * is available in fTM.tmDefaultChar. FON fonts have adefault character, and there exists a 83833346487cbb64134d7204abe32d9318c1b511aa8bungeman@google.com * usDefaultChar in the 'OS/2' table, version 2 and later. If there is no 83933346487cbb64134d7204abe32d9318c1b511aa8bungeman@google.com * 'default character' specified by the font, then often the first character found is used. 84033346487cbb64134d7204abe32d9318c1b511aa8bungeman@google.com * 84133346487cbb64134d7204abe32d9318c1b511aa8bungeman@google.com * When GGI_MARK_NONEXISTING_GLYPHS is specified and a character does not map to a glyph, 84233346487cbb64134d7204abe32d9318c1b511aa8bungeman@google.com * then the glyph 0xFFFF is used. In Windows XP and earlier, Bitmap/Vector FON usually use 84333346487cbb64134d7204abe32d9318c1b511aa8bungeman@google.com * glyph 0x1F instead ('Terminal' appears to be special, returning 0xFFFF). 84433346487cbb64134d7204abe32d9318c1b511aa8bungeman@google.com * Type1 PFM/PFB, TT, OT TT, OT CFF all appear to use 0xFFFF, even on XP. 84533346487cbb64134d7204abe32d9318c1b511aa8bungeman@google.com */ 84633346487cbb64134d7204abe32d9318c1b511aa8bungeman@google.com DWORD result = GetGlyphIndicesW(fDDC, utf16, 1, &index, GGI_MARK_NONEXISTING_GLYPHS); 84733346487cbb64134d7204abe32d9318c1b511aa8bungeman@google.com if (result == GDI_ERROR 84833346487cbb64134d7204abe32d9318c1b511aa8bungeman@google.com || 0xFFFF == index 84933346487cbb64134d7204abe32d9318c1b511aa8bungeman@google.com || (0x1F == index && fType == SkScalerContext_GDI::kBitmap_Type /*&& winVer < Vista */)) 85033346487cbb64134d7204abe32d9318c1b511aa8bungeman@google.com { 85133346487cbb64134d7204abe32d9318c1b511aa8bungeman@google.com index = 0; 85233346487cbb64134d7204abe32d9318c1b511aa8bungeman@google.com } 853ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com } else { 854ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com // Use uniscribe to detemine glyph index for non-BMP characters. 85527f74aab32123e6f021359061149966fa4ca5a62bungeman@google.com static const int numWCHAR = 2; 85627f74aab32123e6f021359061149966fa4ca5a62bungeman@google.com static const int maxItems = 2; 85727f74aab32123e6f021359061149966fa4ca5a62bungeman@google.com // MSDN states that this can be NULL, but some things don't work then. 85827f74aab32123e6f021359061149966fa4ca5a62bungeman@google.com SCRIPT_CONTROL sc = { 0 }; 85927f74aab32123e6f021359061149966fa4ca5a62bungeman@google.com // Add extra item to SCRIPT_ITEM to work around a bug (now documented). 86027f74aab32123e6f021359061149966fa4ca5a62bungeman@google.com // https://bugzilla.mozilla.org/show_bug.cgi?id=366643 86127f74aab32123e6f021359061149966fa4ca5a62bungeman@google.com SCRIPT_ITEM si[maxItems + 1]; 86227f74aab32123e6f021359061149966fa4ca5a62bungeman@google.com int numItems; 86327f74aab32123e6f021359061149966fa4ca5a62bungeman@google.com HRZM(ScriptItemize(utf16, numWCHAR, maxItems, &sc, NULL, si, &numItems), 86427f74aab32123e6f021359061149966fa4ca5a62bungeman@google.com "Could not itemize character."); 86527f74aab32123e6f021359061149966fa4ca5a62bungeman@google.com 86627f74aab32123e6f021359061149966fa4ca5a62bungeman@google.com // Sometimes ScriptShape cannot find a glyph for a non-BMP and returns 2 space glyphs. 86727f74aab32123e6f021359061149966fa4ca5a62bungeman@google.com static const int maxGlyphs = 2; 86827f74aab32123e6f021359061149966fa4ca5a62bungeman@google.com SCRIPT_VISATTR vsa[maxGlyphs]; 86927f74aab32123e6f021359061149966fa4ca5a62bungeman@google.com WORD outGlyphs[maxGlyphs]; 87027f74aab32123e6f021359061149966fa4ca5a62bungeman@google.com WORD logClust[numWCHAR]; 87127f74aab32123e6f021359061149966fa4ca5a62bungeman@google.com int numGlyphs; 87227f74aab32123e6f021359061149966fa4ca5a62bungeman@google.com HRZM(ScriptShape(fDDC, &fSC, utf16, numWCHAR, maxGlyphs, &si[0].a, 87327f74aab32123e6f021359061149966fa4ca5a62bungeman@google.com outGlyphs, logClust, vsa, &numGlyphs), 87427f74aab32123e6f021359061149966fa4ca5a62bungeman@google.com "Could not shape character."); 87527f74aab32123e6f021359061149966fa4ca5a62bungeman@google.com if (1 == numGlyphs) { 87627f74aab32123e6f021359061149966fa4ca5a62bungeman@google.com index = outGlyphs[0]; 87727f74aab32123e6f021359061149966fa4ca5a62bungeman@google.com } 878ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com } 879ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com return index; 880ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com} 881ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com 88230ddd615c447fed73286151b463af20d309c85f1reed@google.comvoid SkScalerContext_GDI::generateAdvance(SkGlyph* glyph) { 883ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com this->generateMetrics(glyph); 884ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com} 885ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com 88630ddd615c447fed73286151b463af20d309c85f1reed@google.comvoid SkScalerContext_GDI::generateMetrics(SkGlyph* glyph) { 887ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com SkASSERT(fDDC); 888ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com 88930ddd615c447fed73286151b463af20d309c85f1reed@google.com if (fType == SkScalerContext_GDI::kBitmap_Type) { 890a0319f6d071bb8298e56ace043ea6c623fb358f7bungeman@google.com SIZE size; 891a0319f6d071bb8298e56ace043ea6c623fb358f7bungeman@google.com WORD glyphs = glyph->getGlyphID(0); 892a0319f6d071bb8298e56ace043ea6c623fb358f7bungeman@google.com if (0 == GetTextExtentPointI(fDDC, &glyphs, 1, &size)) { 893a0319f6d071bb8298e56ace043ea6c623fb358f7bungeman@google.com glyph->fWidth = SkToS16(fTM.tmMaxCharWidth); 894a0319f6d071bb8298e56ace043ea6c623fb358f7bungeman@google.com } else { 895a0319f6d071bb8298e56ace043ea6c623fb358f7bungeman@google.com glyph->fWidth = SkToS16(size.cx); 896a0319f6d071bb8298e56ace043ea6c623fb358f7bungeman@google.com } 897a0319f6d071bb8298e56ace043ea6c623fb358f7bungeman@google.com glyph->fHeight = SkToS16(size.cy); 898a0319f6d071bb8298e56ace043ea6c623fb358f7bungeman@google.com 899a0319f6d071bb8298e56ace043ea6c623fb358f7bungeman@google.com glyph->fTop = SkToS16(-fTM.tmAscent); 900a0319f6d071bb8298e56ace043ea6c623fb358f7bungeman@google.com glyph->fLeft = SkToS16(0); 901a0319f6d071bb8298e56ace043ea6c623fb358f7bungeman@google.com glyph->fAdvanceX = SkIntToFixed(glyph->fWidth); 902a0319f6d071bb8298e56ace043ea6c623fb358f7bungeman@google.com glyph->fAdvanceY = 0; 903a0319f6d071bb8298e56ace043ea6c623fb358f7bungeman@google.com 904d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com // Apply matrix to advance. 905a0319f6d071bb8298e56ace043ea6c623fb358f7bungeman@google.com glyph->fAdvanceY = SkFixedMul(SkFIXEDToFixed(fMat22.eM21), glyph->fAdvanceX); 906a0319f6d071bb8298e56ace043ea6c623fb358f7bungeman@google.com glyph->fAdvanceX = SkFixedMul(SkFIXEDToFixed(fMat22.eM11), glyph->fAdvanceX); 907a0319f6d071bb8298e56ace043ea6c623fb358f7bungeman@google.com 908a0319f6d071bb8298e56ace043ea6c623fb358f7bungeman@google.com return; 909a0319f6d071bb8298e56ace043ea6c623fb358f7bungeman@google.com } 910a0319f6d071bb8298e56ace043ea6c623fb358f7bungeman@google.com 911d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com UINT glyphId = glyph->getGlyphID(0); 912d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com 913ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com GLYPHMETRICS gm; 9141dd17a133f4fa5c5a0c752e6b9a6f7af6f329fb8reed@google.com sk_bzero(&gm, sizeof(gm)); 915ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com 916d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com DWORD status = GetGlyphOutlineW(fDDC, glyphId, GGO_METRICS | GGO_GLYPH_INDEX, &gm, 0, NULL, &fMat22); 917d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com if (GDI_ERROR == status) { 918055180cb9c47c87e5ee8c9fa6d3f6a6079ad6f35reed@google.com LogFontTypeface::EnsureAccessible(this->getTypeface()); 919d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com status = GetGlyphOutlineW(fDDC, glyphId, GGO_METRICS | GGO_GLYPH_INDEX, &gm, 0, NULL, &fMat22); 920d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com if (GDI_ERROR == status) { 921d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com glyph->zeroMetrics(); 922d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com return; 923d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com } 92439698b1bd71fd54c7c44ae8d7224afdaf93c0ddabungeman@google.com } 925ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com 926d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com bool empty = false; 927d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com // The black box is either the embedded bitmap size or the outline extent. 928d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com // It is 1x1 if nothing is to be drawn, but will also be 1x1 if something very small 929d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com // is to be drawn, like a '.'. We need to outset '.' but do not wish to outset ' '. 930d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com if (1 == gm.gmBlackBoxX && 1 == gm.gmBlackBoxY) { 931d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com // If GetGlyphOutline with GGO_NATIVE returns 0, we know there was no outline. 932d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com DWORD bufferSize = GetGlyphOutlineW(fDDC, glyphId, GGO_NATIVE | GGO_GLYPH_INDEX, &gm, 0, NULL, &fMat22); 933d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com empty = (0 == bufferSize); 934d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com } 9351dd17a133f4fa5c5a0c752e6b9a6f7af6f329fb8reed@google.com 936d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com glyph->fTop = SkToS16(-gm.gmptGlyphOrigin.y); 937d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com glyph->fLeft = SkToS16(gm.gmptGlyphOrigin.x); 938d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com if (empty) { 939d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com glyph->fWidth = 0; 940d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com glyph->fHeight = 0; 941ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com } else { 942d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com // Outset, since the image may bleed out of the black box. 943d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com // For embedded bitmaps the black box should be exact. 944d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com // For outlines we need to outset by 1 in all directions for bleed. 945d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com // For ClearType we need to outset by 2 for bleed. 946d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com glyph->fWidth = gm.gmBlackBoxX + 4; 947d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com glyph->fHeight = gm.gmBlackBoxY + 4; 948d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com glyph->fTop -= 2; 949d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com glyph->fLeft -= 2; 950d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com } 951d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com glyph->fAdvanceX = SkIntToFixed(gm.gmCellIncX); 952d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com glyph->fAdvanceY = SkIntToFixed(gm.gmCellIncY); 953d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com glyph->fRsbDelta = 0; 954d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com glyph->fLsbDelta = 0; 955d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com 9566a774a1f266070f304199ee31b8d1f4c0138b6cfbungeman@google.com if (this->isSubpixel()) { 957d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com sk_bzero(&gm, sizeof(gm)); 9586a774a1f266070f304199ee31b8d1f4c0138b6cfbungeman@google.com status = GetGlyphOutlineW(fDDC, glyphId, GGO_METRICS | GGO_GLYPH_INDEX, &gm, 0, NULL, &fHighResMat22); 959d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com if (GDI_ERROR != status) { 960d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com SkPoint advance; 961d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com fHiResMatrix.mapXY(SkIntToScalar(gm.gmCellIncX), SkIntToScalar(gm.gmCellIncY), &advance); 962d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com glyph->fAdvanceX = SkScalarToFixed(advance.fX); 963d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com glyph->fAdvanceY = SkScalarToFixed(advance.fY); 964d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com } 9650abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com } else if (!isAxisAligned(this->fRec)) { 9660abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com status = GetGlyphOutlineW(fDDC, glyphId, GGO_METRICS | GGO_GLYPH_INDEX, &gm, 0, NULL, &fGsA); 9670abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com if (GDI_ERROR != status) { 9680abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com SkPoint advance; 9690abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com fG_inv.mapXY(SkIntToScalar(gm.gmCellIncX), SkIntToScalar(gm.gmCellIncY), &advance); 9700abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com glyph->fAdvanceX = SkScalarToFixed(advance.fX); 9710abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com glyph->fAdvanceY = SkScalarToFixed(advance.fY); 9720abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com } 973ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com } 974ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com} 975ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com 9766a774a1f266070f304199ee31b8d1f4c0138b6cfbungeman@google.comstatic const MAT2 gMat2Identity = {{0, 1}, {0, 0}, {0, 0}, {0, 1}}; 97730ddd615c447fed73286151b463af20d309c85f1reed@google.comvoid SkScalerContext_GDI::generateFontMetrics(SkPaint::FontMetrics* mx, SkPaint::FontMetrics* my) { 97860af92cb6de814b14ee5d40b71bfbd79227597ecreed@google.com if (!(mx || my)) { 979ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com return; 98060af92cb6de814b14ee5d40b71bfbd79227597ecreed@google.com } 98160af92cb6de814b14ee5d40b71bfbd79227597ecreed@google.com 98260af92cb6de814b14ee5d40b71bfbd79227597ecreed@google.com if (mx) { 98360af92cb6de814b14ee5d40b71bfbd79227597ecreed@google.com sk_bzero(mx, sizeof(*mx)); 98460af92cb6de814b14ee5d40b71bfbd79227597ecreed@google.com } 98560af92cb6de814b14ee5d40b71bfbd79227597ecreed@google.com if (my) { 98660af92cb6de814b14ee5d40b71bfbd79227597ecreed@google.com sk_bzero(my, sizeof(*my)); 98760af92cb6de814b14ee5d40b71bfbd79227597ecreed@google.com } 988ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com 989ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com SkASSERT(fDDC); 990ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com 991e9d831957602e3fa46fc4b609ae6d2da46654915bungeman@google.com#ifndef SK_GDI_ALWAYS_USE_TEXTMETRICS_FOR_FONT_METRICS 99230ddd615c447fed73286151b463af20d309c85f1reed@google.com if (fType == SkScalerContext_GDI::kBitmap_Type) { 993e9d831957602e3fa46fc4b609ae6d2da46654915bungeman@google.com#endif 994a0319f6d071bb8298e56ace043ea6c623fb358f7bungeman@google.com if (mx) { 995a0319f6d071bb8298e56ace043ea6c623fb358f7bungeman@google.com mx->fTop = SkIntToScalar(-fTM.tmAscent); 996a0319f6d071bb8298e56ace043ea6c623fb358f7bungeman@google.com mx->fAscent = SkIntToScalar(-fTM.tmAscent); 9970abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com mx->fDescent = SkIntToScalar(fTM.tmDescent); 998a0319f6d071bb8298e56ace043ea6c623fb358f7bungeman@google.com mx->fBottom = SkIntToScalar(fTM.tmDescent); 99960af92cb6de814b14ee5d40b71bfbd79227597ecreed@google.com mx->fLeading = SkIntToScalar(fTM.tmExternalLeading); 1000a0319f6d071bb8298e56ace043ea6c623fb358f7bungeman@google.com } 1001a0319f6d071bb8298e56ace043ea6c623fb358f7bungeman@google.com 1002a0319f6d071bb8298e56ace043ea6c623fb358f7bungeman@google.com if (my) { 1003a0319f6d071bb8298e56ace043ea6c623fb358f7bungeman@google.com my->fTop = SkIntToScalar(-fTM.tmAscent); 1004a0319f6d071bb8298e56ace043ea6c623fb358f7bungeman@google.com my->fAscent = SkIntToScalar(-fTM.tmAscent); 10050abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com my->fDescent = SkIntToScalar(fTM.tmDescent); 1006a0319f6d071bb8298e56ace043ea6c623fb358f7bungeman@google.com my->fBottom = SkIntToScalar(fTM.tmDescent); 100760af92cb6de814b14ee5d40b71bfbd79227597ecreed@google.com my->fLeading = SkIntToScalar(fTM.tmExternalLeading); 100860af92cb6de814b14ee5d40b71bfbd79227597ecreed@google.com my->fAvgCharWidth = SkIntToScalar(fTM.tmAveCharWidth); 1009e9d831957602e3fa46fc4b609ae6d2da46654915bungeman@google.com my->fMaxCharWidth = SkIntToScalar(fTM.tmMaxCharWidth); 1010e9d831957602e3fa46fc4b609ae6d2da46654915bungeman@google.com my->fXMin = 0; 1011e9d831957602e3fa46fc4b609ae6d2da46654915bungeman@google.com my->fXMax = my->fMaxCharWidth; 1012e9d831957602e3fa46fc4b609ae6d2da46654915bungeman@google.com //my->fXHeight = 0; 1013a0319f6d071bb8298e56ace043ea6c623fb358f7bungeman@google.com } 1014e9d831957602e3fa46fc4b609ae6d2da46654915bungeman@google.com#ifndef SK_GDI_ALWAYS_USE_TEXTMETRICS_FOR_FONT_METRICS 1015a0319f6d071bb8298e56ace043ea6c623fb358f7bungeman@google.com return; 1016a0319f6d071bb8298e56ace043ea6c623fb358f7bungeman@google.com } 1017e9d831957602e3fa46fc4b609ae6d2da46654915bungeman@google.com#endif 1018a0319f6d071bb8298e56ace043ea6c623fb358f7bungeman@google.com 1019ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com OUTLINETEXTMETRIC otm; 1020ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com 1021ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com uint32_t ret = GetOutlineTextMetrics(fDDC, sizeof(otm), &otm); 10220abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com if (0 == ret) { 1023055180cb9c47c87e5ee8c9fa6d3f6a6079ad6f35reed@google.com LogFontTypeface::EnsureAccessible(this->getTypeface()); 102439698b1bd71fd54c7c44ae8d7224afdaf93c0ddabungeman@google.com ret = GetOutlineTextMetrics(fDDC, sizeof(otm), &otm); 102539698b1bd71fd54c7c44ae8d7224afdaf93c0ddabungeman@google.com } 10260abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com if (0 == ret) { 1027a0319f6d071bb8298e56ace043ea6c623fb358f7bungeman@google.com return; 1028ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com } 1029ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com 1030ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com if (mx) { 10310abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com mx->fTop = SkIntToScalar(-otm.otmrcFontBox.left); 10320abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com mx->fAscent = SkIntToScalar(-otm.otmAscent); 10330abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com mx->fDescent = SkIntToScalar(-otm.otmDescent); 10340abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com mx->fBottom = SkIntToScalar(otm.otmrcFontBox.right); 10350abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com mx->fLeading = SkIntToScalar(otm.otmLineGap); 1036ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com } 1037ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com 1038ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com if (my) { 1039e9d831957602e3fa46fc4b609ae6d2da46654915bungeman@google.com#ifndef SK_GDI_ALWAYS_USE_TEXTMETRICS_FOR_FONT_METRICS 10400abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com my->fTop = SkIntToScalar(-otm.otmrcFontBox.top); 10410abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com my->fAscent = SkIntToScalar(-otm.otmAscent); 10420abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com my->fDescent = SkIntToScalar(-otm.otmDescent); 10430abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com my->fBottom = SkIntToScalar(-otm.otmrcFontBox.bottom); 10440abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com my->fLeading = SkIntToScalar(otm.otmLineGap); 10450abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com my->fAvgCharWidth = SkIntToScalar(otm.otmTextMetrics.tmAveCharWidth); 10460abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com my->fMaxCharWidth = SkIntToScalar(otm.otmTextMetrics.tmMaxCharWidth); 10470abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com my->fXMin = SkIntToScalar(otm.otmrcFontBox.left); 10480abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com my->fXMax = SkIntToScalar(otm.otmrcFontBox.right); 1049e9d831957602e3fa46fc4b609ae6d2da46654915bungeman@google.com#endif 10500abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com my->fXHeight = SkIntToScalar(otm.otmsXHeight); 10510abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com 10520abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com GLYPHMETRICS gm; 10530abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com sk_bzero(&gm, sizeof(gm)); 10540abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com DWORD len = GetGlyphOutlineW(fDDC, 'x', GGO_METRICS, &gm, 0, 0, &gMat2Identity); 10550abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com if (len != GDI_ERROR && gm.gmBlackBoxY > 0) { 10560abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com my->fXHeight = SkIntToScalar(gm.gmBlackBoxY); 10570abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com } 1058ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com } 1059ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com} 1060ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com 10617430a3376c0f4e0c2809fedecd12765034f9e3a8reed@google.com//////////////////////////////////////////////////////////////////////////////////////// 10627430a3376c0f4e0c2809fedecd12765034f9e3a8reed@google.com 10630abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com#define SK_SHOW_TEXT_BLIT_COVERAGE 0 10640abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com 10657430a3376c0f4e0c2809fedecd12765034f9e3a8reed@google.comstatic void build_power_table(uint8_t table[], float ee) { 10667430a3376c0f4e0c2809fedecd12765034f9e3a8reed@google.com for (int i = 0; i < 256; i++) { 10677430a3376c0f4e0c2809fedecd12765034f9e3a8reed@google.com float x = i / 255.f; 106897efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com x = sk_float_pow(x, ee); 10697430a3376c0f4e0c2809fedecd12765034f9e3a8reed@google.com int xx = SkScalarRound(SkFloatToScalar(x * 255)); 10707430a3376c0f4e0c2809fedecd12765034f9e3a8reed@google.com table[i] = SkToU8(xx); 10717430a3376c0f4e0c2809fedecd12765034f9e3a8reed@google.com } 10727430a3376c0f4e0c2809fedecd12765034f9e3a8reed@google.com} 10737430a3376c0f4e0c2809fedecd12765034f9e3a8reed@google.com 107497efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com/** 107597efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com * This will invert the gamma applied by GDI (gray-scale antialiased), so we 107697efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com * can get linear values. 107797efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com * 107897efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com * GDI grayscale appears to use a hard-coded gamma of 2.3. 107997efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com * 108097efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com * GDI grayscale appears to draw using the black and white rasterizer at four 108197efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com * times the size and then downsamples to compute the coverage mask. As a 108297efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com * result there are only seventeen total grays. This lack of fidelity means 108397efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com * that shifting into other color spaces is imprecise. 108497efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com */ 108597efada074e4806479f1350ab1508939c2fdcb53bungeman@google.comstatic const uint8_t* getInverseGammaTableGDI() { 108605a729ff90f75ac013873742ee0e4ae7e5e6e415bungeman@google.com // Since build_power_table is idempotent, many threads can build gTableGdi 108705a729ff90f75ac013873742ee0e4ae7e5e6e415bungeman@google.com // simultaneously. 108805a729ff90f75ac013873742ee0e4ae7e5e6e415bungeman@google.com 108905a729ff90f75ac013873742ee0e4ae7e5e6e415bungeman@google.com // Microsoft Specific: 109005a729ff90f75ac013873742ee0e4ae7e5e6e415bungeman@google.com // Making gInited volatile provides read-aquire and write-release in vc++. 109105a729ff90f75ac013873742ee0e4ae7e5e6e415bungeman@google.com // In VS2012, see compiler option /volatile:(ms|iso). 109205a729ff90f75ac013873742ee0e4ae7e5e6e415bungeman@google.com // Replace with C++11 atomics when possible. 109305a729ff90f75ac013873742ee0e4ae7e5e6e415bungeman@google.com static volatile bool gInited; 109497efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com static uint8_t gTableGdi[256]; 109505a729ff90f75ac013873742ee0e4ae7e5e6e415bungeman@google.com if (gInited) { 109605a729ff90f75ac013873742ee0e4ae7e5e6e415bungeman@google.com // Need a L/L (read) barrier (full acquire not needed). If gInited is observed 109705a729ff90f75ac013873742ee0e4ae7e5e6e415bungeman@google.com // true then gTableGdi is observable, but it must be requested. 109805a729ff90f75ac013873742ee0e4ae7e5e6e415bungeman@google.com } else { 109997efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com build_power_table(gTableGdi, 2.3f); 110005a729ff90f75ac013873742ee0e4ae7e5e6e415bungeman@google.com // Need a S/S (write) barrier (full release not needed) here so that this 110105a729ff90f75ac013873742ee0e4ae7e5e6e415bungeman@google.com // write to gInited becomes observable after gTableGdi. 110297efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com gInited = true; 110397efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com } 110497efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com return gTableGdi; 110597efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com} 110697efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com 110797efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com/** 110897efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com * This will invert the gamma applied by GDI ClearType, so we can get linear 110997efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com * values. 111097efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com * 111197efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com * GDI ClearType uses SPI_GETFONTSMOOTHINGCONTRAST / 1000 as the gamma value. 111297efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com * If this value is not specified, the default is a gamma of 1.4. 111397efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com */ 111497efada074e4806479f1350ab1508939c2fdcb53bungeman@google.comstatic const uint8_t* getInverseGammaTableClearType() { 111505a729ff90f75ac013873742ee0e4ae7e5e6e415bungeman@google.com // We don't expect SPI_GETFONTSMOOTHINGCONTRAST to ever change, so building 111605a729ff90f75ac013873742ee0e4ae7e5e6e415bungeman@google.com // gTableClearType with build_power_table is effectively idempotent. 111705a729ff90f75ac013873742ee0e4ae7e5e6e415bungeman@google.com 111805a729ff90f75ac013873742ee0e4ae7e5e6e415bungeman@google.com // Microsoft Specific: 111905a729ff90f75ac013873742ee0e4ae7e5e6e415bungeman@google.com // Making gInited volatile provides read-aquire and write-release in vc++. 112005a729ff90f75ac013873742ee0e4ae7e5e6e415bungeman@google.com // In VS2012, see compiler option /volatile:(ms|iso). 112105a729ff90f75ac013873742ee0e4ae7e5e6e415bungeman@google.com // Replace with C++11 atomics when possible. 112205a729ff90f75ac013873742ee0e4ae7e5e6e415bungeman@google.com static volatile bool gInited; 112397efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com static uint8_t gTableClearType[256]; 112405a729ff90f75ac013873742ee0e4ae7e5e6e415bungeman@google.com if (gInited) { 112505a729ff90f75ac013873742ee0e4ae7e5e6e415bungeman@google.com // Need a L/L (read) barrier (acquire not needed). If gInited is observed 112605a729ff90f75ac013873742ee0e4ae7e5e6e415bungeman@google.com // true then gTableClearType is observable, but it must be requested. 112705a729ff90f75ac013873742ee0e4ae7e5e6e415bungeman@google.com } else { 11287430a3376c0f4e0c2809fedecd12765034f9e3a8reed@google.com UINT level = 0; 11297430a3376c0f4e0c2809fedecd12765034f9e3a8reed@google.com if (!SystemParametersInfo(SPI_GETFONTSMOOTHINGCONTRAST, 0, &level, 0) || !level) { 11307430a3376c0f4e0c2809fedecd12765034f9e3a8reed@google.com // can't get the data, so use a default 11317430a3376c0f4e0c2809fedecd12765034f9e3a8reed@google.com level = 1400; 11327430a3376c0f4e0c2809fedecd12765034f9e3a8reed@google.com } 113397efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com build_power_table(gTableClearType, level / 1000.0f); 113405a729ff90f75ac013873742ee0e4ae7e5e6e415bungeman@google.com // Need a S/S (write) barrier (release not needed) here so that this 113505a729ff90f75ac013873742ee0e4ae7e5e6e415bungeman@google.com // write to gInited becomes observable after gTableClearType. 11367430a3376c0f4e0c2809fedecd12765034f9e3a8reed@google.com gInited = true; 11377430a3376c0f4e0c2809fedecd12765034f9e3a8reed@google.com } 113897efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com return gTableClearType; 11397430a3376c0f4e0c2809fedecd12765034f9e3a8reed@google.com} 11407430a3376c0f4e0c2809fedecd12765034f9e3a8reed@google.com 1141ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com#include "SkColorPriv.h" 1142ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com 11436385314686875ecb484d95b33fcbf08890b5144dbungeman@google.com//Cannot assume that the input rgb is gray due to possible setting of kGenA8FromLCD_Flag. 114497efada074e4806479f1350ab1508939c2fdcb53bungeman@google.comtemplate<bool APPLY_PREBLEND> 114597efada074e4806479f1350ab1508939c2fdcb53bungeman@google.comstatic inline uint8_t rgb_to_a8(SkGdiRGB rgb, const uint8_t* table8) { 11466385314686875ecb484d95b33fcbf08890b5144dbungeman@google.com U8CPU r = (rgb >> 16) & 0xFF; 11476385314686875ecb484d95b33fcbf08890b5144dbungeman@google.com U8CPU g = (rgb >> 8) & 0xFF; 11486385314686875ecb484d95b33fcbf08890b5144dbungeman@google.com U8CPU b = (rgb >> 0) & 0xFF; 11491bfe01d06b896eca94c80d9af9a6bb30216b5e42bungeman@google.com return sk_apply_lut_if<APPLY_PREBLEND>(SkComputeLuminance(r, g, b), table8); 115082a34d83f646d069ef2d1d7b649d0a0b1829d62freed@google.com} 115182a34d83f646d069ef2d1d7b649d0a0b1829d62freed@google.com 115297efada074e4806479f1350ab1508939c2fdcb53bungeman@google.comtemplate<bool APPLY_PREBLEND> 115397efada074e4806479f1350ab1508939c2fdcb53bungeman@google.comstatic inline uint16_t rgb_to_lcd16(SkGdiRGB rgb, const uint8_t* tableR, 115497efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com const uint8_t* tableG, 115597efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com const uint8_t* tableB) { 115697efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com U8CPU r = sk_apply_lut_if<APPLY_PREBLEND>((rgb >> 16) & 0xFF, tableR); 115797efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com U8CPU g = sk_apply_lut_if<APPLY_PREBLEND>((rgb >> 8) & 0xFF, tableG); 115897efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com U8CPU b = sk_apply_lut_if<APPLY_PREBLEND>((rgb >> 0) & 0xFF, tableB); 11590abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com#if SK_SHOW_TEXT_BLIT_COVERAGE 11600abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com r = SkMax32(r, 10); g = SkMax32(g, 10); b = SkMax32(b, 10); 11610abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com#endif 116297efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com return SkPack888ToRGB16(r, g, b); 1163ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com} 1164ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com 116597efada074e4806479f1350ab1508939c2fdcb53bungeman@google.comtemplate<bool APPLY_PREBLEND> 116697efada074e4806479f1350ab1508939c2fdcb53bungeman@google.comstatic inline SkPMColor rgb_to_lcd32(SkGdiRGB rgb, const uint8_t* tableR, 116797efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com const uint8_t* tableG, 116897efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com const uint8_t* tableB) { 116997efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com U8CPU r = sk_apply_lut_if<APPLY_PREBLEND>((rgb >> 16) & 0xFF, tableR); 117097efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com U8CPU g = sk_apply_lut_if<APPLY_PREBLEND>((rgb >> 8) & 0xFF, tableG); 117197efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com U8CPU b = sk_apply_lut_if<APPLY_PREBLEND>((rgb >> 0) & 0xFF, tableB); 11720abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com#if SK_SHOW_TEXT_BLIT_COVERAGE 11730abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com r = SkMax32(r, 10); g = SkMax32(g, 10); b = SkMax32(b, 10); 11740abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com#endif 117597efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com return SkPackARGB32(0xFF, r, g, b); 1176754e4ebd10d7353ce55be7dfe0a417e502ef4047reed@google.com} 1177754e4ebd10d7353ce55be7dfe0a417e502ef4047reed@google.com 117882cff020b7e055f2d01686f060a884df842306edreed@google.com// Is this GDI color neither black nor white? If so, we have to keep this 117982cff020b7e055f2d01686f060a884df842306edreed@google.com// image as is, rather than smashing it down to a BW mask. 118082cff020b7e055f2d01686f060a884df842306edreed@google.com// 118182cff020b7e055f2d01686f060a884df842306edreed@google.com// returns int instead of bool, since we don't want/have to pay to convert 118282cff020b7e055f2d01686f060a884df842306edreed@google.com// the zero/non-zero value into a bool 118382cff020b7e055f2d01686f060a884df842306edreed@google.comstatic int is_not_black_or_white(SkGdiRGB c) { 118482cff020b7e055f2d01686f060a884df842306edreed@google.com // same as (but faster than) 118582cff020b7e055f2d01686f060a884df842306edreed@google.com // c &= 0x00FFFFFF; 118682cff020b7e055f2d01686f060a884df842306edreed@google.com // return 0 == c || 0x00FFFFFF == c; 118782cff020b7e055f2d01686f060a884df842306edreed@google.com return (c + (c & 1)) & 0x00FFFFFF; 11885e2df64215f12660ab26b96816f40ad8e32bf16freed@google.com} 11895e2df64215f12660ab26b96816f40ad8e32bf16freed@google.com 11904b18f5767ab1df7fedf0ff2e3a9eac7f7c500c36bungeman@google.comstatic bool is_rgb_really_bw(const SkGdiRGB* src, int width, int height, size_t srcRB) { 11915e2df64215f12660ab26b96816f40ad8e32bf16freed@google.com for (int y = 0; y < height; ++y) { 11925e2df64215f12660ab26b96816f40ad8e32bf16freed@google.com for (int x = 0; x < width; ++x) { 119382cff020b7e055f2d01686f060a884df842306edreed@google.com if (is_not_black_or_white(src[x])) { 11945e2df64215f12660ab26b96816f40ad8e32bf16freed@google.com return false; 11955e2df64215f12660ab26b96816f40ad8e32bf16freed@google.com } 11965e2df64215f12660ab26b96816f40ad8e32bf16freed@google.com } 119705a729ff90f75ac013873742ee0e4ae7e5e6e415bungeman@google.com src = SkTAddOffset<const SkGdiRGB>(src, srcRB); 11985e2df64215f12660ab26b96816f40ad8e32bf16freed@google.com } 11995e2df64215f12660ab26b96816f40ad8e32bf16freed@google.com return true; 12005e2df64215f12660ab26b96816f40ad8e32bf16freed@google.com} 12015e2df64215f12660ab26b96816f40ad8e32bf16freed@google.com 120297efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com// gdi's bitmap is upside-down, so we reverse dst walking in Y 120397efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com// whenever we copy it into skia's buffer 12045e2df64215f12660ab26b96816f40ad8e32bf16freed@google.comstatic void rgb_to_bw(const SkGdiRGB* SK_RESTRICT src, size_t srcRB, 120597efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com const SkGlyph& glyph) { 12065e2df64215f12660ab26b96816f40ad8e32bf16freed@google.com const int width = glyph.fWidth; 12075e2df64215f12660ab26b96816f40ad8e32bf16freed@google.com const size_t dstRB = (width + 7) >> 3; 12085e2df64215f12660ab26b96816f40ad8e32bf16freed@google.com uint8_t* SK_RESTRICT dst = (uint8_t*)((char*)glyph.fImage + (glyph.fHeight - 1) * dstRB); 12095e2df64215f12660ab26b96816f40ad8e32bf16freed@google.com 12105e2df64215f12660ab26b96816f40ad8e32bf16freed@google.com int byteCount = width >> 3; 12115e2df64215f12660ab26b96816f40ad8e32bf16freed@google.com int bitCount = width & 7; 12125e2df64215f12660ab26b96816f40ad8e32bf16freed@google.com 12135e2df64215f12660ab26b96816f40ad8e32bf16freed@google.com // adjust srcRB to skip the values in our byteCount loop, 12145e2df64215f12660ab26b96816f40ad8e32bf16freed@google.com // since we increment src locally there 12155e2df64215f12660ab26b96816f40ad8e32bf16freed@google.com srcRB -= byteCount * 8 * sizeof(SkGdiRGB); 12165e2df64215f12660ab26b96816f40ad8e32bf16freed@google.com 12175e2df64215f12660ab26b96816f40ad8e32bf16freed@google.com for (int y = 0; y < glyph.fHeight; ++y) { 12185e2df64215f12660ab26b96816f40ad8e32bf16freed@google.com if (byteCount > 0) { 12195e2df64215f12660ab26b96816f40ad8e32bf16freed@google.com for (int i = 0; i < byteCount; ++i) { 12207a230142e01c5a8cf955be12a5f287589b551634reed@google.com unsigned byte = 0; 122197efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com byte |= src[0] & (1 << 7); 122297efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com byte |= src[1] & (1 << 6); 122397efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com byte |= src[2] & (1 << 5); 122497efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com byte |= src[3] & (1 << 4); 122597efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com byte |= src[4] & (1 << 3); 122697efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com byte |= src[5] & (1 << 2); 122797efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com byte |= src[6] & (1 << 1); 122897efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com byte |= src[7] & (1 << 0); 12296a8f14d9633b330fb8051581828a0aaf4403d1a9reed@google.com dst[i] = byte; 12305e2df64215f12660ab26b96816f40ad8e32bf16freed@google.com src += 8; 12315e2df64215f12660ab26b96816f40ad8e32bf16freed@google.com } 12325e2df64215f12660ab26b96816f40ad8e32bf16freed@google.com } 12335e2df64215f12660ab26b96816f40ad8e32bf16freed@google.com if (bitCount > 0) { 12345e2df64215f12660ab26b96816f40ad8e32bf16freed@google.com unsigned byte = 0; 12355e2df64215f12660ab26b96816f40ad8e32bf16freed@google.com unsigned mask = 0x80; 12365e2df64215f12660ab26b96816f40ad8e32bf16freed@google.com for (int i = 0; i < bitCount; i++) { 123797efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com byte |= src[i] & mask; 12385e2df64215f12660ab26b96816f40ad8e32bf16freed@google.com mask >>= 1; 12395e2df64215f12660ab26b96816f40ad8e32bf16freed@google.com } 12405e2df64215f12660ab26b96816f40ad8e32bf16freed@google.com dst[byteCount] = byte; 12415e2df64215f12660ab26b96816f40ad8e32bf16freed@google.com } 124205a729ff90f75ac013873742ee0e4ae7e5e6e415bungeman@google.com src = SkTAddOffset<const SkGdiRGB>(src, srcRB); 12435e2df64215f12660ab26b96816f40ad8e32bf16freed@google.com dst -= dstRB; 12445e2df64215f12660ab26b96816f40ad8e32bf16freed@google.com } 12450abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com#if SK_SHOW_TEXT_BLIT_COVERAGE 12460abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com if (glyph.fWidth > 0 && glyph.fHeight > 0) { 12470abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com uint8_t* first = (uint8_t*)glyph.fImage; 12480abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com uint8_t* last = (uint8_t*)((char*)glyph.fImage + glyph.fHeight * dstRB - 1); 12490abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com *first |= 1 << 7; 12500abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com *last |= bitCount == 0 ? 1 : 1 << (8 - bitCount); 12510abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com } 12520abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com#endif 12535e2df64215f12660ab26b96816f40ad8e32bf16freed@google.com} 12545e2df64215f12660ab26b96816f40ad8e32bf16freed@google.com 125597efada074e4806479f1350ab1508939c2fdcb53bungeman@google.comtemplate<bool APPLY_PREBLEND> 12565e2df64215f12660ab26b96816f40ad8e32bf16freed@google.comstatic void rgb_to_a8(const SkGdiRGB* SK_RESTRICT src, size_t srcRB, 125797efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com const SkGlyph& glyph, const uint8_t* table8) { 12585e2df64215f12660ab26b96816f40ad8e32bf16freed@google.com const size_t dstRB = glyph.rowBytes(); 12595e2df64215f12660ab26b96816f40ad8e32bf16freed@google.com const int width = glyph.fWidth; 12605e2df64215f12660ab26b96816f40ad8e32bf16freed@google.com uint8_t* SK_RESTRICT dst = (uint8_t*)((char*)glyph.fImage + (glyph.fHeight - 1) * dstRB); 12615e2df64215f12660ab26b96816f40ad8e32bf16freed@google.com 12625e2df64215f12660ab26b96816f40ad8e32bf16freed@google.com for (int y = 0; y < glyph.fHeight; y++) { 12635e2df64215f12660ab26b96816f40ad8e32bf16freed@google.com for (int i = 0; i < width; i++) { 126497efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com dst[i] = rgb_to_a8<APPLY_PREBLEND>(src[i], table8); 12650abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com#if SK_SHOW_TEXT_BLIT_COVERAGE 12660abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com dst[i] = SkMax32(dst[i], 10); 12670abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com#endif 12685e2df64215f12660ab26b96816f40ad8e32bf16freed@google.com } 126905a729ff90f75ac013873742ee0e4ae7e5e6e415bungeman@google.com src = SkTAddOffset<const SkGdiRGB>(src, srcRB); 12705e2df64215f12660ab26b96816f40ad8e32bf16freed@google.com dst -= dstRB; 12715e2df64215f12660ab26b96816f40ad8e32bf16freed@google.com } 12725e2df64215f12660ab26b96816f40ad8e32bf16freed@google.com} 12735e2df64215f12660ab26b96816f40ad8e32bf16freed@google.com 127497efada074e4806479f1350ab1508939c2fdcb53bungeman@google.comtemplate<bool APPLY_PREBLEND> 127597efada074e4806479f1350ab1508939c2fdcb53bungeman@google.comstatic void rgb_to_lcd16(const SkGdiRGB* SK_RESTRICT src, size_t srcRB, const SkGlyph& glyph, 127697efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com const uint8_t* tableR, const uint8_t* tableG, const uint8_t* tableB) { 12775e2df64215f12660ab26b96816f40ad8e32bf16freed@google.com const size_t dstRB = glyph.rowBytes(); 12785e2df64215f12660ab26b96816f40ad8e32bf16freed@google.com const int width = glyph.fWidth; 12795e2df64215f12660ab26b96816f40ad8e32bf16freed@google.com uint16_t* SK_RESTRICT dst = (uint16_t*)((char*)glyph.fImage + (glyph.fHeight - 1) * dstRB); 12805e2df64215f12660ab26b96816f40ad8e32bf16freed@google.com 12815e2df64215f12660ab26b96816f40ad8e32bf16freed@google.com for (int y = 0; y < glyph.fHeight; y++) { 12825e2df64215f12660ab26b96816f40ad8e32bf16freed@google.com for (int i = 0; i < width; i++) { 128397efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com dst[i] = rgb_to_lcd16<APPLY_PREBLEND>(src[i], tableR, tableG, tableB); 12845e2df64215f12660ab26b96816f40ad8e32bf16freed@google.com } 128505a729ff90f75ac013873742ee0e4ae7e5e6e415bungeman@google.com src = SkTAddOffset<const SkGdiRGB>(src, srcRB); 12865e2df64215f12660ab26b96816f40ad8e32bf16freed@google.com dst = (uint16_t*)((char*)dst - dstRB); 12875e2df64215f12660ab26b96816f40ad8e32bf16freed@google.com } 12885e2df64215f12660ab26b96816f40ad8e32bf16freed@google.com} 12895e2df64215f12660ab26b96816f40ad8e32bf16freed@google.com 129097efada074e4806479f1350ab1508939c2fdcb53bungeman@google.comtemplate<bool APPLY_PREBLEND> 129197efada074e4806479f1350ab1508939c2fdcb53bungeman@google.comstatic void rgb_to_lcd32(const SkGdiRGB* SK_RESTRICT src, size_t srcRB, const SkGlyph& glyph, 129297efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com const uint8_t* tableR, const uint8_t* tableG, const uint8_t* tableB) { 1293754e4ebd10d7353ce55be7dfe0a417e502ef4047reed@google.com const size_t dstRB = glyph.rowBytes(); 1294754e4ebd10d7353ce55be7dfe0a417e502ef4047reed@google.com const int width = glyph.fWidth; 129597efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com uint32_t* SK_RESTRICT dst = (uint32_t*)((char*)glyph.fImage + (glyph.fHeight - 1) * dstRB); 1296754e4ebd10d7353ce55be7dfe0a417e502ef4047reed@google.com 1297754e4ebd10d7353ce55be7dfe0a417e502ef4047reed@google.com for (int y = 0; y < glyph.fHeight; y++) { 1298754e4ebd10d7353ce55be7dfe0a417e502ef4047reed@google.com for (int i = 0; i < width; i++) { 129997efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com dst[i] = rgb_to_lcd32<APPLY_PREBLEND>(src[i], tableR, tableG, tableB); 1300754e4ebd10d7353ce55be7dfe0a417e502ef4047reed@google.com } 130105a729ff90f75ac013873742ee0e4ae7e5e6e415bungeman@google.com src = SkTAddOffset<const SkGdiRGB>(src, srcRB); 130297efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com dst = (uint32_t*)((char*)dst - dstRB); 1303754e4ebd10d7353ce55be7dfe0a417e502ef4047reed@google.com } 1304754e4ebd10d7353ce55be7dfe0a417e502ef4047reed@google.com} 1305754e4ebd10d7353ce55be7dfe0a417e502ef4047reed@google.com 13066f5df48c1d07295b75c1955a69142fb5e66b8647reed@google.comstatic inline unsigned clamp255(unsigned x) { 13076f5df48c1d07295b75c1955a69142fb5e66b8647reed@google.com SkASSERT(x <= 256); 13086f5df48c1d07295b75c1955a69142fb5e66b8647reed@google.com return x - (x >> 8); 13096f5df48c1d07295b75c1955a69142fb5e66b8647reed@google.com} 13106f5df48c1d07295b75c1955a69142fb5e66b8647reed@google.com 131130ddd615c447fed73286151b463af20d309c85f1reed@google.comvoid SkScalerContext_GDI::generateImage(const SkGlyph& glyph) { 1312ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com SkASSERT(fDDC); 1313ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com 13146271117d826098c1399cf7442f8eea2d665cb78areed@google.com const bool isBW = SkMask::kBW_Format == fRec.fMaskFormat; 131582a34d83f646d069ef2d1d7b649d0a0b1829d62freed@google.com const bool isAA = !isLCD(fRec); 131682a34d83f646d069ef2d1d7b649d0a0b1829d62freed@google.com 131799edd43813b7f1a8f02146cbd8c783d3c82be4abreed@google.com size_t srcRB; 131897efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com const void* bits = fOffscreen.draw(glyph, isBW, &srcRB); 131939698b1bd71fd54c7c44ae8d7224afdaf93c0ddabungeman@google.com if (NULL == bits) { 1320055180cb9c47c87e5ee8c9fa6d3f6a6079ad6f35reed@google.com LogFontTypeface::EnsureAccessible(this->getTypeface()); 132197efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com bits = fOffscreen.draw(glyph, isBW, &srcRB); 132239698b1bd71fd54c7c44ae8d7224afdaf93c0ddabungeman@google.com if (NULL == bits) { 132339698b1bd71fd54c7c44ae8d7224afdaf93c0ddabungeman@google.com sk_bzero(glyph.fImage, glyph.computeImageSize()); 132439698b1bd71fd54c7c44ae8d7224afdaf93c0ddabungeman@google.com return; 132539698b1bd71fd54c7c44ae8d7224afdaf93c0ddabungeman@google.com } 132682a34d83f646d069ef2d1d7b649d0a0b1829d62freed@google.com } 132782a34d83f646d069ef2d1d7b649d0a0b1829d62freed@google.com 132897efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com if (!isBW) { 13291bd2d67702a5c14011f02e23b3724965f82c4780bungeman@google.com const uint8_t* table; 13301bd2d67702a5c14011f02e23b3724965f82c4780bungeman@google.com //The offscreen contains a GDI blit if isAA and kGenA8FromLCD_Flag is not set. 13311bd2d67702a5c14011f02e23b3724965f82c4780bungeman@google.com //Otherwise the offscreen contains a ClearType blit. 13321bd2d67702a5c14011f02e23b3724965f82c4780bungeman@google.com if (isAA && !(fRec.fFlags & SkScalerContext::kGenA8FromLCD_Flag)) { 13331bd2d67702a5c14011f02e23b3724965f82c4780bungeman@google.com table = getInverseGammaTableGDI(); 13341bd2d67702a5c14011f02e23b3724965f82c4780bungeman@google.com } else { 13351bd2d67702a5c14011f02e23b3724965f82c4780bungeman@google.com table = getInverseGammaTableClearType(); 133697efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com } 133797efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com //Note that the following cannot really be integrated into the 133897efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com //pre-blend, since we may not be applying the pre-blend; when we aren't 133997efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com //applying the pre-blend it means that a filter wants linear anyway. 134097efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com //Other code may also be applying the pre-blend, so we'd need another 134197efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com //one with this and one without. 13426f5df48c1d07295b75c1955a69142fb5e66b8647reed@google.com SkGdiRGB* addr = (SkGdiRGB*)bits; 13436f5df48c1d07295b75c1955a69142fb5e66b8647reed@google.com for (int y = 0; y < glyph.fHeight; ++y) { 13446f5df48c1d07295b75c1955a69142fb5e66b8647reed@google.com for (int x = 0; x < glyph.fWidth; ++x) { 13456f5df48c1d07295b75c1955a69142fb5e66b8647reed@google.com int r = (addr[x] >> 16) & 0xFF; 13466f5df48c1d07295b75c1955a69142fb5e66b8647reed@google.com int g = (addr[x] >> 8) & 0xFF; 13476f5df48c1d07295b75c1955a69142fb5e66b8647reed@google.com int b = (addr[x] >> 0) & 0xFF; 13487430a3376c0f4e0c2809fedecd12765034f9e3a8reed@google.com addr[x] = (table[r] << 16) | (table[g] << 8) | table[b]; 13496f5df48c1d07295b75c1955a69142fb5e66b8647reed@google.com } 135005a729ff90f75ac013873742ee0e4ae7e5e6e415bungeman@google.com addr = SkTAddOffset<SkGdiRGB>(addr, srcRB); 13516f5df48c1d07295b75c1955a69142fb5e66b8647reed@google.com } 13526f5df48c1d07295b75c1955a69142fb5e66b8647reed@google.com } 13536f5df48c1d07295b75c1955a69142fb5e66b8647reed@google.com 135482a34d83f646d069ef2d1d7b649d0a0b1829d62freed@google.com int width = glyph.fWidth; 135582a34d83f646d069ef2d1d7b649d0a0b1829d62freed@google.com size_t dstRB = glyph.rowBytes(); 135682a34d83f646d069ef2d1d7b649d0a0b1829d62freed@google.com if (isBW) { 135782a34d83f646d069ef2d1d7b649d0a0b1829d62freed@google.com const uint8_t* src = (const uint8_t*)bits; 135882a34d83f646d069ef2d1d7b649d0a0b1829d62freed@google.com uint8_t* dst = (uint8_t*)((char*)glyph.fImage + (glyph.fHeight - 1) * dstRB); 135982a34d83f646d069ef2d1d7b649d0a0b1829d62freed@google.com for (int y = 0; y < glyph.fHeight; y++) { 136082a34d83f646d069ef2d1d7b649d0a0b1829d62freed@google.com memcpy(dst, src, dstRB); 136182a34d83f646d069ef2d1d7b649d0a0b1829d62freed@google.com src += srcRB; 136282a34d83f646d069ef2d1d7b649d0a0b1829d62freed@google.com dst -= dstRB; 1363ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com } 13640abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com#if SK_SHOW_TEXT_BLIT_COVERAGE 13650abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com if (glyph.fWidth > 0 && glyph.fHeight > 0) { 13660abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com int bitCount = width & 7; 13670abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com uint8_t* first = (uint8_t*)glyph.fImage; 13680abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com uint8_t* last = (uint8_t*)((char*)glyph.fImage + glyph.fHeight * dstRB - 1); 13690abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com *first |= 1 << 7; 13700abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com *last |= bitCount == 0 ? 1 : 1 << (8 - bitCount); 13710abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com } 13720abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com#endif 137382a34d83f646d069ef2d1d7b649d0a0b1829d62freed@google.com } else if (isAA) { 13746f5df48c1d07295b75c1955a69142fb5e66b8647reed@google.com // since the caller may require A8 for maskfilters, we can't check for BW 13756f5df48c1d07295b75c1955a69142fb5e66b8647reed@google.com // ... until we have the caller tell us that explicitly 13765e2df64215f12660ab26b96816f40ad8e32bf16freed@google.com const SkGdiRGB* src = (const SkGdiRGB*)bits; 1377a76de72a6036da0a6b051b14411b80941971f881bungeman@google.com if (fPreBlend.isApplicable()) { 1378a76de72a6036da0a6b051b14411b80941971f881bungeman@google.com rgb_to_a8<true>(src, srcRB, glyph, fPreBlend.fG); 137997efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com } else { 1380a76de72a6036da0a6b051b14411b80941971f881bungeman@google.com rgb_to_a8<false>(src, srcRB, glyph, fPreBlend.fG); 138197efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com } 138282a34d83f646d069ef2d1d7b649d0a0b1829d62freed@google.com } else { // LCD16 13835e2df64215f12660ab26b96816f40ad8e32bf16freed@google.com const SkGdiRGB* src = (const SkGdiRGB*)bits; 13845e2df64215f12660ab26b96816f40ad8e32bf16freed@google.com if (is_rgb_really_bw(src, width, glyph.fHeight, srcRB)) { 138597efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com rgb_to_bw(src, srcRB, glyph); 13865e2df64215f12660ab26b96816f40ad8e32bf16freed@google.com ((SkGlyph*)&glyph)->fMaskFormat = SkMask::kBW_Format; 13875e2df64215f12660ab26b96816f40ad8e32bf16freed@google.com } else { 1388754e4ebd10d7353ce55be7dfe0a417e502ef4047reed@google.com if (SkMask::kLCD16_Format == glyph.fMaskFormat) { 1389a76de72a6036da0a6b051b14411b80941971f881bungeman@google.com if (fPreBlend.isApplicable()) { 1390a76de72a6036da0a6b051b14411b80941971f881bungeman@google.com rgb_to_lcd16<true>(src, srcRB, glyph, 1391a76de72a6036da0a6b051b14411b80941971f881bungeman@google.com fPreBlend.fR, fPreBlend.fG, fPreBlend.fB); 139297efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com } else { 1393a76de72a6036da0a6b051b14411b80941971f881bungeman@google.com rgb_to_lcd16<false>(src, srcRB, glyph, 1394a76de72a6036da0a6b051b14411b80941971f881bungeman@google.com fPreBlend.fR, fPreBlend.fG, fPreBlend.fB); 139597efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com } 1396754e4ebd10d7353ce55be7dfe0a417e502ef4047reed@google.com } else { 1397754e4ebd10d7353ce55be7dfe0a417e502ef4047reed@google.com SkASSERT(SkMask::kLCD32_Format == glyph.fMaskFormat); 1398a76de72a6036da0a6b051b14411b80941971f881bungeman@google.com if (fPreBlend.isApplicable()) { 1399a76de72a6036da0a6b051b14411b80941971f881bungeman@google.com rgb_to_lcd32<true>(src, srcRB, glyph, 1400a76de72a6036da0a6b051b14411b80941971f881bungeman@google.com fPreBlend.fR, fPreBlend.fG, fPreBlend.fB); 140197efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com } else { 1402a76de72a6036da0a6b051b14411b80941971f881bungeman@google.com rgb_to_lcd32<false>(src, srcRB, glyph, 1403a76de72a6036da0a6b051b14411b80941971f881bungeman@google.com fPreBlend.fR, fPreBlend.fG, fPreBlend.fB); 140497efada074e4806479f1350ab1508939c2fdcb53bungeman@google.com } 1405754e4ebd10d7353ce55be7dfe0a417e502ef4047reed@google.com } 1406ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com } 1407ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com } 1408ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com} 1409ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com 14100abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.comclass GDIGlyphbufferPointIter { 14110abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.compublic: 141227e21fe577211c1c40cbf40d0385b02c69d04522skia.committer@gmail.com GDIGlyphbufferPointIter(const uint8_t* glyphbuf, DWORD total_size) 14130abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com : fHeaderIter(glyphbuf, total_size), fCurveIter(), fPointIter() 14140abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com { } 14150abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com 1416dd88eccb22bd2cafcf0c0facf674a8aaaacca7febungeman@google.com POINTFX const * next() { 14170abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.comnextHeader: 14180abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com if (!fCurveIter.isSet()) { 14190abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com const TTPOLYGONHEADER* header = fHeaderIter.next(); 1420dd88eccb22bd2cafcf0c0facf674a8aaaacca7febungeman@google.com if (NULL == header) { 1421dd88eccb22bd2cafcf0c0facf674a8aaaacca7febungeman@google.com return NULL; 1422dd88eccb22bd2cafcf0c0facf674a8aaaacca7febungeman@google.com } 14230abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com fCurveIter.set(header); 14240abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com const TTPOLYCURVE* curve = fCurveIter.next(); 1425dd88eccb22bd2cafcf0c0facf674a8aaaacca7febungeman@google.com if (NULL == curve) { 1426dd88eccb22bd2cafcf0c0facf674a8aaaacca7febungeman@google.com return NULL; 1427dd88eccb22bd2cafcf0c0facf674a8aaaacca7febungeman@google.com } 14280abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com fPointIter.set(curve); 1429dd88eccb22bd2cafcf0c0facf674a8aaaacca7febungeman@google.com return &header->pfxStart; 14300abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com } 1431ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com 14320abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com const POINTFX* nextPoint = fPointIter.next(); 14330abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com if (NULL == nextPoint) { 14340abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com const TTPOLYCURVE* curve = fCurveIter.next(); 14350abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com if (NULL == curve) { 14360abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com fCurveIter.set(); 14370abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com goto nextHeader; 14380abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com } else { 14390abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com fPointIter.set(curve); 14400abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com } 14410abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com nextPoint = fPointIter.next(); 14420abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com } 1443dd88eccb22bd2cafcf0c0facf674a8aaaacca7febungeman@google.com return nextPoint; 14440abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com } 1445ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com 14460abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com WORD currentCurveType() { 14470abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com return fPointIter.fCurveType; 14480abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com } 144905a729ff90f75ac013873742ee0e4ae7e5e6e415bungeman@google.com 14500abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.comprivate: 14510abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com /** Iterates over all of the polygon headers in a glyphbuf. */ 14520abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com class GDIPolygonHeaderIter { 14530abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com public: 145427e21fe577211c1c40cbf40d0385b02c69d04522skia.committer@gmail.com GDIPolygonHeaderIter(const uint8_t* glyphbuf, DWORD total_size) 14550abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com : fCurPolygon(reinterpret_cast<const TTPOLYGONHEADER*>(glyphbuf)) 14560abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com , fEndPolygon(SkTAddOffset<const TTPOLYGONHEADER>(glyphbuf, total_size)) 14570abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com { } 14580abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com 14590abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com const TTPOLYGONHEADER* next() { 14600abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com if (fCurPolygon >= fEndPolygon) { 14610abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com return NULL; 14620abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com } 14630abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com const TTPOLYGONHEADER* thisPolygon = fCurPolygon; 14640abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com fCurPolygon = SkTAddOffset<const TTPOLYGONHEADER>(fCurPolygon, fCurPolygon->cb); 14650abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com return thisPolygon; 14660abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com } 14670abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com private: 14680abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com const TTPOLYGONHEADER* fCurPolygon; 14690abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com const TTPOLYGONHEADER* fEndPolygon; 14700abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com }; 147105a729ff90f75ac013873742ee0e4ae7e5e6e415bungeman@google.com 14720abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com /** Iterates over all of the polygon curves in a polygon header. */ 14730abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com class GDIPolygonCurveIter { 14740abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com public: 14750abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com GDIPolygonCurveIter() : fCurCurve(NULL), fEndCurve(NULL) { } 14760abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com 14770abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com GDIPolygonCurveIter(const TTPOLYGONHEADER* curPolygon) 14780abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com : fCurCurve(SkTAddOffset<const TTPOLYCURVE>(curPolygon, sizeof(TTPOLYGONHEADER))) 14790abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com , fEndCurve(SkTAddOffset<const TTPOLYCURVE>(curPolygon, curPolygon->cb)) 14800abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com { } 14810abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com 14820abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com bool isSet() { return fCurCurve != NULL; } 14830abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com 14840abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com void set(const TTPOLYGONHEADER* curPolygon) { 14850abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com fCurCurve = SkTAddOffset<const TTPOLYCURVE>(curPolygon, sizeof(TTPOLYGONHEADER)); 14860abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com fEndCurve = SkTAddOffset<const TTPOLYCURVE>(curPolygon, curPolygon->cb); 14870abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com } 14880abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com void set() { 14890abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com fCurCurve = NULL; 14900abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com fEndCurve = NULL; 14910abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com } 14920abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com 14930abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com const TTPOLYCURVE* next() { 14940abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com if (fCurCurve >= fEndCurve) { 14950abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com return NULL; 149605a729ff90f75ac013873742ee0e4ae7e5e6e415bungeman@google.com } 14970abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com const TTPOLYCURVE* thisCurve = fCurCurve; 14980abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com fCurCurve = SkTAddOffset<const TTPOLYCURVE>(fCurCurve, size_of_TTPOLYCURVE(*fCurCurve)); 14990abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com return thisCurve; 15000abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com } 15010abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com private: 15020abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com size_t size_of_TTPOLYCURVE(const TTPOLYCURVE& curve) { 15030abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com return 2*sizeof(WORD) + curve.cpfx*sizeof(POINTFX); 150405a729ff90f75ac013873742ee0e4ae7e5e6e415bungeman@google.com } 15050abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com const TTPOLYCURVE* fCurCurve; 15060abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com const TTPOLYCURVE* fEndCurve; 15070abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com }; 150805a729ff90f75ac013873742ee0e4ae7e5e6e415bungeman@google.com 15090abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com /** Iterates over all of the polygon points in a polygon curve. */ 15100abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com class GDIPolygonCurvePointIter { 15110abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com public: 15120abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com GDIPolygonCurvePointIter() : fCurveType(0), fCurPoint(NULL), fEndPoint(NULL) { } 151305a729ff90f75ac013873742ee0e4ae7e5e6e415bungeman@google.com 15140abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com GDIPolygonCurvePointIter(const TTPOLYCURVE* curPolygon) 15150abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com : fCurveType(curPolygon->wType) 15160abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com , fCurPoint(&curPolygon->apfx[0]) 15170abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com , fEndPoint(&curPolygon->apfx[curPolygon->cpfx]) 15180abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com { } 15190abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com 15200abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com bool isSet() { return fCurPoint != NULL; } 15210abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com 15220abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com void set(const TTPOLYCURVE* curPolygon) { 15230abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com fCurveType = curPolygon->wType; 15240abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com fCurPoint = &curPolygon->apfx[0]; 15250abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com fEndPoint = &curPolygon->apfx[curPolygon->cpfx]; 15260abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com } 15270abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com void set() { 15280abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com fCurPoint = NULL; 15290abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com fEndPoint = NULL; 15300abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com } 15310abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com 15320abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com const POINTFX* next() { 15330abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com if (fCurPoint >= fEndPoint) { 15340abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com return NULL; 153505a729ff90f75ac013873742ee0e4ae7e5e6e415bungeman@google.com } 15360abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com const POINTFX* thisPoint = fCurPoint; 15370abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com ++fCurPoint; 15380abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com return thisPoint; 1539d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com } 1540ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com 15410abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com WORD fCurveType; 15420abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com private: 15430abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com const POINTFX* fCurPoint; 15440abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com const POINTFX* fEndPoint; 15450abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com }; 15460abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com 15470abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com GDIPolygonHeaderIter fHeaderIter; 15480abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com GDIPolygonCurveIter fCurveIter; 15490abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com GDIPolygonCurvePointIter fPointIter; 15500abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com}; 15510abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com 15520abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.comstatic void sk_path_from_gdi_path(SkPath* path, const uint8_t* glyphbuf, DWORD total_size) { 1553d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com const uint8_t* cur_glyph = glyphbuf; 1554d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com const uint8_t* end_glyph = glyphbuf + total_size; 1555ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com 1556d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com while (cur_glyph < end_glyph) { 1557d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com const TTPOLYGONHEADER* th = (TTPOLYGONHEADER*)cur_glyph; 1558ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com 1559d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com const uint8_t* end_poly = cur_glyph + th->cb; 1560d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com const uint8_t* cur_poly = cur_glyph + sizeof(TTPOLYGONHEADER); 1561ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com 1562d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com path->moveTo(SkFixedToScalar( SkFIXEDToFixed(th->pfxStart.x)), 1563d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com SkFixedToScalar(-SkFIXEDToFixed(th->pfxStart.y))); 1564ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com 1565d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com while (cur_poly < end_poly) { 1566d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com const TTPOLYCURVE* pc = (const TTPOLYCURVE*)cur_poly; 1567ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com 1568d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com if (pc->wType == TT_PRIM_LINE) { 1569d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com for (uint16_t i = 0; i < pc->cpfx; i++) { 1570d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com path->lineTo(SkFixedToScalar( SkFIXEDToFixed(pc->apfx[i].x)), 1571d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com SkFixedToScalar(-SkFIXEDToFixed(pc->apfx[i].y))); 1572ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com } 1573d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com } 1574ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com 1575d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com if (pc->wType == TT_PRIM_QSPLINE) { 1576d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com for (uint16_t u = 0; u < pc->cpfx - 1; u++) { // Walk through points in spline 1577d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com POINTFX pnt_b = pc->apfx[u]; // B is always the current point 1578d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com POINTFX pnt_c = pc->apfx[u+1]; 1579ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com 1580d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com if (u < pc->cpfx - 2) { // If not on last spline, compute C 1581d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com pnt_c.x = SkFixedToFIXED(SkFixedAve(SkFIXEDToFixed(pnt_b.x), 1582d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com SkFIXEDToFixed(pnt_c.x))); 1583d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com pnt_c.y = SkFixedToFIXED(SkFixedAve(SkFIXEDToFixed(pnt_b.y), 1584d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com SkFIXEDToFixed(pnt_c.y))); 1585ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com } 1586d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com 1587d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com path->quadTo(SkFixedToScalar( SkFIXEDToFixed(pnt_b.x)), 1588d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com SkFixedToScalar(-SkFIXEDToFixed(pnt_b.y)), 1589d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com SkFixedToScalar( SkFIXEDToFixed(pnt_c.x)), 1590d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com SkFixedToScalar(-SkFIXEDToFixed(pnt_c.y))); 1591ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com } 1592ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com } 1593d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com // Advance past this TTPOLYCURVE. 1594d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com cur_poly += sizeof(WORD) * 2 + sizeof(POINTFX) * pc->cpfx; 1595ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com } 1596d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com cur_glyph += th->cb; 1597d1c7f71ee371738a8c7896a4f06d28b32e3c713ebungeman@google.com path->close(); 1598ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com } 1599ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com} 1600ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com 1601dd88eccb22bd2cafcf0c0facf674a8aaaacca7febungeman@google.com#define move_next_expected_hinted_point(iter, pElem) do {\ 1602dd88eccb22bd2cafcf0c0facf674a8aaaacca7febungeman@google.com pElem = iter.next(); \ 1603dd88eccb22bd2cafcf0c0facf674a8aaaacca7febungeman@google.com if (NULL == pElem) return false; \ 1604dd88eccb22bd2cafcf0c0facf674a8aaaacca7febungeman@google.com} while(0) 1605dd88eccb22bd2cafcf0c0facf674a8aaaacca7febungeman@google.com 1606dd88eccb22bd2cafcf0c0facf674a8aaaacca7febungeman@google.com// It is possible for the hinted and unhinted versions of the same path to have 1607dd88eccb22bd2cafcf0c0facf674a8aaaacca7febungeman@google.com// a different number of points due to GDI's handling of flipped points. 1608dd88eccb22bd2cafcf0c0facf674a8aaaacca7febungeman@google.com// If this is detected, this will return false. 1609dd88eccb22bd2cafcf0c0facf674a8aaaacca7febungeman@google.comstatic bool sk_path_from_gdi_paths(SkPath* path, const uint8_t* glyphbuf, DWORD total_size, 16100abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com GDIGlyphbufferPointIter hintedYs) { 16110abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com const uint8_t* cur_glyph = glyphbuf; 16120abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com const uint8_t* end_glyph = glyphbuf + total_size; 16130abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com 1614dd88eccb22bd2cafcf0c0facf674a8aaaacca7febungeman@google.com POINTFX const * hintedPoint; 1615dd88eccb22bd2cafcf0c0facf674a8aaaacca7febungeman@google.com 16160abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com while (cur_glyph < end_glyph) { 16170abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com const TTPOLYGONHEADER* th = (TTPOLYGONHEADER*)cur_glyph; 16180abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com 16190abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com const uint8_t* end_poly = cur_glyph + th->cb; 16200abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com const uint8_t* cur_poly = cur_glyph + sizeof(TTPOLYGONHEADER); 16210abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com 1622dd88eccb22bd2cafcf0c0facf674a8aaaacca7febungeman@google.com move_next_expected_hinted_point(hintedYs, hintedPoint); 16230abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com path->moveTo(SkFixedToScalar( SkFIXEDToFixed(th->pfxStart.x)), 1624dd88eccb22bd2cafcf0c0facf674a8aaaacca7febungeman@google.com SkFixedToScalar(-SkFIXEDToFixed(hintedPoint->y))); 16250abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com 16260abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com while (cur_poly < end_poly) { 16270abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com const TTPOLYCURVE* pc = (const TTPOLYCURVE*)cur_poly; 16280abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com 16290abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com if (pc->wType == TT_PRIM_LINE) { 16300abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com for (uint16_t i = 0; i < pc->cpfx; i++) { 1631dd88eccb22bd2cafcf0c0facf674a8aaaacca7febungeman@google.com move_next_expected_hinted_point(hintedYs, hintedPoint); 16320abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com path->lineTo(SkFixedToScalar( SkFIXEDToFixed(pc->apfx[i].x)), 1633dd88eccb22bd2cafcf0c0facf674a8aaaacca7febungeman@google.com SkFixedToScalar(-SkFIXEDToFixed(hintedPoint->y))); 16340abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com } 16350abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com } 16360abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com 16370abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com if (pc->wType == TT_PRIM_QSPLINE) { 16380abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com POINTFX currentPoint = pc->apfx[0]; 1639dd88eccb22bd2cafcf0c0facf674a8aaaacca7febungeman@google.com move_next_expected_hinted_point(hintedYs, hintedPoint); 16400abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com // only take the hinted y if it wasn't flipped 16410abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com if (hintedYs.currentCurveType() == TT_PRIM_QSPLINE) { 1642dd88eccb22bd2cafcf0c0facf674a8aaaacca7febungeman@google.com currentPoint.y = hintedPoint->y; 16430abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com } 16440abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com for (uint16_t u = 0; u < pc->cpfx - 1; u++) { // Walk through points in spline 16450abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com POINTFX pnt_b = currentPoint;//pc->apfx[u]; // B is always the current point 16460abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com POINTFX pnt_c = pc->apfx[u+1]; 1647dd88eccb22bd2cafcf0c0facf674a8aaaacca7febungeman@google.com move_next_expected_hinted_point(hintedYs, hintedPoint); 16480abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com // only take the hinted y if it wasn't flipped 16490abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com if (hintedYs.currentCurveType() == TT_PRIM_QSPLINE) { 1650dd88eccb22bd2cafcf0c0facf674a8aaaacca7febungeman@google.com pnt_c.y = hintedPoint->y; 16510abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com } 16520abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com currentPoint.x = pnt_c.x; 16530abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com currentPoint.y = pnt_c.y; 16540abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com 16550abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com if (u < pc->cpfx - 2) { // If not on last spline, compute C 16560abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com pnt_c.x = SkFixedToFIXED(SkFixedAve(SkFIXEDToFixed(pnt_b.x), 16570abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com SkFIXEDToFixed(pnt_c.x))); 16580abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com pnt_c.y = SkFixedToFIXED(SkFixedAve(SkFIXEDToFixed(pnt_b.y), 16590abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com SkFIXEDToFixed(pnt_c.y))); 16600abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com } 16610abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com 16620abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com path->quadTo(SkFixedToScalar( SkFIXEDToFixed(pnt_b.x)), 16630abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com SkFixedToScalar(-SkFIXEDToFixed(pnt_b.y)), 16640abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com SkFixedToScalar( SkFIXEDToFixed(pnt_c.x)), 16650abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com SkFixedToScalar(-SkFIXEDToFixed(pnt_c.y))); 16660abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com } 16670abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com } 16680abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com // Advance past this TTPOLYCURVE. 16690abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com cur_poly += sizeof(WORD) * 2 + sizeof(POINTFX) * pc->cpfx; 16700abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com } 16710abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com cur_glyph += th->cb; 16720abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com path->close(); 16730abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com } 1674dd88eccb22bd2cafcf0c0facf674a8aaaacca7febungeman@google.com return true; 16750abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com} 16760abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com 167730ddd615c447fed73286151b463af20d309c85f1reed@google.comDWORD SkScalerContext_GDI::getGDIGlyphPath(const SkGlyph& glyph, UINT flags, 16780abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com SkAutoSTMalloc<BUFFERSIZE, uint8_t>* glyphbuf) 16790abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com{ 16800abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com GLYPHMETRICS gm; 16810abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com 16820abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com DWORD total_size = GetGlyphOutlineW(fDDC, glyph.fID, flags, &gm, BUFFERSIZE, glyphbuf->get(), &fMat22); 16830abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com // Sometimes GetGlyphOutlineW returns a number larger than BUFFERSIZE even if BUFFERSIZE > 0. 16840abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com // It has been verified that this does not involve a buffer overrun. 16850abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com if (GDI_ERROR == total_size || total_size > BUFFERSIZE) { 16860abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com // GDI_ERROR because the BUFFERSIZE was too small, or because the data was not accessible. 16870abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com // When the data is not accessable GetGlyphOutlineW fails rather quickly, 16880abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com // so just try to get the size. If that fails then ensure the data is accessible. 16890abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com total_size = GetGlyphOutlineW(fDDC, glyph.fID, flags, &gm, 0, NULL, &fMat22); 16900abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com if (GDI_ERROR == total_size) { 16910abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com LogFontTypeface::EnsureAccessible(this->getTypeface()); 16920abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com total_size = GetGlyphOutlineW(fDDC, glyph.fID, flags, &gm, 0, NULL, &fMat22); 16930abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com if (GDI_ERROR == total_size) { 16940abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com SkASSERT(false); 16950abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com return 0; 16960abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com } 16970abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com } 16980abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com 16990abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com glyphbuf->reset(total_size); 17000abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com 17010abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com DWORD ret = GetGlyphOutlineW(fDDC, glyph.fID, flags, &gm, total_size, glyphbuf->get(), &fMat22); 17020abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com if (GDI_ERROR == ret) { 17030abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com LogFontTypeface::EnsureAccessible(this->getTypeface()); 17040abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com ret = GetGlyphOutlineW(fDDC, glyph.fID, flags, &gm, total_size, glyphbuf->get(), &fMat22); 17050abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com if (GDI_ERROR == ret) { 17060abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com SkASSERT(false); 17070abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com return 0; 17080abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com } 17090abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com } 17100abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com } 17110abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com return total_size; 17120abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com} 17130abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com 171430ddd615c447fed73286151b463af20d309c85f1reed@google.comvoid SkScalerContext_GDI::generatePath(const SkGlyph& glyph, SkPath* path) { 17150abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com SkASSERT(&glyph && path); 17160abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com SkASSERT(fDDC); 17170abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com 17180abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com path->reset(); 17190abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com 17200abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com // Out of all the fonts on a typical Windows box, 17210abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com // 25% of glyphs require more than 2KB. 17220abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com // 1% of glyphs require more than 4KB. 17230abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com // 0.01% of glyphs require more than 8KB. 17240abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com // 8KB is less than 1% of the normal 1MB stack on Windows. 17250abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com // Note that some web fonts glyphs require more than 20KB. 17260abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com //static const DWORD BUFFERSIZE = (1 << 13); 17270abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com 17280abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com //GDI only uses hinted outlines when axis aligned. 17290abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com UINT format = GGO_NATIVE | GGO_GLYPH_INDEX; 17300abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com if (fRec.getHinting() == SkPaint::kNo_Hinting || fRec.getHinting() == SkPaint::kSlight_Hinting){ 17310abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com format |= GGO_UNHINTED; 17320abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com } 17330abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com SkAutoSTMalloc<BUFFERSIZE, uint8_t> glyphbuf(BUFFERSIZE); 17340abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com DWORD total_size = getGDIGlyphPath(glyph, format, &glyphbuf); 17350abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com if (0 == total_size) { 17360abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com return; 17370abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com } 17380abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com 17390abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com if (fRec.getHinting() != SkPaint::kSlight_Hinting) { 17400abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com sk_path_from_gdi_path(path, glyphbuf, total_size); 17410abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com } else { 17420abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com //GDI only uses hinted outlines when axis aligned. 17430abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com UINT format = GGO_NATIVE | GGO_GLYPH_INDEX; 17440abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com 17450abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com SkAutoSTMalloc<BUFFERSIZE, uint8_t> hintedGlyphbuf(BUFFERSIZE); 17460abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com DWORD hinted_total_size = getGDIGlyphPath(glyph, format, &hintedGlyphbuf); 17470abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com if (0 == hinted_total_size) { 17480abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com return; 17490abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com } 17500abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com 1751dd88eccb22bd2cafcf0c0facf674a8aaaacca7febungeman@google.com if (!sk_path_from_gdi_paths(path, glyphbuf, total_size, 1752dd88eccb22bd2cafcf0c0facf674a8aaaacca7febungeman@google.com GDIGlyphbufferPointIter(hintedGlyphbuf, hinted_total_size))) 1753dd88eccb22bd2cafcf0c0facf674a8aaaacca7febungeman@google.com { 1754dd88eccb22bd2cafcf0c0facf674a8aaaacca7febungeman@google.com path->reset(); 1755dd88eccb22bd2cafcf0c0facf674a8aaaacca7febungeman@google.com sk_path_from_gdi_path(path, glyphbuf, total_size); 1756dd88eccb22bd2cafcf0c0facf674a8aaaacca7febungeman@google.com } 17570abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com } 17580abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com} 17590abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com 1760484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.comstatic void logfont_for_name(const char* familyName, LOGFONT* lf) { 1761484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com sk_bzero(lf, sizeof(LOGFONT)); 1762e70f798ebca1a66f0b568fa46065ebbad9a13b2fbungeman@google.com#ifdef UNICODE 1763484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com // Get the buffer size needed first. 1764484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com size_t str_len = ::MultiByteToWideChar(CP_UTF8, 0, familyName, 1765484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com -1, NULL, 0); 1766484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com // Allocate a buffer (str_len already has terminating null 1767484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com // accounted for). 1768484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com wchar_t *wideFamilyName = new wchar_t[str_len]; 1769484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com // Now actually convert the string. 1770484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com ::MultiByteToWideChar(CP_UTF8, 0, familyName, -1, 1771484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com wideFamilyName, str_len); 1772484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com ::wcsncpy(lf->lfFaceName, wideFamilyName, LF_FACESIZE - 1); 1773484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com delete [] wideFamilyName; 1774484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com lf->lfFaceName[LF_FACESIZE-1] = L'\0'; 1775e70f798ebca1a66f0b568fa46065ebbad9a13b2fbungeman@google.com#else 1776484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com ::strncpy(lf->lfFaceName, familyName, LF_FACESIZE - 1); 1777484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com lf->lfFaceName[LF_FACESIZE - 1] = '\0'; 1778e70f798ebca1a66f0b568fa46065ebbad9a13b2fbungeman@google.com#endif 1779e70f798ebca1a66f0b568fa46065ebbad9a13b2fbungeman@google.com} 1780e70f798ebca1a66f0b568fa46065ebbad9a13b2fbungeman@google.com 17815526ede94a2fc58bcf6b578b12a29f6addad776dreed@google.comvoid LogFontTypeface::onGetFontDescriptor(SkFontDescriptor* desc, 17825526ede94a2fc58bcf6b578b12a29f6addad776dreed@google.com bool* isLocalStream) const { 17837103f182ce61280eacb35f1832df350b642a5381bungeman@google.com // Get the actual name of the typeface. The logfont may not know this. 17845526ede94a2fc58bcf6b578b12a29f6addad776dreed@google.com HFONT font = CreateFontIndirect(&fLogFont); 17857103f182ce61280eacb35f1832df350b642a5381bungeman@google.com 17867103f182ce61280eacb35f1832df350b642a5381bungeman@google.com HDC deviceContext = ::CreateCompatibleDC(NULL); 17877103f182ce61280eacb35f1832df350b642a5381bungeman@google.com HFONT savefont = (HFONT)SelectObject(deviceContext, font); 17887103f182ce61280eacb35f1832df350b642a5381bungeman@google.com 1789a980269c2498836101146adc729ef780fb89824ebungeman@google.com SkString familyName; 1790a980269c2498836101146adc729ef780fb89824ebungeman@google.com dcfontname_to_skstring(deviceContext, fLogFont, &familyName); 17917103f182ce61280eacb35f1832df350b642a5381bungeman@google.com 17927103f182ce61280eacb35f1832df350b642a5381bungeman@google.com if (deviceContext) { 17937103f182ce61280eacb35f1832df350b642a5381bungeman@google.com ::SelectObject(deviceContext, savefont); 17947103f182ce61280eacb35f1832df350b642a5381bungeman@google.com ::DeleteDC(deviceContext); 17957103f182ce61280eacb35f1832df350b642a5381bungeman@google.com } 17967103f182ce61280eacb35f1832df350b642a5381bungeman@google.com if (font) { 17977103f182ce61280eacb35f1832df350b642a5381bungeman@google.com ::DeleteObject(font); 17987103f182ce61280eacb35f1832df350b642a5381bungeman@google.com } 17997103f182ce61280eacb35f1832df350b642a5381bungeman@google.com 18005526ede94a2fc58bcf6b578b12a29f6addad776dreed@google.com desc->setFamilyName(familyName.c_str()); 18015526ede94a2fc58bcf6b578b12a29f6addad776dreed@google.com *isLocalStream = this->fSerializeAsStream; 1802ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com} 1803ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com 1804ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.comstatic bool getWidthAdvance(HDC hdc, int gId, int16_t* advance) { 1805ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com // Initialize the MAT2 structure to the identify transformation matrix. 1806ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com static const MAT2 mat2 = {SkScalarToFIXED(1), SkScalarToFIXED(0), 1807ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com SkScalarToFIXED(0), SkScalarToFIXED(1)}; 1808ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com int flags = GGO_METRICS | GGO_GLYPH_INDEX; 1809ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com GLYPHMETRICS gm; 1810ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com if (GDI_ERROR == GetGlyphOutline(hdc, gId, flags, &gm, 0, NULL, &mat2)) { 1811ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com return false; 1812ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com } 1813ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com SkASSERT(advance); 1814ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com *advance = gm.gmCellIncX; 1815ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com return true; 1816ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com} 1817ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com 18182689f615e364dc48ad73826564f5b13d2329179dreed@google.comSkAdvancedTypefaceMetrics* LogFontTypeface::onGetAdvancedTypefaceMetrics( 181937ad8fb72ff1b3faac93b01ead2c79e1a06fc172vandebo@chromium.org SkAdvancedTypefaceMetrics::PerGlyphInfo perGlyphInfo, 182037ad8fb72ff1b3faac93b01ead2c79e1a06fc172vandebo@chromium.org const uint32_t* glyphIDs, 18212689f615e364dc48ad73826564f5b13d2329179dreed@google.com uint32_t glyphIDsCount) const { 18222689f615e364dc48ad73826564f5b13d2329179dreed@google.com LOGFONT lf = fLogFont; 1823ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com SkAdvancedTypefaceMetrics* info = NULL; 1824ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com 1825ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com HDC hdc = CreateCompatibleDC(NULL); 1826ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com HFONT font = CreateFontIndirect(&lf); 1827ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com HFONT savefont = (HFONT)SelectObject(hdc, font); 1828ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com HFONT designFont = NULL; 1829ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com 183005b6f3a5a94de475d3a9dcfdd1833e24d933f207reed@google.com const char stem_chars[] = {'i', 'I', '!', '1'}; 183105b6f3a5a94de475d3a9dcfdd1833e24d933f207reed@google.com int16_t min_width; 183205b6f3a5a94de475d3a9dcfdd1833e24d933f207reed@google.com unsigned glyphCount; 183305b6f3a5a94de475d3a9dcfdd1833e24d933f207reed@google.com 1834ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com // To request design units, create a logical font whose height is specified 1835ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com // as unitsPerEm. 1836ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com OUTLINETEXTMETRIC otm; 183739698b1bd71fd54c7c44ae8d7224afdaf93c0ddabungeman@google.com unsigned int otmRet = GetOutlineTextMetrics(hdc, sizeof(otm), &otm); 183839698b1bd71fd54c7c44ae8d7224afdaf93c0ddabungeman@google.com if (0 == otmRet) { 1839055180cb9c47c87e5ee8c9fa6d3f6a6079ad6f35reed@google.com call_ensure_accessible(lf); 184039698b1bd71fd54c7c44ae8d7224afdaf93c0ddabungeman@google.com otmRet = GetOutlineTextMetrics(hdc, sizeof(otm), &otm); 184139698b1bd71fd54c7c44ae8d7224afdaf93c0ddabungeman@google.com } 184239698b1bd71fd54c7c44ae8d7224afdaf93c0ddabungeman@google.com if (!otmRet || !GetTextFace(hdc, LF_FACESIZE, lf.lfFaceName)) { 1843ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com goto Error; 1844ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com } 1845ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com lf.lfHeight = -SkToS32(otm.otmEMSquare); 1846ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com designFont = CreateFontIndirect(&lf); 1847ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com SelectObject(hdc, designFont); 1848ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com if (!GetOutlineTextMetrics(hdc, sizeof(otm), &otm)) { 1849ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com goto Error; 1850ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com } 18517bdd614a1940935d3badeb54f7aae75d76ea830dbungeman@google.com glyphCount = calculateGlyphCount(hdc, fLogFont); 1852ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com 1853ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com info = new SkAdvancedTypefaceMetrics; 1854ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com info->fEmSize = otm.otmEMSquare; 1855ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com info->fMultiMaster = false; 1856ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com info->fLastGlyphID = SkToU16(glyphCount - 1); 1857ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com info->fStyle = 0; 18587103f182ce61280eacb35f1832df350b642a5381bungeman@google.com tchar_to_skstring(lf.lfFaceName, &info->fFontName); 1859ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com 18606744d498fcbbbcf503ec80c4d43dd8f118a88597vandebo@chromium.org if (perGlyphInfo & SkAdvancedTypefaceMetrics::kToUnicode_PerGlyphInfo) { 18616744d498fcbbbcf503ec80c4d43dd8f118a88597vandebo@chromium.org populate_glyph_to_unicode(hdc, glyphCount, &(info->fGlyphToUnicode)); 18626744d498fcbbbcf503ec80c4d43dd8f118a88597vandebo@chromium.org } 18636744d498fcbbbcf503ec80c4d43dd8f118a88597vandebo@chromium.org 1864d41e70de196e78e21e1001d23a7259785cbd0835vandebo@chromium.org if (glyphCount > 0 && 1865d41e70de196e78e21e1001d23a7259785cbd0835vandebo@chromium.org (otm.otmTextMetrics.tmPitchAndFamily & TMPF_TRUETYPE)) { 1866ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com info->fType = SkAdvancedTypefaceMetrics::kTrueType_Font; 1867ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com } else { 1868ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com info->fType = SkAdvancedTypefaceMetrics::kOther_Font; 1869ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com info->fItalicAngle = 0; 1870ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com info->fAscent = 0; 1871ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com info->fDescent = 0; 1872ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com info->fStemV = 0; 1873ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com info->fCapHeight = 0; 1874ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com info->fBBox = SkIRect::MakeEmpty(); 1875390c6d7a9018e233a6519397ac6c739fb21a99efedisonn@google.com goto ReturnInfo; 1876ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com } 18775aa937b300475c956bfad0c34a6daa71d166f6factguil@chromium.org 1878ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com // If this bit is clear the font is a fixed pitch font. 1879ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com if (!(otm.otmTextMetrics.tmPitchAndFamily & TMPF_FIXED_PITCH)) { 1880ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com info->fStyle |= SkAdvancedTypefaceMetrics::kFixedPitch_Style; 1881ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com } 1882ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com if (otm.otmTextMetrics.tmItalic) { 1883ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com info->fStyle |= SkAdvancedTypefaceMetrics::kItalic_Style; 1884ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com } 1885ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com if (otm.otmTextMetrics.tmPitchAndFamily & FF_ROMAN) { 1886ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com info->fStyle |= SkAdvancedTypefaceMetrics::kSerif_Style; 1887ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com } else if (otm.otmTextMetrics.tmPitchAndFamily & FF_SCRIPT) { 1888ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com info->fStyle |= SkAdvancedTypefaceMetrics::kScript_Style; 1889ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com } 1890ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com 1891ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com // The main italic angle of the font, in tenths of a degree counterclockwise 1892ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com // from vertical. 1893ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com info->fItalicAngle = otm.otmItalicAngle / 10; 1894ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com info->fAscent = SkToS16(otm.otmTextMetrics.tmAscent); 1895ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com info->fDescent = SkToS16(-otm.otmTextMetrics.tmDescent); 1896ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com // TODO(ctguil): Use alternate cap height calculation. 1897ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com // MSDN says otmsCapEmHeight is not support but it is returning a value on 1898ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com // my Win7 box. 1899ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com info->fCapHeight = otm.otmsCapEmHeight; 1900ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com info->fBBox = 1901ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com SkIRect::MakeLTRB(otm.otmrcFontBox.left, otm.otmrcFontBox.top, 1902ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com otm.otmrcFontBox.right, otm.otmrcFontBox.bottom); 1903ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com 1904ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com // Figure out a good guess for StemV - Min width of i, I, !, 1. 1905ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com // This probably isn't very good with an italic font. 190605b6f3a5a94de475d3a9dcfdd1833e24d933f207reed@google.com min_width = SHRT_MAX; 1907ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com info->fStemV = 0; 1908ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com for (size_t i = 0; i < SK_ARRAY_COUNT(stem_chars); i++) { 1909ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com ABC abcWidths; 1910ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com if (GetCharABCWidths(hdc, stem_chars[i], stem_chars[i], &abcWidths)) { 1911ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com int16_t width = abcWidths.abcB; 1912ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com if (width > 0 && width < min_width) { 1913ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com min_width = width; 1914ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com info->fStemV = min_width; 1915ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com } 1916ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com } 1917ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com } 1918ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com 1919ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com // If bit 1 is set, the font may not be embedded in a document. 1920ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com // If bit 1 is clear, the font can be embedded. 1921ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com // If bit 2 is set, the embedding is read-only. 1922ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com if (otm.otmfsType & 0x1) { 1923ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com info->fType = SkAdvancedTypefaceMetrics::kNotEmbeddable_Font; 19240e6dc0a320985ffd31f77eed8a41e62132b9ba95ctguil@chromium.org } else if (perGlyphInfo & 19250e6dc0a320985ffd31f77eed8a41e62132b9ba95ctguil@chromium.org SkAdvancedTypefaceMetrics::kHAdvance_PerGlyphInfo) { 19265aa937b300475c956bfad0c34a6daa71d166f6factguil@chromium.org if (info->fStyle & SkAdvancedTypefaceMetrics::kFixedPitch_Style) { 19275aa937b300475c956bfad0c34a6daa71d166f6factguil@chromium.org appendRange(&info->fGlyphWidths, 0); 19285aa937b300475c956bfad0c34a6daa71d166f6factguil@chromium.org info->fGlyphWidths->fAdvance.append(1, &min_width); 19295aa937b300475c956bfad0c34a6daa71d166f6factguil@chromium.org finishRange(info->fGlyphWidths.get(), 0, 19305aa937b300475c956bfad0c34a6daa71d166f6factguil@chromium.org SkAdvancedTypefaceMetrics::WidthRange::kDefault); 19315aa937b300475c956bfad0c34a6daa71d166f6factguil@chromium.org } else { 19325aa937b300475c956bfad0c34a6daa71d166f6factguil@chromium.org info->fGlyphWidths.reset( 193337ad8fb72ff1b3faac93b01ead2c79e1a06fc172vandebo@chromium.org getAdvanceData(hdc, 193437ad8fb72ff1b3faac93b01ead2c79e1a06fc172vandebo@chromium.org glyphCount, 193537ad8fb72ff1b3faac93b01ead2c79e1a06fc172vandebo@chromium.org glyphIDs, 193637ad8fb72ff1b3faac93b01ead2c79e1a06fc172vandebo@chromium.org glyphIDsCount, 193737ad8fb72ff1b3faac93b01ead2c79e1a06fc172vandebo@chromium.org &getWidthAdvance)); 19385aa937b300475c956bfad0c34a6daa71d166f6factguil@chromium.org } 1939ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com } 1940ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com 1941ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.comError: 1942390c6d7a9018e233a6519397ac6c739fb21a99efedisonn@google.comReturnInfo: 1943ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com SelectObject(hdc, savefont); 1944ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com DeleteObject(designFont); 1945ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com DeleteObject(font); 1946ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com DeleteDC(hdc); 1947ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com 1948ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com return info; 1949ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com} 1950ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com 1951a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com//Dummy representation of a Base64 encoded GUID from create_unique_font_name. 1952a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com#define BASE64_GUID_ID "XXXXXXXXXXXXXXXXXXXXXXXX" 1953a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com//Length of GUID representation from create_id, including NULL terminator. 1954a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com#define BASE64_GUID_ID_LEN SK_ARRAY_COUNT(BASE64_GUID_ID) 1955a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com 1956a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.comSK_COMPILE_ASSERT(BASE64_GUID_ID_LEN < LF_FACESIZE, GUID_longer_than_facesize); 1957a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com 1958a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com/** 1959a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com NameID 6 Postscript names cannot have the character '/'. 1960a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com It would be easier to hex encode the GUID, but that is 32 bytes, 1961a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com and many systems have issues with names longer than 28 bytes. 1962a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com The following need not be any standard base64 encoding. 1963a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com The encoded value is never decoded. 1964a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com*/ 1965d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.comstatic const char postscript_safe_base64_encode[] = 1966a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com "ABCDEFGHIJKLMNOPQRSTUVWXYZ" 1967a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com "abcdefghijklmnopqrstuvwxyz" 1968a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com "0123456789-_="; 1969a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com 1970a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com/** 1971a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com Formats a GUID into Base64 and places it into buffer. 1972a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com buffer should have space for at least BASE64_GUID_ID_LEN characters. 1973a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com The string will always be null terminated. 1974a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com XXXXXXXXXXXXXXXXXXXXXXXX0 1975a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com */ 1976a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.comstatic void format_guid_b64(const GUID& guid, char* buffer, size_t bufferSize) { 1977a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com SkASSERT(bufferSize >= BASE64_GUID_ID_LEN); 1978a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com size_t written = SkBase64::Encode(&guid, sizeof(guid), buffer, postscript_safe_base64_encode); 1979a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com SkASSERT(written < LF_FACESIZE); 1980a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com buffer[written] = '\0'; 1981a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com} 1982a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com 1983a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com/** 1984a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com Creates a Base64 encoded GUID and places it into buffer. 1985a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com buffer should have space for at least BASE64_GUID_ID_LEN characters. 1986a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com The string will always be null terminated. 1987a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com XXXXXXXXXXXXXXXXXXXXXXXX0 1988a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com */ 1989a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.comstatic HRESULT create_unique_font_name(char* buffer, size_t bufferSize) { 1990a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com GUID guid = {}; 1991a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com if (FAILED(CoCreateGuid(&guid))) { 1992a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com return E_UNEXPECTED; 1993a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com } 1994a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com format_guid_b64(guid, buffer, bufferSize); 1995a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com 1996a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com return S_OK; 1997a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com} 1998a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com 1999a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com/** 2000a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com Introduces a font to GDI. On failure will return NULL. The returned handle 2001a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com should eventually be passed to RemoveFontMemResourceEx. 2002a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com*/ 2003a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.comstatic HANDLE activate_font(SkData* fontData) { 2004a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com DWORD numFonts = 0; 2005a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com //AddFontMemResourceEx just copies the data, but does not specify const. 2006a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com HANDLE fontHandle = AddFontMemResourceEx(const_cast<void*>(fontData->data()), 20074b18f5767ab1df7fedf0ff2e3a9eac7f7c500c36bungeman@google.com static_cast<DWORD>(fontData->size()), 2008a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com 0, 2009a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com &numFonts); 2010a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com 2011a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com if (fontHandle != NULL && numFonts < 1) { 2012a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com RemoveFontMemResourceEx(fontHandle); 2013a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com return NULL; 2014a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com } 2015a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com 2016a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com return fontHandle; 2017a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com} 2018a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com 2019437eea160b2f605d9074106891288e85baaecfefreed@google.comstatic SkTypeface* create_from_stream(SkStream* stream) { 2020a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com // Create a unique and unpredictable font name. 2021a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com // Avoids collisions and access from CSS. 2022a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com char familyName[BASE64_GUID_ID_LEN]; 2023a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com const int familyNameSize = SK_ARRAY_COUNT(familyName); 2024a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com if (FAILED(create_unique_font_name(familyName, familyNameSize))) { 2025a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com return NULL; 2026a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com } 2027d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com 2028a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com // Change the name of the font. 2029e9bbee397ce96aa6642a42823feb1d7c4a8ffd8bbungeman@google.com SkAutoTUnref<SkData> rewrittenFontData(SkOTUtils::RenameFont(stream, familyName, familyNameSize-1)); 2030e9bbee397ce96aa6642a42823feb1d7c4a8ffd8bbungeman@google.com if (NULL == rewrittenFontData.get()) { 2031a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com return NULL; 2032a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com } 2033ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com 2034a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com // Register the font with GDI. 2035e9bbee397ce96aa6642a42823feb1d7c4a8ffd8bbungeman@google.com HANDLE fontReference = activate_font(rewrittenFontData.get()); 2036a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com if (NULL == fontReference) { 2037a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com return NULL; 2038a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com } 2039a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com 2040a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com // Create the typeface. 2041a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com LOGFONT lf; 2042484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com logfont_for_name(familyName, &lf); 2043a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com 2044a550199c6f37e1b05a386ea57eee4c40cc91d84dbungeman@google.com return SkCreateFontMemResourceTypefaceFromLOGFONT(lf, fontReference); 2045ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com} 2046ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com 20470042b9c2a2e6fe954cdfbcd5a5b7449cdf41a4c3reed@google.comSkStream* LogFontTypeface::onOpenStream(int* ttcIndex) const { 20480042b9c2a2e6fe954cdfbcd5a5b7449cdf41a4c3reed@google.com *ttcIndex = 0; 20490042b9c2a2e6fe954cdfbcd5a5b7449cdf41a4c3reed@google.com 2050f4c2622a1a3489988f2d85a81fdc132b17a92bddctguil@chromium.org const DWORD kTTCTag = 2051f4c2622a1a3489988f2d85a81fdc132b17a92bddctguil@chromium.org SkEndian_SwapBE32(SkSetFourByteTag('t', 't', 'c', 'f')); 20520042b9c2a2e6fe954cdfbcd5a5b7449cdf41a4c3reed@google.com LOGFONT lf = fLogFont; 2053ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com 2054ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com HDC hdc = ::CreateCompatibleDC(NULL); 205559d2f63583512b47df579e80f1ae39c74fad5f3ereed@google.com HFONT font = CreateFontIndirect(&lf); 2056ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com HFONT savefont = (HFONT)SelectObject(hdc, font); 2057ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com 2058d604481f7a2587f5b400d2a0a68a6491a0d584c7vandebo@chromium.org SkMemoryStream* stream = NULL; 2059d604481f7a2587f5b400d2a0a68a6491a0d584c7vandebo@chromium.org DWORD tables[2] = {kTTCTag, 0}; 2060d604481f7a2587f5b400d2a0a68a6491a0d584c7vandebo@chromium.org for (int i = 0; i < SK_ARRAY_COUNT(tables); i++) { 20614b18f5767ab1df7fedf0ff2e3a9eac7f7c500c36bungeman@google.com DWORD bufferSize = GetFontData(hdc, tables[i], 0, NULL, 0); 206239698b1bd71fd54c7c44ae8d7224afdaf93c0ddabungeman@google.com if (bufferSize == GDI_ERROR) { 2063055180cb9c47c87e5ee8c9fa6d3f6a6079ad6f35reed@google.com call_ensure_accessible(lf); 206439698b1bd71fd54c7c44ae8d7224afdaf93c0ddabungeman@google.com bufferSize = GetFontData(hdc, tables[i], 0, NULL, 0); 206539698b1bd71fd54c7c44ae8d7224afdaf93c0ddabungeman@google.com } 2066d604481f7a2587f5b400d2a0a68a6491a0d584c7vandebo@chromium.org if (bufferSize != GDI_ERROR) { 2067d604481f7a2587f5b400d2a0a68a6491a0d584c7vandebo@chromium.org stream = new SkMemoryStream(bufferSize); 20684b18f5767ab1df7fedf0ff2e3a9eac7f7c500c36bungeman@google.com if (GetFontData(hdc, tables[i], 0, (void*)stream->getMemoryBase(), bufferSize)) { 2069d604481f7a2587f5b400d2a0a68a6491a0d584c7vandebo@chromium.org break; 2070d604481f7a2587f5b400d2a0a68a6491a0d584c7vandebo@chromium.org } else { 2071d604481f7a2587f5b400d2a0a68a6491a0d584c7vandebo@chromium.org delete stream; 2072d604481f7a2587f5b400d2a0a68a6491a0d584c7vandebo@chromium.org stream = NULL; 2073d604481f7a2587f5b400d2a0a68a6491a0d584c7vandebo@chromium.org } 2074d604481f7a2587f5b400d2a0a68a6491a0d584c7vandebo@chromium.org } 2075ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com } 2076ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com 2077ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com SelectObject(hdc, savefont); 2078ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com DeleteObject(font); 2079ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com DeleteDC(hdc); 2080ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com 2081ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com return stream; 2082ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com} 2083ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com 20843c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.comstatic void bmpCharsToGlyphs(HDC hdc, const WCHAR* bmpChars, int count, uint16_t* glyphs, 20853c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com bool Ox1FHack) 20863c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com{ 20873c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com DWORD result = GetGlyphIndicesW(hdc, bmpChars, count, glyphs, GGI_MARK_NONEXISTING_GLYPHS); 20883c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com if (GDI_ERROR == result) { 20893c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com for (int i = 0; i < count; ++i) { 20903c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com glyphs[i] = 0; 20913c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com } 20923c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com return; 20933c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com } 20943c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com 20953c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com if (Ox1FHack) { 20963c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com for (int i = 0; i < count; ++i) { 20973c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com if (0xFFFF == glyphs[i] || 0x1F == glyphs[i]) { 20983c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com glyphs[i] = 0; 20993c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com } 21003c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com } 21013c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com } else { 21023c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com for (int i = 0; i < count; ++i) { 21033c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com if (0xFFFF == glyphs[i]){ 21043c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com glyphs[i] = 0; 21053c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com } 21063c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com } 21073c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com } 21083c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com} 21093c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com 21103c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.comstatic uint16_t nonBmpCharToGlyph(HDC hdc, SCRIPT_CACHE* scriptCache, const WCHAR utf16[2]) { 21113c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com uint16_t index = 0; 21123c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com // Use uniscribe to detemine glyph index for non-BMP characters. 21133c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com static const int numWCHAR = 2; 21143c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com static const int maxItems = 2; 21153c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com // MSDN states that this can be NULL, but some things don't work then. 21163c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com SCRIPT_CONTROL scriptControl = { 0 }; 21173c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com // Add extra item to SCRIPT_ITEM to work around a bug (now documented). 21183c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com // https://bugzilla.mozilla.org/show_bug.cgi?id=366643 21193c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com SCRIPT_ITEM si[maxItems + 1]; 21203c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com int numItems; 21213c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com HRZM(ScriptItemize(utf16, numWCHAR, maxItems, &scriptControl, NULL, si, &numItems), 21223c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com "Could not itemize character."); 21233c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com 21243c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com // Sometimes ScriptShape cannot find a glyph for a non-BMP and returns 2 space glyphs. 21253c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com static const int maxGlyphs = 2; 21263c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com SCRIPT_VISATTR vsa[maxGlyphs]; 21273c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com WORD outGlyphs[maxGlyphs]; 21283c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com WORD logClust[numWCHAR]; 21293c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com int numGlyphs; 21303c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com HRZM(ScriptShape(hdc, scriptCache, utf16, numWCHAR, maxGlyphs, &si[0].a, 21313c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com outGlyphs, logClust, vsa, &numGlyphs), 21323c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com "Could not shape character."); 21333c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com if (1 == numGlyphs) { 21343c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com index = outGlyphs[0]; 21353c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com } 21363c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com return index; 21373c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com} 21383c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com 21393c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.comclass SkAutoHDC { 21403c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.compublic: 21413c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com SkAutoHDC(const LOGFONT& lf) 21423c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com : fHdc(::CreateCompatibleDC(NULL)) 21433c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com , fFont(::CreateFontIndirect(&lf)) 21443c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com , fSavefont((HFONT)SelectObject(fHdc, fFont)) 21453c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com { } 21463c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com ~SkAutoHDC() { 21473c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com SelectObject(fHdc, fSavefont); 21483c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com DeleteObject(fFont); 21493c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com DeleteDC(fHdc); 21503c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com } 21513c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com operator HDC() { return fHdc; } 21523c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.comprivate: 21533c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com HDC fHdc; 21543c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com HFONT fFont; 21553c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com HFONT fSavefont; 21563c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com}; 21573c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com 21583c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.comint LogFontTypeface::onCharsToGlyphs(const void* chars, Encoding encoding, 21593c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com uint16_t userGlyphs[], int glyphCount) const 21603c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com{ 21613c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com SkAutoHDC hdc(fLogFont); 21623c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com 21633c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com TEXTMETRIC tm; 21643c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com if (0 == GetTextMetrics(hdc, &tm)) { 21653c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com call_ensure_accessible(fLogFont); 21663c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com if (0 == GetTextMetrics(hdc, &tm)) { 21673c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com tm.tmPitchAndFamily = TMPF_TRUETYPE; 21683c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com } 21693c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com } 21703c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com bool Ox1FHack = !(tm.tmPitchAndFamily & TMPF_VECTOR) /*&& winVer < Vista */; 21713c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com 21723c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com SkAutoSTMalloc<256, uint16_t> scratchGlyphs; 21733c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com uint16_t* glyphs; 21743c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com if (userGlyphs != NULL) { 21753c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com glyphs = userGlyphs; 21763c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com } else { 21773c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com glyphs = scratchGlyphs.reset(glyphCount); 21783c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com } 21793c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com 21803c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com SCRIPT_CACHE sc = 0; 21813c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com switch (encoding) { 21823c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com case SkTypeface::kUTF8_Encoding: { 21833c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com static const int scratchCount = 256; 21843c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com WCHAR scratch[scratchCount]; 21853c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com int glyphIndex = 0; 21863c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com const char* currentUtf8 = reinterpret_cast<const char*>(chars); 21873c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com SkUnichar currentChar; 21883c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com if (glyphCount) { 21893c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com currentChar = SkUTF8_NextUnichar(¤tUtf8); 21903c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com } 21913c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com while (glyphIndex < glyphCount) { 21923c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com // Try a run of bmp. 21933c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com int glyphsLeft = SkTMin(glyphCount - glyphIndex, scratchCount); 21943c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com int runLength = 0; 21953c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com while (runLength < glyphsLeft && currentChar <= 0xFFFF) { 21963c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com scratch[runLength] = static_cast<WCHAR>(currentChar); 21973c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com ++runLength; 21983c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com if (runLength < glyphsLeft) { 21993c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com currentChar = SkUTF8_NextUnichar(¤tUtf8); 22003c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com } 22013c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com } 22023c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com if (runLength) { 22033c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com bmpCharsToGlyphs(hdc, scratch, runLength, &glyphs[glyphIndex], Ox1FHack); 22043c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com glyphIndex += runLength; 22053c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com } 22063c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com 22073c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com // Try a run of non-bmp. 22083c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com while (glyphIndex < glyphCount && currentChar > 0xFFFF) { 22093c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com SkUTF16_FromUnichar(currentChar, reinterpret_cast<uint16_t*>(scratch)); 22103c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com glyphs[glyphIndex] = nonBmpCharToGlyph(hdc, &sc, scratch); 22113c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com ++glyphIndex; 22123c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com if (glyphIndex < glyphCount) { 22133c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com currentChar = SkUTF8_NextUnichar(¤tUtf8); 22143c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com } 22153c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com } 22163c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com } 22173c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com break; 22183c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com } 22193c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com case SkTypeface::kUTF16_Encoding: { 22203c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com int glyphIndex = 0; 22213c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com const WCHAR* currentUtf16 = reinterpret_cast<const WCHAR*>(chars); 22223c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com while (glyphIndex < glyphCount) { 22233c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com // Try a run of bmp. 22243c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com int glyphsLeft = glyphCount - glyphIndex; 22253c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com int runLength = 0; 22263c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com while (runLength < glyphsLeft && !SkUTF16_IsHighSurrogate(currentUtf16[runLength])) { 22273c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com ++runLength; 22283c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com } 22293c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com if (runLength) { 22303c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com bmpCharsToGlyphs(hdc, currentUtf16, runLength, &glyphs[glyphIndex], Ox1FHack); 22313c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com glyphIndex += runLength; 22323c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com currentUtf16 += runLength; 22333c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com } 22343c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com 22353c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com // Try a run of non-bmp. 22363c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com while (glyphIndex < glyphCount && SkUTF16_IsHighSurrogate(*currentUtf16)) { 22373c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com glyphs[glyphIndex] = nonBmpCharToGlyph(hdc, &sc, currentUtf16); 22383c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com ++glyphIndex; 22393c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com currentUtf16 += 2; 22403c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com } 22413c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com } 22423c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com break; 22433c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com } 22443c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com case SkTypeface::kUTF32_Encoding: { 22453c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com static const int scratchCount = 256; 22463c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com WCHAR scratch[scratchCount]; 22473c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com int glyphIndex = 0; 22483c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com const uint32_t* utf32 = reinterpret_cast<const uint32_t*>(chars); 22493c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com while (glyphIndex < glyphCount) { 22503c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com // Try a run of bmp. 22513c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com int glyphsLeft = SkTMin(glyphCount - glyphIndex, scratchCount); 22523c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com int runLength = 0; 22533c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com while (runLength < glyphsLeft && utf32[glyphIndex + runLength] <= 0xFFFF) { 22543c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com scratch[runLength] = static_cast<WCHAR>(utf32[glyphIndex + runLength]); 22553c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com ++runLength; 22563c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com } 22573c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com if (runLength) { 22583c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com bmpCharsToGlyphs(hdc, scratch, runLength, &glyphs[glyphIndex], Ox1FHack); 22593c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com glyphIndex += runLength; 22603c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com } 22613c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com 22623c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com // Try a run of non-bmp. 22633c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com while (glyphIndex < glyphCount && utf32[glyphIndex] > 0xFFFF) { 22643c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com SkUTF16_FromUnichar(utf32[glyphIndex], reinterpret_cast<uint16_t*>(scratch)); 22653c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com glyphs[glyphIndex] = nonBmpCharToGlyph(hdc, &sc, scratch); 22663c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com ++glyphIndex; 22673c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com } 22683c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com } 22693c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com break; 22703c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com } 22713c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com default: 22723c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com SK_CRASH(); 22733c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com } 22743c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com 22753c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com if (sc) { 22763c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com ::ScriptFreeCache(&sc); 22773c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com } 22783c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com 22793c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com for (int i = 0; i < glyphCount; ++i) { 22803c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com if (0 == glyphs[i]) { 22813c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com return i; 22823c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com } 22833c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com } 22843c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com return glyphCount; 22853c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com} 22863c996f8a15e5d8fada9550d978e9b5344b81d276bungeman@google.com 22877bdd614a1940935d3badeb54f7aae75d76ea830dbungeman@google.comint LogFontTypeface::onCountGlyphs() const { 22887bdd614a1940935d3badeb54f7aae75d76ea830dbungeman@google.com HDC hdc = ::CreateCompatibleDC(NULL); 22897bdd614a1940935d3badeb54f7aae75d76ea830dbungeman@google.com HFONT font = CreateFontIndirect(&fLogFont); 22907bdd614a1940935d3badeb54f7aae75d76ea830dbungeman@google.com HFONT savefont = (HFONT)SelectObject(hdc, font); 22917bdd614a1940935d3badeb54f7aae75d76ea830dbungeman@google.com 22927bdd614a1940935d3badeb54f7aae75d76ea830dbungeman@google.com unsigned int glyphCount = calculateGlyphCount(hdc, fLogFont); 22937bdd614a1940935d3badeb54f7aae75d76ea830dbungeman@google.com 22947bdd614a1940935d3badeb54f7aae75d76ea830dbungeman@google.com SelectObject(hdc, savefont); 22957bdd614a1940935d3badeb54f7aae75d76ea830dbungeman@google.com DeleteObject(font); 22967bdd614a1940935d3badeb54f7aae75d76ea830dbungeman@google.com DeleteDC(hdc); 22977bdd614a1940935d3badeb54f7aae75d76ea830dbungeman@google.com 22987bdd614a1940935d3badeb54f7aae75d76ea830dbungeman@google.com return glyphCount; 22997bdd614a1940935d3badeb54f7aae75d76ea830dbungeman@google.com} 23007bdd614a1940935d3badeb54f7aae75d76ea830dbungeman@google.com 23017bdd614a1940935d3badeb54f7aae75d76ea830dbungeman@google.comint LogFontTypeface::onGetUPEM() const { 23027bdd614a1940935d3badeb54f7aae75d76ea830dbungeman@google.com HDC hdc = ::CreateCompatibleDC(NULL); 23037bdd614a1940935d3badeb54f7aae75d76ea830dbungeman@google.com HFONT font = CreateFontIndirect(&fLogFont); 23047bdd614a1940935d3badeb54f7aae75d76ea830dbungeman@google.com HFONT savefont = (HFONT)SelectObject(hdc, font); 23057bdd614a1940935d3badeb54f7aae75d76ea830dbungeman@google.com 23067bdd614a1940935d3badeb54f7aae75d76ea830dbungeman@google.com unsigned int upem = calculateUPEM(hdc, fLogFont); 23077bdd614a1940935d3badeb54f7aae75d76ea830dbungeman@google.com 23087bdd614a1940935d3badeb54f7aae75d76ea830dbungeman@google.com SelectObject(hdc, savefont); 23097bdd614a1940935d3badeb54f7aae75d76ea830dbungeman@google.com DeleteObject(font); 23107bdd614a1940935d3badeb54f7aae75d76ea830dbungeman@google.com DeleteDC(hdc); 23117bdd614a1940935d3badeb54f7aae75d76ea830dbungeman@google.com 23127bdd614a1940935d3badeb54f7aae75d76ea830dbungeman@google.com return upem; 23137bdd614a1940935d3badeb54f7aae75d76ea830dbungeman@google.com} 23147bdd614a1940935d3badeb54f7aae75d76ea830dbungeman@google.com 2315839702b61934914118ec557dd641be322eba3b5fbungeman@google.comSkTypeface::LocalizedStrings* LogFontTypeface::onCreateFamilyNameIterator() const { 2316a980269c2498836101146adc729ef780fb89824ebungeman@google.com SkTypeface::LocalizedStrings* nameIter = 2317a980269c2498836101146adc729ef780fb89824ebungeman@google.com SkOTUtils::LocalizedStrings_NameTable::CreateForFamilyNames(*this); 2318a980269c2498836101146adc729ef780fb89824ebungeman@google.com if (NULL == nameIter) { 2319a980269c2498836101146adc729ef780fb89824ebungeman@google.com SkString familyName; 2320a980269c2498836101146adc729ef780fb89824ebungeman@google.com this->getFamilyName(&familyName); 2321a980269c2498836101146adc729ef780fb89824ebungeman@google.com SkString language("und"); //undetermined 2322a980269c2498836101146adc729ef780fb89824ebungeman@google.com nameIter = new SkOTUtils::LocalizedStrings_SingleName(familyName, language); 2323a980269c2498836101146adc729ef780fb89824ebungeman@google.com } 2324a980269c2498836101146adc729ef780fb89824ebungeman@google.com return nameIter; 2325a980269c2498836101146adc729ef780fb89824ebungeman@google.com} 2326a980269c2498836101146adc729ef780fb89824ebungeman@google.com 2327b10b51f64dbd1cf44571a1eedb412378702d8cd4bungeman@google.comint LogFontTypeface::onGetTableTags(SkFontTableTag tags[]) const { 2328b10b51f64dbd1cf44571a1eedb412378702d8cd4bungeman@google.com SkSFNTHeader header; 2329b10b51f64dbd1cf44571a1eedb412378702d8cd4bungeman@google.com if (sizeof(header) != this->onGetTableData(0, 0, sizeof(header), &header)) { 2330b10b51f64dbd1cf44571a1eedb412378702d8cd4bungeman@google.com return 0; 2331b10b51f64dbd1cf44571a1eedb412378702d8cd4bungeman@google.com } 2332b10b51f64dbd1cf44571a1eedb412378702d8cd4bungeman@google.com 2333b10b51f64dbd1cf44571a1eedb412378702d8cd4bungeman@google.com int numTables = SkEndian_SwapBE16(header.numTables); 2334b10b51f64dbd1cf44571a1eedb412378702d8cd4bungeman@google.com 2335b10b51f64dbd1cf44571a1eedb412378702d8cd4bungeman@google.com if (tags) { 2336b10b51f64dbd1cf44571a1eedb412378702d8cd4bungeman@google.com size_t size = numTables * sizeof(SkSFNTHeader::TableDirectoryEntry); 2337b10b51f64dbd1cf44571a1eedb412378702d8cd4bungeman@google.com SkAutoSTMalloc<0x20, SkSFNTHeader::TableDirectoryEntry> dir(numTables); 2338b10b51f64dbd1cf44571a1eedb412378702d8cd4bungeman@google.com if (size != this->onGetTableData(0, sizeof(header), size, dir.get())) { 2339b10b51f64dbd1cf44571a1eedb412378702d8cd4bungeman@google.com return 0; 2340b10b51f64dbd1cf44571a1eedb412378702d8cd4bungeman@google.com } 2341b10b51f64dbd1cf44571a1eedb412378702d8cd4bungeman@google.com 2342b10b51f64dbd1cf44571a1eedb412378702d8cd4bungeman@google.com for (int i = 0; i < numTables; ++i) { 2343b10b51f64dbd1cf44571a1eedb412378702d8cd4bungeman@google.com tags[i] = SkEndian_SwapBE32(dir[i].tag); 2344b10b51f64dbd1cf44571a1eedb412378702d8cd4bungeman@google.com } 2345b10b51f64dbd1cf44571a1eedb412378702d8cd4bungeman@google.com } 2346b10b51f64dbd1cf44571a1eedb412378702d8cd4bungeman@google.com return numTables; 2347b10b51f64dbd1cf44571a1eedb412378702d8cd4bungeman@google.com} 2348b10b51f64dbd1cf44571a1eedb412378702d8cd4bungeman@google.com 2349b10b51f64dbd1cf44571a1eedb412378702d8cd4bungeman@google.comsize_t LogFontTypeface::onGetTableData(SkFontTableTag tag, size_t offset, 2350b10b51f64dbd1cf44571a1eedb412378702d8cd4bungeman@google.com size_t length, void* data) const 2351b10b51f64dbd1cf44571a1eedb412378702d8cd4bungeman@google.com{ 2352b10b51f64dbd1cf44571a1eedb412378702d8cd4bungeman@google.com LOGFONT lf = fLogFont; 2353b10b51f64dbd1cf44571a1eedb412378702d8cd4bungeman@google.com 2354b10b51f64dbd1cf44571a1eedb412378702d8cd4bungeman@google.com HDC hdc = ::CreateCompatibleDC(NULL); 2355b10b51f64dbd1cf44571a1eedb412378702d8cd4bungeman@google.com HFONT font = CreateFontIndirect(&lf); 2356b10b51f64dbd1cf44571a1eedb412378702d8cd4bungeman@google.com HFONT savefont = (HFONT)SelectObject(hdc, font); 2357b10b51f64dbd1cf44571a1eedb412378702d8cd4bungeman@google.com 2358b10b51f64dbd1cf44571a1eedb412378702d8cd4bungeman@google.com tag = SkEndian_SwapBE32(tag); 2359b10b51f64dbd1cf44571a1eedb412378702d8cd4bungeman@google.com if (NULL == data) { 2360b10b51f64dbd1cf44571a1eedb412378702d8cd4bungeman@google.com length = 0; 2361b10b51f64dbd1cf44571a1eedb412378702d8cd4bungeman@google.com } 23628b169311b59ab84e8ca6f3630a1e960cc1be751erobertphillips@google.com DWORD bufferSize = GetFontData(hdc, tag, (DWORD) offset, data, (DWORD) length); 2363b10b51f64dbd1cf44571a1eedb412378702d8cd4bungeman@google.com if (bufferSize == GDI_ERROR) { 2364b10b51f64dbd1cf44571a1eedb412378702d8cd4bungeman@google.com call_ensure_accessible(lf); 23658b169311b59ab84e8ca6f3630a1e960cc1be751erobertphillips@google.com bufferSize = GetFontData(hdc, tag, (DWORD) offset, data, (DWORD) length); 2366b10b51f64dbd1cf44571a1eedb412378702d8cd4bungeman@google.com } 2367b10b51f64dbd1cf44571a1eedb412378702d8cd4bungeman@google.com 2368b10b51f64dbd1cf44571a1eedb412378702d8cd4bungeman@google.com SelectObject(hdc, savefont); 2369b10b51f64dbd1cf44571a1eedb412378702d8cd4bungeman@google.com DeleteObject(font); 2370b10b51f64dbd1cf44571a1eedb412378702d8cd4bungeman@google.com DeleteDC(hdc); 2371b10b51f64dbd1cf44571a1eedb412378702d8cd4bungeman@google.com 2372b10b51f64dbd1cf44571a1eedb412378702d8cd4bungeman@google.com return bufferSize == GDI_ERROR ? 0 : bufferSize; 2373b10b51f64dbd1cf44571a1eedb412378702d8cd4bungeman@google.com} 2374b10b51f64dbd1cf44571a1eedb412378702d8cd4bungeman@google.com 23750da48618a758ef46c2174bdc1eaeb6dd8a693a2ereed@google.comSkScalerContext* LogFontTypeface::onCreateScalerContext(const SkDescriptor* desc) const { 237630ddd615c447fed73286151b463af20d309c85f1reed@google.com SkScalerContext_GDI* ctx = SkNEW_ARGS(SkScalerContext_GDI, 237784e22d847fc84727bc220947162363ee1fe068fcreed@google.com (const_cast<LogFontTypeface*>(this), desc)); 237884e22d847fc84727bc220947162363ee1fe068fcreed@google.com if (!ctx->isValid()) { 237984e22d847fc84727bc220947162363ee1fe068fcreed@google.com SkDELETE(ctx); 238084e22d847fc84727bc220947162363ee1fe068fcreed@google.com ctx = NULL; 238184e22d847fc84727bc220947162363ee1fe068fcreed@google.com } 238284e22d847fc84727bc220947162363ee1fe068fcreed@google.com return ctx; 2383ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com} 2384ac6b97972d3c5a8e10b79c1409818756310e0f12reed@google.com 23850da48618a758ef46c2174bdc1eaeb6dd8a693a2ereed@google.comvoid LogFontTypeface::onFilterRec(SkScalerContextRec* rec) const { 2386c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org if (rec->fFlags & SkScalerContext::kLCD_BGROrder_Flag || 2387c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org rec->fFlags & SkScalerContext::kLCD_Vertical_Flag) 2388c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org { 2389c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org rec->fMaskFormat = SkMask::kA8_Format; 2390c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org rec->fFlags |= SkScalerContext::kGenA8FromLCD_Flag; 2391c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org } 2392c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org 2393e8fab0111d11316a027bc6ae60c62cc6575cdc05reed@google.com unsigned flagsWeDontSupport = SkScalerContext::kDevKernText_Flag | 2394e8fab0111d11316a027bc6ae60c62cc6575cdc05reed@google.com SkScalerContext::kAutohinting_Flag | 2395e8fab0111d11316a027bc6ae60c62cc6575cdc05reed@google.com SkScalerContext::kEmbeddedBitmapText_Flag | 2396e8fab0111d11316a027bc6ae60c62cc6575cdc05reed@google.com SkScalerContext::kEmbolden_Flag | 2397e8fab0111d11316a027bc6ae60c62cc6575cdc05reed@google.com SkScalerContext::kLCD_BGROrder_Flag | 2398e8fab0111d11316a027bc6ae60c62cc6575cdc05reed@google.com SkScalerContext::kLCD_Vertical_Flag; 2399e8fab0111d11316a027bc6ae60c62cc6575cdc05reed@google.com rec->fFlags &= ~flagsWeDontSupport; 2400e8fab0111d11316a027bc6ae60c62cc6575cdc05reed@google.com 2401e8fab0111d11316a027bc6ae60c62cc6575cdc05reed@google.com SkPaint::Hinting h = rec->getHinting(); 2402e8fab0111d11316a027bc6ae60c62cc6575cdc05reed@google.com switch (h) { 2403e8fab0111d11316a027bc6ae60c62cc6575cdc05reed@google.com case SkPaint::kNo_Hinting: 24040abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com break; 2405e8fab0111d11316a027bc6ae60c62cc6575cdc05reed@google.com case SkPaint::kSlight_Hinting: 24060abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com // Only do slight hinting when axis aligned. 24077c86d8eb3a61eae188bc8af2cd0363858eaea07ebungeman@google.com // TODO: re-enable slight hinting when FontHostTest can pass. 24087c86d8eb3a61eae188bc8af2cd0363858eaea07ebungeman@google.com //if (!isAxisAligned(*rec)) { 24090abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com h = SkPaint::kNo_Hinting; 24107c86d8eb3a61eae188bc8af2cd0363858eaea07ebungeman@google.com //} 2411e8fab0111d11316a027bc6ae60c62cc6575cdc05reed@google.com break; 2412e8fab0111d11316a027bc6ae60c62cc6575cdc05reed@google.com case SkPaint::kNormal_Hinting: 2413e8fab0111d11316a027bc6ae60c62cc6575cdc05reed@google.com case SkPaint::kFull_Hinting: 24140abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com // TODO: need to be able to distinguish subpixel positioned glyphs 24150abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com // and linear metrics. 24160abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com //rec->fFlags &= ~SkScalerContext::kSubpixelPositioning_Flag; 2417e8fab0111d11316a027bc6ae60c62cc6575cdc05reed@google.com h = SkPaint::kNormal_Hinting; 2418e8fab0111d11316a027bc6ae60c62cc6575cdc05reed@google.com break; 2419e8fab0111d11316a027bc6ae60c62cc6575cdc05reed@google.com default: 24200c00f21fee3f5cfa3aa7e5d46ff94cb8cf340451tomhudson@google.com SkDEBUGFAIL("unknown hinting"); 2421e8fab0111d11316a027bc6ae60c62cc6575cdc05reed@google.com } 24220abbff9987b9452fd30cce198bea34fdb210ac41bungeman@google.com //TODO: if this is a bitmap font, squash hinting and subpixel. 2423e8fab0111d11316a027bc6ae60c62cc6575cdc05reed@google.com rec->setHinting(h); 2424da44067ec97fddd3bab52da34e2fc5ddc5241c34reed@google.com 24259181aa84aa288d2bc3ab079b6b40a79ac87d8807reed@google.com// turn this off since GDI might turn A8 into BW! Need a bigger fix. 24269181aa84aa288d2bc3ab079b6b40a79ac87d8807reed@google.com#if 0 2427da44067ec97fddd3bab52da34e2fc5ddc5241c34reed@google.com // Disable LCD when rotated, since GDI's output is ugly 2428da44067ec97fddd3bab52da34e2fc5ddc5241c34reed@google.com if (isLCD(*rec) && !isAxisAligned(*rec)) { 2429da44067ec97fddd3bab52da34e2fc5ddc5241c34reed@google.com rec->fMaskFormat = SkMask::kA8_Format; 2430da44067ec97fddd3bab52da34e2fc5ddc5241c34reed@google.com } 24319181aa84aa288d2bc3ab079b6b40a79ac87d8807reed@google.com#endif 2432754e4ebd10d7353ce55be7dfe0a417e502ef4047reed@google.com 24330da48618a758ef46c2174bdc1eaeb6dd8a693a2ereed@google.com if (!fCanBeLCD && isLCD(*rec)) { 2434cb1bbb375aa4fdd099dc60302ca1712f04607782bungeman@google.com rec->fMaskFormat = SkMask::kA8_Format; 2435cb1bbb375aa4fdd099dc60302ca1712f04607782bungeman@google.com rec->fFlags &= ~SkScalerContext::kGenA8FromLCD_Flag; 2436754e4ebd10d7353ce55be7dfe0a417e502ef4047reed@google.com } 2437754e4ebd10d7353ce55be7dfe0a417e502ef4047reed@google.com} 2438070da5edcb1c6e9b9507f06a5e2c270e1c1fd796reed@google.com 243930ddd615c447fed73286151b463af20d309c85f1reed@google.comstatic SkTypeface* create_typeface(const SkTypeface* familyFace, 244030ddd615c447fed73286151b463af20d309c85f1reed@google.com const char familyName[], 244130ddd615c447fed73286151b463af20d309c85f1reed@google.com unsigned styleBits) { 244230ddd615c447fed73286151b463af20d309c85f1reed@google.com LOGFONT lf; 244330ddd615c447fed73286151b463af20d309c85f1reed@google.com if (NULL == familyFace && NULL == familyName) { 244430ddd615c447fed73286151b463af20d309c85f1reed@google.com lf = get_default_font(); 244530ddd615c447fed73286151b463af20d309c85f1reed@google.com } else if (familyFace) { 244630ddd615c447fed73286151b463af20d309c85f1reed@google.com LogFontTypeface* face = (LogFontTypeface*)familyFace; 244730ddd615c447fed73286151b463af20d309c85f1reed@google.com lf = face->fLogFont; 244830ddd615c447fed73286151b463af20d309c85f1reed@google.com } else { 244930ddd615c447fed73286151b463af20d309c85f1reed@google.com logfont_for_name(familyName, &lf); 245030ddd615c447fed73286151b463af20d309c85f1reed@google.com } 245130ddd615c447fed73286151b463af20d309c85f1reed@google.com setStyle(&lf, (SkTypeface::Style)styleBits); 245230ddd615c447fed73286151b463af20d309c85f1reed@google.com return SkCreateTypefaceFromLOGFONT(lf); 245330ddd615c447fed73286151b463af20d309c85f1reed@google.com} 245430ddd615c447fed73286151b463af20d309c85f1reed@google.com 245530ddd615c447fed73286151b463af20d309c85f1reed@google.comSkTypeface* LogFontTypeface::onRefMatchingStyle(Style style) const { 245630ddd615c447fed73286151b463af20d309c85f1reed@google.com return create_typeface(this, NULL, style); 245730ddd615c447fed73286151b463af20d309c85f1reed@google.com} 245830ddd615c447fed73286151b463af20d309c85f1reed@google.com 2459070da5edcb1c6e9b9507f06a5e2c270e1c1fd796reed@google.com/////////////////////////////////////////////////////////////////////////////// 2460070da5edcb1c6e9b9507f06a5e2c270e1c1fd796reed@google.com 2461070da5edcb1c6e9b9507f06a5e2c270e1c1fd796reed@google.com#include "SkFontMgr.h" 2462484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com#include "SkDataTable.h" 2463484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com 2464a980269c2498836101146adc729ef780fb89824ebungeman@google.comstatic bool valid_logfont_for_enum(const LOGFONT& lf) { 2465a980269c2498836101146adc729ef780fb89824ebungeman@google.com // TODO: Vector FON is unsupported and should not be listed. 2466a980269c2498836101146adc729ef780fb89824ebungeman@google.com return 2467a980269c2498836101146adc729ef780fb89824ebungeman@google.com // Ignore implicit vertical variants. 2468a980269c2498836101146adc729ef780fb89824ebungeman@google.com lf.lfFaceName[0] && lf.lfFaceName[0] != '@' 2469a980269c2498836101146adc729ef780fb89824ebungeman@google.com 2470a980269c2498836101146adc729ef780fb89824ebungeman@google.com // DEFAULT_CHARSET is used to get all fonts, but also implies all 2471a980269c2498836101146adc729ef780fb89824ebungeman@google.com // character sets. Filter assuming all fonts support ANSI_CHARSET. 2472a980269c2498836101146adc729ef780fb89824ebungeman@google.com && ANSI_CHARSET == lf.lfCharSet 2473a980269c2498836101146adc729ef780fb89824ebungeman@google.com ; 2474a980269c2498836101146adc729ef780fb89824ebungeman@google.com} 2475a980269c2498836101146adc729ef780fb89824ebungeman@google.com 2476a980269c2498836101146adc729ef780fb89824ebungeman@google.com/** An EnumFontFamExProc implementation which interprets builderParam as 2477a980269c2498836101146adc729ef780fb89824ebungeman@google.com * an SkTDArray<ENUMLOGFONTEX>* and appends logfonts which 2478a980269c2498836101146adc729ef780fb89824ebungeman@google.com * pass the valid_logfont_for_enum predicate. 2479a980269c2498836101146adc729ef780fb89824ebungeman@google.com */ 2480a980269c2498836101146adc729ef780fb89824ebungeman@google.comstatic int CALLBACK enum_family_proc(const LOGFONT* lf, const TEXTMETRIC*, 2481a980269c2498836101146adc729ef780fb89824ebungeman@google.com DWORD fontType, LPARAM builderParam) { 2482a980269c2498836101146adc729ef780fb89824ebungeman@google.com if (valid_logfont_for_enum(*lf)) { 2483a65a681d43a8e9f5d8726a389832e957b07ee16breed@google.com SkTDArray<ENUMLOGFONTEX>* array = (SkTDArray<ENUMLOGFONTEX>*)builderParam; 2484a65a681d43a8e9f5d8726a389832e957b07ee16breed@google.com *array->append() = *(ENUMLOGFONTEX*)lf; 2485484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com } 2486484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com return 1; // non-zero means continue 2487484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com} 2488484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com 2489484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.comstatic SkFontStyle compute_fontstyle(const LOGFONT& lf) { 2490484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com return SkFontStyle(lf.lfWeight, SkFontStyle::kNormal_Width, 2491484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com lf.lfItalic ? SkFontStyle::kItalic_Slant 2492484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com : SkFontStyle::kUpright_Slant); 2493484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com} 2494484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com 2495484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.comclass SkFontStyleSetGDI : public SkFontStyleSet { 2496484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.compublic: 2497a65a681d43a8e9f5d8726a389832e957b07ee16breed@google.com SkFontStyleSetGDI(const TCHAR familyName[]) { 2498a980269c2498836101146adc729ef780fb89824ebungeman@google.com LOGFONT lf; 2499a980269c2498836101146adc729ef780fb89824ebungeman@google.com sk_bzero(&lf, sizeof(lf)); 2500a980269c2498836101146adc729ef780fb89824ebungeman@google.com lf.lfCharSet = DEFAULT_CHARSET; 2501a980269c2498836101146adc729ef780fb89824ebungeman@google.com _tcscpy_s(lf.lfFaceName, familyName); 2502a980269c2498836101146adc729ef780fb89824ebungeman@google.com 2503484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com HDC hdc = ::CreateCompatibleDC(NULL); 2504a980269c2498836101146adc729ef780fb89824ebungeman@google.com ::EnumFontFamiliesEx(hdc, &lf, enum_family_proc, (LPARAM)&fArray, 0); 2505484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com ::DeleteDC(hdc); 2506484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com } 2507484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com 2508484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com virtual int count() SK_OVERRIDE { 2509484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com return fArray.count(); 2510484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com } 2511484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com 2512484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com virtual void getStyle(int index, SkFontStyle* fs, SkString* styleName) SK_OVERRIDE { 2513484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com if (fs) { 2514a65a681d43a8e9f5d8726a389832e957b07ee16breed@google.com *fs = compute_fontstyle(fArray[index].elfLogFont); 2515a65a681d43a8e9f5d8726a389832e957b07ee16breed@google.com } 2516a65a681d43a8e9f5d8726a389832e957b07ee16breed@google.com if (styleName) { 2517a65a681d43a8e9f5d8726a389832e957b07ee16breed@google.com const ENUMLOGFONTEX& ref = fArray[index]; 2518a65a681d43a8e9f5d8726a389832e957b07ee16breed@google.com // For some reason, ENUMLOGFONTEX and LOGFONT disagree on their type in the 2519a65a681d43a8e9f5d8726a389832e957b07ee16breed@google.com // non-unicode version. 2520a65a681d43a8e9f5d8726a389832e957b07ee16breed@google.com // ENUMLOGFONTEX uses BYTE 2521a65a681d43a8e9f5d8726a389832e957b07ee16breed@google.com // LOGFONT uses CHAR 2522a65a681d43a8e9f5d8726a389832e957b07ee16breed@google.com // Here we assert they that the style name is logically the same (size) as 2523a65a681d43a8e9f5d8726a389832e957b07ee16breed@google.com // a TCHAR, so we can use the same converter function. 2524a65a681d43a8e9f5d8726a389832e957b07ee16breed@google.com SkASSERT(sizeof(TCHAR) == sizeof(ref.elfStyle[0])); 2525a65a681d43a8e9f5d8726a389832e957b07ee16breed@google.com tchar_to_skstring((const TCHAR*)ref.elfStyle, styleName); 2526484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com } 2527484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com } 2528484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com 2529484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com virtual SkTypeface* createTypeface(int index) SK_OVERRIDE { 2530a65a681d43a8e9f5d8726a389832e957b07ee16breed@google.com return SkCreateTypefaceFromLOGFONT(fArray[index].elfLogFont); 2531484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com } 2532484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com 2533484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com virtual SkTypeface* matchStyle(const SkFontStyle& pattern) SK_OVERRIDE { 2534484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com // todo: 2535a65a681d43a8e9f5d8726a389832e957b07ee16breed@google.com return SkCreateTypefaceFromLOGFONT(fArray[0].elfLogFont); 2536484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com } 2537484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com 2538484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.comprivate: 2539a65a681d43a8e9f5d8726a389832e957b07ee16breed@google.com SkTDArray<ENUMLOGFONTEX> fArray; 2540484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com}; 2541484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com 2542484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.comclass SkFontMgrGDI : public SkFontMgr { 2543a980269c2498836101146adc729ef780fb89824ebungeman@google.compublic: 2544a980269c2498836101146adc729ef780fb89824ebungeman@google.com SkFontMgrGDI() { 2545484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com LOGFONT lf; 2546484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com sk_bzero(&lf, sizeof(lf)); 2547484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com lf.lfCharSet = DEFAULT_CHARSET; 2548484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com 2549484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com HDC hdc = ::CreateCompatibleDC(NULL); 2550484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com ::EnumFontFamiliesEx(hdc, &lf, enum_family_proc, (LPARAM)&fLogFontArray, 0); 2551484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com ::DeleteDC(hdc); 2552484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com } 2553484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com 2554484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.comprotected: 2555484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com virtual int onCountFamilies() SK_OVERRIDE { 2556484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com return fLogFontArray.count(); 2557484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com } 2558484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com 2559484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com virtual void onGetFamilyName(int index, SkString* familyName) SK_OVERRIDE { 2560484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com SkASSERT((unsigned)index < (unsigned)fLogFontArray.count()); 2561a65a681d43a8e9f5d8726a389832e957b07ee16breed@google.com tchar_to_skstring(fLogFontArray[index].elfLogFont.lfFaceName, familyName); 2562484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com } 2563484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com 2564484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com virtual SkFontStyleSet* onCreateStyleSet(int index) SK_OVERRIDE { 2565484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com SkASSERT((unsigned)index < (unsigned)fLogFontArray.count()); 2566a65a681d43a8e9f5d8726a389832e957b07ee16breed@google.com return SkNEW_ARGS(SkFontStyleSetGDI, (fLogFontArray[index].elfLogFont.lfFaceName)); 2567484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com } 2568484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com 2569484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com virtual SkFontStyleSet* onMatchFamily(const char familyName[]) SK_OVERRIDE { 2570484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com if (NULL == familyName) { 2571484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com familyName = ""; // do we need this check??? 2572484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com } 2573484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com LOGFONT lf; 2574484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com logfont_for_name(familyName, &lf); 2575a65a681d43a8e9f5d8726a389832e957b07ee16breed@google.com return SkNEW_ARGS(SkFontStyleSetGDI, (lf.lfFaceName)); 2576484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com } 2577484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com 2578484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com virtual SkTypeface* onMatchFamilyStyle(const char familyName[], 2579484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com const SkFontStyle& fontstyle) SK_OVERRIDE { 2580437eea160b2f605d9074106891288e85baaecfefreed@google.com // could be in base impl 2581484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com SkAutoTUnref<SkFontStyleSet> sset(this->matchFamily(familyName)); 2582484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com return sset->matchStyle(fontstyle); 2583484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com } 2584484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com 2585484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com virtual SkTypeface* onMatchFaceStyle(const SkTypeface* familyMember, 2586484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com const SkFontStyle& fontstyle) SK_OVERRIDE { 2587437eea160b2f605d9074106891288e85baaecfefreed@google.com // could be in base impl 2588484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com SkString familyName; 2589484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com ((LogFontTypeface*)familyMember)->getFamilyName(&familyName); 2590484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com return this->matchFamilyStyle(familyName.c_str(), fontstyle); 2591484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com } 2592484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com 2593437eea160b2f605d9074106891288e85baaecfefreed@google.com virtual SkTypeface* onCreateFromStream(SkStream* stream, int ttcIndex) SK_OVERRIDE { 2594437eea160b2f605d9074106891288e85baaecfefreed@google.com return create_from_stream(stream); 2595484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com } 2596437eea160b2f605d9074106891288e85baaecfefreed@google.com 2597437eea160b2f605d9074106891288e85baaecfefreed@google.com virtual SkTypeface* onCreateFromData(SkData* data, int ttcIndex) SK_OVERRIDE { 2598437eea160b2f605d9074106891288e85baaecfefreed@google.com // could be in base impl 2599437eea160b2f605d9074106891288e85baaecfefreed@google.com SkAutoTUnref<SkStream> stream(SkNEW_ARGS(SkMemoryStream, (data))); 2600437eea160b2f605d9074106891288e85baaecfefreed@google.com return this->createFromStream(stream); 2601484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com } 2602437eea160b2f605d9074106891288e85baaecfefreed@google.com 2603484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com virtual SkTypeface* onCreateFromFile(const char path[], int ttcIndex) SK_OVERRIDE { 2604437eea160b2f605d9074106891288e85baaecfefreed@google.com // could be in base impl 2605437eea160b2f605d9074106891288e85baaecfefreed@google.com SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path)); 2606437eea160b2f605d9074106891288e85baaecfefreed@google.com return this->createFromStream(stream); 2607484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com } 2608484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com 260930ddd615c447fed73286151b463af20d309c85f1reed@google.com virtual SkTypeface* onLegacyCreateTypeface(const char familyName[], 261030ddd615c447fed73286151b463af20d309c85f1reed@google.com unsigned styleBits) SK_OVERRIDE { 261130ddd615c447fed73286151b463af20d309c85f1reed@google.com return create_typeface(NULL, familyName, styleBits); 261230ddd615c447fed73286151b463af20d309c85f1reed@google.com } 261330ddd615c447fed73286151b463af20d309c85f1reed@google.com 2614484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.comprivate: 2615a65a681d43a8e9f5d8726a389832e957b07ee16breed@google.com SkTDArray<ENUMLOGFONTEX> fLogFontArray; 2616484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com}; 2617070da5edcb1c6e9b9507f06a5e2c270e1c1fd796reed@google.com 261830ddd615c447fed73286151b463af20d309c85f1reed@google.com/////////////////////////////////////////////////////////////////////////////// 261930ddd615c447fed73286151b463af20d309c85f1reed@google.com 262030ddd615c447fed73286151b463af20d309c85f1reed@google.com#ifndef SK_FONTHOST_USES_FONTMGR 262130ddd615c447fed73286151b463af20d309c85f1reed@google.com 262230ddd615c447fed73286151b463af20d309c85f1reed@google.comSkTypeface* SkFontHost::CreateTypeface(const SkTypeface* familyFace, 262330ddd615c447fed73286151b463af20d309c85f1reed@google.com const char familyName[], 262430ddd615c447fed73286151b463af20d309c85f1reed@google.com SkTypeface::Style styleBits) { 262530ddd615c447fed73286151b463af20d309c85f1reed@google.com return create_typeface(familyFace, familyName, styleBits); 262630ddd615c447fed73286151b463af20d309c85f1reed@google.com} 262730ddd615c447fed73286151b463af20d309c85f1reed@google.com 262830ddd615c447fed73286151b463af20d309c85f1reed@google.comSkTypeface* SkFontHost::CreateTypefaceFromFile(const char path[]) { 262930ddd615c447fed73286151b463af20d309c85f1reed@google.com SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path)); 263030ddd615c447fed73286151b463af20d309c85f1reed@google.com return stream.get() ? CreateTypefaceFromStream(stream) : NULL; 263130ddd615c447fed73286151b463af20d309c85f1reed@google.com} 263230ddd615c447fed73286151b463af20d309c85f1reed@google.com 263330ddd615c447fed73286151b463af20d309c85f1reed@google.comSkTypeface* SkFontHost::CreateTypefaceFromStream(SkStream* stream) { 263430ddd615c447fed73286151b463af20d309c85f1reed@google.com return create_from_stream(stream); 263530ddd615c447fed73286151b463af20d309c85f1reed@google.com} 263630ddd615c447fed73286151b463af20d309c85f1reed@google.com 263730ddd615c447fed73286151b463af20d309c85f1reed@google.com#endif 263830ddd615c447fed73286151b463af20d309c85f1reed@google.com 2639bfc6cc4b6c41e99d3887d268fbf798aa3abc9a27bungeman@google.comSkFontMgr* SkFontMgr_New_GDI() { 2640484f5bcf07c965e84cf021a6272aff73e2d7c1ecreed@google.com return SkNEW(SkFontMgrGDI); 2641070da5edcb1c6e9b9507f06a5e2c270e1c1fd796reed@google.com} 2642