pygobject / pycairo

Python bindings for cairo
https://pycairo.readthedocs.io
Other
611 stars 83 forks source link

Best way for text rendering in serious applications (on Windows) #322

Open claell opened 1 year ago

claell commented 1 year ago

The docs list two sets of text rendering capabilities: https://pycairo.readthedocs.io/en/latest/reference/text.html#text. It is not entirely clear, which ones are which (at least for me not all of the documented items seem to belong to either of these classes).

In general, I just want to be sure that I can produce high quality text with kerning, etc.

So which functions should I use for that? And should I use Pango for that, as suggested? Or is there something built in already, but not documented? Also, there seems to be a library called pangocairo (among others).

Some advice would be appreciated.

psychon commented 9 months ago

(at least for me not all of the documented items seem to belong to either of these classes).

Of the top of my head, I think that any API that takes text is the "basic API". Anything where the caller has to provide positions of individual glyphs is the "fancy API".

But... the docs you link to basically say the same, so perhaps I am misunderstanding the question?

In general, I just want to be sure that I can produce high quality text with kerning, etc.

That's something that cairo doesn't do, sorry. Things like Pango do exactly that.

Also, there seems to be a library called pangocairo (among others).

PangoCairo is part of Pango. It is the part of Pango that talks to Cairo. There is also PangoXft, but I think Xft is more basic than cairo (and text-specific, so not a general "drawing something").

claell commented 8 months ago

Thanks! That is already helpful.

But... the docs you link to basically say the same, so perhaps I am misunderstanding the question?

No, I think I might not have read the docs carefully enough.

Okay, so I think, then my question is how to use pangocairo with pycairo. I already switched to a different approach for my use case by now, but that might still be good to document for other users or future uses.

I recently asked GPT-4 the same question and got an answer that might have been correct; however, some official documentation on this might be great!