Skip to content

Instantly share code, notes, and snippets.

@drott
Created August 12, 2014 11:35
Show Gist options
  • Save drott/990a8e628cda3a933e75 to your computer and use it in GitHub Desktop.
Save drott/990a8e628cda3a933e75 to your computer and use it in GitHub Desktop.
--- fam1.cpp 2014-08-12 14:23:59.000000000 +0300
+++ fam2.cpp 2014-08-12 14:23:40.000000000 +0300
@@ -1,4 +1,4 @@
-void WebFontInfo::familyForChar(WebUChar32 c, const char* preferredLocale, WebFontFamily* family)
+void WebFontInfo::fallbackFontForChar(WebUChar32 c, const char* preferredLocale, WebFallbackFont* fallbackFont)
{
FcCharSet* cset = FcCharSetCreate();
FcCharSetAddChar(cset, c);
@@ -29,9 +29,9 @@
FcCharSetDestroy(cset);
if (!fontSet) {
- family->name = WebCString();
- family->isBold = false;
- family->isItalic = false;
+ fallbackFont->name = WebCString();
+ fallbackFont->isBold = false;
+ fallbackFont->isItalic = false;
return;
}
+ fallbackFont->isItalic = false;
return;
}
// Older versions of fontconfig have a bug where they cannot select
@@ -52,25 +52,33 @@
if (access(reinterpret_cast<char*>(cFilename), R_OK))
continue;
+ const char* fontFilename = reinterpret_cast<char*>(cFilename);
+ fallbackFont->filename = WebCString(fontFilename, strlen(fontFilename));
+
+ // Index into font collection.
+ int ttcIndex;
+ if (FcPatternGetInteger(current, FC_INDEX, 0, &ttcIndex) != FcResultMatch && ttcIndex < 0)
+ continue;
+ fallbackFont->ttcIndex = ttcIndex;
+
FcChar8* familyName;
if (FcPatternGetString(current, FC_FAMILY, 0, &familyName) == FcResultMatch) {
const char* charFamily = reinterpret_cast<char*>(familyName);
- family->name = WebCString(charFamily, strlen(charFamily));
+ fallbackFont->name = WebCString(charFamily, strlen(charFamily));
}
int weight;
if (FcPatternGetInteger(current, FC_WEIGHT, 0, &weight) == FcResultMatch)
- family->isBold = weight >= FC_WEIGHT_BOLD;
+ fallbackFont->isBold = weight >= FC_WEIGHT_BOLD;
else
- family->isBold = false;
+ fallbackFont->isBold = false;
int slant;
if (FcPatternGetInteger(current, FC_SLANT, 0, &slant) == FcResultMatch)
- family->isItalic = slant != FC_SLANT_ROMAN;
+ fallbackFont->isItalic = slant != FC_SLANT_ROMAN;
else
- family->isItalic = false;
+ fallbackFont->isItalic = false;
FcFontSetDestroy(fontSet);
return;
}
FcFontSetDestroy(fontSet);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment