PDFStreamParser.java (pdfbox-2.0.23-src) | : | PDFStreamParser.java (pdfbox-2.0.24-src) | ||
---|---|---|---|---|
skipping to change at line 34 | skipping to change at line 34 | |||
import org.apache.commons.logging.LogFactory; | import org.apache.commons.logging.LogFactory; | |||
import org.apache.pdfbox.contentstream.PDContentStream; | import org.apache.pdfbox.contentstream.PDContentStream; | |||
import org.apache.pdfbox.contentstream.operator.Operator; | import org.apache.pdfbox.contentstream.operator.Operator; | |||
import org.apache.pdfbox.contentstream.operator.OperatorName; | import org.apache.pdfbox.contentstream.operator.OperatorName; | |||
import org.apache.pdfbox.cos.COSBase; | import org.apache.pdfbox.cos.COSBase; | |||
import org.apache.pdfbox.cos.COSBoolean; | import org.apache.pdfbox.cos.COSBoolean; | |||
import org.apache.pdfbox.cos.COSDictionary; | import org.apache.pdfbox.cos.COSDictionary; | |||
import org.apache.pdfbox.cos.COSName; | import org.apache.pdfbox.cos.COSName; | |||
import org.apache.pdfbox.cos.COSNull; | import org.apache.pdfbox.cos.COSNull; | |||
import org.apache.pdfbox.cos.COSNumber; | import org.apache.pdfbox.cos.COSNumber; | |||
import org.apache.pdfbox.cos.COSObject; | ||||
import org.apache.pdfbox.cos.COSStream; | import org.apache.pdfbox.cos.COSStream; | |||
import org.apache.pdfbox.io.RandomAccessBuffer; | import org.apache.pdfbox.io.RandomAccessBuffer; | |||
import org.apache.pdfbox.pdmodel.common.PDStream; | import org.apache.pdfbox.pdmodel.common.PDStream; | |||
/** | /** | |||
* This will parse a PDF byte stream and extract operands and such. | * This will parse a PDF byte stream and extract operands and such. | |||
* | * | |||
* @author Ben Litchfield | * @author Ben Litchfield | |||
*/ | */ | |||
public class PDFStreamParser extends BaseParser | public class PDFStreamParser extends BaseParser | |||
skipping to change at line 201 | skipping to change at line 200 | |||
return COSBoolean.TRUE; | return COSBoolean.TRUE; | |||
} | } | |||
else if( next.equals( "false" ) ) | else if( next.equals( "false" ) ) | |||
{ | { | |||
return COSBoolean.FALSE; | return COSBoolean.FALSE; | |||
} | } | |||
else | else | |||
{ | { | |||
return Operator.getOperator(next); | return Operator.getOperator(next); | |||
} | } | |||
case 'R': | ||||
String line = readString(); | ||||
if( line.equals( "R" ) ) | ||||
{ | ||||
return new COSObject(null); | ||||
} | ||||
else | ||||
{ | ||||
return Operator.getOperator(line); | ||||
} | ||||
case '0': | case '0': | |||
case '1': | case '1': | |||
case '2': | case '2': | |||
case '3': | case '3': | |||
case '4': | case '4': | |||
case '5': | case '5': | |||
case '6': | case '6': | |||
case '7': | case '7': | |||
case '8': | case '8': | |||
case '9': | case '9': | |||
skipping to change at line 263 | skipping to change at line 252 | |||
String nextOperator = readString(); | String nextOperator = readString(); | |||
Operator beginImageOP = Operator.getOperator(nextOperator); | Operator beginImageOP = Operator.getOperator(nextOperator); | |||
if (nextOperator.equals(OperatorName.BEGIN_INLINE_IMAGE)) | if (nextOperator.equals(OperatorName.BEGIN_INLINE_IMAGE)) | |||
{ | { | |||
COSDictionary imageParams = new COSDictionary(); | COSDictionary imageParams = new COSDictionary(); | |||
beginImageOP.setImageParameters(imageParams); | beginImageOP.setImageParameters(imageParams); | |||
Object nextToken = null; | Object nextToken = null; | |||
while ((nextToken = parseNextToken()) instanceof COSName) | while ((nextToken = parseNextToken()) instanceof COSName) | |||
{ | { | |||
Object value = parseNextToken(); | Object value = parseNextToken(); | |||
if (!(value instanceof COSBase)) | ||||
{ | ||||
LOG.warn("Unexpected token in inline image dictionar | ||||
y at offset " + | ||||
seqSource.getPosition()); | ||||
break; | ||||
} | ||||
imageParams.setItem((COSName) nextToken, (COSBase) value ); | imageParams.setItem((COSName) nextToken, (COSBase) value ); | |||
} | } | |||
// final token will be the image data, maybe?? | // final token will be the image data, maybe?? | |||
if (nextToken instanceof Operator) | if (nextToken instanceof Operator) | |||
{ | { | |||
Operator imageData = (Operator) nextToken; | Operator imageData = (Operator) nextToken; | |||
if (imageData.getImageData() == null | if (imageData.getImageData() == null | |||
|| imageData.getImageData().length == 0) | || imageData.getImageData().length == 0) | |||
{ | { | |||
LOG.warn("empty inline image at stream offset " | LOG.warn("empty inline image at stream offset " | |||
skipping to change at line 323 | skipping to change at line 318 | |||
beginImageDataOP.setImageData(imageData.toByteArray()); | beginImageDataOP.setImageData(imageData.toByteArray()); | |||
return beginImageDataOP; | return beginImageDataOP; | |||
case ']': | case ']': | |||
// some ']' around without its previous '[' | // some ']' around without its previous '[' | |||
// this means a PDF is somewhat corrupt but we will continue to parse. | // this means a PDF is somewhat corrupt but we will continue to parse. | |||
seqSource.read(); | seqSource.read(); | |||
// must be a better solution than null... | // must be a better solution than null... | |||
return COSNull.NULL; | return COSNull.NULL; | |||
default: | default: | |||
// we must be an operator | // we must be an operator | |||
String operator = readOperator(); | String operator = readOperator().trim(); | |||
if (operator.trim().length() > 0) | if (operator.length() > 0) | |||
{ | { | |||
return Operator.getOperator(operator); | return Operator.getOperator(operator); | |||
} | } | |||
} | } | |||
return null; | return null; | |||
} | } | |||
/** | /** | |||
* Looks up an amount of bytes if they contain only ASCII characters (no | * Looks up an amount of bytes if they contain only ASCII characters (no | |||
* control sequences etc.), and that these ASCII characters begin with a | * control sequences etc.), and that these ASCII characters begin with a | |||
End of changes. 4 change blocks. | ||||
13 lines changed or deleted | 9 lines changed or added |