ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/lsys/ps_int.cpp
Revision: 1.1
Committed: Thu Nov 6 14:31:24 2008 UTC (15 years, 5 months ago) by root
Branch: MAIN
CVS Tags: HEAD
Log Message:
*** empty log message ***

File Contents

# Content
1 /*
2 * postscript interface
3 */
4
5 #include "config.h"
6
7 #include <sstream>
8
9 #include "interface.h"
10 #include "ps_int.h"
11
12 static const char ps_prolog[] =
13 "%!PS-Adobe-2.0\n"
14 "%%Creator: " PACKAGE " version " VERSION "\n"
15 "%%BeginProlog\n"
16 "\n"
17 "/rm { rmoveto } bind def\n"
18 "/rl { rlineto } bind def\n"
19 "/m { moveto } bind def\n"
20 "/l { lineto } bind def\n"
21 "/s { stroke } bind def\n"
22 "/w { setlinewidth } bind def\n"
23 "\n"
24 "/beginpage\n"
25 " {\n"
26 " clippath\n"
27 " pathbbox /py2 exch def /px2 exch def /py1 exch def /px1 exch def\n"
28 " /pw px2 px1 sub def /ph py2 py1 sub def\n"
29 " } bind def\n"
30 "\n"
31 "/endpage\n"
32 " {\n"
33 " showpage\n"
34 " } bind def\n"
35 "\n"
36 "/beginfig\n"
37 " {\n"
38 " /fy2 exch def /fx2 exch def /fy1 exch def /fx1 exch def\n"
39 " /fw fx2 fx1 sub def /fh fy2 fy1 sub def\n"
40 " px1 fx1 pw fw div mul sub py1 fy1 ph fh div mul sub translate\n"
41 " pw fw div ph fh div scale\n"
42 "% pw fw sub 0.5 mul ph fh sub 0.5 mul translate\n"
43 " newpath 0 0 moveto\n"
44 " } bind def\n"
45 "\n"
46 "/endfig\n"
47 " {\n"
48 " s\n"
49 " } bind def\n"
50 "\n"
51 "/bp\n"
52 " {\n"
53 " gsave newpath\n"
54 " } bind def\n"
55 "\n"
56 "/ep\n"
57 " {\n"
58 " closepath\n"
59 " fill\n"
60 " grestore\n"
61 " } bind def\n"
62 "\n"
63 "%%EndProlog\n"
64 ;
65
66 static const char ps_epilog[] =
67 "%%Pages: 1\n"
68 "%%EOF\n"
69 ;
70
71 ps_int::ps_int (ostream &out) t_no
72 : o(out)
73 {
74 o << ps_prolog;
75 }
76
77 ps_int::~ps_int () t_no
78 {
79 o << ps_epilog;
80 }
81
82 void ps_int::begin_fig () t_no
83 {
84 x1 = 1e10; x2 = -x1;
85 y1 = 1e10; y2 = -y1;
86 last_pos = vec(0,0,0);
87 o << "%%Page:\n"
88 << "beginpage\n";
89 fig = new ostringstream;
90 }
91
92 void ps_int::end_fig () t_no
93 {
94 o << x1-10 << " " << y1-10 << " " << x2+10 << " " << y2+10 << " beginfig\n";
95 o << fig->str ();
96 delete fig;
97 o << "endfig\n"
98 << "endpage\n"
99 << "%%EndPage:\n";
100 }
101
102 void ps_int::clip (const vec &v) t_no
103 {
104 if (x1 > v[0]) x1 = v[0];
105 if (y1 > v[1]) y1 = v[1];
106 if (x2 < v[0]) x2 = v[0];
107 if (y2 < v[1]) y2 = v[1];
108 }
109
110 void ps_int::check_attrs (const attribute_set &attr) t_err
111 {
112 *fig << "s 0 0 m\n";
113 last_pos = vec(0,0,0);
114 *fig << attr("width", 1) << " w\n";
115 }
116
117 void ps_int::segment (const point &a, const point &b) t_err
118 {
119 check_attrs (a.attr);
120
121 if (last_pos[0] != a.v[0] || last_pos[1] != a.v[1])
122 {
123 clip (a.v);
124 *fig << a.v[0]-last_pos[0] << " " << a.v[1]-last_pos[1] << " rm\n";
125 }
126
127 clip (b.v);
128 *fig << b.v[0]-a.v[0] << " " << b.v[1]-a.v[1] << " rl\n";
129 last_pos = b.v;
130 }
131
132 void ps_int::object (const points &v) t_err
133 {
134 char moveline = 'm';
135
136 check_attrs (v.front().attr);
137
138 *fig << "bp ";
139 for(points::const_iterator i = v.begin (); i != v.end(); ++i)
140 {
141 clip (i->v);
142 *fig << i->v[0] << " " << i->v[1] << " " << moveline << " ";
143 moveline = 'l';
144 }
145
146 *fig << "ep\n";
147 }
148