briangonzalez
briangonzalez

Reputation: 1616

Poorly rendered text (NSFont) in MacRuby/Cocoa. Any advice?

I have a small MacRuby app that displays some text inside a NSTextView. I have a method called make_label() that builds an NSTextView with some text and returns it, which I use to add to another NSView via addSubview()

make_label() looks like this:

def make_label( x, y, width, height, color, font_size, text )
  label = NSTextView.alloc.initWithFrame( NSMakeRect( x, y, width, height) )
  font = NSFont.systemFontOfSize(font_size)
  label.setFont( font )
  label.insertText( text )
  label.setTextColor( color )
  label.setDrawsBackground(false)
  label.setRichText(true)
  label.setEditable(false)
  label.setSelectable(false)
  label
end

My question is, how come my text looks so poorly rendered? It looks very pixelated and not antialiased at all (from what I can see).

Click here for screenshot

This screenshot shows 2 different sizes of the font, with the same phenomenon.

Upvotes: 1

Views: 346

Answers (2)

briangonzalez
briangonzalez

Reputation: 1616

The culprit was setWantsLayer(true) which was called for the view I was drawing in. I deleted that line and I also needed to label.setDrawsBackground(false) as joerick described.

Upvotes: 1

joerick
joerick

Reputation: 16458

Cocoa can't draw sub-pixel antialiased text if it's rendering to a context that isn't opaque.

I come from the objective-C side, so I'm guessing a bit, but try setting label.setDrawsBackground(false) to true.

Upvotes: 1

Related Questions