LibPDF: Tweak implementation of postscript roll op

Since positive offsets roll to the right, it makes more sense
to do the big reverse first. Gets rid of an awkward minus sign.

No behavior change.
This commit is contained in:
Nico Weber 2023-11-10 13:30:37 +01:00 committed by Andreas Kling
commit cd9f4655ec
Notes: sideshowbarker 2024-07-16 17:05:37 +09:00

View file

@ -728,7 +728,7 @@ PDFErrorOr<void> PostScriptCalculatorFunction::execute(Vector<Token> const& toke
TRY(stack.pop());
break;
case OperatorType::Roll: {
int j = -(int)TRY(stack.pop());
int j = (int)TRY(stack.pop());
int n = (int)TRY(stack.pop());
if (n < 0)
return Error { Error::Type::RenderingUnsupported, "PostScript roll with negative argument"_string };
@ -742,9 +742,9 @@ PDFErrorOr<void> PostScriptCalculatorFunction::execute(Vector<Token> const& toke
return Error { Error::Type::RenderingUnsupported, "PostScript roll with argument larger than stack"_string };
// http://pointer-overloading.blogspot.com/2013/09/algorithms-rotating-one-dimensional.html
auto elements = stack.stack.span().slice(stack.top - n, n);
elements.reverse();
elements.slice(0, j).reverse();
elements.slice(j).reverse();
elements.reverse();
break;
}
}