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;
exports org.xbib.graphics.pdfbox.layout.text.annotations; exports org.xbib.graphics.pdfbox.layout.text.annotations;
exports org.xbib.graphics.pdfbox.layout.util; 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.barcode;
requires transitive org.xbib.graphics.pdfbox; requires transitive org.xbib.graphics.pdfbox;
requires transitive org.xbib.settings.api; requires transitive org.xbib.settings.api;

View file

@ -461,7 +461,6 @@ public class Paragraph {
} }
} }
} }
// reset
alreadyTextInLine = false; alreadyTextInLine = false;
sinceLastWrapPoint.push(currentFont, fontSize, sinceLastWrapPoint.push(currentFont, fontSize,
Token.text(TokenType.TEXT, firstPartOfWord.toString())); Token.text(TokenType.TEXT, firstPartOfWord.toString()));
@ -544,14 +543,11 @@ public class Paragraph {
public float write(final PageContentStreamOptimized stream, float cursorX, float cursorY) { public float write(final PageContentStreamOptimized stream, float cursorX, float cursorY) {
if (drawDebug) { if (drawDebug) {
PDStreamUtils.rectFontMetrics(stream, cursorX, cursorY, font, fontSize); PDStreamUtils.rectFontMetrics(stream, cursorX, cursorY, font, fontSize);
// width // width
PDStreamUtils.rect(stream, cursorX, cursorY, width, 1, Color.RED); PDStreamUtils.rect(stream, cursorX, cursorY, width, 1, Color.RED);
} }
for (String line : getLines()) { for (String line : getLines()) {
line = line.trim(); line = line.trim();
float textX = cursorX; float textX = cursorX;
switch (align) { switch (align) {
case CENTER: case CENTER:
@ -563,9 +559,7 @@ public class Paragraph {
textX += getHorizontalFreeSpace(line); textX += getHorizontalFreeSpace(line);
break; break;
} }
PDStreamUtils.write(stream, line, font, fontSize, textX, cursorY, color); PDStreamUtils.write(stream, line, font, fontSize, textX, cursorY, color);
if (textType != null) { if (textType != null) {
switch (textType) { switch (textType) {
case HIGHLIGHT: case HIGHLIGHT:
@ -588,11 +582,8 @@ public class Paragraph {
break; break;
} }
} }
// move one "line" down
cursorY -= getFontHeight(); cursorY -= getFontHeight();
} }
return cursorY; 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, public void drawTitle(String title, PDFont font, int fontSize, float tableWidth, float height, String alignment,
float freeSpaceForPageBreak, WrappingFunction wrappingFunction, boolean drawHeaderMargin) float freeSpaceForPageBreak, WrappingFunction wrappingFunction, boolean drawHeaderMargin)
throws IOException { throws IOException {
ensureStreamIsOpen(); ensureStreamIsOpen();
if (isEndOfPage(freeSpaceForPageBreak)) { if (isEndOfPage(freeSpaceForPageBreak)) {
this.tableContentStream.close(); this.tableContentStream.close();
pageBreak(); pageBreak();
tableStartedAtNewPage = true; tableStartedAtNewPage = true;
} }
if (title == null) { if (title == null) {
// if you don't have title just use the height of maxTextBox in your
// "row"
yStart -= height; yStart -= height;
} else { } else {
PageContentStreamOptimized articleTitle = createPdPageContentStream(); PageContentStreamOptimized articleTitle = createPdPageContentStream();
@ -163,15 +158,11 @@ public abstract class Table<T extends PDPage> {
if (paragraph.getHeight() < height) { if (paragraph.getHeight() < height) {
yStart -= (height - paragraph.getHeight()); yStart -= (height - paragraph.getHeight());
} }
articleTitle.close(); articleTitle.close();
if (drawDebug) { if (drawDebug) {
// margin
PDStreamUtils.rect(tableContentStream, margin, yStart, width, headerBottomMargin, Color.CYAN); PDStreamUtils.rect(tableContentStream, margin, yStart, width, headerBottomMargin, Color.CYAN);
} }
} }
if (drawHeaderMargin) { if (drawHeaderMargin) {
yStart -= headerBottomMargin; yStart -= headerBottomMargin;
} }
@ -196,9 +187,7 @@ public abstract class Table<T extends PDPage> {
} }
/** /**
* <p> * Draws table.
* Draws table
* </p>
* *
* @return Y position of the table * @return Y position of the table
* @throws IOException if underlying stream has problem being written to. * @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) { for (Row<T> row : rows) {
if (header.contains(row)) { 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())) { if (isEndOfPage(getMinimumHeight())) {
pageBreak(); pageBreak();
tableStartedAtNewPage = true; tableStartedAtNewPage = true;
@ -218,25 +204,17 @@ public abstract class Table<T extends PDPage> {
} }
drawRow(row); drawRow(row);
} }
endTable(); endTable();
return yStart; return yStart;
} }
private void drawRow(Row<T> row) throws IOException { 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(); 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 (row != header && row != rows.get(0)) {
if (!isEndOfPage(rowHeight)) { if (!isEndOfPage(rowHeight)) {
row.removeTopBorders(); row.removeTopBorders();
} }
} }
// draw the bookmark
if (row.getBookmark() != null) { if (row.getBookmark() != null) {
PDPageXYZDestination bookmarkDestination = new PDPageXYZDestination(); PDPageXYZDestination bookmarkDestination = new PDPageXYZDestination();
bookmarkDestination.setPage(currentPage); bookmarkDestination.setPage(currentPage);
@ -244,11 +222,7 @@ public abstract class Table<T extends PDPage> {
row.getBookmark().setDestination(bookmarkDestination); row.getBookmark().setDestination(bookmarkDestination);
this.addBookmark(row.getBookmark()); this.addBookmark(row.getBookmark());
} }
// we want to remove the borders as often as possible
removeTopBorders = true; removeTopBorders = true;
// check also if we want all borders removed
if (allBordersRemoved()) { if (allBordersRemoved()) {
row.removeAllBorders(); 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.barcode.render.BarcodeGraphicsRenderer;
import org.xbib.graphics.pdfbox.PdfBoxGraphics2D; import org.xbib.graphics.pdfbox.PdfBoxGraphics2D;
import org.xbib.graphics.pdfbox.layout.text.DrawListener; 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 org.xbib.graphics.pdfbox.layout.text.WidthRespecting;
import java.awt.Color; import java.awt.Color;
import java.io.IOException; 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.chart.xy.XYChart;
import org.xbib.graphics.pdfbox.PdfBoxGraphics2D; import org.xbib.graphics.pdfbox.PdfBoxGraphics2D;
import org.xbib.graphics.pdfbox.layout.text.DrawListener; 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 org.xbib.graphics.pdfbox.layout.text.WidthRespecting;
import java.awt.geom.AffineTransform; 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.PDDocument;
import org.apache.pdfbox.pdmodel.PDPageContentStream; import org.apache.pdfbox.pdmodel.PDPageContentStream;
import org.xbib.graphics.pdfbox.layout.text.DrawListener; 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; import java.io.IOException;
/** /**

View file

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

View file

@ -4,7 +4,7 @@ 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.text.DrawListener; 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; 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.Shape;
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.text.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;
import java.awt.Color; import java.awt.Color;
import java.io.IOException; import java.io.IOException;

View file

@ -4,7 +4,7 @@ import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPageContentStream; import org.apache.pdfbox.pdmodel.PDPageContentStream;
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.text.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;
import java.awt.Color; import java.awt.Color;
import java.io.IOException; 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.LosslessFactory;
import org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject; import org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject;
import org.xbib.graphics.pdfbox.layout.text.DrawListener; 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 org.xbib.graphics.pdfbox.layout.text.WidthRespecting;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;

View file

@ -4,9 +4,9 @@ import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPageContentStream; import org.apache.pdfbox.pdmodel.PDPageContentStream;
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.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.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; 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.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;
import org.xbib.graphics.pdfbox.layout.text.Position; import org.xbib.graphics.pdfbox.layout.position.Position;
import java.awt.Color; import java.awt.Color;
import java.io.IOException; import java.io.IOException;
@ -68,7 +68,8 @@ public class PathElement implements Drawable, Element {
PDPageContentStream contentStream, PDPageContentStream contentStream,
Position upperLeft, Position upperLeft,
DrawListener drawListener) throws IOException { 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 @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 * 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. * 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); return new MovePosition(relativeX, relativeY);
} }
public static class MarkPosition extends PositionControl { public static class MarkPosition extends PositionElement {
private MarkPosition() { private MarkPosition() {
super("MARK_POSITION"); super("MARK_POSITION");
} }
} }
public static class ResetPosition extends PositionControl { public static class ResetPosition extends PositionElement {
private ResetPosition() { private ResetPosition() {
super("RESET_POSITION"); super("RESET_POSITION");
} }
} }
public static class SetPosition extends PositionControl { public static class SetPosition extends PositionElement {
private final Float newX; 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; private final float relativeX;
@ -106,7 +106,7 @@ public class PositionControl extends ControlElement {
} }
} }
private PositionControl(String name) { private PositionElement(String name) {
super(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.DefaultFontDrawer;
import org.xbib.graphics.pdfbox.font.FontDrawer; import org.xbib.graphics.pdfbox.font.FontDrawer;
import org.xbib.graphics.pdfbox.layout.text.DrawListener; 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.awt.color.ICC_Profile;
import java.io.IOException; 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.TableRenderer;
import org.xbib.graphics.pdfbox.layout.table.VerticalAlignment; import org.xbib.graphics.pdfbox.layout.table.VerticalAlignment;
import org.xbib.graphics.pdfbox.layout.text.DrawListener; 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.awt.Color;
import java.io.IOException; import java.io.IOException;

View file

@ -1,13 +1,13 @@
package org.xbib.graphics.pdfbox.layout.element; package org.xbib.graphics.pdfbox.layout.element;
import java.io.IOException; 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; private Float translateX;
@ -23,26 +23,6 @@ public class TransformElement implements Element, Drawable {
private Float angle; 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) { public void setTranslate(Float x, Float y) {
this.translateX = x; this.translateX = x;
this.translateY = y; this.translateY = y;
@ -59,16 +39,45 @@ public class TransformElement implements Element, Drawable {
this.rotateY = rotateY; 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 @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) { if (translateX != null && translateY != null) {
contentStream.transform(Matrix.getTranslateInstance(translateX, translateY)); renderContext.getCurrentPageContentStream().transform(Matrix.getTranslateInstance(translateX, translateY));
} }
if (scaleX != null && scaleY != null) { 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){ 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.PDDocument;
import org.apache.pdfbox.pdmodel.PDPageContentStream; import org.apache.pdfbox.pdmodel.PDPageContentStream;
import org.xbib.graphics.pdfbox.layout.text.DrawListener; 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; 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.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;
import org.xbib.graphics.pdfbox.layout.element.Orientation; import org.xbib.graphics.pdfbox.layout.element.Orientation;
import org.xbib.graphics.pdfbox.layout.element.PageFormat; import org.xbib.graphics.pdfbox.layout.element.PageFormat;
import org.xbib.graphics.pdfbox.layout.element.PositionControl; import org.xbib.graphics.pdfbox.layout.element.PositionElement;
import org.xbib.graphics.pdfbox.layout.element.PositionControl.MarkPosition; import org.xbib.graphics.pdfbox.layout.element.PositionElement.MarkPosition;
import org.xbib.graphics.pdfbox.layout.element.PositionControl.MovePosition; import org.xbib.graphics.pdfbox.layout.element.PositionElement.MovePosition;
import org.xbib.graphics.pdfbox.layout.element.PositionControl.ResetPosition; import org.xbib.graphics.pdfbox.layout.element.PositionElement.ResetPosition;
import org.xbib.graphics.pdfbox.layout.element.PositionControl.SetPosition; import org.xbib.graphics.pdfbox.layout.element.PositionElement.SetPosition;
import org.xbib.graphics.pdfbox.layout.text.DrawContext; import org.xbib.graphics.pdfbox.layout.text.DrawContext;
import org.xbib.graphics.pdfbox.layout.text.DrawListener; 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 org.xbib.graphics.pdfbox.layout.text.annotations.AnnotationDrawListener;
import java.io.Closeable; import java.io.Closeable;
import java.io.IOException; import java.io.IOException;
@ -31,9 +30,11 @@ public class RenderContext implements Renderer, Closeable, DrawContext, DrawList
private final PDDocument pdDocument; private final PDDocument pdDocument;
private final AnnotationDrawListener annotationDrawListener;
private PDPage page; private PDPage page;
private int pageIndex = 0; private int pageIndex;
private PDPageContentStream contentStream; private PDPageContentStream contentStream;
@ -43,13 +44,13 @@ public class RenderContext implements Renderer, Closeable, DrawContext, DrawList
private Position maxPositionOnPage; private Position maxPositionOnPage;
private Layout layout = new VerticalLayout(); private Layout layout;
private PageFormat nextPageFormat; private PageFormat nextPageFormat;
private PageFormat pageFormat; private PageFormat pageFormat;
private final AnnotationDrawListener annotationDrawListener; private Transform transform;
/** /**
* Creates a render context. * Creates a render context.
@ -63,14 +64,7 @@ public class RenderContext implements Renderer, Closeable, DrawContext, DrawList
this.pdDocument = pdDocument; this.pdDocument = pdDocument;
this.pageFormat = document.getPageFormat(); this.pageFormat = document.getPageFormat();
this.annotationDrawListener = new AnnotationDrawListener(this); this.annotationDrawListener = new AnnotationDrawListener(this);
newPage(); this.layout = new VerticalLayout();
}
/**
* @return the current {@link Layout} used for rendering.
*/
public Layout getLayout() {
return layout;
} }
/** /**
@ -83,6 +77,13 @@ public class RenderContext implements Renderer, Closeable, DrawContext, DrawList
resetPositionToLeftEndOfPage(); resetPositionToLeftEndOfPage();
} }
/**
* @return the current {@link Layout} used for rendering.
*/
public Layout getLayout() {
return layout;
}
public void setPageFormat(final PageFormat pageFormat) { public void setPageFormat(final PageFormat pageFormat) {
if (pageFormat == null) { if (pageFormat == null) {
this.pageFormat = document.getPageFormat(); this.pageFormat = document.getPageFormat();
@ -174,51 +175,20 @@ public class RenderContext implements Renderer, Closeable, DrawContext, DrawList
return Orientation.PORTRAIT; 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() { public float getPageWidth() {
if (isPageTilted()) {
return page.getMediaBox().getHeight();
}
return page.getMediaBox().getWidth(); return page.getMediaBox().getWidth();
} }
/**
* @return the page' height, or - if {@link #isPageTilted() rotated} - the
* width.
*/
public float getPageHeight() { public float getPageHeight() {
if (isPageTilted()) {
return page.getMediaBox().getWidth();
}
return page.getMediaBox().getHeight(); return page.getMediaBox().getHeight();
} }
/**
* @return the {@link #getPageWidth() width of the page} respecting the
* margins.
*/
public float getWidth() { public float getWidth() {
return getPageWidth() - getPageFormat().getMarginLeft() return getPageWidth() - getPageFormat().getMarginLeft() - getPageFormat().getMarginRight();
- getPageFormat().getMarginRight();
} }
/**
* @return the {@link #getPageHeight() height of the page} respecting the
* margins.
*/
public float getHeight() { public float getHeight() {
return getPageHeight() - getPageFormat().getMarginTop() return getPageHeight() - getPageFormat().getMarginTop() - getPageFormat().getMarginBottom();
- getPageFormat().getMarginBottom();
} }
/** /**
@ -250,23 +220,21 @@ public class RenderContext implements Renderer, Closeable, DrawContext, DrawList
@Override @Override
public PDPageContentStream getCurrentPageContentStream() { public PDPageContentStream getCurrentPageContentStream() {
return getContentStream();
}
/**
* @return the current PDPageContentStream.
*/
public PDPageContentStream getContentStream() {
return contentStream; return contentStream;
} }
/**
* @return the current page index (starting from 0).
*/
public int getPageIndex() { public int getPageIndex() {
return pageIndex; return pageIndex;
} }
public void setTransform(Transform transform) {
this.transform = transform;
}
public Transform getTransform() {
return transform;
}
@Override @Override
public boolean render(RenderContext renderContext, public boolean render(RenderContext renderContext,
Element element, Element element,
@ -279,9 +247,6 @@ public class RenderContext implements Renderer, Closeable, DrawContext, DrawList
newPage(); newPage();
return true; return true;
} }
if (element instanceof PositionControl) {
return render((PositionControl) element);
}
if (element instanceof PageFormat) { if (element instanceof PageFormat) {
nextPageFormat = (PageFormat) element; nextPageFormat = (PageFormat) element;
return true; return true;
@ -290,19 +255,25 @@ public class RenderContext implements Renderer, Closeable, DrawContext, DrawList
setLayout((Layout) element); setLayout((Layout) element);
return true; return true;
} }
if (element instanceof PositionElement) {
return render((PositionElement) element);
}
if (element instanceof Transform) {
setTransform((Transform) element);
}
return false; return false;
} }
protected boolean render(PositionControl positionControl) { protected boolean render(PositionElement positionElement) {
if (positionControl instanceof MarkPosition) { if (positionElement instanceof MarkPosition) {
setMarkedPosition(getCurrentPosition()); setMarkedPosition(getCurrentPosition());
return true; return true;
} }
if (positionControl instanceof ResetPosition) { if (positionElement instanceof ResetPosition) {
currentPosition = new Position(getMarkedPosition().getX(), getMarkedPosition().getY()); currentPosition = new Position(getMarkedPosition().getX(), getMarkedPosition().getY());
} }
if (positionControl instanceof SetPosition) { if (positionElement instanceof SetPosition) {
SetPosition setPosition = (SetPosition) positionControl; SetPosition setPosition = (SetPosition) positionElement;
Float x = setPosition.getX(); Float x = setPosition.getX();
if (x == null) { if (x == null) {
x = getCurrentPosition().getX(); x = getCurrentPosition().getX();
@ -314,19 +285,14 @@ public class RenderContext implements Renderer, Closeable, DrawContext, DrawList
currentPosition = new Position(x, y); currentPosition = new Position(x, y);
return true; return true;
} }
if (positionControl instanceof MovePosition) { if (positionElement instanceof MovePosition) {
MovePosition movePosition = (MovePosition) positionControl; MovePosition movePosition = (MovePosition) positionElement;
movePositionBy(movePosition.getX(), movePosition.getY()); movePositionBy(movePosition.getX(), movePosition.getY());
return true; return true;
} }
return false; return false;
} }
/**
* Triggers a new page.
*
* @throws IOException by pdfbox
*/
public void newPage() throws IOException { public void newPage() throws IOException {
if (closePage()) { if (closePage()) {
++pageIndex; ++pageIndex;
@ -336,29 +302,17 @@ public class RenderContext implements Renderer, Closeable, DrawContext, DrawList
} }
this.page = new PDPage(getPageFormat().getMediaBox()); this.page = new PDPage(getPageFormat().getMediaBox());
this.pdDocument.addPage(page); 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 (getPageOrientation() != getPageFormat().getOrientation()) {
if (isPageTilted()) {
page.setRotation(0);
} else {
page.setRotation(90); page.setRotation(90);
} }
}
if (isPageTilted()) {
contentStream.transform(new Matrix(0, 1, -1, 0, getPageHeight(), 0));
}
resetPositionToUpperLeft(); resetPositionToUpperLeft();
resetMaxPositionOnPage(); resetMaxPositionOnPage();
document.beforePage(this); document.beforePage(this);
annotationDrawListener.beforePage(this); 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 { public boolean closePage() throws IOException {
if (contentStream != null) { if (contentStream != null) {
annotationDrawListener.afterPage(this); annotationDrawListener.afterPage(this);
@ -386,32 +340,17 @@ public class RenderContext implements Renderer, Closeable, DrawContext, DrawList
annotationDrawListener.drawn(drawnObject, upperLeft, width, height); 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) { protected void updateMaxPositionOnPage(Position upperLeft, float width, float height) {
maxPositionOnPage = new Position(Math.max(maxPositionOnPage.getX(), maxPositionOnPage = new Position(Math.max(maxPositionOnPage.getX(),
upperLeft.getX() + width), Math.min(maxPositionOnPage.getY(), upperLeft.getX() + width), Math.min(maxPositionOnPage.getY(),
upperLeft.getY() - height)); upperLeft.getY() - height));
} }
/**
* Resets the maximumn position to upper left.
*/
protected void resetMaxPositionOnPage() { protected void resetMaxPositionOnPage() {
maxPositionOnPage = getUpperLeft(); maxPositionOnPage = getUpperLeft();
} }
/**
* @return the maximum right and bottom position of all
* objects rendered on this page so far.
*/
protected Position getMaxPositionOnPage() { protected Position getMaxPositionOnPage() {
return maxPositionOnPage; 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.PageFormat;
import org.xbib.graphics.pdfbox.layout.element.VerticalSpacer; import org.xbib.graphics.pdfbox.layout.element.VerticalSpacer;
import org.xbib.graphics.pdfbox.layout.text.Alignment; 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 org.xbib.graphics.pdfbox.layout.text.WidthRespecting;
import java.io.IOException; import java.io.IOException;
@ -78,24 +77,22 @@ public class VerticalLayout implements Layout {
public void render(RenderContext renderContext, Drawable drawable, LayoutHint layoutHint) throws IOException { public void render(RenderContext renderContext, Drawable drawable, LayoutHint layoutHint) throws IOException {
if (drawable.getAbsolutePosition() != null) { if (drawable.getAbsolutePosition() != null) {
renderAbsolute(renderContext, drawable, drawable.getAbsolutePosition()); renderAbsolute(renderContext, drawable);
} else { } else {
renderRelative(renderContext, drawable, layoutHint); 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 renderContext the context providing all rendering state.
* @param drawable the drawable to draw. * @param drawable the drawable to draw.
* @param position the left upper position to start drawing at.
* @throws IOException by pdfbox * @throws IOException by pdfbox
*/ */
protected void renderAbsolute(RenderContext renderContext, protected void renderAbsolute(RenderContext renderContext, Drawable drawable) throws IOException {
Drawable drawable, drawable.draw(renderContext.getPdDocument(), renderContext.getCurrentPageContentStream(),
Position position) throws IOException { drawable.getAbsolutePosition(), renderContext);
drawable.draw(renderContext.getPdDocument(), renderContext.getContentStream(), position, renderContext);
} }
/** /**
@ -170,7 +167,6 @@ public class VerticalLayout implements Layout {
} }
Dividable.Divided divided = dividable.divide(renderContext.getRemainingHeight(), renderContext.getHeight()); Dividable.Divided divided = dividable.divide(renderContext.getRemainingHeight(), renderContext.getHeight());
drawRelativePartAndMovePosition(renderContext, divided.getFirst(), layoutHint, true); drawRelativePartAndMovePosition(renderContext, divided.getFirst(), layoutHint, true);
// new page
turnPage(renderContext); turnPage(renderContext);
drawablePart = divided.getTail(); drawablePart = divided.getTail();
drawablePart = removeLeadingEmptyVerticalSpace(drawablePart, renderContext); drawablePart = removeLeadingEmptyVerticalSpace(drawablePart, renderContext);
@ -200,7 +196,7 @@ public class VerticalLayout implements Layout {
Drawable drawable, Drawable drawable,
LayoutHint layoutHint, LayoutHint layoutHint,
boolean movePosition) throws IOException { boolean movePosition) throws IOException {
PDPageContentStream contentStream = renderContext.getContentStream(); PDPageContentStream contentStream = renderContext.getCurrentPageContentStream();
PageFormat pageFormat = renderContext.getPageFormat(); PageFormat pageFormat = renderContext.getPageFormat();
float offsetX = 0; float offsetX = 0;
if (layoutHint instanceof VerticalLayoutHint) { if (layoutHint instanceof VerticalLayoutHint) {
@ -220,8 +216,11 @@ public class VerticalLayout implements Layout {
} }
} }
contentStream.saveGraphicsState(); contentStream.saveGraphicsState();
contentStream.addRect(0, pageFormat.getMarginBottom(), renderContext.getPageWidth(), if (renderContext.getTransform() != null) {
renderContext.getHeight()); renderContext.getTransform().render(renderContext, null, null);
}
contentStream.addRect(pageFormat.getMarginTop(), pageFormat.getMarginBottom(),
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), 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.Engine;
import org.xbib.graphics.pdfbox.layout.element.scripting.State; import org.xbib.graphics.pdfbox.layout.element.scripting.State;
import org.xbib.graphics.pdfbox.layout.text.Alignment; 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 org.xbib.settings.Settings;
import java.io.IOException; 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.TextCell;
import org.xbib.graphics.pdfbox.layout.table.VerticalAlignment; import org.xbib.graphics.pdfbox.layout.table.VerticalAlignment;
import org.xbib.graphics.pdfbox.layout.text.Alignment; 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 org.xbib.settings.Settings;
import java.awt.Color; 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.Engine;
import org.xbib.graphics.pdfbox.layout.element.scripting.State; import org.xbib.graphics.pdfbox.layout.element.scripting.State;
import org.xbib.graphics.pdfbox.layout.text.Alignment; 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 org.xbib.settings.Settings;
import java.io.IOException; 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.Engine;
import org.xbib.graphics.pdfbox.layout.element.scripting.State; import org.xbib.graphics.pdfbox.layout.element.scripting.State;
import org.xbib.graphics.pdfbox.layout.shape.Stroke; 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 org.xbib.settings.Settings;
import java.awt.Color; 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.Engine;
import org.xbib.graphics.pdfbox.layout.element.scripting.State; import org.xbib.graphics.pdfbox.layout.element.scripting.State;
import org.xbib.graphics.pdfbox.layout.text.Alignment; 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 org.xbib.settings.Settings;
import java.io.IOException; 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; 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.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;
@ -11,7 +11,7 @@ public class MarkpositionCommand implements Command {
@Override @Override
public void execute(Engine engine, State state, Settings settings) throws IOException { 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); state.elements.peek().add(markPosition);
} }
} }

View file

@ -1,17 +1,20 @@
package org.xbib.graphics.pdfbox.layout.element.scripting.command; 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.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;
import java.io.IOException; import java.io.IOException;
import static org.xbib.graphics.pdfbox.layout.util.PdfUtil.mmToPt;
public class MovepositionCommand implements Command { public class MovepositionCommand implements Command {
@Override @Override
public void execute(Engine engine, State state, Settings settings) throws IOException { 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); 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.Engine;
import org.xbib.graphics.pdfbox.layout.element.scripting.State; import org.xbib.graphics.pdfbox.layout.element.scripting.State;
import org.xbib.graphics.pdfbox.layout.text.Alignment; 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 org.xbib.settings.Settings;
import java.io.IOException; 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.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.graphics.pdfbox.layout.shape.LinePosiiton; import org.xbib.graphics.pdfbox.layout.position.LinePosiiton;
import org.xbib.graphics.pdfbox.layout.shape.MovePosition; import org.xbib.graphics.pdfbox.layout.position.MovePosition;
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.Position; import org.xbib.graphics.pdfbox.layout.position.Position;
import org.xbib.settings.Settings; import org.xbib.settings.Settings;
import java.awt.Color; import java.awt.Color;

View file

@ -1,6 +1,6 @@
package org.xbib.graphics.pdfbox.layout.element.scripting.command; 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.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;
@ -11,7 +11,7 @@ public class ResetpositionCommand implements Command {
@Override @Override
public void execute(Engine engine, State state, Settings settings) throws IOException { 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); state.elements.peek().add(resetPosition);
} }
} }

View file

@ -1,17 +1,21 @@
package org.xbib.graphics.pdfbox.layout.element.scripting.command; 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.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;
import java.io.IOException; import java.io.IOException;
import static org.xbib.graphics.pdfbox.layout.util.PdfUtil.mmToPt;
public class SetpositionCommand implements Command { public class SetpositionCommand implements Command {
@Override @Override
public void execute(Engine engine, State state, Settings settings) throws IOException { 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); 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.TableElement;
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.graphics.pdfbox.layout.text.Position; import org.xbib.graphics.pdfbox.layout.position.Position;
import org.xbib.settings.Settings; import org.xbib.settings.Settings;
import java.io.IOException; 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.Engine;
import org.xbib.graphics.pdfbox.layout.element.scripting.State; import org.xbib.graphics.pdfbox.layout.element.scripting.State;
import org.xbib.graphics.pdfbox.layout.text.Alignment; 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 org.xbib.settings.Settings;
import java.util.Locale; import java.util.Locale;

View file

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

View file

@ -1,6 +1,4 @@
package org.xbib.graphics.pdfbox.layout.shape; package org.xbib.graphics.pdfbox.layout.position;
import org.xbib.graphics.pdfbox.layout.text.Position;
public class MovePosition extends 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 * 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.PDDocument;
import org.apache.pdfbox.pdmodel.PDPageContentStream; import org.apache.pdfbox.pdmodel.PDPageContentStream;
import org.xbib.graphics.pdfbox.layout.text.DrawListener; 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.awt.Color;
import java.io.IOException; import java.io.IOException;

View file

@ -1,7 +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.text.Position; import org.xbib.graphics.pdfbox.layout.position.Position;
import java.io.IOException; import java.io.IOException;
/** /**
@ -9,9 +9,6 @@ import java.io.IOException;
*/ */
public class Ellipse extends RoundRect { public class Ellipse extends RoundRect {
/**
* Default constructor.
*/
public Ellipse() { public Ellipse() {
super(0); 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.PDDocument;
import org.apache.pdfbox.pdmodel.PDPageContentStream; 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.DrawListener;
import org.xbib.graphics.pdfbox.layout.text.Position; import org.xbib.graphics.pdfbox.layout.position.Position;
import java.awt.Color; import java.awt.Color;
import java.io.IOException; import java.io.IOException;
@ -26,6 +28,8 @@ public class Path implements Shape {
Color color, Color color,
Stroke stroke, Stroke stroke,
DrawListener drawListener) throws IOException { DrawListener drawListener) throws IOException {
add(pdDocument, contentStream, upperLeft, width, height);
contentStream.saveGraphicsState();
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);
@ -38,6 +42,7 @@ public class Path implements Shape {
} }
} }
contentStream.stroke(); contentStream.stroke();
contentStream.restoreGraphicsState();
if (drawListener != null) { if (drawListener != null) {
drawListener.drawn(this, upperLeft, width, height); drawListener.drawn(this, upperLeft, width, height);
} }
@ -52,5 +57,6 @@ public class Path implements Shape {
@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 { 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.PDDocument;
import org.apache.pdfbox.pdmodel.PDPageContentStream; 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; 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.PDDocument;
import org.apache.pdfbox.pdmodel.PDPageContentStream; 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; import java.io.IOException;
/** /**
@ -73,29 +73,22 @@ public class RoundRect extends AbstractShape {
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;
// top line
Position a = new Position(upperLeft.getX() + cornerRadiusX, Position a = new Position(upperLeft.getX() + cornerRadiusX,
upperLeft.getY()); upperLeft.getY());
Position b = new Position(a.getX() + nettoWidth, a.getY()); Position b = new Position(a.getX() + nettoWidth, a.getY());
// right line
Position c = new Position(upperLeft.getX() + width, upperLeft.getY() Position c = new Position(upperLeft.getX() + width, upperLeft.getY()
- cornerRadiusY); - cornerRadiusY);
Position d = new Position(c.getX(), c.getY() - nettoHeight); Position d = new Position(c.getX(), c.getY() - nettoHeight);
// bottom line
Position e = new Position( Position e = new Position(
upperLeft.getX() + width - cornerRadiusX, upperLeft.getY() upperLeft.getX() + width - cornerRadiusX, upperLeft.getY()
- height); - height);
Position f = new Position(e.getX() - nettoWidth, e.getY()); Position f = new Position(e.getX() - nettoWidth, e.getY());
// left line
Position g = new Position(upperLeft.getX(), upperLeft.getY() - height Position g = new Position(upperLeft.getX(), upperLeft.getY() - height
+ cornerRadiusY); + cornerRadiusY);
Position h = new Position(g.getX(), upperLeft.getY() Position h = new Position(g.getX(), upperLeft.getY()
- cornerRadiusY); - cornerRadiusY);
float bezX = cornerRadiusX * BEZ; float bezX = cornerRadiusX * BEZ;
float bezY = cornerRadiusY * BEZ; float bezY = cornerRadiusY * BEZ;
contentStream.moveTo(a.getX(), a.getY()); contentStream.moveTo(a.getX(), a.getY());
addLine(contentStream, a.getX(), a.getY(), b.getX(), b.getY()); addLine(contentStream, a.getX(), a.getY(), b.getX(), b.getY());
contentStream.curveTo(b.getX() + bezX, b.getY(), c.getX(), 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.PDDocument;
import org.apache.pdfbox.pdmodel.PDPageContentStream; import org.apache.pdfbox.pdmodel.PDPageContentStream;
import org.xbib.graphics.pdfbox.layout.text.DrawListener; 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.awt.Color;
import java.io.IOException; 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.element.Drawable;
import org.xbib.graphics.pdfbox.layout.table.DrawableCell; 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 org.xbib.graphics.pdfbox.layout.text.WidthRespecting;
import java.io.IOException; 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.table.ParagraphCell;
import org.xbib.graphics.pdfbox.layout.text.Alignment; import org.xbib.graphics.pdfbox.layout.text.Alignment;
import org.xbib.graphics.pdfbox.layout.text.DrawContext; 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 org.xbib.graphics.pdfbox.layout.text.annotations.AnnotationDrawListener;
import java.util.EnumMap; import java.util.EnumMap;

View file

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

View file

@ -1,6 +1,8 @@
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.position.Position;
import java.io.IOException; 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.apache.pdfbox.pdmodel.PDPageContentStream;
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.util.TextSequenceUtil; import org.xbib.graphics.pdfbox.layout.position.Position;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; 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.pdmodel.PDPageContentStream;
import org.apache.pdfbox.util.Matrix; import org.apache.pdfbox.util.Matrix;
import org.xbib.graphics.pdfbox.layout.font.FontDescriptor; 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.awt.Color;
import java.io.IOException; 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.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.font.FontDescriptor; import org.xbib.graphics.pdfbox.layout.font.FontDescriptor;
import org.xbib.graphics.pdfbox.layout.text.Alignment; import org.xbib.graphics.pdfbox.layout.position.Position;
import org.xbib.graphics.pdfbox.layout.text.DrawListener; import org.xbib.graphics.pdfbox.layout.util.Pair;
import org.xbib.graphics.pdfbox.layout.text.Indent; import org.xbib.graphics.pdfbox.layout.util.WordBreakerFactory;
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 java.io.IOException; import java.io.IOException;
import java.io.UncheckedIOException; import java.io.UncheckedIOException;
import java.util.ArrayList; 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.DrawContext;
import org.xbib.graphics.pdfbox.layout.text.DrawListener; import org.xbib.graphics.pdfbox.layout.text.DrawListener;
import org.xbib.graphics.pdfbox.layout.text.DrawableText; 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 * 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.apache.pdfbox.pdmodel.PDDocument;
import org.xbib.graphics.pdfbox.layout.text.DrawContext; 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. * 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.PDDestination;
import org.apache.pdfbox.pdmodel.interactive.documentnavigation.destination.PDPageXYZDestination; import org.apache.pdfbox.pdmodel.interactive.documentnavigation.destination.PDPageXYZDestination;
import org.xbib.graphics.pdfbox.layout.text.DrawContext; 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.AnchorAnnotation;
import org.xbib.graphics.pdfbox.layout.text.annotations.Annotations.HyperlinkAnnotation; import org.xbib.graphics.pdfbox.layout.text.annotations.Annotations.HyperlinkAnnotation;
import org.xbib.graphics.pdfbox.layout.text.annotations.Annotations.HyperlinkAnnotation.LinkStyle; 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.apache.pdfbox.pdmodel.PDPageContentStream;
import org.xbib.graphics.pdfbox.layout.shape.Stroke; import org.xbib.graphics.pdfbox.layout.shape.Stroke;
import org.xbib.graphics.pdfbox.layout.text.DrawContext; 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.StyledText;
import org.xbib.graphics.pdfbox.layout.text.annotations.Annotations.UnderlineAnnotation; import org.xbib.graphics.pdfbox.layout.text.annotations.Annotations.UnderlineAnnotation;
import java.awt.Color; import java.awt.Color;

View file

@ -1,6 +1,7 @@
package org.xbib.graphics.pdfbox.layout.util; package org.xbib.graphics.pdfbox.layout.util;
import org.xbib.graphics.pdfbox.layout.font.FontDescriptor; 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.Matcher;
import java.util.regex.Pattern; 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.BaseFont;
import org.xbib.graphics.pdfbox.layout.font.FontDescriptor; import org.xbib.graphics.pdfbox.layout.font.FontDescriptor;
import org.xbib.graphics.pdfbox.layout.text.DrawContext; 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.Annotated;
import org.xbib.graphics.pdfbox.layout.text.annotations.AnnotatedStyledText; import org.xbib.graphics.pdfbox.layout.text.annotations.AnnotatedStyledText;
import org.xbib.graphics.pdfbox.layout.text.annotations.Annotation; 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.shape.Stroke.CapStyle;
import org.xbib.graphics.pdfbox.layout.text.Alignment; import org.xbib.graphics.pdfbox.layout.text.Alignment;
import org.xbib.graphics.pdfbox.layout.font.BaseFont; 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.TextFlow;
import org.xbib.graphics.pdfbox.layout.text.TextFlowUtil; 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.awt.Color;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
@ -101,7 +101,7 @@ 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.getContentStream(), new Position( text.drawText(renderContext.getCurrentPageContentStream(), new Position(
offset, 30), Alignment.RIGHT, null); 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.element.render.VerticalLayoutHint;
import org.xbib.graphics.pdfbox.layout.text.Alignment; import org.xbib.graphics.pdfbox.layout.text.Alignment;
import org.xbib.graphics.pdfbox.layout.font.BaseFont; 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.awt.image.BufferedImage;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; 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.font.FontDescriptor;
import org.xbib.graphics.pdfbox.layout.text.Alignment; import org.xbib.graphics.pdfbox.layout.text.Alignment;
import org.xbib.graphics.pdfbox.layout.font.BaseFont; 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.TextFlow;
import org.xbib.graphics.pdfbox.layout.text.TextFlowUtil; 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; import java.io.FileOutputStream;
public class ListenerTest { public class ListenerTest {
@ -52,7 +52,7 @@ 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.getContentStream(), new Position( text.drawText(renderContext.getCurrentPageContentStream(), new Position(
offset, 30), Alignment.RIGHT, null); 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.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.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;
import org.xbib.graphics.pdfbox.layout.text.Alignment; import org.xbib.graphics.pdfbox.layout.text.Alignment;
import org.xbib.graphics.pdfbox.layout.font.BaseFont; import org.xbib.graphics.pdfbox.layout.font.BaseFont;
import org.xbib.graphics.pdfbox.layout.text.DrawContext; 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.TextFlow;
import org.xbib.graphics.pdfbox.layout.text.TextFlowUtil; 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 org.xbib.graphics.pdfbox.layout.text.annotations.AnnotationDrawListener;
import java.awt.Color; import java.awt.Color;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException;
public class LowLevelText { public class LowLevelText {
@ -106,4 +110,42 @@ public class LowLevelText {
pdDocument.save(new FileOutputStream("build/lowleveltext.pdf")); pdDocument.save(new FileOutputStream("build/lowleveltext.pdf"));
pdDocument.close(); 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", "type": "document",
"margin": "20 20 20 20", "margin": "0 0 0 0",
"author": "Jörg Prante", "author": "Jörg Prante",
"elements": [ "elements": [
{ {
"type": "image", "type": "setposition",
"scalex": 0.2, "x": 10,
"scaley": 0.2, "y": 290
"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": "barcode", "type": "barcode",
"symbol": "Code3Of9", "symbol": "Code3Of9",
"value": "12345678" "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", "type": "path",
"absolute": false, "value": "M 0 0 L 100 0 L 100 20 L 0 20 L 0 0",
"value": "10 10 100 10 100 20 10 20 10 10",
"color": "red", "color": "red",
"dash": 1 "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", "type": "paragraph",
"elements": [ "elements": [
@ -55,7 +79,8 @@
] ]
}, },
{ {
"type": "horizontalruler" "type": "horizontalruler",
"width": 180
}, },
{ {
"type": "paragraph", "type": "paragraph",