2
/******************************************************************************
4
* DESCRIPTION: Basic boxes are the most elementary boxes.
5
* We have implemented the following ones:
8
* COPYRIGHT : (C) 1999 Joris van der Hoeven
9
*******************************************************************************
10
* This software falls under the GNU general public license and comes WITHOUT
11
* ANY WARRANTY WHATSOEVER. See the file $TEXMACS_PATH/LICENSE for more details.
12
* If you don't have this file, write to the Free Software Foundation, Inc.,
13
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
14
******************************************************************************/
17
#include "formatter.hpp"
21
/******************************************************************************
23
******************************************************************************/
25
struct test_box_rep: public box_rep {
26
test_box_rep (path ip): box_rep (ip) {
27
x1=x3=0; x2=x4=50<<8; y1=y3=0; y2=y4= 25<<8; }
28
operator tree () { return "test"; }
29
void display (ps_device dev);
33
test_box_rep::display (ps_device dev) {
34
dev->set_color (dev->green);
35
dev->set_line_style (PIXEL);
36
dev->line (x1, y1, x2, y2);
37
dev->line (x1, y2, x2, y1);
38
// dev->arc (x1, y1, x2, y2, 45*64, 90*64);
41
/******************************************************************************
43
******************************************************************************/
45
struct line_box_rep: public box_rep {
50
line_box_rep (path ip, SI X1b, SI Y1b, SI X2b, SI Y2b, SI w, color c);
51
operator tree () { return "line"; }
52
void display (ps_device dev);
55
line_box_rep::line_box_rep (
56
path ip, SI X1b, SI Y1b, SI X2b, SI Y2b, SI w, color c):
65
x1= min (X1, X2); y1= min (Y1, Y2);
66
x2= max (X1, X2); y2= max (Y1, Y2);
67
x3= x1-(w>>1); y3= y1-(w>>1);
68
x4= x2+(w>>1); y4= y2+(w>>1);
72
line_box_rep::display (ps_device dev) {
73
dev->set_line_style (width);
75
dev->line (X1, Y1, X2, Y2);
78
/******************************************************************************
80
******************************************************************************/
82
struct polygon_box_rep: public box_rep {
87
polygon_box_rep (path ip, array<SI> x, array<SI> y, SI w, color f, color o);
88
operator tree () { return "polygon"; }
89
void display (ps_device dev);
92
polygon_box_rep::polygon_box_rep (
93
path ip, array<SI> X, array<SI> Y, SI W, color f, color o):
94
box_rep (ip), x (X), y (Y), fill (f), outline (o), w (W)
97
x1= x2= x[0]; y1= y2= y[0];
99
x1= min (x1, x[i]); y1= min (y1, y[i]);
100
x2= max (x2, x[i]); y2= max (y2, y[i]);
102
x3= x1-(w>>1); y3= y1-(w>>1);
103
x4= x2+(w>>1); y4= y2+(w>>1);
107
polygon_box_rep::display (ps_device dev) {
108
dev->set_color (fill);
112
dev->set_line_style (w);
113
dev->set_color (outline);
115
dev->line (x[i], y[i], x[(i+1)%n], y[(i+1)%n]);
119
/******************************************************************************
121
******************************************************************************/
123
struct arc_box_rep: public box_rep {
129
arc_box_rep (path ip, SI X1b, SI Y1b, SI X2b, SI Y2b,
130
int A1, int A2, SI w, color c);
131
operator tree () { return "arc"; }
132
void display (ps_device dev);
135
arc_box_rep::arc_box_rep (path ip, SI X1b, SI Y1b, SI X2b, SI Y2b,
136
int a1b, int a2b, SI w, color c): box_rep (ip)
147
double scale= 3.1415927 / (180<<6);
148
SI P1= ((X1+X2)/2) + (SI) (((X2-X1)/2) * cos (((double) a1) * scale));
149
SI Q1= ((Y1+Y2)/2) + (SI) (((Y2-Y1)/2) * sin (((double) a1) * scale));
150
SI P2= ((X1+X2)/2) + (SI) (((X2-X1)/2) * cos (((double) a2) * scale));
151
SI Q2= ((Y1+Y2)/2) + (SI) (((Y2-Y1)/2) * sin (((double) a2) * scale));
159
if ((s< 90) && ((s+d)> 90)) q2= Y2;
160
if ((s<180) && ((s+d)>180)) p1= X1;
161
if ((s<270) && ((s+d)>270)) q1= Y1;
162
if ((s<360) && ((s+d)>360)) p2= X2;
163
if ((s<450) && ((s+d)>450)) q2= Y2;
164
if ((s<540) && ((s+d)>540)) p1= X1;
165
if ((s<630) && ((s+d)>630)) q1= Y1;
167
x1= min (p1, p2); y1= min (q1, q2);
168
x2= max (p1, p2); y2= max (q1, q2);
169
x3= x1-(w>>1); y3= y1-(w>>1);
170
x4= x2+(w>>1); y4= y2+(w>>1);
174
arc_box_rep::display (ps_device dev) {
175
dev->set_line_style (width);
176
dev->set_color (col);
177
dev->arc (X1, Y1, X2, Y2, a1, a2-a1);
178
// dev->line (x1, y1, x2, y2);
181
/******************************************************************************
183
******************************************************************************/
185
struct postscript_box_rep: public box_rep {
189
postscript_box_rep (path ip, url image2, SI w, SI h,
190
int X1, int Y1, int X2, int Y2);
191
operator tree () { return "postscript"; }
192
void display (ps_device dev);
195
postscript_box_rep::postscript_box_rep (
197
SI w, SI h, int X1b, int Y1b, int X2b, int Y2b):
198
box_rep (ip), image (image2)
202
x1= x3= 0; y1= y3= 0;
203
x2= x4= w; y2= y4= h;
207
postscript_box_rep::display (ps_device dev) {
208
dev->postscript (image, x2, y2, 0, 0, X1, Y1, X2, Y2);
211
/******************************************************************************
213
******************************************************************************/
215
struct control_tree_box_rep: public box_rep {
217
control_tree_box_rep (path ip, tree t2, font fn): box_rep (ip), t (t2) {
218
x1=x2=x3=x4=y1=y3=y4=0; y2=fn->yx; }
219
operator tree () { return tuple ("control tree", (tree) t); }
220
void display (ps_device dev) { (void) dev; }
221
tree get_leaf_tree () { return t; }
224
struct control_lazy_box_rep: public box_rep {
226
control_lazy_box_rep (path ip, lazy lz2, font fn): box_rep (ip), lz (lz2) {
227
x1=x2=x3=x4=y1=y3=y4=0; y2=fn->yx; }
228
operator tree () { return tuple ("control lazy", (tree) lz); }
229
void display (ps_device dev) { (void) dev; }
230
lazy get_leaf_lazy () { return lz; }
233
/******************************************************************************
234
* box construction routines
235
******************************************************************************/
239
return new test_box_rep (ip);
243
line_box (path ip, SI x1, SI y1, SI x2, SI y2, SI w, SI c) {
244
return new line_box_rep (ip, x1, y1, x2, y2, w, c);
248
arc_box (path ip, SI x1, SI y1, SI x2, SI y2, int a1, int a2, SI w, SI c) {
249
return new arc_box_rep (ip, x1, y1, x2, y2, a1, a2, w, c);
253
polygon_box (path ip, array<SI> x, array<SI> y, SI w, color cf, color cl) {
254
return new polygon_box_rep (ip, x, y, w, cf, cl);
258
polygon_box (path ip, array<SI> x, array<SI> y, color c) {
259
return new polygon_box_rep (ip, x, y, 0, c, c);
263
postscript_box (path ip, url image, SI w, SI h,
264
int x1, int y1, int x2, int y2)
266
return new postscript_box_rep (ip, image, w, h, x1, y1, x2, y2);
270
control_box (path ip, tree t, font fn) {
271
return new control_tree_box_rep (ip, t, fn);
275
control_box (path ip, lazy lz, font fn) {
276
return new control_lazy_box_rep (ip, lz, fn);