1 /* libwmf ("ipa/svg/device.h"): library for wmf conversion
2    Copyright (C) 2000 - various; see CREDITS, ChangeLog, and sources
3 
4    The libwmf Library is free software; you can redistribute it and/or
5    modify it under the terms of the GNU Library General Public License as
6    published by the Free Software Foundation; either version 2 of the
7    License, or (at your option) any later version.
8 
9    The libwmf Library 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 GNU
12    Library General Public License for more details.
13 
14    You should have received a copy of the GNU Library General Public
15    License along with the libwmf Library; see the file COPYING.  If not,
16    write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17    Boston, MA 02111-1307, USA.  */
18 
19 
20 /* This is called by wmf_play() the *first* time the meta file is played
21  */
wmf_svg_device_open(wmfAPI * API)22 static void wmf_svg_device_open (wmfAPI* API)
23 {	/* wmf_svg_t* ddata = WMF_SVG_GetData (API); */
24 
25 	WMF_DEBUG (API,"~~~~~~~~wmf_[svg_]device_open");
26 
27 
28 }
29 
30 /* This is called by wmf_api_destroy()
31  */
wmf_svg_device_close(wmfAPI * API)32 static void wmf_svg_device_close (wmfAPI* API)
33 {	/* wmf_svg_t* ddata = WMF_SVG_GetData (API); */
34 
35 	WMF_DEBUG (API,"~~~~~~~~wmf_[svg_]device_close");
36 
37 
38 }
39 
40 /* This is called from the beginning of each play for initial page setup
41  */
wmf_svg_device_begin(wmfAPI * API)42 static void wmf_svg_device_begin (wmfAPI* API)
43 {	wmf_svg_t* ddata = WMF_SVG_GetData (API);
44 
45 	wmfStream* out = ddata->out;
46 
47 	WMF_DEBUG (API,"~~~~~~~~wmf_[svg_]device_begin");
48 
49 	if (out == 0) return;
50 
51 	if ((out->reset (out->context)) && ((API->flags & WMF_OPT_IGNORE_NONFATAL) == 0))
52 	{	WMF_ERROR (API,"unable to reset output stream!");
53 		API->err = wmf_E_DeviceError;
54 		return;
55 	}
56 
57 	if ((ddata->bbox.BR.x <= ddata->bbox.TL.x) || (ddata->bbox.BR.y <= ddata->bbox.TL.y))
58 	{	WMF_ERROR (API,"~~~~~~~~wmf_[svg_]device_begin: bounding box has null or negative size!");
59 		API->err = wmf_E_Glitch;
60 		return;
61 	}
62 
63 	if ((ddata->width == 0) || (ddata->height == 0))
64 	{	ddata->width  = (unsigned int) ceil (ddata->bbox.BR.x - ddata->bbox.TL.x);
65 		ddata->height = (unsigned int) ceil (ddata->bbox.BR.y - ddata->bbox.TL.y);
66 	}
67 
68 	wmf_stream_printf (API,out,"<?xml version=\"1.0\" standalone=\"no\"?>\n");
69 	wmf_stream_printf (API,out,"<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 20001102//EN\"\n");
70 	wmf_stream_printf (API,out,"\"http://www.w3.org/TR/2000/CR-SVG-20001102/DTD/svg-20001102.dtd\">\n");
71 
72 	wmf_stream_printf (API,out,"<svg width=\"%u\" height=\"%u\"\n",ddata->width,ddata->height);
73 	wmf_stream_printf (API,out,"\txmlns:sodipodi=\"http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd\">\n");
74 
75 	if (ddata->Description)
76 	{	wmf_stream_printf (API,out,"<desc>%s</desc>\n",ddata->Description);
77 	}
78 }
79 
80 /* This is called from the end of each play for page termination
81  */
wmf_svg_device_end(wmfAPI * API)82 static void wmf_svg_device_end (wmfAPI* API)
83 {	wmf_svg_t* ddata = WMF_SVG_GetData (API);
84 
85 	wmfStream* out = ddata->out;
86 
87 	WMF_DEBUG (API,"~~~~~~~~wmf_[svg_]device_end");
88 
89 	if (out == 0) return;
90 
91 	wmf_stream_printf (API,out,"</svg>\n");
92 }
93 
svg_translate(wmfAPI * API,wmfD_Coord d_pt)94 static svgPoint svg_translate (wmfAPI* API,wmfD_Coord d_pt)
95 {	wmf_svg_t* ddata = WMF_SVG_GetData (API);
96 
97 	svgPoint g_pt;
98 
99 	double x;
100 	double y;
101 
102 	x = ((double) d_pt.x - (double) ddata->bbox.TL.x);
103 	x /= ((double) ddata->bbox.BR.x - (double) ddata->bbox.TL.x);
104 	x *= (double) ddata->width;
105 
106 	y = ((double) d_pt.y - (double) ddata->bbox.TL.y);
107 	y /= ((double) ddata->bbox.BR.y - (double) ddata->bbox.TL.y);
108 	y *= (double) ddata->height;
109 
110 	g_pt.x = (float) x;
111 	g_pt.y = (float) y;
112 
113 	return (g_pt);
114 }
115 
svg_width(wmfAPI * API,float wmf_width)116 static float svg_width (wmfAPI* API,float wmf_width)
117 {	wmf_svg_t* ddata = WMF_SVG_GetData (API);
118 
119 	double width;
120 
121 	width = (double) wmf_width * (double) ddata->width;
122 	width /= ((double) ddata->bbox.BR.x - (double) ddata->bbox.TL.x);
123 
124 	return ((float) width);
125 }
126 
svg_height(wmfAPI * API,float wmf_height)127 static float svg_height (wmfAPI* API,float wmf_height)
128 {	wmf_svg_t* ddata = WMF_SVG_GetData (API);
129 
130 	double height;
131 
132 	height = (double) wmf_height * (double) ddata->height;
133 	height /= ((double) ddata->bbox.BR.y - (double) ddata->bbox.TL.y);
134 
135 	return ((float) height);
136 }
137