ArchiveOrangemail archive

Discussion and help for CoreText programming topics.


coretext-dev.lists.apple.com
(List home) (Recent threads) (100 other Apple lists)

Subscription Options

  • RSS or Atom: Read-only subscription using a browser or aggregator. This is the recommended way if you don't need to send messages to the list. You can learn more about feed syndication and clients here.
  • Conventional: All messages are delivered to your mail address, and you can reply. To subscribe, send an email to the list's subscribe address with "subscribe" in the subject line, or visit the list's homepage here.
  • Low traffic list: less than 3 messages per day
  • This list contains about 626 messages, beginning Oct 2009
  • 0 messages added yesterday
Report the Spam
This button sends a spam report to the moderator. Please use it sparingly. For other removal requests, read this.
Are you sure? yes no

Missing leading?

Ad
David F. 1280797726Tue, 03 Aug 2010 01:08:46 +0000 (UTC)
Using a CFFramesetter to layout a paragraph of text results in lines with more leading than if I use a CFTypesetter, create CTLines manually and lay them out using the metrics from CTLineGetTypographicBounds().

Where is CFFramesetter getting the extra leading from?

Any ideas?

Thanks,
David
Ned Holbrook 1280814065Tue, 03 Aug 2010 05:41:05 +0000 (UTC)
On Aug 2, 2010, at 6:08 PM, David F. wrote:

> Using a CFFramesetter to layout a paragraph of text results in lines with more leading than if I use a CFTypesetter, create CTLines manually and lay them out using the metrics from CTLineGetTypographicBounds().
> 
> Where is CFFramesetter getting the extra leading from?
> 
> Any ideas?CTFramesetter may adjust the effective line height for certain fonts that don't allow enough space for common characters.

Ned
David F. 1280942985Wed, 04 Aug 2010 17:29:45 +0000 (UTC)
On Aug 2, 2010, at 11:40 PM, Ned Holbrook wrote:

> On Aug 2, 2010, at 6:08 PM, David F. wrote:
> 
>> Using a CFFramesetter to layout a paragraph of text results in lines with more leading than if I use a CFTypesetter, create CTLines manually and lay them out using the metrics from CTLineGetTypographicBounds().
>> 
>> Where is CFFramesetter getting the extra leading from?
>> 
>> Any ideas?
> 
> 
> CTFramesetter may adjust the effective line height for certain fonts that don't allow enough space for common characters.OK, I am seeing that the difference in line height is font dependent:  Times Roman and Helvetica are getting extra spacing while Georgia is not.

So how does CTFramesetter decide to adjust the effective line height?  Is this information I can get from NSFont?

Here's a screenshot showing the difference in line spacing for Times Roman 16pt.  Left column is laid out with CTFramesetter.  Right column is laid out with CTTypesetter.

  http://dl.dropbox.com/u/9763962/LeadingDiffer...

Thanks,
David
Gordon Apple 1280945247Wed, 04 Aug 2010 18:07:27 +0000 (UTC)
I'm currently also fighting the battle of fonts, leading, and line spacing.
It's not helped that CT and CTFontRef treat descent as positive and UIFont
treats descent as negative.

For testing, I started painting alternating backgrounds under my lines, so I
could see what is happening.

Again, the docs are useless on much of this stuff, requiring extensive
experimentation.On 8/4/10 12:29 PM, "David F."  wrote:

> 
> On Aug 2, 2010, at 11:40 PM, Ned Holbrook wrote:
> 
>> On Aug 2, 2010, at 6:08 PM, David F. wrote:
>> 
>>> Using a CFFramesetter to layout a paragraph of text results in lines with
>>> more leading than if I use a CFTypesetter, create CTLines manually and lay
>>> them out using the metrics from CTLineGetTypographicBounds().
>>> 
>>> Where is CFFramesetter getting the extra leading from?
>>> 
>>> Any ideas?
>> 
>> 
>> CTFramesetter may adjust the effective line height for certain fonts that
>> don't allow enough space for common characters.
> 
> OK, I am seeing that the difference in line height is font dependent:  Times
> Roman and Helvetica are getting extra spacing while Georgia is not.
> 
> So how does CTFramesetter decide to adjust the effective line height?  Is this
> information I can get from NSFont?
> 
> Here's a screenshot showing the difference in line spacing for Times Roman
> 16pt.  Left column is laid out with CTFramesetter.  Right column is laid out
> with CTTypesetter.
> 
>   http://dl.dropbox.com/u/9763962/LeadingDiffer...
> 
> Thanks,
> David
> 
> 
>  _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Coretext-dev mailing list      
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/corete...
> 
> This email sent to 
David F. 1280980930Thu, 05 Aug 2010 04:02:10 +0000 (UTC)
On OS X 10.6:  If I use a CTFramesetter to layout a paragraph of text, all in Times Roman 16pt, grab the origins for the CTLines out of the CTFrame using CTFrameGetLineOrigins() and then calculate the line height for the lines by subtracting pairs of origins, I get 19.200012 (+/- ~0.000061).

