After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 347236 - provide pango_cairo_font_get_scaled_font
provide pango_cairo_font_get_scaled_font
Status: RESOLVED FIXED
Product: pango
Classification: Platform
Component: general
unspecified
Other Linux
: Normal enhancement
: Small API
Assigned To: pango-maint
pango-maint
Depends on: 337593
Blocks: cairo_font_face_t 353293
 
 
Reported: 2006-07-11 16:11 UTC by Behdad Esfahbod
Modified: 2007-07-22 10:55 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Behdad Esfahbod 2006-07-11 16:11:44 UTC
cairo_scaled_font_t *
pango_cairo_font_get_scaled_font (PangoFont *);
Comment 1 Behdad Esfahbod 2007-06-11 02:58:05 UTC
2007-06-10  Behdad Esfahbod  <behdad@gnome.org>

        Bug 347236 – provide pango_cairo_font_get_scaled_font

        * pango/pangocairo-font.c: New public API:
        
                pango_cairo_font_get_scaled_font()

        * pango/pangocairo-fontmap.c: New public API:
        
                pango_cairo_font_map_new_for_font_type()
                pango_cairo_font_map_get_font_type()

        * pango/pangocairo-fcfontmap.c:
        Implement get_font_type() method.

        * pango/pangocairo.h:
        * pango/pangocairo-private.h:
        * docs/pango-sections.txt:
        * docs/tmpl/pangocairo.sgml:
        * pango/pangocairo.def:
        Update.

Comment 2 Torsten Schoenfeld 2007-07-07 16:31:20 UTC
I'm not sure how to deal with this new method for the Perl bindings.

pango_cairo_font_get_scaled_font resides in the pango_cairo_font_ namespace, but takes an instance of type PangoFont.  Judging from the docs and the code, pango_cairo_font_get_scaled_font can legally be called only on a special subset of instances of type PangoFont: the docs say "@font: a #PangoFont from a #PangoCairoFontMap".  As far as I can see, this kind of information isn't available at compile time.

So how do I wrap it?  Bind pango_cairo_font_get_scaled_font as if it were named pango_font_get_scaled_font, i.e. make it callable on every PangoFont instance: $font->get_scaled_font()?  Or wrap it as a helper function: Gtk2::Pango::Cairo::Font::get_scaled_font($font)?

I don't really like the first option, since it shifts the burden of checking for correctness to the programmer who would have to decide whether it's legal to call get_scaled_font() on the particular instance he has in hands.  It also pollutes a foreign namespace which can lead to name clashes.  The second option is ugly and makes pango_cairo_font_get_scaled_font look like a helper function whereas it really is more of a method.

