]> git.cworth.org Git - grrobot/commitdiff
Update to 2020 main
authorKeith Packard <keithp@keithp.com>
Sat, 14 Mar 2020 05:09:46 +0000 (22:09 -0700)
committerKeith Packard <keithp@keithp.com>
Sat, 14 Mar 2020 05:09:46 +0000 (22:09 -0700)
Use librsvg instead of libsvg.
Use gdk_cairo_create instead of open-coding context creation.
Switch from CAIRO_FORMAT_ARGB32 to CAIRO_CONTENT_COLOR_ALPHA.

Surprisingly few changes required to bring this code forward seventeen
years...

Signed-off-by: Keith Packard <keithp@keithp.com>
configure.in
src/Makefile.am
src/grr_board_view.c
src/grr_icon.c
src/grr_icon.h

index 0761830d455ad55eb6b9928112ab84706eb3db9e..5c93e28f8ff8012386572666788fe0a6713d37e1 100644 (file)
@@ -18,7 +18,7 @@ AC_STDC_HEADERS
 
 dnl ===========================================================================
 
-PKG_CHECK_MODULES(GRROBOT, gtk+-2.0 libsvg-cairo librr cairo >= 0.1.1)
+PKG_CHECK_MODULES(GRROBOT, gtk+-2.0 librsvg-2.0 librr cairo >= 0.1.1)
 AC_SUBST(GRROBOT_CFLAGS)
 AC_SUBST(GRROBOT_LIBS)
 
index 93f7677081bcd5192e0534e8303f4e5ac3320ad4..1a4a29d4d566f4314ee477b21d02e388b18cf876 100644 (file)
@@ -14,4 +14,4 @@ grrobot_SOURCES = \
        grr_util.h
 
 INCLUDES = $(GRROBOT_CFLAGS) -DGRR_ICON_DIR=\"$(pkgdatadir)\"
-LDFLAGS = $(GRROBOT_LIBS)
+LIBS = $(GRROBOT_LIBS)
index fc46a2145bbf983781109582007a8d1b4cbd3b66..ca1d0e1414334b9192a4c802733af6f4cc951ea1 100644 (file)
@@ -1,6 +1,6 @@
 /* grr_board_view - GTK+ widget for displaying an rr_board
  *
- * Copyright © 2003 Carl Worth
+ * Copyright Â© 2003 Carl Worth
  *
  * Permission to use, copy, modify, distribute, and sell this software
  * and its documentation for any purpose is hereby granted without
@@ -31,7 +31,8 @@
 
 #include <cairo.h>
 #include <cairo-xlib.h>
-#include <svg-cairo.h>
+#include <librsvg/rsvg.h>
+#include <librsvg/rsvg-cairo.h>
 
 #include <gtk/gtkmain.h>
 #include <gtk/gtksignal.h>
@@ -354,17 +355,7 @@ grr_board_view_expose (GtkWidget      *widget,
     view = GRR_BOARD_VIEW (widget);
     board = view->board;
 
-    /* Unabstract X from GTK+ */
-    gdk_window_get_internal_paint_info (widget->window, &real_drawable, &x_off, &y_off);
-    dpy = gdk_x11_drawable_get_xdisplay (real_drawable);
-    drawable = gdk_x11_drawable_get_xid (real_drawable);
-
-    /* Ignore GTK+ and use Cairo for drawing. */
-    visual = GDK_VISUAL_XVISUAL (gdk_drawable_get_visual (real_drawable));
-    surface = cairo_xlib_surface_create (dpy, drawable, visual,
-                                        widget->allocation.width,
-                                        widget->allocation.height);
-    xrs = cairo_create (surface);
+    xrs = gdk_cairo_create (widget->window);
 
     new_cell_width = widget->allocation.width / view->board_width;
     if (new_cell_width == 0)
