draw_scale.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681
  1. /*
  2. * draw_scale() places a scalebar somewhere in the display frame
  3. */
  4. #include <stdio.h>
  5. #include <string.h>
  6. #include <stdlib.h>
  7. #include <math.h>
  8. #include <grass/gis.h>
  9. #include <grass/display.h>
  10. #include <grass/symbol.h>
  11. #include <grass/colors.h>
  12. #include <grass/glocale.h>
  13. #include "options.h"
  14. #define NUMSCALES 16
  15. /* declare variables */
  16. static const struct scale
  17. {
  18. char *symbol;
  19. double size;
  20. double limit;
  21. } all_scales[2][NUMSCALES] = {
  22. {
  23. /* meters */
  24. {
  25. "", 0., 2.}, {
  26. "1 m", 1., 7.}, {
  27. "5 m", 5., 20.}, {
  28. "10 m", 10., 70.}, {
  29. "50 m", 50., 200.}, {
  30. "100 m", 100., 700.}, {
  31. "500 m", 500., 2000.}, {
  32. "1 km", 1000., 7000.}, {
  33. "5 km", 5000., 20000.}, {
  34. "10 km", 10000., 70000.}, {
  35. "50 km", 50000., 200000.}, {
  36. "100 km", 100000., 700000.}, {
  37. "500 km", 500000., 2000000.}, {
  38. "1000 km", 1000000., 7000000.}, {
  39. "5000 km", 5000000., 20000000.}, {
  40. "10000 km", 10000000., 70000000.}
  41. }, {
  42. /* feet/miles */
  43. {
  44. "", 0.000, 1.}, {
  45. "1 ft", 0.305, 2.}, {
  46. "5 ft", 1.524, 10.}, {
  47. "10 ft", 3.048, 20.}, {
  48. "50 ft", 15.240, 100.}, {
  49. "100 ft", 30.480, 200.}, {
  50. "500 ft", 152.400, 1000.}, {
  51. "1000 ft", 304.800, 2000.}, {
  52. "1 mi", 1609.344, 10000.}, {
  53. "5 mi", 8046.720, 20000.}, {
  54. "10 mi", 16093.440, 100000.}, {
  55. "50 mi", 80467.200, 200000.}, {
  56. "100 mi", 160934.400, 1000000.}, {
  57. "500 mi", 804672.000, 2000000.}, {
  58. "1000 mi", 1609344.000, 10000000.}, {
  59. "5000 mi", 8046720.000, 20000000.},}
  60. };
  61. int draw_scale(double east, double north, int length, int seg, int units,
  62. char *label_cstm, int style, int text_posn, double width_scale, double fontsize)
  63. {
  64. double meters;
  65. double line_len;
  66. int i, incr;
  67. double x_pos, y_pos;
  68. double t, b, l, r;
  69. double pt, pb, pl, pr; /* background box */
  70. double tt, tb, tl, tr; /* text box */
  71. double xarr[5], yarr[5];
  72. double seg_len;
  73. const struct scale *scales = all_scales[use_feet];
  74. SYMBOL *Symb;
  75. RGBA_Color *line_color, *fill_color;
  76. int R, G, B;
  77. double x0, y0;
  78. double symbol_size;
  79. char *label;
  80. double size;
  81. double xspace_bf_N, x_pos_start, xspace_around_line, xsize_N;
  82. double ysize, ysize_solid, ysize_checker, ysize_ticks;
  83. /* Establish text size */
  84. if (fontsize > 0)
  85. D_text_size(fontsize, fontsize);
  86. D_setup_unity(0);
  87. D_get_src(&t, &b, &l, &r);
  88. x_pos = l + (int)(east * (r - l) / 100.);
  89. y_pos = t + (int)((100. - north) * (b - t) / 100.);
  90. D_setup(0); /* back to regular coordinate settings */
  91. meters = D_get_u_east() - D_get_u_west();
  92. meters *= G_database_units_to_meters_factor();
  93. /* find the right scale only if length is not given by user(length=0) */
  94. if (length == 0) {
  95. for (incr = 0; incr < NUMSCALES; incr++) {
  96. if (meters <= scales[incr].limit)
  97. break;
  98. }
  99. /* region is too small to draw anything. ever reached? */
  100. if (!incr)
  101. return -1;
  102. /* beyond the maximum just make the longest scale narrower */
  103. if (incr >= NUMSCALES)
  104. incr = NUMSCALES - 1;
  105. label = scales[incr].symbol;
  106. size = scales[incr].size;
  107. }
  108. /* length given by user */
  109. else {
  110. label = G_malloc(GNAME_MAX);
  111. size = length / G_meters_to_units_factor(units);
  112. sprintf(label, "%d %s", length, label_cstm);
  113. }
  114. line_len = D_get_u_to_d_xconv() * size
  115. / G_database_units_to_meters_factor();
  116. seg_len = line_len / seg;
  117. /* work around round off */
  118. line_len = seg_len * seg;
  119. D_setup_unity(0);
  120. /* setup size variables */
  121. xspace_bf_N = 5 * width_scale;
  122. xspace_around_line = 10 * width_scale;
  123. xsize_N = 10 * width_scale;
  124. x_pos_start = x_pos + (north_arrow ? (xspace_bf_N + xsize_N + xspace_around_line) : xspace_around_line);
  125. ysize = 30 * width_scale;
  126. ysize_solid = 8 * width_scale;
  127. ysize_checker = 6 * width_scale;
  128. ysize_ticks = 20 * width_scale; /* the length of the edge tick */
  129. if (do_background) {
  130. /* Blank out area with background color */
  131. D_get_text_box(label, &tt, &tb, &tl, &tr);
  132. pl = x_pos + 0;
  133. pr = x_pos + line_len + 2 * xspace_around_line +
  134. (north_arrow ? xspace_bf_N + xsize_N : 0);
  135. if (text_posn == TEXT_OVER) {
  136. pt = y_pos + tb - 5 * width_scale;
  137. pb = y_pos + ysize;
  138. if (style == STYLE_TICKS_DOWN)
  139. pb += 12 * width_scale;
  140. }
  141. if (text_posn == TEXT_UNDER) {
  142. pt = y_pos + 0;
  143. pb = y_pos + ysize - tb + 5 * width_scale;
  144. if (style == STYLE_TICKS_UP)
  145. pt -= 12 * width_scale;
  146. }
  147. else if (text_posn == TEXT_RIGHT) {
  148. pr = pr + tr + xspace_around_line;
  149. pt = y_pos + 0;
  150. pb = y_pos + ysize;
  151. if (style == STYLE_TICKS_UP) {
  152. pt -= 12 * width_scale;
  153. pb -= 6 * width_scale;
  154. }
  155. if (style == STYLE_TICKS_DOWN) {
  156. pt += 4 * width_scale;
  157. pb += 12 * width_scale;
  158. }
  159. }
  160. else if (text_posn == TEXT_LEFT) {
  161. pl = x_pos - tr - 13 * width_scale;
  162. pt = y_pos + 0;
  163. pb = y_pos + ysize;
  164. if (style == STYLE_TICKS_UP) {
  165. pt -= 12 * width_scale;
  166. pb -= 4 * width_scale;
  167. }
  168. if (style == STYLE_TICKS_DOWN) {
  169. pt += 3 * width_scale;
  170. pb += 11 * width_scale;
  171. }
  172. }
  173. if (fontsize < 0) { /* no text */
  174. pl = x_pos + 0;
  175. pr = x_pos + line_len + 2 * xspace_around_line +
  176. (north_arrow ? xspace_bf_N + xsize_N : 0);
  177. switch (style) {
  178. case STYLE_CLASSIC_BAR:
  179. case STYLE_THIN_WITH_ENDS:
  180. case STYLE_PART_CHECKER:
  181. case STYLE_FULL_CHECKER:
  182. case STYLE_MIXED_CHECKER:
  183. case STYLE_TAIL_CHECKER:
  184. case STYLE_SOLID_BAR:
  185. case STYLE_HOLLOW_BAR:
  186. case STYLE_TICKS_BOTH:
  187. case STYLE_ARROW_ENDS:
  188. pt = y_pos + 0;
  189. pb = y_pos + ysize;
  190. break;
  191. case STYLE_TICKS_UP:
  192. pt = y_pos - 12 * width_scale;
  193. pb = y_pos + 25 * width_scale;
  194. break;
  195. case STYLE_TICKS_DOWN:
  196. pt = y_pos + 3 * width_scale;
  197. pb = y_pos + 40 * width_scale;
  198. break;
  199. default:
  200. G_fatal_error(_("Programmer error"));
  201. }
  202. }
  203. /* keep it on the screen */
  204. if (pt < t)
  205. pt = t;
  206. if (pb > b)
  207. pb = b;
  208. if (pl < l)
  209. pl = l;
  210. if (pr > r)
  211. pr = r;
  212. D_use_color(bg_color);
  213. D_box_abs(pl, pt, pr, pb);
  214. }
  215. /* Draw the small N with an arrow through it on the left side for the classic barscale styles */
  216. D_use_color(fg_color);
  217. if (north_arrow) {
  218. D_begin();
  219. D_move_abs(x_pos + xspace_bf_N, y_pos + 2 * ysize / 3);
  220. D_cont_rel(0, -10 * width_scale);
  221. D_cont_rel(10 * width_scale, 10 * width_scale);
  222. D_cont_rel(0, -10 * width_scale);
  223. D_move_rel(-5 * width_scale, 14 * width_scale);
  224. D_cont_rel(0, -17 * width_scale);
  225. D_cont_rel(-2.5 * width_scale, -0);
  226. D_cont_rel(2.5 * width_scale, -4 * width_scale);
  227. D_cont_rel(2.5 * width_scale, 4 * width_scale);
  228. D_cont_rel(-2.5 * width_scale, -0);
  229. D_close();
  230. D_end();
  231. D_stroke();
  232. }
  233. /* The end points of the center-line are (x_pos + 25, y_pos + 15)
  234. and (x_pos + 25 + line_len, y_pos + 15) */
  235. if (style == STYLE_CLASSIC_BAR) {
  236. D_begin();
  237. D_move_abs(x_pos_start, y_pos + ysize / 2 + ysize_checker / 2);
  238. /* actual width is line_len-1+1=line_len */
  239. D_cont_rel(line_len - 1, 0);
  240. D_cont_rel(0, -ysize_checker);
  241. D_cont_rel(-line_len + 1, 0);
  242. D_cont_rel(0, ysize_checker);
  243. D_end();
  244. D_close();
  245. D_stroke();
  246. for (i = 1; i <= seg; i += 2) {
  247. /* width is seg_len and height is 5 */
  248. D_box_rel(seg_len, -ysize_checker);
  249. D_pos_rel(seg_len * 2, 0);
  250. }
  251. }
  252. else if (style == STYLE_THIN_WITH_ENDS) {
  253. /* draw simple line scale */
  254. D_begin();
  255. D_move_abs(x_pos_start, y_pos + (ysize - ysize_ticks) / 2);
  256. D_cont_abs(x_pos_start, y_pos + ysize - (ysize - ysize_ticks) / 2);
  257. D_move_abs(x_pos_start, y_pos + ysize / 2);
  258. D_cont_abs(x_pos_start + line_len, y_pos + ysize / 2);
  259. D_move_abs(x_pos_start + line_len, y_pos + (ysize - ysize_ticks) / 2);
  260. D_cont_abs(x_pos_start + line_len, y_pos + ysize - (ysize - ysize_ticks) / 2);
  261. D_close();
  262. D_end(); /* no-op? */
  263. }
  264. else if (style == STYLE_SOLID_BAR) {
  265. /* draw simple solid-bar scale */
  266. xarr[0] = 0;
  267. yarr[0] = ysize_solid;
  268. xarr[1] = line_len;
  269. yarr[1] = 0;
  270. xarr[2] = 0;
  271. yarr[2] = -ysize_solid;
  272. xarr[3] = -line_len;
  273. yarr[3] = 0;
  274. xarr[4] = 0;
  275. yarr[4] = ysize_solid;
  276. D_move_abs(x_pos_start, y_pos + ysize / 2 - ysize_solid / 2);
  277. D_polygon_rel(xarr, yarr, 5);
  278. }
  279. else if (style == STYLE_HOLLOW_BAR) {
  280. /* draw hollow-bar scale */
  281. D_use_color(fg_color);
  282. D_begin();
  283. D_move_abs(x_pos_start, y_pos + ysize / 2 - ysize_solid / 2);
  284. D_cont_rel(0, ysize_solid);
  285. D_cont_rel(line_len, 0);
  286. D_cont_rel(0, -ysize_solid);
  287. D_cont_rel(-line_len, 0);
  288. D_cont_rel(0, ysize_solid);
  289. D_close();
  290. D_end(); /* no-op? */
  291. }
  292. else if (style == STYLE_FULL_CHECKER) {
  293. D_begin();
  294. D_move_abs(x_pos_start, y_pos + ysize / 2 + ysize_checker);
  295. /* actual width is line_len-1+1=line_len and height is 7+1=8 */
  296. D_cont_rel(line_len, 0);
  297. D_cont_rel(0, -2 * ysize_checker);
  298. D_cont_rel(-line_len, 0);
  299. D_cont_rel(0, +2 * ysize_checker);
  300. D_close();
  301. D_end(); /* no-op? */
  302. D_stroke();
  303. D_pos_rel(0, -ysize_checker);
  304. for (i = 1; i <= seg; i++) {
  305. xarr[0] = 0;
  306. yarr[0] = 0;
  307. xarr[1] = seg_len;
  308. yarr[1] = 0;
  309. xarr[2] = 0;
  310. yarr[2] = (i % 2 ? -ysize_checker : ysize_checker);
  311. xarr[3] = -seg_len;
  312. yarr[3] = 0;
  313. xarr[4] = 0;
  314. yarr[4] = (i % 2 ? ysize_checker : -ysize_checker);
  315. /* width is seg_len and height is 6 */
  316. D_polygon_rel(xarr, yarr, 5);
  317. D_pos_rel(seg_len, 0);
  318. }
  319. }
  320. else if (style == STYLE_PART_CHECKER) {
  321. D_begin();
  322. D_move_abs(x_pos_start, y_pos + ysize / 2 + ysize_checker);
  323. /* actual width is line_len-1+1=line_len and height is 7+1=8 */
  324. D_cont_rel(line_len, 0);
  325. D_cont_rel(0, -2 * ysize_checker);
  326. D_cont_rel(-line_len, 0);
  327. D_cont_rel(0, +2 * ysize_checker);
  328. D_close();
  329. D_end(); /* no-op? */
  330. D_stroke();
  331. D_pos_rel(0, -ysize_checker);
  332. for (i = 1; i <= seg; i++) {
  333. if (i <= (seg == 5 ? 2 : 4)) {
  334. xarr[0] = 0;
  335. yarr[0] = 0;
  336. xarr[1] = seg_len / 2.;
  337. yarr[1] = 0;
  338. xarr[2] = 0;
  339. yarr[2] = -ysize_checker;
  340. xarr[3] = -seg_len / 2.;
  341. yarr[3] = 0;
  342. xarr[4] = 0;
  343. yarr[4] = ysize_checker;
  344. D_polygon_rel(xarr, yarr, 5);
  345. D_pos_rel(seg_len / 2., 0);
  346. xarr[0] = 0;
  347. yarr[0] = 0;
  348. xarr[1] = seg_len / 2.;
  349. yarr[1] = 0;
  350. xarr[2] = 0;
  351. yarr[2] = ysize_checker;
  352. xarr[3] = -seg_len / 2.;
  353. yarr[3] = 0;
  354. xarr[4] = 0;
  355. yarr[4] = -ysize_checker;
  356. D_polygon_rel(xarr, yarr, 5);
  357. D_pos_rel(seg_len / 2., 0);
  358. }
  359. else {
  360. xarr[0] = 0;
  361. yarr[0] = 0;
  362. xarr[1] = seg_len;
  363. yarr[1] = 0;
  364. xarr[2] = 0;
  365. yarr[2] = (i % 2 ? -ysize_checker : ysize_checker);
  366. xarr[3] = -seg_len;
  367. yarr[3] = 0;
  368. xarr[4] = 0;
  369. yarr[4] = (i % 2 ? ysize_checker : -ysize_checker);
  370. /* width is seg_len and height is 6 */
  371. D_polygon_rel(xarr, yarr, 5);
  372. D_pos_rel(seg_len, 0);
  373. }
  374. }
  375. }
  376. else if (style == STYLE_MIXED_CHECKER) {
  377. D_begin();
  378. D_move_abs(x_pos_start, y_pos + ysize / 2 + ysize_checker);
  379. /* actual width is line_len-1+1=line_len and height is 7+1=8 */
  380. D_cont_rel(line_len, 0);
  381. D_cont_rel(0, -2 * ysize_checker);
  382. D_cont_rel(-line_len, 0);
  383. D_cont_rel(0, +2 * ysize_checker);
  384. /* horizontal line across the middle to separate white from white */
  385. D_move_abs(x_pos_start, y_pos + ysize / 2);
  386. D_cont_rel(line_len, 0);
  387. D_end(); /* no-op? */
  388. D_close();
  389. D_stroke();
  390. D_move_abs(x_pos_start, y_pos + ysize / 2);
  391. for (i = 1; i <= seg; i++) {
  392. if (i <= (seg == 5 ? 2 : 6)) {
  393. if (i % 2 == 0) {
  394. xarr[0] = 0;
  395. yarr[0] = 0;
  396. xarr[1] = seg_len;
  397. yarr[1] = 0;
  398. xarr[2] = 0;
  399. yarr[2] = -ysize_checker;
  400. xarr[3] = -seg_len;
  401. yarr[3] = 0;
  402. xarr[4] = 0;
  403. yarr[4] = +ysize_checker;
  404. D_polygon_rel(xarr, yarr, 5);
  405. }
  406. xarr[0] = 0;
  407. yarr[0] = 0;
  408. xarr[1] = seg_len / 2.;
  409. yarr[1] = 0;
  410. xarr[2] = 0;
  411. yarr[2] = +ysize_checker;
  412. xarr[3] = -seg_len / 2.;
  413. yarr[3] = 0;
  414. xarr[4] = 0;
  415. yarr[4] = -ysize_checker;
  416. D_pos_rel(seg_len / 2., 0);
  417. D_polygon_rel(xarr, yarr, 5);
  418. D_pos_rel(seg_len / 2., 0);
  419. }
  420. else {
  421. xarr[0] = 0;
  422. yarr[0] = 0;
  423. xarr[1] = seg_len;
  424. yarr[1] = 0;
  425. xarr[2] = 0;
  426. yarr[2] = (i % 2 ? ysize_checker : +ysize_checker);
  427. xarr[3] = -seg_len;
  428. yarr[3] = 0;
  429. xarr[4] = 0;
  430. yarr[4] = (i % 2 ? -ysize_checker : ysize_checker);
  431. /* width is seg_len and height is 6 */
  432. D_polygon_rel(xarr, yarr, 5);
  433. D_pos_rel(seg_len, -ysize_checker);
  434. }
  435. }
  436. }
  437. else if (style == STYLE_TAIL_CHECKER) {
  438. /* first draw outside box */
  439. D_begin();
  440. D_move_abs(x_pos_start, y_pos + ysize / 2 + ysize_checker);
  441. D_cont_rel(line_len, 0);
  442. D_cont_rel(0, -2 * ysize_checker);
  443. D_cont_rel(-line_len, 0);
  444. D_cont_rel(0, +2 * ysize_checker);
  445. D_close();
  446. D_end(); /* no-op? */
  447. D_stroke();
  448. D_pos_rel(0, -ysize_checker);
  449. for (i = 1; i <= (seg == 5 ? 3 : 5); i++) {
  450. /* width is seg_len and height is 6 */
  451. xarr[0] = 0;
  452. yarr[0] = 0;
  453. xarr[1] = seg_len;
  454. yarr[1] = 0;
  455. xarr[2] = 0;
  456. yarr[2] = (i % 2 ? -ysize_checker : ysize_checker);
  457. xarr[3] = -seg_len;
  458. yarr[3] = 0;
  459. xarr[4] = 0;
  460. yarr[4] = (i % 2 ? ysize_checker : -ysize_checker);
  461. D_polygon_rel(xarr, yarr, 5);
  462. D_pos_rel(seg_len, 0);
  463. }
  464. /* draw a vertical cross line */
  465. D_begin();
  466. D_move_rel(0, ysize_checker);
  467. D_cont_rel(0, -2 * ysize_checker);
  468. D_close();
  469. D_end(); /* no-op? */
  470. D_stroke();
  471. D_pos_rel(0, ysize_checker);
  472. xarr[0] = 0;
  473. yarr[0] = 0;
  474. xarr[1] = line_len / 2.;
  475. if (seg == 5)
  476. xarr[1] -= seg_len / 2.;
  477. yarr[1] = 0;
  478. xarr[2] = 0;
  479. yarr[2] = ysize_checker;
  480. xarr[3] = -line_len / 2.;
  481. if (seg == 5)
  482. xarr[3] += seg_len / 2.;
  483. yarr[3] = 0;
  484. xarr[4] = 0;
  485. yarr[4] = -ysize_checker;
  486. D_polygon_rel(xarr, yarr, 5);
  487. D_pos_rel(seg_len, 0);
  488. }
  489. else if (style == STYLE_TICKS_BOTH) {
  490. /* draw simple line scale with corssing ticks */
  491. D_begin();
  492. D_move_abs(x_pos_start, y_pos + (ysize - ysize_ticks) / 2);
  493. D_cont_abs(x_pos_start, y_pos + ysize - (ysize - ysize_ticks) / 2);
  494. D_move_abs(x_pos_start, y_pos + ysize / 2);
  495. D_cont_abs(x_pos_start + line_len, y_pos + ysize / 2);
  496. D_move_abs(x_pos_start + line_len, y_pos + (ysize - ysize_ticks) / 2);
  497. D_cont_abs(x_pos_start + line_len, y_pos + ysize - (ysize - ysize_ticks) / 2);
  498. D_move_abs(x_pos_start, y_pos + ysize / 2);
  499. D_move_rel(0, ysize_ticks / 4);
  500. for (i = 0; i <= seg - 2; i++) {
  501. D_move_rel(seg_len, 0);
  502. D_cont_rel(0, -ysize_ticks/2); /* 5 above, on px on line, and 5 below */
  503. D_move_rel(0, +ysize_ticks/2);
  504. }
  505. D_end(); /* no-op? */
  506. }
  507. else if (style == STYLE_TICKS_UP) {
  508. /* draw simple line scale with up facing ticks */
  509. D_begin();
  510. D_move_abs(x_pos_start, y_pos - 2 * width_scale);
  511. D_cont_abs(x_pos_start, y_pos + ysize / 2);
  512. D_cont_abs(x_pos_start + line_len, y_pos + ysize / 2);
  513. D_move_abs(x_pos_start + line_len,y_pos - 2 * width_scale);
  514. D_cont_abs(x_pos_start + line_len, y_pos + ysize / 2);
  515. D_move_abs(x_pos_start, y_pos + ysize / 2);
  516. for (i = 0; i <= seg - 2; i++) {
  517. D_move_rel(seg_len, 0);
  518. D_cont_rel(0, -ysize_ticks/2); /* 5 above, on px on line, and 5 below */
  519. D_move_rel(0, +ysize_ticks/2);
  520. }
  521. D_end(); /* no-op? */
  522. D_close();
  523. }
  524. else if (style == STYLE_TICKS_DOWN) {
  525. /* draw simple line scale with down facing ticks */
  526. D_begin();
  527. D_move_abs(x_pos_start, y_pos + ysize / 2 + 17 * width_scale);
  528. D_cont_abs(x_pos_start, y_pos + ysize / 2);
  529. D_cont_abs(x_pos_start + line_len, y_pos + ysize / 2);
  530. D_move_abs(x_pos_start + line_len, y_pos + ysize / 2 + 17 * width_scale);
  531. D_cont_abs(x_pos_start + line_len, y_pos + ysize / 2);
  532. D_move_abs(x_pos_start, y_pos + ysize / 2);
  533. for (i = 0; i <= seg - 2; i++) {
  534. D_move_rel(seg_len, 0);
  535. D_cont_rel(0, +ysize_ticks/2); /* 5 above, on px on line, and 5 below */
  536. D_move_rel(0, -ysize_ticks/2);
  537. }
  538. D_end(); /* no-op? */
  539. D_close();
  540. }
  541. else if (style == STYLE_ARROW_ENDS) {
  542. /* draw line scale with |<--dimension arrows-->| on the ends */
  543. D_begin();
  544. D_cont_abs(x_pos_start, y_pos + ysize / 2);
  545. D_cont_abs(x_pos_start + line_len, y_pos + ysize / 2);
  546. D_end();
  547. /* display the symbol */
  548. line_color = G_malloc(sizeof(RGBA_Color));
  549. fill_color = G_malloc(sizeof(RGBA_Color));
  550. if (D_color_number_to_RGB(fg_color, &R, &G, &B) == 0)
  551. /* fall back to black on failure */
  552. G_str_to_color(DEFAULT_FG_COLOR, &R, &G, &B);
  553. line_color->r = (unsigned char)R;
  554. line_color->g = (unsigned char)G;
  555. line_color->b = (unsigned char)B;
  556. line_color->a = RGBA_COLOR_OPAQUE;
  557. if (D_color_number_to_RGB(fg_color, &R, &G, &B) == 0)
  558. /* fall back to black on failure */
  559. G_str_to_color(DEFAULT_FG_COLOR, &R, &G, &B);
  560. fill_color->r = (unsigned char)R;
  561. fill_color->g = (unsigned char)G;
  562. fill_color->b = (unsigned char)B;
  563. fill_color->a = RGBA_COLOR_OPAQUE;
  564. symbol_size = 12 * width_scale;
  565. x0 = D_d_to_u_col(x_pos_start);
  566. y0 = D_d_to_u_row(y_pos + ysize / 2);
  567. Symb = S_read("extra/dim_arrow");
  568. if (!Symb)
  569. G_fatal_error(_("Could not read symbol \"%s\""),
  570. "extra/dim_arrow");
  571. S_stroke(Symb, symbol_size, 0.0, 0);
  572. D_symbol(Symb, x0, y0, line_color, fill_color);
  573. G_free(Symb);
  574. x0 = D_d_to_u_col(line_len + x_pos_start);
  575. y0 = D_d_to_u_row(y_pos + ysize / 2);
  576. Symb = S_read("extra/dim_arrow");
  577. S_stroke(Symb, symbol_size, 180., 0);
  578. D_symbol(Symb, x0, y0, line_color, fill_color);
  579. G_free(Symb);
  580. G_free(line_color);
  581. G_free(fill_color);
  582. /* draw simple line between the two ends */
  583. D_begin();
  584. D_move_abs(x_pos_start, y_pos + ysize / 2);
  585. D_cont_abs(x_pos_start + line_len, y_pos + ysize / 2);
  586. D_end(); /* no-op? */
  587. }
  588. D_stroke();
  589. if (fontsize < 0)
  590. return 0;
  591. /* draw the distance + units text */
  592. D_get_text_box(label, &tt, &tb, &tl, &tr);
  593. if (text_posn == TEXT_OVER) {
  594. D_pos_abs(x_pos + line_len/2 + xspace_around_line +
  595. (north_arrow ? xspace_bf_N + xsize_N : 0) - (tr - tl) / 2,
  596. y_pos);
  597. D_text(label);
  598. }
  599. else if (text_posn == TEXT_UNDER) {
  600. D_pos_abs(x_pos + line_len/2 + xspace_around_line +
  601. (north_arrow ? xspace_bf_N + xsize_N : 0) - (tr - tl) / 2,
  602. y_pos + 40 * width_scale);
  603. D_text(label);
  604. }
  605. else if (text_posn == TEXT_RIGHT) {
  606. if (style == STYLE_TICKS_UP)
  607. y_pos -= 8 * width_scale;
  608. else if (style == STYLE_TICKS_DOWN)
  609. y_pos += 9 * width_scale;
  610. D_pos_abs(x_pos + line_len + 2 * xspace_around_line +
  611. (north_arrow ? xspace_bf_N + xsize_N : 0),
  612. y_pos + ysize / 2 + (tt - tb) /2);
  613. D_text(label);
  614. }
  615. else if (text_posn == TEXT_LEFT) {
  616. if (style == STYLE_TICKS_UP)
  617. y_pos -= 8 * width_scale;
  618. else if (style == STYLE_TICKS_DOWN)
  619. y_pos += 9 * width_scale;
  620. if (style == STYLE_CLASSIC_BAR || style == STYLE_THIN_WITH_ENDS)
  621. x_pos -= 13 * width_scale;
  622. D_pos_abs(x_pos + 5 - (tr - tl), y_pos + ysize / 2 + (tt - tb) /2);
  623. D_text(label);
  624. }
  625. return 0;
  626. }