[Fontconfig] editing FcConfig in code
Jean Abou Samra
jean at abou-samra.fr
Wed Apr 12 06:33:08 UTC 2023
Le mercredi 12 avril 2023 à 01:12 +0100, Idriss Fekir a écrit :
> Hi,
>
> Some fonts aren't matched by fontconfig correctly e.g: the Amber Whiskey
> family has 4 faces Regular, Aged, Full Color, Shadow.
> `fc-match "Amber Whiskey"` outputs "Aged" instead of "Regular", And
> since Pango relies on fontconfig for that, it also exhibits the same
> behavior (e.g: Inkscape an gimp, both rely on pango, would pick the
> "Aged" variant). This could be worked around with a rule:
>
> ```
> <match target="pattern">
> <test name="family">
> <string>Amber Whiskey</string>
> </test>
> <edit name="style">
> <string>Regular</string>
> </edit>
> </match>
> ```
>
> My question is how can i do that but in code (in C), that is
> how can i check what fc-match would output, then if the output is wrong
> add a rule like the following to the FcConfig?
>
> I'm open to suggestions if there are better ways.
>
> I did read the docs but i couldn't figure out how.
>
> The man page for FcFontMatch says that it should only be called after
> FcConfigSubstitute and FcDefaultSubstitute have been called for
> the pattern, i don't understand what that means exactly.
>
> Thanks a lot.
I'm not a Fontconfig developer, but I will try to answer your question anyway.
As far as I understand, the intent of Fontconfig is to make font configuration shared and static. So, if the font in question is installed through a package manager, the package should normally also include a conf file that makes Fontconfig handle the font correctly.
If you're not taking it from a package, I think you could try
```
FcConfigParseAndLoad(NULL, (FcChar8 *) "your-config-file.conf", FcTrue);
```
or
```
FcConfigParseAndLoadFromMemory(NULL, (FcChar8 *) "<the string of Fontconfig XML code that you would put in a file>", FcTrue);
```
Best,
Jean
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/fontconfig/attachments/20230412/312d8824/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 228 bytes
Desc: This is a digitally signed message part
URL: <https://lists.freedesktop.org/archives/fontconfig/attachments/20230412/312d8824/attachment.sig>
More information about the Fontconfig
mailing list