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 static void init_xlib(
void)
54 #if CAIRO_HAS_XLIB_XRENDER_SURFACE 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,
"%li", &xid) != 1) {
77 G_debug(1,
"cairo: GRASS_RENDER_CAIRO_VISUAL=%s", p);
78 xid = DefaultVisual(
ca.dpy, scrn)->visualid;
83 vinfo = XGetVisualInfo(
ca.dpy, VisualIDMask|VisualScreenMask, &templ, &count);
86 visual = vinfo[0].visual;
88 ca.screen = ScreenOfDisplay(
ca.dpy, scrn);
89 pix = XCreatePixmap(
ca.dpy, RootWindow(
ca.dpy, scrn), 1, 1, vinfo[0].depth);
90 s1 = cairo_xlib_surface_create(
ca.dpy, pix, visual, 1, 1);
91 s2 = cairo_surface_create_similar(s1, CAIRO_CONTENT_COLOR_ALPHA, 1, 1);
92 ca.format = cairo_xlib_surface_get_xrender_format(s2);
93 ca.depth = cairo_xlib_surface_get_depth(s2);
94 cairo_surface_destroy(s2);
95 cairo_surface_destroy(s1);
96 XFreePixmap(
ca.dpy, pix);
99 ca.win = XCreatePixmap(
100 ca.dpy, RootWindow(
ca.dpy, scrn),
105 static void fini_xlib(
void)
107 #if CAIRO_HAS_XLIB_XRENDER_SURFACE 108 XSetCloseDownMode(
ca.dpy, RetainTemporary);
109 XCloseDisplay(
ca.dpy);
113 static void init_file(
void)
127 p =
getenv(
"GRASS_RENDER_FILE");
128 if (!p || strlen(p) == 0)
130 G_debug(1,
"cairo: GRASS_RENDER_FILE=%s", p);
139 #if CAIRO_HAS_PNG_FUNCTIONS 143 #if CAIRO_HAS_PDF_SURFACE 147 #if CAIRO_HAS_PS_SURFACE 151 #if CAIRO_HAS_SVG_SURFACE 155 #if CAIRO_HAS_XLIB_XRENDER_SURFACE 174 p =
getenv(
"GRASS_RENDER_FILE_MAPPED");
175 do_map = p && strcmp(p,
"TRUE") == 0 && ends_with(
ca.
file_name,
".bmp");
176 G_debug(1,
"cairo: GRASS_RENDER_FILE_MAPPED=%d", do_map);
178 p =
getenv(
"GRASS_RENDER_FILE_READ");
179 do_read = p && strcmp(p,
"TRUE") == 0;
180 G_debug(1,
"cairo: GRASS_RENDER_FILE_READ=%d", do_read);
183 do_read = do_map = 0;
195 if (do_read && do_map)
198 #if CAIRO_HAS_XLIB_XRENDER_SURFACE 214 if (!do_read && !is_vector) {
238 cairo_antialias_t antialias;
244 p =
getenv(
"GRASS_RENDER_BACKGROUNDCOLOR");
246 unsigned int red, green, blue;
248 if (sscanf(p,
"%02x%02x%02x", &red, &green, &blue) == 3 ||
249 G_str_to_color(p, (
int *)&red, (
int *)&green, (
int *)&blue) == 1) {
256 G_debug(1,
"cairo: GRASS_RENDER_BACKGROUNDCOLOR=%s", p);
262 p =
getenv(
"GRASS_RENDER_TRANSPARENT");
263 if (p && strcmp(p,
"TRUE") == 0)
267 G_debug(1,
"cairo: GRASS_RENDER_TRANSPARENT=%s", p ? p :
"FALSE");
269 antialias = CAIRO_ANTIALIAS_DEFAULT;
270 p =
getenv(
"GRASS_RENDER_ANTIALIAS");
272 antialias = CAIRO_ANTIALIAS_DEFAULT;
274 antialias = CAIRO_ANTIALIAS_NONE;
276 antialias = CAIRO_ANTIALIAS_GRAY;
278 antialias = CAIRO_ANTIALIAS_SUBPIXEL;
279 G_debug(1,
"cairo: GRASS_RENDER_ANTIALIAS=%s", p ? p :
"FALSE");
283 cairo_set_antialias(
cairo, antialias);
303 G_debug(1,
"Cairo_Graph_close");
305 #if CAIRO_HAS_XLIB_XRENDER_SURFACE 307 XFlush(cairo_xlib_surface_get_display(
surface));
315 cairo_destroy(
cairo);
319 cairo_surface_destroy(
surface);
323 #if CAIRO_HAS_XLIB_XRENDER_SURFACE 329 static void init_cairo(
void)
339 (cairo_surface_t *) cairo_image_surface_create_for_data(
342 #if CAIRO_HAS_PDF_SURFACE 345 (cairo_surface_t *) cairo_pdf_surface_create(
349 #if CAIRO_HAS_PS_SURFACE 352 (cairo_surface_t *) cairo_ps_surface_create(
356 #if CAIRO_HAS_SVG_SURFACE 359 (cairo_surface_t *) cairo_svg_surface_create(
363 #if CAIRO_HAS_XLIB_XRENDER_SURFACE 366 (cairo_surface_t *) cairo_xlib_surface_create_with_xrender_format(
375 if (cairo_surface_status(
surface) != CAIRO_STATUS_SUCCESS)
382 static int ends_with(
const char *
string,
const char *suffix)
384 if (strlen(
string) < strlen(suffix))
388 string + strlen(
string) - strlen(suffix)) == 0;
391 static void map_file(
void)
402 ptr = mmap(
NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, (off_t) 0);
403 if (ptr == MAP_FAILED)
407 cairo_destroy(
cairo);
408 cairo_surface_destroy(
surface);
void cairo_read_xid(void)
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
void Cairo_Graph_close(void)
Close driver.
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.
const char * Cairo_Graph_get_file(void)
Get render file.
cairo_surface_t * surface
int int G_strcasecmp(const char *, const char *)
String compare ignoring case (upper or lower)
int Cairo_Graph_set(void)
Initialize driver.
GRASS cairo display driver - header file.
void cairo_write_image(void)
void cairo_read_image(void)
#define DEFAULT_FILE_NAME
void Cairo_Erase(void)
Erase screen.
void void G_verbose_message(const char *,...) __attribute__((format(printf
int G_debug(int, const char *,...) __attribute__((format(printf