Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PyCairo emits errors when rendering emojis from OpenMoji #310

Open
YakoYakoYokuYoku opened this issue Feb 7, 2023 · 1 comment
Open

Comments

@YakoYakoYokuYoku
Copy link

I was toying with PyCairo to see if it had the capability to display emojis from the OpenMoji SVG-in-OT font.

import cairo
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk

def draw(da, ctx):
    ctx.move_to(80, 80)
    ctx.set_font_size(40.0)
    ctx.show_text("Hello, World!")
    extent = ctx.text_extents("Hello, World!")
    ctx.rel_move_to(extent.x_bearing, 0)
    ctx.select_font_face("OpenMoji")
    ctx.show_text(" 🌎")

def main():
    win = Gtk.Window()
    win.connect("destroy", lambda w: Gtk.main_quit())
    win.set_default_size(450, 180)

    drawingarea = Gtk.DrawingArea()
    win.add(drawingarea)
    drawingarea.connect("draw", draw)

    win.show_all()
    Gtk.main()

if __name__ == "__main__":
    main()

But things didn't work out as it doesn't render the globe and it throws a context save and restore mismatch error.

Traceback (most recent call last):
  File "test.py", line 13, in draw
    ctx.show_text(" 🌎")
cairo.Error: Context.restore() without matching Context.save()

(test.py:2278413): Gtk-WARNING **: 12:05:02.802: drawing failure for widget 'GtkDrawingArea': cairo_restore() without matching cairo_save()

(test.py:2278413): Gtk-WARNING **: 12:05:02.802: drawing failure for widget 'GtkWindow': cairo_restore() without matching cairo_save()

Though if I use Noto Color Emoji instead no error is emitted and I can see the globe. Any ideas?

@stuaxo
Copy link
Collaborator

stuaxo commented Feb 7, 2023

This looks like an issue in the cairo library itself, not pycairo the python binding to cairographics.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants