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

[introspection] Enable hb-cairo #4150

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

[introspection] Enable hb-cairo #4150

wants to merge 3 commits into from

Conversation

khaledhosny
Copy link
Collaborator

No description provided.

@khaledhosny
Copy link
Collaborator Author

This is not working for me, though. If I try something like hb.cairo_font_face_create_for_font(font), I get:

gi.repository.GLib.GError: g-invoke-error-quark: Could not locate hb_cairo_font_face_create_for_font: 'hb_cairo_font_face_create_for_font': dlsym(0x7ff91e8adad0, hb_cairo_font_face_create_for_font): symbol not found (1)

But my installation is botched, so it might be only me.

@khaledhosny
Copy link
Collaborator Author

khaledhosny commented Mar 5, 2023

Build also have the following warnings:

../src/hb-cairo.cc:725: Warning: HarfBuzz: hb_cairo_font_face_set_font_init_func: argument func: Missing (scope) annotation for callback without GDestroyNotify (valid: call, async, forever)
../src/hb-cairo.cc:725: Warning: HarfBuzz: hb_cairo_font_face_set_font_init_func: argument destroy: Missing (scope) annotation for callback without GDestroyNotify (valid: call, async, forever)
../src/hb-cairo.cc:849: Warning: HarfBuzz: hb_cairo_glyphs_from_buffer: argument glyphs: Unresolved type: 'cairo_glyph_t**'
../src/hb-cairo.cc:849: Warning: HarfBuzz: hb_cairo_glyphs_from_buffer: argument clusters: Unresolved type: 'cairo_text_cluster_t**'

@khaledhosny
Copy link
Collaborator Author

../src/hb-cairo.cc:725: Warning: HarfBuzz: hb_cairo_font_face_set_font_init_func: argument func: Missing (scope) annotation for callback without GDestroyNotify (valid: call, async, forever)
../src/hb-cairo.cc:725: Warning: HarfBuzz: hb_cairo_font_face_set_font_init_func: argument destroy: Missing (scope) annotation for callback without GDestroyNotify (valid: call, async, forever)

Fixed these.

@khaledhosny
Copy link
Collaborator Author

../src/hb-cairo.cc:849: Warning: HarfBuzz: hb_cairo_glyphs_from_buffer: argument glyphs: Unresolved type: 'cairo_glyph_t**'
../src/hb-cairo.cc:849: Warning: HarfBuzz: hb_cairo_glyphs_from_buffer: argument clusters: Unresolved type: 'cairo_text_cluster_t**'

This seems to be a cairo-1.0.gir limitation, these types do not seem to be defined there.

@behdad
Copy link
Member

behdad commented Mar 5, 2023

This is not working for me, though. If I try something like hb.cairo_font_face_create_for_font(font), I get:

gi.repository.GLib.GError: g-invoke-error-quark: Could not locate hb_cairo_font_face_create_for_font: 'hb_cairo_font_face_create_for_font': dlsym(0x7ff91e8adad0, hb_cairo_font_face_create_for_font): symbol not found (1)

But my installation is botched, so it might be only me.

Did you link to harfbuzz-cairo?

@behdad
Copy link
Member

behdad commented Mar 5, 2023

This is not working for me, though. If I try something like hb.cairo_font_face_create_for_font(font), I get:

gi.repository.GLib.GError: g-invoke-error-quark: Could not locate hb_cairo_font_face_create_for_font: 'hb_cairo_font_face_create_for_font': dlsym(0x7ff91e8adad0, hb_cairo_font_face_create_for_font): symbol not found (1)

But my installation is botched, so it might be only me.

I get a weirder error:

gi.repository.GLib.GError: g-invoke-error-quark: Could not locate hb_cairo_font_face_create_for_font: 'hb_cairo_font_face_create_for_font': build/src/libharfbuzz-gobject.so.0: undefined symbol: hb_cairo_font_face_create_for_font (1)

@khaledhosny
Copy link
Collaborator Author

This is not working for me, though. If I try something like hb.cairo_font_face_create_for_font(font), I get:

