Gtk.PrintContext¶
- Subclasses:
None
Methods¶
- Inherited:
- Structs:
|
|
|
|
|
|
|
|
|
Virtual Methods¶
- Inherited:
Properties¶
None
Signals¶
- Inherited:
Fields¶
- Inherited:
Class Details¶
- class Gtk.PrintContext(**kwargs)¶
- Bases:
- Abstract:
No
A
GtkPrintContext
encapsulates context information that is required when drawing pages for printing.This includes the cairo context and important parameters like page size and resolution. It also lets you easily create [class`Pango`.Layout] and [class`Pango`.Context] objects that match the font metrics of the cairo surface.
GtkPrintContext
objects get passed to the [signal`Gtk`.PrintOperation::begin-print], [signal`Gtk`.PrintOperation::end-print], [signal`Gtk`.PrintOperation::request-page-setup] and [signal`Gtk`.PrintOperation::draw-page] signals on the [class`Gtk`.PrintOperation] object.- Using
Gtk.PrintContext
in a::draw-page
callback
```c static void draw_page (
Gtk.PrintOperation
*operation,Gtk.PrintContext
*context, int page_nr) {cairo.Context
*cr;Pango.Layout
*layout;Pango.FontDescription
*desc;cr =
Gtk.PrintContext.get_cairo_context
(context);// Draw a red rectangle, as wide as the paper (inside the margins)
cairo.Context.set_source_rgb
(cr, 1.0, 0, 0);cairo.Context.rectangle
(cr, 0, 0,Gtk.PrintContext.get_width
(context), 50);cairo.Context.fill
(cr);// Draw some lines
cairo.Context.move_to
(cr, 20, 10);cairo.Context.line_to
(cr, 40, 20);cairo.Context.arc
(cr, 60, 60, 20, 0, M_PI);cairo.Context.line_to
(cr, 80, 20);cairo.Context.set_source_rgb
(cr, 0, 0, 0);cairo.Context.set_line_width
(cr, 5);cairo.Context.set_line_cap
(cr,cairo.LineCap.ROUND
);cairo.Context.set_line_join
(cr,cairo.LineJoin.ROUND
);cairo.Context.stroke
(cr);// Draw some text layout =
Gtk.PrintContext.create_pango_layout
(context);Pango.Layout.set_text
(layout, “Hello World! Printing is easy”, -1); desc =Pango.FontDescription.from_string
(“sans 28”);Pango.Layout.set_font_description
(layout, desc);Pango.FontDescription.free
(desc);cairo.Context.move_to
(cr, 30, 20);PangoCairo.layout_path
(cr, layout);// Font Outline
cairo.Context.set_source_rgb
(cr, 0.93, 1.0, 0.47);cairo.Context.set_line_width
(cr, 0.5);cairo.Context.stroke_preserve
(cr);// Font Fill
cairo.Context.set_source_rgb
(cr, 0, 0.0, 1.0);cairo.Context.fill
(cr);GObject.Object.unref
(layout); } ```- create_pango_context()[source]¶
- Returns:
a new Pango context for self
- Return type:
Creates a new
PangoContext
that can be used with theGtkPrintContext
.
- create_pango_layout()[source]¶
- Returns:
a new Pango layout for self
- Return type:
Creates a new
PangoLayout
that is suitable for use with theGtkPrintContext
.
- get_cairo_context()[source]¶
- Returns:
the cairo context of self
- Return type:
Obtains the cairo context that is associated with the
GtkPrintContext
.
- get_dpi_x()[source]¶
- Returns:
the horizontal resolution of self
- Return type:
Obtains the horizontal resolution of the
GtkPrintContext
, in dots per inch.
- get_dpi_y()[source]¶
- Returns:
the vertical resolution of self
- Return type:
Obtains the vertical resolution of the
GtkPrintContext
, in dots per inch.
- get_hard_margins()[source]¶
- Returns:
True
if the hard margins were retrieved- top:
top hardware printer margin
- bottom:
bottom hardware printer margin
- left:
left hardware printer margin
- right:
right hardware printer margin
- Return type:
(
bool
, top:float
, bottom:float
, left:float
, right:float
)
Obtains the hardware printer margins of the
GtkPrintContext
, in units.
- get_height()[source]¶
- Returns:
the height of self
- Return type:
Obtains the height of the
GtkPrintContext
, in pixels.
- get_page_setup()[source]¶
- Returns:
the page setup of self
- Return type:
Obtains the
GtkPageSetup
that determines the page dimensions of theGtkPrintContext
.
- get_pango_fontmap()[source]¶
- Returns:
the font map of self
- Return type:
Returns a
PangoFontMap
that is suitable for use with theGtkPrintContext
.
- get_width()[source]¶
- Returns:
the width of self
- Return type:
Obtains the width of the
GtkPrintContext
, in pixels.
- set_cairo_context(cr, dpi_x, dpi_y)[source]¶
- Parameters:
cr (
cairo.Context
) – the cairo contextdpi_x (
float
) – the horizontal resolution to use with crdpi_y (
float
) – the vertical resolution to use with cr
Sets a new cairo context on a print context.
This function is intended to be used when implementing an internal print preview, it is not needed for printing, since GTK itself creates a suitable cairo context in that case.