Drawing text on subpixel coordinates?


#1

In the drawButtonText function in my LookAndFeel, I’m trying to draw the text slightly lower when the button is down, but no matter what I do, it seems like the smallest interval is an integer, not even when using the float version below. Doesn’t this draw on subpixel coordinates?

void Graphics::drawText (const String& text, Rectangle<float> area,
                         Justification justificationType, bool useEllipsesIfTooBig)

#2

At low resolutions, most font renderers will snap text vertically so that the horizontal parts of the glyphs are pixel-aligned, because if you don’t do this, it’s really blurry. CoreGraphics does that, and so does the juce software renderer.


#3

I’m not sure that it would be correct to say that CoreGraphics does this. For example, CoreGraphics text drawn to a CALayer can definitely be positioned at subpixel locations and, especially on a retina display, it’s not blurry at all. In JUCE, however, it seems that only the OpenGL renderer allows text to not be snapped to integer pixels.


#4

I’ve no idea whether CoreGraphics also snaps when rendering to high-res displays or off-screen layers, but it definitely does look blurry at low resolutions unless you snap the horizontals. A lot of people criticised my font renderer for this until I added the feature!

No, the openGL renderer uses exactly the same font rasteriser as the software renderer, which always snaps vertically.


#5

Would it be possible to snap to 0.5px instead of 1px verticals for retina displays? We have a object whose position animates very smoothly, and the snapping text during animation is very obvious and undesirable.

We’ve tried drawing the text to an image first, which makes the animation wonderful, but then we can’t get the text to look the same on retina devices (Text anti-aliasing looks different when drawn to image).


#6

That’s exactly what the juce GL and software renderers will do. If you’re talking about the CoreGraphics text renderer, then it’s Apple’s support you’d need to ask, not us!