Re: Cropped Italic Letters
Re: Cropped Italic Letters
- Subject: Re: Cropped Italic Letters
- From: Ricky Sharp <email@hidden>
- Date: Wed, 23 Feb 2005 06:19:27 -0600
On Wednesday, February 23, 2005, at 02:08AM, Jesse Abram <email@hidden> wrote:
>I am currently working through Cocoa Programming For Mac OS X 2nd
>Edition, and I've encountered a problem while working on an exercise
>program. When I display an italic character in my view object, (nowhere
>near the edges), it is drastically cropped on the righthand side. The
>characters have a shadow as well, which is cropped slightly even when
>the text is not italic. I've pasted some of my code here, if anyone
>knows why this is happening, I would be very happy to hear.
I haven't worked with the italic style, but I can at least confirm the problems with shadows.
I filed a bug last December (<rdar://3910767>) entitled "Cocoa string drawing doesn't take shadow metrics in account".
I first noticed the problem when attempting to subclass NSTextView/NSTextViewCell where my text had the shadow attribute set. I then reproduced it in general (like your code did) and even in TextEdit.
A workaround is to alter the size of the rectangle to draw the string into. From experimentation, I've found that if you increase the width of the rectangle by 'shadow blur plus shadow x-offset' and increase the height by 'shadow blur plus shadow y-offset', you get good results. I used Photoshop to analyze screenshots. In all cases so far, I don't see any more clipping of the shadow.
But depending on the text justification and how your shadow is offset, you may still have problems. For example, if your shadow is physically offset upwards, you'll still get clipping. Same thing happens with right-justified text that has a shadow offset to the right.
But for the most part, shadows are to the right and downward so you can keep things simple. If you need to provide a general way of minimizing clipped shadows, I've found that left justifying the text and then "justifying" its pre-modified bounding rectangle works well.
One thing that I haven't looked at using is drawAtPoint:. This should work well with left-justified text that has a shadow to the right and downward. But for other justifications, shadow positions, it may be better to still work with drawInRect:.
--
Rick Sharp
Instant Interactive(tm)
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden