Re: pango_layout_get_line_count () segfault



On 07/31/2009 11:41 AM, emj10 vt edu wrote:
Hey all,

I am attempting to display text with modified letter spacing using an attribute
list and a font description.  However, I'm not sure if I'm using the
pango_attr_letter_spacing_new (), pango_layout_set_attributes (), or
pango_layout_set_font_description () calls correctly as I am receiving a
segmentation fault when I attempt to call pango_layout_get_line_count ().

Am I using these functions incorrectly? Also, would a simple workaround to avoid
using an attribute list be adding markup to the text when calling
pango_layout_set_text ()?

You forgot to initialize attr_list as far as I can see.  pango_attr_list_new()

behdad


The backtrace shows the actual segmentation fault coming from
pango_attribute_copy (), which was called by pango_attr_list_copy (), which was
called from pango_layout_get_line_count ().

Thanks in advance,
Eric


static gboolean
draw(GtkWidget *widget,
      GdkEventConfigure *event,
      gpointer data)
{
   cairo_surface_t *surface;
   cairo_t         *cr;

   surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32,128,64);
   cr = cairo_create(surface);

   switch(cairo_status(cr))
   {
     case CAIRO_STATUS_SUCCESS:
     {
       PangoLayout          *layout;
       PangoFontDescription *desc;
       PangoAttrList        *attr_list;
       PangoAttribute       *spacing;
       unsigned char        *data;

       layout = pango_cairo_create_layout(cr);
       if (!layout)
       {
           fprintf(stderr,"draw(): ");
           fprintf(stderr,"Could not create pango-layout!\n");
           break;
       }

       desc = pango_font_description_new();
       if (!desc)
       {
           fprintf(stderr,"draw(): ");
           fprintf(stderr,"Could not create pango-font-description!\n");
           break;
       }

       spacing = pango_attr_letter_spacing_new(5);
       pango_attr_list_change(attr_list, spacing);
       pango_font_description_set_absolute_size(desc, 16 * PANGO_SCALE);
       pango_font_description_set_family(desc, "Arial");
       pango_font_description_set_weight(desc, PANGO_WEIGHT_ULTRALIGHT);
       pango_font_description_set_style(desc, PANGO_STYLE_NORMAL);
       pango_layout_set_attributes(layout, attr_list);
       pango_layout_set_font_description (layout, desc);
       pango_layout_set_text (layout, "Display some text", -1);

       cairo_set_source_rgb(cr, 0.5, 0.0, 0.5);
       cairo_move_to(cr, 10, 25);

       fprintf(stderr, "layout line count:%d\n",
pango_layout_get_line_count(layout));
       pango_cairo_show_layout_line(cr, pango_layout_get_line(layout,0));

       pango_attribute_destroy(spacing);
       pango_attr_list_unref(attr_list);
       pango_font_description_free (desc);
       g_object_unref (layout);
     }
   }
   cairo_destroy(cr);
   cairo_surface_destroy(surface);
   return FALSE;
}
_______________________________________________
gtk-i18n-list mailing list
gtk-i18n-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-i18n-list



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]