Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1170)

Unified Diff: src/ports/SkFontConfigInterface_direct.cpp

Issue 2345053005: Sane use of FcPatternGetXXX in SkFontConfigInterface. (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/ports/SkFontConfigInterface_direct.cpp
diff --git a/src/ports/SkFontConfigInterface_direct.cpp b/src/ports/SkFontConfigInterface_direct.cpp
index cdd420c38c675b879683c5cd5227e06fe2b36766..c8bafc712a74f93dd2af4cb0f4d410bf3061b112 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;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698