f_path.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  1. /* This file is part of the GNU plotutils package. Copyright (C) 1995,
  2. 1996, 1997, 1998, 1999, 2000, 2005, 2008, 2009, Free Software
  3. Foundation, Inc.
  4. The GNU plotutils package is free software. You may redistribute it
  5. and/or modify it under the terms of the GNU General Public License as
  6. published by the Free Software foundation; either version 2, or (at your
  7. option) any later version.
  8. The GNU plotutils package is distributed in the hope that it will be
  9. useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License along
  13. with the GNU plotutils package; see the file COPYING. If not, write to
  14. the Free Software Foundation, Inc., 51 Franklin St., Fifth Floor,
  15. Boston, MA 02110-1301, USA. */
  16. /* This file contains the internal paint_path() and paint_paths() methods,
  17. which the public method endpath() is a wrapper around. */
  18. /* This version is for FigPlotters. By construction, for FigPlotters our
  19. path buffer always contains either a segment list, or a rectangle or
  20. circle or ellipse object. If it's a segment list, it consists of either
  21. (1) a sequence of line segments, or (2) a single circular arc segment.
  22. Those are the only sorts of path that xfig can handle. (For the last to
  23. be included, the map from user to device coordinates must be uniform.) */
  24. #include "sys-defines.h"
  25. #include "extern.h"
  26. /* subtypes of xfig POLYLINE object type (xfig numbering) */
  27. #define P_OPEN 1
  28. #define P_BOX 2
  29. #define P_CLOSED 3
  30. /* subtypes of xfig ELLIPSE object type (xfig numbering) */
  31. #define SUBTYPE_ELLIPSE 1 /* ellipse defined by radii */
  32. #define SUBTYPE_CIRCLE 3 /* circle defined by radius */
  33. /* Fig's line styles, indexed into by internal line number
  34. (PL_L_SOLID/PL_L_DOTTED/PL_L_DOTDASHED/PL_L_SHORTDASHED/PL_L_LONGDASHED/PL_L_DOTDOTDASHED) */
  35. const int _pl_f_fig_line_style[PL_NUM_LINE_TYPES] =
  36. { FIG_L_SOLID, FIG_L_DOTTED, FIG_L_DASHDOTTED, FIG_L_DASHED, FIG_L_DASHED,
  37. FIG_L_DASHDOUBLEDOTTED, FIG_L_DASHTRIPLEDOTTED };
  38. /* Fig join styles, indexed by internal number (miter/rd./bevel/triangular) */
  39. const int _pl_f_fig_join_style[PL_NUM_JOIN_TYPES] =
  40. { FIG_JOIN_MITER, FIG_JOIN_ROUND, FIG_JOIN_BEVEL, FIG_JOIN_ROUND };
  41. /* Fig cap styles, indexed by internal number (butt/rd./project/triangular) */
  42. const int _pl_f_fig_cap_style[PL_NUM_CAP_TYPES] =
  43. { FIG_CAP_BUTT, FIG_CAP_ROUND, FIG_CAP_PROJECT, FIG_CAP_ROUND };
  44. #define FUZZ 0.0000001
  45. void
  46. _pl_f_paint_path (S___(Plotter *_plotter))
  47. {
  48. if (_plotter->drawstate->pen_type == 0
  49. && _plotter->drawstate->fill_type == 0)
  50. /* nothing to draw */
  51. return;
  52. switch ((int)_plotter->drawstate->path->type)
  53. {
  54. case (int)PATH_SEGMENT_LIST:
  55. {
  56. bool closed;
  57. const char *format;
  58. int i, polyline_subtype, line_style;
  59. double nominal_spacing;
  60. double device_line_width;
  61. int quantized_device_line_width;
  62. /* sanity checks */
  63. if (_plotter->drawstate->path->num_segments == 0)/* nothing to do */
  64. break;
  65. if (_plotter->drawstate->path->num_segments == 1) /*shouldn't happen */
  66. break;
  67. if (_plotter->drawstate->path->num_segments == 2
  68. && _plotter->drawstate->path->segments[1].type == S_ARC)
  69. /* segment buffer contains a single arc, not a polyline */
  70. {
  71. double x0 = _plotter->drawstate->path->segments[0].p.x;
  72. double y0 = _plotter->drawstate->path->segments[0].p.y;
  73. double x1 = _plotter->drawstate->path->segments[1].p.x;
  74. double y1 = _plotter->drawstate->path->segments[1].p.y;
  75. double xc = _plotter->drawstate->path->segments[1].pc.x;
  76. double yc = _plotter->drawstate->path->segments[1].pc.y;
  77. _pl_f_draw_arc_internal (R___(_plotter) xc, yc, x0, y0, x1, y1);
  78. break;
  79. }
  80. if ((_plotter->drawstate->path->num_segments >= 3)/*check for closure*/
  81. && (_plotter->drawstate->path->segments[_plotter->drawstate->path->num_segments - 1].p.x == _plotter->drawstate->path->segments[0].p.x)
  82. && (_plotter->drawstate->path->segments[_plotter->drawstate->path->num_segments - 1].p.y == _plotter->drawstate->path->segments[0].p.y))
  83. closed = true;
  84. else
  85. closed = false; /* 2-point ones should be open */
  86. if (closed)
  87. {
  88. polyline_subtype = P_CLOSED;
  89. format = "#POLYLINE [CLOSED]\n%d %d %d %d %d %d %d %d %d %.3f %d %d %d %d %d %d";
  90. }
  91. else
  92. {
  93. polyline_subtype = P_OPEN;
  94. format = "#POLYLINE [OPEN]\n%d %d %d %d %d %d %d %d %d %.3f %d %d %d %d %d %d";
  95. }
  96. /* evaluate fig colors lazily, i.e. only when needed */
  97. _pl_f_set_pen_color (S___(_plotter));
  98. _pl_f_set_fill_color (S___(_plotter));
  99. /* In a .fig file, the width of a line is expressed as a
  100. non-negative integer (a positive integer, if the line is to be
  101. visible). Originally, the width, if positive, was interpreted
  102. as a multiple of a fundamental `Fig display unit', namely 1/80
  103. inch. However, the interpretation of the in-file line width was
  104. subsequently changed, thus:
  105. Width in .fig file Width as actually displayed by xfig
  106. 1 0.5
  107. 2 1
  108. 3 2
  109. 4 3
  110. etc.
  111. In consequence, our line width in terms of Fig display units
  112. usually needs to be adjusted upward, before we round it to the
  113. closest integer. Thanks to Wolfgang Glunz and Bart De Schutter
  114. for pointing this out. (See the addition of 0.75 below, which
  115. is what they recommend.)
  116. */
  117. device_line_width =
  118. FIG_UNITS_TO_FIG_DISPLAY_UNITS(_plotter->drawstate->device_line_width);
  119. if (device_line_width > 0.75)
  120. device_line_width += 1.0;
  121. /* round xfig's notion of the line width to the closest integer;
  122. but never round it down to 0 (which would yield an invisible
  123. line) if the line width in user coordinates is positive;
  124. instead, round it upward to 1 */
  125. quantized_device_line_width = IROUND(device_line_width);
  126. if (quantized_device_line_width == 0 && device_line_width > 0.0)
  127. quantized_device_line_width = 1;
  128. /* compute line style (type of dotting/dashing, spacing of
  129. dots/dashes)*/
  130. _pl_f_compute_line_style (R___(_plotter) &line_style, &nominal_spacing);
  131. /* update xfig's `depth' attribute */
  132. if (_plotter->fig_drawing_depth > 0)
  133. (_plotter->fig_drawing_depth)--;
  134. sprintf(_plotter->data->page->point,
  135. format,
  136. 2, /* polyline object */
  137. polyline_subtype, /* polyline subtype */
  138. line_style, /* Fig line style */
  139. /* thickness, in Fig display units */
  140. (_plotter->drawstate->pen_type == 0 ? 0 :
  141. quantized_device_line_width),
  142. _plotter->drawstate->fig_fgcolor, /* pen color */
  143. _plotter->drawstate->fig_fillcolor, /* fill color */
  144. _plotter->fig_drawing_depth, /* depth */
  145. 0, /* pen style, ignored */
  146. _plotter->drawstate->fig_fill_level, /* area fill */
  147. nominal_spacing, /* style val, in Fig display units (float) */
  148. _pl_f_fig_join_style[_plotter->drawstate->join_type],/*join style */
  149. _pl_f_fig_cap_style[_plotter->drawstate->cap_type], /* cap style */
  150. 0, /* radius(of arc boxes, ignored here) */
  151. 0, /* forward arrow */
  152. 0, /* backward arrow */
  153. _plotter->drawstate->path->num_segments /*num points in line */
  154. );
  155. _update_buffer (_plotter->data->page);
  156. for (i=0; i<_plotter->drawstate->path->num_segments; i++)
  157. {
  158. plPathSegment datapoint;
  159. double xu, yu, xd, yd;
  160. int device_x, device_y;
  161. datapoint = _plotter->drawstate->path->segments[i];
  162. xu = datapoint.p.x;
  163. yu = datapoint.p.y;
  164. xd = XD(xu, yu);
  165. yd = YD(xu, yu);
  166. device_x = IROUND(xd);
  167. device_y = IROUND(yd);
  168. if ((i%5) == 0)
  169. sprintf (_plotter->data->page->point, "\n\t");/* make human-readable */
  170. else
  171. sprintf (_plotter->data->page->point, " ");
  172. _update_buffer (_plotter->data->page);
  173. sprintf (_plotter->data->page->point, "%d %d", device_x, device_y);
  174. _update_buffer (_plotter->data->page);
  175. }
  176. sprintf (_plotter->data->page->point, "\n");
  177. _update_buffer (_plotter->data->page);
  178. }
  179. break;
  180. case (int)PATH_BOX:
  181. {
  182. plPoint p0, p1;
  183. p0 = _plotter->drawstate->path->p0;
  184. p1 = _plotter->drawstate->path->p1;
  185. _pl_f_draw_box_internal (R___(_plotter) p0, p1);
  186. }
  187. break;
  188. case (int)PATH_CIRCLE:
  189. {
  190. double x = _plotter->drawstate->path->pc.x;
  191. double y = _plotter->drawstate->path->pc.y;
  192. double r = _plotter->drawstate->path->radius;
  193. _pl_f_draw_ellipse_internal (R___(_plotter)
  194. x, y, r, r, 0.0, SUBTYPE_CIRCLE);
  195. }
  196. break;
  197. case (int)PATH_ELLIPSE:
  198. {
  199. double x = _plotter->drawstate->path->pc.x;
  200. double y = _plotter->drawstate->path->pc.y;
  201. double rx = _plotter->drawstate->path->rx;
  202. double ry = _plotter->drawstate->path->ry;
  203. double angle = _plotter->drawstate->path->angle;
  204. _pl_f_draw_ellipse_internal (R___(_plotter)
  205. x, y, rx, ry, angle, SUBTYPE_ELLIPSE);
  206. }
  207. break;
  208. default: /* shouldn't happen */
  209. break;
  210. }
  211. }
  212. /* Emit Fig code for an arc. This is called if the segment buffer contains
  213. not a polyline, but a single circular arc. If an arc was placed there,
  214. we can count on the map from the user frame to the device frame being
  215. isotropic (so the arc will be circular in the device frame too), and we
  216. can count on the arc not being of zero length. See g_arc.c. */
  217. #define DIST(p1, p2) sqrt( ((p1).x - (p2).x) * ((p1).x - (p2).x) \
  218. + ((p1).y - (p2).y) * ((p1).y - (p2).y))
  219. void
  220. _pl_f_draw_arc_internal (R___(Plotter *_plotter) double xc, double yc, double x0, double y0, double x1, double y1)
  221. {
  222. plPoint p0, p1, pc, pb;
  223. plVector v, v0, v1;
  224. double cross, radius, nominal_spacing;
  225. int line_style, orientation;
  226. double device_line_width;
  227. int quantized_device_line_width;
  228. pc.x = xc, pc.y = yc;
  229. p0.x = x0, p0.y = y0;
  230. p1.x = x1, p1.y = y1;
  231. /* vectors from pc to p0, and pc to p1 */
  232. v0.x = p0.x - pc.x;
  233. v0.y = p0.y - pc.y;
  234. v1.x = p1.x - pc.x;
  235. v1.y = p1.y - pc.y;
  236. /* cross product, zero means points are collinear */
  237. cross = v0.x * v1.y - v1.x * v0.y;
  238. /* Compute orientation. Note libplot convention: if p0, p1, pc are
  239. collinear then arc goes counterclockwise from p0 to p1. */
  240. orientation = (cross >= 0.0 ? 1 : -1);
  241. radius = DIST(pc, p0); /* radius is distance to p0 or p1 */
  242. v.x = p1.x - p0.x; /* chord vector from p0 to p1 */
  243. v.y = p1.y - p0.y;
  244. _vscale(&v, radius);
  245. pb.x = pc.x + orientation * v.y; /* bisection point of arc */
  246. pb.y = pc.y - orientation * v.x;
  247. /* evaluate fig colors lazily, i.e. only when needed */
  248. _pl_f_set_pen_color (S___(_plotter));
  249. _pl_f_set_fill_color (S___(_plotter));
  250. /* xfig expresses the width of a line as an integer number of `Fig
  251. display units', so convert the width to those units */
  252. device_line_width =
  253. FIG_UNITS_TO_FIG_DISPLAY_UNITS(_plotter->drawstate->device_line_width);
  254. /* the interpretation of line width in a .fig file is now more
  255. complicated (see comments in _pl_f_paint_path() above), so this value
  256. must usually be incremented */
  257. if (device_line_width > 0.75)
  258. device_line_width += 1.0;
  259. /* round xfig's notion of the line width to the closest integer; but
  260. never round it down to 0 (which would yield an invisible line) if the
  261. line width in user coordinates is positive; instead, round it upward
  262. to 1 */
  263. quantized_device_line_width = IROUND(device_line_width);
  264. if (quantized_device_line_width == 0 && device_line_width > 0.0)
  265. quantized_device_line_width = 1;
  266. /* compute line style (type of dotting/dashing, spacing of dots/dashes) */
  267. _pl_f_compute_line_style (R___(_plotter) &line_style, &nominal_spacing);
  268. /* update xfig's `depth' attribute */
  269. if (_plotter->fig_drawing_depth > 0)
  270. (_plotter->fig_drawing_depth)--;
  271. /* compute orientation in NDC frame */
  272. orientation *= (_plotter->drawstate->transform.nonreflection ? 1 : -1);
  273. if (orientation == -1)
  274. /* interchange p0, p1 (since xfig insists that p0, pb, p1 must appear
  275. in counterclockwise order around the arc) */
  276. {
  277. plPoint ptmp;
  278. ptmp = p0;
  279. p0 = p1;
  280. p1 = ptmp;
  281. }
  282. sprintf(_plotter->data->page->point,
  283. "#ARC\n%d %d %d %d %d %d %d %d %d %.3f %d %d %d %d %.3f %.3f %d %d %d %d %d %d\n",
  284. 5, /* arc object */
  285. 1, /* open-ended arc subtype */
  286. line_style, /* Fig line style */
  287. /* thickness, in Fig display units */
  288. (_plotter->drawstate->pen_type == 0 ? 0 :
  289. quantized_device_line_width),
  290. _plotter->drawstate->fig_fgcolor, /* pen color */
  291. _plotter->drawstate->fig_fillcolor, /* fill color */
  292. _plotter->fig_drawing_depth, /* depth */
  293. 0, /* pen style, ignored */
  294. _plotter->drawstate->fig_fill_level, /* area fill */
  295. nominal_spacing, /* style val, in Fig display units (float) */
  296. _pl_f_fig_cap_style[_plotter->drawstate->cap_type], /* cap style */
  297. 1, /* counterclockwise */
  298. 0, /* no forward arrow */
  299. 0, /* no backward arrow */
  300. XD(pc.x, pc.y), /* center_x (float) */
  301. YD(pc.x, pc.y), /* center_y (float) */
  302. IROUND(XD(p0.x, p0.y)), /* 1st point user entered (p0) */
  303. IROUND(YD(p0.x, p0.y)),
  304. IROUND(XD(pb.x, pb.y)), /* 2nd point user entered (bisection point)*/
  305. IROUND(YD(pb.x, pb.y)),
  306. IROUND(XD(p1.x, p1.y)), /* last point user entered (p1) */
  307. IROUND(YD(p1.x, p1.y)));
  308. _update_buffer (_plotter->data->page);
  309. }
  310. void
  311. _pl_f_draw_box_internal (R___(Plotter *_plotter) plPoint p0, plPoint p1)
  312. {
  313. int xd0, xd1, yd0, yd1; /* in device coordinates */
  314. double nominal_spacing;
  315. int line_style;
  316. double device_line_width;
  317. int quantized_device_line_width;
  318. /* evaluate fig colors lazily, i.e. only when needed */
  319. _pl_f_set_pen_color (S___(_plotter));
  320. _pl_f_set_fill_color (S___(_plotter));
  321. /* xfig expresses the width of a line as an integer number of `Fig
  322. display units', so convert the width to those units */
  323. device_line_width =
  324. FIG_UNITS_TO_FIG_DISPLAY_UNITS(_plotter->drawstate->device_line_width);
  325. /* the interpretation of line width in a .fig file is now more
  326. complicated (see comments in _pl_f_paint_path() above), so this value
  327. must usually be incremented */
  328. if (device_line_width > 0.75)
  329. device_line_width += 1.0;
  330. /* round xfig's notion of the line width to the closest integer; but
  331. never round it down to 0 (which would yield an invisible line) if the
  332. line width in user coordinates is positive; instead, round it upward
  333. to 1 */
  334. quantized_device_line_width = IROUND(device_line_width);
  335. if (quantized_device_line_width == 0 && device_line_width > 0.0)
  336. quantized_device_line_width = 1;
  337. /* compute line style (type of dotting/dashing, spacing of dots/dashes)*/
  338. _pl_f_compute_line_style (R___(_plotter) &line_style, &nominal_spacing);
  339. /* update xfig's `depth' attribute */
  340. if (_plotter->fig_drawing_depth > 0)
  341. (_plotter->fig_drawing_depth)--;
  342. sprintf(_plotter->data->page->point,
  343. "#POLYLINE [BOX]\n%d %d %d %d %d %d %d %d %d %.3f %d %d %d %d %d %d\n",
  344. 2, /* polyline object */
  345. P_BOX, /* polyline subtype */
  346. line_style, /* Fig line style */
  347. /* thickness, in Fig display units */
  348. (_plotter->drawstate->pen_type == 0 ? 0 :
  349. quantized_device_line_width),
  350. _plotter->drawstate->fig_fgcolor, /* pen color */
  351. _plotter->drawstate->fig_fillcolor, /* fill color */
  352. _plotter->fig_drawing_depth, /* depth */
  353. 0, /* pen style, ignored */
  354. _plotter->drawstate->fig_fill_level, /* area fill */
  355. nominal_spacing, /* style val, in Fig display units (float) */
  356. _pl_f_fig_join_style[_plotter->drawstate->join_type], /* join style */
  357. _pl_f_fig_cap_style[_plotter->drawstate->cap_type], /* cap style */
  358. 0, /* radius (of arc boxes, ignored here) */
  359. 0, /* forward arrow */
  360. 0, /* backward arrow */
  361. 5 /* number of points in line */
  362. );
  363. _update_buffer (_plotter->data->page);
  364. p0 = _plotter->drawstate->path->p0;
  365. p1 = _plotter->drawstate->path->p1;
  366. xd0 = IROUND(XD(p0.x, p0.y));
  367. yd0 = IROUND(YD(p0.x, p0.y));
  368. xd1 = IROUND(XD(p1.x, p1.y));
  369. yd1 = IROUND(YD(p1.x, p1.y));
  370. sprintf (_plotter->data->page->point, "\t%d %d ", xd0, yd0);
  371. _update_buffer (_plotter->data->page);
  372. sprintf (_plotter->data->page->point, "%d %d ", xd0, yd1);
  373. _update_buffer (_plotter->data->page);
  374. sprintf (_plotter->data->page->point, "%d %d ", xd1, yd1);
  375. _update_buffer (_plotter->data->page);
  376. sprintf (_plotter->data->page->point, "%d %d ", xd1, yd0);
  377. _update_buffer (_plotter->data->page);
  378. sprintf (_plotter->data->page->point, "%d %d\n", xd0, yd0);
  379. _update_buffer (_plotter->data->page);
  380. }
  381. void
  382. _pl_f_draw_ellipse_internal (R___(Plotter *_plotter) double x, double y, double rx, double ry, double angle, int subtype)
  383. {
  384. const char *format;
  385. double theta, mixing_angle;
  386. double ux, uy, vx, vy;
  387. double semi_axis_1_x, semi_axis_1_y;
  388. double semi_axis_2_x, semi_axis_2_y;
  389. double rx_device, ry_device, theta_device;
  390. double costheta, sintheta;
  391. double nominal_spacing;
  392. int line_style;
  393. double device_line_width;
  394. int quantized_device_line_width;
  395. /* inclination angle (radians), in user frame */
  396. theta = M_PI * angle / 180.0;
  397. costheta = cos (theta);
  398. sintheta = sin (theta);
  399. /* perform affine user->device coor transformation; (ux,uy) and (vx,vy)
  400. are forward images of the semiaxes, i.e. they are conjugate radial
  401. vectors in the device frame */
  402. ux = XDV(rx * costheta, rx * sintheta);
  403. uy = YDV(rx * costheta, rx * sintheta);
  404. vx = XDV(-ry * sintheta, ry * costheta);
  405. vy = YDV(-ry * sintheta, ry * costheta);
  406. /* angle by which the conjugate radial vectors should be mixed, in order
  407. to yield vectors along the major and minor axes in the device frame */
  408. mixing_angle = 0.5 * _xatan2 (2.0 * (ux * vx + uy * vy),
  409. ux * ux + uy * uy - vx * vx + vy * vy);
  410. /* semi-axis vectors in device coordinates */
  411. semi_axis_1_x = ux * cos(mixing_angle) + vx * sin(mixing_angle);
  412. semi_axis_1_y = uy * cos(mixing_angle) + vy * sin(mixing_angle);
  413. semi_axis_2_x = ux * cos(mixing_angle + M_PI_2)
  414. + vx * sin(mixing_angle + M_PI_2);
  415. semi_axis_2_y = uy * cos(mixing_angle + M_PI_2)
  416. + vy * sin(mixing_angle + M_PI_2);
  417. /* semi-axis lengths in device coordinates */
  418. rx_device = sqrt (semi_axis_1_x * semi_axis_1_x
  419. + semi_axis_1_y * semi_axis_1_y);
  420. ry_device = sqrt (semi_axis_2_x * semi_axis_2_x
  421. + semi_axis_2_y * semi_axis_2_y);
  422. /* angle of inclination of the first semi-axis, in device frame
  423. (note flipped-y convention) */
  424. theta_device = - _xatan2 (semi_axis_1_y, semi_axis_1_x);
  425. if (theta_device == 0.0)
  426. theta_device = 0.0; /* remove sign bit if any */
  427. if (subtype == SUBTYPE_CIRCLE &&
  428. IROUND (rx_device) != IROUND (ry_device))
  429. subtype = SUBTYPE_ELLIPSE;
  430. /* evaluate fig colors lazily, i.e. only when needed */
  431. _pl_f_set_pen_color (S___(_plotter));
  432. _pl_f_set_fill_color (S___(_plotter));
  433. /* xfig expresses the width of a line as an integer number of `Fig
  434. display units', so convert the width to those units */
  435. device_line_width =
  436. FIG_UNITS_TO_FIG_DISPLAY_UNITS(_plotter->drawstate->device_line_width);
  437. /* the interpretation of line width in a .fig file is now more
  438. complicated (see comments in _pl_f_paint_path() above), so this value
  439. must usually be incremented */
  440. if (device_line_width > 0.75)
  441. device_line_width += 1.0;
  442. /* round xfig's notion of the line width to the closest integer; but
  443. never round it down to 0 (which would yield an invisible line) if the
  444. line width in user coordinates is positive; instead, round it upward
  445. to 1 */
  446. quantized_device_line_width = IROUND(device_line_width);
  447. if (quantized_device_line_width == 0 && device_line_width > 0.0)
  448. quantized_device_line_width = 1;
  449. /* compute line style (type of dotting/dashing, spacing of dots/dashes) */
  450. _pl_f_compute_line_style (R___(_plotter) &line_style, &nominal_spacing);
  451. /* update xfig's `depth' attribute */
  452. if (_plotter->fig_drawing_depth > 0)
  453. (_plotter->fig_drawing_depth)--;
  454. if (subtype == SUBTYPE_CIRCLE)
  455. format = "#ELLIPSE [CIRCLE]\n%d %d %d %d %d %d %d %d %d %.3f %d %.3f %d %d %d %d %d %d %d %d\n";
  456. else
  457. format = "#ELLIPSE\n%d %d %d %d %d %d %d %d %d %.3f %d %.3f %d %d %d %d %d %d %d %d\n";
  458. sprintf(_plotter->data->page->point,
  459. format,
  460. 1, /* ellipse object */
  461. subtype, /* subtype, see above */
  462. line_style, /* Fig line style */
  463. /* thickness, in Fig display units */
  464. (_plotter->drawstate->pen_type == 0 ? 0 :
  465. quantized_device_line_width),
  466. _plotter->drawstate->fig_fgcolor, /* pen color */
  467. _plotter->drawstate->fig_fillcolor, /* fill color */
  468. _plotter->fig_drawing_depth, /* depth */
  469. 0, /* pen style, ignored */
  470. _plotter->drawstate->fig_fill_level, /* area fill */
  471. nominal_spacing, /* style val, in Fig display units (float) */
  472. 1, /* direction, always 1 */
  473. theta_device, /* inclination angle, in radians (float) */
  474. IROUND(XD(x,y)), /* center_x (not float, unlike arc) */
  475. IROUND(YD(x,y)), /* center_y (not float, unlike arc) */
  476. IROUND(rx_device), /* radius_x */
  477. IROUND(ry_device), /* radius_y */
  478. IROUND(XD(x,y)), /* start_x, 1st point entered */
  479. IROUND(YD(x,y)), /* start_y, 1st point entered */
  480. IROUND(XD(x,y) /* end_x, last point entered */
  481. + semi_axis_1_x + semi_axis_2_x),
  482. IROUND(YD(x,y) /* end_y, last point entered */
  483. + semi_axis_1_y + semi_axis_2_y)
  484. );
  485. _update_buffer(_plotter->data->page);
  486. }
  487. /* compute appropriate Fig line style, and also appropriate value for Fig's
  488. notion of `dash length/dot gap' (in Fig display units) */
  489. void
  490. _pl_f_compute_line_style (R___(Plotter *_plotter) int *style, double *spacing)
  491. {
  492. int fig_line_style;
  493. double fig_nominal_spacing;
  494. if (_plotter->drawstate->dash_array_in_effect
  495. && _plotter->drawstate->dash_array_len == 2
  496. && (_plotter->drawstate->dash_array[1]
  497. == _plotter->drawstate->dash_array[0]))
  498. /* special case of user-specified dashing (equal on/off lengths);
  499. we map this into Fig's `dashed' line type */
  500. {
  501. double min_sing_val, max_sing_val;
  502. /* Minimum singular value is the nominal device-frame line width
  503. divided by the actual user-frame line-width (see g_linewidth.c),
  504. so it's the user->device frame conversion factor. */
  505. _matrix_sing_vals (_plotter->drawstate->transform.m,
  506. &min_sing_val, &max_sing_val);
  507. /* desired cycle length in Fig display units */
  508. fig_nominal_spacing =
  509. FIG_UNITS_TO_FIG_DISPLAY_UNITS(min_sing_val * 2.0 * _plotter->drawstate->dash_array[0]);
  510. fig_line_style = FIG_L_DASHED;
  511. }
  512. else if (_plotter->drawstate->dash_array_in_effect
  513. && _plotter->drawstate->dash_array_len == 2
  514. && (_plotter->drawstate->dash_array[1]
  515. > (3 - FUZZ) * _plotter->drawstate->dash_array[0])
  516. && (_plotter->drawstate->dash_array[1]
  517. < (3 + FUZZ) * _plotter->drawstate->dash_array[0]))
  518. /* special case of user-specified dashing (gap length = 3 * dash length);
  519. we map this into Fig's `dotted' line type, since it agrees with
  520. libplot's convention for dashing `dotted' lines (see g_dash2.c) */
  521. {
  522. double min_sing_val, max_sing_val;
  523. _matrix_sing_vals (_plotter->drawstate->transform.m,
  524. &min_sing_val, &max_sing_val);
  525. /* desired cycle length in Fig display units */
  526. fig_nominal_spacing =
  527. FIG_UNITS_TO_FIG_DISPLAY_UNITS(min_sing_val * 4.0 * _plotter->drawstate->dash_array[0]);
  528. fig_line_style = FIG_L_DOTTED;
  529. }
  530. else
  531. /* canonical line type; retrieve dash array from database (in g_dash2.c) */
  532. {
  533. int i, num_dashes, cycle_length;
  534. const int *dash_array;
  535. double display_size_in_fig_units, min_dash_unit, dash_unit;
  536. num_dashes =
  537. _pl_g_line_styles[_plotter->drawstate->line_type].dash_array_len;
  538. dash_array = _pl_g_line_styles[_plotter->drawstate->line_type].dash_array;
  539. cycle_length = 0;
  540. for (i = 0; i < num_dashes; i++)
  541. cycle_length += dash_array[i];
  542. /* multiply cycle length of dash array by device-frame line width in
  543. Fig display units, with a floor on the latter (see comments at
  544. head of file) */
  545. display_size_in_fig_units = DMIN(_plotter->data->xmax - _plotter->data->xmin,
  546. /* flipped y */
  547. _plotter->data->ymin - _plotter->data->ymax);
  548. min_dash_unit = PL_MIN_DASH_UNIT_AS_FRACTION_OF_DISPLAY_SIZE
  549. * FIG_UNITS_TO_FIG_DISPLAY_UNITS(display_size_in_fig_units);
  550. dash_unit = DMAX(min_dash_unit,
  551. FIG_UNITS_TO_FIG_DISPLAY_UNITS(_plotter->drawstate->device_line_width));
  552. /* desired cycle length in Fig display units */
  553. fig_nominal_spacing = cycle_length * dash_unit;
  554. fig_line_style = _pl_f_fig_line_style[_plotter->drawstate->line_type];
  555. }
  556. /* compensate for Fig's (or fig2dev's) peculiarities; value stored in Fig
  557. output file isn't really the cycle length */
  558. switch (fig_line_style)
  559. {
  560. case FIG_L_SOLID:
  561. default: /* shouldn't happen */
  562. break;
  563. case FIG_L_DOTTED:
  564. fig_nominal_spacing -= 1.0;
  565. break;
  566. case FIG_L_DASHDOTTED:
  567. fig_nominal_spacing -= 1.0;
  568. /* fall thru */
  569. case FIG_L_DASHED:
  570. fig_nominal_spacing *= 0.5;
  571. break;
  572. case FIG_L_DASHDOUBLEDOTTED:
  573. fig_nominal_spacing -= 2.0;
  574. fig_nominal_spacing /= (1.9 + 1/3.0); /* really */
  575. break;
  576. case FIG_L_DASHTRIPLEDOTTED:
  577. fig_nominal_spacing -= 3.0;
  578. fig_nominal_spacing /= 2.4;
  579. break;
  580. }
  581. if (fig_nominal_spacing <= 1.0)
  582. fig_nominal_spacing = 1.0;
  583. /* pass back what Fig will need */
  584. *style = fig_line_style;
  585. *spacing = fig_nominal_spacing;
  586. }
  587. bool
  588. _pl_f_paint_paths (S___(Plotter *_plotter))
  589. {
  590. return false;
  591. }