• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Sub pixel line positioning for text drawing
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Prev by Date: Re: Refactoring tools available for Cocoa / ObjC?
  • Next by Date: Re: Confused with modal sessions
  • Previous by thread: Re: Confused with modal sessions
  • Next by thread: Re: Incorrect flipping when manually drawing NSCells (was: Fwd: -isFlipped not working right when drawing IconAndTextCell to NSImage)
  • Index(es):
    • Date
    • Thread