123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580 |
- #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");
- int t = R_screen_top();
- int b = R_screen_bot();
- int l = R_screen_left();
- int r = R_screen_rite();
- R_font(font ? font : "romans");
- if (fenc)
- R_charset(fenc);
- 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, "PS") == 0) ? PS_Driver() :
- (p && G_strcasecmp(p, "HTML") == 0) ? HTML_Driver() :
- #ifdef USE_CAIRO
- (p && G_strcasecmp(p, "cairo") == 0) ? Cairo_Driver() :
- #endif
- PNG_Driver();
- LIB_init(drv, 0, NULL);
- init();
- COM_Client_Open();
- return 0;
- }
- void R__open_quiet(void)
- {
- }
- void R_stabilize(void)
- {
- COM_Respond();
- }
- void R_close_driver(void)
- {
- R_stabilize();
- COM_Client_Close();
- }
- void R_flush(void)
- {
- R_stabilize();
- }
- /*!
- * \brief screen left edge
- *
- * Returns the coordinate of the left edge of the screen.
- *
- * \param void
- * \return int
- */
- int R_screen_left(void)
- {
- int l;
- COM_Screen_left(&l);
- return l;
- }
- /*!
- * \brief screen right edge
- *
- * Returns the coordinate of the right edge of the screen.
- *
- * \param void
- * \return int
- */
- int R_screen_rite(void)
- {
- int r;
- COM_Screen_rite(&r);
- return r;
- }
- /*!
- * \brief bottom of screen
- *
- * Returns the coordinate of the bottom of the screen.
- *
- * \param void
- * \return int
- */
- int R_screen_bot(void)
- {
- int b;
- COM_Screen_bot(&b);
- return b;
- }
- /*!
- * \brief top of screen
- *
- * Returns the coordinate of the top of the screen.
- *
- * \param void
- * \return int
- */
- int R_screen_top(void)
- {
- int t;
- COM_Screen_top(&t);
- return t;
- }
- void R_get_num_colors(int *n)
- {
- COM_Number_of_colors(n);
- }
- /*!
- * \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 int
- */
- 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 int
- */
- void R_RGB_color(unsigned char red, unsigned char grn, unsigned char 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 int
- */
- void R_line_width(int width)
- {
- COM_Line_width(width);
- }
- /*!
- * \brief erase screen
- *
- * Erases the entire screen to black.
- *
- * \param void
- * \return int
- */
- 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 int
- */
- void R_move_abs(int x, int y)
- {
- COM_Move_abs(x, y);
- }
- /*!
- * \brief move current location
- *
- * Shift the current screen location by the values in <b>dx</b> and <b>dy</b>:
- \code
- Newx = Oldx + dx;
- Newy = Oldy + dy;
- \endcode
- * Nothing is drawn on the screen.
- *
- * \param x dx
- * \param y dy
- * \return int
- */
- void R_move_rel(int x, int y)
- {
- COM_Move_rel(x, y);
- }
- /*!
- * \brief draw line
- *
- * Draw a line using the current color, selected via <i>R_color</i>, from the
- * current location to the location specified by <b>x,y.</b> The current location
- * is updated to <b>x,y.</b>
- *
- * \param x
- * \param y
- * \return int
- */
- void R_cont_abs(int x, int y)
- {
- COM_Cont_abs(x, y);
- }
- /*!
- * \brief draw line
- *
- * Draw a line using the
- * current color, selected via <i>R_color</i>, from the current location to
- * the relative location specified by <b>x</b> and <b>y.</b> The current
- * location is updated:
- \code
- Newx = Oldx + x;
- Newy = Oldy + y;
- \endcode
- *
- * \param x
- * \param y
- * \return int
- */
- void R_cont_rel(int x, int y)
- {
- COM_Cont_rel(x, y);
- }
- /*!
- * \brief draw a series of dots
- *
- * Pixels at the <b>num</b> absolute positions in the <b>x</b> and
- * <b>y</b> arrays are turned to the current color. The current location is
- * left updated to the position of the last dot.
- *
- * \param xarray x
- * \param yarray y
- * \param number
- * \return int
- */
- void R_polydots_abs(const int *xarray, const int *yarray, int number)
- {
- COM_Polydots_abs(xarray, yarray, number);
- }
- /*!
- * \brief draw a series of dots
- *
- * Pixels at the <b>number</b> relative positions in the <b>x</b> and
- * <b>y</b> arrays are turned to the current color. The first position is
- * relative to the starting current location; the succeeding positions are then
- * relative to the previous position. The current location is updated to the
- * position of the last dot.
- *
- * \param xarray x
- * \param yarray y
- * \param number
- * \return int
- */
- void R_polydots_rel(const int *xarray, const int *yarray, int number)
- {
- COM_Polydots_rel(xarray, yarray, number);
- }
- /*!
- * \brief draw an open polygon
- *
- * The <b>number</b> absolute positions in the <b>x</b> and <b>y</b>
- * arrays are used to generate a multisegment line (often curved). This line is
- * drawn with the current color. The current location is left updated to the
- * position of the last point.
- * <b>Note.</b> It is not assumed that the line is closed, i.e., no line is
- * drawn from the last point to the first point.
- *
- * \param xarray x
- * \param yarray y
- * \param number
- * \return int
- */
- void R_polyline_abs(const int *xarray, const int *yarray, int number)
- {
- COM_Polyline_abs(xarray, yarray, number);
- }
- /*!
- * \brief draw an open polygon
- *
- * The <b>number</b> relative positions in the <b>x</b> and <b>y</b>
- * arrays are used to generate a multisegment line (often curved). The first
- * position is relative to the starting current location; the succeeding
- * positions are then relative to the previous position. The current location is
- * updated to the position of the last point. This line is drawn with the current
- * color.
- * <b>Note.</b> No line is drawn between the last point and the first point.
- *
- * \param xarray x
- * \param yarray y
- * \param number
- * \return int
- */
- void R_polyline_rel(const int *xarray, const int *yarray, int number)
- {
- COM_Polyline_rel(xarray, yarray, number);
- }
- /*!
- * \brief draw a closed polygon
- *
- * The <b>number</b> absolute positions in the <b>x</b> and <b>y</b> arrays
- * outline a closed polygon which is filled with the current color. The current
- * location is undefined afterwards.
- *
- * \param xarray x
- * \param yarray y
- * \param number
- * \return int
- */
- void R_polygon_abs(const int *xarray, const int *yarray, int number)
- {
- COM_Polygon_abs(xarray, yarray, number);
- }
- /*!
- * \brief draw a closed polygon
- *
- * The <b>number</b> relative positions in the <b>x</b> and <b>y</b>
- * arrays outline a closed polygon which is filled with the current color. The
- * first position is relative to the starting current location; the succeeding
- * positions are then relative to the previous position. The current location is
- * undefined afterwards.
- *
- * \param xarray x
- * \param yarray y
- * \param number
- * \return int
- */
- void R_polygon_rel(const int *xarray, const int *yarray, int number)
- {
- COM_Polygon_rel(xarray, yarray, number);
- }
- /*!
- * \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 int
- */
- void R_box_abs(int x1, int y1, int x2, int y2)
- {
- COM_Box_abs(x1, y1, x2, y2);
- }
- /*!
- * \brief fill a box
- *
- * A box is drawn in the current color using the current location as one corner
- * and the current location plus <b>x</b> and <b>y</b> as the opposite corner
- * of the box. The current location is undefined afterwards.
- *
- * \param x
- * \param y
- * \return int
- */
- void R_box_rel(int x, int y)
- {
- COM_Box_rel(x, y);
- }
- /*!
- * \brief set text size
- *
- * Sets text pixel width and height to <b>width</b> and <b>height.</b>
- *
- * \param width
- * \param height
- * \return int
- */
- void R_text_size(int width, int height)
- {
- COM_Text_size(width, height);
- }
- void R_text_rotation(float rotation)
- {
- COM_Text_rotation(rotation);
- }
- /*!
- * \brief set text clipping frame
- *
- * Subsequent calls to <i>R_text</i> will have text strings
- * 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 int
- */
- void R_set_window(int t, int b, int l, int r)
- {
- COM_Set_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 int
- */
- 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 int
- */
- void R_get_text_box(const char *text, int *t, int *b, int *l, int *r)
- {
- COM_Get_text_box(text, t, b, l, r);
- }
- /*!
- * \brief choose font
- *
- * Set current font to <b>font name</b>.
- *
- * \param name
- * \return int
- */
- void R_font(const char *name)
- {
- COM_Font_get(name);
- }
- void R_charset(const char *name)
- {
- COM_Font_init_charset(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], int dst[2][2])
- {
- COM_begin_scaled_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_scaled_raster(n, row, red, grn, blu, nul);
- }
- void R_end_scaled_raster(void)
- {
- COM_end_scaled_raster();
- }
- void R_bitmap(int ncols, int nrows, int threshold, const unsigned char *buf)
- {
- COM_Bitmap(ncols, nrows, threshold, buf);
- }
|