OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 "SkDWrite.h" | 8 #include "SkDWrite.h" |
9 #include "SkDWriteFontFileStream.h" | 9 #include "SkDWriteFontFileStream.h" |
10 #include "SkFontMgr.h" | 10 #include "SkFontMgr.h" |
(...skipping 24 matching lines...) Expand all Loading... |
35 | 35 |
36 // IDWriteFontFileLoader methods | 36 // IDWriteFontFileLoader methods |
37 virtual HRESULT STDMETHODCALLTYPE CreateStreamFromKey( | 37 virtual HRESULT STDMETHODCALLTYPE CreateStreamFromKey( |
38 void const* fontFileReferenceKey, | 38 void const* fontFileReferenceKey, |
39 UINT32 fontFileReferenceKeySize, | 39 UINT32 fontFileReferenceKeySize, |
40 IDWriteFontFileStream** fontFileStream); | 40 IDWriteFontFileStream** fontFileStream); |
41 | 41 |
42 // Takes ownership of stream. | 42 // Takes ownership of stream. |
43 static HRESULT Create(SkStreamAsset* stream, StreamFontFileLoader** streamFo
ntFileLoader) { | 43 static HRESULT Create(SkStreamAsset* stream, StreamFontFileLoader** streamFo
ntFileLoader) { |
44 *streamFontFileLoader = new StreamFontFileLoader(stream); | 44 *streamFontFileLoader = new StreamFontFileLoader(stream); |
45 if (NULL == streamFontFileLoader) { | 45 if (nullptr == streamFontFileLoader) { |
46 return E_OUTOFMEMORY; | 46 return E_OUTOFMEMORY; |
47 } | 47 } |
48 return S_OK; | 48 return S_OK; |
49 } | 49 } |
50 | 50 |
51 SkAutoTDelete<SkStreamAsset> fStream; | 51 SkAutoTDelete<SkStreamAsset> fStream; |
52 | 52 |
53 private: | 53 private: |
54 StreamFontFileLoader(SkStreamAsset* stream) : fStream(stream), fRefCount(1)
{ } | 54 StreamFontFileLoader(SkStreamAsset* stream) : fStream(stream), fRefCount(1)
{ } |
55 virtual ~StreamFontFileLoader() { } | 55 virtual ~StreamFontFileLoader() { } |
56 | 56 |
57 ULONG fRefCount; | 57 ULONG fRefCount; |
58 }; | 58 }; |
59 | 59 |
60 HRESULT StreamFontFileLoader::QueryInterface(REFIID iid, void** ppvObject) { | 60 HRESULT StreamFontFileLoader::QueryInterface(REFIID iid, void** ppvObject) { |
61 if (iid == IID_IUnknown || iid == __uuidof(IDWriteFontFileLoader)) { | 61 if (iid == IID_IUnknown || iid == __uuidof(IDWriteFontFileLoader)) { |
62 *ppvObject = this; | 62 *ppvObject = this; |
63 AddRef(); | 63 AddRef(); |
64 return S_OK; | 64 return S_OK; |
65 } else { | 65 } else { |
66 *ppvObject = NULL; | 66 *ppvObject = nullptr; |
67 return E_NOINTERFACE; | 67 return E_NOINTERFACE; |
68 } | 68 } |
69 } | 69 } |
70 | 70 |
71 ULONG StreamFontFileLoader::AddRef() { | 71 ULONG StreamFontFileLoader::AddRef() { |
72 return InterlockedIncrement(&fRefCount); | 72 return InterlockedIncrement(&fRefCount); |
73 } | 73 } |
74 | 74 |
75 ULONG StreamFontFileLoader::Release() { | 75 ULONG StreamFontFileLoader::Release() { |
76 ULONG newCount = InterlockedDecrement(&fRefCount); | 76 ULONG newCount = InterlockedDecrement(&fRefCount); |
(...skipping 23 matching lines...) Expand all Loading... |
100 virtual ULONG STDMETHODCALLTYPE AddRef(); | 100 virtual ULONG STDMETHODCALLTYPE AddRef(); |
101 virtual ULONG STDMETHODCALLTYPE Release(); | 101 virtual ULONG STDMETHODCALLTYPE Release(); |
102 | 102 |
103 // IDWriteFontFileEnumerator methods | 103 // IDWriteFontFileEnumerator methods |
104 virtual HRESULT STDMETHODCALLTYPE MoveNext(BOOL* hasCurrentFile); | 104 virtual HRESULT STDMETHODCALLTYPE MoveNext(BOOL* hasCurrentFile); |
105 virtual HRESULT STDMETHODCALLTYPE GetCurrentFontFile(IDWriteFontFile** fontF
ile); | 105 virtual HRESULT STDMETHODCALLTYPE GetCurrentFontFile(IDWriteFontFile** fontF
ile); |
106 | 106 |
107 static HRESULT Create(IDWriteFactory* factory, IDWriteFontFileLoader* fontFi
leLoader, | 107 static HRESULT Create(IDWriteFactory* factory, IDWriteFontFileLoader* fontFi
leLoader, |
108 StreamFontFileEnumerator** streamFontFileEnumerator) { | 108 StreamFontFileEnumerator** streamFontFileEnumerator) { |
109 *streamFontFileEnumerator = new StreamFontFileEnumerator(factory, fontFi
leLoader); | 109 *streamFontFileEnumerator = new StreamFontFileEnumerator(factory, fontFi
leLoader); |
110 if (NULL == streamFontFileEnumerator) { | 110 if (nullptr == streamFontFileEnumerator) { |
111 return E_OUTOFMEMORY; | 111 return E_OUTOFMEMORY; |
112 } | 112 } |
113 return S_OK; | 113 return S_OK; |
114 } | 114 } |
115 private: | 115 private: |
116 StreamFontFileEnumerator(IDWriteFactory* factory, IDWriteFontFileLoader* fon
tFileLoader); | 116 StreamFontFileEnumerator(IDWriteFactory* factory, IDWriteFontFileLoader* fon
tFileLoader); |
117 virtual ~StreamFontFileEnumerator() { } | 117 virtual ~StreamFontFileEnumerator() { } |
118 | 118 |
119 ULONG fRefCount; | 119 ULONG fRefCount; |
120 | 120 |
(...skipping 11 matching lines...) Expand all Loading... |
132 , fFontFileLoader(SkRefComPtr(fontFileLoader)) | 132 , fFontFileLoader(SkRefComPtr(fontFileLoader)) |
133 , fHasNext(true) | 133 , fHasNext(true) |
134 { } | 134 { } |
135 | 135 |
136 HRESULT StreamFontFileEnumerator::QueryInterface(REFIID iid, void** ppvObject) { | 136 HRESULT StreamFontFileEnumerator::QueryInterface(REFIID iid, void** ppvObject) { |
137 if (iid == IID_IUnknown || iid == __uuidof(IDWriteFontFileEnumerator)) { | 137 if (iid == IID_IUnknown || iid == __uuidof(IDWriteFontFileEnumerator)) { |
138 *ppvObject = this; | 138 *ppvObject = this; |
139 AddRef(); | 139 AddRef(); |
140 return S_OK; | 140 return S_OK; |
141 } else { | 141 } else { |
142 *ppvObject = NULL; | 142 *ppvObject = nullptr; |
143 return E_NOINTERFACE; | 143 return E_NOINTERFACE; |
144 } | 144 } |
145 } | 145 } |
146 | 146 |
147 ULONG StreamFontFileEnumerator::AddRef() { | 147 ULONG StreamFontFileEnumerator::AddRef() { |
148 return InterlockedIncrement(&fRefCount); | 148 return InterlockedIncrement(&fRefCount); |
149 } | 149 } |
150 | 150 |
151 ULONG StreamFontFileEnumerator::Release() { | 151 ULONG StreamFontFileEnumerator::Release() { |
152 ULONG newCount = InterlockedDecrement(&fRefCount); | 152 ULONG newCount = InterlockedDecrement(&fRefCount); |
153 if (0 == newCount) { | 153 if (0 == newCount) { |
154 delete this; | 154 delete this; |
155 } | 155 } |
156 return newCount; | 156 return newCount; |
157 } | 157 } |
158 | 158 |
159 HRESULT StreamFontFileEnumerator::MoveNext(BOOL* hasCurrentFile) { | 159 HRESULT StreamFontFileEnumerator::MoveNext(BOOL* hasCurrentFile) { |
160 *hasCurrentFile = FALSE; | 160 *hasCurrentFile = FALSE; |
161 | 161 |
162 if (!fHasNext) { | 162 if (!fHasNext) { |
163 return S_OK; | 163 return S_OK; |
164 } | 164 } |
165 fHasNext = false; | 165 fHasNext = false; |
166 | 166 |
167 UINT32 dummy = 0; | 167 UINT32 dummy = 0; |
168 HR(fFactory->CreateCustomFontFileReference( | 168 HR(fFactory->CreateCustomFontFileReference( |
169 &dummy, //cannot be NULL | 169 &dummy, //cannot be nullptr |
170 sizeof(dummy), //even if this is 0 | 170 sizeof(dummy), //even if this is 0 |
171 fFontFileLoader.get(), | 171 fFontFileLoader.get(), |
172 &fCurrentFile)); | 172 &fCurrentFile)); |
173 | 173 |
174 *hasCurrentFile = TRUE; | 174 *hasCurrentFile = TRUE; |
175 return S_OK; | 175 return S_OK; |
176 } | 176 } |
177 | 177 |
178 HRESULT StreamFontFileEnumerator::GetCurrentFontFile(IDWriteFontFile** fontFile)
{ | 178 HRESULT StreamFontFileEnumerator::GetCurrentFontFile(IDWriteFontFile** fontFile)
{ |
179 if (fCurrentFile.get() == NULL) { | 179 if (fCurrentFile.get() == nullptr) { |
180 *fontFile = NULL; | 180 *fontFile = nullptr; |
181 return E_FAIL; | 181 return E_FAIL; |
182 } | 182 } |
183 | 183 |
184 *fontFile = SkRefComPtr(fCurrentFile.get()); | 184 *fontFile = SkRefComPtr(fCurrentFile.get()); |
185 return S_OK; | 185 return S_OK; |
186 } | 186 } |
187 | 187 |
188 //////////////////////////////////////////////////////////////////////////////// | 188 //////////////////////////////////////////////////////////////////////////////// |
189 | 189 |
190 class StreamFontCollectionLoader : public IDWriteFontCollectionLoader { | 190 class StreamFontCollectionLoader : public IDWriteFontCollectionLoader { |
191 public: | 191 public: |
192 // IUnknown methods | 192 // IUnknown methods |
193 virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, void** ppvObjec
t); | 193 virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, void** ppvObjec
t); |
194 virtual ULONG STDMETHODCALLTYPE AddRef(); | 194 virtual ULONG STDMETHODCALLTYPE AddRef(); |
195 virtual ULONG STDMETHODCALLTYPE Release(); | 195 virtual ULONG STDMETHODCALLTYPE Release(); |
196 | 196 |
197 // IDWriteFontCollectionLoader methods | 197 // IDWriteFontCollectionLoader methods |
198 virtual HRESULT STDMETHODCALLTYPE CreateEnumeratorFromKey( | 198 virtual HRESULT STDMETHODCALLTYPE CreateEnumeratorFromKey( |
199 IDWriteFactory* factory, | 199 IDWriteFactory* factory, |
200 void const* collectionKey, | 200 void const* collectionKey, |
201 UINT32 collectionKeySize, | 201 UINT32 collectionKeySize, |
202 IDWriteFontFileEnumerator** fontFileEnumerator); | 202 IDWriteFontFileEnumerator** fontFileEnumerator); |
203 | 203 |
204 static HRESULT Create(IDWriteFontFileLoader* fontFileLoader, | 204 static HRESULT Create(IDWriteFontFileLoader* fontFileLoader, |
205 StreamFontCollectionLoader** streamFontCollectionLoade
r) { | 205 StreamFontCollectionLoader** streamFontCollectionLoade
r) { |
206 *streamFontCollectionLoader = new StreamFontCollectionLoader(fontFileLoa
der); | 206 *streamFontCollectionLoader = new StreamFontCollectionLoader(fontFileLoa
der); |
207 if (NULL == streamFontCollectionLoader) { | 207 if (nullptr == streamFontCollectionLoader) { |
208 return E_OUTOFMEMORY; | 208 return E_OUTOFMEMORY; |
209 } | 209 } |
210 return S_OK; | 210 return S_OK; |
211 } | 211 } |
212 private: | 212 private: |
213 StreamFontCollectionLoader(IDWriteFontFileLoader* fontFileLoader) | 213 StreamFontCollectionLoader(IDWriteFontFileLoader* fontFileLoader) |
214 : fRefCount(1) | 214 : fRefCount(1) |
215 , fFontFileLoader(SkRefComPtr(fontFileLoader)) | 215 , fFontFileLoader(SkRefComPtr(fontFileLoader)) |
216 { } | 216 { } |
217 virtual ~StreamFontCollectionLoader() { } | 217 virtual ~StreamFontCollectionLoader() { } |
218 | 218 |
219 ULONG fRefCount; | 219 ULONG fRefCount; |
220 SkTScopedComPtr<IDWriteFontFileLoader> fFontFileLoader; | 220 SkTScopedComPtr<IDWriteFontFileLoader> fFontFileLoader; |
221 }; | 221 }; |
222 | 222 |
223 HRESULT StreamFontCollectionLoader::QueryInterface(REFIID iid, void** ppvObject)
{ | 223 HRESULT StreamFontCollectionLoader::QueryInterface(REFIID iid, void** ppvObject)
{ |
224 if (iid == IID_IUnknown || iid == __uuidof(IDWriteFontCollectionLoader)) { | 224 if (iid == IID_IUnknown || iid == __uuidof(IDWriteFontCollectionLoader)) { |
225 *ppvObject = this; | 225 *ppvObject = this; |
226 AddRef(); | 226 AddRef(); |
227 return S_OK; | 227 return S_OK; |
228 } else { | 228 } else { |
229 *ppvObject = NULL; | 229 *ppvObject = nullptr; |
230 return E_NOINTERFACE; | 230 return E_NOINTERFACE; |
231 } | 231 } |
232 } | 232 } |
233 | 233 |
234 ULONG StreamFontCollectionLoader::AddRef() { | 234 ULONG StreamFontCollectionLoader::AddRef() { |
235 return InterlockedIncrement(&fRefCount); | 235 return InterlockedIncrement(&fRefCount); |
236 } | 236 } |
237 | 237 |
238 ULONG StreamFontCollectionLoader::Release() { | 238 ULONG StreamFontCollectionLoader::Release() { |
239 ULONG newCount = InterlockedDecrement(&fRefCount); | 239 ULONG newCount = InterlockedDecrement(&fRefCount); |
(...skipping 21 matching lines...) Expand all Loading... |
261 public: | 261 public: |
262 /** localeNameLength must include the null terminator. */ | 262 /** localeNameLength must include the null terminator. */ |
263 SkFontMgr_DirectWrite(IDWriteFactory* factory, IDWriteFontCollection* fontCo
llection, | 263 SkFontMgr_DirectWrite(IDWriteFactory* factory, IDWriteFontCollection* fontCo
llection, |
264 WCHAR* localeName, int localeNameLength) | 264 WCHAR* localeName, int localeNameLength) |
265 : fFactory(SkRefComPtr(factory)) | 265 : fFactory(SkRefComPtr(factory)) |
266 , fFontCollection(SkRefComPtr(fontCollection)) | 266 , fFontCollection(SkRefComPtr(fontCollection)) |
267 , fLocaleName(localeNameLength) | 267 , fLocaleName(localeNameLength) |
268 { | 268 { |
269 #if SK_HAS_DWRITE_2_H | 269 #if SK_HAS_DWRITE_2_H |
270 if (!SUCCEEDED(fFactory->QueryInterface(&fFactory2))) { | 270 if (!SUCCEEDED(fFactory->QueryInterface(&fFactory2))) { |
271 // IUnknown::QueryInterface states that if it fails, punk will be se
t to NULL. | 271 // IUnknown::QueryInterface states that if it fails, punk will be se
t to nullptr. |
272 // http://blogs.msdn.com/b/oldnewthing/archive/2004/03/26/96777.aspx | 272 // http://blogs.msdn.com/b/oldnewthing/archive/2004/03/26/96777.aspx |
273 SK_ALWAYSBREAK(NULL == fFactory2.get()); | 273 SK_ALWAYSBREAK(nullptr == fFactory2.get()); |
274 } | 274 } |
275 #endif | 275 #endif |
276 memcpy(fLocaleName.get(), localeName, localeNameLength * sizeof(WCHAR)); | 276 memcpy(fLocaleName.get(), localeName, localeNameLength * sizeof(WCHAR)); |
277 } | 277 } |
278 | 278 |
279 protected: | 279 protected: |
280 int onCountFamilies() const override; | 280 int onCountFamilies() const override; |
281 void onGetFamilyName(int index, SkString* familyName) const override; | 281 void onGetFamilyName(int index, SkString* familyName) const override; |
282 SkFontStyleSet* onCreateStyleSet(int index) const override; | 282 SkFontStyleSet* onCreateStyleSet(int index) const override; |
283 SkFontStyleSet* onMatchFamily(const char familyName[]) const override; | 283 SkFontStyleSet* onMatchFamily(const char familyName[]) const override; |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 } | 363 } |
364 | 364 |
365 HRB(are_same(cshFace->fDWriteFontFace.get(), ctxFace->fDWriteFontFace, same)
); | 365 HRB(are_same(cshFace->fDWriteFontFace.get(), ctxFace->fDWriteFontFace, same)
); |
366 if (same) { | 366 if (same) { |
367 return true; | 367 return true; |
368 } | 368 } |
369 | 369 |
370 //Check if the two fonts share the same loader and have the same key. | 370 //Check if the two fonts share the same loader and have the same key. |
371 UINT32 cshNumFiles; | 371 UINT32 cshNumFiles; |
372 UINT32 ctxNumFiles; | 372 UINT32 ctxNumFiles; |
373 HRB(cshFace->fDWriteFontFace->GetFiles(&cshNumFiles, NULL)); | 373 HRB(cshFace->fDWriteFontFace->GetFiles(&cshNumFiles, nullptr)); |
374 HRB(ctxFace->fDWriteFontFace->GetFiles(&ctxNumFiles, NULL)); | 374 HRB(ctxFace->fDWriteFontFace->GetFiles(&ctxNumFiles, nullptr)); |
375 if (cshNumFiles != ctxNumFiles) { | 375 if (cshNumFiles != ctxNumFiles) { |
376 return false; | 376 return false; |
377 } | 377 } |
378 | 378 |
379 SkTScopedComPtr<IDWriteFontFile> cshFontFile; | 379 SkTScopedComPtr<IDWriteFontFile> cshFontFile; |
380 SkTScopedComPtr<IDWriteFontFile> ctxFontFile; | 380 SkTScopedComPtr<IDWriteFontFile> ctxFontFile; |
381 HRB(cshFace->fDWriteFontFace->GetFiles(&cshNumFiles, &cshFontFile)); | 381 HRB(cshFace->fDWriteFontFace->GetFiles(&cshNumFiles, &cshFontFile)); |
382 HRB(ctxFace->fDWriteFontFace->GetFiles(&ctxNumFiles, &ctxFontFile)); | 382 HRB(ctxFace->fDWriteFontFace->GetFiles(&ctxNumFiles, &ctxFontFile)); |
383 | 383 |
384 //for (each file) { //we currently only admit fonts from one file. | 384 //for (each file) { //we currently only admit fonts from one file. |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 wcscmp(cshFaceName.get(), ctxFaceName.get()) == 0; | 445 wcscmp(cshFaceName.get(), ctxFaceName.get()) == 0; |
446 } | 446 } |
447 | 447 |
448 SkTypeface* SkFontMgr_DirectWrite::createTypefaceFromDWriteFont( | 448 SkTypeface* SkFontMgr_DirectWrite::createTypefaceFromDWriteFont( |
449 IDWriteFontFace* fontFace, | 449 IDWriteFontFace* fontFace, |
450 IDWriteFont* font, | 450 IDWriteFont* font, |
451 IDWriteFontFamily* fontFamily) const { | 451 IDWriteFontFamily* fontFamily) const { |
452 SkAutoMutexAcquire ama(fTFCacheMutex); | 452 SkAutoMutexAcquire ama(fTFCacheMutex); |
453 ProtoDWriteTypeface spec = { fontFace, font, fontFamily }; | 453 ProtoDWriteTypeface spec = { fontFace, font, fontFamily }; |
454 SkTypeface* face = fTFCache.findByProcAndRef(FindByDWriteFont, &spec); | 454 SkTypeface* face = fTFCache.findByProcAndRef(FindByDWriteFont, &spec); |
455 if (NULL == face) { | 455 if (nullptr == face) { |
456 face = DWriteFontTypeface::Create(fFactory.get(), fontFace, font, fontFa
mily); | 456 face = DWriteFontTypeface::Create(fFactory.get(), fontFace, font, fontFa
mily); |
457 if (face) { | 457 if (face) { |
458 fTFCache.add(face, get_style(font)); | 458 fTFCache.add(face, get_style(font)); |
459 } | 459 } |
460 } | 460 } |
461 return face; | 461 return face; |
462 } | 462 } |
463 | 463 |
464 int SkFontMgr_DirectWrite::onCountFamilies() const { | 464 int SkFontMgr_DirectWrite::onCountFamilies() const { |
465 return fFontCollection->GetFontFamilyCount(); | 465 return fFontCollection->GetFontFamilyCount(); |
(...skipping 18 matching lines...) Expand all Loading... |
484 | 484 |
485 SkFontStyleSet* SkFontMgr_DirectWrite::onMatchFamily(const char familyName[]) co
nst { | 485 SkFontStyleSet* SkFontMgr_DirectWrite::onMatchFamily(const char familyName[]) co
nst { |
486 SkSMallocWCHAR dwFamilyName; | 486 SkSMallocWCHAR dwFamilyName; |
487 HRN(sk_cstring_to_wchar(familyName, &dwFamilyName)); | 487 HRN(sk_cstring_to_wchar(familyName, &dwFamilyName)); |
488 | 488 |
489 UINT32 index; | 489 UINT32 index; |
490 BOOL exists; | 490 BOOL exists; |
491 HRNM(fFontCollection->FindFamilyName(dwFamilyName.get(), &index, &exists), | 491 HRNM(fFontCollection->FindFamilyName(dwFamilyName.get(), &index, &exists), |
492 "Failed while finding family by name."); | 492 "Failed while finding family by name."); |
493 if (!exists) { | 493 if (!exists) { |
494 return NULL; | 494 return nullptr; |
495 } | 495 } |
496 | 496 |
497 return this->onCreateStyleSet(index); | 497 return this->onCreateStyleSet(index); |
498 } | 498 } |
499 | 499 |
500 SkTypeface* SkFontMgr_DirectWrite::onMatchFamilyStyle(const char familyName[], | 500 SkTypeface* SkFontMgr_DirectWrite::onMatchFamilyStyle(const char familyName[], |
501 const SkFontStyle& fontsty
le) const { | 501 const SkFontStyle& fontsty
le) const { |
502 SkAutoTUnref<SkFontStyleSet> sset(this->matchFamily(familyName)); | 502 SkAutoTUnref<SkFontStyleSet> sset(this->matchFamily(familyName)); |
503 return sset->matchStyle(fontstyle); | 503 return sset->matchStyle(fontstyle); |
504 } | 504 } |
505 | 505 |
506 class FontFallbackRenderer : public IDWriteTextRenderer { | 506 class FontFallbackRenderer : public IDWriteTextRenderer { |
507 public: | 507 public: |
508 FontFallbackRenderer(const SkFontMgr_DirectWrite* outer, UINT32 character) | 508 FontFallbackRenderer(const SkFontMgr_DirectWrite* outer, UINT32 character) |
509 : fRefCount(1), fOuter(SkSafeRef(outer)), fCharacter(character), fResolv
edTypeface(NULL) { | 509 : fRefCount(1), fOuter(SkSafeRef(outer)), fCharacter(character), fResolv
edTypeface(nullptr) { |
510 } | 510 } |
511 | 511 |
512 virtual ~FontFallbackRenderer() { } | 512 virtual ~FontFallbackRenderer() { } |
513 | 513 |
514 // IDWriteTextRenderer methods | 514 // IDWriteTextRenderer methods |
515 virtual HRESULT STDMETHODCALLTYPE DrawGlyphRun( | 515 virtual HRESULT STDMETHODCALLTYPE DrawGlyphRun( |
516 void* clientDrawingContext, | 516 void* clientDrawingContext, |
517 FLOAT baselineOriginX, | 517 FLOAT baselineOriginX, |
518 FLOAT baselineOriginY, | 518 FLOAT baselineOriginY, |
519 DWRITE_MEASURING_MODE measuringMode, | 519 DWRITE_MEASURING_MODE measuringMode, |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
609 | 609 |
610 virtual HRESULT STDMETHODCALLTYPE QueryInterface(IID const& riid, void** ppv
Object) override{ | 610 virtual HRESULT STDMETHODCALLTYPE QueryInterface(IID const& riid, void** ppv
Object) override{ |
611 if (__uuidof(IUnknown) == riid || | 611 if (__uuidof(IUnknown) == riid || |
612 __uuidof(IDWritePixelSnapping) == riid || | 612 __uuidof(IDWritePixelSnapping) == riid || |
613 __uuidof(IDWriteTextRenderer) == riid) | 613 __uuidof(IDWriteTextRenderer) == riid) |
614 { | 614 { |
615 *ppvObject = this; | 615 *ppvObject = this; |
616 this->AddRef(); | 616 this->AddRef(); |
617 return S_OK; | 617 return S_OK; |
618 } | 618 } |
619 *ppvObject = NULL; | 619 *ppvObject = nullptr; |
620 return E_FAIL; | 620 return E_FAIL; |
621 } | 621 } |
622 | 622 |
623 SkTypeface* FallbackTypeface() { return fResolvedTypeface; } | 623 SkTypeface* FallbackTypeface() { return fResolvedTypeface; } |
624 | 624 |
625 protected: | 625 protected: |
626 ULONG fRefCount; | 626 ULONG fRefCount; |
627 SkAutoTUnref<const SkFontMgr_DirectWrite> fOuter; | 627 SkAutoTUnref<const SkFontMgr_DirectWrite> fOuter; |
628 UINT32 fCharacter; | 628 UINT32 fCharacter; |
629 SkTypeface* fResolvedTypeface; | 629 SkTypeface* fResolvedTypeface; |
(...skipping 11 matching lines...) Expand all Loading... |
641 | 641 |
642 virtual ~FontFallbackSource() { } | 642 virtual ~FontFallbackSource() { } |
643 | 643 |
644 // IDWriteTextAnalysisSource methods | 644 // IDWriteTextAnalysisSource methods |
645 virtual HRESULT STDMETHODCALLTYPE GetTextAtPosition( | 645 virtual HRESULT STDMETHODCALLTYPE GetTextAtPosition( |
646 UINT32 textPosition, | 646 UINT32 textPosition, |
647 WCHAR const** textString, | 647 WCHAR const** textString, |
648 UINT32* textLength) override | 648 UINT32* textLength) override |
649 { | 649 { |
650 if (fLength <= textPosition) { | 650 if (fLength <= textPosition) { |
651 *textString = NULL; | 651 *textString = nullptr; |
652 *textLength = 0; | 652 *textLength = 0; |
653 return S_OK; | 653 return S_OK; |
654 } | 654 } |
655 *textString = fString + textPosition; | 655 *textString = fString + textPosition; |
656 *textLength = fLength - textPosition; | 656 *textLength = fLength - textPosition; |
657 return S_OK; | 657 return S_OK; |
658 } | 658 } |
659 | 659 |
660 virtual HRESULT STDMETHODCALLTYPE GetTextBeforePosition( | 660 virtual HRESULT STDMETHODCALLTYPE GetTextBeforePosition( |
661 UINT32 textPosition, | 661 UINT32 textPosition, |
662 WCHAR const** textString, | 662 WCHAR const** textString, |
663 UINT32* textLength) override | 663 UINT32* textLength) override |
664 { | 664 { |
665 if (textPosition < 1 || fLength <= textPosition) { | 665 if (textPosition < 1 || fLength <= textPosition) { |
666 *textString = NULL; | 666 *textString = nullptr; |
667 *textLength = 0; | 667 *textLength = 0; |
668 return S_OK; | 668 return S_OK; |
669 } | 669 } |
670 *textString = fString; | 670 *textString = fString; |
671 *textLength = textPosition; | 671 *textLength = textPosition; |
672 return S_OK; | 672 return S_OK; |
673 } | 673 } |
674 | 674 |
675 virtual DWRITE_READING_DIRECTION STDMETHODCALLTYPE GetParagraphReadingDirect
ion() override { | 675 virtual DWRITE_READING_DIRECTION STDMETHODCALLTYPE GetParagraphReadingDirect
ion() override { |
676 // TODO: this is also interesting. | 676 // TODO: this is also interesting. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
709 } | 709 } |
710 | 710 |
711 virtual HRESULT STDMETHODCALLTYPE QueryInterface(IID const& riid, void** ppv
Object) override{ | 711 virtual HRESULT STDMETHODCALLTYPE QueryInterface(IID const& riid, void** ppv
Object) override{ |
712 if (__uuidof(IUnknown) == riid || | 712 if (__uuidof(IUnknown) == riid || |
713 __uuidof(IDWriteTextAnalysisSource) == riid) | 713 __uuidof(IDWriteTextAnalysisSource) == riid) |
714 { | 714 { |
715 *ppvObject = this; | 715 *ppvObject = this; |
716 this->AddRef(); | 716 this->AddRef(); |
717 return S_OK; | 717 return S_OK; |
718 } | 718 } |
719 *ppvObject = NULL; | 719 *ppvObject = nullptr; |
720 return E_FAIL; | 720 return E_FAIL; |
721 } | 721 } |
722 | 722 |
723 protected: | 723 protected: |
724 ULONG fRefCount; | 724 ULONG fRefCount; |
725 const WCHAR* fString; | 725 const WCHAR* fString; |
726 UINT32 fLength; | 726 UINT32 fLength; |
727 const WCHAR* fLocale; | 727 const WCHAR* fLocale; |
728 IDWriteNumberSubstitution* fNumberSubstitution; | 728 IDWriteNumberSubstitution* fNumberSubstitution; |
729 }; | 729 }; |
730 | 730 |
731 SkTypeface* SkFontMgr_DirectWrite::onMatchFamilyStyleCharacter(const char family
Name[], | 731 SkTypeface* SkFontMgr_DirectWrite::onMatchFamilyStyleCharacter(const char family
Name[], |
732 const SkFontStyle
& style, | 732 const SkFontStyle
& style, |
733 const char* bcp47
[], int bcp47Count, | 733 const char* bcp47
[], int bcp47Count, |
734 SkUnichar charact
er) const | 734 SkUnichar charact
er) const |
735 { | 735 { |
736 const DWriteStyle dwStyle(style); | 736 const DWriteStyle dwStyle(style); |
737 | 737 |
738 const WCHAR* dwFamilyName = NULL; | 738 const WCHAR* dwFamilyName = nullptr; |
739 SkSMallocWCHAR dwFamilyNameLocal; | 739 SkSMallocWCHAR dwFamilyNameLocal; |
740 if (familyName) { | 740 if (familyName) { |
741 HRN(sk_cstring_to_wchar(familyName, &dwFamilyNameLocal)); | 741 HRN(sk_cstring_to_wchar(familyName, &dwFamilyNameLocal)); |
742 dwFamilyName = dwFamilyNameLocal; | 742 dwFamilyName = dwFamilyNameLocal; |
743 } | 743 } |
744 | 744 |
745 WCHAR str[16]; | 745 WCHAR str[16]; |
746 UINT32 strLen = static_cast<UINT32>( | 746 UINT32 strLen = static_cast<UINT32>( |
747 SkUTF16_FromUnichar(character, reinterpret_cast<uint16_t*>(str))); | 747 SkUTF16_FromUnichar(character, reinterpret_cast<uint16_t*>(str))); |
748 | 748 |
749 const SkSMallocWCHAR* dwBcp47; | 749 const SkSMallocWCHAR* dwBcp47; |
750 SkSMallocWCHAR dwBcp47Local; | 750 SkSMallocWCHAR dwBcp47Local; |
751 if (bcp47Count < 1) { | 751 if (bcp47Count < 1) { |
752 dwBcp47 = &fLocaleName; | 752 dwBcp47 = &fLocaleName; |
753 } else { | 753 } else { |
754 // TODO: support fallback stack. | 754 // TODO: support fallback stack. |
755 // TODO: DirectWrite supports 'zh-CN' or 'zh-Hans', but 'zh' misses comp
letely | 755 // TODO: DirectWrite supports 'zh-CN' or 'zh-Hans', but 'zh' misses comp
letely |
756 // and may produce a Japanese font. | 756 // and may produce a Japanese font. |
757 HRN(sk_cstring_to_wchar(bcp47[bcp47Count - 1], &dwBcp47Local)); | 757 HRN(sk_cstring_to_wchar(bcp47[bcp47Count - 1], &dwBcp47Local)); |
758 dwBcp47 = &dwBcp47Local; | 758 dwBcp47 = &dwBcp47Local; |
759 } | 759 } |
760 | 760 |
761 #if SK_HAS_DWRITE_2_H | 761 #if SK_HAS_DWRITE_2_H |
762 if (fFactory2.get()) { | 762 if (fFactory2.get()) { |
763 SkTScopedComPtr<IDWriteFontFallback> fontFallback; | 763 SkTScopedComPtr<IDWriteFontFallback> fontFallback; |
764 HRNM(fFactory2->GetSystemFontFallback(&fontFallback), "Could not get sys
tem fallback."); | 764 HRNM(fFactory2->GetSystemFontFallback(&fontFallback), "Could not get sys
tem fallback."); |
765 | 765 |
766 SkTScopedComPtr<IDWriteNumberSubstitution> numberSubstitution; | 766 SkTScopedComPtr<IDWriteNumberSubstitution> numberSubstitution; |
767 HRNM(fFactory2->CreateNumberSubstitution(DWRITE_NUMBER_SUBSTITUTION_METH
OD_NONE, NULL, TRUE, | 767 HRNM(fFactory2->CreateNumberSubstitution(DWRITE_NUMBER_SUBSTITUTION_METH
OD_NONE, nullptr, TRUE, |
768 &numberSubstitution), | 768 &numberSubstitution), |
769 "Could not create number substitution."); | 769 "Could not create number substitution."); |
770 SkTScopedComPtr<FontFallbackSource> fontFallbackSource( | 770 SkTScopedComPtr<FontFallbackSource> fontFallbackSource( |
771 new FontFallbackSource(str, strLen, *dwBcp47, numberSubstitution.get
())); | 771 new FontFallbackSource(str, strLen, *dwBcp47, numberSubstitution.get
())); |
772 | 772 |
773 UINT32 mappedLength; | 773 UINT32 mappedLength; |
774 SkTScopedComPtr<IDWriteFont> font; | 774 SkTScopedComPtr<IDWriteFont> font; |
775 FLOAT scale; | 775 FLOAT scale; |
776 HRNM(fontFallback->MapCharacters(fontFallbackSource.get(), | 776 HRNM(fontFallback->MapCharacters(fontFallbackSource.get(), |
777 0, // textPosition, | 777 0, // textPosition, |
778 strLen, | 778 strLen, |
779 fFontCollection.get(), | 779 fFontCollection.get(), |
780 dwFamilyName, | 780 dwFamilyName, |
781 dwStyle.fWeight, | 781 dwStyle.fWeight, |
782 dwStyle.fSlant, | 782 dwStyle.fSlant, |
783 dwStyle.fWidth, | 783 dwStyle.fWidth, |
784 &mappedLength, | 784 &mappedLength, |
785 &font, | 785 &font, |
786 &scale), | 786 &scale), |
787 "Could not map characters"); | 787 "Could not map characters"); |
788 if (!font.get()) { | 788 if (!font.get()) { |
789 return NULL; | 789 return nullptr; |
790 } | 790 } |
791 | 791 |
792 SkTScopedComPtr<IDWriteFontFace> fontFace; | 792 SkTScopedComPtr<IDWriteFontFace> fontFace; |
793 HRNM(font->CreateFontFace(&fontFace), "Could not get font face from font
."); | 793 HRNM(font->CreateFontFace(&fontFace), "Could not get font face from font
."); |
794 | 794 |
795 SkTScopedComPtr<IDWriteFontFamily> fontFamily; | 795 SkTScopedComPtr<IDWriteFontFamily> fontFamily; |
796 HRNM(font->GetFontFamily(&fontFamily), "Could not get family from font."
); | 796 HRNM(font->GetFontFamily(&fontFamily), "Could not get family from font."
); |
797 return this->createTypefaceFromDWriteFont(fontFace.get(), font.get(), fo
ntFamily.get()); | 797 return this->createTypefaceFromDWriteFont(fontFace.get(), font.get(), fo
ntFamily.get()); |
798 } | 798 } |
799 #else | 799 #else |
(...skipping 13 matching lines...) Expand all Loading... |
813 | 813 |
814 SkTScopedComPtr<IDWriteTextLayout> fallbackLayout; | 814 SkTScopedComPtr<IDWriteTextLayout> fallbackLayout; |
815 HRNM(fFactory->CreateTextLayout(str, strLen, fallbackFormat.get(), | 815 HRNM(fFactory->CreateTextLayout(str, strLen, fallbackFormat.get(), |
816 200.0f, 200.0f, | 816 200.0f, 200.0f, |
817 &fallbackLayout), | 817 &fallbackLayout), |
818 "Could not create text layout."); | 818 "Could not create text layout."); |
819 | 819 |
820 SkTScopedComPtr<FontFallbackRenderer> fontFallbackRenderer( | 820 SkTScopedComPtr<FontFallbackRenderer> fontFallbackRenderer( |
821 new FontFallbackRenderer(this, character)); | 821 new FontFallbackRenderer(this, character)); |
822 | 822 |
823 HRNM(fallbackLayout->Draw(NULL, fontFallbackRenderer.get(), 50.0f, 50.0f), | 823 HRNM(fallbackLayout->Draw(nullptr, fontFallbackRenderer.get(), 50.0f, 50.0f)
, |
824 "Could not draw layout with renderer."); | 824 "Could not draw layout with renderer."); |
825 | 825 |
826 return fontFallbackRenderer->FallbackTypeface(); | 826 return fontFallbackRenderer->FallbackTypeface(); |
827 } | 827 } |
828 | 828 |
829 SkTypeface* SkFontMgr_DirectWrite::onMatchFaceStyle(const SkTypeface* familyMemb
er, | 829 SkTypeface* SkFontMgr_DirectWrite::onMatchFaceStyle(const SkTypeface* familyMemb
er, |
830 const SkFontStyle& fontstyle
) const { | 830 const SkFontStyle& fontstyle
) const { |
831 SkString familyName; | 831 SkString familyName; |
832 SkFontStyleSet_DirectWrite sset( | 832 SkFontStyleSet_DirectWrite sset( |
833 this, ((DWriteFontTypeface*)familyMember)->fDWriteFontFamily.get() | 833 this, ((DWriteFontTypeface*)familyMember)->fDWriteFontFamily.get() |
834 ); | 834 ); |
835 return sset.matchStyle(fontstyle); | 835 return sset.matchStyle(fontstyle); |
836 } | 836 } |
837 | 837 |
838 template <typename T> class SkAutoIDWriteUnregister { | 838 template <typename T> class SkAutoIDWriteUnregister { |
839 public: | 839 public: |
840 SkAutoIDWriteUnregister(IDWriteFactory* factory, T* unregister) | 840 SkAutoIDWriteUnregister(IDWriteFactory* factory, T* unregister) |
841 : fFactory(factory), fUnregister(unregister) | 841 : fFactory(factory), fUnregister(unregister) |
842 { } | 842 { } |
843 | 843 |
844 ~SkAutoIDWriteUnregister() { | 844 ~SkAutoIDWriteUnregister() { |
845 if (fUnregister) { | 845 if (fUnregister) { |
846 unregister(fFactory, fUnregister); | 846 unregister(fFactory, fUnregister); |
847 } | 847 } |
848 } | 848 } |
849 | 849 |
850 T* detatch() { | 850 T* detatch() { |
851 T* old = fUnregister; | 851 T* old = fUnregister; |
852 fUnregister = NULL; | 852 fUnregister = nullptr; |
853 return old; | 853 return old; |
854 } | 854 } |
855 | 855 |
856 private: | 856 private: |
857 HRESULT unregister(IDWriteFactory* factory, IDWriteFontFileLoader* unregiste
r) { | 857 HRESULT unregister(IDWriteFactory* factory, IDWriteFontFileLoader* unregiste
r) { |
858 return factory->UnregisterFontFileLoader(unregister); | 858 return factory->UnregisterFontFileLoader(unregister); |
859 } | 859 } |
860 | 860 |
861 HRESULT unregister(IDWriteFactory* factory, IDWriteFontCollectionLoader* unr
egister) { | 861 HRESULT unregister(IDWriteFactory* factory, IDWriteFontCollectionLoader* unr
egister) { |
862 return factory->UnregisterFontCollectionLoader(unregister); | 862 return factory->UnregisterFontCollectionLoader(unregister); |
(...skipping 11 matching lines...) Expand all Loading... |
874 SkAutoIDWriteUnregister<StreamFontFileLoader> autoUnregisterFontFileLoader( | 874 SkAutoIDWriteUnregister<StreamFontFileLoader> autoUnregisterFontFileLoader( |
875 fFactory.get(), fontFileLoader.get()); | 875 fFactory.get(), fontFileLoader.get()); |
876 | 876 |
877 SkTScopedComPtr<StreamFontCollectionLoader> fontCollectionLoader; | 877 SkTScopedComPtr<StreamFontCollectionLoader> fontCollectionLoader; |
878 HRN(StreamFontCollectionLoader::Create(fontFileLoader.get(), &fontCollection
Loader)); | 878 HRN(StreamFontCollectionLoader::Create(fontFileLoader.get(), &fontCollection
Loader)); |
879 HRN(fFactory->RegisterFontCollectionLoader(fontCollectionLoader.get())); | 879 HRN(fFactory->RegisterFontCollectionLoader(fontCollectionLoader.get())); |
880 SkAutoIDWriteUnregister<StreamFontCollectionLoader> autoUnregisterFontCollec
tionLoader( | 880 SkAutoIDWriteUnregister<StreamFontCollectionLoader> autoUnregisterFontCollec
tionLoader( |
881 fFactory.get(), fontCollectionLoader.get()); | 881 fFactory.get(), fontCollectionLoader.get()); |
882 | 882 |
883 SkTScopedComPtr<IDWriteFontCollection> fontCollection; | 883 SkTScopedComPtr<IDWriteFontCollection> fontCollection; |
884 HRN(fFactory->CreateCustomFontCollection(fontCollectionLoader.get(), NULL, 0
, &fontCollection)); | 884 HRN(fFactory->CreateCustomFontCollection(fontCollectionLoader.get(), nullptr
, 0, &fontCollection)); |
885 | 885 |
886 // Find the first non-simulated font which has the given ttc index. | 886 // Find the first non-simulated font which has the given ttc index. |
887 UINT32 familyCount = fontCollection->GetFontFamilyCount(); | 887 UINT32 familyCount = fontCollection->GetFontFamilyCount(); |
888 for (UINT32 familyIndex = 0; familyIndex < familyCount; ++familyIndex) { | 888 for (UINT32 familyIndex = 0; familyIndex < familyCount; ++familyIndex) { |
889 SkTScopedComPtr<IDWriteFontFamily> fontFamily; | 889 SkTScopedComPtr<IDWriteFontFamily> fontFamily; |
890 HRN(fontCollection->GetFontFamily(familyIndex, &fontFamily)); | 890 HRN(fontCollection->GetFontFamily(familyIndex, &fontFamily)); |
891 | 891 |
892 UINT32 fontCount = fontFamily->GetFontCount(); | 892 UINT32 fontCount = fontFamily->GetFontCount(); |
893 for (UINT32 fontIndex = 0; fontIndex < fontCount; ++fontIndex) { | 893 for (UINT32 fontIndex = 0; fontIndex < fontCount; ++fontIndex) { |
894 SkTScopedComPtr<IDWriteFont> font; | 894 SkTScopedComPtr<IDWriteFont> font; |
895 HRN(fontFamily->GetFont(fontIndex, &font)); | 895 HRN(fontFamily->GetFont(fontIndex, &font)); |
896 if (font->GetSimulations() != DWRITE_FONT_SIMULATIONS_NONE) { | 896 if (font->GetSimulations() != DWRITE_FONT_SIMULATIONS_NONE) { |
897 continue; | 897 continue; |
898 } | 898 } |
899 | 899 |
900 SkTScopedComPtr<IDWriteFontFace> fontFace; | 900 SkTScopedComPtr<IDWriteFontFace> fontFace; |
901 HRN(font->CreateFontFace(&fontFace)); | 901 HRN(font->CreateFontFace(&fontFace)); |
902 | 902 |
903 UINT32 faceIndex = fontFace->GetIndex(); | 903 UINT32 faceIndex = fontFace->GetIndex(); |
904 if (faceIndex == ttcIndex) { | 904 if (faceIndex == ttcIndex) { |
905 return DWriteFontTypeface::Create(fFactory.get(), | 905 return DWriteFontTypeface::Create(fFactory.get(), |
906 fontFace.get(), font.get(), fo
ntFamily.get(), | 906 fontFace.get(), font.get(), fo
ntFamily.get(), |
907 autoUnregisterFontFileLoader.d
etatch(), | 907 autoUnregisterFontFileLoader.d
etatch(), |
908 autoUnregisterFontCollectionLo
ader.detatch()); | 908 autoUnregisterFontCollectionLo
ader.detatch()); |
909 } | 909 } |
910 } | 910 } |
911 } | 911 } |
912 | 912 |
913 return NULL; | 913 return nullptr; |
914 } | 914 } |
915 | 915 |
916 SkTypeface* SkFontMgr_DirectWrite::onCreateFromData(SkData* data, int ttcIndex)
const { | 916 SkTypeface* SkFontMgr_DirectWrite::onCreateFromData(SkData* data, int ttcIndex)
const { |
917 return this->createFromStream(new SkMemoryStream(data), ttcIndex); | 917 return this->createFromStream(new SkMemoryStream(data), ttcIndex); |
918 } | 918 } |
919 | 919 |
920 SkTypeface* SkFontMgr_DirectWrite::onCreateFromFile(const char path[], int ttcIn
dex) const { | 920 SkTypeface* SkFontMgr_DirectWrite::onCreateFromFile(const char path[], int ttcIn
dex) const { |
921 return this->createFromStream(SkStream::NewFromFile(path), ttcIndex); | 921 return this->createFromStream(SkStream::NewFromFile(path), ttcIndex); |
922 } | 922 } |
923 | 923 |
(...skipping 26 matching lines...) Expand all Loading... |
950 SkTypeface* SkFontMgr_DirectWrite::onLegacyCreateTypeface(const char familyName[
], | 950 SkTypeface* SkFontMgr_DirectWrite::onLegacyCreateTypeface(const char familyName[
], |
951 unsigned styleBits) co
nst { | 951 unsigned styleBits) co
nst { |
952 SkTScopedComPtr<IDWriteFontFamily> fontFamily; | 952 SkTScopedComPtr<IDWriteFontFamily> fontFamily; |
953 if (familyName) { | 953 if (familyName) { |
954 SkSMallocWCHAR wideFamilyName; | 954 SkSMallocWCHAR wideFamilyName; |
955 if (SUCCEEDED(sk_cstring_to_wchar(familyName, &wideFamilyName))) { | 955 if (SUCCEEDED(sk_cstring_to_wchar(familyName, &wideFamilyName))) { |
956 this->getByFamilyName(wideFamilyName, &fontFamily); | 956 this->getByFamilyName(wideFamilyName, &fontFamily); |
957 } | 957 } |
958 } | 958 } |
959 | 959 |
960 if (NULL == fontFamily.get()) { | 960 if (nullptr == fontFamily.get()) { |
961 // No family with given name, try default. | 961 // No family with given name, try default. |
962 HRNM(this->getDefaultFontFamily(&fontFamily), "Could not get default fon
t family."); | 962 HRNM(this->getDefaultFontFamily(&fontFamily), "Could not get default fon
t family."); |
963 } | 963 } |
964 | 964 |
965 if (NULL == fontFamily.get()) { | 965 if (nullptr == fontFamily.get()) { |
966 // Could not obtain the default font. | 966 // Could not obtain the default font. |
967 HRNM(fFontCollection->GetFontFamily(0, &fontFamily), | 967 HRNM(fFontCollection->GetFontFamily(0, &fontFamily), |
968 "Could not get default-default font family."); | 968 "Could not get default-default font family."); |
969 } | 969 } |
970 | 970 |
971 SkTScopedComPtr<IDWriteFont> font; | 971 SkTScopedComPtr<IDWriteFont> font; |
972 DWRITE_FONT_WEIGHT weight = (styleBits & SkTypeface::kBold) | 972 DWRITE_FONT_WEIGHT weight = (styleBits & SkTypeface::kBold) |
973 ? DWRITE_FONT_WEIGHT_BOLD | 973 ? DWRITE_FONT_WEIGHT_BOLD |
974 : DWRITE_FONT_WEIGHT_NORMAL; | 974 : DWRITE_FONT_WEIGHT_NORMAL; |
975 DWRITE_FONT_STRETCH stretch = DWRITE_FONT_STRETCH_NORMAL; | 975 DWRITE_FONT_STRETCH stretch = DWRITE_FONT_STRETCH_NORMAL; |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1058 HRNM(font->CreateFontFace(&fontFace), "Could not create font face."); | 1058 HRNM(font->CreateFontFace(&fontFace), "Could not create font face."); |
1059 | 1059 |
1060 return fFontMgr->createTypefaceFromDWriteFont(fontFace.get(), font.get(), | 1060 return fFontMgr->createTypefaceFromDWriteFont(fontFace.get(), font.get(), |
1061 fFontFamily.get()); | 1061 fFontFamily.get()); |
1062 } | 1062 } |
1063 | 1063 |
1064 //////////////////////////////////////////////////////////////////////////////// | 1064 //////////////////////////////////////////////////////////////////////////////// |
1065 #include "SkTypeface_win.h" | 1065 #include "SkTypeface_win.h" |
1066 | 1066 |
1067 SK_API SkFontMgr* SkFontMgr_New_DirectWrite(IDWriteFactory* factory) { | 1067 SK_API SkFontMgr* SkFontMgr_New_DirectWrite(IDWriteFactory* factory) { |
1068 if (NULL == factory) { | 1068 if (nullptr == factory) { |
1069 factory = sk_get_dwrite_factory(); | 1069 factory = sk_get_dwrite_factory(); |
1070 if (NULL == factory) { | 1070 if (nullptr == factory) { |
1071 return NULL; | 1071 return nullptr; |
1072 } | 1072 } |
1073 } | 1073 } |
1074 | 1074 |
1075 SkTScopedComPtr<IDWriteFontCollection> sysFontCollection; | 1075 SkTScopedComPtr<IDWriteFontCollection> sysFontCollection; |
1076 HRNM(factory->GetSystemFontCollection(&sysFontCollection, FALSE), | 1076 HRNM(factory->GetSystemFontCollection(&sysFontCollection, FALSE), |
1077 "Could not get system font collection."); | 1077 "Could not get system font collection."); |
1078 | 1078 |
1079 WCHAR localeNameStorage[LOCALE_NAME_MAX_LENGTH]; | 1079 WCHAR localeNameStorage[LOCALE_NAME_MAX_LENGTH]; |
1080 WCHAR* localeName = NULL; | 1080 WCHAR* localeName = nullptr; |
1081 int localeNameLen = 0; | 1081 int localeNameLen = 0; |
1082 | 1082 |
1083 // Dynamically load GetUserDefaultLocaleName function, as it is not availabl
e on XP. | 1083 // Dynamically load GetUserDefaultLocaleName function, as it is not availabl
e on XP. |
1084 SkGetUserDefaultLocaleNameProc getUserDefaultLocaleNameProc = NULL; | 1084 SkGetUserDefaultLocaleNameProc getUserDefaultLocaleNameProc = nullptr; |
1085 HRESULT hr = SkGetGetUserDefaultLocaleNameProc(&getUserDefaultLocaleNameProc
); | 1085 HRESULT hr = SkGetGetUserDefaultLocaleNameProc(&getUserDefaultLocaleNameProc
); |
1086 if (NULL == getUserDefaultLocaleNameProc) { | 1086 if (nullptr == getUserDefaultLocaleNameProc) { |
1087 SK_TRACEHR(hr, "Could not get GetUserDefaultLocaleName."); | 1087 SK_TRACEHR(hr, "Could not get GetUserDefaultLocaleName."); |
1088 } else { | 1088 } else { |
1089 localeNameLen = getUserDefaultLocaleNameProc(localeNameStorage, LOCALE_N
AME_MAX_LENGTH); | 1089 localeNameLen = getUserDefaultLocaleNameProc(localeNameStorage, LOCALE_N
AME_MAX_LENGTH); |
1090 if (localeNameLen) { | 1090 if (localeNameLen) { |
1091 localeName = localeNameStorage; | 1091 localeName = localeNameStorage; |
1092 }; | 1092 }; |
1093 } | 1093 } |
1094 | 1094 |
1095 return new SkFontMgr_DirectWrite(factory, sysFontCollection.get(), localeNam
e, localeNameLen); | 1095 return new SkFontMgr_DirectWrite(factory, sysFontCollection.get(), localeNam
e, localeNameLen); |
1096 } | 1096 } |
1097 | 1097 |
1098 #include "SkFontMgr_indirect.h" | 1098 #include "SkFontMgr_indirect.h" |
1099 SK_API SkFontMgr* SkFontMgr_New_DirectWriteRenderer(SkRemotableFontMgr* proxy) { | 1099 SK_API SkFontMgr* SkFontMgr_New_DirectWriteRenderer(SkRemotableFontMgr* proxy) { |
1100 SkAutoTUnref<SkFontMgr> impl(SkFontMgr_New_DirectWrite()); | 1100 SkAutoTUnref<SkFontMgr> impl(SkFontMgr_New_DirectWrite()); |
1101 if (impl.get() == NULL) { | 1101 if (impl.get() == nullptr) { |
1102 return NULL; | 1102 return nullptr; |
1103 } | 1103 } |
1104 return new SkFontMgr_Indirect(impl.get(), proxy); | 1104 return new SkFontMgr_Indirect(impl.get(), proxy); |
1105 } | 1105 } |
OLD | NEW |