Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Core Text line height



Subtracting ascent with descent is correct. Descent is actually a negative number, meaning that the glyph extends downward. So to get the difference between the two (the text height) you can either do:

ascent + fabsf(descent)

or

ascent - descent (subtracting a negative is the same as adding)


On Mar 17, 2008, at 10:02 AM, Luigi Castelli wrote:

Hi there,

I am using Core Text to draw a line of text exactly centered in the middle of a rectangle.

For reasons that I am not going to explain I can't/don't want to use the image bounds of the line.
So, in order to retrieve the line metrics I am using the CTLineGetTypographicBounds function.


The width returned by the function perfectly centers my line in the rectangle and I am happy with it.
However, I still don't seem to find a way to retrieve the correct height in order for the line to be perfectly centered.


In theory the correct way to get the line height is to add the ascent and descent together (no leading).
In the majority of the cases this leaves the font too close to the lower edge of my rectangle.


I also tried to use the font X-height, but that doesn't really centers my line of text any better.

I found out that the method that - even though far from perfect - works best is to subtract the descent to the ascent and use that measure as the line height.
However that something I discovered by trial and error and doesn't really make sense to me.


Now, I understand that different fonts have different ways of adhering to the standard font metric rules. (some probably don't)
However is there a more accurate way to get the correct line height to vertically center text, or is what I am after like a moving target ?


Any help is highly appreciated.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Quartz-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/quartz-dev/email@hidden

This email sent to email@hidden
References: 
 >Core Text line height (From: Luigi Castelli <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.