Use commas in FontDescriptions
Tip: always use a comma ',' when constructing a new Pango FontDescription. Otherwise, if your font family has a space in its name (as most do), the font name parser may mistakenly assume the last word of the font name is a size or variant or…
The error I was getting was that
desc = new FontDescription("Times New Roman");
was giving me "Times New" — which, since it doesn’t exist, was resulting in a fallback to the system default font "Deja Vu Sans". Shit. The fix was to use the comma separator even though I wasn’t specifying weight or size in the string:
desc = new FontDescription("Times New Roman,");
Of course, if I read the documentation I wrote years ago for our binding of pango_font_description_from_string() I’d see that I said:
The trailing ‘,’ on the family list is optional but a good idea when a font family you’re targeting includes a space in its name
so apparently I already knew this. Grr. Turns out if I’d just used setters I would have been ok too:
desc = new FontDescription();
desc.setFamily("Times New Roman");
desc.setSize(16.0);
and so on. But if you’re using the useful pango-view command line tool, be aware that the --font option is a font description string that’ll be parsed and you’ll need the comma.
Don’t worry. I’m not using corefonts for anything important :). Just needed it to make make a screenshot.
AfC
