use of org.apache.pdfbox.cos.COSNumber in project pdfbox by apache.
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<>();
args.add(new COSFloat(-1 * y.floatValue()));
context.processOperator("TL", args);
context.processOperator("Td", arguments);
}
use of org.apache.pdfbox.cos.COSNumber in project pdfbox by apache.
the class MoveTo 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;
}
COSNumber x = (COSNumber) base0;
COSNumber y = (COSNumber) base1;
Point2D.Float pos = context.transformedPoint(x.floatValue(), y.floatValue());
context.moveTo(pos.x, pos.y);
}
use of org.apache.pdfbox.cos.COSNumber in project pdfbox by apache.
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, 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 org.apache.pdfbox.cos.COSNumber in project pdfbox by apache.
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;
Point2D.Float pos = context.transformedPoint(x.floatValue(), y.floatValue());
if (context.getCurrentPoint() == null) {
LOG.warn("LineTo (" + pos.x + "," + pos.y + ") without initial MoveTo");
context.moveTo(pos.x, pos.y);
} else {
context.lineTo(pos.x, pos.y);
}
}
use of org.apache.pdfbox.cos.COSNumber in project pdfbox by apache.
the class CurveTo method process.
@Override
public void process(Operator operator, List<COSBase> operands) throws IOException {
if (operands.size() < 6) {
throw new MissingOperandException(operator, operands);
}
if (!checkArrayTypesClass(operands, COSNumber.class)) {
return;
}
COSNumber x1 = (COSNumber) operands.get(0);
COSNumber y1 = (COSNumber) operands.get(1);
COSNumber x2 = (COSNumber) operands.get(2);
COSNumber y2 = (COSNumber) operands.get(3);
COSNumber x3 = (COSNumber) operands.get(4);
COSNumber y3 = (COSNumber) operands.get(5);
Point2D.Float point1 = context.transformedPoint(x1.floatValue(), y1.floatValue());
Point2D.Float point2 = context.transformedPoint(x2.floatValue(), y2.floatValue());
Point2D.Float point3 = context.transformedPoint(x3.floatValue(), y3.floatValue());
if (context.getCurrentPoint() == null) {
LOG.warn("curveTo (" + point3.x + "," + point3.y + ") without initial MoveTo");
context.moveTo(point3.x, point3.y);
} else {
context.curveTo(point1.x, point1.y, point2.x, point2.y, point3.x, point3.y);
}
}
Aggregations