gi.repository.GLib.GError: g-invoke-error-quark: Could not locate hb_cairo_font_face_create_for_font: 'hb_cairo_font_face_create_for_font': dlsym(0x7ff91e8adad0, hb_cairo_font_face_create_for_font): symbol not found (1)

But my installation is botched, so it might be only me.

I get a weirder error:

gi.repository.GLib.GError: g-invoke-error-quark: Could not locate hb_cairo_font_face_create_for_font: 'hb_cairo_font_face_create_for_font': build/src/libharfbuzz-gobject.so.0: undefined symbol: hb_cairo_font_face_create_for_font (1)

Linking with libharfbuzz_cairo fixes this one, but now I get:

Traceback (most recent call last):
  File "src/sample.py", line 26, in <module>
    hb.cairo_font_face_create_for_font (font)
TypeError: Couldn't find foreign struct converter for 'cairo.FontFace'

@behdad
Copy link
Member

behdad commented Mar 5, 2023

Traceback (most recent call last):
File "src/sample.py", line 26, in
hb.cairo_font_face_create_for_font (font)
TypeError: Couldn't find foreign struct converter for 'cairo.FontFace'

Humm we're just passing pointers around. Is there an annotation that says it's an opaque pointer?

@khaledhosny
Copy link
Collaborator Author

Traceback (most recent call last):
File "src/sample.py", line 26, in
hb.cairo_font_face_create_for_font (font)
TypeError: Couldn't find foreign struct converter for 'cairo.FontFace'

Humm we're just passing pointers around. Is there an annotation that says it's an opaque pointer?

cairo-1.0.gir seems to know what cairo.FontFace is, so I wonder what we are still missing.

@khaledhosny
Copy link
Collaborator Author

I get a similar error while using Pango as well:

import gi
gi.require_version('cairo', '1.0')
gi.require_version('Pango', '1.0')
gi.require_version('PangoCairo', '1.0')
from gi.repository import cairo, Pango, PangoCairo

desc = Pango.font_description_from_string ("Sans Bold 27")
fontmap = PangoCairo.FontMap.get_default ()
context = fontmap.create_context ()
font = context.load_font (desc)
PangoCairo.Font.get_scaled_font (font)
Traceback (most recent call last):
  File "test.py", line 14, in <module>
    PangoCairo.Font.get_scaled_font (font)
TypeError: Couldn't find foreign struct converter for 'cairo.ScaledFont'

So I’m starting to think either using cairo types from GI is broken, or we need some magic incantation to get it to work.

@behdad
Copy link
Member

behdad commented Mar 7, 2023

If I'm reading this right, looks like cairo gi bindings are handwritten, and very incomplete to my eyes:
https://github.com/GNOME/gobject-introspection/blob/main/gir/cairo-1.0.gir.in

Eg. the simplest function, cairo_image_surface_create() has no parameters annotated:

  <function name="image_surface_create" c:identifier="cairo_image_surface_create">
      <return-value transfer-ownership="none">
    <type name="none" c:type="void"/>
      </return-value>
      <parameters>
      </parameters>
    </function>

indeed, when I try to call that function, which should take three parameters, I get this error in Python:

TypeError: cairo.image_surface_create() takes exactly 0 arguments (3 given)

Did cairo GI bindings ever work?

@khaledhosny
Copy link
Collaborator Author

Did cairo GI bindings ever work?

I don’t really know, it seems like you can use some cairo with gtk, but probably that is the subset that was ever tested?

@ebassi
Copy link

ebassi commented Mar 8, 2023

Did cairo GI bindings ever work?

No. Cairo does not have introspection data, outside of the small hand-written GIR that is only used to expose the boxed types of cairo-gobject needed to introspect GTK. Every language that provides a Cairo binding has to have a native binding.

Of course, since the Cairo introspection data is handwritten, it can get out of sync.

@khaledhosny
Copy link
Collaborator Author

So is there anyway we can get hb-cairo introspection to work, namely the error in #4150 (comment) above?

@ebassi
Copy link

ebassi commented Mar 8, 2023

