github / twui

A framework for developing interfaces on the Mac.
Other
400 stars 79 forks source link

Inserting TwUI hierarchy into an existing layer with background #155

Closed vojto closed 11 years ago

vojto commented 11 years ago

Hey,

I have a layer-hosting NSView with its own background.

If I simply insert a CATextLayer into that layer, everything looks great.

Now I try this:

  1. Create TwUI hierarchy using TUINSView.
  2. Add a new TUIView that uses TUITextRenderer to render something.
  3. Set backgrounds of all TwUI views to clearColor.

The text rendering is very ugly. I understand that normally, layer needs to have a background in order for that subpixel AA to work, but in this case my parent layer is the background.

My first experiment (inserting simple CATextLayer with clear background) proves that it should work.

Can anybody help me please?

avaidyam commented 11 years ago

This is something I've looked at in the past too, but you may want to check up on what TUINSView is doing. It's also layer-hosting TUIViews with their layers added as sublayers to its layer. Try the CATextLayer example with a transparent NSView and see what happens first.

vojto commented 11 years ago

Here are a few things that I tried:

test

It seems that adding a sublayer, and drawing text manually in it using NSAttributedString is ugly too. On the other hand, adding CATextLayer into TUIView hierarchy looks nice.

avaidyam commented 11 years ago

What platform are you on? (10.6,7,8?)

jspahrsummers commented 11 years ago

None of those examples have subpixel antialiasing – you can tell because the text color is all straight black, not multicolored (which is how SPAA works).

What seems to be happening here is that CATextLayer is smart enough to disable SPAA, because it knows it can't do it correctly. The resulting text is antialiased "normally." The others are trying to do SPAA with a transparent background, with disastrous results.

avaidyam commented 11 years ago

^ This. Though apparently, in 10.8, NSText* views can enable SPAA as long as there is one such compatible (opaque) superview in the view hierarchy. Odd.

vojto commented 11 years ago

Yeah, it's 10.8.

Well, I don't think there's any bug here, sorry about opening the issue without understanding the problem fully!

jspahrsummers commented 11 years ago

No problem! SPAA is an interesting topic. :)

avaidyam commented 11 years ago

@jspahrsummers Out of curiosity, do you have a sliver of an idea how 10.8 NSText* views are able to use SPAA as long as there's one opaque ancestor?

jspahrsummers commented 11 years ago

My assumption is that they replicate their ancestor's rendered image in the same context, then draw the text on top.

avaidyam commented 11 years ago

@jspahrsummers I was thinking that too, but seems a bit too much work...