diff options
| author | Shlomi Fish <shlomif@shlomifish.org> | 2017-10-05 14:33:06 +0000 |
|---|---|---|
| committer | Shlomi Fish <shlomif@shlomifish.org> | 2017-10-05 14:33:06 +0000 |
| commit | 3eae8aa890673270d0907d55395ccaf5368cea37 (patch) | |
| tree | f3bcf182667a4621131f06c34222d7c7b57160f2 /src | |
| parent | Extract SPRoot::setRootDimensions . (diff) | |
| download | inkscape-3eae8aa890673270d0907d55395ccaf5368cea37.tar.gz inkscape-3eae8aa890673270d0907d55395ccaf5368cea37.zip | |
Extract a base class, SPDimensions.
From two places getting rid of duplicate code.
Diffstat (limited to 'src')
| -rw-r--r-- | src/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/sp-dimensions.cpp | 50 | ||||
| -rw-r--r-- | src/sp-dimensions.h | 41 | ||||
| -rw-r--r-- | src/sp-image.cpp | 17 | ||||
| -rw-r--r-- | src/sp-image.h | 8 | ||||
| -rw-r--r-- | src/sp-root.cpp | 16 | ||||
| -rw-r--r-- | src/sp-root.h | 8 |
7 files changed, 99 insertions, 43 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7437f12ae..4b3357d30 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -14,6 +14,7 @@ set(sp_SRC sp-cursor.cpp sp-defs.cpp sp-desc.cpp + sp-dimensions.cpp sp-ellipse.cpp sp-factory.cpp sp-filter-primitive.cpp @@ -97,6 +98,7 @@ set(sp_SRC sp-cursor.h sp-defs.h sp-desc.h + sp-dimensions.h sp-ellipse.h sp-factory.h sp-filter-primitive.h diff --git a/src/sp-dimensions.cpp b/src/sp-dimensions.cpp new file mode 100644 index 000000000..2eb495219 --- /dev/null +++ b/src/sp-dimensions.cpp @@ -0,0 +1,50 @@ +/* + * SVG dimensions implementation + * + * Authors: + * Lauris Kaplinski <lauris@kaplinski.com> + * Edward Flick (EAF) + * Abhishek Sharma + * Jon A. Cruz <jon@joncruz.org> + * + * Copyright (C) 1999-2005 Authors + * Copyright (C) 2000-2001 Ximian, Inc. + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif +#include "sp-dimensions.h" +#include "sp-item.h" + +void SPDimensions::calcDimsFromParentViewport(const SPItemCtx *ictx) +{ + if (this->x.unit == SVGLength::PERCENT) { + this->x.computed = this->x.value * ictx->viewport.width(); + } + + if (this->y.unit == SVGLength::PERCENT) { + this->y.computed = this->y.value * ictx->viewport.height(); + } + + if (this->width.unit == SVGLength::PERCENT) { + this->width.computed = this->width.value * ictx->viewport.width(); + } + + if (this->height.unit == SVGLength::PERCENT) { + this->height.computed = this->height.value * ictx->viewport.height(); + } +} + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : diff --git a/src/sp-dimensions.h b/src/sp-dimensions.h new file mode 100644 index 000000000..b3581d953 --- /dev/null +++ b/src/sp-dimensions.h @@ -0,0 +1,41 @@ +#ifndef SP_DIMENSIONS_H__ +#define SP_DIMENSIONS_H__ + +/* + * dimensions helper class, common code used by root, image and others + * + * Authors: + * Shlomi Fish + * Copyright (C) 2017 Shlomi Fish, authors + * + * Released under dual Expat and GNU GPL, read the file 'COPYING' for more information + * + */ + +#include "svg/svg-length.h" + +class SPItemCtx; + +class SPDimensions { + +public: + SVGLength x; + SVGLength y; + SVGLength width; + SVGLength height; + void calcDimsFromParentViewport(const SPItemCtx *ictx); +}; + +#endif + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-basic-offset:2 + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=2:tabstop=8:softtabstop=2:fileencoding=utf-8:textwidth=99 : diff --git a/src/sp-image.cpp b/src/sp-image.cpp index 1961971cb..6736efdec 100644 --- a/src/sp-image.cpp +++ b/src/sp-image.cpp @@ -374,23 +374,8 @@ void SPImage::update(SPCtx *ctx, unsigned int flags) { } } - // Calculate x, y, width, height from parent/initial viewport, see sp-root.cpp - if (this->x.unit == SVGLength::PERCENT) { - this->x.computed = this->x.value * ictx->viewport.width(); - } - - if (this->y.unit == SVGLength::PERCENT) { - this->y.computed = this->y.value * ictx->viewport.height(); - } - - if (this->width.unit == SVGLength::PERCENT) { - this->width.computed = this->width.value * ictx->viewport.width(); - } - - if (this->height.unit == SVGLength::PERCENT) { - this->height.computed = this->height.value * ictx->viewport.height(); - } + this->calcDimsFromParentViewport(ictx); // Image creates a new viewport ictx->viewport= Geom::Rect::from_xywh( this->x.computed, this->y.computed, diff --git a/src/sp-image.h b/src/sp-image.h index 9fa33b5de..9cd5faa8b 100644 --- a/src/sp-image.h +++ b/src/sp-image.h @@ -19,6 +19,7 @@ #include "display/curve.h" #include "sp-item.h" #include "viewbox.h" +#include "sp-dimensions.h" #define SP_IMAGE(obj) (dynamic_cast<SPImage*>((SPObject*)obj)) #define SP_IS_IMAGE(obj) (dynamic_cast<const SPImage*>((SPObject*)obj) != NULL) @@ -26,16 +27,11 @@ #define SP_IMAGE_HREF_MODIFIED_FLAG SP_OBJECT_USER_MODIFIED_FLAG_A namespace Inkscape { class Pixbuf; } -class SPImage : public SPItem, public SPViewBox { +class SPImage : public SPItem, public SPViewBox, public SPDimensions { public: SPImage(); virtual ~SPImage(); - SVGLength x; - SVGLength y; - SVGLength width; - SVGLength height; - Geom::Rect clipbox; double sx, sy; double ox, oy; diff --git a/src/sp-root.cpp b/src/sp-root.cpp index d69f5300d..9ea1aa976 100644 --- a/src/sp-root.cpp +++ b/src/sp-root.cpp @@ -267,21 +267,7 @@ void SPRoot::update(SPCtx *ctx, guint flags) } // Calculate x, y, width, height from parent/initial viewport - if (this->x.unit == SVGLength::PERCENT) { - this->x.computed = this->x.value * ictx->viewport.width(); - } - - if (this->y.unit == SVGLength::PERCENT) { - this->y.computed = this->y.value * ictx->viewport.height(); - } - - if (this->width.unit == SVGLength::PERCENT) { - this->width.computed = this->width.value * ictx->viewport.width(); - } - - if (this->height.unit == SVGLength::PERCENT) { - this->height.computed = this->height.value * ictx->viewport.height(); - } + this->calcDimsFromParentViewport(ictx); // std::cout << "SPRoot::update: final:" // << " x: " << x.computed diff --git a/src/sp-root.h b/src/sp-root.h index 882b0e1bf..4a37840d9 100644 --- a/src/sp-root.h +++ b/src/sp-root.h @@ -18,6 +18,7 @@ #include "svg/svg-length.h" #include "sp-item-group.h" #include "viewbox.h" +#include "sp-dimensions.h" #define SP_ROOT(obj) (dynamic_cast<SPRoot*>((SPObject*)obj)) #define SP_IS_ROOT(obj) (dynamic_cast<const SPRoot*>((SPObject*)obj) != NULL) @@ -25,7 +26,7 @@ class SPDefs; /** \<svg\> element */ -class SPRoot : public SPGroup, public SPViewBox { +class SPRoot : public SPGroup, public SPViewBox, public SPDimensions { public: SPRoot(); virtual ~SPRoot(); @@ -35,11 +36,6 @@ public: Inkscape::Version inkscape; } version, original; - SVGLength x; - SVGLength y; - SVGLength width; - SVGLength height; - char *onload; /** |
