| 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 266 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   277         } |   277         } | 
|   278 #endif |   278 #endif | 
|   279         memcpy(fLocaleName.get(), localeName, localeNameLength * sizeof(WCHAR)); |   279         memcpy(fLocaleName.get(), localeName, localeNameLength * sizeof(WCHAR)); | 
|   280     } |   280     } | 
|   281  |   281  | 
|   282 protected: |   282 protected: | 
|   283     int onCountFamilies() const override; |   283     int onCountFamilies() const override; | 
|   284     void onGetFamilyName(int index, SkString* familyName) const override; |   284     void onGetFamilyName(int index, SkString* familyName) const override; | 
|   285     SkFontStyleSet* onCreateStyleSet(int index) const override; |   285     SkFontStyleSet* onCreateStyleSet(int index) const override; | 
|   286     SkFontStyleSet* onMatchFamily(const char familyName[]) const override; |   286     SkFontStyleSet* onMatchFamily(const char familyName[]) const override; | 
|   287     virtual SkTypeface* onMatchFamilyStyle(const char familyName[], |   287     SkTypeface* onMatchFamilyStyle(const char familyName[], | 
|   288                                            const SkFontStyle& fontstyle) const o
      verride; |   288                                    const SkFontStyle& fontstyle) const override; | 
|   289     virtual SkTypeface* onMatchFamilyStyleCharacter(const char familyName[], con
      st SkFontStyle&, |   289     SkTypeface* onMatchFamilyStyleCharacter(const char familyName[], const SkFon
      tStyle&, | 
|   290                                                     const char* bcp47[], int bcp
      47Count, |   290                                             const char* bcp47[], int bcp47Count, | 
|   291                                                     SkUnichar character) const o
      verride; |   291                                             SkUnichar character) const override; | 
|   292     virtual SkTypeface* onMatchFaceStyle(const SkTypeface* familyMember, |   292     SkTypeface* onMatchFaceStyle(const SkTypeface* familyMember, | 
|   293                                          const SkFontStyle& fontstyle) const ove
      rride; |   293                                  const SkFontStyle& fontstyle) const override; | 
|   294     SkTypeface* onCreateFromStream(SkStreamAsset* stream, int ttcIndex) const ov
      erride; |   294     SkTypeface* onCreateFromStream(SkStreamAsset* stream, int ttcIndex) const ov
      erride; | 
|   295     SkTypeface* onCreateFromData(SkData* data, int ttcIndex) const override; |   295     SkTypeface* onCreateFromData(SkData* data, int ttcIndex) const override; | 
|   296     SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const override
      ; |   296     SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const override
      ; | 
|   297     virtual SkTypeface* onLegacyCreateTypeface(const char familyName[], |   297 #ifdef SK_VERY_LEGACY_CREATE_TYPEFACE | 
|   298                                                unsigned styleBits) const overrid
      e; |   298     SkTypeface* onLegacyCreateTypeface(const char familyName[], unsigned styleBi
      ts) const override; | 
 |   299 #else | 
 |   300     SkTypeface* onLegacyCreateTypeface(const char familyName[], SkFontStyle) con
      st override; | 
 |   301 #endif | 
|   299  |   302  | 
|   300 private: |   303 private: | 
|   301     HRESULT getByFamilyName(const WCHAR familyName[], IDWriteFontFamily** fontFa
      mily) const; |   304     HRESULT getByFamilyName(const WCHAR familyName[], IDWriteFontFamily** fontFa
      mily) const; | 
|   302     HRESULT getDefaultFontFamily(IDWriteFontFamily** fontFamily) const; |   305     HRESULT getDefaultFontFamily(IDWriteFontFamily** fontFamily) const; | 
|   303  |   306  | 
|   304     /** Creates a typeface using a typeface cache. */ |   307     /** Creates a typeface using a typeface cache. */ | 
|   305     SkTypeface* createTypefaceFromDWriteFont(IDWriteFontFace* fontFace, |   308     SkTypeface* createTypefaceFromDWriteFont(IDWriteFontFace* fontFace, | 
|   306                                              IDWriteFont* font, |   309                                              IDWriteFont* font, | 
|   307                                              IDWriteFontFamily* fontFamily) cons
      t; |   310                                              IDWriteFontFamily* fontFamily) cons
      t; | 
|   308  |   311  | 
| (...skipping 634 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   943                                    sizeof(metrics), |   946                                    sizeof(metrics), | 
|   944                                    &metrics, |   947                                    &metrics, | 
|   945                                    0)) { |   948                                    0)) { | 
|   946         return E_UNEXPECTED; |   949         return E_UNEXPECTED; | 
|   947     } |   950     } | 
|   948     HRM(this->getByFamilyName(metrics.lfMessageFont.lfFaceName, fontFamily), |   951     HRM(this->getByFamilyName(metrics.lfMessageFont.lfFaceName, fontFamily), | 
|   949         "Could not create DWrite font family from LOGFONT."); |   952         "Could not create DWrite font family from LOGFONT."); | 
|   950     return S_OK; |   953     return S_OK; | 
|   951 } |   954 } | 
|   952  |   955  | 
 |   956 #ifdef SK_VERY_LEGACY_CREATE_TYPEFACE | 
