main.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708
  1. /*
  2. ****************************************************************************
  3. *
  4. * MODULE: d.text
  5. *
  6. * AUTHOR(S): James Westervelt, US Army CERL
  7. * Updated by Huidae Cho, Markus Neteler
  8. *
  9. * PURPOSE: display text in active frame
  10. *
  11. * COPYRIGHT: (C) 2001 by the GRASS Development Team
  12. *
  13. * This program is free software under the GNU General Public
  14. * License (>=v2). Read the file COPYING that comes with GRASS
  15. * for details.
  16. *
  17. *****************************************************************************/
  18. /*
  19. * d.text commands:
  20. *
  21. * .F {font|path}[:charset] font
  22. * .C {color_name|RR:GG:BB|0xRRGGBB} color
  23. * .G {color_name|RR:GG:BB|0xRRGGBB} background color
  24. * .S [+|-]size[p] text size
  25. * +/-: relative size
  26. * p: size in pixels
  27. * .B {0|1} bold (double print) off/on
  28. * .A {ll|lc|lr|cl|cc|cr|ul|uc|ur} align (TODO)
  29. * .R [+|-]rotation[r] rotation
  30. * +/-: relative rotation
  31. * r: angle in radian
  32. * .I linespacing linespacing
  33. * .X [+|-]x[%|p] x: relative to x origin
  34. * +/-: relative dx
  35. * %: percentage
  36. * p: pixels
  37. * .Y [+|-]y[%|p] y: relative to y origin
  38. * +/-: relative dy
  39. * %: percentage
  40. * p: pixels
  41. * .L {0|1} linefeed off/on
  42. * .E [+|-]east[%|p] x origin: geographic coordinates
  43. * +/-: relative de
  44. * %: percentage
  45. * p: pixels
  46. * .N [+|-]north[%|p] y origin: geographic coordinates
  47. * +/-: relative dn
  48. * %: percentage
  49. * p: pixels
  50. * .. draw one dot (.)
  51. * .<SPACE> comments
  52. */
  53. #include <math.h>
  54. #include <stdio.h>
  55. #include <stdlib.h>
  56. #include <string.h>
  57. #include <unistd.h>
  58. #include <grass/gis.h>
  59. #include <grass/display.h>
  60. #include <grass/colors.h>
  61. #include <grass/glocale.h>
  62. #define BACKWARD_COMPATIBILITY
  63. #define DEFAULT_COLOR "gray"
  64. struct rectinfo
  65. {
  66. double t, b, l, r;
  67. };
  68. static void set_color(char *);
  69. static void get_coordinates(double *, double *, double *, double *,
  70. struct rectinfo, char **, char, char);
  71. static void draw_text(char *, double *, double *, double, char *, double, char,
  72. int, int, int);
  73. int main(int argc, char **argv)
  74. {
  75. struct GModule *module;
  76. struct
  77. {
  78. struct Option *text;
  79. struct Option *size;
  80. struct Option *fgcolor;
  81. struct Option *bgcolor;
  82. struct Option *line;
  83. struct Option *at;
  84. struct Option *rotation;
  85. struct Option *align;
  86. struct Option *linespacing;
  87. struct Option *font;
  88. struct Option *path;
  89. struct Option *charset;
  90. struct Option *input;
  91. } opt;
  92. struct
  93. {
  94. struct Flag *p;
  95. struct Flag *g;
  96. struct Flag *b;
  97. struct Flag *r;
  98. struct Flag *s;
  99. } flag;
  100. /* options and flags */
  101. char *text;
  102. double size;
  103. double x, y;
  104. int line;
  105. double rotation;
  106. char align[3];
  107. double linespacing;
  108. char bold;
  109. /* window info */
  110. struct rectinfo win;
  111. /* command file */
  112. FILE *cmd_fp;
  113. char buf[512];
  114. int first_text;
  115. int linefeed;
  116. int set_l;
  117. double orig_x, orig_y;
  118. double prev_x, prev_y;
  119. double set_x, set_y;
  120. double east, north;
  121. int do_background, fg_color, bg_color;
  122. /* initialize the GIS calls */
  123. G_gisinit(argv[0]);
  124. module = G_define_module();
  125. G_add_keyword(_("display"));
  126. G_add_keyword(_("cartography"));
  127. module->description =
  128. _("Draws text in the active display frame on the graphics monitor using the current font.");
  129. opt.text = G_define_option();
  130. opt.text->key = "text";
  131. opt.text->type = TYPE_STRING;
  132. opt.text->required = NO;
  133. opt.text->description = _("Text to display");
  134. opt.text->guisection = _("Input");
  135. opt.input = G_define_standard_option(G_OPT_F_INPUT);
  136. opt.input->required = NO;
  137. opt.input->description = _("Input file");
  138. opt.input->guisection = _("Input");
  139. opt.fgcolor = G_define_option();
  140. opt.fgcolor->key = "color";
  141. opt.fgcolor->type = TYPE_STRING;
  142. opt.fgcolor->answer = DEFAULT_COLOR;
  143. opt.fgcolor->required = NO;
  144. opt.fgcolor->description =
  145. _("Text color, either a standard GRASS color or R:G:B triplet");
  146. opt.fgcolor->gisprompt = "old_color,color,color";
  147. opt.fgcolor->guisection = _("Text");
  148. opt.bgcolor = G_define_option();
  149. opt.bgcolor->key = "bgcolor";
  150. opt.bgcolor->type = TYPE_STRING;
  151. opt.bgcolor->required = NO;
  152. opt.bgcolor->description =
  153. _("Text background color, either a standard GRASS color or R:G:B triplet");
  154. opt.bgcolor->gisprompt = "old_color,color,color";
  155. opt.bgcolor->guisection = _("Text");
  156. opt.rotation = G_define_option();
  157. opt.rotation->key = "rotation";
  158. opt.rotation->type = TYPE_DOUBLE;
  159. opt.rotation->required = NO;
  160. opt.rotation->answer = "0";
  161. opt.rotation->description =
  162. _("Rotation angle in degrees (counter-clockwise)");
  163. opt.rotation->guisection = _("Text");
  164. opt.linespacing = G_define_option();
  165. opt.linespacing->key = "linespacing";
  166. opt.linespacing->type = TYPE_DOUBLE;
  167. opt.linespacing->required = NO;
  168. opt.linespacing->answer = "1.25";
  169. opt.linespacing->description = _("Line spacing");
  170. opt.linespacing->guisection = _("Text");
  171. opt.at = G_define_option();
  172. opt.at->key = "at";
  173. opt.at->key_desc = "x,y";
  174. opt.at->type = TYPE_DOUBLE;
  175. opt.at->required = NO;
  176. opt.at->description =
  177. _("Screen position at which text will begin to be drawn (percentage, [0,0] is lower left)");
  178. opt.at->guisection = _("Position");
  179. opt.line = G_define_option();
  180. opt.line->key = "line";
  181. opt.line->required = NO;
  182. opt.line->type = TYPE_INTEGER;
  183. opt.line->options = "1-1000";
  184. opt.line->description =
  185. _("The screen line number on which text will begin to be drawn");
  186. opt.line->guisection = _("Position");
  187. opt.align = G_define_option();
  188. opt.align->key = "align";
  189. opt.align->type = TYPE_STRING;
  190. opt.align->required = NO;
  191. opt.align->answer = "ll";
  192. opt.align->options = "ll,lc,lr,cl,cc,cr,ul,uc,ur";
  193. opt.align->description = _("Text alignment");
  194. opt.align->guisection = _("Position");
  195. opt.font = G_define_option();
  196. opt.font->key = "font";
  197. opt.font->type = TYPE_STRING;
  198. opt.font->required = NO;
  199. opt.font->description = _("Font name");
  200. opt.font->guisection = _("Font settings");
  201. opt.size = G_define_option();
  202. opt.size->key = "size";
  203. opt.size->type = TYPE_DOUBLE;
  204. opt.size->required = NO;
  205. opt.size->answer = "5";
  206. opt.size->options = "0-100";
  207. opt.size->description =
  208. _("Height of letters in percentage of available frame height");
  209. opt.size->guisection = _("Font settings");
  210. opt.path = G_define_standard_option(G_OPT_F_INPUT);
  211. opt.path->key = "path";
  212. opt.path->required = NO;
  213. opt.path->description = _("Path to font file");
  214. opt.path->gisprompt = "old,font,file";
  215. opt.path->guisection = _("Font settings");
  216. opt.charset = G_define_option();
  217. opt.charset->key = "charset";
  218. opt.charset->type = TYPE_STRING;
  219. opt.charset->required = NO;
  220. opt.charset->description =
  221. _("Text encoding (only applicable to TrueType fonts)");
  222. opt.charset->guisection = _("Font settings");
  223. flag.p = G_define_flag();
  224. flag.p->key = 'p';
  225. flag.p->description = _("Screen position in pixels ([0,0] is top left)");
  226. flag.p->guisection = _("Position");
  227. flag.g = G_define_flag();
  228. flag.g->key = 'g';
  229. flag.g->description = _("Screen position in geographic coordinates");
  230. flag.g->guisection = _("Position");
  231. flag.b = G_define_flag();
  232. flag.b->key = 'b';
  233. flag.b->description = _("Use bold text");
  234. flag.b->guisection = _("Text");
  235. flag.r = G_define_flag();
  236. flag.r->key = 'r';
  237. flag.r->description = _("Use radians instead of degrees for rotation");
  238. flag.r->guisection = _("Text");
  239. flag.s = G_define_flag();
  240. flag.s->key = 's';
  241. flag.s->description = _("Font size is height in pixels");
  242. flag.s->guisection = _("Font settings");
  243. G_option_exclusive(opt.line, opt.at, NULL);
  244. G_option_exclusive(flag.p, flag.g, NULL);
  245. /* check command line */
  246. if (G_parser(argc, argv))
  247. exit(1);
  248. /* parse options */
  249. text = opt.text->answer;
  250. line = (opt.line->answer ? atoi(opt.line->answer) : 1);
  251. /* calculate rotation angle in radian */
  252. rotation = atof(opt.rotation->answer);
  253. if (!flag.r->answer)
  254. rotation *= M_PI / 180.0;
  255. rotation = fmod(rotation, 2.0 * M_PI);
  256. if (rotation < 0.0)
  257. rotation += 2.0 * M_PI;
  258. strncpy(align, opt.align->answer, 2);
  259. linespacing = atof(opt.linespacing->answer);
  260. bold = flag.b->answer;
  261. D_open_driver();
  262. if (opt.font->answer)
  263. D_font(opt.font->answer);
  264. else if (opt.path->answer)
  265. D_font(opt.path->answer);
  266. if (opt.charset->answer)
  267. D_encoding(opt.charset->answer);
  268. D_setup(0);
  269. /* figure out where to put text */
  270. D_get_dst(&win.t, &win.b, &win.l, &win.r);
  271. if (flag.s->answer)
  272. size = atof(opt.size->answer);
  273. else
  274. #ifdef BACKWARD_COMPATIBILITY
  275. size = atof(opt.size->answer) / 100.0 * (win.b - win.t) / linespacing;
  276. #else
  277. size = atof(opt.size->answer) / 100.0 * (win.b - win.t);
  278. #endif
  279. fg_color = D_parse_color(opt.fgcolor->answer, TRUE);
  280. if (opt.bgcolor->answer) {
  281. do_background = 1;
  282. bg_color = D_parse_color(opt.bgcolor->answer, TRUE);
  283. if (bg_color == 0) /* ie color="none" */
  284. do_background = 0;
  285. }
  286. else {
  287. do_background = 0;
  288. bg_color = 0;
  289. }
  290. set_color(opt.fgcolor->answer);
  291. orig_x = orig_y = 0;
  292. if (opt.at->answers) {
  293. get_coordinates(&x, &y, &east, &north, win, opt.at->answers,
  294. flag.p->answer, flag.g->answer);
  295. orig_x = x;
  296. orig_y = y;
  297. }
  298. else {
  299. x = win.l + (size * linespacing + 0.5) - size; /* d.text: +5 */
  300. y = win.t + line * (size * linespacing + 0.5);
  301. }
  302. prev_x = x;
  303. prev_y = y;
  304. D_text_size(size, size);
  305. D_text_rotation(rotation * 180.0 / M_PI);
  306. if (text) {
  307. double x2, y2;
  308. x2 = x;
  309. y2 = y;
  310. if (text[0])
  311. draw_text(text, &x2, &y2, size, align, rotation, bold, do_background, fg_color, bg_color);
  312. /* reset */
  313. D_text_size(5, 5);
  314. D_text_rotation(0.0);
  315. D_save_command(G_recreate_command());
  316. D_close_driver();
  317. exit(EXIT_SUCCESS);
  318. }
  319. if (!opt.input->answer || strcmp(opt.input->answer, "-") == 0)
  320. cmd_fp = stdin;
  321. else {
  322. cmd_fp = fopen(opt.input->answer, "r");
  323. if (!cmd_fp)
  324. G_fatal_error(_("Unable to open input file <%s>"), opt.input->answer);
  325. }
  326. if (isatty(fileno(cmd_fp)))
  327. fprintf(stderr,
  328. _("\nPlease enter text instructions. Enter EOF (ctrl-d) on last line to quit\n"));
  329. set_x = set_y = set_l = 0;
  330. first_text = 1;
  331. linefeed = 1;
  332. /* do the plotting */
  333. while (fgets(buf, sizeof(buf), cmd_fp)) {
  334. int buf_len;
  335. char *buf_ptr, *ptr;
  336. buf_len = strlen(buf) - 1;
  337. for (; buf[buf_len] == '\r' || buf[buf_len] == '\n'; buf_len--) ;
  338. buf[buf_len + 1] = 0;
  339. if (buf[0] == '.' && buf[1] != '.') {
  340. int i;
  341. double d;
  342. G_squeeze(buf); /* added 6/91 DBS @ CWU */
  343. for (buf_ptr = buf + 2; *buf_ptr == ' '; buf_ptr++) ;
  344. buf_len = strlen(buf_ptr);
  345. switch (buf[1] & 0x7f) {
  346. case 'F':
  347. /* font */
  348. if ((ptr = strchr(buf_ptr, ':')))
  349. *ptr = 0;
  350. D_font(buf_ptr);
  351. if (ptr)
  352. D_encoding(ptr + 1);
  353. break;
  354. case 'C':
  355. /* color */
  356. set_color(buf_ptr);
  357. fg_color = D_parse_color(buf_ptr, 1);
  358. break;
  359. case 'G':
  360. /* background color */
  361. bg_color = D_parse_color(buf_ptr, 1);
  362. do_background = 1;
  363. break;
  364. case 'S':
  365. /* size */
  366. i = 0;
  367. if (strchr("+-", buf_ptr[0]))
  368. i = 1;
  369. d = atof(buf_ptr);
  370. if (buf_ptr[buf_len - 1] != 'p')
  371. #ifdef BACKWARD_COMPATIBILITY
  372. d *= (win.b - win.t) / 100.0 / linespacing;
  373. #else
  374. d *= (win.b - win.t) / 100.0;
  375. #endif
  376. size = d + (i ? size : 0);
  377. D_text_size(size, size);
  378. break;
  379. case 'B':
  380. /* bold */
  381. bold = (atoi(buf_ptr) ? 1 : 0);
  382. break;
  383. case 'A':
  384. /* align */
  385. strncpy(align, buf_ptr, 2);
  386. break;
  387. case 'R':
  388. /* rotation */
  389. i = 0;
  390. if (strchr("+-", buf_ptr[0]))
  391. i = 1;
  392. d = atof(buf_ptr);
  393. if (buf_ptr[buf_len - 1] != 'r')
  394. d *= M_PI / 180.0;
  395. d += (i ? rotation : 0.0);
  396. rotation = fmod(d, 2.0 * M_PI);
  397. if (rotation < 0.0)
  398. rotation += 2.0 * M_PI;
  399. D_text_rotation(rotation * 180.0 / M_PI);
  400. break;
  401. case 'I':
  402. /* linespacing */
  403. linespacing = atof(buf_ptr);
  404. break;
  405. case 'X':
  406. /* x */
  407. set_l = 0;
  408. set_x = 1;
  409. i = 0;
  410. if (strchr("+-", buf_ptr[0]))
  411. i = 1;
  412. d = atof(buf_ptr);
  413. if (buf_ptr[buf_len - 1] == '%')
  414. /* percentage */
  415. d *= (win.r - win.l) / 100.0;
  416. else if (buf_ptr[buf_len - 1] != 'p')
  417. /* column */
  418. d = (d - 1) * size * linespacing + 0.5;
  419. x = prev_x = d + (i ? x : orig_x);
  420. break;
  421. case 'Y':
  422. /* y */
  423. set_l = 0;
  424. set_y = 1;
  425. i = 0;
  426. if (strchr("+-", buf_ptr[0]))
  427. i = 1;
  428. d = atof(buf_ptr);
  429. if (buf_ptr[buf_len - 1] == '%')
  430. /* percentage */
  431. d = win.b - d * (win.b - win.t) / 100.0;
  432. else if (buf_ptr[buf_len - 1] != 'p')
  433. /* row */
  434. d *= size * linespacing + 0.5;
  435. y = prev_y = d + (i ? y : orig_y);
  436. break;
  437. case 'L':
  438. /* linefeed */
  439. set_l = 1;
  440. linefeed = (atoi(buf_ptr) ? 1 : 0);
  441. break;
  442. case 'E':
  443. i = 0;
  444. if (strchr("+-", buf_ptr[0]))
  445. i = 1;
  446. d = atof(buf_ptr);
  447. if (buf_ptr[buf_len - 1] == '%')
  448. d *= (win.r - win.l) / 100.0;
  449. else if (buf_ptr[buf_len - 1] != 'p')
  450. d = D_u_to_d_col(d);
  451. x = prev_x = orig_x = d + (i ? orig_x : win.l);
  452. break;
  453. case 'N':
  454. i = 0;
  455. if (strchr("+-", buf_ptr[0]))
  456. i = 1;
  457. d = atof(buf_ptr);
  458. if (buf_ptr[buf_len - 1] == '%')
  459. d *= (win.b - win.t) / 100.0;
  460. else if (buf_ptr[buf_len - 1] != 'p')
  461. d = D_u_to_d_row(d);
  462. y = prev_y = orig_y = d + (i ? orig_y : win.t);
  463. break;
  464. }
  465. }
  466. else {
  467. buf_ptr = buf;
  468. if (buf[0] == '.' && buf[1] == '.')
  469. buf_ptr++;
  470. if (!first_text && (linefeed || set_l)) {
  471. /* if x is not given, increment x */
  472. if (!set_x)
  473. x = prev_x +
  474. (size * linespacing + 0.5) * sin(rotation);
  475. /* if y is not given, increment y */
  476. if (!set_y)
  477. y = prev_y +
  478. (size * linespacing + 0.5) * cos(rotation);
  479. prev_x = x;
  480. prev_y = y;
  481. }
  482. set_x = set_y = set_l = first_text = 0;
  483. draw_text(buf_ptr, &x, &y, size, align, rotation, bold, do_background, fg_color, bg_color);
  484. }
  485. }
  486. if (cmd_fp != stdin)
  487. fclose(cmd_fp);
  488. /* reset */
  489. D_text_size(5, 5);
  490. D_text_rotation(0.0);
  491. D_close_driver();
  492. exit(EXIT_SUCCESS);
  493. }
  494. static void set_color(char *tcolor)
  495. {
  496. int r, g, b, color;
  497. if (sscanf(tcolor, "%d:%d:%d", &r, &g, &b) == 3 ||
  498. sscanf(tcolor, "0x%02x%02x%02x", &r, &g, &b) == 3) {
  499. if (r >= 0 && r < 256 && g >= 0 && g < 256 && b >= 0 && b < 256) {
  500. D_RGB_color(r, g, b);
  501. }
  502. }
  503. else {
  504. color = D_translate_color(tcolor);
  505. if (!color) {
  506. G_warning(_("[%s]: No such color. Use '%s'"), tcolor,
  507. DEFAULT_COLOR);
  508. color = D_translate_color(DEFAULT_COLOR);
  509. }
  510. D_use_color(color);
  511. }
  512. }
  513. static void get_coordinates(double *x, double *y, double *east, double *north,
  514. struct rectinfo win, char **at, char pixel,
  515. char geocoor)
  516. {
  517. double e, n;
  518. if (!at)
  519. G_fatal_error(_("Invalid coordinates"));
  520. e = atof(at[0]);
  521. n = atof(at[1]);
  522. if (pixel) {
  523. *x = e + win.l;
  524. *y = n + win.t;
  525. e = D_d_to_u_col(*x);
  526. n = D_d_to_u_row(*y);
  527. }
  528. else if (geocoor) {
  529. *x = D_u_to_d_col(e);
  530. *y = D_u_to_d_row(n);
  531. }
  532. else {
  533. *x = win.l + (win.r - win.l) * e / 100.0;
  534. *y = win.t + (win.b - win.t) * (100.0 - n) / 100.0;
  535. e = D_d_to_u_col(*x);
  536. n = D_d_to_u_row(*y);
  537. }
  538. if (east)
  539. *east = e;
  540. if (north)
  541. *north = n;
  542. }
  543. static void draw_text(char *text, double *x, double *y, double size,
  544. char *align, double rotation, char bold,
  545. int do_background, int fg_color, int bg_color)
  546. {
  547. double w, h;
  548. double t, b, l, r;
  549. double c, s;
  550. int pt, pb, pl, pr;
  551. /* TODO: get text dimension */
  552. /* R_get_text_box() does not work with rotation and returns a little bit
  553. * bigger dimension than actual text size */
  554. if (rotation != 0.0)
  555. D_text_rotation(0.0);
  556. D_get_text_box(text, &t, &b, &l, &r);
  557. t = D_u_to_d_row(t);
  558. b = D_u_to_d_row(b);
  559. l = D_u_to_d_col(l);
  560. r = D_u_to_d_col(r);
  561. if (rotation != 0.0)
  562. D_text_rotation(rotation * 180.0 / M_PI);
  563. w = r - l;
  564. h = b - t;
  565. if (w > 0)
  566. w += 0.2 * size;
  567. else
  568. /* D_text() does not draw " ". */
  569. w = 0.8 * size;
  570. if (h > 0)
  571. h += 0.2 * size;
  572. else
  573. /* D_text() does not draw " ". */
  574. h = 0.8 * size;
  575. c = cos(rotation);
  576. s = sin(rotation);
  577. if (strcmp(align, "ll") != 0) {
  578. switch (align[0]) {
  579. case 'l':
  580. break;
  581. case 'c':
  582. *x += h / 2.0 * s;
  583. *y += h / 2.0 * c;
  584. break;
  585. case 'u':
  586. *x += h * s;
  587. *y += h * c;
  588. break;
  589. }
  590. switch (align[1]) {
  591. case 'l':
  592. break;
  593. case 'c':
  594. *x -= w / 2.0 * c;
  595. *y += w / 2.0 * s;
  596. break;
  597. case 'r':
  598. *x -= w * c;
  599. *y += w * s;
  600. break;
  601. }
  602. }
  603. if (do_background) {
  604. pl = D_d_to_u_col(*x - size/2); /* some pixels margin for both sides */
  605. pt = D_d_to_u_row(*y + size/2);
  606. pr = D_d_to_u_col(*x + w + size/2);
  607. pb = D_d_to_u_row(*y - h - size/2);
  608. D_use_color(bg_color);
  609. D_box_abs(pl, pt, pr, pb); /* draw the box */
  610. D_use_color(fg_color); /* restore */
  611. }
  612. D_pos_abs(D_d_to_u_col(*x), D_d_to_u_row(*y));
  613. D_text(text);
  614. if (bold) {
  615. D_pos_abs(D_d_to_u_col(*x), D_d_to_u_row(*y + 1));
  616. D_text(text);
  617. D_pos_abs(D_d_to_u_col(*x + 1), D_d_to_u_row(*y));
  618. D_text(text);
  619. }
  620. *x += w * c;
  621. *y -= w * s;
  622. }