/** * vik_print_preview_new: * @page: page setup * @drawable_id: the drawable to print * * Creates a new #VikPrintPreview widget. * * Return value: the new #VikPrintPreview widget. **/ GtkWidget * vik_print_preview_new (GtkPageSetup *page, GdkDrawable *drawable) { VikPrintPreview *preview; gfloat ratio; preview = g_object_new (VIK_TYPE_PRINT_PREVIEW, NULL); preview->drawable = drawable; if (page != NULL) preview->page = gtk_page_setup_copy (page); else preview->page = gtk_page_setup_new (); ratio = (gtk_page_setup_get_paper_width (preview->page, GTK_UNIT_POINTS) / gtk_page_setup_get_paper_height (preview->page, GTK_UNIT_POINTS)); gtk_aspect_frame_set (GTK_ASPECT_FRAME (preview), 0.5, 0.5, ratio, FALSE); gtk_widget_set_size_request (preview->area, DRAWING_AREA_SIZE, DRAWING_AREA_SIZE); return GTK_WIDGET (preview); }
JNIEXPORT jdouble JNICALL Java_org_gnome_gtk_GtkPageSetup_gtk_1page_1setup_1get_1paper_1height ( 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_paper_height(self, unit); // cleanup parameter self // cleanup parameter unit // translate return value to JNI type _result = (jdouble) result; // and finally return _result; }
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); }
CefSize ClientPrintHandlerGtk::GetPdfPaperSize(int device_units_per_inch) { GtkPageSetup* page_setup = gtk_page_setup_new(); float width = gtk_page_setup_get_paper_width(page_setup, GTK_UNIT_INCH); float height = gtk_page_setup_get_paper_height(page_setup, GTK_UNIT_INCH); g_object_unref(page_setup); return CefSize(width * device_units_per_inch, height * device_units_per_inch); }
static gdouble get_paper_height (SoliPrintPreview *preview) { GtkPageSetup *page_setup; gdouble paper_height; page_setup = gtk_print_context_get_page_setup (preview->context); paper_height = gtk_page_setup_get_paper_height (page_setup, GTK_UNIT_INCH); return paper_height * get_screen_dpi (preview); }
/*! \brief Export a print-style PDF file of the current page. * \par Function Description * Exports the current page as a PDF file to \a filename. The * export is carried out using a normal paper size and margins, as if * printing. * * \param w_current A #GschemToplevel structure. * \param filename The filename for generated PDF. * * \returns TRUE if the operation was successful. */ gboolean x_print_export_pdf_page (GschemToplevel *w_current, const gchar *filename) { PAGE *page; cairo_surface_t *surface; cairo_status_t status; cairo_t *cr; GtkPageSetup *setup; double width, height; EdaConfig *cfg; gboolean is_color; page = w_current->toplevel->page_current; setup = x_print_default_page_setup (w_current->toplevel, page ); width = gtk_page_setup_get_paper_width (setup, GTK_UNIT_POINTS); height = gtk_page_setup_get_paper_height (setup, GTK_UNIT_POINTS); surface = cairo_pdf_surface_create (filename, width, height); cr = cairo_create (surface); cairo_translate (cr, gtk_page_setup_get_left_margin (setup, GTK_UNIT_POINTS), gtk_page_setup_get_top_margin (setup, GTK_UNIT_POINTS)); width = gtk_page_setup_get_page_width (setup, GTK_UNIT_POINTS); height = gtk_page_setup_get_page_height (setup, GTK_UNIT_POINTS); /* Find out if colour printing is enabled */ cfg = eda_config_get_context_for_path (s_page_get_filename (page)); is_color = !eda_config_get_boolean (cfg, CFG_GROUP_PRINTING, CFG_KEY_PRINTING_MONOCHROME, NULL); x_print_draw_page (w_current->toplevel, page, cr, NULL, width, height, is_color, FALSE); cairo_destroy (cr); cairo_surface_finish (surface); status = cairo_surface_status (surface); if (status != CAIRO_STATUS_SUCCESS) { g_warning (_("Failed to write PDF to '%s': %s\n"), filename, cairo_status_to_string (status)); return FALSE; } g_object_unref (setup); cairo_surface_destroy (surface); return TRUE; }
static void unix_start_page (GtkPrintOperation *op, GtkPrintContext *print_context, GtkPageSetup *page_setup) { GtkPrintOperationUnix *op_unix; GtkPaperSize *paper_size; cairo_surface_type_t type; gdouble w, h; op_unix = op->priv->platform_data; paper_size = gtk_page_setup_get_paper_size (page_setup); w = gtk_paper_size_get_width (paper_size, GTK_UNIT_POINTS); h = gtk_paper_size_get_height (paper_size, GTK_UNIT_POINTS); type = cairo_surface_get_type (op_unix->surface); if ((op->priv->manual_number_up < 2) || (op->priv->page_position % op->priv->manual_number_up == 0)) { if (type == CAIRO_SURFACE_TYPE_PS) { cairo_ps_surface_set_size (op_unix->surface, w, h); cairo_ps_surface_dsc_begin_page_setup (op_unix->surface); switch (gtk_page_setup_get_orientation (page_setup)) { case GTK_PAGE_ORIENTATION_PORTRAIT: case GTK_PAGE_ORIENTATION_REVERSE_PORTRAIT: cairo_ps_surface_dsc_comment (op_unix->surface, "%%PageOrientation: Portrait"); break; case GTK_PAGE_ORIENTATION_LANDSCAPE: case GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE: cairo_ps_surface_dsc_comment (op_unix->surface, "%%PageOrientation: Landscape"); break; } } else if (type == CAIRO_SURFACE_TYPE_PDF) { if (!op->priv->manual_orientation) { w = gtk_page_setup_get_paper_width (page_setup, GTK_UNIT_POINTS); h = gtk_page_setup_get_paper_height (page_setup, GTK_UNIT_POINTS); } cairo_pdf_surface_set_size (op_unix->surface, w, h); } } }
static gdouble vik_print_preview_get_scale (VikPrintPreview* preview) { gdouble scale_x; gdouble scale_y; scale_x = ((gdouble) preview->area->allocation.width / gtk_page_setup_get_paper_width (preview->page, GTK_UNIT_POINTS)); scale_y = ((gdouble) preview->area->allocation.height / gtk_page_setup_get_paper_height (preview->page, GTK_UNIT_POINTS)); return MIN (scale_x, scale_y); }
/** * 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); }
/** * vik_print_preview_set_page_setup: * @preview: a #VikPrintPreview. * @page: the page setup to use * * Sets the page setup to use by the #VikPrintPreview. **/ void vik_print_preview_set_page_setup (VikPrintPreview *preview, GtkPageSetup *page) { gfloat ratio; if (preview->page) g_object_unref (preview->page); preview->page = gtk_page_setup_copy (page); ratio = (gtk_page_setup_get_paper_width (page, GTK_UNIT_POINTS) / gtk_page_setup_get_paper_height (page, GTK_UNIT_POINTS)); gtk_aspect_frame_set (GTK_ASPECT_FRAME (preview), 0.5, 0.5, ratio, FALSE); print_preview_queue_draw (preview); }
static void print_size_info_get_page_dimensions (PrintSizeInfo *info, gdouble *page_width, gdouble *page_height, GtkUnit unit) { GtkPageSetup *setup; setup = gtk_print_operation_get_default_page_setup (info->data->operation); if (info->data->use_full_page) { *page_width = gtk_page_setup_get_paper_width (setup, unit); *page_height = gtk_page_setup_get_paper_height (setup, unit); } else { *page_width = gtk_page_setup_get_page_width (setup, unit); *page_height = gtk_page_setup_get_page_height (setup, unit); } }
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 gboolean vik_print_preview_expose_event (GtkWidget *widget, GdkEventExpose *eevent, VikPrintPreview *preview) { gdouble paper_width; gdouble paper_height; gdouble left_margin; gdouble right_margin; gdouble top_margin; gdouble bottom_margin; gdouble scale; cairo_t *cr; paper_width = gtk_page_setup_get_paper_width (preview->page, GTK_UNIT_POINTS); paper_height = gtk_page_setup_get_paper_height (preview->page, GTK_UNIT_POINTS); vik_print_preview_get_page_margins (preview, &left_margin, &right_margin, &top_margin, &bottom_margin); cr = gdk_cairo_create (gtk_widget_get_window(widget)); scale = vik_print_preview_get_scale (preview); /* draw background */ cairo_scale (cr, scale, scale); gdk_cairo_set_source_color (cr, >k_widget_get_style(widget)->white); cairo_rectangle (cr, 0, 0, paper_width, paper_height); cairo_fill (cr); /* draw page_margins */ gdk_cairo_set_source_color (cr, >k_widget_get_style(widget)->black); cairo_rectangle (cr, left_margin, top_margin, paper_width - left_margin - right_margin, paper_height - top_margin - bottom_margin); cairo_stroke (cr); if (preview->dragging) { gint width, height; gdk_drawable_get_size(preview->drawable, &width, &height); cairo_rectangle (cr, left_margin + preview->image_offset_x, top_margin + preview->image_offset_y, (gdouble) width * 72.0 / preview->image_xres, (gdouble) height * 72.0 / preview->image_yres); cairo_stroke (cr); } else { GdkDrawable *drawable = preview->drawable; /* draw image */ cairo_translate (cr, left_margin + preview->image_offset_x, top_margin + preview->image_offset_y); if (preview->pixbuf == NULL) { gint width = MIN (widget->allocation.width, 1024); gint height = MIN (widget->allocation.height, 1024); preview->pixbuf = get_thumbnail(drawable, width, height); } if (preview->pixbuf != NULL) { gint width, height; gdk_drawable_get_size(drawable, &width, &height); gdouble scale_x = ((gdouble) width / gdk_pixbuf_get_width (preview->pixbuf)); gdouble scale_y = ((gdouble) height / gdk_pixbuf_get_height (preview->pixbuf)); scale_x = scale_x * 72.0 / preview->image_xres; scale_y = scale_y * 72.0 / preview->image_yres; cairo_scale (cr, scale_x, scale_y); gdk_cairo_set_source_pixbuf (cr, preview->pixbuf, 0, 0); cairo_paint (cr); } } cairo_destroy (cr); return FALSE; }
static VALUE rg_get_paper_height(VALUE self, VALUE unit) { return rb_float_new(gtk_page_setup_get_paper_height(_SELF(self), RVAL2GTKUNIT(unit))); }