1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317
|
/* This file contains the internal paint_path() and paint_paths() methods,
which the public method endpath() is a wrapper around. */
#include "sys-defines.h"
#include "extern.h"
void
#ifdef _HAVE_PROTOS
_m_paint_path (S___(Plotter *_plotter))
#else
_m_paint_path (S___(_plotter))
S___(Plotter *_plotter;)
#endif
{
const plPath *path;
bool explicit_endpath, sync_miter_limit = false;
/* sync basic path attributes */
_m_set_attributes (R___(_plotter)
PL_ATTR_TRANSFORMATION_MATRIX
| PL_ATTR_PEN_COLOR | PL_ATTR_PEN_TYPE
| PL_ATTR_LINE_STYLE | PL_ATTR_LINE_WIDTH
| PL_ATTR_JOIN_STYLE | PL_ATTR_CAP_STYLE
| PL_ATTR_FILL_COLOR | PL_ATTR_FILL_TYPE
| PL_ATTR_FILL_RULE);
/* our one and only simple path to paint */
path = _plotter->drawstate->path;
if (_plotter->drawstate->join_type == JOIN_MITER
&& (path->type == PATH_SEGMENT_LIST || path->type == PATH_BOX))
/* path may have mitered juncture points */
sync_miter_limit = true;
if (sync_miter_limit)
_m_set_attributes (R___(_plotter) PL_ATTR_MITER_LIMIT);
if (path->type == PATH_SEGMENT_LIST)
explicit_endpath = true;
else
explicit_endpath = false;
/* emit metafile object-drawing instructions to draw the path; include a
preliminary syncing of the `orientation' attribute if relevant */
_m_paint_path_internal (R___(_plotter) path);
if (explicit_endpath)
{
_m_emit_op_code (R___(_plotter) O_ENDPATH);
_m_emit_terminator (S___(_plotter));
}
}
bool
#ifdef _HAVE_PROTOS
_m_paint_paths (S___(Plotter *_plotter))
#else
_m_paint_paths (S___(_plotter))
S___(Plotter *_plotter;)
#endif
{
const plPath *path;
bool sync_miter_limit = false;
int i;
/* sanity check */
if (_plotter->drawstate->num_paths == 0)
return true;
/* sync basic path attributes */
_m_set_attributes (R___(_plotter)
PL_ATTR_TRANSFORMATION_MATRIX
| PL_ATTR_PEN_COLOR | PL_ATTR_PEN_TYPE
| PL_ATTR_LINE_STYLE | PL_ATTR_LINE_WIDTH
| PL_ATTR_JOIN_STYLE | PL_ATTR_CAP_STYLE
| PL_ATTR_FILL_COLOR | PL_ATTR_FILL_TYPE
| PL_ATTR_FILL_RULE);
if (_plotter->drawstate->join_type == JOIN_MITER)
{
for (i = 0; i < _plotter->drawstate->num_paths; i++)
{
path = _plotter->drawstate->paths[i];
if (path->type == PATH_SEGMENT_LIST || path->type == PATH_BOX)
/* compound path may have mitered juncture points */
{
sync_miter_limit = true;
break;
}
}
}
if (sync_miter_limit)
_m_set_attributes (R___(_plotter) PL_ATTR_MITER_LIMIT);
/* loop over simple paths in compound path */
for (i = 0; i < _plotter->drawstate->num_paths; i++)
{
path = _plotter->drawstate->paths[i];
/* emit metafile object-drawing instructions to draw the path; first
sync `orientation' attribute, if relevant */
_m_paint_path_internal (R___(_plotter) path);
if (i < _plotter->drawstate->num_paths - 1)
{
_m_emit_op_code (R___(_plotter) O_ENDSUBPATH);
_m_emit_terminator (S___(_plotter));
}
}
if (_plotter->drawstate->paths[_plotter->drawstate->num_paths - 1]->type == PATH_SEGMENT_LIST)
/* append explicit (as opposed to implicit) endpath; if we didn't wish
to be clever, we'd append one even if the final simple path isn't a
segment list */
{
_m_emit_op_code (R___(_plotter) O_ENDPATH);
_m_emit_terminator (S___(_plotter));
}
/* succesfully painted compound path */
return true;
}
/* Internal routine, called by the MetaPlotter-specific versions of
paint_path() and paint_paths(). Besides emitting metafile instructions
to draw a path, it may emit an instruction to update the `orientation'
attribute, relevant to paths that are boxes/circles/ellipses. */
void
#ifdef _HAVE_PROTOS
_m_paint_path_internal (R___(Plotter *_plotter) const plPath *path)
#else
_m_paint_path_internal (R___(_plotter) path)
S___(Plotter *_plotter;)
const plPath *path;
#endif
{
if (path->type == PATH_BOX
|| path->type == PATH_CIRCLE || path->type == PATH_ELLIPSE)
/* sync orientation; orientation is stored in the path itself, not in
the drawing state */
{
int orientation = (path->clockwise ? -1 : 1);
if (_plotter->meta_orientation != orientation)
{
_m_emit_op_code (R___(_plotter) O_ORIENTATION);
_m_emit_integer (R___(_plotter) orientation);
_m_emit_terminator (S___(_plotter));
_plotter->meta_orientation = orientation;
}
}
switch ((int)path->type)
{
case (int)PATH_SEGMENT_LIST:
{
plPathSegment segment;
int i;
/* last-minute sanity check */
if (path->num_segments == 0)/* nothing to do */
break;
if (path->num_segments == 1) /* shouldn't happen */
break;
segment = path->segments[0]; /* initial moveto */
if (_plotter->meta_pos.x != segment.p.x
|| _plotter->meta_pos.y != segment.p.y)
{
_m_emit_op_code (R___(_plotter) O_FMOVE);
_m_emit_float (R___(_plotter) segment.p.x);
_m_emit_float (R___(_plotter) segment.p.y);
_m_emit_terminator (S___(_plotter));
_plotter->meta_pos = segment.p;
}
for (i = 1; i < path->num_segments; i++)
{
plPathSegment prev_segment;
prev_segment = segment;
segment = path->segments[i];
switch ((int)segment.type)
{
case (int)S_LINE:
_m_emit_op_code (R___(_plotter) O_FCONT);
_m_emit_float (R___(_plotter) segment.p.x);
_m_emit_float (R___(_plotter) segment.p.y);
_m_emit_terminator (S___(_plotter));
_plotter->meta_pos = segment.p;
break;
case (int)S_ARC:
_m_emit_op_code (R___(_plotter) O_FARC);
_m_emit_float (R___(_plotter) segment.pc.x);
_m_emit_float (R___(_plotter) segment.pc.y);
_m_emit_float (R___(_plotter) prev_segment.p.x);
_m_emit_float (R___(_plotter) prev_segment.p.y);
_m_emit_float (R___(_plotter) segment.p.x);
_m_emit_float (R___(_plotter) segment.p.y);
_m_emit_terminator (S___(_plotter));
_plotter->meta_pos = segment.p;
break;
case (int)S_ELLARC:
_m_emit_op_code (R___(_plotter) O_FELLARC);
_m_emit_float (R___(_plotter) segment.pc.x);
_m_emit_float (R___(_plotter) segment.pc.y);
_m_emit_float (R___(_plotter) prev_segment.p.x);
_m_emit_float (R___(_plotter) prev_segment.p.y);
_m_emit_float (R___(_plotter) segment.p.x);
_m_emit_float (R___(_plotter) segment.p.y);
_m_emit_terminator (S___(_plotter));
_plotter->meta_pos = segment.p;
break;
case (int)S_QUAD:
_m_emit_op_code (R___(_plotter) O_FBEZIER2);
_m_emit_float (R___(_plotter) prev_segment.p.x);
_m_emit_float (R___(_plotter) prev_segment.p.y);
_m_emit_float (R___(_plotter) segment.pc.x);
_m_emit_float (R___(_plotter) segment.pc.y);
_m_emit_float (R___(_plotter) segment.p.x);
_m_emit_float (R___(_plotter) segment.p.y);
_m_emit_terminator (S___(_plotter));
_plotter->meta_pos = segment.p;
break;
case (int)S_CUBIC:
_m_emit_op_code (R___(_plotter) O_FBEZIER3);
_m_emit_float (R___(_plotter) prev_segment.p.x);
_m_emit_float (R___(_plotter) prev_segment.p.y);
_m_emit_float (R___(_plotter) segment.pc.x);
_m_emit_float (R___(_plotter) segment.pc.y);
_m_emit_float (R___(_plotter) segment.pd.x);
_m_emit_float (R___(_plotter) segment.pd.y);
_m_emit_float (R___(_plotter) segment.p.x);
_m_emit_float (R___(_plotter) segment.p.y);
_m_emit_terminator (S___(_plotter));
_plotter->meta_pos = segment.p;
break;
default: /* shouldn't happen */
break;
}
}
}
break;
case (int)PATH_BOX:
{
_m_emit_op_code (R___(_plotter) O_FBOX);
_m_emit_float (R___(_plotter) path->p0.x);
_m_emit_float (R___(_plotter) path->p0.y);
_m_emit_float (R___(_plotter) path->p1.x);
_m_emit_float (R___(_plotter) path->p1.y);
_m_emit_terminator (S___(_plotter));
_plotter->meta_pos.x = 0.5 * (path->p0.x + path->p1.x);
_plotter->meta_pos.y = 0.5 * (path->p0.y + path->p1.y);
}
break;
case (int)PATH_CIRCLE:
{
_m_emit_op_code (R___(_plotter) O_FCIRCLE);
_m_emit_float (R___(_plotter) path->pc.x);
_m_emit_float (R___(_plotter) path->pc.y);
_m_emit_float (R___(_plotter) path->radius);
_m_emit_terminator (S___(_plotter));
_plotter->meta_pos = path->pc;
}
break;
case (int)PATH_ELLIPSE:
{
_m_emit_op_code (R___(_plotter) O_FELLIPSE);
_m_emit_float (R___(_plotter) path->pc.x);
_m_emit_float (R___(_plotter) path->pc.y);
_m_emit_float (R___(_plotter) path->rx);
_m_emit_float (R___(_plotter) path->ry);
_m_emit_float (R___(_plotter) path->angle);
_m_emit_terminator (S___(_plotter));
_plotter->meta_pos = path->pc;
}
break;
default: /* shouldn't happen */
break;
}
}
bool
#ifdef _HAVE_PROTOS
_m_path_is_flushable (S___(Plotter *_plotter))
#else
_m_path_is_flushable (S___(_plotter))
S___(Plotter *_plotter;)
#endif
{
return true;
}
void
#ifdef _HAVE_PROTOS
_m_maybe_prepaint_segments (R___(Plotter *_plotter) int prev_num_segments)
#else
_m_maybe_prepaint_segments (R___(_plotter) prev_num_segments)
S___(Plotter *_plotter;)
int prev_num_segments;
#endif
{
return;
}
|