Indeed, as Steve Pomeroy says, the problem is that websites specifying
`Times' (say) get Nimbus rather than DejaVu (or whatever the default
is in Debian).

Fixing this is complicated because, as Keith Packard says, Nimbus is
needed for (for example) PDF viewing, because DejaVu has different
metrics.  The real problem is that the fontconfig configuration can't
tell whether we're (i) a web browser, which doesn't really care much
about the metrics but definitely wants a font that looks good on
screen or (ii) a PDF handling program (or similar), which must use
fonts with exactly the metrics of the requested font.

Without a way to distinguish these cases, it is impossible to (as
Keith says) `work out [the] rules for when each family should be used
and try to make that happen'.

After staring at the various packages involved, I concluded that the
right answer was: a new font template property `anymetrics' which
would be set by applications which would not mind fonts with different
metrics to that specified in the pattern.  Doing it that way round
means that the stricter behaviour is the default, so that we will err
on the side of ugliness rather than brokenness.

In Ubuntu we configure firefox to use pango for all of its text
rendering (for i18n charset reasons).  And as it turns out, I think
applications that use pango (such as firefox) always leave the
specific text sizing and placement to pango, and pango uses the actual
metrics from the actual font.  So the correct place to set the
anymetrics fontconfig flag is in pango, and firefox does not need to
be changed.

I could be wrong about pango clients but it seems likely that this is
true for the majority at least.  If it's not true for all - if, for
example, pango even provides an interface that could be used by a
program which needs to use specific fonts and do its own text
placement - then an option could be added to pango's font selection
machinery to turn anymetrics off.  It seems to me from what little I
know abouit this situation that this is the right way round for the
default at this layer.

Finally, this provides us with the tools to selectively disable the
font <alias...> directives for the relatively ugly Nimbus fonts when
we know that we don't care about the metrics so that DejaVu fallback
is good.  Sadly <alias...> can only be made conditional by turning
it into <match...> which is much more verbose.  An <if...> construct
would have been very useful.

Attached:

* Patch to fontconfig (against 2.3.2-1.1ubuntu9) to
  - provide a new FC_ANY_METRICS (aka `anymetrics') boolean property.
  - only use Nimbus for Times et al if anymetrics is not set.

