Add namedinstance property

This change allows applications to detect if a font
is a variable font and a named-instance.
If they are, namedinstance property is set to true,
otherwise false.

Fixes https://gitlab.freedesktop.org/fontconfig/fontconfig/-/issues/362
This commit is contained in:
Akira TAGOH 2023-05-25 20:12:31 +09:00
parent 1751596768
commit f0612537cb
7 changed files with 82 additions and 11 deletions

View File

@ -215,6 +215,7 @@ convenience for the application's rendering mechanism.
fonthashint FC_FONT_HAS_HINT Bool Whether font has hinting
order FC_ORDER Int Order number of the font
desktop FC_DESKTOP_NAME String Current desktop name
namedinstance FC_NAMED_INSTANCE Bool Whether font is a named-instance
</programlisting>
</sect2>
</sect1>

View File

@ -147,6 +147,7 @@ variable Bool Wheter font is Variable Font
fonthashint Bool Whether the font has hinting
order Int Order number of the font
desktop String Current desktop name
namedinstance Bool Whether font is a named-instance
</programlisting>
</refsect2>
<refsect2>

View File

@ -129,6 +129,7 @@ typedef int FcBool;
#define FC_FONT_HAS_HINT "fonthashint" /* Bool - true if font has hinting */
#define FC_ORDER "order" /* Integer */
#define FC_DESKTOP_NAME "desktop" /* String */
#define FC_NAMED_INSTANCE "namedinstance" /* Bool - true if font is namedinstance */
#define FC_CACHE_SUFFIX ".cache-" FC_CACHE_VERSION
#define FC_DIR_CACHE_FILE "fonts.cache-" FC_CACHE_VERSION

View File

@ -2175,6 +2175,8 @@ FcFreeTypeQueryFaceInternal (const FT_Face face,
goto bail2;
}
#endif
if (!FcPatternObjectAddBool (pat, FC_NAMED_INSTANCE_OBJECT, !!(id > 0xffff)))
goto bail2;
/*
* Drop our reference to the charset

View File

@ -324,6 +324,7 @@ typedef enum _FcMatcherPriority {
PRI1(FILE),
PRI1(FONTFORMAT),
PRI1(VARIABLE),
PRI1(NAMED_INSTANCE),
PRI1(SCALABLE),
PRI1(COLOR),
PRI1(FOUNDRY),

View File

@ -75,4 +75,5 @@ FC_OBJECT (VARIABLE, FcTypeBool, FcCompareBool)
FC_OBJECT (FONT_HAS_HINT, FcTypeBool, FcCompareBool)
FC_OBJECT (ORDER, FcTypeInteger, FcCompareNumber)
FC_OBJECT (DESKTOP_NAME, FcTypeString, NULL)
FC_OBJECT (NAMED_INSTANCE, FcTypeBool, FcCompareBool)
/* ^-------------- Add new objects here. */

View File

@ -0,0 +1,64 @@
{
"fonts": [
{
"family": [
"Foo"
],
"style": [
"Regular"
],
"file": "/path/to/Foo-VF.otf",
"index": 1,
"namedinstance": false,
"fontversion": 1
},
{
"family": [
"Foo",
"Foo Bold"
],
"style": [
"Bold",
"Regular"
],
"file": "/path/to/Foo-VF.otf",
"index": 65537,
"namedinstance": true,
"fontversion": 1
}
],
"tests": [
{
"method": "match",
"query": {
"family": "Foo",
"style": "Bold",
"namedinstance": false
},
"result": {
"family": "Foo",
"style": "Regular",
"file": "/path/to/Foo-VF.otf",
"index": 1,
"namedinstance": false,
"fontversion": 1
}
},
{
"method": "match",
"query": {
"family": "Foo",
"style": "Bold",
"namedinstance": true
},
"result": {
"family": "Foo",
"style": "Bold",
"file": "/path/to/Foo-VF.otf",
"index": 65537,
"namedinstance": true,
"fontversion": 1
}
}
]
}