Details

[Home]

Issue of the Implementation # S0592

Brief

Unexpected behaviour of FcFontSort

Detailed Description

The description of the function FcFontSort states: "Returns the list of fonts sorted by closeness to p". So, if the font p is present among the set of the system fonts, this font should be in the beginning of the sorted list.

But in reality FcPatternEqual returns FcFalse if we compare the first element of the sorted list and the font p. The print of both fonts by the function FcPatternPrint shows that the fonts are similar but there are missed properties of the font p in the first font of the list.

Problem location(s) in the standard

Fontconfig Developers Reference, Version 2.4.2

Reproducing

  1. Get the system font p2 the most alike to the some pattern p1.
  2. Sort all the system fonts by closeness to the p2 gotten before.
  3. Compare p2 with the first element of the sorted list.

Example

    FcConfig        *fc;
    FcResult        *result;
    FcPattern       *p1, *p2;
    FcFontSet       *fs;
    
    if (!(fc = FcConfigGetCurrent ()))
    {
        printf ("Could not get current config\n");
    }
    if (!(p1 = FcPatternCreate ()))
    {
        printf ("Could not create the pattern\n");
    }
    FcConfigSubstitute (fc, p1, FcMatchPattern);
    FcDefaultSubstitute (p1);
    p2 = FcFontMatch (fc, p1, result);
    
    fs = FcFontSort (fc, p2, FcFalse, NULL, result);

    /*
     * Returns the list of fonts sorted by closeness to p
     *
     * The following condition should be true:
     * FcPatternEqual (p2, fs->fonts[0]) == FcTrue;
     */
    if (FcPatternEqual (p2, fs->fonts[0]) != FcTrue)
    {
        printf("[p1   ]---------------------\n");
        FcPatternPrint(p1);
        printf("[p2   ]---------------------\n");
        FcPatternPrint(p2);
        printf("[fs[0]]---------------------\n");
        FcPatternPrint(fs->fonts[0]);
    }

Component

fontconfig 2.2.3 or later

Accepted

freedesktop.org Bugzilla 13162

Status

Fixed in fontconfig 2.5.0

[Home]