| 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 "SkDataTable.h" | 8 #include "SkDataTable.h" | 
| 9 #include "SkFixed.h" | 9 #include "SkFixed.h" | 
| 10 #include "SkFontDescriptor.h" | 10 #include "SkFontDescriptor.h" | 
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 189     FcLangSetAdd(strongLangSet, (const FcChar8*)"nomatchlang"); | 189     FcLangSetAdd(strongLangSet, (const FcChar8*)"nomatchlang"); | 
| 190     SkAutoFcPattern strong(FcPatternDuplicate(minimal)); | 190     SkAutoFcPattern strong(FcPatternDuplicate(minimal)); | 
| 191     FcPatternAddLangSet(strong, FC_LANG, strongLangSet); | 191     FcPatternAddLangSet(strong, FC_LANG, strongLangSet); | 
| 192 | 192 | 
| 193     SkAutoFcLangSet weakLangSet; | 193     SkAutoFcLangSet weakLangSet; | 
| 194     FcLangSetAdd(weakLangSet, (const FcChar8*)"matchlang"); | 194     FcLangSetAdd(weakLangSet, (const FcChar8*)"matchlang"); | 
| 195     SkAutoFcPattern weak; | 195     SkAutoFcPattern weak; | 
| 196     FcPatternAddString(weak, object, (const FcChar8*)"nomatchstring"); | 196     FcPatternAddString(weak, object, (const FcChar8*)"nomatchstring"); | 
| 197     FcPatternAddLangSet(weak, FC_LANG, weakLangSet); | 197     FcPatternAddLangSet(weak, FC_LANG, weakLangSet); | 
| 198 | 198 | 
| 199     FcFontSetAdd(fontSet, strong.detach()); | 199     FcFontSetAdd(fontSet, strong.release()); | 
| 200     FcFontSetAdd(fontSet, weak.detach()); | 200     FcFontSetAdd(fontSet, weak.release()); | 
| 201 | 201 | 
| 202     // Add 'matchlang' to the copy of the pattern. | 202     // Add 'matchlang' to the copy of the pattern. | 
| 203     FcPatternAddLangSet(minimal, FC_LANG, weakLangSet); | 203     FcPatternAddLangSet(minimal, FC_LANG, weakLangSet); | 
| 204 | 204 | 
| 205     // Run a match against the copy of the pattern. | 205     // Run a match against the copy of the pattern. | 
| 206     // If the 'id' was weak, then we should match the pattern with 'matchlang'. | 206     // If the 'id' was weak, then we should match the pattern with 'matchlang'. | 
| 207     // If the 'id' was strong, then we should match the pattern with 'nomatchlan
     g'. | 207     // If the 'id' was strong, then we should match the pattern with 'nomatchlan
     g'. | 
| 208 | 208 | 
| 209     // Note that this config is only used for FcFontRenderPrepare, which we don'
     t even want. | 209     // Note that this config is only used for FcFontRenderPrepare, which we don'
     t even want. | 
| 210     // However, there appears to be no way to match/sort without it. | 210     // However, there appears to be no way to match/sort without it. | 
| (...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 718             } | 718             } | 
| 719 | 719 | 
| 720             for (int fontIndex = 0; fontIndex < allFonts->nfont; ++fontIndex) { | 720             for (int fontIndex = 0; fontIndex < allFonts->nfont; ++fontIndex) { | 
| 721                 FcPattern* font = allFonts->fonts[fontIndex]; | 721                 FcPattern* font = allFonts->fonts[fontIndex]; | 
| 722                 if (FontAccessible(font) && FontFamilyNameMatches(font, matchPat
     tern)) { | 722                 if (FontAccessible(font) && FontFamilyNameMatches(font, matchPat
     tern)) { | 
| 723                     FcFontSetAdd(matches, FcFontRenderPrepare(fFC, pattern, font
     )); | 723                     FcFontSetAdd(matches, FcFontRenderPrepare(fFC, pattern, font
     )); | 
| 724                 } | 724                 } | 
| 725             } | 725             } | 
| 726         } | 726         } | 
| 727 | 727 | 
| 728         return new StyleSet(this, matches.detach()); | 728         return new StyleSet(this, matches.release()); | 
| 729     } | 729     } | 
| 730 | 730 | 
| 731     virtual SkTypeface* onMatchFamilyStyle(const char familyName[], | 731     virtual SkTypeface* onMatchFamilyStyle(const char familyName[], | 
| 732                                            const SkFontStyle& style) const overr
     ide | 732                                            const SkFontStyle& style) const overr
     ide | 
