Skip to content

Commit

Permalink
PDFBOX-5695: DRY refactoring, by Axel Howind
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1914539 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
THausherr committed Dec 11, 2023
1 parent 924dabe commit a9453ba
Showing 1 changed file with 8 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ private List<Object> parseSequence(byte[] bytes, byte[][] globalSubrIndex,
int b0 = input.readUnsignedByte();
if (b0 == CALLSUBR && localSubroutineIndexProvided)
{
processCallSubr(globalSubrIndex, localSubrIndex);
}
processCallSubr(globalSubrIndex, localSubrIndex, localSubrIndex);
}
else if (b0 == CALLGSUBR && globalSubroutineIndexProvided)
{
processCallGSubr(globalSubrIndex, localSubrIndex);
}
processCallSubr(globalSubrIndex, localSubrIndex, globalSubrIndex);
}
else if ( (b0 >= 0 && b0 <= 27) || (b0 >= 29 && b0 <= 31))
{
sequence.add(readCommand(b0, input));
Expand All @@ -105,33 +105,14 @@ else if (b0 == 28 || (b0 >= 32 && b0 <= 255))
return sequence;
}

private void processCallSubr(byte[][] globalSubrIndex, byte[][] localSubrIndex)
throws IOException
{
int subrNumber = calculateSubrNumber((Integer) sequence.remove(sequence.size() - 1),
localSubrIndex.length);
if (subrNumber < localSubrIndex.length)
{
byte[] subrBytes = localSubrIndex[subrNumber];
parseSequence(subrBytes, globalSubrIndex, localSubrIndex);
Object lastItem = sequence.get(sequence.size() - 1);
if (lastItem instanceof CharStringCommand
&& Type2KeyWord.RET == ((CharStringCommand) lastItem).getType2KeyWord())
{
// remove "return" command
sequence.remove(sequence.size() - 1);
}
}
}

private void processCallGSubr(byte[][] globalSubrIndex, byte[][] localSubrIndex)
private void processCallSubr(byte[][] globalSubrIndex, byte[][] localSubrIndex, byte[][] subrIndex)
throws IOException
{
int subrNumber = calculateSubrNumber((Integer) sequence.remove(sequence.size() - 1),
globalSubrIndex.length);
if (subrNumber < globalSubrIndex.length)
subrIndex.length);
if (subrNumber < subrIndex.length)
{
byte[] subrBytes = globalSubrIndex[subrNumber];
byte[] subrBytes = subrIndex[subrNumber];
parseSequence(subrBytes, globalSubrIndex, localSubrIndex);
Object lastItem = sequence.get(sequence.size() - 1);
if (lastItem instanceof CharStringCommand
Expand Down

0 comments on commit a9453ba

Please sign in to comment.