BigZaphod / Chameleon

Chameleon is a port of Apple's UIKit for iOS (and some minimal related frameworks) to Mac OS X.
http://chameleonproject.org/
BSD 3-Clause "New" or "Revised" License
3.44k stars 569 forks source link

Text render is less clear than AppKit(Subpixel rendering?) #67

Open xhan opened 12 years ago

xhan commented 12 years ago

by using same font and fontSize LucidaGrande 14
Render effect on AppKit(using NSTextField) AppKit Render effect on Chameleon(tested with UILabel, UINSCellControl with NSTextFieldCell) Chameleon Let's zoom in (top one is rendered in AppKit) diff

BigZaphod commented 12 years ago

Chameleon does not use subpixel smoothing when rendering text because it is implemented with CALayers (as is the real UIKit on iOS). Since each major part of a typical UIKit/Chameleon control is drawn into their own layers, there is no way to access the color information behind the text that's necessary to smooth the text in the way AppKit does. If you flatten your views manually by drawing everything (text, etc.) in drawRect:, you can turn on smoothing and have it work but then you're stuck not having any transparent backgrounds on your views and it changes how you do things pretty significantly.

On Sep 25, 2011, at 10:24 AM, xu han wrote:

by using same font and fontSize LucidaGrande 14
Render effect on AppKit(using NSTextField) AppKit Render effect on Chameleon(tested with UILabel, UINSCellControl with NSTextFieldCell) Chameleon Let's zoom in (top one is rendered in AppKit) diff

Reply to this email directly or view it on GitHub: https://github.com/BigZaphod/Chameleon/issues/67

jspahrsummers commented 12 years ago

Subpixel antialiasing, as you mentioned, can be enabled any time you're drawing into an opaque background. Since everything eventually composites onto an opaque background, the easiest way to enable subpixel antialiasing is to avoid drawing and caching individual layers (or, at least, non-opaque layers).

This approach may or may not be possible with CALayer and the rendering employed in Chameleon, but we have some code in a Core Animation imitation framework that successfully employs this technique. It could be useful as a reference: https://github.com/joshaber/MoreAnimation/blob/master/Framework/MoreAnimation/MoreAnimation/Classes/MALayer.m#L835

xhan commented 12 years ago

Still not find a solution on how to enable Subpixel antialiasing on transparent context. next step I will try CGContextSetBlendMode to seem if it helps.
but I just noticed that TWUI has Sub-pixel text rendering enabled. not sure how they did it.

Naituw commented 12 years ago

TWUI can not get sub-pixel AA on transparent context too..

xhan commented 12 years ago

Found a quick-dirty solution so far, by adding a stroke around text with width 0.1.
This makes text feel more clean and a bit border.

ghost commented 12 years ago

@ jspahrsummers even if I would do it more efficiently but I think you'll optimize your calls you are totally right

@xhan does something like pixel grid means something to you?