From dac72fcd64d2fb7e216d5165a8821b722d2eded9 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Wed, 15 Aug 2018 11:11:55 +0200 Subject: 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. --- src/object/sp-shape.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'src/object/sp-shape.cpp') 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(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; + } + } } /** -- cgit v1.2.3