| 733     { | 733     { | 
| 734         FCLocker lock; | 734         FCLocker lock; | 
| 735 | 735 | 
| 736         SkAutoFcPattern pattern; | 736         SkAutoFcPattern pattern; | 
| 737         FcPatternAddString(pattern, FC_FAMILY, (FcChar8*)familyName); | 737         FcPatternAddString(pattern, FC_FAMILY, (FcChar8*)familyName); | 
| 738         fcpattern_from_skfontstyle(style, pattern); | 738         fcpattern_from_skfontstyle(style, pattern); | 
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 823         if (length <= 0 || (1u << 30) < length) { | 823         if (length <= 0 || (1u << 30) < length) { | 
| 824             return nullptr; | 824             return nullptr; | 
| 825         } | 825         } | 
| 826 | 826 | 
| 827         SkFontStyle style; | 827         SkFontStyle style; | 
| 828         bool isFixedWidth = false; | 828         bool isFixedWidth = false; | 
| 829         if (!fScanner.scanFont(stream, ttcIndex, nullptr, &style, &isFixedWidth,
      nullptr)) { | 829         if (!fScanner.scanFont(stream, ttcIndex, nullptr, &style, &isFixedWidth,
      nullptr)) { | 
| 830             return nullptr; | 830             return nullptr; | 
| 831         } | 831         } | 
| 832 | 832 | 
| 833         return new SkTypeface_stream(new SkFontData(stream.detach(), ttcIndex, n
     ullptr, 0), style, | 833         return new SkTypeface_stream(new SkFontData(stream.release(), ttcIndex, 
     nullptr, 0), style, | 
| 834                                      isFixedWidth); | 834                                      isFixedWidth); | 
| 835     } | 835     } | 
| 836 | 836 | 
| 837     SkTypeface* onCreateFromStream(SkStreamAsset* s, const FontParameters& param
     s) const override { | 837     SkTypeface* onCreateFromStream(SkStreamAsset* s, const FontParameters& param
     s) const override { | 
| 838         using Scanner = SkTypeface_FreeType::Scanner; | 838         using Scanner = SkTypeface_FreeType::Scanner; | 
| 839         SkAutoTDelete<SkStreamAsset> stream(s); | 839         SkAutoTDelete<SkStreamAsset> stream(s); | 
| 840         bool isFixedPitch; | 840         bool isFixedPitch; | 
| 841         SkFontStyle style; | 841         SkFontStyle style; | 
| 842         SkString name; | 842         SkString name; | 
| 843         Scanner::AxisDefinitions axisDefinitions; | 843         Scanner::AxisDefinitions axisDefinitions; | 
| 844         if (!fScanner.scanFont(stream, params.getCollectionIndex(), &name, &styl
     e, &isFixedPitch, | 844         if (!fScanner.scanFont(stream, params.getCollectionIndex(), &name, &styl
     e, &isFixedPitch, | 
| 845                                &axisDefinitions)) | 845                                &axisDefinitions)) | 
| 846         { | 846         { | 
| 847             return nullptr; | 847             return nullptr; | 
| 848         } | 848         } | 
| 849 | 849 | 
| 850         int paramAxisCount; | 850         int paramAxisCount; | 
| 851         const FontParameters::Axis* paramAxes = params.getAxes(¶mAxisCount); | 851         const FontParameters::Axis* paramAxes = params.getAxes(¶mAxisCount); | 
| 852         SkAutoSTMalloc<4, SkFixed> axisValues(axisDefinitions.count()); | 852         SkAutoSTMalloc<4, SkFixed> axisValues(axisDefinitions.count()); | 
| 853         Scanner::computeAxisValues(axisDefinitions, paramAxes, paramAxisCount, a
     xisValues, name); | 853         Scanner::computeAxisValues(axisDefinitions, paramAxes, paramAxisCount, a
     xisValues, name); | 
| 854 | 854 | 
| 855         SkFontData* data(new SkFontData(stream.detach(), params.getCollectionInd
     ex(), | 855         SkFontData* data(new SkFontData(stream.release(), params.getCollectionIn
     dex(), | 
| 856                                         axisValues.get(), axisDefinitions.count(
     ))); | 856                                         axisValues.get(), axisDefinitions.count(
     ))); | 
| 857         return new SkTypeface_stream(data, style, isFixedPitch); | 857         return new SkTypeface_stream(data, style, isFixedPitch); | 
| 858     } | 858     } | 
| 859 | 859 | 
| 860     SkTypeface* onCreateFromData(SkData* data, int ttcIndex) const override { | 860     SkTypeface* onCreateFromData(SkData* data, int ttcIndex) const override { | 
| 861         return this->createFromStream(new SkMemoryStream(data), ttcIndex); | 861         return this->createFromStream(new SkMemoryStream(data), ttcIndex); | 
| 862     } | 862     } | 
| 863 | 863 | 
| 864     SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const override
      { | 864     SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const override
      { | 
| 865         return this->createFromStream(SkStream::NewFromFile(path), ttcIndex); | 865         return this->createFromStream(SkStream::NewFromFile(path), ttcIndex); | 
| (...skipping 20 matching lines...) Expand all  Loading... | 
| 886                                                unsigned styleBits) const overrid
     e { | 886                                                unsigned styleBits) const overrid
     e { | 
| 887         bool bold = styleBits & SkTypeface::kBold; | 887         bool bold = styleBits & SkTypeface::kBold; | 
| 888         bool italic = styleBits & SkTypeface::kItalic; | 888         bool italic = styleBits & SkTypeface::kItalic; | 
| 889         SkFontStyle style = SkFontStyle(bold ? SkFontStyle::kBold_Weight | 889         SkFontStyle style = SkFontStyle(bold ? SkFontStyle::kBold_Weight | 
| 890                                              : SkFontStyle::kNormal_Weight, | 890                                              : SkFontStyle::kNormal_Weight, | 
| 891                                         SkFontStyle::kNormal_Width, | 891                                         SkFontStyle::kNormal_Width, | 
| 892                                         italic ? SkFontStyle::kItalic_Slant | 892                                         italic ? SkFontStyle::kItalic_Slant | 
| 893                                                : SkFontStyle::kUpright_Slant); | 893                                                : SkFontStyle::kUpright_Slant); | 
| 894         SkAutoTUnref<SkTypeface> typeface(this->matchFamilyStyle(familyName, sty
     le)); | 894         SkAutoTUnref<SkTypeface> typeface(this->matchFamilyStyle(familyName, sty
     le)); | 
| 895         if (typeface.get()) { | 895         if (typeface.get()) { | 
| 896             return typeface.detach(); | 896             return typeface.release(); | 
| 897         } | 897         } | 
| 898 | 898 | 
| 899         return this->matchFamilyStyle(nullptr, style); | 899         return this->matchFamilyStyle(nullptr, style); | 
| 900     } | 900     } | 
| 901 }; | 901 }; | 
| 902 | 902 | 
| 903 SK_API SkFontMgr* SkFontMgr_New_FontConfig(FcConfig* fc) { | 903 SK_API SkFontMgr* SkFontMgr_New_FontConfig(FcConfig* fc) { | 
| 904     return new SkFontMgr_fontconfig(fc); | 904     return new SkFontMgr_fontconfig(fc); | 
| 905 } | 905 } | 
| OLD | NEW | 
|---|