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>
48 static void init_cairo(
void);
49 static int ends_with(
const char *
string,
const char *suffix);
50 static void map_file(
void);
52 #if CAIRO_HAS_XLIB_XRENDER_SURFACE
53 static void init_xlib(
void)
63 cairo_surface_t *s1, *s2;
65 ca.dpy = XOpenDisplay(
NULL);
69 p = getenv(
"GRASS_RENDER_CAIRO_SCREEN");
70 if (!p || sscanf(p,
"%i", &scrn) != 1) {
71 G_debug(1,
"cairo: GRASS_RENDER_CAIRO_SCREEN=%s", p);
72 scrn = DefaultScreen(
ca.dpy);
75 p = getenv(
"GRASS_RENDER_CAIRO_VISUAL");
76 if (!p || sscanf(p,
"%lu", &xid) != 1) {
77 G_debug(1,
"cairo: GRASS_RENDER_CAIRO_VISUAL=%s", p);
78 xid = DefaultVisual(
ca.dpy, scrn)->visualid;
84 XGetVisualInfo(
ca.dpy, VisualIDMask | VisualScreenMask, &templ, &
count);
87 visual = vinfo[0].visual;
89 ca.screen = ScreenOfDisplay(
ca.dpy, scrn);
90 pix = XCreatePixmap(
ca.dpy, RootWindow(
ca.dpy, scrn), 1, 1, vinfo[0].depth);
91 s1 = cairo_xlib_surface_create(
ca.dpy, pix, visual, 1, 1);
92 s2 = cairo_surface_create_similar(s1, CAIRO_CONTENT_COLOR_ALPHA, 1, 1);
93 ca.format = cairo_xlib_surface_get_xrender_format(s2);
94 ca.depth = cairo_xlib_surface_get_depth(s2);
95 cairo_surface_destroy(s2);
96 cairo_surface_destroy(s1);
97 XFreePixmap(
ca.dpy, pix);
100 ca.win = XCreatePixmap(
ca.dpy, RootWindow(
ca.dpy, scrn),
ca.
width,
104 static void fini_xlib(
void)
106 XSetCloseDownMode(
ca.dpy, RetainTemporary);
107 XCloseDisplay(
ca.dpy);
111 static void init_file(
void)
115 #if CAIRO_HAS_XLIB_XRENDER_SURFACE
128 p = getenv(
"GRASS_RENDER_FILE");
129 if (!p || strlen(p) == 0)
131 G_debug(1,
"cairo: GRASS_RENDER_FILE=%s", p);
140 #if CAIRO_HAS_PNG_FUNCTIONS
144 #if CAIRO_HAS_PDF_SURFACE
148 #if CAIRO_HAS_PS_SURFACE
152 #if CAIRO_HAS_SVG_SURFACE
156 #if CAIRO_HAS_XLIB_XRENDER_SURFACE
170 #if CAIRO_HAS_XLIB_XRENDER_SURFACE
177 p = getenv(
"GRASS_RENDER_FILE_MAPPED");
178 do_map = p && strcmp(p,
"TRUE") == 0 && ends_with(
ca.
file_name,
".bmp");
179 G_debug(1,
"cairo: GRASS_RENDER_FILE_MAPPED=%d", do_map);
181 p = getenv(
"GRASS_RENDER_FILE_READ");
182 do_read = p && strcmp(p,
"TRUE") == 0;
183 G_debug(1,
"cairo: GRASS_RENDER_FILE_READ=%d", do_read);
186 do_read = do_map = 0;
196 if (do_read && do_map)
199 #if CAIRO_HAS_XLIB_XRENDER_SURFACE
215 if (!do_read && !is_vector) {
239 cairo_antialias_t antialias;
245 p = getenv(
"GRASS_RENDER_BACKGROUNDCOLOR");
247 unsigned int red, green, blue;
249 if (sscanf(p,
"%02x%02x%02x", &red, &green, &blue) == 3 ||
250 G_str_to_color(p, (
int *)&red, (
int *)&green, (
int *)&blue) == 1) {
257 G_debug(1,
"cairo: GRASS_RENDER_BACKGROUNDCOLOR=%s", p);
263 p = getenv(
"GRASS_RENDER_TRANSPARENT");
264 if (p && strcmp(p,
"TRUE") == 0)
268 G_debug(1,
"cairo: GRASS_RENDER_TRANSPARENT=%s", p ? p :
"FALSE");
270 antialias = CAIRO_ANTIALIAS_DEFAULT;
271 p = getenv(
"GRASS_RENDER_ANTIALIAS");
273 antialias = CAIRO_ANTIALIAS_DEFAULT;
275 antialias = CAIRO_ANTIALIAS_NONE;
277 antialias = CAIRO_ANTIALIAS_GRAY;
279 antialias = CAIRO_ANTIALIAS_SUBPIXEL;
280 G_debug(1,
"cairo: GRASS_RENDER_ANTIALIAS=%s", p ? p :
"FALSE");
284 cairo_set_antialias(
cairo, antialias);
304 G_debug(1,
"Cairo_Graph_close");
306 #if CAIRO_HAS_XLIB_XRENDER_SURFACE
308 XFlush(cairo_xlib_surface_get_display(
surface));
316 cairo_destroy(
cairo);
320 cairo_surface_destroy(
surface);
324 #if CAIRO_HAS_XLIB_XRENDER_SURFACE
330 static void init_cairo(
void)
339 surface = (cairo_surface_t *)cairo_image_surface_create_for_data(
342 #if CAIRO_HAS_PDF_SURFACE
344 surface = (cairo_surface_t *)cairo_pdf_surface_create(
348 #if CAIRO_HAS_PS_SURFACE
350 surface = (cairo_surface_t *)cairo_ps_surface_create(
354 #if CAIRO_HAS_SVG_SURFACE
356 surface = (cairo_surface_t *)cairo_svg_surface_create(
360 #if CAIRO_HAS_XLIB_XRENDER_SURFACE
363 (cairo_surface_t *)cairo_xlib_surface_create_with_xrender_format(
372 if (cairo_surface_status(
surface) != CAIRO_STATUS_SUCCESS)
374 " (width: %d, height: %d): %s"),
376 cairo_status_to_string(cairo_surface_status(
surface)));
382 static int ends_with(
const char *
string,
const char *suffix)
384 if (strlen(
string) < strlen(suffix))
387 return G_strcasecmp(suffix,
string + strlen(
string) - strlen(suffix)) == 0;
390 static void map_file(
void)
401 ptr = mmap(
NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, (off_t)0);
402 if (ptr == MAP_FAILED)
406 cairo_destroy(
cairo);
407 cairo_surface_destroy(
surface);
cairo_surface_t * surface
const char * Cairo_Graph_get_file(void)
Get render file.
int Cairo_Graph_set(void)
Initialize driver.
void Cairo_Graph_close(void)
Close driver.
GRASS cairo display driver - header file.
void Cairo_Erase(void)
Erase screen.
void cairo_read_xid(void)
void cairo_read_image(void)
void cairo_write_image(void)
#define DEFAULT_FILE_NAME
int G_str_to_color(const char *, int *, int *, int *)
Parse color string and set red,green,blue.
void G_free(void *)
Free allocated memory.
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
void void G_verbose_message(const char *,...) __attribute__((format(printf
int int G_strcasecmp(const char *, const char *)
String compare ignoring case (upper or lower)
int G_debug(int, const char *,...) __attribute__((format(printf