gerbv  2.10.1-dev~93f1b5
export-image.c
Go to the documentation of this file.
1 /*
2  * gEDA - GNU Electronic Design Automation
3  * This file is a part of gerbv.
4  *
5  * Copyright (C) 2000-2002 Stefan Petersen (spe@stacken.kth.se)
6  *
7  * Contributed by Dino Ghilardi <dino.ghilardi@ieee.org>
8  *
9  * $Id$
10  *
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.
15  *
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.
20  *
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
24  */
25 
31 #include "gerbv.h"
32 #include "common.h"
33 
34 #include <math.h>
35 #include <gdk-pixbuf/gdk-pixbuf.h>
36 #include <png.h>
37 
38 #include "render.h"
39 
40 #include "draw.h"
41 #include <cairo.h>
42 #include <cairo-pdf.h>
43 #include <cairo-ps.h>
44 #include <cairo-svg.h>
45 
46 void
47 exportimage_render_to_surface_and_destroy(
48  gerbv_project_t* gerbvProject, cairo_surface_t* cSurface, gerbv_render_info_t* renderInfo, const gchar* filename
49 ) {
50  cairo_t* cairoTarget = cairo_create(cSurface);
51 
52  gerbv_render_all_layers_to_cairo_target_for_vector_output(gerbvProject, cairoTarget, renderInfo);
53  cairo_destroy(cairoTarget);
54  cairo_surface_destroy(cSurface);
55 }
56 
58 gerbv_export_autoscale_project(gerbv_project_t* gerbvProject) {
60  gerbv_render_get_boundingbox(gerbvProject, &bb);
61  // add a border around the bounding box
62  gfloat tempWidth = bb.right - bb.left;
63  gfloat tempHeight = bb.bottom - bb.top;
64  bb.right += (tempWidth * 0.05);
65  bb.left -= (tempWidth * 0.05);
66  bb.bottom += (tempHeight * 0.05);
67  bb.top -= (tempHeight * 0.05);
68  float width = bb.right - bb.left + 0.001; // Plus a little extra to prevent from
69  float height = bb.bottom - bb.top + 0.001; // missing items due to round-off errors
70 
72  width * 72, height * 72 };
73  return renderInfo;
74 }
75 
76 void
78  gerbv_project_t* gerbvProject, int widthInPixels, int heightInPixels, const gchar* filename
79 ) {
80  gerbv_render_info_t renderInfo = {
81  1, 1, 0, 0, GERBV_RENDER_TYPE_CAIRO_HIGH_QUALITY, widthInPixels, heightInPixels
82  };
83 
84  gerbv_render_zoom_to_fit_display(gerbvProject, &renderInfo);
85  gerbv_export_png_file_from_project(gerbvProject, &renderInfo, filename);
86 }
87 
88 void
90  gerbv_project_t* gerbvProject, gerbv_render_info_t* renderInfo, const gchar* filename
91 ) {
92  cairo_surface_t* cSurface =
93  cairo_image_surface_create(CAIRO_FORMAT_ARGB32, renderInfo->displayWidth, renderInfo->displayHeight);
94  cairo_t* cairoTarget = cairo_create(cSurface);
95  gerbv_render_all_layers_to_cairo_target(gerbvProject, cairoTarget, renderInfo);
96  if (CAIRO_STATUS_SUCCESS != cairo_surface_write_to_png(cSurface, filename)) {
97  GERB_COMPILE_ERROR(_("Exporting error to file \"%s\""), filename);
98  }
99  cairo_destroy(cairoTarget);
100  cairo_surface_destroy(cSurface);
101 }
102 
103 void
104 gerbv_export_pdf_file_from_project_autoscaled(gerbv_project_t* gerbvProject, const gchar* filename) {
105  gerbv_render_info_t renderInfo = gerbv_export_autoscale_project(gerbvProject);
106  gerbv_export_pdf_file_from_project(gerbvProject, &renderInfo, filename);
107 }
108 
109 void
111  gerbv_project_t* gerbvProject, gerbv_render_info_t* renderInfo, const gchar* filename
112 ) {
113  cairo_surface_t* cSurface = cairo_pdf_surface_create(filename, renderInfo->displayWidth, renderInfo->displayHeight);
114 
115  exportimage_render_to_surface_and_destroy(gerbvProject, cSurface, renderInfo, filename);
116 }
117 
118 void
120  gerbv_render_info_t renderInfo = gerbv_export_autoscale_project(gerbvProject);
121  gerbv_export_postscript_file_from_project(gerbvProject, &renderInfo, filename);
122 }
123 
124 void
126  gerbv_project_t* gerbvProject, gerbv_render_info_t* renderInfo, const gchar* filename
127 ) {
128  cairo_surface_t* cSurface = cairo_ps_surface_create(filename, renderInfo->displayWidth, renderInfo->displayHeight);
129  exportimage_render_to_surface_and_destroy(gerbvProject, cSurface, renderInfo, filename);
130 }
131 
132 void
133 gerbv_export_svg_file_from_project_autoscaled(gerbv_project_t* gerbvProject, const gchar* filename) {
134  gerbv_render_info_t renderInfo = gerbv_export_autoscale_project(gerbvProject);
135  gerbv_export_svg_file_from_project(gerbvProject, &renderInfo, filename);
136 }
137 
138 void
140  gerbv_project_t* gerbvProject, gerbv_render_info_t* renderInfo, const gchar* filename
141 ) {
142  cairo_surface_t* cSurface = cairo_svg_surface_create(filename, renderInfo->displayWidth, renderInfo->displayHeight);
143  exportimage_render_to_surface_and_destroy(gerbvProject, cSurface, renderInfo, filename);
144 }
Contains basic defines.
Header info for the cairo rendering functions and the related selection calculating functions.
void gerbv_export_png_file_from_project(gerbv_project_t *gerbvProject, gerbv_render_info_t *renderInfo, const gchar *filename)
Render a project to a PNG file using user-specified render info.
Definition: export-image.c:89
void gerbv_export_svg_file_from_project_autoscaled(gerbv_project_t *gerbvProject, const gchar *filename)
Render a project to a SVG file, autoscaling the layers to fit inside the specified image dimensions.
Definition: export-image.c:133
void gerbv_export_pdf_file_from_project(gerbv_project_t *gerbvProject, gerbv_render_info_t *renderInfo, const gchar *filename)
Render a project to a PDF file using user-specified render info.
Definition: export-image.c:110
void gerbv_export_postscript_file_from_project_autoscaled(gerbv_project_t *gerbvProject, const gchar *filename)
Render a project to a Postscript file, autoscaling the layers to fit inside the specified image dimen...
Definition: export-image.c:119
void gerbv_export_svg_file_from_project(gerbv_project_t *gerbvProject, gerbv_render_info_t *renderInfo, const gchar *filename)
Render a project to a file using user-specified render info.
Definition: export-image.c:139
void gerbv_export_pdf_file_from_project_autoscaled(gerbv_project_t *gerbvProject, const gchar *filename)
Render a project to a PDF file, autoscaling the layers to fit inside the specified image dimensions.
Definition: export-image.c:104
void gerbv_export_postscript_file_from_project(gerbv_project_t *gerbvProject, gerbv_render_info_t *renderInfo, const gchar *filename)
Render a project to a Postscript file using user-specified render info.
Definition: export-image.c:125
void gerbv_export_png_file_from_project_autoscaled(gerbv_project_t *gerbvProject, int widthInPixels, int heightInPixels, const gchar *filename)
Render a project to a PNG file, autoscaling the layers to fit inside the specified image dimensions.
Definition: export-image.c:77
void gerbv_render_zoom_to_fit_display(gerbv_project_t *gerbvProject, gerbv_render_info_t *renderInfo)
Calculate the zoom and translations to fit the rendered scene inside the given scene size.
Definition: gerbv.c:683
The main header file for the libgerbv library.
@ GERBV_RENDER_TYPE_CAIRO_HIGH_QUALITY
Definition: gerbv.h:371
Header info for the rendering support functions for gerbv.
gint displayHeight
Definition: gerbv.h:791