Re: How does NSButtonCell do its drawing?
Re: How does NSButtonCell do its drawing?
- Subject: Re: How does NSButtonCell do its drawing?
- From: Uli Kusterer <email@hidden>
- Date: Fri, 1 Feb 2008 12:00:58 +0100
On 21.01.2008, at 20:15, Ricky Sharp wrote:
For me, it was as simple as using NSAttributedString instances,
sending a "size" message to get the NSSize and then exactly
centering a box of that width/height within my cell's bounds. Then,
I just use drawInRect: to do the rendering.
Thanks for the answer, sorry for the delay.
I'm doing something similar for one-line text. The trouble is, I'd
like to be able to also correctly measure wrapped multi-line text. I
was hoping that there was a way to just create and cache the text
system objects and measure those. The -size method is good for un-
wrapped text, but of course creates and tears down its text system
objects every time, which I was hoping to be able to avoid, as this
text is going to be moved around a lot.
My thinking was that if I knew how the button cell makes its
Japanese text center correctly, I might be able to do the same for
Japanese.
Using the baseline approach (computing, e.g. the "x" height, or
working with ascenders/descenders) always yielding incorrect results
(at least in my eyes). Probably similar "wrong" results as you're
seeing.
Yes, that's what surprises me. I thought about not accounting for
the descent for Japanese, but that's no solution with English words
(e.g. my app's name) interspersed with the Japanese stuff, not to
mention there seems to be no way (except looking at each character
directly and comparing its Unicode range to a table) to detect if a
string contains Japanese glyphs.
I've been using this approach extensively with Unicode text (past 3
years). I always use systemFontOfSize: which ultimately renders in
the appropriate font for a particular language. I've used many
different sizes ranging from 18 pt to 48 pt. Since my baseline is
Tiger, I've only though looked at this on 10.4 and later. I would
hope 10.3 and even earlier would produce similar, if not identical
output.
I only need 10.4 and up at the moment, so that's not a thing I'd
have to worry about. Though I do want to use some custom fonts, where
available and applicable (i.e. at least in Latin text). I'm trying to
size my text to exactly fit a button, and things just look horribly
off as soon as there's a word of Japanese text.
Output also looked good no matter what the res-ind scaling factor
(0.5 through 3.0 to include non-integral ones like 1.33333).
I've also specifically looked at Japanese (Kanji, Hiragana and
Katakana characters) and haven't noticed anything strange.
(...)
Finally, here are some screen shots from my app you can use to
determine if my centering logic would appeal to you:
<http://www.instantinteractive.com/drills_slides.html>
It doesn't seem to be as bad at larger text sizes (which is what
you're using), but in many cases I'm working with the small system
font. I even tried scaling the CGContext down and drawing at larger
sizes, hoping that text measurement might be more accurate, but that
didn't help. I'm really curious why NSButtonCell can do it right, and
for me it's this iffy. Does it turn off the leading or something?
Cheers,
-- M. Uli Kusterer
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden