On font dialog default sample string selection
- From: Behdad Esfahbod <behdad behdad org>
- To: Henrique Carvalho Alves <hcarvalhoalves gmail com>
- Cc: gtk-devel-list gnome org, Sven Neumann <sven gimp org>, gtk-i18n-list gnome org
- Subject: On font dialog default sample string selection
- Date: Mon, 18 Aug 2008 00:14:54 -0400
Henrique Carvalho Alves wrote:
> 2008/8/17 Henrique Carvalho Alves <hcarvalhoalves gmail com>:
>> 2008/8/17 Sven Neumann <sven gimp org>:
>>> Using the font name for preview does not work. You could try to add some
>>> heuristics that select a reasonable text depending on font coverage. But
>>> that is likely going to fail in some corner cases. So whatever you end
>>> up doing, you should give the user a way to change the text used for
>> You're right. The current font dialog also fails for that (see Ubuntu,
>> which ships some fonts for other languages, and the preview just
>> presents a default "abcdABCDE" text in sans). I too guess finding the
>> glyph coverage for the font is hard and not reliable. As stated on the
>> last reply, making the preview editable is better, of course. The
>> question here: is using the font name and size as preview text a
>> better default?
The text should be editable, sure.
It's still useful to have a better default preview text. It may also be
useful to have a drop down of some other preset texts the font supports.
For preset texts, there's a lot around:
- For Latin: The quick brown... , abcd..., "Hamburgfonts" , Lorem
- Font samples for other lagnauges 
- Pangrams for other languages ,
- When no languages are available, "I can eat glass" 
In fact, these can go right in Pango. There's already API for that:
pango_language_get_sample_string(). There's a bug to make that more useful
. I may have been motivated now to fix that for tomorrow's release.
Note that Gtk+ can also use a special translatable string to let translators
decide what string should be used for their language. Let's call this
"current locale's preferred sample string".
I have also added API to Pango already to be able to tell if a font can render
a particular string. Just turn fallback off in your layout
(pango_attr_fallback_new()), then use pango_layout_get_unknown_glyphs_count()
and divide that by the number of characters in the string.
Next is to decide which language to show by default, and which ones to show in
the drop down. Here's what I propose:
- If the font can render the current locale's preferred sample string, that
should be the default, otherwise pick one of the supported strings
arbitrarily. For bonus, prefer those that use scripts other than Latin.
Among those, take one that uses the PangoScript with smaller/larger value,
depending on whether you want to promote common or exotic languages :P.
- To the list add all strings that can be rendered by the font. If the
Pango fontmap being used is not a PangoFcFontMap, simply add the Latin ones
(other than the current locale's preferred sample string that is). If it is a
* Get a PangoFont of the font at hand (simply use any string and fallbacks
* Get the "pattern" GObject property of the PangoFont (which actually is a
PangoFcFont) which is a FcPattern *. Note that this fails with older Pango
versions, so be prepared for handling that.
* Fetch all the FC_LANG elements of the pattern.
* For all those languages, use pango_language_get_sample_string() and add
them. Note that that function returns a junk string if it doesn't know about
the language. This can be detected by comparing the return value to that of
That's all. I don't mind jumping in and implementing this when someone has a
patch against GTK+ to use the right widget there.
] [Thread Prev