Looks like (1) was the problem. Filling with white before drawing the text worked. Thanks!
On 2010-06-27, at 4:47 PM, Ken Ferry wrote: > I don't think this is likely to be the problem in this case. Text looks good > no matter where you draw it. > > In this case, I think the problem is more likely either > (1) A lack of what Quartz calls font smoothing, more popularly known as > subpixel rendering. > (2) The resulting image being drawn non-pixel aligned, incurring double > anti-aliasing effects. > > We would be able to tell from a screenshot. > > I would guess (1) is more likely. Dave, if you were to read that wikipedia > article and think about it carefully, you would realize that doing full > featured transparency with font smoothing would require six channels (red, > red alpha, green, green alpha, blue, blue alpha) instead of the usual ARGB > backing stores bitmaps use. The easiest fix when applicable is to make sure > the image isn't transparent. Fill the NSImage with an opaque color before > doing the text drawing. > > Re: 2, -[NSView centerScanRect:] will pixel-align a rect in a view in a > default way. If the default way doesn't work for you, convert to pixels > (-[NSView convertRectToBase:]), round/floor/ceil as desired, and convert back > (-[NSView convertRectFromBase:]). > > Uli, whenever you do "+ 0.5" or something like that, you're very likely > making an assumption that one unit the local coordinate system is one pixel, > and that the current coordinate system is aligned to pixels. I.e., latent > bug. :-) Consider the approaches in the previous paragraph. Also, the > reason people generally find themselves adding 0.5 is that stroking a line in > quartz centers the drawing on the line. So, if you want to _inscribe_ a path > in a given pixel aligned rect, you want to inset the rect by half the stroke > width first. Since the most common stroke width is 1.0, people have > internalized +0.5 as being somewhat magic. Dave isn't stroking anything. > > -Ken > Cocoa Frameworks > > On Sun, Jun 27, 2010 at 1:29 PM, Uli Kusterer <[email protected]> > wrote: > On 27.06.2010, at 22:12, Dave Fernandes wrote: > > I'm trying to render text in System font in an NSImage as shown below. The > > NSImage is displayed *unscaled* in an NSImageView. However, the text does > > not look as good as when rendered in an NSView. Is there any way to get > > crisp clean text in an NSImage? > > Try drawing the text offset by 0.5 points. Fuzzy drawing like that usually > means that, at some point, you're drawing "between pixels". Since the > mathematical coordinate system actually passes each pixel at the upper left, > to get a line that lies on a pixel, you generally have to draw offset by 0.5 > pt to hit a pixel straight on. OTOH, I think drawing an NSImage usually needs > to be done at a 0,0 coordinate (because the upper left of an NSImage is also > at a full logical coordinate and everything has already been drawn offset > twice). > > If it's not your drawing code, you may have a view whose coordinates are not > on a x.0 boundary, which can cause all sorts of weird things like that > because it indirectly causes drawing like that. You can see that in the NIB > by looking at the numbers in the inspector. Keep in mind that the coordinates > of a superview could be wrong in this case as well. > > -- Uli Kusterer > "The Witnesses of TeachText are everywhere..." > http://www.masters-of-the-void.com > > > > _______________________________________________ > > Cocoa-dev mailing list ([email protected]) > > 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: > http://lists.apple.com/mailman/options/cocoa-dev/kenferry%40gmail.com > > This email sent to [email protected] > _______________________________________________ Cocoa-dev mailing list ([email protected]) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [email protected]
