manpagez: man pages & more
html files: pygtk
Home | html | info | man
): def get_cairo_context()
def get_page_setup()
def get_width()
def get_height()
def get_dpi_x()
def get_dpi_y()
def get_pango_fontmap()
def create_pango_context()
def create_pango_layout()
def set_cairo_context(cr, dpi_x, dpi_y)

Ancestry

+-- gobject.GObject
  +-- gtk.PrintContext

gtk.PrintContext Signal Prototypes

gobject.GObject Signal Prototypes

Description

A gtk.PrintContext encapsulates context information that is required when drawing pages for printing, such as the cairo context and important parameters like page size and resolution. It also lets you easily create pango.Layout and pango.Context objects that match the font metrics of the cairo surface.

gtk.PrintContext objects gets passed to the "begin-print", "end-print", "request-page-setup" and "draw-page" signals on the gtk.PrintOperation.

Example 2. Using gtk.PrintContext in a "draw-page" callback

def draw_page(operation, context, page_nr):
  cr = context.get_cairo_context()

  # Draw a red rectangle, as wide as the paper (inside the margins)
  cr.set_source_rgb(1.0, 0, 0)
  cr.rectangle(0, 0, context.get_width(), 50)
  
  cr.fill()

  # Draw some lines
  cr.move_to(20, 10)
  cr.line_to(40, 20)
  cr.arc(60, 60, 20, 0, M_PI)
  cr.line_to(80, 20)
  
  cr.set_source_rgb(0, 0, 0)
  cr.set_line_width(5)
  cr.set_line_cap(cairo.LINE_CAP_ROUND)
  cr.set_line_join(cairo.LINE_JOIN_ROUND)
  
  cr.stroke()

  # Draw some text
  layout = context.create_layout()
  layout.set_text("Hello World! Printing is easy")
  desc = pango.FontDescription("sans 28")
  layout.set_font_description(desc)

  cr.move_to(30, 20)
  layout.layout_path()

  # Font Outline
  cr.set_source_rgb(0.93, 1.0, 0.47)
  cr.set_line_width(0.5)
  cr.stroke_preserve()

  # Font Fill
  cr.set_source_rgb(0, 0.0, 1.0)
  cr.fill()

Printing support was added in GTK+ 2.10.

Methods

gtk.PrintContext.get_cairo_context

    def get_cairo_context()

Returns :

the cairo context

Note

This method is available in PyGTK 2.10 and above.

The get_cairo_context() method returns the cairo context that is associated with the gtk.PrintContext.

gtk.PrintContext.get_page_setup

    def get_page_setup()

Returns :

the page setup

Note

This method is available in PyGTK 2.10 and above.

The get_page_setup() method returns the gtk.PageSetup that determines the page dimensions of the gtk.PrintContext.

gtk.PrintContext.get_width

    def get_width()

Returns :

the width

Note

This method is available in PyGTK 2.10 and above.

The get_width() method returns the width of the gtk.PrintContext, in pixels.

gtk.PrintContext.get_height

    def get_height()

Returns :

the height

Note

This method is available in PyGTK 2.10 and above.

The get_height() method returns the width of the gtk.PrintContext, in pixels.

gtk.PrintContext.get_dpi_x

    def get_dpi_x()

Returns :

the horizontal resolution

Note

This method is available in PyGTK 2.10 and above.

The get_dpi_x() method returns the horizontal resolution of the gtk.PrintContext, in dots per inch.

gtk.PrintContext.get_dpi_y

    def get_dpi_y()

Returns :

the vertical resolution

Note

This method is available in PyGTK 2.10 and above.

The get_dpi_y() method returns the vertical resolution of the gtk.PrintContext, in dots per inch.

gtk.PrintContext.get_pango_fontmap

    def get_pango_fontmap()

Returns :

the font map

Note

This method is available in PyGTK 2.10 and above.

The method returns a pango.FontMap that is suitable for use with the gtk.PrintContext.

gtk.PrintContext.create_pango_context

    def create_pango_context()

Returns :

a new pango.Context

Note

This method is available in PyGTK 2.10 and above.

The create_pango_context() method creates a new pango.Context that can be used with the gtk.PrintContext.

gtk.PrintContext.create_pango_layout

    def create_pango_layout()

Returns :

a new pango.Layout

Note

This method is available in PyGTK 2.10 and above.

The create_pango_layout() method creates a new pango.Layout that is suitable for use with the gtk.PrintContext.

gtk.PrintContext.set_cairo_context

    def set_cairo_context(cr, dpi_x, dpi_y)

cr :

dpi_x :

dpi_y :

Note

This method is available in PyGTK 2.10 and above.

The set_cairo_context() method sets the CairoContext specified by cr as the cairo context for the print context. dpi_x and dpi_y specify the horizontal and vertical resolution of the print context.

© manpagez.com 2000-2024
Individual documents may contain additional copyright information.