|   953 SkTypeface* SkFontMgr_DirectWrite::onLegacyCreateTypeface(const char familyName[
      ], |   957 SkTypeface* SkFontMgr_DirectWrite::onLegacyCreateTypeface(const char familyName[
      ], | 
|   954                                                           unsigned styleBits) co
      nst { |   958                                                           unsigned styleBits) co
      nst { | 
 |   959     SkFontStyle style = SkFontStyle::FromOldStyle(styleBits); | 
 |   960 #else | 
 |   961 SkTypeface* SkFontMgr_DirectWrite::onLegacyCreateTypeface(const char familyName[
      ], | 
 |   962                                                           SkFontStyle style) con
      st { | 
 |   963 #endif | 
|   955     SkTScopedComPtr<IDWriteFontFamily> fontFamily; |   964     SkTScopedComPtr<IDWriteFontFamily> fontFamily; | 
|   956     if (familyName) { |   965     if (familyName) { | 
|   957         SkSMallocWCHAR wideFamilyName; |   966         SkSMallocWCHAR wideFamilyName; | 
|   958         if (SUCCEEDED(sk_cstring_to_wchar(familyName, &wideFamilyName))) { |   967         if (SUCCEEDED(sk_cstring_to_wchar(familyName, &wideFamilyName))) { | 
|   959             this->getByFamilyName(wideFamilyName, &fontFamily); |   968             this->getByFamilyName(wideFamilyName, &fontFamily); | 
|   960         } |   969         } | 
|   961     } |   970     } | 
|   962  |   971  | 
|   963     if (nullptr == fontFamily.get()) { |   972     if (nullptr == fontFamily.get()) { | 
|   964         // No family with given name, try default. |   973         // No family with given name, try default. | 
|   965         HRNM(this->getDefaultFontFamily(&fontFamily), "Could not get default fon
      t family."); |   974         HRNM(this->getDefaultFontFamily(&fontFamily), "Could not get default fon
      t family."); | 
|   966     } |   975     } | 
|   967  |   976  | 
|   968     if (nullptr == fontFamily.get()) { |   977     if (nullptr == fontFamily.get()) { | 
|   969         // Could not obtain the default font. |   978         // Could not obtain the default font. | 
|   970         HRNM(fFontCollection->GetFontFamily(0, &fontFamily), |   979         HRNM(fFontCollection->GetFontFamily(0, &fontFamily), | 
|   971              "Could not get default-default font family."); |   980              "Could not get default-default font family."); | 
|   972     } |   981     } | 
|   973  |   982  | 
|   974     SkTScopedComPtr<IDWriteFont> font; |   983     SkTScopedComPtr<IDWriteFont> font; | 
|   975     DWRITE_FONT_WEIGHT weight = (styleBits & SkTypeface::kBold) |   984     DWRITE_FONT_WEIGHT weight = (DWRITE_FONT_WEIGHT)style.weight(); | 
|   976                               ? DWRITE_FONT_WEIGHT_BOLD |   985     DWRITE_FONT_STRETCH stretch = (DWRITE_FONT_STRETCH)style.width(); | 
|   977                               : DWRITE_FONT_WEIGHT_NORMAL; |   986     DWRITE_FONT_STYLE italic = style.isItalic() ? DWRITE_FONT_STYLE_ITALIC | 
|   978     DWRITE_FONT_STRETCH stretch = DWRITE_FONT_STRETCH_NORMAL; |   987                                                 : DWRITE_FONT_STYLE_NORMAL; | 
|   979     DWRITE_FONT_STYLE italic = (styleBits & SkTypeface::kItalic) |  | 
|   980                              ? DWRITE_FONT_STYLE_ITALIC |  | 
|   981                              : DWRITE_FONT_STYLE_NORMAL; |  | 
|   982     HRNM(fontFamily->GetFirstMatchingFont(weight, stretch, italic, &font), |   988     HRNM(fontFamily->GetFirstMatchingFont(weight, stretch, italic, &font), | 
|   983          "Could not get matching font."); |   989          "Could not get matching font."); | 
|   984  |   990  | 
|   985     SkTScopedComPtr<IDWriteFontFace> fontFace; |   991     SkTScopedComPtr<IDWriteFontFace> fontFace; | 
|   986     HRNM(font->CreateFontFace(&fontFace), "Could not create font face."); |   992     HRNM(font->CreateFontFace(&fontFace), "Could not create font face."); | 
|   987  |   993  | 
|   988     return this->createTypefaceFromDWriteFont(fontFace.get(), font.get(), fontFa
      mily.get()); |   994     return this->createTypefaceFromDWriteFont(fontFace.get(), font.get(), fontFa
      mily.get()); | 
|   989 } |   995 } | 
|   990  |   996  | 
|   991 /////////////////////////////////////////////////////////////////////////////// |   997 /////////////////////////////////////////////////////////////////////////////// | 
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1104  |  1110  | 
|  1105 #include "SkFontMgr_indirect.h" |  1111 #include "SkFontMgr_indirect.h" | 
|  1106 SK_API SkFontMgr* SkFontMgr_New_DirectWriteRenderer(SkRemotableFontMgr* proxy) { |  1112 SK_API SkFontMgr* SkFontMgr_New_DirectWriteRenderer(SkRemotableFontMgr* proxy) { | 
|  1107     SkAutoTUnref<SkFontMgr> impl(SkFontMgr_New_DirectWrite()); |  1113     SkAutoTUnref<SkFontMgr> impl(SkFontMgr_New_DirectWrite()); | 
|  1108     if (impl.get() == nullptr) { |  1114     if (impl.get() == nullptr) { | 
|  1109         return nullptr; |  1115         return nullptr; | 
|  1110     } |  1116     } | 
|  1111     return new SkFontMgr_Indirect(impl.get(), proxy); |  1117     return new SkFontMgr_Indirect(impl.get(), proxy); | 
|  1112 } |  1118 } | 
|  1113 #endif//defined(SK_BUILD_FOR_WIN32) |  1119 #endif//defined(SK_BUILD_FOR_WIN32) | 
| OLD | NEW |