Comment 12 for bug 42559

Revision history for this message
In , Ian Jackson (iwj) wrote : Re: Bug#299697: fontconfig: Still unresolved

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.