(All this might sound like I'm asking you to do my job, but I think other bindings will have similar problems.)
Comment 3 Owen Taylor 2007-07-07 17:49:57 UTC
IMO (I'm not the maintainer) it's weird this was added as a PangoFont method 
without exposing the PangoCairoFont interface type. There may be internal
gymnastics related to avoiding cut-and-paste code, but the external
view should be that some fonts implement an interface with additional
methods (the vtable for the iface doesn't need to be exposed, just the
type for the iface)

Comment 4 Behdad Esfahbod 2007-07-08 12:57:42 UTC
I was trying to follow the pattern that was already there, that:

void pango_cairo_show_glyph_string (cairo_t          *cr,
                                    PangoFont        *font,
                                    PangoGlyphString *glyphs);


takes a PangoFont, not a PangoCairoFont.  It's not just here, the confusion is all over Pango.  For example see pangoxft.h:

XftFont *     pango_xft_font_get_font          (PangoFont *font);
Display *     pango_xft_font_get_display       (PangoFont *font);
#ifndef PANGO_DISABLE_DEPRECATED
FT_Face       pango_xft_font_lock_face         (PangoFont *font);
void          pango_xft_font_unlock_face       (PangoFont *font);
guint         pango_xft_font_get_glyph         (PangoFont *font,
                                                gunichar   wc);
gboolean      pango_xft_font_has_char          (PangoFont *font,
                                                gunichar   wc);
PangoGlyph    pango_xft_font_get_unknown_glyph (PangoFont *font,
                                                gunichar   wc);

And I know this has created lots of headaches for binding people before.  Another similar thing is that even the pangocairo fontmap constructors return PangoFontMap.  That's slightly different though.  So, what is the preferred pattern?
Comment 5 Torsten Schoenfeld 2007-07-08 14:59:19 UTC
Since pango_cairo_show_glyph_string is a helper function, it's wrapped accordingly in the Perl bindings:

  Gtk2::Pango::Cairo::show_glyph_string($cr, $font, $glyphs);

So the type of the font isn't that much of a problem in this case.  It's different for pango_cairo_font_get_scaled_font.  This one really is a method working on the font, and you'd like to be able to say

  $font->get_scaled_font

For this, the type of the font is crucial.

I can't say much about API naming patterns in pango or whether legacy API should influence new API.  But from a binding's perspective, there's one clear rule: a method's prefix must agree with the type of the instance it gets passed.  Otherwise it's hard to wrap.
Comment 6 Behdad Esfahbod 2007-07-08 16:06:46 UTC
How do you handle the Xft ones I listed?
Comment 7 Owen Taylor 2007-07-08 16:36:06 UTC
I don't think you can extra a *lot* of sense from old stuff in Pango
like the Xft API... the functions may have been added at a point I
didn't want to expose PangoXftFont or something.

I think pango_cairo_show_glyph_string() mostly has the PangoFont parameter
because it matches the generic pango_renderer_draw_glyphs(). (*)

What I'm really campaigning for with PangoCairoFont is not so much
changing the type of the parameter (though I think you should, and I
believe recent Pango fnuctions are pretty clean about it), but rather
exposing enough .. the get_type() function, in particular, so that 
language bindings can deploy their standard methods for binding
an interface and put the PangoCairoFont method(s) on that interface.

[ now, the challenge for language bindings is that PangoCairoWin32Font
FcFont aren't public, and shouldn't be public, so it's not clear 
what type the proxy object should have ... probably the language binding
needs to have non-public proxy classes for those non-public types.
That's no different than the challenge for 
pango_cairo_font_map_set_resolution(), so it's nothing particularly
new ]


(http://mail.gnome.org/archives/language-bindings/2005-May/msg00008.html
has my recommendation for binding gdk_cairo_show_glyph_string())
Comment 8 Torsten Schoenfeld 2007-07-08 16:59:56 UTC
> How do you handle the Xft ones I listed?

They're not wrapped since there's no way to deal with the things they return or take due to a lack of Perl bindings for the X types.  The same holds for the rest of the backend-specific API, apart from pangocairo.h: cairo has Perl bindings.

I don't know of any other language binding that wraps the Xft stuff.
Comment 9 Torsten Schoenfeld 2007-07-08 17:12:49 UTC
> (http://mail.gnome.org/archives/language-bindings/2005-May/msg00008.html
> has my recommendation for binding gdk_cairo_show_glyph_string())

(I presume you mean pango_cairo_show_glyph_string here.)

The advice from your mail (wrap gdk_cairo_* as methods on a special context object deriving from cairo_t) hinges on one crucial fact: there's a constructor for this special context object -- gdk_cairo_create.  This enables language bindings to wrap the context somehow so that, from the language's point of view, you have an object which you can call gdk_cairo_* and cairo_* on.

This doesn't work for the various pango_cairo_* functions working on a cairo_t.  There is no special constructor.  Thus I didn't see another way but to wrap those as functions.
Comment 10 Behdad Esfahbod 2007-07-21 00:54:55 UTC
Should be fixed.

2007-07-21  Behdad Esfahbod  <behdad@gnome.org>

        Part of Bug 347236 – provide pango_cairo_font_get_scaled_font

        * docs/Makefile.am:
        * docs/pango-sections.txt:
        * docs/tmpl/atsui-fonts.sgml:
        * docs/tmpl/opentype.sgml:
        * docs/tmpl/pango-engine-lang.sgml:
        * docs/tmpl/pango-engine-shape.sgml:
        * docs/tmpl/pangocairo.sgml:
        * pango/pangoatsui.h:
        * pango/pangocairo-atsuifont.h:
        * pango/pangocairo-font.c (pango_cairo_font_get_scaled_font):
        * pango/pangocairo-private.h:
        * pango/pangocairo.h:
        Export PangoCairoFont and cleanup various standard macros.

Comment 11 Torsten Schoenfeld 2007-07-22 10:55:44 UTC
Yep, this solves the problem nicely.  Thanks.