[planner: 8/32] libgnomecanvas: Fix building of GnomeCanvasLine copy




commit e40aad1d543a64caea9669e31a7d60a5876ca5fa
Author: Mart Raudsepp <leio gentoo org>
Date:   Sun Mar 21 13:05:28 2021 +0200

    libgnomecanvas: Fix building of GnomeCanvasLine copy
    
    GnomeCanvasLine got removed from evolution libgnomecanvas copy before all
    the necessary porting changes were complete.
    Adapt the older GnomeCanvasLine code to work with the newer imported
    libgnomecanvas, which fully works with GTK3.
    
    Among many other routine changes, the "fill_color_rgba" property is
    fully removed, as it uses GdkColormap. Planner code only uses the
    "fill_color" variant, so the unused property is removed instead of
    ported.

 src/libgnomecanvas/gnome-canvas-line.c | 166 +++++++++------------------------
 src/libgnomecanvas/gnome-canvas-line.h |   6 --
 2 files changed, 43 insertions(+), 129 deletions(-)
---
diff --git a/src/libgnomecanvas/gnome-canvas-line.c b/src/libgnomecanvas/gnome-canvas-line.c
index 20cde8a6..562368d6 100644
--- a/src/libgnomecanvas/gnome-canvas-line.c
+++ b/src/libgnomecanvas/gnome-canvas-line.c
@@ -35,10 +35,8 @@
 #include <config.h>
 #include <math.h>
 #include <string.h>
-#include <libart_lgpl/art_vpath.h>
-#include <libart_lgpl/art_svp.h>
-#include <libart_lgpl/art_svp_vpath.h>
-#include <libart_lgpl/art_svp_vpath_stroke.h>
+#include <cairo-gobject.h>
+#include "libgnomecanvas/gnome-canvas-line.h"
 #include "libgnomecanvas.h"
 
 #define noVERBOSE