* Patch to pango (against pango1.0 1.12.1-1ubuntu1) to set
  FC_ANY_METRICS (aka `anymetrics') to FcTrue everywhere a fontconfig
  font pattern is constructed.  Note that the versioned
  build-dependency on libfontconfig1-dev may need adjusting for Debian.

Regards,
Ian.

diff -ruN --exclude '*~' orig/fontconfig-2.3.2/debian/changelog 
fontconfig-2.3.2/debian/changelog
--- orig/fontconfig-2.3.2/debian/changelog      2006-04-19 14:31:45.000000000 
+0100
+++ fontconfig-2.3.2/debian/changelog   2006-04-19 14:37:51.000000000 +0100
@@ -1,3 +1,15 @@
+fontconfig (2.3.2-1.1ubuntu10) dapper; urgency=low
+
+  * Correctly fix the (eg) firefox vs. (eg) evince font metrics
+    problem:
+    - New FC_ANY_METRICS property, boolean.
+    - Revert change from 2.3.2-1.1ubuntu9 and instead:
+    - Change URW Nimbus font aliases in fonts.conf.in into equivalent
+      <match> directives so that we can add an additional test which
+      disables them when the anymetrics property is true.
+
+ -- Ian Jackson <[EMAIL PROTECTED]>  Wed, 19 Apr 2006 12:51:29 +0100
+
 fontconfig (2.3.2-1.1ubuntu9) dapper; urgency=low
 
   * Until firefox and thunderbird can be tought to use it's own
diff -ruN --exclude '*~' 
orig/fontconfig-2.3.2/debian/patches/05_no_nimbus_fallback.patch 
fontconfig-2.3.2/debian/patches/05_no_nimbus_fallback.patch
--- orig/fontconfig-2.3.2/debian/patches/05_no_nimbus_fallback.patch    
2006-04-19 14:31:45.000000000 +0100
+++ fontconfig-2.3.2/debian/patches/05_no_nimbus_fallback.patch 1970-01-01 
01:00:00.000000000 +0100
@@ -1,23 +0,0 @@
---- fonts.conf.in~     2006-04-18 16:06:59.203112376 +0000
-+++ fonts.conf.in      2006-04-18 16:11:52.197570448 +0000
-@@ -147,6 +147,12 @@
- <!--
-   URW provides metric and shape compatible fonts for these 3 Adobe families.
-   -->
-+<!--
-+  Disable the usage of metric and shape compatible fonts for the
-+  3 Adobe families. evince cannot display documents correctly
-+  with these replacements not beeing available, but web browsers not
-+  using these fonts look definitely nicer.
-+
-         <alias>
-         <family>Times</family>
-         <accept><family>Nimbus Roman No9 L</family></accept>
-@@ -159,6 +165,7 @@
-         <family>Courier</family>
-         <accept><family>Nimbus Mono L</family></accept>
-       </alias>
-+  -->
- 
- <!--
-  AMT provides metric and shape compatible fonts for these three web font
diff -ruN --exclude '*~' orig/fontconfig-2.3.2/fontconfig/fontconfig.h 
fontconfig-2.3.2/fontconfig/fontconfig.h
--- orig/fontconfig-2.3.2/fontconfig/fontconfig.h       2006-04-19 
14:31:45.000000000 +0100
+++ fontconfig-2.3.2/fontconfig/fontconfig.h    2006-04-18 18:58:44.000000000 
+0100
@@ -97,6 +97,7 @@
 #define FC_FONTFORMAT      "fontformat"        /* String */
 #define FC_EMBOLDEN        "embolden"          /* Bool - true if emboldening 
needed*/
 #define FC_EMBEDDED_BITMAP  "embeddedbitmap"   /* Bool - true to enable 
embedded bitmaps */
+#define FC_ANY_METRICS      "anymetrics"       /* Bool - true to allow metrics 
which do not match the requested font */
 
 #define FC_DIR_CACHE_FILE          "fonts.cache-"FC_CACHE_VERSION
 #define FC_USER_CACHE_FILE         ".fonts.cache-"FC_CACHE_VERSION
diff -ruN --exclude '*~' orig/fontconfig-2.3.2/fonts.conf.in 
fontconfig-2.3.2/fonts.conf.in
--- orig/fontconfig-2.3.2/fonts.conf.in 2006-04-19 14:31:45.000000000 +0100
+++ fontconfig-2.3.2/fonts.conf.in      2006-04-19 14:35:11.000000000 +0100
@@ -146,19 +146,38 @@
 
 <!--
   URW provides metric and shape compatible fonts for these 3 Adobe families.
+  However, these fonts are quite ugly and do not render well on-screen,
+  so we avoid matching them if the application said `anymetrics'; in that
+  case, a more generic font with different metrics but better appearance
+  will be used.
   -->
-        <alias>
-         <family>Times</family>
-         <accept><family>Nimbus Roman No9 L</family></accept>
-       </alias>
-        <alias>
-         <family>Helvetica</family>
-         <accept><family>Nimbus Sans L</family></accept>
-       </alias>
-        <alias>
-         <family>Courier</family>
-         <accept><family>Nimbus Mono L</family></accept>
-       </alias>
+       <match target="pattern">
+               <test name="family"><string>Times</string></test>
+               <test name="anymetrics" qual="all" compare="not_eq">
+                       <bool>true</bool>
+               </test>
+               <edit name="family" mode="append">
+                       <string>Nimbus Roman No9 L</string>
+               </edit>
+       </match>
+       <match target="pattern">
+               <test name="family"><string>Helvetica</string></test>
+               <test name="anymetrics" qual="all" compare="not_eq">
+                       <bool>true</bool>
+               </test>
+               <edit name="family" mode="append">
+                       <string>Nimbus Sans L</string>
+               </edit>
+       </match>
+       <match target="pattern">
+               <test name="family"><string>Courier</string></test>
+               <test name="anymetrics" qual="all" compare="not_eq">
+                       <bool>true</bool>
+               </test>
+               <edit name="family" mode="append">
+                       <string>Nimbus Mono L</string>
+               </edit>
+       </match>
 
 <!--
  AMT provides metric and shape compatible fonts for these three web font
diff -ruN --exclude '*~' orig/fontconfig-2.3.2/src/fcname.c 
fontconfig-2.3.2/src/fcname.c
--- orig/fontconfig-2.3.2/src/fcname.c  2006-04-19 14:31:45.000000000 +0100
+++ fontconfig-2.3.2/src/fcname.c       2006-04-18 18:57:42.000000000 +0100
@@ -71,6 +71,7 @@
     { FC_FONTFORMAT,   FcTypeString },
     { FC_EMBOLDEN,     FcTypeBool },
     { FC_EMBEDDED_BITMAP,   FcTypeBool },
+    { FC_ANY_METRICS,   FcTypeBool },
 };
 
 #define NUM_OBJECT_TYPES    (sizeof _FcBaseObjectTypes / sizeof 
