/* attribute wstring paperName; */ NS_IMETHODIMP nsPrintSettingsGTK::GetPaperName(char16_t * *aPaperName) { NS_ENSURE_ARG_POINTER(aPaperName); *aPaperName = ToNewUnicode(NS_ConvertUTF8toUTF16(gtk_paper_size_get_name(mPaperSize))); return NS_OK; }
static GtkPaperSize* moz_gtk_paper_size_copy_to_new_custom(GtkPaperSize* oldPaperSize) { // We make a "custom-ified" copy of the paper size so it can be changed later. return gtk_paper_size_new_custom(gtk_paper_size_get_name(oldPaperSize), gtk_paper_size_get_display_name(oldPaperSize), gtk_paper_size_get_width(oldPaperSize, GTK_UNIT_INCH), gtk_paper_size_get_height(oldPaperSize, GTK_UNIT_INCH), GTK_UNIT_INCH); }
/** ------------------------------------------------------- * Initialize the nsDeviceContextSpecGTK * @update dc 2/15/98 * @update syd 3/2/99 */ NS_IMETHODIMP nsDeviceContextSpecGTK::Init(nsIWidget *aWidget, nsIPrintSettings* aPS, PRBool aIsPrintPreview) { DO_PR_DEBUG_LOG(("nsDeviceContextSpecGTK::Init(aPS=%p)\n", aPS)); if (gtk_major_version < 2 || (gtk_major_version == 2 && gtk_minor_version < 10)) return NS_ERROR_NOT_AVAILABLE; // I'm so sorry bz mPrintSettings = aPS; mIsPPreview = aIsPrintPreview; // This is only set by embedders PRBool toFile; aPS->GetPrintToFile(&toFile); mToPrinter = !toFile && !aIsPrintPreview; nsCOMPtr<nsPrintSettingsGTK> printSettingsGTK(do_QueryInterface(aPS)); if (!printSettingsGTK) return NS_ERROR_NO_INTERFACE; mGtkPrinter = printSettingsGTK->GetGtkPrinter(); mGtkPrintSettings = printSettingsGTK->GetGtkPrintSettings(); mGtkPageSetup = printSettingsGTK->GetGtkPageSetup(); // This is a horrible workaround for some printer driver bugs that treat custom page sizes different // to standard ones. If our paper object matches one of a standard one, use a standard paper size // object instead. See bug 414314 for more info. GtkPaperSize* geckosHackishPaperSize = gtk_page_setup_get_paper_size(mGtkPageSetup); GtkPaperSize* standardGtkPaperSize = gtk_paper_size_new(gtk_paper_size_get_name(geckosHackishPaperSize)); mGtkPageSetup = gtk_page_setup_copy(mGtkPageSetup); mGtkPrintSettings = gtk_print_settings_copy(mGtkPrintSettings); GtkPaperSize* properPaperSize; if (gtk_paper_size_is_equal(geckosHackishPaperSize, standardGtkPaperSize)) { properPaperSize = standardGtkPaperSize; } else { properPaperSize = geckosHackishPaperSize; gtk_paper_size_free(standardGtkPaperSize); } gtk_print_settings_set_paper_size(mGtkPrintSettings, properPaperSize); gtk_page_setup_set_paper_size_and_default_margins(mGtkPageSetup, properPaperSize); return NS_OK; }
//------------------------------------------------------------------------------ void WBPageSetup::propagate_print_settings_to_grt_tree() { std::string page_orientation_as_str; // Set orientation Gtk::PageOrientation page_orient = _page_setup->get_orientation(); if ( page_orient == Gtk::PAGE_ORIENTATION_PORTRAIT ) page_orientation_as_str = "portrait"; else if ( page_orient == Gtk::PAGE_ORIENTATION_LANDSCAPE ) page_orientation_as_str = "landscape"; else { g_message("Unsupported page orientation. Setting page orientation to portrait"); page_orientation_as_str = "portrait"; } _app_page_settings->orientation(page_orientation_as_str); // Set paper type Gtk::PaperSize gtk_paper_size = _page_setup->get_paper_size(); app_PaperTypeRef paper_type = _app_page_settings->paperType(); const std::string paper_name = bec::replace_string(gtk_paper_size_get_name(gtk_paper_size.gobj()), "_", "-"); grt::ListRef<app_PaperType> paper_types(grt::ListRef<app_PaperType>::cast_from(_app_page_settings.get_grt()->get("/wb/options/paperTypes"))); app_PaperTypeRef ptype(app_PaperTypeRef::cast_from(grt::find_named_object_in_list(paper_types, paper_name))); _app_page_settings->marginBottom(gtk_paper_size.get_default_bottom_margin(Gtk::UNIT_MM)); _app_page_settings->marginLeft(gtk_paper_size.get_default_left_margin(Gtk::UNIT_MM)); _app_page_settings->marginRight(gtk_paper_size.get_default_right_margin(Gtk::UNIT_MM)); _app_page_settings->marginTop(gtk_paper_size.get_default_top_margin(Gtk::UNIT_MM)); if (ptype.is_valid()) _app_page_settings->paperType(ptype); else g_warning("Unknown paper size selected in GTK Page Setup dialog: %s", paper_name.c_str()); }
/* The width is always the shortest side, measure in mm */ static VALUE rg_name(VALUE self) { return CSTR2RVAL(gtk_paper_size_get_name(_SELF(self))); }
/* 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; }
FormatDialog::FormatDialog(GladeSearchpath* gladeSearchPath, Settings* settings, double width, double heigth) : GladeGui(gladeSearchPath, "pagesize.glade", "pagesizeDialog") { XOJ_INIT_TYPE(FormatDialog); this->orientation = ORIENTATION_NOT_DEFINED; this->selectedScale = 0; this->settings = settings; SElement& format = settings->getCustomElement("format"); string unit; if (format.getString("unit", unit)) { for (int i = 0; i < XOJ_UNIT_COUNT; i++) { if (unit == XOJ_UNITS[i].name) { this->selectedScale = i; break; } } } this->scale = XOJ_UNITS[this->selectedScale].scale; this->origHeight = heigth; this->origWidth = width; this->width = -1; this->height = -1; gtk_spin_button_set_value(GTK_SPIN_BUTTON(get("spinWidth")), this->origWidth / this->scale); gtk_spin_button_set_value(GTK_SPIN_BUTTON(get("spinHeight")), this->origHeight / this->scale); GtkWidget* cbUnit = get("cbUnit"); GtkListStore* store = gtk_list_store_new(1, G_TYPE_STRING); gtk_combo_box_set_model(GTK_COMBO_BOX(cbUnit), GTK_TREE_MODEL(store)); g_object_unref(store); GtkCellRenderer* cell = gtk_cell_renderer_text_new(); gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(cbUnit), cell, TRUE); gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(cbUnit), cell, "text", 0, NULL); for (int i = 0; i < XOJ_UNIT_COUNT; i++) { gtk_combo_box_append_text(GTK_COMBO_BOX(cbUnit), XOJ_UNITS[i].name); } gtk_combo_box_set_active(GTK_COMBO_BOX(cbUnit), this->selectedScale); GtkWidget* cbTemplate = get("cbTemplate"); store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_POINTER); gtk_combo_box_set_model(GTK_COMBO_BOX(cbTemplate), GTK_TREE_MODEL(store)); g_object_unref(store); cell = gtk_cell_renderer_text_new(); gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(cbTemplate), cell, TRUE); gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(cbTemplate), cell, "text", 0, NULL); int selectedFormat = -1; string formatlist = settings->getVisiblePageFormats(); if (heigth < width) { double tmp = width; width = heigth; heigth = tmp; } this->list = gtk_paper_size_get_paper_sizes(false); int i = 0; GList* next = NULL; for (GList* l = list; l != NULL; l = next) { GtkPaperSize* s = (GtkPaperSize*) l->data; next = l->next; double w = gtk_paper_size_get_width(s, GTK_UNIT_POINTS); double h = gtk_paper_size_get_height(s, GTK_UNIT_POINTS); bool visible = false; if (((int) (w - width) * 10) == 0 && ((int) (h - heigth) * 10) == 0) { selectedFormat = i; visible = true; } if (formatlist.find(gtk_paper_size_get_name(s)) != string::npos) { visible = true; } if (visible) { GtkTreeIter iter; gtk_list_store_append(store, &iter); gtk_list_store_set(store, &iter, 0, gtk_paper_size_get_display_name(s), -1); gtk_list_store_set(store, &iter, 1, s, -1); i++; } else { gtk_paper_size_free(s); this->list = g_list_delete_link(this->list, l); } } GtkTreeIter iter; gtk_list_store_append(store, &iter); gtk_list_store_set(store, &iter, 0, _C("Custom"), -1); gtk_list_store_set(store, &iter, 1, NULL, -1); // not found, select custom format if (selectedFormat == -1) { selectedFormat = i; } gtk_combo_box_set_active(GTK_COMBO_BOX(cbTemplate), selectedFormat); spinValueChangedCb(NULL, this); g_signal_connect(get("btLandscape"), "toggled", G_CALLBACK(landscapeSelectedCb), this); g_signal_connect(get("btPortrait"), "toggled", G_CALLBACK(portraitSelectedCb), this); g_signal_connect(cbTemplate, "changed", G_CALLBACK(cbFormatChangedCb), this); g_signal_connect(cbUnit, "changed", G_CALLBACK(cbUnitChanged), this); g_signal_connect(get("spinWidth"), "value-changed", G_CALLBACK(spinValueChangedCb), this); g_signal_connect(get("spinHeight"), "value-changed", G_CALLBACK(spinValueChangedCb), this); }