On 15. Mai 2005, at 23:51, Dietmar Planitzer wrote:
there are a couple of issues with your code which together are
probably the reason why it doesn't work as expected.
On May 15, 2005, at 9:17 PM, Bernhard Barkow wrote:
- (void)drawRect:(NSRect *)rect
The AppKit passes the dirty rect by value - not by reference. Thus,
this should be changed to -(void)drawRect: (NSRect)rect.
Wow, I didn't notice that...
// the drawRect method of my custom view
{
float frh, frw;
NSRect fr = [self frame];
The -frame method returns the view's bounding rectangle in terms of
the parent view's coordinate system. That's why most often what you
want here is the -bounds method which returns the view's bounding
rectangle in terms of its own coordinate system. The important
difference is that the origin of -frame is the origin of the view
relative to the parent view, while the origin of -bounds is de
facto always (0, 0), except when scrolling comes into play.
Ok, this has no effect in my special case, because I do a
transformation anyway, but it's good to keep in mind...
Normally, calling CGContextBeginPage, CGContextEndPage and
CGContextFlush from inside a -drawRect: method is not necessary, as
this stuff is already handled by the AppKit. You just need to
implement the code which does the actual drawing. AppKit
automatically makes sure that the graphic commands are only flushed
if really necessary, thus potentially improving drawing performance.
The fixed data type is special in the sense that the upper bits
hold the integer part of the fractional number while the lower bits
hold the fractional part. Thats why trying to assign an integer
straight to a fixed won't work as expected. Use the IntToFixed
function / macro instead: Fixed atsuSize = IntToFixed(72).
Ah, I think that was the main culprit! These are my first experiments
with Quartz, I guess I have to aquire a lot more background
knowledge. I changed everything to Long2Fix(), and now it works
perfectly.
Now, playing devils advocate for a second: a much simpler way to
draw Unicode text in Cocoa is to take advantage of the string
drawing methods which the AppKit adds to the NSString class via a
category. Thus, all of the above code could be replaced with
something like this:
Of course you are right, this is a much more elegant approach; it's
just a matter of performance: I have to draw about 20-30 strings in
similar style, so the ATSUI-approach seems to be more efficient
(although the user won't probably notice the difference on a modern
machine...).
Thanks a lot!
Bernhard Barkow
_______________________________________________
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