pygobject / pycairo

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

Cairo 1.18.0 doesn't draw bold or italic text on Mac #351

Closed schmave closed 8 months ago

schmave commented 8 months ago

I've got what I assume is a bug in cairo, rather than pycairo, but I'm not sure. Is there anything worth looking into in pycairo here or should I take this to the cairo mailing list? Thanks in advance for your help.

When I run the following program with Python 3.9/3.10/3.11 on a Mac (mine is Intel, but it happens on ARM also), pycairo 1.24.0/1.25.1, the same font is used for both calls to show_text() if I am using cairo 1.18.0 installed via homebrew.

import cairo

WIDTH = 3
HEIGHT = 2
PIXEL_SCALE = 200

surface = cairo.ImageSurface(cairo.FORMAT_RGB24,
                             WIDTH*PIXEL_SCALE,
                             HEIGHT*PIXEL_SCALE)
ctx = cairo.Context(surface)
ctx.scale(PIXEL_SCALE, PIXEL_SCALE)

# Drawing code
ctx.set_source_rgb(1, 0, 0)
ctx.set_font_size(0.25)
ctx.select_font_face("Arial",
                     cairo.FONT_SLANT_NORMAL,
                     cairo.FONT_WEIGHT_NORMAL)
ctx.move_to(0.5, 0.5)
ctx.show_text("Normal text")
# End of drawing code

ctx.set_source_rgb(0, 1, 0)
ctx.set_font_size(0.25)
ctx.select_font_face("Arial",
                     cairo.FONT_SLANT_ITALIC,
                     cairo.FONT_WEIGHT_BOLD)
ctx.move_to(0.5, 0.75)
ctx.show_text("Bold + italic text")

surface.write_to_png('text.png')

Output with homebrew's cairo 1.18.0:

text-1 18 0

Output with homebrew's cairo 1.16.0_5:

text-1 16 0_5

stuaxo commented 8 months ago

This kind of thing may be an issue with cairo itself - can you port the example to C ?

(One thing LLMs like ChatGPT are good at is porting small examples like this between languages).

If you still have the issue, there then I would report it upstream to cairo https://gitlab.freedesktop.org/cairo/cairo

schmave commented 8 months ago

Thanks for the quick reply and the tip about using an LLM! That made it very fast to determine that the same thing happens without pycairo. I'll report it upstream.

schmave commented 8 months ago

Bug reported here, in case that is helpful: https://gitlab.freedesktop.org/cairo/cairo/-/issues/811