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