Greetings. We use fontconfig in Graphviz. Before we did this, we had some simple rules to bind fonts by names to system font files. Obviously fontconfig improves this greatly, but we also want to report to a human when the match has, for all practical purposes, failed. For example, the user may specify a font that does not exist locally, or we may have misconfigured fontconfig or made an error in Graphviz itself. fontconfig silently fails over to some default. How can we tell when this happens and warn the user? Very recently I noticed that the ''default'' font in Graphviz was a sans-serif font, not Times (which it has been for years). This turned out to be a logic error on our part, but we strongly feel that if the user asks for XYZ font and basically there is no such thing locally, we ought to be able to provide a warning. How can we do this? Stephen North
???? 16-07-2006, ????? ???, ??? ??? 08:29 -0400, ?/? Stephen C. North ??????:> Greetings. We use fontconfig in Graphviz. Before we did this, > we had some simple rules to bind fonts by names to system font > files. Obviously fontconfig improves this greatly, but we also > want to report to a human when the match has, for all practical > purposes, failed. For example, the user may specify a font > that does not exist locally, or we may have misconfigured fontconfig > or made an error in Graphviz itself. > > fontconfig silently fails over to some default. How can we tell > when this happens and warn the user?I suppose the plan would be to iterate through the list of all installed fonts to check if the selected font is indeed installed. If it is not installed, notify the user that the default "Sans" alias will be used.> Very recently I noticed that the ''default'' font in Graphviz was > a sans-serif font, not Times (which it has been for years). > This turned out to be a logic error on our part, but we strongly > feel that if the user asks for XYZ font and basically there is > no such thing locally, we ought to be able to provide a warning. > > How can we do this?Normally, the suggested way is to delegate the choice of the suitable desktop font to the Linux distribution; applications will use this default font so the look and feel will be similar across the desktop. Using the default "virtual" font Sans that the distribution defines, it is possible to show text correctly in different languages (provided fonts.conf has been configured well to pick up the proper fonts by the distro). Of course, if the user prefers a specific font, then the glyphs from this font will take precedence over the others installed on the system. I think that you can consider that when you specify the font, you effectively get the Sans font where your selected font goes on the top of the preference list. Hope this helps, Simos
On Sun, 2006-07-16 at 08:29 -0400, Stephen C. North wrote:> fontconfig silently fails over to some default. How can we tell > when this happens and warn the user?You can compare the family name in the returned font with the name you requested; if they don''t match, fontconfig has gone off and found something other than what they requested. -- keith.packard@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/20060716/d91da45b/attachment.pgp
On Sun, 2006-07-16 at 10:18 -0700, Keith Packard wrote:> On Sun, 2006-07-16 at 08:29 -0400, Stephen C. North wrote: > > > fontconfig silently fails over to some default. How can we tell > > when this happens and warn the user? > > You can compare the family name in the returned font with the name you > requested; if they don''t match, fontconfig has gone off and found > something other than what they requested.But note that this will be the case when there are aliases involved; if the user asked for Arial and got the metric-matched Albany AMT instead, say. So it''s probably not good to warn in that case. Owen
OK, "fail over to a default font" may not be quite the right way to describe what happens. At the end of the day, when fontconfig can''t resolve a request like "Cursive-Script-Like-Don-Knuth''s-Handwriting at 12 pt" to anything better, its rule of last resort substitutes a system default like "Sans". In our world, we would consider this worth a runtime warning. So, how can I tell if the last resort rule was matched? Just check if the family is "Sans" when we didn''t ask for "Sans"? BTW, it''s impressive that a request for Arial can be resolved to Albany AMT. How was that knowledge built into fontconfig? Rule by painstaking rule, defined manually by the fontconfig developers? Thanks for writing this software and making it possible for us to use it. Stephen North
On Mon, 2006-07-17 at 12:05 -0400, Stephen C. North wrote:> OK, "fail over to a default font" may not be quite the right way to describe > what happens. At the end of the day, when fontconfig can''t resolve a request > like "Cursive-Script-Like-Don-Knuth''s-Handwriting at 12 pt" to anything > better, its rule of last resort substitutes a system default like "Sans". > In our world, we would consider this worth a runtime warning. So, how can > I tell if the last resort rule was matched? Just check if the family > is "Sans" when we didn''t ask for "Sans"?Basically, what you want to do is detect whether the resulting font matches: A) The family that was originally specified B) A family that was added by an alias rule, except for families resulting indirectly from the rule in the default config: "If the font still has no generic name, add sans-serif" But that''s hard to do. An approximation might be: - If the user specifies sans-serif, sans, mono, monospace, serif, never warn. - Otherwise warn unless the font matches a "strongly bound" family name in the config-expanded pattern (Aliases like "sans-serif" are weak, and result in tagging the expanded family names differently from strong aliases. Maybe someone can give a more detailed recipe for how to do the above giving the fontconfig API) This isn''t perfect, and could give false-positive warnings, especially with custom font configurations, but would probably normally work pretty well. The basic problem, however, is that fontconfig simply has no idea of failure. As long as you have a single font on your system, it thinks the match succeeded.> BTW, it''s impressive that a request for Arial can be resolved to Albany AMT. > How was that knowledge built into fontconfig? Rule by painstaking rule, > defined manually by the fontconfig developers?Yes. (or by the system integrator) Owen
Is it asking too much to somehow mark the "default" rule and notice when it has been matched? That would be helpful. Stephen
I''m forwarding this due to problems Behdad had in posting to the list. His solution is clever. Behdad Esfahbod wrote:>On Mon, 2006-07-17 at 12:22 -0400, Owen Taylor wrote: > > >>On Mon, 2006-07-17 at 12:05 -0400, Stephen C. North wrote: >> >> >>>OK, "fail over to a default font" may not be quite the right way to describe >>>what happens. At the end of the day, when fontconfig can''t resolve a request >>>like "Cursive-Script-Like-Don-Knuth''s-Handwriting at 12 pt" to anything >>>better, its rule of last resort substitutes a system default like "Sans". >>>In our world, we would consider this worth a runtime warning. So, how can >>>I tell if the last resort rule was matched? Just check if the family >>>is "Sans" when we didn''t ask for "Sans"? >>> >>> >>Basically, what you want to do is detect whether the resulting font >>matches: >> >> A) The family that was originally specified >> B) A family that was added by an alias rule, except for families >> resulting indirectly from the rule in the default config: >> >> "If the font still has no generic name, add sans-serif" >> >>But that''s hard to do. An approximation might be: >> >> > >What about this: match font for "YourFamily,sans", and >"YourFamily,serif". If they return the same family, it''s a match, if >they don''t, it''s junk fallback. > >[behdad@home ~]$ fc-match "Helvetica,serif" >n019003l.pfb: "Nimbus Sans L" "Regular" >[behdad@home ~]$ fc-match "Helvetica,sans" >n019003l.pfb: "Nimbus Sans L" "Regular" >[behdad@home ~]$ fc-match "NonExistant,serif" >VeraSe.ttf: "Bitstream Vera Serif" "Roman" >[behdad@home ~]$ fc-match "NonExistant,sans" >Vera.ttf: "Bitstream Vera Sans" "Roman" > > >