summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTavmjong Bah <tavmjong@free.fr>2016-03-22 13:56:36 +0000
committertavmjong-free <tavmjong@free.fr>2016-03-22 13:56:36 +0000
commit4cce40a79ab973a3609cd5ee7666673bc2337fef (patch)
treeb2f2ccbc21c94eb5d0d0c5e377473dd4ec04106d /src
parentReverting 14701. (diff)
downloadinkscape-4cce40a79ab973a3609cd5ee7666673bc2337fef.tar.gz
inkscape-4cce40a79ab973a3609cd5ee7666673bc2337fef.zip
Add line-height unit selector to text toolbar.
Remove 'm' and 'ft' non-CSS lengths. (bzr r14716.1.3)
Diffstat (limited to 'src')
-rw-r--r--src/desktop-style.cpp96
-rw-r--r--src/style.cpp3
-rw-r--r--src/svg/svg-length-test.h5
-rw-r--r--src/svg/svg-length.cpp20
-rw-r--r--src/svg/svg-length.h2
-rw-r--r--src/ui/widget/preferences-widget.cpp4
-rw-r--r--src/widgets/text-toolbar.cpp256
-rw-r--r--src/widgets/toolbox.cpp1
8 files changed, 320 insertions, 67 deletions
diff --git a/src/desktop-style.cpp b/src/desktop-style.cpp
index 7f9670af3..5f6441aa7 100644
--- a/src/desktop-style.cpp
+++ b/src/desktop-style.cpp
@@ -1036,19 +1036,24 @@ int
objects_query_fontnumbers (const std::vector<SPItem*> &objects, SPStyle *style_res)
{
bool different = false;
+ bool different_lineheight = false;
+ bool different_lineheight_unit = false;
double size = 0;
double letterspacing = 0;
double wordspacing = 0;
- double linespacing = 0;
+ double lineheight = 0;
bool letterspacing_normal = false;
bool wordspacing_normal = false;
- bool linespacing_normal = false;
+ bool lineheight_normal = false;
+ bool lineheight_unit_proportional = false;
+ bool lineheight_unit_absolute = false;
double size_prev = 0;
double letterspacing_prev = 0;
double wordspacing_prev = 0;
- double linespacing_prev = 0;
+ double lineheight_prev = 0;
+ int lineheight_unit_prev = -1;
int texts = 0;
int no_size = 0;
@@ -1093,31 +1098,55 @@ objects_query_fontnumbers (const std::vector<SPItem*> &objects, SPStyle *style_r
wordspacing_normal = false;
}
- double linespacing_current;
+ // If all line spacing units the same, use that (average line spacing).
+ // Else if all line spacings absolute, use 'px' (average line spacing).
+ // Else if all line spacings proportional, use % (average line spacing).
+ // Else use default.
+ double lineheight_current;
+ int lineheight_unit_current;
if (style->line_height.normal) {
- linespacing_current = Inkscape::Text::Layout::LINE_HEIGHT_NORMAL;
- if (!different && (linespacing_prev == 0 || linespacing_prev == linespacing_current))
- linespacing_normal = true;
- } else if (style->line_height.unit == SP_CSS_UNIT_PERCENT || style->font_size.computed == 0) {
- linespacing_current = style->line_height.value;
- linespacing_normal = false;
+ lineheight_current = Inkscape::Text::Layout::LINE_HEIGHT_NORMAL;
+ lineheight_unit_current = SP_CSS_UNIT_NONE;
+ if (!different_lineheight &&
+ (lineheight_prev == 0 || lineheight_prev == lineheight_current))
+ lineheight_normal = true;
+ } else if (style->line_height.unit == SP_CSS_UNIT_NONE ||
+ style->line_height.unit == SP_CSS_UNIT_PERCENT ||
+ style->line_height.unit == SP_CSS_UNIT_EM ||
+ style->line_height.unit == SP_CSS_UNIT_EX ||
+ style->font_size.computed == 0) {
+ lineheight_current = style->line_height.value;
+ lineheight_unit_current = style->line_height.unit;
+ lineheight_unit_proportional = true;
+ lineheight_normal = false;
} else {
- linespacing_current = style->line_height.computed;
- linespacing_normal = false;
+ // Always 'px' internally
+ lineheight_current = style->line_height.computed;
+ lineheight_unit_current = style->line_height.unit;
+ lineheight_unit_absolute = true;
+ lineheight_normal = false;
}
- linespacing += linespacing_current;
+ lineheight += lineheight_current;
if ((size_prev != 0 && style->font_size.computed != size_prev) ||
(letterspacing_prev != 0 && style->letter_spacing.computed != letterspacing_prev) ||
- (wordspacing_prev != 0 && style->word_spacing.computed != wordspacing_prev) ||
- (linespacing_prev != 0 && linespacing_current != linespacing_prev)) {
+ (wordspacing_prev != 0 && style->word_spacing.computed != wordspacing_prev)) {
different = true;
}
+ if (lineheight_prev != 0 && lineheight_current != lineheight_prev) {
+ different_lineheight = true;
+ }
+
+ if (lineheight_unit_prev != -1 && lineheight_unit_current != lineheight_unit_prev) {
+ different_lineheight_unit = true;
+ }
+
size_prev = style->font_size.computed;
letterspacing_prev = style->letter_spacing.computed;
wordspacing_prev = style->word_spacing.computed;
- linespacing_prev = linespacing_current;
+ lineheight_prev = lineheight_current;
+ lineheight_unit_prev = lineheight_unit_current;
// FIXME: we must detect MULTIPLE_DIFFERENT for these too
style_res->text_anchor.computed = style->text_anchor.computed;
@@ -1133,7 +1162,7 @@ objects_query_fontnumbers (const std::vector<SPItem*> &objects, SPStyle *style_r
}
letterspacing /= texts;
wordspacing /= texts;
- linespacing /= texts;
+ lineheight /= texts;
}
style_res->font_size.computed = size;
@@ -1145,13 +1174,36 @@ objects_query_fontnumbers (const std::vector<SPItem*> &objects, SPStyle *style_r
style_res->word_spacing.normal = wordspacing_normal;
style_res->word_spacing.computed = wordspacing;
- 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.normal = lineheight_normal;
+ style_res->line_height.computed = lineheight;
+ style_res->line_height.value = lineheight;
+ if (different_lineheight_unit) {
+ if (lineheight_unit_absolute && !lineheight_unit_proportional) {
+ // Mixture of absolute units
+ style_res->line_height.unit = SP_CSS_UNIT_PX;
+ } else {
+ // Mixture of relative units
+ style_res->line_height.unit = SP_CSS_UNIT_PERCENT;
+ }
+ if (lineheight_unit_absolute && lineheight_unit_proportional) {
+ // Mixed types of units, fallback to default
+ style_res->line_height.computed = Inkscape::Text::Layout::LINE_HEIGHT_NORMAL * 100.0;
+ style_res->line_height.value = Inkscape::Text::Layout::LINE_HEIGHT_NORMAL * 100.0;
+ }
+ } else {
+ // Same units.
+ if (lineheight_unit_prev != -1) {
+ style_res->line_height.unit = lineheight_unit_prev;
+ } else {
+ // No text object... use default.
+ style_res->line_height.unit = SP_CSS_UNIT_NONE;
+ style_res->line_height.computed = Inkscape::Text::Layout::LINE_HEIGHT_NORMAL;
+ style_res->line_height.value = Inkscape::Text::Layout::LINE_HEIGHT_NORMAL;
+ }
+ }
if (texts > 1) {
- if (different) {
+ if (different || different_lineheight) {
return QUERY_STYLE_MULTIPLE_AVERAGED;
} else {
return QUERY_STYLE_MULTIPLE_SAME;
diff --git a/src/style.cpp b/src/style.cpp
index 35138d25b..1f98a50a3 100644
--- a/src/style.cpp
+++ b/src/style.cpp
@@ -1510,7 +1510,8 @@ gchar const *
sp_style_get_css_unit_string(int unit)
{
// specify px by default, see inkscape bug 1221626, mozilla bug 234789
-
+ // This is a problematic fix as some properties (e.g. 'line-height') have
+ // different behaviour if there is no unit.
switch (unit) {
case SP_CSS_UNIT_NONE: return "px";
diff --git a/src/svg/svg-length-test.h b/src/svg/svg-length-test.h
index 0dac4854a..e73211ade 100644
--- a/src/svg/svg-length-test.h
+++ b/src/svg/svg-length-test.h
@@ -102,10 +102,7 @@ public:
for ( int i = (static_cast<int>(SVGLength::NONE) + 1); i <= static_cast<int>(SVGLength::LAST_UNIT); i++ ) {
SVGLength::Unit target = static_cast<SVGLength::Unit>(i);
// PX is a special case where we don't have a unit string
- // FOOT and MITRE are not CSS/SVG Units
- if ( (target != SVGLength::PX) &&
- (target != SVGLength::FOOT) &&
- (target != SVGLength::MITRE) ) {
+ if ( (target != SVGLength::PX) ) {
gchar const* val = sp_svg_length_get_css_units(target);
TSM_ASSERT_DIFFERS(i, val, "");
}
diff --git a/src/svg/svg-length.cpp b/src/svg/svg-length.cpp
index cd995582d..d22da69cd 100644
--- a/src/svg/svg-length.cpp
+++ b/src/svg/svg-length.cpp
@@ -411,14 +411,6 @@ So after the number, the string does not necessarily have a \0 or a unit, it mig
*computed = Inkscape::Util::Quantity::convert(v, "in", "px");
}
break;
- case UVAL('f','t'):
- if (unit) {
- *unit = SVGLength::FOOT;
- }
- if (computed) {
- *computed = Inkscape::Util::Quantity::convert(v, "ft", "px");
- }
- break;
case UVAL('e','m'):
if (unit) {
*unit = SVGLength::EM;
@@ -495,12 +487,6 @@ void SVGLength::set(SVGLength::Unit u, float v)
case INCH:
hack = "pt";
break;
- case FOOT:
- hack = "pt";
- break;
- case MITRE:
- hack = "m";
- break;
default:
break;
}
@@ -572,8 +558,6 @@ gchar const *sp_svg_length_get_css_units(SVGLength::Unit unit)
case SVGLength::MM: return "mm";
case SVGLength::CM: return "cm";
case SVGLength::INCH: return "in";
- case SVGLength::FOOT: return ""; // Not in SVG/CSS specification.
- case SVGLength::MITRE: return ""; // Not in SVG/CSS specification.
case SVGLength::EM: return "em";
case SVGLength::EX: return "ex";
case SVGLength::PERCENT: return "%";
@@ -590,10 +574,6 @@ std::string sp_svg_length_write_with_units(SVGLength const &length)
Inkscape::SVGOStringStream os;
if (length.unit == SVGLength::PERCENT) {
os << 100*length.value << sp_svg_length_get_css_units(length.unit);
- } else if (length.unit == SVGLength::FOOT) {
- os << 12*length.value << sp_svg_length_get_css_units(SVGLength::INCH);
- } else if (length.unit == SVGLength::MITRE) {
- os << 100*length.value << sp_svg_length_get_css_units(SVGLength::CM);
} else {
os << length.value << sp_svg_length_get_css_units(length.unit);
}
diff --git a/src/svg/svg-length.h b/src/svg/svg-length.h
index 2aaf248b1..bd3435ca6 100644
--- a/src/svg/svg-length.h
+++ b/src/svg/svg-length.h
@@ -27,8 +27,6 @@ public:
MM,
CM,
INCH,
- FOOT,
- MITRE,
EM,
EX,
PERCENT,
diff --git a/src/ui/widget/preferences-widget.cpp b/src/ui/widget/preferences-widget.cpp
index e906762e3..d56506d62 100644
--- a/src/ui/widget/preferences-widget.cpp
+++ b/src/ui/widget/preferences-widget.cpp
@@ -468,12 +468,8 @@ ZoomCorrRuler::on_draw(const Cairo::RefPtr<Cairo::Context>& cr) {
Glib::ustring abbr = prefs->getString("/options/zoomcorrection/unit");
if (abbr == "cm") {
draw_marks(cr, 0.1, 10);
- } else if (abbr == "ft") {
- draw_marks(cr, 1/12.0, 12);
} else if (abbr == "in") {
draw_marks(cr, 0.25, 4);
- } else if (abbr == "m") {
- draw_marks(cr, 1/10.0, 10);
} else if (abbr == "mm") {
draw_marks(cr, 10, 10);
} else if (abbr == "pc") {
diff --git a/src/widgets/text-toolbar.cpp b/src/widgets/text-toolbar.cpp
index 5ca92b4c0..8df80d2b6 100644
--- a/src/widgets/text-toolbar.cpp
+++ b/src/widgets/text-toolbar.cpp
@@ -54,12 +54,18 @@
#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::Util::Unit;
+using Inkscape::Util::Quantity;
+using Inkscape::Util::unit_table;
+using Inkscape::UI::Widget::UnitTracker;
//#define DEBUG_TEXT
@@ -510,25 +516,48 @@ static void sp_text_lineheight_value_changed( GtkAdjustment *adj, GObject *tbl )
}
g_object_set_data( tbl, "freeze", GINT_TO_POINTER(TRUE) );
- // At the moment this handles only numerical values (i.e. no percent).
+
+ // Get user selected unit and save as preference
+ UnitTracker *tracker = reinterpret_cast<UnitTracker*>(g_object_get_data(tbl, "tracker"));
+ Unit const *unit = tracker->getActiveUnit();
+ g_return_if_fail(unit != NULL);
+ Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+
+
+ // This nonsense is to get SP_CSS_UNIT_xx value corresponding to unit so
+ // we can save it (allows us to adjust line height value when unit changes).
+ SPILength temp_length;
+ 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);
+ g_object_set_data( tbl, "lineheight_unit", GINT_TO_POINTER(temp_length.unit));
+
+
// Set css line height.
SPCSSAttr *css = sp_repr_css_attr_new ();
Inkscape::CSSOStringStream osfs;
- osfs << gtk_adjustment_get_value(adj)*100 << "%";
+ // We should handle unitless values as well as 'em' and 'ex'
+ if ((unit->abbr) == "em" || unit->abbr == "ex" || unit->abbr == "%") {
+ osfs << gtk_adjustment_get_value(adj) << unit->abbr;
+ } else {
+ // Inside SVG file, always use "px" for absolute units.
+ osfs << Quantity::convert(gtk_adjustment_get_value(adj), unit, "px") << "px";
+ }
sp_repr_css_set_property (css, "line-height", osfs.str().c_str());
+
// Apply line-height to selected objects.
SPDesktop *desktop = SP_ACTIVE_DESKTOP;
sp_desktop_set_style (desktop, css, true, false);
- // Until deprecated sodipodi:linespacing purged:
+ // Only need to save for undo if a text item has been changed.
Inkscape::Selection *selection = desktop->getSelection();
bool modmade = false;
std::vector<SPItem*> itemlist=selection->itemList();
for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end(); ++i){
if (SP_IS_TEXT (*i)) {
- (*i)->getRepr()->setAttribute("sodipodi:linespacing", sp_repr_css_property (css, "line-height", NULL));
modmade = true;
}
}
@@ -554,6 +583,153 @@ static void sp_text_lineheight_value_changed( GtkAdjustment *adj, GObject *tbl )
g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) );
}
+
+static void sp_text_lineheight_unit_changed( gpointer /* */, GObject *tbl )
+{
+ // quit if run by the _changed callbacks
+ if (g_object_get_data(G_OBJECT(tbl), "freeze")) {
+ return;
+ }
+ g_object_set_data( tbl, "freeze", GINT_TO_POINTER(TRUE) );
+
+ // Get old saved unit
+ int old_unit = GPOINTER_TO_INT( g_object_get_data(tbl, "lineheight_unit"));
+
+ // Get user selected unit and save as preference
+ UnitTracker *tracker = reinterpret_cast<UnitTracker*>(g_object_get_data(tbl, "tracker"));
+ Unit const *unit = tracker->getActiveUnit();
+ g_return_if_fail(unit != NULL);
+ Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+
+ // This nonsense is to get SP_CSS_UNIT_xx value corresponding to unit.
+ SPILength temp_length;
+ 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);
+ g_object_set_data( tbl, "lineheight_unit", GINT_TO_POINTER(temp_length.unit));
+
+ // Read current line height value
+ EgeAdjustmentAction *line_height_act =
+ reinterpret_cast<EgeAdjustmentAction *>(g_object_get_data(tbl, "TextLineHeightAction"));
+ GtkAdjustment *line_height_adj = ege_adjustment_action_get_adjustment( line_height_act );
+ double line_height = gtk_adjustment_get_value(line_height_adj);
+
+ SPDesktop *desktop = SP_ACTIVE_DESKTOP;
+ Inkscape::Selection *selection = desktop->getSelection();
+ std::vector<SPItem*> itemlist=selection->itemList();
+
+ // Convert between units
+ if ((unit->abbr) == "em" && old_unit == SP_CSS_UNIT_EX) {
+ line_height *= 0.5;
+ } else if ((unit->abbr) == "ex" && old_unit == SP_CSS_UNIT_EM) {
+ line_height *= 2.0;
+ } else if ((unit->abbr) == "em" && old_unit == SP_CSS_UNIT_PERCENT) {
+ line_height /= 100.0;
+ } else if ((unit->abbr) == "%" && old_unit == SP_CSS_UNIT_EM) {
+ line_height *= 100;
+ } else if ((unit->abbr) == "ex" && old_unit == SP_CSS_UNIT_PERCENT) {
+ line_height /= 50.0;
+ } else if ((unit->abbr) == "%" && old_unit == SP_CSS_UNIT_EX) {
+ line_height *= 50;
+ } else if ((unit->abbr) == "%" || (unit->abbr) == "em" || (unit->abbr) == "ex") {
+ // Convert absolute to relative... for the moment use average font-size
+ double font_size = 0;
+ int count = 0;
+ for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end(); ++i){
+ if (SP_IS_TEXT (*i)) {
+ font_size += (*i)->style->font_size.computed;
+ ++count;
+ }
+ }
+ if (count > 0) {
+ font_size /= count;
+ } else {
+ font_size = 20;
+ }
+ line_height = Quantity::convert(line_height, sp_style_get_css_unit_string(old_unit), "px");
+ if (font_size > 0) {
+ line_height /= font_size;
+ }
+ if ((unit->abbr) == "%") {
+ line_height *= 100;
+ } else if ((unit->abbr) == "ex") {
+ line_height *= 2;
+ }
+ } else if (old_unit==SP_CSS_UNIT_PERCENT || old_unit==SP_CSS_UNIT_EM || old_unit==SP_CSS_UNIT_EX) {
+ // Convert relative to absolute... for the moment use average font-size
+ double font_size = 0;
+ int count = 0;
+ for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end(); ++i){
+ if (SP_IS_TEXT (*i)) {
+ font_size += (*i)->style->font_size.computed;
+ ++count;
+ }
+ }
+ if (count > 0) {
+ font_size /= count;
+ } else {
+ font_size = 20;
+ }
+ line_height *= font_size;
+ if (old_unit == SP_CSS_UNIT_PERCENT) {
+ line_height /= 100.0;
+ } else if (old_unit == SP_CSS_UNIT_EX) {
+ line_height /= 2.0;
+ }
+ line_height = Quantity::convert(line_height, "px", unit);
+ } else {
+ // Convert between different absolute units (only used in GUI)
+ line_height = Quantity::convert(line_height, sp_style_get_css_unit_string(old_unit), unit);
+ }
+
+ // Set css line height.
+ SPCSSAttr *css = sp_repr_css_attr_new ();
+ Inkscape::CSSOStringStream osfs;
+ // We should handle unitless values as well as 'em' and 'ex'
+ if ((unit->abbr) == "em" || unit->abbr == "ex" || unit->abbr == "%") {
+ 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.
+ gtk_adjustment_set_value(line_height_adj, line_height);
+
+ // Apply line-height to selected objects.
+ sp_desktop_set_style (desktop, css, true, false);
+
+ // Only need to save for undo if a text item has been changed.
+ bool modmade = false;
+ for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end(); ++i){
+ if (SP_IS_TEXT (*i)) {
+ modmade = true;
+ }
+ }
+
+ // Save for undo
+ if(modmade) {
+ DocumentUndo::maybeDone(SP_ACTIVE_DESKTOP->getDocument(), "ttb:line-height", SP_VERB_NONE,
+ _("Text: Change line-height unit"));
+ }
+
+ // If no selected objects, set default.
+ SPStyle query(SP_ACTIVE_DOCUMENT);
+ int result_numbers =
+ sp_desktop_query_style (SP_ACTIVE_DESKTOP, &query, QUERY_STYLE_PROPERTY_FONTNUMBERS);
+ if (result_numbers == QUERY_STYLE_NOTHING)
+ {
+ Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+ prefs->mergeStyle("/tools/text/style", css);
+ }
+
+ sp_repr_css_attr_unref (css);
+
+ g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) );
+}
+
+
static void sp_text_wordspacing_value_changed( GtkAdjustment *adj, GObject *tbl )
{
// quit if run by the _changed callbacks
@@ -1064,6 +1240,7 @@ static void sp_text_toolbox_selection_changed(Inkscape::Selection */*selection*/
{
activeButton = 3;
} else {
+ // This should take 'direction' into account
if (query.text_anchor.computed == SP_CSS_TEXT_ANCHOR_START) activeButton = 0;
if (query.text_anchor.computed == SP_CSS_TEXT_ANCHOR_MIDDLE) activeButton = 1;
if (query.text_anchor.computed == SP_CSS_TEXT_ANCHOR_END) activeButton = 2;
@@ -1071,16 +1248,47 @@ static void sp_text_toolbox_selection_changed(Inkscape::Selection */*selection*/
ege_select_one_action_set_active( textAlignAction, activeButton );
- // Line height (spacing)
+ // Line height (spacing) and line height unit
double height;
+ int line_height_unit = -1;
if (query.line_height.normal) {
+ std::cout << " normal" << std::endl;
height = Inkscape::Text::Layout::LINE_HEIGHT_NORMAL;
+ line_height_unit = SP_CSS_UNIT_NONE;
} else {
- if (query.line_height.unit == SP_CSS_UNIT_PERCENT) {
- height = query.line_height.value;
- } else {
- height = query.line_height.computed;
- }
+ height = query.line_height.value;
+ line_height_unit = query.line_height.unit;
+ }
+
+ switch (line_height_unit) {
+ case SP_CSS_UNIT_NONE:
+ // tracker can't show no unit... use 'em'
+ line_height_unit = SP_CSS_UNIT_EM;
+ case SP_CSS_UNIT_EM:
+ case SP_CSS_UNIT_EX:
+ break;
+ case SP_CSS_UNIT_PERCENT:
+ height *= 100.0; // Inkscape store % as fraction in .value
+ break;
+ case SP_CSS_UNIT_PX:
+ // If unit is set to 'px', use the preferred display unit (if absolute).
+ line_height_unit =
+ prefs->getInt("/tools/text/lineheight/display_unit", SP_CSS_UNIT_PT);
+ if (line_height_unit != SP_CSS_UNIT_EM &&
+ line_height_unit != SP_CSS_UNIT_EX &&
+ line_height_unit != SP_CSS_UNIT_PERCENT) {
+ height =
+ Quantity::convert(height, "px", sp_style_get_css_unit_string(line_height_unit));
+ } else {
+ line_height_unit = SP_CSS_UNIT_PX;
+ }
+ break;
+ default:
+ // If unit has been set by an external program to something other than 'px', use
+ // that unit. But height is average of computed values (px) so we need to convert
+ // back.
+ height =
+ Quantity::convert(height, "px", sp_style_get_css_unit_string(line_height_unit));
}
GtkAction* lineHeightAction = GTK_ACTION( g_object_get_data( tbl, "TextLineHeightAction" ) );
@@ -1088,7 +1296,11 @@ static void sp_text_toolbox_selection_changed(Inkscape::Selection */*selection*/
ege_adjustment_action_get_adjustment(EGE_ADJUSTMENT_ACTION( lineHeightAction ));
gtk_adjustment_set_value( lineHeightAdjustment, height );
-
+ UnitTracker* tracker = reinterpret_cast<UnitTracker*>( g_object_get_data( tbl, "tracker" ) );
+ tracker->setActiveUnitByAbbr(sp_style_get_css_unit_string(line_height_unit));
+ // Save unit so we can do convertions between new/old units.
+ g_object_set_data( tbl, "lineheight_unit", GINT_TO_POINTER(line_height_unit));
+
// Word spacing
double wordSpacing;
if (query.word_spacing.normal) wordSpacing = 0.0;
@@ -1231,7 +1443,6 @@ static void sp_text_toolbox_selection_changed(Inkscape::Selection */*selection*/
#endif
g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) );
-
}
static void sp_text_toolbox_selection_modified(Inkscape::Selection *selection, guint /*flags*/, GObject *tbl)
@@ -1582,6 +1793,15 @@ void sp_text_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje
g_signal_connect_after( G_OBJECT(act), "changed", G_CALLBACK(sp_text_orientation_changed), holder );
}
+ /* Line height unit tracker */
+ UnitTracker* tracker = new UnitTracker(Inkscape::Util::UNIT_TYPE_LINEAR);
+ tracker->addUnit(unit_table.getUnit("%"));
+ tracker->addUnit(unit_table.getUnit("em"));
+ tracker->addUnit(unit_table.getUnit("ex"));
+ // tracker->addUnit(unit_table.getUnit("None"));
+ tracker->setActiveUnit(unit_table.getUnit("%"));
+ g_object_set_data( holder, "tracker", tracker );
+
/* Line height */
{
// Drop down menu
@@ -1599,20 +1819,28 @@ void sp_text_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje
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, 1000.0, 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 */
+ NULL, // tracker, /* unit tracker */
0.1, /* step (used?) */
2, /* digits to show */
1.0 /* factor (multiplies default) */
);
+ //tracker->addAdjustment( ege_adjustment_action_get_adjustment(eact) );
gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
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 );
}
+ /* Line height units */
+ {
+ GtkAction* act = tracker->createAction( "TextLineHeightUnitsAction", _("Units"), ("") );
+ gtk_action_group_add_action( mainActions, act );
+ g_signal_connect_after( G_OBJECT(act), "changed", G_CALLBACK(sp_text_lineheight_unit_changed), holder );
+ }
+
/* Word spacing */
{
// Drop down menu
diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp
index 72537f727..705c16d1f 100644
--- a/src/widgets/toolbox.cpp
+++ b/src/widgets/toolbox.cpp
@@ -515,6 +515,7 @@ static gchar const * ui_descr =
" <toolitem action='TextSubscriptAction' />"
" <separator />"
" <toolitem action='TextLineHeightAction' />"
+ " <toolitem action='TextLineHeightUnitsAction' />"
" <toolitem action='TextLetterSpacingAction' />"
" <toolitem action='TextWordSpacingAction' />"
" <toolitem action='TextDxAction' />"