1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module gtk.PrintContext; 26 27 private import cairo.Context; 28 private import gobject.ObjectG; 29 private import gtk.PageSetup; 30 private import gtk.c.functions; 31 public import gtk.c.types; 32 public import gtkc.gtktypes; 33 private import pango.PgContext; 34 private import pango.PgFontMap; 35 private import pango.PgLayout; 36 37 38 /** 39 * A GtkPrintContext encapsulates context information that is required when 40 * drawing pages for printing, such as the cairo context and important 41 * parameters like page size and resolution. It also lets you easily 42 * create #PangoLayout and #PangoContext objects that match the font metrics 43 * of the cairo surface. 44 * 45 * GtkPrintContext objects gets passed to the #GtkPrintOperation::begin-print, 46 * #GtkPrintOperation::end-print, #GtkPrintOperation::request-page-setup and 47 * #GtkPrintOperation::draw-page signals on the #GtkPrintOperation. 48 * 49 * ## Using GtkPrintContext in a #GtkPrintOperation::draw-page callback 50 * 51 * |[<!-- language="C" --> 52 * static void 53 * draw_page (GtkPrintOperation *operation, 54 * GtkPrintContext *context, 55 * int page_nr) 56 * { 57 * cairo_t *cr; 58 * PangoLayout *layout; 59 * PangoFontDescription *desc; 60 * 61 * cr = gtk_print_context_get_cairo_context (context); 62 * 63 * // Draw a red rectangle, as wide as the paper (inside the margins) 64 * cairo_set_source_rgb (cr, 1.0, 0, 0); 65 * cairo_rectangle (cr, 0, 0, gtk_print_context_get_width (context), 50); 66 * 67 * cairo_fill (cr); 68 * 69 * // Draw some lines 70 * cairo_move_to (cr, 20, 10); 71 * cairo_line_to (cr, 40, 20); 72 * cairo_arc (cr, 60, 60, 20, 0, M_PI); 73 * cairo_line_to (cr, 80, 20); 74 * 75 * cairo_set_source_rgb (cr, 0, 0, 0); 76 * cairo_set_line_width (cr, 5); 77 * cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); 78 * cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND); 79 * 80 * cairo_stroke (cr); 81 * 82 * // Draw some text 83 * layout = gtk_print_context_create_layout (context); 84 * pango_layout_set_text (layout, "Hello World! Printing is easy", -1); 85 * desc = pango_font_description_from_string ("sans 28"); 86 * pango_layout_set_font_description (layout, desc); 87 * pango_font_description_free (desc); 88 * 89 * cairo_move_to (cr, 30, 20); 90 * pango_cairo_layout_path (cr, layout); 91 * 92 * // Font Outline 93 * cairo_set_source_rgb (cr, 0.93, 1.0, 0.47); 94 * cairo_set_line_width (cr, 0.5); 95 * cairo_stroke_preserve (cr); 96 * 97 * // Font Fill 98 * cairo_set_source_rgb (cr, 0, 0.0, 1.0); 99 * cairo_fill (cr); 100 * 101 * g_object_unref (layout); 102 * } 103 * ]| 104 * 105 * Printing support was added in GTK+ 2.10. 106 */ 107 public class PrintContext : ObjectG 108 { 109 /** the main Gtk struct */ 110 protected GtkPrintContext* gtkPrintContext; 111 112 /** Get the main Gtk struct */ 113 public GtkPrintContext* getPrintContextStruct(bool transferOwnership = false) 114 { 115 if (transferOwnership) 116 ownedRef = false; 117 return gtkPrintContext; 118 } 119 120 /** the main Gtk struct as a void* */ 121 protected override void* getStruct() 122 { 123 return cast(void*)gtkPrintContext; 124 } 125 126 protected override void setStruct(GObject* obj) 127 { 128 gtkPrintContext = cast(GtkPrintContext*)obj; 129 super.setStruct(obj); 130 } 131 132 /** 133 * Sets our main struct and passes it to the parent class. 134 */ 135 public this (GtkPrintContext* gtkPrintContext, bool ownedRef = false) 136 { 137 this.gtkPrintContext = gtkPrintContext; 138 super(cast(GObject*)gtkPrintContext, ownedRef); 139 } 140 141 142 /** */ 143 public static GType getType() 144 { 145 return gtk_print_context_get_type(); 146 } 147 148 /** 149 * Creates a new #PangoContext that can be used with the 150 * #GtkPrintContext. 151 * 152 * Returns: a new Pango context for @context 153 * 154 * Since: 2.10 155 */ 156 public PgContext createPangoContext() 157 { 158 auto p = gtk_print_context_create_pango_context(gtkPrintContext); 159 160 if(p is null) 161 { 162 return null; 163 } 164 165 return ObjectG.getDObject!(PgContext)(cast(PangoContext*) p, true); 166 } 167 168 /** 169 * Creates a new #PangoLayout that is suitable for use 170 * with the #GtkPrintContext. 171 * 172 * Returns: a new Pango layout for @context 173 * 174 * Since: 2.10 175 */ 176 public PgLayout createPangoLayout() 177 { 178 auto p = gtk_print_context_create_pango_layout(gtkPrintContext); 179 180 if(p is null) 181 { 182 return null; 183 } 184 185 return ObjectG.getDObject!(PgLayout)(cast(PangoLayout*) p, true); 186 } 187 188 /** 189 * Obtains the cairo context that is associated with the 190 * #GtkPrintContext. 191 * 192 * Returns: the cairo context of @context 193 * 194 * Since: 2.10 195 */ 196 public Context getCairoContext() 197 { 198 auto p = gtk_print_context_get_cairo_context(gtkPrintContext); 199 200 if(p is null) 201 { 202 return null; 203 } 204 205 return new Context(cast(cairo_t*) p); 206 } 207 208 /** 209 * Obtains the horizontal resolution of the #GtkPrintContext, 210 * in dots per inch. 211 * 212 * Returns: the horizontal resolution of @context 213 * 214 * Since: 2.10 215 */ 216 public double getDpiX() 217 { 218 return gtk_print_context_get_dpi_x(gtkPrintContext); 219 } 220 221 /** 222 * Obtains the vertical resolution of the #GtkPrintContext, 223 * in dots per inch. 224 * 225 * Returns: the vertical resolution of @context 226 * 227 * Since: 2.10 228 */ 229 public double getDpiY() 230 { 231 return gtk_print_context_get_dpi_y(gtkPrintContext); 232 } 233 234 /** 235 * Obtains the hardware printer margins of the #GtkPrintContext, in units. 236 * 237 * Params: 238 * top = top hardware printer margin 239 * bottom = bottom hardware printer margin 240 * left = left hardware printer margin 241 * right = right hardware printer margin 242 * 243 * Returns: %TRUE if the hard margins were retrieved 244 * 245 * Since: 2.20 246 */ 247 public bool getHardMargins(out double top, out double bottom, out double left, out double right) 248 { 249 return gtk_print_context_get_hard_margins(gtkPrintContext, &top, &bottom, &left, &right) != 0; 250 } 251 252 /** 253 * Obtains the height of the #GtkPrintContext, in pixels. 254 * 255 * Returns: the height of @context 256 * 257 * Since: 2.10 258 */ 259 public double getHeight() 260 { 261 return gtk_print_context_get_height(gtkPrintContext); 262 } 263 264 /** 265 * Obtains the #GtkPageSetup that determines the page 266 * dimensions of the #GtkPrintContext. 267 * 268 * Returns: the page setup of @context 269 * 270 * Since: 2.10 271 */ 272 public PageSetup getPageSetup() 273 { 274 auto p = gtk_print_context_get_page_setup(gtkPrintContext); 275 276 if(p is null) 277 { 278 return null; 279 } 280 281 return ObjectG.getDObject!(PageSetup)(cast(GtkPageSetup*) p); 282 } 283 284 /** 285 * Returns a #PangoFontMap that is suitable for use 286 * with the #GtkPrintContext. 287 * 288 * Returns: the font map of @context 289 * 290 * Since: 2.10 291 */ 292 public PgFontMap getPangoFontmap() 293 { 294 auto p = gtk_print_context_get_pango_fontmap(gtkPrintContext); 295 296 if(p is null) 297 { 298 return null; 299 } 300 301 return ObjectG.getDObject!(PgFontMap)(cast(PangoFontMap*) p); 302 } 303 304 /** 305 * Obtains the width of the #GtkPrintContext, in pixels. 306 * 307 * Returns: the width of @context 308 * 309 * Since: 2.10 310 */ 311 public double getWidth() 312 { 313 return gtk_print_context_get_width(gtkPrintContext); 314 } 315 316 /** 317 * Sets a new cairo context on a print context. 318 * 319 * This function is intended to be used when implementing 320 * an internal print preview, it is not needed for printing, 321 * since GTK+ itself creates a suitable cairo context in that 322 * case. 323 * 324 * Params: 325 * cr = the cairo context 326 * dpiX = the horizontal resolution to use with @cr 327 * dpiY = the vertical resolution to use with @cr 328 * 329 * Since: 2.10 330 */ 331 public void setCairoContext(Context cr, double dpiX, double dpiY) 332 { 333 gtk_print_context_set_cairo_context(gtkPrintContext, (cr is null) ? null : cr.getContextStruct(), dpiX, dpiY); 334 } 335 }