If I call CTLineGetTypographicBounds() on each of the CTLines in the CTFrame I get: ascent=12.0, descent=4.0 and leading=0.0.

So the difference between the line height calculated from the typographic bounds (16.0) and the line height used by the framesetter (19.2) is 3.2 pixels.

If I instantiate an NSLayoutManager and call defaultLineHeightForFont I get 19.0.  Close!  But I'm still missing 0.2 pixels.

If I also ask the NSLayoutManager for the defaultBaselineOffsetForFont, it tells me 15.0.  Interesting.  15.0 plus the regular font descender (4.0) plus the regular font leading (0.0) is 19.0.

Now I notice that the line origin for the very first CTLine is 15.2 pixels below the top of my CTFrame.

Aha!

So there isn't any extra leading here.  There is extra baseline offset: 15.2 pixels versus only 12.0 pixels for the font ascent.

So, can anyone tell me where this baseline offset of 15.2 is coming from?

Thanks,
DavidOn Aug 4, 2010, at 11:29 AM, David F. wrote:

> 
> On Aug 2, 2010, at 11:40 PM, Ned Holbrook wrote:
> 
>> On Aug 2, 2010, at 6:08 PM, David F. wrote:
>> 
>>> Using a CFFramesetter to layout a paragraph of text results in lines with more leading than if I use a CFTypesetter, create CTLines manually and lay them out using the metrics from CTLineGetTypographicBounds().
>>> 
>>> Where is CFFramesetter getting the extra leading from?
>>> 
>>> Any ideas?
>> 
>> 
>> CTFramesetter may adjust the effective line height for certain fonts that don't allow enough space for common characters.
> 
> OK, I am seeing that the difference in line height is font dependent:  Times Roman and Helvetica are getting extra spacing while Georgia is not.
> 
> So how does CTFramesetter decide to adjust the effective line height?  Is this information I can get from NSFont?
> 
> Here's a screenshot showing the difference in line spacing for Times Roman 16pt.  Left column is laid out with CTFramesetter.  Right column is laid out with CTTypesetter.
> 
>  http://dl.dropbox.com/u/9763962/LeadingDiffer...
> 
> Thanks,
> David
> 
> 
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Coretext-dev mailing list      
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/corete...
> 
> This email sent to 
Ned Holbrook 1280984226Thu, 05 Aug 2010 04:57:06 +0000 (UTC)
On Aug 4, 2010, at 9:01 PM, David F. wrote:

> So, can anyone tell me where this baseline offset of 15.2 is coming from?As I noted before, CTFramesetter may adjust the effective line height depending on the font. The problem is that CTFramesetter has no way of knowing where the frame is relative to other elements. As such, it makes conservative adjustments to avoid known cases where glyphs for normal characters in otherwise normal fonts would end up drawing outside the supplied frame.

In the end, CTFramesetter is just a convenience. It can be awfully convenient, to be sure, but in the end it's not got (much) magic. If you don't like the way the default framesetter behaves, it should be fairly straightforward to roll your own. Even better, please file a bug if there are behaviors you want more control over.

Ned
David F. 1281042758Thu, 05 Aug 2010 21:12:38 +0000 (UTC)
On Aug 4, 2010, at 10:56 PM, Ned Holbrook wrote:

> If you don't like the way the default framesetter behaves, it should be fairly straightforward to roll your own.And my experience so far mostly confirms that it is straightforward.  (Handling ParagraphStyles on my own is a pain, but, as you say, straightforward.)

Except that I don't know how to calculate the line height for CTLines.

As you pointed out, for some common characters in some common fonts, the typographic bounds don't prevent glyphs from overlapping.  So I shouldn't calculate line height as ascent + descent + leading.

But Core Text doesn't implement anything like NSLayoutManager defaultLineHeightForFont--which appears (according to both experience and the documentation[1]) to take into account ascenders and descenders that extend beyond the font's typographic bounds.

So if I'm OS X, I can call NSLayoutManager defaultLineHeightForFont to get the line height.

If I'm on iOS 3.2 I'm out of luck.

If I'm on iOS 4.0 maybe I can call UIFont lineHeight?  Does it try to return a line height that accounts for out-of-bounds ascenders and descenders?  (I'd try it myself, but I don't have the 4.0 SDK.)

So, that's my frustration.  I don't know how to calculate line height.

Thanks,
David

[1]  http://developer.apple.com/mac/library/docume...
Home | About | Privacy