Package: gtk

Class gtk-print-context

Superclasses

g-object, common-lisp:standard-object, common-lisp:t

Documented Subclasses

None

Direct Slots

None

Details

A gtk-print-context 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-print-context objects gets passed to the "begin-print", "end-print", "request-page-setup" and "draw-page" signals on the print operation.

Example

Using gtk-print-context in a "draw-page" callback.
(defun draw-page (operation context page-nr)
  (declare (ignore operation page-nr))
  (let ((cr (gtk-print-context-get-cairo-context context))
        (layout (gtk-print-context-create-pango-layout 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-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 3.14) (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 :round) (cairo-set-line-join cr :round)

(cairo-stroke cr)

;; Draw some text (setf (pango-layout-text layout) "Hello World! Printing is easy") (setf (pango-layout-font-description layout) (pango-font-description-from-string "sans 28")) (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)))
 

Inherited Slot Access Functions

See also

2020-4-9