Just some CVS ignore stuff.
[dia.git] / app / render_eps.c
blobc6cd1e777f8f22843a423d4096656ae7a2bb4986
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"),
104 dia_message_filename(filename), strerror(errno));
105 g_object_unref(renderer);
106 return;
108 renderer->file = outfile;
109 renderer->scale = 28.346 * data->paper.scaling;
110 renderer->extent = data->extents;
111 renderer->pstype = (guint)user_data;
112 if (renderer->pstype & PSTYPE_EPSI) {
113 /* Must store the diagram for making a preview */
114 renderer->diagram = data;
117 if (renderer->file) {
118 renderer->title = g_strdup (diafilename);
120 data_render(data, DIA_RENDERER(renderer), NULL, NULL, NULL);
122 g_object_unref (renderer);
123 fclose(outfile);
126 DiaRenderer *
127 new_psprint_renderer(Diagram *dia, FILE *file)
129 DiaPsRenderer *renderer;
131 #ifdef HAVE_FREETYPE
132 renderer = g_object_new (DIA_TYPE_PS_FT2_RENDERER, NULL);
133 #else
134 renderer = g_object_new (DIA_TYPE_PS_RENDERER, NULL);
135 #endif
136 renderer->file = file;
137 renderer->pstype = PSTYPE_PS;;
139 return DIA_RENDERER(renderer);
142 static const gchar *eps_extensions[] = { "eps", NULL };
143 #if 0
144 static const gchar *epsi_extensions[] = { "epsi", NULL };
145 #endif
146 #ifdef HAVE_FREETYPE
147 DiaExportFilter eps_ft2_export_filter = {
148 N_("Encapsulated Postscript (using Pango fonts)"),
149 eps_extensions,
150 export_ft2_eps,
151 GINT_TO_POINTER(PSTYPE_EPS), /* user_data */
152 "eps-pango"
154 /* Disabled until we can actually make the preview. */
155 # if 0
156 DiaExportFilter epsi_ft2_export_filter = {
157 N_("Encapsulated Postscript with preview (using Pango fonts)"),
158 epsi_extensions,
159 export_ft2_eps,
160 GINT_TO_POINTER(PSTYPE_EPSI), /* user_data */
161 "epsi-pango"
163 # endif
164 #endif
166 DiaExportFilter eps_export_filter = {
167 N_("Encapsulated Postscript (using PostScript Latin-1 fonts)"),
168 eps_extensions,
169 export_eps,
170 GINT_TO_POINTER(PSTYPE_EPS), /* user_data */
171 "eps-builtin"
173 /* Commented out until we can actually make the preview.
174 DiaExportFilter epsi_export_filter = {
175 N_("Encapsulated Postscript with preview (using PostScript Latin-1 fonts)"),
176 epsi_extensions,
177 export_eps,
178 PSTYPE_EPSI,
179 "epsi-builtin"