diff options
| author | Tavmjong Bah <tavmjong@free.fr> | 2019-05-14 11:59:03 +0000 |
|---|---|---|
| committer | Tavmjong Bah <tavmjong@free.fr> | 2019-05-14 11:59:03 +0000 |
| commit | 74287e0f0f2ed09c57e969c396fa59b1986ad3f4 (patch) | |
| tree | c8f286fa3cd90c83f5a48fce82cdc1d8faa5462f /src/object | |
| parent | Remove error message when SVG OpenType table is empty. (diff) | |
| download | inkscape-74287e0f0f2ed09c57e969c396fa59b1986ad3f4.tar.gz inkscape-74287e0f0f2ed09c57e969c396fa59b1986ad3f4.zip | |
Support percentage (include default) values for linear and radial gradient attribues.
Fix for inbox issue #415.
Diffstat (limited to 'src/object')
| -rw-r--r-- | src/object/sp-linear-gradient.cpp | 35 | ||||
| -rw-r--r-- | src/object/sp-linear-gradient.h | 13 | ||||
| -rw-r--r-- | src/object/sp-radial-gradient.cpp | 38 | ||||
| -rw-r--r-- | src/object/sp-radial-gradient.h | 11 |
4 files changed, 86 insertions, 11 deletions
diff --git a/src/object/sp-linear-gradient.cpp b/src/object/sp-linear-gradient.cpp index 4d2867f98..7b0029356 100644 --- a/src/object/sp-linear-gradient.cpp +++ b/src/object/sp-linear-gradient.cpp @@ -12,6 +12,7 @@ #include "sp-linear-gradient.h" #include "attributes.h" +#include "style.h" #include "xml/repr.h" /* @@ -66,6 +67,29 @@ void SPLinearGradient::set(SPAttributeEnum key, const gchar* value) { } } +void +SPLinearGradient::update(SPCtx *ctx, guint flags) +{ + // To do: Verify flags. + if (flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) { + + SPItemCtx const *ictx = reinterpret_cast<SPItemCtx const *>(ctx); + + if (getUnits() == SP_GRADIENT_UNITS_USERSPACEONUSE) { + double w = ictx->viewport.width(); + double h = ictx->viewport.height(); + double d = sqrt ((w*w + h*h)/2.0); + double const em = style->font_size.computed; + double const ex = 0.5 * em; // fixme: get x height from pango or libnrtype. + + this->x1.update(em, ex, w); + this->y1.update(em, ex, h); + this->x2.update(em, ex, w); + this->y2.update(em, ex, h); + } + } +} + /** * Callback: write attributes to associated repr. */ @@ -106,3 +130,14 @@ cairo_pattern_t* SPLinearGradient::pattern_new(cairo_t * /*ct*/, Geom::OptRect c return cp; } + +/* + 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/object/sp-linear-gradient.h b/src/object/sp-linear-gradient.h index f88c38dc4..c54e900c2 100644 --- a/src/object/sp-linear-gradient.h +++ b/src/object/sp-linear-gradient.h @@ -23,20 +23,21 @@ /** Linear gradient. */ class SPLinearGradient : public SPGradient { public: - SPLinearGradient(); - ~SPLinearGradient() override; + SPLinearGradient(); + ~SPLinearGradient() override; SVGLength x1; SVGLength y1; SVGLength x2; SVGLength y2; - cairo_pattern_t* pattern_new(cairo_t *ct, Geom::OptRect const &bbox, double opacity) override; + cairo_pattern_t* pattern_new(cairo_t *ct, Geom::OptRect const &bbox, double opacity) override; protected: - void build(SPDocument *document, Inkscape::XML::Node *repr) override; - void set(SPAttributeEnum key, char const *value) override; - Inkscape::XML::Node* write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, unsigned int flags) override; + void build(SPDocument *document, Inkscape::XML::Node *repr) override; + void set(SPAttributeEnum key, char const *value) override; + void update(SPCtx *ctx, guint flags) override; + Inkscape::XML::Node* write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, unsigned int flags) override; }; #endif /* !SP_LINEAR_GRADIENT_H */ diff --git a/src/object/sp-radial-gradient.cpp b/src/object/sp-radial-gradient.cpp index 271894ae2..79817143e 100644 --- a/src/object/sp-radial-gradient.cpp +++ b/src/object/sp-radial-gradient.cpp @@ -12,6 +12,7 @@ #include "sp-radial-gradient.h" #include "attributes.h" +#include "style.h" #include "xml/repr.h" #include <2geom/transforms.h> @@ -48,6 +49,7 @@ void SPRadialGradient::build(SPDocument *document, Inkscape::XML::Node *repr) { * Set radial gradient attribute. */ void SPRadialGradient::set(SPAttributeEnum key, gchar const *value) { + switch (key) { case SP_ATTR_CX: if (!this->cx.read(value)) { @@ -112,6 +114,31 @@ void SPRadialGradient::set(SPAttributeEnum key, gchar const *value) { } } +void +SPRadialGradient::update(SPCtx *ctx, guint flags) +{ + // To do: Verify flags. + if (flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) { + + SPItemCtx const *ictx = reinterpret_cast<SPItemCtx const *>(ctx); + + if (getUnits() == SP_GRADIENT_UNITS_USERSPACEONUSE) { + double w = ictx->viewport.width(); + double h = ictx->viewport.height(); + double d = sqrt ((w*w + h*h)/2.0); + double const em = style->font_size.computed; + double const ex = 0.5 * em; // fixme: get x height from pango or libnrtype. + + this->cx.update(em, ex, w); + this->cy.update(em, ex, h); + this->r.update(em, ex, d); + this->fx.update(em, ex, w); + this->fy.update(em, ex, h); + this->fr.update(em, ex, d); + } + } +} + /** * Write radial gradient attributes to associated repr. */ @@ -212,3 +239,14 @@ cairo_pattern_t* SPRadialGradient::pattern_new(cairo_t *ct, Geom::OptRect const return cp; } + +/* + 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/object/sp-radial-gradient.h b/src/object/sp-radial-gradient.h index b88ac7e2f..72c4dec55 100644 --- a/src/object/sp-radial-gradient.h +++ b/src/object/sp-radial-gradient.h @@ -26,8 +26,8 @@ typedef struct _cairo_pattern cairo_pattern_t; /** Radial gradient. */ class SPRadialGradient : public SPGradient { public: - SPRadialGradient(); - ~SPRadialGradient() override; + SPRadialGradient(); + ~SPRadialGradient() override; SVGLength cx; SVGLength cy; @@ -39,9 +39,10 @@ public: cairo_pattern_t* pattern_new(cairo_t *ct, Geom::OptRect const &bbox, double opacity) override; protected: - void build(SPDocument *document, Inkscape::XML::Node *repr) override; - void set(SPAttributeEnum key, char const *value) override; - Inkscape::XML::Node* write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, unsigned int flags) override; + void build(SPDocument *document, Inkscape::XML::Node *repr) override; + void set(SPAttributeEnum key, char const *value) override; + void update(SPCtx *ctx, unsigned int flags) override; + Inkscape::XML::Node* write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, unsigned int flags) override; }; #endif /* !SP_RADIAL_GRADIENT_H */ |
