diff --git a/po/generate_POTFILES.sh b/po/generate_POTFILES.sh
index bbdeff0a4a68c5c7f5b4e60dd9c225b631740733..f883b9b44d74879644c9748d564efe879b544c76 100755
--- a/po/generate_POTFILES.sh
+++ b/po/generate_POTFILES.sh
@@ -39,6 +39,7 @@ rm -f POTFILES.in.new
# - add any other UI files we might need in future
# - evaluate to use xgettext with proper options directly and drop intltool-update
echo "[type: gettext/xml] share/ui/menus.xml"
+ echo "[type: gettext/xml] share/ui/units.xml"
#do not include files from POTFILES.skip in the generated list
) | grep -vx -f POTFILES.skip > POTFILES.in.new
diff --git a/share/ui/units.xml b/share/ui/units.xml
index 713a538d7f39fda980bf9b969667194d4e631c31..861f6cb51b2cc6c998238e82518f9fec5eeaa56b 100644
--- a/share/ui/units.xml
+++ b/share/ui/units.xml
@@ -1,101 +1,143 @@
-
-
- %
- %
- %
- 1.00
- Percentage
-
-
- pixel
- pixels
- px
- 1.00
- CSS Pixels (96/inch)
-
-
- point
- points
- pt
- 1.333333333333333
- PostScript points (72/inch)
-
-
- pica
- picas
- pc
- 16.0
- 12 points
-
-
- inch
- inches
- in
- 96.0
- Inches (96 px/in)
-
-
- millimeter
- millimeters
- mm
- 3.779527559055119
- Millimeters (25.4 mm/in)
-
-
- centimeter
- centimeters
- cm
- 37.79527559055119
- Centimeters (10 mm/cm)
-
-
- degree
- degrees
- °
- 1.00
- Degrees
-
-
- radian
- radians
- rad
- 57.29577951308232
- Radians (180/pi deg/rad)
-
-
- gradian
- gradians
- grad
- 0.9
- Gradians (360/400 deg/grad)
-
-
- turn
- turns
- turn
- 360
- Turns (360 deg/turn)
-
-
- font-height
- font-heights
- em
- 1.00
- Font height
-
-
- x-height
- x-heights
- ex
- 0.50
- Height of letter 'x'
-
-
- half-em
- half-ems
- en
- 0.50
- Half of font height
-
+
+
+
+ Unit
+ Unnamed dimensionless unit
+ unit
+ <_name_plural msgctxt="unit-text-plural" >units
+ <_abbr msgctxt="unit-abbr" >unit
+ <_format msgctxt="unit-format" >%1
+
+
+ Percent
+ Percentage of a number
+ percent
+ <_name_plural msgctxt="unit-text-plural" >percent
+ <_abbr msgctxt="unit-abbr" >%
+ <_format msgctxt="unit-format" >%1%%
+ 1.00
+
+
+
+ Pixel
+ CSS pixels (96/inch)
+ pixel
+ <_name_plural msgctxt="unit-text-plural" >pixels
+ <_abbr msgctxt="unit-abbr" >px
+ <_format msgctxt="unit-format" >%1 px
+ 1.00
+
+
+ Point
+ PostScript points (72/inch)
+ point
+ <_name_plural msgctxt="unit-text-plural" >points
+ <_abbr msgctxt="unit-abbr" >pt
+ <_format msgctxt="unit-format" >%1 pt
+ 1.333333333333333
+
+
+ Pica
+ Picas (6/inch)
+ pica
+ <_name_plural msgctxt="unit-text-plural" >picas
+ <_abbr msgctxt="unit-abbr" >pc
+ <_format msgctxt="unit-format" >%1 pc
+ 16.0
+
+
+ Inch
+ Inches (96 px/in)
+ inch
+ <_name_plural msgctxt="unit-text-plural" >inches
+ <_abbr msgctxt="unit-abbr" >in
+ <_format msgctxt="unit-format" >%1″
+ 96.0
+
+
+ Millimeter
+ Millimeters (25.4 mm/in)
+ millimeter
+ <_name_plural msgctxt="unit-text-plural" >millimeters
+ <_abbr msgctxt="unit-abbr" >mm
+ <_format msgctxt="unit-format" >%1 mm
+ 3.779527559055119
+
+
+ Centimeter
+ Centimeters (10 mm/cm)
+ centimeter
+ <_name_plural msgctxt="unit-text-plural" >centimeters
+ <_abbr msgctxt="unit-abbr" >cm
+ <_format msgctxt="unit-format" >%1 cm
+ 37.79527559055119
+
+
+
+ Degree
+ Degrees (1° = (π/180) rad)
+ degree
+ <_name_plural msgctxt="unit-text-plural" >degrees
+ <_abbr msgctxt="unit-abbr" >deg
+ <_format msgctxt="unit-format" >%1°
+ 1.00
+
+
+ Radian
+ Radians (pi/180 rad/deg)
+ radian
+ <_name_plural msgctxt="unit-text-plural" >radians
+ <_abbr msgctxt="unit-abbr" >rad
+ <_format msgctxt="unit-format" >%1 rad
+ 57.29577951308232
+
+
+ Gradian
+ Gradians (400/360 grad/deg)
+ gradian
+ <_name_plural msgctxt="unit-text-plural" >gradians
+ <_abbr msgctxt="unit-abbr" >grad
+ <_format msgctxt="unit-format" >%1 grad
+ 0.9
+
+
+ Turn
+ Turns (1/360 turn/deg)
+ turn
+ <_name_plural msgctxt="unit-text-plural" >turns
+ <_abbr msgctxt="unit-abbr" >turn
+ <_format msgctxt="unit-format" >%1 turn
+ 360
+
+
+
+ Font-Height
+ Point size of the current font
+ em
+ <_name_plural msgctxt="unit-text-plural" >ems
+ <_abbr msgctxt="unit-abbr" >em
+ <_format msgctxt="unit-format" >%1 em
+ 1.00
+
+
+
+ X-Height
+ Height of the letter 'x' in the current font
+ ex
+ <_name_plural msgctxt="unit-text-plural" >exes
+ <_abbr msgctxt="unit-abbr" >ex
+ <_format msgctxt="unit-format" >%1 ex
+ 0.50
+
+
+
+ Half Font-Height
+ Half the current font-height
+ en
+ <_name_plural msgctxt="unit-text-plural" >ens
+ <_abbr msgctxt="unit-abbr" >en
+ <_format msgctxt="unit-format" >%1 en
+ 0.50
+
diff --git a/src/live_effects/parameter/unit.cpp b/src/live_effects/parameter/unit.cpp
index 109d7fcedf93836929f29d4597a4e0887972124e..a43e1bbe06dabbabaabb8254f162a86e171c0097 100644
--- a/src/live_effects/parameter/unit.cpp
+++ b/src/live_effects/parameter/unit.cpp
@@ -73,6 +73,7 @@ UnitParam::param_set_value(Inkscape::Util::Unit const &val)
unit = new Inkscape::Util::Unit(val);
}
+// TODO: Should this be localized?
const gchar *
UnitParam::get_abbreviation() const
{
diff --git a/src/svg/svg-angle.cpp b/src/svg/svg-angle.cpp
index e82d0de457a9e1930790da29ce73f6b91420ea62..1ca952a029cdcde1de7505774f2c326621b51292 100644
--- a/src/svg/svg-angle.cpp
+++ b/src/svg/svg-angle.cpp
@@ -103,15 +103,15 @@ static bool sp_svg_angle_read_lff(gchar const *str, SVGAngle::Unit &unit, float
} else if (strncmp(e, "grad", 4) == 0) {
unit = SVGAngle::GRAD;
val = v;
- computed = Inkscape::Util::Quantity::convert(v, "grad", "°");
+ computed = Inkscape::Util::Quantity::convert(v, "grad", Inkscape::Util::DEG);
} else if (strncmp(e, "rad", 3) == 0) {
unit = SVGAngle::RAD;
val = v;
- computed = Inkscape::Util::Quantity::convert(v, "rad", "°");
+ computed = Inkscape::Util::Quantity::convert(v, "rad", Inkscape::Util::DEG);
} else if (strncmp(e, "turn", 4) == 0) {
unit = SVGAngle::TURN;
val = v;
- computed = Inkscape::Util::Quantity::convert(v, "turn", "°");
+ computed = Inkscape::Util::Quantity::convert(v, "turn", Inkscape::Util::DEG);
} else {
return false;
}
diff --git a/src/ui/dialog/inkscape-preferences.cpp b/src/ui/dialog/inkscape-preferences.cpp
index 1f094abbfd93d690b785f06da1561f053d7ce24c..bd9390abd46ba21f9c99a66e9fed4fdbcd161c8b 100644
--- a/src/ui/dialog/inkscape-preferences.cpp
+++ b/src/ui/dialog/inkscape-preferences.cpp
@@ -252,7 +252,7 @@ void InkscapePreferences::AddPencilPowerStrokePressureStep(DialogPage &p, Glib::
{
PrefSpinButton* sb = Gtk::manage( new PrefSpinButton);
sb->init ( prefs_path + "/ps-step-pressure", 1, 100, 1, 10, def_value, true, false);
- p.add_line( false, _("Pressure change for new knot:"), *sb, _("%"),
+ p.add_line( false, _("Pressure change for new knot:"), *sb, C_("unit-abbr", "%"),
_("Percentage increase / decrease of stylus pressure that is required to create a new PowerStroke knot."),
false );
}
@@ -417,7 +417,7 @@ void InkscapePreferences::initPageTools()
_t_node_pathflash_selected.init ( _("Show temporary outline for selected paths"), "/tools/nodes/pathflash_selected", false);
_page_node.add_line( true, "", _t_node_pathflash_selected, "", _("Show temporary outline even when a path is selected for editing"));
_t_node_pathflash_timeout.init("/tools/nodes/pathflash_timeout", 0, 10000.0, 100.0, 100.0, 1000.0, true, false);
- _page_node.add_line( false, _("_Flash time:"), _t_node_pathflash_timeout, "ms", _("Specifies how long the path outline will be visible after a mouse-over (in milliseconds); specify 0 to have the outline shown until mouse leaves the path"), false);
+ _page_node.add_line( false, _("_Flash time:"), _t_node_pathflash_timeout, C_("unit-abbr", "ms"), _("Specifies how long the path outline will be visible after a mouse-over (in milliseconds); specify 0 to have the outline shown until mouse leaves the path"), false);
_page_node.add_group_header(_("Editing preferences"));
_t_node_single_node_transform_handles.init(_("Show transform handles for single nodes"), "/tools/nodes/single_node_transform_handles", false);
_page_node.add_line( true, "", _t_node_single_node_transform_handles, "", _("Show transform handles even when only a single node is selected"));
@@ -562,7 +562,7 @@ void InkscapePreferences::initPageTools()
_("When on, the Gradient Edit button in the Fill & Stroke dialog will show the legacy Gradient Editor dialog, when off the Gradient Tool will be used"), true);
_misc_gradientangle.init("/dialogs/gradienteditor/angle", -359, 359, 1, 90, 0, false, false);
- _page_gradient.add_line( false, _("Linear gradient _angle:"), _misc_gradientangle, "",
+ _page_gradient.add_line( false, _("Linear gradient _angle:"), _misc_gradientangle, _("degrees"),
_("Default angle of new linear gradients in degrees (clockwise from horizontal)"), false);
@@ -1132,7 +1132,7 @@ void InkscapePreferences::initPageUI()
_win_trans_blur.init("/dialogs/transparency/on-blur", 0.0, 1.0, 0.01, 0.1, 0.5, false, false);
_page_windows.add_line( true, _("Opacity when _unfocused:"), _win_trans_blur, "", "", false);
_win_trans_time.init("/dialogs/transparency/animate-time", 0, 1000, 10, 100, 100, true, false);
- _page_windows.add_line( true, _("_Time of opacity change animation:"), _win_trans_time, "ms", "", false);
+ _page_windows.add_line( true, _("_Time of opacity change animation:"), _win_trans_time, C_("unit-abbr", "ms"), "", false);
_page_windows.add_group_header( _("Miscellaneous"));
@@ -1272,10 +1272,10 @@ void InkscapePreferences::initPageIO()
// Input devices options
_mouse_sens.init ( "/options/cursortolerance/value", 0.0, 30.0, 1.0, 1.0, 8.0, true, false);
- _page_mouse.add_line( false, _("_Grab sensitivity:"), _mouse_sens, _("pixels (requires restart)"),
+ _page_mouse.add_line( false, _("_Grab sensitivity:"), _mouse_sens, _("pixels (requires restart)"), // "pixels (requires restart)" should be seperated into two strings
_("How close on the screen you need to be to an object to be able to grab it with mouse (in screen pixels)"), false);
_mouse_thres.init ( "/options/dragtolerance/value", 0.0, 20.0, 1.0, 1.0, 4.0, true, false);
- _page_mouse.add_line( false, _("_Click/drag threshold:"), _mouse_thres, _("pixels"),
+ _page_mouse.add_line( false, _("_Click/drag threshold:"), _mouse_thres, C_("unit-abbr", "px"),
_("Maximum mouse drag (in screen pixels) which is considered a click, not a drag"), false);
_mouse_grabsize.init("/options/grabsize/value", 1, 7, 1, 2, 3, 0);
@@ -1531,7 +1531,7 @@ void InkscapePreferences::initPageIO()
}
_page_autosave.add_line(false, C_("Filesystem", "Autosave _directory:"), _save_autosave_path, "", _("The directory where autosaves will be written. This should be an absolute path (starts with / on UNIX or a drive letter such as C: on Windows). "), false);
_save_autosave_interval.init("/options/autosave/interval", 1.0, 10800.0, 1.0, 10.0, 10.0, true, false);
- _page_autosave.add_line(false, _("_Interval (in minutes):"), _save_autosave_interval, "", _("Interval (in minutes) at which document will be autosaved"), false);
+ _page_autosave.add_line(false, _("_Interval:"), _save_autosave_interval, _("minutes"), _("Interval (in minutes) at which document will be autosaved"), false);
_save_autosave_max.init("/options/autosave/max", 1.0, 100.0, 1.0, 10.0, 10.0, true, false);
_page_autosave.add_line(false, _("_Maximum number of autosaves:"), _save_autosave_max, "", _("Maximum number of autosaved files; use this to limit the storage space used"), false);
@@ -1638,11 +1638,11 @@ void InkscapePreferences::initPageBehavior()
// Scrolling options
_scroll_wheel.init ( "/options/wheelscroll/value", 0.0, 1000.0, 1.0, 1.0, 40.0, true, false);
- _page_scrolling.add_line( false, _("Mouse _wheel scrolls by:"), _scroll_wheel, _("pixels"),
+ _page_scrolling.add_line( false, _("Mouse _wheel scrolls by:"), _scroll_wheel, C_("unit-abbr", "px"),
_("One mouse wheel notch scrolls by this distance in screen pixels (horizontally with Shift)"), false);
_page_scrolling.add_group_header( _("Ctrl+arrows"));
_scroll_arrow_px.init ( "/options/keyscroll/value", 0.0, 1000.0, 1.0, 1.0, 10.0, true, false);
- _page_scrolling.add_line( true, _("Sc_roll by:"), _scroll_arrow_px, _("pixels"),
+ _page_scrolling.add_line( true, _("Sc_roll by:"), _scroll_arrow_px, C_("unit-abbr", "px"),
_("Pressing Ctrl+arrow key scrolls by this distance (in screen pixels)"), false);
_scroll_arrow_acc.init ( "/options/scrollingacceleration/value", 0.0, 5.0, 0.01, 1.0, 0.35, false, false);
_page_scrolling.add_line( true, _("_Acceleration:"), _scroll_arrow_acc, "",
@@ -1652,7 +1652,7 @@ void InkscapePreferences::initPageBehavior()
_page_scrolling.add_line( true, _("_Speed:"), _scroll_auto_speed, "",
_("How fast the canvas autoscrolls when you drag beyond canvas edge (0 to turn autoscroll off)"), false);
_scroll_auto_thres.init ( "/options/autoscrolldistance/value", -600.0, 600.0, 1.0, 1.0, -10.0, true, false);
- _page_scrolling.add_line( true, _("_Threshold:"), _scroll_auto_thres, _("pixels"),
+ _page_scrolling.add_line( true, _("_Threshold:"), _scroll_auto_thres, C_("unit-abbr", "px"),
_("How far (in screen pixels) you need to be from the canvas edge to trigger autoscroll; positive is outside the canvas, negative is within the canvas"), false);
_scroll_space.init ( _("Mouse move pans when Space is pressed"), "/options/spacebarpans/value", true);
_page_scrolling.add_line( true, "", _scroll_space, "",
@@ -1678,7 +1678,7 @@ void InkscapePreferences::initPageBehavior()
_snap_indicator.changed_signal.connect( sigc::mem_fun(_snap_persistence, &Gtk::Widget::set_sensitive) );
_snap_persistence.init("/options/snapindicatorpersistence/value", 0.1, 10, 0.1, 1, 2, 1);
- _page_snapping.add_line( true, _("Snap indicator persistence (in seconds):"), _snap_persistence, "",
+ _page_snapping.add_line( true, _("Snap indicator persistence (seconds):"), _snap_persistence, "",
_("Controls how long the snap indicator message will be shown, before it disappears"), true);
_page_snapping.add_group_header( _("What should snap"));
@@ -1698,7 +1698,7 @@ void InkscapePreferences::initPageBehavior()
_page_snapping.add_group_header( _("Delayed snap"));
_snap_delay.init("/options/snapdelay/value", 0, 1, 0.1, 0.2, 0.3, 1);
- _page_snapping.add_line( true, _("Delay (in seconds):"), _snap_delay, "",
+ _page_snapping.add_line( true, _("Delay (seconds):"), _snap_delay, "",
_("Postpone snapping as long as the mouse is moving, and then wait an additional fraction of a second. This additional delay is specified here. When set to zero or to a very small number, snapping will be immediate."), true);
this->AddPage(_page_snapping, _("Snapping"), iter_behavior, PREFS_PAGE_BEHAVIOR_SNAPPING);
@@ -1729,7 +1729,7 @@ void InkscapePreferences::initPageBehavior()
_page_steps.add_line( false, "", _steps_rot_relative, "",
_("When on, the snap angles when rotating a guideline will be relative to the original angle"));
_steps_zoom.init ( "/options/zoomincrement/value", 101.0, 500.0, 1.0, 1.0, M_SQRT2, true, true);
- _page_steps.add_line( false, _("_Zoom in/out by:"), _steps_zoom, _("%"),
+ _page_steps.add_line( false, _("_Zoom in/out by:"), _steps_zoom, C_("unit-abbr", "%"),
_("Zoom tool click, +/- keys, and middle click zoom in and out by this multiplier"), false);
_steps_rotate.init ( "/options/rotateincrement/value", 1, 90, 1.0, 5.0, 15, false, false);
_page_steps.add_line( false, _("_Rotate canvas by:"), _steps_rotate, _("degrees"),
diff --git a/src/ui/dialog/polar-arrange-tab.cpp b/src/ui/dialog/polar-arrange-tab.cpp
index de026b8d59a5bbb9b6c545ed461929b891576e38..cfcfd57d13c3609373b2803109622ffa484f3750 100644
--- a/src/ui/dialog/polar-arrange-tab.cpp
+++ b/src/ui/dialog/polar-arrange-tab.cpp
@@ -107,11 +107,11 @@ PolarArrangeTab::PolarArrangeTab(ArrangeDialog *parent_)
angleX.setDigits(2);
angleX.setIncrements(0.2, 0);
angleX.setRange(-10000, 10000);
- angleX.setValue(0, "°");
+ angleX.setValue(0, Inkscape::Util::DEG);
angleY.setDigits(2);
angleY.setIncrements(0.2, 0);
angleY.setRange(-10000, 10000);
- angleY.setValue(180, "°");
+ angleY.setValue(180, Inkscape::Util::DEG);
parametersTable.attach(angleX, 1, 2, 1, 1);
parametersTable.attach(angleY, 2, 2, 1, 1);
pack_start(parametersTable, false, false);
diff --git a/src/ui/tools/lpe-tool.cpp b/src/ui/tools/lpe-tool.cpp
index 55ec014abdb7fe4a18ba73183482b1c1a09660fa..51423873fafb6c1233ba4cb9317495dad9355e22 100644
--- a/src/ui/tools/lpe-tool.cpp
+++ b/src/ui/tools/lpe-tool.cpp
@@ -392,8 +392,6 @@ lpetool_create_measuring_items(LpeTool *lc, Inkscape::Selection *selection)
SPCurve *curve;
SPCanvasText *canvas_text;
SPCanvasGroup *tmpgrp = lc->desktop->getTempGroup();
- gchar *arc_length;
- double lengthval;
auto items= selection->items();
for(auto i=items.begin();i!=items.end();++i){
if (SP_IS_PATH(*i)) {
@@ -411,10 +409,8 @@ lpetool_create_measuring_items(LpeTool *lc, Inkscape::Selection *selection)
unit = unit_table.getUnit("px");
}
- lengthval = Geom::length(pwd2);
- lengthval = Inkscape::Util::Quantity::convert(lengthval, "px", unit);
- arc_length = g_strdup_printf("%.2f %s", lengthval, unit->abbr.c_str());
- sp_canvastext_set_text (canvas_text, arc_length);
+ auto q = Inkscape::Util::Quantity(Geom::length(pwd2), "px");
+ sp_canvastext_set_text(canvas_text, q.string(unit).c_str());
set_pos_and_anchor(canvas_text, pwd2, 0.5, 10);
// TODO: must we free arc_length?
(*lc->measuring_items)[path] = SP_CANVAS_ITEM(canvas_text);
@@ -449,10 +445,8 @@ lpetool_update_measuring_items(LpeTool *lc)
} else {
unit = unit_table.getUnit("px");
}
- double lengthval = Geom::length(pwd2);
- lengthval = Inkscape::Util::Quantity::convert(lengthval, "px", unit);
- gchar *arc_length = g_strdup_printf("%.2f %s", lengthval, unit->abbr.c_str());
- sp_canvastext_set_text (SP_CANVASTEXT(i->second), arc_length);
+ auto q = Inkscape::Util::Quantity(Geom::length(pwd2), "px");
+ sp_canvastext_set_text(SP_CANVASTEXT(i->second), q.string(unit).c_str());
set_pos_and_anchor(SP_CANVASTEXT(i->second), pwd2, 0.5, 10);
// TODO: must we free arc_length?
}
diff --git a/src/ui/tools/measure-tool.cpp b/src/ui/tools/measure-tool.cpp
index f8c8517c99d67308c995f0faaaca7a36ea0ce244..54c56e28c1e6fa885ac53e6fa0eab3ba25ad50ef 100644
--- a/src/ui/tools/measure-tool.cpp
+++ b/src/ui/tools/measure-tool.cpp
@@ -1035,28 +1035,21 @@ void MeasureTool::reset()
measure_tmp_items.clear();
}
-void MeasureTool::setMeasureCanvasText(bool is_angle, double precision, double amount, double fontsize, Glib::ustring unit_name, Geom::Point position, guint32 background, CanvasTextAnchorPositionEnum text_anchor, bool to_item, bool to_phantom, Inkscape::XML::Node *measure_repr)
+void MeasureTool::setMeasureCanvasText(double precision, double amount, double fontsize, Glib::ustring unit_name, Geom::Point position, guint32 background, CanvasTextAnchorPositionEnum text_anchor, bool to_item, bool to_phantom, Inkscape::XML::Node *measure_repr)
{
SPDesktop *desktop = SP_ACTIVE_DESKTOP;
- std::stringstream precision_str;
- precision_str.imbue(std::locale::classic());
- if(is_angle){
- precision_str << "%." << precision << "f °";
- } else {
- precision_str << "%." << precision << "f %s";
- }
- gchar *measure_str = g_strdup_printf(precision_str.str().c_str(), amount, unit_name.c_str());
+ auto measure_str = Inkscape::Util::Quantity(amount, unit_name).string(precision);
SPCanvasText *canvas_tooltip = sp_canvastext_new(desktop->getTempGroup(),
desktop,
position,
- measure_str);
+ measure_str.c_str());
sp_canvastext_set_fontsize(canvas_tooltip, fontsize);
canvas_tooltip->rgba = 0xffffffff;
canvas_tooltip->rgba_background = background;
canvas_tooltip->outline = false;
canvas_tooltip->background = true;
canvas_tooltip->anchor_position = text_anchor;
- if(to_phantom){
+ if (to_phantom) {
canvas_tooltip->rgba_background = 0x4444447f;
measure_phantom_items.push_back(SP_CANVAS_ITEM(canvas_tooltip));
sp_canvas_item_show(SP_CANVAS_ITEM(canvas_tooltip));
@@ -1065,10 +1058,9 @@ void MeasureTool::setMeasureCanvasText(bool is_angle, double precision, double a
sp_canvas_item_show(SP_CANVAS_ITEM(canvas_tooltip));
}
- if(to_item) {
- setLabelText(measure_str, position, fontsize, 0, background, measure_repr);
+ if (to_item) {
+ setLabelText(measure_str.c_str(), position, fontsize, 0, background, measure_repr);
}
- g_free(measure_str);
}
void MeasureTool::setMeasureCanvasItem(Geom::Point position, bool to_item, bool to_phantom, Inkscape::XML::Node *measure_repr){
@@ -1364,27 +1356,29 @@ void MeasureTool::showCanvasItems(bool to_guides, bool to_item, bool to_phantom,
// Adjust positions
repositionOverlappingLabels(placements, desktop, windowNormal, fontsize, precision);
for (auto & place : placements) {
- setMeasureCanvasText(false, precision, place.lengthVal * scale, fontsize, unit_name, place.end, 0x0000007f, TEXT_ANCHOR_CENTER, to_item, to_phantom, measure_repr);
+ setMeasureCanvasText(precision, place.lengthVal * scale, fontsize, unit_name.c_str(),
+ place.end, 0x0000007f, TEXT_ANCHOR_CENTER, to_item, to_phantom, measure_repr);
}
Geom::Point angleDisplayPt = calcAngleDisplayAnchor(desktop, angle, baseAngle,
start_p, end_p,
fontsize);
{
- setMeasureCanvasText(true, precision, Geom::deg_from_rad(angle), fontsize, unit_name, angleDisplayPt, 0x337f337f, TEXT_ANCHOR_CENTER, to_item, to_phantom, measure_repr);
+ setMeasureCanvasText(precision, Geom::deg_from_rad(angle), fontsize, "deg", angleDisplayPt, 0x337f337f, TEXT_ANCHOR_CENTER, to_item, to_phantom, measure_repr);
}
{
double totallengthval = (end_p - start_p).length();
totallengthval = Inkscape::Util::Quantity::convert(totallengthval, "px", unit_name);
Geom::Point origin = end_p + desktop->w2d(Geom::Point(3*fontsize, -fontsize));
- setMeasureCanvasText(false, precision, totallengthval * scale, fontsize, unit_name, origin, 0x3333337f, TEXT_ANCHOR_LEFT, to_item, to_phantom, measure_repr);
+ setMeasureCanvasText(precision, totallengthval * scale, fontsize, unit_name.c_str(),
+ origin, 0x3333337f, TEXT_ANCHOR_LEFT, to_item, to_phantom, measure_repr);
}
if (intersections.size() > 2) {
double totallengthval = (intersections[intersections.size()-1] - intersections[0]).length();
totallengthval = Inkscape::Util::Quantity::convert(totallengthval, "px", unit_name);
Geom::Point origin = desktop->doc2dt((intersections[0] + intersections[intersections.size()-1])/2) + normal * dimension_offset;
- setMeasureCanvasText(false, precision, totallengthval * scale, fontsize, unit_name, origin, 0x33337f7f, TEXT_ANCHOR_CENTER, to_item, to_phantom, measure_repr);
+ setMeasureCanvasText(precision, totallengthval * scale, fontsize, unit_name, origin, 0x33337f7f, TEXT_ANCHOR_CENTER, to_item, to_phantom, measure_repr);
}
// Initial point
diff --git a/src/ui/tools/measure-tool.h b/src/ui/tools/measure-tool.h
index a6ca39ec7a1a9554661823cb896914430cc7ac33..a55322df48db9bc394a77a82827becddd31e24a6 100644
--- a/src/ui/tools/measure-tool.h
+++ b/src/ui/tools/measure-tool.h
@@ -57,7 +57,7 @@ public:
void setGuide(Geom::Point origin, double angle, const char *label);
void setPoint(Geom::Point origin, Inkscape::XML::Node *measure_repr);
void setLine(Geom::Point start_point,Geom::Point end_point, bool markers, guint32 color, Inkscape::XML::Node *measure_repr = nullptr);
- void setMeasureCanvasText(bool is_angle, double precision, double amount, double fontsize, Glib::ustring unit_name, Geom::Point position, guint32 background, CanvasTextAnchorPositionEnum text_anchor, bool to_item, bool to_phantom, Inkscape::XML::Node *measure_repr);
+ void setMeasureCanvasText(double precision, double amount, double fontsize, Glib::ustring unit_name, Geom::Point position, guint32 background, CanvasTextAnchorPositionEnum text_anchor, bool to_item, bool to_phantom, Inkscape::XML::Node *measure_repr);
void setMeasureCanvasItem(Geom::Point position, bool to_item, bool to_phantom, Inkscape::XML::Node *measure_repr);
void setMeasureCanvasControlLine(Geom::Point start, Geom::Point end, bool to_item, bool to_phantom, Inkscape::CtrlLineType ctrl_line_type, Inkscape::XML::Node *measure_repr);
void setLabelText(const char *value, Geom::Point pos, double fontsize, Geom::Coord angle, guint32 background , Inkscape::XML::Node *measure_repr = nullptr, CanvasTextAnchorPositionEnum text_anchor = TEXT_ANCHOR_CENTER );
diff --git a/src/ui/widget/page-sizer.cpp b/src/ui/widget/page-sizer.cpp
index 030e90af0782df77f342a2e4d6702b2fdcd09e3d..21d6c1f32279dcad608bde6dc8a6b4d1aa5866f3 100644
--- a/src/ui/widget/page-sizer.cpp
+++ b/src/ui/widget/page-sizer.cpp
@@ -624,6 +624,7 @@ PageSizer::updateScaleUI()
Geom::Scale scale = doc->getDocumentScale();
SPNamedView *nv = dt->getNamedView();
+ // TODO: Localize this.
std::stringstream ss;
ss << _("User units per ") << nv->display_units->abbr << "." ;
_scaleLabel.set_text( ss.str() );
diff --git a/src/ui/widget/scalar-unit.cpp b/src/ui/widget/scalar-unit.cpp
index d9acd375bde702cd213d286d1bfd6b182caa76be..a20f2e2979c287f96657fd18e696a3f03a214ca8 100644
--- a/src/ui/widget/scalar-unit.cpp
+++ b/src/ui/widget/scalar-unit.cpp
@@ -223,7 +223,7 @@ void ScalarUnit::on_unit_changed()
g_assert(_unit_menu != nullptr);
Glib::ustring abbr = _unit_menu->getUnitAbbr();
- _suffix->set_label(abbr);
+ _suffix->set_label(g_dpgettext2(nullptr, "unit-abbr", abbr.c_str()));
Inkscape::Util::Unit const *new_unit = unit_table.getUnit(abbr);
Inkscape::Util::Unit const *old_unit = unit_table.getUnit(lastUnits);
diff --git a/src/ui/widget/selected-style.cpp b/src/ui/widget/selected-style.cpp
index 149b70f6fc7c05ffdef78a19802ffe4dbe37d210..327fae4410c43d728c36794d394ff18ac8b63f7d 100644
--- a/src/ui/widget/selected-style.cpp
+++ b/src/ui/widget/selected-style.cpp
@@ -331,16 +331,14 @@ SelectedStyle::SelectedStyle(bool /*layout*/)
int row = 0;
Inkscape::Util::UnitTable::UnitMap m = unit_table.units(Inkscape::Util::UNIT_TYPE_LINEAR);
- Inkscape::Util::UnitTable::UnitMap::iterator iter = m.begin();
- while(iter != m.end()) {
+ for (auto & iter : m) {
+ Inkscape::Util::Unit const *u = unit_table.getUnit(iter.first);
Gtk::RadioMenuItem *mi = Gtk::manage(new Gtk::RadioMenuItem(_sw_group));
- mi->add(*(new Gtk::Label(iter->first, Gtk::ALIGN_START)));
+ mi->add(*(new Gtk::Label(g_dpgettext2(nullptr, "unit-abbr", u->abbr.c_str()), Gtk::ALIGN_START)));
_unit_mis.push_back(mi);
- Inkscape::Util::Unit const *u = unit_table.getUnit(iter->first);
mi->signal_activate().connect(sigc::bind(sigc::mem_fun(*this, &SelectedStyle::on_popup_units), u));
_popup_sw.attach(*mi, 0,1, row, row+1);
row++;
- ++iter;
}
_popup_sw.attach(*(new Gtk::SeparatorMenuItem()), 0,1, row, row+1);
@@ -489,6 +487,7 @@ SelectedStyle::setDesktop(SPDesktop *desktop)
_sw_unit = desktop->getNamedView()->display_units;
+ // TODO: Fix potential localization issues here.
// Set the doc default unit active in the units list
for ( auto mi:_unit_mis ) {
if (mi && mi->get_label() == _sw_unit->abbr) {
@@ -1104,9 +1103,10 @@ SelectedStyle::update()
g_free (str);
}
{
- gchar *str = g_strdup_printf(_("Stroke width: %.5g%s%s"),
- w,
- _sw_unit? _sw_unit->abbr.c_str() : "px",
+ Inkscape::Util::Quantity q = Inkscape::Util::Quantity(w,
+ _sw_unit ? _sw_unit->abbr.c_str() : "px");
+ gchar *str = g_strdup_printf(_("Stroke width: %s%s"),
+ q.string().c_str(),
(result_sw == QUERY_STYLE_MULTIPLE_AVERAGED)?
_(" (averaged)") : "");
_stroke_width_place.set_tooltip_text(str);
diff --git a/src/ui/widget/style-swatch.cpp b/src/ui/widget/style-swatch.cpp
index 97b8015471ed57aa10e2815abd09f269fb93b550..013bc8a487778586209331000e0ca791a8c72a68 100644
--- a/src/ui/widget/style-swatch.cpp
+++ b/src/ui/widget/style-swatch.cpp
@@ -337,15 +337,15 @@ void StyleSwatch::setStyle(SPStyle *query)
w = query->stroke_width.computed;
}
+ auto q_str = Inkscape::Util::Quantity(w,
+ _sw_unit ? _sw_unit->abbr.c_str() : "px").string();
{
- gchar *str = g_strdup_printf(" %.3g", w);
+ gchar *str = g_strdup_printf(" %s", q_str.c_str());
_stroke_width.set_markup(str);
g_free (str);
}
{
- gchar *str = g_strdup_printf(_("Stroke width: %.5g%s"),
- w,
- _sw_unit? _sw_unit->abbr.c_str() : "px");
+ gchar *str = g_strdup_printf(_("Stroke width: %s"), q_str.c_str());
_stroke_width_place.set_tooltip_text(str);
g_free (str);
}
@@ -357,14 +357,15 @@ void StyleSwatch::setStyle(SPStyle *query)
gdouble op = SP_SCALE24_TO_FLOAT(query->opacity.value);
if (op != 1) {
+ auto q_str = Inkscape::Util::Quantity(op*100.0, "%").string();
{
gchar *str;
- str = g_strdup_printf(_("O: %2.0f"), (op*100.0));
+ str = g_strdup_printf(_("O: %s"), q_str.c_str());
_opacity_value.set_markup (str);
g_free (str);
}
{
- gchar *str = g_strdup_printf(_("Opacity: %2.1f %%"), (op*100.0));
+ gchar *str = g_strdup_printf(_("Opacity: %s"), q_str.c_str());
_opacity_place.set_tooltip_text(str);
g_free (str);
}
diff --git a/src/ui/widget/unit-menu.cpp b/src/ui/widget/unit-menu.cpp
index 93885126550126a9bb023c49ba5d530f82e391e0..21e8c1cb86ea675c5c005e47b75e2f1003409078 100644
--- a/src/ui/widget/unit-menu.cpp
+++ b/src/ui/widget/unit-menu.cpp
@@ -9,6 +9,7 @@
*/
#include
+#include
#include "unit-menu.h"
@@ -31,10 +32,10 @@ bool UnitMenu::setUnitType(UnitType unit_type)
UnitTable::UnitMap m = unit_table.units(unit_type);
for (auto & i : m) {
- append(i.first);
+ append(i.first, g_dpgettext2(nullptr, "unit-abbr", i.first.c_str()));
}
_type = unit_type;
- set_active_text(unit_table.primary(unit_type));
+ set_active_id(unit_table.primary(unit_type));
return true;
}
@@ -49,30 +50,27 @@ bool UnitMenu::resetUnitType(UnitType unit_type)
void UnitMenu::addUnit(Unit const& u)
{
unit_table.addUnit(u, false);
- append(u.abbr);
+ append(u.abbr, g_dpgettext2(nullptr, "unit-abbr", u.abbr.c_str()));
}
Unit const * UnitMenu::getUnit() const
{
- if (get_active_text() == "") {
+ if (get_active_id() == "") {
g_assert(_type != UNIT_TYPE_NONE);
return unit_table.getUnit(unit_table.primary(_type));
}
- return unit_table.getUnit(get_active_text());
+ return unit_table.getUnit(get_active_id());
}
bool UnitMenu::setUnit(Glib::ustring const & unit)
{
- // TODO: Determine if 'unit' is available in the dropdown.
- // If not, return false
-
- set_active_text(unit);
- return true;
+ return set_active_id(unit);
}
+// TODO: Should this be localized?
Glib::ustring UnitMenu::getUnitAbbr() const
{
- if (get_active_text() == "") {
+ if (get_active_id() == "") {
return "";
}
return getUnit()->abbr;
diff --git a/src/ui/widget/unit-tracker.cpp b/src/ui/widget/unit-tracker.cpp
index 665bb74971c40e7fefd236cb09e2b593aafdcd01..43d300c16447811473f898f525c27602a40ea2d0 100644
--- a/src/ui/widget/unit-tracker.cpp
+++ b/src/ui/widget/unit-tracker.cpp
@@ -15,6 +15,7 @@
*/
#include
+#include
#include
#include "unit-tracker.h"
@@ -39,21 +40,12 @@ UnitTracker::UnitTracker(UnitType unit_type) :
_store(nullptr),
_priorValues()
{
- UnitTable::UnitMap m = unit_table.units(unit_type);
-
InkSelectOneActionColumns columns;
_store = Gtk::ListStore::create(columns);
- Gtk::TreeModel::Row row;
+ UnitTable::UnitMap m = unit_table.units(unit_type);
for (auto & m_iter : m) {
-
- Glib::ustring unit = m_iter.first;
-
- row = *(_store->append());
- row[columns.col_label ] = unit;
- row[columns.col_tooltip ] = ("");
- row[columns.col_icon ] = "NotUsed";
- row[columns.col_sensitive] = true;
+ addUnit(unit_table.getUnit(m_iter.first));
}
// Why?
@@ -94,9 +86,11 @@ void UnitTracker::setActiveUnit(Inkscape::Util::Unit const *unit)
InkSelectOneActionColumns columns;
int index = 0;
for (auto& row: _store->children() ) {
- Glib::ustring storedUnit = row[columns.col_label];
- if (!unit->abbr.compare (storedUnit)) {
- _setActive (index);
+ void* pointer = row[columns.col_data];
+ assert(pointer);
+ auto storedUnit = static_cast(pointer);
+ if (*unit != *storedUnit) {
+ _setActive(index);
break;
}
index++;
@@ -120,32 +114,35 @@ void UnitTracker::addAdjustment(GtkAdjustment *adj)
}
}
-void UnitTracker::addUnit(Inkscape::Util::Unit const *u)
+void initialize_row(Gtk::TreeModel::Row &row, Inkscape::Util::Unit const *u)
{
- InkSelectOneActionColumns columns;
+ assert(u);
+
+ Glib::ustring label = u->abbr;
+ if (label != "")
+ label = g_dpgettext2(nullptr, "unit-abbr", u->abbr.c_str());
- Gtk::TreeModel::Row row;
- row = *(_store->append());
- row[columns.col_label ] = u ? u->abbr.c_str() : "";
+ InkSelectOneActionColumns columns;
+ row[columns.col_data ] = const_cast(u);
+ row[columns.col_label ] = label;
row[columns.col_tooltip ] = ("");
row[columns.col_icon ] = "NotUsed";
row[columns.col_sensitive] = true;
}
-void UnitTracker::prependUnit(Inkscape::Util::Unit const *u)
+void UnitTracker::addUnit(Inkscape::Util::Unit const *u)
{
- InkSelectOneActionColumns columns;
+ Gtk::TreeModel::Row r = *(_store->append());
+ initialize_row(r, u);
+}
- Gtk::TreeModel::Row row;
- row = *(_store->prepend());
- row[columns.col_label ] = u ? u->abbr.c_str() : "";
- row[columns.col_tooltip ] = ("");
- row[columns.col_icon ] = "NotUsed";
- row[columns.col_sensitive] = true;
+void UnitTracker::prependUnit(Inkscape::Util::Unit const *u)
+{
+ Gtk::TreeModel::Row r = *(_store->prepend());
+ initialize_row(r, u);
/* Re-shuffle our default selection here (_active gets out of sync) */
setActiveUnit(_activeUnit);
-
}
void UnitTracker::setFullVal(GtkAdjustment *adj, gdouble val)
@@ -230,58 +227,61 @@ void UnitTracker::_adjustmentFinalized(GObject *where_the_object_was)
void UnitTracker::_setActive(gint active)
{
- if ( active != _active || !_activeUnitInitialized ) {
- gint oldActive = _active;
-
- if (_store) {
-
- // Find old and new units
- InkSelectOneActionColumns columns;
- int index = 0;
- Glib::ustring oldAbbr( "NotFound" );
- Glib::ustring newAbbr( "NotFound" );
- for (auto& row: _store->children() ) {
- if (index == _active) {
- oldAbbr = row[columns.col_label];
- }
- if (index == active) {
- newAbbr = row[columns.col_label];
- }
- if (newAbbr != "NotFound" && oldAbbr != "NotFound") break;
- ++index;
+ if (active == _active && _activeUnitInitialized) {
+ return;
+ }
+
+ if (_store) {
+
+ // Find old and new units
+ InkSelectOneActionColumns columns;
+ int index = 0;
+ Inkscape::Util::Unit const *oldUnit;
+ Inkscape::Util::Unit const *newUnit;
+ for (auto& row: _store->children() ) {
+ if (index == _active) {
+ void* pointer = row[columns.col_data];
+ assert(pointer);
+ oldUnit = static_cast(pointer);
+ }
+ if (index == active) {
+ void* pointer = row[columns.col_data];
+ assert(pointer);
+ newUnit = static_cast(pointer);
}
+ if (oldUnit && newUnit) break;
+ ++index;
+ }
- if (oldAbbr != "NotFound") {
+ if (oldUnit) {
- if (newAbbr != "NotFound") {
- Inkscape::Util::Unit const *oldUnit = unit_table.getUnit(oldAbbr);
- Inkscape::Util::Unit const *newUnit = unit_table.getUnit(newAbbr);
- _activeUnit = newUnit;
+ if (newUnit) {
+ _activeUnit = newUnit;
- if (!_adjList.empty()) {
- _fixupAdjustments(oldUnit, newUnit);
- }
- } else {
- std::cerr << "UnitTracker::_setActive: Did not find new unit: " << active << std::endl;
+ if (!_adjList.empty()) {
+ _fixupAdjustments(oldUnit, newUnit);
}
-
} else {
- std::cerr << "UnitTracker::_setActive: Did not find old unit: " << oldActive
- << " new: " << active << std::endl;
+ std::cerr << "UnitTracker::_setActive: Did not find new unit: " << active << std::endl;
}
- }
- _active = active;
- for (auto act: _actionList) {
- act->set_active (active);
+ } else {
+ std::cerr << "UnitTracker::_setActive: Did not find old unit: " << _active
+ << " new: " << active << std::endl;
}
+ }
- for (auto combo : _combo_list) {
- if(combo) combo->set_active(active);
- }
+ _active = active;
+
+ for (auto act: _actionList) {
+ act->set_active(active);
+ }
- _activeUnitInitialized = true;
+ for (auto combo : _combo_list) {
+ if(combo) combo->set_active(active);
}
+
+ _activeUnitInitialized = true;
}
void UnitTracker::_fixupAdjustments(Inkscape::Util::Unit const *oldUnit, Inkscape::Util::Unit const *newUnit)
diff --git a/src/util/units.cpp b/src/util/units.cpp
index 0a1fdbf31cf4b349ff555a6da9713109023ce2e5..313128af5fc8ff7bbe070554e9ae1ff1538a570b 100644
--- a/src/util/units.cpp
+++ b/src/util/units.cpp
@@ -105,10 +105,10 @@ typedef std::unordered_map TypeMap;
TypeMap make_type_map()
{
TypeMap tmap;
- tmap["DIMENSIONLESS"] = UNIT_TYPE_DIMENSIONLESS;
- tmap["LINEAR"] = UNIT_TYPE_LINEAR;
- tmap["RADIAL"] = UNIT_TYPE_RADIAL;
- tmap["FONT_HEIGHT"] = UNIT_TYPE_FONT_HEIGHT;
+ tmap["dimensionless"] = UNIT_TYPE_DIMENSIONLESS;
+ tmap["linear"] = UNIT_TYPE_LINEAR;
+ tmap["angular"] = UNIT_TYPE_RADIAL;
+ tmap["fontSize"] = UNIT_TYPE_FONT_HEIGHT;
// Note that code was not yet handling LINEAR_SCALED, TIME, QTY and NONE
return tmap;
@@ -157,6 +157,7 @@ Unit::Unit() :
name(),
name_plural(),
abbr(),
+ format(),
description()
{
}
@@ -166,12 +167,14 @@ Unit::Unit(UnitType type,
Glib::ustring name,
Glib::ustring name_plural,
Glib::ustring abbr,
+ Glib::ustring format,
Glib::ustring description)
: type(type)
, factor(factor)
, name(std::move(name))
, name_plural(std::move(name_plural))
, abbr(std::move(abbr))
+ , format(std::move(format))
, description(std::move(description))
{
g_return_if_fail(factor <= 0);
@@ -215,7 +218,7 @@ bool Unit::compatibleWith(Glib::ustring const &u) const
bool Unit::operator==(Unit const &other) const
{
- return (type == other.type && name.compare(other.name) == 0);
+ return (this != &other && type == other.type && name.compare(other.name) == 0);
}
int Unit::svgUnit() const
@@ -444,7 +447,7 @@ void UnitParser::on_start_element(Ctx &/*ctx*/, Glib::ustring const &name, AttrM
skip = true;
}
}
- if ((f = attrs.find("pri")) != attrs.end()) {
+ if ((f = attrs.find("primary")) != attrs.end()) {
primary = (f->second[0] == 'y' || f->second[0] == 'Y');
}
}
@@ -453,12 +456,17 @@ void UnitParser::on_start_element(Ctx &/*ctx*/, Glib::ustring const &name, AttrM
void UnitParser::on_text(Ctx &ctx, Glib::ustring const &text)
{
Glib::ustring element = ctx.get_element();
+ if (element.length() > 0 && element[0] == '_') {
+ element = element.substr(1);
+ }
if (element == "name") {
unit.name = text;
- } else if (element == "plural") {
+ } else if (element == "name_plural") {
unit.name_plural = text;
} else if (element == "abbr") {
unit.abbr = text;
+ } else if (element == "format") {
+ unit.format = text;
} else if (element == "factor") {
// TODO make sure we use the right conversion
unit.factor = g_ascii_strtod(text.c_str(), nullptr);
@@ -516,14 +524,15 @@ double Quantity::value(char const *u) const
return value(unit_table.getUnit(u));
}
-Glib::ustring Quantity::string(Unit const *u) const {
- return Glib::ustring::format(std::fixed, std::setprecision(2), value(u)) + " " + u->abbr;
+Glib::ustring Quantity::string(Unit const *u, int p) const {
+ return Glib::ustring::compose(u->format, Glib::ustring::format(
+ std::fixed, std::setprecision(p == -1 ? u->defaultDigits() : p), value(u)));
}
-Glib::ustring Quantity::string(Glib::ustring const &u) const {
- return string(unit_table.getUnit(u.c_str()));
+Glib::ustring Quantity::string(Glib::ustring const &u, int p) const {
+ return string(unit_table.getUnit(u.c_str()), p);
}
-Glib::ustring Quantity::string() const {
- return string(unit);
+Glib::ustring Quantity::string(int p) const {
+ return string(unit, p);
}
double Quantity::convert(double from_dist, Unit const *from, Unit const *to)
diff --git a/src/util/units.h b/src/util/units.h
index 2b7f8674cf6edcd7edaf5a13e7f692db99216616..0a6d94a41968e324caa2f03ec787f4aa11dd36f1 100644
--- a/src/util/units.h
+++ b/src/util/units.h
@@ -47,7 +47,7 @@ enum UnitType {
UNIT_TYPE_NONE = -1
};
-const char DEG[] = "°";
+const char DEG[] = "deg";
class Unit
: boost::equality_comparable
@@ -59,6 +59,7 @@ public:
Glib::ustring name,
Glib::ustring name_plural,
Glib::ustring abbr,
+ Glib::ustring format,
Glib::ustring description);
void clear();
@@ -81,6 +82,7 @@ public:
Glib::ustring name;
Glib::ustring name_plural;
Glib::ustring abbr;
+ Glib::ustring format;
Glib::ustring description;
/** Check if units are equal. */
@@ -117,10 +119,10 @@ public:
double value(Glib::ustring const &u) const;
double value(char const *u) const;
- /** Return a printable string of the value in the specified unit. */
- Glib::ustring string(Unit const *u) const;
- Glib::ustring string(Glib::ustring const &u) const;
- Glib::ustring string() const;
+ /** Return a localized printable string of the value in the specified unit. */
+ Glib::ustring string(Unit const *u, int precision=2) const;
+ Glib::ustring string(Glib::ustring const &u, int precision=2) const;
+ Glib::ustring string(int precision=2) const;
/** Convert distances.
no NULL check is performed on the passed pointers to Unit objects! */
diff --git a/src/widgets/desktop-widget.cpp b/src/widgets/desktop-widget.cpp
index 13a7b649e9e040985d2c14db4f607ce13d601a26..a02447af2fe9327d5bd9485836d67cdab6a6ef38 100644
--- a/src/widgets/desktop-widget.cpp
+++ b/src/widgets/desktop-widget.cpp
@@ -386,7 +386,7 @@ void SPDesktopWidget::init( SPDesktopWidget *dtw )
dtw->_hruler_box = Gtk::manage(new Gtk::EventBox());
Inkscape::Util::Unit const *pt = unit_table.getUnit("pt");
sp_ruler_set_unit(SP_RULER(dtw->_hruler->gobj()), pt);
- dtw->_hruler_box->set_tooltip_text(gettext(pt->name_plural.c_str()));
+ dtw->_hruler_box->set_tooltip_text(g_dpgettext2(nullptr, "unit-text-plural", pt->name_plural.c_str()));
dtw->_hruler_box->add(*dtw->_hruler);
dtw->_hruler_box->signal_button_press_event().connect(sigc::bind(sigc::mem_fun(*dtw, &SPDesktopWidget::on_ruler_box_button_press_event), dtw->_hruler_box, true));
@@ -400,7 +400,7 @@ void SPDesktopWidget::init( SPDesktopWidget *dtw )
dtw->_vruler->set_name("VerticalRuler");
dtw->_vruler_box = Gtk::manage(new Gtk::EventBox());
sp_ruler_set_unit (SP_RULER (dtw->_vruler->gobj()), pt);
- dtw->_vruler_box->set_tooltip_text(gettext(pt->name_plural.c_str()));
+ dtw->_vruler_box->set_tooltip_text(g_dpgettext2(nullptr, "unit-text-plural", pt->name_plural.c_str()));
dtw->_vruler_box->add(*dtw->_vruler);
dtw->_vruler_box->signal_button_press_event().connect(sigc::bind(sigc::mem_fun(*dtw, &SPDesktopWidget::on_ruler_box_button_press_event), dtw->_vruler_box, false));
@@ -645,8 +645,8 @@ void SPDesktopWidget::init( SPDesktopWidget *dtw )
dtw->_coord_status_y = Gtk::manage(new Gtk::Label());
dtw->_coord_status_x->set_name("CoordinateStatusX");
dtw->_coord_status_y->set_name("CoordinateStatusY");
- dtw->_coord_status_x->set_markup(" 0.00 ");
- dtw->_coord_status_y->set_markup(" 0.00 ");
+ dtw->_coord_status_x->set_text(" 0.00 ");
+ dtw->_coord_status_y->set_text(" 0.00 ");
auto label_z = Gtk::manage(new Gtk::Label(_("Z:")));
label_z->set_name("ZLabel");
@@ -654,6 +654,10 @@ void SPDesktopWidget::init( SPDesktopWidget *dtw )
label_r->set_name("RLabel");
dtw->_coord_status_x->set_halign(Gtk::ALIGN_END);
dtw->_coord_status_y->set_halign(Gtk::ALIGN_END);
+ dtw->_coord_status_x->set_xalign(1);
+ dtw->_coord_status_y->set_xalign(1);
+ dtw->_coord_status_x->set_width_chars(10);
+ dtw->_coord_status_y->set_width_chars(10);
dtw->_coord_status->attach(*dtw->_coord_status_x, 2, 0, 1, 1);
dtw->_coord_status->attach(*dtw->_coord_status_y, 2, 1, 1, 1);
dtw->_coord_status->attach(*label_z, 3, 0, 1, 2);
@@ -1265,14 +1269,10 @@ SPDesktopWidget::disableInteraction()
void
SPDesktopWidget::setCoordinateStatus(Geom::Point p)
{
- gchar *cstr;
- cstr = g_strdup_printf("%7.2f", _dt2r * p[Geom::X]);
- _coord_status_x->set_markup(cstr);
- g_free(cstr);
-
- cstr = g_strdup_printf("%7.2f", _dt2r * p[Geom::Y]);
- _coord_status_y->set_markup(cstr);
- g_free(cstr);
+ SPNamedView *nv = desktop->namedview;
+ auto unit = nv->display_units;
+ _coord_status_x->set_text(Inkscape::Util::Quantity(_dt2r * p[Geom::X], unit).string());
+ _coord_status_y->set_text(Inkscape::Util::Quantity(_dt2r * p[Geom::Y], unit).string());
}
void
@@ -1771,8 +1771,8 @@ void SPDesktopWidget::namedviewModified(SPObject *obj, guint flags)
} // children
} // if aux_toolbox is a container
- _hruler_box->set_tooltip_text(gettext(nv->display_units->name_plural.c_str()));
- _vruler_box->set_tooltip_text(gettext(nv->display_units->name_plural.c_str()));
+ _hruler_box->set_tooltip_text(g_dpgettext2(nullptr, "unit-text-plural", nv->display_units->name_plural.c_str()));
+ _vruler_box->set_tooltip_text(g_dpgettext2(nullptr, "unit-text-plural", nv->display_units->name_plural.c_str()));
update_rulers();
ToolboxFactory::updateSnapToolbox(this->desktop, nullptr, this->snap_toolbox);