| 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 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 487 protected: | 487 protected: |
| 488 virtual SkStream* onOpenStream(int* ttcIndex) const SK_OVERRIDE; | 488 virtual SkStream* onOpenStream(int* ttcIndex) const SK_OVERRIDE; |
| 489 virtual SkScalerContext* onCreateScalerContext(const SkDescriptor*) const SK
_OVERRIDE; | 489 virtual SkScalerContext* onCreateScalerContext(const SkDescriptor*) const SK
_OVERRIDE; |
| 490 virtual void onFilterRec(SkScalerContextRec*) const SK_OVERRIDE; | 490 virtual void onFilterRec(SkScalerContextRec*) const SK_OVERRIDE; |
| 491 virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics( | 491 virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics( |
| 492 SkAdvancedTypefaceMetrics::PerGlyphInfo, | 492 SkAdvancedTypefaceMetrics::PerGlyphInfo, |
| 493 const uint32_t*, uint32_t) const SK_OVERRIDE; | 493 const uint32_t*, uint32_t) const SK_OVERRIDE; |
| 494 virtual void onGetFontDescriptor(SkFontDescriptor*, bool*) const SK_OVERRIDE
; | 494 virtual void onGetFontDescriptor(SkFontDescriptor*, bool*) const SK_OVERRIDE
; |
| 495 virtual int onCountGlyphs() const SK_OVERRIDE; | 495 virtual int onCountGlyphs() const SK_OVERRIDE; |
| 496 virtual int onGetUPEM() const SK_OVERRIDE; | 496 virtual int onGetUPEM() const SK_OVERRIDE; |
| 497 virtual SkTypeface* onRefMatchingStyle(Style) const SK_OVERRIDE; |
| 497 }; | 498 }; |
| 498 | 499 |
| 499 class SkScalerContext_Windows : public SkScalerContext { | 500 class SkScalerContext_DW : public SkScalerContext { |
| 500 public: | 501 public: |
| 501 SkScalerContext_Windows(DWriteFontTypeface*, const SkDescriptor* desc); | 502 SkScalerContext_DW(DWriteFontTypeface*, const SkDescriptor* desc); |
| 502 virtual ~SkScalerContext_Windows(); | 503 virtual ~SkScalerContext_DW(); |
| 503 | 504 |
| 504 protected: | 505 protected: |
| 505 virtual unsigned generateGlyphCount() SK_OVERRIDE; | 506 virtual unsigned generateGlyphCount() SK_OVERRIDE; |
| 506 virtual uint16_t generateCharToGlyph(SkUnichar uni) SK_OVERRIDE; | 507 virtual uint16_t generateCharToGlyph(SkUnichar uni) SK_OVERRIDE; |
| 507 virtual void generateAdvance(SkGlyph* glyph) SK_OVERRIDE; | 508 virtual void generateAdvance(SkGlyph* glyph) SK_OVERRIDE; |
| 508 virtual void generateMetrics(SkGlyph* glyph) SK_OVERRIDE; | 509 virtual void generateMetrics(SkGlyph* glyph) SK_OVERRIDE; |
| 509 virtual void generateImage(const SkGlyph& glyph) SK_OVERRIDE; | 510 virtual void generateImage(const SkGlyph& glyph) SK_OVERRIDE; |
| 510 virtual void generatePath(const SkGlyph& glyph, SkPath* path) SK_OVERRIDE; | 511 virtual void generatePath(const SkGlyph& glyph, SkPath* path) SK_OVERRIDE; |
| 511 virtual void generateFontMetrics(SkPaint::FontMetrics* mX, | 512 virtual void generateFontMetrics(SkPaint::FontMetrics* mX, |
| 512 SkPaint::FontMetrics* mY) SK_OVERRIDE; | 513 SkPaint::FontMetrics* mY) SK_OVERRIDE; |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 716 if (NULL == face) { | 717 if (NULL == face) { |
| 717 HRVM(get_default_font(font), "Could not get default font."); | 718 HRVM(get_default_font(font), "Could not get default font."); |
| 718 } else { | 719 } else { |
| 719 *font = SkRefComPtr(static_cast<const DWriteFontTypeface*>(face)->fDWrit
eFont.get()); | 720 *font = SkRefComPtr(static_cast<const DWriteFontTypeface*>(face)->fDWrit
eFont.get()); |
| 720 } | 721 } |
| 721 } | 722 } |
| 722 static DWriteFontTypeface* GetDWriteFontByID(SkFontID fontID) { | 723 static DWriteFontTypeface* GetDWriteFontByID(SkFontID fontID) { |
| 723 return static_cast<DWriteFontTypeface*>(SkTypefaceCache::FindByID(fontID)); | 724 return static_cast<DWriteFontTypeface*>(SkTypefaceCache::FindByID(fontID)); |
| 724 } | 725 } |
| 725 | 726 |
| 726 SkScalerContext_Windows::SkScalerContext_Windows(DWriteFontTypeface* typeface, | 727 SkScalerContext_DW::SkScalerContext_DW(DWriteFontTypeface* typeface, |
| 727 const SkDescriptor* desc) | 728 const SkDescriptor* desc) |
| 728 : SkScalerContext(typeface, desc) | 729 : SkScalerContext(typeface, desc) |
| 729 , fTypeface(SkRef(typeface)) | 730 , fTypeface(SkRef(typeface)) |
| 730 , fGlyphCount(-1) { | 731 , fGlyphCount(-1) { |
| 731 SkAutoMutexAcquire ac(gFTMutex); | 732 SkAutoMutexAcquire ac(gFTMutex); |
| 732 | 733 |
| 733 fXform.m11 = SkScalarToFloat(fRec.fPost2x2[0][0]); | 734 fXform.m11 = SkScalarToFloat(fRec.fPost2x2[0][0]); |
| 734 fXform.m12 = SkScalarToFloat(fRec.fPost2x2[1][0]); | 735 fXform.m12 = SkScalarToFloat(fRec.fPost2x2[1][0]); |
| 735 fXform.m21 = SkScalarToFloat(fRec.fPost2x2[0][1]); | 736 fXform.m21 = SkScalarToFloat(fRec.fPost2x2[0][1]); |
| 736 fXform.m22 = SkScalarToFloat(fRec.fPost2x2[1][1]); | 737 fXform.m22 = SkScalarToFloat(fRec.fPost2x2[1][1]); |
| 737 fXform.dx = 0; | 738 fXform.dx = 0; |
| 738 fXform.dy = 0; | 739 fXform.dy = 0; |
| 739 | 740 |
| 740 fOffscreen.init(fTypeface->fDWriteFontFace.get(), fXform, SkScalarToFloat(fR
ec.fTextSize)); | 741 fOffscreen.init(fTypeface->fDWriteFontFace.get(), fXform, SkScalarToFloat(fR
ec.fTextSize)); |
| 741 } | 742 } |
| 742 | 743 |
| 743 SkScalerContext_Windows::~SkScalerContext_Windows() { | 744 SkScalerContext_DW::~SkScalerContext_DW() { |
| 744 } | 745 } |
| 745 | 746 |
| 746 unsigned SkScalerContext_Windows::generateGlyphCount() { | 747 unsigned SkScalerContext_DW::generateGlyphCount() { |
| 747 if (fGlyphCount < 0) { | 748 if (fGlyphCount < 0) { |
| 748 fGlyphCount = fTypeface->fDWriteFontFace->GetGlyphCount(); | 749 fGlyphCount = fTypeface->fDWriteFontFace->GetGlyphCount(); |
| 749 } | 750 } |
| 750 return fGlyphCount; | 751 return fGlyphCount; |
| 751 } | 752 } |
| 752 | 753 |
| 753 uint16_t SkScalerContext_Windows::generateCharToGlyph(SkUnichar uni) { | 754 uint16_t SkScalerContext_DW::generateCharToGlyph(SkUnichar uni) { |
| 754 uint16_t index = 0; | 755 uint16_t index = 0; |
| 755 fTypeface->fDWriteFontFace->GetGlyphIndices(reinterpret_cast<UINT32*>(&uni),
1, &index); | 756 fTypeface->fDWriteFontFace->GetGlyphIndices(reinterpret_cast<UINT32*>(&uni),
1, &index); |
| 756 return index; | 757 return index; |
| 757 } | 758 } |
| 758 | 759 |
| 759 void SkScalerContext_Windows::generateAdvance(SkGlyph* glyph) { | 760 void SkScalerContext_DW::generateAdvance(SkGlyph* glyph) { |
| 760 //Delta is the difference between the right/left side bearing metric | 761 //Delta is the difference between the right/left side bearing metric |
| 761 //and where the right/left side bearing ends up after hinting. | 762 //and where the right/left side bearing ends up after hinting. |
| 762 //DirectWrite does not provide this information. | 763 //DirectWrite does not provide this information. |
| 763 glyph->fRsbDelta = 0; | 764 glyph->fRsbDelta = 0; |
| 764 glyph->fLsbDelta = 0; | 765 glyph->fLsbDelta = 0; |
| 765 | 766 |
| 766 glyph->fAdvanceX = 0; | 767 glyph->fAdvanceX = 0; |
| 767 glyph->fAdvanceY = 0; | 768 glyph->fAdvanceY = 0; |
| 768 | 769 |
| 769 uint16_t glyphId = glyph->getGlyphID(); | 770 uint16_t glyphId = glyph->getGlyphID(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 784 | 785 |
| 785 SkVector vecs[1] = { { advanceX, 0 } }; | 786 SkVector vecs[1] = { { advanceX, 0 } }; |
| 786 SkMatrix mat; | 787 SkMatrix mat; |
| 787 fRec.getMatrixFrom2x2(&mat); | 788 fRec.getMatrixFrom2x2(&mat); |
| 788 mat.mapVectors(vecs, SK_ARRAY_COUNT(vecs)); | 789 mat.mapVectors(vecs, SK_ARRAY_COUNT(vecs)); |
| 789 | 790 |
| 790 glyph->fAdvanceX = SkScalarToFixed(vecs[0].fX); | 791 glyph->fAdvanceX = SkScalarToFixed(vecs[0].fX); |
| 791 glyph->fAdvanceY = SkScalarToFixed(vecs[0].fY); | 792 glyph->fAdvanceY = SkScalarToFixed(vecs[0].fY); |
| 792 } | 793 } |
| 793 | 794 |
| 794 void SkScalerContext_Windows::generateMetrics(SkGlyph* glyph) { | 795 void SkScalerContext_DW::generateMetrics(SkGlyph* glyph) { |
| 795 glyph->fWidth = 0; | 796 glyph->fWidth = 0; |
| 796 | 797 |
| 797 this->generateAdvance(glyph); | 798 this->generateAdvance(glyph); |
| 798 | 799 |
| 799 //Measure raster size. | 800 //Measure raster size. |
| 800 fXform.dx = SkFixedToFloat(glyph->getSubXFixed()); | 801 fXform.dx = SkFixedToFloat(glyph->getSubXFixed()); |
| 801 fXform.dy = SkFixedToFloat(glyph->getSubYFixed()); | 802 fXform.dy = SkFixedToFloat(glyph->getSubYFixed()); |
| 802 | 803 |
| 803 FLOAT advance = 0; | 804 FLOAT advance = 0; |
| 804 | 805 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 846 RECT bbox; | 847 RECT bbox; |
| 847 HRVM(glyphRunAnalysis->GetAlphaTextureBounds(textureType, &bbox), | 848 HRVM(glyphRunAnalysis->GetAlphaTextureBounds(textureType, &bbox), |
| 848 "Could not get texture bounds."); | 849 "Could not get texture bounds."); |
| 849 | 850 |
| 850 glyph->fWidth = SkToU16(bbox.right - bbox.left); | 851 glyph->fWidth = SkToU16(bbox.right - bbox.left); |
| 851 glyph->fHeight = SkToU16(bbox.bottom - bbox.top); | 852 glyph->fHeight = SkToU16(bbox.bottom - bbox.top); |
| 852 glyph->fLeft = SkToS16(bbox.left); | 853 glyph->fLeft = SkToS16(bbox.left); |
| 853 glyph->fTop = SkToS16(bbox.top); | 854 glyph->fTop = SkToS16(bbox.top); |
| 854 } | 855 } |
| 855 | 856 |
| 856 void SkScalerContext_Windows::generateFontMetrics(SkPaint::FontMetrics* mx, | 857 void SkScalerContext_DW::generateFontMetrics(SkPaint::FontMetrics* mx, |
| 857 SkPaint::FontMetrics* my) { | 858 SkPaint::FontMetrics* my) { |
| 858 if (!(mx || my)) | 859 if (!(mx || my)) |
| 859 return; | 860 return; |
| 860 | 861 |
| 861 DWRITE_FONT_METRICS dwfm; | 862 DWRITE_FONT_METRICS dwfm; |
| 862 fTypeface->fDWriteFontFace->GetMetrics(&dwfm); | 863 fTypeface->fDWriteFontFace->GetMetrics(&dwfm); |
| 863 | 864 |
| 864 if (mx) { | 865 if (mx) { |
| 865 mx->fTop = SkScalarMulDiv(-fRec.fTextSize, | 866 mx->fTop = SkScalarMulDiv(-fRec.fTextSize, |
| 866 SkIntToScalar(dwfm.ascent), | 867 SkIntToScalar(dwfm.ascent), |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 980 for (U16CPU i = 0; i < width; i++) { | 981 for (U16CPU i = 0; i < width; i++) { |
| 981 U8CPU r = sk_apply_lut_if<APPLY_PREBLEND>(*(src++), tableR); | 982 U8CPU r = sk_apply_lut_if<APPLY_PREBLEND>(*(src++), tableR); |
| 982 U8CPU g = sk_apply_lut_if<APPLY_PREBLEND>(*(src++), tableG); | 983 U8CPU g = sk_apply_lut_if<APPLY_PREBLEND>(*(src++), tableG); |
| 983 U8CPU b = sk_apply_lut_if<APPLY_PREBLEND>(*(src++), tableB); | 984 U8CPU b = sk_apply_lut_if<APPLY_PREBLEND>(*(src++), tableB); |
| 984 dst[i] = SkPackARGB32(0xFF, r, g, b); | 985 dst[i] = SkPackARGB32(0xFF, r, g, b); |
| 985 } | 986 } |
| 986 dst = (SkPMColor*)((char*)dst + dstRB); | 987 dst = (SkPMColor*)((char*)dst + dstRB); |
| 987 } | 988 } |
| 988 } | 989 } |
| 989 | 990 |
| 990 void SkScalerContext_Windows::generateImage(const SkGlyph& glyph) { | 991 void SkScalerContext_DW::generateImage(const SkGlyph& glyph) { |
| 991 SkAutoMutexAcquire ac(gFTMutex); | 992 SkAutoMutexAcquire ac(gFTMutex); |
| 992 | 993 |
| 993 const bool isBW = SkMask::kBW_Format == fRec.fMaskFormat; | 994 const bool isBW = SkMask::kBW_Format == fRec.fMaskFormat; |
| 994 const bool isAA = !isLCD(fRec); | 995 const bool isAA = !isLCD(fRec); |
| 995 | 996 |
| 996 //Create the mask. | 997 //Create the mask. |
| 997 const void* bits = fOffscreen.draw(glyph, isBW); | 998 const void* bits = fOffscreen.draw(glyph, isBW); |
| 998 if (!bits) { | 999 if (!bits) { |
| 999 sk_bzero(glyph.fImage, glyph.computeImageSize()); | 1000 sk_bzero(glyph.fImage, glyph.computeImageSize()); |
| 1000 return; | 1001 return; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1019 } else { | 1020 } else { |
| 1020 SkASSERT(SkMask::kLCD32_Format == glyph.fMaskFormat); | 1021 SkASSERT(SkMask::kLCD32_Format == glyph.fMaskFormat); |
| 1021 if (fPreBlend.isApplicable()) { | 1022 if (fPreBlend.isApplicable()) { |
| 1022 rgb_to_lcd32<true>(src, glyph, fPreBlend.fR, fPreBlend.fG, fPreBlend
.fB); | 1023 rgb_to_lcd32<true>(src, glyph, fPreBlend.fR, fPreBlend.fG, fPreBlend
.fB); |
| 1023 } else { | 1024 } else { |
| 1024 rgb_to_lcd32<false>(src, glyph, fPreBlend.fR, fPreBlend.fG, fPreBlen
d.fB); | 1025 rgb_to_lcd32<false>(src, glyph, fPreBlend.fR, fPreBlend.fG, fPreBlen
d.fB); |
| 1025 } | 1026 } |
| 1026 } | 1027 } |
| 1027 } | 1028 } |
| 1028 | 1029 |
| 1029 void SkScalerContext_Windows::generatePath(const SkGlyph& glyph, SkPath* path) { | 1030 void SkScalerContext_DW::generatePath(const SkGlyph& glyph, SkPath* path) { |
| 1030 SkAutoMutexAcquire ac(gFTMutex); | 1031 SkAutoMutexAcquire ac(gFTMutex); |
| 1031 | 1032 |
| 1032 SkASSERT(&glyph && path); | 1033 SkASSERT(&glyph && path); |
| 1033 | 1034 |
| 1034 path->reset(); | 1035 path->reset(); |
| 1035 | 1036 |
| 1036 SkTScopedComPtr<IDWriteGeometrySink> geometryToPath; | 1037 SkTScopedComPtr<IDWriteGeometrySink> geometryToPath; |
| 1037 HRVM(SkDWriteGeometrySink::Create(path, &geometryToPath), | 1038 HRVM(SkDWriteGeometrySink::Create(path, &geometryToPath), |
| 1038 "Could not create geometry to path converter."); | 1039 "Could not create geometry to path converter."); |
| 1039 uint16_t glyphId = glyph.getGlyphID(); | 1040 uint16_t glyphId = glyph.getGlyphID(); |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1155 return SkCreateTypefaceFromDWriteFont(fontFace.get(), font.get()
, fontFamily.get(), | 1156 return SkCreateTypefaceFromDWriteFont(fontFace.get(), font.get()
, fontFamily.get(), |
| 1156 autoUnregisterFontFileLoad
er.detatch(), | 1157 autoUnregisterFontFileLoad
er.detatch(), |
| 1157 autoUnregisterFontCollecti
onLoader.detatch()); | 1158 autoUnregisterFontCollecti
onLoader.detatch()); |
| 1158 } | 1159 } |
| 1159 } | 1160 } |
| 1160 } | 1161 } |
| 1161 | 1162 |
| 1162 return NULL; | 1163 return NULL; |
| 1163 } | 1164 } |
| 1164 | 1165 |
| 1165 SkTypeface* SkFontHost::CreateTypefaceFromStream(SkStream* stream) { | |
| 1166 return create_from_stream(stream, 0); | |
| 1167 } | |
| 1168 | |
| 1169 SkStream* DWriteFontTypeface::onOpenStream(int* ttcIndex) const { | 1166 SkStream* DWriteFontTypeface::onOpenStream(int* ttcIndex) const { |
| 1170 *ttcIndex = fDWriteFontFace->GetIndex(); | 1167 *ttcIndex = fDWriteFontFace->GetIndex(); |
| 1171 | 1168 |
| 1172 UINT32 numFiles; | 1169 UINT32 numFiles; |
| 1173 HRNM(fDWriteFontFace->GetFiles(&numFiles, NULL), | 1170 HRNM(fDWriteFontFace->GetFiles(&numFiles, NULL), |
| 1174 "Could not get number of font files."); | 1171 "Could not get number of font files."); |
| 1175 if (numFiles != 1) { | 1172 if (numFiles != 1) { |
| 1176 return NULL; | 1173 return NULL; |
| 1177 } | 1174 } |
| 1178 | 1175 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1189 | 1186 |
| 1190 SkTScopedComPtr<IDWriteFontFileStream> fontFileStream; | 1187 SkTScopedComPtr<IDWriteFontFileStream> fontFileStream; |
| 1191 HRNM(fontFileLoader->CreateStreamFromKey(fontFileKey, fontFileKeySize, | 1188 HRNM(fontFileLoader->CreateStreamFromKey(fontFileKey, fontFileKeySize, |
| 1192 &fontFileStream), | 1189 &fontFileStream), |
| 1193 "Could not create font file stream."); | 1190 "Could not create font file stream."); |
| 1194 | 1191 |
| 1195 return SkNEW_ARGS(SkDWriteFontFileStream, (fontFileStream.get())); | 1192 return SkNEW_ARGS(SkDWriteFontFileStream, (fontFileStream.get())); |
| 1196 } | 1193 } |
| 1197 | 1194 |
| 1198 SkScalerContext* DWriteFontTypeface::onCreateScalerContext(const SkDescriptor* d
esc) const { | 1195 SkScalerContext* DWriteFontTypeface::onCreateScalerContext(const SkDescriptor* d
esc) const { |
| 1199 return SkNEW_ARGS(SkScalerContext_Windows, (const_cast<DWriteFontTypeface*>(
this), desc)); | 1196 return SkNEW_ARGS(SkScalerContext_DW, (const_cast<DWriteFontTypeface*>(this)
, desc)); |
| 1200 } | 1197 } |
| 1201 | 1198 |
| 1202 static HRESULT get_by_family_name(const char familyName[], IDWriteFontFamily** f
ontFamily) { | 1199 static HRESULT get_by_family_name(const char familyName[], IDWriteFontFamily** f
ontFamily) { |
| 1203 IDWriteFactory* factory; | 1200 IDWriteFactory* factory; |
| 1204 HR(get_dwrite_factory(&factory)); | 1201 HR(get_dwrite_factory(&factory)); |
| 1205 | 1202 |
| 1206 SkTScopedComPtr<IDWriteFontCollection> sysFontCollection; | 1203 SkTScopedComPtr<IDWriteFontCollection> sysFontCollection; |
| 1207 HR(factory->GetSystemFontCollection(&sysFontCollection, FALSE)); | 1204 HR(factory->GetSystemFontCollection(&sysFontCollection, FALSE)); |
| 1208 | 1205 |
| 1209 SkSMallocWCHAR wideFamilyName; | 1206 SkSMallocWCHAR wideFamilyName; |
| 1210 HR(cstring_to_wchar(familyName, &wideFamilyName)); | 1207 HR(cstring_to_wchar(familyName, &wideFamilyName)); |
| 1211 | 1208 |
| 1212 UINT32 index; | 1209 UINT32 index; |
| 1213 BOOL exists; | 1210 BOOL exists; |
| 1214 HR(sysFontCollection->FindFamilyName(wideFamilyName.get(), &index, &exists))
; | 1211 HR(sysFontCollection->FindFamilyName(wideFamilyName.get(), &index, &exists))
; |
| 1215 | 1212 |
| 1216 if (exists) { | 1213 if (exists) { |
| 1217 HR(sysFontCollection->GetFontFamily(index, fontFamily)); | 1214 HR(sysFontCollection->GetFontFamily(index, fontFamily)); |
| 1218 return S_OK; | 1215 return S_OK; |
| 1219 } | 1216 } |
| 1220 return S_FALSE; | 1217 return S_FALSE; |
| 1221 } | 1218 } |
| 1222 | 1219 |
| 1223 /** Return the closest matching typeface given either an existing family | |
| 1224 (specified by a typeface in that family) or by a familyName, and a | |
| 1225 requested style. | |
| 1226 1) If familyFace is null, use familyName. | |
| 1227 2) If familyName is null, use familyFace. | |
| 1228 3) If both are null, return the default font that best matches style | |
| 1229 This MUST not return NULL. | |
| 1230 */ | |
| 1231 SkTypeface* SkFontHost::CreateTypeface(const SkTypeface* familyFace, | |
| 1232 const char familyName[], | |
| 1233 SkTypeface::Style style) { | |
| 1234 HRESULT hr; | |
| 1235 SkTScopedComPtr<IDWriteFontFamily> fontFamily; | |
| 1236 if (familyFace) { | |
| 1237 const DWriteFontTypeface* face = static_cast<const DWriteFontTypeface*>(
familyFace); | |
| 1238 *(&fontFamily) = SkRefComPtr(face->fDWriteFontFamily.get()); | |
| 1239 | |
| 1240 } else if (familyName) { | |
| 1241 hr = get_by_family_name(familyName, &fontFamily); | |
| 1242 } | |
| 1243 | |
| 1244 if (NULL == fontFamily.get()) { | |
| 1245 //No good family found, go with default. | |
| 1246 SkTScopedComPtr<IDWriteFont> font; | |
| 1247 hr = get_default_font(&font); | |
| 1248 hr = font->GetFontFamily(&fontFamily); | |
| 1249 } | |
| 1250 | |
| 1251 SkTScopedComPtr<IDWriteFont> font; | |
| 1252 DWRITE_FONT_WEIGHT weight = (style & SkTypeface::kBold) | |
| 1253 ? DWRITE_FONT_WEIGHT_BOLD | |
| 1254 : DWRITE_FONT_WEIGHT_NORMAL; | |
| 1255 DWRITE_FONT_STRETCH stretch = DWRITE_FONT_STRETCH_UNDEFINED; | |
| 1256 DWRITE_FONT_STYLE italic = (style & SkTypeface::kItalic) | |
| 1257 ? DWRITE_FONT_STYLE_ITALIC | |
| 1258 : DWRITE_FONT_STYLE_NORMAL; | |
| 1259 hr = fontFamily->GetFirstMatchingFont(weight, stretch, italic, &font); | |
| 1260 | |
| 1261 SkTScopedComPtr<IDWriteFontFace> fontFace; | |
| 1262 hr = font->CreateFontFace(&fontFace); | |
| 1263 | |
| 1264 return SkCreateTypefaceFromDWriteFont(fontFace.get(), font.get(), fontFamily
.get()); | |
| 1265 } | |
| 1266 | |
| 1267 SkTypeface* SkFontHost::CreateTypefaceFromFile(const char path[]) { | |
| 1268 printf("SkFontHost::CreateTypefaceFromFile unimplemented"); | |
| 1269 return NULL; | |
| 1270 } | |
| 1271 | |
| 1272 void DWriteFontTypeface::onFilterRec(SkScalerContext::Rec* rec) const { | 1220 void DWriteFontTypeface::onFilterRec(SkScalerContext::Rec* rec) const { |
| 1273 if (rec->fFlags & SkScalerContext::kLCD_BGROrder_Flag || | 1221 if (rec->fFlags & SkScalerContext::kLCD_BGROrder_Flag || |
| 1274 rec->fFlags & SkScalerContext::kLCD_Vertical_Flag) | 1222 rec->fFlags & SkScalerContext::kLCD_Vertical_Flag) |
| 1275 { | 1223 { |
| 1276 rec->fMaskFormat = SkMask::kA8_Format; | 1224 rec->fMaskFormat = SkMask::kA8_Format; |
| 1277 } | 1225 } |
| 1278 | 1226 |
| 1279 unsigned flagsWeDontSupport = SkScalerContext::kDevKernText_Flag | | 1227 unsigned flagsWeDontSupport = SkScalerContext::kDevKernText_Flag | |
| 1280 SkScalerContext::kAutohinting_Flag | | 1228 SkScalerContext::kAutohinting_Flag | |
| 1281 SkScalerContext::kEmbeddedBitmapText_Flag | | 1229 SkScalerContext::kEmbeddedBitmapText_Flag | |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1557 glyphCount, | 1505 glyphCount, |
| 1558 glyphIDs, | 1506 glyphIDs, |
| 1559 glyphIDsCount, | 1507 glyphIDsCount, |
| 1560 getWidthAdvance)); | 1508 getWidthAdvance)); |
| 1561 } | 1509 } |
| 1562 } | 1510 } |
| 1563 | 1511 |
| 1564 return info; | 1512 return info; |
| 1565 } | 1513 } |
| 1566 | 1514 |
| 1515 static SkTypeface* create_typeface(const SkTypeface* familyFace, |
| 1516 const char familyName[], |
| 1517 unsigned style) { |
| 1518 HRESULT hr; |
| 1519 SkTScopedComPtr<IDWriteFontFamily> fontFamily; |
| 1520 if (familyFace) { |
| 1521 const DWriteFontTypeface* face = static_cast<const DWriteFontTypeface*>(
familyFace); |
| 1522 *(&fontFamily) = SkRefComPtr(face->fDWriteFontFamily.get()); |
| 1523 |
| 1524 } else if (familyName) { |
| 1525 hr = get_by_family_name(familyName, &fontFamily); |
| 1526 } |
| 1527 |
| 1528 if (NULL == fontFamily.get()) { |
| 1529 //No good family found, go with default. |
| 1530 SkTScopedComPtr<IDWriteFont> font; |
| 1531 hr = get_default_font(&font); |
| 1532 hr = font->GetFontFamily(&fontFamily); |
| 1533 } |
| 1534 |
| 1535 SkTScopedComPtr<IDWriteFont> font; |
| 1536 DWRITE_FONT_WEIGHT weight = (style & SkTypeface::kBold) |
| 1537 ? DWRITE_FONT_WEIGHT_BOLD |
| 1538 : DWRITE_FONT_WEIGHT_NORMAL; |
| 1539 DWRITE_FONT_STRETCH stretch = DWRITE_FONT_STRETCH_UNDEFINED; |
| 1540 DWRITE_FONT_STYLE italic = (style & SkTypeface::kItalic) |
| 1541 ? DWRITE_FONT_STYLE_ITALIC |
| 1542 : DWRITE_FONT_STYLE_NORMAL; |
| 1543 hr = fontFamily->GetFirstMatchingFont(weight, stretch, italic, &font); |
| 1544 |
| 1545 SkTScopedComPtr<IDWriteFontFace> fontFace; |
| 1546 hr = font->CreateFontFace(&fontFace); |
| 1547 |
| 1548 return SkCreateTypefaceFromDWriteFont(fontFace.get(), font.get(), fontFamily
.get()); |
| 1549 } |
| 1550 |
| 1551 SkTypeface* DWriteFontTypeface::onRefMatchingStyle(Style style) const { |
| 1552 return create_typeface(this, NULL, style); |
| 1553 } |
| 1554 |
| 1567 /////////////////////////////////////////////////////////////////////////////// | 1555 /////////////////////////////////////////////////////////////////////////////// |
| 1568 | 1556 |
| 1569 #include "SkFontMgr.h" | 1557 #include "SkFontMgr.h" |
| 1570 | 1558 |
| 1571 static void get_locale_string(IDWriteLocalizedStrings* names, const WCHAR* prefe
redLocale, | 1559 static void get_locale_string(IDWriteLocalizedStrings* names, const WCHAR* prefe
redLocale, |
| 1572 SkString* skname) { | 1560 SkString* skname) { |
| 1573 UINT32 nameIndex = 0; | 1561 UINT32 nameIndex = 0; |
| 1574 if (preferedLocale) { | 1562 if (preferedLocale) { |
| 1575 // Ignore any errors and continue with index 0 if there is a problem. | 1563 // Ignore any errors and continue with index 0 if there is a problem. |
| 1576 BOOL nameExists; | 1564 BOOL nameExists; |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1713 return create_from_stream(stream, ttcIndex); | 1701 return create_from_stream(stream, ttcIndex); |
| 1714 } | 1702 } |
| 1715 virtual SkTypeface* onCreateFromData(SkData* data, int ttcIndex) SK_OVERRIDE
{ | 1703 virtual SkTypeface* onCreateFromData(SkData* data, int ttcIndex) SK_OVERRIDE
{ |
| 1716 SkAutoTUnref<SkStream> stream(SkNEW_ARGS(SkMemoryStream, (data))); | 1704 SkAutoTUnref<SkStream> stream(SkNEW_ARGS(SkMemoryStream, (data))); |
| 1717 return this->createFromStream(stream, ttcIndex); | 1705 return this->createFromStream(stream, ttcIndex); |
| 1718 } | 1706 } |
| 1719 virtual SkTypeface* onCreateFromFile(const char path[], int ttcIndex) SK_OVE
RRIDE { | 1707 virtual SkTypeface* onCreateFromFile(const char path[], int ttcIndex) SK_OVE
RRIDE { |
| 1720 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path)); | 1708 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path)); |
| 1721 return this->createFromStream(stream, ttcIndex); | 1709 return this->createFromStream(stream, ttcIndex); |
| 1722 } | 1710 } |
| 1711 |
| 1712 virtual SkTypeface* onLegacyCreateTypeface(const char familyName[], |
| 1713 unsigned styleBits) SK_OVERRIDE { |
| 1714 return create_typeface(NULL, familyName, styleBits); |
| 1715 } |
| 1723 }; | 1716 }; |
| 1724 | 1717 |
| 1725 void SkFontStyleSet_DirectWrite::getStyle(int index, SkFontStyle* fs, SkString*
styleName) { | 1718 void SkFontStyleSet_DirectWrite::getStyle(int index, SkFontStyle* fs, SkString*
styleName) { |
| 1726 SkTScopedComPtr<IDWriteFont> font; | 1719 SkTScopedComPtr<IDWriteFont> font; |
| 1727 HRVM(fFontFamily->GetFont(index, &font), "Could not get font."); | 1720 HRVM(fFontFamily->GetFont(index, &font), "Could not get font."); |
| 1728 | 1721 |
| 1729 SkFontStyle::Slant slant; | 1722 SkFontStyle::Slant slant; |
| 1730 switch (font->GetStyle()) { | 1723 switch (font->GetStyle()) { |
| 1731 case DWRITE_FONT_STYLE_NORMAL: | 1724 case DWRITE_FONT_STYLE_NORMAL: |
| 1732 slant = SkFontStyle::kUpright_Slant; | 1725 slant = SkFontStyle::kUpright_Slant; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1743 int width = font->GetStretch(); | 1736 int width = font->GetStretch(); |
| 1744 | 1737 |
| 1745 *fs = SkFontStyle(weight, width, slant); | 1738 *fs = SkFontStyle(weight, width, slant); |
| 1746 | 1739 |
| 1747 SkTScopedComPtr<IDWriteLocalizedStrings> faceNames; | 1740 SkTScopedComPtr<IDWriteLocalizedStrings> faceNames; |
| 1748 if (SUCCEEDED(font->GetFaceNames(&faceNames))) { | 1741 if (SUCCEEDED(font->GetFaceNames(&faceNames))) { |
| 1749 get_locale_string(faceNames.get(), fFontMgr->fLocaleName.get(), styleNam
e); | 1742 get_locale_string(faceNames.get(), fFontMgr->fLocaleName.get(), styleNam
e); |
| 1750 } | 1743 } |
| 1751 } | 1744 } |
| 1752 | 1745 |
| 1746 /////////////////////////////////////////////////////////////////////////////// |
| 1747 |
| 1748 #ifndef SK_FONTHOST_USES_FONTMGR |
| 1749 |
| 1750 SkTypeface* SkFontHost::CreateTypeface(const SkTypeface* familyFace, |
| 1751 const char familyName[], |
| 1752 SkTypeface::Style style) { |
| 1753 return create_typeface(familyFace, familyName, style); |
| 1754 } |
| 1755 |
| 1756 SkTypeface* SkFontHost::CreateTypefaceFromFile(const char path[]) { |
| 1757 printf("SkFontHost::CreateTypefaceFromFile unimplemented"); |
| 1758 return NULL; |
| 1759 } |
| 1760 |
| 1761 SkTypeface* SkFontHost::CreateTypefaceFromStream(SkStream* stream) { |
| 1762 return create_from_stream(stream, 0); |
| 1763 } |
| 1764 |
| 1765 #endif |
| 1766 |
| 1753 SkFontMgr* SkFontMgr::Factory() { | 1767 SkFontMgr* SkFontMgr::Factory() { |
| 1754 IDWriteFactory* factory; | 1768 IDWriteFactory* factory; |
| 1755 HRNM(get_dwrite_factory(&factory), "Could not get factory."); | 1769 HRNM(get_dwrite_factory(&factory), "Could not get factory."); |
| 1756 | 1770 |
| 1757 SkTScopedComPtr<IDWriteFontCollection> sysFontCollection; | 1771 SkTScopedComPtr<IDWriteFontCollection> sysFontCollection; |
| 1758 HRNM(factory->GetSystemFontCollection(&sysFontCollection, FALSE), | 1772 HRNM(factory->GetSystemFontCollection(&sysFontCollection, FALSE), |
| 1759 "Could not get system font collection."); | 1773 "Could not get system font collection."); |
| 1760 | 1774 |
| 1761 WCHAR localeNameStorage[LOCALE_NAME_MAX_LENGTH]; | 1775 WCHAR localeNameStorage[LOCALE_NAME_MAX_LENGTH]; |
| 1762 WCHAR* localeName = NULL; | 1776 WCHAR* localeName = NULL; |
| 1763 int localeNameLen = GetUserDefaultLocaleName(localeNameStorage, LOCALE_NAME_
MAX_LENGTH); | 1777 int localeNameLen = GetUserDefaultLocaleName(localeNameStorage, LOCALE_NAME_
MAX_LENGTH); |
| 1764 if (localeNameLen) { | 1778 if (localeNameLen) { |
| 1765 localeName = localeNameStorage; | 1779 localeName = localeNameStorage; |
| 1766 }; | 1780 }; |
| 1767 | 1781 |
| 1768 return SkNEW_ARGS(SkFontMgr_DirectWrite, (sysFontCollection.get(), localeNam
e, localeNameLen)); | 1782 return SkNEW_ARGS(SkFontMgr_DirectWrite, (sysFontCollection.get(), localeNam
e, localeNameLen)); |
| 1769 } | 1783 } |
| OLD | NEW |