[gtkada] GtkAda printing problem

bertus.dries at planet.nl bertus.dries at planet.nl
Mon Nov 26 08:38:56 CET 2018


I have a problem with printing from Gtk.

The print is working correctly if I print a document which results in 19
pages. But with one page with 48 lines of text I just get an empty page and
I just don't get the print dialog. Herewith I give you the part of  the
program where it goes wrong.:

In the On_Print procedure:

      last_line := integer(nr) - 1;
      Print_Op := new Gtkada_Print_Operation_Record;
      Gtkada.Printing.Initialize (Print_Op);
      Gtk_New(Print_Set);
      Set_Current_Page (Print_Op, 1);
      Number := long_float(last_line) / long_float(delta_lines);
      Number := long_float'Rounding(Number + 0.4999999);
      nr_Pages := Gint(Number);
      Set_N_Pages (Print_Op, nr_Pages);
      Set_Use_Full_Page(Print_Op, true);
      Set_Unit (Print_Op, points);
      Print_Op.Set_Print_Settings(Print_Set);
--------------------------------------------------------------------
--   procedure On_Draw_Page
--      (Self  : not null access Gtk_Print_Operation_Record;
--       Call  : Cb_Gtk_Print_Operation_Gtk_Print_Context_Gint_Void;
--       After : Boolean := False);
--------------------------------------------------------------------
      On_Draw_Page(Print_Op, Draw);
      Result := Connect_and_Run(Print_Op ,Action_Print_Dialog, Main_Window);

Draw is declared as

Draw      : Cb_Gtk_Print_Operation_Gtk_Print_Context_Gint_Void
            := Draw_Page'Access;


and  the Draw_Page procedure

   procedure Draw_Page
     (Op          : access Gtk_Print_Operation_Record'Class;
      Context     : not null access Gtk_Print_Context_Record'Class;
      Page_Number : Gint) is
      Cr    : Cairo_Context;
      nr    : integer;
      width : integer;
      rb    : boolean;
--      re    : boolean;
      ok    : boolean;
      str   : Unbounded_String;
   begin
      nr := first_line;
      Cr := Get_Cairo_Context (Context);
      Set_Source_Rgb (Cr, 0.0, 0.0, 0.0);
      Select_font_face(Cr, "Monospace", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
      Set_Font_Size(Cr, GDouble(9));
      if nr = 1 then
         pagenr := 1;
      else
         pagenr := pagenr + 1;
      end if;
      if pagenr rem 2 = 1 then
         width := 70;
      else
         width := 40;
      end if;
      if last_page_line > last_line then
         last_page_line := last_line;
      end if;
      ok := false;
      while not ok loop
         Get_Iter_At_Line(Main_Window.Draw_Buffer, first, Gint(nr));
         Get_Iter_At_Line_Offset(Main_Window.Draw_Buffer, endln, Gint(nr), 500);
         move_to(cr, Gdouble(width), Gdouble((nr - first_line + 1) * 13 + 65));
         str :=
To_Unbounded_String(Get_Text(Main_Window.Draw_Buffer,first,endln));
         show_text(cr, To_String(str));
         nr := nr + 1;
         ok := nr >= last_page_line;
         if nr <= last_line then
            Forward_Line(first, rb);
         end if;
      end loop;
      first_line := nr - 1;
      last_page_line := last_page_line + delta_lines;
   end Draw_Page; 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/gtkada/attachments/20181126/1bc02111/attachment.html>


More information about the gtkada mailing list