static void vik_print_preview_get_page_margins (VikPrintPreview *preview, gdouble *left_margin, gdouble *right_margin, gdouble *top_margin, gdouble *bottom_margin) { if (preview->use_full_page) { *left_margin = 0.0; *right_margin = 0.0; *top_margin = 0.0; *bottom_margin = 0.0; } else { *left_margin = gtk_page_setup_get_left_margin (preview->page, GTK_UNIT_POINTS); *right_margin = gtk_page_setup_get_right_margin (preview->page, GTK_UNIT_POINTS); *top_margin = gtk_page_setup_get_top_margin (preview->page, GTK_UNIT_POINTS); *bottom_margin = gtk_page_setup_get_bottom_margin (preview->page, GTK_UNIT_POINTS); } }
static void begin_print (GtkPrintOperation *operation, GtkPrintContext *context, PrintData *print_data) { DiaCairoRenderer *cairo_renderer; g_return_if_fail (print_data->renderer != NULL); cairo_renderer = DIA_CAIRO_RENDERER (print_data->renderer); g_return_if_fail (cairo_renderer->cr == NULL); /* the renderer wants it's own reference */ #if 0 /* no alpha with printers */ cairo_renderer->with_alpha = TRUE; #endif cairo_renderer->cr = cairo_reference (gtk_print_context_get_cairo_context (context)); cairo_renderer->dia = print_data->data; #if 0 /* needs some text size scaling ... */ cairo_renderer->layout = gtk_print_context_create_pango_layout (context); #endif /* scaling - as usual I don't get it, or do I? */ cairo_renderer->scale = ( gtk_page_setup_get_paper_width (gtk_print_context_get_page_setup (context), GTK_UNIT_MM) - gtk_page_setup_get_left_margin( gtk_print_context_get_page_setup (context), GTK_UNIT_MM) - gtk_page_setup_get_right_margin( gtk_print_context_get_page_setup (context), GTK_UNIT_MM) ) / print_data->data->paper.width; cairo_renderer->skip_show_page = TRUE; }
JNIEXPORT jdouble JNICALL Java_org_gnome_gtk_GtkPageSetup_gtk_1page_1setup_1get_1right_1margin ( JNIEnv* env, jclass cls, jlong _self, jint _unit ) { gdouble result; jdouble _result; GtkPageSetup* self; GtkUnit unit; // convert parameter self self = (GtkPageSetup*) _self; // convert parameter unit unit = (GtkUnit) _unit; // call function result = gtk_page_setup_get_right_margin(self, unit); // cleanup parameter self // cleanup parameter unit // translate return value to JNI type _result = (jdouble) result; // and finally return _result; }
void nsPrintSettingsGTK::InitUnwriteableMargin() { mUnwriteableMargin.SizeTo( NS_INCHES_TO_INT_TWIPS(gtk_page_setup_get_top_margin(mPageSetup, GTK_UNIT_INCH)), NS_INCHES_TO_INT_TWIPS(gtk_page_setup_get_right_margin(mPageSetup, GTK_UNIT_INCH)), NS_INCHES_TO_INT_TWIPS(gtk_page_setup_get_bottom_margin(mPageSetup, GTK_UNIT_INCH)), NS_INCHES_TO_INT_TWIPS(gtk_page_setup_get_left_margin(mPageSetup, GTK_UNIT_INCH)) ); }
/** * photos_print_preview_set_from_page_setup: * @preview: a #PhotosPrintPreview * @setup: a #GtkPageSetup to set the properties from * * Sets up the page properties from a #GtkPageSetup. Useful when using the * widget with the GtkPrint API. **/ void photos_print_preview_set_from_page_setup (PhotosPrintPreview *preview, GtkPageSetup *setup) { g_return_if_fail (PHOTOS_IS_PRINT_PREVIEW (preview)); g_return_if_fail (GTK_IS_PAGE_SETUP (setup)); g_object_set (G_OBJECT (preview), "page-left-margin", gtk_page_setup_get_left_margin (setup, GTK_UNIT_INCH), "page-right-margin", gtk_page_setup_get_right_margin (setup, GTK_UNIT_INCH), "page-top-margin", gtk_page_setup_get_top_margin (setup, GTK_UNIT_INCH), "page-bottom-margin", gtk_page_setup_get_bottom_margin (setup, GTK_UNIT_INCH), "paper-width", gtk_page_setup_get_paper_width (setup, GTK_UNIT_INCH), "paper-height", gtk_page_setup_get_paper_height (setup, GTK_UNIT_INCH), NULL); }
/* Callback for beginning the print operation, we give the printed pages our tab width from the preferences, and the margins from the page setup dialog. */ static void on_begin_print(GtkPrintOperation *print, GtkPrintContext *context, I7Document *document) { I7App *theapp = i7_app_get(); GSettings *prefs = i7_app_get_prefs(theapp); GtkSourcePrintCompositor *compositor = gtk_source_print_compositor_new(i7_document_get_buffer(document)); g_signal_connect(print, "draw-page", G_CALLBACK(on_draw_page), compositor); g_signal_connect(print, "end-print", G_CALLBACK(on_end_print), compositor); /* Design our printed page */ unsigned tabwidth = g_settings_get_uint(prefs, PREFS_TAB_WIDTH); if(tabwidth == 0) tabwidth = DEFAULT_TAB_WIDTH; gtk_source_print_compositor_set_tab_width(compositor, tabwidth); gtk_source_print_compositor_set_wrap_mode(compositor, GTK_WRAP_WORD_CHAR); PangoFontDescription *font = get_font_description(); gchar *fontstring = pango_font_description_to_string(font); pango_font_description_free(font); gtk_source_print_compositor_set_body_font_name(compositor, fontstring); g_free(fontstring); GtkPageSetup *setup = i7_app_get_page_setup(i7_app_get()); gtk_source_print_compositor_set_top_margin(compositor, gtk_page_setup_get_top_margin(setup, GTK_UNIT_MM), GTK_UNIT_MM); gtk_source_print_compositor_set_bottom_margin(compositor, gtk_page_setup_get_bottom_margin(setup, GTK_UNIT_MM), GTK_UNIT_MM); gtk_source_print_compositor_set_left_margin(compositor, gtk_page_setup_get_left_margin(setup, GTK_UNIT_MM), GTK_UNIT_MM); gtk_source_print_compositor_set_right_margin(compositor, gtk_page_setup_get_right_margin(setup, GTK_UNIT_MM), GTK_UNIT_MM); /* Display a notification in the status bar while paginating */ i7_document_display_status_message(document, _("Paginating..."), PRINT_OPERATIONS); while(!gtk_source_print_compositor_paginate(compositor, context)) { i7_document_display_progress_percentage(document, gtk_source_print_compositor_get_pagination_progress(compositor)); while(gtk_events_pending()) gtk_main_iteration(); } i7_document_display_progress_percentage(document, 0.0); i7_document_remove_status_message(document, PRINT_OPERATIONS); gtk_print_operation_set_n_pages(print, gtk_source_print_compositor_get_n_pages(compositor)); }
static void get_page_dimensions (CustomWidgetInfo *info, gdouble *page_width, gdouble *page_height, GtkUnit unit) { GtkPageSetup *setup; setup = gtk_print_operation_get_default_page_setup (info->data->operation); *page_width = gtk_page_setup_get_paper_width (setup, unit); *page_height = gtk_page_setup_get_paper_height (setup, unit); if (!info->data->use_full_page) { gdouble left_margin = gtk_page_setup_get_left_margin (setup, unit); gdouble right_margin = gtk_page_setup_get_right_margin (setup, unit); gdouble top_margin = gtk_page_setup_get_top_margin (setup, unit); gdouble bottom_margin = gtk_page_setup_get_bottom_margin (setup, unit); *page_width -= left_margin + right_margin; *page_height -= top_margin + bottom_margin; } }
static void draw_page (GtkPrintOperation *operation, GtkPrintContext *context, int page_nr, PrintData *print_data) { Rectangle bounds; DiagramData *data = print_data->data; int x, y; /* the effective sizes - dia already applied is_portrait */ double dp_width = data->paper.width; double dp_height = data->paper.height; DiaCairoRenderer *cairo_renderer; g_return_if_fail (print_data->renderer != NULL); cairo_renderer = DIA_CAIRO_RENDERER (print_data->renderer); if (data->paper.fitto) { x = page_nr % data->paper.fitwidth; y = page_nr / data->paper.fitwidth; bounds.left = dp_width * x + data->extents.left; bounds.top = dp_height * y + data->extents.top; bounds.right = bounds.left + dp_width; bounds.bottom = bounds.top + dp_height; } else { double dx, dy; int nx = ceil((data->extents.right - data->extents.left) / dp_width); x = page_nr % nx; y = page_nr / nx; /* Respect the original pagination as shown by the page guides. * Caclulate the offset between page origin 0,0 and data.extents.topleft. * For the usual first page this boils down to lefttop=(0,0) but beware * the origin being negative. */ dx = fmod(data->extents.left, dp_width); if (dx < 0.0) dx += dp_width; dy = fmod(data->extents.top, dp_height); if (dy < 0.0) dy += dp_height; bounds.left = dp_width * x + data->extents.left - dx; bounds.top = dp_height * y + data->extents.top - dy; bounds.right = bounds.left + dp_width; bounds.bottom = bounds.top + dp_height; } #if 0 /* calls begin/end of the given renderer */ /* count the number of objects in this region */ data_render(data, print_data->renderer, &bounds, (ObjectRenderer) count_objs, &nobjs); if (!nobjs) return; /* not printing empty pages */ #endif /* setup a clipping rect */ { GtkPageSetup *setup = gtk_print_context_get_page_setup (context); double left = gtk_page_setup_get_left_margin (setup, GTK_UNIT_MM); double top = gtk_page_setup_get_top_margin (setup, GTK_UNIT_MM); double width = gtk_page_setup_get_paper_width (setup, GTK_UNIT_MM) - left - gtk_page_setup_get_right_margin (setup, GTK_UNIT_MM); double height = gtk_page_setup_get_paper_height (setup, GTK_UNIT_MM) - top - gtk_page_setup_get_bottom_margin (setup, GTK_UNIT_MM); cairo_save (cairo_renderer->cr); /* we are still in the gtk-print coordinate system */ #if 1 /* ... but apparently already transalted to top,left */ top = left = 0; #endif cairo_rectangle (cairo_renderer->cr, left, top, width, height); cairo_clip (cairo_renderer->cr); } { Rectangle extents = data->extents; data->extents = bounds; /* render only the region, FIXME: better way than modifying DiagramData ? */ data_render(data, print_data->renderer, &bounds, NULL, NULL); data->extents = extents; } cairo_restore (cairo_renderer->cr); }
/* 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; }
PrintInfo::PrintInfo(GtkPrintSettings* settings, GtkPageSetup* pageSetup) : pageSetupScaleFactor(gtk_print_settings_get_scale(settings) / 100.0) , availablePaperWidth(gtk_page_setup_get_paper_width(pageSetup, GTK_UNIT_POINTS) - gtk_page_setup_get_left_margin(pageSetup, GTK_UNIT_POINTS) - gtk_page_setup_get_right_margin(pageSetup, GTK_UNIT_POINTS)) , availablePaperHeight(gtk_page_setup_get_paper_height(pageSetup, GTK_UNIT_POINTS) - gtk_page_setup_get_top_margin(pageSetup, GTK_UNIT_POINTS) - gtk_page_setup_get_bottom_margin(pageSetup, GTK_UNIT_POINTS)) , printSettings(settings) , pageSetup(pageSetup) { ASSERT(settings); ASSERT(pageSetup); }
static VALUE rg_get_right_margin(VALUE self, VALUE unit) { return rb_float_new(gtk_page_setup_get_right_margin(_SELF(self), RVAL2GTKUNIT(unit))); }