use of com.tom_roush.pdfbox.cos.COSNumber in project PdfBox-Android by TomRoush.
the class MoveTextSetLeading method process.
@Override
public void process(Operator operator, List<COSBase> arguments) throws IOException {
if (arguments.size() < 2) {
throw new MissingOperandException(operator, arguments);
}
// move text position and set leading
COSBase base1 = arguments.get(1);
if (!(base1 instanceof COSNumber)) {
return;
}
COSNumber y = (COSNumber) base1;
List<COSBase> args = new ArrayList<COSBase>();
args.add(new COSFloat(-1 * y.floatValue()));
context.processOperator(OperatorName.SET_TEXT_LEADING, args);
context.processOperator(OperatorName.MOVE_TEXT, arguments);
}
use of com.tom_roush.pdfbox.cos.COSNumber in project PdfBox-Android by TomRoush.
the class SetCharSpacing method process.
@Override
public void process(Operator operator, List<COSBase> arguments) throws IOException {
if (arguments.isEmpty()) {
throw new MissingOperandException(operator, arguments);
}
// there are some documents which are incorrectly structured, and have
// a wrong number of arguments to this, so we will assume the last argument
// in the list
Object charSpacing = arguments.get(arguments.size() - 1);
if (charSpacing instanceof COSNumber) {
COSNumber characterSpacing = (COSNumber) charSpacing;
context.getGraphicsState().getTextState().setCharacterSpacing(characterSpacing.floatValue());
}
}
use of com.tom_roush.pdfbox.cos.COSNumber in project PdfBox-Android by TomRoush.
the class PDCircleAppearanceHandler method getLineWidth.
/**
* Get the line with of the border.
*
* Get the width of the line used to draw a border around the annotation.
* This may either be specified by the annotation dictionaries Border
* setting or by the W entry in the BS border style dictionary. If both are
* missing the default width is 1.
*
* @return the line width
*/
// TODO: according to the PDF spec the use of the BS entry is annotation
// specific
// so we will leave that to be implemented by individual handlers.
// If at the end all annotations support the BS entry this can be handled
// here and removed from the individual handlers.
float getLineWidth() {
PDAnnotationMarkup annotation = (PDAnnotationMarkup) getAnnotation();
PDBorderStyleDictionary bs = annotation.getBorderStyle();
if (bs != null) {
return bs.getWidth();
}
COSArray borderCharacteristics = annotation.getBorder();
if (borderCharacteristics.size() >= 3) {
COSBase base = borderCharacteristics.getObject(2);
if (base instanceof COSNumber) {
return ((COSNumber) base).floatValue();
}
}
return 1;
}
use of com.tom_roush.pdfbox.cos.COSNumber 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.cos.COSNumber in project PdfBox-Android by TomRoush.
the class PDLinkAppearanceHandler method getLineWidth.
/**
* Get the line with of the border.
*
* Get the width of the line used to draw a border around the annotation.
* This may either be specified by the annotation dictionaries Border
* setting or by the W entry in the BS border style dictionary. If both are
* missing the default width is 1.
*
* @return the line width
*/
// TODO: according to the PDF spec the use of the BS entry is annotation
// specific
// so we will leave that to be implemented by individual handlers.
// If at the end all annotations support the BS entry this can be handled
// here and removed from the individual handlers.
float getLineWidth() {
PDAnnotationLink annotation = (PDAnnotationLink) getAnnotation();
PDBorderStyleDictionary bs = annotation.getBorderStyle();
if (bs != null) {
return bs.getWidth();
}
COSArray borderCharacteristics = annotation.getBorder();
if (borderCharacteristics.size() >= 3) {
COSBase base = borderCharacteristics.getObject(2);
if (base instanceof COSNumber) {
return ((COSNumber) base).floatValue();
}
}
return 1;
}
Aggregations