Re: Printing with gtk+, cairo and pango - need to iterate glyphs and problems with pango attributes

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

 



Uh, looks like may be a bug with our win32 backends.  Can you try on Linux?

behdad

On 07/09/2009 08:07 AM, joel@xxxxxxxxxxxx wrote:
Hi
I'm trying to print a form which I developed with gtk+. I developed it on m$
Vista with mingw and glade libraries from sourceforge.net. I didn't write it on
GNU/Linux because it should run on win32. That's why I installed ghostscript and
FreePDF to print to PDF to save toner and paper.
I don't understand why the following codes don't work and I have a need for both
for simple usage and iterating glyphs!

First I tried this whereby every letter seems to be painted at same position:

void
ar_print_draw_page(ArPrint *print, GtkPrintOperation *operation, GtkPrintContext
*context, gint page_nr)
{
   cairo_t *cr;
   PangoLayout *layout;
   PangoFontDescription *desc;
   PangoAttrList *attribute_list;
   PangoAttribute *attribute;
   PangoLayoutRun *run;
   PangoRectangle logical_rect;
   GList *list_line, *list_run;
   guint x_offset, y_offset;
   void ar_print_draw_page_header(){
     gdouble info_width;
     gdouble font_size, offset;

     info_width = (print->content_width) * (5.35 / 18.5);
     offset = 0.0;

     cairo_set_source_rgb(cr, 0.0, 0.0, 1.0);

     cairo_rectangle(cr, print->padding_left + info_width, print->padding_top,
print->content_width - info_width, print->header_height);
     cairo_fill(cr);

     cairo_rectangle(cr, print->padding_left, print->padding_top, info_width,
print->header_height);
     cairo_stroke(cr);

     layout = gtk_print_context_create_pango_layout(context);
     //    layout = pango_layout_new(pango_cairo_create_context(cr));
     pango_layout_set_text(layout, "Title\nsecondary text\0", -1);

     desc = pango_font_description_from_string("Arial 10\0");
     pango_layout_set_font_description(layout, desc);
     //    pango_font_description_free(desc);

     attribute_list = pango_attr_list_new();

     attribute = pango_attr_size_new(9);
     attribute->start_index = 0;
     attribute->end_index = 6;
     pango_attr_list_insert(attribute_list, attribute);

     attribute = pango_attr_size_new(7);
     attribute->start_index = 6;
     attribute->end_index = 15;
     pango_attr_list_insert(attribute_list, attribute);

     pango_layout_set_attributes(layout, attribute_list);
     pango_layout_set_alignment(layout, PANGO_ALIGN_LEFT);

     pango_layout_context_changed(layout);

     cairo_set_source_rgb(cr, 0.0, 0.0, 0.0);
     cairo_move_to(cr, print->padding_left, print->padding_top);
     pango_cairo_show_layout(cr, layout);

     g_object_unref(layout);

   }
   void ar_print_draw_page_body(){
   }
   void ar_print_draw_page_footer(){
   }

   cr = gtk_print_context_get_cairo_context(context);

   ar_print_draw_page_header();
   ar_print_draw_page_body();
   ar_print_draw_page_footer();
}

furthermore I tried something like following and got the same result as above:

void
ar_print_draw_page(ArPrint *print, GtkPrintOperation *operation, GtkPrintContext
*context, gint page_nr)
{
  ...

  list0 = pango_layout_get_lines(layout);

  y_off = 0;

  for(i = 0; i<  rows&&  list0 != NULL; i++){
    list1 = ((PangoLayoutLine *) (list0->data))->runs;
    x_off = 0;

    while(list1 != NULL){
      run = (PangoLayoutRun *) list1->data;

      pango_glyph_string_extents(run->glyphs, run->item->analysis.font,
                                 NULL,&logical_rect);

      pango_cairo_show_glyph_string(cr, run->item->analysis.font, run->glyphs);

      x_off += logical_rect.width;
      list1 = list1->next;
    }

    y_off += height;
    list0 = list0->next;
  }

   ...
}

_______________________________________________
gtk-list mailing list
gtk-list@xxxxxxxxx
http://mail.gnome.org/mailman/listinfo/gtk-list

_______________________________________________
gtk-list mailing list
gtk-list@xxxxxxxxx
http://mail.gnome.org/mailman/listinfo/gtk-list

[Index of Archives]     [Touch Screen Library]     [GIMP Users]     [Gnome]     [KDE]     [Yosemite News]     [Steve's Art]

  Powered by Linux