[cairo] How can I activate subpixel positioning for text with `pangocairo` and `(py)cairo`?

Uli Schlachter psychon at znc.in
Thu May 7 14:32:57 UTC 2020

Hi Sebastian,

On 07.05.20 15:59, Sebastian M. Ernst wrote:
>> Random guess: This is related to src/cairo-ft-font.c, so I took a quick
>> look at the output of "git log src/cairo-ft-font.c". The third entry
>> sounds like what you are looking for:
> Is this the "toy" font renderer of cairo or is this also used when
> interacting with pangocairo?

The toy font face lives in cairo-toy-font-face.c. Freetype is most
likely the "proper" font support that you are also using "normally".

>> P.S.: Why do you need this feature anyway? My fonts look fine to me
>> without it, I think...
> For still images I'd say yes, you're right. But I am using cairo for
> rendering frames of an animation. If the text moves around, you can
> literally see it jumping line by line. It looks really awful. I can of
> cause render at a higher resolution and then reduce the resolution in a
> later step, but I was wondering whether there is an easier way.

Ah, that makes sense.
Please report back when/if you get this working whether the 4x4 subpixel
positions that is currently used is enough for this case.

>>> How do I activate subpixel positioning with Cairo (pycairo) / pangocairo?
>> You don't. As I understand it, it is automatically activated. The question then is: How do I deactivate it? And the answer to that also seems to be "you don't".
> One of the blog posts explicitly says "To address this problem, subpixel
> positioning is now optional, and off by default". I have also tested
> this in much length against the latest releases of all involved
> libraries: There is no subpixel positioning for text in my described
> workflow ...

Found it [0]:

> To address this problem, subpixel positioning is now optional, and off by default. Use
> pango_context_set_round_glyph_positions (context, FALSE)
> to turn it on.
So, at least this also says what is necessary in Pango to enable this

Also, according to the docs, this function exists "since 1.44", so I
guess when you can call the function, then Pango also supports the
subpixel positioning. [1]

It seems like all that this is does is to disable some rounding in Pango.

[0]: https://blogs.gnome.org/mclasen/2019/08/07/pango-1-44-wrap-up/
Bitte nicht mit dem verbleibenden Auge in den Laser gucken.
 - Vincent Ebert

More information about the cairo mailing list