pycairo icon indicating copy to clipboard operation
pycairo copied to clipboard

How can I activate subpixel positioning for text with `pangocairo` and `pycairo`?

Open s-m-e opened this issue 5 years ago • 9 comments

I am not sure if this is the right place to ask ... My apologies if I am wrong here.

I just came across this article saying that subpixel positioning was added to pango 1.44 in 2019 - not without its issues though. Apparently it is switched off by default. Both articles go as far as saying that the latest master from cairo is needed. Maybe it has been released in the meantime (?).

Two questions actually:

  • Which version / release of cairo & pycairo do I need for activating this feature? Or do I (still) need to build cairo & pycairo from (unreleased) master?
  • How do I activate subpixel positioning with pycairo & pangocairo?

(I also posted this question on stackoverflow.)

s-m-e avatar May 07 '20 09:05 s-m-e

cairo hasn't had a release since then. I don't know the current status of all this, sorry.

lazka avatar May 07 '20 09:05 lazka

@lazka Thanks. Just posted a question in the cairo mailing list.

s-m-e avatar May 07 '20 12:05 s-m-e

(the only thing I do know is that it's still broken on Windows, with master of everything)

lazka avatar May 07 '20 12:05 lazka

(the only thing I do know is that it's still broken on Windows, with master of everything)

Which cairo backend are you using? Is that cairo-win32?

It seems like this is only supported on cairo-image and cairo-xlib (run in a (not up-to-date) git checkout of cairo):

$ git log | grep -5 'Support subpixel positionin'

commit e4a79db0108be6a2b06dfce51a44bcbdead66ebd
Author: Matthias Clasen <[email protected]>
Date:   Sat May 25 00:35:04 2019 +0000

    xlib compositor: Support subpixel positioning
    
    As for the image compository, support a 4x4
    subpixel grid.

commit 6fd4222ab00c3b93f038172a8c9d48375c5f86f0
--

commit ea9329215d3431ded51a71b724baf0edc25ad633
Author: Matthias Clasen <[email protected]>
Date:   Sat Jul 28 12:25:47 2018 +0000

    image compositor: Support subpixel positioning
    
    Support subpixel positioning with a 4x4 subpixel grid.
    
    When compositing glyphs in the image compositor,
    we store the subpixel phases in the high bits of the
    glyph index. The _cairo_scaled_glyph_index() macro
    has been updated to discard these bits. By storing

psychon avatar May 07 '20 13:05 psychon

Which cairo backend are you using? Is that cairo-win32?

Sorry, this was just a tiny rant and not cairo's fault (well, somewhat), and not related to subpixel rendering. Newer pango doesn't send pixel aligned coordinates for characters to cairo any more and cairo then tries to align them, but only does so badly because it is missing any context, leading to random character spacing. The fix would be to support subpixel rendering in the win32 backend, but that would mean using a different win32 API.

lazka avatar May 07 '20 13:05 lazka

Gotta love those drive-by contributions to OSS projects that do exactly enough for their own use case instead of implementing things properly for everyone. :-) This makes me wonder what Pango did differently than cairo does now. Apparently just rounding each individual glyph position is not the answer.

@s-m-e Your answer seems to be "whatever Pango version @lazka is using automatically uses subpixel positioning with cairo, whether cairo supports that or not" and "cairo does not support it yet".

psychon avatar May 07 '20 13:05 psychon

@s-m-e Your answer seems to be "whatever Pango version @lazka is using automatically uses subpixel positioning with cairo, whether cairo supports that or not" and "cairo does not support it yet".

I do not entirely understand what you're trying to say. I basically do not want to blame anyone. It is (was?) my understanding that this feature requires symmetrical support from both pango and cairo. So from a distance it looks like "feature is now part of pango releases, but a corresponding cairo release is missing at this point".

s-m-e avatar May 07 '20 14:05 s-m-e

"feature is now part of pango releases, but a corresponding cairo release is missing at this point".

Yup, that's also my understanding. Sorry for my mis-communication.

psychon avatar May 07 '20 14:05 psychon

(I didn't want to sidetrack this, so I've hidden the win32/pango comments. I hope that's ok)

lazka avatar May 07 '20 15:05 lazka