1 /* Libart_LGPL - library of basic graphic primitives
2 * Copyright (C) 1998 Raph Levien
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This 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.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
25 #include "art_vpath.h"
26 #include "art_uta_vpath.h"
28 #include "art_rect_uta.h"
29 #include "art_uta_rect.h"
32 #define noTEST_UTA_SPEED
38 print_uta_ps (ArtUta *uta)
42 int width = uta->width;
45 for (y = 0; y < uta->height; y++)
46 for (x = 0; x < width; x++)
48 ub = uta->utiles[y * width + x];
51 x0 = (uta->x0 + x) * ART_UTILE_SIZE + ART_UTA_BBOX_X0(ub);
52 x1 = (uta->x0 + x) * ART_UTILE_SIZE + ART_UTA_BBOX_X1(ub);
53 y0 = (uta->y0 + y) * ART_UTILE_SIZE + ART_UTA_BBOX_Y0(ub);
54 y1 = (uta->y0 + y) * ART_UTILE_SIZE + ART_UTA_BBOX_Y1(ub);
55 printf ("%% tile %d, %d: %d %d %d %d\n",
61 printf ("%d %d moveto %d %d lineto %d %d lineto %d %d lineto closepath fill\n",
62 XOFF + x0, YOFF - y0, XOFF + x1, YOFF - y0,
63 XOFF + x1, YOFF - y1, XOFF + x0, YOFF - y1);
69 print_rbuf_ps (int *rbuf, int width, int height)
73 for (y = 0; y < height; y++)
74 for (x = 0; x < width; x++)
75 if (1 && rbuf[y * width + x] != 0)
76 printf ("%d %d moveto (%d) show\n", x * ART_UTILE_SIZE, y * ART_UTILE_SIZE,
82 randline (ArtUta *uta, int *rbuf, int rbuf_rowstride)
84 double x0, y0, x1, y1;
86 x0 = rand () * (500.0 / RAND_MAX);
87 y0 = rand () * (500.0 / RAND_MAX);
88 x1 = rand () * (500.0 / RAND_MAX);
89 y1 = rand () * (500.0 / RAND_MAX);
91 printf ("%g %g moveto %g %g lineto stroke\n", x0, y0, x1, y1);
92 art_uta_add_line (uta, x0, y0, x1, y1, rbuf, rbuf_rowstride);
97 print_ps_vpath (ArtVpath *vpath)
101 for (i = 0; vpath[i].code != ART_END; i++)
103 switch (vpath[i].code)
106 printf ("%g %g moveto\n", XOFF + vpath[i].x, YOFF - vpath[i].y);
109 printf ("%g %g lineto\n", XOFF + vpath[i].x, YOFF - vpath[i].y);
125 vec = art_new (ArtVpath, n + 2);
126 for (i = 0; i < n; i++)
128 vec[i].code = i ? ART_LINETO : ART_MOVETO;
129 r = rand () * (250.0 / RAND_MAX);
130 th = i * 2 * M_PI / n;
131 vec[i].x = 250 + r * cos (th);
132 vec[i].y = 250 - r * sin (th);
134 vec[i].code = ART_LINETO;
138 vec[i].code = ART_END;
145 main (int argc, char **argv)
155 srand (atoi (argv[1]));
158 printf ("%%!PS-Adobe\n");
159 printf ("/Helvetica findfont 12 scalefont setfont\n");
160 printf ("0.5 setlinewidth\n");
162 printf ("0.5 setgray\n");
163 for (i = 0; i < 500; i += ART_UTILE_SIZE)
165 printf ("%d %d moveto %d %d lineto stroke\n",
166 XOFF, YOFF - i, XOFF + 500, YOFF - i);
167 printf ("%d %d moveto %d %d lineto stroke\n",
168 XOFF + i, YOFF, XOFF + i, YOFF - 500);
175 print_ps_vpath (vec);
176 uta = art_uta_from_vpath (vec);
179 ArtIRect bbox = {5, 5, 450, 450};
180 uta = art_uta_from_irect (&bbox);
185 uta = art_uta_new_coords (0, 0, 500, 500);
187 rbuf = malloc (sizeof(int) * (500 >> ART_UTILE_SHIFT) * (500 >> ART_UTILE_SHIFT));
188 for (i = 0; i < 10; i++)
189 randline (uta, rbuf, 500 >> ART_UTILE_SHIFT);
192 printf ("} def 1 0.5 0.5 setrgbcolor\n");
196 printf ("0 0 0.5 setrgbcolor\n");
199 print_rbuf_ps (rbuf, 500 >> ART_UTILE_SHIFT, 500 >> ART_UTILE_SHIFT);
201 printf ("0 setgray a\n");
203 rects = art_rect_list_from_uta (uta, 256, 64, &n_rects);
205 printf ("%% %d rectangles:\n0 0 1 setrgbcolor\n", n_rects);
207 for (i = 0; i < n_rects; i++)
208 printf ("%d %d moveto %d %d lineto %d %d lineto %d %d lineto closepath stroke\n",
209 XOFF + rects[i].x0, YOFF - rects[i].y0,
210 XOFF + rects[i].x1, YOFF - rects[i].y0,
211 XOFF + rects[i].x1, YOFF - rects[i].y1,
212 XOFF + rects[i].x0, YOFF - rects[i].y1);
214 printf ("showpage\n");
217 #ifdef TEST_UTA_SPEED
218 for (i = 0; i < 1000; i++)
221 uta = art_uta_from_vpath (vec);