draw_scale.c 20 KB

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