comp.lang.ada
 help / color / mirror / Atom feed
* Gtk Printing programming problem a one page file does not print
@ 2018-11-23  9:55 ldries46
  0 siblings, 0 replies; only message in thread
From: ldries46 @ 2018-11-23  9:55 UTC (permalink / raw)


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; 


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2018-11-23  9:55 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-23  9:55 Gtk Printing programming problem a one page file does not print ldries46

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox