diff --git a/clang_format_diff b/clang_format_diff new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/src/extension/internal/emf-inout.cpp b/src/extension/internal/emf-inout.cpp index a0803aafcf18a6a9ae1c138913d54d60d124b90b..3f6d79aead09ac9ec508ae6417b76b54bce9bff7 100644 --- a/src/extension/internal/emf-inout.cpp +++ b/src/extension/internal/emf-inout.cpp @@ -1095,16 +1095,19 @@ Emf::select_pen(PEMF_CALLBACK_DATA d, int index) case U_PS_DASHDOT: case U_PS_DASHDOTDOT: { - SPILength spilength("temp", 1); + 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; d->dc[d->level].style.stroke_dasharray.values.push_back(spilength); - spilength.setDouble(1); + spilength.value = 1; + 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) { @@ -1211,22 +1214,29 @@ 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(); 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; d->dc[d->level].style.stroke_dasharray.values.push_back(spilength); - spilength.setDouble(2); + spilength.value = 2; + 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) { - spilength.setDouble(1); + spilength.value = 1; + spilength.computed = 1; d->dc[d->level].style.stroke_dasharray.values.push_back(spilength); - spilength.setDouble(2); + spilength.value = 2; + spilength.computed = 2; 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; d->dc[d->level].style.stroke_dasharray.values.push_back(spilength); - spilength.setDouble(2); + spilength.value = 2; + 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 3bc6b1b3df4e77d9e423ba5f033008f4efa9aa1c..6412e39f28e82bedc05472d9739f19a59c404319 100644 --- a/src/extension/internal/wmf-inout.cpp +++ b/src/extension/internal/wmf-inout.cpp @@ -984,16 +984,19 @@ Wmf::select_pen(PWMF_CALLBACK_DATA d, int index) case U_PS_DASHDOT: case U_PS_DASHDOTDOT: { + 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; d->dc[d->level].style.stroke_dasharray.values.push_back(spilength); - spilength.setDouble(1); + spilength.value = 1; + 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 39e334d1fc7f88a02813d2cbbbc2673434d37112..3875e8856e7c36438684508addd096d1a49dbeb5 100644 --- a/src/style-internal.cpp +++ b/src/style-internal.cpp @@ -32,8 +32,10 @@ #include "style.h" #include "bad-uri-exception.h" +#include "document.h" #include "extract-uri.h" #include "inkscape.h" +#include "object/sp-namedview.h" #include "preferences.h" #include "streq.h" #include "strneq.h" @@ -234,7 +236,6 @@ SPIScale24::operator==(const SPIBase& rhs) { void SPILength::read( gchar const *str ) { - if( !str ) return; if (!strcmp(str, "inherit")) { @@ -250,8 +251,21 @@ SPILength::read( gchar const *str ) { if ( !IS_FINITE(value_tmp) ) { // fix for bug lp:935157 return; } - if ((gchar const *) e != 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) { + 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; + } + if ((gchar const *)e != str) { value = value_tmp; if (!*e) { /* Userspace */ @@ -259,40 +273,56 @@ SPILength::read( gchar const *str ) { computed = value; } else if (!strcmp(e, "px")) { /* Userspace */ - unit = SP_CSS_UNIT_PX; + 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 = SP_CSS_UNIT_PT; + unit = wnormal ? SP_CSS_UNIT_PT : SP_CSS_UNIT_NONE; computed = Inkscape::Util::Quantity::convert(value, "pt", "px"); + value = wnormal ? value : Inkscape::Util::Quantity::convert(computed, "px", unitnv); + computed = wnormal ? computed : value; } else if (!strcmp(e, "pc")) { - unit = SP_CSS_UNIT_PC; + unit = wnormal ? SP_CSS_UNIT_PC : SP_CSS_UNIT_NONE; computed = Inkscape::Util::Quantity::convert(value, "pc", "px"); + value = wnormal ? value : Inkscape::Util::Quantity::convert(computed, "px", unitnv); + computed = wnormal ? computed : value; } else if (!strcmp(e, "mm")) { - unit = SP_CSS_UNIT_MM; + unit = wnormal ? SP_CSS_UNIT_MM : SP_CSS_UNIT_NONE; computed = Inkscape::Util::Quantity::convert(value, "mm", "px"); + value = wnormal ? value : Inkscape::Util::Quantity::convert(computed, "px", unitnv); + computed = wnormal ? computed : value; } else if (!strcmp(e, "cm")) { - unit = SP_CSS_UNIT_CM; + unit = wnormal ? SP_CSS_UNIT_CM : SP_CSS_UNIT_NONE; computed = Inkscape::Util::Quantity::convert(value, "cm", "px"); + value = wnormal ? value : Inkscape::Util::Quantity::convert(computed, "px", unitnv); + computed = wnormal ? computed : value; } else if (!strcmp(e, "in")) { - unit = SP_CSS_UNIT_IN; + unit = wnormal ? SP_CSS_UNIT_IN : SP_CSS_UNIT_NONE; computed = Inkscape::Util::Quantity::convert(value, "in", "px"); + value = wnormal ? value : Inkscape::Util::Quantity::convert(computed, "px", unitnv); + computed = wnormal ? computed : value; } else if (!strcmp(e, "em")) { /* EM square */ - unit = SP_CSS_UNIT_EM; + 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 : Inkscape::Util::Quantity::convert(computed, "px", unitnv); + computed = wnormal ? computed : value; } else if (!strcmp(e, "ex")) { /* ex square */ - unit = SP_CSS_UNIT_EX; + 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 : Inkscape::Util::Quantity::convert(computed, "px", unitnv); + computed = wnormal ? computed : value; } else if (!strcmp(e, "%")) { /* Percentage */ unit = SP_CSS_UNIT_PERCENT; @@ -325,7 +355,45 @@ SPILength::write( guint const flags, SPStyleSrc const &style_src_req, SPIBase co if (this->inherit) { return (name + ":inherit;"); } else { - return toString(true); + 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(""); @@ -393,69 +461,12 @@ 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 -{ -Inkscape: - CSSOStringStream os; - if (wname) { - os << name << ":"; - } - 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; - } - if (wname) { - os << important_str(); - os << ";"; - } - return os.str(); -} - 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; @@ -465,7 +476,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; } @@ -2089,7 +2100,45 @@ SPIDashArray::write( guint const flags, SPStyleSrc const &style_src_req, SPIBase if (i) { os << ", "; } - os << this->values[i].toString().c_str(); + 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/style-internal.h b/src/style-internal.h index f716601f626ee84f4f3751d65a29f154ef0b24d0..6d8e2088df2f0973e404d0eec7a089e7dc5e8cfb 100644 --- a/src/style-internal.h +++ b/src/style-internal.h @@ -402,8 +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 public: diff --git a/src/widgets/stroke-style.cpp b/src/widgets/stroke-style.cpp index bfa21a9eae40989cbf1f9afb8ac7c50a6b2e7445..9aca6e499203008cedb74bc3c3d4cb77b832d52e 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); } @@ -1021,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(); @@ -1050,13 +1046,13 @@ 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, document->getDocumentScale()[0]); + 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); }