1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 19:18:12 +00:00

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
parent b23ed86889
commit cd9f4655ec

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;
}
}