Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkTypes.h" | 8 #include "SkTypes.h" |
| 9 #undef GetGlyphIndices | 9 #undef GetGlyphIndices |
| 10 | 10 |
| 11 #include "SkAdvancedTypefaceMetrics.h" | 11 #include "SkAdvancedTypefaceMetrics.h" |
| 12 #include "SkColorFilter.h" | 12 #include "SkColorFilter.h" |
| 13 #include "SkDWriteFontFileStream.h" | 13 #include "SkDWriteFontFileStream.h" |
| 14 #include "SkDWriteGeometrySink.h" | 14 #include "SkDWriteGeometrySink.h" |
| 15 #include "SkDescriptor.h" | 15 #include "SkDescriptor.h" |
| 16 #include "SkEndian.h" | 16 #include "SkEndian.h" |
| 17 #include "SkFontDescriptor.h" | 17 #include "SkFontDescriptor.h" |
| 18 #include "SkFontHost.h" | 18 #include "SkFontHost.h" |
| 19 #include "SkFontMgr.h" | 19 #include "SkFontMgr.h" |
| 20 #include "SkFontStream.h" | 20 #include "SkFontStream.h" |
| 21 #include "SkGlyph.h" | 21 #include "SkGlyph.h" |
| 22 #include "SkHRESULT.h" | 22 #include "SkHRESULT.h" |
| 23 #include "SkMaskGamma.h" | 23 #include "SkMaskGamma.h" |
| 24 #include "SkOnce.h" | |
| 24 #include "SkOTTable_head.h" | 25 #include "SkOTTable_head.h" |
| 25 #include "SkOTTable_hhea.h" | 26 #include "SkOTTable_hhea.h" |
| 26 #include "SkOTTable_OS_2.h" | 27 #include "SkOTTable_OS_2.h" |
| 27 #include "SkOTTable_post.h" | 28 #include "SkOTTable_post.h" |
| 28 #include "SkPath.h" | 29 #include "SkPath.h" |
| 29 #include "SkStream.h" | 30 #include "SkStream.h" |
| 30 #include "SkString.h" | 31 #include "SkString.h" |
| 31 #include "SkTScopedComPtr.h" | 32 #include "SkTScopedComPtr.h" |
| 32 #include "SkThread.h" | 33 #include "SkThread.h" |
| 33 #include "SkTypeface_win.h" | 34 #include "SkTypeface_win.h" |
| 34 #include "SkTypefaceCache.h" | 35 #include "SkTypefaceCache.h" |
| 35 #include "SkUtils.h" | 36 #include "SkUtils.h" |
| 36 | 37 |
| 37 #include <dwrite.h> | 38 #include <dwrite.h> |
| 38 | 39 |
| 39 static bool isLCD(const SkScalerContext::Rec& rec) { | 40 static bool isLCD(const SkScalerContext::Rec& rec) { |
| 40 return SkMask::kLCD16_Format == rec.fMaskFormat || | 41 return SkMask::kLCD16_Format == rec.fMaskFormat || |
| 41 SkMask::kLCD32_Format == rec.fMaskFormat; | 42 SkMask::kLCD32_Format == rec.fMaskFormat; |
| 42 } | 43 } |
| 43 | 44 |
| 44 /** Prefer to use this type to prevent template proliferation. */ | 45 /** Prefer to use this type to prevent template proliferation. */ |
| 45 typedef SkAutoSTMalloc<16, WCHAR> SkSMallocWCHAR; | 46 typedef SkAutoSTMalloc<16, WCHAR> SkSMallocWCHAR; |
| 46 | 47 |
| 48 /** Converts a utf8 string to a WCHAR string. */ | |
| 47 static HRESULT cstring_to_wchar(const char* skname, SkSMallocWCHAR* name) { | 49 static HRESULT cstring_to_wchar(const char* skname, SkSMallocWCHAR* name) { |
| 48 int wlen = MultiByteToWideChar(CP_UTF8, 0, skname, -1, NULL, 0); | 50 int wlen = MultiByteToWideChar(CP_UTF8, 0, skname, -1, NULL, 0); |
| 49 if (0 == wlen) { | 51 if (0 == wlen) { |
| 50 HRM(HRESULT_FROM_WIN32(GetLastError()), | 52 HRM(HRESULT_FROM_WIN32(GetLastError()), |
| 51 "Could not get length for wchar to utf-8 conversion."); | 53 "Could not get length for wchar to utf-8 conversion."); |
| 52 } | 54 } |
| 53 name->reset(wlen); | 55 name->reset(wlen); |
| 54 wlen = MultiByteToWideChar(CP_UTF8, 0, skname, -1, name->get(), wlen); | 56 wlen = MultiByteToWideChar(CP_UTF8, 0, skname, -1, name->get(), wlen); |
| 55 if (0 == wlen) { | 57 if (0 == wlen) { |
| 56 HRM(HRESULT_FROM_WIN32(GetLastError()), "Could not convert wchar to utf- 8."); | 58 HRM(HRESULT_FROM_WIN32(GetLastError()), "Could not convert wchar to utf- 8."); |
| 57 } | 59 } |
| 58 return S_OK; | 60 return S_OK; |
| 59 } | 61 } |
| 60 | 62 |
| 63 /** Converts a WCHAR string to a utf8 string. */ | |
| 61 static HRESULT wchar_to_skstring(WCHAR* name, SkString* skname) { | 64 static HRESULT wchar_to_skstring(WCHAR* name, SkString* skname) { |
| 62 int len = WideCharToMultiByte(CP_UTF8, 0, name, -1, NULL, 0, NULL, NULL); | 65 int len = WideCharToMultiByte(CP_UTF8, 0, name, -1, NULL, 0, NULL, NULL); |
| 63 if (0 == len) { | 66 if (0 == len) { |
| 64 HRM(HRESULT_FROM_WIN32(GetLastError()), | 67 HRM(HRESULT_FROM_WIN32(GetLastError()), |
| 65 "Could not get length for utf-8 to wchar conversion."); | 68 "Could not get length for utf-8 to wchar conversion."); |
| 66 } | 69 } |
| 67 skname->resize(len - 1); | 70 skname->resize(len - 1); |
| 68 len = WideCharToMultiByte(CP_UTF8, 0, name, -1, skname->writable_str(), len, NULL, NULL); | 71 len = WideCharToMultiByte(CP_UTF8, 0, name, -1, skname->writable_str(), len, NULL, NULL); |
| 69 if (0 == len) { | 72 if (0 == len) { |
| 70 HRM(HRESULT_FROM_WIN32(GetLastError()), "Could not convert utf-8 to wcha r."); | 73 HRM(HRESULT_FROM_WIN32(GetLastError()), "Could not convert utf-8 to wcha r."); |
| 71 } | 74 } |
| 72 return S_OK; | 75 return S_OK; |
| 73 } | 76 } |
| 74 | 77 |
| 75 /////////////////////////////////////////////////////////////////////////////// | 78 /////////////////////////////////////////////////////////////////////////////// |
| 76 | 79 |
| 80 static void create_dwrite_factory(IDWriteFactory** factory) { | |
| 81 typedef decltype(DWriteCreateFactory)* DWriteCreateFactoryProc; | |
| 82 DWriteCreateFactoryProc dWriteCreateFactoryProc = | |
| 83 reinterpret_cast<DWriteCreateFactoryProc>( | |
| 84 GetProcAddress(LoadLibraryW(L"dwrite.dll"), "DWriteCreateFactory") | |
| 85 ) | |
| 86 ; | |
|
caryclark
2013/12/09 18:45:50
I know this is old code, but I find the indention
bungeman-skia
2013/12/09 18:57:51
Probably not. I think the idea was to put the clos
| |
| 87 if (!dWriteCreateFactoryProc) { | |
| 88 HRESULT hr = HRESULT_FROM_WIN32(GetLastError()); | |
| 89 if (!IS_ERROR(hr)) { | |
| 90 hr = ERROR_PROC_NOT_FOUND; | |
| 91 } | |
| 92 HRVM(hr, "Could not get DWriteCreateFactory proc."); | |
| 93 } | |
| 94 | |
| 95 HRVM(dWriteCreateFactoryProc(DWRITE_FACTORY_TYPE_SHARED, | |
| 96 __uuidof(IDWriteFactory), | |
| 97 reinterpret_cast<IUnknown**>(&factory)), | |
| 98 "Could not create DirectWrite factory."); | |
|
caryclark
2013/12/09 18:45:50
More unusual indention
bungeman-skia
2013/12/09 18:57:51
Not sure this is that unusual, the HRVM macro take
| |
| 99 } | |
| 100 | |
| 101 static IDWriteFactory* get_dwrite_factory() { | |
| 102 static IDWriteFactory* gDWriteFactory = NULL; | |
| 103 SK_DECLARE_STATIC_ONCE(once); | |
| 104 SkOnce(&once, create_dwrite_factory, &gDWriteFactory); | |
| 105 | |
| 106 return gDWriteFactory; | |
| 107 } | |
| 108 | |
| 109 /////////////////////////////////////////////////////////////////////////////// | |
| 110 | |
| 77 class StreamFontFileLoader; | 111 class StreamFontFileLoader; |
| 78 | 112 |
| 79 class SkFontMgr_DirectWrite : public SkFontMgr { | 113 class SkFontMgr_DirectWrite : public SkFontMgr { |
| 80 public: | 114 public: |
| 81 /** localeNameLength must include the null terminator. */ | 115 /** localeNameLength must include the null terminator. */ |
| 82 SkFontMgr_DirectWrite(IDWriteFontCollection* fontCollection, | 116 SkFontMgr_DirectWrite(IDWriteFontCollection* fontCollection, |
| 83 WCHAR* localeName, int localeNameLength) | 117 WCHAR* localeName, int localeNameLength) |
| 84 : fFontCollection(SkRefComPtr(fontCollection)) | 118 : fFontCollection(SkRefComPtr(fontCollection)) |
| 85 , fLocaleName(localeNameLength) | 119 , fLocaleName(localeNameLength) |
| 86 { | 120 { |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 166 | 200 |
| 167 private: | 201 private: |
| 168 uint16_t fWidth; | 202 uint16_t fWidth; |
| 169 uint16_t fHeight; | 203 uint16_t fHeight; |
| 170 IDWriteFontFace* fFontFace; | 204 IDWriteFontFace* fFontFace; |
| 171 FLOAT fFontSize; | 205 FLOAT fFontSize; |
| 172 DWRITE_MATRIX fXform; | 206 DWRITE_MATRIX fXform; |
| 173 SkTDArray<uint8_t> fBits; | 207 SkTDArray<uint8_t> fBits; |
| 174 }; | 208 }; |
| 175 | 209 |
| 176 static HRESULT get_dwrite_factory(IDWriteFactory** factory) { | |
| 177 static IDWriteFactory* gDWriteFactory = NULL; | |
| 178 | |
| 179 if (gDWriteFactory != NULL) { | |
| 180 *factory = gDWriteFactory; | |
| 181 return S_OK; | |
| 182 } | |
| 183 | |
| 184 typedef decltype(DWriteCreateFactory)* DWriteCreateFactoryProc; | |
| 185 DWriteCreateFactoryProc dWriteCreateFactoryProc = | |
| 186 reinterpret_cast<DWriteCreateFactoryProc>( | |
| 187 GetProcAddress(LoadLibraryW(L"dwrite.dll"), "DWriteCreateFactory") | |
| 188 ) | |
| 189 ; | |
| 190 if (!dWriteCreateFactoryProc) { | |
| 191 HRESULT hr = HRESULT_FROM_WIN32(GetLastError()); | |
| 192 if (!IS_ERROR(hr)) { | |
| 193 hr = ERROR_PROC_NOT_FOUND; | |
| 194 } | |
| 195 return hr; | |
| 196 } | |
| 197 | |
| 198 HRM(dWriteCreateFactoryProc(DWRITE_FACTORY_TYPE_SHARED, | |
| 199 __uuidof(IDWriteFactory), | |
| 200 reinterpret_cast<IUnknown**>(&gDWriteFactory)), | |
| 201 "Could not create DirectWrite factory."); | |
| 202 | |
| 203 *factory = gDWriteFactory; | |
| 204 return S_OK; | |
| 205 } | |
| 206 | |
| 207 const void* DWriteOffscreen::draw(const SkGlyph& glyph, bool isBW) { | 210 const void* DWriteOffscreen::draw(const SkGlyph& glyph, bool isBW) { |
| 208 IDWriteFactory* factory; | 211 IDWriteFactory* factory = get_dwrite_factory(); |
| 209 HRNM(get_dwrite_factory(&factory), "Could not get factory."); | 212 SkASSERT(factory != NULL); |
| 210 | 213 |
| 211 if (fWidth < glyph.fWidth || fHeight < glyph.fHeight) { | 214 if (fWidth < glyph.fWidth || fHeight < glyph.fHeight) { |
| 212 fWidth = SkMax32(fWidth, glyph.fWidth); | 215 fWidth = SkMax32(fWidth, glyph.fWidth); |
| 213 fHeight = SkMax32(fHeight, glyph.fHeight); | 216 fHeight = SkMax32(fHeight, glyph.fHeight); |
| 214 | 217 |
| 215 if (isBW) { | 218 if (isBW) { |
| 216 fBits.setCount(fWidth * fHeight); | 219 fBits.setCount(fWidth * fHeight); |
| 217 } else { | 220 } else { |
| 218 fBits.setCount(fWidth * fHeight * 3); | 221 fBits.setCount(fWidth * fHeight * 3); |
| 219 } | 222 } |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 546 SkTypeface::Style style = get_style(font); | 549 SkTypeface::Style style = get_style(font); |
| 547 SkFontID fontID = SkTypefaceCache::NewFontID(); | 550 SkFontID fontID = SkTypefaceCache::NewFontID(); |
| 548 return SkNEW_ARGS(DWriteFontTypeface, (style, fontID, | 551 return SkNEW_ARGS(DWriteFontTypeface, (style, fontID, |
| 549 fontFace, font, fontFamily, | 552 fontFace, font, fontFamily, |
| 550 fontFileLoader, fontCollectionLoa der)); | 553 fontFileLoader, fontCollectionLoa der)); |
| 551 } | 554 } |
| 552 | 555 |
| 553 ~DWriteFontTypeface() { | 556 ~DWriteFontTypeface() { |
| 554 if (fDWriteFontCollectionLoader.get() == NULL) return; | 557 if (fDWriteFontCollectionLoader.get() == NULL) return; |
| 555 | 558 |
| 556 IDWriteFactory* factory; | 559 IDWriteFactory* factory = get_dwrite_factory(); |
| 557 HRVM(get_dwrite_factory(&factory), "Could not get factory."); | 560 SkASSERT(factory != NULL); |
| 558 HRV(factory->UnregisterFontCollectionLoader(fDWriteFontCollectionLoader. get())); | 561 HRV(factory->UnregisterFontCollectionLoader(fDWriteFontCollectionLoader. get())); |
| 559 HRV(factory->UnregisterFontFileLoader(fDWriteFontFileLoader.get())); | 562 HRV(factory->UnregisterFontFileLoader(fDWriteFontFileLoader.get())); |
| 560 } | 563 } |
| 561 | 564 |
| 562 protected: | 565 protected: |
| 563 virtual SkStream* onOpenStream(int* ttcIndex) const SK_OVERRIDE; | 566 virtual SkStream* onOpenStream(int* ttcIndex) const SK_OVERRIDE; |
| 564 virtual SkScalerContext* onCreateScalerContext(const SkDescriptor*) const SK _OVERRIDE; | 567 virtual SkScalerContext* onCreateScalerContext(const SkDescriptor*) const SK _OVERRIDE; |
| 565 virtual void onFilterRec(SkScalerContextRec*) const SK_OVERRIDE; | 568 virtual void onFilterRec(SkScalerContextRec*) const SK_OVERRIDE; |
| 566 virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics( | 569 virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics( |
| 567 SkAdvancedTypefaceMetrics::PerGlyphInfo, | 570 SkAdvancedTypefaceMetrics::PerGlyphInfo, |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 799 DWRITE_GLYPH_RUN run; | 802 DWRITE_GLYPH_RUN run; |
| 800 run.glyphCount = 1; | 803 run.glyphCount = 1; |
| 801 run.glyphAdvances = &advance; | 804 run.glyphAdvances = &advance; |
| 802 run.fontFace = fTypeface->fDWriteFontFace.get(); | 805 run.fontFace = fTypeface->fDWriteFontFace.get(); |
| 803 run.fontEmSize = SkScalarToFloat(fRec.fTextSize); | 806 run.fontEmSize = SkScalarToFloat(fRec.fTextSize); |
| 804 run.bidiLevel = 0; | 807 run.bidiLevel = 0; |
| 805 run.glyphIndices = &glyphId; | 808 run.glyphIndices = &glyphId; |
| 806 run.isSideways = FALSE; | 809 run.isSideways = FALSE; |
| 807 run.glyphOffsets = &offset; | 810 run.glyphOffsets = &offset; |
| 808 | 811 |
| 809 IDWriteFactory* factory; | 812 IDWriteFactory* factory = get_dwrite_factory(); |
| 810 HRVM(get_dwrite_factory(&factory), "Could not get factory."); | 813 SkASSERT(factory != NULL); |
| 811 | 814 |
| 812 const bool isBW = SkMask::kBW_Format == fRec.fMaskFormat; | 815 const bool isBW = SkMask::kBW_Format == fRec.fMaskFormat; |
| 813 DWRITE_RENDERING_MODE renderingMode; | 816 DWRITE_RENDERING_MODE renderingMode; |
| 814 DWRITE_TEXTURE_TYPE textureType; | 817 DWRITE_TEXTURE_TYPE textureType; |
| 815 if (isBW) { | 818 if (isBW) { |
| 816 renderingMode = DWRITE_RENDERING_MODE_ALIASED; | 819 renderingMode = DWRITE_RENDERING_MODE_ALIASED; |
| 817 textureType = DWRITE_TEXTURE_ALIASED_1x1; | 820 textureType = DWRITE_TEXTURE_ALIASED_1x1; |
| 818 } else { | 821 } else { |
| 819 renderingMode = DWRITE_RENDERING_MODE_CLEARTYPE_NATURAL_SYMMETRIC; | 822 renderingMode = DWRITE_RENDERING_MODE_CLEARTYPE_NATURAL_SYMMETRIC; |
| 820 textureType = DWRITE_TEXTURE_CLEARTYPE_3x1; | 823 textureType = DWRITE_TEXTURE_CLEARTYPE_3x1; |
| (...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1265 | 1268 |
| 1266 HRESULT unregister(IDWriteFactory* factory, IDWriteFontCollectionLoader* unr egister) { | 1269 HRESULT unregister(IDWriteFactory* factory, IDWriteFontCollectionLoader* unr egister) { |
| 1267 return factory->UnregisterFontCollectionLoader(unregister); | 1270 return factory->UnregisterFontCollectionLoader(unregister); |
| 1268 } | 1271 } |
| 1269 | 1272 |
| 1270 IDWriteFactory* fFactory; | 1273 IDWriteFactory* fFactory; |
| 1271 T* fUnregister; | 1274 T* fUnregister; |
| 1272 }; | 1275 }; |
| 1273 | 1276 |
| 1274 static SkTypeface* create_from_stream(SkStream* stream, int ttcIndex) { | 1277 static SkTypeface* create_from_stream(SkStream* stream, int ttcIndex) { |
| 1275 IDWriteFactory* factory; | 1278 IDWriteFactory* factory = get_dwrite_factory(); |
| 1276 HRN(get_dwrite_factory(&factory)); | 1279 if (NULL == factory) { |
| 1280 return NULL; | |
| 1281 } | |
| 1277 | 1282 |
| 1278 SkTScopedComPtr<StreamFontFileLoader> fontFileLoader; | 1283 SkTScopedComPtr<StreamFontFileLoader> fontFileLoader; |
| 1279 HRN(StreamFontFileLoader::Create(stream, &fontFileLoader)); | 1284 HRN(StreamFontFileLoader::Create(stream, &fontFileLoader)); |
| 1280 HRN(factory->RegisterFontFileLoader(fontFileLoader.get())); | 1285 HRN(factory->RegisterFontFileLoader(fontFileLoader.get())); |
| 1281 SkAutoIDWriteUnregister<StreamFontFileLoader> autoUnregisterFontFileLoader( | 1286 SkAutoIDWriteUnregister<StreamFontFileLoader> autoUnregisterFontFileLoader( |
| 1282 factory, fontFileLoader.get()); | 1287 factory, fontFileLoader.get()); |
| 1283 | 1288 |
| 1284 SkTScopedComPtr<StreamFontCollectionLoader> fontCollectionLoader; | 1289 SkTScopedComPtr<StreamFontCollectionLoader> fontCollectionLoader; |
| 1285 HRN(StreamFontCollectionLoader::Create(fontFileLoader.get(), &fontCollection Loader)); | 1290 HRN(StreamFontCollectionLoader::Create(fontFileLoader.get(), &fontCollection Loader)); |
| 1286 HRN(factory->RegisterFontCollectionLoader(fontCollectionLoader.get())); | 1291 HRN(factory->RegisterFontCollectionLoader(fontCollectionLoader.get())); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1366 SkScalerContext::kLCD_BGROrder_Flag | | 1371 SkScalerContext::kLCD_BGROrder_Flag | |
| 1367 SkScalerContext::kLCD_Vertical_Flag; | 1372 SkScalerContext::kLCD_Vertical_Flag; |
| 1368 rec->fFlags &= ~flagsWeDontSupport; | 1373 rec->fFlags &= ~flagsWeDontSupport; |
| 1369 | 1374 |
| 1370 SkPaint::Hinting h = rec->getHinting(); | 1375 SkPaint::Hinting h = rec->getHinting(); |
| 1371 // DirectWrite does not provide for hinting hints. | 1376 // DirectWrite does not provide for hinting hints. |
| 1372 h = SkPaint::kSlight_Hinting; | 1377 h = SkPaint::kSlight_Hinting; |
| 1373 rec->setHinting(h); | 1378 rec->setHinting(h); |
| 1374 | 1379 |
| 1375 #if SK_FONT_HOST_USE_SYSTEM_SETTINGS | 1380 #if SK_FONT_HOST_USE_SYSTEM_SETTINGS |
| 1376 IDWriteFactory* factory; | 1381 IDWriteFactory* factory = get_dwrite_factory(); |
| 1377 if (SUCCEEDED(get_dwrite_factory(&factory))) { | 1382 if (factory != NULL) { |
| 1378 SkTScopedComPtr<IDWriteRenderingParams> defaultRenderingParams; | 1383 SkTScopedComPtr<IDWriteRenderingParams> defaultRenderingParams; |
| 1379 if (SUCCEEDED(factory->CreateRenderingParams(&defaultRenderingParams))) { | 1384 if (SUCCEEDED(factory->CreateRenderingParams(&defaultRenderingParams))) { |
| 1380 float gamma = defaultRenderingParams->GetGamma(); | 1385 float gamma = defaultRenderingParams->GetGamma(); |
| 1381 rec->setDeviceGamma(gamma); | 1386 rec->setDeviceGamma(gamma); |
| 1382 rec->setPaintGamma(gamma); | 1387 rec->setPaintGamma(gamma); |
| 1383 | 1388 |
| 1384 rec->setContrast(defaultRenderingParams->GetEnhancedContrast()); | 1389 rec->setContrast(defaultRenderingParams->GetEnhancedContrast()); |
| 1385 } | 1390 } |
| 1386 } | 1391 } |
| 1387 #endif | 1392 #endif |
| (...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1873 HRESULT hr = HRESULT_FROM_WIN32(GetLastError()); | 1878 HRESULT hr = HRESULT_FROM_WIN32(GetLastError()); |
| 1874 if (!IS_ERROR(hr)) { | 1879 if (!IS_ERROR(hr)) { |
| 1875 hr = ERROR_PROC_NOT_FOUND; | 1880 hr = ERROR_PROC_NOT_FOUND; |
| 1876 } | 1881 } |
| 1877 return hr; | 1882 return hr; |
| 1878 } | 1883 } |
| 1879 return S_OK; | 1884 return S_OK; |
| 1880 } | 1885 } |
| 1881 | 1886 |
| 1882 SkFontMgr* SkFontMgr_New_DirectWrite() { | 1887 SkFontMgr* SkFontMgr_New_DirectWrite() { |
| 1883 IDWriteFactory* factory; | 1888 IDWriteFactory* factory = get_dwrite_factory(); |
| 1884 HRNM(get_dwrite_factory(&factory), "Could not get factory."); | 1889 if (NULL == factory) { |
| 1890 return NULL; | |
| 1891 } | |
| 1885 | 1892 |
| 1886 SkTScopedComPtr<IDWriteFontCollection> sysFontCollection; | 1893 SkTScopedComPtr<IDWriteFontCollection> sysFontCollection; |
| 1887 HRNM(factory->GetSystemFontCollection(&sysFontCollection, FALSE), | 1894 HRNM(factory->GetSystemFontCollection(&sysFontCollection, FALSE), |
| 1888 "Could not get system font collection."); | 1895 "Could not get system font collection."); |
| 1889 | 1896 |
| 1890 WCHAR localeNameStorage[LOCALE_NAME_MAX_LENGTH]; | 1897 WCHAR localeNameStorage[LOCALE_NAME_MAX_LENGTH]; |
| 1891 WCHAR* localeName = NULL; | 1898 WCHAR* localeName = NULL; |
| 1892 int localeNameLen = 0; | 1899 int localeNameLen = 0; |
| 1893 | 1900 |
| 1894 // Dynamically load GetUserDefaultLocaleName function, as it is not availabl e on XP. | 1901 // Dynamically load GetUserDefaultLocaleName function, as it is not availabl e on XP. |
| 1895 GetUserDefaultLocaleNameProc getUserDefaultLocaleNameProc = NULL; | 1902 GetUserDefaultLocaleNameProc getUserDefaultLocaleNameProc = NULL; |
| 1896 HRESULT hr = GetGetUserDefaultLocaleNameProc(&getUserDefaultLocaleNameProc); | 1903 HRESULT hr = GetGetUserDefaultLocaleNameProc(&getUserDefaultLocaleNameProc); |
| 1897 if (NULL == getUserDefaultLocaleNameProc) { | 1904 if (NULL == getUserDefaultLocaleNameProc) { |
| 1898 SK_TRACEHR(hr, "Could not get GetUserDefaultLocaleName."); | 1905 SK_TRACEHR(hr, "Could not get GetUserDefaultLocaleName."); |
| 1899 } else { | 1906 } else { |
| 1900 localeNameLen = getUserDefaultLocaleNameProc(localeNameStorage, LOCALE_N AME_MAX_LENGTH); | 1907 localeNameLen = getUserDefaultLocaleNameProc(localeNameStorage, LOCALE_N AME_MAX_LENGTH); |
| 1901 if (localeNameLen) { | 1908 if (localeNameLen) { |
| 1902 localeName = localeNameStorage; | 1909 localeName = localeNameStorage; |
| 1903 }; | 1910 }; |
| 1904 } | 1911 } |
| 1905 | 1912 |
| 1906 return SkNEW_ARGS(SkFontMgr_DirectWrite, (sysFontCollection.get(), localeNam e, localeNameLen)); | 1913 return SkNEW_ARGS(SkFontMgr_DirectWrite, (sysFontCollection.get(), localeNam e, localeNameLen)); |
| 1907 } | 1914 } |
| OLD | NEW |