Greetings. FontConfig newbie here. What would be involved if I wanted to enumerate or search fonts by PostScript FontName (OT ''name'' table ID 6)? Presumably I''d need to (for OpenType/TrueType fonts): 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. 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? 3. For Type 1 fonts, I''d have to replace (b) and (c) above with simply parsing the font file directly, right? Thanks! I look forward to becoming more familiar with FontConfig. Sairus.
mpsuzuki at hiroshima-u.ac.jp
2007-Aug-03 07:07 UTC
[Fontconfig] Searching by PostScript FontName
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
Greetings. I''d like to ask FontConfig to find a font but *not* do font fallback if a precise match isn''t found. Is there a way I can tell FcFontMatch to do this (see below) or is there another API I should be using? The FC documentation says: > Font configuration is separate from font matching; applications needing to do their own matching can access the available fonts from the library and perform private matching. Does this means that there is no explicit findfont API and I should be using FcFontList and managing things myself? TIA, Sairus FcPattern* pattern = FcPatternBuild(0, FC_SCALABLE, FcTypeBool, 1, FC_FAMILY, FcTypeString, familyUtf8, FC_WEIGHT, FcTypeInteger, weight, FC_SLANT, FcTypeInteger, slant, (char *)0); if (pattern) { FcResult result; FcPattern* match; /* These *must* be called before FcFontMatch or the results won''t be correct: */ FcConfigSubstitute(0, pattern, FcMatchPattern); FcDefaultSubstitute(pattern); /* Add default values for other attribs */ /* FcFontMatch substitutes a fallback font if not found; can we suppress this? */ match = FcFontMatch(0, pattern, &result); if (match) { ....
I haven''t seen a response yet. Is querying for fonts without fallback not possible, or is it that folks don''t know (or is the answer so obvious you have refrained from replying :^)? Any response, including a "I always want fallback to happen, so I don''t know the answer" appreciated. Feel free to email me privately as well. Best, Sairus At 4/15/2008 02:51 PM, Sairus Patel wrote:>Greetings. > >I''d like to ask FontConfig to find a font but *not* do font fallback >if a precise match isn''t found. > >Is there a way I can tell FcFontMatch to do this (see below) or is >there another API I should be using? > >The FC documentation says: > > Font configuration is separate from font matching; applications >needing to do their own matching can access the available fonts from >the library and perform private matching. > >Does this means that there is no explicit findfont API and I should >be using FcFontList and managing things myself? > >TIA, >Sairus > > > > FcPattern* pattern = FcPatternBuild(0, > FC_SCALABLE, FcTypeBool, 1, > FC_FAMILY, FcTypeString, familyUtf8, > FC_WEIGHT, FcTypeInteger, weight, > FC_SLANT, FcTypeInteger, slant, > (char *)0); > if (pattern) { > FcResult result; > FcPattern* match; > > /* These *must* be called before FcFontMatch or the results >won''t be correct: */ > FcConfigSubstitute(0, pattern, FcMatchPattern); > FcDefaultSubstitute(pattern); /* Add default values for >other attribs */ > > /* FcFontMatch substitutes a fallback font if not found; can >we suppress this? */ > match = FcFontMatch(0, pattern, &result); > if (match) { > .... > >_______________________________________________ >Fontconfig mailing list >Fontconfig at lists.freedesktop.org >http://lists.freedesktop.org/mailman/listinfo/fontconfig
Vous (Sairus Patel) avez ?crit?:> I haven''t seen a response yet. > > Is querying for fonts without fallback not possible, or is it that > folks don''t know (or is the answer so obvious you have refrained from > replying :^)? > > Any response, including a "I always want fallback to happen, so I > don''t know the answer" appreciated. Feel free to email me privately as > well. > > Best, > Sairus >I?m just a user but from http://fontconfig.org/fontconfig-user.html , I can read : "Fontconfig performs matching by measuring the distance from a provided pattern to all of the available fonts in the system. The closest matching font is selected. This ensures that a font will always be returned, but doesn''t ensure that it is anything like the requested pattern." I don?t know if it applies for all methods, but I would say yes. And thus "no" for your question.> At 4/15/2008 02:51 PM, Sairus Patel wrote: > >Greetings. > > > >I''d like to ask FontConfig to find a font but *not* do font fallback > >if a precise match isn''t found. > >My idea would be, rather than no result to a request, to access the computed distance. So one could quickly evaluate if the font is close enough from what?s the desired functionality or not. By the way, the term "fallback" is not really good because returning the best font available is not the same as returning a default font. I want to repeat I don?t know Fontconfig very well & I can be completely wrong here! But I?m still interested in the discussion because I had the same question and finally opted for a private management. Bien ? vous -- Pierre Marchand http://www.oep-h.com
Le vendredi 25 avril 2008 ? 13:34 -0700, Sairus Patel a ?crit :> I haven''t seen a response yet.As a user, and as someone interested in i18n, I''d be *very* suspicious of any application that tried to disable the normal system font management. I''d strongly suspect the application writer of wanting to disable a core platform feature just so he does not have to care about differences between this platform and other more limited ones, applying a lowest common denominator logic. Font & glyph substitution is *very* important on FLOSS systems, especially when you render documents composed on other platforms with different fonts (that have different unicode coverages) Nevertheless if you insist on producing something that does not fit with the rest of the system, I''d say look up gucharmap''s code ? it knows what font each glyph is taken from, and once you have this info, refusing to use a particular glyph is not too far away. -- Nicolas Mailhot -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 197 bytes Desc: Ceci est une partie de message =?ISO-8859-1?Q?num=E9riquement?= =?ISO-8859-1?Q?_sign=E9e?Url : http://lists.freedesktop.org/archives/fontconfig/attachments/20080425/28e01785/attachment.pgp
Vous (Nicolas Mailhot) avez ?crit?:> Le vendredi 25 avril 2008 ? 13:34 -0700, Sairus Patel a ?crit : > > I haven''t seen a response yet. > > As a user, and as someone interested in i18n, I''d be *very* suspicious > of any application that tried to disable the normal system font > management.I think you forget that Fontconfig not only manages system fonts. And all font management applications or modules I know (except TeX stuff) for users fonts also use Fontconfig.> Font & glyph substitution is *very* important on FLOSS systems, > especially when you render documents composed on other platforms with > different fonts (that have different unicode coverages)In my opinion, font & glyph substitutions should not be done without clear statement from the user that he agrees on these substitutions. From my graphic designer point of view, a silent font substitution can be a disaster. And nevermind if it?s FLOSS or not.> Nevertheless if you insist on producing something that does not fit with > the rest of the system, I''d say look up gucharmap''s code ? it knows what > font each glyph is taken from, and once you have this info, refusing to > use a particular glyph is not too far away.Gucharmap, because it focuses on Unicode rather than fonts, might not be the best code to look at. -- Pierre Marchand http://www.oep-h.com
> I''d be *very* suspicious of any applicationthat tried to disable the normal system font management [ I''m assuming that by "the normal system font management" you mean FontConfig''s fallback mechanism. ] I believe I have good reasons to do so. I want my app to have its own fallback mechanism. This fallback mechanism will not just replace one font with another, as FontConfig seems to be doing, but do the fallback on a grapheme cluster granularity. (My app does its own layout, parsing GSUB and GPOS and other OT tables.) For this, I need to be able to tell whether a particular font is present on the system or not. > I''d say look up gucharmap''s code gucharmap doesn''t seem to use FontConfig (I grepped for "Fc" and got no matches), but maybe it uses another facility e.g. Pango, which relies on FC. So it doesn''t really answer my question about whether I can get FontConfig to tell me whether a particular font is present on the system or not. Thanks for your response! Sairus At 4/25/2008 02:32 PM, Nicolas Mailhot wrote:>Le vendredi 25 avril 2008 ? 13:34 -0700, Sairus Patel a ??crit : > > I haven''t seen a response yet. > >As a user, and as someone interested in i18n, I''d be *very* suspicious >of any application that tried to disable the normal system font >management. I''d strongly suspect the application writer of wanting to >disable a core platform feature just so he does not have to care about >differences between this platform and other more limited ones, applying >a lowest common denominator logic. > >Font & glyph substitution is *very* important on FLOSS systems, >especially when you render documents composed on other platforms with >different fonts (that have different unicode coverages) > >Nevertheless if you insist on producing something that does not fit with >the rest of the system, I''d say look up gucharmap''s code ? it knowss what >font each glyph is taken from, and once you have this info, refusing to >use a particular glyph is not too far away. > >-- >Nicolas Mailhot >
Vous (Sairus Patel) avez ?crit?:> granularity. (My app does its own layout, parsing > GSUB and GPOS and other OT tables.)Miam miam :)> For this, I > need to be able to tell whether a particular font > is present on the system or not.As an example, in Fontmatrix we ask for all directories registered in the Fontconfig configuration and then we build our own list of font files by running recursively through these directories. We do so rather than FcList because we want to avoid our own registered directory. Once you get this list, you?ll be able to do watever you want with these files. -- Pierre Marchand http://www.oep-h.com
On Fri, 2008-04-25 at 15:29 -0700, Sairus Patel wrote:> > I''d be *very* suspicious of any application > that tried to disable the normal system font management > > [ I''m assuming that by "the normal system font > management" you mean FontConfig''s fallback mechanism. ] > > I believe I have good reasons to do so. I want my > app to have its own fallback mechanism. This > fallback mechanism will not just replace one font > with another, as FontConfig seems to be doing, > but do the fallback on a grapheme cluster > granularity. (My app does its own layout, parsing > GSUB and GPOS and other OT tables.) For this, I > need to be able to tell whether a particular font > is present on the system or not.Fontconfig doesn''t do any of the font substitution, it simply provides information about the available fonts. It certainly isn''t responsible for doing glyph-by-glyph substitution; that obviously couldn''t work. Pango, for instance, does precisely what you''re looking to do as it builds sets of glyphs based on the input unicode stream and the set of fonts returned by fontconfig.> > > I''d say look up gucharmap''s code > > gucharmap doesn''t seem to use FontConfig (I > grepped for "Fc" and got no matches), but maybe > it uses another facility e.g. Pango, which relies > on FC. So it doesn''t really answer my question > about whether I can get FontConfig to tell me > whether a particular font is present on the system or not.The FcList functions can tell you whether a specific font is available, or you can use the FcMatch functions and simply check the returned font family. Fontconfig is supposed to provide a central database of available fonts with some simple search operations to look for suitable font sets for your application. If the search operations provided can''t do what you want, we should add some that do. Working around the library doesn''t make sense -- your application performance will suffer badly if you end up constructing your own font database as fontconfig is both reasonably efficient and also generally integrated into the package management system from your operating system to ensure reliable and fast font package management. -- keith.packard at intel.com -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: This is a digitally signed message part Url : http://lists.freedesktop.org/archives/fontconfig/attachments/20080426/503769b4/attachment.pgp
On Sat, 2008-04-26 at 00:58 +0200, Pierre Marchand wrote:> As an example, in Fontmatrix we ask for all directories registered in the > Fontconfig configuration and then we build our own list of font files by > running recursively through these directories. We do so rather than FcList > because we want to avoid our own registered directory. Once you get this > list, you?ll be able to do watever you want with these files.I hope you realize what a performance cost this is -- fontconfig has been designed to cache information about fonts reasonably efficiently; on my system with 3382 font files, ''fc-list foo'', which reads the entire database scanning it for any fonts named ''foo'', takes 19ms. If fontconfig doesn''t provide the interface you need, please build what you want and let us see it. We can''t fix the library if you continue to work around it. -- keith.packard at intel.com -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: This is a digitally signed message part Url : http://lists.freedesktop.org/archives/fontconfig/attachments/20080426/6a1737b4/attachment.pgp
Vous (Keith Packard) avez ?crit?:> I hope you realize what a performance cost this is -- fontconfig has > been designed to cache information about fonts reasonably efficiently; > on my system with 3382 font files, ''fc-list foo'', which reads the entire > database scanning it for any fonts named ''foo'', takes 19ms.I know how Fontconfig is good in this field and more generally takes care of these things. It is just that dealing with uninstalled fonts, I already had a function for scanning directories. So when someone asked for, at least, having the system fonts in "read-only" mode listed in the application (without the possibility to deactivate them) I reused the same function.> > If fontconfig doesn''t provide the interface you need, please build what > you want and let us see it. We can''t fix the library if you continue to > work around it.To be honest, I actually think that using Fontconfig the way we do comes to pervert it :-) Though not in how we grab the system fonts list because I do it just once at program startup, but rather the way we "activate" fonts (ie sym-links into a directory for which we write a DIR element in ~/.fonts.conf) and thus we maintain our own database, that?s bad. But when I tried to base all the activation on Fontconfig by means of SELECTFONT, REJECTFONT & ACCEPTFONT I had some issues I could not overcome and at this point nobody was interested to help. It?s not a problem since we?re at the very beginning of the development and have time to refine^^rewrite the code. Finally, for the moment, the only feature we would want is a font channel on DBUS (or something similar) to activate/deactivate, lock/unlock fonts, etc. Or is it the only thing I can think at by now? We?ll see! -- Pierre Marchand http://www.oep-h.com
Sairus Patel
2008-Jul-08 22:37 UTC
[Fontconfig] Lifetime of strings from FcPatternGetString
Hello all, It?s not clear from the FC documentation how long we can expect a string returned from a pattern by FcPatternGetString to remain valid. The doc does say that FcPatternGetString provides a pointer to the actual string within the pattern, but as in the code snippet below, the pattern is destroyed but I''ve observed that the returned filename value seems to remain usable. Am I purely lucky that the memory is still valid, or are these strings ?atoms? i.e. strings that remain valid for the entire lifetime of FontConfig? Is this documented anywhere? Thanks, Sairus const char* FindFileName(const char* family, bool isBold, bool isItalic) { const char* filename = NULL; [...] FcPattern* pattern = FcPatternBuild(NULL, FC_SCALABLE, FcTypeBool, true, FC_FAMILY, FcTypeString, family, FC_WEIGHT, FcTypeInteger, weight, FC_SLANT, FcTypeInteger, slant, NULL); if(pattern) { FcConfigSubstitute(0, pattern, FcMatchPattern); FcDefaultSubstitute(pattern); FcResult result; FcPattern* match = FcFontMatch(0, pattern, &result); if(match) { FcChar8* str = 0; if(FcPatternGetString(match, FC_FILE, 0, &str) == FcResultMatch) { filename = (const char*)str; } } FcPatternDestroy(pattern); } return filename; }
Keith Packard
2008-Jul-09 00:24 UTC
[Fontconfig] Lifetime of strings from FcPatternGetString
On Tue, 2008-07-08 at 15:37 -0700, Sairus Patel wrote:> Hello all, > > It?s not clear from the FC documentation how long we can expect a > string returned from a pattern by FcPatternGetString to remain valid.You shouldn''t count on them being valid any longer than the pattern is around.> The doc does say that FcPatternGetString provides a pointer to the > actual string within the pattern, but as in the code snippet below, > the pattern is destroyed but I''ve observed that the returned filename > value seems to remain usable.The strings will have varying lifetimes depending on what kind of pattern you''re using. Patterns from font files are live as long as that directory cache is mapped, which is generally the same as the application lifetime unless the directory is rescanned. Of course, any patterns in use by the application will hold the whole directory content from being freed. Patterns created by the user will end up with strings that are dumped into a shared data structure, and so they have lifetime equal to the program itself.> Am I purely lucky that the memory is still valid, or are these strings > ?atoms? i.e. strings that remain valid for the entire lifetime of > FontConfig? Is this documented anywhere?Most of the time, the strings will persist, but strings in patterns loaded from disk can go away when the pattern is freed. "don''t do that". Note that these patterns are entirely shared, so it''s almost free (again, except when the directory is rescanned) to hold a reference to the pattern if you need to store the string somewhere. -- keith.packard at intel.com -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: This is a digitally signed message part Url : http://lists.freedesktop.org/archives/fontconfig/attachments/20080708/25a12b70/attachment.pgp