17 #if CAIRO_HAS_PS_SURFACE
20 #if CAIRO_HAS_PDF_SURFACE
21 #include <cairo-pdf.h>
23 #if CAIRO_HAS_SVG_SURFACE
24 #include <cairo-svg.h>
26 #if CAIRO_HAS_XLIB_XRENDER_SURFACE
27 #include <cairo-xlib.h>
28 #include <cairo-xlib-xrender.h>
34 #include <sys/types.h>
39 #if defined(USE_X11) && CAIRO_HAS_XLIB_SURFACE
42 #include <X11/Xutil.h>
62 static void init_cairo(
void);
63 static int ends_with(
const char *
string,
const char *suffix);
64 static void map_file(
void);
66 #if defined(USE_X11) && CAIRO_HAS_XLIB_SURFACE
67 static int init_xlib(
void)
82 p =
getenv(
"GRASS_CAIRO_DRAWABLE");
83 if (!p || sscanf(p,
"%li", &xid) != 1)
87 dpy = XOpenDisplay(
NULL);
91 p =
getenv(
"GRASS_CAIRO_VISUAL");
92 if (!p || sscanf(p,
"%li", &xid) != 1)
96 vinfo = XGetVisualInfo(dpy, VisualIDMask, &templ, &count);
99 visual = vinfo[0].visual;
102 (dpy, win, &root, &si, &si, &
width, &
height, &ui, &depth))
107 if (cairo_surface_status(
surface) != CAIRO_STATUS_SUCCESS)
122 static int init_file(
void)
134 p =
getenv(
"GRASS_CAIROFILE");
135 if (!p || strlen(p) == 0)
146 #if CAIRO_HAS_PNG_FUNCTIONS
150 #if CAIRO_HAS_PDF_SURFACE
154 #if CAIRO_HAS_PS_SURFACE
158 #if CAIRO_HAS_SVG_SURFACE
174 p =
getenv(
"GRASS_CAIRO_MAPPED");
175 do_map = p && strcmp(p,
"TRUE") == 0 && ends_with(
file_name,
".bmp");
177 p =
getenv(
"GRASS_CAIRO_READ");
178 do_read = p && strcmp(p,
"TRUE") == 0;
181 do_read = do_map = 0;
185 if (do_read && access(
file_name, 0) != 0)
189 (
"cairo: collecting to file: %s,\n GRASS_WIDTH=%d, GRASS_HEIGHT=%d",
192 if (do_read && do_map)
221 G_gisinit(
"Cairo driver");
225 p =
getenv(
"GRASS_BACKGROUNDCOLOR");
227 unsigned int red, green, blue;
229 if (sscanf(p,
"%02x%02x%02x", &red, &green, &blue) == 3) {
241 p =
getenv(
"GRASS_TRANSPARENT");
242 if (p && strcmp(p,
"TRUE") == 0)
247 p =
getenv(
"GRASS_AUTO_WRITE");
250 #if defined(USE_X11) && CAIRO_HAS_XLIB_SURFACE
251 p =
getenv(
"GRASS_CAIRO_DRAWABLE");
260 G_debug(1,
"Cairo_Graph_close");
265 cairo_destroy(
cairo);
269 cairo_surface_destroy(
surface);
274 static void init_cairo(
void)
284 (cairo_surface_t *) cairo_image_surface_create_for_data(
grid,
290 #if CAIRO_HAS_PDF_SURFACE
293 (cairo_surface_t *) cairo_pdf_surface_create(
file_name,
298 #if CAIRO_HAS_PS_SURFACE
301 (cairo_surface_t *) cairo_ps_surface_create(
file_name,
306 #if CAIRO_HAS_SVG_SURFACE
309 (cairo_surface_t *) cairo_svg_surface_create(
file_name,
319 if (cairo_surface_status(
surface) != CAIRO_STATUS_SUCCESS)
326 static int ends_with(
const char *
string,
const char *suffix)
328 if (strlen(
string) < strlen(suffix))
332 string + strlen(
string) - strlen(suffix)) == 0;
335 static void map_file(
void)
346 ptr = mmap(
NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, (off_t) 0);
347 if (ptr == MAP_FAILED)
351 cairo_destroy(
cairo);
352 cairo_surface_destroy(
surface);
int G_strcasecmp(const char *x, const char *y)
String compare ignoring case (upper or lower)
void G_free(void *buf)
Free allocated memory.
void Cairo_Graph_close(void)
void G_message(const char *msg,...)
Print a message to stderr.
int G_debug(int level, const char *msg,...)
Print debugging message.
#define DEFAULT_FILE_NAME
int G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.
int Cairo_Graph_set(int, char **)