@@ -65,7 +63,6 @@ enum {
        PROP_0,
        PROP_POINTS,
        PROP_FILL_COLOR,
-       PROP_FILL_COLOR_GDK,
        PROP_FILL_COLOR_RGBA,
        PROP_WIDTH_PIXELS,
        PROP_WIDTH_UNITS,
@@ -82,7 +79,7 @@ enum {
 
 static void gnome_canvas_line_class_init   (GnomeCanvasLineClass *class);
 static void gnome_canvas_line_init         (GnomeCanvasLine      *line);
-static void gnome_canvas_line_destroy      (GnomeCanvasItem      *object);
+static void gnome_canvas_line_dispose      (GnomeCanvasItem      *object);
 static void gnome_canvas_line_set_property (GObject              *object,
                                            guint                 param_id,
                                            const GValue         *value,
@@ -92,8 +89,8 @@ static void gnome_canvas_line_get_property (GObject              *object,
                                            GValue               *value,
                                            GParamSpec           *pspec);
 
-static void   gnome_canvas_line_update      (GnomeCanvasItem *item, gdouble *affine, ArtSVP *clip_path, gint 
flags);
-static void   gnome_canvas_line_draw        (GnomeCanvasItem *item, GdkDrawable *drawable,
+static void   gnome_canvas_line_update      (GnomeCanvasItem *item, const cairo_matrix_t *i2c, gint flags);
+static void   gnome_canvas_line_draw        (GnomeCanvasItem *item, cairo_t *cr,
                                             gint x, gint y, gint width, gint height);
 static GnomeCanvasItem *gnome_canvas_line_point  (GnomeCanvasItem *item, gdouble x, gdouble y,
                                             gint cx, gint cy);
@@ -153,12 +150,6 @@ gnome_canvas_line_class_init (GnomeCanvasLineClass *class)
                  g_param_spec_string ("fill_color", NULL, NULL,
                                       NULL,
                                       (G_PARAM_READABLE | G_PARAM_WRITABLE)));
-        g_object_class_install_property
-                (gobject_class,
-                 PROP_FILL_COLOR_GDK,
-                 g_param_spec_boxed ("fill_color_gdk", NULL, NULL,
-                                    GDK_TYPE_COLOR,
-                                    (G_PARAM_READABLE | G_PARAM_WRITABLE)));
         g_object_class_install_property
                 (gobject_class,
                  PROP_FILL_COLOR_RGBA,
@@ -181,14 +172,14 @@ gnome_canvas_line_class_init (GnomeCanvasLineClass *class)
                 (gobject_class,
                  PROP_CAP_STYLE,
                  g_param_spec_enum ("cap_style", NULL, NULL,
-                                    G_TYPE_UINT, /* XXX */
+                                    CAIRO_GOBJECT_TYPE_LINE_CAP,
                                     CAIRO_LINE_CAP_BUTT,
                                     (G_PARAM_READABLE | G_PARAM_WRITABLE)));
         g_object_class_install_property
                 (gobject_class,
                  PROP_JOIN_STYLE,
                  g_param_spec_enum ("join_style", NULL, NULL,
-                                    G_TYPE_UINT, /* XXX */
+                                    CAIRO_GOBJECT_TYPE_LINE_JOIN,
                                     CAIRO_LINE_JOIN_MITER,
                                     (G_PARAM_READABLE | G_PARAM_WRITABLE)));
         g_object_class_install_property
@@ -234,7 +225,7 @@ gnome_canvas_line_class_init (GnomeCanvasLineClass *class)
                                      -G_MAXDOUBLE, G_MAXDOUBLE, 0,
                                      (G_PARAM_READABLE | G_PARAM_WRITABLE)));
 
-       item_class->destroy = gnome_canvas_line_destroy;
+       item_class->dispose = gnome_canvas_line_dispose;
        item_class->update = gnome_canvas_line_update;
        item_class->draw = gnome_canvas_line_draw;
        item_class->point = gnome_canvas_line_point;
@@ -254,7 +245,7 @@ gnome_canvas_line_init (GnomeCanvasLine *line)
 }
 
 static void
-gnome_canvas_line_destroy (GnomeCanvasItem *object)
+gnome_canvas_line_dispose (GnomeCanvasItem *object)
 {
        GnomeCanvasLine *line;
 
@@ -263,7 +254,7 @@ gnome_canvas_line_destroy (GnomeCanvasItem *object)
 
        line = GNOME_CANVAS_LINE (object);
 
-       /* remember, destroy can be run multiple times! */
+       /* remember, dispose can be run multiple times! */
 
        if (line->coords)
                g_free (line->coords);
@@ -277,20 +268,8 @@ gnome_canvas_line_destroy (GnomeCanvasItem *object)
                g_free (line->last_coords);
        line->last_coords = NULL;
 
-       if (line->fill_svp)
-               art_svp_free (line->fill_svp);
-       line->fill_svp = NULL;
-
-       if (line->first_svp)
-               art_svp_free (line->first_svp);
-       line->first_svp = NULL;
-
-       if (line->last_svp)
-               art_svp_free (line->last_svp);
-       line->last_svp = NULL;
-
-       if (GNOME_CANVAS_ITEM_CLASS (parent_class)->destroy)
-               GNOME_CANVAS_ITEM_CLASS (parent_class)->destroy (object);
+       if (GNOME_CANVAS_ITEM_CLASS (parent_class)->dispose)
+               GNOME_CANVAS_ITEM_CLASS (parent_class)->dispose (object);
 }
 
 /* Computes the bounding box of the line, including its arrow points.  Assumes that the number of
@@ -319,10 +298,7 @@ get_bounds (GnomeCanvasLine *line, gdouble *bx1, gdouble *by1, gdouble *bx2, gdo
 
        /* Add possible over-estimate for wide lines */
 
-       if (line->width_pixels)
-               width = line->width / line->item.canvas->pixels_per_unit;
-       else
-               width = line->width;
+       width = line->width;
 
        x1 -= width;
        y1 -= width;
@@ -369,21 +345,25 @@ get_bounds (GnomeCanvasLine *line, gdouble *bx1, gdouble *by1, gdouble *bx2, gdo
  * not zero. Affine is the i2c transformation.
  */
 static void
-get_bounds_canvas (GnomeCanvasLine *line, gdouble *bx1, gdouble *by1, gdouble *bx2, gdouble *by2, gdouble 
affine[6])
+get_bounds_canvas (GnomeCanvasLine      *line,
+                   gdouble              *bx1,
+                   gdouble              *by1,
+                   gdouble              *bx2,
+                   gdouble              *by2,
+                   const cairo_matrix_t *i2c)
 {
        /* It would be possible to tighten the bounds somewhat by transforming the individual points before
           aggregating them into the bbox. But it hardly seems worth it. */
-       ArtDRect bbox_world;
-       ArtDRect bbox_canvas;
+       gdouble x1, x2, y1, y2;
 
-       get_bounds (line, &bbox_world.x0, &bbox_world.y0, &bbox_world.x1, &bbox_world.y1);
+       get_bounds (line, &x1, &y1, &x2, &y2);
+       gnome_canvas_matrix_transform_rect (i2c, &x1, &y1, &x2, &y2);
 
-       art_drect_affine_transform (&bbox_canvas, &bbox_world, affine);
        /* include 1 pixel of fudge */
-       *bx1 = bbox_canvas.x0 - 1;
-       *by1 = bbox_canvas.y0 - 1;
-       *bx2 = bbox_canvas.x1 + 1;
-       *by2 = bbox_canvas.y1 + 1;
+       *bx1 = floor (x1) - 1;
+       *by1 = floor (y1) - 1;
+       *bx2 = ceil (x2) + 1;
+       *by2 = ceil (y2) + 1;
 }
 
 /* Recalculates the arrow polygons for the line */
@@ -438,10 +418,7 @@ reconfigure_arrows (GnomeCanvasLine *line)
        if (!line->first_arrow && !line->last_arrow)
                return;
 
-       if (line->width_pixels)
-               width = line->width / line->item.canvas->pixels_per_unit;
-       else
-               width = line->width;
+       width = line->width;
 
        /* Add fudge value for better-looking results */
 
@@ -449,12 +426,6 @@ reconfigure_arrows (GnomeCanvasLine *line)
        shape_b = line->shape_b;
        shape_c = line->shape_c + width / 2.0;
 
-       if (line->width_pixels) {
-               shape_a /= line->item.canvas->pixels_per_unit;
-               shape_b /= line->item.canvas->pixels_per_unit;
-               shape_c /= line->item.canvas->pixels_per_unit;
-       }
-
        shape_a += 0.001;
        shape_b += 0.001;
        shape_c += 0.001;
@@ -558,9 +529,7 @@ gnome_canvas_line_set_property (GObject              *object,
        GnomeCanvasLine *line;
        GnomeCanvasPoints *points;
        GdkColor color = { 0, 0, 0, 0, };
-       GdkColor *pcolor;
        gboolean color_changed;
-       gint have_pixel;
 
        g_return_if_fail (object != NULL);
        g_return_if_fail (GNOME_IS_CANVAS_LINE (object));
@@ -569,7 +538,6 @@ gnome_canvas_line_set_property (GObject              *object,
        line = GNOME_CANVAS_LINE (object);
 
        color_changed = FALSE;
-       have_pixel = FALSE;
 
        switch (param_id) {
        case PROP_POINTS:
@@ -616,25 +584,6 @@ gnome_canvas_line_set_property (GObject              *object,
                color_changed = TRUE;
                break;
 
-       case PROP_FILL_COLOR_GDK:
-               pcolor = g_value_get_boxed (value);
-               if (pcolor) {
-                       GdkColormap *colormap;
-                       color = *pcolor;
-
-                       colormap = gtk_widget_get_colormap (GTK_WIDGET (item->canvas));
-                       gdk_rgb_find_color (colormap, &color);
-
-                       have_pixel = TRUE;
-               }
-
-               line->fill_rgba = ((color.red & 0xff00) << 16 |
-                                  (color.green & 0xff00) << 8 |
-                                  (color.blue & 0xff00) |
-                                  0xff);
-               color_changed = TRUE;
-               break;
-
        case PROP_FILL_COLOR_RGBA:
                line->fill_rgba = g_value_get_uint (value);
                color_changed = TRUE;
@@ -700,22 +649,8 @@ gnome_canvas_line_set_property (GObject              *object,
                break;
        }
 
-       if (color_changed) {
-               if (have_pixel)
-                       line->fill_pixel = color.pixel;
-               else
-                       line->fill_pixel = gnome_canvas_get_color_pixel (item->canvas,
-                                                                        line->fill_rgba);
-
-               gnome_canvas_item_request_redraw_svp (item, line->fill_svp);
-
-               if (line->first_svp)
-                       gnome_canvas_item_request_redraw_svp (item, line->first_svp);
-
-               if (line->last_svp)
-                       gnome_canvas_item_request_redraw_svp (item, line->last_svp);
-
-       }
+       if (color_changed)
+               gnome_canvas_request_redraw (item->canvas, item->x1, item->y1, item->x2, item->y2);
 }
 
 /* Returns a copy of the line's points without the endpoint adjustments for
@@ -786,16 +721,6 @@ gnome_canvas_line_get_property (GObject              *object,
                                     (line->fill_rgba >> 8) & 0xff));
                break;
 
-       case PROP_FILL_COLOR_GDK: {
-               GnomeCanvas *canvas = GNOME_CANVAS_ITEM (line)->canvas;
-               GdkColormap *colormap = gtk_widget_get_colormap (GTK_WIDGET (canvas));
-               GdkColor color;
-
-               gdk_colormap_query_color (colormap, line->fill_pixel, &color);
-               g_value_set_boxed (value, &color);
-               break;
-       }
-
        case PROP_FILL_COLOR_RGBA:
                g_value_set_uint (value, line->fill_rgba);
                break;
@@ -851,7 +776,7 @@ gnome_canvas_line_get_property (GObject              *object,
 }
 
 static void
-gnome_canvas_line_update (GnomeCanvasItem *item, gdouble *affine, ArtSVP *clip_path, gint flags)
+gnome_canvas_line_update (GnomeCanvasItem *item, const cairo_matrix_t *i2c, gint flags)
 {
        GnomeCanvasLine *line;
        gdouble x1, y1, x2, y2;
@@ -859,12 +784,12 @@ gnome_canvas_line_update (GnomeCanvasItem *item, gdouble *affine, ArtSVP *clip_p
        line = GNOME_CANVAS_LINE (item);
 
        if (parent_class->update)
-               (* parent_class->update) (item, affine, clip_path, flags);
+               (* parent_class->update) (item, i2c, flags);
 
        reconfigure_arrows (line);
 
-        get_bounds_canvas (line, &x1, &y1, &x2, &y2, affine);
-        gnome_canvas_update_bbox (item, x1, y1, x2, y2);
+       get_bounds_canvas (line, &x1, &y1, &x2, &y2, i2c);
+       gnome_canvas_update_bbox (item, x1, y1, x2, y2);
 }
 
 static void
@@ -916,7 +841,7 @@ item_to_canvas (GnomeCanvas *canvas, gdouble *item_coords, GdkPoint *canvas_coor
 }
 
 static void
-gnome_canvas_line_draw (GnomeCanvasItem *item, GdkDrawable *drawable,
+gnome_canvas_line_draw (GnomeCanvasItem *item, cairo_t *cr,
                        gint x, gint y, gint width, gint height)
 {
        GnomeCanvasLine *line;
@@ -924,7 +849,6 @@ gnome_canvas_line_draw (GnomeCanvasItem *item, GdkDrawable *drawable,
        GdkPoint *points;
        gint actual_num_points_drawn;
        cairo_matrix_t matrix;
-        cairo_t *cr;
         int i;
 
        line = GNOME_CANVAS_LINE (item);
@@ -932,21 +856,21 @@ gnome_canvas_line_draw (GnomeCanvasItem *item, GdkDrawable *drawable,
        if (line->num_points == 0)
                return;
 
-        cr = gdk_cairo_create (drawable);
+        cairo_save (cr);
         cairo_translate (cr, -x, -y);
 
         /* points are always centered */
         cairo_translate (cr, 0.5, 0.5);
 
         cairo_set_source_rgba (cr,
-                               ((line->fill_pixel >> 24) & 0xff) / 255.0,
-                               ((line->fill_pixel >> 16) & 0xff) / 255.0,
-                               ((line->fill_pixel >>  8) & 0xff) / 255.0,
-                               ((line->fill_pixel >>  0) & 0xff) / 255.0);
+                               ((line->fill_rgba >> 24) & 0xff) / 255.0,
+                               ((line->fill_rgba >> 16) & 0xff) / 255.0,
+                               ((line->fill_rgba >>  8) & 0xff) / 255.0,
+                               ((line->fill_rgba >>  0) & 0xff) / 255.0);
        if (line->width_pixels)
                 cairo_set_line_width (cr, (gint) line->width);
         else
-               cairo_set_line_width (cr, (gint) (line->width * line->item.canvas->pixels_per_unit + 0.5));
+               cairo_set_line_width (cr, (gint) (line->width + 0.5));
         if (line->first_arrow || line->last_arrow)
                 cairo_set_line_cap (cr, CAIRO_LINE_CAP_BUTT);
         else
@@ -993,6 +917,8 @@ gnome_canvas_line_draw (GnomeCanvasItem *item, GdkDrawable *drawable,
                         cairo_line_to (cr, points[i].x, points[i].y);
                 cairo_fill (cr);
        }
+
+  cairo_restore (cr);
 }
 
 static GnomeCanvasItem *
@@ -1031,13 +957,7 @@ gnome_canvas_line_point (GnomeCanvasItem *item, gdouble x, gdouble y,
         * pixel-wide lines can be pickedup as well).
         */
 
-       if (line->width_pixels)
-               width = line->width / item->canvas->pixels_per_unit;
-       else
-               width = line->width;
-
-       if (width < (1.0 / item->canvas->pixels_per_unit))
-               width = 1.0 / item->canvas->pixels_per_unit;
+       width = MAX(line->width, 1.0);
 
        changed_miter_to_bevel = 0;
 
diff --git a/src/libgnomecanvas/gnome-canvas-line.h b/src/libgnomecanvas/gnome-canvas-line.h
index 749478ff..5c548b89 100644
--- a/src/libgnomecanvas/gnome-canvas-line.h
+++ b/src/libgnomecanvas/gnome-canvas-line.h
@@ -101,12 +101,6 @@ struct _GnomeCanvasLine {
        gdouble *first_coords;  /* Array of points describing polygon for the first arrowhead */
        gdouble *last_coords;   /* Array of points describing polygon for the last arrowhead */
 
-       GdkGC *gc;              /* GC for drawing line */
-
-        ArtSVP *fill_svp;              /* The SVP for the outline shape */ /*AA*/
-       ArtSVP *first_svp;              /* The SVP for the first arrow */ /*AA*/
-       ArtSVP *last_svp;               /* The SVP for the last arrow */ /*AA*/
-
        gdouble width;          /* Width of the line */
 
        gdouble shape_a;                /* Distance from tip of arrowhead to center */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]