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

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

 



Hi,

Exactly speaking, there are three types of matching pattern in
fontconfig though, trying to mention only two here in a question.
FcMatchPattern sets various information to evaluate what is better
and/or what's preferrable. if you don't have any for that, you won't
get any fonts. fc-pattern will demonstrates this behavior. just try to
run fc-pattern without any argument or any property you want. you'll
get empty result or what you set in the pattern.
FcFontMatch() will evaluates the best font against this result.
speaking more details, FcFontRenderprepare() will calls the sort of
FcConfigSubstitite() with FcMatchFont in FcFontMatch(), to evaluate
that pattern against fonts on the system and then returns best font.
So basically you don't need to worry about FcMatchFont unless you
yourself need to emulate something in fontconfig to match on fonts.

On Fri, Jun 29, 2018 at 7:12 PM, Elias Mårtenson <lokedhs@xxxxxxxxx> wrote:
> Hello,
>
> 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.
>
> Regards,
> Elias
>
> 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");
>         abort();
>     }
> }
>
> int main(void)
> {
>     FcConfig *config = FcInitLoadConfigAndFonts();
>
>     FcPattern *pattern = FcPatternCreate();
>
>     FcCharSet *charset = FcCharSetCreate();
>     checkError(FcCharSetAddChar(charset, 0x63a));
>     checkError(FcPatternAddCharSet(pattern, "charset", charset));
>     FcCharSetDestroy(charset);
>
>     checkError(FcConfigSubstitute(config, pattern, FcMatchPattern));
>
>     FcDefaultSubstitute(pattern);
>
>     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);
>
>     FcPatternDestroy(pattern);
>
>     return 0;
> }
>
>
> _______________________________________________
> Fontconfig mailing list
> Fontconfig@xxxxxxxxxxxxxxxxxxxxx
> https://lists.freedesktop.org/mailman/listinfo/fontconfig
>



-- 
Akira TAGOH
_______________________________________________
Fontconfig mailing list
Fontconfig@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/fontconfig




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

  Powered by Linux