diff options
| author | su_v <suv-sf@users.sourceforge.net> | 2012-12-16 05:41:25 +0000 |
|---|---|---|
| committer | ~suv <suv-sf@users.sourceforge.net> | 2012-12-16 05:41:25 +0000 |
| commit | 7ec903c9898f872dbd9426ed7a62e1969fdb7be7 (patch) | |
| tree | a306139e829118a83516af02279c9eafd3440eaa /src/display | |
| parent | Hershey Text: whitespace; py: docstring, modeline; inx: fix attribute value (diff) | |
| parent | Translations.Spanish translation update by Lucas Vieites. (diff) | |
| download | inkscape-7ec903c9898f872dbd9426ed7a62e1969fdb7be7.tar.gz inkscape-7ec903c9898f872dbd9426ed7a62e1969fdb7be7.zip | |
merge from trunk (r11955)
(bzr r11687.1.3)
Diffstat (limited to 'src/display')
30 files changed, 427 insertions, 236 deletions
diff --git a/src/display/Makefile_insert b/src/display/Makefile_insert index cf211108f..abbd89a68 100644 --- a/src/display/Makefile_insert +++ b/src/display/Makefile_insert @@ -47,7 +47,6 @@ ink_common_sources += \ display/guideline.h \ display/nr-3dutils.cpp \ display/nr-3dutils.h \ - display/nr-arena-forward.h \ display/nr-filter-blend.cpp \ display/nr-filter-blend.h \ display/nr-filter-colormatrix.cpp \ @@ -107,6 +106,8 @@ ink_common_sources += \ display/sodipodi-ctrlrect.h \ display/sp-canvas.cpp \ display/sp-canvas.h \ + display/sp-canvas-item.h \ + display/sp-canvas-group.h \ display/sp-canvas-util.cpp \ display/sp-canvas-util.h \ display/sp-ctrlcurve.cpp \ diff --git a/src/display/canvas-arena.cpp b/src/display/canvas-arena.cpp index f0fd63ef4..8e25c1843 100644 --- a/src/display/canvas-arena.cpp +++ b/src/display/canvas-arena.cpp @@ -316,6 +316,18 @@ sp_canvas_arena_event (SPCanvasItem *item, GdkEvent *event) ret = sp_canvas_arena_send_event (arena, event); break; + case GDK_SCROLL: { + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + bool wheelzooms = prefs->getBool("/options/wheelzooms/value"); + bool ctrl = (event->scroll.state & GDK_CONTROL_MASK); + if ((ctrl && !wheelzooms) || (!ctrl && wheelzooms)) { + /* Zoom is emitted by the canvas as well, ignore here */ + return FALSE; + } + ret = sp_canvas_arena_send_event (arena, event); + break; + } + default: /* Just send event */ ret = sp_canvas_arena_send_event (arena, event); diff --git a/src/display/canvas-axonomgrid.cpp b/src/display/canvas-axonomgrid.cpp index d4e15f475..bfc6f27c4 100644 --- a/src/display/canvas-axonomgrid.cpp +++ b/src/display/canvas-axonomgrid.cpp @@ -2,7 +2,7 @@ * Authors: * Johan Engelen <j.b.c.engelen@alumnus.utwente.nl> * - * Copyright (C) 2006-2011 Authors + * Copyright (C) 2006-2012 Authors * Released under GNU GPL, read the file 'COPYING' for more information */ @@ -12,47 +12,37 @@ * smaller than 90 degrees (measured from horizontal, 0 degrees being a line extending * to the right). The x-axis will always have an angle between 0 and 90 degrees. */ + - /* - * TODO: - * THIS FILE AND THE HEADER FILE NEED CLEANING UP. PLEASE DO NOT HESISTATE TO DO SO. - */ - +#include <gtkmm/box.h> +#include <gtkmm/label.h> +#include <gtkmm/table.h> #include <glibmm/i18n.h> -#include "ui/widget/registered-widget.h" #include "display/canvas-axonomgrid.h" -#include "2geom/line.h" + +#include "ui/widget/registered-widget.h" #include "desktop.h" -#include "canvas-grid.h" #include "desktop-handles.h" #include "display/cairo-utils.h" #include "display/canvas-grid.h" #include "display/sp-canvas-util.h" +#include "display/sp-canvas.h" #include "document.h" -#include "helper/units.h" #include "inkscape.h" #include "preferences.h" #include "sp-namedview.h" #include "sp-object.h" #include "svg/svg-color.h" +#include "2geom/line.h" +#include "2geom/angle.h" #include "util/mathfns.h" -#include "xml/node-event-vector.h" #include "round.h" -#include "display/sp-canvas.h" +#include "helper/units.h" -#include <gtkmm/box.h> -#include <gtkmm/label.h> -#include <gtkmm/table.h> enum Dim3 { X=0, Y, Z }; -#ifndef M_PI -# define M_PI 3.14159265358979323846 -#endif - -static double deg_to_rad(double deg) { return deg*M_PI/180.0;} - /** * This function calls Cairo to render a line on a particular canvas buffer. * Coordinates are interpreted as SCREENcoordinates @@ -138,9 +128,9 @@ CanvasAxonomGrid::CanvasAxonomGrid (SPNamedView * nv, Inkscape::XML::Node * in_r angle_deg[Z] = prefs->getDouble("/options/grids/axonom/angle_z", 30.0); angle_deg[Y] = 0; - angle_rad[X] = deg_to_rad(angle_deg[X]); + angle_rad[X] = Geom::deg_to_rad(angle_deg[X]); tan_angle[X] = tan(angle_rad[X]); - angle_rad[Z] = deg_to_rad(angle_deg[Z]); + angle_rad[Z] = Geom::deg_to_rad(angle_deg[Z]); tan_angle[Z] = tan(angle_rad[Z]); snapper = new CanvasAxonomGridSnapper(this, &namedview->snap_manager, 0); @@ -251,17 +241,17 @@ CanvasAxonomGrid::readRepr() if ( (value = repr->attribute("gridanglex")) ) { angle_deg[X] = g_ascii_strtod(value, NULL); - if (angle_deg[X] < 1.0) angle_deg[X] = 1.0; + if (angle_deg[X] < 0.) angle_deg[X] = 0.; if (angle_deg[X] > 89.0) angle_deg[X] = 89.0; - angle_rad[X] = deg_to_rad(angle_deg[X]); + angle_rad[X] = Geom::deg_to_rad(angle_deg[X]); tan_angle[X] = tan(angle_rad[X]); } if ( (value = repr->attribute("gridanglez")) ) { angle_deg[Z] = g_ascii_strtod(value, NULL); - if (angle_deg[Z] < 1.0) angle_deg[Z] = 1.0; + if (angle_deg[Z] < 0.) angle_deg[Z] = 0.; if (angle_deg[Z] > 89.0) angle_deg[Z] = 89.0; - angle_rad[Z] = deg_to_rad(angle_deg[Z]); + angle_rad[Z] = Geom::deg_to_rad(angle_deg[Z]); tan_angle[Z] = tan(angle_rad[Z]); } @@ -477,8 +467,8 @@ CanvasAxonomGrid::Update (Geom::Affine const &affine, unsigned int /*flags*/) spacing_ylines = sw[Geom::X] /(tan_angle[X] + tan_angle[Z]); lyw = sw[Geom::Y]; - lxw_x = sw[Geom::X] / tan_angle[X]; - lxw_z = sw[Geom::X] / tan_angle[Z]; + lxw_x = Geom::are_near(tan_angle[X],0.) ? Geom::infinity() : sw[Geom::X] / tan_angle[X]; + lxw_z = Geom::are_near(tan_angle[Z],0.) ? Geom::infinity() : sw[Geom::X] / tan_angle[Z]; if (empspacing == 0) { scaled = true; @@ -526,8 +516,12 @@ CanvasAxonomGrid::Render (SPCanvasBuf *buf) for (gdouble y = xstart_y_sc; y < buf->rect.bottom(); y += lyw, xlinenum++) { gint const x0 = buf->rect.left(); gint const y0 = round(y); - gint const x1 = x0 + round( (buf->rect.bottom() - y) / tan_angle[X] ); - gint const y1 = buf->rect.bottom(); + gint x1 = x0 + round( (buf->rect.bottom() - y) / tan_angle[X] ); + gint y1 = buf->rect.bottom(); + if ( Geom::are_near(tan_angle[X],0.) ) { + x1 = buf->rect.right(); + y1 = y0; + } if (!scaled && (xlinenum % empspacing) != 0) { sp_caxonomgrid_drawline (buf, x0, y0, x1, y1, color); @@ -536,18 +530,21 @@ CanvasAxonomGrid::Render (SPCanvasBuf *buf) } } // lines starting from top side - gdouble const xstart_x_sc = buf->rect.left() + (lxw_x - (xstart_y_sc - buf->rect.top()) / tan_angle[X]) ; - xlinenum = xlinestart-1; - for (gdouble x = xstart_x_sc; x < buf->rect.right(); x += lxw_x, xlinenum--) { - gint const y0 = buf->rect.top(); - gint const y1 = buf->rect.bottom(); - gint const x0 = round(x); - gint const x1 = x0 + round( (y1 - y0) / tan_angle[X] ); - - if (!scaled && (xlinenum % empspacing) != 0) { - sp_caxonomgrid_drawline (buf, x0, y0, x1, y1, color); - } else { - sp_caxonomgrid_drawline (buf, x0, y0, x1, y1, _empcolor); + if (!Geom::are_near(tan_angle[X],0.)) + { + gdouble const xstart_x_sc = buf->rect.left() + (lxw_x - (xstart_y_sc - buf->rect.top()) / tan_angle[X]) ; + xlinenum = xlinestart-1; + for (gdouble x = xstart_x_sc; x < buf->rect.right(); x += lxw_x, xlinenum--) { + gint const y0 = buf->rect.top(); + gint const y1 = buf->rect.bottom(); + gint const x0 = round(x); + gint const x1 = x0 + round( (y1 - y0) / tan_angle[X] ); + + if (!scaled && (xlinenum % empspacing) != 0) { + sp_caxonomgrid_drawline (buf, x0, y0, x1, y1, color); + } else { + sp_caxonomgrid_drawline (buf, x0, y0, x1, y1, _empcolor); + } } } @@ -575,8 +572,12 @@ CanvasAxonomGrid::Render (SPCanvasBuf *buf) for (gdouble y = zstart_y_sc; y < buf->rect.bottom(); y += lyw, zlinenum++, next_y = y) { gint const x0 = buf->rect.left(); gint const y0 = round(y); - gint const x1 = x0 + round( (y - buf->rect.top() ) / tan_angle[Z] ); - gint const y1 = buf->rect.top(); + gint x1 = x0 + round( (y - buf->rect.top() ) / tan_angle[Z] ); + gint y1 = buf->rect.top(); + if ( Geom::are_near(tan_angle[Z],0.) ) { + x1 = buf->rect.right(); + y1 = y0; + } if (!scaled && (zlinenum % empspacing) != 0) { sp_caxonomgrid_drawline (buf, x0, y0, x1, y1, color); @@ -585,17 +586,20 @@ CanvasAxonomGrid::Render (SPCanvasBuf *buf) } } // draw lines from bottom-up - gdouble const zstart_x_sc = buf->rect.left() + (next_y - buf->rect.bottom()) / tan_angle[Z] ; - for (gdouble x = zstart_x_sc; x < buf->rect.right(); x += lxw_z, zlinenum++) { - gint const y0 = buf->rect.bottom(); - gint const y1 = buf->rect.top(); - gint const x0 = round(x); - gint const x1 = x0 + round(buf->rect.height() / tan_angle[Z] ); - - if (!scaled && (zlinenum % empspacing) != 0) { - sp_caxonomgrid_drawline (buf, x0, y0, x1, y1, color); - } else { - sp_caxonomgrid_drawline (buf, x0, y0, x1, y1, _empcolor); + if (!Geom::are_near(tan_angle[Z],0.)) + { + gdouble const zstart_x_sc = buf->rect.left() + (next_y - buf->rect.bottom()) / tan_angle[Z] ; + for (gdouble x = zstart_x_sc; x < buf->rect.right(); x += lxw_z, zlinenum++) { + gint const y0 = buf->rect.bottom(); + gint const y1 = buf->rect.top(); + gint const x0 = round(x); + gint const x1 = x0 + round(buf->rect.height() / tan_angle[Z] ); + + if (!scaled && (zlinenum % empspacing) != 0) { + sp_caxonomgrid_drawline (buf, x0, y0, x1, y1, color); + } else { + sp_caxonomgrid_drawline (buf, x0, y0, x1, y1, _empcolor); + } } } diff --git a/src/display/canvas-axonomgrid.h b/src/display/canvas-axonomgrid.h index 04919f947..0e24d3f56 100644 --- a/src/display/canvas-axonomgrid.h +++ b/src/display/canvas-axonomgrid.h @@ -2,9 +2,12 @@ #define CANVAS_AXONOMGRID_H /* - * Copyright (C) 2006-2007 Johan Engelen <johan@shouraizou.nl> + * Authors: + * Johan Engelen <j.b.c.engelen@alumnus.utwente.nl> * - */ + * Copyright (C) 2006-2012 Authors + * Released under GNU GPL, read the file 'COPYING' for more information + */ #include "line-snapper.h" #include "canvas-grid.h" @@ -15,7 +18,7 @@ struct SPNamedView; namespace Inkscape { namespace XML { - class Node; + class Node; }; class CanvasAxonomGrid : public CanvasGrid { @@ -36,6 +39,9 @@ public: bool scaled; /**< Whether the grid is in scaled mode */ +protected: + friend class CanvasAxonomGridSnapper; + Geom::Point ow; /**< Transformed origin by the affine for the zoom */ double lyw; /**< Transformed length y by the affine for the zoom */ double lxw_x; @@ -44,7 +50,6 @@ public: Geom::Point sw; /**< the scaling factors of the affine transform */ -protected: virtual Gtk::Widget * newSpecificWidget(); private: @@ -63,7 +68,7 @@ public: bool ThisSnapperMightSnap() const; Geom::Coord getSnapperTolerance() const; //returns the tolerance of the snapper in screen pixels (i.e. independent of zoom) - bool getSnapperAlwaysSnap() const; //if true, then the snapper will always snap, regardless of its tolerance + bool getSnapperAlwaysSnap() const; //if true, then the snapper will always snap, regardless of its tolerance private: LineList _getSnapLines(Geom::Point const &p) const; diff --git a/src/display/canvas-grid.cpp b/src/display/canvas-grid.cpp index 498958f08..329b621ae 100644 --- a/src/display/canvas-grid.cpp +++ b/src/display/canvas-grid.cpp @@ -14,6 +14,9 @@ */ #include <glibmm/i18n.h> +#include <gtkmm/box.h> +#include <gtkmm/label.h> +#include <gtkmm/table.h> #include "ui/widget/registered-widget.h" #include "desktop.h" @@ -37,10 +40,6 @@ #include "verbs.h" #include "display/sp-canvas.h" -#include <gtkmm/box.h> -#include <gtkmm/label.h> -#include <gtkmm/table.h> - using Inkscape::DocumentUndo; namespace Inkscape { @@ -275,9 +274,9 @@ CanvasGrid::NewGrid(SPNamedView * nv, Inkscape::XML::Node * repr, SPDocument * d switch (gridtype) { case GRID_RECTANGULAR: - return (CanvasGrid*) new CanvasXYGrid(nv, repr, doc); + return dynamic_cast<CanvasGrid*>(new CanvasXYGrid(nv, repr, doc)); case GRID_AXONOMETRIC: - return (CanvasGrid*) new CanvasAxonomGrid(nv, repr, doc); + return dynamic_cast<CanvasGrid*>(new CanvasAxonomGrid(nv, repr, doc)); } return NULL; @@ -351,12 +350,13 @@ CanvasGrid::newWidget() _rcb_enabled->setSlaveWidgets(slaves); // set widget values + _wr.setUpdating (true); _rcb_visible->setActive(visible); if (snapper != NULL) { _rcb_enabled->setActive(snapper->getEnabled()); _rcb_snap_visible_only->setActive(snapper->getSnapVisibleOnly()); } - + _wr.setUpdating (false); return dynamic_cast<Gtk::Widget *> (vbox); } @@ -366,7 +366,7 @@ CanvasGrid::on_repr_attr_changed(Inkscape::XML::Node *repr, gchar const *key, gc if (!data) return; - ((CanvasGrid*) data)->onReprAttrChanged(repr, key, oldval, newval, is_interactive); + (static_cast<CanvasGrid*>(data))->onReprAttrChanged(repr, key, oldval, newval, is_interactive); } bool CanvasGrid::isEnabled() @@ -735,7 +735,6 @@ _wr.setUpdating (true); new Inkscape::UI::Widget::RegisteredCheckButton( _("_Show dots instead of lines"), _("If set, displays dots at gridpoints instead of gridlines"), "dotted", _wr, false, repr, doc) ); -_wr.setUpdating (false); Gtk::Widget const *const widget_array[] = { 0, _rumg, @@ -775,6 +774,8 @@ _wr.setUpdating (false); _rcb_dotted->setActive(render_dotted); + _wr.setUpdating (false); + _rsu_ox->setProgrammatically = false; _rsu_oy->setProgrammatically = false; _rsu_sx->setProgrammatically = false; diff --git a/src/display/canvas-text.cpp b/src/display/canvas-text.cpp index ddc946d5d..fe60d9c65 100644 --- a/src/display/canvas-text.cpp +++ b/src/display/canvas-text.cpp @@ -58,9 +58,9 @@ sp_canvastext_get_type (void) static void sp_canvastext_class_init(SPCanvasTextClass *klass) { - SPCanvasItemClass *item_class = (SPCanvasItemClass *) klass; + SPCanvasItemClass *item_class = SP_CANVAS_ITEM_CLASS(klass); - parent_class_ct = (SPCanvasItemClass*)g_type_class_peek_parent (klass); + parent_class_ct = SP_CANVAS_ITEM_CLASS(g_type_class_peek_parent(klass)); item_class->destroy = sp_canvastext_destroy; item_class->update = sp_canvastext_update; diff --git a/src/display/curve.cpp b/src/display/curve.cpp index 1a788b59a..ae243853e 100644 --- a/src/display/curve.cpp +++ b/src/display/curve.cpp @@ -150,7 +150,7 @@ SPCurve::concat(GSList const *list) SPCurve *new_curve = new SPCurve(); for (GSList const *l = list; l != NULL; l = l->next) { - SPCurve *c = (SPCurve *) l->data; + SPCurve *c = static_cast<SPCurve *>(l->data); new_curve->_pathv.insert( new_curve->_pathv.end(), c->get_pathvector().begin(), c->get_pathvector().end() ); } diff --git a/src/display/drawing-context.h b/src/display/drawing-context.h index fb6662202..b8c4667c2 100644 --- a/src/display/drawing-context.h +++ b/src/display/drawing-context.h @@ -101,6 +101,8 @@ public: cairo_t *raw() { return _ct; } cairo_surface_t *rawTarget() { return cairo_get_group_target(_ct); } + DrawingSurface *surface() { return _surface; } // Needed to find scale in drawing-item.cpp + private: DrawingContext(cairo_t *ct, DrawingSurface *surface, bool destroy); diff --git a/src/display/drawing-item.cpp b/src/display/drawing-item.cpp index 0fb1f0018..1e6e44d6f 100644 --- a/src/display/drawing-item.cpp +++ b/src/display/drawing-item.cpp @@ -667,29 +667,24 @@ DrawingItem::clip(Inkscape::DrawingContext &ct, Geom::IntRect const &area) if (!_visible) return; if (!area.intersects(_bbox)) return; - // The item used as the clipping path itself has a clipping path. - // Render this item's clipping path onto a temporary surface, then composite it - // with the item using the IN operator - if (_clip) { - ct.pushAlphaGroup(); - { Inkscape::DrawingContext::Save save(ct); - ct.setSource(0,0,0,1); - _clip->clip(ct, area); - } - ct.pushAlphaGroup(); - } - + ct.setSource(0,0,0,1); + ct.pushGroup(); // rasterize the clipping path _clipItem(ct, area); - if (_clip) { + // The item used as the clipping path itself has a clipping path. + // Render this item's clipping path onto a temporary surface, then composite it + // with the item using the IN operator + ct.pushGroup(); + _clip->clip(ct, area); ct.popGroupToSource(); ct.setOperator(CAIRO_OPERATOR_IN); ct.paint(); - ct.popGroupToSource(); - ct.setOperator(CAIRO_OPERATOR_SOURCE); - ct.paint(); } + ct.popGroupToSource(); + ct.setOperator(CAIRO_OPERATOR_OVER); + ct.paint(); + ct.setSource(0,0,0,0); } /** diff --git a/src/display/drawing-shape.cpp b/src/display/drawing-shape.cpp index 4ca306092..e80f12486 100644 --- a/src/display/drawing-shape.cpp +++ b/src/display/drawing-shape.cpp @@ -167,7 +167,7 @@ DrawingShape::_renderItem(DrawingContext &ct, Geom::IntRect const &area, unsigne { Inkscape::DrawingContext::Save save(ct); ct.setSource(rgba); ct.setLineWidth(0.5); - ct.setTolerance(1.25); + ct.setTolerance(0.5); ct.stroke(); } } else { diff --git a/src/display/drawing-text.cpp b/src/display/drawing-text.cpp index 7f63c555a..2a6505c67 100644 --- a/src/display/drawing-text.cpp +++ b/src/display/drawing-text.cpp @@ -162,7 +162,7 @@ unsigned DrawingText::_renderItem(DrawingContext &ct, Geom::IntRect const &/*are guint32 rgba = _drawing.outlinecolor; Inkscape::DrawingContext::Save save(ct); ct.setSource(rgba); - ct.setTolerance(1.25); // low quality, but good enough for outline mode + ct.setTolerance(0.5); // low quality, but good enough for outline mode for (ChildrenList::iterator i = _children.begin(); i != _children.end(); ++i) { DrawingGlyphs *g = dynamic_cast<DrawingGlyphs *>(&*i); diff --git a/src/display/drawing.cpp b/src/display/drawing.cpp index 77f24caf3..171cc014f 100644 --- a/src/display/drawing.cpp +++ b/src/display/drawing.cpp @@ -4,8 +4,9 @@ *//* * Authors: * Krzysztof KosiĆski <tweenk.pl@gmail.com> + * Johan Engelen <j.b.c.engelen@alumnus.utwente.nl> * - * Copyright (C) 2011 Authors + * Copyright (C) 2011-2012 Authors * Released under GNU GPL, read the file 'COPYING' for more information */ @@ -14,6 +15,12 @@ #include "nr-filter-gaussian.h" #include "nr-filter-types.h" +//grayscale colormode: +#include "nr-filter-colormatrix.h" +#include "cairo-templates.h" +#include "drawing-context.h" + + namespace Inkscape { Drawing::Drawing(SPCanvasArena *arena) @@ -145,12 +152,37 @@ Drawing::update(Geom::IntRect const &area, UpdateContext const &ctx, unsigned fl _pickItemsForCaching(); } +// hardcoded grayscale color matrix values. could be turned into preference settings in future. +static const gdouble grayscale_value_matrix[] = { + 0.21, 0.72, 0.072, 0, 0, + 0.21, 0.72, 0.072, 0, 0, + 0.21, 0.72, 0.072, 0, 0, + 0 , 0 , 0 , 1, 0 +}; +static Filters::FilterColorMatrix::ColorMatrixMatrix grayscale_colormatrix( + std::vector<gdouble> (grayscale_value_matrix, grayscale_value_matrix + sizeof(grayscale_value_matrix) / sizeof(grayscale_value_matrix[0]) ) +); + void Drawing::render(DrawingContext &ct, Geom::IntRect const &area, unsigned flags) { if (_root) { _root->render(ct, area, flags); } + + if (colorMode() == COLORMODE_GRAYSCALE) { + // apply grayscale filter on top of everything + cairo_surface_t *input = ct.rawTarget(); + cairo_surface_t *out = ink_cairo_surface_create_identical(input); + ink_cairo_surface_filter(input, out, grayscale_colormatrix); + Geom::Point origin = ct.targetLogicalBounds().min(); + ct.setSource(out, origin[Geom::X], origin[Geom::Y]); + ct.setOperator(CAIRO_OPERATOR_SOURCE); + ct.paint(); + ct.setOperator(CAIRO_OPERATOR_OVER); + + cairo_surface_destroy(out); + } } DrawingItem * diff --git a/src/display/guideline.cpp b/src/display/guideline.cpp index d3385978a..f71bc82ef 100644 --- a/src/display/guideline.cpp +++ b/src/display/guideline.cpp @@ -66,9 +66,9 @@ GType sp_guideline_get_type() static void sp_guideline_class_init(SPGuideLineClass *c) { - parent_class = (SPCanvasItemClass*) g_type_class_peek_parent(c); + parent_class = SP_CANVAS_ITEM_CLASS(g_type_class_peek_parent(c)); - SPCanvasItemClass *item_class = (SPCanvasItemClass *) c; + SPCanvasItemClass *item_class = SP_CANVAS_ITEM_CLASS(c); item_class->destroy = sp_guideline_destroy; item_class->update = sp_guideline_update; item_class->render = sp_guideline_render; @@ -191,8 +191,8 @@ static void sp_guideline_update(SPCanvasItem *item, Geom::Affine const &affine, { SPGuideLine *gl = SP_GUIDELINE(item); - if (((SPCanvasItemClass *) parent_class)->update) { - ((SPCanvasItemClass *) parent_class)->update(item, affine, flags); + if ((SP_CANVAS_ITEM_CLASS(parent_class))->update) { + (SP_CANVAS_ITEM_CLASS(parent_class))->update(item, affine, flags); } gl->affine = affine; diff --git a/src/display/nr-filter-colormatrix.cpp b/src/display/nr-filter-colormatrix.cpp index 33718ed68..fad6215ff 100644 --- a/src/display/nr-filter-colormatrix.cpp +++ b/src/display/nr-filter-colormatrix.cpp @@ -32,50 +32,47 @@ FilterPrimitive * FilterColorMatrix::create() { FilterColorMatrix::~FilterColorMatrix() {} -struct ColorMatrixMatrix { - ColorMatrixMatrix(std::vector<double> const &values) { - unsigned limit = std::min(static_cast<size_t>(20), values.size()); - for (unsigned i = 0; i < limit; ++i) { - if (i % 5 == 4) { - _v[i] = round(values[i]*255*255); - } else { - _v[i] = round(values[i]*255); - } - } - for (unsigned i = limit; i < 20; ++i) { - _v[i] = 0; +FilterColorMatrix::ColorMatrixMatrix::ColorMatrixMatrix(std::vector<double> const &values) { + unsigned limit = std::min(static_cast<size_t>(20), values.size()); + for (unsigned i = 0; i < limit; ++i) { + if (i % 5 == 4) { + _v[i] = round(values[i]*255*255); + } else { + _v[i] = round(values[i]*255); } } + for (unsigned i = limit; i < 20; ++i) { + _v[i] = 0; + } +} - guint32 operator()(guint32 in) { - EXTRACT_ARGB32(in, a, r, g, b) - // we need to un-premultiply alpha values for this type of matrix - // TODO: unpremul can be ignored if there is an identity mapping on the alpha channel - if (a != 0) { - r = unpremul_alpha(r, a); - g = unpremul_alpha(g, a); - b = unpremul_alpha(b, a); - } - - gint32 ro = r*_v[0] + g*_v[1] + b*_v[2] + a*_v[3] + _v[4]; - gint32 go = r*_v[5] + g*_v[6] + b*_v[7] + a*_v[8] + _v[9]; - gint32 bo = r*_v[10] + g*_v[11] + b*_v[12] + a*_v[13] + _v[14]; - gint32 ao = r*_v[15] + g*_v[16] + b*_v[17] + a*_v[18] + _v[19]; - ro = (pxclamp(ro, 0, 255*255) + 127) / 255; - go = (pxclamp(go, 0, 255*255) + 127) / 255; - bo = (pxclamp(bo, 0, 255*255) + 127) / 255; - ao = (pxclamp(ao, 0, 255*255) + 127) / 255; +guint32 FilterColorMatrix::ColorMatrixMatrix::operator()(guint32 in) { + EXTRACT_ARGB32(in, a, r, g, b) + // we need to un-premultiply alpha values for this type of matrix + // TODO: unpremul can be ignored if there is an identity mapping on the alpha channel + if (a != 0) { + r = unpremul_alpha(r, a); + g = unpremul_alpha(g, a); + b = unpremul_alpha(b, a); + } - ro = premul_alpha(ro, ao); - go = premul_alpha(go, ao); - bo = premul_alpha(bo, ao); + gint32 ro = r*_v[0] + g*_v[1] + b*_v[2] + a*_v[3] + _v[4]; + gint32 go = r*_v[5] + g*_v[6] + b*_v[7] + a*_v[8] + _v[9]; + gint32 bo = r*_v[10] + g*_v[11] + b*_v[12] + a*_v[13] + _v[14]; + gint32 ao = r*_v[15] + g*_v[16] + b*_v[17] + a*_v[18] + _v[19]; + ro = (pxclamp(ro, 0, 255*255) + 127) / 255; + go = (pxclamp(go, 0, 255*255) + 127) / 255; + bo = (pxclamp(bo, 0, 255*255) + 127) / 255; + ao = (pxclamp(ao, 0, 255*255) + 127) / 255; + + ro = premul_alpha(ro, ao); + go = premul_alpha(go, ao); + bo = premul_alpha(bo, ao); + + ASSEMBLE_ARGB32(pxout, ao, ro, go, bo) + return pxout; +} - ASSEMBLE_ARGB32(pxout, ao, ro, go, bo) - return pxout; - } -private: - gint32 _v[20]; -}; struct ColorMatrixSaturate { ColorMatrixSaturate(double v_in) { @@ -163,7 +160,7 @@ void FilterColorMatrix::render_cairo(FilterSlot &slot) switch (type) { case COLORMATRIX_MATRIX: - ink_cairo_surface_filter(input, out, ColorMatrixMatrix(values)); + ink_cairo_surface_filter(input, out, FilterColorMatrix::ColorMatrixMatrix(values)); break; case COLORMATRIX_SATURATE: ink_cairo_surface_filter(input, out, ColorMatrixSaturate(value)); diff --git a/src/display/nr-filter-colormatrix.h b/src/display/nr-filter-colormatrix.h index 5f21a4210..c7e5e91d9 100644 --- a/src/display/nr-filter-colormatrix.h +++ b/src/display/nr-filter-colormatrix.h @@ -42,6 +42,15 @@ public: virtual void set_type(FilterColorMatrixType type); virtual void set_value(gdouble value); virtual void set_values(std::vector<gdouble> const &values); + +public: + struct ColorMatrixMatrix { + ColorMatrixMatrix(std::vector<double> const &values); + guint32 operator()(guint32 in); + private: + gint32 _v[20]; + }; + private: std::vector<gdouble> values; gdouble value; diff --git a/src/display/nr-filter-composite.cpp b/src/display/nr-filter-composite.cpp index b25ecdf2c..040424cb3 100644 --- a/src/display/nr-filter-composite.cpp +++ b/src/display/nr-filter-composite.cpp @@ -48,10 +48,11 @@ struct ComposeArithmetic { gint32 go = _k1*ga*gb + _k2*ga + _k3*gb + _k4; gint32 bo = _k1*ba*bb + _k2*ba + _k3*bb + _k4; - ao = (pxclamp(ao, 0, 255*255*255) + (255*255/2)) / (255*255); - ro = (pxclamp(ro, 0, 255*255*255) + (255*255/2)) / (255*255); - go = (pxclamp(go, 0, 255*255*255) + (255*255/2)) / (255*255); - bo = (pxclamp(bo, 0, 255*255*255) + (255*255/2)) / (255*255); + ao = pxclamp(ao, 0, 255*255*255); // r, g and b are premultiplied, so should be clamped to the alpha channel + ro = (pxclamp(ro, 0, ao) + (255*255/2)) / (255*255); + go = (pxclamp(go, 0, ao) + (255*255/2)) / (255*255); + bo = (pxclamp(bo, 0, ao) + (255*255/2)) / (255*255); + ao = (ao + (255*255/2)) / (255*255); ASSEMBLE_ARGB32(pxout, ao, ro, go, bo) return pxout; diff --git a/src/display/nr-filter-flood.cpp b/src/display/nr-filter-flood.cpp index 449255133..56a27ecd7 100644 --- a/src/display/nr-filter-flood.cpp +++ b/src/display/nr-filter-flood.cpp @@ -55,11 +55,34 @@ void FilterFlood::render_cairo(FilterSlot &slot) #endif cairo_surface_t *out = ink_cairo_surface_create_same_size(input, CAIRO_CONTENT_COLOR_ALPHA); - cairo_t *ct = cairo_create(out); - cairo_set_source_rgba(ct, r, g, b, a); - cairo_set_operator(ct, CAIRO_OPERATOR_SOURCE); - cairo_paint(ct); - cairo_destroy(ct); + + // Get filter primitive area in user units + Geom::Rect fp = filter_primitive_area( slot.get_units() ); + + // Convert to Cairo units + Geom::Rect fp_cairo = fp * slot.get_units().get_matrix_user2pb(); + + // Get area in slot (tile to fill) + Geom::Rect sa = slot.get_slot_area(); + + // Get overlap + Geom::OptRect optoverlap = intersect( fp_cairo, sa ); + if( optoverlap ) { + + Geom::Rect overlap = *optoverlap; + + double dx = fp_cairo.min()[Geom::X] - sa.min()[Geom::X]; + double dy = fp_cairo.min()[Geom::Y] - sa.min()[Geom::Y]; + if( dx < 0.0 ) dx = 0.0; + if( dy < 0.0 ) dy = 0.0; + + cairo_t *ct = cairo_create(out); + cairo_set_source_rgba(ct, r, g, b, a); + cairo_set_operator(ct, CAIRO_OPERATOR_SOURCE); + cairo_rectangle(ct, dx, dy, overlap.width(), overlap.height() ); + cairo_fill(ct); + cairo_destroy(ct); + } slot.set(_output, out); cairo_surface_destroy(out); diff --git a/src/display/nr-filter-gaussian.cpp b/src/display/nr-filter-gaussian.cpp index 390021712..6ef321992 100644 --- a/src/display/nr-filter-gaussian.cpp +++ b/src/display/nr-filter-gaussian.cpp @@ -102,15 +102,16 @@ static inline Tt clip_round_cast(Ts const v) { Ts const minval = std::numeric_limits<Tt>::min(); Ts const maxval = std::numeric_limits<Tt>::max(); Tt const minval_rounded = std::numeric_limits<Tt>::min(); - Ts const maxval_rounded = std::numeric_limits<Tt>::max(); + Tt const maxval_rounded = std::numeric_limits<Tt>::max(); if ( v < minval ) return minval_rounded; if ( v > maxval ) return maxval_rounded; return round_cast<Tt>(v); } template<typename Tt, typename Ts> -static inline Tt clip_round_cast_varmax(Ts const v, Ts const maxval, Tt const maxval_rounded) { +static inline Tt clip_round_cast_varmax(Ts const v, Tt const maxval_rounded) { Ts const minval = std::numeric_limits<Tt>::min(); + Tt const maxval = maxval_rounded; Tt const minval_rounded = std::numeric_limits<Tt>::min(); if ( v < minval ) return minval_rounded; if ( v > maxval ) return maxval_rounded; @@ -339,7 +340,7 @@ filter2D_IIR(PT *const dest, int const dstr1, int const dstr2, dstimg -= dstr1; if ( PREMULTIPLIED_ALPHA ) { dstimg[alpha_PC] = clip_round_cast<PT>(v[0][alpha_PC]); - PREMUL_ALPHA_LOOP dstimg[c] = clip_round_cast_varmax<PT>(v[0][c], v[0][alpha_PC], dstimg[alpha_PC]); + PREMUL_ALPHA_LOOP dstimg[c] = clip_round_cast_varmax<PT>(v[0][c], dstimg[alpha_PC]); } else { for(unsigned int c=0; c<PC; c++) dstimg[c] = clip_round_cast<PT>(v[0][c]); } @@ -354,7 +355,7 @@ filter2D_IIR(PT *const dest, int const dstr1, int const dstr2, dstimg -= dstr1; if ( PREMULTIPLIED_ALPHA ) { dstimg[alpha_PC] = clip_round_cast<PT>(v[0][alpha_PC]); - PREMUL_ALPHA_LOOP dstimg[c] = clip_round_cast_varmax<PT>(v[0][c], v[0][alpha_PC], dstimg[alpha_PC]); + PREMUL_ALPHA_LOOP dstimg[c] = clip_round_cast_varmax<PT>(v[0][c], dstimg[alpha_PC]); } else { for(unsigned int c=0; c<PC; c++) dstimg[c] = clip_round_cast<PT>(v[0][c]); } diff --git a/src/display/nr-filter-image.cpp b/src/display/nr-filter-image.cpp index a9a5ec3e0..bc18cbcc6 100644 --- a/src/display/nr-filter-image.cpp +++ b/src/display/nr-filter-image.cpp @@ -20,6 +20,7 @@ #include "display/nr-filter-image.h" #include "display/nr-filter-slot.h" #include "display/nr-filter-units.h" +#include "enums.h" #include <glibmm/fileutils.h> namespace Inkscape { @@ -50,22 +51,31 @@ void FilterImage::render_cairo(FilterSlot &slot) //cairo_surface_t *input = slot.getcairo(_input); + // Viewport is filter primitive area (in user coordinates). + // Note: viewport calculation in non-trivial. Do not rely + // on get_matrix_primitiveunits2pb(). + Geom::Rect vp = filter_primitive_area( slot.get_units() ); + double feImageX = vp.min()[Geom::X]; + double feImageY = vp.min()[Geom::Y]; + double feImageWidth = vp.width(); + double feImageHeight = vp.height(); + + // feImage is suppose to use the same parameters as a normal SVG image. + // If a width or height is set to zero, the image is not suppose to be displayed. + // This does not seem to be what Firefox or Opera does, nor does the W3C displacement + // filter test expect this behavior. If the width and/or height are zero, we use + // the width and height of the object bounding box. Geom::Affine m = slot.get_units().get_matrix_user2filterunits().inverse(); Geom::Point bbox_00 = Geom::Point(0,0) * m; Geom::Point bbox_w0 = Geom::Point(1,0) * m; Geom::Point bbox_0h = Geom::Point(0,1) * m; double bbox_width = Geom::distance(bbox_00, bbox_w0); double bbox_height = Geom::distance(bbox_00, bbox_0h); - - // feImage is suppose to use the same parameters as a normal SVG image. - // If a width or height is set to zero, the image is not suppose to be displayed. - // This does not seem to be what Firefox or Opera does, nor does the W3C displacement - // filter test expect this behavior. If the width and/or height are zero, we use - // the width and height of the object bounding box. if( feImageWidth == 0 ) feImageWidth = bbox_width; if( feImageHeight == 0 ) feImageHeight = bbox_height; + // Internal image, like <use> if (from_element) { if (!SVGElem) return; @@ -87,18 +97,20 @@ void FilterImage::render_cairo(FilterSlot &slot) drawing.setRoot(ai); Geom::Rect area = *optarea; - Geom::Affine pu2pb = slot.get_units().get_matrix_primitiveunits2pb(); + Geom::Affine user2pb = slot.get_units().get_matrix_user2pb(); + /* FIXME: These variables are currently unused. Why were they calculated? double scaleX = feImageWidth / area.width(); double scaleY = feImageHeight / area.height(); + */ Geom::Rect sa = slot.get_slot_area(); cairo_surface_t *out = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, sa.width(), sa.height()); Inkscape::DrawingContext ct(out, sa.min()); - ct.transform(pu2pb); // we are now in primitive units + ct.transform(user2pb); // we are now in primitive units ct.translate(feImageX, feImageY); - ct.scale(scaleX, scaleY); +// ct.scale(scaleX, scaleY); No scaling should be done Geom::IntRect render_rect = area.roundOutwards(); ct.translate(render_rect.min()); @@ -113,6 +125,7 @@ void FilterImage::render_cairo(FilterSlot &slot) return; } + // External image, like <image> if (!image && !broken_ref) { broken_ref = true; try { @@ -158,9 +171,9 @@ void FilterImage::render_cairo(FilterSlot &slot) } // Native size of image - //width = image->get_width(); - //height = image->get_height(); - //rowstride = image->get_rowstride(); + // width = image->get_width(); + // height = image->get_height(); + // rowstride = image->get_rowstride(); convert_pixbuf_normal_to_argb32(image->gobj()); @@ -174,11 +187,94 @@ void FilterImage::render_cairo(FilterSlot &slot) cairo_t *ct = cairo_create(out); cairo_translate(ct, -sa.min()[Geom::X], -sa.min()[Geom::Y]); - // now ct is in pb coordinates - ink_cairo_transform(ct, slot.get_units().get_matrix_primitiveunits2pb()); + + // now ct is in pb coordinates, note the feWidth etc. are in user units + ink_cairo_transform(ct, slot.get_units().get_matrix_user2pb()); + // now ct is in the coordinates of feImageX etc. - // TODO: add preserveAspectRatio support here + // Now that we have the viewport, we must map image inside. + // Partially copied from sp-image.cpp. + + // Do nothing if preserveAspectRatio is "none". + if( aspect_align != SP_ASPECT_NONE ) { + + // Check aspect ratio of image vs. viewport + double feAspect = feImageHeight/feImageWidth; + double aspect = (double)image->get_height()/(double)image->get_width(); + bool ratio = (feAspect < aspect); + + double ax, ay; // Align side + switch( aspect_align ) { + case SP_ASPECT_XMIN_YMIN: + ax = 0.0; + ay = 0.0; + break; + case SP_ASPECT_XMID_YMIN: + ax = 0.5; + ay = 0.0; + break; + case SP_ASPECT_XMAX_YMIN: + ax = 1.0; + ay = 0.0; + break; + case SP_ASPECT_XMIN_YMID: + ax = 0.0; + ay = 0.5; + break; + case SP_ASPECT_XMID_YMID: + ax = 0.5; + ay = 0.5; + break; + case SP_ASPECT_XMAX_YMID: + ax = 1.0; + ay = 0.5; + break; + case SP_ASPECT_XMIN_YMAX: + ax = 0.0; + ay = 1.0; + break; + case SP_ASPECT_XMID_YMAX: + ax = 0.5; + ay = 1.0; + break; + case SP_ASPECT_XMAX_YMAX: + ax = 1.0; + ay = 1.0; + break; + default: + ax = 0.0; + ay = 0.0; + break; + } + + if( aspect_clip == SP_ASPECT_SLICE ) { + // image clipped by viewbox + + if( ratio ) { + // clip top/bottom + feImageY -= ay * (feImageWidth * aspect - feImageHeight); + feImageHeight = feImageWidth * aspect; + } else { + // clip sides + feImageX -= ax * (feImageHeight / aspect - feImageWidth); + feImageWidth = feImageHeight / aspect; + } + + } else { + // image fits into viewbox + + if( ratio ) { + // fit to height + feImageX += ax * (feImageWidth - feImageHeight / aspect ); + feImageWidth = feImageHeight / aspect; + } else { + // fit to width + feImageY += ay * (feImageHeight - feImageWidth * aspect); + feImageHeight = feImageWidth * aspect; + } + } + } double scaleX = feImageWidth / image->get_width(); double scaleY = feImageHeight / image->get_height(); @@ -204,6 +300,7 @@ double FilterImage::complexity(Geom::Affine const &) } void FilterImage::set_href(const gchar *href){ + if (feImageHref) g_free (feImageHref); feImageHref = (href) ? g_strdup (href) : NULL; @@ -218,13 +315,6 @@ void FilterImage::set_document(SPDocument *doc){ document = doc; } -void FilterImage::set_region(SVGLength x, SVGLength y, SVGLength width, SVGLength height) { - feImageX=x.computed; - feImageY=y.computed; - feImageWidth=width.computed; - feImageHeight=height.computed; -} - void FilterImage::set_align( unsigned int align ) { aspect_align = align; } diff --git a/src/display/nr-filter-image.h b/src/display/nr-filter-image.h index c0b9d6e81..05b7d65a8 100644 --- a/src/display/nr-filter-image.h +++ b/src/display/nr-filter-image.h @@ -35,7 +35,6 @@ public: void set_document( SPDocument *document ); void set_href(const gchar *href); - void set_region(SVGLength x, SVGLength y, SVGLength width, SVGLength height); void set_align( unsigned int align ); void set_clip( unsigned int clip ); bool from_element; diff --git a/src/display/nr-filter-merge.cpp b/src/display/nr-filter-merge.cpp index f1fbd7d33..759d7d6d1 100644 --- a/src/display/nr-filter-merge.cpp +++ b/src/display/nr-filter-merge.cpp @@ -31,7 +31,7 @@ FilterMerge::~FilterMerge() void FilterMerge::render_cairo(FilterSlot &slot) { - if (_input_image.size() == 0) return; + if (_input_image.empty()) return; // output is RGBA if at least one input is RGBA bool rgba32 = false; diff --git a/src/display/nr-filter-primitive.cpp b/src/display/nr-filter-primitive.cpp index c6bd8a74e..ce562668a 100644 --- a/src/display/nr-filter-primitive.cpp +++ b/src/display/nr-filter-primitive.cpp @@ -15,6 +15,12 @@ #include "display/nr-filter-types.h" #include "svg/svg-length.h" +#include "inkscape.h" +#include "desktop.h" +#include "desktop-handles.h" +#include "document.h" +#include "sp-root.h" + namespace Inkscape { namespace Filters { @@ -103,6 +109,18 @@ Geom::Rect FilterPrimitive::filter_primitive_area(FilterUnits const &units) Geom::OptRect bb = units.get_item_bbox(); Geom::OptRect fa = units.get_filter_area(); + // This is definitely a hack... but what else to do? + // Current viewport might not be document viewport... but how to find? + SPDocument* document = inkscape_active_document(); + SPRoot* root = document->getRoot(); + Geom::Rect viewport; + if( root->viewBox_set ) { + viewport = root->viewBox; + } else { + // Pick some random values + viewport = Geom::Rect::from_xywh(0,0,480,360); + } + /* Update computed values for ex, em, %. For %, assumes primitive unit is objectBoundingBox. */ /* TODO: fetch somehow the object ex and em lengths; 12, 6 are just dummy values. */ double len_x = bb->width(); @@ -144,11 +162,11 @@ Geom::Rect FilterPrimitive::filter_primitive_area(FilterUnits const &units) if( _subregion_y._set && _subregion_y.unit != SVGLength::PERCENT ) y = _subregion_y.computed; if( _subregion_width._set && _subregion_width.unit != SVGLength::PERCENT ) width = _subregion_width.computed; if( _subregion_height._set && _subregion_height.unit != SVGLength::PERCENT ) height = _subregion_height.computed; - // TODO: add percent of viewport TEMPORARY HACK FOR TESTING... - if( _subregion_x._set && _subregion_x.unit == SVGLength::PERCENT ) x = _subregion_x.value * 480; // viewport_x - if( _subregion_y._set && _subregion_y.unit == SVGLength::PERCENT ) y = _subregion_y.value * 360; - if( _subregion_width._set && _subregion_width.unit == SVGLength::PERCENT ) width = _subregion_width.value * 480; - if( _subregion_height._set && _subregion_height.unit == SVGLength::PERCENT ) height = _subregion_height.value * 360; + // Percent of viewport + if( _subregion_x._set && _subregion_x.unit == SVGLength::PERCENT ) x = _subregion_x.value * viewport.width(); + if( _subregion_y._set && _subregion_y.unit == SVGLength::PERCENT ) y = _subregion_y.value * viewport.height(); + if( _subregion_width._set && _subregion_width.unit == SVGLength::PERCENT ) width = _subregion_width.value * viewport.width(); + if( _subregion_height._set && _subregion_height.unit == SVGLength::PERCENT ) height = _subregion_height.value * viewport.height(); } Geom::Point minp, maxp; diff --git a/src/display/nr-filter-skeleton.cpp b/src/display/nr-filter-skeleton.cpp index 0c455a818..86ab8141e 100644 --- a/src/display/nr-filter-skeleton.cpp +++ b/src/display/nr-filter-skeleton.cpp @@ -42,7 +42,8 @@ FilterSkeleton::~FilterSkeleton() void FilterSkeleton::render_cairo(FilterSlot &slot) { cairo_surface_t *in = slot.getcairo(_input); cairo_surface_t *out = ink_cairo_surface_create_identical(in); - cairo_t *ct = cairo_create(out); + +// cairo_t *ct = cairo_create(out); // cairo_set_source_surface(ct, in, offset[X], offset[Y]); // cairo_paint(ct); diff --git a/src/display/nr-style.cpp b/src/display/nr-style.cpp index 86102f9e8..ba2340074 100644 --- a/src/display/nr-style.cpp +++ b/src/display/nr-style.cpp @@ -60,7 +60,9 @@ NRStyle::~NRStyle() { if (fill_pattern) cairo_pattern_destroy(fill_pattern); if (stroke_pattern) cairo_pattern_destroy(stroke_pattern); - if (dash) delete dash; + if (dash){ + delete [] dash; + } } void NRStyle::set(SPStyle *style) @@ -126,7 +128,9 @@ void NRStyle::set(SPStyle *style) } miter_limit = style->stroke_miterlimit.value; - if (dash) delete [] dash; + if (dash){ + delete [] dash; + } n_dash = style->stroke_dash.n_dash; if (n_dash != 0) { diff --git a/src/display/nr-svgfonts.cpp b/src/display/nr-svgfonts.cpp index e095fb9a9..d0c6d2d56 100644 --- a/src/display/nr-svgfonts.cpp +++ b/src/display/nr-svgfonts.cpp @@ -43,10 +43,9 @@ static cairo_user_data_key_t key; static cairo_status_t font_init_cb (cairo_scaled_font_t *scaled_font, - cairo_t */*cairo*/, cairo_font_extents_t *metrics){ - cairo_font_face_t* face; - face = cairo_scaled_font_get_font_face(scaled_font); - SvgFont* instance = (SvgFont*) cairo_font_face_get_user_data(face, &key); + cairo_t * /*cairo*/, cairo_font_extents_t *metrics){ + cairo_font_face_t* face = cairo_scaled_font_get_font_face(scaled_font); + SvgFont* instance = static_cast<SvgFont*>(cairo_font_face_get_user_data(face, &key)); return instance->scaled_font_init(scaled_font, metrics); } @@ -58,9 +57,8 @@ static cairo_status_t font_text_to_glyphs_cb ( cairo_scaled_font_t *scaled_font cairo_text_cluster_t **clusters, int *num_clusters, cairo_text_cluster_flags_t *flags){ - cairo_font_face_t* face; - face = cairo_scaled_font_get_font_face(scaled_font); - SvgFont* instance = (SvgFont*) cairo_font_face_get_user_data(face, &key); + cairo_font_face_t* face = cairo_scaled_font_get_font_face(scaled_font); + SvgFont* instance = static_cast<SvgFont*>(cairo_font_face_get_user_data(face, &key)); return instance->scaled_font_text_to_glyphs(scaled_font, utf8, utf8_len, glyphs, num_glyphs, clusters, num_clusters, flags); } @@ -68,9 +66,8 @@ static cairo_status_t font_render_glyph_cb (cairo_scaled_font_t *scaled_font, unsigned long glyph, cairo_t *cr, cairo_text_extents_t *metrics){ - cairo_font_face_t* face; - face = cairo_scaled_font_get_font_face(scaled_font); - SvgFont* instance = (SvgFont*) cairo_font_face_get_user_data(face, &key); + cairo_font_face_t* face = cairo_scaled_font_get_font_face(scaled_font); + SvgFont* instance = static_cast<SvgFont*>(cairo_font_face_get_user_data(face, &key)); return instance->scaled_font_render_glyph(scaled_font, glyph, cr, metrics); } @@ -116,15 +113,15 @@ unsigned int size_of_substring(const char* substring, gchar* str){ } //TODO: in these macros, verify what happens when using unicode strings. -#define Match_VKerning_Rule (((SPVkern*)node)->u1->contains(previous_unicode[0])\ - || ((SPVkern*)node)->g1->contains(previous_glyph_name)) &&\ - (((SPVkern*)node)->u2->contains(this->glyphs[i]->unicode[0])\ - || ((SPVkern*)node)->g2->contains(this->glyphs[i]->glyph_name.c_str())) +#define Match_VKerning_Rule ((SP_VKERN(node))->u1->contains(previous_unicode[0])\ + || (SP_VKERN(node))->g1->contains(previous_glyph_name)) &&\ + ((SP_VKERN(node))->u2->contains(this->glyphs[i]->unicode[0])\ + || (SP_VKERN(node))->g2->contains(this->glyphs[i]->glyph_name.c_str())) -#define Match_HKerning_Rule (((SPHkern*)node)->u1->contains(previous_unicode[0])\ - || ((SPHkern*)node)->g1->contains(previous_glyph_name)) &&\ - (((SPHkern*)node)->u2->contains(this->glyphs[i]->unicode[0])\ - || ((SPHkern*)node)->g2->contains(this->glyphs[i]->glyph_name.c_str())) +#define Match_HKerning_Rule ((SP_HKERN(node))->u1->contains(previous_unicode[0])\ + || (SP_HKERN(node))->g1->contains(previous_glyph_name)) &&\ + ((SP_HKERN(node))->u2->contains(this->glyphs[i]->unicode[0])\ + || (SP_HKERN(node))->g2->contains(this->glyphs[i]->glyph_name.c_str())) cairo_status_t SvgFont::scaled_font_text_to_glyphs (cairo_scaled_font_t */*scaled_font*/, @@ -187,14 +184,14 @@ SvgFont::scaled_font_text_to_glyphs (cairo_scaled_font_t */*scaled_font*/, for(SPObject* node = this->font->children;previous_unicode && node;node=node->next){ //apply glyph kerning if appropriate if (SP_IS_HKERN(node) && is_horizontal_text && Match_HKerning_Rule ){ - x -= (((SPHkern*)node)->k / 1000.0);//TODO: use here the height of the font + x -= ((SP_HKERN(node))->k / 1000.0);//TODO: use here the height of the font } if (SP_IS_VKERN(node) && !is_horizontal_text && Match_VKerning_Rule ){ - y -= (((SPVkern*)node)->k / 1000.0);//TODO: use here the "height" of the font + y -= ((SP_VKERN(node))->k / 1000.0);//TODO: use here the "height" of the font } } - previous_unicode = (char*) this->glyphs[i]->unicode.c_str();//used for kerning checking - previous_glyph_name = (char*) this->glyphs[i]->glyph_name.c_str();//used for kerning checking + previous_unicode = const_cast<char*>(this->glyphs[i]->unicode.c_str());//used for kerning checking + previous_glyph_name = const_cast<char*>(this->glyphs[i]->glyph_name.c_str());//used for kerning checking (*glyphs)[count].index = i; (*glyphs)[count].x = x; (*glyphs)[count++].y = y; @@ -251,7 +248,7 @@ Geom::PathVector SvgFont::flip_coordinate_system(SPFont* spfont, Geom::PathVector pathv){ double units_per_em = 1000; SPObject* obj; - for (obj = ((SPObject*) spfont)->children; obj; obj=obj->next){ + for (obj = (SP_OBJECT(spfont))->children; obj; obj=obj->next){ if (SP_IS_FONTFACE(obj)){ //XML Tree being directly used here while it shouldn't be. sp_repr_get_double(obj->getRepr(), "units_per_em", &units_per_em); @@ -282,16 +279,16 @@ SvgFont::scaled_font_render_glyph (cairo_scaled_font_t */*scaled_font*/, SPObject* node; if (glyph == this->glyphs.size()){ if (!this->missingglyph) return CAIRO_STATUS_SUCCESS; - node = (SPObject*) this->missingglyph; + node = SP_OBJECT(this->missingglyph); } else { - node = (SPObject*) this->glyphs[glyph]; + node = SP_OBJECT(this->glyphs[glyph]); } if (!SP_IS_GLYPH(node) && !SP_IS_MISSING_GLYPH(node)) { return CAIRO_STATUS_SUCCESS; // FIXME: is this the right code to return? } - SPFont* spfont = (SPFont*) node->parent; + SPFont* spfont = SP_FONT(node->parent); if (!spfont) { return CAIRO_STATUS_SUCCESS; // FIXME: is this the right code to return? } @@ -300,12 +297,12 @@ SvgFont::scaled_font_render_glyph (cairo_scaled_font_t */*scaled_font*/, // or using the d attribute of a glyph node. // pathv stores the path description from the d attribute: Geom::PathVector pathv; - if (SP_IS_GLYPH(node) && ((SPGlyph*)node)->d) { - pathv = sp_svg_read_pathv(((SPGlyph*)node)->d); + if (SP_IS_GLYPH(node) && (SP_GLYPH(node))->d) { + pathv = sp_svg_read_pathv((SP_GLYPH(node))->d); pathv = flip_coordinate_system(spfont, pathv); this->render_glyph_path(cr, &pathv); - } else if (SP_IS_MISSING_GLYPH(node) && ((SPMissingGlyph*)node)->d) { - pathv = sp_svg_read_pathv(((SPMissingGlyph*)node)->d); + } else if (SP_IS_MISSING_GLYPH(node) && (SP_MISSING_GLYPH(node))->d) { + pathv = sp_svg_read_pathv((SP_MISSING_GLYPH(node))->d); pathv = flip_coordinate_system(spfont, pathv); this->render_glyph_path(cr, &pathv); } @@ -314,7 +311,7 @@ SvgFont::scaled_font_render_glyph (cairo_scaled_font_t */*scaled_font*/, //render the SVG described on this glyph's child nodes. for(node = node->children; node; node=node->next){ if (SP_IS_PATH(node)){ - pathv = ((SPShape*)node)->_curve->get_pathvector(); + pathv = (SP_SHAPE(node))->_curve->get_pathvector(); pathv = flip_coordinate_system(spfont, pathv); this->render_glyph_path(cr, &pathv); } @@ -324,12 +321,12 @@ SvgFont::scaled_font_render_glyph (cairo_scaled_font_t */*scaled_font*/, if (SP_IS_USE(node)){ SPItem* item = SP_USE(node)->ref->getObject(); if (SP_IS_PATH(item)){ - pathv = ((SPShape*)item)->_curve->get_pathvector(); + pathv = (SP_SHAPE(item))->_curve->get_pathvector(); pathv = flip_coordinate_system(spfont, pathv); this->render_glyph_path(cr, &pathv); } - glyph_modified_connection = ((SPObject*) item)->connectModified(sigc::mem_fun(*this, &SvgFont::glyph_modified)); + glyph_modified_connection = (SP_OBJECT(item))->connectModified(sigc::mem_fun(*this, &SvgFont::glyph_modified)); } } } @@ -342,10 +339,10 @@ SvgFont::get_font_face(){ if (!this->userfont) { for(SPObject* node = this->font->children;node;node=node->next){ if (SP_IS_GLYPH(node)){ - this->glyphs.push_back((SPGlyph*)node); + this->glyphs.push_back(SP_GLYPH(node)); } if (SP_IS_MISSING_GLYPH(node)){ - this->missingglyph=(SPMissingGlyph*)node; + this->missingglyph=SP_MISSING_GLYPH(node); } } this->userfont = new UserFont(this); diff --git a/src/display/sodipodi-ctrl.cpp b/src/display/sodipodi-ctrl.cpp index e21bdff15..45dc38a37 100644 --- a/src/display/sodipodi-ctrl.cpp +++ b/src/display/sodipodi-ctrl.cpp @@ -63,10 +63,10 @@ sp_ctrl_get_type (void) static void sp_ctrl_class_init (SPCtrlClass *klass) { - SPCanvasItemClass *item_class = (SPCanvasItemClass *) klass; + SPCanvasItemClass *item_class = SP_CANVAS_ITEM_CLASS(klass); GObjectClass *g_object_class = (GObjectClass *) klass; - parent_class = (SPCanvasItemClass *)g_type_class_peek_parent (klass); + parent_class = SP_CANVAS_ITEM_CLASS(g_type_class_peek_parent (klass)); g_object_class->set_property = sp_ctrl_set_property; g_object_class->get_property = sp_ctrl_get_property; @@ -287,8 +287,8 @@ sp_ctrl_update (SPCanvasItem *item, Geom::Affine const &affine, unsigned int fla ctrl = SP_CTRL (item); - if (((SPCanvasItemClass *) parent_class)->update) - (* ((SPCanvasItemClass *) parent_class)->update) (item, affine, flags); + if ((SP_CANVAS_ITEM_CLASS(parent_class))->update) + (* (SP_CANVAS_ITEM_CLASS(parent_class))->update) (item, affine, flags); sp_canvas_item_reset_bounds (item); diff --git a/src/display/sodipodi-ctrlrect.cpp b/src/display/sodipodi-ctrlrect.cpp index b0c997a92..c350e4614 100644 --- a/src/display/sodipodi-ctrlrect.cpp +++ b/src/display/sodipodi-ctrlrect.cpp @@ -61,9 +61,9 @@ GType sp_ctrlrect_get_type() static void sp_ctrlrect_class_init(SPCtrlRectClass *c) { - SPCanvasItemClass *item_class = (SPCanvasItemClass *) c; + SPCanvasItemClass *item_class = SP_CANVAS_ITEM_CLASS(c); - parent_class = (SPCanvasItemClass*) g_type_class_peek_parent(c); + parent_class = SP_CANVAS_ITEM_CLASS(g_type_class_peek_parent(c)); item_class->destroy = sp_ctrlrect_destroy; item_class->update = sp_ctrlrect_update; @@ -119,8 +119,6 @@ void CtrlRect::render(SPCanvasBuf *buf) using Geom::X; using Geom::Y; - static double const dashes[2] = {4.0, 4.0}; - if (!_area) { return; } @@ -129,6 +127,7 @@ void CtrlRect::render(SPCanvasBuf *buf) area[X].max() + _shadow_size, area[Y].max() + _shadow_size); if ( area_w_shadow.intersects(buf->rect) ) { + static double const dashes[2] = {4.0, 4.0}; cairo_save(buf->ct); cairo_translate(buf->ct, -buf->rect.left(), -buf->rect.top()); cairo_set_line_width(buf->ct, 1); @@ -161,8 +160,8 @@ void CtrlRect::update(Geom::Affine const &affine, unsigned int flags) using Geom::X; using Geom::Y; - if (((SPCanvasItemClass *) parent_class)->update) { - ((SPCanvasItemClass *) parent_class)->update(this, affine, flags); + if ((SP_CANVAS_ITEM_CLASS(parent_class))->update) { + (SP_CANVAS_ITEM_CLASS(parent_class))->update(this, affine, flags); } sp_canvas_item_reset_bounds(this); diff --git a/src/display/sp-canvas.cpp b/src/display/sp-canvas.cpp index 6d4d01e33..536c54609 100644 --- a/src/display/sp-canvas.cpp +++ b/src/display/sp-canvas.cpp @@ -1081,7 +1081,7 @@ void SPCanvasGroup::update(SPCanvasItem *item, Geom::Affine const &affine, unsig Geom::OptRect bounds; for (GList *list = group->items; list; list = list->next) { - SPCanvasItem *i = (SPCanvasItem *)list->data; + SPCanvasItem *i = SP_CANVAS_ITEM(list->data); sp_canvas_item_invoke_update (i, affine, flags); @@ -1118,7 +1118,7 @@ double SPCanvasGroup::point(SPCanvasItem *item, Geom::Point p, SPCanvasItem **ac double dist = 0.0; for (GList *list = group->items; list; list = list->next) { - SPCanvasItem *child = (SPCanvasItem *)list->data; + SPCanvasItem *child = SP_CANVAS_ITEM(list->data); if ((child->x1 <= x2) && (child->y1 <= y2) && (child->x2 >= x1) && (child->y2 >= y1)) { SPCanvasItem *point_item = NULL; // cater for incomplete item implementations @@ -1152,7 +1152,7 @@ void SPCanvasGroup::render(SPCanvasItem *item, SPCanvasBuf *buf) SPCanvasGroup const *group = SP_CANVAS_GROUP(item); for (GList *list = group->items; list; list = list->next) { - SPCanvasItem *child = (SPCanvasItem *)list->data; + SPCanvasItem *child = SP_CANVAS_ITEM(list->data); if (child->visible) { if ((child->x1 < buf->rect.right()) && (child->y1 < buf->rect.bottom()) && @@ -1171,7 +1171,7 @@ void SPCanvasGroup::viewboxChanged(SPCanvasItem *item, Geom::IntRect const &new_ SPCanvasGroup *group = SP_CANVAS_GROUP(item); for (GList *list = group->items; list; list = list->next) { - SPCanvasItem *child = (SPCanvasItem *)list->data; + SPCanvasItem *child = SP_CANVAS_ITEM(list->data); if (child->visible) { if (SP_CANVAS_ITEM_GET_CLASS(child)->viewbox_changed) { SP_CANVAS_ITEM_GET_CLASS(child)->viewbox_changed(child, new_area); @@ -1649,7 +1649,6 @@ int SPCanvasImpl::emitEvent(SPCanvas *canvas, GdkEvent *event) int SPCanvasImpl::pickCurrentItem(SPCanvas *canvas, GdkEvent *event) { int button_down = 0; - double x, y; if (!canvas->root) // canvas may have already be destroyed by closing desktop durring interrupted display! return FALSE; @@ -1709,6 +1708,7 @@ int SPCanvasImpl::pickCurrentItem(SPCanvas *canvas, GdkEvent *event) // LeaveNotify means that there is no current item, so we don't look for one if (canvas->pick_event.type != GDK_LEAVE_NOTIFY) { // these fields don't have the same offsets in both types of events + double x, y; if (canvas->pick_event.type == GDK_ENTER_NOTIFY) { x = canvas->pick_event.crossing.x; diff --git a/src/display/sp-ctrlpoint.cpp b/src/display/sp-ctrlpoint.cpp index d07e9385b..026cc7589 100644 --- a/src/display/sp-ctrlpoint.cpp +++ b/src/display/sp-ctrlpoint.cpp @@ -52,9 +52,9 @@ sp_ctrlpoint_get_type (void) static void sp_ctrlpoint_class_init(SPCtrlPointClass *klass) { - SPCanvasItemClass *item_class = (SPCanvasItemClass *) klass; + SPCanvasItemClass *item_class = SP_CANVAS_ITEM_CLASS(klass); - parent_class = (SPCanvasItemClass*)g_type_class_peek_parent (klass); + parent_class = SP_CANVAS_ITEM_CLASS(g_type_class_peek_parent(klass)); item_class->destroy = sp_ctrlpoint_destroy; item_class->update = sp_ctrlpoint_update; diff --git a/src/display/sp-ctrlquadr.cpp b/src/display/sp-ctrlquadr.cpp index ae15d620a..b6a0da109 100644 --- a/src/display/sp-ctrlquadr.cpp +++ b/src/display/sp-ctrlquadr.cpp @@ -61,9 +61,9 @@ sp_ctrlquadr_get_type (void) static void sp_ctrlquadr_class_init (SPCtrlQuadrClass *klass) { - SPCanvasItemClass *item_class = (SPCanvasItemClass *) klass; + SPCanvasItemClass *item_class = SP_CANVAS_ITEM_CLASS(klass); - parent_class = (SPCanvasItemClass*)g_type_class_peek_parent (klass); + parent_class = SP_CANVAS_ITEM_CLASS(g_type_class_peek_parent(klass)); item_class->destroy = sp_ctrlquadr_destroy; item_class->update = sp_ctrlquadr_update; |
