pygobject / pycairo

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

PangoCairo: Wrong letter spacing on small fonts #371

Open artemious3 opened 1 week ago

artemious3 commented 1 week ago

The following code produces PDF file with weird character spacing:

import cairo as cr
from gi.repository import Pango, PangoCairo

with cr.PDFSurface("example.pdf", 595, 842) as surf:
    fontmap = PangoCairo.font_map_new()
    fontmap.set_resolution(300)
    pango_ctx = fontmap.create_context()
    layout = Pango.Layout(pango_ctx)
    cairo_ctx = cr.Context(surf)

    layout.set_font_description(Pango.FontDescription("Noto Sans 1"))
    layout.set_markup("Lorem ipsum dolor sit amet ")
    cairo_ctx.set_source_rgb(0,0,0)
    PangoCairo.show_layout(cairo_ctx, layout)

image

Changing font size to 3 and more fixes the issue.

Pango: 1.54.0 Cairo: 1.18.0 Python-cairo: 1.26.1-1