diff options
| author | Jabiertxof <jabier.arraiza@marker.es> | 2019-07-25 18:03:01 +0000 |
|---|---|---|
| committer | Jabier Arraiza <jabier.arraiza@marker.es> | 2019-08-02 21:26:28 +0000 |
| commit | a233a33e9bd81f76a75d17a6355ed59e1679d125 (patch) | |
| tree | b7ab4dc90ace09b4a60dfa257f9dd9042dad920f | |
| parent | Stop worinig with units switch to px. Keep discussion opengit add .git add . (diff) | |
| download | inkscape-a233a33e9bd81f76a75d17a6355ed59e1679d125.tar.gz inkscape-a233a33e9bd81f76a75d17a6355ed59e1679d125.zip | |
Removing absolute units
| -rw-r--r-- | src/desktop-style.cpp | 5 | ||||
| -rw-r--r-- | src/style.cpp | 6 | ||||
| -rw-r--r-- | src/style.h | 2 | ||||
| -rw-r--r-- | src/ui/toolbar/text-toolbar.cpp | 131 | ||||
| -rw-r--r-- | src/ui/toolbar/text-toolbar.h | 2 |
5 files changed, 35 insertions, 111 deletions
diff --git a/src/desktop-style.cpp b/src/desktop-style.cpp index ee8a96c4e..6c8095d53 100644 --- a/src/desktop-style.cpp +++ b/src/desktop-style.cpp @@ -1066,12 +1066,14 @@ objects_query_fontnumbers (const std::vector<SPItem*> &objects, SPStyle *style_r // Quick way of getting document scale. Should be same as: // item->document->getDocumentScale().Affine().descrim() double doc_scale = Geom::Affine(item->i2dt_affine()).descrim(); + double dummy = style->font_size.computed * doc_scale; if (!std::isnan(dummy)) { size += dummy; /// \todo FIXME: we assume non-% units here } else { no_size++; } + if (style->letter_spacing.normal) { if (!different && (letterspacing_prev == 0 || letterspacing_prev == letterspacing)) { letterspacing_normal = true; @@ -1113,7 +1115,8 @@ objects_query_fontnumbers (const std::vector<SPItem*> &objects, SPStyle *style_r lineheight_normal = false; lineheight += lineheight_current; } else { - lineheight_current = style->line_height.value; + // Always 'px' internally + lineheight_current = style->line_height.computed; lineheight_unit_current = style->line_height.unit; lineheight_unit_absolute = true; lineheight_normal = false; diff --git a/src/style.cpp b/src/style.cpp index 69d31ee1e..2d82791af 100644 --- a/src/style.cpp +++ b/src/style.cpp @@ -1538,9 +1538,9 @@ sp_css_attr_unset_uris(SPCSSAttr *css) /** * Scale a single-value property. */ -void +static void sp_css_attr_scale_property_single(SPCSSAttr *css, gchar const *property, - double ex, bool only_with_units) + double ex, bool only_with_units = false) { gchar const *w = sp_repr_css_property(css, property, nullptr); if (w) { @@ -1608,7 +1608,7 @@ sp_css_attr_scale(SPCSSAttr *css, double ex) sp_css_attr_scale_property_single(css, "kerning", ex); sp_css_attr_scale_property_single(css, "letter-spacing", ex); sp_css_attr_scale_property_single(css, "word-spacing", ex); - sp_css_attr_scale_property_single(css, "line-height", true); + sp_css_attr_scale_property_single(css, "line-height", ex, true); return css; } diff --git a/src/style.h b/src/style.h index 9b1afeee4..9e46fa3ea 100644 --- a/src/style.h +++ b/src/style.h @@ -354,7 +354,7 @@ SPCSSAttr *sp_css_attr_unset_text(SPCSSAttr *css); SPCSSAttr *sp_css_attr_unset_blacklist(SPCSSAttr *css); SPCSSAttr *sp_css_attr_unset_uris(SPCSSAttr *css); SPCSSAttr *sp_css_attr_scale(SPCSSAttr *css, double ex); -void sp_css_attr_scale_property_single(SPCSSAttr *css, gchar const *property, double ex, bool only_with_units = false); + void sp_style_unset_property_attrs(SPObject *o); void sp_style_set_property_url (SPObject *item, char const *property, SPObject *linked, bool recursive); diff --git a/src/ui/toolbar/text-toolbar.cpp b/src/ui/toolbar/text-toolbar.cpp index c5bc7625f..2cdfbb5f0 100644 --- a/src/ui/toolbar/text-toolbar.cpp +++ b/src/ui/toolbar/text-toolbar.cpp @@ -142,82 +142,6 @@ static void recursively_set_properties( SPObject* object, SPCSSAttr *css, bool u sp_repr_css_attr_unref (css_unset); } -void sp_line_height_to_child(SPItem *root, SPCSSAttr *css, SPILengthOrNormal line_height, bool not_selected) -{ - if (root) { - SPILengthOrNormal current_line_height = root->style->line_height; - SPCSSAttr *css_item = sp_repr_css_attr_new(); - sp_repr_css_merge(css_item, css); - if (current_line_height.computed < line_height.computed) { - /* - @Tav you disable children units but in the spec is alowwd so I retain allowed - */ - sp_repr_css_set_property(css_item, "line-height", line_height.toString().c_str()); - } else { - if (not_selected) { - /* - @Tav you disable children units but in the spec is alowwd so I retain allowed - */ - sp_repr_css_set_property(css_item, "line-height", current_line_height.toString().c_str()); - } - } - root->changeCSS(css_item, "style"); - sp_repr_css_attr_unref(css_item); - for (auto item : root->childList(false)) { - SPItem *subitem = dynamic_cast<SPItem *>(item); - sp_line_height_to_child(subitem, css, line_height, not_selected); - } - } -} - -std::pair<double,int> -sp_get_line_height(SPItem *item, SPStyle *line_height_style, bool force_no_units = false) -{ - int line_height_unit = SP_CSS_UNIT_NONE; - if (line_height_style->line_height.normal) { - if (force_no_units) { - line_height_unit = SP_CSS_UNIT_PX; - } - } else { - if (force_no_units) { - line_height_unit = SP_CSS_UNIT_PX; - } else { - line_height_unit = line_height_style->line_height.unit; - } - } - double doc_scale = 1; - SPText *text = dynamic_cast<SPText *>(item); - SPFlowtext *flowtext = dynamic_cast<SPFlowtext *>(item); - SPText *ptext = dynamic_cast<SPText *>(item->parent); - SPFlowtext *pflowtext = dynamic_cast<SPFlowtext *>(item->parent); - if (flowtext && !is_relative(SPCSSUnit(line_height_unit))) { - doc_scale = SP_ITEM(item->parent)->transform.descrim(); - doc_scale *= doc_scale; - } - if (pflowtext && !is_relative(SPCSSUnit(line_height_unit))) { - doc_scale = SP_ITEM(item->parent->parent)->transform.descrim(); - doc_scale *= doc_scale; - } - if ((text || ptext) && !is_relative(SPCSSUnit(line_height_unit))) { - doc_scale = Geom::Affine(item->i2dt_affine()).descrim(); - } - double height = 0; - if (line_height_style->line_height.normal) { - if (force_no_units) { - height = Inkscape::Text::Layout::LINE_HEIGHT_NORMAL * line_height_style->font_size.computed * doc_scale; - } else { - height = Inkscape::Text::Layout::LINE_HEIGHT_NORMAL * doc_scale; - } - } else { - if (force_no_units) { - height = line_height_style->line_height.computed * doc_scale; - } else { - height = line_height_style->line_height.value * doc_scale; - } - } - return std::make_pair(height, line_height_unit); -} - /* * Set the default list of font sizes, scaled to the users preferred unit */ @@ -295,7 +219,6 @@ namespace Toolbar { TextToolbar::TextToolbar(SPDesktop *desktop) : Toolbar(desktop), _freeze(false), - _initial(true), _tracker(new UnitTracker(Inkscape::Util::UNIT_TYPE_LINEAR)) { /* Line height unit tracker */ @@ -406,7 +329,7 @@ TextToolbar::TextToolbar(SPDesktop *desktop) std::vector<Glib::ustring> labels = {_("Smaller spacing"), "", "", "", "", C_("Text tool", "Normal"), "", "", "", "", "", _("Larger spacing")}; std::vector<double> values = { 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 2.0}; - auto line_height_val = prefs->getDouble("/tools/text/lineheight", 1.15); + auto line_height_val = prefs->getDouble("/tools/text/lineheight", 1.25); _line_height_adj = Gtk::Adjustment::create(line_height_val, 0.0, 1000.0, 0.1, 1.0); _line_height_item = Gtk::manage(new UI::Widget::SpinButtonToolItem("text-line-height", "", _line_height_adj, 0.1, 2)); @@ -1313,22 +1236,6 @@ TextToolbar::direction_changed(int mode) _freeze = false; } -/* void sp_copy_property(SPItem *from, SPItem *to, Glib::ustring const &name) -{ - SPStyle *from_style = from->style; - SPStyle *to_style = to->style; - SPCSSAttr *from_cssattr = sp_css_attr_from_style(from_style, SP_STYLE_FLAG_IFSET); - SPCSSAttr *to_cssattr = sp_css_attr_from_style(to_style, SP_STYLE_FLAG_IFSET); - Glib::ustring from_value = sp_repr_css_property(from_cssattr, name, "0"); - SPCSSAttr *css = sp_repr_css_attr_new (); - std::cout << from_value.c_str() << std::endl; - sp_repr_css_set_property (css, "line-height", from_value.c_str()); - to->changeCSS (css, "style"); - sp_repr_css_attr_unref (css); - sp_repr_css_attr_unref (from_cssattr); - sp_repr_css_attr_unref (to_cssattr); -} */ - void TextToolbar::lineheight_value_changed() { @@ -1350,11 +1257,13 @@ TextToolbar::lineheight_value_changed() // Set css line height. SPCSSAttr *css = sp_repr_css_attr_new (); Inkscape::CSSOStringStream osfs; - // @tav is this correct why we coudent store oter units if we need to render ok if it came from outside - // if ( is_relative(unit) ) { - osfs << _line_height_adj->get_value() << unit->abbr; + if ( is_relative(unit) ) { + osfs << _line_height_adj->get_value() << unit->abbr; + } else { + // Inside SVG file, always use "px" for absolute units. + osfs << Quantity::convert(_line_height_adj->get_value(), unit, "px") << "px"; + } sp_repr_css_set_property (css, "line-height", osfs.str().c_str()); - Inkscape::Selection *selection = desktop->getSelection(); auto itemlist= selection->items(); bool modmade = false; @@ -1376,6 +1285,9 @@ TextToolbar::lineheight_value_changed() } } } else { + SPCSSAttr *css_unset = sp_repr_css_attr_unset_all( css ); + SPItem *parent = dynamic_cast<SPItem *>(*itemlist.begin()); + parent->changeCSS (css, "style"); subselection_wrap_toggle(); sp_desktop_set_style (desktop, css, true, true); subselection_wrap_toggle(); @@ -1437,8 +1349,9 @@ TextToolbar::lineheight_unit_changed(int /* Not Used */) Inkscape::CSSOStringStream temp_stream; temp_stream << 1 << unit->abbr; temp_length.read(temp_stream.str().c_str()); - prefs->setInt("/tools/text/lineheight/display_unit", temp_length.unit); - _lineheight_unit = temp_length.unit; + if (!is_relative(SPCSSUnit(temp_length.unit))) { + prefs->setInt("/tools/text/lineheight/display_unit", temp_length.unit); + } if (old_unit == temp_length.unit) { return; } @@ -1516,8 +1429,12 @@ TextToolbar::lineheight_unit_changed(int /* Not Used */) // Set css line height. SPCSSAttr *css = sp_repr_css_attr_new (); Inkscape::CSSOStringStream osfs; - // @tav the same to store units diferent than pixels - osfs << line_height << unit->abbr; + // Set css line height. + if ( is_relative(unit) ) { + osfs << line_height << unit->abbr; + } else { + osfs << Quantity::convert(line_height, unit, "px") << "px"; + } sp_repr_css_set_property (css, "line-height", osfs.str().c_str()); // Update GUI with line_height value. @@ -1548,6 +1465,9 @@ TextToolbar::lineheight_unit_changed(int /* Not Used */) } } } else { + SPCSSAttr *css_unset = sp_repr_css_attr_unset_all( css ); + SPItem *parent = dynamic_cast<SPItem *>(*itemlist.begin()); + parent->changeCSS (css, "style"); subselection_wrap_toggle(); sp_desktop_set_style (desktop, css, true, true); subselection_wrap_toggle(); @@ -2003,6 +1923,11 @@ TextToolbar::selection_changed(Inkscape::Selection * /*selection*/, bool subsele } // We dot want to parse values just show + if (!is_relative(SPCSSUnit(line_height_unit))) { + gint absunit = prefs->getInt("/tools/text/lineheight/display_unit", 1); + height = Quantity::convert(height, "px", sp_style_get_css_unit_string(absunit)); + line_height_unit = absunit; + } _line_height_adj->set_value(height); @@ -2025,8 +1950,6 @@ TextToolbar::selection_changed(Inkscape::Selection * /*selection*/, bool subsele // Save unit so we can do conversions between new/old units. _lineheight_unit = line_height_unit; - prefs->setInt("/tools/text/lineheight/display_unit", line_height_unit); - // Word spacing double wordSpacing; if (query.word_spacing.normal) wordSpacing = 0.0; diff --git a/src/ui/toolbar/text-toolbar.h b/src/ui/toolbar/text-toolbar.h index f18a3f434..6e0127223 100644 --- a/src/ui/toolbar/text-toolbar.h +++ b/src/ui/toolbar/text-toolbar.h @@ -65,13 +65,11 @@ class TextToolbar : public Toolbar { private: bool _freeze; bool _text_style_from_prefs; - bool _initial; UI::Widget::UnitTracker *_tracker; UI::Widget::ComboBoxEntryToolItem *_font_family_item; UI::Widget::ComboBoxEntryToolItem *_font_size_item; UI::Widget::ComboBoxEntryToolItem *_font_style_item; - Gtk::ToggleToolButton *_line_spacing_menu_launcher; UI::Widget::ComboToolItem *_line_height_units_item; UI::Widget::SpinButtonToolItem *_line_height_item; Gtk::ToggleToolButton *_superscript_item; |
