r_raster.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /*!
  2. \file display/r_raster.c
  3. \brief Display Library - Raster graphics subroutines
  4. (C) 2001-2009 by the GRASS Development Team
  5. This program is free software under the GNU General Public License
  6. (>=v2). Read the file COPYING that comes with GRASS for details.
  7. \author Original author CERL
  8. */
  9. #include <grass/config.h>
  10. #include <errno.h>
  11. #include <signal.h>
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <string.h>
  15. #include <unistd.h>
  16. #include <grass/gis.h>
  17. #include <grass/glocale.h>
  18. #include <grass/display.h>
  19. #include "driver.h"
  20. extern const struct driver *PNG_Driver(void);
  21. extern const struct driver *PS_Driver(void);
  22. extern const struct driver *HTML_Driver(void);
  23. #ifdef USE_CAIRO
  24. extern const struct driver *Cairo_Driver(void);
  25. #endif
  26. static void init(void)
  27. {
  28. const char *fenc = getenv("GRASS_ENCODING");
  29. const char *font = getenv("GRASS_FONT");
  30. const char *line_width = getenv("GRASS_LINE_WIDTH");
  31. const char *text_size = getenv("GRASS_TEXT_SIZE");
  32. const char *frame = getenv("GRASS_FRAME");
  33. D_font(font ? font : "romans");
  34. if (fenc)
  35. D_encoding(fenc);
  36. if (line_width)
  37. COM_Line_width(atof(line_width));
  38. if (text_size) {
  39. double s = atof(text_size);
  40. D_text_size(s, s);
  41. }
  42. D_text_rotation(0);
  43. if (frame) {
  44. double t, b, l, r;
  45. sscanf(frame, "%lf,%lf,%lf,%lf", &t, &b, &l, &r);
  46. COM_Set_window(t, b, l, r);
  47. }
  48. }
  49. int D_open_driver(void)
  50. {
  51. const char *p = getenv("GRASS_RENDER_IMMEDIATE");
  52. const struct driver *drv =
  53. (p && G_strcasecmp(p, "PNG") == 0) ? PNG_Driver() :
  54. (p && G_strcasecmp(p, "PS") == 0) ? PS_Driver() :
  55. (p && G_strcasecmp(p, "HTML") == 0) ? HTML_Driver() :
  56. #ifdef USE_CAIRO
  57. (p && G_strcasecmp(p, "cairo") == 0) ? Cairo_Driver() :
  58. Cairo_Driver();
  59. #else
  60. PNG_Driver();
  61. #endif
  62. LIB_init(drv);
  63. init();
  64. return 0;
  65. }
  66. void D_close_driver(void)
  67. {
  68. const char *cmd = getenv("GRASS_NOTIFY");
  69. COM_Graph_close();
  70. if (cmd)
  71. system(cmd);
  72. }
  73. void D__erase(void)
  74. {
  75. COM_Erase();
  76. }
  77. /*!
  78. * \brief set text size
  79. *
  80. * Sets text pixel width and height to <b>width</b> and <b>height.</b>
  81. *
  82. * \param width
  83. * \param height
  84. * \return void
  85. */
  86. void D_text_size(double width, double height)
  87. {
  88. COM_Text_size(width, height);
  89. }
  90. void D_text_rotation(double rotation)
  91. {
  92. COM_Text_rotation(rotation);
  93. }
  94. /*!
  95. * \brief get clipping frame
  96. *
  97. * Retrieve clipping frame
  98. *
  99. * \param t top
  100. * \param b bottom
  101. * \param l left
  102. * \param r right
  103. * \return void
  104. */
  105. void D_get_window(double *t, double *b, double *l, double *r)
  106. {
  107. return COM_Get_window(t, b, l, r);
  108. }
  109. /*!
  110. * \brief write text
  111. *
  112. * Writes <b>text</b> in the current color and font, at the current text
  113. * width and height, starting at the current screen location.
  114. *
  115. * \param sometext
  116. * \return void
  117. */
  118. void D_text(const char *text)
  119. {
  120. COM_Text(text);
  121. }
  122. /*!
  123. * \brief choose font
  124. *
  125. * Set current font to <b>font name</b>.
  126. *
  127. * \param name
  128. * \return void
  129. */
  130. void D_font(const char *name)
  131. {
  132. COM_Set_font(name);
  133. }
  134. void D_encoding(const char *name)
  135. {
  136. COM_Set_encoding(name);
  137. }
  138. void D_font_list(char ***list, int *count)
  139. {
  140. COM_Font_list(list, count);
  141. }
  142. void D_font_info(char ***list, int *count)
  143. {
  144. COM_Font_info(list, count);
  145. }