Sub pixel line positioning for text drawing
Sub pixel line positioning for text drawing
- Subject: Sub pixel line positioning for text drawing
- From: Tom Andersen <email@hidden>
- Date: Wed, 3 May 2006 11:25:23 -0400
When I draw an NSString with drawAtPoint, cocoa always draws the line
of text using the nearest _integer_ y coordinate as a baseline. This
is probably a 'good thing' for most applications, but for our list we
get inconsistent line to line spacing as the window is resized. In
short, it looks a bit ugly.
eg:
NSPoint thePoint;
thePoint.x = 50;
thePoint.y = 25.466;
NSString* aString = @"Some Text";
[aString drawAtPoint: thePoint withAttributes:someAttributes ];
// will draw a line that looks identical to one drawn like this:
thePoint.x = 50;
thePoint.y = 25;
[aString drawAtPoint: thePoint withAttributes:someAttributes ];
I would like the drawing to take place at y = 25.466, not 25.
The string draws antialiased. We are drawing into a standard NSView
drawRect call.
I found this from 2004: - is it relevant?
"
http://lists.apple.com/archives/quartz-dev/2004/Apr/msg00000.html
kATSUCGContextTag
.Specifies to use a Quartz context. When you use
this tag to set up a Quartz context, ATSUI uses an
8-bit, sub-pixel rendering. This method of
rendering positions glyph origins on fractional
points, which results in superior rendering
compared to ATSUIs default 4-bit pixel-aligned
rendering.
...
I am quite sure there is. TextEdit uses Cocoa (NSLayoutManager) which
does its own layout. For example if I render "Hello world" with
Cocoa, there are exactly 7 pixels between each letter, where ATSUI
puts 7.29 or something pixels between each letter (which is the width
found in the font, given in Em-units -- apparently Cocoa rounds off
glyph sizes/kernings!?!).
"
Is there any attribute, flag, etc I can set in cocoa or coregraphics
to do this, or will I have to render text by some other means? (ATSUI?)
Thanks for any feedback,
Tom Andersen
_______________________________________________
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