static void begin_print(GtkPrintOperation *operation, GtkPrintContext *context, PrintData *data) { // fputs("DEBUG: begin_print() called\n", stderr); gtk_print_operation_set_n_pages (operation, data->num_pages); gtk_print_operation_set_use_full_page (operation, data->use_full_page); }
static void begin_print (GtkPrintOperation *operation, GtkPrintContext *context, PrintData *data) { gtk_print_operation_set_use_full_page (operation, data->use_full_page); gimp_progress_init (_("Printing")); }
GtkWidget * do_printing (GtkWidget *do_widget) { GtkPrintOperation *operation; GtkPrintSettings *settings; PrintData *data; GError *error = NULL; operation = gtk_print_operation_new (); data = g_new0 (PrintData, 1); data->resourcename = g_strdup ("/sources/printing.c"); data->font_size = 12.0; g_signal_connect (G_OBJECT (operation), "begin-print", G_CALLBACK (begin_print), data); g_signal_connect (G_OBJECT (operation), "draw-page", G_CALLBACK (draw_page), data); g_signal_connect (G_OBJECT (operation), "end-print", G_CALLBACK (end_print), data); gtk_print_operation_set_use_full_page (operation, FALSE); gtk_print_operation_set_unit (operation, GTK_UNIT_POINTS); gtk_print_operation_set_embed_page_setup (operation, TRUE); settings = gtk_print_settings_new (); gtk_print_settings_set (settings, GTK_PRINT_SETTINGS_OUTPUT_BASENAME, "gtk-demo"); gtk_print_operation_set_print_settings (operation, settings); gtk_print_operation_run (operation, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, GTK_WINDOW (do_widget), &error); g_object_unref (operation); g_object_unref (settings); if (error) { GtkWidget *dialog; dialog = gtk_message_dialog_new (GTK_WINDOW (do_widget), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "%s", error->message); g_error_free (error); g_signal_connect (dialog, "response", G_CALLBACK (gtk_widget_destroy), NULL); gtk_widget_show (dialog); } return NULL; }
void print(zathura_t* zathura) { g_return_if_fail(zathura != NULL); g_return_if_fail(zathura->document != NULL); GtkPrintOperation* print_operation = gtk_print_operation_new(); /* print operation settings */ gtk_print_operation_set_job_name(print_operation, zathura_document_get_path(zathura->document)); gtk_print_operation_set_allow_async(print_operation, TRUE); gtk_print_operation_set_n_pages(print_operation, zathura_document_get_number_of_pages(zathura->document)); gtk_print_operation_set_current_page(print_operation, zathura_document_get_current_page_number(zathura->document)); gtk_print_operation_set_use_full_page(print_operation, TRUE); if (zathura->print.settings != NULL) { gtk_print_operation_set_print_settings(print_operation, zathura->print.settings); } if (zathura->print.page_setup != NULL) { gtk_print_operation_set_default_page_setup(print_operation, zathura->print.page_setup); } gtk_print_operation_set_embed_page_setup(print_operation, TRUE); /* print operation signals */ g_signal_connect(print_operation, "draw-page", G_CALLBACK(cb_print_draw_page), zathura); g_signal_connect(print_operation, "end-print", G_CALLBACK(cb_print_end), zathura); g_signal_connect(print_operation, "request-page-setup", G_CALLBACK(cb_print_request_page_setup), zathura); /* print */ GError* error = NULL; GtkPrintOperationResult result = gtk_print_operation_run(print_operation, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, GTK_WINDOW(zathura->ui.session->gtk.window), &error); if (result == GTK_PRINT_OPERATION_RESULT_ERROR) { girara_notify(zathura->ui.session, GIRARA_ERROR, _("Printing failed: %s"), error->message); g_error_free(error); } else if (result == GTK_PRINT_OPERATION_RESULT_APPLY) { g_clear_object(&zathura->print.settings); g_clear_object(&zathura->print.page_setup); /* save previous settings */ zathura->print.settings = g_object_ref(gtk_print_operation_get_print_settings(print_operation)); zathura->print.page_setup = g_object_ref(gtk_print_operation_get_default_page_setup(print_operation)); } g_object_unref(print_operation); }
Print::Print(SPDocument *doc, SPItem *base) : _doc (doc), _base (base) { g_assert (_doc); g_assert (_base); _printop = gtk_print_operation_new (); // set up dialog title, based on document name gchar *jobname = _doc->name ? _doc->name : _("SVG Document"); Glib::ustring title = _("Print"); title += " "; title += jobname; gtk_print_operation_set_job_name (_printop, title.c_str()); // set up paper size to match the document size gtk_print_operation_set_unit (_printop, GTK_UNIT_POINTS); GtkPageSetup *page_setup = gtk_page_setup_new(); gdouble doc_width = sp_document_width(_doc) * PT_PER_PX; gdouble doc_height = sp_document_height(_doc) * PT_PER_PX; GtkPaperSize *paper_size = gtk_paper_size_new_custom("custom", "custom", doc_width, doc_height, GTK_UNIT_POINTS); gtk_page_setup_set_paper_size (page_setup, paper_size); #ifndef WIN32 gtk_print_operation_set_default_page_setup (_printop, page_setup); #endif gtk_print_operation_set_use_full_page (_printop, TRUE); // set up signals _workaround._doc = _doc; _workaround._base = _base; _workaround._tab = &_tab; g_signal_connect (_printop, "create-custom-widget", G_CALLBACK (create_custom_widget), _tab.gobj()); g_signal_connect (_printop, "begin-print", G_CALLBACK (begin_print), NULL); g_signal_connect (_printop, "draw-page", G_CALLBACK (draw_page), &_workaround); // build custom preferences tab gtk_print_operation_set_custom_tab_label (_printop, _("Rendering")); }
//! //! @brief Sets up a print operation for the current results //! //! The function checks the results of the results text buffer, and then attempts //! to set up a print operation. If a section of the search results are highlighted //! only those results are printed. //! void gw_print (const GtkPrintOperationAction ACTION, GwSearchWindow *window) { //Declarations GwPrintData *data; GtkPrintOperation *operation; GtkPrintOperationResult res; //Initializations data = gw_printdata_new (window); operation = gtk_print_operation_new (); //Force at least some minimal margins on the pages that print gtk_print_operation_set_default_page_setup (operation, NULL); gtk_print_operation_set_use_full_page (operation, FALSE); gtk_print_operation_set_unit (operation, GTK_UNIT_MM); if (_settings != NULL) gtk_print_operation_set_print_settings (operation, _settings); g_signal_connect (operation, "begin_print", G_CALLBACK (_begin_print), data); g_signal_connect (operation, "draw_page", G_CALLBACK (_draw_page), data); g_signal_connect (operation, "paginate", G_CALLBACK (_paginate), data); g_signal_connect (operation, "done", G_CALLBACK (_done), data); res = gtk_print_operation_run (operation, ACTION, NULL, NULL); if (res == GTK_PRINT_OPERATION_RESULT_APPLY) { if (_settings != NULL) g_object_unref (_settings); _settings = g_object_ref (gtk_print_operation_get_print_settings (operation)); } //Cleanup gw_printdata_free (data); g_object_unref (operation); }
void XAP_UnixDialog_Print::setupPrint() { double blockMrgnLeft, blockMrgnRight, mrgnTop, mrgnBottom, mrgnLeft, mrgnRight = 0.; double width, height; bool portrait; m_pView = static_cast<FV_View*>(m_pFrame->getCurrentView()); m_pPO = gtk_print_operation_new(); // // Set filename if it's not present already // std::string sURI = m_pView->getDocument()->getPrintFilename(); if(sURI.empty()) { const std::string & filename = m_pView->getDocument()->getFilename(); if(!filename.empty()) { sURI = filename; UT_addOrReplacePathSuffix(sURI, ".pdf"); } } if(!sURI.empty()) { GtkPrintSettings * pSettings = gtk_print_settings_new(); gtk_print_settings_set(pSettings, GTK_PRINT_SETTINGS_OUTPUT_URI, sURI.c_str() ); gtk_print_operation_set_print_settings(m_pPO,pSettings); g_object_unref(pSettings); } s_getPageMargins(m_pView, blockMrgnLeft, blockMrgnRight, mrgnLeft, mrgnRight, mrgnTop, mrgnBottom); portrait = m_pView->getPageSize().isPortrait(); width = m_pView->getPageSize().Width (DIM_MM); height = m_pView->getPageSize().Height (DIM_MM); m_pPageSetup = gtk_page_setup_new(); const char * pszName = m_pView->getPageSize().getPredefinedName(); bool isPredefined = false; const char * pszGtkName = NULL; if(pszName == NULL) { } else if(g_ascii_strcasecmp(pszName,"Custom") == 0) { } else if(g_ascii_strcasecmp(pszName,"A0") == 0) { isPredefined = true; pszGtkName = "iso_a0"; } else if(g_ascii_strcasecmp(pszName,"A1") == 0) { isPredefined = true; pszGtkName = "iso_a1"; } else if(g_ascii_strcasecmp(pszName,"A2") == 0) { isPredefined = true; pszGtkName = "iso_a2"; } else if(g_ascii_strcasecmp(pszName,"A3") == 0) { isPredefined = true; pszGtkName = "iso_a3"; } else if(g_ascii_strcasecmp(pszName,"A4") == 0) { isPredefined = true; pszGtkName = "iso_a4"; } else if(g_ascii_strcasecmp(pszName,"A5") == 0) { isPredefined = true; pszGtkName = "iso_a5"; } else if(g_ascii_strcasecmp(pszName,"A6") == 0) { isPredefined = true; pszGtkName = "iso_a6"; } else if(g_ascii_strcasecmp(pszName,"A7") == 0) { isPredefined = true; pszGtkName = "iso_a7"; } else if(g_ascii_strcasecmp(pszName,"A8") == 0) { isPredefined = true; pszGtkName = "iso_a8"; } else if(g_ascii_strcasecmp(pszName,"A9") == 0) { isPredefined = true; pszGtkName = "iso_a9"; } else if(g_ascii_strcasecmp(pszName,"B0") == 0) { isPredefined = true; pszGtkName = "iso_b0"; } else if(g_ascii_strcasecmp(pszName,"B1") == 0) { isPredefined = true; pszGtkName = "iso_b1"; } else if(g_ascii_strcasecmp(pszName,"B2") == 0) { isPredefined = true; pszGtkName = "iso_b2"; } else if(g_ascii_strcasecmp(pszName,"B3") == 0) { isPredefined = true; pszGtkName = "iso_b3"; } else if(g_ascii_strcasecmp(pszName,"B4") == 0) { isPredefined = true; pszGtkName = "iso_b4"; } else if(g_ascii_strcasecmp(pszName,"B4") == 0) { isPredefined = true; pszGtkName = "iso_b4"; } else if(g_ascii_strcasecmp(pszName,"B5") == 0) { isPredefined = true; pszGtkName = "iso_b5"; } else if(g_ascii_strcasecmp(pszName,"B6") == 0) { isPredefined = true; pszGtkName = "iso_b6"; } else if(g_ascii_strcasecmp(pszName,"B7") == 0) { isPredefined = true; pszGtkName = "iso_b7"; } else if(g_ascii_strcasecmp(pszName,"Legal") == 0) { isPredefined = true; pszGtkName = "na_legal"; } else if(g_ascii_strcasecmp(pszName,"Letter") == 0) { isPredefined = true; pszGtkName = "na_letter"; } if(isPredefined) { m_pGtkPageSize = gtk_paper_size_new(static_cast<const gchar *>(pszGtkName)); } else { /* * Width() and Height() will return the paper size as shown in the UI. * Gtk wants the real paper size, however, and will swap the two * itself when we specify the orientation. */ m_pGtkPageSize = gtk_paper_size_new_custom("custom", "custom", portrait ? width : height, portrait ? height : width, GTK_UNIT_MM); } // // Set the Page Size // gtk_page_setup_set_paper_size(m_pPageSetup,m_pGtkPageSize); // // Set the margins // gtk_page_setup_set_top_margin(m_pPageSetup,mrgnTop,GTK_UNIT_INCH); gtk_page_setup_set_bottom_margin(m_pPageSetup,mrgnBottom,GTK_UNIT_INCH); gtk_page_setup_set_left_margin(m_pPageSetup,mrgnLeft,GTK_UNIT_INCH); gtk_page_setup_set_right_margin(m_pPageSetup,mrgnRight,GTK_UNIT_INCH); // // Set orientation // if( portrait) gtk_page_setup_set_orientation(m_pPageSetup,GTK_PAGE_ORIENTATION_PORTRAIT); else gtk_page_setup_set_orientation(m_pPageSetup,GTK_PAGE_ORIENTATION_LANDSCAPE); gtk_print_operation_set_default_page_setup(m_pPO,m_pPageSetup); gtk_print_operation_set_use_full_page (m_pPO, true); m_pDL = m_pView->getLayout(); m_iCurrentPage = m_pDL->findPage(m_pView->getCurrentPage()); m_iNumberPages = (gint) m_pDL->countPages(); gtk_print_operation_set_current_page(m_pPO,m_iCurrentPage); g_signal_connect (m_pPO, "begin_print", G_CALLBACK (s_Begin_Print), this); g_signal_connect (m_pPO, "draw_page", G_CALLBACK (s_Print_Page), this); }
/** \brief Print a satellite pass. * \param pass Pointer to the pass_t data * \param qth Pointer to the qth_t structure * \param parent Transient parent of the dialog, or NULL * * This function prints a satellite pass to the printer (or a file) using the * Gtk+ printing API. The function takes the user configuration into account * and only prints the selected columns. The font size will be adjusted so that * one row can fit on one line. The function will also try to reduce the number * of rows so that the whole pass can fit on one page: * * +-------------------------+ * | header | * |------------+------------| * | | | * | | | * | polar | az/el | * | | | * |------------+------------| * | | * | Table with data | * | | * | - - - - - - - - - - - | * | - - - - - - - - - - - | * | - - - - - - - - - - - | * | - - - - - - - - - - - | * | - - - - - - - - - - - | * | - - - - - - - - - - - | * | - - - - - - - - - - - | * | | * +-------------------------+ * */ void print_pass (pass_t *pass, qth_t *qth, GtkWindow *parent) { gchar *text,*header,*buff; GtkPrintOperation *operation; PrintData *data; GError *error = NULL; /* TODO check pass and qth */ operation = gtk_print_operation_new (); data = g_new0 (PrintData, 1); data->font_size = 12.0; // FIXME /* page header */ data->pgheader = g_strdup_printf (_("Pass details for %s (orbit %d)"), pass->satname, pass->orbit); /* convert data to printable strings; we use existing pass_to_txt functions */ data->fields = sat_cfg_get_int (SAT_CFG_INT_PRED_SINGLE_COL); header = pass_to_txt_tblheader (pass, qth, data->fields); text = pass_to_txt_tblcontents (pass, qth, data->fields); buff = g_strconcat (header, text, NULL); data->lines = g_strsplit (buff, "\n", 0); g_free (text); g_free (header); g_free (buff); g_signal_connect (G_OBJECT (operation), "begin-print", G_CALLBACK (begin_print), data); g_signal_connect (G_OBJECT (operation), "draw-page", G_CALLBACK (draw_page), data); g_signal_connect (G_OBJECT (operation), "end-print", G_CALLBACK (end_print), data); gtk_print_operation_set_use_full_page (operation, FALSE); gtk_print_operation_set_unit (operation, GTK_UNIT_POINTS); gtk_print_operation_run (operation, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, parent, &error); g_object_unref (operation); if (error) { sat_log_log (SAT_LOG_LEVEL_ERROR, "%s: %s", __func__, error->message); GtkWidget *dialog; dialog = gtk_message_dialog_new (parent, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "%s", error->message); g_error_free (error); g_signal_connect (dialog, "response", G_CALLBACK (gtk_widget_destroy), NULL); gtk_widget_show (dialog); } }
GtkWidget * do_printing (GtkWidget *do_widget) { GtkPrintOperation *operation; GtkPrintSettings *settings; PrintData *data; gchar *uri, *ext; const gchar *dir; GError *error = NULL; operation = gtk_print_operation_new (); data = g_new0 (PrintData, 1); data->filename = demo_find_file ("printing.c", NULL); data->font_size = 12.0; g_signal_connect (G_OBJECT (operation), "begin-print", G_CALLBACK (begin_print), data); g_signal_connect (G_OBJECT (operation), "draw-page", G_CALLBACK (draw_page), data); g_signal_connect (G_OBJECT (operation), "end-print", G_CALLBACK (end_print), data); gtk_print_operation_set_use_full_page (operation, FALSE); gtk_print_operation_set_unit (operation, GTK_UNIT_POINTS); gtk_print_operation_set_embed_page_setup (operation, TRUE); settings = gtk_print_settings_new (); dir = g_get_user_special_dir (G_USER_DIRECTORY_DOCUMENTS); if (dir == NULL) dir = g_get_home_dir (); if (g_strcmp0 (gtk_print_settings_get (settings, GTK_PRINT_SETTINGS_OUTPUT_FILE_FORMAT), "ps") == 0) ext = ".ps"; else if (g_strcmp0 (gtk_print_settings_get (settings, GTK_PRINT_SETTINGS_OUTPUT_FILE_FORMAT), "svg") == 0) ext = ".svg"; else ext = ".pdf"; uri = g_strconcat ("file://", dir, "/", "gtk-demo", ext, NULL); gtk_print_settings_set (settings, GTK_PRINT_SETTINGS_OUTPUT_URI, uri); gtk_print_operation_set_print_settings (operation, settings); gtk_print_operation_run (operation, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, GTK_WINDOW (do_widget), &error); g_object_unref (operation); g_object_unref (settings); g_free (uri); if (error) { GtkWidget *dialog; dialog = gtk_message_dialog_new (GTK_WINDOW (do_widget), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "%s", error->message); g_error_free (error); g_signal_connect (dialog, "response", G_CALLBACK (gtk_widget_destroy), NULL); gtk_widget_show (dialog); } return NULL; }
void CmOutputPrinter(int select_file, int show_dialog) { GtkPrintOperation *print; GtkPrintOperationResult res; char buf[MESSAGE_BUF_SIZE]; struct objlist *graobj, *g2wobj; int id, g2wid, g2woid, opt; N_VALUE *g2winst; GError *error; struct print_obj pobj; GtkPaperSize *paper_size; GtkPageSetup *page_setup; if (Menulock || Globallock) return; if (select_file && ! SetFileHidden()) return; FileAutoScale(); AdjustAxis(); graobj = chkobject("gra"); if (graobj == NULL) return; g2wobj = chkobject("gra2gtkprint"); if (g2wobj == NULL) return; g2wid = newobj(g2wobj); if (g2wid < 0) return; putobj(g2wobj, "use_opacity", g2wid, &Menulocal.use_opacity); g2winst = chkobjinst(g2wobj, g2wid); _getobj(g2wobj, "oid", g2winst, &g2woid); id = newobj(graobj); init_graobj(graobj, id, "gra2gtkprint", g2woid); print = gtk_print_operation_new(); gtk_print_operation_set_n_pages(print, 1); #if GTK_CHECK_VERSION(2, 18, 0) gtk_print_operation_set_has_selection(print, FALSE); gtk_print_operation_set_support_selection(print, FALSE); gtk_print_operation_set_embed_page_setup(print, FALSE); #endif gtk_print_operation_set_use_full_page(print, TRUE); if (PrintSettings == NULL) PrintSettings = gtk_print_settings_new(); if (Menulocal.PaperId == PAPER_ID_CUSTOM) { paper_size = gtk_paper_size_new_custom(Menulocal.PaperName, Menulocal.PaperName, Menulocal.PaperWidth / 100.0, Menulocal.PaperHeight / 100.0, GTK_UNIT_MM); } else { paper_size = gtk_paper_size_new(Menulocal.PaperName); } page_setup = gtk_page_setup_new(); gtk_page_setup_set_paper_size(page_setup, paper_size); if (Menulocal.PaperLandscape) { gtk_page_setup_set_orientation(page_setup, GTK_PAGE_ORIENTATION_LANDSCAPE); } else { gtk_page_setup_set_orientation(page_setup, GTK_PAGE_ORIENTATION_PORTRAIT); } gtk_print_operation_set_default_page_setup(print, page_setup); gtk_print_operation_set_print_settings(print, PrintSettings); pobj.graobj = graobj; pobj.id = id; pobj.g2wobj = g2wobj; pobj.g2winst = g2winst; g_signal_connect(print, "draw_page", G_CALLBACK(draw_page), &pobj); switch (show_dialog) { case PRINT_SHOW_DIALOG_NONE: opt = GTK_PRINT_OPERATION_ACTION_PRINT; break; case PRINT_SHOW_DIALOG_PREVIEW: opt = GTK_PRINT_OPERATION_ACTION_PREVIEW; break; case PRINT_SHOW_DIALOG_DIALOG: opt = GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG; break; default: opt = GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG; } res = gtk_print_operation_run(print, opt, GTK_WINDOW(TopLevel), &error); if (res == GTK_PRINT_OPERATION_RESULT_ERROR) { snprintf(buf, sizeof(buf), _("Printing error: %s"), error->message); message_box(NULL, buf, _("Print"), RESPONS_ERROR); g_error_free(error); } else if (res == GTK_PRINT_OPERATION_RESULT_APPLY) { if (PrintSettings) g_object_unref(PrintSettings); PrintSettings = g_object_ref(gtk_print_operation_get_print_settings(print)); } g_object_unref(print); delobj(graobj, id); delobj(g2wobj, g2wid); if (select_file && NgraphApp.FileWin.data.data) { FileWinUpdate(NgraphApp.FileWin.data.data, TRUE); } }