1 /* Dia -- an diagram creation/manipulation program
2 * Copyright (C) 1998 Alexander Larsson
3 *
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.
8 *
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.
13 *
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.
17 */
18
19 /* The eps_dump_truetype_body function and much inspiration for font dumping
20 * came from ttfps, which bears the following license notice:
21
22 Copyright (c) 1997 by Juliusz Chroboczek
23
24 Copying
25 *******
26
27 This software is provided with no guarantee, not even of any kind.
28
29 Feel free to do whatever you wish with it as long as you don't ask me
30 to maintain it.
31
32 */
33
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)
37 */
38
39 /* Note: There is a use of setmatrix in ellipse, which is supposed to be
40 * avoided. Could it be?
41 */
42
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.
45 */
46
47 #include <config.h>
48
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>
57
58 #include <glib/gstdio.h>
59
60 #include "intl.h"
61 #include "render_eps.h"
62 #include "message.h"
63 #include "diagramdata.h"
64 #include "font.h"
65 #include "diapsrenderer.h"
66
67 #ifdef HAVE_FREETYPE
68 #include "diapsft2renderer.h"
69 #endif
70
71 static void export_eps(DiagramData *data, const gchar *filename,
72 const gchar *diafilename, void* user_data);
73 static void export_render_eps(DiaPsRenderer *renderer,
74 DiagramData *data, const gchar *filename,
75 const gchar *diafilename, void* user_data);
76
77 #ifdef HAVE_FREETYPE
78 static void export_ft2_eps(DiagramData *data, const gchar *filename,
79 const gchar *diafilename, void* user_data);
80 static void
export_ft2_eps(DiagramData * data,const gchar * filename,const gchar * diafilename,void * user_data)81 export_ft2_eps(DiagramData *data, const gchar *filename,
82 const gchar *diafilename, void* user_data) {
83 export_render_eps(g_object_new (DIA_TYPE_PS_FT2_RENDERER, NULL),
84 data, filename, diafilename, user_data);
85 }
86 #endif
87
88 static void
export_eps(DiagramData * data,const gchar * filename,const gchar * diafilename,void * user_data)89 export_eps(DiagramData *data, const gchar *filename,
90 const gchar *diafilename, void* user_data)
91 {
92 export_render_eps(g_object_new (DIA_TYPE_PS_RENDERER, NULL),
93 data, filename, diafilename, user_data);
94 }
95
96 static void
export_render_eps(DiaPsRenderer * renderer,DiagramData * data,const gchar * filename,const gchar * diafilename,void * user_data)97 export_render_eps(DiaPsRenderer *renderer,
98 DiagramData *data, const gchar *filename,
99 const gchar *diafilename, void* user_data)
100 {
101 FILE *outfile;
102
103 outfile = g_fopen(filename, "w");
104 if (outfile == NULL) {
105 message_error(_("Can't open output file %s: %s\n"),
106 dia_message_filename(filename), strerror(errno));
107 g_object_unref(renderer);
108 return;
109 }
110 renderer->file = outfile;
111 renderer->scale = 28.346 * data->paper.scaling;
112 renderer->extent = data->extents;
113 renderer->pstype = (guint)user_data;
114 if (renderer->pstype & PSTYPE_EPSI) {
115 /* Must store the diagram for making a preview */
116 renderer->diagram = data;
117 }
118
119 if (renderer->file) {
120 renderer->title = g_strdup (diafilename);
121
122 data_render(data, DIA_RENDERER(renderer), NULL, NULL, NULL);
123 }
124 g_object_unref (renderer);
125 fclose(outfile);
126 }
127
128 DiaRenderer *
new_psprint_renderer(DiagramData * dia,FILE * file)129 new_psprint_renderer(DiagramData *dia, FILE *file)
130 {
131 DiaPsRenderer *renderer;
132
133 #ifdef HAVE_FREETYPE
134 renderer = g_object_new (DIA_TYPE_PS_FT2_RENDERER, NULL);
135 #else
136 renderer = g_object_new (DIA_TYPE_PS_RENDERER, NULL);
137 #endif
138 renderer->file = file;
139 renderer->pstype = PSTYPE_PS;;
140
141 return DIA_RENDERER(renderer);
142 }
143
144 static const gchar *eps_extensions[] = { "eps", NULL };
145 #if 0
146 static const gchar *epsi_extensions[] = { "epsi", NULL };
147 #endif
148 #ifdef HAVE_FREETYPE
149 DiaExportFilter eps_ft2_export_filter = {
150 N_("Encapsulated Postscript (using Pango fonts)"),
151 eps_extensions,
152 export_ft2_eps,
153 GINT_TO_POINTER(PSTYPE_EPS), /* user_data */
154 "eps-pango"
155 };
156 /* Disabled until we can actually make the preview. */
157 # if 0
158 DiaExportFilter epsi_ft2_export_filter = {
159 N_("Encapsulated Postscript with preview (using Pango fonts)"),
160 epsi_extensions,
161 export_ft2_eps,
162 GINT_TO_POINTER(PSTYPE_EPSI), /* user_data */
163 "epsi-pango"
164 };
165 # endif
166 #endif
167
168 DiaExportFilter eps_export_filter = {
169 N_("Encapsulated Postscript (using PostScript Latin-1 fonts)"),
170 eps_extensions,
171 export_eps,
172 GINT_TO_POINTER(PSTYPE_EPS), /* user_data */
173 "eps-builtin"
174 };
175 /* Commented out until we can actually make the preview.
176 DiaExportFilter epsi_export_filter = {
177 N_("Encapsulated Postscript with preview (using PostScript Latin-1 fonts)"),
178 epsi_extensions,
179 export_eps,
180 PSTYPE_EPSI,
181 "epsi-builtin"
182 };
183 */
184