index fa76331a042a52b066d7bfea3ed5c70993d53b47..c273bd712ef450a69672453f766d7252a1c8df54 100644 (file)
@@ -1,6 +1,6 @@
 /* grrobot - Ricochet Robot using GTK+ and Xr
  *
- * Copyright © 2003 Carl Worth
+ * Copyright Â© 2003 Carl Worth
  *
  * Permission to use, copy, modify, distribute, and sell this software
  * and its documentation for any purpose is hereby granted without
@@ -127,35 +127,28 @@ grr_icon_create (char *name)
 static rr_status_t
 _grr_icon_init (grr_icon_t *icon, char *name)
 {
-    svg_cairo_status_t status;
     char *file, *buf;
     int buflen;
+    GError *error = NULL;
 
     icon->surface = NULL;
     icon->surface_width = 0;
     icon->surface_height = 0;
 
-    status = svg_cairo_create (&icon->svg_cairo);
-    if (status)
-       return RR_STATUS_NO_MEMORY;
-
     file = _grr_icon_find_file (name);
-
     if (file) {
-       status = svg_cairo_parse (icon->svg_cairo, file);
-       if (status == SVG_CAIRO_STATUS_SUCCESS) {
-           free (file);
-           return RR_STATUS_SUCCESS;
-       }
-       fprintf (stderr, "Error parsing SVG icon: %s\n", file);
-       free (file);
-    }
-
-    _grr_icon_find_buffer (name, &buf, &buflen);
-    status = svg_cairo_parse_buffer (icon->svg_cairo, buf, buflen);
-    if (status) {
-       fprintf (stderr, "Error parsing built-in SVG icon for: %s\n", name);
-       return RR_STATUS_PARSE_ERROR;
+           icon->rsvg = rsvg_handle_new_from_file(file, &error);
+           if (!icon->rsvg) {
+                   fprintf (stderr, "Error parsing SVG icon: %s\n", file);
+                   return RR_STATUS_PARSE_ERROR;
+           }
+    } else {
+           _grr_icon_find_buffer (name, &buf, &buflen);
+           icon->rsvg = rsvg_handle_new_from_data(buf, buflen, &error);
+           if (!icon->rsvg) {
+                   fprintf (stderr, "Error parsing built-in SVG icon for: %s\n", name);
+                   return RR_STATUS_PARSE_ERROR;
+           }
     }
     return RR_STATUS_SUCCESS;
 }
@@ -225,13 +218,13 @@ grr_icon_target_name (rr_target_t target)
 void
 grr_icon_draw (grr_icon_t *icon, cairo_t *xrs)
 {
-    svg_cairo_status_t status;
-
-    status =  svg_cairo_render (icon->svg_cairo, xrs);
+    rsvg_handle_render_cairo(icon->rsvg, xrs);
+#if 0
     if (status) {
        fprintf (stderr, "svg_cairo_render error\n");
        return;
     }
+#endif
 }
 
 void
@@ -246,7 +239,7 @@ grr_icon_predraw (grr_icon_t *icon, cairo_t *xrs, int width, int height)
        icon->surface_width = width;
        icon->surface_height = height;
        icon->surface = cairo_surface_create_similar (cairo_get_target (xrs),
-                                                     CAIRO_FORMAT_ARGB32,
+                                                     CAIRO_CONTENT_COLOR_ALPHA,
                                                      width, height);
     }
 
index ed16942f88d23cfdd76b3197e5c1f3428db2b4e0..10a954fa030f35dfd6ca299b9574f7c3d125c2e3 100644 (file)
@@ -1,6 +1,6 @@
 /* grrobot - Ricochet Robot using GTK+ and Xr
  *
- * Copyright © 2003 Carl Worth
+ * Copyright Â© 2003 Carl Worth
  *
  * Permission to use, copy, modify, distribute, and sell this software
  * and its documentation for any purpose is hereby granted without
 #define GRR_ICON_H
 
 #include <rr.h>
-#include <svg-cairo.h>
+#include <librsvg/rsvg.h>
+#include <librsvg/rsvg-cairo.h>
 
 typedef struct grr_icon {
-    svg_cairo_t *svg_cairo;
-
+    RsvgHandle *rsvg;
     cairo_surface_t *surface;
     int surface_width;
     int surface_height;