Skip to content

compose: font APIs do not handle .ttc files correctly #715

@joebonrichie

Description

@joebonrichie

TrueType Collection (.ttc) files are a collection of .ttf (maybe also .otf?) files mushed together into one file. These files are common with CJK fonts.

Currently the compose font APIs only get the information from the first font contained within the collection.

Instead, they should iterate over the index within the file to get the information from all fonts.

Example C code

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

int main(int argc, char **argv) {
    if (argc != 2) {
        fprintf(stderr, "Usage: %s <font-file>\n", argv[0]);
        return 1;
    }

    const char *file = argv[1];
    FcConfig *config = FcInitLoadConfigAndFonts();
    int index = 0;
    FcPattern *pat = NULL;

    while ((pat = FcFreeTypeQuery((const FcChar8 *)file, index, NULL, NULL))) {
        FcChar8 *fullname;
        if (FcPatternGetString(pat, FC_FULLNAME, 0, &fullname) == FcResultMatch) {
            printf("Index %d: %s\n", index, fullname);
        } else {
            printf("Index %d: [no name found]\n", index);
        }

        FcPatternDestroy(pat);
        index++;
    }
    FcFini();
    return 0;
}

This then works with both normal font files as well ttc files

$ ./ttc-fontconfig-test tests/samples/compose/NotoSansCJK-Regular.ttc
Index 0: Noto Sans CJK JP
Index 1: Noto Sans CJK KR
Index 2: Noto Sans CJK SC
Index 3: Noto Sans CJK TC
Index 4: Noto Sans CJK HK
Index 5: Noto Sans Mono CJK JP
Index 6: Noto Sans Mono CJK KR
Index 7: Noto Sans Mono CJK SC
Index 8: Noto Sans Mono CJK TC
Index 9: Noto Sans Mono CJK HK
$ ./ttc-fontconfig-test tests/samples/compose/Raleway-Regular.ttf 
Index 0: Raleway Regular

But of course, the API usage will need to adjusted throughout the codebase to handle getting multiple results from one file.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions