[Fontconfig] Searching by PostScript FontName
mpsuzuki at hiroshima-u.ac.jp
mpsuzuki at hiroshima-u.ac.jp
Fri Aug 3 00:07:08 PDT 2007
Hi,
On Thu, 02 Aug 2007 23:25:30 -0700
Sairus Patel <sppatel at adobe.com> wrote:
>What would be involved if I wanted to enumerate or search fonts by
>PostScript FontName (OT 'name' table ID 6)?
Yet I'm not sure if I'm understanding what you want,
please check FcFreeTypeQueryFace() function implemented
by fontconfig-x.y.z/src/fcfreetype.c. It opens the font
face (the font file is already opened, and FreeType2's
"face" object is passed to this function) and it gets
some properties by calling FreeType2 library, and it
summarizes the properties. Here I quote fontconfig-2.4.2.
1065 FcPattern *
1066 FcFreeTypeQueryFace (const FT_Face face,
1067 const FcChar8 *file,
1068 int id,
1069 FcBlanks *blanks)
1070 {
...
1145 snamec = FT_Get_Sfnt_Name_Count (face);
1146 for (p = 0; p <= NUM_PLATFORM_ORDER; p++)
1147 {
...
1157 for (n = 0; n < NUM_NAMEID_ORDER; n++)
1158 {
1159 nameid = nameid_order[n];
1160
1161 for (snamei = 0; snamei < snamec; snamei++)
1162 {
...
1197
1198 switch (sname.name_id) {
1199 case TT_NAME_ID_PREFERRED_FAMILY:
1200 case TT_NAME_ID_FONT_FAMILY:
1201 #if 0
1202 case TT_NAME_ID_PS_NAME:
1203 case TT_NAME_ID_UNIQUE_ID:
1204 #endif
1205 if (FcDebug () & FC_DBG_SCANV)
1206 printf ("found family (n %2d p %d e %d l 0x%04x) %s\n",
1207 sname.name_id, sname.platform_id,
1208 sname.encoding_id, sname.language_id,
1209 utf8);
1210
1211 elt = FC_FAMILY;
1212 eltlang = FC_FAMILYLANG;
1213 np = &nfamily;
1214 nlangp = &nfamily_lang;
1215 break;
...
1242 case TT_NAME_ID_TRADEMARK:
1243 case TT_NAME_ID_MANUFACTURER:
1244 /* If the foundry wasn't found in the OS/2 table, look here */
1245 if(!foundry)
1246 foundry = FcNoticeFoundry((FT_String *) utf8);
1247 break;
1248 }
1249 if (elt)
1250 {
1251 if (FcStringInPatternElement (pat, elt, utf8))
1252 {
1253 free (utf8);
1254 continue;
1255 }
1256
1257 /* add new element */
1258 if (!FcPatternAddString (pat, elt, utf8))
1259 {
1260 free (utf8);
1261 goto bail1;
1262 }
1263 free (utf8);
...
Here, as you can find, PS font name is parsed (if it's
written in the font file and FreeType2 can read it),
but not stored in FcPattern (the summary of properties
which fontconfig can handle).
>a. enumerate all font file paths
>b. read in the sfnt/TTC myself to get to the name table
>c. then parse the name table to get to the PostScript FontName
>
>Questions:
>1. Is there a more direct way to do any or all of these steps that
>I'm missing? I can't seem to find a PostScript FontName property at
>http://fontconfig.org/fontconfig-devel/x19.html#AEN27 and searching
>the mailing list archives didn't help.
If you're not asking for the enhancement of fontconfig
to store PS FontName, you are not missing anything.
>2. Can FontConfig at least do step (b) for me, i.e. can I ask it to
>get me a particular table from the sfnt/TTC? Or is the idea that
>FontConfig can provide the full path to the font file, and from there
>on clients are on their own if they want to do interesting stuff with
>the font that FontConfig doesn't support?
Once the full path to font file is resolved, using FreeType2
is easy to open a font file, get a face in it, and parse name
table. I guess, fontconfig is expected to handle any font
file that FreeType2 supports, but the summarization of font
properties in fontconfig is not appropriate for some bitmap
fonts. I'm not sure what you mean by "FontConfig doesn't support",
I wish you give any concrete example.
>3. For Type 1 fonts, I'd have to replace (b) and (c) above with
>simply parsing the font file directly, right?
I think most Type1 fonts can be parsed by FreeType2.
Regards,
mpsuzuki
More information about the Fontconfig
mailing list