On Sat, 27 Jul 2002, Owen Taylor wrote:
> If you believe a font is monospaced, then you can determine it's
> width by asking for the width of any character.
Is there a way of doing that short of creating a pango layout?
Thanks very much for your responses to my questions. On the business
of selecting monospaced fonts I have hacked up a version of gtkfontsel
that "works for me". It's mostly identical to the existing fontsel
except it's invoked with
gtk_font_selection_hack_dialog_new (const gchar *title,
GtkFontFilterType filter)
(and all the public functions have "hack" inserted to avoid colliding
with the existing font selector).
GtkFontFilterType can be
GTK_FONT_HACK_ALL - no filter is applied
GTK_FONT_HACK_LATIN - filters to Latin text fonts only
GTK_FONT_HACK_LATIN_MONO - filters to monospaced Latin text
fonts.
The heuristic for the LATIN filter is that the font contains the
letter 'A' with PANGO_COVERAGE_EXACT. The heuristic for LATIN_MONO is
that in addition the width of the letter 'i' equals the width of the
letter 'W'. I suppose there may be pathological cases that could
defeat these rules.
The dialog is a little slow to appear when first opened, as it checks
through the list of fonts, but on the second and subsequent accesses
it consults a cache.
I'd be interested in any reactions to this. I'm sure it could be done
better.
I'm attaching a small tarfile with the code.
Allin Cottrell.
Attachment:
fontsel_hack.tgz
Description: Binary data