Index: src/ports/SkFontConfigInterfaceDirect.cpp |
diff --git a/src/ports/SkFontConfigInterface_direct.cpp b/src/ports/SkFontConfigInterfaceDirect.cpp |
similarity index 90% |
copy from src/ports/SkFontConfigInterface_direct.cpp |
copy to src/ports/SkFontConfigInterfaceDirect.cpp |
index 8a8e4a1b538dfcfa270ed40b24d9f60adb3be023..57751cdddc442fde2407acf3e5486101ae3faaf4 100644 |
--- a/src/ports/SkFontConfigInterface_direct.cpp |
+++ b/src/ports/SkFontConfigInterfaceDirect.cpp |
@@ -7,9 +7,9 @@ |
/* migrated from chrome/src/skia/ext/SkFontHost_fontconfig_direct.cpp */ |
+#include "SkFontConfigInterfaceDirect.h" |
#include "SkBuffer.h" |
#include "SkDataTable.h" |
-#include "SkFontConfigInterface.h" |
#include "SkFontStyle.h" |
#include "SkMutex.h" |
#include "SkStream.h" |
@@ -107,42 +107,11 @@ static void fontconfiginterface_unittest() { |
} |
#endif |
-class SkFontConfigInterfaceDirect : public SkFontConfigInterface { |
-public: |
- SkFontConfigInterfaceDirect(); |
- virtual ~SkFontConfigInterfaceDirect(); |
- |
- virtual bool matchFamilyName(const char familyName[], |
- SkTypeface::Style requested, |
- FontIdentity* outFontIdentifier, |
- SkString* outFamilyName, |
- SkTypeface::Style* outStyle) override; |
- SkStreamAsset* openStream(const FontIdentity&) override; |
- |
- // new APIs |
- SkDataTable* getFamilyNames() override; |
- virtual bool matchFamilySet(const char inFamilyName[], |
- SkString* outFamilyName, |
- SkTArray<FontIdentity>*) override; |
- |
-private: |
- SkMutex mutex_; |
-}; |
- |
-SkFontConfigInterface* SkFontConfigInterface::GetSingletonDirectInterface(SkBaseMutex* mutex) { |
- SkAutoMutexAcquire ac(mutex); |
- static SkFontConfigInterfaceDirect* singleton = nullptr; |
- if (singleton == nullptr) { |
- singleton = new SkFontConfigInterfaceDirect; |
- } |
- return singleton; |
-} |
- |
/////////////////////////////////////////////////////////////////////////////// |
// Returns the string from the pattern, or nullptr |
-static const char* get_name(FcPattern* pattern, const char field[], |
- int index = 0) { |
+const char* SkFontConfigInterfaceDirect::GetName(FcPattern* pattern, const char field[], |
+ int index) { |
const char* name; |
if (FcPatternGetString(pattern, field, index, |
(FcChar8**)&name) != FcResultMatch) { |
@@ -334,7 +303,57 @@ bool IsFallbackFontAllowed(const SkString& family) { |
strcasecmp(family_cstr, "monospace") == 0; |
} |
-static bool valid_pattern(FcPattern* pattern) { |
+// Retrieves |is_bold|, |is_italic| and |font_family| properties from |font|. |
+SkTypeface::Style GetFontStyle(FcPattern* font) { |
+ int resulting_bold; |
+ if (FcPatternGetInteger(font, FC_WEIGHT, 0, &resulting_bold)) |
+ resulting_bold = FC_WEIGHT_NORMAL; |
+ |
+ int resulting_italic; |
+ if (FcPatternGetInteger(font, FC_SLANT, 0, &resulting_italic)) |
+ resulting_italic = FC_SLANT_ROMAN; |
+ |
+ // If we ask for an italic font, fontconfig might take a roman font and set |
+ // the undocumented property FC_MATRIX to a skew matrix. It'll then say |
+ // that the font is italic or oblique. So, if we see a matrix, we don't |
+ // believe that it's italic. |
+ FcValue matrix; |
+ const bool have_matrix = FcPatternGet(font, FC_MATRIX, 0, &matrix) == 0; |
+ |
+ // If we ask for an italic font, fontconfig might take a roman font and set |
+ // FC_EMBOLDEN. |
+ FcValue embolden; |
+ const bool have_embolden = FcPatternGet(font, FC_EMBOLDEN, 0, &embolden) == 0; |
+ |
+ int styleBits = 0; |
+ if (resulting_bold > FC_WEIGHT_MEDIUM && !have_embolden) { |
+ styleBits |= SkTypeface::kBold; |
+ } |
+ if (resulting_italic > FC_SLANT_ROMAN && !have_matrix) { |
+ styleBits |= SkTypeface::kItalic; |
+ } |
+ |
+ return (SkTypeface::Style)styleBits; |
+} |
+ |
+} // anonymous namespace |
+ |
+/////////////////////////////////////////////////////////////////////////////// |
+ |
+#define kMaxFontFamilyLength 2048 |
+ |
+SkFontConfigInterfaceDirect::SkFontConfigInterfaceDirect() { |
+ SkAutoMutexAcquire ac(mutex_); |
+ |
+ FcInit(); |
+ |
+ SkDEBUGCODE(fontconfiginterface_unittest();) |
+} |
+ |
+SkFontConfigInterfaceDirect::~SkFontConfigInterfaceDirect() { |
+} |
+ |
+bool SkFontConfigInterfaceDirect::isValidPattern(FcPattern* pattern) { |
#ifdef SK_FONT_CONFIG_ONLY_ALLOW_SCALABLE_FONTS |
FcBool is_scalable; |
if (FcPatternGetBool(pattern, FC_SCALABLE, 0, &is_scalable) != FcResultMatch |
@@ -344,26 +363,27 @@ static bool valid_pattern(FcPattern* pattern) { |
#endif |
// fontconfig can also return fonts which are unreadable |
- const char* c_filename = get_name(pattern, FC_FILE); |
+ const char* c_filename = GetName(pattern, FC_FILE); |
if (!c_filename) { |
return false; |
} |
if (access(c_filename, R_OK) != 0) { |
return false; |
} |
+ |
return true; |
} |
// Find matching font from |font_set| for the given font family. |
-FcPattern* MatchFont(FcFontSet* font_set, |
- const char* post_config_family, |
- const SkString& family) { |
+FcPattern* SkFontConfigInterfaceDirect::MatchFont(FcFontSet* font_set, |
+ const char* post_config_family, |
+ const SkString& family) { |
// Older versions of fontconfig have a bug where they cannot select |
// only scalable fonts so we have to manually filter the results. |
FcPattern* match = nullptr; |
for (int i = 0; i < font_set->nfont; ++i) { |
FcPattern* current = font_set->fonts[i]; |
- if (valid_pattern(current)) { |
+ if (this->isValidPattern(current)) { |
match = current; |
break; |
} |
@@ -372,7 +392,7 @@ FcPattern* MatchFont(FcFontSet* font_set, |
if (match && !IsFallbackFontAllowed(family)) { |
bool acceptable_substitute = false; |
for (int id = 0; id < 255; ++id) { |
- const char* post_match_family = get_name(match, FC_FAMILY, id); |
+ const char* post_match_family = GetName(match, FC_FAMILY, id); |
if (!post_match_family) |
break; |
acceptable_substitute = |
@@ -394,56 +414,6 @@ FcPattern* MatchFont(FcFontSet* font_set, |
return match; |
} |
-// Retrieves |is_bold|, |is_italic| and |font_family| properties from |font|. |
-SkTypeface::Style GetFontStyle(FcPattern* font) { |
- int resulting_bold; |
- if (FcPatternGetInteger(font, FC_WEIGHT, 0, &resulting_bold)) |
- resulting_bold = FC_WEIGHT_NORMAL; |
- |
- int resulting_italic; |
- if (FcPatternGetInteger(font, FC_SLANT, 0, &resulting_italic)) |
- resulting_italic = FC_SLANT_ROMAN; |
- |
- // If we ask for an italic font, fontconfig might take a roman font and set |
- // the undocumented property FC_MATRIX to a skew matrix. It'll then say |
- // that the font is italic or oblique. So, if we see a matrix, we don't |
- // believe that it's italic. |
- FcValue matrix; |
- const bool have_matrix = FcPatternGet(font, FC_MATRIX, 0, &matrix) == 0; |
- |
- // If we ask for an italic font, fontconfig might take a roman font and set |
- // FC_EMBOLDEN. |
- FcValue embolden; |
- const bool have_embolden = FcPatternGet(font, FC_EMBOLDEN, 0, &embolden) == 0; |
- |
- int styleBits = 0; |
- if (resulting_bold > FC_WEIGHT_MEDIUM && !have_embolden) { |
- styleBits |= SkTypeface::kBold; |
- } |
- if (resulting_italic > FC_SLANT_ROMAN && !have_matrix) { |
- styleBits |= SkTypeface::kItalic; |
- } |
- |
- return (SkTypeface::Style)styleBits; |
-} |
- |
-} // anonymous namespace |
- |
-/////////////////////////////////////////////////////////////////////////////// |
- |
-#define kMaxFontFamilyLength 2048 |
- |
-SkFontConfigInterfaceDirect::SkFontConfigInterfaceDirect() { |
- SkAutoMutexAcquire ac(mutex_); |
- |
- FcInit(); |
- |
- SkDEBUGCODE(fontconfiginterface_unittest();) |
-} |
- |
-SkFontConfigInterfaceDirect::~SkFontConfigInterfaceDirect() { |
-} |
- |
bool SkFontConfigInterfaceDirect::matchFamilyName(const char familyName[], |
SkTypeface::Style style, |
FontIdentity* outIdentity, |
@@ -501,7 +471,7 @@ bool SkFontConfigInterfaceDirect::matchFamilyName(const char familyName[], |
// |
// However, we special-case fallback fonts; see IsFallbackFontAllowed(). |
- const char* post_config_family = get_name(pattern, FC_FAMILY); |
+ const char* post_config_family = GetName(pattern, FC_FAMILY); |
if (!post_config_family) { |
// we can just continue with an empty name, e.g. default font |
post_config_family = ""; |
@@ -514,7 +484,7 @@ bool SkFontConfigInterfaceDirect::matchFamilyName(const char familyName[], |
return false; |
} |
- FcPattern* match = MatchFont(font_set, post_config_family, familyStr); |
+ FcPattern* match = this->MatchFont(font_set, post_config_family, familyStr); |
if (!match) { |
FcPatternDestroy(pattern); |
FcFontSetDestroy(font_set); |
@@ -525,13 +495,13 @@ bool SkFontConfigInterfaceDirect::matchFamilyName(const char familyName[], |
// From here out we just extract our results from 'match' |
- post_config_family = get_name(match, FC_FAMILY); |
+ post_config_family = GetName(match, FC_FAMILY); |
if (!post_config_family) { |
FcFontSetDestroy(font_set); |
return false; |
} |
- const char* c_filename = get_name(match, FC_FILE); |
+ const char* c_filename = GetName(match, FC_FILE); |
if (!c_filename) { |
FcFontSetDestroy(font_set); |
return false; |
@@ -599,7 +569,7 @@ SkDataTable* SkFontConfigInterfaceDirect::getFamilyNames() { |
SkTDArray<size_t> sizes; |
for (int i = 0; i < fs->nfont; ++i) { |
FcPattern* match = fs->fonts[i]; |
- const char* famName = get_name(match, FC_FAMILY); |
+ const char* famName = GetName(match, FC_FAMILY); |
if (famName && !find_name(names, famName)) { |
*names.append() = famName; |
*sizes.append() = strlen(famName) + 1; |
@@ -662,7 +632,7 @@ bool SkFontConfigInterfaceDirect::matchFamilySet(const char inFamilyName[], |
// |
// However, we special-case fallback fonts; see IsFallbackFontAllowed(). |
- const char* post_config_family = get_name(pattern, FC_FAMILY); |
+ const char* post_config_family = GetName(pattern, FC_FAMILY); |
FcResult result; |
FcFontSet* font_set = FcFontSort(0, pattern, 0, 0, &result); |
@@ -671,7 +641,7 @@ bool SkFontConfigInterfaceDirect::matchFamilySet(const char inFamilyName[], |
return false; |
} |
- FcPattern* match = MatchFont(font_set, post_config_family, familyStr); |
+ FcPattern* match = this->MatchFont(font_set, post_config_family, familyStr); |
if (!match) { |
FcPatternDestroy(pattern); |
FcFontSetDestroy(font_set); |
@@ -716,7 +686,7 @@ bool SkFontConfigInterfaceDirect::matchFamilySet(const char inFamilyName[], |
//////////////////// |
int count; |
- FcPattern** match = MatchFont(font_set, post_config_family, &count); |
+ FcPattern** match = this->MatchFont(font_set, post_config_family, &count); |
if (!match) { |
FcPatternDestroy(pattern); |
FcFontSetDestroy(font_set); |
@@ -727,7 +697,7 @@ bool SkFontConfigInterfaceDirect::matchFamilySet(const char inFamilyName[], |
SkTDArray<FcPattern*> trimmedMatches; |
for (int i = 0; i < count; ++i) { |
- const char* justName = find_just_name(get_name(match[i], FC_FILE)); |
+ const char* justName = find_just_name(GetName(match[i], FC_FILE)); |
if (!is_lower(*justName)) { |
*trimmedMatches.append() = match[i]; |
} |