use of com.tom_roush.pdfbox.contentstream.operator.Operator in project PdfBox-Android by TomRoush.
the class PDDefaultAppearanceString method processAppearanceStringOperators.
/**
* Processes the operators of the given content stream.
*
* @param content the content to parse.
* @throws IOException if there is an error reading or parsing the content stream.
*/
private void processAppearanceStringOperators(byte[] content) throws IOException {
List<COSBase> arguments = new ArrayList<COSBase>();
PDFStreamParser parser = new PDFStreamParser(content);
Object token = parser.parseNextToken();
while (token != null) {
if (token instanceof COSObject) {
arguments.add(((COSObject) token).getObject());
} else if (token instanceof Operator) {
processOperator((Operator) token, arguments);
arguments = new ArrayList<COSBase>();
} else {
arguments.add((COSBase) token);
}
token = parser.parseNextToken();
}
}
use of com.tom_roush.pdfbox.contentstream.operator.Operator in project PdfBox-Android by TomRoush.
the class PDFreeTextAppearanceHandler method extractFontDetails.
// TODO extractNonStrokingColor and extractFontDetails
// might somehow be replaced with PDDefaultAppearanceString, which is quite similar.
private void extractFontDetails(PDAnnotationMarkup annotation) {
String defaultAppearance = annotation.getDefaultAppearance();
if (defaultAppearance == null && document != null && document.getDocumentCatalog().getAcroForm() != null) {
defaultAppearance = document.getDocumentCatalog().getAcroForm().getDefaultAppearance();
}
if (defaultAppearance == null) {
return;
}
try {
// not sure if charset is correct, but we only need numbers and simple characters
PDFStreamParser parser = new PDFStreamParser(defaultAppearance.getBytes(Charsets.US_ASCII));
COSArray arguments = new COSArray();
COSArray fontArguments = new COSArray();
for (Object token = parser.parseNextToken(); token != null; token = parser.parseNextToken()) {
if (token instanceof COSObject) {
arguments.add(((COSObject) token).getObject());
} else if (token instanceof Operator) {
Operator op = (Operator) token;
String name = op.getName();
if (OperatorName.SET_FONT_AND_SIZE.equals(name)) {
fontArguments = arguments;
}
arguments = new COSArray();
} else {
arguments.add((COSBase) token);
}
}
if (fontArguments.size() >= 2) {
COSBase base = fontArguments.get(0);
if (base instanceof COSName) {
fontName = (COSName) base;
}
base = fontArguments.get(1);
if (base instanceof COSNumber) {
fontSize = ((COSNumber) base).floatValue();
}
}
} catch (IOException ex) {
Log.w("PdfBox-Android", "Problem parsing /DA, will use default 'Helv 10'", ex);
}
}
use of com.tom_roush.pdfbox.contentstream.operator.Operator in project PdfBox-Android by TomRoush.
the class PDFStreamEngine method processOperator.
/**
* This is used to handle an operation.
*
* @param operation The operation to perform.
* @param arguments The list of arguments.
* @throws IOException If there is an error processing the operation.
*/
public void processOperator(String operation, List<COSBase> arguments) throws IOException {
Operator operator = Operator.getOperator(operation);
processOperator(operator, arguments);
}
use of com.tom_roush.pdfbox.contentstream.operator.Operator in project PdfBox-Android by TomRoush.
the class PDFStreamEngine method processStreamOperators.
/**
* Processes the operators of the given content stream.
*
* @param contentStream to content stream to parse.
* @throws IOException if there is an error reading or parsing the content stream.
*/
private void processStreamOperators(PDContentStream contentStream) throws IOException {
List<COSBase> arguments = new ArrayList<COSBase>();
PDFStreamParser parser = new PDFStreamParser(contentStream);
Object token = parser.parseNextToken();
while (token != null) {
if (token instanceof COSObject) {
arguments.add(((COSObject) token).getObject());
} else if (token instanceof Operator) {
processOperator((Operator) token, arguments);
arguments = new ArrayList<COSBase>();
} else {
arguments.add((COSBase) token);
}
token = parser.parseNextToken();
}
}
Aggregations