123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363 |
- #include <grass/config.h>
- #include <errno.h>
- #include <signal.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <unistd.h>
- #include <grass/gis.h>
- #include <grass/glocale.h>
- #include <grass/raster.h>
- #include "driver.h"
- extern const struct driver *PNG_Driver(void);
- extern const struct driver *PS_Driver(void);
- extern const struct driver *HTML_Driver(void);
- #ifdef USE_CAIRO
- extern const struct driver *Cairo_Driver(void);
- #endif
- static void init(void)
- {
- const char *fenc = getenv("GRASS_ENCODING");
- const char *font = getenv("GRASS_FONT");
- const char *line_width = getenv("GRASS_LINE_WIDTH");
- const char *text_size = getenv("GRASS_TEXT_SIZE");
- const char *frame = getenv("GRASS_FRAME");
- R_font(font ? font : "romans");
- if (fenc)
- R_encoding(fenc);
- if (line_width)
- R_line_width(atof(line_width));
- if (text_size) {
- double s = atof(text_size);
- R_text_size(s, s);
- }
- R_text_rotation(0);
- if (frame) {
- double t, b, l, r;
- sscanf(frame, "%lf,%lf,%lf,%lf", &t, &b, &l, &r);
- R_set_window(t, b, l, r);
- }
- }
- int R_open_driver(void)
- {
- const char *p = getenv("GRASS_RENDER_IMMEDIATE");
- const struct driver *drv =
- (p && G_strcasecmp(p, "PNG") == 0) ? PNG_Driver() :
- (p && G_strcasecmp(p, "PS") == 0) ? PS_Driver() :
- (p && G_strcasecmp(p, "HTML") == 0) ? HTML_Driver() :
- #ifdef USE_CAIRO
- (p && G_strcasecmp(p, "cairo") == 0) ? Cairo_Driver() :
- Cairo_Driver();
- #else
- PNG_Driver();
- #endif
- LIB_init(drv);
- init();
- return 0;
- }
- void R_close_driver(void)
- {
- const char *cmd = getenv("GRASS_NOTIFY");
- COM_Graph_close();
- if (cmd)
- system(cmd);
- }
- /*!
- * \brief select standard color
- *
- * Selects the
- * standard <b>color</b> to be used in subsequent draw commands. The
- * <b>color</b> value is best retrieved using <i>D_translate_color.</i>
- * See Display_Graphics_Library.
- *
- * \param index
- * \return void
- */
- void R_standard_color(int index)
- {
- COM_Standard_color(index);
- }
- /*!
- * \brief select color
- *
- * When in
- * float mode (see <i>R_color_table_float</i>), this call selects the color
- * most closely matched to the <b>red, grn</b>, and <b>blue</b> intensities
- * requested. These values must be in the range of 0-255.
- *
- * \param red
- * \param grn
- * \param blue
- * \return void
- */
- void R_RGB_color(int red, int grn, int blu)
- {
- COM_Color_RGB(red, grn, blu);
- }
- /*!
- * \brief change the width of line
- *
- * Changes the <b>width</b> of line to be used in subsequent draw commands.
- *
- * \param width
- * \return void
- */
- void R_line_width(double width)
- {
- COM_Line_width(width);
- }
- /*!
- * \brief erase screen
- *
- * Erases the entire screen to black.
- *
- * \param void
- * \return void
- */
- void R_erase(void)
- {
- COM_Erase();
- }
- /*!
- * \brief move current location
- *
- * Move the current location to the absolute screen coordinate <b>x,y.</b>
- * Nothing is drawn on the screen.
- *
- * \param x
- * \param y
- * \return void
- */
- void R_pos_abs(double x, double y)
- {
- COM_Pos_abs(x, y);
- }
- /*!
- * \brief fill a box
- *
- * A box is drawn in the current color using the coordinates <b>x1,y1</b> and
- * <b>x2,y2</b> as opposite corners of the box. The current location is undefined
- * afterwards
- *
- * \param x1
- * \param y1
- * \param x2
- * \param y2
- * \return void
- */
- void R_box_abs(double x1, double y1, double x2, double y2)
- {
- COM_Box_abs(x1, y1, x2, y2);
- }
- /*!
- * \brief set text size
- *
- * Sets text pixel width and height to <b>width</b> and <b>height.</b>
- *
- * \param width
- * \param height
- * \return void
- */
- void R_text_size(double width, double height)
- {
- COM_Text_size(width, height);
- }
- void R_text_rotation(double rotation)
- {
- COM_Text_rotation(rotation);
- }
- /*!
- * \brief set clipping frame
- *
- * Subsequent drawing operations will be clipped to the screen frame
- * defined by <b>top, bottom, left, right.</b>
- *
- * \param t top
- * \param b bottom
- * \param l left
- * \param r right
- * \return void
- */
- void R_set_window(double t, double b, double l, double r)
- {
- COM_Set_window(t, b, l, r);
- }
- /*!
- * \brief get clipping frame
- *
- * Retrieve clipping frame
- *
- * \param t top
- * \param b bottom
- * \param l left
- * \param r right
- * \return void
- */
- void R_get_window(double *t, double *b, double *l, double *r)
- {
- return COM_Get_window(t, b, l, r);
- }
- /*!
- * \brief write text
- *
- * Writes <b>text</b> in the current color and font, at the current text
- * width and height, starting at the current screen location.
- *
- * \param sometext
- * \return void
- */
- void R_text(const char *text)
- {
- COM_Text(text);
- }
- /*!
- * \brief get text extents
- *
- * The extent of the area enclosing the <b>text</b>
- * is returned in the integer pointers <b>top, bottom, left</b>, and
- * <b>right.</b> No text is actually drawn. This is useful for capturing the
- * text extent so that the text location can be prepared with proper background
- * or border.
- *
- * \param sometext
- * \param t top
- * \param b bottom
- * \param l left
- * \param r right
- * \return void
- */
- void R_get_text_box(const char *text, double *t, double *b, double *l, double *r)
- {
- COM_Get_text_box(text, t, b, l, r);
- }
- /*!
- * \brief choose font
- *
- * Set current font to <b>font name</b>.
- *
- * \param name
- * \return void
- */
- void R_font(const char *name)
- {
- COM_Set_font(name);
- }
- void R_encoding(const char *name)
- {
- COM_Set_encoding(name);
- }
- void R_font_list(char ***list, int *count)
- {
- COM_Font_list(list, count);
- }
- void R_font_info(char ***list, int *count)
- {
- COM_Font_info(list, count);
- }
- void R_begin_scaled_raster(int mask, int src[2][2], double dst[2][2])
- {
- COM_begin_raster(mask, src, dst);
- }
- int R_scaled_raster(int n, int row,
- const unsigned char *red, const unsigned char *grn,
- const unsigned char *blu, const unsigned char *nul)
- {
- return COM_raster(n, row, red, grn, blu, nul);
- }
- void R_end_scaled_raster(void)
- {
- COM_end_raster();
- }
- void R_bitmap(int ncols, int nrows, int threshold, const unsigned char *buf)
- {
- COM_Bitmap(ncols, nrows, threshold, buf);
- }
- void R_begin(void)
- {
- COM_Begin();
- }
- void R_move(double x, double y)
- {
- COM_Move(x, y);
- }
- void R_cont(double x, double y)
- {
- COM_Cont(x, y);
- }
- void R_close(void)
- {
- COM_Close();
- }
- void R_stroke(void)
- {
- COM_Stroke();
- }
- void R_fill(void)
- {
- COM_Fill();
- }
- void R_point(double x, double y)
- {
- COM_Point(x, y);
- }
|