summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTavmjong Bah <tavmjong@free.fr>2018-11-08 14:56:09 +0000
committerTavmjong Bah <tavmjong@free.fr>2018-11-08 14:56:09 +0000
commit517288aebef7426ab1a70065746d0a81d545568d (patch)
tree2a35356ce5c50d302e69de010a7047af78503013 /src
parentfix bug 1793940 ODG image export (diff)
downloadinkscape-517288aebef7426ab1a70065746d0a81d545568d.tar.gz
inkscape-517288aebef7426ab1a70065746d0a81d545568d.zip
Implement the remaining vector effects properties.
Diffstat (limited to 'src')
-rw-r--r--src/display/drawing-item.cpp27
-rw-r--r--src/display/drawing-shape.cpp4
-rw-r--r--src/display/drawing-text.cpp2
-rw-r--r--src/style-enums.h10
-rw-r--r--src/style-internal.cpp100
-rw-r--r--src/style-internal.h43
-rw-r--r--src/style.cpp2
-rw-r--r--src/style.h2
8 files changed, 183 insertions, 7 deletions
diff --git a/src/display/drawing-item.cpp b/src/display/drawing-item.cpp
index f83d0eaeb..86bd0c7f9 100644
--- a/src/display/drawing-item.cpp
+++ b/src/display/drawing-item.cpp
@@ -555,6 +555,33 @@ DrawingItem::update(Geom::IntRect const &area, UpdateContext const &ctx, unsigne
if (_transform) {
child_ctx.ctm = *_transform * ctx.ctm;
}
+
+ // Vector effects
+ if (_style) {
+
+ if (_style->vector_effect.fixed) {
+ child_ctx.ctm.setTranslation(Geom::Point(0,0));
+ }
+
+ if (_style->vector_effect.size) {
+ double value = sqrt(child_ctx.ctm.det());
+ if (value > 0 ) {
+ child_ctx.ctm[0] = child_ctx.ctm[0]/value;
+ child_ctx.ctm[1] = child_ctx.ctm[1]/value;
+ child_ctx.ctm[2] = child_ctx.ctm[2]/value;
+ child_ctx.ctm[3] = child_ctx.ctm[3]/value;
+ }
+ }
+
+ if (_style->vector_effect.rotate) {
+ double value = sqrt(child_ctx.ctm.det());
+ child_ctx.ctm[0] = value;
+ child_ctx.ctm[1] = 0;
+ child_ctx.ctm[2] = 0;
+ child_ctx.ctm[3] = value;
+ }
+ }
+
/* Remember the transformation matrix */
Geom::Affine ctm_change = _ctm.inverse() * child_ctx.ctm;
_ctm = child_ctx.ctm;
diff --git a/src/display/drawing-shape.cpp b/src/display/drawing-shape.cpp
index 05123297e..612593ad8 100644
--- a/src/display/drawing-shape.cpp
+++ b/src/display/drawing-shape.cpp
@@ -180,7 +180,7 @@ DrawingShape::_renderStroke(DrawingContext &dc)
if( has_stroke ) {
// TODO: remove segments outside of bbox when no dashes present
dc.path(_curve->get_pathvector());
- if (_style && _style->vector_effect.computed == SP_VECTOR_EFFECT_NON_SCALING_STROKE) {
+ if (_style && _style->vector_effect.stroke) {
dc.restore();
dc.save();
}
@@ -260,7 +260,7 @@ DrawingShape::_renderItem(DrawingContext &dc, Geom::IntRect const &area, unsigne
_nrstyle.applyFill(dc);
dc.fillPreserve();
}
- if (_style && _style->vector_effect.computed == SP_VECTOR_EFFECT_NON_SCALING_STROKE) {
+ if (_style && _style->vector_effect.stroke) {
dc.restore();
dc.save();
}
diff --git a/src/display/drawing-text.cpp b/src/display/drawing-text.cpp
index d823012e3..5a8a06ede 100644
--- a/src/display/drawing-text.cpp
+++ b/src/display/drawing-text.cpp
@@ -598,7 +598,7 @@ unsigned DrawingText::_renderItem(DrawingContext &dc, Geom::IntRect const &/*are
}
{
Inkscape::DrawingContext::Save save(dc);
- if (!_style || !(_style->vector_effect.computed == SP_VECTOR_EFFECT_NON_SCALING_STROKE)) {
+ if (!_style || !(_style->vector_effect.stroke)) {
dc.transform(_ctm);
}
if (has_stroke) {
diff --git a/src/style-enums.h b/src/style-enums.h
index 24ebda5d1..be34f56b5 100644
--- a/src/style-enums.h
+++ b/src/style-enums.h
@@ -310,8 +310,11 @@ enum SPTextRendering {
};
enum SPVectorEffect {
- SP_VECTOR_EFFECT_NONE,
- SP_VECTOR_EFFECT_NON_SCALING_STROKE
+ SP_VECTOR_EFFECT_NONE = 0,
+ SP_VECTOR_EFFECT_NON_SCALING_STROKE = 1,
+ SP_VECTOR_EFFECT_NON_SCALING_SIZE = 2,
+ SP_VECTOR_EFFECT_NON_ROTATION = 4,
+ SP_VECTOR_EFFECT_FIXED_POSITION = 8
};
struct SPStyleEnum {
@@ -675,6 +678,9 @@ static SPStyleEnum const enum_color_interpolation[] = {
static SPStyleEnum const enum_vector_effect[] = {
{"none", SP_VECTOR_EFFECT_NONE},
{"non-scaling-stroke", SP_VECTOR_EFFECT_NON_SCALING_STROKE},
+ {"non-scaling-size", SP_VECTOR_EFFECT_NON_SCALING_SIZE},
+ {"non-rotation", SP_VECTOR_EFFECT_NON_ROTATION},
+ {"fixed-position", SP_VECTOR_EFFECT_FIXED_POSITION},
{nullptr, -1}
};
diff --git a/src/style-internal.cpp b/src/style-internal.cpp
index 186d382f0..76e83ce44 100644
--- a/src/style-internal.cpp
+++ b/src/style-internal.cpp
@@ -2780,6 +2780,106 @@ SPITextDecoration::operator==(const SPIBase& rhs) {
}
}
+// SPIVectorEffect ------------------------------------------------
+
+void
+SPIVectorEffect::read( gchar const *str ) {
+
+ if( !str ) return;
+
+ if (!strcmp(str, "none")) {
+ set = true;
+ stroke = false;
+ size = false;
+ rotate = false;
+ fixed = false;
+ } else {
+ bool found_one = false;
+ bool hit_one = false;
+
+ bool found_stroke = false;
+ bool found_size = false;
+ bool found_rotate = false;
+ bool found_fixed = false;
+
+ const gchar *hstr = str;
+ while (true) {
+ if (*str == ' ' || *str == ',' || *str == '\0'){
+ int slen = str - hstr;
+
+ while(true){ // not really a loop, used to avoid a goto
+ hit_one = true; // most likely we will
+ if ((slen == 18) && strneq(hstr, "non-scaling-stroke", slen)){ found_stroke = true; break; }
+ if ((slen == 16) && strneq(hstr, "non-scaling-size", slen)){ found_size = true; break; }
+ if ((slen == 12) && strneq(hstr, "non-rotation", slen)){ found_rotate = true; break; }
+ if ((slen == 14) && strneq(hstr, "fixed-position", slen)){ found_fixed = true; break; }
+ if ((slen == 4) && strneq(hstr, "none", slen)){ break; }
+
+ hit_one = false; // whatever this thing is, we do not recognize it
+ break;
+ }
+ found_one |= hit_one;
+ if(*str == '\0')break;
+ hstr = str + 1;
+ }
+ str++;
+ }
+ if (found_one) {
+ set = true;
+ stroke = found_stroke;
+ size = found_size;
+ rotate = found_rotate;
+ fixed = found_fixed;
+ }
+ else {
+ set = false;
+ }
+ }
+
+ // std::cout << " stroke: " << stroke
+ // << " size: " << size
+ // << " rotate: " << rotate
+ // << " fixed: " << fixed
+ // << std::endl;
+}
+
+const Glib::ustring SPIVectorEffect::get_value() const
+{
+ if (this->inherit) return Glib::ustring("inherit");
+ auto ret = Glib::ustring("");
+ if (this->stroke) ret += " non-scaling-stroke";
+ if (this->size) ret += " non-scaling-size";
+ if (this->rotate) ret += " non-rotation";
+ if (this->fixed) ret += " fixed-position";
+ if (ret.empty()) ret += "none";
+ return ret;
+}
+
+// Does not inherit!
+// void
+// SPIVectorEffect::cascade( const SPIBase* const parent ) {
+// }
+
+// void
+// SPIVectorEffect::merge( const SPIBase* const parent ) {
+// }
+
+bool
+SPIVectorEffect::operator==(const SPIBase& rhs) {
+ if( const SPIVectorEffect* r = dynamic_cast<const SPIVectorEffect*>(&rhs) ) {
+ return
+ (stroke == r->stroke) &&
+ (size == r->size ) &&
+ (rotate == r->rotate) &&
+ (fixed == r->fixed ) &&
+ SPIBase::operator==(rhs);
+ } else {
+ return false;
+ }
+}
+
+
+
/* ---------------------------- NOTES ----------------------------- */
diff --git a/src/style-internal.h b/src/style-internal.h
index 16877f9a5..e3b3fcada 100644
--- a/src/style-internal.h
+++ b/src/style-internal.h
@@ -1299,6 +1299,49 @@ struct SPITextDecorationData {
float line_through_position;
};
+/// Vector Effects. THIS SHOULD BE A GENERIC CLASS
+class SPIVectorEffect : public SPIBase
+{
+
+public:
+ SPIVectorEffect()
+ : SPIBase( "vector-effect" ) {
+ this->clear();
+ inherits = false;
+ }
+
+ ~SPIVectorEffect() override
+ = default;
+
+ void read( gchar const *str ) override;
+ const Glib::ustring get_value() const override;
+ void clear() override {
+ SPIBase::clear();
+ stroke = false;
+ size = false;
+ rotate = false;
+ fixed = false;
+ }
+
+ // Does not inherit
+ void cascade( const SPIBase* const parent ) override {};
+ void merge( const SPIBase* const parent ) override {};
+
+ SPIVectorEffect& operator=(const SPIVectorEffect& rhs) = default;
+
+ bool operator==(const SPIBase& rhs) override;
+ bool operator!=(const SPIBase& rhs) override {
+ return !(*this == rhs);
+ }
+
+ // To do: make private
+public:
+ bool stroke : 1;
+ bool size : 1;
+ bool rotate : 1;
+ bool fixed : 1;
+};
+
#endif // SEEN_SP_STYLE_INTERNAL_H
diff --git a/src/style.cpp b/src/style.cpp
index 6c7e849dc..5a9464139 100644
--- a/src/style.cpp
+++ b/src/style.cpp
@@ -354,7 +354,7 @@ SPStyle::SPStyle(SPDocument *document_in, SPObject *object_in) :
solid_opacity( "solid-opacity", SP_SCALE24_MAX ),
// Vector effects
- vector_effect( "vector-effect", enum_vector_effect, SP_VECTOR_EFFECT_NONE, false ),
+ vector_effect(),
// Fill properties
fill( "fill" ), // SPIPaint
diff --git a/src/style.h b/src/style.h
index 303e8dcbb..992e0a5cb 100644
--- a/src/style.h
+++ b/src/style.h
@@ -225,7 +225,7 @@ public:
SPIScale24 solid_opacity;
/** vector effect */
- SPIEnum vector_effect;
+ SPIVectorEffect vector_effect;
/** fill */
SPIPaint fill;