Package: gtk
Class gtk-print-operation
Superclassesgtk-print-operation-preview, g-object, common-lisp:standard-object, common-lisp:t Documented Subclasses
None
Direct SlotsDetails gtk-print-operation is the high-level, portable printing API.
It looks a bit different than other GTK+ dialogs such as the gtk-file-chooser, since some platforms do not expose enough
infrastructure to implement a good print dialog. On such platforms, gtk-print-operation uses the native print dialog. On platforms which
do not provide a native print dialog, GTK+ uses its own, see gtk-print-unix-dialog. The typical way to use the high-level printing API is to create a gtk-print-operation object with the gtk-print-operation-new function when the user selects to print. Then you set some properties on it, e.g. the page size, any gtk-print-settings from previous print operations, the number of pages, the current page, etc. Then you start the print operation by calling the gtk-print-operation-run function. It will then show a dialog, let the user select a printer and options. When the user finished the dialog various signals will be emitted on the gtk-print-operation, the main one being "draw-page", which you are supposed to catch and render the page on the provided gtk-print-context using Cairo. By default gtk-print-operation uses an external application to do print preview. To implement a custom print preview, an application must connect to the "preview" signal. The functions gtk-print-operation-preview-render-page, gtk-print-operation-preview-end-preview and gtk-print-operation-preview-is-selected are useful when implementing a print preview. Example(defvar *print-settings* nil) Signal DetailsThe "begin-print" signallambda (operation context) : Run LastEmitted after the user has finished changing print settings in the dialog, before the actual rendering starts. A typical use for the "begin-print" signal is to use the parameters from the gtk-print-context and paginate the document accordingly, and then set the number of pages with the function gtk-print-operation-n-pages.
The "create-custom-widget" signallambda (operation) : Run LastEmitted when displaying the print dialog. If you return a widget in a handler for this signal it will be added to a custom tab in the print dialog. You typically return a container widget with multiple widgets in it. The print dialog owns the returned widget, and its lifetime is not controlled by the application. However, the widget is guaranteed to stay around until the "custom-widget-apply" signal is emitted on the operation. Then you can read out any information you need from the widgets.
The "custom-widget-apply" signallambda (operation widget) : Run LastEmitted right before the "begin-print" signal if you added a custom widget in the "create-custom-widget" handler. When you get this signal you should read the information from the custom widgets, as the widgets are not guaraneed to be around at a later time.
The "done" signallambda (operation result) : Run LastEmitted when the print operation run has finished doing everything required for printing. result gives you information about what happened during the run. If result is :error then you can call the function gtk_print_operation_get_error () for more information. If you enabled print status tracking then the function gtk-print-operation-is-finished may still return false after the "done" signal was emitted.
The "draw-page" signallambda (operation context page-nr) : Run LastEmitted for every page that is printed. The signal handler must render the page-nr's page onto the Cairo context obtained from context using the function gtk-print-context-cairo-context. Use the functions gtk-print-operation-use-full-page and gtk-print-operation-unit before starting the print operation to set up the transformation of the Cairo context according to your needs. (defun draw-page (operation context page-nr) (declare (ignore operation page-nr)) (let ((text-height 0) (cr (gtk-print-context-cairo-context context)) (width (floor (gtk-print-context-get-width context))) (layout (gtk-print-context-create-pango-layout context))) ;; Print a grey colored header (cairo-rectangle cr 0 0 width *header-height*) (cairo-set-source-rgb cr 0.9 0.9 0.9) (cairo-fill cr) ;; Set the font and text to print (setf (pango-layout-font-description layout) (pango-font-description-from-string "sans 14")) (setf (pango-layout-text layout) "Title") (setf (pango-layout-width layout) (* width +pango-scale+)) (setf (pango-layout-alignment layout) :center) ;; Get the height of the text (multiple-value-bind (width height) (pango-layout-size layout) (setf text-height (/ height +pango-scale+))) ;; Set color to black and center the text in header (cairo-set-source-rgb cr 0.0 0.0 0.0) (cairo-move-to cr 0 (floor (/ (- *header-height* text-height) 2))) (pango-cairo-show-layout cr layout)))
The "end-print" signallambda (operation context) : Run LastEmitted after all pages have been rendered. A handler for this signal can clean up any resources that have been allocated in the "begin-print" handler.
The "paginate" signallambda (operation context) : Run LastEmitted after the "begin-print" signal, but before the actual rendering starts. It keeps getting emitted until a connected signal handler returns true. The "paginate" signal is intended to be used for paginating a document in small chunks, to avoid blocking the user interface for a long time. The signal handler should update the number of pages using the function gtk-print-operation-n-pages, and return true if the document has been completely paginated. If you do not need to do pagination in chunks, you can simply do it all in the "begin-print" handler, and set the number of pages from there.
The "preview" signallambda (operation preview context parent) : Run LastGets emitted when a preview is requested from the native dialog. The default handler for this signal uses an external viewer application to preview. To implement a custom print preview, an application must return true from its handler for this signal. In order to use the provided context for the preview implementation, it must be given a suitable cairo context with the function gtk-print-context-set-cairo-context. The custom preview implementation can use the functions gtk-print-operation-preview-is-selected and gtk-print-operation-preview-render-page to find pages which are selected for print and render them. The preview must be finished by calling the function gtk-print-operation-preview-end-preview, typically in response to the user clicking a Close button.
The "request-page-setup" signallambda (operation context page-nr setup) : Run LastEmitted once for every page that is printed, to give the application a chance to modify the page setup. Any changes done to the page setup will be in force only for printing this page.
The "status-changed" signallambda (operation) : Run LastEmitted at between the various phases of the print operation. See the gtk-print-status enumeration for the phases that are being discriminated. Use the function gtk-print-operation-status to find out the current status.
The "update-custom-widget" signallambda (operation widget setup settings) : Run LastEmitted after change of the selected printer. The actual page setup and print settings are passed to the custom widget, which can actualize itself according to this change.
The "got-page-size" signallambda (preview context page-setup) : Run LastThe "got-page-size" signal is emitted once for each page that gets rendered to the preview. A handler for this signal should update the context according to the page-setup argument and set up a suitable Cairo context, using the function gtk-print-context-set-cairo-context.
The "ready" signallambda (preview context) : Run LastThe "ready" signal gets emitted once per preview operation, before the first page is rendered. A handler for this signal can be used for setup tasks.
| Slot Access FunctionsInherited Slot Access Functions |
2020-4-8