You should install pycairo and import it:

import cairo
from gi.repository import Pango, PangoCairo

instead of using:

from gi.repository import cairo, Pango, PangoCairo

This is typically how Cairo is used in Python.

@khaledhosny
Copy link
Collaborator Author

I tried that already, and I still get the same error:

import cairo
import gi
gi.require_version('Pango', '1.0')
gi.require_version('PangoCairo', '1.0')
from gi.repository import Pango, PangoCairo

desc = Pango.font_description_from_string ("Sans Bold 27")
fontmap = PangoCairo.FontMap.get_default ()
context = fontmap.create_context ()
font = context.load_font (desc)
PangoCairo.Font.get_scaled_font (font)
Traceback (most recent call last):
  File "test.py", line 11, in <module>
    PangoCairo.Font.get_scaled_font (font)
TypeError: Couldn't find foreign struct converter for 'cairo.ScaledFont'

@ebassi
Copy link

ebassi commented Mar 8, 2023

@khaledhosny
Copy link
Collaborator Author

Sounds similar to this issue https://gitlab.gnome.org/GNOME/pygobject/-/issues/16, so likely a pygobject issue.

@khaledhosny khaledhosny marked this pull request as ready for review March 9, 2023 18:31
@behdad
Copy link
Member

behdad commented Mar 9, 2023

Sounds similar to this issue https://gitlab.gnome.org/GNOME/pygobject/-/issues/16, so likely a pygobject issue.

However, CairoFontFace does have a record in:
https://github.com/GNOME/gobject-introspection/blob/main/gir/cairo-1.0.gir.in

Same error when you search, other people (mostly on Ubuntu) solved by installing cairo gobject... But that doesn't seem to be my problem here.

@khaledhosny
Copy link
Collaborator Author

khaledhosny commented Mar 9, 2023

Sounds similar to this issue https://gitlab.gnome.org/GNOME/pygobject/-/issues/16, so likely a pygobject issue.

However, CairoFontFace does have a record in: https://github.com/GNOME/gobject-introspection/blob/main/gir/cairo-1.0.gir.in

Same error when you search, other people (mostly on Ubuntu) solved by installing cairo gobject... But that doesn't seem to be my problem here.

Yes, but based on this commit (which fixes the cairo.Matrix issue above), manual conversion code is still needed. The pygi-foreign-cairo.c file has nothing for FontFace or ScaledFont.

@behdad
Copy link
Member

behdad commented Mar 9, 2023

Sounds similar to this issue https://gitlab.gnome.org/GNOME/pygobject/-/issues/16, so likely a pygobject issue.

However, CairoFontFace does have a record in: https://github.com/GNOME/gobject-introspection/blob/main/gir/cairo-1.0.gir.in
Same error when you search, other people (mostly on Ubuntu) solved by installing cairo gobject... But that doesn't seem to be my problem here.

Yes, but based on this commit (which fixes the cairo.Matrix issue above), manual conversion code is still needed. The pygi-foreign-cairo.c file has nothing for FontFace or ScaledFont.

Wonder if this is not enough:
https://gitlab.gnome.org/GNOME/pygobject/-/blob/master/gi/pygi-foreign-cairo.c#L281

@ebassi
Copy link

ebassi commented Mar 9, 2023

That only really helps for properties and signal handlers, not for function arguments and return values, unless those arguments take a GValue.

@behdad
Copy link
Member

behdad commented Mar 9, 2023

I see. Thanks. Okay, I'm binding font-face and scaled-font now.

@behdad
Copy link
Member

behdad commented Mar 9, 2023

I see. Thanks. Okay, I'm binding font-face and scaled-font now.

I confirm it works with my MR:
https://gitlab.gnome.org/GNOME/pygobject/-/merge_requests/236

@khaledhosny
Copy link
Collaborator Author

I see. Thanks. Okay, I'm binding font-face and scaled-font now.

I confirm it works with my MR: https://gitlab.gnome.org/GNOME/pygobject/-/merge_requests/236

Excellent!

