Summary: This starts by adding support for AFSimple_Calculate which is the standard "calculate" function in Adobe Acrobat Pro. Reviewers: #okular Subscribers: aacid Tags: #okular Maniphest Tasks: T7805 Differential Revision: https://phabricator.kde.org/D10049remotes/origin/Applications/18.04
parent
d50c06df25
commit
cead2bbef3
4 changed files with 88 additions and 1 deletions
@ -0,0 +1,62 @@ |
||||
/*************************************************************************** |
||||
* Copyright (C) 2018 Intevation GmbH <intevation@intevation.de> * |
||||
* * |
||||
* This program is free software; you can redistribute it and/or modify * |
||||
* it under the terms of the GNU General Public License as published by * |
||||
* the Free Software Foundation; either version 2 of the License, or * |
||||
* (at your option) any later version. * |
||||
***************************************************************************/ |
||||
|
||||
/* Builtin functions for Okular's PDF JavaScript interpretation. */ |
||||
|
||||
/** AFSimple_Calculate |
||||
* |
||||
* cFunction is a string that identifies the operation. |
||||
* It is one of AVG, SUM, PRD, MIN, MAX |
||||
* cFields is an array of the names of the fields used to calculate. |
||||
*/ |
||||
function AFSimple_Calculate( cFunction, cFields ) |
||||
{ |
||||
var ret = 0; |
||||
|
||||
if ( cFunction === "PRD" ) |
||||
{ |
||||
ret = 1; |
||||
} |
||||
|
||||
for (i = 0; i < cFields.length; i++) |
||||
{ |
||||
var field = Doc.getField( cFields[i] ); |
||||
var val = Number( field.value ); |
||||
|
||||
if ( cFunction === "SUM" || cFunction === "AVG" ) |
||||
{ |
||||
ret += val; |
||||
} |
||||
else if ( cFunction === "PRD" ) |
||||
{ |
||||
ret *= val; |
||||
} |
||||
else if ( cFunction === "MIN" ) |
||||
{ |
||||
if ( i === 0 || val < ret ) |
||||
{ |
||||
ret = val; |
||||
} |
||||
} |
||||
else if ( cFunction === "MAX" ) |
||||
{ |
||||
if ( i === 0 || val > ret ) |
||||
{ |
||||
ret = val; |
||||
} |
||||
} |
||||
} |
||||
|
||||
if ( cFunction === "AVG" ) |
||||
{ |
||||
ret /= cFields.length; |
||||
} |
||||
|
||||
event.value = ret; |
||||
} |
||||
@ -0,0 +1,5 @@ |
||||
<!DOCTYPE RCC><RCC version="1.0"> |
||||
<qresource prefix="/script"> |
||||
<file>builtin.js</file> |
||||
</qresource> |
||||
</RCC> |
||||
Loading…
Reference in new issue