#include #include #include #include #include #include #include #include #include #include #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 color to be used in subsequent draw commands. The * color value is best retrieved using D_translate_color. * 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 R_color_table_float), this call selects the color * most closely matched to the red, grn, and blue 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 width 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 x,y. * 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 x1,y1 and * x2,y2 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 width and height. * * \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 top, bottom, left, right. * * \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 text 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 text * is returned in the integer pointers top, bottom, left, and * right. 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 font name. * * \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); }