AFSimple_Calculate (doc) is the default function for calculate action's that is added when modifying "Calculate" in the Text Field Properties in Adobe Acrobat Pro:
(This is how you add the calculate function in Adobe)
The function itself is simple and easy to implement in JavaScript. But currently Okular's JavaScript executor runs in an Exception that AFSimple_Calculate is unknown.
For Okular most things to handle this are already in place, we evaluate the calculate already and execute the javascript in there. But to handle this properly I think four things are needed:
- Using the result of a JavaScript calculate action to set the value of text fields.
- Updating the text field based on the result of a calculate action.
- A way to add built-in JavaScript functions.
- Some way to handle localized numbers. (e.g. in German 1.3 is 1,3)
- A unit test :-)
Example document:
I have a patch for everything, which I will add as differentials, except localized number handling. For this I need to experiment a bit with where this would be ideally handled, as I would like to do it somehow with Qt and not in JavaScript.
Here is a behavior comparison between Adobe and Okular (with the patches):