/* attribute wstring toFileName; */ NS_IMETHODIMP nsPrintSettingsGTK::GetToFileName(char16_t * *aToFileName) { // Get the gtk output filename const char* gtk_output_uri = gtk_print_settings_get(mPrintSettings, GTK_PRINT_SETTINGS_OUTPUT_URI); if (!gtk_output_uri) { *aToFileName = ToNewUnicode(mToFileName); return NS_OK; } // Convert to an nsIFile nsCOMPtr<nsIFile> file; nsresult rv = NS_GetFileFromURLSpec(nsDependentCString(gtk_output_uri), getter_AddRefs(file)); if (NS_FAILED(rv)) return rv; // Extract the path nsAutoString path; rv = file->GetPath(path); NS_ENSURE_SUCCESS(rv, rv); *aToFileName = ToNewUnicode(path); return NS_OK; }
static void portal_job_complete (GtkPrintJob *job, gpointer data, const GError *error) { GtkPrintOperation *op = data; GtkPrintOperationPortal *op_portal = op->priv->platform_data; GtkPrintSettings *settings; const char *uri; char *filename; int fd, idx; GVariantBuilder opt_builder; GUnixFDList *fd_list; if (error != NULL && op->priv->error == NULL) { g_warning ("Print job failed: %s", error->message); op->priv->error = g_error_copy (error); return; } op_portal->file_written = TRUE; settings = gtk_print_job_get_settings (job); uri = gtk_print_settings_get (settings, GTK_PRINT_SETTINGS_OUTPUT_URI); filename = g_filename_from_uri (uri, NULL, NULL); fd = open (filename, O_RDONLY|O_CLOEXEC); fd_list = g_unix_fd_list_new (); idx = g_unix_fd_list_append (fd_list, fd, NULL); close (fd); g_free (filename); g_variant_builder_init (&opt_builder, G_VARIANT_TYPE_VARDICT); g_variant_builder_add (&opt_builder, "{sv}", "token", g_variant_new_uint32 (op_portal->token)); g_dbus_proxy_call_with_unix_fd_list (op_portal->proxy, "Print", g_variant_new ("(ssh@a{sv})", "", /* window */ _("Print"), /* title */ idx, g_variant_builder_end (&opt_builder)), G_DBUS_CALL_FLAGS_NONE, -1, fd_list, NULL, print_file_done, op); g_object_unref (fd_list); }
void XAP_UnixDialog_Print::cleanup(void) { // // Get the filename we printed to // GtkPrintSettings * pSettings = gtk_print_operation_get_print_settings(m_pPO); const gchar * szFname = gtk_print_settings_get(pSettings,GTK_PRINT_SETTINGS_OUTPUT_URI); if((szFname != NULL) && (strcmp(szFname,"output.pdf") != 0)) { m_pView->getDocument()->setPrintFilename(szFname); } g_object_unref(m_pPO); m_pPO= NULL; if(!m_bDidQuickPrint) { UT_DEBUGMSG(("Deleting PrintView %p \n",m_pPrintView)); DELETEP(m_pPrintLayout); DELETEP(m_pPrintView); } else { if(m_pPrintLayout) m_pPrintLayout->setQuickPrint(NULL); m_pPrintLayout = NULL; m_pPrintView = NULL; if(m_bShowParagraphs) m_pView->setShowPara(true); m_pDL->incrementGraphicTick(); } UT_DEBUGMSG(("Reset fontmap m_pView %p Graphics %p \n",m_pView,m_pView->getGraphics())); static_cast<GR_CairoGraphics *>(m_pView->getGraphics())->resetFontMapResolution(); DELETEP(m_pPrintGraphics); // // Finish pending expose events. // m_pFrame->nullUpdate(); }
NS_IMETHODIMP nsPrintSettingsGTK::GetOutputFormat(int16_t *aOutputFormat) { NS_ENSURE_ARG_POINTER(aOutputFormat); int16_t format; nsresult rv = nsPrintSettings::GetOutputFormat(&format); if (NS_FAILED(rv)) { return rv; } if (format == nsIPrintSettings::kOutputFormatNative) { const gchar* fmtGTK = gtk_print_settings_get(mPrintSettings, GTK_PRINT_SETTINGS_OUTPUT_FILE_FORMAT); if (fmtGTK) { if (nsDependentCString(fmtGTK).EqualsIgnoreCase("pdf")) { format = nsIPrintSettings::kOutputFormatPDF; } else { format = nsIPrintSettings::kOutputFormatPS; } } else if (GTK_IS_PRINTER(mGTKPrinter)) { // Prior to gtk 2.24, gtk_printer_accepts_pdf() and // gtk_printer_accepts_ps() always returned true regardless of the // printer's capability. bool shouldTrustGTK = (gtk_major_version > 2 || (gtk_major_version == 2 && gtk_minor_version >= 24)); bool acceptsPDF = shouldTrustGTK && gtk_printer_accepts_pdf(mGTKPrinter); format = acceptsPDF ? nsIPrintSettings::kOutputFormatPDF : nsIPrintSettings::kOutputFormatPS; } } *aOutputFormat = format; return NS_OK; }
/** * Prints the current page. * * If printing on WIN32, in order to prevent the font from being tiny, (see bug #591177), * A GtkPrintOperation object needs to be created so that the unit can be set, and then * webkit_web_frame_print_full() needs to be called to use that GtkPrintOperation. On * other platforms (specifically linux - not sure about MacOSX), the version of webkit may * not contain the function webkit_web_frame_print_full(), so webkit_web_frame_print() is * called instead (the font size problem doesn't show up on linux). * * @param self HTML renderer object */ static void impl_webkit_print( GncHtml* self, const gchar* jobname, gboolean export_pdf ) { #if !HAVE(WEBKIT_WEB_FRAME_PRINT_FULL) extern void webkit_web_frame_print( WebKitWebFrame * frame ); #endif gchar *export_filename = NULL; GncHtmlWebkitPrivate* priv; WebKitWebFrame* frame; #if HAVE(WEBKIT_WEB_FRAME_PRINT_FULL) GtkPrintOperation* op = gtk_print_operation_new(); GError* error = NULL; GtkPrintSettings *print_settings; #endif priv = GNC_HTML_WEBKIT_GET_PRIVATE(self); frame = webkit_web_view_get_main_frame( priv->web_view ); #if HAVE(WEBKIT_WEB_FRAME_PRINT_FULL) gnc_print_operation_init( op, jobname ); print_settings = gtk_print_operation_get_print_settings (op); if (!print_settings) { print_settings = gtk_print_settings_new(); gtk_print_operation_set_print_settings(op, print_settings); } #ifdef G_OS_WIN32 gtk_print_operation_set_unit( op, GTK_UNIT_POINTS ); #endif // Make sure to generate a full export filename if (g_str_has_suffix(jobname, ".pdf")) { export_filename = g_strdup(jobname); } else { export_filename = g_strconcat(jobname, ".pdf", NULL); } // Two different modes of operation. Either export to PDF, or run the // normal print dialog if (export_pdf) { GtkWidget *dialog; gint result; gchar *export_dirname = NULL; gchar* basename; // Before we save the PDF file, we always as the user for the export // file name. We will store the chosen directory in the gtk print settings // as well. dialog = gtk_file_chooser_dialog_new (_("Export to PDF File"), NULL, GTK_FILE_CHOOSER_ACTION_SAVE, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, NULL); gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog), TRUE); // Does the jobname look like a valid full file path? basename = g_path_get_basename(jobname); if (strcmp(basename, jobname) != 0) { gchar *tmp_basename; gchar *tmp_dirname = g_path_get_dirname(jobname); if (g_file_test(tmp_dirname, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) { // Yes, the jobname starts with a directory name that actually // exists. Hence we use this as output directory. export_dirname = tmp_dirname; tmp_dirname = NULL; // As the prefix part of the "jobname" is the directory path, we // need to extract the suffix part for the filename. tmp_basename = g_path_get_basename(export_filename); g_free(export_filename); export_filename = tmp_basename; } g_free(tmp_dirname); } g_free(basename); // Set the output file name from the given jobname gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER(dialog), export_filename); // Do we have a stored output directory? if (!export_dirname && gtk_print_settings_has_key(print_settings, GNC_GTK_PRINT_SETTINGS_EXPORT_DIR)) { const char* tmp_dirname = gtk_print_settings_get(print_settings, GNC_GTK_PRINT_SETTINGS_EXPORT_DIR); // Only use the directory subsequently if it exists. if (g_file_test(tmp_dirname, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) { export_dirname = g_strdup(tmp_dirname); } } // If we have an already existing directory, propose it now. if (export_dirname) { gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), export_dirname); } g_free(export_dirname); result = gtk_dialog_run (GTK_DIALOG (dialog)); // Weird. In gtk_dialog_run, the gtk code will run a fstat() on the // proposed new output filename, which of course fails with "file not // found" as this file doesn't exist. It will still show a warning output // in the trace file, though. if (result == GTK_RESPONSE_ACCEPT) { // The user pressed "Ok", so use the file name for the actual file output. gchar *dirname; char *tmp = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog)); g_free(export_filename); export_filename = tmp; // Store the directory part of the file for later dirname = g_path_get_dirname(export_filename); if (g_file_test(dirname, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) { gtk_print_settings_set(print_settings, GNC_GTK_PRINT_SETTINGS_EXPORT_DIR, dirname); } g_free(dirname); } gtk_widget_destroy (dialog); if (result != GTK_RESPONSE_ACCEPT) { // User pressed cancel - no saving of the PDF file here. g_free(export_filename); g_object_unref( op ); return; } // This function expects the full filename including (absolute?) path gtk_print_operation_set_export_filename(op, export_filename); // Run the "Export to PDF" print operation webkit_web_frame_print_full( frame, op, GTK_PRINT_OPERATION_ACTION_EXPORT, &error ); } else { // Also store this export file name as output URI in the settings if (gtk_print_settings_has_key(print_settings, GTK_PRINT_SETTINGS_OUTPUT_URI)) { // Get the previous output URI, extract the directory part, and // append the current filename. const gchar *olduri = gtk_print_settings_get(print_settings, GTK_PRINT_SETTINGS_OUTPUT_URI); gchar *dirname = g_path_get_dirname(olduri); gchar *newuri = (g_strcmp0(dirname, ".") == 0) ? g_strdup(export_filename) : g_build_filename(dirname, export_filename, NULL); //g_warning("olduri=%s newuri=%s", olduri, newuri); // This function expects the full filename including protocol, path, and name gtk_print_settings_set(print_settings, GTK_PRINT_SETTINGS_OUTPUT_URI, newuri); g_free(newuri); g_free(dirname); } else { // No stored output URI from the print settings, so just set our export filename gtk_print_settings_set(print_settings, GTK_PRINT_SETTINGS_OUTPUT_URI, export_filename); } // Run the normal printing dialog webkit_web_frame_print_full( frame, op, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, &error ); } if ( error != NULL ) { GtkWidget* window = gtk_widget_get_toplevel( GTK_WIDGET(priv->web_view) ); GtkWidget* dialog = gtk_message_dialog_new( gtk_widget_is_toplevel(window) ? GTK_WINDOW(window) : NULL, 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 ); } // Remember to save the printing settings after this print job gnc_print_operation_save_print_settings(op); g_object_unref( op ); g_free(export_filename); #else webkit_web_frame_print( frame ); #endif }
static VALUE ps_get(VALUE self, VALUE key) { return CSTR2RVAL(gtk_print_settings_get(_SELF(self), RVAL2CSTR(key))); }
/* static */ nsresult GeckoPrintService::TranslateSettings (GtkPrintSettings *aGtkSettings, GtkPageSetup *aPageSetup, GtkPrinter *aPrinter, const nsACString &aSourceFile, PRInt16 aPrintFrames, PRBool aIsForPrinting, nsIPrintSettings *aSettings) { NS_ENSURE_ARG (aGtkSettings); NS_ENSURE_ARG (aPageSetup); GtkPrintCapabilities capabilities = GtkPrintCapabilities (0); if (aIsForPrinting) { NS_ENSURE_TRUE (aPrinter, NS_ERROR_FAILURE); capabilities = gtk_printer_get_capabilities (aPrinter); } /* Initialisation */ aSettings->SetIsInitializedFromPrinter (PR_FALSE); /* FIXME: PR_TRUE? */ aSettings->SetIsInitializedFromPrefs (PR_FALSE); /* FIXME: PR_TRUE? */ aSettings->SetPrintSilent (PR_FALSE); aSettings->SetShowPrintProgress (PR_TRUE); /* We always print PS to a file and then hand that off to gtk-print */ aSettings->SetPrinterName (LITERAL ("PostScript/default")); if (aIsForPrinting) { aSettings->SetPrintToFile (PR_TRUE); nsString sourceFile; NS_CStringToUTF16 (aSourceFile, NS_CSTRING_ENCODING_NATIVE_FILESYSTEM, sourceFile); aSettings->SetToFileName (sourceFile.get ()); } else { /* Otherwise mozilla will create the file nevertheless and * fail since we haven't set a name! */ aSettings->SetPrintToFile (PR_FALSE); } /* This is the time between printing each page, in ms. * It 'gives the user more time to press cancel' ! * We don't want any of this nonsense, so set this to a low value, * just enough to update the print dialogue. */ aSettings->SetPrintPageDelay (50); if (aIsForPrinting) { #ifdef HAVE_NSIPRINTSETTINGS_SETOUTPUTFORMAT NS_ENSURE_TRUE (aPrinter, NS_ERROR_FAILURE); const char *format = gtk_print_settings_get (aGtkSettings, GTK_PRINT_SETTINGS_OUTPUT_FILE_FORMAT); if (!format) format = "ps"; if (strcmp (format, "pdf") == 0 && gtk_printer_accepts_pdf (aPrinter)) { aSettings->SetOutputFormat (nsIPrintSettings::kOutputFormatPDF); } else if (strcmp (format, "ps") == 0 && gtk_printer_accepts_ps (aPrinter)) { aSettings->SetOutputFormat (nsIPrintSettings::kOutputFormatPS); } else { g_warning ("Output format '%s' specified, but printer '%s' does not support it!", format, gtk_printer_get_name (aPrinter)); return NS_ERROR_FAILURE; } #endif int n_copies = gtk_print_settings_get_n_copies (aGtkSettings); if (n_copies <= 0) return NS_ERROR_FAILURE; if (capabilities & GTK_PRINT_CAPABILITY_COPIES) { aSettings->SetNumCopies (1); } else { /* We have to copy them ourself */ aSettings->SetNumCopies (n_copies); gtk_print_settings_set_n_copies (aGtkSettings, 1); } gboolean reverse = gtk_print_settings_get_reverse (aGtkSettings); if (capabilities & GTK_PRINT_CAPABILITY_REVERSE) { aSettings->SetPrintReversed (PR_FALSE); } else { aSettings->SetPrintReversed (reverse); gtk_print_settings_set_reverse (aGtkSettings, FALSE); } GtkPageSet pageSet = gtk_print_settings_get_page_set (aGtkSettings); aSettings->SetPrintOptions (nsIPrintSettings::kPrintEvenPages, pageSet != GTK_PAGE_SET_ODD); aSettings->SetPrintOptions (nsIPrintSettings::kPrintEvenPages, pageSet != GTK_PAGE_SET_EVEN); GtkPrintPages printPages = gtk_print_settings_get_print_pages (aGtkSettings); switch (printPages) { case GTK_PRINT_PAGES_RANGES: { int numRanges = 0; GtkPageRange *pageRanges = gtk_print_settings_get_page_ranges (aGtkSettings, &numRanges); if (numRanges > 0) { /* FIXME: We can only support one range, ignore more ranges or raise error? */ aSettings->SetPrintRange (nsIPrintSettings::kRangeSpecifiedPageRange); /* Gecko page numbers start at 1, while gtk page numbers start at 0 */ aSettings->SetStartPageRange (pageRanges[0].start + 1); aSettings->SetEndPageRange (pageRanges[0].end + 1); g_free (pageRanges); break; } /* Fall-through to PAGES_ALL */ } case GTK_PRINT_PAGES_CURRENT: /* not supported, fall through */ case GTK_PRINT_PAGES_ALL: aSettings->SetPrintRange (nsIPrintSettings::kRangeAllPages); break; /* FIXME: we need some custom ranges here, "Selection" and "Focused Frame" */ } } else { aSettings->SetPrintOptions (nsIPrintSettings::kPrintEvenPages, PR_TRUE); aSettings->SetPrintOptions (nsIPrintSettings::kPrintEvenPages, PR_TRUE); aSettings->SetPrintReversed (PR_FALSE); aSettings->SetPrintRange (nsIPrintSettings::kRangeAllPages); } /* And clear those in the settings, so the printer doesn't try to apply them too */ gtk_print_settings_set_print_pages (aGtkSettings, GTK_PRINT_PAGES_ALL); gtk_print_settings_set_page_ranges (aGtkSettings, NULL, 0); gtk_print_settings_set_page_set (aGtkSettings, GTK_PAGE_SET_ALL); /* We must use the page setup here instead of the print settings, see gtk bug #485685 */ switch (gtk_page_setup_get_orientation (aPageSetup)) { case GTK_PAGE_ORIENTATION_PORTRAIT: case GTK_PAGE_ORIENTATION_REVERSE_PORTRAIT: /* not supported */ aSettings->SetOrientation (nsIPrintSettings::kPortraitOrientation); break; case GTK_PAGE_ORIENTATION_LANDSCAPE: case GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE: /* not supported */ aSettings->SetOrientation (nsIPrintSettings::kLandscapeOrientation); break; } aSettings->SetPrintInColor (gtk_print_settings_get_use_color (aGtkSettings)); aSettings->SetPaperSizeUnit(nsIPrintSettings::kPaperSizeMillimeters); #ifdef HAVE_NSIPRINTSETTINGS_SETPAPERSIZE aSettings->SetPaperSize (nsIPrintSettings::kPaperSizeDefined); #endif GtkPaperSize *paperSize = gtk_page_setup_get_paper_size (aPageSetup); if (!paperSize) { return NS_ERROR_FAILURE; } aSettings->SetPaperSizeType (nsIPrintSettings::kPaperSizeDefined); aSettings->SetPaperWidth (gtk_paper_size_get_width (paperSize, GTK_UNIT_MM)); aSettings->SetPaperHeight (gtk_paper_size_get_height (paperSize, GTK_UNIT_MM)); #ifdef HAVE_NSIPRINTSETTINGS_SETPAPERNAME aSettings->SetPaperName (NS_ConvertUTF8toUTF16 (gtk_paper_size_get_name (paperSize)).get ()); #else { /* Mozilla bug https://bugzilla.mozilla.org/show_bug.cgi?id=307404 * means that we cannot actually use any paper sizes except mozilla's * builtin list, and we must refer to them *by name*! */ static const struct { const char gtkPaperName[13]; const char mozPaperName[10]; } paperTable [] = { { GTK_PAPER_NAME_A5, "A5" }, { GTK_PAPER_NAME_A4, "A4" }, { GTK_PAPER_NAME_A3, "A3" }, { GTK_PAPER_NAME_LETTER, "Letter" }, { GTK_PAPER_NAME_LEGAL, "Legal" }, { GTK_PAPER_NAME_EXECUTIVE, "Executive" }, }; const char *paperName = gtk_paper_size_get_name (paperSize); PRUint32 i; for (i = 0; i < G_N_ELEMENTS (paperTable); i++) { if (g_ascii_strcasecmp (paperTable[i].gtkPaperName, paperName) == 0) { paperName = paperTable[i].mozPaperName; break; } } if (i == G_N_ELEMENTS (paperTable)) { /* Not in table, fall back to A4 */ g_warning ("Unknown paper name '%s', falling back to A4", gtk_paper_size_get_name (paperSize)); paperName = paperTable[1].mozPaperName; } aSettings->SetPaperName (NS_ConvertUTF8toUTF16 (paperName).get ()); } #endif /* !HAVE_NSIPRINTSETTINGS_SETPAPERNAME */ /* Sucky mozilla wants margins in inch! */ aSettings->SetMarginTop (gtk_page_setup_get_top_margin (aPageSetup, GTK_UNIT_INCH)); aSettings->SetMarginBottom (gtk_page_setup_get_bottom_margin (aPageSetup, GTK_UNIT_INCH)); aSettings->SetMarginLeft (gtk_page_setup_get_left_margin (aPageSetup, GTK_UNIT_INCH)); aSettings->SetMarginRight (gtk_page_setup_get_right_margin (aPageSetup, GTK_UNIT_INCH)); aSettings->SetHeaderStrLeft (eel_gconf_get_boolean (CONF_PRINT_PAGE_TITLE) ? LITERAL ("&T") : LITERAL ("")); aSettings->SetHeaderStrCenter (LITERAL ("")); aSettings->SetHeaderStrRight (eel_gconf_get_boolean (CONF_PRINT_PAGE_URL) ? LITERAL ("&U") : LITERAL ("")); aSettings->SetFooterStrLeft (eel_gconf_get_boolean (CONF_PRINT_PAGE_NUMBERS) ? LITERAL ("&PT") : LITERAL ("")); aSettings->SetFooterStrCenter (LITERAL ("")); aSettings->SetFooterStrRight (eel_gconf_get_boolean (CONF_PRINT_DATE) ? LITERAL ("&D") : LITERAL ("")); aSettings->SetPrintFrameType (aPrintFrames); aSettings->SetPrintFrameTypeUsage (nsIPrintSettings::kUseSettingWhenPossible); /* FIXME: only if GTK_PRINT_CAPABILITY_SCALE is not set? */ aSettings->SetScaling (gtk_print_settings_get_scale (aGtkSettings) / 100.0); gtk_print_settings_set_scale (aGtkSettings, 1.0); aSettings->SetShrinkToFit (PR_FALSE); /* FIXME setting */ aSettings->SetPrintBGColors (eel_gconf_get_boolean (CONF_PRINT_BG_COLORS) != FALSE); aSettings->SetPrintBGImages (eel_gconf_get_boolean (CONF_PRINT_BG_IMAGES) != FALSE); /* aSettings->SetPlexName (LITERAL ("default")); */ /* aSettings->SetColorspace (LITERAL ("default")); */ /* aSettings->SetResolutionName (LITERAL ("default")); */ /* aSettings->SetDownloadFonts (PR_TRUE); */ /* Unset those setting that we can handle, so they don't get applied * again for the print job. */ /* gtk_print_settings_set_collate (aGtkSettings, FALSE); not yet */ /* FIXME: Unset the orientation for the print job? */ /* gtk_page_setup_set_orientation (aPageSetup, GTK_PAGE_ORIENTATION_PORTRAIT); */ /* FIXME: unset output format -> "ps" ? */ return NS_OK; }
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; }
NS_IMETHODIMP nsDeviceContextSpecGTK::GetSurfaceForPrinter(gfxASurface **aSurface) { *aSurface = nsnull; const char *path; GetPath(&path); double width, height; mPrintSettings->GetEffectivePageSize(&width, &height); // If we're in landscape mode, we'll be rotating the output -- // need to swap width & height. PRInt32 orientation; mPrintSettings->GetOrientation(&orientation); if (nsIPrintSettings::kLandscapeOrientation == orientation) { double tmp = width; width = height; height = tmp; } // convert twips to points width /= TWIPS_PER_POINT_FLOAT; height /= TWIPS_PER_POINT_FLOAT; DO_PR_DEBUG_LOG(("\"%s\", %f, %f\n", path, width, height)); nsresult rv; // Spool file. Use Glib's temporary file function since we're // already dependent on the gtk software stack. gchar *buf; gint fd = g_file_open_tmp("XXXXXX.tmp", &buf, nsnull); if (-1 == fd) return NS_ERROR_GFX_PRINTER_COULD_NOT_OPEN_FILE; close(fd); rv = NS_NewNativeLocalFile(nsDependentCString(buf), PR_FALSE, getter_AddRefs(mSpoolFile)); if (NS_FAILED(rv)) { unlink(buf); return NS_ERROR_GFX_PRINTER_COULD_NOT_OPEN_FILE; } mSpoolName = buf; g_free(buf); mSpoolFile->SetPermissions(0600); nsCOMPtr<nsIFileOutputStream> stream = do_CreateInstance("@mozilla.org/network/file-output-stream;1"); rv = stream->Init(mSpoolFile, -1, -1, 0); if (NS_FAILED(rv)) return rv; PRInt16 format; mPrintSettings->GetOutputFormat(&format); nsRefPtr<gfxASurface> surface; gfxSize surfaceSize(width, height); // Determine the real format with some GTK magic if (format == nsIPrintSettings::kOutputFormatNative) { if (mIsPPreview) { // There is nothing to detect on Print Preview, use PS. format = nsIPrintSettings::kOutputFormatPS; } else { const gchar* fmtGTK = gtk_print_settings_get(mGtkPrintSettings, GTK_PRINT_SETTINGS_OUTPUT_FILE_FORMAT); if (!fmtGTK && GTK_IS_PRINTER(mGtkPrinter)) { // Likely not print-to-file, check printer's capabilities format = (gtk_printer_accepts_ps(mGtkPrinter)) ? nsIPrintSettings::kOutputFormatPS : nsIPrintSettings::kOutputFormatPDF; } else if (nsDependentCString(fmtGTK).EqualsIgnoreCase("pdf")) { format = nsIPrintSettings::kOutputFormatPDF; } else { format = nsIPrintSettings::kOutputFormatPS; } } } if (format == nsIPrintSettings::kOutputFormatPDF) { surface = new gfxPDFSurface(stream, surfaceSize); } else { surface = new gfxPSSurface(stream, surfaceSize); } if (!surface) return NS_ERROR_OUT_OF_MEMORY; surface.swap(*aSurface); return NS_OK; }