[]Struct gtk::PrintContext

pub struct PrintContext(_, _);

A 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.

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

Using PrintContext in a PrintOperation::draw-page callback

static void
draw_page (GtkPrintOperation *operation,
       GtkPrintContext   *context,
       int                page_nr)
{
  cairo_t *cr;
  PangoLayout *layout;
  PangoFontDescription *desc;

  cr = gtk_print_context_get_cairo_context (context);

  // Draw a red rectangle, as wide as the paper (inside the margins)
  cairo_set_source_rgb (cr, 1.0, 0, 0);
  cairo_rectangle (cr, 0, 0, gtk_print_context_get_width (context), 50);

  cairo_fill (cr);

  // Draw some lines
  cairo_move_to (cr, 20, 10);
  cairo_line_to (cr, 40, 20);
  cairo_arc (cr, 60, 60, 20, 0, M_PI);
  cairo_line_to (cr, 80, 20);

  cairo_set_source_rgb (cr, 0, 0, 0);
  cairo_set_line_width (cr, 5);
  cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
  cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND);

  cairo_stroke (cr);

  // Draw some text
  layout = gtk_print_context_create_pango_layout (context);
  pango_layout_set_text (layout, "Hello World! Printing is easy", -1);
  desc = pango_font_description_from_string ("sans 28");
  pango_layout_set_font_description (layout, desc);
  pango_font_description_free (desc);

  cairo_move_to (cr, 30, 20);
  pango_cairo_layout_path (cr, layout);

  // Font Outline
  cairo_set_source_rgb (cr, 0.93, 1.0, 0.47);
  cairo_set_line_width (cr, 0.5);
  cairo_stroke_preserve (cr);

  // Font Fill
  cairo_set_source_rgb (cr, 0, 0.0, 1.0);
  cairo_fill (cr);

  g_object_unref (layout);
}

Printing support was added in GTK+ 2.10.

Implements

glib::object::ObjectExt

Implementations

impl PrintContext[src]

pub fn create_pango_context(&self) -> Option<Context>[src]

Creates a new pango::Context that can be used with the PrintContext.

Returns

a new Pango context for self

pub fn create_pango_layout(&self) -> Option<Layout>[src]

Creates a new pango::Layout that is suitable for use with the PrintContext.

Returns

a new Pango layout for self

pub fn get_cairo_context(&self) -> Option<Context>[src]

Obtains the cairo context that is associated with the PrintContext.

Returns

the cairo context of self

pub fn get_dpi_x(&self) -> f64[src]

Obtains the horizontal resolution of the PrintContext, in dots per inch.

Returns

the horizontal resolution of self

pub fn get_dpi_y(&self) -> f64[src]

Obtains the vertical resolution of the PrintContext, in dots per inch.

Returns

the vertical resolution of self

pub fn get_hard_margins(&self) -> Option<(f64, f64, f64, f64)>[src]

Obtains the hardware printer margins of the PrintContext, in units.

top

top hardware printer margin

bottom

bottom hardware printer margin

left

left hardware printer margin

right hardware printer margin

Returns

true if the hard margins were retrieved

pub fn get_height(&self) -> f64[src]

Obtains the height of the PrintContext, in pixels.

Returns

the height of self

pub fn get_page_setup(&self) -> Option<PageSetup>[src]

Obtains the PageSetup that determines the page dimensions of the PrintContext.

Returns

the page setup of self

pub fn get_pango_fontmap(&self) -> Option<FontMap>[src]

Returns a pango::FontMap that is suitable for use with the PrintContext.

Returns

the font map of self

pub fn get_width(&self) -> f64[src]

Obtains the width of the PrintContext, in pixels.

Returns

the width of self

pub fn set_cairo_context(&self, cr: &Context, dpi_x: f64, dpi_y: f64)[src]

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.

cr

the cairo context

dpi_x

the horizontal resolution to use with cr

dpi_y

the vertical resolution to use with cr

Trait Implementations

impl Clone for PrintContext

impl Debug for PrintContext

impl Display for PrintContext[src]

impl Eq for PrintContext

impl Hash for PrintContext

impl Ord for PrintContext

impl<T: ObjectType> PartialEq<T> for PrintContext

impl<T: ObjectType> PartialOrd<T> for PrintContext

impl StaticType for PrintContext

Auto Trait Implementations

impl RefUnwindSafe for PrintContext

impl !Send for PrintContext

impl !Sync for PrintContext

impl Unpin for PrintContext

impl UnwindSafe for PrintContext

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<Super, Sub> CanDowncast<Sub> for Super where
    Sub: IsA<Super>,
    Super: IsA<Super>, 

impl<T> Cast for T where
    T: ObjectType, 

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ObjectExt for T where
    T: ObjectType, 

impl<'a, T> ToGlibContainerFromSlice<'a, *const GList> for T where
    T: GlibPtrDefault + ToGlibPtr<'a, <T as GlibPtrDefault>::GlibType>, 

type Storage = (Option<List>, Vec<Stash<'a, <T as GlibPtrDefault>::GlibType, T>>)

impl<'a, T> ToGlibContainerFromSlice<'a, *const GPtrArray> for T where
    T: GlibPtrDefault + ToGlibPtr<'a, <T as GlibPtrDefault>::GlibType>, 

type Storage = (Option<PtrArray>, Vec<Stash<'a, <T as GlibPtrDefault>::GlibType, T>>)

impl<'a, T> ToGlibContainerFromSlice<'a, *mut GArray> for T where
    T: GlibPtrDefault + ToGlibPtr<'a, <T as GlibPtrDefault>::GlibType>, 

type Storage = (Option<Array>, Vec<Stash<'a, <T as GlibPtrDefault>::GlibType, T>>)

impl<'a, T> ToGlibContainerFromSlice<'a, *mut GList> for T where
    T: GlibPtrDefault + ToGlibPtr<'a, <T as GlibPtrDefault>::GlibType>, 

type Storage = (Option<List>, Vec<Stash<'a, <T as GlibPtrDefault>::GlibType, T>>)

impl<'a, T> ToGlibContainerFromSlice<'a, *mut GPtrArray> for T where
    T: GlibPtrDefault + ToGlibPtr<'a, <T as GlibPtrDefault>::GlibType>, 

type Storage = (Option<PtrArray>, Vec<Stash<'a, <T as GlibPtrDefault>::GlibType, T>>)

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToSendValue for T where
    T: ToValue + SetValue + Send + ?Sized

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T> ToValue for T where
    T: SetValue + ?Sized

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.