How to use FcFontMatch to find a font with a given character

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



I am currently implementing character replacement in McCLIM (if a character is missing from the font, pick a different font that has the character).

I observe that FcFontMatch returns some unexpected values.

The code is written in Lisp, but I wrote a simple C program that replicates the behaviour. The program simply attempts to find a font that contains the character U+063A.

When I use FcMatchPattern, the program returns DejaVuSans.ttf. If I use FcMatchFont instead, it returns FreeMono.ttf.

The interesting thing is that none of these fonts actually contains U+0x63A (checked by reading the "charset" value).

What is the correct way to perform this operation?

A second question: What is the actual difference between FcMatchPattern and FcMatchFont? The documentation isn't very clear on that.


The test program follows:

#include <fontconfig/fontconfig.h>
#include <stdio.h>
#include <stdlib.h>

void checkError(FcBool result) {
    if(!result) {
        fprintf(stderr, "error from fontconfig call\n");

int main(void)
    FcConfig *config = FcInitLoadConfigAndFonts();

    FcPattern *pattern = FcPatternCreate();

    FcCharSet *charset = FcCharSetCreate();
    checkError(FcCharSetAddChar(charset, 0x63a));
    checkError(FcPatternAddCharSet(pattern, "charset", charset));

    checkError(FcConfigSubstitute(config, pattern, FcMatchPattern));


    FcResult result;
    FcPattern *resultPattern = FcFontMatch(config, pattern, &result);
    if(result != FcResultMatch) {
        fprintf(stderr, "no fonts matched\n");
        return 1;

    FcValue value;
    FcResult patternResult = FcPatternGet(resultPattern, "file", 0, &value);
    if(patternResult != FcResultMatch) {
        fprintf(stderr, "file value not found\n");
        return 1;

    if(value.type != FcTypeString) {
        fprintf(stderr, "expected to find a string value\n");
        return 1;

    printf("font file = %s\n", value.u.s);


    return 0;

Fontconfig mailing list

[Index of Archives]     [Fedora Fonts]     [Fedora Users]     [Fedora Cloud]     [Kernel]     [Fedora Packaging]     [Fedora Desktop]     [PAM]     [Gimp Graphics Editor]     [Yosemite News]

  Powered by Linux