/src/wrappers/gtk/library/gtk_print_context.e

http://github.com/tybor/Liberty · Specman e · 239 lines · 103 code · 38 blank · 98 comment · 2 complexity · fe35a12b41fd672fd0b896a811b9082e MD5 · raw file

  1. indexing
  2. description: "GtkPrintContext -- Encapsulates context for drawing pages."
  3. copyright: "[
  4. Copyright (C) 2007 Paolo Redaelli, GTK+ team
  5. This library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public License
  7. as published by the Free Software Foundation; either version 2.1 of
  8. the License, or (at your option) any later version.
  9. This library is distributed in the hopeOA that it will be useful, but
  10. WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with this library; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  16. 02110-1301 USA
  17. ]"
  18. wrapped_version: "2.10.6"
  19. class GTK_PRINT_CONTEXT
  20. -- A GtkPrintContext encapsulates context information that is required when
  21. -- drawing pages for printing, such as the cairo context and important
  22. -- parameters like page size and resolution. It also lets you easily create
  23. -- PangoLayout and PangoContext objects that match the font metrics of the
  24. -- cairo surface.
  25. -- GtkPrintContext objects gets passed to the ::begin-print, ::end-print,
  26. -- ::request-page-setup and ::draw-page signals on the GtkPrintOperation.
  27. -- TODO: Eiffelize this example Example 2. Using GtkPrintContext in a
  28. -- ::draw-page callback
  29. -- static void
  30. -- draw_page (GtkPrintOperation *operation,
  31. -- GtkPrintContext *context,
  32. -- int page_nr)
  33. -- {
  34. -- cairo_t *cr;
  35. -- PangoLayout *layout;
  36. -- PangoFontDescription *desc;
  37. --
  38. -- cr = gtk_print_context_get_cairo_context (context);
  39. --
  40. -- /* Draw a red rectangle, as wide as the paper (inside the margins) */
  41. -- cairo_set_source_rgb (cr, 1.0, 0, 0);
  42. -- cairo_rectangle (cr, 0, 0, gtk_print_context_get_width (context), 50);
  43. --
  44. -- cairo_fill (cr);
  45. --
  46. -- /* Draw some lines */
  47. -- cairo_move_to (cr, 20, 10);
  48. -- cairo_line_to (cr, 40, 20);
  49. -- cairo_arc (cr, 60, 60, 20, 0, M_PI);
  50. -- cairo_line_to (cr, 80, 20);
  51. --
  52. -- cairo_set_source_rgb (cr, 0, 0, 0);
  53. -- cairo_set_line_width (cr, 5);
  54. -- cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
  55. -- cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND);
  56. --
  57. -- cairo_stroke (cr);
  58. --
  59. -- /* Draw some text */
  60. -- layout = gtk_print_context_create_layout (context);
  61. -- pango_layout_set_text (layout, "Hello World! Printing is easy", -1);
  62. -- desc = pango_font_description_from_string ("sans 28");
  63. -- pango_layout_set_font_description (layout, desc);
  64. -- pango_font_description_free (desc);
  65. --
  66. -- cairo_move_to (cr, 30, 20);
  67. -- pango_cairo_layout_path (cr, layout);
  68. --
  69. -- /* Font Outline */
  70. -- cairo_set_source_rgb (cr, 0.93, 1.0, 0.47);
  71. -- cairo_set_line_width (cr, 0.5);
  72. -- cairo_stroke_preserve (cr);
  73. --
  74. -- /* Font Fill */
  75. -- cairo_set_source_rgb (cr, 0, 0.0, 1.0);
  76. -- cairo_fill (cr);
  77. --
  78. -- g_object_unref (layout);
  79. -- }
  80. -- Printing support was added in GTK+ 2.10.
  81. inherit G_OBJECT
  82. creation from_external_pointer
  83. feature {} -- Creation
  84. context: CAIRO_CONTEXT is
  85. -- the cairo context that is associated with the
  86. -- GTK_PRINT_CONTEXT.
  87. do
  88. create Result.from_external_pointer(gtk_print_context_get_cairo_context(handle))
  89. end
  90. set_context (a_context: CAIRO_CONTEXT; an_x_dpi, an_y_dpi: REAL) is
  91. -- Sets a new cairo context on a print context.
  92. -- This function is intended to be used when implementing an
  93. -- internal print preview, it is not needed for printing,
  94. -- since GTK+ itself creates a suitable cairo context in that
  95. -- case.
  96. -- `an_x_dpi': the horizontal resolution to use with
  97. -- `a_context'
  98. -- `an_y_dpi': the vertical resolution to use with
  99. -- `a_context'
  100. require context_not_void: a_context/=Void
  101. do
  102. gtk_print_context_set_cairo_context(handle,a_context.handle,
  103. an_x_dpi, an_y_dpi)
  104. end
  105. page_setup: GTK_PAGE_SETUP is
  106. -- the GtkPageSetup that determines the page dimensions of
  107. -- the GtkPrintContext.
  108. do
  109. create Result.from_external_pointer(gtk_print_context_get_page_setup(handle))
  110. end
  111. width: REAL is
  112. -- the width of context, in pixels.
  113. do
  114. Result:=gtk_print_context_get_width(handle)
  115. end
  116. height: REAL is
  117. -- the height of context, in pixels.
  118. do
  119. Result:=gtk_print_context_get_height(handle)
  120. end
  121. dpi_x: REAL is
  122. -- the horizontal resolution of the GtkPrintContext, in dots per inch.
  123. do
  124. Result:=gtk_print_context_get_dpi_x(handle)
  125. end
  126. dpi_y: REAL is
  127. -- the vertical resolution of the GtkPrintContext, in dots per inch.
  128. do
  129. Result:=gtk_print_context_get_dpi_y(handle)
  130. end
  131. pango_font_map: PANGO_FONT_MAP is
  132. -- a PangoFontMap that is suitable for use with the
  133. -- GtkPrintContext.
  134. local factory: G_OBJECT_EXPANDED_FACTORY[PANGO_FONT_MAP]
  135. do
  136. Result := factory.wrapper(gtk_print_context_get_pango_fontmap(handle))
  137. end
  138. pango_context: PANGO_CONTEXT is
  139. -- a new PangoContext that can be used with the
  140. -- GtkPrintContext.
  141. do
  142. create Result.from_external_pointer(gtk_print_context_create_pango_context(handle))
  143. end
  144. pango_layout: PANGO_LAYOUT is
  145. -- a PangoLayout that is suitable for use with the GtkPrintContext.
  146. do
  147. create Result.from_external_pointer
  148. (gtk_print_context_create_pango_layout(handle))
  149. end
  150. feature {} -- External calls
  151. gtk_print_context_get_cairo_context (a_context: POINTER): POINTER is
  152. -- cairo_t* gtk_print_context_get_cairo_context (GtkPrintContext
  153. -- *context);
  154. external "C inline use <gtk/gtk.h>"
  155. end
  156. gtk_print_context_set_cairo_context (a_context, a_cairo: POINTER; a_dpi_x, a_dpi_y: REAL) is
  157. -- void gtk_print_context_set_cairo_context (GtkPrintContext *context,
  158. -- cairo_t *cr, double dpi_x, double dpi_y);
  159. external "C inline use <gtk/gtk.h>"
  160. end
  161. gtk_print_context_get_page_setup (a_context: POINTER): POINTER is
  162. -- GtkPageSetup* gtk_print_context_get_page_setup (GtkPrintContext *context);
  163. external "C inline use <gtk/gtk.h>"
  164. end
  165. gtk_print_context_get_width (a_context: POINTER): REAL is
  166. -- gdouble gtk_print_context_get_width (GtkPrintContext *context);
  167. external "C inline use <gtk/gtk.h>"
  168. end
  169. gtk_print_context_get_height (a_context: POINTER): REAL is
  170. -- gdouble gtk_print_context_get_height (GtkPrintContext *context);
  171. external "C inline use <gtk/gtk.h>"
  172. end
  173. gtk_print_context_get_dpi_x (a_context: POINTER): REAL is
  174. -- gdouble gtk_print_context_get_dpi_x (GtkPrintContext *context);
  175. external "C inline use <gtk/gtk.h>"
  176. end
  177. gtk_print_context_get_dpi_y (a_context: POINTER): REAL is
  178. -- gdouble gtk_print_context_get_dpi_y (GtkPrintContext *context);
  179. external "C inline use <gtk/gtk.h>"
  180. end
  181. gtk_print_context_get_pango_fontmap (a_context: POINTER): POINTER is
  182. -- PangoFontMap* gtk_print_context_get_pango_fontmap (GtkPrintContext
  183. -- *context);
  184. external "C inline use <gtk/gtk.h>"
  185. end
  186. gtk_print_context_create_pango_context (a_context: POINTER): POINTER is
  187. -- PangoContext* gtk_print_context_create_pango_context
  188. -- (GtkPrintContext --*context);
  189. external "C inline use <gtk/gtk.h>"
  190. end
  191. gtk_print_context_create_pango_layout (a_context: POINTER): POINTER is
  192. -- PangoLayout* gtk_print_context_create_pango_layout (GtkPrintContext
  193. -- *context);
  194. external "C inline use <gtk/gtk.h>"
  195. end
  196. feature -- size
  197. struct_size: INTEGER is
  198. external "C inline use <gtk/gtk.h>"
  199. alias "sizeof(GtkPrintContext)"
  200. end
  201. end -- class GTK_PRINT_CONTEXT