diff options
author | bungeman <bungeman@google.com> | 2016-04-12 13:45:06 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-04-12 13:45:06 -0700 |
commit | 11a77c6e0634e2feb6fe4e74806db2fdd2a799ec (patch) | |
tree | d62d216858bbe136c4b41b9ec563ea35bd7ff1ed /src/ports/SkFontMgr_win_dw.cpp | |
parent | 0586f5cc9713268238394411a5daa2c7758b092b (diff) |
Begin switch to SkFontStyle for legacy calls.
This adds SK_VERY_LEGACY_CREATE_TYPEFACE which, when defined, provides
only the old interface.
Ideally, everyone would switch directly to SkFontMgr and use one of the
newer calls, but there is currently no path for current users to get
there. This updates all the internals to use SkFontStyle, after
switching these over the higher level APIs can be switched.
The Chromium follow on patch can be seen at https://crrev.com/1877673002
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1873923002
TBR=reed
This doesn't really change API, just modernizes it.
Review URL: https://codereview.chromium.org/1873923002
Diffstat (limited to 'src/ports/SkFontMgr_win_dw.cpp')
-rw-r--r-- | src/ports/SkFontMgr_win_dw.cpp | 38 |
1 files changed, 22 insertions, 16 deletions
diff --git a/src/ports/SkFontMgr_win_dw.cpp b/src/ports/SkFontMgr_win_dw.cpp index 11afec3b53..788bb5edd3 100644 --- a/src/ports/SkFontMgr_win_dw.cpp +++ b/src/ports/SkFontMgr_win_dw.cpp @@ -284,18 +284,21 @@ protected: void onGetFamilyName(int index, SkString* familyName) const override; SkFontStyleSet* onCreateStyleSet(int index) const override; SkFontStyleSet* onMatchFamily(const char familyName[]) const override; - virtual SkTypeface* onMatchFamilyStyle(const char familyName[], - const SkFontStyle& fontstyle) const override; - virtual SkTypeface* onMatchFamilyStyleCharacter(const char familyName[], const SkFontStyle&, - const char* bcp47[], int bcp47Count, - SkUnichar character) const override; - virtual SkTypeface* onMatchFaceStyle(const SkTypeface* familyMember, - const SkFontStyle& fontstyle) const override; + SkTypeface* onMatchFamilyStyle(const char familyName[], + const SkFontStyle& fontstyle) const override; + SkTypeface* onMatchFamilyStyleCharacter(const char familyName[], const SkFontStyle&, + const char* bcp47[], int bcp47Count, + SkUnichar character) const override; + SkTypeface* onMatchFaceStyle(const SkTypeface* familyMember, + const SkFontStyle& fontstyle) const override; SkTypeface* onCreateFromStream(SkStreamAsset* stream, int ttcIndex) const override; SkTypeface* onCreateFromData(SkData* data, int ttcIndex) const override; SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const override; - virtual SkTypeface* onLegacyCreateTypeface(const char familyName[], - unsigned styleBits) const override; +#ifdef SK_VERY_LEGACY_CREATE_TYPEFACE + SkTypeface* onLegacyCreateTypeface(const char familyName[], unsigned styleBits) const override; +#else + SkTypeface* onLegacyCreateTypeface(const char familyName[], SkFontStyle) const override; +#endif private: HRESULT getByFamilyName(const WCHAR familyName[], IDWriteFontFamily** fontFamily) const; @@ -950,8 +953,14 @@ HRESULT SkFontMgr_DirectWrite::getDefaultFontFamily(IDWriteFontFamily** fontFami return S_OK; } +#ifdef SK_VERY_LEGACY_CREATE_TYPEFACE SkTypeface* SkFontMgr_DirectWrite::onLegacyCreateTypeface(const char familyName[], unsigned styleBits) const { + SkFontStyle style = SkFontStyle::FromOldStyle(styleBits); +#else +SkTypeface* SkFontMgr_DirectWrite::onLegacyCreateTypeface(const char familyName[], + SkFontStyle style) const { +#endif SkTScopedComPtr<IDWriteFontFamily> fontFamily; if (familyName) { SkSMallocWCHAR wideFamilyName; @@ -972,13 +981,10 @@ SkTypeface* SkFontMgr_DirectWrite::onLegacyCreateTypeface(const char familyName[ } SkTScopedComPtr<IDWriteFont> font; - DWRITE_FONT_WEIGHT weight = (styleBits & SkTypeface::kBold) - ? DWRITE_FONT_WEIGHT_BOLD - : DWRITE_FONT_WEIGHT_NORMAL; - DWRITE_FONT_STRETCH stretch = DWRITE_FONT_STRETCH_NORMAL; - DWRITE_FONT_STYLE italic = (styleBits & SkTypeface::kItalic) - ? DWRITE_FONT_STYLE_ITALIC - : DWRITE_FONT_STYLE_NORMAL; + DWRITE_FONT_WEIGHT weight = (DWRITE_FONT_WEIGHT)style.weight(); + DWRITE_FONT_STRETCH stretch = (DWRITE_FONT_STRETCH)style.width(); + DWRITE_FONT_STYLE italic = style.isItalic() ? DWRITE_FONT_STYLE_ITALIC + : DWRITE_FONT_STYLE_NORMAL; HRNM(fontFamily->GetFirstMatchingFont(weight, stretch, italic, &font), "Could not get matching font."); |