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); }
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); }