summaryrefslogtreecommitdiffstats
path: root/src/extension/internal/emf-print.cpp
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/extension/internal/emf-print.cpp
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/extension/internal/emf-print.cpp')
-rw-r--r--src/extension/internal/emf-print.cpp53
1 files changed, 46 insertions, 7 deletions
diff --git a/src/extension/internal/emf-print.cpp b/src/extension/internal/emf-print.cpp
index 254000db3..459794654 100644
--- a/src/extension/internal/emf-print.cpp
+++ b/src/extension/internal/emf-print.cpp
@@ -38,7 +38,7 @@
#include "helper/geom.h"
#include "helper/geom-curves.h"
#include "util/units.h"
-
+#include "inkscape.h"
#include "inkscape-version.h"
#include "extension/system.h"
@@ -55,6 +55,7 @@
#include "object/sp-root.h"
#include "object/sp-shape.h"
#include "object/sp-clippath.h"
+#include "object/sp-namedview.h"
#include "style.h"
#include "display/cairo-utils.h"
@@ -695,17 +696,32 @@ int PrintEmf::create_pen(SPStyle const *style, const Geom::Affine &transform)
} else {
unsigned i = 0;
while ((linestyle != U_PS_USERSTYLE) && (i < style->stroke_dasharray.values.size())) {
- if (style->stroke_dasharray.values[i] > 0.00000001) {
+ if (style->stroke_dasharray.values[i].computed > 0.00000001) {
linestyle = U_PS_USERSTYLE;
}
i++;
}
-
+
if (linestyle == U_PS_USERSTYLE) {
+ 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;
+ }
n_dash = style->stroke_dasharray.values.size();
dash = new uint32_t[n_dash];
for (i = 0; i < n_dash; i++) {
- dash[i] = MAX(1, (uint32_t) round(scale * style->stroke_dasharray.values[i] * PX2WORLD));
+ double dashval = 0;
+ if(style->stroke_dasharray.values[i].unit == SVGLength::NONE) {
+ dashval = style->stroke_dasharray.values[i].value;
+ } else if (style->stroke_dasharray.values[i].unit == SVGLength::PERCENT) {
+ dashval = vbox.width() * style->stroke_dasharray.values[i].value;
+ } else {
+ dashval = Inkscape::Util::Quantity::convert(style->stroke_dasharray.values[i].computed, "px", display_unit.c_str());
+ }
+ dash[i] = MAX(1, (uint32_t) round(scale * dashval * PX2WORLD));
}
}
}
@@ -1455,10 +1471,25 @@ unsigned int PrintEmf::stroke(
}
tlength = length(tmp_pathpw, 0.1);
tmp_pathpw2 = arc_length_parametrization(tmp_pathpw);
-
+ 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;
+ }
// go around the dash array repeatedly until the entire path is consumed (but not beyond).
while (slength < tlength) {
- elength = slength + style->stroke_dasharray.values[i++];
+ SVGLength i1 = style->stroke_dasharray.values[i++];
+ double dashval = 0;
+ if(i1.unit == SVGLength::NONE) {
+ dashval = i1.value;
+ } else if (i1.unit == SVGLength::PERCENT) {
+ dashval = vbox.width() * i1.value;
+ } else {
+ dashval = Inkscape::Util::Quantity::convert(i1.computed, "px", display_unit.c_str());
+ }
+ elength = slength + dashval;
if (elength > tlength) {
elength = tlength;
}
@@ -1469,7 +1500,15 @@ unsigned int PrintEmf::stroke(
first_frag = fragment;
}
slength = elength;
- slength += style->stroke_dasharray.values[i++]; // the gap
+ SVGLength i2 = style->stroke_dasharray.values[i++];
+ if(i2.unit == SVGLength::NONE) {
+ dashval = i2.value;
+ } else if (i2.unit == SVGLength::PERCENT) {
+ dashval = vbox.width() * i2.value;
+ } else {
+ dashval = Inkscape::Util::Quantity::convert(i2.computed, "px", display_unit.c_str());
+ }
+ slength += dashval; // the gap
if (i >= n_dash) {
i = 0;
}