use of com.tom_roush.pdfbox.cos.COSNumber in project PdfBox-Android by TomRoush.
the class PDAnnotation method getRectangle.
/**
* The annotation rectangle, defining the location of the annotation on the page in default user space units. This
* is usually required and should not return null on valid PDF documents. But where this is a parent form field with
* children, such as radio button collections then the rectangle will be null.
*
* @return The Rect value of this annotation.
*/
public PDRectangle getRectangle() {
COSArray rectArray = (COSArray) dictionary.getDictionaryObject(COSName.RECT);
PDRectangle rectangle = null;
if (rectArray != null) {
if (rectArray.size() == 4 && rectArray.getObject(0) instanceof COSNumber && rectArray.getObject(1) instanceof COSNumber && rectArray.getObject(2) instanceof COSNumber && rectArray.getObject(3) instanceof COSNumber) {
rectangle = new PDRectangle(rectArray);
} else {
Log.w("PdfBox-Android", rectArray + " is not a rectangle array, returning null");
}
}
return rectangle;
}
use of com.tom_roush.pdfbox.cos.COSNumber in project PdfBox-Android by TomRoush.
the class PDFStreamEngine method showTextStrings.
/**
* Called when a string of text with spacing adjustments is to be shown.
*
* @param array array of encoded text strings and adjustments
* @throws IOException if there was an error showing the text
*/
public void showTextStrings(COSArray array) throws IOException {
PDTextState textState = getGraphicsState().getTextState();
float fontSize = textState.getFontSize();
float horizontalScaling = textState.getHorizontalScaling() / 100f;
PDFont font = textState.getFont();
boolean isVertical = false;
if (font != null) {
isVertical = font.isVertical();
}
for (COSBase obj : array) {
if (obj instanceof COSNumber) {
float tj = ((COSNumber) obj).floatValue();
// calculate the combined displacements
float tx;
float ty;
if (isVertical) {
tx = 0;
ty = -tj / 1000 * fontSize;
} else {
tx = -tj / 1000 * fontSize * horizontalScaling;
ty = 0;
}
applyTextAdjustment(tx, ty);
} else if (obj instanceof COSString) {
byte[] string = ((COSString) obj).getBytes();
showText(string);
} else {
throw new IOException("Unknown type in array for TJ operation:" + obj);
}
}
}
use of com.tom_roush.pdfbox.cos.COSNumber in project PdfBox-Android by TomRoush.
the class CurveToReplicateFinalPoint method process.
@Override
public void process(Operator operator, List<COSBase> operands) throws IOException {
if (operands.size() < 4) {
throw new MissingOperandException(operator, operands);
}
if (!checkArrayTypesClass(operands, COSNumber.class)) {
return;
}
COSNumber x1 = (COSNumber) operands.get(0);
COSNumber y1 = (COSNumber) operands.get(1);
COSNumber x3 = (COSNumber) operands.get(2);
COSNumber y3 = (COSNumber) operands.get(3);
PointF point1 = context.transformedPoint(x1.floatValue(), y1.floatValue());
PointF point3 = context.transformedPoint(x3.floatValue(), y3.floatValue());
context.curveTo(point1.x, point1.y, point3.x, point3.y, point3.x, point3.y);
}
use of com.tom_roush.pdfbox.cos.COSNumber in project PdfBox-Android by TomRoush.
the class LineTo method process.
@Override
public void process(Operator operator, List<COSBase> operands) throws IOException {
if (operands.size() < 2) {
throw new MissingOperandException(operator, operands);
}
COSBase base0 = operands.get(0);
if (!(base0 instanceof COSNumber)) {
return;
}
COSBase base1 = operands.get(1);
if (!(base1 instanceof COSNumber)) {
return;
}
// append straight line segment from the current point to the point
COSNumber x = (COSNumber) base0;
COSNumber y = (COSNumber) base1;
PointF pos = context.transformedPoint(x.floatValue(), y.floatValue());
if (context.getCurrentPoint() == null) {
Log.w("PdfBox-Android", "LineTo (" + pos.x + "," + pos.y + ") without initial MoveTo");
context.moveTo(pos.x, pos.y);
} else {
context.lineTo(pos.x, pos.y);
}
}
use of com.tom_roush.pdfbox.cos.COSNumber in project PdfBox-Android by TomRoush.
the class DictionaryEncoding method applyDifferences.
private void applyDifferences() {
// now replace with the differences
COSBase base = encoding.getDictionaryObject(COSName.DIFFERENCES);
if (!(base instanceof COSArray)) {
return;
}
COSArray diffArray = (COSArray) base;
int currentIndex = -1;
for (int i = 0; i < diffArray.size(); i++) {
COSBase next = diffArray.getObject(i);
if (next instanceof COSNumber) {
currentIndex = ((COSNumber) next).intValue();
} else if (next instanceof COSName) {
COSName name = (COSName) next;
overwrite(currentIndex, name.getName());
this.differences.put(currentIndex, name.getName());
currentIndex++;
}
}
}
Aggregations