Text Not Anti-Aliased Inside NSView?

Discussion in 'Mac Programming' started by Darkroom, Dec 8, 2008.

  1. Darkroom Guest

    Darkroom

    Joined:
    Dec 15, 2006
    Location:
    Montréal, Canada
    #1
    wtf? :confused:

    the window on the left is from IB, which clearly shows nice, anti-aliased text. the window on the right is the running build with choppy text... what's up with that? previously i had placed the text inside an NSWindow and it looked fine, but ever since i started placing my text on views it all changed.

    any thoughts?
     

    Attached Files:

  2. BravoBug macrumors newbie

    Joined:
    Dec 8, 2008
    Location:
    Oregon, USA
    #2
    I remember running into this problem before, although I can't remember how I solved it. You may want to consider just drawing your strings into the view itself with the drawAtPoint or drawInRect methods:

    http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSString_AppKitAdditions/Reference/Reference.html
     
  3. Darkroom thread starter Guest

    Darkroom

    Joined:
    Dec 15, 2006
    Location:
    Montréal, Canada
    #3
    text seems to automatically anti-alias inside a normal NSView... the difference with these views is that they are added and replaced subviews of a window using core animation... i'm sure that has something to do with it, but i'm still very surprised that the text is not anti-aliasing automatically, and i have no idea how to fix it.

    however, i don't have much hope. i used Apple's own "Basic Cocoa Animations" app to learn how to do this, and i notice even in their own example the text has aliasing (look at Medium View): http://developer.apple.com/samplecode/BasicCocoaAnimations/index.html

    :(

    [edit] humm... just looking at other apps, i see they use this method (at least i think it's this method) to switch thru views, and their text is fine...
     
  4. Catfish_Man macrumors 68030

    Catfish_Man

    Joined:
    Sep 13, 2001
    Location:
    Portland, OR
    #4
    Subpixel AA is disabled in CoreAnimation layers. Did you by any chance set "wants layer" on the view?
     
  5. Darkroom thread starter Guest

    Darkroom

    Joined:
    Dec 15, 2006
    Location:
    Montréal, Canada
    #5
    yes i have this:

    Code:
    [[self contentView] setWantsLayer:YES];
    
    are you suggesting that if i set this to NO then the text will anti-alias? isn't this line of code required for this method to work?

    [EDIT] i changed all references to "setWantsLayer:NO" just to see what would happen. the text was no longer aliased and the animated resizing of the window frame from view to view still worked, but it no longer faded in and out of the views, which kinda ruins the nice effect and therefore doesn't really work for me :eek:
     
  6. HiRez macrumors 603

    HiRez

    Joined:
    Jan 6, 2004
    Location:
    Western US
    #6
    Right, you can either have antialiased text, or Core Animation, not both. (Apparently, I don't have personal experience in this but I've seen this topic come up a number of times). I think Apple's going to have to solve that, because it's a major inhibitor.
     
  7. Darkroom thread starter Guest

    Darkroom

    Joined:
    Dec 15, 2006
    Location:
    Montréal, Canada
    #7
    humm... that kinda sucks, and is pretty surprising... i guess i could use images of text instead? unless images in core animation layers are also choppy?
     
  8. HiRez macrumors 603

    HiRez

    Joined:
    Jan 6, 2004
    Location:
    Western US
    #8
    Yeah, I think using images is OK. What you could maybe do is draw your text into an image, so you have pre-rendered antialiasing. It's a bit of a PITA, but it might work.
     
  9. Darkroom thread starter Guest

    Darkroom

    Joined:
    Dec 15, 2006
    Location:
    Montréal, Canada
    #9
    Solved!

    i got it! and it's somewhat of an very simple fix.

    all i had to do was select the text in IB, click "Draws Background" in Attributes, and choose the color named "windowBackgroundColor" from Colors > Color Palettes > Palette: Developer...

    the downside to this is that it only works on text fields, so the text accompanying Checkbox buttons needs to be replaced by a separate string, and Push Buttons with key equivalent set to "Return" for the continuos pulse still don't pulse correctly.

    Actually, there is a bug that i found with core animation views besides aliased text. if a view has checkbox buttons with an pulsating push button (set to key equivalent "Return"), the checkboxes and their text will appear and disappear randomly when the view changes... i mean, it's a bug, but who uses pulsating push buttons anymore? what is it, 2001? :p
     

Share This Page