From 4454f6b665f2f14d0107a0144be947d95a252f8e Mon Sep 17 00:00:00 2001 From: Matthias Kramm Date: Wed, 7 Apr 2010 17:49:52 -0700 Subject: [PATCH] reworked external font matching logic --- lib/pdf/GFXOutputDev.cc | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/lib/pdf/GFXOutputDev.cc b/lib/pdf/GFXOutputDev.cc index 1149088..635d10d 100644 --- a/lib/pdf/GFXOutputDev.cc +++ b/lib/pdf/GFXOutputDev.cc @@ -371,6 +371,11 @@ static char fc_ismatch(FcPattern*match, char*family, char*style) } #endif +static inline char islowercase(char c) +{ + return (c>='a' && c<='z'); +} + char* fontconfig_searchForFont(char*name) { #ifdef HAVE_FONTCONFIG @@ -468,20 +473,36 @@ char* fontconfig_searchForFont(char*name) } char*family = strdup(name); - char*style = 0; - char*dash = strchr(family, '-'); - if(!dash) dash = strchr(family, ','); + int len = strlen(family); + char*styles[] = {"Medium", "Regular", "Bold", "Italic", "Black", "Narrow"}; + char*style = 0; + int t; + for(t=0;tl+1 && !strcmp(family+len-l, styles[t]) && islowercase(family[len-l-1])) { + style = styles[t]; + family[len-l]=0; + break; + } + } + if(!style) { + char*dash = strchr(family, '-'); + if(!dash) dash = strchr(family, ','); + if(dash) { + *dash = 0; + style = dash+1; + } + } FcPattern*pattern = 0; - if(dash) { - *dash = 0; - style = dash+1; + if(style) { msg(" FontConfig: Looking for font %s (family=%s style=%s)", name, family, style); pattern = FcPatternBuild(NULL, FC_OUTLINE, FcTypeBool, FcTrue, FC_SCALABLE, FcTypeBool, FcTrue, FC_FAMILY, FcTypeString, family, FC_STYLE, FcTypeString, style, NULL); } else { msg(" FontConfig: Looking for font %s (family=%s)", name, family); pattern = FcPatternBuild(NULL, FC_OUTLINE, FcTypeBool, FcTrue, FC_SCALABLE, FcTypeBool, FcTrue, FC_FAMILY, FcTypeString, family, NULL); } + pattern = FcPatternBuild(NULL, FC_OUTLINE, FcTypeBool, FcTrue, FC_SCALABLE, FcTypeBool, FcTrue, FC_FAMILY, FcTypeString, family, NULL); FcResult result; FcConfigSubstitute(0, pattern, FcMatchPattern); -- 1.7.10.4