PageRenderTime 32ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

/Libs/ImageMagick-6.7.4-Windows/wmf/src/ipa/fig/draw.h

https://bitbucket.org/ardalanaz/dava.framework
C Header | 637 lines | 436 code | 164 blank | 37 comment | 28 complexity | 4ce7d9569f2fbb31a2c3600c46a796f2 MD5 | raw file
  1. /* libwmf ("ipa/fig/draw.h"): library for wmf conversion
  2. Copyright (C) 2000 - various; see CREDITS, ChangeLog, and sources
  3. The libwmf Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Library General Public License as
  5. published by the Free Software Foundation; either version 2 of the
  6. License, or (at your option) any later version.
  7. The libwmf Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Library General Public License for more details.
  11. You should have received a copy of the GNU Library General Public
  12. License along with the libwmf Library; see the file COPYING. If not,
  13. write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  14. Boston, MA 02111-1307, USA. */
  15. static void wmf_fig_flood_interior (wmfAPI* API,wmfFlood_t* flood)
  16. { /* wmf_fig_t* ddata = WMF_FIG_GetData (API); */
  17. WMF_DEBUG (API,"~~~~~~~~wmf_[fig_]flood_interior");
  18. if (API->flags & WMF_OPT_IGNORE_NONFATAL)
  19. { WMF_DEBUG (API,"flood_interior unsupported.");
  20. }
  21. else
  22. { WMF_ERROR (API,"flood_interior unsupported.");
  23. API->err = wmf_E_Glitch;
  24. }
  25. }
  26. static void wmf_fig_flood_exterior (wmfAPI* API,wmfFlood_t* flood)
  27. { /* wmf_fig_t* ddata = WMF_FIG_GetData (API); */
  28. WMF_DEBUG (API,"~~~~~~~~wmf_[fig_]flood_exterior");
  29. if (API->flags & WMF_OPT_IGNORE_NONFATAL)
  30. { WMF_DEBUG (API,"flood_exterior unsupported.");
  31. }
  32. else
  33. { WMF_ERROR (API,"flood_exterior unsupported.");
  34. API->err = wmf_E_Glitch;
  35. }
  36. }
  37. static void wmf_fig_draw_pixel (wmfAPI* API,wmfDrawPixel_t* draw_pixel)
  38. { wmfBrush* set_brush = 0;
  39. wmfBrush brush;
  40. wmfPen* set_pen = 0;
  41. wmfPen pen;
  42. wmfDrawRectangle_t draw_rect;
  43. WMF_DEBUG (API,"~~~~~~~~wmf_[fig_]draw_pixel");
  44. /* Going to redirect this to wmf_fig_draw_rectangle
  45. */
  46. draw_rect.dc = draw_pixel->dc;
  47. draw_rect.width = 0;
  48. draw_rect.height = 0;
  49. /* brush setup
  50. */
  51. set_brush = WMF_DC_BRUSH (draw_rect.dc);
  52. brush = (*set_brush);
  53. WMF_BRUSH_SET_STYLE (&brush,BS_SOLID);
  54. WMF_BRUSH_SET_COLOR (&brush,&(draw_pixel->color));
  55. WMF_DC_SET_BRUSH (draw_rect.dc,&brush);
  56. /* pen setup
  57. */
  58. set_pen = WMF_DC_PEN (draw_rect.dc);
  59. pen = (*set_pen);
  60. WMF_PEN_SET_STYLE (&pen,PS_NULL);
  61. WMF_DC_SET_PEN (draw_rect.dc,&pen);
  62. draw_rect.TL.x = (float) draw_pixel->pt.x;
  63. draw_rect.TL.y = (float) draw_pixel->pt.y;
  64. draw_rect.BR.x = (float) (draw_pixel->pt.x + draw_pixel->pixel_width );
  65. draw_rect.BR.y = (float) (draw_pixel->pt.y + draw_pixel->pixel_height);
  66. wmf_fig_draw_rectangle (API,&draw_rect);
  67. WMF_DC_SET_BRUSH (draw_rect.dc,set_brush); /* Soon to be redundant ?? */
  68. WMF_DC_SET_PEN (draw_rect.dc,set_pen); /* Soon to be redundant ?? */
  69. }
  70. static void wmf_fig_draw_pie (wmfAPI* API,wmfDrawArc_t* draw_arc)
  71. { wmf_fig_t* ddata = WMF_FIG_GetData (API);
  72. wmfStream* out = ddata->out;
  73. WMF_DEBUG (API,"~~~~~~~~wmf_[fig_]draw_pie");
  74. wmf_stream_printf (API,out,"# wmf_[fig_]draw_pie\n");
  75. fig_draw_arc (API,draw_arc,0);
  76. wmf_stream_printf (API,out,"# draw_pie not impl\n");
  77. }
  78. static void wmf_fig_draw_chord (wmfAPI* API,wmfDrawArc_t* draw_arc)
  79. { wmf_fig_t* ddata = WMF_FIG_GetData (API);
  80. wmfStream* out = ddata->out;
  81. WMF_DEBUG (API,"~~~~~~~~wmf_[fig_]draw_chord");
  82. wmf_stream_printf (API,out,"# draw_chord not impl\n");
  83. }
  84. static void wmf_fig_draw_arc (wmfAPI* API,wmfDrawArc_t* draw_arc)
  85. { wmf_fig_t* ddata = WMF_FIG_GetData (API);
  86. wmfStream* out = ddata->out;
  87. WMF_DEBUG (API,"~~~~~~~~wmf_[fig_]draw_arc");
  88. wmf_stream_printf (API,out,"# wmf_[fig_]draw_arc\n");
  89. fig_draw_arc(API, draw_arc, 1);
  90. wmf_stream_printf (API,out,"# end draw_arc\n");
  91. }
  92. static void fig_draw_arc (wmfAPI* API,wmfDrawArc_t* draw_arc,int sub_type)
  93. { wmf_fig_t* ddata = WMF_FIG_GetData (API);
  94. wmfStream* out = ddata->out;
  95. figDC fig;
  96. figPoint TL;
  97. figPoint BR;
  98. int direction;
  99. int Ox;
  100. int Oy;
  101. float start_x;
  102. float start_y;
  103. float end_x;
  104. float end_y;
  105. float mid_x;
  106. float mid_y;
  107. float rad;
  108. float start;
  109. float end;
  110. float mid;
  111. WMF_DEBUG (API,"~~~~~~~~fig_draw_arc");
  112. wmf_stream_printf (API,out,"# fig_draw_arc\n");
  113. fig_set_style (API,draw_arc->dc,&fig);
  114. ddata->depth -= ddata->ddec;
  115. direction = 0;
  116. start_x = (float) draw_arc->start.x;
  117. start_y = (float) draw_arc->start.y;
  118. end_x = (float) draw_arc->end.x;
  119. end_y = (float) draw_arc->end.y;
  120. TL = fig_translate (API,draw_arc->TL);
  121. BR = fig_translate (API,draw_arc->BR);
  122. /* origin: */
  123. Ox = (BR.x + TL.x + 1) / 2;
  124. Oy = (BR.y + TL.y + 1) / 2;
  125. /* long axis */
  126. rad = ((float) (BR.x - TL.x)) / 2;
  127. /*
  128. start_y = sqrt(rad * rad - start_x * start_x);
  129. if (draw_arc->start.y < 0) start_y = - start_y;
  130. end_y = sqrt(rad * rad - end_x * end_x);
  131. if (draw_arc->end.y < 0) end_y = - end_y;
  132. */
  133. start = atan2 (start_y,start_x);
  134. end = atan2 ( end_y, end_x);
  135. /* rad = sqrt(start_x*start_x + start_y*start_y); */
  136. /* Construct middle point: */
  137. if (end < start) end += M_2PI;
  138. mid = 0.5 * (start + end);
  139. mid_x = Ox + (rad * cos (mid));
  140. mid_y = Oy + (rad * sin (mid));
  141. /* Shift to origin: */
  142. start_x = Ox + start_x;
  143. start_y = Oy + start_y;
  144. end_x = Ox + end_x;
  145. end_y = Oy + end_y;
  146. wmf_stream_printf (API,out,
  147. "%d %d %d %d %d %d %d %d %d %f %d %d %d %d %f %f %d %d %d %d %d %d\n",
  148. O_ARC,
  149. sub_type,
  150. fig.line_style,
  151. fig.thickness,
  152. fig.pen_color,
  153. fig.fill_color,
  154. ddata->depth,
  155. fig.pen_style,
  156. fig.area_fill,
  157. fig.style_val,
  158. fig.cap_style,
  159. direction,
  160. fig.forward_arrow,
  161. fig.backward_arrow,
  162. (float) Ox,
  163. (float) Oy,
  164. (int) start_x,
  165. (int) start_y,
  166. (int) mid_x,
  167. (int) mid_y,
  168. (int) end_x,
  169. (int) end_y);
  170. }
  171. static void wmf_fig_draw_ellipse (wmfAPI* API,wmfDrawArc_t* draw_arc)
  172. { wmf_fig_t* ddata = WMF_FIG_GetData (API);
  173. wmfStream* out = ddata->out;
  174. figDC fig;
  175. figPoint TL;
  176. figPoint BR;
  177. float angle;
  178. int sub_type;
  179. int direction;
  180. int Ox;
  181. int Oy;
  182. int a;
  183. int b;
  184. WMF_DEBUG (API,"~~~~~~~~wmf_[fig_]draw_ellipse");
  185. wmf_stream_printf (API,out,"# wmf_[fig_]draw_ellipse\n");
  186. fig_set_style (API,draw_arc->dc,&fig);
  187. sub_type = 1;
  188. ddata->depth -= ddata->ddec;
  189. direction = 1;
  190. angle = 0.0;
  191. TL = fig_translate (API,draw_arc->TL);
  192. BR = fig_translate (API,draw_arc->BR);
  193. /* origin of ellipse */
  194. Ox = (BR.x + TL.x + 1) / 2;
  195. Oy = (BR.y + TL.y + 1) / 2;
  196. /* axes of ellipse */
  197. a = (BR.x - TL.x + 1) / 2;
  198. b = (BR.y - TL.y + 1) / 2;
  199. wmf_stream_printf (API,out,
  200. "%d %d %d %d %d %d %d %d %d %f %d %f %d %d %d %d %d %d %d %d\n",
  201. O_ELLIPSE,
  202. sub_type,
  203. fig.line_style,
  204. fig.thickness,
  205. fig.pen_color,
  206. fig.fill_color,
  207. ddata->depth,
  208. fig.pen_style,
  209. fig.area_fill,
  210. fig.style_val,
  211. direction,
  212. angle,
  213. Ox,
  214. Oy,
  215. a,
  216. b,
  217. Ox,
  218. Oy,
  219. (Ox + a),
  220. (Oy + b));
  221. wmf_stream_printf (API,out,"# end draw_ellipse\n");
  222. }
  223. static void wmf_fig_draw_line (wmfAPI* API,wmfDrawLine_t* draw_line)
  224. { wmf_fig_t* ddata = WMF_FIG_GetData (API);
  225. wmfStream* out = ddata->out;
  226. figDC fig;
  227. figPoint from;
  228. figPoint to;
  229. int npoints;
  230. WMF_DEBUG (API,"~~~~~~~~wmf_[fig_]draw_line");
  231. if (out == 0) return;
  232. if (TO_DRAW (draw_line))
  233. { wmf_stream_printf (API,out,"# wmf_[fig_]draw_line\n");
  234. fig_set_style (API,draw_line->dc,&fig);
  235. ddata->depth -= ddata->ddec;
  236. npoints = 2;
  237. wmf_stream_printf (API,out,
  238. "%d %d %d %d %d %d %d %d %d %f %d %d %d %d %d %d\n",
  239. O_POLYLINE,
  240. T_POLYLINE,
  241. fig.line_style,
  242. fig.thickness,
  243. fig.pen_color,
  244. fig.fill_color,
  245. ddata->depth,
  246. fig.pen_style,
  247. fig.area_fill,
  248. fig.style_val,
  249. fig.join_style,
  250. fig.cap_style,
  251. fig.radius,
  252. fig.forward_arrow,
  253. fig.backward_arrow,
  254. npoints);
  255. from = fig_translate (API,draw_line->from);
  256. to = fig_translate (API,draw_line->to );
  257. wmf_stream_printf (API,out,
  258. "%d %d\n%d %d\n",
  259. from.x,
  260. from.y,
  261. to.x,
  262. to.y);
  263. wmf_stream_printf (API,out,"# end draw_line\n");
  264. }
  265. }
  266. static void wmf_fig_poly_line (wmfAPI* API,wmfPolyLine_t* poly_line)
  267. { wmf_fig_t* ddata = WMF_FIG_GetData (API);
  268. wmfStream* out = ddata->out;
  269. wmfPolyLine_t sub_line;
  270. figDC fig;
  271. figPoint pt;
  272. U16 i;
  273. U16 sub_length;
  274. U16 sub_count;
  275. WMF_DEBUG (API,"~~~~~~~~wmf_[fig_]poly_line");
  276. if (out == 0) return;
  277. if (poly_line->count > 500)
  278. { sub_length = poly_line->count / (1 + poly_line->count / 500);
  279. sub_count = 0;
  280. sub_line.dc = poly_line->dc;
  281. sub_line.pt = poly_line->pt;
  282. while (poly_line->count > sub_count + 1)
  283. { sub_line.count = MIN (sub_length,poly_line->count - sub_count);
  284. wmf_fig_poly_line (API,&sub_line);
  285. sub_line.pt += sub_line.count - 1;
  286. sub_count += sub_line.count - 1;
  287. }
  288. }
  289. else if ((poly_line->count > 1) && TO_DRAW (poly_line))
  290. { fig_set_style (API,poly_line->dc,&fig); /* fjf - the logic may have change here ?? */
  291. fig.area_fill = -1; /* override fill settings */
  292. ddata->depth -= ddata->ddec;
  293. wmf_stream_printf (API,out,"# wmf_[fig_]poly_line\n");
  294. wmf_stream_printf (API,out,
  295. "%d %d %d %d %d %d %d %d %d %f %d %d %d %d %d %d\n",
  296. O_POLYLINE,
  297. T_POLYLINE,
  298. fig.line_style,
  299. fig.thickness,
  300. fig.pen_color,
  301. fig.fill_color,
  302. ddata->depth,
  303. fig.pen_style,
  304. fig.area_fill,
  305. fig.style_val,
  306. fig.join_style,
  307. fig.cap_style,
  308. fig.radius,
  309. fig.forward_arrow,
  310. fig.backward_arrow,
  311. poly_line->count);
  312. /* Output co-ordinate pairs: */
  313. for (i = 0; i < poly_line->count; i++)
  314. { pt = fig_translate (API,poly_line->pt[poly_line->count-1-i]);
  315. wmf_stream_printf (API,out,"%d %d\n",pt.x,pt.y);
  316. }
  317. wmf_stream_printf (API,out,"# end poly_line\n");
  318. }
  319. }
  320. static void wmf_fig_draw_polygon (wmfAPI* API,wmfPolyLine_t* poly_line)
  321. { wmf_fig_t* ddata = WMF_FIG_GetData (API);
  322. wmfStream* out = ddata->out;
  323. figDC fig;
  324. figPoint pt;
  325. U16 i;
  326. WMF_DEBUG (API,"~~~~~~~~wmf_[fig_]draw_polygon");
  327. if (out == 0) return;
  328. if (poly_line->count > 500)
  329. { if (API->flags & WMF_OPT_IGNORE_NONFATAL)
  330. { WMF_DEBUG (API,"Too many points on polygon!");
  331. }
  332. else
  333. { WMF_ERROR (API,"Too many points on polygon!");
  334. API->err = wmf_E_Glitch;
  335. }
  336. }
  337. else if (poly_line->count > 2)
  338. { fig_set_style (API,poly_line->dc,&fig);
  339. ddata->depth -= ddata->ddec;
  340. if (TO_FILL (poly_line))
  341. { wmf_stream_printf (API,out,"# wmf_[fig_]draw_polygon\n");
  342. wmf_stream_printf (API,out,
  343. "%d %d %d %d %d %d %d %d %d %f %d %d %d %d %d %d\n",
  344. O_POLYLINE,
  345. T_POLYGON,
  346. fig.line_style,
  347. fig.thickness,
  348. fig.pen_color,
  349. fig.fill_color,
  350. ddata->depth,
  351. fig.pen_style,
  352. fig.area_fill,
  353. fig.style_val,
  354. fig.join_style,
  355. fig.cap_style,
  356. fig.radius,
  357. fig.forward_arrow,
  358. fig.backward_arrow,
  359. poly_line->count + 1);
  360. for (i = 0; i < poly_line->count; i++)
  361. { pt = fig_translate (API,poly_line->pt[i]);
  362. wmf_stream_printf (API,out,"%d %d\n",pt.x,pt.y);
  363. }
  364. pt = fig_translate (API,poly_line->pt[0]);
  365. wmf_stream_printf (API,out,"%d %d\n",pt.x,pt.y);
  366. wmf_stream_printf (API,out,"# end draw_polygon\n");
  367. }
  368. if (TO_DRAW (poly_line))
  369. { fig.area_fill = -1;
  370. fig.thickness++;
  371. wmf_stream_printf (API,out,"# wmf_[fig_]draw_polygon\n");
  372. wmf_stream_printf (API,out,
  373. "%d %d %d %d %d %d %d %d %d %f %d %d %d %d %d %d\n",
  374. O_POLYLINE,
  375. T_POLYGON,
  376. fig.line_style,
  377. fig.thickness,
  378. fig.pen_color,
  379. fig.fill_color,
  380. ddata->depth,
  381. fig.pen_style,
  382. fig.area_fill,
  383. fig.style_val,
  384. fig.join_style,
  385. fig.cap_style,
  386. fig.radius,
  387. fig.forward_arrow,
  388. fig.backward_arrow,
  389. poly_line->count + 1);
  390. for (i = 0; i < poly_line->count; i++)
  391. { pt = fig_translate (API,poly_line->pt[poly_line->count-1-i]);
  392. wmf_stream_printf (API,out,"%d %d\n",pt.x,pt.y);
  393. }
  394. pt = fig_translate (API,poly_line->pt[poly_line->count-1]);
  395. wmf_stream_printf (API,out,"%d %d\n",pt.x,pt.y);
  396. wmf_stream_printf (API,out,"# end draw_polygon\n");
  397. }
  398. }
  399. }
  400. static void wmf_fig_draw_rectangle (wmfAPI* API,wmfDrawRectangle_t* draw_rect)
  401. { wmf_fig_t* ddata = WMF_FIG_GetData (API);
  402. wmfStream* out = ddata->out;
  403. figDC fig;
  404. figPoint TL;
  405. figPoint BR;
  406. WMF_DEBUG (API,"~~~~~~~~wmf_[fig_]draw_rectangle");
  407. if (out == 0) return;
  408. fig_set_style (API,draw_rect->dc,&fig);
  409. ddata->depth -= ddata->ddec;
  410. TL = fig_translate (API,draw_rect->TL);
  411. BR = fig_translate (API,draw_rect->BR);
  412. if (TO_FILL (draw_rect))
  413. { wmf_stream_printf (API,out,"# wmf_[fig_]draw_rectangle\n");
  414. wmf_stream_printf (API,out,
  415. "%d %d %d %d %d %d %d %d %d %f %d %d %d %d %d %d\n",
  416. O_POLYLINE,
  417. T_BOX,
  418. fig.line_style,
  419. fig.thickness,
  420. fig.pen_color,
  421. fig.fill_color,
  422. ddata->depth,
  423. fig.pen_style,
  424. fig.area_fill,
  425. fig.style_val,
  426. fig.join_style,
  427. fig.cap_style,
  428. fig.radius,
  429. fig.forward_arrow,
  430. fig.backward_arrow,
  431. 5);
  432. wmf_stream_printf (API,out,"%d %d\n%d %d\n%d %d\n%d %d\n%d %d\n",
  433. TL.x,TL.y,
  434. TL.x,BR.y,
  435. BR.x,BR.y,
  436. BR.x,TL.y,
  437. TL.x,TL.y);
  438. wmf_stream_printf (API,out,"# end draw_rectangle\n");
  439. }
  440. if (TO_DRAW (draw_rect))
  441. { fig.area_fill = -1;
  442. fig.thickness++;
  443. wmf_stream_printf (API,out,"# wmf_[fig_]draw_rectangle\n");
  444. wmf_stream_printf (API,out,
  445. "%d %d %d %d %d %d %d %d %d %f %d %d %d %d %d %d\n",
  446. O_POLYLINE,
  447. T_BOX,
  448. fig.line_style,
  449. fig.thickness,
  450. fig.pen_color,
  451. fig.fill_color,
  452. ddata->depth,
  453. fig.pen_style,
  454. fig.area_fill,
  455. fig.style_val,
  456. fig.join_style,
  457. fig.cap_style,
  458. fig.radius,
  459. fig.forward_arrow,
  460. fig.backward_arrow,
  461. 5);
  462. wmf_stream_printf (API,out,"%d %d\n%d %d\n%d %d\n%d %d\n %d %d\n",
  463. TL.x,TL.y,
  464. TL.x,BR.y,
  465. BR.x,BR.y,
  466. BR.x,TL.y,
  467. TL.x,TL.y);
  468. wmf_stream_printf (API,out,"# end draw_rectangle\n");
  469. }
  470. }