Comment 0 for bug 1024362

Revision history for this message
Kieran Clancy (clancy-kieran+launchpad) wrote : RFE: Support unit and numerical arithmetic and conversion in input boxes

The concept is simple enough:

When I am modifying an object's property or filling in toolbox options, and there's a field for length, position or even just an integer, I want Inkscape to support some simple in-field calculations. It would also be great if I could specify units and have Inkscape understand how to convert them to the current display units.

Here's a bit of an outline of how I think this could work:

When a user changes the field, a function is used to pre-process it and replace it. Currently this is already done by Inkscape for some fields; for example if you type just 0.5 into a field it will sometimes change to 0.500 automatically.

If the input is not recognised, it should become red and prevent the user from activating the change with the keyboard (by keypress like enter) until fixed. If not fixed and the user cancels the operation or presses Esc, it will return to the (valid) value before the change.

Types of arithmetic / conversions supported:

Basic mathematical operations, with highest precedence first

* multiply
/ divide
% modulo
+ add
- subtract
( <expr> ) evaluate <expr> first
<whitespace> ignored

This should be supported by all numerical fields. (If the field is an integer-only field, truncate fractional part after finishing entire calculation.)

If a binary operator is the first non-whitespace input to a field, the previous input should be automatically recalled and inserted before the inserted operator.

Examples:
Typing "2*88" in a field should be replaced by "176"
Typing "29.7/21" would give you the ratio of any ISO A paper size (~=1.414~=sqrt(2)).

Unit operations:

For fields representing lengths or coordinates, accept '<expr>mm', '<expr>cm', '<expr>in', '<expr>%','<expr>px','<expr>pt', etc, where <expr> is either a number of a valid number or mathematical expression.

These should work regardless of which units are currently being displayed.

That is, if I am displaying my units in millimetres and I type '1in' into the width field, it should be updated to display '24.5'.

Furthermore, it should be possible to combine units, so "3*14.2cm+10/3pt" would work as expected.

I think that it would be such a useful feature, and I don't think it should be difficult to make?

Bonus features:

If this ends up being done, perhaps keep in mind that in future it might be cool to support some extra functions and operators:

^ exponentiation operator
sin(), cos(), tan(), exp()

Contextually relevant variables:

l / last (previous value)
dw / docwidth (width of document)
dh / docheight (height of document)
w / width (width of current object - if applicable)
h / height (height of current object - if applicable)
x / xpos (x position of current object - if applicable)
y / ypos (y position of current object - if applicable)

Other context-sensitive parameters? Maybe they can be summarised in the field's on-hover tooltip. (For example, circle objects might have a 'r / radius' parameter.