2 * gEDA - GNU Electronic Design Automation
3 * This file is a part of gerbv.
5 * Copyright (C) 2000-2002 Stefan Petersen (spe@stacken.kth.se)
7 * Contributed by Dino Ghilardi <dino.ghilardi@ieee.org>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
26 /** \file exportimage.c
27 \brief This file contains image exporting functions for exporting to PNG, PDF, SVG, and Postscript formats
40 #include <gdk-pixbuf/gdk-pixbuf.h>
47 #include <cairo-pdf.h>
49 #include <cairo-svg.h>
51 extern gerbv_render_info_t screenRenderInfo
;
53 void exportimage_render_to_surface_and_destroy (gerbv_project_t
*gerbvProject
,
54 cairo_surface_t
*cSurface
, gerbv_render_info_t
*renderInfo
, gchar
const* filename
) {
55 cairo_t
*cairoTarget
= cairo_create (cSurface
);
57 gerbv_render_all_layers_to_cairo_target_for_vector_output (gerbvProject
, cairoTarget
, renderInfo
);
58 cairo_destroy (cairoTarget
);
59 cairo_surface_destroy (cSurface
);
62 gerbv_render_info_t
gerbv_export_autoscale_project (gerbv_project_t
*gerbvProject
) {
63 gerbv_render_size_t bb
;
64 gerbv_render_get_boundingbox(gerbvProject
, &bb
);
65 // add a border around the bounding box
66 gfloat tempWidth
= bb
.right
- bb
.left
;
67 gfloat tempHeight
= bb
.bottom
- bb
.top
;
68 bb
.right
+= (tempWidth
*0.05);
69 bb
.left
-= (tempWidth
*0.05);
70 bb
.bottom
+= (tempHeight
*0.05);
71 bb
.top
-= (tempHeight
*0.05);
72 float width
= bb
.right
- bb
.left
+ 0.001; // Plus a little extra to prevent from
73 float height
= bb
.bottom
- bb
.top
+ 0.001; // missing items due to round-off errors
75 gerbv_render_info_t renderInfo
= {72, 72, bb
.left
, bb
.top
, 3, width
*72, height
*72};
79 void gerbv_export_png_file_from_project_autoscaled (gerbv_project_t
*gerbvProject
, int widthInPixels
,
80 int heightInPixels
, gchar
const* filename
) {
81 gerbv_render_info_t renderInfo
= {1, 1, 0, 0, 3, widthInPixels
, heightInPixels
};
83 gerbv_render_zoom_to_fit_display (gerbvProject
, &renderInfo
);
84 gerbv_export_png_file_from_project (gerbvProject
, &renderInfo
, filename
);
87 void gerbv_export_png_file_from_project (gerbv_project_t
*gerbvProject
, gerbv_render_info_t
*renderInfo
, gchar
const* filename
) {
88 cairo_surface_t
*cSurface
= cairo_image_surface_create (CAIRO_FORMAT_ARGB32
,
89 renderInfo
->displayWidth
, renderInfo
->displayHeight
);
90 cairo_t
*cairoTarget
= cairo_create (cSurface
);
91 gerbv_render_all_layers_to_cairo_target (gerbvProject
, cairoTarget
, renderInfo
);
92 cairo_surface_write_to_png (cSurface
, filename
);
93 cairo_destroy (cairoTarget
);
94 cairo_surface_destroy (cSurface
);
97 void gerbv_export_pdf_file_from_project_autoscaled (gerbv_project_t
*gerbvProject
, gchar
const* filename
) {
98 gerbv_render_info_t renderInfo
= gerbv_export_autoscale_project(gerbvProject
);
99 gerbv_export_pdf_file_from_project (gerbvProject
, &renderInfo
, filename
);
102 void gerbv_export_pdf_file_from_project (gerbv_project_t
*gerbvProject
, gerbv_render_info_t
*renderInfo
,
103 gchar
const* filename
) {
104 cairo_surface_t
*cSurface
= cairo_pdf_surface_create (filename
, renderInfo
->displayWidth
,
105 renderInfo
->displayHeight
);
107 exportimage_render_to_surface_and_destroy (gerbvProject
, cSurface
, renderInfo
, filename
);
110 void gerbv_export_postscript_file_from_project_autoscaled (gerbv_project_t
*gerbvProject
, gchar
const* filename
) {
111 gerbv_render_info_t renderInfo
= gerbv_export_autoscale_project(gerbvProject
);
112 gerbv_export_postscript_file_from_project (gerbvProject
, &renderInfo
, filename
);
115 void gerbv_export_postscript_file_from_project (gerbv_project_t
*gerbvProject
, gerbv_render_info_t
*renderInfo
,
116 gchar
const* filename
) {
117 cairo_surface_t
*cSurface
= cairo_ps_surface_create (filename
, renderInfo
->displayWidth
,
118 renderInfo
->displayHeight
);
119 exportimage_render_to_surface_and_destroy (gerbvProject
, cSurface
, renderInfo
, filename
);
122 void gerbv_export_svg_file_from_project_autoscaled (gerbv_project_t
*gerbvProject
, gchar
const* filename
) {
123 gerbv_render_info_t renderInfo
= gerbv_export_autoscale_project(gerbvProject
);
124 gerbv_export_svg_file_from_project (gerbvProject
, &renderInfo
, filename
);
127 void gerbv_export_svg_file_from_project (gerbv_project_t
*gerbvProject
, gerbv_render_info_t
*renderInfo
,
128 gchar
const* filename
) {
129 cairo_surface_t
*cSurface
= cairo_svg_surface_create (filename
, renderInfo
->displayWidth
,
130 renderInfo
->displayHeight
);
131 exportimage_render_to_surface_and_destroy (gerbvProject
, cSurface
, renderInfo
, filename
);