r_vlegend.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /* Function: vlegfile
  2. **
  3. ** Author: Paul W. Carlson April 1992
  4. */
  5. #include <stdlib.h>
  6. #include <string.h>
  7. #include <grass/colors.h>
  8. #include <grass/glocale.h>
  9. #include "vector.h"
  10. #include "local_proto.h"
  11. #define KEY(x) (strcmp(key,x)==0)
  12. static char *help[] = {
  13. "where x y",
  14. "font fontname",
  15. "fontsize fontsize",
  16. "width sample box width",
  17. "cols number of columns",
  18. "border color|none",
  19. "span column separation",
  20. ""
  21. };
  22. int read_vlegend(void)
  23. {
  24. char buf[1024];
  25. char *key, *data;
  26. int fontsize, cols;
  27. double x, y, width, cseparation;
  28. int r, g, b, ret;
  29. PSCOLOR border;
  30. fontsize = 0;
  31. x = y = 0.0;
  32. width = -1;
  33. cols = 1;
  34. unset_color(&border);
  35. cseparation = -1;
  36. while (input(2, buf, help)) {
  37. if (!key_data(buf, &key, &data))
  38. continue;
  39. if (KEY("where")) {
  40. if (sscanf(data, "%lf %lf", &x, &y) != 2) {
  41. x = y = 0.0;
  42. error(key, data, _("illegal where request"));
  43. }
  44. else
  45. continue;
  46. }
  47. if (KEY("fontsize")) {
  48. fontsize = atoi(data);
  49. continue;
  50. }
  51. if (KEY("font")) {
  52. get_font(data);
  53. vector.font = G_store(data);
  54. continue;
  55. }
  56. if (KEY("width")) {
  57. G_strip(data);
  58. width = atof(data);
  59. continue;
  60. }
  61. if (KEY("cols")) {
  62. cols = atoi(data);
  63. if (cols < 1 || cols > 10)
  64. cols = 1;
  65. continue;
  66. }
  67. if (KEY("border")) {
  68. ret = G_str_to_color(data, &r, &g, &b);
  69. if (ret == 1)
  70. set_color(&border, r, g, b);
  71. else if (ret == 2) /* i.e. "none" */
  72. unset_color(&border);
  73. else
  74. error(key, data, _("illegal border color request"));
  75. continue;
  76. }
  77. if (KEY("span")) {
  78. G_strip(data);
  79. cseparation = atof(data);
  80. continue;
  81. }
  82. error(key, data, _("illegal vlegend sub-request"));
  83. }
  84. vector.x = x;
  85. vector.y = y;
  86. if (fontsize)
  87. vector.fontsize = fontsize;
  88. if (width > 0)
  89. vector.width = width;
  90. else
  91. vector.width = 3 * fontsize / 72.0;
  92. vector.cols = cols;
  93. vector.border = border;
  94. vector.span = cseparation;
  95. return 0;
  96. }