working on positions, matrix transform, clean up

This commit is contained in:
Jörg Prante 2022-01-24 10:07:57 +01:00
parent 630d50bce7
commit b85fd84abd
63 changed files with 270 additions and 316 deletions

View file

@ -12,6 +12,7 @@ module org.xbib.graphics.layout.pdfbox {
exports org.xbib.graphics.pdfbox.layout.text;
exports org.xbib.graphics.pdfbox.layout.text.annotations;
exports org.xbib.graphics.pdfbox.layout.util;
exports org.xbib.graphics.pdfbox.layout.position;
requires transitive org.xbib.graphics.barcode;
requires transitive org.xbib.graphics.pdfbox;
requires transitive org.xbib.settings.api;

View file

@ -461,7 +461,6 @@ public class Paragraph {
}
}
}
// reset
alreadyTextInLine = false;
sinceLastWrapPoint.push(currentFont, fontSize,
Token.text(TokenType.TEXT, firstPartOfWord.toString()));
@ -544,14 +543,11 @@ public class Paragraph {
public float write(final PageContentStreamOptimized stream, float cursorX, float cursorY) {
if (drawDebug) {
PDStreamUtils.rectFontMetrics(stream, cursorX, cursorY, font, fontSize);
// width
PDStreamUtils.rect(stream, cursorX, cursorY, width, 1, Color.RED);
}
for (String line : getLines()) {
line = line.trim();
float textX = cursorX;
switch (align) {
case CENTER:
@ -563,9 +559,7 @@ public class Paragraph {
textX += getHorizontalFreeSpace(line);
break;
}
PDStreamUtils.write(stream, line, font, fontSize, textX, cursorY, color);
if (textType != null) {
switch (textType) {
case HIGHLIGHT:
@ -588,11 +582,8 @@ public class Paragraph {
break;
}
}
// move one "line" down
cursorY -= getFontHeight();
}
return cursorY;
}

View file

@ -141,18 +141,13 @@ public abstract class Table<T extends PDPage> {
public void drawTitle(String title, PDFont font, int fontSize, float tableWidth, float height, String alignment,
float freeSpaceForPageBreak, WrappingFunction wrappingFunction, boolean drawHeaderMargin)
throws IOException {
ensureStreamIsOpen();
if (isEndOfPage(freeSpaceForPageBreak)) {
this.tableContentStream.close();
pageBreak();
tableStartedAtNewPage = true;
}
if (title == null) {
// if you don't have title just use the height of maxTextBox in your
// "row"
yStart -= height;
} else {
PageContentStreamOptimized articleTitle = createPdPageContentStream();
@ -163,15 +158,11 @@ public abstract class Table<T extends PDPage> {
if (paragraph.getHeight() < height) {
yStart -= (height - paragraph.getHeight());
}
articleTitle.close();
if (drawDebug) {
// margin
PDStreamUtils.rect(tableContentStream, margin, yStart, width, headerBottomMargin, Color.CYAN);
}
}
if (drawHeaderMargin) {
yStart -= headerBottomMargin;
}
@ -196,9 +187,7 @@ public abstract class Table<T extends PDPage> {
}
/**
* <p>
* Draws table
* </p>
* Draws table.
*
* @return Y position of the table
* @throws IOException if underlying stream has problem being written to.
@ -208,9 +197,6 @@ public abstract class Table<T extends PDPage> {
for (Row<T> row : rows) {
if (header.contains(row)) {
// check if header row height and first data row height can fit
// the page
// if not draw them on another side
if (isEndOfPage(getMinimumHeight())) {
pageBreak();
tableStartedAtNewPage = true;
@ -218,25 +204,17 @@ public abstract class Table<T extends PDPage> {
}
drawRow(row);
}
endTable();
return yStart;
}
private void drawRow(Row<T> row) throws IOException {
// row.getHeight is currently an extremely expensive function so get the value
// once during drawing and reuse it, since it will not change during drawing
float rowHeight = row.getHeight();
// if it is not header row or first row in the table then remove row's
// top border
if (row != header && row != rows.get(0)) {
if (!isEndOfPage(rowHeight)) {
row.removeTopBorders();
}
}
// draw the bookmark
if (row.getBookmark() != null) {
PDPageXYZDestination bookmarkDestination = new PDPageXYZDestination();
bookmarkDestination.setPage(currentPage);
@ -244,11 +222,7 @@ public abstract class Table<T extends PDPage> {
row.getBookmark().setDestination(bookmarkDestination);
this.addBookmark(row.getBookmark());
}
// we want to remove the borders as often as possible
removeTopBorders = true;
// check also if we want all borders removed
if (allBordersRemoved()) {
row.removeAllBorders();
}

View file

@ -8,7 +8,7 @@ import org.xbib.graphics.barcode.Symbol;
import org.xbib.graphics.barcode.render.BarcodeGraphicsRenderer;
import org.xbib.graphics.pdfbox.PdfBoxGraphics2D;
import org.xbib.graphics.pdfbox.layout.text.DrawListener;
import org.xbib.graphics.pdfbox.layout.text.Position;
import org.xbib.graphics.pdfbox.layout.position.Position;
import org.xbib.graphics.pdfbox.layout.text.WidthRespecting;
import java.awt.Color;
import java.io.IOException;

View file

@ -8,7 +8,7 @@ import org.xbib.graphics.chart.QuickChart;
import org.xbib.graphics.chart.xy.XYChart;
import org.xbib.graphics.pdfbox.PdfBoxGraphics2D;
import org.xbib.graphics.pdfbox.layout.text.DrawListener;
import org.xbib.graphics.pdfbox.layout.text.Position;
import org.xbib.graphics.pdfbox.layout.position.Position;
import org.xbib.graphics.pdfbox.layout.text.WidthRespecting;
import java.awt.geom.AffineTransform;

View file

@ -3,7 +3,7 @@ package org.xbib.graphics.pdfbox.layout.element;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPageContentStream;
import org.xbib.graphics.pdfbox.layout.text.DrawListener;
import org.xbib.graphics.pdfbox.layout.text.Position;
import org.xbib.graphics.pdfbox.layout.position.Position;
import java.io.IOException;
/**

View file

@ -232,6 +232,7 @@ public class Document implements Element, Closeable, RenderListener {
public Document render() throws IOException {
pdDocument.setDocumentInformation(pdDocumentInformation);
RenderContext renderContext = new RenderContext(this, pdDocument);
renderContext.newPage();
for (Entry<Element, LayoutHint> entry : elements) {
Element element = entry.getKey();
LayoutHint layoutHint = entry.getValue();

View file

@ -4,7 +4,7 @@ import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPageContentStream;
import org.xbib.graphics.pdfbox.layout.element.render.Layout;
import org.xbib.graphics.pdfbox.layout.text.DrawListener;
import org.xbib.graphics.pdfbox.layout.text.Position;
import org.xbib.graphics.pdfbox.layout.position.Position;
import java.io.IOException;
/**

View file

@ -6,7 +6,7 @@ import org.xbib.graphics.pdfbox.layout.shape.Rect;
import org.xbib.graphics.pdfbox.layout.shape.Shape;
import org.xbib.graphics.pdfbox.layout.shape.Stroke;
import org.xbib.graphics.pdfbox.layout.text.DrawListener;
import org.xbib.graphics.pdfbox.layout.text.Position;
import org.xbib.graphics.pdfbox.layout.position.Position;
import org.xbib.graphics.pdfbox.layout.text.WidthRespecting;
import java.awt.Color;
import java.io.IOException;

View file

@ -4,7 +4,7 @@ import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPageContentStream;
import org.xbib.graphics.pdfbox.layout.shape.Stroke;
import org.xbib.graphics.pdfbox.layout.text.DrawListener;
import org.xbib.graphics.pdfbox.layout.text.Position;
import org.xbib.graphics.pdfbox.layout.position.Position;
import org.xbib.graphics.pdfbox.layout.text.WidthRespecting;
import java.awt.Color;
import java.io.IOException;

View file

@ -5,7 +5,7 @@ import org.apache.pdfbox.pdmodel.PDPageContentStream;
import org.apache.pdfbox.pdmodel.graphics.image.LosslessFactory;
import org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject;
import org.xbib.graphics.pdfbox.layout.text.DrawListener;
import org.xbib.graphics.pdfbox.layout.text.Position;
import org.xbib.graphics.pdfbox.layout.position.Position;
import org.xbib.graphics.pdfbox.layout.text.WidthRespecting;
import javax.imageio.ImageIO;

View file

@ -4,9 +4,9 @@ import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPageContentStream;
import org.xbib.graphics.pdfbox.layout.text.Alignment;
import org.xbib.graphics.pdfbox.layout.text.DrawListener;
import org.xbib.graphics.pdfbox.layout.text.Position;
import org.xbib.graphics.pdfbox.layout.position.Position;
import org.xbib.graphics.pdfbox.layout.text.TextFlow;
import org.xbib.graphics.pdfbox.layout.util.TextSequenceUtil;
import org.xbib.graphics.pdfbox.layout.text.TextSequenceUtil;
import org.xbib.graphics.pdfbox.layout.text.WidthRespecting;
/**

View file

@ -5,7 +5,7 @@ import org.apache.pdfbox.pdmodel.PDPageContentStream;
import org.xbib.graphics.pdfbox.layout.shape.Path;
import org.xbib.graphics.pdfbox.layout.shape.Stroke;
import org.xbib.graphics.pdfbox.layout.text.DrawListener;
import org.xbib.graphics.pdfbox.layout.text.Position;
import org.xbib.graphics.pdfbox.layout.position.Position;
import java.awt.Color;
import java.io.IOException;
@ -68,7 +68,8 @@ public class PathElement implements Drawable, Element {
PDPageContentStream contentStream,
Position upperLeft,
DrawListener drawListener) throws IOException {
path.draw(pdDocument, contentStream, upperLeft, getWidth(), getHeight(), color, stroke, drawListener);
path.draw(pdDocument, contentStream, upperLeft, getWidth(), getHeight(),
color, stroke, drawListener);
}
@Override

View file

@ -2,9 +2,9 @@ package org.xbib.graphics.pdfbox.layout.element;
/**
* Utility class to create elements that allow the manipulation of the current
* layout position. Use carefully.
* layout position.
*/
public class PositionControl extends ControlElement {
public class PositionElement extends ControlElement {
/**
* Add this element to a document to mark the current position.
@ -50,21 +50,21 @@ public class PositionControl extends ControlElement {
return new MovePosition(relativeX, relativeY);
}
public static class MarkPosition extends PositionControl {
public static class MarkPosition extends PositionElement {
private MarkPosition() {
super("MARK_POSITION");
}
}
public static class ResetPosition extends PositionControl {
public static class ResetPosition extends PositionElement {
private ResetPosition() {
super("RESET_POSITION");
}
}
public static class SetPosition extends PositionControl {
public static class SetPosition extends PositionElement {
private final Float newX;
@ -85,7 +85,7 @@ public class PositionControl extends ControlElement {
}
}
public static class MovePosition extends PositionControl {
public static class MovePosition extends PositionElement {
private final float relativeX;
@ -106,7 +106,7 @@ public class PositionControl extends ControlElement {
}
}
private PositionControl(String name) {
private PositionElement(String name) {
super(name);
}
}

View file

@ -19,7 +19,7 @@ import org.xbib.graphics.pdfbox.color.RGBtoCMYKColorMapper;
import org.xbib.graphics.pdfbox.font.DefaultFontDrawer;
import org.xbib.graphics.pdfbox.font.FontDrawer;
import org.xbib.graphics.pdfbox.layout.text.DrawListener;
import org.xbib.graphics.pdfbox.layout.text.Position;
import org.xbib.graphics.pdfbox.layout.position.Position;
import java.awt.color.ICC_Profile;
import java.io.IOException;

View file

@ -9,7 +9,7 @@ import org.xbib.graphics.pdfbox.layout.table.Table;
import org.xbib.graphics.pdfbox.layout.table.TableRenderer;
import org.xbib.graphics.pdfbox.layout.table.VerticalAlignment;
import org.xbib.graphics.pdfbox.layout.text.DrawListener;
import org.xbib.graphics.pdfbox.layout.text.Position;
import org.xbib.graphics.pdfbox.layout.position.Position;
import java.awt.Color;
import java.io.IOException;

View file

@ -1,13 +1,13 @@
package org.xbib.graphics.pdfbox.layout.element;
import java.io.IOException;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPageContentStream;
import org.apache.pdfbox.util.Matrix;
import org.xbib.graphics.pdfbox.layout.text.DrawListener;
import org.xbib.graphics.pdfbox.layout.text.Position;
public class TransformElement implements Element, Drawable {
import org.apache.pdfbox.util.Matrix;
import org.xbib.graphics.pdfbox.layout.element.render.LayoutHint;
import org.xbib.graphics.pdfbox.layout.element.render.RenderContext;
import org.xbib.graphics.pdfbox.layout.element.render.Transform;
public class TransformElement implements Transform {
private Float translateX;
@ -23,26 +23,6 @@ public class TransformElement implements Element, Drawable {
private Float angle;
@Override
public float getWidth() throws IOException {
return 0;
}
@Override
public float getHeight() throws IOException {
return 0;
}
@Override
public Position getAbsolutePosition() throws IOException {
return null;
}
@Override
public Drawable removeLeadingEmptyVerticalSpace() throws IOException {
return this;
}
public void setTranslate(Float x, Float y) {
this.translateX = x;
this.translateY = y;
@ -59,16 +39,45 @@ public class TransformElement implements Element, Drawable {
this.rotateY = rotateY;
}
public Float getAngle() {
return angle;
}
public Float getRotateX() {
return rotateX;
}
public Float getRotateY() {
return rotateY;
}
public Float getScaleX() {
return scaleX;
}
public Float getScaleY() {
return scaleY;
}
public Float getTranslateX() {
return translateX;
}
public Float getTranslateY() {
return translateY;
}
@Override
public void draw(PDDocument pdDocument, PDPageContentStream contentStream, Position upperLeft, DrawListener drawListener) throws IOException {
public boolean render(RenderContext renderContext, Element element, LayoutHint layoutHint) throws IOException {
if (translateX != null && translateY != null) {
contentStream.transform(Matrix.getTranslateInstance(translateX, translateY));
renderContext.getCurrentPageContentStream().transform(Matrix.getTranslateInstance(translateX, translateY));
}
if (scaleX != null && scaleY != null) {
contentStream.transform(Matrix.getScaleInstance(scaleX, scaleY));
renderContext.getCurrentPageContentStream().transform(Matrix.getScaleInstance(scaleX, scaleY));
}
if (angle != null && rotateX != null && rotateY != null){
contentStream.transform(Matrix.getRotateInstance(Math.toRadians(angle), rotateX, rotateY));
renderContext.getCurrentPageContentStream().transform(Matrix.getRotateInstance(Math.toRadians(angle), rotateX, rotateY));
}
return true;
}
}

View file

@ -3,7 +3,7 @@ package org.xbib.graphics.pdfbox.layout.element;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPageContentStream;
import org.xbib.graphics.pdfbox.layout.text.DrawListener;
import org.xbib.graphics.pdfbox.layout.text.Position;
import org.xbib.graphics.pdfbox.layout.position.Position;
import java.io.IOException;
/**

View file

@ -1,14 +0,0 @@
package org.xbib.graphics.pdfbox.layout.element.render;
public enum Layouts {
VERTICAL,
COLUMN;
public Layout getLayout() {
switch (name()) {
case "VERTICAL": return new VerticalLayout();
case "COLUMN": return new ColumnLayout();
}
throw new IllegalArgumentException();
}
}

View file

@ -3,20 +3,19 @@ package org.xbib.graphics.pdfbox.layout.element.render;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
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.Document;
import org.xbib.graphics.pdfbox.layout.element.Element;
import org.xbib.graphics.pdfbox.layout.element.Orientation;
import org.xbib.graphics.pdfbox.layout.element.PageFormat;
import org.xbib.graphics.pdfbox.layout.element.PositionControl;
import org.xbib.graphics.pdfbox.layout.element.PositionControl.MarkPosition;
import org.xbib.graphics.pdfbox.layout.element.PositionControl.MovePosition;
import org.xbib.graphics.pdfbox.layout.element.PositionControl.ResetPosition;
import org.xbib.graphics.pdfbox.layout.element.PositionControl.SetPosition;
import org.xbib.graphics.pdfbox.layout.element.PositionElement;
import org.xbib.graphics.pdfbox.layout.element.PositionElement.MarkPosition;
import org.xbib.graphics.pdfbox.layout.element.PositionElement.MovePosition;
import org.xbib.graphics.pdfbox.layout.element.PositionElement.ResetPosition;
import org.xbib.graphics.pdfbox.layout.element.PositionElement.SetPosition;
import org.xbib.graphics.pdfbox.layout.text.DrawContext;
import org.xbib.graphics.pdfbox.layout.text.DrawListener;
import org.xbib.graphics.pdfbox.layout.text.Position;
import org.xbib.graphics.pdfbox.layout.position.Position;
import org.xbib.graphics.pdfbox.layout.text.annotations.AnnotationDrawListener;
import java.io.Closeable;
import java.io.IOException;
@ -31,9 +30,11 @@ public class RenderContext implements Renderer, Closeable, DrawContext, DrawList
private final PDDocument pdDocument;
private final AnnotationDrawListener annotationDrawListener;
private PDPage page;
private int pageIndex = 0;
private int pageIndex;
private PDPageContentStream contentStream;
@ -43,13 +44,13 @@ public class RenderContext implements Renderer, Closeable, DrawContext, DrawList
private Position maxPositionOnPage;
private Layout layout = new VerticalLayout();
private Layout layout;
private PageFormat nextPageFormat;
private PageFormat pageFormat;
private final AnnotationDrawListener annotationDrawListener;
private Transform transform;
/**
* Creates a render context.
@ -63,14 +64,7 @@ public class RenderContext implements Renderer, Closeable, DrawContext, DrawList
this.pdDocument = pdDocument;
this.pageFormat = document.getPageFormat();
this.annotationDrawListener = new AnnotationDrawListener(this);
newPage();
}
/**
* @return the current {@link Layout} used for rendering.
*/
public Layout getLayout() {
return layout;
this.layout = new VerticalLayout();
}
/**
@ -83,6 +77,13 @@ public class RenderContext implements Renderer, Closeable, DrawContext, DrawList
resetPositionToLeftEndOfPage();
}
/**
* @return the current {@link Layout} used for rendering.
*/
public Layout getLayout() {
return layout;
}
public void setPageFormat(final PageFormat pageFormat) {
if (pageFormat == null) {
this.pageFormat = document.getPageFormat();
@ -174,51 +175,20 @@ public class RenderContext implements Renderer, Closeable, DrawContext, DrawList
return Orientation.PORTRAIT;
}
/**
* @return <code>true</code> if the page is rotated by 90/270 degrees.
*/
public boolean isPageTilted() {
return page.getRotation() == 90 || page.getRotation() == 270;
}
/**
* @return the page' width, or - if {@link #isPageTilted() rotated} - the
* height.
*/
public float getPageWidth() {
if (isPageTilted()) {
return page.getMediaBox().getHeight();
}
return page.getMediaBox().getWidth();
}
/**
* @return the page' height, or - if {@link #isPageTilted() rotated} - the
* width.
*/
public float getPageHeight() {
if (isPageTilted()) {
return page.getMediaBox().getWidth();
}
return page.getMediaBox().getHeight();
}
/**
* @return the {@link #getPageWidth() width of the page} respecting the
* margins.
*/
public float getWidth() {
return getPageWidth() - getPageFormat().getMarginLeft()
- getPageFormat().getMarginRight();
return getPageWidth() - getPageFormat().getMarginLeft() - getPageFormat().getMarginRight();
}
/**
* @return the {@link #getPageHeight() height of the page} respecting the
* margins.
*/
public float getHeight() {
return getPageHeight() - getPageFormat().getMarginTop()
- getPageFormat().getMarginBottom();
return getPageHeight() - getPageFormat().getMarginTop() - getPageFormat().getMarginBottom();
}
/**
@ -250,23 +220,21 @@ public class RenderContext implements Renderer, Closeable, DrawContext, DrawList
@Override
public PDPageContentStream getCurrentPageContentStream() {
return getContentStream();
}
/**
* @return the current PDPageContentStream.
*/
public PDPageContentStream getContentStream() {
return contentStream;
}
/**
* @return the current page index (starting from 0).
*/
public int getPageIndex() {
return pageIndex;
}
public void setTransform(Transform transform) {
this.transform = transform;
}
public Transform getTransform() {
return transform;
}
@Override
public boolean render(RenderContext renderContext,
Element element,
@ -279,9 +247,6 @@ public class RenderContext implements Renderer, Closeable, DrawContext, DrawList
newPage();
return true;
}
if (element instanceof PositionControl) {
return render((PositionControl) element);
}
if (element instanceof PageFormat) {
nextPageFormat = (PageFormat) element;
return true;
@ -290,19 +255,25 @@ public class RenderContext implements Renderer, Closeable, DrawContext, DrawList
setLayout((Layout) element);
return true;
}
if (element instanceof PositionElement) {
return render((PositionElement) element);
}
if (element instanceof Transform) {
setTransform((Transform) element);
}
return false;
}
protected boolean render(PositionControl positionControl) {
if (positionControl instanceof MarkPosition) {
protected boolean render(PositionElement positionElement) {
if (positionElement instanceof MarkPosition) {
setMarkedPosition(getCurrentPosition());
return true;
}
if (positionControl instanceof ResetPosition) {
if (positionElement instanceof ResetPosition) {
currentPosition = new Position(getMarkedPosition().getX(), getMarkedPosition().getY());
}
if (positionControl instanceof SetPosition) {
SetPosition setPosition = (SetPosition) positionControl;
if (positionElement instanceof SetPosition) {
SetPosition setPosition = (SetPosition) positionElement;
Float x = setPosition.getX();
if (x == null) {
x = getCurrentPosition().getX();
@ -314,19 +285,14 @@ public class RenderContext implements Renderer, Closeable, DrawContext, DrawList
currentPosition = new Position(x, y);
return true;
}
if (positionControl instanceof MovePosition) {
MovePosition movePosition = (MovePosition) positionControl;
if (positionElement instanceof MovePosition) {
MovePosition movePosition = (MovePosition) positionElement;
movePositionBy(movePosition.getX(), movePosition.getY());
return true;
}
return false;
}
/**
* Triggers a new page.
*
* @throws IOException by pdfbox
*/
public void newPage() throws IOException {
if (closePage()) {
++pageIndex;
@ -336,16 +302,10 @@ public class RenderContext implements Renderer, Closeable, DrawContext, DrawList
}
this.page = new PDPage(getPageFormat().getMediaBox());
this.pdDocument.addPage(page);
this.contentStream = new PDPageContentStream(pdDocument, page, PDPageContentStream.AppendMode.APPEND, true);
this.contentStream = new PDPageContentStream(pdDocument, page,
PDPageContentStream.AppendMode.APPEND, true);
if (getPageOrientation() != getPageFormat().getOrientation()) {
if (isPageTilted()) {
page.setRotation(0);
} else {
page.setRotation(90);
}
}
if (isPageTilted()) {
contentStream.transform(new Matrix(0, 1, -1, 0, getPageHeight(), 0));
page.setRotation(90);
}
resetPositionToUpperLeft();
resetMaxPositionOnPage();
@ -353,12 +313,6 @@ public class RenderContext implements Renderer, Closeable, DrawContext, DrawList
annotationDrawListener.beforePage(this);
}
/**
* Closes the current page.
*
* @return <code>true</code> if the current page has not been closed before.
* @throws IOException by pdfbox
*/
public boolean closePage() throws IOException {
if (contentStream != null) {
annotationDrawListener.afterPage(this);
@ -386,32 +340,17 @@ public class RenderContext implements Renderer, Closeable, DrawContext, DrawList
annotationDrawListener.drawn(drawnObject, upperLeft, width, height);
}
/**
* Updates the maximum right resp. bottom position on the page.
*
* @param upperLeft the upper left position
* @param width the width
* @param height the height
*/
protected void updateMaxPositionOnPage(Position upperLeft, float width, float height) {
maxPositionOnPage = new Position(Math.max(maxPositionOnPage.getX(),
upperLeft.getX() + width), Math.min(maxPositionOnPage.getY(),
upperLeft.getY() - height));
}
/**
* Resets the maximumn position to upper left.
*/
protected void resetMaxPositionOnPage() {
maxPositionOnPage = getUpperLeft();
}
/**
* @return the maximum right and bottom position of all
* objects rendered on this page so far.
*/
protected Position getMaxPositionOnPage() {
return maxPositionOnPage;
}
}

View file

@ -0,0 +1,6 @@
package org.xbib.graphics.pdfbox.layout.element.render;
import org.xbib.graphics.pdfbox.layout.element.Element;
public interface Transform extends Element, Renderer {
}

View file

@ -9,7 +9,6 @@ import org.xbib.graphics.pdfbox.layout.element.Element;
import org.xbib.graphics.pdfbox.layout.element.PageFormat;
import org.xbib.graphics.pdfbox.layout.element.VerticalSpacer;
import org.xbib.graphics.pdfbox.layout.text.Alignment;
import org.xbib.graphics.pdfbox.layout.text.Position;
import org.xbib.graphics.pdfbox.layout.text.WidthRespecting;
import java.io.IOException;
@ -78,24 +77,22 @@ public class VerticalLayout implements Layout {
public void render(RenderContext renderContext, Drawable drawable, LayoutHint layoutHint) throws IOException {
if (drawable.getAbsolutePosition() != null) {
renderAbsolute(renderContext, drawable, drawable.getAbsolutePosition());
renderAbsolute(renderContext, drawable);
} else {
renderRelative(renderContext, drawable, layoutHint);
}
}
/**
* Draws at the given position, ignoring all layouting rules.
* Draws at the absolute position, ignoring all layouting rules.
*
* @param renderContext the context providing all rendering state.
* @param drawable the drawable to draw.
* @param position the left upper position to start drawing at.
* @throws IOException by pdfbox
*/
protected void renderAbsolute(RenderContext renderContext,
Drawable drawable,
Position position) throws IOException {
drawable.draw(renderContext.getPdDocument(), renderContext.getContentStream(), position, renderContext);
protected void renderAbsolute(RenderContext renderContext, Drawable drawable) throws IOException {
drawable.draw(renderContext.getPdDocument(), renderContext.getCurrentPageContentStream(),
drawable.getAbsolutePosition(), renderContext);
}
/**
@ -170,7 +167,6 @@ public class VerticalLayout implements Layout {
}
Dividable.Divided divided = dividable.divide(renderContext.getRemainingHeight(), renderContext.getHeight());
drawRelativePartAndMovePosition(renderContext, divided.getFirst(), layoutHint, true);
// new page
turnPage(renderContext);
drawablePart = divided.getTail();
drawablePart = removeLeadingEmptyVerticalSpace(drawablePart, renderContext);
@ -200,7 +196,7 @@ public class VerticalLayout implements Layout {
Drawable drawable,
LayoutHint layoutHint,
boolean movePosition) throws IOException {
PDPageContentStream contentStream = renderContext.getContentStream();
PDPageContentStream contentStream = renderContext.getCurrentPageContentStream();
PageFormat pageFormat = renderContext.getPageFormat();
float offsetX = 0;
if (layoutHint instanceof VerticalLayoutHint) {
@ -220,8 +216,11 @@ public class VerticalLayout implements Layout {
}
}
contentStream.saveGraphicsState();
contentStream.addRect(0, pageFormat.getMarginBottom(), renderContext.getPageWidth(),
renderContext.getHeight());
if (renderContext.getTransform() != null) {
renderContext.getTransform().render(renderContext, null, null);
}
contentStream.addRect(pageFormat.getMarginTop(), pageFormat.getMarginBottom(),
renderContext.getPageWidth(), renderContext.getHeight());
contentStream.clip();
drawable.draw(renderContext.getPdDocument(), contentStream,
renderContext.getCurrentPosition().add(offsetX, 0), renderContext);

View file

@ -8,7 +8,7 @@ import org.xbib.graphics.pdfbox.layout.element.render.VerticalLayoutHint;
import org.xbib.graphics.pdfbox.layout.element.scripting.Engine;
import org.xbib.graphics.pdfbox.layout.element.scripting.State;
import org.xbib.graphics.pdfbox.layout.text.Alignment;
import org.xbib.graphics.pdfbox.layout.text.Position;
import org.xbib.graphics.pdfbox.layout.position.Position;
import org.xbib.settings.Settings;
import java.io.IOException;

View file

@ -15,7 +15,7 @@ import org.xbib.graphics.pdfbox.layout.table.ParagraphCell;
import org.xbib.graphics.pdfbox.layout.table.TextCell;
import org.xbib.graphics.pdfbox.layout.table.VerticalAlignment;
import org.xbib.graphics.pdfbox.layout.text.Alignment;
import org.xbib.graphics.pdfbox.layout.text.Position;
import org.xbib.graphics.pdfbox.layout.position.Position;
import org.xbib.settings.Settings;
import java.awt.Color;

View file

@ -5,7 +5,7 @@ import org.xbib.graphics.pdfbox.layout.element.render.VerticalLayoutHint;
import org.xbib.graphics.pdfbox.layout.element.scripting.Engine;
import org.xbib.graphics.pdfbox.layout.element.scripting.State;
import org.xbib.graphics.pdfbox.layout.text.Alignment;
import org.xbib.graphics.pdfbox.layout.text.Position;
import org.xbib.graphics.pdfbox.layout.position.Position;
import org.xbib.settings.Settings;
import java.io.IOException;

View file

@ -5,7 +5,7 @@ import org.xbib.graphics.pdfbox.layout.element.HorizontalRuler;
import org.xbib.graphics.pdfbox.layout.element.scripting.Engine;
import org.xbib.graphics.pdfbox.layout.element.scripting.State;
import org.xbib.graphics.pdfbox.layout.shape.Stroke;
import org.xbib.graphics.pdfbox.layout.text.Position;
import org.xbib.graphics.pdfbox.layout.position.Position;
import org.xbib.settings.Settings;
import java.awt.Color;

View file

@ -6,7 +6,7 @@ import org.xbib.graphics.pdfbox.layout.element.render.VerticalLayoutHint;
import org.xbib.graphics.pdfbox.layout.element.scripting.Engine;
import org.xbib.graphics.pdfbox.layout.element.scripting.State;
import org.xbib.graphics.pdfbox.layout.text.Alignment;
import org.xbib.graphics.pdfbox.layout.text.Position;
import org.xbib.graphics.pdfbox.layout.position.Position;
import org.xbib.settings.Settings;
import java.io.IOException;

View file

@ -1,16 +0,0 @@
package org.xbib.graphics.pdfbox.layout.element.scripting.command;
import org.xbib.graphics.pdfbox.layout.element.scripting.Engine;
import org.xbib.graphics.pdfbox.layout.element.scripting.State;
import org.xbib.settings.Settings;
import java.io.IOException;
import java.util.Locale;
public class LayoutCommand implements Command {
@Override
public void execute(Engine engine, State state, Settings settings) throws IOException {
String layout = settings.get("layout", "vertical").toUpperCase(Locale.ROOT);
}
}

View file

@ -1,6 +1,6 @@
package org.xbib.graphics.pdfbox.layout.element.scripting.command;
import org.xbib.graphics.pdfbox.layout.element.PositionControl;
import org.xbib.graphics.pdfbox.layout.element.PositionElement;
import org.xbib.graphics.pdfbox.layout.element.scripting.Engine;
import org.xbib.graphics.pdfbox.layout.element.scripting.State;
import org.xbib.settings.Settings;
@ -11,7 +11,7 @@ public class MarkpositionCommand implements Command {
@Override
public void execute(Engine engine, State state, Settings settings) throws IOException {
PositionControl.MarkPosition markPosition = PositionControl.createMarkPosition();
PositionElement.MarkPosition markPosition = PositionElement.createMarkPosition();
state.elements.peek().add(markPosition);
}
}

View file

@ -1,17 +1,20 @@
package org.xbib.graphics.pdfbox.layout.element.scripting.command;
import org.xbib.graphics.pdfbox.layout.element.PositionControl;
import org.xbib.graphics.pdfbox.layout.element.PositionElement;
import org.xbib.graphics.pdfbox.layout.element.scripting.Engine;
import org.xbib.graphics.pdfbox.layout.element.scripting.State;
import org.xbib.settings.Settings;
import java.io.IOException;
import static org.xbib.graphics.pdfbox.layout.util.PdfUtil.mmToPt;
public class MovepositionCommand implements Command {
@Override
public void execute(Engine engine, State state, Settings settings) throws IOException {
PositionControl.MovePosition movePosition = PositionControl.createMovePosition(settings.getAsFloat("x", null), settings.getAsFloat("y", null));
PositionElement.MovePosition movePosition = PositionElement.createMovePosition(mmToPt(settings.getAsFloat("x", 0f)),
mmToPt(settings.getAsFloat("y", null)));
state.elements.peek().add(movePosition);
}
}

View file

@ -5,7 +5,7 @@ import org.xbib.graphics.pdfbox.layout.element.render.VerticalLayoutHint;
import org.xbib.graphics.pdfbox.layout.element.scripting.Engine;
import org.xbib.graphics.pdfbox.layout.element.scripting.State;
import org.xbib.graphics.pdfbox.layout.text.Alignment;
import org.xbib.graphics.pdfbox.layout.text.Position;
import org.xbib.graphics.pdfbox.layout.position.Position;
import org.xbib.settings.Settings;
import java.io.IOException;

View file

@ -5,11 +5,11 @@ import org.xbib.graphics.pdfbox.layout.element.PathElement;
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.State;
import org.xbib.graphics.pdfbox.layout.shape.LinePosiiton;
import org.xbib.graphics.pdfbox.layout.shape.MovePosition;
import org.xbib.graphics.pdfbox.layout.position.LinePosiiton;
import org.xbib.graphics.pdfbox.layout.position.MovePosition;
import org.xbib.graphics.pdfbox.layout.shape.Path;
import org.xbib.graphics.pdfbox.layout.shape.Stroke;
import org.xbib.graphics.pdfbox.layout.text.Position;
import org.xbib.graphics.pdfbox.layout.position.Position;
import org.xbib.settings.Settings;
import java.awt.Color;

View file

@ -1,6 +1,6 @@
package org.xbib.graphics.pdfbox.layout.element.scripting.command;
import org.xbib.graphics.pdfbox.layout.element.PositionControl;
import org.xbib.graphics.pdfbox.layout.element.PositionElement;
import org.xbib.graphics.pdfbox.layout.element.scripting.Engine;
import org.xbib.graphics.pdfbox.layout.element.scripting.State;
import org.xbib.settings.Settings;
@ -11,7 +11,7 @@ public class ResetpositionCommand implements Command {
@Override
public void execute(Engine engine, State state, Settings settings) throws IOException {
PositionControl.ResetPosition resetPosition = PositionControl.createResetPosition();
PositionElement.ResetPosition resetPosition = PositionElement.createResetPosition();
state.elements.peek().add(resetPosition);
}
}

View file

@ -1,17 +1,21 @@
package org.xbib.graphics.pdfbox.layout.element.scripting.command;
import org.xbib.graphics.pdfbox.layout.element.PositionControl;
import org.xbib.graphics.pdfbox.layout.element.PositionElement;
import org.xbib.graphics.pdfbox.layout.element.scripting.Engine;
import org.xbib.graphics.pdfbox.layout.element.scripting.State;
import org.xbib.settings.Settings;
import java.io.IOException;
import static org.xbib.graphics.pdfbox.layout.util.PdfUtil.mmToPt;
public class SetpositionCommand implements Command {
@Override
public void execute(Engine engine, State state, Settings settings) throws IOException {
PositionControl.SetPosition setPosition = PositionControl.createSetPosition(settings.getAsFloat("x", null), settings.getAsFloat("y", null));
PositionElement.SetPosition setPosition =
PositionElement.createSetPosition(mmToPt(settings.getAsFloat("x", 0f)),
mmToPt(settings.getAsFloat("y", 0f)));
state.elements.peek().add(setPosition);
}
}

View file

@ -3,7 +3,7 @@ package org.xbib.graphics.pdfbox.layout.element.scripting.command;
import org.xbib.graphics.pdfbox.layout.element.TableElement;
import org.xbib.graphics.pdfbox.layout.element.scripting.Engine;
import org.xbib.graphics.pdfbox.layout.element.scripting.State;
import org.xbib.graphics.pdfbox.layout.text.Position;
import org.xbib.graphics.pdfbox.layout.position.Position;
import org.xbib.settings.Settings;
import java.io.IOException;

View file

@ -10,7 +10,7 @@ import org.xbib.graphics.pdfbox.layout.font.Fonts;
import org.xbib.graphics.pdfbox.layout.element.scripting.Engine;
import org.xbib.graphics.pdfbox.layout.element.scripting.State;
import org.xbib.graphics.pdfbox.layout.text.Alignment;
import org.xbib.graphics.pdfbox.layout.text.Position;
import org.xbib.graphics.pdfbox.layout.position.Position;
import org.xbib.settings.Settings;
import java.util.Locale;

View file

@ -1,6 +1,4 @@
package org.xbib.graphics.pdfbox.layout.shape;
import org.xbib.graphics.pdfbox.layout.text.Position;
package org.xbib.graphics.pdfbox.layout.position;
public class LinePosiiton extends Position {
/**

View file

@ -1,6 +1,4 @@
package org.xbib.graphics.pdfbox.layout.shape;
import org.xbib.graphics.pdfbox.layout.text.Position;
package org.xbib.graphics.pdfbox.layout.position;
public class MovePosition extends Position {
/**

View file

@ -1,4 +1,4 @@
package org.xbib.graphics.pdfbox.layout.text;
package org.xbib.graphics.pdfbox.layout.position;
/**
* In order to avoid dependencies to AWT classes (e.g. Point), we have our own

View file

@ -3,7 +3,7 @@ package org.xbib.graphics.pdfbox.layout.shape;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPageContentStream;
import org.xbib.graphics.pdfbox.layout.text.DrawListener;
import org.xbib.graphics.pdfbox.layout.text.Position;
import org.xbib.graphics.pdfbox.layout.position.Position;
import java.awt.Color;
import java.io.IOException;

View file

@ -1,7 +1,7 @@
package org.xbib.graphics.pdfbox.layout.shape;
import org.apache.pdfbox.pdmodel.PDPageContentStream;
import org.xbib.graphics.pdfbox.layout.text.Position;
import org.xbib.graphics.pdfbox.layout.position.Position;
import java.io.IOException;
/**
@ -9,9 +9,6 @@ import java.io.IOException;
*/
public class Ellipse extends RoundRect {
/**
* Default constructor.
*/
public Ellipse() {
super(0);
}

View file

@ -2,8 +2,10 @@ package org.xbib.graphics.pdfbox.layout.shape;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPageContentStream;
import org.xbib.graphics.pdfbox.layout.position.LinePosiiton;
import org.xbib.graphics.pdfbox.layout.position.MovePosition;
import org.xbib.graphics.pdfbox.layout.text.DrawListener;
import org.xbib.graphics.pdfbox.layout.text.Position;
import org.xbib.graphics.pdfbox.layout.position.Position;
import java.awt.Color;
import java.io.IOException;
@ -26,6 +28,8 @@ public class Path implements Shape {
Color color,
Stroke stroke,
DrawListener drawListener) throws IOException {
add(pdDocument, contentStream, upperLeft, width, height);
contentStream.saveGraphicsState();
float x = upperLeft.getX();
float y = upperLeft.getY() - stroke.getLineWidth() / 2;
contentStream.setStrokingColor(color);
@ -38,6 +42,7 @@ public class Path implements Shape {
}
}
contentStream.stroke();
contentStream.restoreGraphicsState();
if (drawListener != null) {
drawListener.drawn(this, upperLeft, width, height);
}
@ -52,5 +57,6 @@ public class Path implements Shape {
@Override
public void add(PDDocument pdDocument, PDPageContentStream contentStream, Position upperLeft,
float width, float height) throws IOException {
// do nothing
}
}

View file

@ -2,7 +2,7 @@ package org.xbib.graphics.pdfbox.layout.shape;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPageContentStream;
import org.xbib.graphics.pdfbox.layout.text.Position;
import org.xbib.graphics.pdfbox.layout.position.Position;
import java.io.IOException;
/**

View file

@ -2,7 +2,7 @@ package org.xbib.graphics.pdfbox.layout.shape;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPageContentStream;
import org.xbib.graphics.pdfbox.layout.text.Position;
import org.xbib.graphics.pdfbox.layout.position.Position;
import java.io.IOException;
/**
@ -73,29 +73,22 @@ public class RoundRect extends AbstractShape {
float cornerRadiusY) throws IOException {
float nettoWidth = width - 2 * cornerRadiusX;
float nettoHeight = height - 2 * cornerRadiusY;
// top line
Position a = new Position(upperLeft.getX() + cornerRadiusX,
upperLeft.getY());
Position b = new Position(a.getX() + nettoWidth, a.getY());
// right line
Position c = new Position(upperLeft.getX() + width, upperLeft.getY()
- cornerRadiusY);
Position d = new Position(c.getX(), c.getY() - nettoHeight);
// bottom line
Position e = new Position(
upperLeft.getX() + width - cornerRadiusX, upperLeft.getY()
- height);
Position f = new Position(e.getX() - nettoWidth, e.getY());
// left line
Position g = new Position(upperLeft.getX(), upperLeft.getY() - height
+ cornerRadiusY);
Position h = new Position(g.getX(), upperLeft.getY()
- cornerRadiusY);
float bezX = cornerRadiusX * BEZ;
float bezY = cornerRadiusY * BEZ;
contentStream.moveTo(a.getX(), a.getY());
addLine(contentStream, a.getX(), a.getY(), b.getX(), b.getY());
contentStream.curveTo(b.getX() + bezX, b.getY(), c.getX(),

View file

@ -3,7 +3,7 @@ package org.xbib.graphics.pdfbox.layout.shape;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPageContentStream;
import org.xbib.graphics.pdfbox.layout.text.DrawListener;
import org.xbib.graphics.pdfbox.layout.text.Position;
import org.xbib.graphics.pdfbox.layout.position.Position;
import java.awt.Color;
import java.io.IOException;

View file

@ -2,7 +2,7 @@ package org.xbib.graphics.pdfbox.layout.table.render;
import org.xbib.graphics.pdfbox.layout.element.Drawable;
import org.xbib.graphics.pdfbox.layout.table.DrawableCell;
import org.xbib.graphics.pdfbox.layout.text.Position;
import org.xbib.graphics.pdfbox.layout.position.Position;
import org.xbib.graphics.pdfbox.layout.text.WidthRespecting;
import java.io.IOException;

View file

@ -8,7 +8,7 @@ import org.xbib.graphics.pdfbox.layout.table.HorizontalAlignment;
import org.xbib.graphics.pdfbox.layout.table.ParagraphCell;
import org.xbib.graphics.pdfbox.layout.text.Alignment;
import org.xbib.graphics.pdfbox.layout.text.DrawContext;
import org.xbib.graphics.pdfbox.layout.text.Position;
import org.xbib.graphics.pdfbox.layout.position.Position;
import org.xbib.graphics.pdfbox.layout.text.annotations.AnnotationDrawListener;
import java.util.EnumMap;

View file

@ -1,5 +1,7 @@
package org.xbib.graphics.pdfbox.layout.text;
import org.xbib.graphics.pdfbox.layout.position.Position;
/**
* Called if an object has been drawn.
*/

View file

@ -1,6 +1,8 @@
package org.xbib.graphics.pdfbox.layout.text;
import org.apache.pdfbox.pdmodel.PDPageContentStream;
import org.xbib.graphics.pdfbox.layout.position.Position;
import java.io.IOException;
/**

View file

@ -3,7 +3,7 @@ package org.xbib.graphics.pdfbox.layout.text;
import org.apache.pdfbox.pdmodel.PDPageContentStream;
import org.xbib.graphics.pdfbox.layout.font.Font;
import org.xbib.graphics.pdfbox.layout.font.FontDescriptor;
import org.xbib.graphics.pdfbox.layout.util.TextSequenceUtil;
import org.xbib.graphics.pdfbox.layout.position.Position;
import java.util.ArrayList;
import java.util.HashMap;

View file

@ -3,7 +3,7 @@ package org.xbib.graphics.pdfbox.layout.text;
import org.apache.pdfbox.pdmodel.PDPageContentStream;
import org.apache.pdfbox.util.Matrix;
import org.xbib.graphics.pdfbox.layout.font.FontDescriptor;
import org.xbib.graphics.pdfbox.layout.util.TextSequenceUtil;
import org.xbib.graphics.pdfbox.layout.position.Position;
import java.awt.Color;
import java.io.IOException;

View file

@ -1,21 +1,13 @@
package org.xbib.graphics.pdfbox.layout.util;
package org.xbib.graphics.pdfbox.layout.text;
import org.apache.pdfbox.pdmodel.PDPageContentStream;
import org.xbib.graphics.pdfbox.layout.element.Dividable.Divided;
import org.xbib.graphics.pdfbox.layout.element.Paragraph;
import org.xbib.graphics.pdfbox.layout.font.FontDescriptor;
import org.xbib.graphics.pdfbox.layout.text.Alignment;
import org.xbib.graphics.pdfbox.layout.text.DrawListener;
import org.xbib.graphics.pdfbox.layout.text.Indent;
import org.xbib.graphics.pdfbox.layout.text.NewLine;
import org.xbib.graphics.pdfbox.layout.text.Position;
import org.xbib.graphics.pdfbox.layout.text.ReplacedWhitespace;
import org.xbib.graphics.pdfbox.layout.text.StyledText;
import org.xbib.graphics.pdfbox.layout.text.TextFlow;
import org.xbib.graphics.pdfbox.layout.text.TextFragment;
import org.xbib.graphics.pdfbox.layout.text.TextLine;
import org.xbib.graphics.pdfbox.layout.text.TextSequence;
import org.xbib.graphics.pdfbox.layout.text.WrappingNewLine;
import org.xbib.graphics.pdfbox.layout.position.Position;
import org.xbib.graphics.pdfbox.layout.util.Pair;
import org.xbib.graphics.pdfbox.layout.util.WordBreakerFactory;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.ArrayList;

View file

@ -8,7 +8,7 @@ import org.xbib.graphics.pdfbox.layout.text.Alignment;
import org.xbib.graphics.pdfbox.layout.text.DrawContext;
import org.xbib.graphics.pdfbox.layout.text.DrawListener;
import org.xbib.graphics.pdfbox.layout.text.DrawableText;
import org.xbib.graphics.pdfbox.layout.text.Position;
import org.xbib.graphics.pdfbox.layout.position.Position;
/**
* This listener has to be passed to all

View file

@ -2,7 +2,7 @@ package org.xbib.graphics.pdfbox.layout.text.annotations;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.xbib.graphics.pdfbox.layout.text.DrawContext;
import org.xbib.graphics.pdfbox.layout.text.Position;
import org.xbib.graphics.pdfbox.layout.position.Position;
/**
* Processes an annotation.

View file

@ -12,7 +12,7 @@ import org.apache.pdfbox.pdmodel.interactive.annotation.PDBorderStyleDictionary;
import org.apache.pdfbox.pdmodel.interactive.documentnavigation.destination.PDDestination;
import org.apache.pdfbox.pdmodel.interactive.documentnavigation.destination.PDPageXYZDestination;
import org.xbib.graphics.pdfbox.layout.text.DrawContext;
import org.xbib.graphics.pdfbox.layout.text.Position;
import org.xbib.graphics.pdfbox.layout.position.Position;
import org.xbib.graphics.pdfbox.layout.text.annotations.Annotations.AnchorAnnotation;
import org.xbib.graphics.pdfbox.layout.text.annotations.Annotations.HyperlinkAnnotation;
import org.xbib.graphics.pdfbox.layout.text.annotations.Annotations.HyperlinkAnnotation.LinkStyle;

View file

@ -4,7 +4,7 @@ import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPageContentStream;
import org.xbib.graphics.pdfbox.layout.shape.Stroke;
import org.xbib.graphics.pdfbox.layout.text.DrawContext;
import org.xbib.graphics.pdfbox.layout.text.Position;
import org.xbib.graphics.pdfbox.layout.position.Position;
import org.xbib.graphics.pdfbox.layout.text.StyledText;
import org.xbib.graphics.pdfbox.layout.text.annotations.Annotations.UnderlineAnnotation;
import java.awt.Color;

View file

@ -1,6 +1,7 @@
package org.xbib.graphics.pdfbox.layout.util;
import org.xbib.graphics.pdfbox.layout.font.FontDescriptor;
import org.xbib.graphics.pdfbox.layout.text.TextSequenceUtil;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

View file

@ -13,7 +13,7 @@ import org.xbib.graphics.pdfbox.layout.element.Paragraph;
import org.xbib.graphics.pdfbox.layout.font.BaseFont;
import org.xbib.graphics.pdfbox.layout.font.FontDescriptor;
import org.xbib.graphics.pdfbox.layout.text.DrawContext;
import org.xbib.graphics.pdfbox.layout.text.Position;
import org.xbib.graphics.pdfbox.layout.position.Position;
import org.xbib.graphics.pdfbox.layout.text.annotations.Annotated;
import org.xbib.graphics.pdfbox.layout.text.annotations.AnnotatedStyledText;
import org.xbib.graphics.pdfbox.layout.text.annotations.Annotation;

View file

@ -15,10 +15,10 @@ import org.xbib.graphics.pdfbox.layout.shape.Stroke;
import org.xbib.graphics.pdfbox.layout.shape.Stroke.CapStyle;
import org.xbib.graphics.pdfbox.layout.text.Alignment;
import org.xbib.graphics.pdfbox.layout.font.BaseFont;
import org.xbib.graphics.pdfbox.layout.text.Position;
import org.xbib.graphics.pdfbox.layout.position.Position;
import org.xbib.graphics.pdfbox.layout.text.TextFlow;
import org.xbib.graphics.pdfbox.layout.text.TextFlowUtil;
import org.xbib.graphics.pdfbox.layout.util.TextSequenceUtil;
import org.xbib.graphics.pdfbox.layout.text.TextSequenceUtil;
import java.awt.Color;
import java.io.FileOutputStream;
import java.io.IOException;
@ -101,7 +101,7 @@ public class CustomRendererTest {
TextFlow text = TextFlowUtil.createTextFlow(content, fontDescriptor, 1.2f, 0f);
float offset = renderContext.getPageFormat().getMarginLeft() +
TextSequenceUtil.getOffset(text, renderContext.getWidth(), Alignment.RIGHT);
text.drawText(renderContext.getContentStream(), new Position(
text.drawText(renderContext.getCurrentPageContentStream(), new Position(
offset, 30), Alignment.RIGHT, null);
}
}

View file

@ -8,7 +8,7 @@ import org.xbib.graphics.pdfbox.layout.element.VerticalSpacer;
import org.xbib.graphics.pdfbox.layout.element.render.VerticalLayoutHint;
import org.xbib.graphics.pdfbox.layout.text.Alignment;
import org.xbib.graphics.pdfbox.layout.font.BaseFont;
import org.xbib.graphics.pdfbox.layout.text.Position;
import org.xbib.graphics.pdfbox.layout.position.Position;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileOutputStream;

View file

@ -8,10 +8,10 @@ import org.xbib.graphics.pdfbox.layout.element.render.RenderListener;
import org.xbib.graphics.pdfbox.layout.font.FontDescriptor;
import org.xbib.graphics.pdfbox.layout.text.Alignment;
import org.xbib.graphics.pdfbox.layout.font.BaseFont;
import org.xbib.graphics.pdfbox.layout.text.Position;
import org.xbib.graphics.pdfbox.layout.position.Position;
import org.xbib.graphics.pdfbox.layout.text.TextFlow;
import org.xbib.graphics.pdfbox.layout.text.TextFlowUtil;
import org.xbib.graphics.pdfbox.layout.util.TextSequenceUtil;
import org.xbib.graphics.pdfbox.layout.text.TextSequenceUtil;
import java.io.FileOutputStream;
public class ListenerTest {
@ -52,7 +52,7 @@ public class ListenerTest {
float offset = renderContext.getPageFormat().getMarginLeft()
+ TextSequenceUtil.getOffset(text,
renderContext.getWidth(), Alignment.RIGHT);
text.drawText(renderContext.getContentStream(), new Position(
text.drawText(renderContext.getCurrentPageContentStream(), new Position(
offset, 30), Alignment.RIGHT, null);
}
});

View file

@ -3,22 +3,26 @@ package org.xbib.graphics.pdfbox.layout.test;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.pdmodel.PDPageContentStream;
import org.apache.pdfbox.util.Matrix;
import org.junit.jupiter.api.Test;
import org.xbib.graphics.pdfbox.layout.element.PageFormat;
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.Shape;
import org.xbib.graphics.pdfbox.layout.shape.Stroke;
import org.xbib.graphics.pdfbox.layout.text.Alignment;
import org.xbib.graphics.pdfbox.layout.font.BaseFont;
import org.xbib.graphics.pdfbox.layout.text.DrawContext;
import org.xbib.graphics.pdfbox.layout.text.Position;
import org.xbib.graphics.pdfbox.layout.position.Position;
import org.xbib.graphics.pdfbox.layout.text.TextFlow;
import org.xbib.graphics.pdfbox.layout.text.TextFlowUtil;
import org.xbib.graphics.pdfbox.layout.util.TextSequenceUtil;
import org.xbib.graphics.pdfbox.layout.text.TextSequenceUtil;
import org.xbib.graphics.pdfbox.layout.text.annotations.AnnotationDrawListener;
import java.awt.Color;
import java.io.FileOutputStream;
import java.io.IOException;
public class LowLevelText {
@ -106,4 +110,42 @@ public class LowLevelText {
pdDocument.save(new FileOutputStream("build/lowleveltext.pdf"));
pdDocument.close();
}
@Test
public void transformTest() throws IOException {
PDDocument pdDocument = new PDDocument();
PDPage page = new PDPage(PageFormat.A4);
pdDocument.addPage(page);
final PDPageContentStream contentStream =
new PDPageContentStream(pdDocument, page, PDPageContentStream.AppendMode.APPEND, true);
contentStream.transform(Matrix.getTranslateInstance(30f, 30f));
contentStream.transform(Matrix.getScaleInstance(2.0f, 2.0f));
contentStream.saveGraphicsState();
contentStream.setStrokingColor(Color.BLACK);
contentStream.moveTo(10f, 10f);
contentStream.lineTo(10f, 20f);
contentStream.lineTo(20f, 20f);
contentStream.lineTo(20f, 10f);
contentStream.lineTo(10f, 10f);
contentStream.stroke();
contentStream.restoreGraphicsState();
float factor = 2.0f;
contentStream.saveGraphicsState();
contentStream.setStrokingColor(Color.BLUE);
contentStream.moveTo(factor * 10f, factor * 10f);
contentStream.lineTo(factor * 10f, factor * 20f);
contentStream.lineTo(factor * 20f, factor * 20f);
contentStream.lineTo(factor * 20f, factor * 10f);
contentStream.lineTo(factor * 10f, factor * 10f);
contentStream.stroke();
contentStream.restoreGraphicsState();
contentStream.close();
pdDocument.save(new FileOutputStream("build/lowlevelscale.pdf"));
pdDocument.close();
}
}

View file

@ -1,26 +1,50 @@
{
"type": "document",
"margin": "20 20 20 20",
"margin": "0 0 0 0",
"author": "Jörg Prante",
"elements": [
{
"type": "image",
"scalex": 0.2,
"scaley": 0.2,
"value": "iVBORw0KGgoAAAANSUhEUgAAAfQAAAC0AQMAAABYN0wRAAAABlBMVEUAAAD///+l2Z/dAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH1gsEDjEFTKgt4wAAAi5JREFUaN7t2s1ygyAQAOClHLiVHnvojI/io+mj+Sg+Qo4eGKmwgPkfdjfTNC05ZEblm+BmxQUFL/ocoPnmhX6Fy0/zzf+kN8L8fXl/Fr8Z9O/wACq1nQAs1S9Q/Mabb/6v+qOd0+O82/3C8eFYvn6X++evrno/lwNr88033/zr+Vlnv8BA99vIOSQ/nvahzs+x58G7OBynglnX+jGO78EfIHSF6FfIv2rDoZ7qHRb0wY/xJkT0odPYawvxVkX0M+RevyMj+rANXWj2BTEURD8W/4lzG6KPjWPUPjhen/uB5t/gJOpbKGkeHu07jteP85bsp+K/ON644uMsas0hqfT9mrPWhG2TvK31g8/ebgJrxYXg/TYCoe+CMzjybRt1Xu2+9zEUuL+v9DrsEniz+zgK6dRoqPR29774Ma5x0L2n+654tXvcYHnly2lU+b547fGvlHuHaVTlhys+TWaI3hz7rtb7K/4g9BgWkR8kfhJ6TF+qt0deiTzUe3XF56tY4I3EO6HPc3muT+nL81rkY+RT+rN9St+n+ZT+PG/2VdWf92sqxfRtn8rOOz6nL8O78C31ZSmL7pdUBHUXfj5dAbztO4mPNKc/w0ea05fhJ6EfA40zIhxHiH5N5SjXu1hEcT2Enpf5H8MjcyKvhd482Vuh74R+EHov80rotdBboe+F3nM9TqU133vMnguPzylVzdPO81Y0f+/9i6d7/vP35ptvvvnmX9i/8PuHzf9f/w3g1VrR1Tf4UwAAAABJRU5ErkJggg=="
"type": "setposition",
"x": 10,
"y": 290
},
{
"type": "barcode",
"symbol": "Code3Of9",
"value": "12345678"
},
{
"type": "setposition",
"x": 100,
"y": 290
},
{
"type": "image",
"scalex": 0.25,
"scaley": 0.25,
"value": "iVBORw0KGgoAAAANSUhEUgAAAfQAAAC0AQMAAABYN0wRAAAABlBMVEUAAAD///+l2Z/dAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH1gsEDjEFTKgt4wAAAi5JREFUaN7t2s1ygyAQAOClHLiVHnvojI/io+mj+Sg+Qo4eGKmwgPkfdjfTNC05ZEblm+BmxQUFL/ocoPnmhX6Fy0/zzf+kN8L8fXl/Fr8Z9O/wACq1nQAs1S9Q/Mabb/6v+qOd0+O82/3C8eFYvn6X++evrno/lwNr88033/zr+Vlnv8BA99vIOSQ/nvahzs+x58G7OBynglnX+jGO78EfIHSF6FfIv2rDoZ7qHRb0wY/xJkT0odPYawvxVkX0M+RevyMj+rANXWj2BTEURD8W/4lzG6KPjWPUPjhen/uB5t/gJOpbKGkeHu07jteP85bsp+K/ON644uMsas0hqfT9mrPWhG2TvK31g8/ebgJrxYXg/TYCoe+CMzjybRt1Xu2+9zEUuL+v9DrsEniz+zgK6dRoqPR29774Ma5x0L2n+654tXvcYHnly2lU+b547fGvlHuHaVTlhys+TWaI3hz7rtb7K/4g9BgWkR8kfhJ6TF+qt0deiTzUe3XF56tY4I3EO6HPc3muT+nL81rkY+RT+rN9St+n+ZT+PG/2VdWf92sqxfRtn8rOOz6nL8O78C31ZSmL7pdUBHUXfj5dAbztO4mPNKc/w0ea05fhJ6EfA40zIhxHiH5N5SjXu1hEcT2Enpf5H8MjcyKvhd482Vuh74R+EHov80rotdBboe+F3nM9TqU133vMnguPzylVzdPO81Y0f+/9i6d7/vP35ptvvvnmX9i/8PuHzf9f/w3g1VrR1Tf4UwAAAABJRU5ErkJggg=="
},
{
"type": "setposition",
"x": 10,
"y": 250
},
{
"type": "path",
"absolute": false,
"value": "10 10 100 10 100 20 10 20 10 10",
"value": "M 0 0 L 100 0 L 100 20 L 0 20 L 0 0",
"color": "red",
"dash": 1
},
{
"type": "setposition",
"x": 10,
"y": 220
},
{
"type": "path",
"value": "M 0 0 L 80 0 L 80 10 L 0 10 L 0 0",
"color": "blue"
},
{
"type": "paragraph",
"elements": [
@ -55,7 +79,8 @@
]
},
{
"type": "horizontalruler"
"type": "horizontalruler",
"width": 180
},
{
"type": "paragraph",