@khaledhosny
Copy link
Collaborator Author

Now, there is still this warning while building HarfBuzz:

../src/hb-cairo.cc:849: Warning: HarfBuzz: hb_cairo_glyphs_from_buffer: argument glyphs: Unresolved type: 'cairo_glyph_t**'
../src/hb-cairo.cc:849: Warning: HarfBuzz: hb_cairo_glyphs_from_buffer: argument clusters: Unresolved type: 'cairo_text_cluster_t**'

@behdad
Copy link
Member

behdad commented Mar 9, 2023

Now, there is still this warning while building HarfBuzz:

../src/hb-cairo.cc:849: Warning: HarfBuzz: hb_cairo_glyphs_from_buffer: argument glyphs: Unresolved type: 'cairo_glyph_t**'
../src/hb-cairo.cc:849: Warning: HarfBuzz: hb_cairo_glyphs_from_buffer: argument clusters: Unresolved type: 'cairo_text_cluster_t**'

Yeah that one needs more work

@behdad
Copy link
Member

behdad commented Mar 9, 2023

Now, there is still this warning while building HarfBuzz:

../src/hb-cairo.cc:849: Warning: HarfBuzz: hb_cairo_glyphs_from_buffer: argument glyphs: Unresolved type: 'cairo_glyph_t**'
../src/hb-cairo.cc:849: Warning: HarfBuzz: hb_cairo_glyphs_from_buffer: argument clusters: Unresolved type: 'cairo_text_cluster_t**'

Yeah that one needs more work

It's not even bound in cairo-gobject. So needs to go there first. Then in gobject-introspection handcoded cairo-1.0.gir.in, then in pygobject. I'll try to take a look.

@behdad
Copy link
Member

behdad commented Mar 9, 2023

It's not even bound in cairo-gobject. So needs to go there first. Then in gobject-introspection handcoded cairo-1.0.gir.in, then in pygobject. I'll try to take a look.

https://gitlab.freedesktop.org/cairo/cairo/-/merge_requests/468

@behdad
Copy link
Member

behdad commented Mar 9, 2023

Then in gobject-introspection handcoded cairo-1.0.gir.in,

https://gitlab.gnome.org/GNOME/gobject-introspection/-/merge_requests/392

@behdad
Copy link
Member

behdad commented Mar 9, 2023

It's not clear to me how to teach GI that an array of cairo_glyph_t returned needs to be freed using cairo_glyph_free...

@behdad
Copy link
Member

behdad commented Mar 9, 2023

Then in gobject-introspection handcoded cairo-1.0.gir.in,

https://gitlab.gnome.org/GNOME/gobject-introspection/-/merge_requests/392

With this, I don't get those warnings anymore.

@behdad
Copy link
Member

behdad commented Mar 9, 2023

Then in gobject-introspection handcoded cairo-1.0.gir.in,

https://gitlab.gnome.org/GNOME/gobject-introspection/-/merge_requests/392

With this, I don't get those warnings anymore.

Not sure. My bad probably. Testing again.

@behdad
Copy link
Member

behdad commented Mar 9, 2023

Then in gobject-introspection handcoded cairo-1.0.gir.in,

https://gitlab.gnome.org/GNOME/gobject-introspection/-/merge_requests/392

With this, I don't get those warnings anymore.

Not sure. My bad probably. Testing again.

I don't get a warning. But the function is not exported to Python either.

@behdad
Copy link
Member

behdad commented Mar 9, 2023

But the function is not exported to Python either.

It has introspectable="0" attribute.

@behdad
Copy link
Member

behdad commented Mar 9, 2023

Binding hb_cairo_glyphs_from_buffer is essentially impossible because of how it reallocates the arrays and expects the caller to free them if they changed... Also https://gitlab.gnome.org/GNOME/gobject-introspection/-/issues/352

@behdad
Copy link
Member

behdad commented Dec 7, 2023

So, what should we do with this?

@khaledhosny
Copy link
Collaborator Author

I don’t know. I lost track of what is working and what is not.

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

Successfully merging this pull request may close these issues.

3 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy