Add FC_FONT_WRAPPER

Currently detects only SFNT wrappers:
- WOFF: if it is FreeType says it is an SFNT font the file starts with wOFF tag
- WOFF2: the same but tag is wOF2
- SFNT: for any other SFNT font (which helps distinguishing standalone
  CFF fonts from CFF in SFNT aka OTF)

Fixes #375
This commit is contained in:
Khaled Hosny 2023-08-03 11:08:23 +03:00 committed by Khaled Hosny
parent 2fb3419a92
commit f614ec4d60
6 changed files with 31 additions and 0 deletions

View File

@ -216,6 +216,7 @@ convenience for the application's rendering mechanism.
order FC_ORDER Int Order number of the font order FC_ORDER Int Order number of the font
desktop FC_DESKTOP_NAME String Current desktop name desktop FC_DESKTOP_NAME String Current desktop name
namedinstance FC_NAMED_INSTANCE Bool Whether font is a named instance namedinstance FC_NAMED_INSTANCE Bool Whether font is a named instance
fontwarapper FC_FONT_WRAPPER String The font wrapper format
</programlisting> </programlisting>
</sect2> </sect2>
</sect1> </sect1>

View File

@ -148,6 +148,8 @@ fonthashint Bool Whether the font has hinting
order Int Order number of the font order Int Order number of the font
desktop String Current desktop name desktop String Current desktop name
namedinstance Bool Whether font is a named instance namedinstance Bool Whether font is a named instance
fontwarapper String The font wrapper format, current values are WOFF, WOFF2,
and SFNT for any other SFNT font.
</programlisting> </programlisting>
</refsect2> </refsect2>
<refsect2> <refsect2>

View File

@ -130,6 +130,7 @@ typedef int FcBool;
#define FC_ORDER "order" /* Integer */ #define FC_ORDER "order" /* Integer */
#define FC_DESKTOP_NAME "desktop" /* String */ #define FC_DESKTOP_NAME "desktop" /* String */
#define FC_NAMED_INSTANCE "namedinstance" /* Bool - true if font is named instance */ #define FC_NAMED_INSTANCE "namedinstance" /* Bool - true if font is named instance */
#define FC_FONT_WRAPPER "fontwrapper" /* String */
#define FC_CACHE_SUFFIX ".cache-" FC_CACHE_VERSION #define FC_CACHE_SUFFIX ".cache-" FC_CACHE_VERSION
#define FC_DIR_CACHE_FILE "fonts.cache-" FC_CACHE_VERSION #define FC_DIR_CACHE_FILE "fonts.cache-" FC_CACHE_VERSION

View File

@ -27,6 +27,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <fcntl.h>
#include <ft2build.h> #include <ft2build.h>
#include FT_FREETYPE_H #include FT_FREETYPE_H
#include FT_ADVANCES_H #include FT_ADVANCES_H
@ -2178,6 +2179,30 @@ FcFreeTypeQueryFaceInternal (const FT_Face face,
if (!FcPatternObjectAddBool (pat, FC_NAMED_INSTANCE_OBJECT, !!(id > 0xffff))) if (!FcPatternObjectAddBool (pat, FC_NAMED_INSTANCE_OBJECT, !!(id > 0xffff)))
goto bail2; goto bail2;
if (face->face_flags & FT_FACE_FLAG_SFNT)
{
/* If this is an SFNT wrapper, try to sniff the SFNT tag which is the
* first 4 bytes, to see if it is a WOFF or WOFF2 wrapper. */
FcChar8* wrapper = (FcChar8*) "SFNT";
char buf[4];
int fd = FcOpen ((char *) file, O_RDONLY);
if (fd != -1 && read (fd, buf, 4))
{
if (buf[0] == 'w' && buf[1] == 'O' && buf[2] == 'F')
{
if (buf[3] == 'F')
wrapper = (FcChar8*) "WOFF";
else if (buf[3] == '2')
wrapper = (FcChar8*) "WOFF2";
}
}
close (fd);
if (!FcPatternObjectAddString (pat, FC_FONT_WRAPPER_OBJECT, wrapper))
goto bail2;
}
/* /*
* Drop our reference to the charset * Drop our reference to the charset
*/ */

View File

@ -322,6 +322,7 @@ typedef enum _FcMatcherPriorityDummy {
typedef enum _FcMatcherPriority { typedef enum _FcMatcherPriority {
PRI1(FILE), PRI1(FILE),
PRI1(FONT_WRAPPER),
PRI1(FONTFORMAT), PRI1(FONTFORMAT),
PRI1(VARIABLE), PRI1(VARIABLE),
PRI1(NAMED_INSTANCE), PRI1(NAMED_INSTANCE),

View File

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