summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJabier Arraiza <jabier.arraiza@marker.es>2018-06-12 21:33:11 +0000
committerJabier Arraiza <jabier.arraiza@marker.es>2018-08-05 00:31:06 +0000
commitbbf828d9ae370e9aede9702e520c106c380a3867 (patch)
tree1995e3e38ee25046906073df927999988e445941 /src
parentRevert changes (diff)
downloadinkscape-bbf828d9ae370e9aede9702e520c106c380a3867.tar.gz
inkscape-bbf828d9ae370e9aede9702e520c106c380a3867.zip
Refactor with Tav help
Diffstat (limited to 'src')
-rw-r--r--src/display/nr-style.cpp2
-rw-r--r--src/extension/internal/cairo-render-context.cpp2
-rw-r--r--src/extension/internal/emf-inout.cpp44
-rw-r--r--src/extension/internal/emf-print.cpp8
-rw-r--r--src/extension/internal/javafx-out.cpp4
-rw-r--r--src/extension/internal/latex-pstricks.cpp2
-rw-r--r--src/extension/internal/wmf-inout.cpp18
-rw-r--r--src/extension/internal/wmf-print.cpp6
-rw-r--r--src/livarot/PathCutting.cpp4
-rw-r--r--src/object/sp-item.cpp6
-rw-r--r--src/preferences-skeleton.h1
-rw-r--r--src/style-internal.cpp103
-rw-r--r--src/style-internal.h6
-rw-r--r--src/ui/dialog/inkscape-preferences.cpp6
-rw-r--r--src/ui/dialog/inkscape-preferences.h4
-rw-r--r--src/widgets/dash-selector.cpp2
-rw-r--r--src/widgets/stroke-style.cpp22
17 files changed, 175 insertions, 65 deletions
diff --git a/src/display/nr-style.cpp b/src/display/nr-style.cpp
index cec6de4d3..fa0db55cc 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.value;
dash = new double[n_dash];
for (unsigned int i = 0; i < n_dash; ++i) {
- dash[i] = style->stroke_dasharray.values[i];
+ dash[i] = style->stroke_dasharray.values[i].value;
}
} else {
dash_offset = 0.0;
diff --git a/src/extension/internal/cairo-render-context.cpp b/src/extension/internal/cairo-render-context.cpp
index da0797600..4727f1e4e 100644
--- a/src/extension/internal/cairo-render-context.cpp
+++ b/src/extension/internal/cairo-render-context.cpp
@@ -1436,7 +1436,7 @@ CairoRenderContext::_setStrokeStyle(SPStyle const *style, Geom::OptRect const &p
size_t ndashes = style->stroke_dasharray.values.size();
double* dashes =(double*)malloc(ndashes*sizeof(double));
for( unsigned i = 0; i < ndashes; ++i ) {
- dashes[i] = style->stroke_dasharray.values[i];
+ dashes[i] = style->stroke_dasharray.values[i].value;
}
cairo_set_dash(_cr, dashes, ndashes, style->stroke_dashoffset.value);
free(dashes);
diff --git a/src/extension/internal/emf-inout.cpp b/src/extension/internal/emf-inout.cpp
index d0556e467..3e3b6ec43 100644
--- a/src/extension/internal/emf-inout.cpp
+++ b/src/extension/internal/emf-inout.cpp
@@ -45,6 +45,7 @@
#include "display/drawing-item.h"
#include "clear-n_.h"
#include "svg/svg.h"
+#include "svg/css-ostringstream.h"
#include "util/units.h" // even though it is included indirectly by emf-inout.h
#include "inkscape.h" // even though it is included indirectly by emf-inout.h
@@ -984,7 +985,7 @@ Emf::output_style(PEMF_CALLBACK_DATA d, int iType)
for (unsigned i=0; i<d->dc[d->level].style.stroke_dasharray.values.size(); i++) {
if (i)
tmp_style << ",";
- tmp_style << d->dc[d->level].style.stroke_dasharray.values[i];
+ tmp_style << d->dc[d->level].style.stroke_dasharray.values[i].value;
}
tmp_style << ";";
tmp_style << "stroke-dashoffset:0;";
@@ -1094,20 +1095,24 @@ Emf::select_pen(PEMF_CALLBACK_DATA d, int index)
case U_PS_DASHDOT:
case U_PS_DASHDOTDOT:
{
+ SPILength spilength;
+ spilength.read("1");
int penstyle = (pEmr->lopn.lopnStyle & U_PS_STYLE_MASK);
if (!d->dc[d->level].style.stroke_dasharray.values.empty() && (d->level==0 || (d->level>0 && d->dc[d->level].style.stroke_dasharray.values!=d->dc[d->level-1].style.stroke_dasharray.values)))
d->dc[d->level].style.stroke_dasharray.values.clear();
if (penstyle==U_PS_DASH || penstyle==U_PS_DASHDOT || penstyle==U_PS_DASHDOTDOT) {
- d->dc[d->level].style.stroke_dasharray.values.push_back( 3 );
- d->dc[d->level].style.stroke_dasharray.values.push_back( 1 );
+ spilength.read("3");
+ d->dc[d->level].style.stroke_dasharray.values.push_back( spilength );
+ spilength.read("1");
+ d->dc[d->level].style.stroke_dasharray.values.push_back( spilength );
}
if (penstyle==U_PS_DOT || penstyle==U_PS_DASHDOT || penstyle==U_PS_DASHDOTDOT) {
- d->dc[d->level].style.stroke_dasharray.values.push_back( 1 );
- d->dc[d->level].style.stroke_dasharray.values.push_back( 1 );
+ d->dc[d->level].style.stroke_dasharray.values.push_back( spilength );
+ d->dc[d->level].style.stroke_dasharray.values.push_back( spilength );
}
if (penstyle==U_PS_DASHDOTDOT) {
- d->dc[d->level].style.stroke_dasharray.values.push_back( 1 );
- d->dc[d->level].style.stroke_dasharray.values.push_back( 1 );
+ d->dc[d->level].style.stroke_dasharray.values.push_back( spilength );
+ d->dc[d->level].style.stroke_dasharray.values.push_back( spilength );
}
d->dc[d->level].style.stroke_dasharray.set = 1;
@@ -1181,9 +1186,13 @@ Emf::select_extpen(PEMF_CALLBACK_DATA d, int index)
if (pEmr->elp.elpNumEntries) {
if (!d->dc[d->level].style.stroke_dasharray.values.empty() && (d->level==0 || (d->level>0 && d->dc[d->level].style.stroke_dasharray.values!=d->dc[d->level-1].style.stroke_dasharray.values)))
d->dc[d->level].style.stroke_dasharray.values.clear();
+ SPILength spilength;
for (unsigned int i=0; i<pEmr->elp.elpNumEntries; i++) {
double dash_length = pix_to_abs_size( d, pEmr->elp.elpStyleEntry[i] );
- d->dc[d->level].style.stroke_dasharray.values.push_back(dash_length);
+ Inkscape::CSSOStringStream osarray;
+ osarray << dash_length;
+ spilength.read(osarray.str().c_str());
+ d->dc[d->level].style.stroke_dasharray.values.push_back(spilength);
}
d->dc[d->level].style.stroke_dasharray.set = 1;
} else {
@@ -1200,17 +1209,24 @@ Emf::select_extpen(PEMF_CALLBACK_DATA d, int index)
int penstyle = (pEmr->elp.elpPenStyle & U_PS_STYLE_MASK);
if (!d->dc[d->level].style.stroke_dasharray.values.empty() && (d->level==0 || (d->level>0 && d->dc[d->level].style.stroke_dasharray.values!=d->dc[d->level-1].style.stroke_dasharray.values)))
d->dc[d->level].style.stroke_dasharray.values.clear();
+ SPILength spilength;
if (penstyle==U_PS_DASH || penstyle==U_PS_DASHDOT || penstyle==U_PS_DASHDOTDOT) {
- d->dc[d->level].style.stroke_dasharray.values.push_back( 3 );
- d->dc[d->level].style.stroke_dasharray.values.push_back( 2 );
+ spilength.read("3");
+ d->dc[d->level].style.stroke_dasharray.values.push_back( spilength );
+ spilength.read("2");
+ d->dc[d->level].style.stroke_dasharray.values.push_back( spilength );
}
if (penstyle==U_PS_DOT || penstyle==U_PS_DASHDOT || penstyle==U_PS_DASHDOTDOT) {
- d->dc[d->level].style.stroke_dasharray.values.push_back( 1 );
- d->dc[d->level].style.stroke_dasharray.values.push_back( 2 );
+ spilength.read("1");
+ d->dc[d->level].style.stroke_dasharray.values.push_back( spilength );
+ spilength.read("2");
+ d->dc[d->level].style.stroke_dasharray.values.push_back( spilength );
}
if (penstyle==U_PS_DASHDOTDOT) {
- d->dc[d->level].style.stroke_dasharray.values.push_back( 1 );
- d->dc[d->level].style.stroke_dasharray.values.push_back( 2 );
+ spilength.read("1");
+ d->dc[d->level].style.stroke_dasharray.values.push_back( spilength );
+ spilength.read("2");
+ d->dc[d->level].style.stroke_dasharray.values.push_back( spilength );
}
d->dc[d->level].style.stroke_dasharray.set = 1;
diff --git a/src/extension/internal/emf-print.cpp b/src/extension/internal/emf-print.cpp
index 254000db3..ee698ea4a 100644
--- a/src/extension/internal/emf-print.cpp
+++ b/src/extension/internal/emf-print.cpp
@@ -695,7 +695,7 @@ 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].value > 0.00000001) {
linestyle = U_PS_USERSTYLE;
}
i++;
@@ -705,7 +705,7 @@ int PrintEmf::create_pen(SPStyle const *style, const Geom::Affine &transform)
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));
+ dash[i] = MAX(1, (uint32_t) round(scale * style->stroke_dasharray.values[i].value * PX2WORLD));
}
}
}
@@ -1458,7 +1458,7 @@ unsigned int PrintEmf::stroke(
// 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++];
+ elength = slength + style->stroke_dasharray.values[i++].value;
if (elength > tlength) {
elength = tlength;
}
@@ -1469,7 +1469,7 @@ unsigned int PrintEmf::stroke(
first_frag = fragment;
}
slength = elength;
- slength += style->stroke_dasharray.values[i++]; // the gap
+ slength += style->stroke_dasharray.values[i++].value; // the gap
if (i >= n_dash) {
i = 0;
}
diff --git a/src/extension/internal/javafx-out.cpp b/src/extension/internal/javafx-out.cpp
index ad8fa855d..ffe50bc7d 100644
--- a/src/extension/internal/javafx-out.cpp
+++ b/src/extension/internal/javafx-out.cpp
@@ -441,9 +441,9 @@ bool JavaFXOutput::doStyle(SPStyle *style)
out(" strokeDashArray: [ ");
for(unsigned i = 0; i < style->stroke_dasharray.values.size(); i++ ) {
if (i > 0) {
- out(", %.2lf", style->stroke_dasharray.values[i]);
+ out(", %.2lf", style->stroke_dasharray.values[i].value);
}else {
- out(" %.2lf", style->stroke_dasharray.values[i]);
+ out(" %.2lf", style->stroke_dasharray.values[i].value);
}
}
out(" ]\n");
diff --git a/src/extension/internal/latex-pstricks.cpp b/src/extension/internal/latex-pstricks.cpp
index f3bf06708..4f0eb7709 100644
--- a/src/extension/internal/latex-pstricks.cpp
+++ b/src/extension/internal/latex-pstricks.cpp
@@ -244,7 +244,7 @@ unsigned int PrintLatex::stroke(Inkscape::Extension::Print * /*mod*/,
if ((i)) {
os << " ";
}
- os << style->stroke_dasharray.values[i];
+ os << style->stroke_dasharray.values[i].value;
}
}
diff --git a/src/extension/internal/wmf-inout.cpp b/src/extension/internal/wmf-inout.cpp
index 72d44e123..b6d0b8ba1 100644
--- a/src/extension/internal/wmf-inout.cpp
+++ b/src/extension/internal/wmf-inout.cpp
@@ -892,7 +892,7 @@ Wmf::output_style(PWMF_CALLBACK_DATA d)
for (unsigned i=0; i<d->dc[d->level].style.stroke_dasharray.values.size(); i++) {
if (i)
tmp_style << ",";
- tmp_style << d->dc[d->level].style.stroke_dasharray.values[i];
+ tmp_style << d->dc[d->level].style.stroke_dasharray.values[i].value;
}
tmp_style << ";";
tmp_style << "stroke-dashoffset:0;";
@@ -985,19 +985,23 @@ Wmf::select_pen(PWMF_CALLBACK_DATA d, int index)
case U_PS_DASHDOTDOT:
{
int penstyle = (up.Style & U_PS_STYLE_MASK);
+ SPILength spilength;
+ spilength.read("1");
if (!d->dc[d->level].style.stroke_dasharray.values.empty() && (d->level==0 || (d->level>0 && d->dc[d->level].style.stroke_dasharray.values!=d->dc[d->level-1].style.stroke_dasharray.values)))
d->dc[d->level].style.stroke_dasharray.values.clear();
if (penstyle==U_PS_DASH || penstyle==U_PS_DASHDOT || penstyle==U_PS_DASHDOTDOT) {
- d->dc[d->level].style.stroke_dasharray.values.push_back( 3 );
- d->dc[d->level].style.stroke_dasharray.values.push_back( 1 );
+ spilength.read("3");
+ d->dc[d->level].style.stroke_dasharray.values.push_back( spilength );
+ spilength.read("1");
+ d->dc[d->level].style.stroke_dasharray.values.push_back( spilength );
}
if (penstyle==U_PS_DOT || penstyle==U_PS_DASHDOT || penstyle==U_PS_DASHDOTDOT) {
- d->dc[d->level].style.stroke_dasharray.values.push_back( 1 );
- d->dc[d->level].style.stroke_dasharray.values.push_back( 1 );
+ d->dc[d->level].style.stroke_dasharray.values.push_back( spilength );
+ d->dc[d->level].style.stroke_dasharray.values.push_back( spilength );
}
if (penstyle==U_PS_DASHDOTDOT) {
- d->dc[d->level].style.stroke_dasharray.values.push_back( 1 );
- d->dc[d->level].style.stroke_dasharray.values.push_back( 1 );
+ d->dc[d->level].style.stroke_dasharray.values.push_back( spilength );
+ d->dc[d->level].style.stroke_dasharray.values.push_back( spilength );
}
d->dc[d->level].style.stroke_dasharray.set = 1;
diff --git a/src/extension/internal/wmf-print.cpp b/src/extension/internal/wmf-print.cpp
index 613ae3f04..3419ac89a 100644
--- a/src/extension/internal/wmf-print.cpp
+++ b/src/extension/internal/wmf-print.cpp
@@ -603,7 +603,7 @@ int PrintWmf::create_pen(SPStyle const *style, const Geom::Affine &transform)
int mark_long =0;
int i;
for (i=0;i<n_dash;i++) {
- int mark = style->stroke_dasharray.values[i];
+ int mark = style->stroke_dasharray.values[i].value;
if (mark>mark_long) { mark_long = mark; }
if (mark<mark_short) { mark_short = mark; }
}
@@ -890,7 +890,7 @@ unsigned int PrintWmf::stroke(
// 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++];
+ elength = slength + style->stroke_dasharray.values[i++].value;
if (elength > tlength) {
elength = tlength;
}
@@ -901,7 +901,7 @@ unsigned int PrintWmf::stroke(
first_frag = fragment;
}
slength = elength;
- slength += style->stroke_dasharray.values[i++]; // the gap
+ slength += style->stroke_dasharray.values[i++].value; // the gap
if (i >= n_dash) {
i = 0;
}
diff --git a/src/livarot/PathCutting.cpp b/src/livarot/PathCutting.cpp
index 3c518c521..d99091ade 100644
--- a/src/livarot/PathCutting.cpp
+++ b/src/livarot/PathCutting.cpp
@@ -63,7 +63,7 @@ void Path::DashPolylineFromStyle(SPStyle *style, float scale, float min_len)
double dlen = 0.0;
// Find total length
for (unsigned i = 0; i < style->stroke_dasharray.values.size(); i++) {
- dlen += style->stroke_dasharray.values[i] * scale;
+ dlen += style->stroke_dasharray.values[i].value * scale;
}
if (dlen >= min_len) {
// Extract out dash pattern (relative positions)
@@ -71,7 +71,7 @@ void Path::DashPolylineFromStyle(SPStyle *style, float scale, float min_len)
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;
+ dash[i] = style->stroke_dasharray.values[i].value * scale;
}
// Convert relative positions to absolute postions
diff --git a/src/object/sp-item.cpp b/src/object/sp-item.cpp
index ec92c655f..fa281e9ee 100644
--- a/src/object/sp-item.cpp
+++ b/src/object/sp-item.cpp
@@ -22,6 +22,7 @@
#include "bad-uri-exception.h"
#include "svg/svg.h"
+#include "svg/css-ostringstream.h"
#include "print.h"
#include "display/drawing-item.h"
#include "attributes.h"
@@ -1307,7 +1308,10 @@ void SPItem::adjust_stroke( gdouble ex )
if ( !style->stroke_dasharray.values.empty() ) {
for (unsigned i = 0; i < style->stroke_dasharray.values.size(); i++) {
- style->stroke_dasharray.values[i] *= ex;
+ double dash = style->stroke_dasharray.values[i].value * ex;
+ Inkscape::CSSOStringStream osarray;
+ osarray << dash;
+ style->stroke_dasharray.values[i].read(osarray.str().c_str());
}
style->stroke_dashoffset.value *= ex;
}
diff --git a/src/preferences-skeleton.h b/src/preferences-skeleton.h
index 2a6083e55..c9479e90e 100644
--- a/src/preferences-skeleton.h
+++ b/src/preferences-skeleton.h
@@ -307,6 +307,7 @@ static char const preferences_skeleton[] =
" <group id=\"stickyzoom\" value=\"0\"/>\n"
" <group id=\"selcue\" value=\"2\"/>\n"
" <group id=\"transform\" stroke=\"1\" rectcorners=\"1\" pattern=\"1\" gradient=\"1\" />\n"
+" <group id=\"dash\" scale=\"1\" />\n"
" <group id=\"kbselection\" inlayer=\"1\" onlyvisible=\"1\" onlysensitive=\"1\" />\n"
" <group id=\"selection\" layerdeselect=\"1\" />\n"
" <group id=\"createbitmap\"/>\n"
diff --git a/src/style-internal.cpp b/src/style-internal.cpp
index 17391c4bd..400ef2e77 100644
--- a/src/style-internal.cpp
+++ b/src/style-internal.cpp
@@ -36,7 +36,7 @@
#include "preferences.h"
#include "streq.h"
#include "strneq.h"
-
+#include "inkscape.h"
#include "svg/svg.h"
#include "svg/svg-color.h"
#include "svg/css-ostringstream.h"
@@ -430,8 +430,60 @@ SPILength::merge( const SPIBase* const parent ) {
}
}
+// Generate a string useful for passing dasharray without name, etc.
+const Glib::ustring
+SPILength::toString( guint const flags, SPStyleSrc const &style_src_req, SPIBase const *const base) const {
+ SPILength const *const my_base = dynamic_cast<const SPILength*>(base);
+ bool dfp = (!inherits || !my_base || (my_base != this)); // Different from parent
+ bool src = (style_src_req == style_src || !(flags & SP_STYLE_FLAG_IFSRC));
+ if (should_write(flags, set, dfp, src)) {
+ if (this->inherit) {
+ return ("inherit");
+ } else {
+ Inkscape::CSSOStringStream os;
+ switch (this->unit) {
+ case SP_CSS_UNIT_NONE:
+ os << this->computed;
+ break;
+ case SP_CSS_UNIT_PX:
+ os << this->computed << "px";
+ break;
+ case SP_CSS_UNIT_PT:
+ os << Inkscape::Util::Quantity::convert(this->computed, "px", "pt") << "pt";
+ break;
+ case SP_CSS_UNIT_PC:
+ os << Inkscape::Util::Quantity::convert(this->computed, "px", "pc") << "pc";
+ break;
+ case SP_CSS_UNIT_MM:
+ os << Inkscape::Util::Quantity::convert(this->computed, "px", "mm") << "mm";
+ break;
+ case SP_CSS_UNIT_CM:
+ os << Inkscape::Util::Quantity::convert(this->computed, "px", "cm") << "cm";
+ break;
+ case SP_CSS_UNIT_IN:
+ os << Inkscape::Util::Quantity::convert(this->computed, "px", "in") << "in";
+ break;
+ case SP_CSS_UNIT_EM:
+ os << this->value << "em";
+ break;
+ case SP_CSS_UNIT_EX:
+ os << this->value << "ex";
+ break;
+ case SP_CSS_UNIT_PERCENT:
+ os << (this->value * 100.0) << "%";
+ break;
+ default:
+ /* Invalid */
+ break;
+ }
+ return os.str();
+ }
+ }
+ return Glib::ustring("");
+}
+
bool
-SPILength::operator==(const SPIBase& rhs) {
+SPILength::operator==(const SPIBase& rhs) const {
if( const SPILength* r = dynamic_cast<const SPILength*>(&rhs) ) {
if( unit != r->unit ) return false;
@@ -450,8 +502,6 @@ SPILength::operator==(const SPIBase& rhs) {
}
}
-
-
// SPILengthOrNormal ----------------------------------------------------
void
@@ -2033,23 +2083,30 @@ SPIDashArray::read( gchar const *str ) {
if( strcmp(str, "none") == 0) {
return;
}
-
- // std::vector<Glib::ustring> tokens = Glib::Regex::split_simple("[,\\s]+", str );
+ std::vector<Glib::ustring> tokens = Glib::Regex::split_simple("[,\\s]+", str );
gchar *e = NULL;
bool LineSolid = true;
- while (e != str && *str != '\0') {
- /* TODO: Should allow <length> rather than just a unitless (px) number. */
- double number = g_ascii_strtod(str, (char **) &e);
- values.push_back( number );
- if (number > 0.00000001)
- LineSolid = false;
- if (e != str) {
- str = e;
+ SPDocument * document = SP_ACTIVE_DOCUMENT;
+ Geom::Rect vbox = document->getViewBox();
+ for (auto token:tokens) {
+ SPILength spilength;
+ spilength.read(token.c_str());
+ if(spilength.value > 0.00000001)
+ LineSolid = false;
+ double dash = 0;
+ if(spilength.unit == SPCSSUnit::SP_CSS_UNIT_NONE) {
+ dash = spilength.value;
+ } else if (spilength.unit == SPCSSUnit::SP_CSS_UNIT_PERCENT) {
+ dash = vbox.width() * spilength.value;
+ } else {
+ dash = spilength.computed / document->getDocumentScale()[0];
}
- while (str && *str && !(isalnum(*str) || *str=='.')) str += 1;
+ Inkscape::CSSOStringStream osarray;
+ osarray << dash;
+ spilength.read(osarray.str().c_str());
+ values.push_back(spilength);
}
-
if (LineSolid) {
values.clear();
}
@@ -2074,7 +2131,7 @@ SPIDashArray::write( guint const flags, SPStyleSrc const &style_src_req, SPIBase
if (i) {
os << ", ";
}
- os << this->values[i];
+ os << this->values[i].toString().c_str();
}
os << important_str();
os << ";";
@@ -2111,15 +2168,17 @@ SPIDashArray::merge( const SPIBase* const parent ) {
bool
SPIDashArray::operator==(const SPIBase& rhs) {
- if( const SPIDashArray* r = dynamic_cast<const SPIDashArray*>(&rhs) ) {
- return values == r->values && SPIBase::operator==(rhs);
- } else {
- return false;
+ if( const SPIDashArray* r = dynamic_cast<const SPIDashArray*>(&rhs) ) {
+ for (int i = 0;i < values.size(); i++) {
+ if (values[i] != r->values[i]) {
+ return false;
+ }
+ }
}
+ return SPIBase::operator==(rhs);
}
-
// SPIFontSize ----------------------------------------------------------
/** Indexed by SP_CSS_FONT_SIZE_blah. These seem a bit small */
diff --git a/src/style-internal.h b/src/style-internal.h
index 869f862af..4ddad939b 100644
--- a/src/style-internal.h
+++ b/src/style-internal.h
@@ -403,6 +403,10 @@ public:
return !(*this == rhs);
}
+ virtual const Glib::ustring toString(guint const flags = SP_STYLE_FLAG_IFSET,
+ SPStyleSrc const &style_src_req = SP_STYLE_SRC_STYLE_PROP,
+ SPIBase const *const base = NULL) const;
+
// To do: make private
public:
unsigned unit : 4;
@@ -1012,7 +1016,7 @@ public:
// To do: make private, change double to SVGLength
public:
- std::vector<double> values;
+ std::vector<SPILength> values;
};
/// Filter type internal to SPStyle
diff --git a/src/ui/dialog/inkscape-preferences.cpp b/src/ui/dialog/inkscape-preferences.cpp
index 70ee0a78a..9e6ff92c1 100644
--- a/src/ui/dialog/inkscape-preferences.cpp
+++ b/src/ui/dialog/inkscape-preferences.cpp
@@ -1447,6 +1447,12 @@ void InkscapePreferences::initPageBehavior()
_("Always store transformation as a transform= attribute on objects"));
this->AddPage(_page_transforms, _("Transforms"), iter_behavior, PREFS_PAGE_BEHAVIOR_TRANSFORMS);
+
+ _dash_scale.init ( _("Stroke width change dashes"), "/options/dash/scale", true);
+ _page_dashes.add_line( false, "", _dash_scale, "",
+ _("When chage stroke width, scale the dash array"));
+
+ this->AddPage(_page_dashes, _("Dashes"), iter_behavior, PREFS_PAGE_BEHAVIOR_DASHES);
// Scrolling options
_scroll_wheel.init ( "/options/wheelscroll/value", 0.0, 1000.0, 1.0, 1.0, 40.0, true, false);
diff --git a/src/ui/dialog/inkscape-preferences.h b/src/ui/dialog/inkscape-preferences.h
index a2f758287..55ea35f63 100644
--- a/src/ui/dialog/inkscape-preferences.h
+++ b/src/ui/dialog/inkscape-preferences.h
@@ -77,6 +77,7 @@ enum {
PREFS_PAGE_BEHAVIOR,
PREFS_PAGE_BEHAVIOR_SELECTING,
PREFS_PAGE_BEHAVIOR_TRANSFORMS,
+ PREFS_PAGE_BEHAVIOR_DASHES,
PREFS_PAGE_BEHAVIOR_SCROLLING,
PREFS_PAGE_BEHAVIOR_SNAPPING,
PREFS_PAGE_BEHAVIOR_STEPS,
@@ -168,6 +169,7 @@ protected:
UI::Widget::DialogPage _page_behavior;
UI::Widget::DialogPage _page_select;
UI::Widget::DialogPage _page_transforms;
+ UI::Widget::DialogPage _page_dashes;
UI::Widget::DialogPage _page_scrolling;
UI::Widget::DialogPage _page_snapping;
UI::Widget::DialogPage _page_steps;
@@ -317,6 +319,8 @@ protected:
UI::Widget::PrefRadioButton _trans_optimized;
UI::Widget::PrefRadioButton _trans_preserved;
+ UI::Widget::PrefCheckButton _dash_scale;
+
UI::Widget::PrefRadioButton _sel_all;
UI::Widget::PrefRadioButton _sel_current;
UI::Widget::PrefRadioButton _sel_recursive;
diff --git a/src/widgets/dash-selector.cpp b/src/widgets/dash-selector.cpp
index 37bf08b3d..5ad74914a 100644
--- a/src/widgets/dash-selector.cpp
+++ b/src/widgets/dash-selector.cpp
@@ -120,7 +120,7 @@ void SPDashSelector::init_dashes() {
double *d = dashes[pos];
unsigned i = 0;
for (; i < style.stroke_dasharray.values.size(); i++) {
- d[i] = style.stroke_dasharray.values[i];
+ d[i] = style.stroke_dasharray.values[i].value;
}
d[i] = -1;
} else {
diff --git a/src/widgets/stroke-style.cpp b/src/widgets/stroke-style.cpp
index 3a5abbca4..ae49f9e40 100644
--- a/src/widgets/stroke-style.cpp
+++ b/src/widgets/stroke-style.cpp
@@ -741,14 +741,21 @@ StrokeStyle::setDashSelectorFromStyle(SPDashSelector *dsel, SPStyle *style)
if (!style->stroke_dasharray.values.empty()) {
double d[64];
size_t len = MIN(style->stroke_dasharray.values.size(), 64);
+ /* Set dash */
+ Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+ gboolean scale = prefs->getBool("/options/dash/scale", true);
+ double scaledash = 1.0;
+ if (scale) {
+ scaledash = style->stroke_width.computed;
+ }
for (unsigned i = 0; i < len; i++) {
if (style->stroke_width.computed != 0)
- d[i] = style->stroke_dasharray.values[i] / style->stroke_width.computed;
+ d[i] = style->stroke_dasharray.values[i].value / scaledash;
else
- d[i] = style->stroke_dasharray.values[i]; // is there a better thing to do for stroke_width==0?
+ d[i] = style->stroke_dasharray.values[i].value; // is there a better thing to do for stroke_width==0?
}
dsel->set_dash(len, d, style->stroke_width.computed != 0 ?
- style->stroke_dashoffset.value / style->stroke_width.computed :
+ style->stroke_dashoffset.value / scaledash :
style->stroke_dashoffset.value);
} else {
dsel->set_dash(0, nullptr, 0.0);
@@ -1042,8 +1049,13 @@ StrokeStyle::scaleLine()
}
/* Set dash */
- setScaledDash(css, ndash, dash, offset, width);
-
+ Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+ gboolean scale = prefs->getBool("/options/dash/scale", true);
+ if (scale) {
+ setScaledDash(css, ndash, dash, offset, width);
+ } else {
+ setScaledDash(css, ndash, dash, offset, document->getDocumentScale()[0]);
+ }
sp_desktop_apply_css_recursive ((*i), css, true);
}