diff options
| author | Tavmjong Bah <tavmjong@free.fr> | 2018-08-15 09:11:55 +0000 |
|---|---|---|
| committer | Tavmjong Bah <tavmjong@free.fr> | 2018-08-15 09:11:55 +0000 |
| commit | dac72fcd64d2fb7e216d5165a8821b722d2eded9 (patch) | |
| tree | 82949171f4c2b8cf32fef4d20657492ec908b3d3 /src/object/sp-shape.cpp | |
| parent | fix a typo (diff) | |
| download | inkscape-dac72fcd64d2fb7e216d5165a8821b722d2eded9.tar.gz inkscape-dac72fcd64d2fb7e216d5165a8821b722d2eded9.zip | |
Relative values for strokes:
Fix segmenation fault on reading dashes with % values.
Fix computed value for dashes with % values (use viewport diagonal length).
Support % values for stroke width.
Diffstat (limited to 'src/object/sp-shape.cpp')
| -rw-r--r-- | src/object/sp-shape.cpp | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/object/sp-shape.cpp b/src/object/sp-shape.cpp index d3fce702e..a5c806e34 100644 --- a/src/object/sp-shape.cpp +++ b/src/object/sp-shape.cpp @@ -194,6 +194,46 @@ void SPShape::update(SPCtx* ctx, guint flags) { sh->setChildrenStyle(this->context_style); // Resolve 'context-xxx' in children. } } + + /* Update stroke/dashes for relative units. */ + if (flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) { + + SPItemCtx const *ictx = reinterpret_cast<SPItemCtx const *>(ctx); + + double const w = ictx->viewport.width(); + double const h = ictx->viewport.height(); + double const d = sqrt(w*w + h*h) * M_SQRT1_2; // diagonal per SVG spec + double const em = style->font_size.computed; + double const ex = 0.5 * em; // fixme: get x height from pango or libnrtype. + + if (style->stroke_width.unit == SP_CSS_UNIT_EM) { + style->stroke_width.computed = style->stroke_width.value * em; + } + else if (style->stroke_width.unit == SP_CSS_UNIT_EX) { + style->stroke_width.computed = style->stroke_width.value * ex; + } + else if (style->stroke_width.unit == SP_CSS_UNIT_PERCENT) { + style->stroke_width.computed = style->stroke_width.value * d; + } + + if (style->stroke_dasharray.values.size() != 0) { + for (auto&& i: style->stroke_dasharray.values) { + if (i.unit == SP_CSS_UNIT_EM) i.computed = i.value * em; + else if (i.unit == SP_CSS_UNIT_EX) i.computed = i.value * ex; + else if (i.unit == SP_CSS_UNIT_PERCENT) i.computed = i.value * d; + } + } + + if (style->stroke_dashoffset.unit == SP_CSS_UNIT_EM) { + style->stroke_dashoffset.computed = style->stroke_dashoffset.value * em; + } + else if (style->stroke_dashoffset.unit == SP_CSS_UNIT_EX) { + style->stroke_dashoffset.computed = style->stroke_dashoffset.value * ex; + } + else if (style->stroke_dashoffset.unit == SP_CSS_UNIT_PERCENT) { + style->stroke_dashoffset.computed = style->stroke_dashoffset.value * d; + } + } } /** |
