4 * accept dvi function calls and translate to X
8 #include <X11/IntrinsicP.h>
9 #include <X11/StringDefs.h>
14 /* math.h on a Sequent doesn't define M_PI, apparently */
16 #define M_PI 3.14159265358979323846
21 HorizontalMove(dw
, delta
)
25 dw
->dvi
.state
->x
+= delta
;
28 HorizontalGoto(dw
, NewPosition
)
32 dw
->dvi
.state
->x
= NewPosition
;
35 VerticalMove(dw
, delta
)
39 dw
->dvi
.state
->y
+= delta
;
42 VerticalGoto(dw
, NewPosition
)
46 dw
->dvi
.state
->y
= NewPosition
;
52 if (dw
->dvi
.cache
.char_index
!= 0)
53 XDrawText (XtDisplay (dw
), XtWindow (dw
), dw
->dvi
.normal_GC
,
54 dw
->dvi
.cache
.start_x
, dw
->dvi
.cache
.start_y
,
55 dw
->dvi
.cache
.cache
, dw
->dvi
.cache
.index
+ 1);
56 dw
->dvi
.cache
.index
= 0;
57 dw
->dvi
.cache
.max
= DVI_TEXT_CACHE_SIZE
;
58 if (dw
->dvi
.noPolyText
)
59 dw
->dvi
.cache
.max
= 1;
60 dw
->dvi
.cache
.char_index
= 0;
61 dw
->dvi
.cache
.cache
[0].nchars
= 0;
62 dw
->dvi
.cache
.start_x
= dw
->dvi
.cache
.x
= dw
->dvi
.state
->x
;
63 dw
->dvi
.cache
.start_y
= dw
->dvi
.cache
.y
= dw
->dvi
.state
->y
;
69 XClearWindow (XtDisplay (dw
), XtWindow (dw
));
76 int desired_line_width
;
78 if (dw
->dvi
.line_thickness
< 0) {
79 desired_line_width
= (((dw
->dvi
.device_resolution
80 * dw
->dvi
.state
->font_size
) + 5*72)
82 if (desired_line_width
== 0)
83 desired_line_width
= 1;
86 desired_line_width
= dw
->dvi
.line_thickness
;
88 if (desired_line_width
!= dw
->dvi
.line_width
) {
90 values
.line_width
= desired_line_width
;
91 XChangeGC(XtDisplay (dw
), dw
->dvi
.normal_GC
,
92 GCLineWidth
, &values
);
93 dw
->dvi
.line_width
= desired_line_width
;
103 if (dw
->dvi
.fill
== DVI_FILL_MAX
)
104 fill_type
= DVI_FILL_BLACK
;
105 else if (dw
->dvi
.fill
== 0)
106 fill_type
= DVI_FILL_WHITE
;
108 fill_type
= DVI_FILL_GRAY
;
109 if (dw
->dvi
.fill_type
!= fill_type
) {
113 values
.foreground
= dw
->dvi
.background
;
114 values
.fill_style
= FillSolid
;
117 values
.foreground
= dw
->dvi
.foreground
;
118 values
.fill_style
= FillSolid
;
121 values
.foreground
= dw
->dvi
.foreground
;
122 values
.fill_style
= FillOpaqueStippled
;
125 XChangeGC(XtDisplay (dw
), dw
->dvi
.fill_GC
,
126 GCFillStyle
|GCForeground
,
128 dw
->dvi
.fill_type
= fill_type
;
137 XDrawLine (XtDisplay (dw
), XtWindow (dw
), dw
->dvi
.normal_GC
,
138 dw
->dvi
.state
->x
, dw
->dvi
.state
->y
,
139 dw
->dvi
.state
->x
+ x
, dw
->dvi
.state
->y
+ y
);
142 DrawCircle (dw
, diam
)
147 XDrawArc (XtDisplay (dw
), XtWindow (dw
), dw
->dvi
.normal_GC
,
148 dw
->dvi
.state
->x
, dw
->dvi
.state
->y
- diam
/2,
149 diam
, diam
, 0, 64*360);
152 DrawFilledCircle (dw
, diam
)
157 XFillArc (XtDisplay (dw
), XtWindow (dw
), dw
->dvi
.fill_GC
,
158 dw
->dvi
.state
->x
, dw
->dvi
.state
->y
- diam
/2,
159 diam
, diam
, 0, 64*360);
162 DrawEllipse (dw
, a
, b
)
167 XDrawArc (XtDisplay (dw
), XtWindow (dw
), dw
->dvi
.normal_GC
,
168 dw
->dvi
.state
->x
, dw
->dvi
.state
->y
- b
/2,
172 DrawFilledEllipse (dw
, a
, b
)
177 XFillArc (XtDisplay (dw
), XtWindow (dw
), dw
->dvi
.fill_GC
,
178 dw
->dvi
.state
->x
, dw
->dvi
.state
->y
- b
/2,
182 DrawArc (dw
, x0
, y0
, x1
, y1
)
188 int rad
= (int)((sqrt ((double)x0
*x0
+ (double)y0
*y0
)
189 + sqrt ((double)x1
*x1
+ (double)y1
*y1
) + 1.0)/2.0);
190 if ((x0
== 0 && y0
== 0) || (x1
== 0 && y1
== 0))
192 angle1
= (int)(atan2 ((double)y0
, (double)-x0
)*180.0*64.0/M_PI
);
193 angle2
= (int)(atan2 ((double)-y1
, (double)x1
)*180.0*64.0/M_PI
);
200 XDrawArc (XtDisplay (dw
), XtWindow (dw
), dw
->dvi
.normal_GC
,
201 dw
->dvi
.state
->x
+ x0
- rad
, dw
->dvi
.state
->y
+ y0
- rad
,
202 rad
*2, rad
*2, angle1
, angle2
);
205 DrawPolygon (dw
, v
, n
)
210 extern char *malloc();
217 p
= (XPoint
*)malloc((n
+ 2)*sizeof(XPoint
));
220 p
[0].x
= dw
->dvi
.state
->x
;
221 p
[0].y
= dw
->dvi
.state
->y
;
222 for (i
= 0; i
< n
; i
++) {
223 p
[i
+ 1].x
= v
[2*i
] + p
[i
].x
;
224 p
[i
+ 1].y
= v
[2*i
+ 1] + p
[i
].y
;
226 p
[n
+1].x
= dw
->dvi
.state
->x
;
227 p
[n
+1].y
= dw
->dvi
.state
->y
;
228 XDrawLines (XtDisplay (dw
), XtWindow (dw
), dw
->dvi
.normal_GC
,
229 p
, n
+ 2, CoordModeOrigin
);
234 DrawFilledPolygon (dw
, v
, n
)
239 extern char *malloc();
248 p
= (XPoint
*)malloc((n
+ 1)*sizeof(XPoint
));
251 p
[0].x
= dw
->dvi
.state
->x
;
252 p
[0].y
= dw
->dvi
.state
->y
;
253 for (i
= 0; i
< n
; i
++) {
255 p
[i
+ 1].y
= v
[2*i
+ 1];
257 XFillPolygon (XtDisplay (dw
), XtWindow (dw
), dw
->dvi
.fill_GC
,
258 p
, n
+ 1, Complex
, CoordModePrevious
);
262 #define POINTS_MAX 10000
265 appendPoint(points
, pointi
, x
, y
)
270 if (*pointi
< POINTS_MAX
) {
271 points
[*pointi
].x
= x
;
272 points
[*pointi
].y
= y
;
280 flattenCurve(points
, pointi
, x2
, y2
, x3
, y3
, x4
, y4
)
283 int x2
, y2
, x3
, y3
, x4
, y4
;
285 int x1
, y1
, dx
, dy
, n1
, n2
, n
;
287 x1
= points
[*pointi
- 1].x
;
288 y1
= points
[*pointi
- 1].y
;
293 n1
= dy
*(x2
- x1
) - dx
*(y2
- y1
);
294 n2
= dy
*(x3
- x1
) - dx
*(y3
- y1
);
299 n
= n1
> n2
? n1
: n2
;
301 if (n
*n
/ (dy
*dy
+ dx
*dx
) <= FLATNESS
*FLATNESS
)
302 appendPoint (points
, pointi
, x4
, y4
);
304 flattenCurve (points
, pointi
,
305 (x1
+ x2
)/2, (y1
+ y2
)/2,
306 (x1
+ x2
*2 + x3
)/4, (y1
+ y2
*2 + y3
)/4,
307 (x1
+3*x2
+ 3*x3
+ x4
)/8, (y1
+3*y2
+ 3*y3
+ y4
)/8);
308 flattenCurve (points
, pointi
,
309 (x2
+ x3
*2 + x4
)/4, (y2
+ y3
*2 + y4
)/4,
310 (x3
+ x4
)/2, (y3
+ y4
)/2,
316 DrawSpline (dw
, v
, n
)
321 int sx
, sy
, tx
, ty
, ux
, uy
;
324 XPoint points
[POINTS_MAX
];
326 if (n
== 0 || (n
& 1) != 0)
329 sx
= dw
->dvi
.state
->x
;
330 sy
= dw
->dvi
.state
->y
;
336 appendPoint (points
, &pointi
, sx
, sy
);
337 appendPoint (points
, &pointi
, (sx
+ tx
)/2, (sy
+ ty
)/2);
339 for (i
= 2; i
< n
; i
+= 2) {
341 int uy
= ty
+ v
[i
+1];
342 flattenCurve (points
, &pointi
,
343 (sx
+ tx
*5)/6, (sy
+ ty
*5)/6,
344 (tx
*5 + ux
)/6, (ty
*5 + uy
)/6,
345 (tx
+ ux
)/2, (ty
+ uy
)/2);
352 appendPoint (points
, &pointi
, tx
, ty
);
354 XDrawLines (XtDisplay (dw
), XtWindow (dw
), dw
->dvi
.normal_GC
,
355 points
, pointi
, CoordModeOrigin
);
362 c-continued-statement-offset: 8
366 c-tab-always-indent: nil