aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/ports/SkFontConfigInterface_direct.cpp
diff options
context:
space:
mode:
authorGravatar bungeman <bungeman@google.com>2016-09-16 13:19:49 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-09-16 13:19:49 -0700
commit875b8f6d35510523b0267e9a78217a91b2484698 (patch)
treef4ec3f37b78c9d68841e4fa5d1baa687d069dcc2 /src/ports/SkFontConfigInterface_direct.cpp
parente7904f3979e2e8b80b5d77165291e649ff1278dd (diff)
Sane use of FcPatternGetXXX in SkFontConfigInterface.
This renames get_name to get_string to better reflect what it does, uses get_int where appropriate, and removes the no longer used code that uses FcPatternGetBool. GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2345053005 Review-Url: https://codereview.chromium.org/2345053005
Diffstat (limited to 'src/ports/SkFontConfigInterface_direct.cpp')
-rw-r--r--src/ports/SkFontConfigInterface_direct.cpp34
1 files changed, 10 insertions, 24 deletions
diff --git a/src/ports/SkFontConfigInterface_direct.cpp b/src/ports/SkFontConfigInterface_direct.cpp
index cdd420c38c..c8bafc712a 100644
--- a/src/ports/SkFontConfigInterface_direct.cpp
+++ b/src/ports/SkFontConfigInterface_direct.cpp
@@ -161,11 +161,9 @@ static void fontconfiginterface_unittest() {
///////////////////////////////////////////////////////////////////////////////
// Returns the string from the pattern, or nullptr
-static const char* get_name(FcPattern* pattern, const char field[],
- int index = 0) {
+static const char* get_string(FcPattern* pattern, const char field[], int index = 0) {
const char* name;
- if (FcPatternGetString(pattern, field, index,
- (FcChar8**)&name) != FcResultMatch) {
+ if (FcPatternGetString(pattern, field, index, (FcChar8**)&name) != FcResultMatch) {
name = nullptr;
}
return name;
@@ -520,16 +518,8 @@ bool SkFontConfigInterfaceDirect::isAccessible(const char* filename) {
}
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
- || !is_scalable) {
- return false;
- }
-#endif
-
#ifdef SK_FONT_CONFIG_INTERFACE_ONLY_ALLOW_SFNT_FONTS
- const char* font_format = get_name(pattern, FC_FONTFORMAT);
+ const char* font_format = get_string(pattern, FC_FONTFORMAT);
if (font_format
&& strcmp(font_format, kFontFormatTrueType) != 0
&& strcmp(font_format, kFontFormatCFF) != 0)
@@ -539,7 +529,7 @@ bool SkFontConfigInterfaceDirect::isValidPattern(FcPattern* pattern) {
#endif
// fontconfig can also return fonts which are unreadable
- const char* c_filename = get_name(pattern, FC_FILE);
+ const char* c_filename = get_string(pattern, FC_FILE);
if (!c_filename) {
return false;
}
@@ -564,7 +554,7 @@ FcPattern* SkFontConfigInterfaceDirect::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 = get_string(match, FC_FAMILY, id);
if (!post_match_family)
break;
acceptable_substitute =
@@ -644,7 +634,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 = get_string(pattern, FC_FAMILY);
if (!post_config_family) {
// we can just continue with an empty name, e.g. default font
post_config_family = "";
@@ -668,23 +658,19 @@ 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 = get_string(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 = get_string(match, FC_FILE);
if (!c_filename) {
FcFontSetDestroy(font_set);
return false;
}
- int face_index;
- if (FcPatternGetInteger(match, FC_INDEX, 0, &face_index) != FcResultMatch) {
- FcFontSetDestroy(font_set);
- return false;
- }
+ int face_index = get_int(match, FC_INDEX, 0);
FcFontSetDestroy(font_set);
@@ -742,7 +728,7 @@ sk_sp<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 = get_string(match, FC_FAMILY);
if (famName && !find_name(names, famName)) {
*names.append() = famName;
*sizes.append() = strlen(famName) + 1;