From 3788e27cfdd54d85e5e20f5facd88298f3dd45f0 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Date: Tue, 21 Aug 2018 15:39:40 +0200 Subject: [PATCH 01/12] improve SPILength --- src/extension/internal/emf-inout.cpp | 32 ++++++++++++++++------- src/extension/internal/wmf-inout.cpp | 11 +++++--- src/style-internal.cpp | 38 +++++++++++++++------------- src/style-internal.h | 1 - src/widgets/stroke-style.cpp | 5 ++-- 5 files changed, 55 insertions(+), 32 deletions(-) diff --git a/src/extension/internal/emf-inout.cpp b/src/extension/internal/emf-inout.cpp index a0803aafcf..97d5a6968e 100644 --- a/src/extension/internal/emf-inout.cpp +++ b/src/extension/internal/emf-inout.cpp @@ -1095,16 +1095,21 @@ Emf::select_pen(PEMF_CALLBACK_DATA d, int index) case U_PS_DASHDOT: case U_PS_DASHDOTDOT: { - SPILength spilength("temp", 1); + SPDocument *document = SP_ACTIVE_DOCUMENT; + double scale_doc = document->getDocumentScale()[0]; + SPILength spilength("temp"); + spilength.unit = SP_CSS_UNIT_NONE; 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 != d->dc[d->level - 1].style.stroke_dasharray))) d->dc[d->level].style.stroke_dasharray.values.clear(); if (penstyle==U_PS_DASH || penstyle==U_PS_DASHDOT || penstyle==U_PS_DASHDOTDOT) { - spilength.setDouble(3); + spilength.value = 3; + spilength.computed = 3 * scale_doc; d->dc[d->level].style.stroke_dasharray.values.push_back(spilength); - spilength.setDouble(1); + spilength.value = 1; + spilength.computed = scale_doc; d->dc[d->level].style.stroke_dasharray.values.push_back(spilength); } if (penstyle==U_PS_DOT || penstyle==U_PS_DASHDOT || penstyle==U_PS_DASHDOTDOT) { @@ -1210,23 +1215,32 @@ Emf::select_extpen(PEMF_CALLBACK_DATA d, int index) (d->level == 0 || (d->level > 0 && d->dc[d->level].style.stroke_dasharray != d->dc[d->level - 1].style.stroke_dasharray))) d->dc[d->level].style.stroke_dasharray.values.clear(); + SPDocument *document = SP_ACTIVE_DOCUMENT; + double scale_doc = document->getDocumentScale()[0]; SPILength spilength("temp"); + spilength.unit = SP_CSS_UNIT_NONE; if (penstyle==U_PS_DASH || penstyle==U_PS_DASHDOT || penstyle==U_PS_DASHDOTDOT) { - spilength.setDouble(3); + spilength.value = 3; + spilength.computed = 3 * scale_doc; d->dc[d->level].style.stroke_dasharray.values.push_back(spilength); - spilength.setDouble(2); + spilength.value = 2; + spilength.computed = 2 * scale_doc; d->dc[d->level].style.stroke_dasharray.values.push_back(spilength); } if (penstyle==U_PS_DOT || penstyle==U_PS_DASHDOT || penstyle==U_PS_DASHDOTDOT) { - spilength.setDouble(1); + spilength.value = 1; + spilength.computed = 1 * scale_doc; d->dc[d->level].style.stroke_dasharray.values.push_back(spilength); - spilength.setDouble(2); + spilength.value = 2; + spilength.computed = 2 * scale_doc; d->dc[d->level].style.stroke_dasharray.values.push_back(spilength); } if (penstyle==U_PS_DASHDOTDOT) { - spilength.setDouble(1); + spilength.value = 1; + spilength.computed = 1 * scale_doc; d->dc[d->level].style.stroke_dasharray.values.push_back(spilength); - spilength.setDouble(2); + spilength.value = 2; + spilength.computed = 2 * scale_doc; d->dc[d->level].style.stroke_dasharray.values.push_back(spilength); } diff --git a/src/extension/internal/wmf-inout.cpp b/src/extension/internal/wmf-inout.cpp index 3bc6b1b3df..a23ac02113 100644 --- a/src/extension/internal/wmf-inout.cpp +++ b/src/extension/internal/wmf-inout.cpp @@ -984,16 +984,21 @@ Wmf::select_pen(PWMF_CALLBACK_DATA d, int index) case U_PS_DASHDOT: case U_PS_DASHDOTDOT: { + SPDocument *document = SP_ACTIVE_DOCUMENT; + double scale_doc = document->getDocumentScale()[0]; + SPILength spilength("temp"); + spilength.unit = SP_CSS_UNIT_NONE; int penstyle = (up.Style & U_PS_STYLE_MASK); - SPILength spilength("temp", 1); if (!d->dc[d->level].style.stroke_dasharray.values.empty() && (d->level == 0 || (d->level > 0 && d->dc[d->level].style.stroke_dasharray != d->dc[d->level - 1].style.stroke_dasharray))) d->dc[d->level].style.stroke_dasharray.values.clear(); if (penstyle==U_PS_DASH || penstyle==U_PS_DASHDOT || penstyle==U_PS_DASHDOTDOT) { - spilength.setDouble(3); + spilength.value = 3; + spilength.computed = 3 * scale_doc; d->dc[d->level].style.stroke_dasharray.values.push_back(spilength); - spilength.setDouble(1); + spilength.value = 1; + spilength.computed = scale_doc; d->dc[d->level].style.stroke_dasharray.values.push_back(spilength); } if (penstyle==U_PS_DOT || penstyle==U_PS_DASHDOT || penstyle==U_PS_DASHDOTDOT) { diff --git a/src/style-internal.cpp b/src/style-internal.cpp index 39e334d1fc..21e6f68a30 100644 --- a/src/style-internal.cpp +++ b/src/style-internal.cpp @@ -247,9 +247,13 @@ SPILength::read( gchar const *str ) { gchar *e; /** \todo fixme: Move this to standard place (Lauris) */ value_tmp = g_ascii_strtod(str, &e); + if ( !IS_FINITE(value_tmp) ) { // fix for bug lp:935157 return; } + SPDocument *document = SP_ACTIVE_DOCUMENT; + double scale_doc = document->getDocumentScale()[0]; + if ((gchar const *) e != str) { value = value_tmp; @@ -259,40 +263,48 @@ SPILength::read( gchar const *str ) { computed = value; } else if (!strcmp(e, "px")) { /* Userspace */ - unit = SP_CSS_UNIT_PX; + unit = SP_CSS_UNIT_NONE; computed = value; + value = computed / scale_doc; } else if (!strcmp(e, "pt")) { /* Userspace / DEVICESCALE */ - unit = SP_CSS_UNIT_PT; + unit = SP_CSS_UNIT_NONE; computed = Inkscape::Util::Quantity::convert(value, "pt", "px"); + value = computed / scale_doc; } else if (!strcmp(e, "pc")) { - unit = SP_CSS_UNIT_PC; + unit = SP_CSS_UNIT_NONE; computed = Inkscape::Util::Quantity::convert(value, "pc", "px"); + value = computed / scale_doc; } else if (!strcmp(e, "mm")) { - unit = SP_CSS_UNIT_MM; + unit = SP_CSS_UNIT_NONE; computed = Inkscape::Util::Quantity::convert(value, "mm", "px"); + value = computed / scale_doc; } else if (!strcmp(e, "cm")) { - unit = SP_CSS_UNIT_CM; + unit = SP_CSS_UNIT_NONE; computed = Inkscape::Util::Quantity::convert(value, "cm", "px"); + value = computed / scale_doc; } else if (!strcmp(e, "in")) { - unit = SP_CSS_UNIT_IN; + unit = SP_CSS_UNIT_NONE; computed = Inkscape::Util::Quantity::convert(value, "in", "px"); + value = computed / scale_doc; } else if (!strcmp(e, "em")) { /* EM square */ - unit = SP_CSS_UNIT_EM; + unit = SP_CSS_UNIT_NONE; if( style ) { computed = value * style->font_size.computed; } else { computed = value * SPIFontSize::font_size_default; } + value = computed / scale_doc; } else if (!strcmp(e, "ex")) { /* ex square */ - unit = SP_CSS_UNIT_EX; + unit = SP_CSS_UNIT_NONE; if( style ) { computed = value * style->font_size.computed * 0.5; // FIXME } else { computed = value * SPIFontSize::font_size_default * 0.5; } + value = computed / scale_doc; } else if (!strcmp(e, "%")) { /* Percentage */ unit = SP_CSS_UNIT_PERCENT; @@ -393,14 +405,6 @@ SPILength::merge( const SPIBase* const parent ) { } } -void SPILength::setDouble(double v) -{ - unit = SP_CSS_UNIT_NONE; - value = v; - computed = v; - value_default = v; -} - // Generate a string and allow emove name for parsing dasharray, etc. const Glib::ustring SPILength::toString(bool wname) const { @@ -411,7 +415,7 @@ Inkscape: } switch (this->unit) { case SP_CSS_UNIT_NONE: - os << this->computed; + os << this->value; break; case SP_CSS_UNIT_PX: os << this->computed << "px"; diff --git a/src/style-internal.h b/src/style-internal.h index f716601f62..61d1c78b69 100644 --- a/src/style-internal.h +++ b/src/style-internal.h @@ -402,7 +402,6 @@ public: bool operator!=(const SPIBase& rhs) override { return !(*this == rhs); } - void setDouble(double v); virtual const Glib::ustring toString(bool wname = false) const; // To do: make private diff --git a/src/widgets/stroke-style.cpp b/src/widgets/stroke-style.cpp index bfa21a9eae..c3d080b88d 100644 --- a/src/widgets/stroke-style.cpp +++ b/src/widgets/stroke-style.cpp @@ -996,7 +996,8 @@ StrokeStyle::setScaledDash(SPCSSAttr *css, static inline double calcScaleLineWidth(const double width_typed, SPItem *const item, Inkscape::Util::Unit const *const unit) { if (unit->type == Inkscape::Util::UNIT_TYPE_LINEAR) { - return Inkscape::Util::Quantity::convert(width_typed, unit, "px"); + SPDocument *document = SP_ACTIVE_DOCUMENT; + return Inkscape::Util::Quantity::convert(width_typed, unit, "px") * document->getDocumentScale()[0]; } else { // percentage const gdouble old_w = item->style->stroke_width.computed; return old_w * width_typed / 100; @@ -1055,7 +1056,7 @@ StrokeStyle::scaleLine() setScaledDash(css, ndash, dash, offset, width); } else { - setScaledDash(css, ndash, dash, offset, document->getDocumentScale()[0]); + setScaledDash(css, ndash, dash, offset, 1); } sp_desktop_apply_css_recursive ((*i), css, true); } -- GitLab From 8b410ed01d7a777c229267e18c7e5fcd91539382 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Date: Tue, 21 Aug 2018 22:01:41 +0200 Subject: [PATCH 02/12] Updating SPILenght to remove tostring --- src/style-internal.cpp | 62 ++++-------------------------------- src/style-internal.h | 1 - src/widgets/stroke-style.cpp | 2 +- 3 files changed, 8 insertions(+), 57 deletions(-) diff --git a/src/style-internal.cpp b/src/style-internal.cpp index 21e6f68a30..ac0a9c6ea9 100644 --- a/src/style-internal.cpp +++ b/src/style-internal.cpp @@ -251,8 +251,10 @@ SPILength::read( gchar const *str ) { if ( !IS_FINITE(value_tmp) ) { // fix for bug lp:935157 return; } - SPDocument *document = SP_ACTIVE_DOCUMENT; - double scale_doc = document->getDocumentScale()[0]; + double scale_doc = 1; +// if (SP_ACTIVE_DOCUMENT) { +// scale_doc = SP_ACTIVE_DOCUMENT->getDocumentScale()[0]; +// } if ((gchar const *) e != str) { @@ -260,7 +262,7 @@ SPILength::read( gchar const *str ) { if (!*e) { /* Userspace */ unit = SP_CSS_UNIT_NONE; - computed = value; + computed = value * scale_doc; } else if (!strcmp(e, "px")) { /* Userspace */ unit = SP_CSS_UNIT_NONE; @@ -337,7 +339,7 @@ SPILength::write( guint const flags, SPStyleSrc const &style_src_req, SPIBase co if (this->inherit) { return (name + ":inherit;"); } else { - return toString(true); + return (name + ":" value); } } return Glib::ustring(""); @@ -405,56 +407,6 @@ SPILength::merge( const SPIBase* const parent ) { } } -// Generate a string and allow emove name for parsing dasharray, etc. -const Glib::ustring SPILength::toString(bool wname) const -{ -Inkscape: - CSSOStringStream os; - if (wname) { - os << name << ":"; - } - switch (this->unit) { - case SP_CSS_UNIT_NONE: - os << this->value; - 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; - } - if (wname) { - os << important_str(); - os << ";"; - } - return os.str(); -} - bool SPILength::operator==(const SPIBase& rhs) { if( const SPILength* r = dynamic_cast(&rhs) ) { @@ -2093,7 +2045,7 @@ SPIDashArray::write( guint const flags, SPStyleSrc const &style_src_req, SPIBase if (i) { os << ", "; } - os << this->values[i].toString().c_str(); + os << this->values[i].value; } os << important_str(); os << ";"; diff --git a/src/style-internal.h b/src/style-internal.h index 61d1c78b69..6d8e2088df 100644 --- a/src/style-internal.h +++ b/src/style-internal.h @@ -402,7 +402,6 @@ public: bool operator!=(const SPIBase& rhs) override { return !(*this == rhs); } - virtual const Glib::ustring toString(bool wname = false) const; // To do: make private public: diff --git a/src/widgets/stroke-style.cpp b/src/widgets/stroke-style.cpp index c3d080b88d..4d1bc24003 100644 --- a/src/widgets/stroke-style.cpp +++ b/src/widgets/stroke-style.cpp @@ -997,7 +997,7 @@ static inline double calcScaleLineWidth(const double width_typed, SPItem *const { if (unit->type == Inkscape::Util::UNIT_TYPE_LINEAR) { SPDocument *document = SP_ACTIVE_DOCUMENT; - return Inkscape::Util::Quantity::convert(width_typed, unit, "px") * document->getDocumentScale()[0]; + return Inkscape::Util::Quantity::convert(width_typed, unit, "px"); } else { // percentage const gdouble old_w = item->style->stroke_width.computed; return old_w * width_typed / 100; -- GitLab From e412b33586f8165d8b20d45e9362a238685dfde8 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Date: Sat, 25 Aug 2018 00:29:08 +0200 Subject: [PATCH 03/12] Fix dasharray --- src/extension/internal/emf-inout.cpp | 4 +- src/extension/internal/wmf-inout.cpp | 2 +- src/style-internal.cpp | 149 ++++++++++++++++++++++----- src/widgets/stroke-style.cpp | 21 ++-- 4 files changed, 130 insertions(+), 46 deletions(-) diff --git a/src/extension/internal/emf-inout.cpp b/src/extension/internal/emf-inout.cpp index 97d5a6968e..2b9cc62a51 100644 --- a/src/extension/internal/emf-inout.cpp +++ b/src/extension/internal/emf-inout.cpp @@ -1096,7 +1096,7 @@ Emf::select_pen(PEMF_CALLBACK_DATA d, int index) case U_PS_DASHDOTDOT: { SPDocument *document = SP_ACTIVE_DOCUMENT; - double scale_doc = document->getDocumentScale()[0]; + double scale_doc = Geom::Affine(document->getDocumentScale()).descrim(); SPILength spilength("temp"); spilength.unit = SP_CSS_UNIT_NONE; int penstyle = (pEmr->lopn.lopnStyle & U_PS_STYLE_MASK); @@ -1216,7 +1216,7 @@ Emf::select_extpen(PEMF_CALLBACK_DATA d, int index) d->dc[d->level - 1].style.stroke_dasharray))) d->dc[d->level].style.stroke_dasharray.values.clear(); SPDocument *document = SP_ACTIVE_DOCUMENT; - double scale_doc = document->getDocumentScale()[0]; + double scale_doc = Geom::Affine(document->getDocumentScale()).descrim(); SPILength spilength("temp"); spilength.unit = SP_CSS_UNIT_NONE; if (penstyle==U_PS_DASH || penstyle==U_PS_DASHDOT || penstyle==U_PS_DASHDOTDOT) { diff --git a/src/extension/internal/wmf-inout.cpp b/src/extension/internal/wmf-inout.cpp index a23ac02113..fbf3d4559e 100644 --- a/src/extension/internal/wmf-inout.cpp +++ b/src/extension/internal/wmf-inout.cpp @@ -985,7 +985,7 @@ Wmf::select_pen(PWMF_CALLBACK_DATA d, int index) case U_PS_DASHDOTDOT: { SPDocument *document = SP_ACTIVE_DOCUMENT; - double scale_doc = document->getDocumentScale()[0]; + double scale_doc = Geom::Affine(document->getDocumentScale()).descrim(); SPILength spilength("temp"); spilength.unit = SP_CSS_UNIT_NONE; int penstyle = (up.Style & U_PS_STYLE_MASK); diff --git a/src/style-internal.cpp b/src/style-internal.cpp index ac0a9c6ea9..142de3f579 100644 --- a/src/style-internal.cpp +++ b/src/style-internal.cpp @@ -35,6 +35,7 @@ #include "extract-uri.h" #include "inkscape.h" #include "preferences.h" +#include "document.h" #include "streq.h" #include "strneq.h" @@ -247,66 +248,83 @@ SPILength::read( gchar const *str ) { gchar *e; /** \todo fixme: Move this to standard place (Lauris) */ value_tmp = g_ascii_strtod(str, &e); - + if ( !IS_FINITE(value_tmp) ) { // fix for bug lp:935157 + return; + } + bool wnormal = false; + if (name.compare( "line-height" ) == 0 || + name.compare( "word-spacing" ) == 0 || + name.compare( "letter-spacing" ) == 0) + { + wnormal = true; + } + if ( !IS_FINITE(value_tmp) ) { // fix for bug lp:935157 return; } double scale_doc = 1; -// if (SP_ACTIVE_DOCUMENT) { -// scale_doc = SP_ACTIVE_DOCUMENT->getDocumentScale()[0]; -// } - + if (!wnormal && Inkscape::Application::exists() && SP_ACTIVE_DOCUMENT) { + scale_doc = Geom::Affine(SP_ACTIVE_DOCUMENT->getDocumentScale()).descrim(); + } else { + //If no application dont transform SPILenghts + wnormal = true; + } if ((gchar const *) e != str) { - value = value_tmp; if (!*e) { /* Userspace */ unit = SP_CSS_UNIT_NONE; - computed = value * scale_doc; + computed = value; } else if (!strcmp(e, "px")) { /* Userspace */ - unit = SP_CSS_UNIT_NONE; + unit = wnormal? SP_CSS_UNIT_PX : SP_CSS_UNIT_NONE; computed = value; - value = computed / scale_doc; } else if (!strcmp(e, "pt")) { /* Userspace / DEVICESCALE */ - unit = SP_CSS_UNIT_NONE; + unit = wnormal? SP_CSS_UNIT_PT : SP_CSS_UNIT_NONE; computed = Inkscape::Util::Quantity::convert(value, "pt", "px"); - value = computed / scale_doc; + value = wnormal? value : computed / scale_doc; + computed = value; } else if (!strcmp(e, "pc")) { - unit = SP_CSS_UNIT_NONE; + unit = wnormal? SP_CSS_UNIT_PC : SP_CSS_UNIT_NONE; computed = Inkscape::Util::Quantity::convert(value, "pc", "px"); - value = computed / scale_doc; + value = wnormal? value : computed / scale_doc; + computed = value; } else if (!strcmp(e, "mm")) { - unit = SP_CSS_UNIT_NONE; + unit = wnormal? SP_CSS_UNIT_MM : SP_CSS_UNIT_NONE; computed = Inkscape::Util::Quantity::convert(value, "mm", "px"); - value = computed / scale_doc; + value = wnormal? value : computed / scale_doc; + computed = value; } else if (!strcmp(e, "cm")) { - unit = SP_CSS_UNIT_NONE; + unit = wnormal? SP_CSS_UNIT_CM : SP_CSS_UNIT_NONE; computed = Inkscape::Util::Quantity::convert(value, "cm", "px"); - value = computed / scale_doc; + value = wnormal? value : computed / scale_doc; + computed = value; } else if (!strcmp(e, "in")) { - unit = SP_CSS_UNIT_NONE; + unit = wnormal? SP_CSS_UNIT_IN : SP_CSS_UNIT_NONE; computed = Inkscape::Util::Quantity::convert(value, "in", "px"); - value = computed / scale_doc; + value = wnormal? value : computed / scale_doc; + computed = value; } else if (!strcmp(e, "em")) { /* EM square */ - unit = SP_CSS_UNIT_NONE; + unit = wnormal? SP_CSS_UNIT_EM : SP_CSS_UNIT_NONE; if( style ) { computed = value * style->font_size.computed; } else { computed = value * SPIFontSize::font_size_default; } - value = computed / scale_doc; + value = wnormal? value : computed / scale_doc; + computed = value; } else if (!strcmp(e, "ex")) { /* ex square */ - unit = SP_CSS_UNIT_NONE; + unit = wnormal? SP_CSS_UNIT_EX : SP_CSS_UNIT_NONE; if( style ) { computed = value * style->font_size.computed * 0.5; // FIXME } else { computed = value * SPIFontSize::font_size_default * 0.5; } - value = computed / scale_doc; + value = wnormal? value : computed / scale_doc; + computed = value; } else if (!strcmp(e, "%")) { /* Percentage */ unit = SP_CSS_UNIT_PERCENT; @@ -339,7 +357,45 @@ SPILength::write( guint const flags, SPStyleSrc const &style_src_req, SPIBase co if (this->inherit) { return (name + ":inherit;"); } else { - return (name + ":" value); + Inkscape::CSSOStringStream os; + switch (this->unit) { + case SP_CSS_UNIT_NONE: + os << name << ":" << this->computed; + break; + case SP_CSS_UNIT_PX: + os << name << ":" << this->computed << "px"; + break; + case SP_CSS_UNIT_PT: + os << name << ":" << Inkscape::Util::Quantity::convert(this->computed, "px", "pt") << "pt"; + break; + case SP_CSS_UNIT_PC: + os << name << ":" << Inkscape::Util::Quantity::convert(this->computed, "px", "pc") << "pc"; + break; + case SP_CSS_UNIT_MM: + os << name << ":" << Inkscape::Util::Quantity::convert(this->computed, "px", "mm") << "mm"; + break; + case SP_CSS_UNIT_CM: + os << name << ":" << Inkscape::Util::Quantity::convert(this->computed, "px", "cm") << "cm"; + break; + case SP_CSS_UNIT_IN: + os << name << ":" << Inkscape::Util::Quantity::convert(this->computed, "px", "in") << "in"; + break; + case SP_CSS_UNIT_EM: + os << name << ":" << this->value << "em"; + break; + case SP_CSS_UNIT_EX: + os << name << ":" << this->value << "ex"; + break; + case SP_CSS_UNIT_PERCENT: + os << name << ":" << (this->value * 100.0) << "%"; + break; + default: + /* Invalid */ + break; + } + os << important_str(); + os << ";"; + return os.str(); } } return Glib::ustring(""); @@ -410,8 +466,8 @@ SPILength::merge( const SPIBase* const parent ) { bool SPILength::operator==(const SPIBase& rhs) { if( const SPILength* r = dynamic_cast(&rhs) ) { - - if( unit != r->unit ) return false; + + if (unit != r->unit ) return false; // If length depends on external parameter, lengths cannot be equal. if (unit == SP_CSS_UNIT_EM) return false; @@ -421,7 +477,7 @@ SPILength::operator==(const SPIBase& rhs) { if (r->unit == SP_CSS_UNIT_EX) return false; if (r->unit == SP_CSS_UNIT_PERCENT) return false; - return (computed == r->computed ); + return (computed == r->computed); } else { return false; } @@ -2045,7 +2101,44 @@ SPIDashArray::write( guint const flags, SPStyleSrc const &style_src_req, SPIBase if (i) { os << ", "; } - os << this->values[i].value; + Glib::ustring unit_str=""; + switch (this->values[i].unit) { + case SP_CSS_UNIT_PX: + unit_str="px"; + break; + case SP_CSS_UNIT_PT: + unit_str="pt"; + break; + case SP_CSS_UNIT_PC: + unit_str="pc"; + break; + case SP_CSS_UNIT_MM: + unit_str="mm"; + break; + case SP_CSS_UNIT_CM: + unit_str="cm"; + break; + case SP_CSS_UNIT_IN: + unit_str="in"; + break; + case SP_CSS_UNIT_EM: + unit_str="em"; + break; + case SP_CSS_UNIT_EX: + unit_str="ex"; + break; + case SP_CSS_UNIT_PERCENT: + unit_str="%"; + break; + default: + /* Invalid */ + break; + } + if (this->values[i].unit == SP_CSS_UNIT_PERCENT) { + os << (this->values[i].value * 100.0) << unit_str ; + } else { + os << this->values[i].value << unit_str ; + } } os << important_str(); os << ";"; diff --git a/src/widgets/stroke-style.cpp b/src/widgets/stroke-style.cpp index 4d1bc24003..1100da77f0 100644 --- a/src/widgets/stroke-style.cpp +++ b/src/widgets/stroke-style.cpp @@ -749,14 +749,11 @@ StrokeStyle::setDashSelectorFromStyle(SPDashSelector *dsel, SPStyle *style) 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].value / scaledash; - else - d[i] = style->stroke_dasharray.values[i].value; // is there a better thing to do for stroke_width==0? + d[i] = style->stroke_dasharray.values[i].computed / scaledash; } dsel->set_dash(len, d, - style->stroke_width.computed != 0 ? style->stroke_dashoffset.value / scaledash - : style->stroke_dashoffset.value); + style->stroke_width.computed != 0 ? style->stroke_dashoffset.computed / scaledash + : style->stroke_dashoffset.computed); } else { dsel->set_dash(0, nullptr, 0.0); } @@ -996,7 +993,6 @@ StrokeStyle::setScaledDash(SPCSSAttr *css, static inline double calcScaleLineWidth(const double width_typed, SPItem *const item, Inkscape::Util::Unit const *const unit) { if (unit->type == Inkscape::Util::UNIT_TYPE_LINEAR) { - SPDocument *document = SP_ACTIVE_DOCUMENT; return Inkscape::Util::Quantity::convert(width_typed, unit, "px"); } else { // percentage const gdouble old_w = item->style->stroke_width.computed; @@ -1022,7 +1018,6 @@ StrokeStyle::scaleLine() /* TODO: Create some standardized method */ SPCSSAttr *css = sp_repr_css_attr_new(); - if (!items.empty()) { double width_typed = (*widthAdj)->get_value(); double const miterlimit = (*miterLimitAdj)->get_value(); @@ -1051,13 +1046,9 @@ StrokeStyle::scaleLine() /* Set dash */ 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, 1); - } + double desktop_scale = Geom::Affine(SP_ACTIVE_DOCUMENT->getDocumentScale()).descrim(); + double scale = prefs->getBool("/options/dash/scale", true) ? width : desktop_scale; + setScaledDash(css, ndash, dash, offset, scale); sp_desktop_apply_css_recursive ((*i), css, true); } -- GitLab From 2b2d0f0d61944328eab27b6780f5ab5e01b5dbde Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Date: Sat, 25 Aug 2018 00:43:55 +0200 Subject: [PATCH 04/12] Coding style fixes --- src/extension/internal/emf-inout.cpp | 16 +++--- src/extension/internal/wmf-inout.cpp | 2 +- src/style-internal.cpp | 83 ++++++++++++++-------------- 3 files changed, 51 insertions(+), 50 deletions(-) diff --git a/src/extension/internal/emf-inout.cpp b/src/extension/internal/emf-inout.cpp index 2b9cc62a51..165c58f83c 100644 --- a/src/extension/internal/emf-inout.cpp +++ b/src/extension/internal/emf-inout.cpp @@ -1106,10 +1106,10 @@ Emf::select_pen(PEMF_CALLBACK_DATA d, int index) d->dc[d->level].style.stroke_dasharray.values.clear(); if (penstyle==U_PS_DASH || penstyle==U_PS_DASHDOT || penstyle==U_PS_DASHDOTDOT) { spilength.value = 3; - spilength.computed = 3 * scale_doc; + spilength.computed = 3 * scale_doc; d->dc[d->level].style.stroke_dasharray.values.push_back(spilength); spilength.value = 1; - spilength.computed = scale_doc; + spilength.computed = scale_doc; d->dc[d->level].style.stroke_dasharray.values.push_back(spilength); } if (penstyle==U_PS_DOT || penstyle==U_PS_DASHDOT || penstyle==U_PS_DASHDOTDOT) { @@ -1221,26 +1221,26 @@ Emf::select_extpen(PEMF_CALLBACK_DATA d, int index) spilength.unit = SP_CSS_UNIT_NONE; if (penstyle==U_PS_DASH || penstyle==U_PS_DASHDOT || penstyle==U_PS_DASHDOTDOT) { spilength.value = 3; - spilength.computed = 3 * scale_doc; + spilength.computed = 3 * scale_doc; d->dc[d->level].style.stroke_dasharray.values.push_back(spilength); spilength.value = 2; - spilength.computed = 2 * scale_doc; + spilength.computed = 2 * scale_doc; d->dc[d->level].style.stroke_dasharray.values.push_back(spilength); } if (penstyle==U_PS_DOT || penstyle==U_PS_DASHDOT || penstyle==U_PS_DASHDOTDOT) { spilength.value = 1; - spilength.computed = 1 * scale_doc; + spilength.computed = 1 * scale_doc; d->dc[d->level].style.stroke_dasharray.values.push_back(spilength); spilength.value = 2; - spilength.computed = 2 * scale_doc; + spilength.computed = 2 * scale_doc; d->dc[d->level].style.stroke_dasharray.values.push_back(spilength); } if (penstyle==U_PS_DASHDOTDOT) { spilength.value = 1; - spilength.computed = 1 * scale_doc; + spilength.computed = 1 * scale_doc; d->dc[d->level].style.stroke_dasharray.values.push_back(spilength); spilength.value = 2; - spilength.computed = 2 * scale_doc; + spilength.computed = 2 * scale_doc; d->dc[d->level].style.stroke_dasharray.values.push_back(spilength); } diff --git a/src/extension/internal/wmf-inout.cpp b/src/extension/internal/wmf-inout.cpp index fbf3d4559e..a8a0af5d47 100644 --- a/src/extension/internal/wmf-inout.cpp +++ b/src/extension/internal/wmf-inout.cpp @@ -995,7 +995,7 @@ Wmf::select_pen(PWMF_CALLBACK_DATA d, int index) d->dc[d->level].style.stroke_dasharray.values.clear(); if (penstyle==U_PS_DASH || penstyle==U_PS_DASHDOT || penstyle==U_PS_DASHDOTDOT) { spilength.value = 3; - spilength.computed = 3 * scale_doc; + spilength.computed = 3 * scale_doc; d->dc[d->level].style.stroke_dasharray.values.push_back(spilength); spilength.value = 1; spilength.computed = scale_doc; diff --git a/src/style-internal.cpp b/src/style-internal.cpp index 142de3f579..4579b0e0e7 100644 --- a/src/style-internal.cpp +++ b/src/style-internal.cpp @@ -32,10 +32,10 @@ #include "style.h" #include "bad-uri-exception.h" +#include "document.h" #include "extract-uri.h" #include "inkscape.h" #include "preferences.h" -#include "document.h" #include "streq.h" #include "strneq.h" @@ -251,22 +251,21 @@ SPILength::read( gchar const *str ) { if ( !IS_FINITE(value_tmp) ) { // fix for bug lp:935157 return; } - bool wnormal = false; - if (name.compare( "line-height" ) == 0 || - name.compare( "word-spacing" ) == 0 || - name.compare( "letter-spacing" ) == 0) - { - wnormal = true; + bool wnormal = false; + if (name.compare("line-height") == 0 || name.compare("word-spacing") == 0 || + name.compare("letter-spacing") == 0) { + wnormal = true; } - - if ( !IS_FINITE(value_tmp) ) { // fix for bug lp:935157 + + if (!IS_FINITE(value_tmp)) { // fix for bug lp:935157 return; } double scale_doc = 1; if (!wnormal && Inkscape::Application::exists() && SP_ACTIVE_DOCUMENT) { scale_doc = Geom::Affine(SP_ACTIVE_DOCUMENT->getDocumentScale()).descrim(); - } else { - //If no application dont transform SPILenghts + } + else { + // If no application dont transform SPILenghts wnormal = true; } if ((gchar const *) e != str) { @@ -277,53 +276,53 @@ SPILength::read( gchar const *str ) { computed = value; } else if (!strcmp(e, "px")) { /* Userspace */ - unit = wnormal? SP_CSS_UNIT_PX : SP_CSS_UNIT_NONE; + unit = wnormal ? SP_CSS_UNIT_PX : SP_CSS_UNIT_NONE; computed = value; } else if (!strcmp(e, "pt")) { /* Userspace / DEVICESCALE */ - unit = wnormal? SP_CSS_UNIT_PT : SP_CSS_UNIT_NONE; + unit = wnormal ? SP_CSS_UNIT_PT : SP_CSS_UNIT_NONE; computed = Inkscape::Util::Quantity::convert(value, "pt", "px"); - value = wnormal? value : computed / scale_doc; + value = wnormal ? value : computed / scale_doc; computed = value; } else if (!strcmp(e, "pc")) { - unit = wnormal? SP_CSS_UNIT_PC : SP_CSS_UNIT_NONE; + unit = wnormal ? SP_CSS_UNIT_PC : SP_CSS_UNIT_NONE; computed = Inkscape::Util::Quantity::convert(value, "pc", "px"); - value = wnormal? value : computed / scale_doc; + value = wnormal ? value : computed / scale_doc; computed = value; } else if (!strcmp(e, "mm")) { - unit = wnormal? SP_CSS_UNIT_MM : SP_CSS_UNIT_NONE; + unit = wnormal ? SP_CSS_UNIT_MM : SP_CSS_UNIT_NONE; computed = Inkscape::Util::Quantity::convert(value, "mm", "px"); - value = wnormal? value : computed / scale_doc; + value = wnormal ? value : computed / scale_doc; computed = value; } else if (!strcmp(e, "cm")) { - unit = wnormal? SP_CSS_UNIT_CM : SP_CSS_UNIT_NONE; + unit = wnormal ? SP_CSS_UNIT_CM : SP_CSS_UNIT_NONE; computed = Inkscape::Util::Quantity::convert(value, "cm", "px"); - value = wnormal? value : computed / scale_doc; + value = wnormal ? value : computed / scale_doc; computed = value; } else if (!strcmp(e, "in")) { - unit = wnormal? SP_CSS_UNIT_IN : SP_CSS_UNIT_NONE; + unit = wnormal ? SP_CSS_UNIT_IN : SP_CSS_UNIT_NONE; computed = Inkscape::Util::Quantity::convert(value, "in", "px"); - value = wnormal? value : computed / scale_doc; + value = wnormal ? value : computed / scale_doc; computed = value; } else if (!strcmp(e, "em")) { /* EM square */ - unit = wnormal? SP_CSS_UNIT_EM : SP_CSS_UNIT_NONE; + unit = wnormal ? SP_CSS_UNIT_EM : SP_CSS_UNIT_NONE; if( style ) { computed = value * style->font_size.computed; } else { computed = value * SPIFontSize::font_size_default; } - value = wnormal? value : computed / scale_doc; + value = wnormal ? value : computed / scale_doc; computed = value; } else if (!strcmp(e, "ex")) { /* ex square */ - unit = wnormal? SP_CSS_UNIT_EX : SP_CSS_UNIT_NONE; + unit = wnormal ? SP_CSS_UNIT_EX : SP_CSS_UNIT_NONE; if( style ) { computed = value * style->font_size.computed * 0.5; // FIXME } else { computed = value * SPIFontSize::font_size_default * 0.5; } - value = wnormal? value : computed / scale_doc; + value = wnormal ? value : computed / scale_doc; computed = value; } else if (!strcmp(e, "%")) { /* Percentage */ @@ -466,8 +465,9 @@ SPILength::merge( const SPIBase* const parent ) { bool SPILength::operator==(const SPIBase& rhs) { if( const SPILength* r = dynamic_cast(&rhs) ) { - - if (unit != r->unit ) return false; + + if (unit != r->unit) + return false; // If length depends on external parameter, lengths cannot be equal. if (unit == SP_CSS_UNIT_EM) return false; @@ -2101,43 +2101,44 @@ SPIDashArray::write( guint const flags, SPStyleSrc const &style_src_req, SPIBase if (i) { os << ", "; } - Glib::ustring unit_str=""; + Glib::ustring unit_str = ""; switch (this->values[i].unit) { case SP_CSS_UNIT_PX: - unit_str="px"; + unit_str = "px"; break; case SP_CSS_UNIT_PT: - unit_str="pt"; + unit_str = "pt"; break; case SP_CSS_UNIT_PC: - unit_str="pc"; + unit_str = "pc"; break; case SP_CSS_UNIT_MM: - unit_str="mm"; + unit_str = "mm"; break; case SP_CSS_UNIT_CM: - unit_str="cm"; + unit_str = "cm"; break; case SP_CSS_UNIT_IN: - unit_str="in"; + unit_str = "in"; break; case SP_CSS_UNIT_EM: - unit_str="em"; + unit_str = "em"; break; case SP_CSS_UNIT_EX: - unit_str="ex"; + unit_str = "ex"; break; case SP_CSS_UNIT_PERCENT: - unit_str="%"; + unit_str = "%"; break; default: /* Invalid */ break; } if (this->values[i].unit == SP_CSS_UNIT_PERCENT) { - os << (this->values[i].value * 100.0) << unit_str ; - } else { - os << this->values[i].value << unit_str ; + os << (this->values[i].value * 100.0) << unit_str; + } + else { + os << this->values[i].value << unit_str; } } os << important_str(); -- GitLab From db1fb8d016e83281073fc458c3e4dceee68a99eb Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Date: Sat, 25 Aug 2018 00:47:37 +0200 Subject: [PATCH 05/12] Coding style fixes II --- src/style-internal.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/style-internal.cpp b/src/style-internal.cpp index 4579b0e0e7..3edfeb8aed 100644 --- a/src/style-internal.cpp +++ b/src/style-internal.cpp @@ -268,7 +268,7 @@ SPILength::read( gchar const *str ) { // If no application dont transform SPILenghts wnormal = true; } - if ((gchar const *) e != str) { + if ((gchar const *)e != str) { value = value_tmp; if (!*e) { /* Userspace */ -- GitLab From 68e80b449a357785c1a066e34c993fb24f435926 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Date: Sat, 25 Aug 2018 01:05:18 +0200 Subject: [PATCH 06/12] minor fixes --- src/extension/internal/emf-inout.cpp | 18 +++++++----------- src/extension/internal/wmf-inout.cpp | 6 ++---- src/style-internal.cpp | 2 ++ 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/src/extension/internal/emf-inout.cpp b/src/extension/internal/emf-inout.cpp index 165c58f83c..56820440c9 100644 --- a/src/extension/internal/emf-inout.cpp +++ b/src/extension/internal/emf-inout.cpp @@ -1095,8 +1095,6 @@ Emf::select_pen(PEMF_CALLBACK_DATA d, int index) case U_PS_DASHDOT: case U_PS_DASHDOTDOT: { - SPDocument *document = SP_ACTIVE_DOCUMENT; - double scale_doc = Geom::Affine(document->getDocumentScale()).descrim(); SPILength spilength("temp"); spilength.unit = SP_CSS_UNIT_NONE; int penstyle = (pEmr->lopn.lopnStyle & U_PS_STYLE_MASK); @@ -1106,10 +1104,10 @@ Emf::select_pen(PEMF_CALLBACK_DATA d, int index) d->dc[d->level].style.stroke_dasharray.values.clear(); if (penstyle==U_PS_DASH || penstyle==U_PS_DASHDOT || penstyle==U_PS_DASHDOTDOT) { spilength.value = 3; - spilength.computed = 3 * scale_doc; + spilength.computed = 3; d->dc[d->level].style.stroke_dasharray.values.push_back(spilength); spilength.value = 1; - spilength.computed = scale_doc; + spilength.computed = 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) { @@ -1215,13 +1213,11 @@ Emf::select_extpen(PEMF_CALLBACK_DATA d, int index) (d->level == 0 || (d->level > 0 && d->dc[d->level].style.stroke_dasharray != d->dc[d->level - 1].style.stroke_dasharray))) d->dc[d->level].style.stroke_dasharray.values.clear(); - SPDocument *document = SP_ACTIVE_DOCUMENT; - double scale_doc = Geom::Affine(document->getDocumentScale()).descrim(); SPILength spilength("temp"); spilength.unit = SP_CSS_UNIT_NONE; if (penstyle==U_PS_DASH || penstyle==U_PS_DASHDOT || penstyle==U_PS_DASHDOTDOT) { spilength.value = 3; - spilength.computed = 3 * scale_doc; + spilength.computed = 3; d->dc[d->level].style.stroke_dasharray.values.push_back(spilength); spilength.value = 2; spilength.computed = 2 * scale_doc; @@ -1229,18 +1225,18 @@ Emf::select_extpen(PEMF_CALLBACK_DATA d, int index) } if (penstyle==U_PS_DOT || penstyle==U_PS_DASHDOT || penstyle==U_PS_DASHDOTDOT) { spilength.value = 1; - spilength.computed = 1 * scale_doc; + spilength.computed = 1; d->dc[d->level].style.stroke_dasharray.values.push_back(spilength); spilength.value = 2; - spilength.computed = 2 * scale_doc; + spilength.computed = 2; d->dc[d->level].style.stroke_dasharray.values.push_back(spilength); } if (penstyle==U_PS_DASHDOTDOT) { spilength.value = 1; - spilength.computed = 1 * scale_doc; + spilength.computed = 1; d->dc[d->level].style.stroke_dasharray.values.push_back(spilength); spilength.value = 2; - spilength.computed = 2 * scale_doc; + spilength.computed = 2; d->dc[d->level].style.stroke_dasharray.values.push_back(spilength); } diff --git a/src/extension/internal/wmf-inout.cpp b/src/extension/internal/wmf-inout.cpp index a8a0af5d47..6412e39f28 100644 --- a/src/extension/internal/wmf-inout.cpp +++ b/src/extension/internal/wmf-inout.cpp @@ -984,8 +984,6 @@ Wmf::select_pen(PWMF_CALLBACK_DATA d, int index) case U_PS_DASHDOT: case U_PS_DASHDOTDOT: { - SPDocument *document = SP_ACTIVE_DOCUMENT; - double scale_doc = Geom::Affine(document->getDocumentScale()).descrim(); SPILength spilength("temp"); spilength.unit = SP_CSS_UNIT_NONE; int penstyle = (up.Style & U_PS_STYLE_MASK); @@ -995,10 +993,10 @@ Wmf::select_pen(PWMF_CALLBACK_DATA d, int index) d->dc[d->level].style.stroke_dasharray.values.clear(); if (penstyle==U_PS_DASH || penstyle==U_PS_DASHDOT || penstyle==U_PS_DASHDOTDOT) { spilength.value = 3; - spilength.computed = 3 * scale_doc; + spilength.computed = 3; d->dc[d->level].style.stroke_dasharray.values.push_back(spilength); spilength.value = 1; - spilength.computed = scale_doc; + spilength.computed = 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) { diff --git a/src/style-internal.cpp b/src/style-internal.cpp index 3edfeb8aed..fb94cf1be4 100644 --- a/src/style-internal.cpp +++ b/src/style-internal.cpp @@ -273,6 +273,8 @@ SPILength::read( gchar const *str ) { if (!*e) { /* Userspace */ unit = SP_CSS_UNIT_NONE; + //TODO: this not need to be 'computed = wnormal ? value : value * scale_doc;' + // Seems consistent but break a lot... computed = value; } else if (!strcmp(e, "px")) { /* Userspace */ -- GitLab From 4a7682d0a7cc2ff52d353d7814828ce6da554e8d Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Date: Sat, 25 Aug 2018 01:10:31 +0200 Subject: [PATCH 07/12] Coding style fixes III --- src/style-internal.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/style-internal.cpp b/src/style-internal.cpp index fb94cf1be4..dae00216a3 100644 --- a/src/style-internal.cpp +++ b/src/style-internal.cpp @@ -273,7 +273,7 @@ SPILength::read( gchar const *str ) { if (!*e) { /* Userspace */ unit = SP_CSS_UNIT_NONE; - //TODO: this not need to be 'computed = wnormal ? value : value * scale_doc;' + // TODO: this not need to be 'computed = wnormal ? value : value * scale_doc;' // Seems consistent but break a lot... computed = value; } else if (!strcmp(e, "px")) { -- GitLab From c3d99793c09985ee1acea26f4453f37e4b535a59 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Date: Sat, 25 Aug 2018 01:23:34 +0200 Subject: [PATCH 08/12] Fix compiling bug --- src/extension/internal/emf-inout.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/extension/internal/emf-inout.cpp b/src/extension/internal/emf-inout.cpp index 56820440c9..3f6d79aead 100644 --- a/src/extension/internal/emf-inout.cpp +++ b/src/extension/internal/emf-inout.cpp @@ -1220,7 +1220,7 @@ Emf::select_extpen(PEMF_CALLBACK_DATA d, int index) spilength.computed = 3; d->dc[d->level].style.stroke_dasharray.values.push_back(spilength); spilength.value = 2; - spilength.computed = 2 * scale_doc; + spilength.computed = 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) { -- GitLab From 424f3670e952d1283b05c29c46f30afb2462f07f Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Date: Sat, 25 Aug 2018 02:59:38 +0200 Subject: [PATCH 09/12] Fix bug on tests --- src/style-internal.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/style-internal.cpp b/src/style-internal.cpp index dae00216a3..a4eef07926 100644 --- a/src/style-internal.cpp +++ b/src/style-internal.cpp @@ -285,27 +285,27 @@ SPILength::read( gchar const *str ) { unit = wnormal ? SP_CSS_UNIT_PT : SP_CSS_UNIT_NONE; computed = Inkscape::Util::Quantity::convert(value, "pt", "px"); value = wnormal ? value : computed / scale_doc; - computed = value; + computed = wnormal ? computed : value; } else if (!strcmp(e, "pc")) { unit = wnormal ? SP_CSS_UNIT_PC : SP_CSS_UNIT_NONE; computed = Inkscape::Util::Quantity::convert(value, "pc", "px"); value = wnormal ? value : computed / scale_doc; - computed = value; + computed = wnormal ? computed : value; } else if (!strcmp(e, "mm")) { unit = wnormal ? SP_CSS_UNIT_MM : SP_CSS_UNIT_NONE; computed = Inkscape::Util::Quantity::convert(value, "mm", "px"); value = wnormal ? value : computed / scale_doc; - computed = value; + computed = wnormal ? computed : value; } else if (!strcmp(e, "cm")) { unit = wnormal ? SP_CSS_UNIT_CM : SP_CSS_UNIT_NONE; computed = Inkscape::Util::Quantity::convert(value, "cm", "px"); value = wnormal ? value : computed / scale_doc; - computed = value; + computed = wnormal ? computed : value; } else if (!strcmp(e, "in")) { unit = wnormal ? SP_CSS_UNIT_IN : SP_CSS_UNIT_NONE; computed = Inkscape::Util::Quantity::convert(value, "in", "px"); value = wnormal ? value : computed / scale_doc; - computed = value; + computed = wnormal ? computed : value; } else if (!strcmp(e, "em")) { /* EM square */ unit = wnormal ? SP_CSS_UNIT_EM : SP_CSS_UNIT_NONE; @@ -315,7 +315,7 @@ SPILength::read( gchar const *str ) { computed = value * SPIFontSize::font_size_default; } value = wnormal ? value : computed / scale_doc; - computed = value; + computed = wnormal ? computed : value; } else if (!strcmp(e, "ex")) { /* ex square */ unit = wnormal ? SP_CSS_UNIT_EX : SP_CSS_UNIT_NONE; @@ -325,7 +325,7 @@ SPILength::read( gchar const *str ) { computed = value * SPIFontSize::font_size_default * 0.5; } value = wnormal ? value : computed / scale_doc; - computed = value; + computed = wnormal ? computed : value; } else if (!strcmp(e, "%")) { /* Percentage */ unit = SP_CSS_UNIT_PERCENT; -- GitLab From 1ecf560fad04e4954bb45230551b77d3c13b8245 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Date: Sun, 26 Aug 2018 02:02:00 +0200 Subject: [PATCH 10/12] Fix Tav warnings --- src/style-internal.cpp | 35 ++++++++++++++++------------------- src/widgets/stroke-style.cpp | 8 ++++++-- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/style-internal.cpp b/src/style-internal.cpp index a4eef07926..39082b73cf 100644 --- a/src/style-internal.cpp +++ b/src/style-internal.cpp @@ -35,6 +35,7 @@ #include "document.h" #include "extract-uri.h" #include "inkscape.h" +#include "object/sp-namedview.h" #include "preferences.h" #include "streq.h" #include "strneq.h" @@ -235,7 +236,6 @@ SPIScale24::operator==(const SPIBase& rhs) { void SPILength::read( gchar const *str ) { - if( !str ) return; if (!strcmp(str, "inherit")) { @@ -252,59 +252,56 @@ SPILength::read( gchar const *str ) { return; } bool wnormal = false; + Glib::ustring unitnv = ""; if (name.compare("line-height") == 0 || name.compare("word-spacing") == 0 || - name.compare("letter-spacing") == 0) { + name.compare("letter-spacing") == 0 || !Inkscape::Application::exists() || + !SP_ACTIVE_DOCUMENT || !SP_ACTIVE_DESKTOP) + { wnormal = true; + } else if (SPNamedView *namedview = SP_ACTIVE_DESKTOP->getNamedView()) { + unitnv = namedview->display_units->abbr; } if (!IS_FINITE(value_tmp)) { // fix for bug lp:935157 return; } - double scale_doc = 1; - if (!wnormal && Inkscape::Application::exists() && SP_ACTIVE_DOCUMENT) { - scale_doc = Geom::Affine(SP_ACTIVE_DOCUMENT->getDocumentScale()).descrim(); - } - else { - // If no application dont transform SPILenghts - wnormal = true; - } if ((gchar const *)e != str) { value = value_tmp; if (!*e) { /* Userspace */ unit = SP_CSS_UNIT_NONE; - // TODO: this not need to be 'computed = wnormal ? value : value * scale_doc;' - // Seems consistent but break a lot... computed = value; } else if (!strcmp(e, "px")) { /* Userspace */ unit = wnormal ? SP_CSS_UNIT_PX : SP_CSS_UNIT_NONE; computed = value; + value = wnormal ? value : Inkscape::Util::Quantity::convert(computed, "px", unitnv); + computed = wnormal ? computed : value; } else if (!strcmp(e, "pt")) { /* Userspace / DEVICESCALE */ unit = wnormal ? SP_CSS_UNIT_PT : SP_CSS_UNIT_NONE; computed = Inkscape::Util::Quantity::convert(value, "pt", "px"); - value = wnormal ? value : computed / scale_doc; + value = wnormal ? value : Inkscape::Util::Quantity::convert(computed, "px", unitnv); computed = wnormal ? computed : value; } else if (!strcmp(e, "pc")) { unit = wnormal ? SP_CSS_UNIT_PC : SP_CSS_UNIT_NONE; computed = Inkscape::Util::Quantity::convert(value, "pc", "px"); - value = wnormal ? value : computed / scale_doc; + value = wnormal ? value : Inkscape::Util::Quantity::convert(computed, "px", unitnv); computed = wnormal ? computed : value; } else if (!strcmp(e, "mm")) { unit = wnormal ? SP_CSS_UNIT_MM : SP_CSS_UNIT_NONE; computed = Inkscape::Util::Quantity::convert(value, "mm", "px"); - value = wnormal ? value : computed / scale_doc; + value = wnormal ? value : Inkscape::Util::Quantity::convert(computed, "px", unitnv); computed = wnormal ? computed : value; } else if (!strcmp(e, "cm")) { unit = wnormal ? SP_CSS_UNIT_CM : SP_CSS_UNIT_NONE; computed = Inkscape::Util::Quantity::convert(value, "cm", "px"); - value = wnormal ? value : computed / scale_doc; + value = wnormal ? value : Inkscape::Util::Quantity::convert(computed, "px", unitnv); computed = wnormal ? computed : value; } else if (!strcmp(e, "in")) { unit = wnormal ? SP_CSS_UNIT_IN : SP_CSS_UNIT_NONE; computed = Inkscape::Util::Quantity::convert(value, "in", "px"); - value = wnormal ? value : computed / scale_doc; + value = wnormal ? value : Inkscape::Util::Quantity::convert(computed, "px", unitnv); computed = wnormal ? computed : value; } else if (!strcmp(e, "em")) { /* EM square */ @@ -314,7 +311,7 @@ SPILength::read( gchar const *str ) { } else { computed = value * SPIFontSize::font_size_default; } - value = wnormal ? value : computed / scale_doc; + value = wnormal ? value : Inkscape::Util::Quantity::convert(computed, "px", unitnv); computed = wnormal ? computed : value; } else if (!strcmp(e, "ex")) { /* ex square */ @@ -324,7 +321,7 @@ SPILength::read( gchar const *str ) { } else { computed = value * SPIFontSize::font_size_default * 0.5; } - value = wnormal ? value : computed / scale_doc; + value = wnormal ? value : Inkscape::Util::Quantity::convert(computed, "px", unitnv); computed = wnormal ? computed : value; } else if (!strcmp(e, "%")) { /* Percentage */ diff --git a/src/widgets/stroke-style.cpp b/src/widgets/stroke-style.cpp index 1100da77f0..9aca6e4992 100644 --- a/src/widgets/stroke-style.cpp +++ b/src/widgets/stroke-style.cpp @@ -1046,8 +1046,12 @@ StrokeStyle::scaleLine() /* Set dash */ Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - double desktop_scale = Geom::Affine(SP_ACTIVE_DOCUMENT->getDocumentScale()).descrim(); - double scale = prefs->getBool("/options/dash/scale", true) ? width : desktop_scale; + Glib::ustring unitnv = "px"; + if (SPNamedView *namedview = SP_ACTIVE_DESKTOP->getNamedView()) { + unitnv = namedview->display_units->abbr; + } + double unit_scale = Inkscape::Util::Quantity::convert(1, unitnv, "px"); + double scale = prefs->getBool("/options/dash/scale", true) ? width : unit_scale; setScaledDash(css, ndash, dash, offset, scale); sp_desktop_apply_css_recursive ((*i), css, true); } -- GitLab From 6bb54c6d00ec1acd26b08e20e1a5edc812b108ae Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Date: Sun, 26 Aug 2018 02:13:54 +0200 Subject: [PATCH 11/12] Fix coding style --- clang_format_diff | 32 ++++++++++++++++++++++++++++++++ src/style-internal.cpp | 8 ++++---- src/widgets/stroke-style.cpp | 5 ++--- 3 files changed, 38 insertions(+), 7 deletions(-) create mode 100644 clang_format_diff diff --git a/clang_format_diff b/clang_format_diff new file mode 100644 index 0000000000..0280521abe --- /dev/null +++ b/clang_format_diff @@ -0,0 +1,32 @@ +--- src/style-internal.cpp (before formatting) ++++ src/style-internal.cpp (after formatting) +@@ -254,11 +254,11 @@ + bool wnormal = false; + Glib::ustring unitnv = ""; + if (name.compare("line-height") == 0 || name.compare("word-spacing") == 0 || +- name.compare("letter-spacing") == 0 || !Inkscape::Application::exists() || +- !SP_ACTIVE_DOCUMENT || !SP_ACTIVE_DESKTOP) +- { ++ name.compare("letter-spacing") == 0 || !Inkscape::Application::exists() || !SP_ACTIVE_DOCUMENT || ++ !SP_ACTIVE_DESKTOP) { + wnormal = true; +- } else if (SPNamedView *namedview = SP_ACTIVE_DESKTOP->getNamedView()) { ++ } ++ else if (SPNamedView *namedview = SP_ACTIVE_DESKTOP->getNamedView()) { + unitnv = namedview->display_units->abbr; + } + +--- src/widgets/stroke-style.cpp (before formatting) ++++ src/widgets/stroke-style.cpp (after formatting) +@@ -751,9 +751,8 @@ + for (unsigned i = 0; i < len; i++) { + d[i] = style->stroke_dasharray.values[i].computed / scaledash; + } +- dsel->set_dash(len, d, +- style->stroke_width.computed != 0 ? style->stroke_dashoffset.computed / scaledash +- : style->stroke_dashoffset.computed); ++ dsel->set_dash(len, d, style->stroke_width.computed != 0 ? style->stroke_dashoffset.computed / scaledash ++ : style->stroke_dashoffset.computed); + } else { + dsel->set_dash(0, nullptr, 0.0); + } diff --git a/src/style-internal.cpp b/src/style-internal.cpp index 39082b73cf..3875e8856e 100644 --- a/src/style-internal.cpp +++ b/src/style-internal.cpp @@ -254,11 +254,11 @@ SPILength::read( gchar const *str ) { bool wnormal = false; Glib::ustring unitnv = ""; if (name.compare("line-height") == 0 || name.compare("word-spacing") == 0 || - name.compare("letter-spacing") == 0 || !Inkscape::Application::exists() || - !SP_ACTIVE_DOCUMENT || !SP_ACTIVE_DESKTOP) - { + name.compare("letter-spacing") == 0 || !Inkscape::Application::exists() || !SP_ACTIVE_DOCUMENT || + !SP_ACTIVE_DESKTOP) { wnormal = true; - } else if (SPNamedView *namedview = SP_ACTIVE_DESKTOP->getNamedView()) { + } + else if (SPNamedView *namedview = SP_ACTIVE_DESKTOP->getNamedView()) { unitnv = namedview->display_units->abbr; } diff --git a/src/widgets/stroke-style.cpp b/src/widgets/stroke-style.cpp index 9aca6e4992..fc29dbd91b 100644 --- a/src/widgets/stroke-style.cpp +++ b/src/widgets/stroke-style.cpp @@ -751,9 +751,8 @@ StrokeStyle::setDashSelectorFromStyle(SPDashSelector *dsel, SPStyle *style) for (unsigned i = 0; i < len; i++) { d[i] = style->stroke_dasharray.values[i].computed / scaledash; } - dsel->set_dash(len, d, - style->stroke_width.computed != 0 ? style->stroke_dashoffset.computed / scaledash - : style->stroke_dashoffset.computed); + dsel->set_dash(len, d, style->stroke_width.computed != 0 ? style->stroke_dashoffset.computed / scaledash + : style->stroke_dashoffset.computed); } else { dsel->set_dash(0, nullptr, 0.0); } -- GitLab From 73dff355c50a3e1166f3e4ac88c866da0b3880f3 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Date: Sun, 26 Aug 2018 02:29:11 +0200 Subject: [PATCH 12/12] Fix coding style --- clang_format_diff | 32 -------------------------------- src/widgets/stroke-style.cpp | 5 +++-- 2 files changed, 3 insertions(+), 34 deletions(-) diff --git a/clang_format_diff b/clang_format_diff index 0280521abe..e69de29bb2 100644 --- a/clang_format_diff +++ b/clang_format_diff @@ -1,32 +0,0 @@ ---- src/style-internal.cpp (before formatting) -+++ src/style-internal.cpp (after formatting) -@@ -254,11 +254,11 @@ - bool wnormal = false; - Glib::ustring unitnv = ""; - if (name.compare("line-height") == 0 || name.compare("word-spacing") == 0 || -- name.compare("letter-spacing") == 0 || !Inkscape::Application::exists() || -- !SP_ACTIVE_DOCUMENT || !SP_ACTIVE_DESKTOP) -- { -+ name.compare("letter-spacing") == 0 || !Inkscape::Application::exists() || !SP_ACTIVE_DOCUMENT || -+ !SP_ACTIVE_DESKTOP) { - wnormal = true; -- } else if (SPNamedView *namedview = SP_ACTIVE_DESKTOP->getNamedView()) { -+ } -+ else if (SPNamedView *namedview = SP_ACTIVE_DESKTOP->getNamedView()) { - unitnv = namedview->display_units->abbr; - } - ---- src/widgets/stroke-style.cpp (before formatting) -+++ src/widgets/stroke-style.cpp (after formatting) -@@ -751,9 +751,8 @@ - for (unsigned i = 0; i < len; i++) { - d[i] = style->stroke_dasharray.values[i].computed / scaledash; - } -- dsel->set_dash(len, d, -- style->stroke_width.computed != 0 ? style->stroke_dashoffset.computed / scaledash -- : style->stroke_dashoffset.computed); -+ dsel->set_dash(len, d, style->stroke_width.computed != 0 ? style->stroke_dashoffset.computed / scaledash -+ : style->stroke_dashoffset.computed); - } else { - dsel->set_dash(0, nullptr, 0.0); - } diff --git a/src/widgets/stroke-style.cpp b/src/widgets/stroke-style.cpp index fc29dbd91b..9aca6e4992 100644 --- a/src/widgets/stroke-style.cpp +++ b/src/widgets/stroke-style.cpp @@ -751,8 +751,9 @@ StrokeStyle::setDashSelectorFromStyle(SPDashSelector *dsel, SPStyle *style) for (unsigned i = 0; i < len; i++) { d[i] = style->stroke_dasharray.values[i].computed / scaledash; } - dsel->set_dash(len, d, style->stroke_width.computed != 0 ? style->stroke_dashoffset.computed / scaledash - : style->stroke_dashoffset.computed); + dsel->set_dash(len, d, + style->stroke_width.computed != 0 ? style->stroke_dashoffset.computed / scaledash + : style->stroke_dashoffset.computed); } else { dsel->set_dash(0, nullptr, 0.0); } -- GitLab