PageRenderTime 14ms CodeModel.GetById 7ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

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