Code

Patch from codedread. Prevents rendering of title/desc/metadata elements in text...
[inkscape.git] / src / display / sp-ctrlline.cpp
index 6715f890fc0ebd215b6640e9f6164c5da1dc855c..f14eddfc2c0307bbb41026561ef1fefadfcc3d85 100644 (file)
@@ -5,7 +5,9 @@
  *
  * Author:
  *   Lauris Kaplinski <lauris@kaplinski.com>
+ *   Johan Engelen <j.b.c.engelen@ewi.utwente.nl>
  *
+ * Copyright (C) 2007 Johan Engelen
  * Copyright (C) 1999-2002 Lauris Kaplinski
  *
  * Released under GNU GPL
 #ifdef HAVE_CONFIG_H
 # include "config.h"
 #endif
-#include <livarot/Shape.h>
-#include <livarot/Path.h>
+#include <color.h>
+#include "display/inkscape-cairo.h"
 
-struct SPCtrlLine : public SPCanvasItem{
-    guint32 rgba;
-    NRPoint s, e;
-    Shape* shp;
-};
-
-struct SPCtrlLineClass : public SPCanvasItemClass{};
 
 static void sp_ctrlline_class_init (SPCtrlLineClass *klass);
 static void sp_ctrlline_init (SPCtrlLine *ctrlline);
@@ -81,8 +76,8 @@ static void
 sp_ctrlline_init (SPCtrlLine *ctrlline)
 {
     ctrlline->rgba = 0x0000ff7f;
-    ctrlline->s.x = ctrlline->s.y = ctrlline->e.x = ctrlline->e.y = 0.0;
-    ctrlline->shp=NULL;
+    ctrlline->s[NR::X] = ctrlline->s[NR::Y] = ctrlline->e[NR::X] = ctrlline->e[NR::Y] = 0.0;
+    ctrlline->item=NULL;
 }
 
 static void
@@ -93,10 +88,7 @@ sp_ctrlline_destroy (GtkObject *object)
 
     SPCtrlLine *ctrlline = SP_CTRLLINE (object);
 
