summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMartin Owens <doctormo@gmail.com>2016-03-12 23:50:04 +0000
committerMartin Owens <doctormo@gmail.com>2016-03-12 23:50:04 +0000
commit1c9e7ee09d40b8e06b80d0a09eca17d1b0fb8357 (patch)
treec660c2c4b4002e3c142d386582afeddd5f5b35b3 /src
parentAdd new TTF to the logo in seamless pattern extension (diff)
downloadinkscape-1c9e7ee09d40b8e06b80d0a09eca17d1b0fb8357.tar.gz
inkscape-1c9e7ee09d40b8e06b80d0a09eca17d1b0fb8357.zip
Add a units box to line height and wire in the style units, plus some cleanup
(bzr r14701)
Diffstat (limited to 'src')
-rw-r--r--src/desktop-style.cpp8
-rw-r--r--src/libnrtype/Layout-TNG.cpp2
-rw-r--r--src/sp-text.cpp9
-rw-r--r--src/style.cpp4
-rw-r--r--src/ui/widget/unit-tracker.cpp10
-rw-r--r--src/ui/widget/unit-tracker.h1
-rw-r--r--src/util/units.cpp70
-rw-r--r--src/util/units.h8
-rw-r--r--src/widgets/select-toolbar.cpp159
-rw-r--r--src/widgets/text-toolbar.cpp81
-rw-r--r--src/widgets/toolbox.cpp6
11 files changed, 233 insertions, 125 deletions
diff --git a/src/desktop-style.cpp b/src/desktop-style.cpp
index c36bcee44..c28302d22 100644
--- a/src/desktop-style.cpp
+++ b/src/desktop-style.cpp
@@ -1049,6 +1049,7 @@ objects_query_fontnumbers (const std::vector<SPItem*> &objects, SPStyle *style_r
double letterspacing_prev = 0;
double wordspacing_prev = 0;
double linespacing_prev = 0;
+ int linespacing_unit = 0;
int texts = 0;
int no_size = 0;
@@ -1105,6 +1106,11 @@ objects_query_fontnumbers (const std::vector<SPItem*> &objects, SPStyle *style_r
linespacing_current = style->line_height.computed;
linespacing_normal = false;
}
+ if (linespacing_unit == 0) {
+ linespacing_unit = style->line_height.unit;
+ } else if (linespacing_unit != style->line_height.unit) {
+ linespacing_unit = SP_CSS_UNIT_PERCENT;
+ }
linespacing += linespacing_current;
if ((size_prev != 0 && style->font_size.computed != size_prev) ||
@@ -1148,7 +1154,7 @@ objects_query_fontnumbers (const std::vector<SPItem*> &objects, SPStyle *style_r
style_res->line_height.normal = linespacing_normal;
style_res->line_height.computed = linespacing;
style_res->line_height.value = linespacing;
- style_res->line_height.unit = SP_CSS_UNIT_PERCENT;
+ style_res->line_height.unit = linespacing_unit;
if (texts > 1) {
if (different) {
diff --git a/src/libnrtype/Layout-TNG.cpp b/src/libnrtype/Layout-TNG.cpp
index 8b0889188..ec488b584 100644
--- a/src/libnrtype/Layout-TNG.cpp
+++ b/src/libnrtype/Layout-TNG.cpp
@@ -14,7 +14,7 @@ namespace Inkscape {
namespace Text {
const gunichar Layout::UNICODE_SOFT_HYPHEN = 0x00AD;
-const double Layout::LINE_HEIGHT_NORMAL = 1.25;
+const double Layout::LINE_HEIGHT_NORMAL = 125;
Layout::Layout() :
_input_truncated(0),
diff --git a/src/sp-text.cpp b/src/sp-text.cpp
index afbe0b147..4a5b1b1d6 100644
--- a/src/sp-text.cpp
+++ b/src/sp-text.cpp
@@ -302,15 +302,6 @@ Inkscape::XML::Node *SPText::write(Inkscape::XML::Document *xml_doc, Inkscape::X
this->attributes.writeTo(repr);
this->rebuildLayout(); // copied from update(), see LP Bug 1339305
- // deprecated attribute, but keep it around for backwards compatibility
- if (this->style->line_height.set && !this->style->line_height.inherit && !this->style->line_height.normal && this->style->line_height.unit == SP_CSS_UNIT_PERCENT) {
- Inkscape::SVGOStringStream os;
- os << (this->style->line_height.value * 100.0) << "%";
- this->getRepr()->setAttribute("sodipodi:linespacing", os.str().c_str());
- } else {
- this->getRepr()->setAttribute("sodipodi:linespacing", NULL);
- }
-
// SVG 2 Auto-wrapped text
if( this->width.computed > 0.0 ) {
sp_repr_set_svg_double(repr, "width", this->width.computed);
diff --git a/src/style.cpp b/src/style.cpp
index 35138d25b..99beaed22 100644
--- a/src/style.cpp
+++ b/src/style.cpp
@@ -113,7 +113,7 @@ SPStyle::SPStyle(SPDocument *document_in, SPObject *object_in) :
font_weight( "font-weight", enum_font_weight, SP_CSS_FONT_WEIGHT_NORMAL, SP_CSS_FONT_WEIGHT_400 ),
font_stretch( "font-stretch", enum_font_stretch, SP_CSS_FONT_STRETCH_NORMAL ),
font_size(),
- line_height( "line-height", 1.25 ), // SPILengthOrNormal
+ line_height( "line-height", 125 ), // SPILengthOrNormal
font_family( "font-family", "sans-serif" ), // SPIString w/default
font(), // SPIFont
font_specification( "-inkscape-font-specification" ), // SPIString
@@ -1957,7 +1957,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", ex, true);
+ //sp_css_attr_scale_property_single(css, "line-height", ex, true);
return css;
}
diff --git a/src/ui/widget/unit-tracker.cpp b/src/ui/widget/unit-tracker.cpp
index c6318db25..a1501c229 100644
--- a/src/ui/widget/unit-tracker.cpp
+++ b/src/ui/widget/unit-tracker.cpp
@@ -12,6 +12,7 @@
* Released under GNU GPL, read the file 'COPYING' for more information
*/
+#include "style-internal.h"
#include "unit-tracker.h"
#include "widgets/ege-select-one-action.h"
@@ -121,6 +122,15 @@ void UnitTracker::addUnit(Inkscape::Util::Unit const *u)
gtk_list_store_set(_store, &iter, COLUMN_STRING, u ? u->abbr.c_str() : "NULL", -1);
}
+void UnitTracker::prependUnit(Inkscape::Util::Unit const *u)
+{
+ GtkTreeIter iter;
+ gtk_list_store_prepend(_store, &iter);
+ gtk_list_store_set(_store, &iter, COLUMN_STRING, u ? u->abbr.c_str() : "NULL", -1);
+ /* Re-shuffle our default selection here (_active gets out of sync) */
+ setActiveUnit(_activeUnit);
+}
+
void UnitTracker::setFullVal(GtkAdjustment *adj, gdouble val)
{
_priorValues[adj] = val;
diff --git a/src/ui/widget/unit-tracker.h b/src/ui/widget/unit-tracker.h
index 06245930e..0fe5bda80 100644
--- a/src/ui/widget/unit-tracker.h
+++ b/src/ui/widget/unit-tracker.h
@@ -42,6 +42,7 @@ public:
Inkscape::Util::Unit const * getActiveUnit() const;
void addUnit(Inkscape::Util::Unit const *u);
+ void prependUnit(Inkscape::Util::Unit const *u);
void addAdjustment(GtkAdjustment *adj);
void setFullVal(GtkAdjustment *adj, gdouble val);
diff --git a/src/util/units.cpp b/src/util/units.cpp
index 2c72ec3ae..2e7a3b1d2 100644
--- a/src/util/units.cpp
+++ b/src/util/units.cpp
@@ -81,7 +81,21 @@ unsigned const svg_length_lookup[] = {
UNIT_CODE_PERCENT
};
-
+/* From SP_CSS_UNIT_* to unit */
+unsigned const sp_css_unit_lookup[] = {
+ 0,
+ UNIT_CODE_PX,
+ UNIT_CODE_PT,
+ UNIT_CODE_PC,
+ UNIT_CODE_MM,
+ UNIT_CODE_CM,
+ UNIT_CODE_IN,
+ UNIT_CODE_EM,
+ UNIT_CODE_EX,
+ UNIT_CODE_PERCENT
+ // UNIT_CODE_FT Missing,
+ // UNIT_CODE_MT Missing,
+};
// maps unit codes obtained from their abbreviations to their SVGLength unit indexes
typedef INK_UNORDERED_MAP<unsigned, SVGLength::Unit> UnitCodeLookup;
@@ -213,6 +227,10 @@ bool Unit::compatibleWith(Glib::ustring const &u) const
{
return compatibleWith(unit_table.getUnit(u));
}
+bool Unit::compatibleWith(char const *u) const
+{
+ return compatibleWith(unit_table.getUnit(u));
+}
bool Unit::operator==(Unit const &other) const
{
@@ -231,7 +249,29 @@ int Unit::svgUnit() const
return 0;
}
-
+double Unit::convert(double from_dist, Unit const *to) const
+{
+ // Percentage
+ if (to->type == UNIT_TYPE_DIMENSIONLESS) {
+ return from_dist * to->factor;
+ }
+
+ // Incompatible units
+ if (type != to->type) {
+ return -1;
+ }
+
+ // Compatible units
+ return from_dist * factor / to->factor;
+}
+double Unit::convert(double from_dist, Glib::ustring const &to) const
+{
+ return convert(from_dist, unit_table.getUnit(to));
+}
+double Unit::convert(double from_dist, char const *to) const
+{
+ return convert(from_dist, unit_table.getUnit(to));
+}
Unit UnitTable::_empty_unit;
@@ -283,6 +323,19 @@ Unit const *UnitTable::getUnit(SVGLength::Unit u) const
}
return &_empty_unit;
}
+/* SP_CSS_UNIT lookup */
+Unit const *UnitTable::getUnit(unsigned int u) const
+{
+ if (u == 0 || u > 9) {
+ return &_empty_unit;
+ }
+
+ UnitCodeMap::const_iterator f = _unit_map.find(sp_css_unit_lookup[u]);
+ if (f != _unit_map.end()) {
+ return &(*f->second);
+ }
+ return &_empty_unit;
+}
Unit const *UnitTable::findUnit(double factor, UnitType type) const
{
@@ -505,18 +558,7 @@ Glib::ustring Quantity::string() const {
double Quantity::convert(double from_dist, Unit const *from, Unit const *to)
{
- // Percentage
- if (to->type == UNIT_TYPE_DIMENSIONLESS) {
- return from_dist * to->factor;
- }
-
- // Incompatible units
- if (from->type != to->type) {
- return -1;
- }
-
- // Compatible units
- return from_dist * from->factor / to->factor;
+ return from->convert(from_dist, to);
}
double Quantity::convert(double from_dist, Glib::ustring const &from, Unit const *to)
{
diff --git a/src/util/units.h b/src/util/units.h
index 13777fd1b..a840a37ec 100644
--- a/src/util/units.h
+++ b/src/util/units.h
@@ -75,6 +75,11 @@ public:
/** Get SVG unit code. */
int svgUnit() const;
+
+ /** Convert value from this unit **/
+ double convert(double from_dist, Unit const *to) const;
+ double convert(double from_dist, Glib::ustring const &to) const;
+ double convert(double from_dist, char const *to) const;
};
class Quantity
@@ -147,6 +152,9 @@ public:
/** Retrieve a given unit based on its SVGLength unit */
Unit const *getUnit(SVGLength::Unit u) const;
+
+ /** Retrieve a given unit based on its SP_CSS_UNIT */
+ Unit const *getUnit(unsigned int u) const;
/** Retrieve a quantity based on its string identifier */
Quantity parseQuantity(Glib::ustring const &q) const;
diff --git a/src/widgets/select-toolbar.cpp b/src/widgets/select-toolbar.cpp
index e49c4c00a..3cd6c0e28 100644
--- a/src/widgets/select-toolbar.cpp
+++ b/src/widgets/select-toolbar.cpp
@@ -136,13 +136,13 @@ sp_selection_layout_widget_change_selection(SPWidget *spw, Inkscape::Selection *
}
static void
-sp_object_layout_any_value_changed(GtkAdjustment *adj, SPWidget *spw)
+sp_object_layout_any_value_changed(GtkAdjustment *adj, GObject *tbl)
{
- if (g_object_get_data(G_OBJECT(spw), "update")) {
+ if (g_object_get_data(tbl, "update")) {
return;
}
- UnitTracker *tracker = reinterpret_cast<UnitTracker*>(g_object_get_data(G_OBJECT(spw), "tracker"));
+ UnitTracker *tracker = reinterpret_cast<UnitTracker*>(g_object_get_data(tbl, "tracker"));
if ( !tracker || tracker->isUpdating() ) {
/*
* When only units are being changed, don't treat changes
@@ -150,7 +150,7 @@ sp_object_layout_any_value_changed(GtkAdjustment *adj, SPWidget *spw)
*/
return;
}
- g_object_set_data(G_OBJECT(spw), "update", GINT_TO_POINTER(TRUE));
+ g_object_set_data(tbl, "update", GINT_TO_POINTER(TRUE));
SPDesktop *desktop = SP_ACTIVE_DESKTOP;
Inkscape::Selection *selection = desktop->getSelection();
@@ -168,7 +168,7 @@ sp_object_layout_any_value_changed(GtkAdjustment *adj, SPWidget *spw)
Geom::OptRect bbox_user = selection->bounds(bbox_type);
if ( !bbox_user ) {
- g_object_set_data(G_OBJECT(spw), "update", GINT_TO_POINTER(FALSE));
+ g_object_set_data(tbl, "update", GINT_TO_POINTER(FALSE));
return;
}
@@ -181,10 +181,10 @@ sp_object_layout_any_value_changed(GtkAdjustment *adj, SPWidget *spw)
Unit const *unit = tracker->getActiveUnit();
g_return_if_fail(unit != NULL);
- GtkAdjustment* a_x = GTK_ADJUSTMENT( g_object_get_data( G_OBJECT(spw), "X" ) );
- GtkAdjustment* a_y = GTK_ADJUSTMENT( g_object_get_data( G_OBJECT(spw), "Y" ) );
- GtkAdjustment* a_w = GTK_ADJUSTMENT( g_object_get_data( G_OBJECT(spw), "width" ) );
- GtkAdjustment* a_h = GTK_ADJUSTMENT( g_object_get_data( G_OBJECT(spw), "height" ) );
+ GtkAdjustment* a_x = GTK_ADJUSTMENT( g_object_get_data( tbl, "X" ) );
+ GtkAdjustment* a_y = GTK_ADJUSTMENT( g_object_get_data( tbl, "Y" ) );
+ GtkAdjustment* a_w = GTK_ADJUSTMENT( g_object_get_data( tbl, "width" ) );
+ GtkAdjustment* a_h = GTK_ADJUSTMENT( g_object_get_data( tbl, "height" ) );
if (unit->type == Inkscape::Util::UNIT_TYPE_LINEAR) {
x0 = Quantity::convert(gtk_adjustment_get_value(a_x), unit, "px");
@@ -205,7 +205,7 @@ sp_object_layout_any_value_changed(GtkAdjustment *adj, SPWidget *spw)
}
// Keep proportions if lock is on
- GtkToggleAction *lock = GTK_TOGGLE_ACTION( g_object_get_data(G_OBJECT(spw), "lock") );
+ GtkToggleAction *lock = GTK_TOGGLE_ACTION( g_object_get_data(tbl, "lock") );
if ( gtk_toggle_action_get_active(lock) ) {
if (adj == a_h) {
x1 = x0 + yrel * bbox_user->dimensions()[Geom::X];
@@ -265,68 +265,7 @@ sp_object_layout_any_value_changed(GtkAdjustment *adj, SPWidget *spw)
desktop->getCanvas()->endForcedFullRedraws();
}
- g_object_set_data(G_OBJECT(spw), "update", GINT_TO_POINTER(FALSE));
-}
-
-static GtkWidget* createCustomSlider( GtkAdjustment *adjustment, gdouble climbRate, guint digits, Inkscape::UI::Widget::UnitTracker *unit_tracker )
-{
-#if WITH_GTKMM_3_0
- Glib::RefPtr<Gtk::Adjustment> adj = Glib::wrap(adjustment, true);
- Inkscape::UI::Widget::SpinButton *inkSpinner = new Inkscape::UI::Widget::SpinButton(adj, climbRate, digits);
-#else
- Inkscape::UI::Widget::SpinButton *inkSpinner = new Inkscape::UI::Widget::SpinButton(*Glib::wrap(adjustment, true), climbRate, digits);
-#endif
- inkSpinner->addUnitTracker(unit_tracker);
- inkSpinner = Gtk::manage( inkSpinner );
- GtkWidget *widget = GTK_WIDGET( inkSpinner->gobj() );
- return widget;
-}
-
-// TODO create_adjustment_action appears to be a rogue tile copy from toolbox.cpp. Resolve it to be unified:
-
-static EgeAdjustmentAction * create_adjustment_action( gchar const *name,
- gchar const *label,
- gchar const *shortLabel,
- gchar const *data,
- gdouble lower,
- GtkWidget* focusTarget,
- UnitTracker* tracker,
- GtkWidget* spw,
- gchar const *tooltip,
- gboolean altx )
-{
- static bool init = false;
- if ( !init ) {
- init = true;
- ege_adjustment_action_set_compact_tool_factory( createCustomSlider );
- }
-
- GtkAdjustment* adj = GTK_ADJUSTMENT( gtk_adjustment_new( 0.0, lower, 1e6, SPIN_STEP, SPIN_PAGE_STEP, 0 ) );
- if (tracker) {
- tracker->addAdjustment(adj);
- }
- if ( spw ) {
- g_object_set_data( G_OBJECT(spw), data, adj );
- }
-
- EgeAdjustmentAction* act = ege_adjustment_action_new( adj, name, Q_(label), tooltip, 0, SPIN_STEP, 3, tracker );
- if ( shortLabel ) {
- g_object_set( act, "short_label", Q_(shortLabel), NULL );
- }
-
- g_signal_connect( G_OBJECT(adj), "value_changed", G_CALLBACK(sp_object_layout_any_value_changed), spw );
- if ( focusTarget ) {
- ege_adjustment_action_set_focuswidget( act, focusTarget );
- }
-
- if ( altx ) { // this spinbutton will be activated by alt-x
- g_object_set( G_OBJECT(act), "self-id", "altx", NULL );
- }
-
- // Using a cast just to make sure we pass in the right kind of function pointer
- g_object_set( G_OBJECT(act), "tool-post", static_cast<EgeWidgetFixup>(sp_set_font_size_smaller), NULL );
-
- return act;
+ g_object_set_data(tbl, "update", GINT_TO_POINTER(FALSE));
}
// toggle button callbacks and updaters
@@ -497,21 +436,60 @@ void sp_select_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GOb
// four spinbuttons
- eact = create_adjustment_action( "XAction", C_("Select toolbar", "X position"), C_("Select toolbar", "X:"), "X",
- -1e6, GTK_WIDGET(desktop->canvas), tracker, spw,
- _("Horizontal coordinate of selection"), TRUE );
+ eact = create_adjustment_action(
+ /* name= */ "XAction",
+ /* label= */ C_("Select toolbar", "X position"),
+ /* shortLabel= */ C_("Select toolbar", "X:"),
+ /* tooltip= */ C_("Select toolbar", "Horizontal coordinate of selection"),
+ /* path= */ "/tools/select/X",
+ /* def(default) */ 0.0,
+ /* focusTarget= */ GTK_WIDGET(desktop->canvas),
+ /* dataKludge= */ G_OBJECT(spw),
+ /* altx, altx_mark */ TRUE, "altx",
+ /* lower, uppper, step, page */ -1e6, 1e6, SPIN_STEP, SPIN_PAGE_STEP,
+ /* descrLabels, descrValues, descrCount */ 0, 0, 0,
+ /* callback= */ sp_object_layout_any_value_changed,
+ /* unit_tracker= */ tracker,
+ /* climb, digits, factor */ SPIN_STEP, 3, 1);
+
gtk_action_group_add_action( selectionActions, GTK_ACTION(eact) );
contextActions->push_back( GTK_ACTION(eact) );
- eact = create_adjustment_action( "YAction", C_("Select toolbar", "Y position"), C_("Select toolbar", "Y:"), "Y",
- -1e6, GTK_WIDGET(desktop->canvas), tracker, spw,
- _("Vertical coordinate of selection"), FALSE );
+ eact = create_adjustment_action(
+ /* name= */ "YAction",
+ /* label= */ C_("Select toolbar", "Y position"),
+ /* shortLabel= */ C_("Select toolbar", "Y:"),
+ /* tooltip= */ C_("Select toolbar", "Vertical coordinate of selection"),
+ /* path= */ "/tools/select/Y",
+ /* def(default) */ 0.0,
+ /* focusTarget= */ GTK_WIDGET(desktop->canvas),
+ /* dataKludge= */ G_OBJECT(spw),
+ /* altx, altx_mark */ TRUE, "altx",
+ /* lower, uppper, step, page */ -1e6, 1e6, SPIN_STEP, SPIN_PAGE_STEP,
+ /* descrLabels, descrValues, descrCount */ 0, 0, 0,
+ /* callback= */ sp_object_layout_any_value_changed,
+ /* unit_tracker= */ tracker,
+ /* climb, digits, factor */ SPIN_STEP, 3, 1);
+
gtk_action_group_add_action( selectionActions, GTK_ACTION(eact) );
contextActions->push_back( GTK_ACTION(eact) );
- eact = create_adjustment_action( "WidthAction", C_("Select toolbar", "Width"), C_("Select toolbar", "W:"), "width",
- 0.0, GTK_WIDGET(desktop->canvas), tracker, spw,
- _("Width of selection"), FALSE );
+ eact = create_adjustment_action(
+ /* name= */ "WidthAction",
+ /* label= */ C_("Select toolbar", "Width"),
+ /* shortLabel= */ C_("Select toolbar", "W:"),
+ /* tooltip= */ C_("Select toolbar", "Width of selection"),
+ /* path= */ "/tools/select/width",
+ /* def(default) */ 0.0,
+ /* focusTarget= */ GTK_WIDGET(desktop->canvas),
+ /* dataKludge= */ G_OBJECT(spw),
+ /* altx, altx_mark */ TRUE, "altx",
+ /* lower, uppper, step, page */ 0.0, 1e6, SPIN_STEP, SPIN_PAGE_STEP,
+ /* descrLabels, descrValues, descrCount */ 0, 0, 0,
+ /* callback= */ sp_object_layout_any_value_changed,
+ /* unit_tracker= */ tracker,
+ /* climb, digits, factor */ SPIN_STEP, 3, 1);
+
gtk_action_group_add_action( selectionActions, GTK_ACTION(eact) );
contextActions->push_back( GTK_ACTION(eact) );
@@ -528,9 +506,22 @@ void sp_select_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GOb
gtk_action_group_add_action( mainActions, GTK_ACTION(itact) );
}
- eact = create_adjustment_action( "HeightAction", C_("Select toolbar", "Height"), C_("Select toolbar", "H:"), "height",
- 0.0, GTK_WIDGET(desktop->canvas), tracker, spw,
- _("Height of selection"), FALSE );
+ eact = create_adjustment_action(
+ /* name= */ "HeightAction",
+ /* label= */ C_("Select toolbar", "Height"),
+ /* shortLabel= */ C_("Select toolbar", "H:"),
+ /* tooltip= */ C_("Select toolbar", "Height of selection"),
+ /* path= */ "/tools/select/height",
+ /* def(default) */ 0.0,
+ /* focusTarget= */ GTK_WIDGET(desktop->canvas),
+ /* dataKludge= */ G_OBJECT(spw),
+ /* altx, altx_mark */ TRUE, "altx",
+ /* lower, uppper, step, page */ 0.0, 1e6, SPIN_STEP, SPIN_PAGE_STEP,
+ /* descrLabels, descrValues, descrCount */ 0, 0, 0,
+ /* callback= */ sp_object_layout_any_value_changed,
+ /* unit_tracker= */ tracker,
+ /* climb, digits, factor */ SPIN_STEP, 3, 1);
+
gtk_action_group_add_action( selectionActions, GTK_ACTION(eact) );
contextActions->push_back( GTK_ACTION(eact) );
diff --git a/src/widgets/text-toolbar.cpp b/src/widgets/text-toolbar.cpp
index 5ca92b4c0..c49f0bc05 100644
--- a/src/widgets/text-toolbar.cpp
+++ b/src/widgets/text-toolbar.cpp
@@ -54,12 +54,17 @@
#include "ui/icon-names.h"
#include "ui/tools/text-tool.h"
#include "ui/tools/tool-base.h"
+#include "ui/widget/unit-tracker.h"
+#include "util/units.h"
#include "verbs.h"
#include "xml/repr.h"
using Inkscape::DocumentUndo;
using Inkscape::UI::ToolboxFactory;
using Inkscape::UI::PrefPusher;
+using Inkscape::UI::Widget::UnitTracker;
+using Inkscape::Util::Unit;
+using Inkscape::Util::unit_table;
//#define DEBUG_TEXT
@@ -504,8 +509,14 @@ static void sp_text_align_mode_changed( EgeSelectOneAction *act, GObject *tbl )
static void sp_text_lineheight_value_changed( GtkAdjustment *adj, GObject *tbl )
{
- // quit if run by the _changed callbacks
- if (g_object_get_data(G_OBJECT(tbl), "freeze")) {
+ UnitTracker *tracker = reinterpret_cast<UnitTracker*>(g_object_get_data(tbl, "tracker"));
+
+ if ( !tracker || tracker->isUpdating() || g_object_get_data(tbl, "freeze")) {
+ /*
+ * When only units are being changed, don't treat changes
+ * to adjuster values as object changes.
+ * or quit if run by the _changed callbacks
+ */
return;
}
g_object_set_data( tbl, "freeze", GINT_TO_POINTER(TRUE) );
@@ -514,7 +525,18 @@ static void sp_text_lineheight_value_changed( GtkAdjustment *adj, GObject *tbl )
// Set css line height.
SPCSSAttr *css = sp_repr_css_attr_new ();
Inkscape::CSSOStringStream osfs;
- osfs << gtk_adjustment_get_value(adj)*100 << "%";
+
+ gdouble value = gtk_adjustment_get_value(adj);
+
+ Unit const *unit = tracker->getActiveUnit();
+
+ // Value can only be in px or percent or naked pc (e.g. 0.7 for 70%)
+ if (unit->abbr != "%") {
+ value = unit->convert(value, "px");
+ unit = unit_table.getUnit("px");
+ }
+
+ osfs << value << unit->abbr;
sp_repr_css_set_property (css, "line-height", osfs.str().c_str());
// Apply line-height to selected objects.
@@ -1073,21 +1095,31 @@ static void sp_text_toolbox_selection_changed(Inkscape::Selection */*selection*/
// Line height (spacing)
double height;
+
+ Unit const *lh_unit;
+ UnitTracker* tracker = reinterpret_cast<UnitTracker*>( g_object_get_data( tbl, "tracker" ) );
+
if (query.line_height.normal) {
- height = Inkscape::Text::Layout::LINE_HEIGHT_NORMAL;
+ lh_unit = unit_table.getUnit("%");
+ height = Inkscape::Text::Layout::LINE_HEIGHT_NORMAL * 100;
+ } else if (query.line_height.unit == SP_CSS_UNIT_PERCENT) {
+ lh_unit = unit_table.getUnit("%");
+ height = query.line_height.value * 100;
} else {
- if (query.line_height.unit == SP_CSS_UNIT_PERCENT) {
- height = query.line_height.value;
- } else {
- height = query.line_height.computed;
- }
+ lh_unit = tracker->getActiveUnit();
+ // Can get unit like this: unit_table.getUnit(query.line_height.unit);
+ height = Inkscape::Util::Quantity::convert(query.line_height.computed, "px", lh_unit);
}
+ // Set before value is set
+ tracker->setActiveUnit(lh_unit);
+
GtkAction* lineHeightAction = GTK_ACTION( g_object_get_data( tbl, "TextLineHeightAction" ) );
GtkAdjustment *lineHeightAdjustment =
ege_adjustment_action_get_adjustment(EGE_ADJUSTMENT_ACTION( lineHeightAction ));
gtk_adjustment_set_value( lineHeightAdjustment, height );
+ height = gtk_adjustment_get_value( lineHeightAdjustment );
// Word spacing
double wordSpacing;
@@ -1290,6 +1322,15 @@ static void sp_text_toolbox_select_cb( GtkEntry* entry, GtkEntryIconPosition /*p
static void text_toolbox_watch_ec(SPDesktop* dt, Inkscape::UI::Tools::ToolBase* ec, GObject* holder);
+static void destroy_tracker( GObject* obj, gpointer /*user_data*/ )
+{
+ UnitTracker *tracker = reinterpret_cast<UnitTracker*>(g_object_get_data(obj, "tracker"));
+ if ( tracker ) {
+ delete tracker;
+ g_object_set_data( obj, "tracker", 0 );
+ }
+}
+
// Define all the "widgets" in the toolbar.
void sp_text_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder)
{
@@ -1588,22 +1629,29 @@ void sp_text_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje
gchar const* labels[] = {_("Smaller spacing"), 0, 0, 0, 0, C_("Text tool", "Normal"), 0, 0, 0, 0, 0, _("Larger spacing")};
gdouble 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};
+ // Add the units menu.
+ UnitTracker* tracker = new UnitTracker(Inkscape::Util::UNIT_TYPE_LINEAR);
+ tracker->prependUnit(unit_table.getUnit("%"));
+
+ g_object_set_data( holder, "tracker", tracker );
+ g_signal_connect( holder, "destroy", G_CALLBACK(destroy_tracker), holder );
+
EgeAdjustmentAction *eact = create_adjustment_action(
"TextLineHeightAction", /* name */
_("Line Height"), /* label */
_("Line:"), /* short label */
- _("Spacing between baselines (times font size)"), /* tooltip */
+ _("Spacing between baselines"), /* tooltip */
"/tools/text/lineheight", /* preferences path */
- 0.0, /* default */
+ 125, /* default */
GTK_WIDGET(desktop->canvas), /* focusTarget */
holder, /* dataKludge */
FALSE, /* set alt-x keyboard shortcut? */
NULL, /* altx_mark */
- 0.0, 10.0, 0.01, 0.10, /* lower, upper, step (arrow up/down), page up/down */
+ 0.0, 1e6, 1.0, 10.0, /* lower, upper, step (arrow up/down), page up/down */
labels, values, G_N_ELEMENTS(labels), /* drop down menu */
sp_text_lineheight_value_changed, /* callback */
- NULL, /* unit tracker */
- 0.1, /* step (used?) */
+ tracker, /* unit tracker */
+ 1.0, /* step (used?) */
2, /* digits to show */
1.0 /* factor (multiplies default) */
);
@@ -1611,6 +1659,11 @@ void sp_text_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje
gtk_action_set_sensitive( GTK_ACTION(eact), TRUE );
g_object_set_data( holder, "TextLineHeightAction", eact );
g_object_set( G_OBJECT(eact), "iconId", "text_line_spacing", NULL );
+
+ GtkAction* act = tracker->createAction( "TextLineHeightUnitAction", _("Units"), ("") );
+ gtk_action_group_add_action( mainActions, act );
+ g_object_set_data( holder, "TextLineHeightUnitAction", act );
+
}
/* Word spacing */
diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp
index 72537f727..f4d7ebf25 100644
--- a/src/widgets/toolbox.cpp
+++ b/src/widgets/toolbox.cpp
@@ -55,6 +55,7 @@
#include "ui/tools-switch.h"
#include "../ui/icon-names.h"
#include "../ui/widget/style-swatch.h"
+#include "../ui/widget/unit-tracker.h"
#include "../verbs.h"
#include "../widgets/button.h"
#include "../widgets/spinbutton-events.h"
@@ -515,6 +516,7 @@ static gchar const * ui_descr =
" <toolitem action='TextSubscriptAction' />"
" <separator />"
" <toolitem action='TextLineHeightAction' />"
+ " <toolitem action='TextLineHeightUnitAction' />"
" <toolitem action='TextLetterSpacingAction' />"
" <toolitem action='TextWordSpacingAction' />"
" <toolitem action='TextDxAction' />"
@@ -1122,6 +1124,10 @@ EgeAdjustmentAction * create_adjustment_action( gchar const *name,
g_object_set_data( dataKludge, prefs->getEntry(path).getEntryName().data(), adj );
}
+ if (unit_tracker) {
+ unit_tracker->addAdjustment(adj);
+ }
+
// Using a cast just to make sure we pass in the right kind of function pointer
g_object_set( G_OBJECT(act), "tool-post", static_cast<EgeWidgetFixup>(sp_set_font_size_smaller), NULL );