_FcBaseObjectTypes[0])
diff -u pango1.0-1.12.1/debian/control pango1.0-1.12.1/debian/control
--- pango1.0-1.12.1/debian/control
+++ pango1.0-1.12.1/debian/control
@@ -2,7 +2,7 @@
 Section: libs
 Priority: optional
 Maintainer: Sebastien Bacher <[EMAIL PROTECTED]>
-Uploaders: Debian GNOME Maintainers <[EMAIL PROTECTED]>, Akira TAGOH <[EMAIL 
PROTECTED]>, Andreas Rottmann <[EMAIL PROTECTED]>, Andrew Lau <[EMAIL 
PROTECTED]>, Carlos Perelló Marín <[EMAIL PROTECTED]>, Clément Stenac 
<[EMAIL PROTECTED]>, Ed Boraas <[EMAIL PROTECTED]>, Edd Dumbill <[EMAIL 
PROTECTED]>, Emil Soleyman-Zomalan <[EMAIL PROTECTED]>, Guilherme de S. Pastore 
<[EMAIL PROTECTED]>, Gustavo Noronha Silva <[EMAIL PROTECTED]>, J.H.M. Dassen 
(Ray) <[EMAIL PROTECTED]>, Joe Drew <[EMAIL PROTECTED]>, Johannes Rohr <[EMAIL 
PROTECTED]>, Jordi Mallach <[EMAIL PROTECTED]>, Jose Carlos Garcia Sogo <[EMAIL 
PROTECTED]>, Josselin Mouette <[EMAIL PROTECTED]>, Loic Minier <[EMAIL 
PROTECTED]>, Marc HE Brockschmidt <[EMAIL PROTECTED]>, Ondřej Surý <[EMAIL 
PROTECTED]>, Rob Bradford <[EMAIL PROTECTED]>, Robert McQueen <[EMAIL 
PROTECTED]>, Ross Burton <[EMAIL PROTECTED]>, Sjoerd Simons <[EMAIL 
PROTECTED]>, Takuo KITAME <[EMAIL PROTECTED]>
+Uploaders: Debian GNOME Maintainers <[EMAIL PROTECTED]>, Akira TAGOH <[EMAIL 
PROTECTED]>, Andreas Rottmann <[EMAIL PROTECTED]>, Andrew Lau <[EMAIL 
PROTECTED]>, Carlos Perelló Marín <[EMAIL PROTECTED]>, Ed Boraas <[EMAIL 
PROTECTED]>, Edd Dumbill <[EMAIL PROTECTED]>, Emil Soleyman-Zomalan <[EMAIL 
PROTECTED]>, Gustavo Noronha Silva <[EMAIL PROTECTED]>, J.H.M. Dassen (Ray) 
<[EMAIL PROTECTED]>, Joe Drew <[EMAIL PROTECTED]>, Johannes Rohr <[EMAIL 
PROTECTED]>, Jordi Mallach <[EMAIL PROTECTED]>, Jose Carlos Garcia Sogo <[EMAIL 
PROTECTED]>, Josselin Mouette <[EMAIL PROTECTED]>, Marc HE Brockschmidt <[EMAIL 
PROTECTED]>, Ondřej Surý <[EMAIL PROTECTED]>, Rob Bradford <[EMAIL 
PROTECTED]>, Robert McQueen <[EMAIL PROTECTED]>, Ross Burton <[EMAIL 
PROTECTED]>, Sjoerd Simons <[EMAIL PROTECTED]>, Takuo KITAME <[EMAIL PROTECTED]>
 Build-Depends: debhelper (>= 4.9.12), libfreetype6-dev (>= 2.1.7), libx11-dev, 
libxrender-dev, libxt-dev, libglib2.0-dev (>= 2.10.0), pkg-config, defoma (>= 
0.11.1), libxft-dev, libfontconfig1-dev (>= 2.1.91), autotools-dev, po-debconf, 
gnome-pkg-tools, libcairo2-dev (>= 1.0.0)
 Standards-Version: 3.6.2
 
