This source file includes following definitions.
- setSubpixelPositioning
- familyForChar
- renderStyleForStrike
#include "config.h"
#include "public/platform/linux/WebFontInfo.h"
#include "public/platform/linux/WebFontFamily.h"
#include "public/platform/linux/WebFontRenderStyle.h"
#include <fontconfig/fontconfig.h>
#include <string.h>
#include <unicode/utf16.h>
namespace blink {
static bool useSubpixelPositioning = false;
void WebFontInfo::setSubpixelPositioning(bool subpixelPositioning)
{
useSubpixelPositioning = subpixelPositioning;
}
void WebFontInfo::familyForChar(WebUChar32 c, const char* preferredLocale, WebFontFamily* family)
{
FcCharSet* cset = FcCharSetCreate();
FcCharSetAddChar(cset, c);
FcPattern* pattern = FcPatternCreate();
FcValue fcvalue;
fcvalue.type = FcTypeCharSet;
fcvalue.u.c = cset;
FcPatternAdd(pattern, FC_CHARSET, fcvalue, FcFalse);
fcvalue.type = FcTypeBool;
fcvalue.u.b = FcTrue;
FcPatternAdd(pattern, FC_SCALABLE, fcvalue, FcFalse);
if (preferredLocale) {
FcLangSet* langset = FcLangSetCreate();
FcLangSetAdd(langset, reinterpret_cast<const FcChar8 *>(preferredLocale));
FcPatternAddLangSet(pattern, FC_LANG, langset);
FcLangSetDestroy(langset);
}
FcConfigSubstitute(0, pattern, FcMatchPattern);
FcDefaultSubstitute(pattern);
FcResult result;
FcFontSet* fontSet = FcFontSort(0, pattern, 0, 0, &result);
FcPatternDestroy(pattern);
FcCharSetDestroy(cset);
if (!fontSet) {
family->name = WebCString();
family->isBold = false;
family->isItalic = false;
return;
}
for (int i = 0; i < fontSet->nfont; ++i) {
FcPattern* current = fontSet->fonts[i];
FcBool isScalable;
if (FcPatternGetBool(current, FC_SCALABLE, 0, &isScalable) != FcResultMatch
|| !isScalable)
continue;
FcChar8* cFilename;
if (FcPatternGetString(current, FC_FILE, 0, &cFilename) != FcResultMatch)
continue;
if (access(reinterpret_cast<char*>(cFilename), R_OK))
continue;
FcChar8* familyName;
if (FcPatternGetString(current, FC_FAMILY, 0, &familyName) == FcResultMatch) {
const char* charFamily = reinterpret_cast<char*>(familyName);
family->name = WebCString(charFamily, strlen(charFamily));
}
int weight;
if (FcPatternGetInteger(current, FC_WEIGHT, 0, &weight) == FcResultMatch)
family->isBold = weight >= FC_WEIGHT_BOLD;
else
family->isBold = false;
int slant;
if (FcPatternGetInteger(current, FC_SLANT, 0, &slant) == FcResultMatch)
family->isItalic = slant != FC_SLANT_ROMAN;
else
family->isItalic = false;
FcFontSetDestroy(fontSet);
return;
}
FcFontSetDestroy(fontSet);
}
void WebFontInfo::renderStyleForStrike(const char* family, int sizeAndStyle, WebFontRenderStyle* out)
{
bool isBold = sizeAndStyle & 1;
bool isItalic = sizeAndStyle & 2;
int pixelSize = sizeAndStyle >> 2;
FcPattern* pattern = FcPatternCreate();
FcValue fcvalue;
fcvalue.type = FcTypeString;
fcvalue.u.s = reinterpret_cast<const FcChar8 *>(family);
FcPatternAdd(pattern, FC_FAMILY, fcvalue, FcFalse);
fcvalue.type = FcTypeInteger;
fcvalue.u.i = isBold ? FC_WEIGHT_BOLD : FC_WEIGHT_NORMAL;
FcPatternAdd(pattern, FC_WEIGHT, fcvalue, FcFalse);
fcvalue.type = FcTypeInteger;
fcvalue.u.i = isItalic ? FC_SLANT_ITALIC : FC_SLANT_ROMAN;
FcPatternAdd(pattern, FC_SLANT, fcvalue, FcFalse);
fcvalue.type = FcTypeBool;
fcvalue.u.b = FcTrue;
FcPatternAdd(pattern, FC_SCALABLE, fcvalue, FcFalse);
fcvalue.type = FcTypeDouble;
fcvalue.u.d = pixelSize;
FcPatternAdd(pattern, FC_SIZE, fcvalue, FcFalse);
FcConfigSubstitute(0, pattern, FcMatchPattern);
FcDefaultSubstitute(pattern);
FcResult result;
FcPattern* match = FcFontMatch(0, pattern, &result);
FcPatternDestroy(pattern);
out->setDefaults();
if (!match)
return;
FcBool b;
int i;
if (FcPatternGetBool(match, FC_ANTIALIAS, 0, &b) == FcResultMatch)
out->useAntiAlias = b;
if (FcPatternGetBool(match, FC_EMBEDDED_BITMAP, 0, &b) == FcResultMatch)
out->useBitmaps = b;
if (FcPatternGetBool(match, FC_AUTOHINT, 0, &b) == FcResultMatch)
out->useAutoHint = b;
if (FcPatternGetBool(match, FC_HINTING, 0, &b) == FcResultMatch)
out->useHinting = b;
if (FcPatternGetInteger(match, FC_HINT_STYLE, 0, &i) == FcResultMatch)
out->hintStyle = i;
if (FcPatternGetInteger(match, FC_RGBA, 0, &i) == FcResultMatch) {
switch (i) {
case FC_RGBA_NONE:
out->useSubpixelRendering = 0;
break;
case FC_RGBA_RGB:
case FC_RGBA_BGR:
case FC_RGBA_VRGB:
case FC_RGBA_VBGR:
out->useSubpixelRendering = 1;
break;
default:
out->useSubpixelRendering = 2;
break;
}
}
out->useSubpixelPositioning = useSubpixelPositioning;
FcPatternDestroy(match);
}
}