List Info

Thread: pango_layout_get_pixel_extents crash on Win32




pango_layout_get_pixel_extents crash on Win32
country flaguser name
Czech Republic
2007-09-06 16:02:06
Hello,

I have a problem with pango_layout_get_pixel_extents()
crashing on Win32 with a layout created from FT2 context.

I cannot reproduce the problem myself which complicates
debugging a bit...  However, I extracted the problem into
a relatively minimal program that my users confirm crashing
the same way as the application -- it's attached at the
end.

The program works flawlessly on Unix/X11.

It crashes on Windows XP -- for some people -- on the
pango_layout_get_pixel_extents() line (marked Bang!) with
no
run-time errors messages before.

The users who report the crashes generally run the latest
(or about) version of GladeWin32 runtime if it matters.

Is there something obviously wrong in the program?
What kind of problem it can be that it just crashes without
any failed assertion message?

Yeti

--
http://gwyddion.net/


============================================================
================
#include <pango/pangoft2.h>
#include <gtk/gtk.h>

PangoFontMap *ft2_font_map;

gboolean
try_layout(gpointer user_data)
{
    GtkWidget *widget = GTK_WIDGET(user_data);
    PangoFontDescription *fontdesc;
    PangoContext *context, *ft2_context;
    PangoRectangle rect;
    PangoLayout *layout;

    ft2_context
        =
pango_ft2_font_map_create_context(PANGO_FT2_FONT_MAP(ft2_fon
t_map));

    context = gtk_widget_get_pango_context(widget);
    fontdesc = pango_context_get_font_description(context);
    fontdesc =
pango_font_description_copy_static(fontdesc);
    pango_font_description_set_size(fontdesc,
12*PANGO_SCALE);
    pango_context_set_font_description(ft2_context,
fontdesc);
    pango_font_description_free(fontdesc);

    layout = pango_layout_new(ft2_context);
    pango_layout_set_width(layout, -1);
    pango_layout_set_alignment(layout, PANGO_ALIGN_LEFT);

    pango_layout_set_text(layout, "1", -1);
    /* Bang! */
    pango_layout_get_pixel_extents(layout, NULL,
&rect);

    gtk_widget_destroy(widget);

    return FALSE;
}

int
main(int argc, char *argv[])
{
    GtkWidget *widget;

    gtk_init(&argc, &argv);

    /* FT2 font map */
    ft2_font_map = pango_ft2_font_map_new();
   
pango_ft2_font_map_set_resolution(PANGO_FT2_FONT_MAP(ft2_fon
t_map), 72, 72);

    /* Create some widget */
    widget = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_default_size(GTK_WINDOW(widget), 300,
300);
    g_signal_connect(widget, "destroy",
G_CALLBACK(gtk_main_quit), NULL);
    gtk_widget_show_all(widget);

    /* After the widget is realized, do not put it into the
callback... */
    g_timeout_add(500, try_layout, widget);

    gtk_main();

    return 0;
}

_______________________________________________
gtk-i18n-list mailing list
gtk-i18n-listgnome.org

http://mail.gnome.org/mailman/listinfo/gtk-i18n-list

Re: pango_layout_get_pixel_extents crash on Win32
user name
2007-09-06 16:12:05
On 9/6/07, David Nečas (Yeti) <yetiphysics.muni.cz> wrote:
>
> Hello,
>
> I have a problem with pango_layout_get_pixel_extents()
> crashing on Win32 with a layout created from FT2
context.
>
> I cannot reproduce the problem myself which
complicates
> debugging a bit...  However, I extracted the problem
into
> a relatively minimal program that my users confirm
crashing
> the same way as the application -- it's attached at the
end.
>
> The program works flawlessly on Unix/X11.

I can't really guess exactly why it is crashing, but a
couple of notes:

 - pango_layout_get_pixel_extents() is a bit of a red
herring - it's
just the first time that it is actually laying out the text.
What you
are saying is that "laying out the text of a layout is
crashing". A
much more general complaint.

 - Your code assumes that the fonts for the Pango backend
used on GTK+
are the same as those for the FT2 backend ... true on X11,
where both
are using fontconfig. False on windows, where GTK+ uses the
native
font catalog and font system. Now, of course, using a font
description
that doesn't point to a known font shouldn't *crash*, but
it's quite
possible that your users have *no fonts at all* configured
for the FT2
backend, and at that point, it's more likely that there
might be a
crash.

 - Using FT2 on Windows is generally a poor idea. To render
to an
offscreen in-memory image, use cairo. With pango/cairo, you
can render
to offscreen images using the exact same font catalog that
GTK+ is
using, rather than dragging in an nonnative, innappropriate
dependencies (FreeType/fontconfig).

- Owen
_______________________________________________
gtk-i18n-list mailing list
gtk-i18n-listgnome.org

http://mail.gnome.org/mailman/listinfo/gtk-i18n-list

