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 jlong JNICALL Java_org_gnome_gtk_GtkPrintContext_gtk_1print_1context_1get_1page_1setup ( JNIEnv* env, jclass cls, jlong _self ) { GtkPageSetup* result; jlong _result; GtkPrintContext* self; // convert parameter self self = (GtkPrintContext*) _self; // call function result = gtk_print_context_get_page_setup(self); // cleanup parameter self // translate return value to JNI type _result = (jlong) result; // cleanup return value if (result != NULL) { bindings_java_memory_cleanup((GObject*)result, FALSE); } // and finally return _result; }
static void contact_draw (EContact *contact, EContactPrintContext *ctxt) { GtkPageSetup *setup; gdouble page_height; gchar *file_as; gboolean new_section = FALSE; setup = gtk_print_context_get_page_setup (ctxt->context); page_height = gtk_page_setup_get_page_height (setup, GTK_UNIT_POINTS); file_as = e_contact_get (contact, E_CONTACT_FILE_AS); if (file_as != NULL) { gchar *section; gsize width; width = g_utf8_next_char (file_as) - file_as; section = g_utf8_strup (file_as, width); new_section = (ctxt->section == NULL || g_utf8_collate (ctxt->section, section) != 0); if (new_section) { g_free (ctxt->section); ctxt->section = section; } else g_free (section); } if (new_section) { if (!ctxt->first_contact) { if (ctxt->style->sections_start_new_page) e_contact_start_new_page (ctxt); else if ((ctxt->y + e_contact_get_contact_height ( contact, ctxt)) > page_height) e_contact_start_new_column (ctxt); } if (ctxt->style->letter_headings) e_contact_print_letter_heading (ctxt, ctxt->section); ctxt->first_section = FALSE; } else if (!ctxt->first_contact && ((ctxt->y + e_contact_get_contact_height (contact, ctxt)) > page_height)) { e_contact_start_new_column (ctxt); if (ctxt->style->letter_headings) e_contact_print_letter_heading (ctxt, ctxt->section); } e_contact_print_contact (contact, ctxt); ctxt->first_contact = FALSE; }
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); }
/* Get the paper size in points: these must be used only * after the widget has been mapped and the dpi is known. */ static gdouble get_paper_width (GeditPrintPreview *preview) { GtkPageSetup *page_setup; gdouble paper_width; page_setup = gtk_print_context_get_page_setup (preview->context); paper_width = gtk_page_setup_get_paper_width (page_setup, GTK_UNIT_INCH); return paper_width * get_screen_dpi (preview); }
static cairo_surface_t * create_preview_surface (SoliPrintPreview *preview, gdouble *dpi_x, gdouble *dpi_y) { GtkPageSetup *page_setup; GtkPaperSize *paper_size; page_setup = gtk_print_context_get_page_setup (preview->context); /* Note: gtk_page_setup_get_paper_size() swaps width and height for * landscape. */ paper_size = gtk_page_setup_get_paper_size (page_setup); return create_preview_surface_platform (paper_size, dpi_x, dpi_y); }
/* contact_page_draw_footer inserts the * page number at the end of each page * while printing*/ void contact_page_draw_footer (GtkPrintOperation *operation, GtkPrintContext *context, gint page_nr) { PangoFontDescription *desc; PangoLayout *layout; gdouble x, y, page_height, page_width, page_margin; /*gint n_pages;*/ gchar *text; cairo_t *cr; GtkPageSetup *setup; /*Uncomment next if it is successful to get total number if pages in list view * g_object_get (operation, "n-pages", &n_pages, NULL)*/ text = g_strdup_printf (_("Page %d"), page_nr + 1); setup = gtk_print_context_get_page_setup ( context); page_height = gtk_page_setup_get_page_height (setup, GTK_UNIT_POINTS); page_width = gtk_page_setup_get_page_width (setup, GTK_UNIT_POINTS); page_margin = gtk_page_setup_get_bottom_margin (setup, GTK_UNIT_POINTS); desc = pango_font_description_from_string ("Sans Regular 8"); layout = gtk_print_context_create_pango_layout (context); pango_layout_set_alignment (layout, PANGO_ALIGN_CENTER); pango_layout_set_font_description (layout, desc); pango_layout_set_text (layout, text, -1); pango_layout_set_width (layout, -1); x = page_width / 2.0 - page_margin; y = page_height - page_margin / 2.0; cr = gtk_print_context_get_cairo_context (context); cairo_save (cr); cairo_set_source_rgb (cr, .0, .0, .0); cairo_move_to (cr, x, y); pango_cairo_show_layout (cr, layout); cairo_restore (cr); g_object_unref (layout); pango_font_description_free (desc); g_free (text); }
static void biorhythm_print_draw_page (GtkPrintOperation *operation, GtkPrintContext *context, gint page_nr, gpointer user_data) { cairo_t *cr; gdouble p_width, p_height; GtkPageSetup *page_setup; BiorhythmChart *chart; chart = (BiorhythmChart *) user_data; page_setup = gtk_print_context_get_page_setup (context); p_width = gtk_page_setup_get_page_width (page_setup, GTK_UNIT_POINTS); p_height = gtk_page_setup_get_page_height (page_setup, GTK_UNIT_POINTS); cr = gtk_print_context_get_cairo_context (context); biorhythm_chart_draw_cairo (chart, cr, p_height, p_width); }
static void contact_begin_print (GtkPrintOperation *operation, GtkPrintContext *context, EContactPrintContext *ctxt) { GtkPageSetup *setup; gdouble page_width; e_contact_build_style (ctxt->style); setup = gtk_print_context_get_page_setup (context); page_width = gtk_page_setup_get_page_width (setup, GTK_UNIT_POINTS); ctxt->context = context; ctxt->x = ctxt->y = .0; ctxt->column = 0; ctxt->first_contact = TRUE; ctxt->first_section = TRUE; ctxt->section = NULL; ctxt->column_spacing = gtk_print_context_get_dpi_x (context) / 4; ctxt->column_width = (page_width + ctxt->column_spacing) / ctxt->style->num_columns - ctxt->column_spacing; ctxt->letter_heading_font = pango_font_description_new (); pango_font_description_set_family ( ctxt->letter_heading_font, pango_font_description_get_family ( ctxt->style->headings_font)); pango_font_description_set_size ( ctxt->letter_heading_font, pango_font_description_get_size ( ctxt->style->headings_font) * 1.5); if (ctxt->contact_list != NULL) { ctxt->page_nr = -1; ctxt->pages = 1; g_slist_foreach (ctxt->contact_list, (GFunc) contact_draw, ctxt); gtk_print_operation_set_n_pages (operation, ctxt->pages); } }
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 void xviewer_print_draw_page (GtkPrintOperation *operation, GtkPrintContext *context, gint page_nr, gpointer user_data) { cairo_t *cr; gdouble dpi_x, dpi_y; gdouble x0, y0; gdouble scale_factor; gdouble p_width, p_height; gint width, height; XviewerPrintData *data; GtkPageSetup *page_setup; xviewer_debug (DEBUG_PRINTING); data = (XviewerPrintData *) user_data; scale_factor = data->scale_factor/100; dpi_x = gtk_print_context_get_dpi_x (context); dpi_y = gtk_print_context_get_dpi_y (context); switch (data->unit) { case GTK_UNIT_INCH: x0 = data->left_margin * dpi_x; y0 = data->top_margin * dpi_y; break; case GTK_UNIT_MM: x0 = data->left_margin * dpi_x/25.4; y0 = data->top_margin * dpi_y/25.4; break; default: g_assert_not_reached (); } cr = gtk_print_context_get_cairo_context (context); cairo_translate (cr, x0, y0); page_setup = gtk_print_context_get_page_setup (context); p_width = gtk_page_setup_get_page_width (page_setup, GTK_UNIT_POINTS); p_height = gtk_page_setup_get_page_height (page_setup, GTK_UNIT_POINTS); xviewer_image_get_size (data->image, &width, &height); /* this is both a workaround for a bug in cairo's PDF backend, and a way to ensure we are not printing outside the page margins */ cairo_rectangle (cr, 0, 0, MIN (width*scale_factor, p_width), MIN (height*scale_factor, p_height)); cairo_clip (cr); cairo_scale (cr, scale_factor, scale_factor); #ifdef HAVE_RSVG if (xviewer_image_is_svg (data->image)) { RsvgHandle *svg = xviewer_image_get_svg (data->image); rsvg_handle_render_cairo (svg, cr); return; } else #endif /* JPEGs can be attached to the cairo surface which simply embeds the JPEG file into the * destination PDF skipping (PNG-)recompression. This should reduce PDF sizes enormously. */ if (xviewer_image_is_jpeg (data->image) && _cairo_ctx_supports_jpg_metadata (cr)) { GFile *file; char *img_data; gsize data_len; cairo_surface_t *surface = NULL; xviewer_debug_message (DEBUG_PRINTING, "Attaching image to cairo surface"); file = xviewer_image_get_file (data->image); if (g_file_load_contents (file, NULL, &img_data, &data_len, NULL, NULL)) { XviewerTransform *tf = xviewer_image_get_transform (data->image); XviewerTransform *auto_tf = xviewer_image_get_autorotate_transform (data->image); cairo_matrix_t mx, mx2; if (!tf && auto_tf) { /* If only autorotation data present, * make it the normal rotation. */ tf = auto_tf; auto_tf = NULL; } /* Care must be taken with height and width values. They are not the original * values but were affected by the transformation. As the surface needs to be * generated using the original dimensions they might need to be flipped. */ if (tf) { if (auto_tf) { /* If we have an autorotation apply * it before the others */ tf = xviewer_transform_compose (auto_tf, tf); } switch (xviewer_transform_get_transform_type (tf)) { case XVIEWER_TRANSFORM_ROT_90: surface = cairo_image_surface_create ( CAIRO_FORMAT_RGB24, height, width); cairo_rotate (cr, 90.0 * (G_PI/180.0)); cairo_translate (cr, 0.0, -width); break; case XVIEWER_TRANSFORM_ROT_180: surface = cairo_image_surface_create ( CAIRO_FORMAT_RGB24, width, height); cairo_rotate (cr, 180.0 * (G_PI/180.0)); cairo_translate (cr, -width, -height); break; case XVIEWER_TRANSFORM_ROT_270: surface = cairo_image_surface_create ( CAIRO_FORMAT_RGB24, height, width); cairo_rotate (cr, 270.0 * (G_PI/180.0)); cairo_translate (cr, -height, 0.0); break; case XVIEWER_TRANSFORM_FLIP_HORIZONTAL: surface = cairo_image_surface_create ( CAIRO_FORMAT_RGB24, width, height); cairo_matrix_init_identity (&mx); _xviewer_cairo_matrix_flip (&mx2, &mx, TRUE, FALSE); cairo_transform (cr, &mx2); cairo_translate (cr, -width, 0.0); break; case XVIEWER_TRANSFORM_FLIP_VERTICAL: surface = cairo_image_surface_create ( CAIRO_FORMAT_RGB24, width, height); cairo_matrix_init_identity (&mx); _xviewer_cairo_matrix_flip (&mx2, &mx, FALSE, TRUE); cairo_transform (cr, &mx2); cairo_translate (cr, 0.0, -height); break; case XVIEWER_TRANSFORM_TRANSPOSE: surface = cairo_image_surface_create ( CAIRO_FORMAT_RGB24, height, width); cairo_matrix_init_rotate (&mx, 90.0 * (G_PI/180.0)); cairo_matrix_init_identity (&mx2); _xviewer_cairo_matrix_flip (&mx2, &mx2, TRUE, FALSE); cairo_matrix_multiply (&mx2, &mx, &mx2); cairo_transform (cr, &mx2); break; case XVIEWER_TRANSFORM_TRANSVERSE: surface = cairo_image_surface_create ( CAIRO_FORMAT_RGB24, height, width); cairo_matrix_init_rotate (&mx, 90.0 * (G_PI/180.0)); cairo_matrix_init_identity (&mx2); _xviewer_cairo_matrix_flip (&mx2, &mx2, FALSE, TRUE); cairo_matrix_multiply (&mx2, &mx, &mx2); cairo_transform (cr, &mx2); cairo_translate (cr, -height , -width); break; case XVIEWER_TRANSFORM_NONE: default: surface = cairo_image_surface_create ( CAIRO_FORMAT_RGB24, width, height); break; } } if (!surface) surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24, width, height); cairo_surface_set_mime_data (surface, CAIRO_MIME_TYPE_JPEG, (unsigned char*)img_data, data_len, g_free, img_data); cairo_set_source_surface (cr, surface, 0, 0); cairo_paint (cr); cairo_surface_destroy (surface); g_object_unref (file); return; } g_object_unref (file); } { GdkPixbuf *pixbuf; pixbuf = xviewer_image_get_pixbuf (data->image); gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0); cairo_paint (cr); g_object_unref (pixbuf); } }
static void photos_print_operation_draw_page (GtkPrintOperation *operation, GtkPrintContext *context, gint page_nr) { PhotosPrintOperation *self = PHOTOS_PRINT_OPERATION (operation); GeglRectangle bbox; GdkPixbuf *pixbuf = NULL; GtkPageSetup *page_setup; cairo_t *cr; gdouble dpi_x; gdouble dpi_y; gdouble page_height; gdouble page_width; gdouble scale_factor_n; gdouble x0; gdouble y0; scale_factor_n = self->scale_factor / 100.0; bbox = gegl_node_get_bounding_box (self->node); dpi_x = gtk_print_context_get_dpi_x (context); dpi_y = gtk_print_context_get_dpi_x (context); switch (self->unit) { case GTK_UNIT_INCH: x0 = self->left_margin * dpi_x; y0 = self->top_margin * dpi_y; break; case GTK_UNIT_MM: x0 = self->left_margin * dpi_x / 25.4; y0 = self->top_margin * dpi_y / 25.4; break; case GTK_UNIT_NONE: case GTK_UNIT_POINTS: default: g_assert_not_reached (); } cr = gtk_print_context_get_cairo_context (context); cairo_translate (cr, x0, y0); page_setup = gtk_print_context_get_page_setup (context); page_width = gtk_page_setup_get_page_width (page_setup, GTK_UNIT_POINTS); page_height = gtk_page_setup_get_page_height (page_setup, GTK_UNIT_POINTS); /* This is both a workaround for a bug in cairo's PDF backend, and * a way to ensure we are not printing outside the page margins. */ cairo_rectangle (cr, 0, 0, MIN (bbox.width * scale_factor_n, page_width), MIN (bbox.height * scale_factor_n, page_height)); cairo_clip (cr); cairo_scale (cr, scale_factor_n, scale_factor_n); pixbuf = photos_utils_create_pixbuf_from_node (self->node); if (pixbuf == NULL) goto out; gdk_cairo_set_source_pixbuf (cr, pixbuf, 0.0, 0.0); cairo_paint (cr); out: g_clear_object (&pixbuf); }
static VALUE rg_page_setup(VALUE self) { return GOBJ2RVAL(gtk_print_context_get_page_setup(_SELF(self))); }
static void e_contact_print_contact (EContact *contact, EContactPrintContext *ctxt) { GtkPageSetup *setup; gchar *file_as; cairo_t *cr; gdouble page_height; gint field; setup = gtk_print_context_get_page_setup (ctxt->context); page_height = gtk_page_setup_get_page_height (setup, GTK_UNIT_POINTS); cr = gtk_print_context_get_cairo_context (ctxt->context); cairo_save (cr); ctxt->y += get_font_height (ctxt->style->headings_font) * .2; file_as = e_contact_get (contact, E_CONTACT_FILE_AS); if (ctxt->style->print_using_grey && ctxt->pages == ctxt->page_nr) { cairo_save (cr); cairo_set_source_rgb (cr, .85, .85, .85); cairo_rectangle (cr, ctxt->x, ctxt->y, ctxt->column_width, e_contact_text_height (ctxt->context, ctxt->style->headings_font, file_as)); cairo_fill (cr); cairo_restore (cr); } if (ctxt->pages == ctxt->page_nr) e_contact_output ( ctxt->context, ctxt->style->headings_font, ctxt->x, ctxt->y, ctxt->column_width + 4, file_as); ctxt->y += e_contact_text_height ( ctxt->context, ctxt->style->headings_font, file_as); g_free (file_as); ctxt->y += get_font_height (ctxt->style->headings_font) * .2; for (field = E_CONTACT_FILE_AS; field != E_CONTACT_LAST_SIMPLE_STRING; field++) { const gchar *value; gchar *text; gint wrapped_lines = 0; if (ctxt->y > page_height) e_contact_start_new_column (ctxt); value = e_contact_get_const (contact, field); if (value == NULL || *value == '\0') continue; text = g_strdup_printf ("%s: %s", e_contact_pretty_name (field), value); if (ctxt->pages == ctxt->page_nr) e_contact_output ( ctxt->context, ctxt->style->body_font, ctxt->x, ctxt->y, ctxt->column_width + 4, text); if (get_font_width (ctxt->context, ctxt->style->body_font, text) > ctxt->column_width) wrapped_lines = (get_font_width (ctxt->context, ctxt->style->body_font, text) / (ctxt->column_width + 4)) + 1; ctxt->y = ctxt->y + ((wrapped_lines + 1) * e_contact_text_height (ctxt->context, ctxt->style->body_font, text)); ctxt->y += .2 * get_font_height (ctxt->style->body_font); g_free (text); } ctxt->y += get_font_height (ctxt->style->headings_font) * .4 + 8; cairo_restore (cr); }