本文整理汇总了C++中FcConfigSubstitute函数的典型用法代码示例。如果您正苦于以下问题:C++ FcConfigSubstitute函数的具体用法?C++ FcConfigSubstitute怎么用?C++ FcConfigSubstitute使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了FcConfigSubstitute函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: XftConfigSubstitute
Bool
XftConfigSubstitute (XftPattern *p)
{
FcConfigSubstitute (0, p, FcMatchPattern);
FcConfigSubstitute (0, p, FcMatchFont);
return True;
}
示例2: FcPatternCreate
QStringList QFontconfigDatabase::fallbacksForFamily(const QString family, const QFont::Style &style, const QFont::StyleHint &styleHint, const QUnicodeTables::Script &script) const
{
QStringList fallbackFamilies;
FcPattern *pattern = FcPatternCreate();
if (!pattern)
return fallbackFamilies;
FcValue value;
value.type = FcTypeString;
QByteArray cs = family.toUtf8();
value.u.s = (const FcChar8 *)cs.data();
FcPatternAdd(pattern,FC_FAMILY,value,true);
int slant_value = FC_SLANT_ROMAN;
if (style == QFont::StyleItalic)
slant_value = FC_SLANT_ITALIC;
else if (style == QFont::StyleOblique)
slant_value = FC_SLANT_OBLIQUE;
FcPatternAddInteger(pattern, FC_SLANT, slant_value);
if (script != QUnicodeTables::Common && *specialLanguages[script] != '\0') {
Q_ASSERT(script < QUnicodeTables::ScriptCount);
FcLangSet *ls = FcLangSetCreate();
FcLangSetAdd(ls, (const FcChar8*)specialLanguages[script]);
FcPatternAddLangSet(pattern, FC_LANG, ls);
FcLangSetDestroy(ls);
}
const char *stylehint = getFcFamilyForStyleHint(styleHint);
if (stylehint) {
value.u.s = (const FcChar8 *)stylehint;
FcPatternAddWeak(pattern, FC_FAMILY, value, FcTrue);
}
FcConfigSubstitute(0, pattern, FcMatchPattern);
FcConfigSubstitute(0, pattern, FcMatchFont);
FcResult result = FcResultMatch;
FcFontSet *fontSet = FcFontSort(0,pattern,FcFalse,0,&result);
if (fontSet && result == FcResultMatch)
{
for (int i = 0; i < fontSet->nfont; i++) {
FcChar8 *value = 0;
if (FcPatternGetString(fontSet->fonts[i], FC_FAMILY, 0, &value) != FcResultMatch)
continue;
// capitalize(value);
QString familyName = QString::fromUtf8((const char *)value);
if (!fallbackFamilies.contains(familyName,Qt::CaseInsensitive)) {
fallbackFamilies << familyName;
}
}
}
// qDebug() << "fallbackFamilies for:" << family << fallbackFamilies;
return fallbackFamilies;
}
示例3: FindDefaultFont
std::string FindDefaultFont()
{
std::string answer("/usr/share/fonts/liberation/LiberationSans-Regular.ttf");
FcFontSet *fs;
FcPattern *pat;
FcResult result;
if (!FcInit())
{
return answer;
}
pat = FcNameParse((FcChar8 *)"LiberationSans-Regular.ttf");
FcConfigSubstitute(0, pat, FcMatchPattern);
FcDefaultSubstitute(pat);
fs = FcFontSetCreate();
FcPattern *match;
match = FcFontMatch(0, pat, &result);
if (match)
{
FcChar8 *file;
if (FcPatternGetString(match, FC_FILE, 0, &file) == FcResultMatch)
{
answer = (const char *)file;
}
FcPatternDestroy(match);
}
FcPatternDestroy(pat);
FcFini();
return answer;
}
示例4: fcinfo_name_parse
FcPattern *fcinfo_get_font(const FcChar8 *request)
{
FcPattern *pattern, *match;
FcResult r;
FcChar8 *string;
int integer;
double double_num;
pattern = fcinfo_name_parse((FcChar8 *) request);
if (FcPatternGetString(pattern, FC_FAMILY, 0, &string)
!= FcResultMatch)
FcPatternAddString(pattern, FC_FAMILY, (FcChar8 *)"sans-serif");
if (FcPatternGetDouble(pattern, FC_PIXEL_SIZE, 0, &double_num)
!= FcResultMatch)
FcPatternAddDouble(pattern, FC_PIXEL_SIZE, 12.0);
if (FcPatternGetInteger(pattern, FC_WEIGHT, 0, &integer)
!= FcResultMatch)
FcPatternAddInteger(pattern, FC_WEIGHT, FC_WEIGHT_REGULAR);
if (FcPatternGetInteger(pattern, FC_SLANT, 0, &integer)
!= FcResultMatch)
FcPatternAddInteger(pattern, FC_SLANT, FC_SLANT_ROMAN);
if (FcPatternGetInteger(pattern, FC_WIDTH, 0, &integer)
!= FcResultMatch)
FcPatternAddInteger(pattern, FC_WIDTH, FC_WIDTH_NORMAL);
FcConfigSubstitute(NULL, pattern, FcMatchPattern);
FcDefaultSubstitute(pattern);
match = FcFontMatch(0, pattern, &r);
assert(r == FcResultMatch);
FcPatternDestroy(pattern);
return match;
}
示例5: linuxFontPathByName
static string linuxFontPathByName(string fontname){
string filename;
FcPattern * pattern = FcNameParse((const FcChar8*)fontname.c_str());
FcBool ret = FcConfigSubstitute(0,pattern,FcMatchPattern);
if(!ret){
ofLogError() << "linuxFontPathByName(): couldn't find font file or system font with name \"" << fontname << "\"";
return "";
}
FcDefaultSubstitute(pattern);
FcResult result;
FcPattern * fontMatch=NULL;
fontMatch = FcFontMatch(0,pattern,&result);
if(!fontMatch){
ofLogError() << "linuxFontPathByName(): couldn't match font file or system font with name \"" << fontname << "\"";
return "";
}
FcChar8 *file;
if (FcPatternGetString (fontMatch, FC_FILE, 0, &file) == FcResultMatch){
filename = (const char*)file;
}else{
ofLogError() << "linuxFontPathByName(): couldn't find font match for \"" << fontname << "\"";
return "";
}
return filename;
}
示例6: claro_ft2_load_font
claro_font_t * claro_ft2_load_font(claro_font_backend_t * backend, claro_font_pattern_t * pattern, const char * lang_id)
{
claro_ft2_backend * ft2_backend = (claro_ft2_backend *)backend;
FcPattern * real_pattern = NULL, * test_pattern;
int res;
claro_font_t * font;
g_return_val_if_fail(ft2_backend != NULL, NULL);
g_return_val_if_fail(pattern != NULL, NULL);
// lang_id can be unspecified
test_pattern = (FcPattern *)pattern->native;
if(lang_id)
FcPatternAddString (test_pattern, FC_LANG, lang_id);
g_return_val_if_fail(FcConfigSubstitute(ft2_backend->config, test_pattern, FcMatchPattern), NULL);
FcDefaultSubstitute(test_pattern);
//TODO this sets res to "134524017" wtf?
real_pattern = FcFontMatch(ft2_backend->config, test_pattern, NULL);
if(res != FcResultMatch)
{
printf("%s: res = %d\n", __FUNCTION__, res);
FcPatternDestroy(real_pattern);
return NULL;
}
font = _claro_ft2_make_font(real_pattern);
return font;
}
示例7: sui_font_fromfc
bool sui_font_fromfc(sui_font *font, sui_library *l, char **error, FcPattern *pattern)
{
FcResult res;
FcConfig *config = FcConfigGetCurrent();
if (!FcConfigSubstitute(config, pattern, FcMatchFont)) {
*error = sui_aprintf("FcConfigSubstitute: Allocation failure");
return false;
}
FcDefaultSubstitute(pattern);
FcPattern *match = FcFontMatch(config, pattern, &res);
if (res != FcResultMatch) {
*error = sui_aprintf("FcFontMatch: %s", sui_result_name(res));
return false;
}
FcChar8 *file;
int index;
res = FcPatternGetString(match, FC_FILE, 0, &file);
if (res != FcResultMatch) {
*error = sui_aprintf("FcPatternGetString FC_FILE: %s", sui_result_name(res));
return false;
}
res = FcPatternGetInteger(match, FC_INDEX, 0, &index);
if (res != FcResultMatch) {
*error = sui_aprintf("FcPatternGetInteger FC_INDEX: %s", sui_result_name(res));
return false;
}
FT_Error fterr;
if ((fterr = FT_New_Face(l->library, (const char*)file, index, &font->face))) {
*error = sui_aprintf("FT_New_Face: Error code %i", fterr);
return false;
}
return font_fromfont(font, l, error, font->face);
}
示例8: font_manager_match_description
// ----------------------------------------- font_manager_match_description ---
char *
font_manager_match_description( font_manager_t * self,
const char * family,
const float size,
const int bold,
const int italic )
{
// Use of fontconfig is disabled by default.
#if 1
return 0;
#else
# if defined _WIN32 || defined _WIN64
fprintf( stderr, "\"font_manager_match_description\" not implemented for windows.\n" );
return 0;
# endif
char *filename = 0;
int weight = FC_WEIGHT_REGULAR;
int slant = FC_SLANT_ROMAN;
if ( bold )
{
weight = FC_WEIGHT_BOLD;
}
if( italic )
{
slant = FC_SLANT_ITALIC;
}
FcInit();
FcPattern *pattern = FcPatternCreate();
FcPatternAddDouble( pattern, FC_SIZE, size );
FcPatternAddInteger( pattern, FC_WEIGHT, weight );
FcPatternAddInteger( pattern, FC_SLANT, slant );
FcPatternAddString( pattern, FC_FAMILY, (FcChar8*) family );
FcConfigSubstitute( 0, pattern, FcMatchPattern );
FcDefaultSubstitute( pattern );
FcResult result;
FcPattern *match = FcFontMatch( 0, pattern, &result );
FcPatternDestroy( pattern );
if ( !match )
{
fprintf( stderr, "fontconfig error: could not match family '%s'", family );
return 0;
}
else
{
FcValue value;
FcResult result = FcPatternGet( match, FC_FILE, 0, &value );
if ( result )
{
fprintf( stderr, "fontconfig error: could not match family '%s'", family );
}
else
{
filename = strdup( (char *)(value.u.s) );
}
}
FcPatternDestroy( match );
return filename;
#endif
}
示例9: decltype
/**
* Match and create font from given fontconfig pattern
*/
decltype(auto) make_font(cairo_t* cairo, string&& fontname, double offset, double dpi_x, double dpi_y) {
static bool fc_init{false};
if (!fc_init && !(fc_init = FcInit())) {
throw application_error("Could not load fontconfig");
} else if (FT_Init_FreeType(&g_ftlib) != FT_Err_Ok) {
throw application_error("Could not load FreeType");
}
static auto fc_cleanup = scope_util::make_exit_handler([] {
FT_Done_FreeType(g_ftlib);
FcFini();
});
auto pattern = FcNameParse((FcChar8*)fontname.c_str());
FcDefaultSubstitute(pattern);
FcConfigSubstitute(nullptr, pattern, FcMatchPattern);
FcResult result;
FcPattern* match = FcFontMatch(nullptr, pattern, &result);
FcPatternDestroy(pattern);
if (match == nullptr) {
throw application_error("Could not load font \"" + fontname + "\"");
}
#ifdef DEBUG_FONTCONFIG
FcPatternPrint(match);
#endif
return make_shared<font_fc>(cairo, match, offset, dpi_x, dpi_y);
}
示例10: initfonts
static void initfonts(void)
{
FcResult result;
FcPattern *pat = FcPatternCreate();
FcPatternAddString(pat, FC_FAMILY, (uint8_t*)"Roboto");
FcConfigSubstitute(0, pat, FcMatchPattern);
FcDefaultSubstitute(pat);
fs = FcFontSort(NULL, pat, 0, &charset, &result);
FcPatternDestroy(pat);
#define F(x) (x * SCALE / 2.0)
font[FONT_TEXT][0] = XftFontOpen(display, screen, XFT_FAMILY, XftTypeString, "Roboto", XFT_PIXEL_SIZE, XftTypeDouble, F(12.0), NULL);
font[FONT_TITLE][0] = XftFontOpen(display, screen, XFT_FAMILY, XftTypeString, "Roboto", XFT_PIXEL_SIZE, XftTypeDouble, F(12.0), XFT_WEIGHT, XftTypeInteger, FC_WEIGHT_BOLD, NULL);
font[FONT_SELF_NAME][0] = XftFontOpen(display, screen, XFT_FAMILY, XftTypeString, "Roboto", XFT_PIXEL_SIZE, XftTypeDouble, F(14.0), XFT_WEIGHT, XftTypeInteger, FC_WEIGHT_BOLD, NULL);
font[FONT_STATUS][0] = XftFontOpen(display, screen, XFT_FAMILY, XftTypeString, "Roboto", XFT_PIXEL_SIZE, XftTypeDouble, F(11.0), NULL);
font[FONT_LIST_NAME][0] = XftFontOpen(display, screen, XFT_FAMILY, XftTypeString, "Roboto", XFT_PIXEL_SIZE, XftTypeDouble, F(12.0), NULL);
font[FONT_MSG][0] = XftFontOpen(display, screen, XFT_FAMILY, XftTypeString, "Roboto", XFT_PIXEL_SIZE, XftTypeDouble, F(11.0), XFT_WEIGHT, XftTypeInteger, FC_WEIGHT_LIGHT, NULL);
font[FONT_MSG_NAME][0] = XftFontOpen(display, screen, XFT_FAMILY, XftTypeString, "Roboto", XFT_PIXEL_SIZE, XftTypeDouble, F(10.0), XFT_WEIGHT, XftTypeInteger, FC_WEIGHT_LIGHT, NULL);
font[FONT_MISC][0] = XftFontOpen(display, screen, XFT_FAMILY, XftTypeString, "Roboto", XFT_PIXEL_SIZE, XftTypeDouble, F(10.0), NULL);
font[FONT_MSG_LINK][0] = font[FONT_MSG][0];
#undef F
}
示例11: get_font_path
// Thanks to http://stackoverflow.com/a/14634033/1447751
const std::string get_font_path(const std::string &name) {
std::string path;
const FcChar8 *fcname = reinterpret_cast<const FcChar8 *>(name.c_str());
FcConfig *config = FcInitLoadConfigAndFonts();
// configure the search pattern,
// assume "name" is a std::string with the desired font name in it
FcPattern *pat = FcNameParse(fcname);
FcConfigSubstitute(config, pat, FcMatchPattern);
FcDefaultSubstitute(pat);
FcResult result;
// find the font
FcPattern *font = FcFontMatch(config, pat, &result);
if (font) {
FcChar8 *fcpath = NULL;
FcChar8 *fcfamily = NULL;
if (FcPatternGetString(font, FC_FAMILY, 0, &fcfamily) == FcResultMatch &&
(name.empty() || !FcStrCmpIgnoreCase(fcname, fcfamily)) // Empty name means searching for default font, otherwise make
// sure the returned font is exactly what we searched for
&&
FcPatternGetString(font, FC_FILE, 0, &fcpath) == FcResultMatch)
path = std::string(reinterpret_cast<char *>(fcpath));
FcPatternDestroy(font);
}
FcPatternDestroy(pat);
return path;
}
示例12: pattern_font_sort
CAMLprim value pattern_font_sort(value plist, value trim)
{
CAMLparam0();
CAMLlocal2(res, nres);
FcPattern *pat;
FcFontSet *match;
FcResult result;
int i;
pat = FcPattern_val(plist);
FcConfigSubstitute(NULL, pat, FcMatchPattern);
FcDefaultSubstitute(pat);
match = FcFontSort(NULL, pat, Bool_val(trim) ? FcTrue : FcFalse, NULL, &result);
/* Reconstruire la belle liste */
res = Val_int(0); /* empty list */
for(i = match->nfont; i >= 0; i--) {
nres = caml_alloc(2, 0);
Store_field(nres, 0, caml_copy_pattern(match->fonts[i]));
Store_field(nres, 1, res);
res = nres;
}
FcFontSetDestroy(match);
FcPatternDestroy(pat);
CAMLreturn(res);
}
示例13: Py_Config_substitute
static PyObject*
Py_Config_substitute(Py_Config *self, PyObject *args, PyObject *kwds)
{
PyObject *py_pattern;
static char *kwlist[] = {"pattern", NULL};
if (!PyArg_ParseTupleAndKeywords(
args, kwds, "O:substitute", kwlist,
&py_pattern)) {
return NULL;
}
if (Py_TYPE(py_pattern) != &Py_Pattern_Type) {
PyErr_SetString(PyExc_TypeError, "pattern must be Pattern object");
return NULL;
}
if (!FcConfigSubstitute(self->x, ((Py_Pattern *)py_pattern)->x, FcMatchFont)) {
PyErr_SetString(PyExc_MemoryError, "Out of memory");
return NULL;
}
Py_RETURN_NONE;
}
示例14: adoptRef
FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& family)
{
// The CSS font matching algorithm (http://www.w3.org/TR/css3-fonts/#font-matching-algorithm)
// says that we must find an exact match for font family, slant (italic or oblique can be used)
// and font weight (we only match bold/non-bold here).
RefPtr<FcPattern> pattern = adoptRef(FcPatternCreate());
String familyNameString(getFamilyNameStringFromFontDescriptionAndFamily(fontDescription, family));
if (!FcPatternAddString(pattern.get(), FC_FAMILY, reinterpret_cast<const FcChar8*>(familyNameString.utf8().data())))
return 0;
bool italic = fontDescription.italic();
if (!FcPatternAddInteger(pattern.get(), FC_SLANT, italic ? FC_SLANT_ITALIC : FC_SLANT_ROMAN))
return 0;
if (!FcPatternAddInteger(pattern.get(), FC_WEIGHT, fontWeightToFontconfigWeight(fontDescription.weight())))
return 0;
if (!FcPatternAddDouble(pattern.get(), FC_PIXEL_SIZE, fontDescription.computedPixelSize()))
return 0;
// The strategy is originally from Skia (src/ports/SkFontHost_fontconfig.cpp):
// Allow Fontconfig to do pre-match substitution. Unless we are accessing a "fallback"
// family like "sans," this is the only time we allow Fontconfig to substitute one
// family name for another (i.e. if the fonts are aliased to each other).
FcConfigSubstitute(0, pattern.get(), FcMatchPattern);
FcDefaultSubstitute(pattern.get());
FcChar8* fontConfigFamilyNameAfterConfiguration;
FcPatternGetString(pattern.get(), FC_FAMILY, 0, &fontConfigFamilyNameAfterConfiguration);
String familyNameAfterConfiguration = String::fromUTF8(reinterpret_cast<char*>(fontConfigFamilyNameAfterConfiguration));
FcResult fontConfigResult;
RefPtr<FcPattern> resultPattern = adoptRef(FcFontMatch(0, pattern.get(), &fontConfigResult));
if (!resultPattern) // No match.
return 0;
FcChar8* fontConfigFamilyNameAfterMatching;
FcPatternGetString(resultPattern.get(), FC_FAMILY, 0, &fontConfigFamilyNameAfterMatching);
String familyNameAfterMatching = String::fromUTF8(reinterpret_cast<char*>(fontConfigFamilyNameAfterMatching));
// If Fontconfig gave use a different font family than the one we requested, we should ignore it
// and allow WebCore to give us the next font on the CSS fallback list. The only exception is if
// this family name is a commonly used generic family.
if (!equalIgnoringCase(familyNameAfterConfiguration, familyNameAfterMatching)
&& !(equalIgnoringCase(familyNameString, "sans") || equalIgnoringCase(familyNameString, "sans-serif")
|| equalIgnoringCase(familyNameString, "serif") || equalIgnoringCase(familyNameString, "monospace")
|| equalIgnoringCase(familyNameString, "fantasy") || equalIgnoringCase(familyNameString, "cursive")))
return 0;
// Verify that this font has an encoding compatible with Fontconfig. Fontconfig currently
// supports three encodings in FcFreeTypeCharIndex: Unicode, Symbol and AppleRoman.
// If this font doesn't have one of these three encodings, don't select it.
FontPlatformData* platformData = new FontPlatformData(resultPattern.get(), fontDescription);
if (!platformData->hasCompatibleCharmap()) {
delete platformData;
return 0;
}
return platformData;
}
示例15: pdf_loadbuiltinfont
fz_error *
pdf_loadbuiltinfont(pdf_font *font, char *basefont)
{
fz_error *error;
FcResult fcerr;
int fterr;
FcPattern *searchpat;
FcPattern *matchpat;
FT_Face face;
char *pattern;
char *file;
int index;
int i;
error = initfontlibs();
if (error)
return error;
pattern = basefont;
for (i = 0; i < 14; i++)
if (!strcmp(basefont, basenames[i]))
pattern = basepatterns[i];
pdf_logfont("load builtin %s\n", pattern);
fcerr = FcResultMatch;
searchpat = FcNameParse(pattern);
FcDefaultSubstitute(searchpat);
FcConfigSubstitute(fclib, searchpat, FcMatchPattern);
matchpat = FcFontMatch(fclib, searchpat, &fcerr);
if (fcerr != FcResultMatch)
return fz_throw("fontconfig could not find font %s", pattern);
fcerr = FcPatternGetString(matchpat, FC_FILE, 0, (FcChar8**)&file);
if (fcerr != FcResultMatch)
return fz_throw("fontconfig could not find font %s", pattern);
index = 0;
fcerr = FcPatternGetInteger(matchpat, FC_INDEX, 0, &index);
pdf_logfont("load font file %s %d\n", file, index);
fterr = FT_New_Face(ftlib, file, index, &face);
if (fterr)
return fz_throw("freetype could not load font file '%s': %s", file, pdf_fterrorstring(fterr));
FcPatternDestroy(matchpat);
FcPatternDestroy(searchpat);
font->ftface = face;
return nil;
}