Re: pango_layout_get_pixel_extents crash on Win32
country flaguser name
Czech Republic
2007-09-06 17:48:17
On Thu, Sep 06, 2007 at 05:12:05PM -0400, Owen Taylor
wrote:
> 
>  - Your code assumes that the fonts for the Pango
backend used on GTK+
> are the same as those for the FT2 backend ... true on
X11, where both
> are using fontconfig. False on windows, where GTK+ uses
the native
> font catalog and font system. Now, of course, using a
font description
> that doesn't point to a known font shouldn't *crash*,

Should't I get either the requested font or a replacement
(possibly being awarded with a Pango warning)?

> but it's quite
> possible that your users have *no fonts at all*
configured for the FT2
> backend, and at that point, it's more likely that there
might be a
> crash.
> 
>  - Using FT2 on Windows is generally a poor idea.

Hm, I thought Gimp had been using FT2 so it could not be so
bad -- but maybe I was mistaken.  Anyway, if it's possible
that there are no fonts at all configured for FT2 then
obviously I cannot use it, at least not on Win32.

>  To render to an
> offscreen in-memory image, use cairo. With pango/cairo,
you can render
> to offscreen images using the exact same font catalog
that GTK+ is
> using, rather than dragging in an nonnative,
innappropriate
> dependencies (FreeType/fontconfig).

I see.  The trouble is my application has still Gtk+ 2.6 as
the lowest supported version (and changing requirements in
a minor stable version is a bit unfortunate).

Does any safe off-screen text rendering method exist that
does not require Cairo?  I do not need much features,
simple
strings with some default font would be sufficient.

Since I need off-screen text rendering only in a few places
I could also branch the code according to the platform, but
I'd rather avoid this too if there is another way...

Yeti

--
http://gwyddion.net/
_______________________________________________
gtk-i18n-list mailing list
gtk-i18n-listgnome.org

http://mail.gnome.org/mailman/listinfo/gtk-i18n-list

Re: pango_layout_get_pixel_extents crash on Win32
country flaguser name
United States
2007-09-06 17:54:31
On Fri, 2007-09-07 at 00:48 +0200, David NeÄŤas (Yeti)
wrote:
> On Thu, Sep 06, 2007 at 05:12:05PM -0400, Owen Taylor
wrote:
> > 
> >  - Your code assumes that the fonts for the Pango
backend used on GTK+
> > are the same as those for the FT2 backend ... true
on X11, where both
> > are using fontconfig. False on windows, where GTK+
uses the native
> > font catalog and font system. Now, of course,
using a font description
> > that doesn't point to a known font shouldn't
*crash*,
> 
> Should't I get either the requested font or a
replacement
> (possibly being awarded with a Pango warning)?

Can you at least give us a backtrace or something?

> > but it's quite
> > possible that your users have *no fonts at all*
configured for the FT2
> > backend, and at that point, it's more likely that
there might be a
> > crash.
> > 
> >  - Using FT2 on Windows is generally a poor idea.
> 
> Hm, I thought Gimp had been using FT2 so it could not
be so
> bad -- but maybe I was mistaken.

That's still the case I guess.

> Anyway, if it's possible
> that there are no fonts at all configured for FT2 then
> obviously I cannot use it, at least not on Win32.
> 
> >  To render to an
> > offscreen in-memory image, use cairo. With
pango/cairo, you can render
> > to offscreen images using the exact same font
catalog that GTK+ is
> > using, rather than dragging in an nonnative,
innappropriate
> > dependencies (FreeType/fontconfig).
> 
> I see.  The trouble is my application has still Gtk+
2.6 as
> the lowest supported version (and changing requirements
in
> a minor stable version is a bit unfortunate).
> 
> Does any safe off-screen text rendering method exist
that
> does not require Cairo?  I do not need much features,
simple
> strings with some default font would be sufficient.
> 
> Since I need off-screen text rendering only in a few
places
> I could also branch the code according to the platform,
but
> I'd rather avoid this too if there is another way...
>
> Yeti

-- 
behdad
http://behdad.org/

"Those who would give up Essential Liberty to purchase
a little
 Temporary Safety, deserve neither Liberty nor Safety."
        -- Benjamin Franklin, 1759



_______________________________________________
gtk-i18n-list mailing list
gtk-i18n-listgnome.org

http://mail.gnome.org/mailman/listinfo/gtk-i18n-list
Re: pango_layout_get_pixel_extents crash on Win32
country flaguser name
Czech Republic
2007-09-06 18:26:42
On Thu, Sep 06, 2007 at 06:54:31PM -0400, Behdad Esfahbod
wrote:
> 
> Can you at least give us a backtrace or something?

I would love to.  I just don't know how to get a backtrace
with the current procedure: I build something and find a
user (who does not have compilers, debuggers and similar
stuff) willing to run it and report me results.

I can try to cripple my font config to reproduce the crash
though -- if having no fonts configured is the cause.

Yeti

--
http://gwyddion.net/
_______________________________________________
gtk-i18n-list mailing list
gtk-i18n-listgnome.org

http://mail.gnome.org/mailman/listinfo/gtk-i18n-list

Re: pango_layout_get_pixel_extents crash on Win32
country flaguser name
Czech Republic
2007-09-07 03:33:21
On Fri, Sep 07, 2007 at 01:26:42AM +0200, David Nečas (Yeti)
wrote:
> 
> I can try to cripple my font config to reproduce the
crash
> though -- if having no fonts configured is the cause.

