Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: src/ports/SkFontHost_win_dw.cpp

Issue 14600009: TTC support for DirectWrite. (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Add some missing error checks. Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « include/utils/win/SkTScopedComPtr.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 *streamFontFileLoader = new StreamFontFileLoader(stream); 222 *streamFontFileLoader = new StreamFontFileLoader(stream);
223 if (NULL == streamFontFileLoader) { 223 if (NULL == streamFontFileLoader) {
224 return E_OUTOFMEMORY; 224 return E_OUTOFMEMORY;
225 } 225 }
226 return S_OK; 226 return S_OK;
227 } 227 }
228 228
229 SkAutoTUnref<SkStream> fStream; 229 SkAutoTUnref<SkStream> fStream;
230 230
231 private: 231 private:
232 StreamFontFileLoader(SkStream* stream) : fRefCount(1), fStream(stream) { 232 StreamFontFileLoader(SkStream* stream) : fRefCount(1), fStream(SkRef(stream) ) { }
233 stream->ref();
234 }
235 233
236 ULONG fRefCount; 234 ULONG fRefCount;
237 }; 235 };
238 236
239 HRESULT StreamFontFileLoader::QueryInterface(REFIID iid, void** ppvObject) { 237 HRESULT StreamFontFileLoader::QueryInterface(REFIID iid, void** ppvObject) {
240 if (iid == IID_IUnknown || iid == __uuidof(IDWriteFontFileLoader)) { 238 if (iid == IID_IUnknown || iid == __uuidof(IDWriteFontFileLoader)) {
241 *ppvObject = this; 239 *ppvObject = this;
242 AddRef(); 240 AddRef();
243 return S_OK; 241 return S_OK;
244 } else { 242 } else {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 293
296 SkTScopedComPtr<IDWriteFactory> fFactory; 294 SkTScopedComPtr<IDWriteFactory> fFactory;
297 SkTScopedComPtr<IDWriteFontFile> fCurrentFile; 295 SkTScopedComPtr<IDWriteFontFile> fCurrentFile;
298 SkTScopedComPtr<IDWriteFontFileLoader> fFontFileLoader; 296 SkTScopedComPtr<IDWriteFontFileLoader> fFontFileLoader;
299 bool fHasNext; 297 bool fHasNext;
300 }; 298 };
301 299
302 StreamFontFileEnumerator::StreamFontFileEnumerator(IDWriteFactory* factory, 300 StreamFontFileEnumerator::StreamFontFileEnumerator(IDWriteFactory* factory,
303 IDWriteFontFileLoader* fontFi leLoader) 301 IDWriteFontFileLoader* fontFi leLoader)
304 : fRefCount(1) 302 : fRefCount(1)
305 , fFactory(factory) 303 , fFactory(SkRefComPtr(factory))
306 , fCurrentFile() 304 , fCurrentFile()
307 , fFontFileLoader(fontFileLoader) 305 , fFontFileLoader(SkRefComPtr(fontFileLoader))
308 , fHasNext(true) 306 , fHasNext(true)
309 { 307 { }
310 factory->AddRef();
311 fontFileLoader->AddRef();
312 }
313 308
314 HRESULT StreamFontFileEnumerator::QueryInterface(REFIID iid, void** ppvObject) { 309 HRESULT StreamFontFileEnumerator::QueryInterface(REFIID iid, void** ppvObject) {
315 if (iid == IID_IUnknown || iid == __uuidof(IDWriteFontFileEnumerator)) { 310 if (iid == IID_IUnknown || iid == __uuidof(IDWriteFontFileEnumerator)) {
316 *ppvObject = this; 311 *ppvObject = this;
317 AddRef(); 312 AddRef();
318 return S_OK; 313 return S_OK;
319 } else { 314 } else {
320 *ppvObject = NULL; 315 *ppvObject = NULL;
321 return E_NOINTERFACE; 316 return E_NOINTERFACE;
322 } 317 }
(...skipping 29 matching lines...) Expand all
352 *hasCurrentFile = TRUE; 347 *hasCurrentFile = TRUE;
353 return S_OK; 348 return S_OK;
354 } 349 }
355 350
356 HRESULT StreamFontFileEnumerator::GetCurrentFontFile(IDWriteFontFile** fontFile) { 351 HRESULT StreamFontFileEnumerator::GetCurrentFontFile(IDWriteFontFile** fontFile) {
357 if (fCurrentFile.get() == NULL) { 352 if (fCurrentFile.get() == NULL) {
358 *fontFile = NULL; 353 *fontFile = NULL;
359 return E_FAIL; 354 return E_FAIL;
360 } 355 }
361 356
362 fCurrentFile.get()->AddRef(); 357 *fontFile = SkRefComPtr(fCurrentFile.get());
363 *fontFile = fCurrentFile.get();
364 return S_OK; 358 return S_OK;
365 } 359 }
366 360
367 class StreamFontCollectionLoader : public IDWriteFontCollectionLoader { 361 class StreamFontCollectionLoader : public IDWriteFontCollectionLoader {
368 public: 362 public:
369 // IUnknown methods 363 // IUnknown methods
370 virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, void** ppvObjec t); 364 virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, void** ppvObjec t);
371 virtual ULONG STDMETHODCALLTYPE AddRef(); 365 virtual ULONG STDMETHODCALLTYPE AddRef();
372 virtual ULONG STDMETHODCALLTYPE Release(); 366 virtual ULONG STDMETHODCALLTYPE Release();
373 367
374 // IDWriteFontCollectionLoader methods 368 // IDWriteFontCollectionLoader methods
375 virtual HRESULT STDMETHODCALLTYPE CreateEnumeratorFromKey( 369 virtual HRESULT STDMETHODCALLTYPE CreateEnumeratorFromKey(
376 IDWriteFactory* factory, 370 IDWriteFactory* factory,
377 void const* collectionKey, 371 void const* collectionKey,
378 UINT32 collectionKeySize, 372 UINT32 collectionKeySize,
379 IDWriteFontFileEnumerator** fontFileEnumerator); 373 IDWriteFontFileEnumerator** fontFileEnumerator);
380 374
381 static HRESULT Create(IDWriteFontFileLoader* fontFileLoader, 375 static HRESULT Create(IDWriteFontFileLoader* fontFileLoader,
382 StreamFontCollectionLoader** streamFontCollectionLoade r) { 376 StreamFontCollectionLoader** streamFontCollectionLoade r) {
383 *streamFontCollectionLoader = new StreamFontCollectionLoader(fontFileLoa der); 377 *streamFontCollectionLoader = new StreamFontCollectionLoader(fontFileLoa der);
384 if (NULL == streamFontCollectionLoader) { 378 if (NULL == streamFontCollectionLoader) {
385 return E_OUTOFMEMORY; 379 return E_OUTOFMEMORY;
386 } 380 }
387 return S_OK; 381 return S_OK;
388 } 382 }
389 private: 383 private:
390 StreamFontCollectionLoader(IDWriteFontFileLoader* fontFileLoader) 384 StreamFontCollectionLoader(IDWriteFontFileLoader* fontFileLoader)
391 : fRefCount(1) 385 : fRefCount(1)
392 , fFontFileLoader(fontFileLoader) 386 , fFontFileLoader(SkRefComPtr(fontFileLoader))
393 { 387 { }
394 fontFileLoader->AddRef();
395 }
396 388
397 ULONG fRefCount; 389 ULONG fRefCount;
398 SkTScopedComPtr<IDWriteFontFileLoader> fFontFileLoader; 390 SkTScopedComPtr<IDWriteFontFileLoader> fFontFileLoader;
399 }; 391 };
400 392
401 HRESULT StreamFontCollectionLoader::QueryInterface(REFIID iid, void** ppvObject) { 393 HRESULT StreamFontCollectionLoader::QueryInterface(REFIID iid, void** ppvObject) {
402 if (iid == IID_IUnknown || iid == __uuidof(IDWriteFontCollectionLoader)) { 394 if (iid == IID_IUnknown || iid == __uuidof(IDWriteFontCollectionLoader)) {
403 *ppvObject = this; 395 *ppvObject = this;
404 AddRef(); 396 AddRef();
405 return S_OK; 397 return S_OK;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 442
451 class DWriteFontTypeface : public SkTypeface { 443 class DWriteFontTypeface : public SkTypeface {
452 private: 444 private:
453 DWriteFontTypeface(SkTypeface::Style style, SkFontID fontID, 445 DWriteFontTypeface(SkTypeface::Style style, SkFontID fontID,
454 IDWriteFontFace* fontFace, 446 IDWriteFontFace* fontFace,
455 IDWriteFont* font, 447 IDWriteFont* font,
456 IDWriteFontFamily* fontFamily, 448 IDWriteFontFamily* fontFamily,
457 StreamFontFileLoader* fontFileLoader = NULL, 449 StreamFontFileLoader* fontFileLoader = NULL,
458 IDWriteFontCollectionLoader* fontCollectionLoader = NULL) 450 IDWriteFontCollectionLoader* fontCollectionLoader = NULL)
459 : SkTypeface(style, fontID, false) 451 : SkTypeface(style, fontID, false)
460 , fDWriteFontCollectionLoader(fontCollectionLoader) 452 , fDWriteFontCollectionLoader(SkSafeRefComPtr(fontCollectionLoader))
461 , fDWriteFontFileLoader(fontFileLoader) 453 , fDWriteFontFileLoader(SkSafeRefComPtr(fontFileLoader))
462 , fDWriteFontFamily(fontFamily) 454 , fDWriteFontFamily(SkRefComPtr(fontFamily))
463 , fDWriteFont(font) 455 , fDWriteFont(SkRefComPtr(font))
464 , fDWriteFontFace(fontFace) { 456 , fDWriteFontFace(SkRefComPtr(fontFace))
465 457 { }
466 if (fontCollectionLoader != NULL) {
467 fontCollectionLoader->AddRef();
468 }
469 if (fontFileLoader != NULL) {
470 fontFileLoader->AddRef();
471 }
472 fontFamily->AddRef();
473 font->AddRef();
474 fontFace->AddRef();
475 }
476 458
477 public: 459 public:
478 SkTScopedComPtr<IDWriteFontCollectionLoader> fDWriteFontCollectionLoader; 460 SkTScopedComPtr<IDWriteFontCollectionLoader> fDWriteFontCollectionLoader;
479 SkTScopedComPtr<StreamFontFileLoader> fDWriteFontFileLoader; 461 SkTScopedComPtr<StreamFontFileLoader> fDWriteFontFileLoader;
480 SkTScopedComPtr<IDWriteFontFamily> fDWriteFontFamily; 462 SkTScopedComPtr<IDWriteFontFamily> fDWriteFontFamily;
481 SkTScopedComPtr<IDWriteFont> fDWriteFont; 463 SkTScopedComPtr<IDWriteFont> fDWriteFont;
482 SkTScopedComPtr<IDWriteFontFace> fDWriteFontFace; 464 SkTScopedComPtr<IDWriteFontFace> fDWriteFontFace;
483 465
484 static DWriteFontTypeface* Create(IDWriteFontFace* fontFace, 466 static DWriteFontTypeface* Create(IDWriteFontFace* fontFace,
485 IDWriteFont* font, 467 IDWriteFont* font,
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
725 fontFileLoader, fontCollectionLoader); 707 fontFileLoader, fontCollectionLoader);
726 SkTypefaceCache::Add(face, get_style(font), fontCollectionLoader != NULL ); 708 SkTypefaceCache::Add(face, get_style(font), fontCollectionLoader != NULL );
727 } 709 }
728 return face; 710 return face;
729 } 711 }
730 712
731 void SkDWriteFontFromTypeface(const SkTypeface* face, IDWriteFont** font) { 713 void SkDWriteFontFromTypeface(const SkTypeface* face, IDWriteFont** font) {
732 if (NULL == face) { 714 if (NULL == face) {
733 HRVM(get_default_font(font), "Could not get default font."); 715 HRVM(get_default_font(font), "Could not get default font.");
734 } else { 716 } else {
735 *font = static_cast<const DWriteFontTypeface*>(face)->fDWriteFont.get(); 717 *font = SkRefComPtr(static_cast<const DWriteFontTypeface*>(face)->fDWrit eFont.get());
736 (*font)->AddRef();
737 } 718 }
738 } 719 }
739 static DWriteFontTypeface* GetDWriteFontByID(SkFontID fontID) { 720 static DWriteFontTypeface* GetDWriteFontByID(SkFontID fontID) {
740 return static_cast<DWriteFontTypeface*>(SkTypefaceCache::FindByID(fontID)); 721 return static_cast<DWriteFontTypeface*>(SkTypefaceCache::FindByID(fontID));
741 } 722 }
742 723
743 SkScalerContext_Windows::SkScalerContext_Windows(DWriteFontTypeface* typeface, 724 SkScalerContext_Windows::SkScalerContext_Windows(DWriteFontTypeface* typeface,
744 const SkDescriptor* desc) 725 const SkDescriptor* desc)
745 : SkScalerContext(typeface, desc) 726 : SkScalerContext(typeface, desc)
746 , fTypeface(SkRef(typeface)) 727 , fTypeface(SkRef(typeface))
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
1083 SkSMallocWCHAR dwFamilyNameChar(dwFamilyNamesLength+1); 1064 SkSMallocWCHAR dwFamilyNameChar(dwFamilyNamesLength+1);
1084 HRV(dwFamilyNames->GetString(0, dwFamilyNameChar.get(), dwFamilyNamesLength+ 1)); 1065 HRV(dwFamilyNames->GetString(0, dwFamilyNameChar.get(), dwFamilyNamesLength+ 1));
1085 1066
1086 SkString utf8FamilyName; 1067 SkString utf8FamilyName;
1087 HRV(wchar_to_skstring(dwFamilyNameChar.get(), &utf8FamilyName)); 1068 HRV(wchar_to_skstring(dwFamilyNameChar.get(), &utf8FamilyName));
1088 1069
1089 desc->setFamilyName(utf8FamilyName.c_str()); 1070 desc->setFamilyName(utf8FamilyName.c_str());
1090 *isLocalStream = SkToBool(fDWriteFontFileLoader.get()); 1071 *isLocalStream = SkToBool(fDWriteFontFileLoader.get());
1091 } 1072 }
1092 1073
1093 static SkTypeface* create_from_stream(SkStream* stream) { 1074 template <typename T> class SkAutoIDWriteUnregister {
1075 public:
1076 SkAutoIDWriteUnregister(IDWriteFactory* factory, T* unregister)
1077 : fFactory(factory), fUnregister(unregister)
1078 { }
1079
1080 ~SkAutoIDWriteUnregister() {
1081 if (fUnregister) {
1082 unregister(fFactory, fUnregister);
1083 }
1084 }
1085
1086 T* detatch() {
1087 T* old = fUnregister;
1088 fUnregister = NULL;
1089 return old;
1090 }
1091
1092 private:
1093 HRESULT unregister(IDWriteFactory* factory, IDWriteFontFileLoader* unregiste r) {
1094 return factory->UnregisterFontFileLoader(unregister);
1095 }
1096
1097 HRESULT unregister(IDWriteFactory* factory, IDWriteFontCollectionLoader* unr egister) {
1098 return factory->UnregisterFontCollectionLoader(unregister);
1099 }
1100
1101 IDWriteFactory* fFactory;
1102 T* fUnregister;
1103 };
1104
1105 static SkTypeface* create_from_stream(SkStream* stream, int ttcIndex) {
1094 IDWriteFactory* factory; 1106 IDWriteFactory* factory;
1095 HRN(get_dwrite_factory(&factory)); 1107 HRN(get_dwrite_factory(&factory));
1096 1108
1097 SkTScopedComPtr<StreamFontFileLoader> fontFileLoader; 1109 SkTScopedComPtr<StreamFontFileLoader> fontFileLoader;
1098 HRN(StreamFontFileLoader::Create(stream, &fontFileLoader)); 1110 HRN(StreamFontFileLoader::Create(stream, &fontFileLoader));
1099 HRN(factory->RegisterFontFileLoader(fontFileLoader.get())); 1111 HRN(factory->RegisterFontFileLoader(fontFileLoader.get()));
1112 SkAutoIDWriteUnregister<StreamFontFileLoader> autoUnregisterFontFileLoader(
1113 factory, fontFileLoader.get());
1100 1114
1101 SkTScopedComPtr<StreamFontCollectionLoader> streamFontCollectionLoader; 1115 SkTScopedComPtr<StreamFontCollectionLoader> fontCollectionLoader;
1102 HRN(StreamFontCollectionLoader::Create(fontFileLoader.get(), &streamFontColl ectionLoader)); 1116 HRN(StreamFontCollectionLoader::Create(fontFileLoader.get(), &fontCollection Loader));
1103 HRN(factory->RegisterFontCollectionLoader(streamFontCollectionLoader.get())) ; 1117 HRN(factory->RegisterFontCollectionLoader(fontCollectionLoader.get()));
1118 SkAutoIDWriteUnregister<StreamFontCollectionLoader> autoUnregisterFontCollec tionLoader(
1119 factory, fontCollectionLoader.get());
1104 1120
1105 SkTScopedComPtr<IDWriteFontCollection> streamFontCollection; 1121 SkTScopedComPtr<IDWriteFontCollection> fontCollection;
1106 HRN(factory->CreateCustomFontCollection(streamFontCollectionLoader.get(), NU LL, 0, 1122 HRN(factory->CreateCustomFontCollection(fontCollectionLoader.get(), NULL, 0, &fontCollection));
1107 &streamFontCollection));
1108 1123
1109 SkTScopedComPtr<IDWriteFontFamily> fontFamily; 1124 // Find the first non-simulated font which has the given ttc index.
1110 HRN(streamFontCollection->GetFontFamily(0, &fontFamily)); 1125 UINT32 familyCount = fontCollection->GetFontFamilyCount();
1126 for (UINT32 familyIndex = 0; familyIndex < familyCount; ++familyIndex) {
1127 SkTScopedComPtr<IDWriteFontFamily> fontFamily;
1128 HRN(fontCollection->GetFontFamily(familyIndex, &fontFamily));
1111 1129
1112 SkTScopedComPtr<IDWriteFont> font; 1130 UINT32 fontCount = fontFamily->GetFontCount();
1113 HRN(fontFamily->GetFont(0, &font)); 1131 for (UINT32 fontIndex = 0; fontIndex < fontCount; ++fontIndex) {
1132 SkTScopedComPtr<IDWriteFont> font;
1133 HRN(fontFamily->GetFont(fontIndex, &font));
1134 if (font->GetSimulations() != DWRITE_FONT_SIMULATIONS_NONE) {
1135 continue;
1136 }
1114 1137
1115 SkTScopedComPtr<IDWriteFontFace> fontFace; 1138 SkTScopedComPtr<IDWriteFontFace> fontFace;
1116 HRN(font->CreateFontFace(&fontFace)); 1139 HRN(font->CreateFontFace(&fontFace));
1117 1140
1118 return SkCreateTypefaceFromDWriteFont(fontFace.get(), font.get(), fontFamily .get(), 1141 UINT32 faceIndex = fontFace->GetIndex();
1119 fontFileLoader.get(), streamFontCollec tionLoader.get()); 1142 if (faceIndex == ttcIndex) {
1143 return SkCreateTypefaceFromDWriteFont(fontFace.get(), font.get() , fontFamily.get(),
1144 autoUnregisterFontFileLoad er.detatch(),
1145 autoUnregisterFontCollecti onLoader.detatch());
1146 }
1147 }
1148 }
1149
1150 return NULL;
1120 } 1151 }
1121 1152
1122 SkTypeface* SkFontHost::CreateTypefaceFromStream(SkStream* stream) { 1153 SkTypeface* SkFontHost::CreateTypefaceFromStream(SkStream* stream) {
1123 return create_from_stream(stream); 1154 return create_from_stream(stream, 0);
1124 } 1155 }
1125 1156
1126 SkStream* DWriteFontTypeface::onOpenStream(int* ttcIndex) const { 1157 SkStream* DWriteFontTypeface::onOpenStream(int* ttcIndex) const {
1127 *ttcIndex = 0; 1158 *ttcIndex = fDWriteFontFace->GetIndex();
1128 1159
1129 UINT32 numFiles; 1160 UINT32 numFiles;
1130 HRNM(fDWriteFontFace->GetFiles(&numFiles, NULL), 1161 HRNM(fDWriteFontFace->GetFiles(&numFiles, NULL),
1131 "Could not get number of font files."); 1162 "Could not get number of font files.");
1132 if (numFiles != 1) { 1163 if (numFiles != 1) {
1133 return NULL; 1164 return NULL;
1134 } 1165 }
1135 1166
1136 SkTScopedComPtr<IDWriteFontFile> fontFile; 1167 SkTScopedComPtr<IDWriteFontFile> fontFile;
1137 HRNM(fDWriteFontFace->GetFiles(&numFiles, &fontFile), "Could not get font fi les."); 1168 HRNM(fDWriteFontFace->GetFiles(&numFiles, &fontFile), "Could not get font fi les.");
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1183 1) If familyFace is null, use familyName. 1214 1) If familyFace is null, use familyName.
1184 2) If familyName is null, use familyFace. 1215 2) If familyName is null, use familyFace.
1185 3) If both are null, return the default font that best matches style 1216 3) If both are null, return the default font that best matches style
1186 This MUST not return NULL. 1217 This MUST not return NULL.
1187 */ 1218 */
1188 SkTypeface* SkFontHost::CreateTypeface(const SkTypeface* familyFace, 1219 SkTypeface* SkFontHost::CreateTypeface(const SkTypeface* familyFace,
1189 const char familyName[], 1220 const char familyName[],
1190 SkTypeface::Style style) { 1221 SkTypeface::Style style) {
1191 HRESULT hr; 1222 HRESULT hr;
1192 SkTScopedComPtr<IDWriteFontFamily> fontFamily; 1223 SkTScopedComPtr<IDWriteFontFamily> fontFamily;
1193 SkTScopedComPtr<IDWriteFontCollectionLoader> fontCollectionLoader;
1194 SkTScopedComPtr<IDWriteFontFileLoader> fontFileLoader;
1195 if (familyFace) { 1224 if (familyFace) {
1196 const DWriteFontTypeface* face = static_cast<const DWriteFontTypeface*>( familyFace); 1225 const DWriteFontTypeface* face = static_cast<const DWriteFontTypeface*>( familyFace);
1197 face->fDWriteFontFamily.get()->AddRef(); 1226 *(&fontFamily) = SkRefComPtr(face->fDWriteFontFamily.get());
1198 *(&fontFamily) = face->fDWriteFontFamily.get();
1199
1200 if (face->fDWriteFontCollectionLoader.get() != NULL) {
1201 face->fDWriteFontCollectionLoader.get()->AddRef();
1202 *(&fontCollectionLoader) = face->fDWriteFontCollectionLoader.get();
1203
1204 face->fDWriteFontFileLoader.get()->AddRef();
1205 *(&fontFileLoader) = face->fDWriteFontFileLoader.get();
1206 }
1207 1227
1208 } else if (familyName) { 1228 } else if (familyName) {
1209 hr = get_by_family_name(familyName, &fontFamily); 1229 hr = get_by_family_name(familyName, &fontFamily);
1210 } 1230 }
1211 1231
1212 if (NULL == fontFamily.get()) { 1232 if (NULL == fontFamily.get()) {
1213 //No good family found, go with default. 1233 //No good family found, go with default.
1214 SkTScopedComPtr<IDWriteFont> font; 1234 SkTScopedComPtr<IDWriteFont> font;
1215 hr = get_default_font(&font); 1235 hr = get_default_font(&font);
1216 hr = font->GetFontFamily(&fontFamily); 1236 hr = font->GetFontFamily(&fontFamily);
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
1342 return true; 1362 return true;
1343 } 1363 }
1344 1364
1345 template<typename T> 1365 template<typename T>
1346 class AutoDWriteTable { 1366 class AutoDWriteTable {
1347 public: 1367 public:
1348 AutoDWriteTable(IDWriteFontFace* fontFace) 1368 AutoDWriteTable(IDWriteFontFace* fontFace)
1349 : fFontFace(fontFace) 1369 : fFontFace(fontFace)
1350 , fExists(FALSE) { 1370 , fExists(FALSE) {
1351 1371
1352 //fontFace->AddRef();
1353 const UINT32 tag = DWRITE_MAKE_OPENTYPE_TAG(T::TAG0, 1372 const UINT32 tag = DWRITE_MAKE_OPENTYPE_TAG(T::TAG0,
1354 T::TAG1, 1373 T::TAG1,
1355 T::TAG2, 1374 T::TAG2,
1356 T::TAG3); 1375 T::TAG3);
1357 // TODO: need to check for failure 1376 // Any errors are ignored, user must check fExists anyway.
1358 /*HRESULT hr =*/ fontFace->TryGetFontTable(tag, 1377 fontFace->TryGetFontTable(tag,
1359 reinterpret_cast<const void **>(&fData), &fSize, &fLock, &fExists); 1378 reinterpret_cast<const void **>(&fData), &fSize, &fLock, &fExists);
1360 } 1379 }
1361 ~AutoDWriteTable() { 1380 ~AutoDWriteTable() {
1362 if (fExists) { 1381 if (fExists) {
1363 fFontFace->ReleaseFontTable(fLock); 1382 fFontFace->ReleaseFontTable(fLock);
1364 } 1383 }
1365 } 1384 }
1366 const T* operator->() const { return fData; } 1385 const T* operator->() const { return fData; }
1367 1386
1368 const T* fData; 1387 const T* fData;
1369 UINT32 fSize; 1388 UINT32 fSize;
1370 BOOL fExists; 1389 BOOL fExists;
1371 private: 1390 private:
1372 //SkTScopedComPtr<IDWriteFontFace> fFontFace; 1391 // Borrowed reference, the user must ensure the fontFace stays alive.
1373 IDWriteFontFace* fFontFace; 1392 IDWriteFontFace* fFontFace;
1374 void* fLock; 1393 void* fLock;
1375 }; 1394 };
1376 1395
1377 SkAdvancedTypefaceMetrics* DWriteFontTypeface::onGetAdvancedTypefaceMetrics( 1396 SkAdvancedTypefaceMetrics* DWriteFontTypeface::onGetAdvancedTypefaceMetrics(
1378 SkAdvancedTypefaceMetrics::PerGlyphInfo perGlyphInfo, 1397 SkAdvancedTypefaceMetrics::PerGlyphInfo perGlyphInfo,
1379 const uint32_t* glyphIDs, 1398 const uint32_t* glyphIDs,
1380 uint32_t glyphIDsCount) const { 1399 uint32_t glyphIDsCount) const {
1381 1400
1382 SkAdvancedTypefaceMetrics* info = NULL; 1401 SkAdvancedTypefaceMetrics* info = NULL;
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
1666 } 1685 }
1667 virtual SkTypeface* onMatchFaceStyle(const SkTypeface* familyMember, 1686 virtual SkTypeface* onMatchFaceStyle(const SkTypeface* familyMember,
1668 const SkFontStyle& fontstyle) SK_OVERRI DE { 1687 const SkFontStyle& fontstyle) SK_OVERRI DE {
1669 SkString familyName; 1688 SkString familyName;
1670 SkFontStyleSet_DirectWrite sset( 1689 SkFontStyleSet_DirectWrite sset(
1671 this, ((DWriteFontTypeface*)familyMember)->fDWriteFontFamily.get() 1690 this, ((DWriteFontTypeface*)familyMember)->fDWriteFontFamily.get()
1672 ); 1691 );
1673 return sset.matchStyle(fontstyle); 1692 return sset.matchStyle(fontstyle);
1674 } 1693 }
1675 virtual SkTypeface* onCreateFromStream(SkStream* stream, int ttcIndex) SK_OV ERRIDE { 1694 virtual SkTypeface* onCreateFromStream(SkStream* stream, int ttcIndex) SK_OV ERRIDE {
1676 return create_from_stream(stream); 1695 return create_from_stream(stream, ttcIndex);
1677 } 1696 }
1678 virtual SkTypeface* onCreateFromData(SkData* data, int ttcIndex) SK_OVERRIDE { 1697 virtual SkTypeface* onCreateFromData(SkData* data, int ttcIndex) SK_OVERRIDE {
1679 SkAutoTUnref<SkStream> stream(SkNEW_ARGS(SkMemoryStream, (data))); 1698 SkAutoTUnref<SkStream> stream(SkNEW_ARGS(SkMemoryStream, (data)));
1680 return this->createFromStream(stream, ttcIndex); 1699 return this->createFromStream(stream, ttcIndex);
1681 } 1700 }
1682 virtual SkTypeface* onCreateFromFile(const char path[], int ttcIndex) SK_OVE RRIDE { 1701 virtual SkTypeface* onCreateFromFile(const char path[], int ttcIndex) SK_OVE RRIDE {
1683 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path)); 1702 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path));
1684 return this->createFromStream(stream, ttcIndex); 1703 return this->createFromStream(stream, ttcIndex);
1685 } 1704 }
1686 }; 1705 };
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1723 1742
1724 WCHAR localeNameStorage[LOCALE_NAME_MAX_LENGTH]; 1743 WCHAR localeNameStorage[LOCALE_NAME_MAX_LENGTH];
1725 WCHAR* localeName = NULL; 1744 WCHAR* localeName = NULL;
1726 int localeNameLen = GetUserDefaultLocaleName(localeNameStorage, LOCALE_NAME_ MAX_LENGTH); 1745 int localeNameLen = GetUserDefaultLocaleName(localeNameStorage, LOCALE_NAME_ MAX_LENGTH);
1727 if (localeNameLen) { 1746 if (localeNameLen) {
1728 localeName = localeNameStorage; 1747 localeName = localeNameStorage;
1729 }; 1748 };
1730 1749
1731 return SkNEW_ARGS(SkFontMgr_DirectWrite, (sysFontCollection.get(), localeNam e, localeNameLen)); 1750 return SkNEW_ARGS(SkFontMgr_DirectWrite, (sysFontCollection.get(), localeNam e, localeNameLen));
1732 } 1751 }
OLDNEW
« no previous file with comments | « include/utils/win/SkTScopedComPtr.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698