1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-22 16:18:08 +02:00

Correct PostScript trigonometric operators

PDF 32000-1:2008 7.10.5.1 "Type 4 (PostScript Calculator) Functions"
defers to the PostScript Language Reference for the description of these
functions. The PostScript Language Reference, third edition chapter 8
"Operators" defines the `angle` type as a "number of degrees". Section
8.1 defines "angle `sin` real", "angle `cos` real", and "num den `atan`
angle". The documentation for `atan` further states that it will return
an angle in degrees between 0 and 360.

Handle these operators correctly in `PostScriptEvaluator.execute`.
Convert the inputs to `sin` and `cos` from degrees to radians for use
with `Math.sin` and `Math.cos`. Correctly pop two values from the stack
for `atan`, use `Math.atan2`, and convert from radians to (positive)
degrees.
This commit is contained in:
Ben Wagner 2023-02-27 12:34:12 -05:00
parent 4e52bcee44
commit 158c836e26
7 changed files with 37 additions and 11 deletions

View file

@ -628,8 +628,13 @@ class PostScriptEvaluator {
}
break;
case "atan":
b = stack.pop();
a = stack.pop();
stack.push(Math.atan(a));
a = (Math.atan2(a, b) / Math.PI) * 180;
if (a < 0) {
a += 360;
}
stack.push(a);
break;
case "bitshift":
b = stack.pop();
@ -650,7 +655,7 @@ class PostScriptEvaluator {
break;
case "cos":
a = stack.pop();
stack.push(Math.cos(a));
stack.push(Math.cos(((a % 360) / 180) * Math.PI));
break;
case "cvi":
a = stack.pop() | 0;
@ -774,7 +779,7 @@ class PostScriptEvaluator {
break;
case "sin":
a = stack.pop();
stack.push(Math.sin(a));
stack.push(Math.sin(((a % 360) / 180) * Math.PI));
break;
case "sqrt":
a = stack.pop();