text2.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. #include <math.h>
  2. #include <grass/gis.h>
  3. #include "driver.h"
  4. #include "driverlib.h"
  5. static int dont_draw;
  6. static double t, b, l, r;
  7. static double basex, basey;
  8. static double curx, cury;
  9. static void remember(double x, double y)
  10. {
  11. if (x > r)
  12. r = x;
  13. if (x < l)
  14. l = x;
  15. if (y > b)
  16. b = y;
  17. if (y < t)
  18. t = y;
  19. curx = x;
  20. cury = y;
  21. }
  22. static void text_draw(double x, double y)
  23. {
  24. COM_Line_abs(curx, cury, x, y);
  25. curx = x;
  26. cury = y;
  27. }
  28. static void text_move(double x, double y)
  29. {
  30. curx = x;
  31. cury = y;
  32. }
  33. void drawchar(double text_size_x, double text_size_y,
  34. double sinrot, double cosrot, unsigned char character)
  35. {
  36. unsigned char *X;
  37. unsigned char *Y;
  38. int n_vects;
  39. int i;
  40. double ax, ay;
  41. double x, y;
  42. void (*Do) (double, double);
  43. int ix, iy;
  44. x = basex;
  45. y = basey;
  46. get_char_vects(character, &n_vects, &X, &Y);
  47. Do = text_move;
  48. for (i = 1; i < n_vects; i++) {
  49. if (X[i] == ' ') {
  50. Do = text_move;
  51. continue;
  52. }
  53. ix = 10 + X[i] - 'R';
  54. iy = 10 - Y[i] + 'R';
  55. ax = text_size_x * ix;
  56. ay = text_size_y * iy;
  57. if (dont_draw) {
  58. remember(x + (ax * cosrot - ay * sinrot),
  59. y - (ax * sinrot + ay * cosrot));
  60. }
  61. else {
  62. (*Do) (x + (ax * cosrot - ay * sinrot),
  63. y - (ax * sinrot + ay * cosrot));
  64. Do = text_draw;
  65. }
  66. }
  67. /* This seems to do variable spacing
  68. ix = 10 + X[i] - 'R';
  69. */
  70. ix = 20;
  71. iy = 0;
  72. ax = text_size_x * ix;
  73. ay = text_size_y * iy;
  74. if (!dont_draw)
  75. text_move(basex + (ax * cosrot - ay * sinrot),
  76. basey - (ax * sinrot + ay * cosrot));
  77. else
  78. remember(basex + (ax * cosrot - ay * sinrot),
  79. basey - (ax * sinrot + ay * cosrot));
  80. }
  81. void soft_text_ext(double x, double y,
  82. double text_size_x, double text_size_y,
  83. double text_rotation, const char *string)
  84. {
  85. t = 999999;
  86. b = 0;
  87. l = 999999;
  88. r = 0;
  89. dont_draw = 1;
  90. soft_text(x, y, text_size_x, text_size_y, text_rotation, string);
  91. dont_draw = 0;
  92. }
  93. void get_text_ext(double *top, double *bot, double *left, double *rite)
  94. {
  95. *top = t;
  96. *bot = b;
  97. *left = l;
  98. *rite = r;
  99. }
  100. # define RpD ((2 * M_PI) / 360.) /* radians/degree */
  101. # define D2R(d) (double)(d * RpD) /* degrees->radians */
  102. void soft_text(double x, double y,
  103. double text_size_x, double text_size_y, double text_rotation,
  104. const char *string)
  105. {
  106. double sinrot = sin(D2R(text_rotation));
  107. double cosrot = cos(D2R(text_rotation));
  108. curx = basex = x;
  109. cury = basey = y;
  110. while (*string) {
  111. drawchar(text_size_x, text_size_y, sinrot, cosrot, *string++);
  112. basex = curx;
  113. basey = cury;
  114. }
  115. }
  116. void onechar(double x, double y,
  117. double text_size_x, double text_size_y, double text_rotation,
  118. unsigned char achar)
  119. {
  120. double sinrot = sin(D2R(text_rotation));
  121. double cosrot = cos(D2R(text_rotation));
  122. curx = basex = x;
  123. cury = basey = y;
  124. drawchar(text_size_x, text_size_y, sinrot, cosrot, achar);
  125. }