-    if (ctrlline->shp) {
-        delete ctrlline->shp;
-        ctrlline->shp = NULL;
-    }
+    ctrlline->item=NULL;
 
     if (GTK_OBJECT_CLASS (parent_class)->destroy)
         (* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
@@ -105,25 +97,29 @@ sp_ctrlline_destroy (GtkObject *object)
 static void
 sp_ctrlline_render (SPCanvasItem *item, SPCanvasBuf *buf)
 {
-    SPCtrlLine *ctrlline = SP_CTRLLINE (item);
+    SPCtrlLine *cl = SP_CTRLLINE (item);
 
-    NRRectL  area;
-    area.x0=buf->rect.x0;
-    area.x1=buf->rect.x1;
-    area.y0=buf->rect.y0;
-    area.y1=buf->rect.y1;
+    if (!buf->ct)
+        return;
 
-    if (ctrlline->shp) {
-        sp_canvas_prepare_buffer (buf);
-        nr_pixblock_render_ctrl_rgba (ctrlline->shp,ctrlline->rgba,area,(char*)buf->buf, buf->buf_rowstride);
-    }
+    guint32 rgba = cl->rgba;
+    cairo_set_source_rgba(buf->ct, SP_RGBA32_B_F(rgba), SP_RGBA32_G_F(rgba), SP_RGBA32_R_F(rgba), SP_RGBA32_A_F(rgba));
+
+    cairo_set_line_width(buf->ct, 1);
+    cairo_new_path(buf->ct);
+
+    NR::Point s = cl->s * cl->affine;
+    NR::Point e = cl->e * cl->affine;
+
+    cairo_move_to (buf->ct, s[NR::X] - buf->rect.x0, s[NR::Y] - buf->rect.y0);
+    cairo_line_to (buf->ct, e[NR::X] - buf->rect.x0, e[NR::Y] - buf->rect.y0);
+
+    cairo_stroke(buf->ct);
 }
 
 static void
 sp_ctrlline_update (SPCanvasItem *item, NR::Matrix const &affine, unsigned int flags)
 {
-    NRRect dbox;
-
     SPCtrlLine *cl = SP_CTRLLINE (item);
 
     sp_canvas_request_redraw (item->canvas, (int)item->x1, (int)item->y1, (int)item->x2, (int)item->y2);
@@ -133,36 +129,15 @@ sp_ctrlline_update (SPCanvasItem *item, NR::Matrix const &affine, unsigned int f
 
     sp_canvas_item_reset_bounds (item);
 
-    dbox.x0=dbox.x1=dbox.y0=dbox.y1=0;
-    if (cl->shp) {
-        delete cl->shp;
-        cl->shp = NULL;
-    }
-    Path* thePath = new Path;
-    thePath->MoveTo(NR::Point(cl->s.x, cl->s.y) * affine);
-    thePath->LineTo(NR::Point(cl->e.x, cl->e.y) * affine);
-
-    thePath->Convert(1.0);
-    if ( cl->shp == NULL ) cl->shp=new Shape;
-    thePath->Stroke(cl->shp,false,0.5,join_straight,butt_straight,20.0,false);
-    cl->shp->CalcBBox();
-    if ( cl->shp->leftX < cl->shp->rightX ) {
-        if ( dbox.x0 >= dbox.x1 ) {
-            dbox.x0=cl->shp->leftX;dbox.x1=cl->shp->rightX;
-            dbox.y0=cl->shp->topY;dbox.y1=cl->shp->bottomY;
-        } else {
-            if ( cl->shp->leftX < dbox.x0 ) dbox.x0=cl->shp->leftX;
-            if ( cl->shp->rightX > dbox.x1 ) dbox.x1=cl->shp->rightX;
-            if ( cl->shp->topY < dbox.y0 ) dbox.y0=cl->shp->topY;
-            if ( cl->shp->bottomY > dbox.y1 ) dbox.y1=cl->shp->bottomY;
-        }
-    }
-    delete thePath;
+    cl->affine = affine;
+
+    NR::Point s = cl->s * affine;
+    NR::Point e = cl->e * affine;
 
-    item->x1 = (int)dbox.x0;
-    item->y1 = (int)dbox.y0;
-    item->x2 = (int)dbox.x1;
-    item->y2 = (int)dbox.y1;
+    item->x1 = (int)(MIN(s[NR::X], e[NR::X]) - 1);
+    item->y1 = (int)(MIN(s[NR::Y], e[NR::Y]) - 1);
+    item->x2 = (int)(MAX(s[NR::X], e[NR::X]) + 1);
+    item->y2 = (int)(MAX(s[NR::Y], e[NR::Y]) + 1);
 
     sp_canvas_request_redraw (item->canvas, (int)item->x1, (int)item->y1, (int)item->x2, (int)item->y2);
 }
@@ -190,11 +165,11 @@ sp_ctrlline_set_coords (SPCtrlLine *cl, gdouble x0, gdouble y0, gdouble x1, gdou
     g_return_if_fail (cl != NULL);
     g_return_if_fail (SP_IS_CTRLLINE (cl));
 
-    if (DIFFER (x0, cl->s.x) || DIFFER (y0, cl->s.y) || DIFFER (x1, cl->e.x) || DIFFER (y1, cl->e.y)) {
-        cl->s.x = x0;
-        cl->s.y = y0;
-        cl->e.x = x1;
-        cl->e.y = y1;
+    if (DIFFER (x0, cl->s[NR::X]) || DIFFER (y0, cl->s[NR::Y]) || DIFFER (x1, cl->e[NR::X]) || DIFFER (y1, cl->e[NR::Y])) {
+        cl->s[NR::X] = x0;
+        cl->s[NR::Y] = y0;
+        cl->e[NR::X] = x1;
+        cl->e[NR::Y] = y1;
         sp_canvas_item_request_update (SP_CANVAS_ITEM (cl));
     }
 }