diff options
author | drott <drott@chromium.org> | 2016-08-26 10:08:45 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-08-26 10:08:45 -0700 |
commit | 358f93de3d16bd3fe5b0d043ea15b59ebc994e86 (patch) | |
tree | d9b8dd7c431ac069aeda9869eff8322a4f27b691 /src/ports/SkFontConfigInterface_direct.cpp | |
parent | 55713afb7a531bbb6a345a42b5a25ad709d8fd19 (diff) |
Restrict supported font formats in Chrome context
Chrome's complex text path uses HarfBuzz OpenType glyph lookup
functions. These do not support glyph lookup in Type 1 / Postscript
fonts and we do not wish to support those in Chrome any longer.
In order to avoid matching fonts against Type 1 fonts possible present
on Linux installations and exposed through fontconfig, this CL filters
those out in Skia's font matching code.
This change might not be desirable for all context in which Skia is
used, hence making it conditional on a Chrome context define.
BUG=skia:5685
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2280053002
Review-Url: https://codereview.chromium.org/2280053002
Diffstat (limited to 'src/ports/SkFontConfigInterface_direct.cpp')
-rw-r--r-- | src/ports/SkFontConfigInterface_direct.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/ports/SkFontConfigInterface_direct.cpp b/src/ports/SkFontConfigInterface_direct.cpp index 3455447246..8fe9898bc7 100644 --- a/src/ports/SkFontConfigInterface_direct.cpp +++ b/src/ports/SkFontConfigInterface_direct.cpp @@ -496,6 +496,10 @@ static void fcpattern_from_skfontstyle(SkFontStyle style, FcPattern* pattern) { /////////////////////////////////////////////////////////////////////////////// #define kMaxFontFamilyLength 2048 +#ifdef SK_FONT_CONFIG_INTERFACE_ONLY_ALLOW_SFNT_FONTS +const char* kFontFormatTrueType = "TrueType"; +const char* kFontFormatCFF = "CFF"; +#endif SkFontConfigInterfaceDirect::SkFontConfigInterfaceDirect() { FCLocker lock; @@ -524,6 +528,16 @@ bool SkFontConfigInterfaceDirect::isValidPattern(FcPattern* pattern) { } #endif +#ifdef SK_FONT_CONFIG_INTERFACE_ONLY_ALLOW_SFNT_FONTS + const char* font_format = get_name(pattern, FC_FONTFORMAT); + if (font_format + && strcmp(font_format, kFontFormatTrueType) != 0 + && strcmp(font_format, kFontFormatCFF) != 0) + { + return false; + } +#endif + // fontconfig can also return fonts which are unreadable const char* c_filename = get_name(pattern, FC_FILE); if (!c_filename) { @@ -593,6 +607,11 @@ bool SkFontConfigInterfaceDirect::matchFamilyName(const char familyName[], FcPatternAddBool(pattern, FC_SCALABLE, FcTrue); +#ifdef SK_FONT_CONFIG_INTERFACE_ONLY_ALLOW_SFNT_FONTS + FcPatternAddString(pattern, FC_FONTFORMAT, reinterpret_cast<const FcChar8*>(kFontFormatTrueType)); + FcPatternAddString(pattern, FC_FONTFORMAT, reinterpret_cast<const FcChar8*>(kFontFormatCFF)); +#endif + FcConfigSubstitute(nullptr, pattern, FcMatchPattern); FcDefaultSubstitute(pattern); |