diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/display/nr-style.cpp | 2 | ||||
| -rw-r--r-- | src/object/sp-item.cpp | 7 | ||||
| -rw-r--r-- | src/object/sp-shape.cpp | 40 | ||||
| -rw-r--r-- | src/style-internal.cpp | 16 |
4 files changed, 47 insertions, 18 deletions
diff --git a/src/display/nr-style.cpp b/src/display/nr-style.cpp index d509ced9c..58ef29a45 100644 --- a/src/display/nr-style.cpp +++ b/src/display/nr-style.cpp @@ -221,7 +221,7 @@ void NRStyle::set(SPStyle *style, SPStyle *context_style) dash_offset = style->stroke_dashoffset.computed; dash = new double[n_dash]; for (unsigned int i = 0; i < n_dash; ++i) { - dash[i] = style->stroke_dasharray.values[i].value; + dash[i] = style->stroke_dasharray.values[i].computed; } } else { dash_offset = 0.0; diff --git a/src/object/sp-item.cpp b/src/object/sp-item.cpp index 3b6329436..d7c461f92 100644 --- a/src/object/sp-item.cpp +++ b/src/object/sp-item.cpp @@ -1307,10 +1307,11 @@ void SPItem::adjust_stroke( gdouble ex ) if ( !style->stroke_dasharray.values.empty() ) { for (unsigned i = 0; i < style->stroke_dasharray.values.size(); i++) { - double dash = style->stroke_dasharray.values[i].value * ex; - style->stroke_dasharray.values[i].setDouble(dash); + style->stroke_dasharray.values[i].value *= ex; + style->stroke_dasharray.values[i].computed *= ex; } - style->stroke_dashoffset.value *= ex; + style->stroke_dashoffset.value *= ex; + style->stroke_dashoffset.computed *= ex; } updateRepr(); 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; + } + } } /** diff --git a/src/style-internal.cpp b/src/style-internal.cpp index 14b523302..39e334d1f 100644 --- a/src/style-internal.cpp +++ b/src/style-internal.cpp @@ -2052,9 +2052,9 @@ SPIDashArray::read( gchar const *str ) { if( strcmp(str, "none") == 0) { return; } + std::vector<Glib::ustring> tokens = Glib::Regex::split_simple("[(,\\s|\\s)]+", str); - gchar *e = NULL; bool LineSolid = true; for (auto token : tokens) { @@ -2062,21 +2062,9 @@ SPIDashArray::read( gchar const *str ) { spilength.read(token.c_str()); if (spilength.value > 0.00000001) LineSolid = false; - double dash = spilength.value; - // Currently inkscape handle unit conversion in dasharray but need - // a active document to do it, so put document inside a check for units - // and supose units are not included in tests - if (spilength.unit == SPCSSUnit::SP_CSS_UNIT_PERCENT) { - SPDocument *document = SP_ACTIVE_DOCUMENT; - dash = document->getViewBox().width() * spilength.value; - } - else if (spilength.unit != SPCSSUnit::SP_CSS_UNIT_NONE) { - SPDocument *document = SP_ACTIVE_DOCUMENT; - dash = spilength.computed / document->getDocumentScale()[0]; - } - spilength.setDouble(dash); values.push_back(spilength); } + if (LineSolid) { values.clear(); } |
