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 "SkTypes.h" | 8 #include "SkTypes.h" |
9 #if defined(SK_BUILD_FOR_WIN32) | 9 #if defined(SK_BUILD_FOR_WIN32) |
10 | 10 |
(...skipping 966 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
977 HRNM(this->getDefaultFontFamily(&fontFamily), "Could not get default fon
t family."); | 977 HRNM(this->getDefaultFontFamily(&fontFamily), "Could not get default fon
t family."); |
978 } | 978 } |
979 | 979 |
980 if (nullptr == fontFamily.get()) { | 980 if (nullptr == fontFamily.get()) { |
981 // Could not obtain the default font. | 981 // Could not obtain the default font. |
982 HRNM(fFontCollection->GetFontFamily(0, &fontFamily), | 982 HRNM(fFontCollection->GetFontFamily(0, &fontFamily), |
983 "Could not get default-default font family."); | 983 "Could not get default-default font family."); |
984 } | 984 } |
985 | 985 |
986 SkTScopedComPtr<IDWriteFont> font; | 986 SkTScopedComPtr<IDWriteFont> font; |
987 DWRITE_FONT_WEIGHT weight = (DWRITE_FONT_WEIGHT)style.weight(); | 987 DWriteStyle dwStyle(style); |
988 DWRITE_FONT_STRETCH stretch = (DWRITE_FONT_STRETCH)style.width(); | 988 HRNM(fontFamily->GetFirstMatchingFont(dwStyle.fWeight, dwStyle.fWidth, dwSty
le.fSlant, &font), |
989 DWRITE_FONT_STYLE italic = style.isItalic() ? DWRITE_FONT_STYLE_ITALIC | |
990 : DWRITE_FONT_STYLE_NORMAL; | |
991 HRNM(fontFamily->GetFirstMatchingFont(weight, stretch, italic, &font), | |
992 "Could not get matching font."); | 989 "Could not get matching font."); |
993 | 990 |
994 SkTScopedComPtr<IDWriteFontFace> fontFace; | 991 SkTScopedComPtr<IDWriteFontFace> fontFace; |
995 HRNM(font->CreateFontFace(&fontFace), "Could not create font face."); | 992 HRNM(font->CreateFontFace(&fontFace), "Could not create font face."); |
996 | 993 |
997 return this->createTypefaceFromDWriteFont(fontFace.get(), font.get(), fontFa
mily.get()); | 994 return this->createTypefaceFromDWriteFont(fontFace.get(), font.get(), fontFa
mily.get()); |
998 } | 995 } |
999 | 996 |
1000 /////////////////////////////////////////////////////////////////////////////// | 997 /////////////////////////////////////////////////////////////////////////////// |
1001 | 998 |
1002 int SkFontStyleSet_DirectWrite::count() { | 999 int SkFontStyleSet_DirectWrite::count() { |
1003 return fFontFamily->GetFontCount(); | 1000 return fFontFamily->GetFontCount(); |
1004 } | 1001 } |
1005 | 1002 |
1006 SkTypeface* SkFontStyleSet_DirectWrite::createTypeface(int index) { | 1003 SkTypeface* SkFontStyleSet_DirectWrite::createTypeface(int index) { |
1007 SkTScopedComPtr<IDWriteFont> font; | 1004 SkTScopedComPtr<IDWriteFont> font; |
1008 HRNM(fFontFamily->GetFont(index, &font), "Could not get font."); | 1005 HRNM(fFontFamily->GetFont(index, &font), "Could not get font."); |
1009 | 1006 |
1010 SkTScopedComPtr<IDWriteFontFace> fontFace; | 1007 SkTScopedComPtr<IDWriteFontFace> fontFace; |
1011 HRNM(font->CreateFontFace(&fontFace), "Could not create font face."); | 1008 HRNM(font->CreateFontFace(&fontFace), "Could not create font face."); |
1012 | 1009 |
1013 return fFontMgr->createTypefaceFromDWriteFont(fontFace.get(), font.get(), fF
ontFamily.get()); | 1010 return fFontMgr->createTypefaceFromDWriteFont(fontFace.get(), font.get(), fF
ontFamily.get()); |
1014 } | 1011 } |
1015 | 1012 |
1016 void SkFontStyleSet_DirectWrite::getStyle(int index, SkFontStyle* fs, SkString*
styleName) { | 1013 void SkFontStyleSet_DirectWrite::getStyle(int index, SkFontStyle* fs, SkString*
styleName) { |
1017 SkTScopedComPtr<IDWriteFont> font; | 1014 SkTScopedComPtr<IDWriteFont> font; |
1018 HRVM(fFontFamily->GetFont(index, &font), "Could not get font."); | 1015 HRVM(fFontFamily->GetFont(index, &font), "Could not get font."); |
1019 | 1016 |
1020 if (fs) { | 1017 if (fs) { |
1021 SkFontStyle::Slant slant; | 1018 *fs = get_style(font.get()); |
1022 switch (font->GetStyle()) { | |
1023 case DWRITE_FONT_STYLE_NORMAL: | |
1024 slant = SkFontStyle::kUpright_Slant; | |
1025 break; | |
1026 case DWRITE_FONT_STYLE_OBLIQUE: | |
1027 case DWRITE_FONT_STYLE_ITALIC: | |
1028 slant = SkFontStyle::kItalic_Slant; | |
1029 break; | |
1030 default: | |
1031 SkASSERT(false); | |
1032 } | |
1033 | |
1034 int weight = font->GetWeight(); | |
1035 int width = font->GetStretch(); | |
1036 | |
1037 *fs = SkFontStyle(weight, width, slant); | |
1038 } | 1019 } |
1039 | 1020 |
1040 if (styleName) { | 1021 if (styleName) { |
1041 SkTScopedComPtr<IDWriteLocalizedStrings> faceNames; | 1022 SkTScopedComPtr<IDWriteLocalizedStrings> faceNames; |
1042 if (SUCCEEDED(font->GetFaceNames(&faceNames))) { | 1023 if (SUCCEEDED(font->GetFaceNames(&faceNames))) { |
1043 sk_get_locale_string(faceNames.get(), fFontMgr->fLocaleName.get(), s
tyleName); | 1024 sk_get_locale_string(faceNames.get(), fFontMgr->fLocaleName.get(), s
tyleName); |
1044 } | 1025 } |
1045 } | 1026 } |
1046 } | 1027 } |
1047 | 1028 |
1048 SkTypeface* SkFontStyleSet_DirectWrite::matchStyle(const SkFontStyle& pattern) { | 1029 SkTypeface* SkFontStyleSet_DirectWrite::matchStyle(const SkFontStyle& pattern) { |
1049 DWRITE_FONT_STYLE slant; | |
1050 switch (pattern.slant()) { | |
1051 case SkFontStyle::kUpright_Slant: | |
1052 slant = DWRITE_FONT_STYLE_NORMAL; | |
1053 break; | |
1054 case SkFontStyle::kItalic_Slant: | |
1055 slant = DWRITE_FONT_STYLE_ITALIC; | |
1056 break; | |
1057 default: | |
1058 SkASSERT(false); | |
1059 } | |
1060 | |
1061 DWRITE_FONT_WEIGHT weight = (DWRITE_FONT_WEIGHT)pattern.weight(); | |
1062 DWRITE_FONT_STRETCH width = (DWRITE_FONT_STRETCH)pattern.width(); | |
1063 | |
1064 SkTScopedComPtr<IDWriteFont> font; | 1030 SkTScopedComPtr<IDWriteFont> font; |
| 1031 DWriteStyle dwStyle(pattern); |
1065 // TODO: perhaps use GetMatchingFonts and get the least simulated? | 1032 // TODO: perhaps use GetMatchingFonts and get the least simulated? |
1066 HRNM(fFontFamily->GetFirstMatchingFont(weight, width, slant, &font), | 1033 HRNM(fFontFamily->GetFirstMatchingFont(dwStyle.fWeight, dwStyle.fWidth, dwSt
yle.fSlant, &font), |
1067 "Could not match font in family."); | 1034 "Could not match font in family."); |
1068 | 1035 |
1069 SkTScopedComPtr<IDWriteFontFace> fontFace; | 1036 SkTScopedComPtr<IDWriteFontFace> fontFace; |
1070 HRNM(font->CreateFontFace(&fontFace), "Could not create font face."); | 1037 HRNM(font->CreateFontFace(&fontFace), "Could not create font face."); |
1071 | 1038 |
1072 return fFontMgr->createTypefaceFromDWriteFont(fontFace.get(), font.get(), | 1039 return fFontMgr->createTypefaceFromDWriteFont(fontFace.get(), font.get(), |
1073 fFontFamily.get()); | 1040 fFontFamily.get()); |
1074 } | 1041 } |
1075 | 1042 |
1076 //////////////////////////////////////////////////////////////////////////////// | 1043 //////////////////////////////////////////////////////////////////////////////// |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1119 | 1086 |
1120 #include "SkFontMgr_indirect.h" | 1087 #include "SkFontMgr_indirect.h" |
1121 SK_API SkFontMgr* SkFontMgr_New_DirectWriteRenderer(SkRemotableFontMgr* proxy) { | 1088 SK_API SkFontMgr* SkFontMgr_New_DirectWriteRenderer(SkRemotableFontMgr* proxy) { |
1122 SkAutoTUnref<SkFontMgr> impl(SkFontMgr_New_DirectWrite()); | 1089 SkAutoTUnref<SkFontMgr> impl(SkFontMgr_New_DirectWrite()); |
1123 if (impl.get() == nullptr) { | 1090 if (impl.get() == nullptr) { |
1124 return nullptr; | 1091 return nullptr; |
1125 } | 1092 } |
1126 return new SkFontMgr_Indirect(impl.get(), proxy); | 1093 return new SkFontMgr_Indirect(impl.get(), proxy); |
1127 } | 1094 } |
1128 #endif//defined(SK_BUILD_FOR_WIN32) | 1095 #endif//defined(SK_BUILD_FOR_WIN32) |
OLD | NEW |