more leaks plugged and more *_OPTIONAL
[dia.git] / app / render_eps.c
blob79df954a6d8cf08efdbfd5477d40a057b82836cd
1 /* Dia -- an diagram creation/manipulation program
2 * Copyright (C) 1998 Alexander Larsson
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 /* The eps_dump_truetype_body function and much inspiration for font dumping
20 * came from ttfps, which bears the following license notice:
22 Copyright (c) 1997 by Juliusz Chroboczek
24 Copying
25 *******
27 This software is provided with no guarantee, not even of any kind.
29 Feel free to do whatever you wish with it as long as you don't ask me
30 to maintain it.
34 /* The Document Structure Definitions used for the output is available at
35 * http://www-cdf.fnal.gov/offline/PostScript/psstruct.ps
36 * (Appendix G of the Red and White Book)
39 /* Note: There is a use of setmatrix in ellipse, which is supposed to be
40 * avoided. Could it be?
43 /* Note that the EPS renderer now has two phases: One to collect font
44 * info (and conceivably more, like color defs), and one to actually render.
47 #include <config.h>
49 #include <string.h>
50 #include <time.h>
51 #include <math.h>
52 #ifdef HAVE_UNISTD_H
53 #include <unistd.h>
54 #endif
55 #include <locale.h>
56 #include <errno.h>
58 #include "intl.h"
59 #include "render_eps.h"
60 #include "message.h"
61 #include "diagramdata.h"
62 #include "font.h"
63 #include "diapsrenderer.h"
65 #ifdef HAVE_FREETYPE
66 #include "diapsft2renderer.h"
67 #endif
69 static void export_eps(DiagramData *data, const gchar *filename,
70 const gchar *diafilename, void* user_data);
71 static void export_render_eps(DiaPsRenderer *renderer,
72 DiagramData *data, const gchar *filename,
73 const gchar *diafilename, void* user_data);
75 #ifdef HAVE_FREETYPE
76 static void export_ft2_eps(DiagramData *data, const gchar *filename,
77 const gchar *diafilename, void* user_data);
78 static void
79 export_ft2_eps(DiagramData *data, const gchar *filename,
80 const gchar *diafilename, void* user_data) {
81 export_render_eps(g_object_new (DIA_TYPE_PS_FT2_RENDERER, NULL),
82 data, filename, diafilename, user_data);
84 #endif
86 static void
87 export_eps(DiagramData *data, const gchar *filename,
88 const gchar *diafilename, void* user_data)
90 export_render_eps(g_object_new (DIA_TYPE_PS_RENDERER, NULL),
91 data, filename, diafilename, user_data);
94 static void
95 export_render_eps(DiaPsRenderer *renderer,
96 DiagramData *data, const gchar *filename,
97 const gchar *diafilename, void* user_data)
99 FILE *outfile;
101 outfile = fopen(filename, "w");
102 if (outfile == NULL) {
103 message_error(_("Can't open output file %s: %s\n"), filename, strerror(errno));
104 g_object_unref(renderer);
105 return;
107 renderer->file = outfile;
108 renderer->scale = 28.346 * data->paper.scaling;
109 renderer->extent = data->extents;
110 renderer->is_eps = TRUE;
112 if (renderer->file) {
113 renderer->title = g_strdup (diafilename);
115 data_render(data, DIA_RENDERER(renderer), NULL, NULL, NULL);
117 g_object_unref (renderer);
118 fclose(outfile);
121 DiaRenderer *
122 new_psprint_renderer(Diagram *dia, FILE *file)
124 DiaPsRenderer *renderer;
126 #ifdef HAVE_FREETYPE
127 renderer = g_object_new (DIA_TYPE_PS_FT2_RENDERER, NULL);
128 #else
129 renderer = g_object_new (DIA_TYPE_PS_RENDERER, NULL);
130 #endif
131 renderer->file = file;
132 renderer->is_eps = FALSE;
134 return DIA_RENDERER(renderer);
137 static const gchar *extensions[] = { "eps", "epsi", NULL };
138 #ifdef HAVE_FREETYPE
139 DiaExportFilter eps_ft2_export_filter = {
140 N_("Encapsulated Postscript (using Pango fonts)"),
141 extensions,
142 export_ft2_eps,
143 NULL,
144 "eps-pango"
146 #endif
148 DiaExportFilter eps_export_filter = {
149 N_("Encapsulated Postscript (using PostScript Latin-1 fonts)"),
150 extensions,
151 export_eps,
152 NULL,
153 "eps-builtin"