draw_scale.c 16 KB

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