1. ------------------------------------------------------------------------------ 
  2. --                                                                          -- 
  3. --      Copyright (C) 1998-2000 E. Briot, J. Brobecker and A. Charlet       -- 
  4. --                     Copyright (C) 2000-2014, AdaCore                     -- 
  5. --                                                                          -- 
  6. -- This library is free software;  you can redistribute it and/or modify it -- 
  7. -- under terms of the  GNU General Public License  as published by the Free -- 
  8. -- Software  Foundation;  either version 3,  or (at your  option) any later -- 
  9. -- version. This library is distributed in the hope that it will be useful, -- 
  10. -- but WITHOUT ANY WARRANTY;  without even the implied warranty of MERCHAN- -- 
  11. -- TABILITY or FITNESS FOR A PARTICULAR PURPOSE.                            -- 
  12. --                                                                          -- 
  13. -- As a special exception under Section 7 of GPL version 3, you are granted -- 
  14. -- additional permissions described in the GCC Runtime Library Exception,   -- 
  15. -- version 3.1, as published by the Free Software Foundation.               -- 
  16. --                                                                          -- 
  17. -- You should have received a copy of the GNU General Public License and    -- 
  18. -- a copy of the GCC Runtime Library Exception along with this program;     -- 
  19. -- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    -- 
  20. -- <http://www.gnu.org/licenses/>.                                          -- 
  21. --                                                                          -- 
  22. ------------------------------------------------------------------------------ 
  23.  
  24. --  <description> 
  25. --  A GtkPrintContext encapsulates context information that is required when 
  26. --  drawing pages for printing, such as the cairo context and important 
  27. --  parameters like page size and resolution. It also lets you easily create 
  28. --  Pango.Layout.Pango_Layout and Pango.Context.Pango_Context objects that 
  29. --  match the font metrics of the cairo surface. 
  30. -- 
  31. --  GtkPrintContext objects gets passed to the 
  32. --  Gtk.Print_Operation.Gtk_Print_Operation::begin-print, 
  33. --  Gtk.Print_Operation.Gtk_Print_Operation::end-print, 
  34. --  Gtk.Print_Operation.Gtk_Print_Operation::request-page-setup and 
  35. --  Gtk.Print_Operation.Gtk_Print_Operation::draw-page signals on the 
  36. --  Gtk.Print_Operation.Gtk_Print_Operation. 
  37. -- 
  38. --  == Using GtkPrintContext in a 
  39. --  Gtk.Print_Operation.Gtk_Print_Operation::draw-page callback == 
  40. -- 
  41. --    static void 
  42. --    draw_page (GtkPrintOperation *operation, 
  43. --       GtkPrintContext   *context, 
  44. --       int                page_nr) 
  45. --    { 
  46. --       cairo_t *cr; 
  47. --       PangoLayout *layout; 
  48. --       PangoFontDescription *desc; 
  49. --       cr = gtk_print_context_get_cairo_context (context); 
  50. --       // Draw a red rectangle, as wide as the paper (inside the margins) 
  51. --       cairo_set_source_rgb (cr, 1.0, 0, 0); 
  52. --       cairo_rectangle (cr, 0, 0, gtk_print_context_get_width (context), 50); 
  53. --       cairo_fill (cr); 
  54. --       // Draw some lines 
  55. --       cairo_move_to (cr, 20, 10); 
  56. --       cairo_line_to (cr, 40, 20); 
  57. --       cairo_arc (cr, 60, 60, 20, 0, M_PI); 
  58. --       cairo_line_to (cr, 80, 20); 
  59. --       cairo_set_source_rgb (cr, 0, 0, 0); 
  60. --       cairo_set_line_width (cr, 5); 
  61. --       cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); 
  62. --       cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND); 
  63. --       cairo_stroke (cr); 
  64. --       // Draw some text 
  65. --       layout = gtk_print_context_create_layout (context); 
  66. --       pango_layout_set_text (layout, "Hello World! Printing is easy", -1); 
  67. --       desc = pango_font_description_from_string ("sans 28"); 
  68. --       pango_layout_set_font_description (layout, desc); 
  69. --       pango_font_description_free (desc); 
  70. --       cairo_move_to (cr, 30, 20); 
  71. --       pango_cairo_layout_path (cr, layout); 
  72. --       // Font Outline 
  73. --       cairo_set_source_rgb (cr, 0.93, 1.0, 0.47); 
  74. --       cairo_set_line_width (cr, 0.5); 
  75. --       cairo_stroke_preserve (cr); 
  76. --       // Font Fill 
  77. --       cairo_set_source_rgb (cr, 0, 0.0, 1.0); 
  78. --       cairo_fill (cr); 
  79. --       g_object_unref (layout); 
  80. --    } 
  81. -- 
  82. --  Printing support was added in GTK+ 2.10. 
  83. -- 
  84. --  </description> 
  85. pragma Ada_2005; 
  86.  
  87. pragma Warnings (Off, "*is already use-visible*"); 
  88. with Cairo;          use Cairo; 
  89. with Glib;           use Glib; 
  90. with Glib.Object;    use Glib.Object; 
  91. with Gtk.Page_Setup; use Gtk.Page_Setup; 
  92. with Pango.Context;  use Pango.Context; 
  93. with Pango.Font_Map; use Pango.Font_Map; 
  94. with Pango.Layout;   use Pango.Layout; 
  95.  
  96. package Gtk.Print_Context is 
  97.  
  98.    type Gtk_Print_Context_Record is new GObject_Record with null record; 
  99.    type Gtk_Print_Context is access all Gtk_Print_Context_Record'Class; 
  100.  
  101.    ------------------ 
  102.    -- Constructors -- 
  103.    ------------------ 
  104.  
  105.    function Get_Type return Glib.GType; 
  106.    pragma Import (C, Get_Type, "gtk_print_context_get_type"); 
  107.  
  108.    ------------- 
  109.    -- Methods -- 
  110.    ------------- 
  111.  
  112.    function Create_Pango_Context 
  113.       (Context : not null access Gtk_Print_Context_Record) 
  114.        return Pango.Context.Pango_Context; 
  115.    --  Creates a new Pango.Context.Pango_Context that can be used with the 
  116.    --  Gtk.Print_Context.Gtk_Print_Context. 
  117.    --  Since: gtk+ 2.10 
  118.  
  119.    function Create_Pango_Layout 
  120.       (Context : not null access Gtk_Print_Context_Record) 
  121.        return Pango.Layout.Pango_Layout; 
  122.    --  Creates a new Pango.Layout.Pango_Layout that is suitable for use with 
  123.    --  the Gtk.Print_Context.Gtk_Print_Context. 
  124.    --  Since: gtk+ 2.10 
  125.  
  126.    function Get_Cairo_Context 
  127.       (Context : not null access Gtk_Print_Context_Record) 
  128.        return Cairo.Cairo_Context; 
  129.    --  Obtains the cairo context that is associated with the 
  130.    --  Gtk.Print_Context.Gtk_Print_Context. 
  131.    --  Since: gtk+ 2.10 
  132.  
  133.    procedure Set_Cairo_Context 
  134.       (Context : not null access Gtk_Print_Context_Record; 
  135.        Cr      : Cairo.Cairo_Context; 
  136.        Dpi_X   : Gdouble; 
  137.        Dpi_Y   : Gdouble); 
  138.    --  Sets a new cairo context on a print context. 
  139.    --  This function is intended to be used when implementing an internal 
  140.    --  print preview, it is not needed for printing, since GTK+ itself creates 
  141.    --  a suitable cairo context in that case. 
  142.    --  Since: gtk+ 2.10 
  143.    --  "cr": the cairo context 
  144.    --  "dpi_x": the horizontal resolution to use with Cr 
  145.    --  "dpi_y": the vertical resolution to use with Cr 
  146.  
  147.    function Get_Dpi_X 
  148.       (Context : not null access Gtk_Print_Context_Record) return Gdouble; 
  149.    --  Obtains the horizontal resolution of the 
  150.    --  Gtk.Print_Context.Gtk_Print_Context, in dots per inch. 
  151.    --  Since: gtk+ 2.10 
  152.  
  153.    function Get_Dpi_Y 
  154.       (Context : not null access Gtk_Print_Context_Record) return Gdouble; 
  155.    --  Obtains the vertical resolution of the 
  156.    --  Gtk.Print_Context.Gtk_Print_Context, in dots per inch. 
  157.    --  Since: gtk+ 2.10 
  158.  
  159.    function Get_Hard_Margins 
  160.       (Context : not null access Gtk_Print_Context_Record; 
  161.        Top     : access Gdouble; 
  162.        Bottom  : access Gdouble; 
  163.        Left    : access Gdouble; 
  164.        Right   : access Gdouble) return Boolean; 
  165.    --  Obtains the hardware printer margins of the 
  166.    --  Gtk.Print_Context.Gtk_Print_Context, in units. 
  167.    --  Since: gtk+ 2.20 
  168.    --  "top": top hardware printer margin 
  169.    --  "bottom": bottom hardware printer margin 
  170.    --  "left": left hardware printer margin 
  171.    --  "right": right hardware printer margin 
  172.  
  173.    function Get_Height 
  174.       (Context : not null access Gtk_Print_Context_Record) return Gdouble; 
  175.    --  Obtains the height of the Gtk.Print_Context.Gtk_Print_Context, in 
  176.    --  pixels. 
  177.    --  Since: gtk+ 2.10 
  178.  
  179.    function Get_Page_Setup 
  180.       (Context : not null access Gtk_Print_Context_Record) 
  181.        return Gtk.Page_Setup.Gtk_Page_Setup; 
  182.    --  Obtains the Gtk.Page_Setup.Gtk_Page_Setup that determines the page 
  183.    --  dimensions of the Gtk.Print_Context.Gtk_Print_Context. 
  184.    --  Since: gtk+ 2.10 
  185.  
  186.    function Get_Pango_Fontmap 
  187.       (Context : not null access Gtk_Print_Context_Record) 
  188.        return Pango.Font_Map.Pango_Font_Map; 
  189.    --  Returns a Pango.Font_Map.Pango_Font_Map that is suitable for use with 
  190.    --  the Gtk.Print_Context.Gtk_Print_Context. 
  191.    --  Since: gtk+ 2.10 
  192.  
  193.    function Get_Width 
  194.       (Context : not null access Gtk_Print_Context_Record) return Gdouble; 
  195.    --  Obtains the width of the Gtk.Print_Context.Gtk_Print_Context, in 
  196.    --  pixels. 
  197.    --  Since: gtk+ 2.10 
  198.  
  199. end Gtk.Print_Context;