summaryrefslogtreecommitdiffstats
path: root/src/livarot
diff options
context:
space:
mode:
authorJabier Arraiza <jabier.arraiza@marker.es>2018-06-10 14:20:18 +0000
committerJabier Arraiza <jabier.arraiza@marker.es>2018-08-05 00:31:06 +0000
commit7aaeaacc08de60fd324646afe69f4dbed93f89d4 (patch)
tree13c87e946659151021e553dc3b752c3dbcd2f4a2 /src/livarot
parentFix one symbolic icon bug (diff)
downloadinkscape-7aaeaacc08de60fd324646afe69f4dbed93f89d4.tar.gz
inkscape-7aaeaacc08de60fd324646afe69f4dbed93f89d4.zip
Allow inkscape handle units and percent in dasharray and dashoffset. Add pref optional to scale dashes on stroke scale
Diffstat (limited to 'src/livarot')
-rw-r--r--src/livarot/PathCutting.cpp35
1 files changed, 32 insertions, 3 deletions
diff --git a/src/livarot/PathCutting.cpp b/src/livarot/PathCutting.cpp
index 3c518c521..b7f736021 100644
--- a/src/livarot/PathCutting.cpp
+++ b/src/livarot/PathCutting.cpp
@@ -20,6 +20,9 @@
#include "Path.h"
#include "style.h"
#include "livarot/path-description.h"
+#include "object/sp-namedview.h"
+#include "util/units.h"
+#include "inkscape.h"
#include <2geom/pathvector.h>
#include <2geom/point.h>
#include <2geom/affine.h>
@@ -62,16 +65,42 @@ void Path::DashPolylineFromStyle(SPStyle *style, float scale, float min_len)
double dlen = 0.0;
// Find total length
+ SPDocument * document = SP_ACTIVE_DOCUMENT;
+ SPNamedView *nv = sp_document_namedview(document, NULL);
+ Geom::Rect vbox = document->getViewBox();
+ Glib::ustring display_unit = "px";
+ if (nv) {
+ display_unit = nv->display_units->abbr;
+ }
for (unsigned i = 0; i < style->stroke_dasharray.values.size(); i++) {
- dlen += style->stroke_dasharray.values[i] * scale;
+ if(style->stroke_dasharray.values[i].unit == SVGLength::NONE) {
+ dlen += style->stroke_dasharray.values[i].value * scale;
+ } else if (style->stroke_dasharray.values[i].unit == SVGLength::PERCENT) {
+ dlen += vbox.width() * style->stroke_dasharray.values[i].value * scale;
+ } else {
+ dlen += Inkscape::Util::Quantity::convert(style->stroke_dasharray.values[i].computed, "px", display_unit.c_str()) * scale;
+ }
}
if (dlen >= min_len) {
// Extract out dash pattern (relative positions)
- double dash_offset = style->stroke_dashoffset.value * scale;
+ double dash_offset = 0;
+ if (style->stroke_dashoffset.unit == SVGLength::NONE) {
+ dash_offset = style->stroke_dashoffset.value * scale;
+ } else if (style->stroke_dashoffset.unit == SVGLength::PERCENT) {
+ dash_offset = vbox.width() * style->stroke_dashoffset.value * scale;
+ } else {
+ dash_offset = Inkscape::Util::Quantity::convert(style->stroke_dashoffset.computed * scale, "px", display_unit.c_str());
+ }
size_t n_dash = style->stroke_dasharray.values.size();
double *dash = g_new(double, n_dash);
for (unsigned i = 0; i < n_dash; i++) {
- dash[i] = style->stroke_dasharray.values[i] * scale;
+ if(style->stroke_dasharray.values[i].unit == SVGLength::NONE) {
+ dash[i] = style->stroke_dasharray.values[i].value;
+ } else if (style->stroke_dasharray.values[i].unit == SVGLength::PERCENT) {
+ dash[i] = vbox.width() * style->stroke_dasharray.values[i].value;
+ } else {
+ dash[i] = Inkscape::Util::Quantity::convert(style->stroke_dasharray.values[i].computed, "px", display_unit.c_str());
+ }
}
// Convert relative positions to absolute postions