[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[ft-devel] discrepancy in underline offset
From: |
Graham Asher |
Subject: |
[ft-devel] discrepancy in underline offset |
Date: |
Wed, 20 Jun 2007 16:31:15 +0100 |
Dear FreeTypers,
the definition of FT_FaceRec_::underline_position, given in freetype.h, is:
/* underline_position :: The position, in font units, of the
*/
/* underline line for this face. It's the
*/
/* center of the underlining stem. Only
*/
/* relevant for scalable formats.
*/
This field is copied from the postscript table for TrueType fonts, using
this code in sfobjs.c:
root->underline_position = face->postscript.underlinePosition;
However, the definition of postscript.underlinePosition is (according to
http://www.microsoft.com/OpenType/OTSpec/post.htm):
"
This is the suggested distance of the top of the underline from the baseline
(negative values indicate below baseline).
The PostScript definition of this FontInfo dictionary key (the y coordinate
of the center of the stroke) is not used for historical reasons. The value
of the PostScript key may be calculated by subtracting half the
underlineThickness from the value of this field.
"
So, to sum up: the first definition refers to the centre of the stroke; the
second to the top edge.
Thus (depending on whether there are other discrepancies that I have not had
time to search for) we ought to either change the definition of
FT_FaceRec_::underline_position, or change the code in sfobjs.c.
I would favour the first course of action; it is easier (for me, in my code
- this is a personal view) to draw the rectangle for an underline using its
top edge as a reference point, and feels more natural. But that may
contradict long-standing policy, depending on what users have done with this
code. It changes the API, but only if that API has been read, understood and
acted upon correctly. That cannot be the case for TrueType fonts because it
produces incorrect results: the underline is too far up and touches the
baseline at small sizes.
But if we choose the second course of action the patch is this: change line
890 of sfobjs.c to:
root->underline_position =
(FT_Short)(face->postscript.underlinePosition -
(face->postscript.underlineThickness / 2));
I have tested it and it does the job.
Best regards,
Graham Asher
- [ft-devel] discrepancy in underline offset,
Graham Asher <=