add global transformation to all elements that can render at absolute positions

This commit is contained in:
Jörg Prante 2022-01-24 17:42:09 +01:00
parent b85fd84abd
commit 10afc65dff
41 changed files with 211 additions and 176 deletions

View file

@ -7,6 +7,7 @@ import org.apache.pdfbox.util.Matrix;
import org.xbib.graphics.barcode.Symbol; import org.xbib.graphics.barcode.Symbol;
import org.xbib.graphics.barcode.render.BarcodeGraphicsRenderer; import org.xbib.graphics.barcode.render.BarcodeGraphicsRenderer;
import org.xbib.graphics.pdfbox.PdfBoxGraphics2D; import org.xbib.graphics.pdfbox.PdfBoxGraphics2D;
import org.xbib.graphics.pdfbox.layout.element.render.Transform;
import org.xbib.graphics.pdfbox.layout.text.DrawListener; import org.xbib.graphics.pdfbox.layout.text.DrawListener;
import org.xbib.graphics.pdfbox.layout.position.Position; import org.xbib.graphics.pdfbox.layout.position.Position;
import org.xbib.graphics.pdfbox.layout.text.WidthRespecting; import org.xbib.graphics.pdfbox.layout.text.WidthRespecting;
@ -116,6 +117,7 @@ public class BarcodeElement implements Element, Drawable, Dividable, WidthRespec
public void draw(PDDocument pdDocument, public void draw(PDDocument pdDocument,
PDPageContentStream contentStream, PDPageContentStream contentStream,
Position upperLeft, Position upperLeft,
Transform transform,
DrawListener drawListener) throws IOException { DrawListener drawListener) throws IOException {
float x = upperLeft.getX(); float x = upperLeft.getX();
float y = upperLeft.getY() - getHeight(); float y = upperLeft.getY() - getHeight();
@ -127,6 +129,9 @@ public class BarcodeElement implements Element, Drawable, Dividable, WidthRespec
PDFormXObject xFormObject = pdfBoxGraphics2D.getXFormObject(); PDFormXObject xFormObject = pdfBoxGraphics2D.getXFormObject();
Matrix matrix = new Matrix(); Matrix matrix = new Matrix();
matrix.translate(x, y); matrix.translate(x, y);
if (transform != null) {
matrix = matrix.multiply(transform.getMatrix());
}
contentStream.saveGraphicsState(); contentStream.saveGraphicsState();
contentStream.transform(matrix); contentStream.transform(matrix);
contentStream.drawForm(xFormObject); contentStream.drawForm(xFormObject);

View file

@ -7,6 +7,7 @@ import org.apache.pdfbox.util.Matrix;
import org.xbib.graphics.chart.QuickChart; import org.xbib.graphics.chart.QuickChart;
import org.xbib.graphics.chart.xy.XYChart; import org.xbib.graphics.chart.xy.XYChart;
import org.xbib.graphics.pdfbox.PdfBoxGraphics2D; import org.xbib.graphics.pdfbox.PdfBoxGraphics2D;
import org.xbib.graphics.pdfbox.layout.element.render.Transform;
import org.xbib.graphics.pdfbox.layout.text.DrawListener; import org.xbib.graphics.pdfbox.layout.text.DrawListener;
import org.xbib.graphics.pdfbox.layout.position.Position; import org.xbib.graphics.pdfbox.layout.position.Position;
import org.xbib.graphics.pdfbox.layout.text.WidthRespecting; import org.xbib.graphics.pdfbox.layout.text.WidthRespecting;
@ -16,8 +17,6 @@ import java.io.IOException;
public class ChartElement implements Element, Drawable, Dividable, WidthRespecting { public class ChartElement implements Element, Drawable, Dividable, WidthRespecting {
String chartTitle;
private double[] xData; private double[] xData;
private double[] yData; private double[] yData;
@ -108,6 +107,7 @@ public class ChartElement implements Element, Drawable, Dividable, WidthRespecti
public void draw(PDDocument pdDocument, public void draw(PDDocument pdDocument,
PDPageContentStream contentStream, PDPageContentStream contentStream,
Position upperLeft, Position upperLeft,
Transform transform,
DrawListener drawListener) throws IOException { DrawListener drawListener) throws IOException {
float x = upperLeft.getX(); float x = upperLeft.getX();
float y = upperLeft.getY() - getHeight(); float y = upperLeft.getY() - getHeight();
@ -120,6 +120,9 @@ public class ChartElement implements Element, Drawable, Dividable, WidthRespecti
Matrix matrix = new Matrix(); Matrix matrix = new Matrix();
matrix.translate(x, y); matrix.translate(x, y);
matrix.scale(scaleX, scaleY); matrix.scale(scaleX, scaleY);
if (transform != null) {
matrix = matrix.multiply(transform.getMatrix());
}
contentStream.saveGraphicsState(); contentStream.saveGraphicsState();
contentStream.transform(matrix); contentStream.transform(matrix);
contentStream.drawForm(xFormObject); contentStream.drawForm(xFormObject);

View file

@ -2,6 +2,7 @@ package org.xbib.graphics.pdfbox.layout.element;
import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPageContentStream; import org.apache.pdfbox.pdmodel.PDPageContentStream;
import org.xbib.graphics.pdfbox.layout.element.render.Transform;
import org.xbib.graphics.pdfbox.layout.text.DrawListener; import org.xbib.graphics.pdfbox.layout.text.DrawListener;
import org.xbib.graphics.pdfbox.layout.position.Position; import org.xbib.graphics.pdfbox.layout.position.Position;
import java.io.IOException; import java.io.IOException;
@ -52,9 +53,9 @@ public class Cutter implements Dividable, Drawable {
@Override @Override
public void draw(PDDocument pdDocument, PDPageContentStream contentStream, public void draw(PDDocument pdDocument, PDPageContentStream contentStream,
Position upperLeft, DrawListener drawListener) throws IOException { Position upperLeft, Transform transform, DrawListener drawListener) throws IOException {
Position viewPortOrigin = upperLeft.add(0, -viewPortY); Position viewPortOrigin = upperLeft.add(0, -viewPortY);
undividable.draw(pdDocument, contentStream, viewPortOrigin, drawListener); undividable.draw(pdDocument, contentStream, viewPortOrigin, transform, drawListener);
} }
@Override @Override

View file

@ -3,6 +3,7 @@ package org.xbib.graphics.pdfbox.layout.element;
import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPageContentStream; import org.apache.pdfbox.pdmodel.PDPageContentStream;
import org.xbib.graphics.pdfbox.layout.element.render.Layout; import org.xbib.graphics.pdfbox.layout.element.render.Layout;
import org.xbib.graphics.pdfbox.layout.element.render.Transform;
import org.xbib.graphics.pdfbox.layout.text.DrawListener; import org.xbib.graphics.pdfbox.layout.text.DrawListener;
import org.xbib.graphics.pdfbox.layout.position.Position; import org.xbib.graphics.pdfbox.layout.position.Position;
import java.io.IOException; import java.io.IOException;
@ -39,13 +40,14 @@ public interface Drawable {
* @param pdDocument the underlying pdfbox document. * @param pdDocument the underlying pdfbox document.
* @param contentStream the stream to draw to. * @param contentStream the stream to draw to.
* @param upperLeft the upper left position to start drawing. * @param upperLeft the upper left position to start drawing.
* @param transform the transformation for drawing.
* @param drawListener the listener to * @param drawListener the listener to
* {@link DrawListener#drawn(Object, Position, float, float) notify} on * {@link DrawListener#drawn(Object, Position, float, float) notify} on
* drawn objects. * drawn objects.
* @throws IOException by pdfbox * @throws IOException if draw fails
*/ */
void draw(PDDocument pdDocument, PDPageContentStream contentStream, void draw(PDDocument pdDocument, PDPageContentStream contentStream,
Position upperLeft, DrawListener drawListener) throws IOException; Position upperLeft, Transform transform, DrawListener drawListener) throws IOException;
/** /**
* @return a copy of this drawable where any leading empty vertical space is * @return a copy of this drawable where any leading empty vertical space is

View file

@ -2,6 +2,7 @@ package org.xbib.graphics.pdfbox.layout.element;
import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPageContentStream; import org.apache.pdfbox.pdmodel.PDPageContentStream;
import org.xbib.graphics.pdfbox.layout.element.render.Transform;
import org.xbib.graphics.pdfbox.layout.shape.Rect; import org.xbib.graphics.pdfbox.layout.shape.Rect;
import org.xbib.graphics.pdfbox.layout.shape.Shape; import org.xbib.graphics.pdfbox.layout.shape.Shape;
import org.xbib.graphics.pdfbox.layout.shape.Stroke; import org.xbib.graphics.pdfbox.layout.shape.Stroke;
@ -510,7 +511,7 @@ public class Frame implements Element, Drawable, WidthRespecting, Dividable {
@Override @Override
public void draw(PDDocument pdDocument, PDPageContentStream contentStream, public void draw(PDDocument pdDocument, PDPageContentStream contentStream,
Position upperLeft, DrawListener drawListener) throws IOException { Position upperLeft, Transform transform, DrawListener drawListener) throws IOException {
setInnerMaxWidthIfNecessary(); setInnerMaxWidthIfNecessary();
float halfBorderWidth = 0; float halfBorderWidth = 0;
if (getBorderWidth() > 0) { if (getBorderWidth() > 0) {
@ -521,19 +522,19 @@ public class Frame implements Element, Drawable, WidthRespecting, Dividable {
float shapeWidth = getWidth() - getMarginLeft() - getMarginRight() - getBorderWidth(); float shapeWidth = getWidth() - getMarginLeft() - getMarginRight() - getBorderWidth();
float shapeHeight = getHeight() - getMarginTop() - getMarginBottom() - getBorderWidth(); float shapeHeight = getHeight() - getMarginTop() - getMarginBottom() - getBorderWidth();
if (getBackgroundColor() != null) { if (getBackgroundColor() != null) {
getShape().fill(pdDocument, contentStream, upperLeft, getShape().fill(pdDocument, contentStream, upperLeft, transform,
shapeWidth, shapeHeight, getBackgroundColor(), shapeWidth, shapeHeight, getBackgroundColor(),
drawListener); drawListener);
} }
if (hasBorder()) { if (hasBorder()) {
getShape().draw(pdDocument, contentStream, upperLeft, getShape().draw(pdDocument, contentStream, upperLeft, transform,
shapeWidth, shapeHeight, getBorderColor(), shapeWidth, shapeHeight, getBorderColor(),
getBorderStroke(), drawListener); getBorderStroke(), drawListener);
} }
} }
Position innerUpperLeft = upperLeft.add(getPaddingLeft() + halfBorderWidth, -getPaddingTop() - halfBorderWidth); Position innerUpperLeft = upperLeft.add(getPaddingLeft() + halfBorderWidth, -getPaddingTop() - halfBorderWidth);
for (Drawable inner : innerList) { for (Drawable inner : innerList) {
inner.draw(pdDocument, contentStream, innerUpperLeft, drawListener); inner.draw(pdDocument, contentStream, innerUpperLeft, transform, drawListener);
innerUpperLeft = innerUpperLeft.add(0, -inner.getHeight()); innerUpperLeft = innerUpperLeft.add(0, -inner.getHeight());
} }
} }

View file

@ -2,6 +2,7 @@ package org.xbib.graphics.pdfbox.layout.element;
import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPageContentStream; import org.apache.pdfbox.pdmodel.PDPageContentStream;
import org.xbib.graphics.pdfbox.layout.element.render.Transform;
import org.xbib.graphics.pdfbox.layout.shape.Stroke; import org.xbib.graphics.pdfbox.layout.shape.Stroke;
import org.xbib.graphics.pdfbox.layout.text.DrawListener; import org.xbib.graphics.pdfbox.layout.text.DrawListener;
import org.xbib.graphics.pdfbox.layout.position.Position; import org.xbib.graphics.pdfbox.layout.position.Position;
@ -81,8 +82,11 @@ public class HorizontalRuler implements Drawable, Element, WidthRespecting {
} }
@Override @Override
public void draw(PDDocument pdDocument, PDPageContentStream contentStream, public void draw(PDDocument pdDocument,
Position upperLeft, DrawListener drawListener) throws IOException { PDPageContentStream contentStream,
Position upperLeft,
Transform transform,
DrawListener drawListener) throws IOException {
if (getColor() != null) { if (getColor() != null) {
contentStream.setStrokingColor(getColor()); contentStream.setStrokingColor(getColor());
} }

View file

@ -4,6 +4,7 @@ import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPageContentStream; import org.apache.pdfbox.pdmodel.PDPageContentStream;
import org.apache.pdfbox.pdmodel.graphics.image.LosslessFactory; import org.apache.pdfbox.pdmodel.graphics.image.LosslessFactory;
import org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject; import org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject;
import org.xbib.graphics.pdfbox.layout.element.render.Transform;
import org.xbib.graphics.pdfbox.layout.text.DrawListener; import org.xbib.graphics.pdfbox.layout.text.DrawListener;
import org.xbib.graphics.pdfbox.layout.position.Position; import org.xbib.graphics.pdfbox.layout.position.Position;
import org.xbib.graphics.pdfbox.layout.text.WidthRespecting; import org.xbib.graphics.pdfbox.layout.text.WidthRespecting;
@ -144,11 +145,18 @@ public class ImageElement implements Element, Drawable, Dividable, WidthRespecti
@Override @Override
public void draw(PDDocument pdDocument, PDPageContentStream contentStream, public void draw(PDDocument pdDocument, PDPageContentStream contentStream,
Position upperLeft, DrawListener drawListener) throws IOException { Position upperLeft,
Transform transform,
DrawListener drawListener) throws IOException {
float x = upperLeft.getX(); float x = upperLeft.getX();
float y = upperLeft.getY() - getHeight(); float y = upperLeft.getY() - getHeight();
PDImageXObject imageXObject = LosslessFactory.createFromImage(pdDocument, image); PDImageXObject imageXObject = LosslessFactory.createFromImage(pdDocument, image);
contentStream.saveGraphicsState();
if (transform != null) {
contentStream.transform(transform.getMatrix());
}
contentStream.drawImage(imageXObject, x, y, getWidth(), getHeight()); contentStream.drawImage(imageXObject, x, y, getWidth(), getHeight());
contentStream.restoreGraphicsState();
if (drawListener != null) { if (drawListener != null) {
drawListener.drawn(this, upperLeft, getWidth(), getHeight()); drawListener.drawn(this, upperLeft, getWidth(), getHeight());
} }

View file

@ -2,6 +2,7 @@ package org.xbib.graphics.pdfbox.layout.element;
import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPageContentStream; import org.apache.pdfbox.pdmodel.PDPageContentStream;
import org.xbib.graphics.pdfbox.layout.element.render.Transform;
import org.xbib.graphics.pdfbox.layout.text.Alignment; import org.xbib.graphics.pdfbox.layout.text.Alignment;
import org.xbib.graphics.pdfbox.layout.text.DrawListener; import org.xbib.graphics.pdfbox.layout.text.DrawListener;
import org.xbib.graphics.pdfbox.layout.position.Position; import org.xbib.graphics.pdfbox.layout.position.Position;
@ -53,8 +54,8 @@ public class Paragraph extends TextFlow implements Drawable, Element, WidthRespe
@Override @Override
public void draw(PDDocument pdDocument, PDPageContentStream contentStream, public void draw(PDDocument pdDocument, PDPageContentStream contentStream,
Position upperLeft, DrawListener drawListener) { Position upperLeft, Transform transform, DrawListener drawListener) {
drawText(contentStream, upperLeft, getAlignment(), drawListener); drawText(contentStream, upperLeft, transform, getAlignment(), drawListener);
} }
@Override @Override
@ -70,8 +71,8 @@ public class Paragraph extends TextFlow implements Drawable, Element, WidthRespe
@Override @Override
public Paragraph removeLeadingEmptyLines() { public Paragraph removeLeadingEmptyLines() {
Paragraph result = (Paragraph) super.removeLeadingEmptyLines(); Paragraph result = (Paragraph) super.removeLeadingEmptyLines();
result.setAbsolutePosition(this.getAbsolutePosition()); result.setAbsolutePosition(getAbsolutePosition());
result.setAlignment(this.getAlignment()); result.setAlignment(getAlignment());
return result; return result;
} }

View file

@ -2,6 +2,7 @@ package org.xbib.graphics.pdfbox.layout.element;
import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPageContentStream; import org.apache.pdfbox.pdmodel.PDPageContentStream;
import org.xbib.graphics.pdfbox.layout.element.render.Transform;
import org.xbib.graphics.pdfbox.layout.shape.Path; import org.xbib.graphics.pdfbox.layout.shape.Path;
import org.xbib.graphics.pdfbox.layout.shape.Stroke; import org.xbib.graphics.pdfbox.layout.shape.Stroke;
import org.xbib.graphics.pdfbox.layout.text.DrawListener; import org.xbib.graphics.pdfbox.layout.text.DrawListener;
@ -67,8 +68,9 @@ public class PathElement implements Drawable, Element {
public void draw(PDDocument pdDocument, public void draw(PDDocument pdDocument,
PDPageContentStream contentStream, PDPageContentStream contentStream,
Position upperLeft, Position upperLeft,
Transform transform,
DrawListener drawListener) throws IOException { DrawListener drawListener) throws IOException {
path.draw(pdDocument, contentStream, upperLeft, getWidth(), getHeight(), path.draw(pdDocument, contentStream, upperLeft, transform, getWidth(), getHeight(),
color, stroke, drawListener); color, stroke, drawListener);
} }

View file

@ -1,14 +1,5 @@
package org.xbib.graphics.pdfbox.layout.element; package org.xbib.graphics.pdfbox.layout.element;
/*
import io.sf.carte.echosvg.anim.dom.SAXSVGDocumentFactory;
import io.sf.carte.echosvg.bridge.BridgeContext;
import io.sf.carte.echosvg.bridge.DocumentLoader;
import io.sf.carte.echosvg.bridge.GVTBuilder;
import io.sf.carte.echosvg.bridge.UserAgent;
import io.sf.carte.echosvg.bridge.UserAgentAdapter;
import io.sf.carte.echosvg.gvt.GraphicsNode;
*/
import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPageContentStream; import org.apache.pdfbox.pdmodel.PDPageContentStream;
import org.apache.pdfbox.pdmodel.graphics.form.PDFormXObject; import org.apache.pdfbox.pdmodel.graphics.form.PDFormXObject;
@ -18,6 +9,7 @@ import org.xbib.graphics.pdfbox.color.DefaultColorMapper;
import org.xbib.graphics.pdfbox.color.RGBtoCMYKColorMapper; import org.xbib.graphics.pdfbox.color.RGBtoCMYKColorMapper;
import org.xbib.graphics.pdfbox.font.DefaultFontDrawer; import org.xbib.graphics.pdfbox.font.DefaultFontDrawer;
import org.xbib.graphics.pdfbox.font.FontDrawer; import org.xbib.graphics.pdfbox.font.FontDrawer;
import org.xbib.graphics.pdfbox.layout.element.render.Transform;
import org.xbib.graphics.pdfbox.layout.text.DrawListener; import org.xbib.graphics.pdfbox.layout.text.DrawListener;
import org.xbib.graphics.pdfbox.layout.position.Position; import org.xbib.graphics.pdfbox.layout.position.Position;
@ -34,8 +26,11 @@ public class SVGElement extends ImageElement {
} }
@Override @Override
public void draw(PDDocument pdDocument, PDPageContentStream contentStream, public void draw(PDDocument pdDocument,
Position upperLeft, DrawListener drawListener) throws IOException { PDPageContentStream contentStream,
Position upperLeft,
Transform transform,
DrawListener drawListener) throws IOException {
if (svg == null) { if (svg == null) {
return; return;
} }
@ -54,6 +49,9 @@ public class SVGElement extends ImageElement {
PDFormXObject xFormObject = pdfBoxGraphics2D.getXFormObject(); PDFormXObject xFormObject = pdfBoxGraphics2D.getXFormObject();
Matrix matrix = new Matrix(); Matrix matrix = new Matrix();
matrix.translate(x, y); matrix.translate(x, y);
if (transform != null) {
matrix = matrix.multiply(transform.getMatrix());
}
contentStream.saveGraphicsState(); contentStream.saveGraphicsState();
contentStream.transform(matrix); contentStream.transform(matrix);
contentStream.drawForm(xFormObject); contentStream.drawForm(xFormObject);
@ -67,20 +65,4 @@ public class SVGElement extends ImageElement {
public Drawable removeLeadingEmptyVerticalSpace() { public Drawable removeLeadingEmptyVerticalSpace() {
return this; return this;
} }
/*private GraphicsNode load(String svg) throws IOException {
try {
XMLReader xmlReader = SAXParserFactory.newDefaultInstance().newSAXParser().getXMLReader();
SAXSVGDocumentFactory documentFactory = new SAXSVGDocumentFactory(xmlReader);
Document document = documentFactory.createDocument(null, new StringReader(svg));
UserAgent userAgent = new UserAgentAdapter();
DocumentLoader documentLoader = new DocumentLoader(userAgent);
BridgeContext bridgeContext = new BridgeContext(userAgent, documentLoader);
bridgeContext.setDynamicState(BridgeContext.STATIC);
GVTBuilder gvtBuilder = new GVTBuilder();
return gvtBuilder.build(bridgeContext, document);
} catch (Exception e) {
throw new IOException(e);
}
}*/
} }

View file

@ -2,6 +2,7 @@ package org.xbib.graphics.pdfbox.layout.element;
import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPageContentStream; import org.apache.pdfbox.pdmodel.PDPageContentStream;
import org.xbib.graphics.pdfbox.layout.element.render.Transform;
import org.xbib.graphics.pdfbox.layout.table.BorderStyleInterface; import org.xbib.graphics.pdfbox.layout.table.BorderStyleInterface;
import org.xbib.graphics.pdfbox.layout.table.HorizontalAlignment; import org.xbib.graphics.pdfbox.layout.table.HorizontalAlignment;
import org.xbib.graphics.pdfbox.layout.table.Row; import org.xbib.graphics.pdfbox.layout.table.Row;
@ -103,7 +104,7 @@ public class TableElement implements Element, Drawable, Dividable {
@Override @Override
public void draw(PDDocument pdDocument, PDPageContentStream contentStream, public void draw(PDDocument pdDocument, PDPageContentStream contentStream,
Position upperLeft, DrawListener drawListener) throws IOException { Position upperLeft, Transform transform, DrawListener drawListener) throws IOException {
TableRenderer tableRenderer = TableRenderer.builder() TableRenderer tableRenderer = TableRenderer.builder()
.table(table.build()) .table(table.build())
.document(pdDocument) .document(pdDocument)

View file

@ -17,12 +17,12 @@ public class TransformElement implements Transform {
private Float scaleY; private Float scaleY;
private Float angle;
private Float rotateX; private Float rotateX;
private Float rotateY; private Float rotateY;
private Float angle;
public void setTranslate(Float x, Float y) { public void setTranslate(Float x, Float y) {
this.translateX = x; this.translateX = x;
this.translateY = y; this.translateY = y;
@ -39,44 +39,26 @@ public class TransformElement implements Transform {
this.rotateY = rotateY; this.rotateY = rotateY;
} }
public Float getAngle() { @Override
return angle; public Matrix getMatrix() {
} Matrix matrix = new Matrix();
if (angle != null && rotateX != null && rotateY != null) {
public Float getRotateX() { matrix = matrix.multiply(Matrix.getRotateInstance(Math.toRadians(angle), rotateX, rotateY));
return rotateX; }
} if (scaleX != null && scaleY != null) {
matrix = matrix.multiply(Matrix.getScaleInstance(scaleX, scaleY));
public Float getRotateY() { }
return rotateY; if (translateX != null && translateY != null) {
} matrix = matrix.multiply(Matrix.getTranslateInstance(translateX, translateY));
}
public Float getScaleX() { return matrix;
return scaleX;
}
public Float getScaleY() {
return scaleY;
}
public Float getTranslateX() {
return translateX;
}
public Float getTranslateY() {
return translateY;
} }
@Override @Override
public boolean render(RenderContext renderContext, Element element, LayoutHint layoutHint) throws IOException { public boolean render(RenderContext renderContext, Element element, LayoutHint layoutHint) throws IOException {
if (translateX != null && translateY != null) { Matrix matrix = getMatrix();
renderContext.getCurrentPageContentStream().transform(Matrix.getTranslateInstance(translateX, translateY)); if (matrix != null) {
} renderContext.getCurrentPageContentStream().transform(matrix);
if (scaleX != null && scaleY != null) {
renderContext.getCurrentPageContentStream().transform(Matrix.getScaleInstance(scaleX, scaleY));
}
if (angle != null && rotateX != null && rotateY != null){
renderContext.getCurrentPageContentStream().transform(Matrix.getRotateInstance(Math.toRadians(angle), rotateX, rotateY));
} }
return true; return true;
} }

View file

@ -2,6 +2,7 @@ package org.xbib.graphics.pdfbox.layout.element;
import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPageContentStream; import org.apache.pdfbox.pdmodel.PDPageContentStream;
import org.xbib.graphics.pdfbox.layout.element.render.Transform;
import org.xbib.graphics.pdfbox.layout.text.DrawListener; import org.xbib.graphics.pdfbox.layout.text.DrawListener;
import org.xbib.graphics.pdfbox.layout.position.Position; import org.xbib.graphics.pdfbox.layout.position.Position;
import java.io.IOException; import java.io.IOException;
@ -40,7 +41,7 @@ public class VerticalSpacer implements Drawable, Element, Dividable {
@Override @Override
public void draw(PDDocument pdDocument, PDPageContentStream contentStream, public void draw(PDDocument pdDocument, PDPageContentStream contentStream,
Position upperLeft, DrawListener drawListener) throws IOException { Position upperLeft, Transform transform, DrawListener drawListener) throws IOException {
if (drawListener != null) { if (drawListener != null) {
drawListener.drawn(this, upperLeft, getWidth(), getHeight()); drawListener.drawn(this, upperLeft, getWidth(), getHeight());
} }

View file

@ -3,6 +3,7 @@ package org.xbib.graphics.pdfbox.layout.element.render;
import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.pdmodel.PDPageContentStream; import org.apache.pdfbox.pdmodel.PDPageContentStream;
import org.apache.pdfbox.util.Matrix;
import org.xbib.graphics.pdfbox.layout.element.ControlElement; import org.xbib.graphics.pdfbox.layout.element.ControlElement;
import org.xbib.graphics.pdfbox.layout.element.Document; import org.xbib.graphics.pdfbox.layout.element.Document;
import org.xbib.graphics.pdfbox.layout.element.Element; import org.xbib.graphics.pdfbox.layout.element.Element;
@ -260,6 +261,7 @@ public class RenderContext implements Renderer, Closeable, DrawContext, DrawList
} }
if (element instanceof Transform) { if (element instanceof Transform) {
setTransform((Transform) element); setTransform((Transform) element);
return true;
} }
return false; return false;
} }
@ -305,6 +307,14 @@ public class RenderContext implements Renderer, Closeable, DrawContext, DrawList
this.contentStream = new PDPageContentStream(pdDocument, page, this.contentStream = new PDPageContentStream(pdDocument, page,
PDPageContentStream.AppendMode.APPEND, true); PDPageContentStream.AppendMode.APPEND, true);
if (getPageOrientation() != getPageFormat().getOrientation()) { if (getPageOrientation() != getPageFormat().getOrientation()) {
if (page.getRotation() == 90 || page.getRotation() == 270) {
page.setRotation(0);
} else {
page.setRotation(90);
}
}
if (page.getRotation() == 90 || page.getRotation() == 270) {
contentStream.transform(new Matrix(0, 1, -1, 0, getPageHeight(), 0));
page.setRotation(90); page.setRotation(90);
} }
resetPositionToUpperLeft(); resetPositionToUpperLeft();

View file

@ -1,6 +1,9 @@
package org.xbib.graphics.pdfbox.layout.element.render; package org.xbib.graphics.pdfbox.layout.element.render;
import org.apache.pdfbox.util.Matrix;
import org.xbib.graphics.pdfbox.layout.element.Element; import org.xbib.graphics.pdfbox.layout.element.Element;
public interface Transform extends Element, Renderer { public interface Transform extends Element, Renderer {
Matrix getMatrix();
} }

View file

@ -91,8 +91,11 @@ public class VerticalLayout implements Layout {
* @throws IOException by pdfbox * @throws IOException by pdfbox
*/ */
protected void renderAbsolute(RenderContext renderContext, Drawable drawable) throws IOException { protected void renderAbsolute(RenderContext renderContext, Drawable drawable) throws IOException {
drawable.draw(renderContext.getPdDocument(), renderContext.getCurrentPageContentStream(), drawable.draw(renderContext.getPdDocument(),
drawable.getAbsolutePosition(), renderContext); renderContext.getCurrentPageContentStream(),
drawable.getAbsolutePosition(),
renderContext.getTransform(),
renderContext);
} }
/** /**
@ -223,7 +226,7 @@ public class VerticalLayout implements Layout {
renderContext.getPageWidth(), renderContext.getHeight()); renderContext.getPageWidth(), renderContext.getHeight());
contentStream.clip(); contentStream.clip();
drawable.draw(renderContext.getPdDocument(), contentStream, drawable.draw(renderContext.getPdDocument(), contentStream,
renderContext.getCurrentPosition().add(offsetX, 0), renderContext); renderContext.getCurrentPosition().add(offsetX, 0), null, renderContext);
contentStream.restoreGraphicsState(); contentStream.restoreGraphicsState();
if (movePosition) { if (movePosition) {
renderContext.movePositionBy(0, -drawable.getHeight()); renderContext.movePositionBy(0, -drawable.getHeight());

View file

@ -2,7 +2,6 @@ package org.xbib.graphics.pdfbox.layout.element.scripting.command;
import java.io.IOException; import java.io.IOException;
import org.xbib.graphics.pdfbox.layout.element.TransformElement; import org.xbib.graphics.pdfbox.layout.element.TransformElement;
import org.xbib.graphics.pdfbox.layout.element.render.LayoutHint;
import org.xbib.graphics.pdfbox.layout.element.scripting.Engine; import org.xbib.graphics.pdfbox.layout.element.scripting.Engine;
import org.xbib.graphics.pdfbox.layout.element.scripting.State; import org.xbib.graphics.pdfbox.layout.element.scripting.State;
import org.xbib.settings.Settings; import org.xbib.settings.Settings;
@ -23,6 +22,6 @@ public class TransformCommand implements Command {
if (settings.containsSetting("angle") && settings.containsSetting("rotatex") && settings.containsSetting("rotatey")) { if (settings.containsSetting("angle") && settings.containsSetting("rotatex") && settings.containsSetting("rotatey")) {
element.setRotate(settings.getAsFloat("angle", null), mmToPt(settings.getAsFloat("rotatex", null)), mmToPt(settings.getAsFloat("rotatey", null))); element.setRotate(settings.getAsFloat("angle", null), mmToPt(settings.getAsFloat("rotatex", null)), mmToPt(settings.getAsFloat("rotatey", null)));
} }
state.elements.peek().add(element, LayoutHint.NOP); state.elements.peek().add(element);
} }
} }

View file

@ -2,6 +2,7 @@ package org.xbib.graphics.pdfbox.layout.shape;
import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPageContentStream; import org.apache.pdfbox.pdmodel.PDPageContentStream;
import org.xbib.graphics.pdfbox.layout.element.render.Transform;
import org.xbib.graphics.pdfbox.layout.text.DrawListener; import org.xbib.graphics.pdfbox.layout.text.DrawListener;
import org.xbib.graphics.pdfbox.layout.position.Position; import org.xbib.graphics.pdfbox.layout.position.Position;
import java.awt.Color; import java.awt.Color;
@ -9,16 +10,16 @@ import java.io.IOException;
/** /**
* Abstract base class for shapes which performs the * Abstract base class for shapes which performs the
* {@link #fill(PDDocument, PDPageContentStream, Position, float, float, Color, DrawListener)} * {@link #fill(PDDocument, PDPageContentStream, Position, Transform, float, float, Color, DrawListener)}
* and {@link #draw(PDDocument, PDPageContentStream, Position, float, float, Color, Stroke, DrawListener)} * and {@link #draw(PDDocument, PDPageContentStream, Position, Transform, float, float, Color, Stroke, DrawListener)}
*/ */
public abstract class AbstractShape implements Shape { public abstract class AbstractShape implements Shape {
@Override @Override
public void draw(PDDocument pdDocument, PDPageContentStream contentStream, public void draw(PDDocument pdDocument, PDPageContentStream contentStream,
Position upperLeft, float width, float height, Color color, Position upperLeft, Transform transform, float width, float height, Color color,
Stroke stroke, DrawListener drawListener) throws IOException { Stroke stroke, DrawListener drawListener) throws IOException {
add(pdDocument, contentStream, upperLeft, width, height); add(pdDocument, contentStream, upperLeft, transform, width, height);
if (stroke != null) { if (stroke != null) {
stroke.applyTo(contentStream); stroke.applyTo(contentStream);
} }
@ -33,9 +34,9 @@ public abstract class AbstractShape implements Shape {
@Override @Override
public void fill(PDDocument pdDocument, PDPageContentStream contentStream, public void fill(PDDocument pdDocument, PDPageContentStream contentStream,
Position upperLeft, float width, float height, Color color, Position upperLeft, Transform transform, float width, float height, Color color,
DrawListener drawListener) throws IOException { DrawListener drawListener) throws IOException {
add(pdDocument, contentStream, upperLeft, width, height); add(pdDocument, contentStream, upperLeft, transform, width, height);
if (color != null) { if (color != null) {
contentStream.setNonStrokingColor(color); contentStream.setNonStrokingColor(color);
} }

View file

@ -1,6 +1,7 @@
package org.xbib.graphics.pdfbox.layout.shape; package org.xbib.graphics.pdfbox.layout.shape;
import org.apache.pdfbox.pdmodel.PDPageContentStream; import org.apache.pdfbox.pdmodel.PDPageContentStream;
import org.xbib.graphics.pdfbox.layout.element.render.Transform;
import org.xbib.graphics.pdfbox.layout.position.Position; import org.xbib.graphics.pdfbox.layout.position.Position;
import java.io.IOException; import java.io.IOException;
@ -15,8 +16,8 @@ public class Ellipse extends RoundRect {
@Override @Override
protected void addRoundRect(PDPageContentStream contentStream, protected void addRoundRect(PDPageContentStream contentStream,
Position upperLeft, float width, float height, float cornerRadiusX, Position upperLeft, Transform transform, float width, float height, float cornerRadiusX,
float cornerRadiusY) throws IOException { float cornerRadiusY) throws IOException {
super.addRoundRect(contentStream, upperLeft, width, height, width / 2f, height / 2); super.addRoundRect(contentStream, upperLeft, transform, width, height, width / 2f, height / 2);
} }
} }

View file

@ -2,6 +2,7 @@ package org.xbib.graphics.pdfbox.layout.shape;
import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPageContentStream; import org.apache.pdfbox.pdmodel.PDPageContentStream;
import org.xbib.graphics.pdfbox.layout.element.render.Transform;
import org.xbib.graphics.pdfbox.layout.position.LinePosiiton; import org.xbib.graphics.pdfbox.layout.position.LinePosiiton;
import org.xbib.graphics.pdfbox.layout.position.MovePosition; import org.xbib.graphics.pdfbox.layout.position.MovePosition;
import org.xbib.graphics.pdfbox.layout.text.DrawListener; import org.xbib.graphics.pdfbox.layout.text.DrawListener;
@ -23,13 +24,17 @@ public class Path implements Shape {
public void draw(PDDocument pdDocument, public void draw(PDDocument pdDocument,
PDPageContentStream contentStream, PDPageContentStream contentStream,
Position upperLeft, Position upperLeft,
Transform transform,
float width, float width,
float height, float height,
Color color, Color color,
Stroke stroke, Stroke stroke,
DrawListener drawListener) throws IOException { DrawListener drawListener) throws IOException {
add(pdDocument, contentStream, upperLeft, width, height); add(pdDocument, contentStream, upperLeft, transform, width, height);
contentStream.saveGraphicsState(); contentStream.saveGraphicsState();
if (transform != null) {
contentStream.transform(transform.getMatrix());
}
float x = upperLeft.getX(); float x = upperLeft.getX();
float y = upperLeft.getY() - stroke.getLineWidth() / 2; float y = upperLeft.getY() - stroke.getLineWidth() / 2;
contentStream.setStrokingColor(color); contentStream.setStrokingColor(color);
@ -50,13 +55,13 @@ public class Path implements Shape {
@Override @Override
public void fill(PDDocument pdDocument, PDPageContentStream contentStream, Position upperLeft, public void fill(PDDocument pdDocument, PDPageContentStream contentStream, Position upperLeft,
float width, float height, Color color, DrawListener drawListener) throws IOException { Transform transform, float width, float height, Color color, DrawListener drawListener) throws IOException {
// do not fill // do not fill
} }
@Override @Override
public void add(PDDocument pdDocument, PDPageContentStream contentStream, Position upperLeft, public void add(PDDocument pdDocument, PDPageContentStream contentStream, Position upperLeft,
float width, float height) throws IOException { Transform transform, float width, float height) throws IOException {
// do nothing // do nothing
} }
} }

View file

@ -2,6 +2,7 @@ package org.xbib.graphics.pdfbox.layout.shape;
import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPageContentStream; import org.apache.pdfbox.pdmodel.PDPageContentStream;
import org.xbib.graphics.pdfbox.layout.element.render.Transform;
import org.xbib.graphics.pdfbox.layout.position.Position; import org.xbib.graphics.pdfbox.layout.position.Position;
import java.io.IOException; import java.io.IOException;
@ -12,7 +13,7 @@ public class Rect extends AbstractShape {
@Override @Override
public void add(PDDocument pdDocument, PDPageContentStream contentStream, public void add(PDDocument pdDocument, PDPageContentStream contentStream,
Position upperLeft, float width, float height) throws IOException { Position upperLeft, Transform transform, float width, float height) throws IOException {
contentStream.addRect(upperLeft.getX(), upperLeft.getY() - height, width, height); contentStream.addRect(upperLeft.getX(), upperLeft.getY() - height, width, height);
} }
} }

View file

@ -2,6 +2,7 @@ package org.xbib.graphics.pdfbox.layout.shape;
import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPageContentStream; import org.apache.pdfbox.pdmodel.PDPageContentStream;
import org.xbib.graphics.pdfbox.layout.element.render.Transform;
import org.xbib.graphics.pdfbox.layout.position.Position; import org.xbib.graphics.pdfbox.layout.position.Position;
import java.io.IOException; import java.io.IOException;
@ -40,9 +41,10 @@ public class RoundRect extends AbstractShape {
public void add(PDDocument pdDocument, public void add(PDDocument pdDocument,
PDPageContentStream contentStream, PDPageContentStream contentStream,
Position upperLeft, Position upperLeft,
Transform transform,
float width, float width,
float height) throws IOException { float height) throws IOException {
addRoundRect(contentStream, upperLeft, width, height, cornerRadiusX, cornerRadiusY); addRoundRect(contentStream, upperLeft, transform, width, height, cornerRadiusX, cornerRadiusY);
} }
/** /**
@ -69,7 +71,7 @@ public class RoundRect extends AbstractShape {
* @throws IOException by pdfbox * @throws IOException by pdfbox
*/ */
protected void addRoundRect(PDPageContentStream contentStream, protected void addRoundRect(PDPageContentStream contentStream,
Position upperLeft, float width, float height, float cornerRadiusX, Position upperLeft, Transform transform, float width, float height, float cornerRadiusX,
float cornerRadiusY) throws IOException { float cornerRadiusY) throws IOException {
float nettoWidth = width - 2 * cornerRadiusX; float nettoWidth = width - 2 * cornerRadiusX;
float nettoHeight = height - 2 * cornerRadiusY; float nettoHeight = height - 2 * cornerRadiusY;

View file

@ -2,6 +2,7 @@ package org.xbib.graphics.pdfbox.layout.shape;
import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPageContentStream; import org.apache.pdfbox.pdmodel.PDPageContentStream;
import org.xbib.graphics.pdfbox.layout.element.render.Transform;
import org.xbib.graphics.pdfbox.layout.text.DrawListener; import org.xbib.graphics.pdfbox.layout.text.DrawListener;
import org.xbib.graphics.pdfbox.layout.position.Position; import org.xbib.graphics.pdfbox.layout.position.Position;
import java.awt.Color; import java.awt.Color;
@ -9,11 +10,11 @@ import java.io.IOException;
/** /**
* Shapes can be used to either * Shapes can be used to either
* {@link #draw(PDDocument, PDPageContentStream, Position, float, float, Color, Stroke, DrawListener) * {@link #draw(PDDocument, PDPageContentStream, Position, Transform, float, float, Color, Stroke, DrawListener)
* stroke} or * stroke} or
* {@link #fill(PDDocument, PDPageContentStream, Position, float, float, Color, DrawListener) * {@link #fill(PDDocument, PDPageContentStream, Position, Transform, float, float, Color, DrawListener)
* fill} the path of the shape, or simply * fill} the path of the shape, or simply
* {@link #add(PDDocument, PDPageContentStream, Position, float, float) add the * {@link #add(PDDocument, PDPageContentStream, Position, Transform, float, float) add the
* path} of the shape to the drawing context. * path} of the shape to the drawing context.
*/ */
public interface Shape { public interface Shape {
@ -24,6 +25,7 @@ public interface Shape {
* @param pdDocument the underlying pdfbox document. * @param pdDocument the underlying pdfbox document.
* @param contentStream the stream to draw to. * @param contentStream the stream to draw to.
* @param upperLeft the upper left position to start drawing. * @param upperLeft the upper left position to start drawing.
* @param transform the transform or null
* @param width the width of the bounding box. * @param width the width of the bounding box.
* @param height the height of the bounding box. * @param height the height of the bounding box.
* @param color the color to use. * @param color the color to use.
@ -34,7 +36,9 @@ public interface Shape {
* @throws IOException by pdfbox * @throws IOException by pdfbox
*/ */
void draw(PDDocument pdDocument, PDPageContentStream contentStream, void draw(PDDocument pdDocument, PDPageContentStream contentStream,
Position upperLeft, float width, float height, Color color, Position upperLeft,
Transform transform,
float width, float height, Color color,
Stroke stroke, DrawListener drawListener) throws IOException; Stroke stroke, DrawListener drawListener) throws IOException;
/** /**
@ -52,7 +56,7 @@ public interface Shape {
* @throws IOException by pdfbox * @throws IOException by pdfbox
*/ */
void fill(PDDocument pdDocument, PDPageContentStream contentStream, void fill(PDDocument pdDocument, PDPageContentStream contentStream,
Position upperLeft, float width, float height, Color color, Position upperLeft, Transform transform, float width, float height, Color color,
DrawListener drawListener) throws IOException; DrawListener drawListener) throws IOException;
/** /**
@ -66,6 +70,6 @@ public interface Shape {
* @throws IOException by pdfbox * @throws IOException by pdfbox
*/ */
void add(PDDocument pdDocument, PDPageContentStream contentStream, void add(PDDocument pdDocument, PDPageContentStream contentStream,
Position upperLeft, float width, float height) throws IOException; Position upperLeft, Transform transform, float width, float height) throws IOException;
} }

View file

@ -4,7 +4,7 @@ import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.pdmodel.PDPageContentStream; import org.apache.pdfbox.pdmodel.PDPageContentStream;
import org.xbib.graphics.pdfbox.layout.table.render.Renderer; import org.xbib.graphics.pdfbox.layout.table.render.Renderer;
import org.xbib.graphics.pdfbox.layout.table.render.RenderContext; import org.xbib.graphics.pdfbox.layout.table.render.TableRenderContext;
import java.awt.geom.Point2D; import java.awt.geom.Point2D;
import java.io.IOException; import java.io.IOException;
@ -39,7 +39,7 @@ public class TableRenderer {
protected boolean startTableInNewPage; protected boolean startTableInNewPage;
protected final List<BiConsumer<Renderer, RenderContext>> drawerList = new LinkedList<>(); protected final List<BiConsumer<Renderer, TableRenderContext>> drawerList = new LinkedList<>();
{ {
this.drawerList.add((drawer, drawingContext) -> { this.drawerList.add((drawer, drawingContext) -> {
@ -150,7 +150,7 @@ public class TableRenderer {
return pageToDrawOn; return pageToDrawOn;
} }
protected void drawWithFunction(PageData pageData, Point2D.Float startingPoint, BiConsumer<Renderer, RenderContext> consumer) { protected void drawWithFunction(PageData pageData, Point2D.Float startingPoint, BiConsumer<Renderer, TableRenderContext> consumer) {
float y = startingPoint.y; float y = startingPoint.y;
for (int rowIndex = pageData.firstRowOnPage; rowIndex < pageData.firstRowOnNextPage; rowIndex++) { for (int rowIndex = pageData.firstRowOnPage; rowIndex < pageData.firstRowOnNextPage; rowIndex++) {
final Row row = table.getRows().get(rowIndex); final Row row = table.getRows().get(rowIndex);
@ -159,7 +159,7 @@ public class TableRenderer {
} }
} }
protected void drawRow(Point2D.Float start, Row row, int rowIndex, BiConsumer<Renderer, RenderContext> consumer) { protected void drawRow(Point2D.Float start, Row row, int rowIndex, BiConsumer<Renderer, TableRenderContext> consumer) {
float x = start.x; float x = start.x;
int columnCounter = 0; int columnCounter = 0;
for (Cell cell : row.getCells()) { for (Cell cell : row.getCells()) {
@ -167,7 +167,7 @@ public class TableRenderer {
x += table.getColumns().get(columnCounter).getWidth(); x += table.getColumns().get(columnCounter).getWidth();
columnCounter++; columnCounter++;
} }
consumer.accept(cell.getRenderer(), new RenderContext(pdDocument, contentStream, page, new Point2D.Float(x, start.y))); consumer.accept(cell.getRenderer(), new TableRenderContext(pdDocument, contentStream, page, new Point2D.Float(x, start.y)));
x += cell.getWidth(); x += cell.getWidth();
columnCounter += cell.getColSpan(); columnCounter += cell.getColSpan();
} }

View file

@ -19,10 +19,10 @@ public abstract class AbstractCellRenderer<T extends Cell> implements Renderer {
} }
@Override @Override
public void renderBackground(RenderContext renderContext) { public void renderBackground(TableRenderContext tableRenderContext) {
if (cell.hasBackgroundColor()) { if (cell.hasBackgroundColor()) {
final PDPageContentStream contentStream = renderContext.getContentStream(); final PDPageContentStream contentStream = tableRenderContext.getContentStream();
final Point2D.Float start = renderContext.getStartingPoint(); final Point2D.Float start = tableRenderContext.getStartingPoint();
final float rowHeight = cell.getRow().getHeight(); final float rowHeight = cell.getRow().getHeight();
final float height = Math.max(cell.getHeight(), rowHeight); final float height = Math.max(cell.getHeight(), rowHeight);
final float y = rowHeight < cell.getHeight() final float y = rowHeight < cell.getHeight()
@ -35,12 +35,12 @@ public abstract class AbstractCellRenderer<T extends Cell> implements Renderer {
} }
@Override @Override
public abstract void renderContent(RenderContext renderContext); public abstract void renderContent(TableRenderContext tableRenderContext);
@Override @Override
public void renderBorders(RenderContext renderContext) { public void renderBorders(TableRenderContext tableRenderContext) {
final Point2D.Float start = renderContext.getStartingPoint(); final Point2D.Float start = tableRenderContext.getStartingPoint();
final PDPageContentStream contentStream = renderContext.getContentStream(); final PDPageContentStream contentStream = tableRenderContext.getContentStream();
final float cellWidth = cell.getWidth(); final float cellWidth = cell.getWidth();
final float rowHeight = cell.getRow().getHeight(); final float rowHeight = cell.getRow().getHeight();
final float height = Math.max(cell.getHeight(), rowHeight); final float height = Math.max(cell.getHeight(), rowHeight);

View file

@ -15,17 +15,17 @@ public class DrawableCellRenderer extends AbstractCellRenderer<DrawableCell> {
} }
@Override @Override
public void renderContent(RenderContext renderContext) { public void renderContent(TableRenderContext tableRenderContext) {
Drawable drawable = cell.getDrawable(); Drawable drawable = cell.getDrawable();
if (drawable instanceof WidthRespecting) { if (drawable instanceof WidthRespecting) {
WidthRespecting widthRespecting = (WidthRespecting) drawable; WidthRespecting widthRespecting = (WidthRespecting) drawable;
widthRespecting.setMaxWidth(cell.getWidth()); widthRespecting.setMaxWidth(cell.getWidth());
} }
float x = renderContext.getStartingPoint().x + cell.getPaddingLeft(); float x = tableRenderContext.getStartingPoint().x + cell.getPaddingLeft();
float y = renderContext.getStartingPoint().y + getAdaptionForVerticalAlignment(); float y = tableRenderContext.getStartingPoint().y + getAdaptionForVerticalAlignment();
Position position = new Position(x, y); Position position = new Position(x, y);
try { try {
drawable.draw(renderContext.getPdDocument(), renderContext.getContentStream(), position,null); drawable.draw(tableRenderContext.getPdDocument(), tableRenderContext.getContentStream(), position,null, null);
} catch (IOException e) { } catch (IOException e) {
throw new UncheckedIOException(e); throw new UncheckedIOException(e);
} }

View file

@ -15,9 +15,9 @@ public class ImageCellRenderer extends AbstractCellRenderer<ImageCell> {
} }
@Override @Override
public void renderContent(RenderContext renderContext) { public void renderContent(TableRenderContext tableRenderContext) {
final PDPageContentStream contentStream = renderContext.getContentStream(); final PDPageContentStream contentStream = tableRenderContext.getContentStream();
final float moveX = renderContext.getStartingPoint().x; final float moveX = tableRenderContext.getStartingPoint().x;
final Point2D.Float size = cell.getFitSize(); final Point2D.Float size = cell.getFitSize();
final Point2D.Float drawAt = new Point2D.Float(); final Point2D.Float drawAt = new Point2D.Float();
float xOffset = moveX + cell.getPaddingLeft(); float xOffset = moveX + cell.getPaddingLeft();
@ -28,7 +28,7 @@ public class ImageCellRenderer extends AbstractCellRenderer<ImageCell> {
xOffset = moveX + diff; xOffset = moveX + diff;
} }
drawAt.x = xOffset; drawAt.x = xOffset;
drawAt.y = renderContext.getStartingPoint().y + getAdaptionForVerticalAlignment() - size.y; drawAt.y = tableRenderContext.getStartingPoint().y + getAdaptionForVerticalAlignment() - size.y;
try { try {
contentStream.drawImage(cell.getImage(), drawAt.x, drawAt.y, size.x, size.y); contentStream.drawImage(cell.getImage(), drawAt.x, drawAt.y, size.x, size.y);
} catch (IOException exception) { } catch (IOException exception) {

View file

@ -29,13 +29,14 @@ public class ParagraphCellRenderer extends AbstractCellRenderer<ParagraphCell> {
} }
@Override @Override
public void renderContent(RenderContext renderContext) { public void renderContent(TableRenderContext tableRenderContext) {
Paragraph paragraph = cell.getCellParagraph().getParagraph(); Paragraph paragraph = cell.getCellParagraph().getParagraph();
float x = renderContext.getStartingPoint().x + cell.getPaddingLeft(); float x = tableRenderContext.getStartingPoint().x + cell.getPaddingLeft();
float y = renderContext.getStartingPoint().y + getAdaptionForVerticalAlignment(); float y = tableRenderContext.getStartingPoint().y + getAdaptionForVerticalAlignment();
AnnotationDrawListener annotationDrawListener = createAndGetAnnotationDrawListenerWith(renderContext); AnnotationDrawListener annotationDrawListener = createAndGetAnnotationDrawListenerWith(tableRenderContext);
paragraph.drawText(renderContext.getContentStream(), paragraph.drawText(tableRenderContext.getContentStream(),
new Position(x, y), new Position(x, y),
null,
ALIGNMENT_MAP.getOrDefault(cell.getParameters().getHorizontalAlignment(), Alignment.LEFT), ALIGNMENT_MAP.getOrDefault(cell.getParameters().getHorizontalAlignment(), Alignment.LEFT),
annotationDrawListener annotationDrawListener
); );
@ -46,21 +47,21 @@ public class ParagraphCellRenderer extends AbstractCellRenderer<ParagraphCell> {
return cell.getCellParagraph().getParagraph().getHeight(); return cell.getCellParagraph().getParagraph().getHeight();
} }
private AnnotationDrawListener createAndGetAnnotationDrawListenerWith(RenderContext renderContext) { private AnnotationDrawListener createAndGetAnnotationDrawListenerWith(TableRenderContext tableRenderContext) {
return new AnnotationDrawListener(new DrawContext() { return new AnnotationDrawListener(new DrawContext() {
@Override @Override
public PDDocument getPdDocument() { public PDDocument getPdDocument() {
return renderContext.getPdDocument(); return tableRenderContext.getPdDocument();
} }
@Override @Override
public PDPage getCurrentPage() { public PDPage getCurrentPage() {
return renderContext.getPage(); return tableRenderContext.getPage();
} }
@Override @Override
public PDPageContentStream getCurrentPageContentStream() { public PDPageContentStream getCurrentPageContentStream() {
return renderContext.getContentStream(); return tableRenderContext.getContentStream();
} }
}); });
} }

View file

@ -2,10 +2,10 @@ package org.xbib.graphics.pdfbox.layout.table.render;
public interface Renderer { public interface Renderer {
void renderContent(RenderContext renderContext); void renderContent(TableRenderContext tableRenderContext);
void renderBackground(RenderContext renderContext); void renderBackground(TableRenderContext tableRenderContext);
void renderBorders(RenderContext renderContext); void renderBorders(TableRenderContext tableRenderContext);
} }

View file

@ -6,7 +6,7 @@ import org.apache.pdfbox.pdmodel.PDPageContentStream;
import java.awt.geom.Point2D; import java.awt.geom.Point2D;
public class RenderContext { public class TableRenderContext {
private final PDDocument pdDocument; private final PDDocument pdDocument;
@ -16,7 +16,7 @@ public class RenderContext {
private final Point2D.Float startingPoint; private final Point2D.Float startingPoint;
public RenderContext(PDDocument pdDocument, PDPageContentStream contentStream, PDPage page, Point2D.Float startingPoint) { public TableRenderContext(PDDocument pdDocument, PDPageContentStream contentStream, PDPage page, Point2D.Float startingPoint) {
this.pdDocument = pdDocument; this.pdDocument = pdDocument;
this.contentStream = contentStream; this.contentStream = contentStream;
this.page = page; this.page = page;

View file

@ -21,12 +21,12 @@ public class TextCellRenderer<T extends AbstractTextCell> extends AbstractCellRe
} }
@Override @Override
public void renderContent(RenderContext renderContext) { public void renderContent(TableRenderContext tableRenderContext) {
float startX = renderContext.getStartingPoint().x; float startX = tableRenderContext.getStartingPoint().x;
Font currentFont = cell.getFont(); Font currentFont = cell.getFont();
float currentFontSize = cell.getFontSize(); float currentFontSize = cell.getFontSize();
Color currentTextColor = cell.getTextColor(); Color currentTextColor = cell.getTextColor();
float yOffset = renderContext.getStartingPoint().y + getAdaptionForVerticalAlignment(); float yOffset = tableRenderContext.getStartingPoint().y + getAdaptionForVerticalAlignment();
float xOffset = startX + cell.getPaddingLeft(); float xOffset = startX + cell.getPaddingLeft();
final List<String> lines = calculateAndGetLines(currentFont, currentFontSize, cell.getMaxWidth()); final List<String> lines = calculateAndGetLines(currentFont, currentFontSize, cell.getMaxWidth());
for (int i = 0; i < lines.size(); i++) { for (int i = 0; i < lines.size(); i++) {
@ -39,14 +39,14 @@ public class TextCellRenderer<T extends AbstractTextCell> extends AbstractCellRe
xOffset = startX + (cell.getWidth() - textWidth) / 2; xOffset = startX + (cell.getWidth() - textWidth) / 2;
} else if (cell.isHorizontallyAligned(JUSTIFY) && isNotLastLine(lines, i)) { } else if (cell.isHorizontallyAligned(JUSTIFY) && isNotLastLine(lines, i)) {
try { try {
renderContext.getContentStream().setCharacterSpacing(calculateCharSpacingFor(line)); tableRenderContext.getContentStream().setCharacterSpacing(calculateCharSpacingFor(line));
} catch (IOException exception) { } catch (IOException exception) {
throw new UncheckedIOException(exception); throw new UncheckedIOException(exception);
} }
} }
PositionedStyledText positionedStyledText = new PositionedStyledText(xOffset, yOffset, line, PositionedStyledText positionedStyledText = new PositionedStyledText(xOffset, yOffset, line,
currentFont, currentFontSize, currentTextColor); currentFont, currentFontSize, currentTextColor);
RenderUtil.drawText(renderContext.getContentStream(), positionedStyledText); RenderUtil.drawText(tableRenderContext.getContentStream(), positionedStyledText);
} }
} }

View file

@ -24,9 +24,9 @@ public class VerticalTextCellRenderer extends AbstractCellRenderer<VerticalTextC
} }
@Override @Override
public void renderContent(RenderContext renderContext) { public void renderContent(TableRenderContext tableRenderContext) {
float startX = renderContext.getStartingPoint().x; float startX = tableRenderContext.getStartingPoint().x;
float startY = renderContext.getStartingPoint().y; float startY = tableRenderContext.getStartingPoint().y;
Font currentFont = cell.getFont(); Font currentFont = cell.getFont();
float currentFontSize = cell.getFontSize(); float currentFontSize = cell.getFontSize();
Color currentTextColor = cell.getTextColor(); Color currentTextColor = cell.getTextColor();
@ -44,7 +44,7 @@ public class VerticalTextCellRenderer extends AbstractCellRenderer<VerticalTextC
for (int i = 0; i < lines.size(); i++) { for (int i = 0; i < lines.size(); i++) {
final String line = lines.get(i); final String line = lines.get(i);
xOffset += (PdfUtil.getFontHeight(currentFont, currentFontSize) + (i > 0 ? PdfUtil.getFontHeight(currentFont, currentFontSize) * cell.getLineSpacing() : 0f)); xOffset += (PdfUtil.getFontHeight(currentFont, currentFontSize) + (i > 0 ? PdfUtil.getFontHeight(currentFont, currentFontSize) * cell.getLineSpacing() : 0f));
drawText(line, currentFont, currentFontSize, currentTextColor, xOffset, yOffset, renderContext.getContentStream()); drawText(line, currentFont, currentFontSize, currentTextColor, xOffset, yOffset, tableRenderContext.getContentStream());
} }
} }

View file

@ -1,6 +1,7 @@
package org.xbib.graphics.pdfbox.layout.text; package org.xbib.graphics.pdfbox.layout.text;
import org.apache.pdfbox.pdmodel.PDPageContentStream; import org.apache.pdfbox.pdmodel.PDPageContentStream;
import org.xbib.graphics.pdfbox.layout.element.render.Transform;
import org.xbib.graphics.pdfbox.layout.position.Position; import org.xbib.graphics.pdfbox.layout.position.Position;
import java.io.IOException; import java.io.IOException;
@ -15,12 +16,13 @@ public interface DrawableText extends Area {
* *
* @param contentStream the content stream used to render. * @param contentStream the content stream used to render.
* @param upperLeft the upper left position to draw to. * @param upperLeft the upper left position to draw to.
* @param transform the transformation or null
* @param alignment the text alignment. * @param alignment the text alignment.
* @param drawListener the listener to * @param drawListener the listener to
* {@link DrawListener#drawn(Object, Position, float, float) * {@link DrawListener#drawn(Object, Position, float, float)
* notify} on drawn objects. * notify} on drawn objects.
* @throws IOException by pdfbox. * @throws IOException by pdfbox.
*/ */
void drawText(PDPageContentStream contentStream, Position upperLeft, void drawText(PDPageContentStream contentStream, Position upperLeft, Transform transform,
Alignment alignment, DrawListener drawListener) throws IOException; Alignment alignment, DrawListener drawListener) throws IOException;
} }

View file

@ -1,6 +1,7 @@
package org.xbib.graphics.pdfbox.layout.text; package org.xbib.graphics.pdfbox.layout.text;
import org.apache.pdfbox.pdmodel.PDPageContentStream; import org.apache.pdfbox.pdmodel.PDPageContentStream;
import org.xbib.graphics.pdfbox.layout.element.render.Transform;
import org.xbib.graphics.pdfbox.layout.font.Font; import org.xbib.graphics.pdfbox.layout.font.Font;
import org.xbib.graphics.pdfbox.layout.font.FontDescriptor; import org.xbib.graphics.pdfbox.layout.font.FontDescriptor;
import org.xbib.graphics.pdfbox.layout.position.Position; import org.xbib.graphics.pdfbox.layout.position.Position;
@ -233,18 +234,12 @@ public class TextFlow implements TextSequence, WidthRespecting {
} }
@Override @Override
public void drawText(PDPageContentStream contentStream, Position upperLeft, public void drawText(PDPageContentStream contentStream, Position upperLeft, Transform transform,
Alignment alignment, DrawListener drawListener) { Alignment alignment, DrawListener drawListener) {
TextSequenceUtil.drawText(this, contentStream, upperLeft, drawListener, TextSequenceUtil.drawText(this, contentStream, upperLeft, transform, drawListener,
alignment, getMaxWidth(), getLineSpacing(), isApplyLineSpacingToFirstLine()); alignment, getMaxWidth(), getLineSpacing(), isApplyLineSpacingToFirstLine());
} }
public void drawTextRightAligned(PDPageContentStream contentStream,
Position endOfFirstLine, DrawListener drawListener) {
drawText(contentStream, endOfFirstLine.add(-getWidth(), 0),
Alignment.RIGHT, drawListener);
}
/** /**
* @return a copy of this text flow where all leading {@link NewLine}s are removed. * @return a copy of this text flow where all leading {@link NewLine}s are removed.
*/ */

View file

@ -2,6 +2,7 @@ package org.xbib.graphics.pdfbox.layout.text;
import org.apache.pdfbox.pdmodel.PDPageContentStream; import org.apache.pdfbox.pdmodel.PDPageContentStream;
import org.apache.pdfbox.util.Matrix; import org.apache.pdfbox.util.Matrix;
import org.xbib.graphics.pdfbox.layout.element.render.Transform;
import org.xbib.graphics.pdfbox.layout.font.FontDescriptor; import org.xbib.graphics.pdfbox.layout.font.FontDescriptor;
import org.xbib.graphics.pdfbox.layout.position.Position; import org.xbib.graphics.pdfbox.layout.position.Position;
@ -155,13 +156,14 @@ public class TextLine implements TextSequence {
} }
@Override @Override
public void drawText(PDPageContentStream contentStream, Position upperLeft, public void drawText(PDPageContentStream contentStream, Position upperLeft, Transform transform,
Alignment alignment, DrawListener drawListener) { Alignment alignment, DrawListener drawListener) {
drawAligned(contentStream, upperLeft, alignment, getWidth(), drawListener); drawAligned(contentStream, upperLeft, transform, alignment, getWidth(), drawListener);
} }
public void drawAligned(PDPageContentStream contentStream, public void drawAligned(PDPageContentStream contentStream,
Position upperLeft, Position upperLeft,
Transform transform,
Alignment alignment, Alignment alignment,
float availableLineWidth, float availableLineWidth,
DrawListener drawListener) { DrawListener drawListener) {
@ -195,6 +197,9 @@ public class TextLine implements TextSequence {
if (isRotated) { if (isRotated) {
matrix.rotate(Math.toRadians(styledText.getRotation())); matrix.rotate(Math.toRadians(styledText.getRotation()));
} }
if (transform != null) {
matrix = matrix.multiply(transform.getMatrix());
}
contentStream.beginText(); contentStream.beginText();
contentStream.setTextMatrix(matrix); contentStream.setTextMatrix(matrix);
if (!styledText.getFontDescriptor().equals(lastFontDesc)) { if (!styledText.getFontDescriptor().equals(lastFontDesc)) {

View file

@ -3,6 +3,7 @@ package org.xbib.graphics.pdfbox.layout.text;
import org.apache.pdfbox.pdmodel.PDPageContentStream; import org.apache.pdfbox.pdmodel.PDPageContentStream;
import org.xbib.graphics.pdfbox.layout.element.Dividable.Divided; import org.xbib.graphics.pdfbox.layout.element.Dividable.Divided;
import org.xbib.graphics.pdfbox.layout.element.Paragraph; import org.xbib.graphics.pdfbox.layout.element.Paragraph;
import org.xbib.graphics.pdfbox.layout.element.render.Transform;
import org.xbib.graphics.pdfbox.layout.font.FontDescriptor; import org.xbib.graphics.pdfbox.layout.font.FontDescriptor;
import org.xbib.graphics.pdfbox.layout.position.Position; import org.xbib.graphics.pdfbox.layout.position.Position;
import org.xbib.graphics.pdfbox.layout.util.Pair; import org.xbib.graphics.pdfbox.layout.util.Pair;
@ -384,6 +385,7 @@ public class TextSequenceUtil {
public static void drawText(TextSequence text, public static void drawText(TextSequence text,
PDPageContentStream contentStream, PDPageContentStream contentStream,
Position upperLeft, Position upperLeft,
Transform transform,
DrawListener drawListener, DrawListener drawListener,
Alignment alignment, Alignment alignment,
float maxWidth, final float lineSpacing, final boolean applyLineSpacingToFirstLine) { float maxWidth, final float lineSpacing, final boolean applyLineSpacingToFirstLine) {
@ -401,7 +403,7 @@ public class TextSequenceUtil {
} }
lastLineHeight = currentLineHeight; lastLineHeight = currentLineHeight;
position = position.add(0, -lead); position = position.add(0, -lead);
textLine.drawAligned(contentStream, position, alignment, maxLineWidth, drawListener); textLine.drawAligned(contentStream, position, transform, alignment, maxLineWidth, drawListener);
} }
} }

View file

@ -101,8 +101,8 @@ public class CustomRendererTest {
TextFlow text = TextFlowUtil.createTextFlow(content, fontDescriptor, 1.2f, 0f); TextFlow text = TextFlowUtil.createTextFlow(content, fontDescriptor, 1.2f, 0f);
float offset = renderContext.getPageFormat().getMarginLeft() + float offset = renderContext.getPageFormat().getMarginLeft() +
TextSequenceUtil.getOffset(text, renderContext.getWidth(), Alignment.RIGHT); TextSequenceUtil.getOffset(text, renderContext.getWidth(), Alignment.RIGHT);
text.drawText(renderContext.getCurrentPageContentStream(), new Position( text.drawText(renderContext.getCurrentPageContentStream(),
offset, 30), Alignment.RIGHT, null); new Position(offset, 30), null, Alignment.RIGHT, null);
} }
} }
} }

View file

@ -52,8 +52,8 @@ public class ListenerTest {
float offset = renderContext.getPageFormat().getMarginLeft() float offset = renderContext.getPageFormat().getMarginLeft()
+ TextSequenceUtil.getOffset(text, + TextSequenceUtil.getOffset(text,
renderContext.getWidth(), Alignment.RIGHT); renderContext.getWidth(), Alignment.RIGHT);
text.drawText(renderContext.getCurrentPageContentStream(), new Position( text.drawText(renderContext.getCurrentPageContentStream(),
offset, 30), Alignment.RIGHT, null); new Position(offset, 30), null, Alignment.RIGHT, null);
} }
}); });

View file

@ -7,8 +7,6 @@ import org.apache.pdfbox.util.Matrix;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.xbib.graphics.pdfbox.layout.element.PageFormat; import org.xbib.graphics.pdfbox.layout.element.PageFormat;
import org.xbib.graphics.pdfbox.layout.font.FontDescriptor; import org.xbib.graphics.pdfbox.layout.font.FontDescriptor;
import org.xbib.graphics.pdfbox.layout.position.LinePosiiton;
import org.xbib.graphics.pdfbox.layout.position.MovePosition;
import org.xbib.graphics.pdfbox.layout.shape.RoundRect; import org.xbib.graphics.pdfbox.layout.shape.RoundRect;
import org.xbib.graphics.pdfbox.layout.shape.Shape; import org.xbib.graphics.pdfbox.layout.shape.Shape;
import org.xbib.graphics.pdfbox.layout.shape.Stroke; import org.xbib.graphics.pdfbox.layout.shape.Stroke;
@ -65,7 +63,7 @@ public class LowLevelText {
text.setMaxWidth(100); text.setMaxWidth(100);
float xOffset = TextSequenceUtil.getOffset(text, pageWidth, float xOffset = TextSequenceUtil.getOffset(text, pageWidth,
Alignment.RIGHT); Alignment.RIGHT);
text.drawText(contentStream, new Position(xOffset, pageHeight - 50), text.drawText(contentStream, new Position(xOffset, pageHeight - 50), null,
Alignment.RIGHT, annotationDrawListener); Alignment.RIGHT, annotationDrawListener);
String textBlock = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, " String textBlock = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, "
@ -83,7 +81,7 @@ public class LowLevelText {
text.addMarkup(textBlock, 8, BaseFont.COURIER); text.addMarkup(textBlock, 8, BaseFont.COURIER);
text.setMaxWidth(200); text.setMaxWidth(200);
xOffset = TextSequenceUtil.getOffset(text, pageWidth, Alignment.CENTER); xOffset = TextSequenceUtil.getOffset(text, pageWidth, Alignment.CENTER);
text.drawText(contentStream, new Position(xOffset, pageHeight - 100), text.drawText(contentStream, new Position(xOffset, pageHeight - 100), null,
Alignment.JUSTIFY, annotationDrawListener); Alignment.JUSTIFY, annotationDrawListener);
// draw a round rect box with text // draw a round rect box with text
@ -96,12 +94,12 @@ public class LowLevelText {
float boxHeight = text.getHeight() + 2 * paddingY; float boxHeight = text.getHeight() + 2 * paddingY;
Shape shape = new RoundRect(20); Shape shape = new RoundRect(20);
shape.fill(pdDocument, contentStream, new Position(x, y), boxWidth, shape.fill(pdDocument, contentStream, new Position(x, y), null, boxWidth,
boxHeight, Color.pink, null); boxHeight, Color.pink, null);
shape.draw(pdDocument, contentStream, new Position(x, y), boxWidth, shape.draw(pdDocument, contentStream, new Position(x, y), null, boxWidth,
boxHeight, Color.blue, new Stroke(3), null); boxHeight, Color.blue, new Stroke(3), null);
// now the text // now the text
text.drawText(contentStream, new Position(x + paddingX, y - paddingY), text.drawText(contentStream, new Position(x + paddingX, y - paddingY), null,
Alignment.CENTER, annotationDrawListener); Alignment.CENTER, annotationDrawListener);
annotationDrawListener.afterPage(null); annotationDrawListener.afterPage(null);

View file

@ -12,13 +12,13 @@ public class ScriptingTest {
@Test @Test
public void script() throws Exception { public void script() throws Exception {
Settings settings = Settings.settingsBuilder() Settings settings = Settings.settingsBuilder()
.loadFromResource("json", getClass().getResourceAsStream("elements.json")) .loadFromResource("json", getClass().getResourceAsStream("scripting.json"))
.build(); .build();
Engine engine = new Engine(); Engine engine = new Engine();
engine.execute(settings); engine.execute(settings);
int i = 0; int i = 0;
for (Document document : engine.getState().getDocuments()) { for (Document document : engine.getState().getDocuments()) {
document.render().save(new FileOutputStream("build/elements" + (i++) + ".pdf")).close(); document.render().save(new FileOutputStream("build/scripting" + (i++) + ".pdf")).close();
} }
engine.close(); engine.close();
} }

View file

@ -3,6 +3,16 @@
"margin": "0 0 0 0", "margin": "0 0 0 0",
"author": "Jörg Prante", "author": "Jörg Prante",
"elements": [ "elements": [
{
"type": "transform",
"translatex": 150,
"translatey": 5,
"scalex": 0.75,
"scaley": 0.5,
"angle": 45,
"rotatex" : 10,
"rotatey": 200
},
{ {
"type": "setposition", "type": "setposition",
"x": 10, "x": 10,