Reputation: 36073
Using DirectWrite and Direct2D1, I am attempting to mimic the rendering that Illustrator CS6 does to an area text box. CS6 has an option where the baseline can be placed at a distance from the top of the area text box that equals the font's "em box size". For example, using Trajan Pro font, 100pt point size, the baseline is 87.5pt from the top of the area text box.
From an IDWriteFontFace object, I can get the ascent, descent, designUnitsPerEm values, etc.
What seems to be missing is the baseline location relative to the top of the em box.
Is there a way to get the baseline position in design units relative to the top of the em box?
DWRITE_FONT_METRICS doesn't have it. I looked at DWRITE_LINE_METRICS, but it's baseline value is ascent + lineGap and does not match.
Upvotes: 3
Views: 1505
Reputation: 11
This is only a partial answer, but here goes The way I handle this in similar scenario's is:
EM height - Ascent = baseline
What I'm not certain about is how or even if linegap should be applied. Many fonts have a zero line gap so it's not relevent, in fact in the css world that I think I'm familiar with it's not uncommon to sort of Add in a line gap by indicating that line hieght is 1.2*EM height. When I really need to know the distribution of that gap I've always lumped it in as being just after decent hieght, but I'm not totally convinced that's 100% correct, it's just been good enough for what I do.
In general, EM height = Ascent + Descent + linegap in that order. Too, I believe it is totally valid to have a negative line gap so however it get's distributed, all on the bottom, half on top, half on bottom (which I figure wouldn't make sense really, but I could be wrong), or whatever, you'll need to be consistent about it. Hope this helps.
Upvotes: 1