The ability to select a font based on its psname rather than on its fullname is important for a number of applications. Viewers and RIPs for a number of page description languages need to render documents which specify their (non-embedded) fonts by psname. The spliced font format, which the ISO is likely to standardize as part of its Open Font Format (ISO 14496-22), references component fonts by their psnames. (OFF is the ISO standardization of OpenType.) A few SFNT/GLYF fonts specify multiple psnames; even though non-ASCII /FontNames may not be legal PostScript, they are cached none-the-less. As of this commit, fc-cat(1), fc-list(1), fc-query(1) and fc-scan(1) all correctly report psnames of SFNT, Type1 and (bare) CFF fonts. Signed-off-by: James Cloos <cloos at jhcloos.com> --- doc/fontconfig-devel.sgml | 3 +++ fontconfig/fontconfig.h | 2 ++ src/fcfreetype.c | 38 +++++++++++++++++++++++++++++++++++++- src/fcint.h | 6 ++++-- src/fcname.c | 4 +++- 5 files changed, 49 insertions(+), 4 deletions(-) diff --git a/doc/fontconfig-devel.sgml b/doc/fontconfig-devel.sgml index 891251f..e27e2e6 100644 --- a/doc/fontconfig-devel.sgml +++ b/doc/fontconfig-devel.sgml @@ -145,6 +145,9 @@ convenience for the applications rendering mechanism. family + style fullnamelang FC_FULLNAMELANG String Language cooresponding to each fullname + psname FC_PSNAME String Font PostScript name + psnamelang FC_PSNAMELANG String Language cooresponding to + each psname slant FC_SLANT Int Italic, oblique or roman weight FC_WEIGHT Int Light, medium, demibold, bold or black diff --git a/fontconfig/fontconfig.h b/fontconfig/fontconfig.h index c9f20cc..76bcdbb 100644 --- a/fontconfig/fontconfig.h +++ b/fontconfig/fontconfig.h @@ -111,6 +111,8 @@ typedef int FcBool; #define FC_EMBEDDED_BITMAP "embeddedbitmap" /* Bool - true to enable embedded bitmaps */ #define FC_DECORATIVE "decorative" /* Bool - true if style is a decorative variant */ #define FC_LCD_FILTER "lcdfilter" /* Int */ +#define FC_PSNAME "psname" /* String */ +#define FC_PSNAMELANG "psnamelang" /* String */ #define FC_CACHE_SUFFIX ".cache-"FC_CACHE_VERSION #define FC_DIR_CACHE_FILE "fonts.cache-"FC_CACHE_VERSION diff --git a/src/fcfreetype.c b/src/fcfreetype.c index 68596f5..d472039 100644 --- a/src/fcfreetype.c +++ b/src/fcfreetype.c @@ -1105,6 +1105,7 @@ static const FT_UShort nameid_order[] = { TT_NAME_ID_FONT_SUBFAMILY, TT_NAME_ID_TRADEMARK, TT_NAME_ID_MANUFACTURER, + TT_NAME_ID_PS_NAME, }; #define NUM_NAMEID_ORDER (sizeof (nameid_order) / sizeof (nameid_order[0])) @@ -1146,6 +1147,8 @@ FcFreeTypeQueryFace (const FT_Face face, int nstyle_lang = 0; int nfullname = 0; int nfullname_lang = 0; + int npsname = 0; + int npsname_lang = 0; int p, platform; int n, nameid; @@ -1248,7 +1251,6 @@ FcFreeTypeQueryFace (const FT_Face face, case TT_NAME_ID_PREFERRED_FAMILY: case TT_NAME_ID_FONT_FAMILY: #if 0 - case TT_NAME_ID_PS_NAME: case TT_NAME_ID_UNIQUE_ID: #endif if (FcDebug () & FC_DBG_SCANV) @@ -1275,6 +1277,18 @@ FcFreeTypeQueryFace (const FT_Face face, np = &nfullname; nlangp = &nfullname_lang; break; + case TT_NAME_ID_PS_NAME: + if (FcDebug () & FC_DBG_SCANV) + printf ("found psname (n %2d p %d e %d l 0x%04x) %s\n", + sname.name_id, sname.platform_id, + sname.encoding_id, sname.language_id, + utf8); + + elt = FC_PSNAME; + eltlang = FC_PSNAMELANG; + np = &npsname; + nlangp = &npsname_lang; + break; #ifdef TT_NAME_ID_WWS_SUBFAMILY case TT_NAME_ID_WWS_SUBFAMILY: #endif @@ -1354,6 +1368,28 @@ FcFreeTypeQueryFace (const FT_Face face, ++nstyle; } + if (!npsname && face) + { + const char *ps_name; + + ps_name = FT_Get_Postscript_Name (face); + + if (ps_name && + FcStrCmpIgnoreBlanksAndCase ((FcChar8 *) ps_name, (FcChar8 *) "") != 0) + { + if (FcDebug () & FC_DBG_SCANV) + printf ("using FreeType psname \"%s\"\n", ps_name); + + if (!FcPatternAddString (pat, FC_PSNAME, (FcChar8 *) ps_name)) + goto bail1; + + if (!FcPatternAddString (pat, FC_PSNAMELANG, (FcChar8 *) "en")) + goto bail1; + + ++npsname; + } + } + if (!nfamily) { FcChar8 *start, *end; diff --git a/src/fcint.h b/src/fcint.h index 8e80d1e..3495761 100644 --- a/src/fcint.h +++ b/src/fcint.h @@ -419,7 +419,7 @@ typedef struct _FcCaseFold { #define FC_CACHE_MAGIC_MMAP 0xFC02FC04 #define FC_CACHE_MAGIC_ALLOC 0xFC02FC05 -#define FC_CACHE_CONTENT_VERSION 3 /* also check FC_CACHE_VERSION */ +#define FC_CACHE_CONTENT_VERSION 4 /* also check FC_CACHE_VERSION */ struct _FcAtomic { FcChar8 *file; /* original file name */ @@ -837,7 +837,9 @@ FcListPatternMatchAny (const FcPattern *p, #define FC_EMBEDDED_BITMAP_OBJECT 39 #define FC_DECORATIVE_OBJECT 40 #define FC_LCD_FILTER_OBJECT 41 -#define FC_MAX_BASE_OBJECT FC_LCD_FILTER_OBJECT +#define FC_PSNAME_OBJECT 42 +#define FC_PSNAMELANG_OBJECT 43 +#define FC_MAX_BASE_OBJECT FC_PSNAMELANG_OBJECT FcPrivate FcBool FcNameBool (const FcChar8 *v, FcBool *result); diff --git a/src/fcname.c b/src/fcname.c index b4ce944..d0ee0bc 100644 --- a/src/fcname.c +++ b/src/fcname.c @@ -75,7 +75,9 @@ static const FcObjectType _FcBaseObjectTypes[] = { { FC_EMBOLDEN, FcTypeBool }, { FC_EMBEDDED_BITMAP, FcTypeBool }, { FC_DECORATIVE, FcTypeBool }, - { FC_LCD_FILTER, FcTypeInteger }, /* 41 */ + { FC_LCD_FILTER, FcTypeInteger }, + { FC_PSNAME, FcTypeString }, + { FC_PSNAMELANG, FcTypeString }, /* 43 */ }; #define NUM_OBJECT_TYPES (sizeof _FcBaseObjectTypes / sizeof _FcBaseObjectTypes[0]) -- 1.7.0.1.147.g6d84b