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 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 SkMask::kLCD32_Format == rec.fMaskFormat; | 43 SkMask::kLCD32_Format == rec.fMaskFormat; |
44 } | 44 } |
45 | 45 |
46 /////////////////////////////////////////////////////////////////////////////// | 46 /////////////////////////////////////////////////////////////////////////////// |
47 | 47 |
48 class StreamFontFileLoader; | 48 class StreamFontFileLoader; |
49 | 49 |
50 class SkFontMgr_DirectWrite : public SkFontMgr { | 50 class SkFontMgr_DirectWrite : public SkFontMgr { |
51 public: | 51 public: |
52 /** localeNameLength must include the null terminator. */ | 52 /** localeNameLength must include the null terminator. */ |
53 SkFontMgr_DirectWrite(IDWriteFontCollection* fontCollection, | 53 SkFontMgr_DirectWrite(IDWriteFactory* factory, IDWriteFontCollection* fontCo
llection, |
54 WCHAR* localeName, int localeNameLength) | 54 WCHAR* localeName, int localeNameLength) |
55 : fFontCollection(SkRefComPtr(fontCollection)) | 55 : fFactory(SkRefComPtr(factory)) |
| 56 , fFontCollection(SkRefComPtr(fontCollection)) |
56 , fLocaleName(localeNameLength) | 57 , fLocaleName(localeNameLength) |
57 { | 58 { |
58 memcpy(fLocaleName.get(), localeName, localeNameLength * sizeof(WCHAR)); | 59 memcpy(fLocaleName.get(), localeName, localeNameLength * sizeof(WCHAR)); |
59 } | 60 } |
60 | 61 |
| 62 /** Creates a typeface using a typeface cache. */ |
61 SkTypeface* createTypefaceFromDWriteFont(IDWriteFontFace* fontFace, | 63 SkTypeface* createTypefaceFromDWriteFont(IDWriteFontFace* fontFace, |
62 IDWriteFont* font, | 64 IDWriteFont* font, |
63 IDWriteFontFamily* fontFamily, | 65 IDWriteFontFamily* fontFamily) cons
t; |
64 StreamFontFileLoader* = NULL, | |
65 IDWriteFontCollectionLoader* = NULL
) const; | |
66 | 66 |
67 protected: | 67 protected: |
68 virtual int onCountFamilies() const SK_OVERRIDE; | 68 virtual int onCountFamilies() const SK_OVERRIDE; |
69 virtual void onGetFamilyName(int index, SkString* familyName) const SK_OVERR
IDE; | 69 virtual void onGetFamilyName(int index, SkString* familyName) const SK_OVERR
IDE; |
70 virtual SkFontStyleSet* onCreateStyleSet(int index) const SK_OVERRIDE; | 70 virtual SkFontStyleSet* onCreateStyleSet(int index) const SK_OVERRIDE; |
71 virtual SkFontStyleSet* onMatchFamily(const char familyName[]) const SK_OVER
RIDE; | 71 virtual SkFontStyleSet* onMatchFamily(const char familyName[]) const SK_OVER
RIDE; |
72 virtual SkTypeface* onMatchFamilyStyle(const char familyName[], | 72 virtual SkTypeface* onMatchFamilyStyle(const char familyName[], |
73 const SkFontStyle& fontstyle) const S
K_OVERRIDE; | 73 const SkFontStyle& fontstyle) const S
K_OVERRIDE; |
74 virtual SkTypeface* onMatchFaceStyle(const SkTypeface* familyMember, | 74 virtual SkTypeface* onMatchFaceStyle(const SkTypeface* familyMember, |
75 const SkFontStyle& fontstyle) const SK_
OVERRIDE; | 75 const SkFontStyle& fontstyle) const SK_
OVERRIDE; |
(...skipping 11 matching lines...) Expand all Loading... |
87 SkAutoMutexAcquire ama(fTFCacheMutex); | 87 SkAutoMutexAcquire ama(fTFCacheMutex); |
88 fTFCache.add(face, requestedStyle, strong); | 88 fTFCache.add(face, requestedStyle, strong); |
89 } | 89 } |
90 | 90 |
91 SkTypeface* FindByProcAndRef(SkTypefaceCache::FindProc proc, void* ctx) cons
t { | 91 SkTypeface* FindByProcAndRef(SkTypefaceCache::FindProc proc, void* ctx) cons
t { |
92 SkAutoMutexAcquire ama(fTFCacheMutex); | 92 SkAutoMutexAcquire ama(fTFCacheMutex); |
93 SkTypeface* typeface = fTFCache.findByProcAndRef(proc, ctx); | 93 SkTypeface* typeface = fTFCache.findByProcAndRef(proc, ctx); |
94 return typeface; | 94 return typeface; |
95 } | 95 } |
96 | 96 |
| 97 SkTScopedComPtr<IDWriteFactory> fFactory; |
97 SkTScopedComPtr<IDWriteFontCollection> fFontCollection; | 98 SkTScopedComPtr<IDWriteFontCollection> fFontCollection; |
98 SkSMallocWCHAR fLocaleName; | 99 SkSMallocWCHAR fLocaleName; |
99 mutable SkMutex fTFCacheMutex; | 100 mutable SkMutex fTFCacheMutex; |
100 mutable SkTypefaceCache fTFCache; | 101 mutable SkTypefaceCache fTFCache; |
101 | 102 |
102 friend class SkFontStyleSet_DirectWrite; | 103 friend class SkFontStyleSet_DirectWrite; |
103 }; | 104 }; |
104 | 105 |
105 class SkFontStyleSet_DirectWrite : public SkFontStyleSet { | 106 class SkFontStyleSet_DirectWrite : public SkFontStyleSet { |
106 public: | 107 public: |
(...skipping 10 matching lines...) Expand all Loading... |
117 | 118 |
118 private: | 119 private: |
119 SkAutoTUnref<const SkFontMgr_DirectWrite> fFontMgr; | 120 SkAutoTUnref<const SkFontMgr_DirectWrite> fFontMgr; |
120 SkTScopedComPtr<IDWriteFontFamily> fFontFamily; | 121 SkTScopedComPtr<IDWriteFontFamily> fFontFamily; |
121 }; | 122 }; |
122 | 123 |
123 /////////////////////////////////////////////////////////////////////////////// | 124 /////////////////////////////////////////////////////////////////////////////// |
124 | 125 |
125 class DWriteOffscreen { | 126 class DWriteOffscreen { |
126 public: | 127 public: |
127 DWriteOffscreen() : fWidth(0), fHeight(0) { | 128 DWriteOffscreen() : fWidth(0), fHeight(0) { } |
128 } | |
129 | 129 |
130 void init(IDWriteFontFace* fontFace, const DWRITE_MATRIX& xform, FLOAT fontS
ize) { | 130 void init(IDWriteFactory* factory, IDWriteFontFace* fontFace, |
| 131 const DWRITE_MATRIX& xform, FLOAT fontSize) |
| 132 { |
| 133 fFactory = factory; |
131 fFontFace = fontFace; | 134 fFontFace = fontFace; |
132 fFontSize = fontSize; | 135 fFontSize = fontSize; |
133 fXform = xform; | 136 fXform = xform; |
134 } | 137 } |
135 | 138 |
136 const void* draw(const SkGlyph&, bool isBW); | 139 const void* draw(const SkGlyph&, bool isBW); |
137 | 140 |
138 private: | 141 private: |
139 uint16_t fWidth; | 142 uint16_t fWidth; |
140 uint16_t fHeight; | 143 uint16_t fHeight; |
| 144 IDWriteFactory* fFactory; |
141 IDWriteFontFace* fFontFace; | 145 IDWriteFontFace* fFontFace; |
142 FLOAT fFontSize; | 146 FLOAT fFontSize; |
143 DWRITE_MATRIX fXform; | 147 DWRITE_MATRIX fXform; |
144 SkTDArray<uint8_t> fBits; | 148 SkTDArray<uint8_t> fBits; |
145 }; | 149 }; |
146 | 150 |
147 const void* DWriteOffscreen::draw(const SkGlyph& glyph, bool isBW) { | 151 const void* DWriteOffscreen::draw(const SkGlyph& glyph, bool isBW) { |
148 IDWriteFactory* factory = sk_get_dwrite_factory(); | |
149 SkASSERT(factory != NULL); | |
150 | |
151 if (fWidth < glyph.fWidth || fHeight < glyph.fHeight) { | 152 if (fWidth < glyph.fWidth || fHeight < glyph.fHeight) { |
152 fWidth = SkMax32(fWidth, glyph.fWidth); | 153 fWidth = SkMax32(fWidth, glyph.fWidth); |
153 fHeight = SkMax32(fHeight, glyph.fHeight); | 154 fHeight = SkMax32(fHeight, glyph.fHeight); |
154 | 155 |
155 if (isBW) { | 156 if (isBW) { |
156 fBits.setCount(fWidth * fHeight); | 157 fBits.setCount(fWidth * fHeight); |
157 } else { | 158 } else { |
158 fBits.setCount(fWidth * fHeight * 3); | 159 fBits.setCount(fWidth * fHeight * 3); |
159 } | 160 } |
160 } | 161 } |
(...skipping 25 matching lines...) Expand all Loading... |
186 DWRITE_RENDERING_MODE renderingMode; | 187 DWRITE_RENDERING_MODE renderingMode; |
187 DWRITE_TEXTURE_TYPE textureType; | 188 DWRITE_TEXTURE_TYPE textureType; |
188 if (isBW) { | 189 if (isBW) { |
189 renderingMode = DWRITE_RENDERING_MODE_ALIASED; | 190 renderingMode = DWRITE_RENDERING_MODE_ALIASED; |
190 textureType = DWRITE_TEXTURE_ALIASED_1x1; | 191 textureType = DWRITE_TEXTURE_ALIASED_1x1; |
191 } else { | 192 } else { |
192 renderingMode = DWRITE_RENDERING_MODE_CLEARTYPE_NATURAL_SYMMETRIC; | 193 renderingMode = DWRITE_RENDERING_MODE_CLEARTYPE_NATURAL_SYMMETRIC; |
193 textureType = DWRITE_TEXTURE_CLEARTYPE_3x1; | 194 textureType = DWRITE_TEXTURE_CLEARTYPE_3x1; |
194 } | 195 } |
195 SkTScopedComPtr<IDWriteGlyphRunAnalysis> glyphRunAnalysis; | 196 SkTScopedComPtr<IDWriteGlyphRunAnalysis> glyphRunAnalysis; |
196 HRNM(factory->CreateGlyphRunAnalysis(&run, | 197 HRNM(fFactory->CreateGlyphRunAnalysis(&run, |
197 1.0f, // pixelsPerDip, | 198 1.0f, // pixelsPerDip, |
198 &fXform, | 199 &fXform, |
199 renderingMode, | 200 renderingMode, |
200 DWRITE_MEASURING_MODE_NATURAL, | 201 DWRITE_MEASURING_MODE_NATURAL, |
201 0.0f, // baselineOriginX, | 202 0.0f, // baselineOriginX, |
202 0.0f, // baselineOriginY, | 203 0.0f, // baselineOriginY, |
203 &glyphRunAnalysis), | 204 &glyphRunAnalysis), |
204 "Could not create glyph run analysis."); | 205 "Could not create glyph run analysis."); |
205 | 206 |
206 //NOTE: this assumes that the glyph has already been measured | 207 //NOTE: this assumes that the glyph has already been measured |
207 //with an exact same glyph run analysis. | 208 //with an exact same glyph run analysis. |
208 RECT bbox; | 209 RECT bbox; |
209 bbox.left = glyph.fLeft; | 210 bbox.left = glyph.fLeft; |
210 bbox.top = glyph.fTop; | 211 bbox.top = glyph.fTop; |
211 bbox.right = glyph.fLeft + glyph.fWidth; | 212 bbox.right = glyph.fLeft + glyph.fWidth; |
212 bbox.bottom = glyph.fTop + glyph.fHeight; | 213 bbox.bottom = glyph.fTop + glyph.fHeight; |
213 HRNM(glyphRunAnalysis->CreateAlphaTexture(textureType, | 214 HRNM(glyphRunAnalysis->CreateAlphaTexture(textureType, |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
451 DWRITE_FONT_STYLE angle = font->GetStyle(); | 452 DWRITE_FONT_STYLE angle = font->GetStyle(); |
452 if (DWRITE_FONT_STYLE_OBLIQUE == angle || DWRITE_FONT_STYLE_ITALIC == angle)
{ | 453 if (DWRITE_FONT_STYLE_OBLIQUE == angle || DWRITE_FONT_STYLE_ITALIC == angle)
{ |
453 style |= SkTypeface::kItalic; | 454 style |= SkTypeface::kItalic; |
454 } | 455 } |
455 return static_cast<SkTypeface::Style>(style); | 456 return static_cast<SkTypeface::Style>(style); |
456 } | 457 } |
457 | 458 |
458 class DWriteFontTypeface : public SkTypeface { | 459 class DWriteFontTypeface : public SkTypeface { |
459 private: | 460 private: |
460 DWriteFontTypeface(SkTypeface::Style style, SkFontID fontID, | 461 DWriteFontTypeface(SkTypeface::Style style, SkFontID fontID, |
| 462 IDWriteFactory* factory, |
461 IDWriteFontFace* fontFace, | 463 IDWriteFontFace* fontFace, |
462 IDWriteFont* font, | 464 IDWriteFont* font, |
463 IDWriteFontFamily* fontFamily, | 465 IDWriteFontFamily* fontFamily, |
464 StreamFontFileLoader* fontFileLoader = NULL, | 466 StreamFontFileLoader* fontFileLoader = NULL, |
465 IDWriteFontCollectionLoader* fontCollectionLoader = NULL) | 467 IDWriteFontCollectionLoader* fontCollectionLoader = NULL) |
466 : SkTypeface(style, fontID, false) | 468 : SkTypeface(style, fontID, false) |
| 469 , fFactory(SkRefComPtr(factory)) |
467 , fDWriteFontCollectionLoader(SkSafeRefComPtr(fontCollectionLoader)) | 470 , fDWriteFontCollectionLoader(SkSafeRefComPtr(fontCollectionLoader)) |
468 , fDWriteFontFileLoader(SkSafeRefComPtr(fontFileLoader)) | 471 , fDWriteFontFileLoader(SkSafeRefComPtr(fontFileLoader)) |
469 , fDWriteFontFamily(SkRefComPtr(fontFamily)) | 472 , fDWriteFontFamily(SkRefComPtr(fontFamily)) |
470 , fDWriteFont(SkRefComPtr(font)) | 473 , fDWriteFont(SkRefComPtr(font)) |
471 , fDWriteFontFace(SkRefComPtr(fontFace)) | 474 , fDWriteFontFace(SkRefComPtr(fontFace)) |
472 { } | 475 { } |
473 | 476 |
474 public: | 477 public: |
| 478 SkTScopedComPtr<IDWriteFactory> fFactory; |
475 SkTScopedComPtr<IDWriteFontCollectionLoader> fDWriteFontCollectionLoader; | 479 SkTScopedComPtr<IDWriteFontCollectionLoader> fDWriteFontCollectionLoader; |
476 SkTScopedComPtr<StreamFontFileLoader> fDWriteFontFileLoader; | 480 SkTScopedComPtr<StreamFontFileLoader> fDWriteFontFileLoader; |
477 SkTScopedComPtr<IDWriteFontFamily> fDWriteFontFamily; | 481 SkTScopedComPtr<IDWriteFontFamily> fDWriteFontFamily; |
478 SkTScopedComPtr<IDWriteFont> fDWriteFont; | 482 SkTScopedComPtr<IDWriteFont> fDWriteFont; |
479 SkTScopedComPtr<IDWriteFontFace> fDWriteFontFace; | 483 SkTScopedComPtr<IDWriteFontFace> fDWriteFontFace; |
480 | 484 |
481 static DWriteFontTypeface* Create(IDWriteFontFace* fontFace, | 485 static DWriteFontTypeface* Create(IDWriteFactory* factory, |
| 486 IDWriteFontFace* fontFace, |
482 IDWriteFont* font, | 487 IDWriteFont* font, |
483 IDWriteFontFamily* fontFamily, | 488 IDWriteFontFamily* fontFamily, |
484 StreamFontFileLoader* fontFileLoader = NUL
L, | 489 StreamFontFileLoader* fontFileLoader = NUL
L, |
485 IDWriteFontCollectionLoader* fontCollectio
nLoader = NULL) { | 490 IDWriteFontCollectionLoader* fontCollectio
nLoader = NULL) { |
486 SkTypeface::Style style = get_style(font); | 491 SkTypeface::Style style = get_style(font); |
487 SkFontID fontID = SkTypefaceCache::NewFontID(); | 492 SkFontID fontID = SkTypefaceCache::NewFontID(); |
488 return SkNEW_ARGS(DWriteFontTypeface, (style, fontID, | 493 return SkNEW_ARGS(DWriteFontTypeface, (style, fontID, |
489 fontFace, font, fontFamily, | 494 factory, fontFace, font, fontFami
ly, |
490 fontFileLoader, fontCollectionLoa
der)); | 495 fontFileLoader, fontCollectionLoa
der)); |
491 } | 496 } |
492 | 497 |
493 protected: | 498 protected: |
494 virtual void weak_dispose() const SK_OVERRIDE { | 499 virtual void weak_dispose() const SK_OVERRIDE { |
495 if (fDWriteFontCollectionLoader.get() == NULL) return; | 500 if (fDWriteFontCollectionLoader.get()) { |
496 | 501 HRV(fFactory->UnregisterFontCollectionLoader(fDWriteFontCollectionLo
ader.get())); |
497 IDWriteFactory* factory = sk_get_dwrite_factory(); | 502 } |
498 SkASSERT(factory != NULL); | 503 if (fDWriteFontFileLoader.get()) { |
499 HRV(factory->UnregisterFontCollectionLoader(fDWriteFontCollectionLoader.
get())); | 504 HRV(fFactory->UnregisterFontFileLoader(fDWriteFontFileLoader.get()))
; |
500 HRV(factory->UnregisterFontFileLoader(fDWriteFontFileLoader.get())); | 505 } |
501 | 506 |
502 //SkTypefaceCache::Remove(this); | 507 //SkTypefaceCache::Remove(this); |
503 INHERITED::weak_dispose(); | 508 INHERITED::weak_dispose(); |
504 } | 509 } |
505 | 510 |
506 virtual SkStream* onOpenStream(int* ttcIndex) const SK_OVERRIDE; | 511 virtual SkStream* onOpenStream(int* ttcIndex) const SK_OVERRIDE; |
507 virtual SkScalerContext* onCreateScalerContext(const SkDescriptor*) const SK
_OVERRIDE; | 512 virtual SkScalerContext* onCreateScalerContext(const SkDescriptor*) const SK
_OVERRIDE; |
508 virtual void onFilterRec(SkScalerContextRec*) const SK_OVERRIDE; | 513 virtual void onFilterRec(SkScalerContextRec*) const SK_OVERRIDE; |
509 virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics( | 514 virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics( |
510 SkAdvancedTypefaceMetrics::PerGlyphInfo, | 515 SkAdvancedTypefaceMetrics::PerGlyphInfo, |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
652 SkSMallocWCHAR dwFontFamilyNameChar(dwFontFamilyNameLength+1); | 657 SkSMallocWCHAR dwFontFamilyNameChar(dwFontFamilyNameLength+1); |
653 SkSMallocWCHAR dwFontNameChar(dwFontNameLength+1); | 658 SkSMallocWCHAR dwFontNameChar(dwFontNameLength+1); |
654 HRB(dwFontFamilyNames->GetString(0, dwFontFamilyNameChar.get(), dwFontFamily
NameLength+1)); | 659 HRB(dwFontFamilyNames->GetString(0, dwFontFamilyNameChar.get(), dwFontFamily
NameLength+1)); |
655 HRB(dwFontNames->GetString(0, dwFontNameChar.get(), dwFontNameLength+1)); | 660 HRB(dwFontNames->GetString(0, dwFontNameChar.get(), dwFontNameLength+1)); |
656 | 661 |
657 return wcscmp(dwFaceFontFamilyNameChar.get(), dwFontFamilyNameChar.get()) ==
0 && | 662 return wcscmp(dwFaceFontFamilyNameChar.get(), dwFontFamilyNameChar.get()) ==
0 && |
658 wcscmp(dwFaceFontNameChar.get(), dwFontNameChar.get()) == 0; | 663 wcscmp(dwFaceFontNameChar.get(), dwFontNameChar.get()) == 0; |
659 } | 664 } |
660 | 665 |
661 SkScalerContext_DW::SkScalerContext_DW(DWriteFontTypeface* typeface, | 666 SkScalerContext_DW::SkScalerContext_DW(DWriteFontTypeface* typeface, |
662 const SkDescriptor* desc) | 667 const SkDescriptor* desc) |
663 : SkScalerContext(typeface, desc) | 668 : SkScalerContext(typeface, desc) |
664 , fTypeface(SkRef(typeface)) | 669 , fTypeface(SkRef(typeface)) |
665 , fGlyphCount(-1) { | 670 , fGlyphCount(-1) { |
666 | 671 |
667 fXform.m11 = SkScalarToFloat(fRec.fPost2x2[0][0]); | 672 fXform.m11 = SkScalarToFloat(fRec.fPost2x2[0][0]); |
668 fXform.m12 = SkScalarToFloat(fRec.fPost2x2[1][0]); | 673 fXform.m12 = SkScalarToFloat(fRec.fPost2x2[1][0]); |
669 fXform.m21 = SkScalarToFloat(fRec.fPost2x2[0][1]); | 674 fXform.m21 = SkScalarToFloat(fRec.fPost2x2[0][1]); |
670 fXform.m22 = SkScalarToFloat(fRec.fPost2x2[1][1]); | 675 fXform.m22 = SkScalarToFloat(fRec.fPost2x2[1][1]); |
671 fXform.dx = 0; | 676 fXform.dx = 0; |
672 fXform.dy = 0; | 677 fXform.dy = 0; |
673 | 678 |
674 fOffscreen.init(fTypeface->fDWriteFontFace.get(), fXform, SkScalarToFloat(fR
ec.fTextSize)); | 679 fOffscreen.init(fTypeface->fFactory.get(), fTypeface->fDWriteFontFace.get(), |
| 680 fXform, SkScalarToFloat(fRec.fTextSize)); |
675 } | 681 } |
676 | 682 |
677 SkScalerContext_DW::~SkScalerContext_DW() { | 683 SkScalerContext_DW::~SkScalerContext_DW() { |
678 } | 684 } |
679 | 685 |
680 unsigned SkScalerContext_DW::generateGlyphCount() { | 686 unsigned SkScalerContext_DW::generateGlyphCount() { |
681 if (fGlyphCount < 0) { | 687 if (fGlyphCount < 0) { |
682 fGlyphCount = fTypeface->fDWriteFontFace->GetGlyphCount(); | 688 fGlyphCount = fTypeface->fDWriteFontFace->GetGlyphCount(); |
683 } | 689 } |
684 return fGlyphCount; | 690 return fGlyphCount; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
745 DWRITE_GLYPH_RUN run; | 751 DWRITE_GLYPH_RUN run; |
746 run.glyphCount = 1; | 752 run.glyphCount = 1; |
747 run.glyphAdvances = &advance; | 753 run.glyphAdvances = &advance; |
748 run.fontFace = fTypeface->fDWriteFontFace.get(); | 754 run.fontFace = fTypeface->fDWriteFontFace.get(); |
749 run.fontEmSize = SkScalarToFloat(fRec.fTextSize); | 755 run.fontEmSize = SkScalarToFloat(fRec.fTextSize); |
750 run.bidiLevel = 0; | 756 run.bidiLevel = 0; |
751 run.glyphIndices = &glyphId; | 757 run.glyphIndices = &glyphId; |
752 run.isSideways = FALSE; | 758 run.isSideways = FALSE; |
753 run.glyphOffsets = &offset; | 759 run.glyphOffsets = &offset; |
754 | 760 |
755 IDWriteFactory* factory = sk_get_dwrite_factory(); | |
756 SkASSERT(factory != NULL); | |
757 | |
758 const bool isBW = SkMask::kBW_Format == fRec.fMaskFormat; | 761 const bool isBW = SkMask::kBW_Format == fRec.fMaskFormat; |
759 DWRITE_RENDERING_MODE renderingMode; | 762 DWRITE_RENDERING_MODE renderingMode; |
760 DWRITE_TEXTURE_TYPE textureType; | 763 DWRITE_TEXTURE_TYPE textureType; |
761 if (isBW) { | 764 if (isBW) { |
762 renderingMode = DWRITE_RENDERING_MODE_ALIASED; | 765 renderingMode = DWRITE_RENDERING_MODE_ALIASED; |
763 textureType = DWRITE_TEXTURE_ALIASED_1x1; | 766 textureType = DWRITE_TEXTURE_ALIASED_1x1; |
764 } else { | 767 } else { |
765 renderingMode = DWRITE_RENDERING_MODE_CLEARTYPE_NATURAL_SYMMETRIC; | 768 renderingMode = DWRITE_RENDERING_MODE_CLEARTYPE_NATURAL_SYMMETRIC; |
766 textureType = DWRITE_TEXTURE_CLEARTYPE_3x1; | 769 textureType = DWRITE_TEXTURE_CLEARTYPE_3x1; |
767 } | 770 } |
768 | 771 |
769 SkTScopedComPtr<IDWriteGlyphRunAnalysis> glyphRunAnalysis; | 772 SkTScopedComPtr<IDWriteGlyphRunAnalysis> glyphRunAnalysis; |
770 HRVM(factory->CreateGlyphRunAnalysis(&run, | 773 HRVM(fTypeface->fFactory->CreateGlyphRunAnalysis( |
771 1.0f, // pixelsPerDip, | 774 &run, |
772 &fXform, | 775 1.0f, // pixelsPerDip, |
773 renderingMode, | 776 &fXform, |
774 DWRITE_MEASURING_MODE_NATURAL, | 777 renderingMode, |
775 0.0f, // baselineOriginX, | 778 DWRITE_MEASURING_MODE_NATURAL, |
776 0.0f, // baselineOriginY, | 779 0.0f, // baselineOriginX, |
777 &glyphRunAnalysis), | 780 0.0f, // baselineOriginY, |
| 781 &glyphRunAnalysis), |
778 "Could not create glyph run analysis."); | 782 "Could not create glyph run analysis."); |
779 | 783 |
780 RECT bbox; | 784 RECT bbox; |
781 HRVM(glyphRunAnalysis->GetAlphaTextureBounds(textureType, &bbox), | 785 HRVM(glyphRunAnalysis->GetAlphaTextureBounds(textureType, &bbox), |
782 "Could not get texture bounds."); | 786 "Could not get texture bounds."); |
783 | 787 |
784 glyph->fWidth = SkToU16(bbox.right - bbox.left); | 788 glyph->fWidth = SkToU16(bbox.right - bbox.left); |
785 glyph->fHeight = SkToU16(bbox.bottom - bbox.top); | 789 glyph->fHeight = SkToU16(bbox.bottom - bbox.top); |
786 glyph->fLeft = SkToS16(bbox.left); | 790 glyph->fLeft = SkToS16(bbox.left); |
787 glyph->fTop = SkToS16(bbox.top); | 791 glyph->fTop = SkToS16(bbox.top); |
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1220 } | 1224 } |
1221 | 1225 |
1222 HRESULT unregister(IDWriteFactory* factory, IDWriteFontCollectionLoader* unr
egister) { | 1226 HRESULT unregister(IDWriteFactory* factory, IDWriteFontCollectionLoader* unr
egister) { |
1223 return factory->UnregisterFontCollectionLoader(unregister); | 1227 return factory->UnregisterFontCollectionLoader(unregister); |
1224 } | 1228 } |
1225 | 1229 |
1226 IDWriteFactory* fFactory; | 1230 IDWriteFactory* fFactory; |
1227 T* fUnregister; | 1231 T* fUnregister; |
1228 }; | 1232 }; |
1229 | 1233 |
1230 static SkTypeface* create_from_stream(SkStream* stream, int ttcIndex) { | |
1231 IDWriteFactory* factory = sk_get_dwrite_factory(); | |
1232 if (NULL == factory) { | |
1233 return NULL; | |
1234 } | |
1235 | |
1236 SkTScopedComPtr<StreamFontFileLoader> fontFileLoader; | |
1237 HRN(StreamFontFileLoader::Create(stream, &fontFileLoader)); | |
1238 HRN(factory->RegisterFontFileLoader(fontFileLoader.get())); | |
1239 SkAutoIDWriteUnregister<StreamFontFileLoader> autoUnregisterFontFileLoader( | |
1240 factory, fontFileLoader.get()); | |
1241 | |
1242 SkTScopedComPtr<StreamFontCollectionLoader> fontCollectionLoader; | |
1243 HRN(StreamFontCollectionLoader::Create(fontFileLoader.get(), &fontCollection
Loader)); | |
1244 HRN(factory->RegisterFontCollectionLoader(fontCollectionLoader.get())); | |
1245 SkAutoIDWriteUnregister<StreamFontCollectionLoader> autoUnregisterFontCollec
tionLoader( | |
1246 factory, fontCollectionLoader.get()); | |
1247 | |
1248 SkTScopedComPtr<IDWriteFontCollection> fontCollection; | |
1249 HRN(factory->CreateCustomFontCollection(fontCollectionLoader.get(), NULL, 0,
&fontCollection)); | |
1250 | |
1251 // Find the first non-simulated font which has the given ttc index. | |
1252 UINT32 familyCount = fontCollection->GetFontFamilyCount(); | |
1253 for (UINT32 familyIndex = 0; familyIndex < familyCount; ++familyIndex) { | |
1254 SkTScopedComPtr<IDWriteFontFamily> fontFamily; | |
1255 HRN(fontCollection->GetFontFamily(familyIndex, &fontFamily)); | |
1256 | |
1257 UINT32 fontCount = fontFamily->GetFontCount(); | |
1258 for (UINT32 fontIndex = 0; fontIndex < fontCount; ++fontIndex) { | |
1259 SkTScopedComPtr<IDWriteFont> font; | |
1260 HRN(fontFamily->GetFont(fontIndex, &font)); | |
1261 if (font->GetSimulations() != DWRITE_FONT_SIMULATIONS_NONE) { | |
1262 continue; | |
1263 } | |
1264 | |
1265 SkTScopedComPtr<IDWriteFontFace> fontFace; | |
1266 HRN(font->CreateFontFace(&fontFace)); | |
1267 | |
1268 UINT32 faceIndex = fontFace->GetIndex(); | |
1269 if (faceIndex == ttcIndex) { | |
1270 return DWriteFontTypeface::Create(fontFace.get(), font.get(), fo
ntFamily.get(), | |
1271 autoUnregisterFontFileLoader.d
etatch(), | |
1272 autoUnregisterFontCollectionLo
ader.detatch()); | |
1273 } | |
1274 } | |
1275 } | |
1276 | |
1277 return NULL; | |
1278 } | |
1279 | |
1280 SkStream* DWriteFontTypeface::onOpenStream(int* ttcIndex) const { | 1234 SkStream* DWriteFontTypeface::onOpenStream(int* ttcIndex) const { |
1281 *ttcIndex = fDWriteFontFace->GetIndex(); | 1235 *ttcIndex = fDWriteFontFace->GetIndex(); |
1282 | 1236 |
1283 UINT32 numFiles; | 1237 UINT32 numFiles; |
1284 HRNM(fDWriteFontFace->GetFiles(&numFiles, NULL), | 1238 HRNM(fDWriteFontFace->GetFiles(&numFiles, NULL), |
1285 "Could not get number of font files."); | 1239 "Could not get number of font files."); |
1286 if (numFiles != 1) { | 1240 if (numFiles != 1) { |
1287 return NULL; | 1241 return NULL; |
1288 } | 1242 } |
1289 | 1243 |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1580 } | 1534 } |
1581 | 1535 |
1582 return info; | 1536 return info; |
1583 } | 1537 } |
1584 | 1538 |
1585 /////////////////////////////////////////////////////////////////////////////// | 1539 /////////////////////////////////////////////////////////////////////////////// |
1586 | 1540 |
1587 SkTypeface* SkFontMgr_DirectWrite::createTypefaceFromDWriteFont( | 1541 SkTypeface* SkFontMgr_DirectWrite::createTypefaceFromDWriteFont( |
1588 IDWriteFontFace* fontFace, | 1542 IDWriteFontFace* fontFace, |
1589 IDWriteFont* font, | 1543 IDWriteFont* font, |
1590 IDWriteFontFamily* fontFamily, | 1544 IDWriteFontFamily* fontFamily) const { |
1591 StreamFontFileLoader* fontFileLoader, | |
1592 IDWriteFontCollectionLoader* fontCollectionLoader) const { | |
1593 SkTypeface* face = FindByProcAndRef(FindByDWriteFont, font); | 1545 SkTypeface* face = FindByProcAndRef(FindByDWriteFont, font); |
1594 if (NULL == face) { | 1546 if (NULL == face) { |
1595 face = DWriteFontTypeface::Create(fontFace, font, fontFamily, | 1547 face = DWriteFontTypeface::Create(fFactory.get(), fontFace, font, fontFa
mily); |
1596 fontFileLoader, fontCollectionLoader); | |
1597 if (face) { | 1548 if (face) { |
1598 Add(face, get_style(font), fontCollectionLoader != NULL); | 1549 Add(face, get_style(font), true); |
1599 } | 1550 } |
1600 } | 1551 } |
1601 return face; | 1552 return face; |
1602 } | 1553 } |
1603 | 1554 |
1604 int SkFontMgr_DirectWrite::onCountFamilies() const { | 1555 int SkFontMgr_DirectWrite::onCountFamilies() const { |
1605 return fFontCollection->GetFontFamilyCount(); | 1556 return fFontCollection->GetFontFamilyCount(); |
1606 } | 1557 } |
1607 | 1558 |
1608 void SkFontMgr_DirectWrite::onGetFamilyName(int index, SkString* familyName) con
st { | 1559 void SkFontMgr_DirectWrite::onGetFamilyName(int index, SkString* familyName) con
st { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1646 SkTypeface* SkFontMgr_DirectWrite::onMatchFaceStyle(const SkTypeface* familyMemb
er, | 1597 SkTypeface* SkFontMgr_DirectWrite::onMatchFaceStyle(const SkTypeface* familyMemb
er, |
1647 const SkFontStyle& fontstyle
) const { | 1598 const SkFontStyle& fontstyle
) const { |
1648 SkString familyName; | 1599 SkString familyName; |
1649 SkFontStyleSet_DirectWrite sset( | 1600 SkFontStyleSet_DirectWrite sset( |
1650 this, ((DWriteFontTypeface*)familyMember)->fDWriteFontFamily.get() | 1601 this, ((DWriteFontTypeface*)familyMember)->fDWriteFontFamily.get() |
1651 ); | 1602 ); |
1652 return sset.matchStyle(fontstyle); | 1603 return sset.matchStyle(fontstyle); |
1653 } | 1604 } |
1654 | 1605 |
1655 SkTypeface* SkFontMgr_DirectWrite::onCreateFromStream(SkStream* stream, int ttcI
ndex) const { | 1606 SkTypeface* SkFontMgr_DirectWrite::onCreateFromStream(SkStream* stream, int ttcI
ndex) const { |
1656 return create_from_stream(stream, ttcIndex); | 1607 SkTScopedComPtr<StreamFontFileLoader> fontFileLoader; |
| 1608 HRN(StreamFontFileLoader::Create(stream, &fontFileLoader)); |
| 1609 HRN(fFactory->RegisterFontFileLoader(fontFileLoader.get())); |
| 1610 SkAutoIDWriteUnregister<StreamFontFileLoader> autoUnregisterFontFileLoader( |
| 1611 fFactory.get(), fontFileLoader.get()); |
| 1612 |
| 1613 SkTScopedComPtr<StreamFontCollectionLoader> fontCollectionLoader; |
| 1614 HRN(StreamFontCollectionLoader::Create(fontFileLoader.get(), &fontCollection
Loader)); |
| 1615 HRN(fFactory->RegisterFontCollectionLoader(fontCollectionLoader.get())); |
| 1616 SkAutoIDWriteUnregister<StreamFontCollectionLoader> autoUnregisterFontCollec
tionLoader( |
| 1617 fFactory.get(), fontCollectionLoader.get()); |
| 1618 |
| 1619 SkTScopedComPtr<IDWriteFontCollection> fontCollection; |
| 1620 HRN(fFactory->CreateCustomFontCollection(fontCollectionLoader.get(), NULL, 0
, &fontCollection)); |
| 1621 |
| 1622 // Find the first non-simulated font which has the given ttc index. |
| 1623 UINT32 familyCount = fontCollection->GetFontFamilyCount(); |
| 1624 for (UINT32 familyIndex = 0; familyIndex < familyCount; ++familyIndex) { |
| 1625 SkTScopedComPtr<IDWriteFontFamily> fontFamily; |
| 1626 HRN(fontCollection->GetFontFamily(familyIndex, &fontFamily)); |
| 1627 |
| 1628 UINT32 fontCount = fontFamily->GetFontCount(); |
| 1629 for (UINT32 fontIndex = 0; fontIndex < fontCount; ++fontIndex) { |
| 1630 SkTScopedComPtr<IDWriteFont> font; |
| 1631 HRN(fontFamily->GetFont(fontIndex, &font)); |
| 1632 if (font->GetSimulations() != DWRITE_FONT_SIMULATIONS_NONE) { |
| 1633 continue; |
| 1634 } |
| 1635 |
| 1636 SkTScopedComPtr<IDWriteFontFace> fontFace; |
| 1637 HRN(font->CreateFontFace(&fontFace)); |
| 1638 |
| 1639 UINT32 faceIndex = fontFace->GetIndex(); |
| 1640 if (faceIndex == ttcIndex) { |
| 1641 return DWriteFontTypeface::Create(fFactory.get(), |
| 1642 fontFace.get(), font.get(), fo
ntFamily.get(), |
| 1643 autoUnregisterFontFileLoader.d
etatch(), |
| 1644 autoUnregisterFontCollectionLo
ader.detatch()); |
| 1645 } |
| 1646 } |
| 1647 } |
| 1648 |
| 1649 return NULL; |
1657 } | 1650 } |
1658 | 1651 |
1659 SkTypeface* SkFontMgr_DirectWrite::onCreateFromData(SkData* data, int ttcIndex)
const { | 1652 SkTypeface* SkFontMgr_DirectWrite::onCreateFromData(SkData* data, int ttcIndex)
const { |
1660 SkAutoTUnref<SkStream> stream(SkNEW_ARGS(SkMemoryStream, (data))); | 1653 SkAutoTUnref<SkStream> stream(SkNEW_ARGS(SkMemoryStream, (data))); |
1661 return this->createFromStream(stream, ttcIndex); | 1654 return this->createFromStream(stream, ttcIndex); |
1662 } | 1655 } |
1663 | 1656 |
1664 SkTypeface* SkFontMgr_DirectWrite::onCreateFromFile(const char path[], int ttcIn
dex) const { | 1657 SkTypeface* SkFontMgr_DirectWrite::onCreateFromFile(const char path[], int ttcIn
dex) const { |
1665 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path)); | 1658 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path)); |
1666 return this->createFromStream(stream, ttcIndex); | 1659 return this->createFromStream(stream, ttcIndex); |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1801 | 1794 |
1802 SkTScopedComPtr<IDWriteFontFace> fontFace; | 1795 SkTScopedComPtr<IDWriteFontFace> fontFace; |
1803 HRNM(font->CreateFontFace(&fontFace), "Could not create font face."); | 1796 HRNM(font->CreateFontFace(&fontFace), "Could not create font face."); |
1804 | 1797 |
1805 return fFontMgr->createTypefaceFromDWriteFont(fontFace.get(), font.get(), | 1798 return fFontMgr->createTypefaceFromDWriteFont(fontFace.get(), font.get(), |
1806 fFontFamily.get()); | 1799 fFontFamily.get()); |
1807 } | 1800 } |
1808 | 1801 |
1809 /////////////////////////////////////////////////////////////////////////////// | 1802 /////////////////////////////////////////////////////////////////////////////// |
1810 | 1803 |
1811 SkFontMgr* SkFontMgr_New_DirectWrite() { | 1804 SkFontMgr* SkFontMgr_New_DirectWrite(IDWriteFactory* factory) { |
1812 IDWriteFactory* factory = sk_get_dwrite_factory(); | |
1813 if (NULL == factory) { | 1805 if (NULL == factory) { |
1814 return NULL; | 1806 factory = sk_get_dwrite_factory(); |
| 1807 if (NULL == factory) { |
| 1808 return NULL; |
| 1809 } |
1815 } | 1810 } |
1816 | 1811 |
1817 SkTScopedComPtr<IDWriteFontCollection> sysFontCollection; | 1812 SkTScopedComPtr<IDWriteFontCollection> sysFontCollection; |
1818 HRNM(factory->GetSystemFontCollection(&sysFontCollection, FALSE), | 1813 HRNM(factory->GetSystemFontCollection(&sysFontCollection, FALSE), |
1819 "Could not get system font collection."); | 1814 "Could not get system font collection."); |
1820 | 1815 |
1821 WCHAR localeNameStorage[LOCALE_NAME_MAX_LENGTH]; | 1816 WCHAR localeNameStorage[LOCALE_NAME_MAX_LENGTH]; |
1822 WCHAR* localeName = NULL; | 1817 WCHAR* localeName = NULL; |
1823 int localeNameLen = 0; | 1818 int localeNameLen = 0; |
1824 | 1819 |
1825 // Dynamically load GetUserDefaultLocaleName function, as it is not availabl
e on XP. | 1820 // Dynamically load GetUserDefaultLocaleName function, as it is not availabl
e on XP. |
1826 SkGetUserDefaultLocaleNameProc getUserDefaultLocaleNameProc = NULL; | 1821 SkGetUserDefaultLocaleNameProc getUserDefaultLocaleNameProc = NULL; |
1827 HRESULT hr = SkGetGetUserDefaultLocaleNameProc(&getUserDefaultLocaleNameProc
); | 1822 HRESULT hr = SkGetGetUserDefaultLocaleNameProc(&getUserDefaultLocaleNameProc
); |
1828 if (NULL == getUserDefaultLocaleNameProc) { | 1823 if (NULL == getUserDefaultLocaleNameProc) { |
1829 SK_TRACEHR(hr, "Could not get GetUserDefaultLocaleName."); | 1824 SK_TRACEHR(hr, "Could not get GetUserDefaultLocaleName."); |
1830 } else { | 1825 } else { |
1831 localeNameLen = getUserDefaultLocaleNameProc(localeNameStorage, LOCALE_N
AME_MAX_LENGTH); | 1826 localeNameLen = getUserDefaultLocaleNameProc(localeNameStorage, LOCALE_N
AME_MAX_LENGTH); |
1832 if (localeNameLen) { | 1827 if (localeNameLen) { |
1833 localeName = localeNameStorage; | 1828 localeName = localeNameStorage; |
1834 }; | 1829 }; |
1835 } | 1830 } |
1836 | 1831 |
1837 return SkNEW_ARGS(SkFontMgr_DirectWrite, (sysFontCollection.get(), localeNam
e, localeNameLen)); | 1832 return SkNEW_ARGS(SkFontMgr_DirectWrite, (factory, sysFontCollection.get(), |
| 1833 localeName, localeNameLen)); |
1838 } | 1834 } |
1839 | 1835 |
1840 #include "SkFontMgr_indirect.h" | 1836 #include "SkFontMgr_indirect.h" |
1841 SkFontMgr* SkFontMgr_New_DirectWriteRenderer(SkRemotableFontMgr* proxy) { | 1837 SkFontMgr* SkFontMgr_New_DirectWriteRenderer(SkRemotableFontMgr* proxy) { |
1842 SkAutoTUnref<SkFontMgr> impl(SkFontMgr_New_DirectWrite()); | 1838 SkAutoTUnref<SkFontMgr> impl(SkFontMgr_New_DirectWrite()); |
1843 if (impl.get() == NULL) { | 1839 if (impl.get() == NULL) { |
1844 return NULL; | 1840 return NULL; |
1845 } | 1841 } |
1846 return SkNEW_ARGS(SkFontMgr_Indirect, (impl.get(), proxy)); | 1842 return SkNEW_ARGS(SkFontMgr_Indirect, (impl.get(), proxy)); |
1847 } | 1843 } |
OLD | NEW |