X-Git-Url: https://git.wh0rd.org/?a=blobdiff_plain;f=src%2Ffcmatch.c;h=0abd42ac4f3cb86e069feb88b20b4d7a84829deb;hb=76845a40c58b092a9b1812830dc98b6f32e13da6;hp=49dd0ddae78771f6daf7be4c223adee9698671ad;hpb=a5a384c5ffb479e095092c2aaedd406f8785280a;p=fontconfig.git diff --git a/src/fcmatch.c b/src/fcmatch.c index 49dd0dd..0abd42a 100644 --- a/src/fcmatch.c +++ b/src/fcmatch.c @@ -13,9 +13,9 @@ * representations about the suitability of this software for any purpose. It * is provided "as is" without express or implied warranty. * - * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR @@ -184,7 +184,7 @@ typedef struct _FcMatcher { * each value, earlier values are more significant than * later values */ -static FcMatcher _FcMatchers [] = { +static const FcMatcher _FcMatchers [] = { { FC_FOUNDRY_OBJECT, FcCompareString, 0, 0 }, #define MATCH_FOUNDRY 0 #define MATCH_FOUNDRY_INDEX 0 @@ -459,12 +459,12 @@ FcFontRenderPrepare (FcConfig *config, return new; } -FcPattern * -FcFontSetMatch (FcConfig *config, - FcFontSet **sets, - int nsets, - FcPattern *p, - FcResult *result) +static FcPattern * +FcFontSetMatchInternal (FcConfig *config, + FcFontSet **sets, + int nsets, + FcPattern *p, + FcResult *result) { double score[NUM_MATCH_VALUES], bestscore[NUM_MATCH_VALUES]; int f; @@ -481,12 +481,6 @@ FcFontSetMatch (FcConfig *config, printf ("Match "); FcPatternPrint (p); } - if (!config) - { - config = FcConfigGetCurrent (); - if (!config) - return 0; - } for (set = 0; set < nsets; set++) { s = sets[set]; @@ -537,7 +531,29 @@ FcFontSetMatch (FcConfig *config, *result = FcResultNoMatch; return 0; } - return FcFontRenderPrepare (config, p, best); + return best; +} + +FcPattern * +FcFontSetMatch (FcConfig *config, + FcFontSet **sets, + int nsets, + FcPattern *p, + FcResult *result) +{ + FcPattern *best; + + if (!config) + { + config = FcConfigGetCurrent (); + if (!config) + return 0; + } + best = FcFontSetMatchInternal (config, sets, nsets, p, result); + if (best) + return FcFontRenderPrepare (config, p, best); + else + return NULL; } FcPattern * @@ -547,6 +563,7 @@ FcFontMatch (FcConfig *config, { FcFontSet *sets[2]; int nsets; + FcPattern *best; if (!config) { @@ -559,7 +576,12 @@ FcFontMatch (FcConfig *config, sets[nsets++] = config->fonts[FcSetSystem]; if (config->fonts[FcSetApplication]) sets[nsets++] = config->fonts[FcSetApplication]; - return FcFontSetMatch (config, sets, nsets, p, result); + + best = FcFontSetMatchInternal (config, sets, nsets, p, result); + if (best) + return FcFontRenderPrepare (config, p, best); + else + return NULL; } typedef struct _FcSortNode { @@ -584,38 +606,45 @@ FcSortCompare (const void *aa, const void *ab) } static FcBool -FcSortWalk (FcSortNode **n, int nnode, FcFontSet *fs, FcCharSet **cs, FcBool trim, FcBool build_cs) +FcSortWalk (FcSortNode **n, int nnode, FcFontSet *fs, FcCharSet **csp, FcBool trim) { - FcCharSet *ncs; - FcSortNode *node; + FcBool ret = FcFalse; + FcCharSet *cs; + + cs = 0; + if (trim || csp) + { + cs = FcCharSetCreate (); + if (cs == NULL) + goto bail; + } while (nnode--) { - node = *n++; + FcSortNode *node = *n++; + FcBool adds_chars = FcFalse; /* * Only fetch node charset if we'd need it */ - if (trim || build_cs) + if (cs) { + FcCharSet *ncs; + if (FcPatternGetCharSet (node->pattern, FC_CHARSET, 0, &ncs) != FcResultMatch) continue; + + if (!FcCharSetMerge (cs, ncs, &adds_chars)) + goto bail; } /* * If this font isn't a subset of the previous fonts, * add it to the list */ - if (!trim || !*cs || !FcCharSetIsSubset (ncs, *cs)) + if (!trim || adds_chars) { - if (trim || build_cs) - { - *cs = FcCharSetMerge (*cs, ncs); - if (*cs == NULL) - return FcFalse; - } - FcPatternReference (node->pattern); if (FcDebug () & FC_DBG_MATCHV) { @@ -625,11 +654,23 @@ FcSortWalk (FcSortNode **n, int nnode, FcFontSet *fs, FcCharSet **cs, FcBool tri if (!FcFontSetAdd (fs, node->pattern)) { FcPatternDestroy (node->pattern); - return FcFalse; + goto bail; } } } - return FcTrue; + if (csp) + { + *csp = cs; + cs = 0; + } + + ret = FcTrue; + +bail: + if (cs) + FcCharSetDestroy (cs); + + return ret; } void @@ -653,7 +694,6 @@ FcFontSetSort (FcConfig *config, FcSortNode **nodeps, **nodep; int nnodes; FcSortNode *new; - FcCharSet *cs; int set; int f; int i; @@ -781,19 +821,9 @@ FcFontSetSort (FcConfig *config, if (!ret) goto bail1; - cs = 0; - - if (!FcSortWalk (nodeps, nnodes, ret, &cs, trim, (csp!=0))) + if (!FcSortWalk (nodeps, nnodes, ret, csp, trim)) goto bail2; - if (csp) - *csp = cs; - else - { - if (cs) - FcCharSetDestroy (cs); - } - free (nodes); if (FcDebug() & FC_DBG_MATCH) @@ -804,8 +834,6 @@ FcFontSetSort (FcConfig *config, return ret; bail2: - if (cs) - FcCharSetDestroy (cs); FcFontSetDestroy (ret); bail1: free (nodes);