[mythtv-users] MythArchive - blank title text

Michael T. Dean mtdean at thirdcontact.com
Thu Jul 12 02:26:23 UTC 2007


On 07/06/2007 01:38 PM, Paul Harrison wrote:
> I've also just started to see some font scaling problem after updating
> to current svn. I've not had time to look at the issue properly but the
> chap who posted this
> http://www.gossamer-threads.com/lists/mythtv/dev/277106 seems to think
> it's something to do with the new fonts that where updated in [13588] by
> stuartm.

As requested by me.  (Oops.  But, in my defense, who would have thought
a font upgrade would break a program?)

>  Try reverting back to the old fonts and see if that fixes it
> for you.

I finally got a chance to look into it.  The problem is with the
superscript/subscript "set asides" in the font (verified with testing as
described below and by comparing the fonts in FontForge).  In the old
font, not enough space was provided for the specified height/width of
the sub/superscripts.  That meant if you used the old font in a
text-layout program that used the font-specified values, the lines with
sub/superscripts would have to be "bumped" to make room for the
sub/superscripts.  (I.e. "normal" line spacing until you include a
superscript, then there's a big gap between the above line and the one
with the superscript--unless, of course, the app were really lazy, in
which case the superscript would overlap the above line.)  Most
text-layout programs (like OpenOffice.org, for example) don't tend to
use the font-specified values, though (they calculate their own sizes
and set asides or allow users to specify them or both).

The new font was changed so that rather than specify values for
sub/superscript size/set asides, it allowed the font creator program to
calculate them.  In so doing, the sub/superscripts became bigger and the
set aside became bigger by the amount the previous version's set aside
was lacking plus the difference in size of the sub/superscripts. 
Therefore, the font's metrics now indicate that a line of text is nearly
twice as tall as before.

Since PIL uses the font-specified height, rather than the actual glyph
height, MythArchive is now getting a value almost twice what it
previously got.  Since it seems MythArchive specifies "text box" sizes
that worked with the old height value in the font, it thinks the text
will no longer fit (in fact the text is the exact same size, but there's
blank space above and below it).

While I can create new fonts that specify the same font height as the
previous-version fonts, in doing so, we'll end up with fonts that differ
from upstream (and, perhaps, the same issue in the future--but that time
because we forgot to modify the font again).  However, my recommendation
would be to adjust the height (and probably position) of the "text
boxes" that are affected by the changed font.

Another option is to modify PIL to allow retrieving per-character size
information using FreeType's height member of the FT_Glyph_Metrics
structure (which, TTBOMK, is not currently possible), push that change
upstream, change MythArchive to find the height of the tallest glyph in
the text string using the new function, and get everyone to upgrade to
PIL 1.1.7; but I think you'll agree that won't work. :)  I've also heard
that aggdraw ( http://effbot.org/zone/pythondoc-aggdraw.htm ) does
better at font sizing/positioning, but I haven't tested it and don't
even know if it would work for what you're doing (and it would create a
new dependency, so it's probably not worth trying).

As I haven't yet used MythArchive (I watch and delete shows--never
archive any), I'm not volunteering to make the modifications I'm
recommending we make to the text boxes.  If no one else is willing to
fix the text positioning and fixing the problem falls on me (because I
encouraged the upgrade of the fonts), I'll just make custom versions of
the fonts (because doing so will only take minutes).

I'm guessing that fixing it properly would simply require someone's
modifying MythArchive's theme.xml files.  If so, this would be a great
job for someone who wants to contribute but who's not a coder.  :)

Mike

Details of testing:

I wrote a quick test script (attached, and, yeah, I'm sure it could be
cleaned up a /lot/ as it's my first ever Python script).  When executed
with the old and new font, I get:

$ ./fonttest.py Test old.png old/FreeSans.ttf 19
Loading font old/FreeSans.ttf, size 19
Font actual size (for "Test") is 38 by 21

$ ./fonttest.py Test new.png new/FreeSans.ttf 19
Loading font new/FreeSans.ttf, size 19
Font actual size (for "Test") is 38 by 36

Notice that the height it gives is different, just like Russell
noticed.  However, when you open up old.png and new.png, the text is
"identical" (I didn't do a pixel-for-pixel comparison, but the font size
is the same and it looks the same).  When I use GIMP's measuring tool, I
see the capital T is 14 pixels high--which is what I would expect (since
I'm not getting any descent).  If I use:

$ ./fonttest.py Testing old.png old/FreeSans.ttf 19
Loading font old/FreeSans.ttf, size 19
Font actual size (for "Testing") is 64 by 21

or

$ ./fonttest.py Testing new.png new/FreeSans.ttf 19
Loading font new/FreeSans.ttf, size 19
Font actual size (for "Testing") is 64 by 36

and measure from the top of the capital T to the bottom of the
lower-case g, the font is 19 pixels high--regardless of whether I used
the old or new--exactly as requested when the font was created.

However, the placement of the fonts is different (since I used the
calculated textheight to place the text on the very bottom of the
image.  The textheight is calculated by PIL by asking FreeType for the
font-specified height (which is generally not very useful as it's never
guaranteed to be the right size for all glyphs in the font).  Therefore,
text from the new font is not placed at the bottom of the image.

It seems MythArchive also uses the "calculated" text height for
placement, so the problem comes down to the text boxes being
sized/placed with the old (broken) font (that didn't have room for
sub/superscripts in the font-specified height) when MythArchive and its
themes were developed.
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: fonttest.py
Url: http://mythtv.org/pipermail/mythtv-users/attachments/20070711/30a6fa0b/attachment.diff 


More information about the mythtv-users mailing list