diff -u pango1.0-1.12.1/debian/changelog pango1.0-1.12.1/debian/changelog
--- pango1.0-1.12.1/debian/changelog
+++ pango1.0-1.12.1/debian/changelog
@@ -1,3 +1,20 @@
+pango1.0 (1.12.1-1ubuntu3) dapper; urgency=low
+
+  * Correct version for build-dependency on fontconfig, for version
+    with FC_ANY_METRICS.
+
+ -- Ian Jackson <[EMAIL PROTECTED]>  Mon, 24 Apr 2006 11:09:40 +0100
+
+pango1.0 (1.12.1-1ubuntu2) dapper; urgency=low
+
+  * Turn on FC_ANY_METRICS whenever looking up fonts with fontconfig.
+    This lets fontconfig's configuration know that we don't care about
+    getting a font with exactly the same shape as the family we asked for.
+    This fixes the (eg) firefox vs. (eg) evince font metrics ugliness
+    problem.
+
+ -- Ian Jackson <[EMAIL PROTECTED]>  Wed, 19 Apr 2006 12:48:06 +0100
+
 pango1.0 (1.12.1-1ubuntu1) dapper; urgency=low
 
   * Sync with Debian
only in patch2:
unchanged:
--- pango1.0-1.12.1.orig/debian/patches/anymetrics.patch
+++ pango1.0-1.12.1/debian/patches/anymetrics.patch
@@ -0,0 +1,52 @@
+--- pango-1.12.1/pango/pangoft2.c~     2006-02-21 10:12:01.000000000 +0000
++++ pango-1.12.1/pango/pangoft2.c      2006-04-19 12:43:07.000000000 +0100
+@@ -98,6 +98,7 @@
+   sans = FcPatternBuild (NULL,
+                        FC_FAMILY,     FcTypeString, "sans",
+                        FC_PIXEL_SIZE, FcTypeDouble, (double)ft2font->size / 
PANGO_SCALE,
++                       FC_ANY_METRICS, FcTypeBool, FcTrue,
+                        NULL);
+   
+   matched = FcFontMatch (NULL, sans, &result);
+--- pango-1.12.1/pango/pangofc-fontmap.c~      2006-02-21 10:12:01.000000000 
+0000
++++ pango-1.12.1/pango/pangofc-fontmap.c       2006-04-19 12:42:50.000000000 
+0100
+@@ -822,6 +822,7 @@
+ #endif
+                           FC_SIZE,  FcTypeDouble,  pixel_size * (72. / dpi),
+                           FC_PIXEL_SIZE,  FcTypeDouble,  pixel_size,
++                          FC_ANY_METRICS, FcTypeBool, FcTrue,
+                           NULL);
+ 
+   families = g_strsplit (pango_font_description_get_family (description), 
",", -1);
+@@ -975,6 +976,7 @@
+       FcPattern *tmp = FcPatternBuild (NULL,
+                                      FC_FAMILY, FcTypeString, "Sans",
+                                      FC_SIZE,   FcTypeDouble, 10.,
++                                     FC_ANY_METRICS, FcTypeBool, FcTrue,
+                                      NULL);
+       if (tmp)
+       {
+@@ -1651,6 +1653,7 @@
+   match_pattern = FcPatternBuild (NULL,
+                                 FC_FAMILY, FcTypeString, 
fcfamily->family_name,
+                                 FC_STYLE, FcTypeString, fcface->style,
++                                FC_ANY_METRICS, FcTypeBool, FcTrue,
+                                 NULL);
+ 
+   g_assert (match_pattern);
+@@ -1703,6 +1706,7 @@
+   pattern = FcPatternCreate ();
+   FcPatternAddString (pattern, FC_FAMILY, fcface->family->family_name);
+   FcPatternAddString (pattern, FC_STYLE, fcface->style);
++  FcPatternAddBool (pattern, FC_ANY_METRICS, FcTrue);
+ 
+   objectset = FcObjectSetCreate ();
+   FcObjectSetAdd (objectset, FC_PIXEL_SIZE);
+@@ -1856,6 +1860,7 @@
+         FcObjectSet *os = FcObjectSetBuild (FC_STYLE, NULL);
+         FcPattern *pat = FcPatternBuild (NULL, 
+                                          FC_FAMILY, FcTypeString, 
fcfamily->family_name,
++                                         FC_ANY_METRICS, FcTypeBool, FcTrue,
+                                          NULL);
+       
+         fontset = FcFontList (NULL, pat, os);

Reply via email to