The best I can manage is program termination with

  No fonts found; this probably means that the fontconfig
  library is not correctly configured. You may need to
  edit the fonts.conf configuration file. More information
  about fontconfig can be found in the fontconfig(3) manual
  page and on http://fontconfig.org

printed to the console (if enabled).  While silent
application termination is not good either, users report
crashes/hangs with the accompanying Windows error boxes, so
probably something different.  I'm sorry.

Thanks for the hints, I will try different off-screen
rendering methods.

Yeti

--
http://gwyddion.net/
_______________________________________________
gtk-i18n-list mailing list
gtk-i18n-listgnome.org

http://mail.gnome.org/mailman/listinfo/gtk-i18n-list

Re: pango_layout_get_pixel_extents crash on Win32
country flaguser name
Czech Republic
2007-09-07 05:29:45
On Thu, Sep 06, 2007 at 05:12:05PM -0400, Owen Taylor
wrote:
> 
> To render to an
> offscreen in-memory image, use cairo. With pango/cairo,
you can render
> to offscreen images using the exact same font catalog
that GTK+ is
> using

Could you please hint a bit more?  I would rather avoid
repeating the same mistake.

Can I assume the map returned by
pango_cairo_font_map_get_default()
is the same map as Gtk+ (Gdk) uses?  Or how do I draw on an
image surface with the same font a widget would use
on-screen?

It seems to me I still need to transfer the font
description between two contexts.

Yeti

--
http://gwyddion.net/
_______________________________________________
gtk-i18n-list mailing list
gtk-i18n-listgnome.org

http://mail.gnome.org/mailman/listinfo/gtk-i18n-list

Re: pango_layout_get_pixel_extents crash on Win32
user name
2007-09-07 07:46:29
On 9/6/07, David Nečas (Yeti) <yetiphysics.muni.cz> wrote:
> On Thu, Sep 06, 2007 at 05:12:05PM -0400, Owen Taylor
wrote:
> >
> >  - Your code assumes that the fonts for the Pango
backend used on GTK+
> > are the same as those for the FT2 backend ... true
on X11, where both
> > are using fontconfig. False on windows, where GTK+
uses the native
> > font catalog and font system. Now, of course,
using a font description
> > that doesn't point to a known font shouldn't
*crash*,
>
> Should't I get either the requested font or a
replacement
> (possibly being awarded with a Pango warning)?

If there are any fonts at all, yes, you'll get a
replacement. The
replacement will have no apparent relationship to what was
requested,
other than size, and maybe bold/italic.

Dealing with no fonts at all is hard; Behdad did a bunch of
work to
avoid crashing in that case a year or two ago, but it's
possible that
those fixes haven't reached your users yet if you are trying
to work
with old versions of GTK+. Or they may not be complete in
the case of
the FT2 backend, which isn't a primary target for testing.

> > but it's quite
> > possible that your users have *no fonts at all*
configured for the FT2
> > backend, and at that point, it's more likely that
there might be a
> > crash.
> >
> >  - Using FT2 on Windows is generally a poor idea.
>
> Hm, I thought Gimp had been using FT2 so it could not
be so
> bad -- but maybe I was mistaken.  Anyway, if it's
possible
> that there are no fonts at all configured for FT2 then
> obviously I cannot use it, at least not on Win32.

*IF* the user has a working install of the GIMP using FT2
*AND* your
application is using the same install of GTK+ as the GIMP,
then it's
likely that the user will have a working configuration for
fontconfig.
Neither of those is at all a given. Once you drag fontconfig
into the
system, you have a second font system involved, and unlike
the native
font system, there is no guarantee at all that it has been
configured
correctly. (It's also badly inefficient to have two copies
of the font
database in memory.)

> >  To render to an
> > offscreen in-memory image, use cairo. With
pango/cairo, you can render
> > to offscreen images using the exact same font
catalog that GTK+ is
> > using, rather than dragging in an nonnative,
innappropriate
> > dependencies (FreeType/fontconfig).
>
> I see.  The trouble is my application has still Gtk+
2.6 as
> the lowest supported version (and changing requirements
in
> a minor stable version is a bit unfortunate).
>
> Does any safe off-screen text rendering method exist
that
> does not require Cairo?  I do not need much features,
simple
> strings with some default font would be sufficient.
>
> Since I need off-screen text rendering only in a few
places
> I could also branch the code according to the platform,
but
> I'd rather avoid this too if there is another way...

The only other the way I can think of doing offscreen
rendering that
uses the native font system would be to use Win32 GDI calls
and
pango_win32_* calls to render the layout to a Device Context
(DC) that
targets an offscreen image (a DIB).

Basically, if you want to work on old versions of GTK+,
you'll get old
APIs and old bugs.

- Owen
_______________________________________________
gtk-i18n-list mailing list
gtk-i18n-listgnome.org

http://mail.gnome.org/mailman/listinfo/gtk-i18n-list

[1-8]

about | contact  Other archives ( Real Estate discussion Medical topics )