fix PDF chart font Helvetica selection, fix stroke in underline annotations
This commit is contained in:
parent
a091bc52cf
commit
49278772e8
20 changed files with 114 additions and 219 deletions
|
@ -4,8 +4,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import org.junit.jupiter.api.AfterEach;
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.condition.DisabledOnOs;
|
|
||||||
import org.junit.jupiter.api.condition.OS;
|
|
||||||
import org.xbib.graphics.barcode.Code93;
|
import org.xbib.graphics.barcode.Code93;
|
||||||
import org.xbib.graphics.barcode.render.BarcodeGraphicsRenderer;
|
import org.xbib.graphics.barcode.render.BarcodeGraphicsRenderer;
|
||||||
import org.xbib.graphics.barcode.MaxiCode;
|
import org.xbib.graphics.barcode.MaxiCode;
|
||||||
|
@ -24,7 +22,6 @@ import java.nio.file.Files;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
@DisabledOnOs(OS.MAC)
|
|
||||||
public class EPSRendererTest {
|
public class EPSRendererTest {
|
||||||
|
|
||||||
private Locale originalDefaultLocale;
|
private Locale originalDefaultLocale;
|
||||||
|
@ -98,7 +95,7 @@ public class EPSRendererTest {
|
||||||
int height = (int) (symbol.getHeight() * magnification);
|
int height = (int) (symbol.getHeight() * magnification);
|
||||||
Rectangle rectangle = new Rectangle(0, 0, width, height);
|
Rectangle rectangle = new Rectangle(0, 0, width, height);
|
||||||
EPSGraphics2D epsGraphics2D = new EPSGraphics2D(rectangle);
|
EPSGraphics2D epsGraphics2D = new EPSGraphics2D(rectangle);
|
||||||
epsGraphics2D.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 12));
|
epsGraphics2D.setFont(Font.decode("Dialog"));
|
||||||
BarcodeGraphicsRenderer barcodeGraphicsRenderer = new BarcodeGraphicsRenderer(epsGraphics2D, rectangle,
|
BarcodeGraphicsRenderer barcodeGraphicsRenderer = new BarcodeGraphicsRenderer(epsGraphics2D, rectangle,
|
||||||
magnification, paper, ink, false, false);
|
magnification, paper, ink, false, false);
|
||||||
barcodeGraphicsRenderer.render(symbol);
|
barcodeGraphicsRenderer.render(symbol);
|
||||||
|
|
|
@ -4,8 +4,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import org.junit.jupiter.api.AfterEach;
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.condition.DisabledOnOs;
|
|
||||||
import org.junit.jupiter.api.condition.OS;
|
|
||||||
import org.xbib.graphics.barcode.Code93;
|
import org.xbib.graphics.barcode.Code93;
|
||||||
import org.xbib.graphics.barcode.MaxiCode;
|
import org.xbib.graphics.barcode.MaxiCode;
|
||||||
import org.xbib.graphics.barcode.AbstractSymbol;
|
import org.xbib.graphics.barcode.AbstractSymbol;
|
||||||
|
@ -24,7 +22,6 @@ import java.nio.file.Files;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
@DisabledOnOs({OS.MAC, OS.LINUX})
|
|
||||||
public class PDFRendererTest {
|
public class PDFRendererTest {
|
||||||
|
|
||||||
private Locale originalDefaultLocale;
|
private Locale originalDefaultLocale;
|
||||||
|
@ -98,8 +95,7 @@ public class PDFRendererTest {
|
||||||
int height = (int) (symbol.getHeight() * magnification);
|
int height = (int) (symbol.getHeight() * magnification);
|
||||||
Rectangle rectangle = new Rectangle(0, 0, width, height);
|
Rectangle rectangle = new Rectangle(0, 0, width, height);
|
||||||
PDFGraphics2D pdfGraphics2D = new PDFGraphics2D(rectangle);
|
PDFGraphics2D pdfGraphics2D = new PDFGraphics2D(rectangle);
|
||||||
// we need a trick here to generate HELVETICA font statements
|
pdfGraphics2D.setFont(Font.decode("Dialog")); // Helvetica
|
||||||
pdfGraphics2D.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 12));
|
|
||||||
BarcodeGraphicsRenderer barcodeGraphicsRenderer = new BarcodeGraphicsRenderer(pdfGraphics2D,
|
BarcodeGraphicsRenderer barcodeGraphicsRenderer = new BarcodeGraphicsRenderer(pdfGraphics2D,
|
||||||
rectangle, magnification, paper, ink, false, false);
|
rectangle, magnification, paper, ink, false, false);
|
||||||
barcodeGraphicsRenderer.render(symbol);
|
barcodeGraphicsRenderer.render(symbol);
|
||||||
|
|
|
@ -4,8 +4,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import org.junit.jupiter.api.AfterEach;
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.condition.DisabledOnOs;
|
|
||||||
import org.junit.jupiter.api.condition.OS;
|
|
||||||
import org.xbib.graphics.barcode.Code93;
|
import org.xbib.graphics.barcode.Code93;
|
||||||
import org.xbib.graphics.barcode.MaxiCode;
|
import org.xbib.graphics.barcode.MaxiCode;
|
||||||
import org.xbib.graphics.barcode.AbstractSymbol;
|
import org.xbib.graphics.barcode.AbstractSymbol;
|
||||||
|
@ -24,7 +22,6 @@ import java.nio.file.Files;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
@DisabledOnOs(OS.MAC)
|
|
||||||
public class SvgRendererTest {
|
public class SvgRendererTest {
|
||||||
|
|
||||||
private Locale originalDefaultLocale;
|
private Locale originalDefaultLocale;
|
||||||
|
@ -98,7 +95,7 @@ public class SvgRendererTest {
|
||||||
int height = (int) (symbol.getHeight() * magnification);
|
int height = (int) (symbol.getHeight() * magnification);
|
||||||
Rectangle rectangle = new Rectangle(0, 0, width, height);
|
Rectangle rectangle = new Rectangle(0, 0, width, height);
|
||||||
SVGGraphics2D svgGraphics2D = new SVGGraphics2D(rectangle);
|
SVGGraphics2D svgGraphics2D = new SVGGraphics2D(rectangle);
|
||||||
svgGraphics2D.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 12));
|
svgGraphics2D.setFont(Font.decode("Dialog"));
|
||||||
BarcodeGraphicsRenderer barcodeGraphicsRenderer = new BarcodeGraphicsRenderer(svgGraphics2D,
|
BarcodeGraphicsRenderer barcodeGraphicsRenderer = new BarcodeGraphicsRenderer(svgGraphics2D,
|
||||||
rectangle, magnification, paper, ink, false, false);
|
rectangle, magnification, paper, ink, false, false);
|
||||||
barcodeGraphicsRenderer.render(symbol);
|
barcodeGraphicsRenderer.render(symbol);
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
This work is derived from XChart by Tim Molter
|
This work is derived from XChart by Tim Molter
|
||||||
|
|
||||||
http://knowm.org/open-source/xchart/
|
http://knowm.org/open-source/xchart/
|
||||||
|
|
||||||
https://github.com/timmolter/xchart
|
https://github.com/timmolter/xchart
|
||||||
|
|
||||||
Apache License 2.0
|
Apache License 2.0
|
||||||
|
|
|
@ -361,7 +361,7 @@ public abstract class Chart<ST extends Styler, S extends Series> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public BufferedImage getBufferedImage() {
|
public BufferedImage getBufferedImage() {
|
||||||
BufferedImage bufferedImage = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_RGB);
|
BufferedImage bufferedImage = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB);
|
||||||
Graphics2D graphics2D = bufferedImage.createGraphics();
|
Graphics2D graphics2D = bufferedImage.createGraphics();
|
||||||
paint(graphics2D, getWidth(), getHeight());
|
paint(graphics2D, getWidth(), getHeight());
|
||||||
return bufferedImage;
|
return bufferedImage;
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package org.xbib.graphics.pdfbox.layout.elements;
|
package org.xbib.graphics.pdfbox.layout.elements;
|
||||||
|
|
||||||
import org.apache.pdfbox.pdmodel.PDDocument;
|
import org.apache.pdfbox.pdmodel.PDDocument;
|
||||||
import org.apache.pdfbox.pdmodel.common.PDRectangle;
|
|
||||||
import org.xbib.graphics.pdfbox.layout.elements.render.Layout;
|
import org.xbib.graphics.pdfbox.layout.elements.render.Layout;
|
||||||
import org.xbib.graphics.pdfbox.layout.elements.render.LayoutHint;
|
import org.xbib.graphics.pdfbox.layout.elements.render.LayoutHint;
|
||||||
import org.xbib.graphics.pdfbox.layout.elements.render.RenderContext;
|
import org.xbib.graphics.pdfbox.layout.elements.render.RenderContext;
|
||||||
|
@ -55,11 +54,11 @@ public class Document implements RenderListener {
|
||||||
* @param marginTop the top margin
|
* @param marginTop the top margin
|
||||||
* @param marginBottom the bottom margin
|
* @param marginBottom the bottom margin
|
||||||
*/
|
*/
|
||||||
public Document(float marginLeft, float marginRight, float marginTop,
|
public Document(float marginLeft,
|
||||||
|
float marginRight,
|
||||||
|
float marginTop,
|
||||||
float marginBottom) {
|
float marginBottom) {
|
||||||
this(PageFormat.with()
|
this(PageFormat.with().margins(marginLeft, marginRight, marginTop, marginBottom).build());
|
||||||
.margins(marginLeft, marginRight, marginTop, marginBottom)
|
|
||||||
.build());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -68,7 +67,7 @@ public class Document implements RenderListener {
|
||||||
*
|
*
|
||||||
* @param pageFormat the page format box to use.
|
* @param pageFormat the page format box to use.
|
||||||
*/
|
*/
|
||||||
public Document(final PageFormat pageFormat) {
|
public Document(PageFormat pageFormat) {
|
||||||
this.pageFormat = pageFormat;
|
this.pageFormat = pageFormat;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,7 +76,7 @@ public class Document implements RenderListener {
|
||||||
*
|
*
|
||||||
* @param element the element to add
|
* @param element the element to add
|
||||||
*/
|
*/
|
||||||
public void add(final Element element) {
|
public void add(Element element) {
|
||||||
add(element, new VerticalLayoutHint());
|
add(element, new VerticalLayoutHint());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,24 +86,15 @@ public class Document implements RenderListener {
|
||||||
* @param element the element to add
|
* @param element the element to add
|
||||||
* @param layoutHint the hint for the {@link Layout}.
|
* @param layoutHint the hint for the {@link Layout}.
|
||||||
*/
|
*/
|
||||||
public void add(final Element element, final LayoutHint layoutHint) {
|
public void add(Element element, LayoutHint layoutHint) {
|
||||||
elements.add(createEntry(element, layoutHint));
|
elements.add(createEntry(element, layoutHint));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Entry<Element, LayoutHint> createEntry(final Element element,
|
private Entry<Element, LayoutHint> createEntry(Element element,
|
||||||
final LayoutHint layoutHint) {
|
LayoutHint layoutHint) {
|
||||||
return new SimpleEntry<>(element, layoutHint);
|
return new SimpleEntry<>(element, layoutHint);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Removes the given element.
|
|
||||||
*
|
|
||||||
* @param element the element to remove.
|
|
||||||
*/
|
|
||||||
public void remove(final Element element) {
|
|
||||||
elements.remove(element);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the page format to use as default.
|
* @return the page format to use as default.
|
||||||
*/
|
*/
|
||||||
|
@ -112,72 +102,20 @@ public class Document implements RenderListener {
|
||||||
return pageFormat;
|
return pageFormat;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the left document margin.
|
|
||||||
* @deprecated use {@link #getPageFormat()} instead.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public float getMarginLeft() {
|
|
||||||
return getPageFormat().getMarginLeft();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the right document margin.
|
|
||||||
* @deprecated use {@link #getPageFormat()} instead.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public float getMarginRight() {
|
|
||||||
return getPageFormat().getMarginRight();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the top document margin.
|
|
||||||
* @deprecated use {@link #getPageFormat()} instead.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public float getMarginTop() {
|
|
||||||
return getPageFormat().getMarginTop();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the bottom document margin.
|
|
||||||
* @deprecated use {@link #getPageFormat()} instead.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public float getMarginBottom() {
|
|
||||||
return getPageFormat().getMarginBottom();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the media box to use.
|
|
||||||
* @deprecated use {@link #getPageFormat()} instead.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public PDRectangle getMediaBox() {
|
|
||||||
return getPageFormat().getMediaBox();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the orientation to use.
|
|
||||||
* @deprecated use {@link #getPageFormat()} instead.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public Orientation getOrientation() {
|
|
||||||
return getPageFormat().getOrientation();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the media box width minus margins.
|
* @return the media box width minus margins.
|
||||||
*/
|
*/
|
||||||
public float getPageWidth() {
|
public float getPageWidth() {
|
||||||
return getMediaBox().getWidth() - getMarginLeft() - getMarginRight();
|
return pageFormat.getMediaBox().getWidth() -
|
||||||
|
pageFormat.getMarginLeft() - pageFormat.getMarginRight();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the media box height minus margins.
|
* @return the media box height minus margins.
|
||||||
*/
|
*/
|
||||||
public float getPageHeight() {
|
public float getPageHeight() {
|
||||||
return getMediaBox().getHeight() - getMarginTop() - getMarginBottom();
|
return pageFormat.getMediaBox().getHeight() -
|
||||||
|
pageFormat.getMarginTop() - pageFormat.getMarginBottom();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -215,15 +153,6 @@ public class Document implements RenderListener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Removes a {@link Renderer} .
|
|
||||||
*
|
|
||||||
* @param renderer the renderer to remove.
|
|
||||||
*/
|
|
||||||
public void removeRenderer(final Renderer renderer) {
|
|
||||||
customRenderer.remove(renderer);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Renders all elements and returns the resulting {@link PDDocument}.
|
* Renders all elements and returns the resulting {@link PDDocument}.
|
||||||
*
|
*
|
||||||
|
@ -298,17 +227,8 @@ public class Document implements RenderListener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Removes a {@link RenderListener} .
|
|
||||||
*
|
|
||||||
* @param listener the listener to remove.
|
|
||||||
*/
|
|
||||||
public void removeRenderListener(final RenderListener listener) {
|
|
||||||
renderListener.remove(listener);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void beforePage(final RenderContext renderContext)
|
public void beforePage(RenderContext renderContext)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
for (RenderListener listener : renderListener) {
|
for (RenderListener listener : renderListener) {
|
||||||
listener.beforePage(renderContext);
|
listener.beforePage(renderContext);
|
||||||
|
@ -316,10 +236,9 @@ public class Document implements RenderListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterPage(final RenderContext renderContext) throws IOException {
|
public void afterPage(RenderContext renderContext) throws IOException {
|
||||||
for (RenderListener listener : renderListener) {
|
for (RenderListener listener : renderListener) {
|
||||||
listener.afterPage(renderContext);
|
listener.afterPage(renderContext);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,6 @@ package org.xbib.graphics.pdfbox.layout.elements.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.pdmodel.common.PDRectangle;
|
|
||||||
import org.apache.pdfbox.util.Matrix;
|
import org.apache.pdfbox.util.Matrix;
|
||||||
import org.xbib.graphics.pdfbox.layout.elements.ControlElement;
|
import org.xbib.graphics.pdfbox.layout.elements.ControlElement;
|
||||||
import org.xbib.graphics.pdfbox.layout.elements.Document;
|
import org.xbib.graphics.pdfbox.layout.elements.Document;
|
||||||
|
@ -83,28 +82,6 @@ public class RenderContext implements Renderer, Closeable, DrawContext, DrawList
|
||||||
resetPositionToLeftEndOfPage();
|
resetPositionToLeftEndOfPage();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the orientation to use for the page. If no special
|
|
||||||
* {@link #setPageFormat(PageFormat) page format} is set, the
|
|
||||||
* {@link Document#getOrientation() document orientation} is used.
|
|
||||||
* @deprecated use {@link #getPageFormat()} instead.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public Orientation getOrientation() {
|
|
||||||
return getPageFormat().getOrientation();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the media box to use for the page. If no special
|
|
||||||
* {@link #setPageFormat(PageFormat) page format} is set, the
|
|
||||||
* {@link Document#getMediaBox() document media box} is used.
|
|
||||||
* @deprecated use {@link #getPageFormat()} instead.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public PDRectangle getMediaBox() {
|
|
||||||
return getPageFormat().getMediaBox();
|
|
||||||
}
|
|
||||||
|
|
||||||
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();
|
||||||
|
@ -279,14 +256,6 @@ public class RenderContext implements Renderer, Closeable, DrawContext, DrawList
|
||||||
return getContentStream();
|
return getContentStream();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the current PDPage.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public PDPage getPage() {
|
|
||||||
return getCurrentPage();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the current PDPageContentStream.
|
* @return the current PDPageContentStream.
|
||||||
*/
|
*/
|
||||||
|
@ -302,10 +271,10 @@ public class RenderContext implements Renderer, Closeable, DrawContext, DrawList
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean render(RenderContext renderContext, Element element,
|
public boolean render(RenderContext renderContext,
|
||||||
|
Element element,
|
||||||
LayoutHint layoutHint) throws IOException {
|
LayoutHint layoutHint) throws IOException {
|
||||||
boolean success = getLayout()
|
boolean success = getLayout().render(renderContext, element, layoutHint);
|
||||||
.render(renderContext, element, layoutHint);
|
|
||||||
if (success) {
|
if (success) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -327,7 +296,7 @@ public class RenderContext implements Renderer, Closeable, DrawContext, DrawList
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean render(final PositionControl positionControl) {
|
protected boolean render(PositionControl positionControl) {
|
||||||
if (positionControl instanceof MarkPosition) {
|
if (positionControl instanceof MarkPosition) {
|
||||||
setMarkedPosition(getCurrentPosition());
|
setMarkedPosition(getCurrentPosition());
|
||||||
return true;
|
return true;
|
||||||
|
@ -401,16 +370,12 @@ public class RenderContext implements Renderer, Closeable, DrawContext, DrawList
|
||||||
*/
|
*/
|
||||||
public boolean closePage() throws IOException {
|
public boolean closePage() throws IOException {
|
||||||
if (contentStream != null) {
|
if (contentStream != null) {
|
||||||
|
|
||||||
annotationDrawListener.afterPage(this);
|
annotationDrawListener.afterPage(this);
|
||||||
document.afterPage(this);
|
document.afterPage(this);
|
||||||
|
|
||||||
if (getPageFormat().getRotation() != 0) {
|
if (getPageFormat().getRotation() != 0) {
|
||||||
int currentRotation = getCurrentPage().getRotation();
|
int currentRotation = getCurrentPage().getRotation();
|
||||||
getCurrentPage().setRotation(
|
getCurrentPage().setRotation(currentRotation + getPageFormat().getRotation());
|
||||||
currentRotation + getPageFormat().getRotation());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
contentStream.close();
|
contentStream.close();
|
||||||
contentStream = null;
|
contentStream = null;
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -3,7 +3,6 @@ package org.xbib.graphics.pdfbox.layout.shape;
|
||||||
import org.apache.pdfbox.pdmodel.PDPageContentStream;
|
import org.apache.pdfbox.pdmodel.PDPageContentStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is a container for all information needed to perform a stroke.
|
* This is a container for all information needed to perform a stroke.
|
||||||
|
@ -176,18 +175,14 @@ public class Stroke {
|
||||||
*/
|
*/
|
||||||
public void applyTo(PDPageContentStream contentStream) throws IOException {
|
public void applyTo(PDPageContentStream contentStream) throws IOException {
|
||||||
if (getCapStyle() != null) {
|
if (getCapStyle() != null) {
|
||||||
Logger.getLogger("").info(" cap style = " + getCapStyle().value());
|
|
||||||
contentStream.setLineCapStyle(getCapStyle().value());
|
contentStream.setLineCapStyle(getCapStyle().value());
|
||||||
}
|
}
|
||||||
if (getJoinStyle() != null) {
|
if (getJoinStyle() != null) {
|
||||||
Logger.getLogger("").info(" join style = " + getJoinStyle().value());
|
|
||||||
contentStream.setLineJoinStyle(getJoinStyle().value());
|
contentStream.setLineJoinStyle(getJoinStyle().value());
|
||||||
}
|
}
|
||||||
if (getDashPattern() != null) {
|
if (getDashPattern() != null) {
|
||||||
Logger.getLogger("").info(" dash pattern = " + Arrays.asList(getDashPattern().getPattern()));
|
|
||||||
contentStream.setLineDashPattern(getDashPattern().getPattern(), getDashPattern().getPhase());
|
contentStream.setLineDashPattern(getDashPattern().getPattern(), getDashPattern().getPhase());
|
||||||
}
|
}
|
||||||
Logger.getLogger("").info(" line width = " + getLineWidth());
|
|
||||||
contentStream.setLineWidth(getLineWidth());
|
contentStream.setLineWidth(getLineWidth());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -116,7 +116,7 @@ public class StyledText implements TextFragment {
|
||||||
* @return the ascent of the associated font.
|
* @return the ascent of the associated font.
|
||||||
* @throws IOException by pdfbox.
|
* @throws IOException by pdfbox.
|
||||||
*/
|
*/
|
||||||
public float getAsent() throws IOException {
|
public float getAscent() throws IOException {
|
||||||
return getFontDescriptor().getSize() * getFontDescriptor().getSelectedFont().getFontDescriptor().getAscent() / 1000;
|
return getFontDescriptor().getSize() * getFontDescriptor().getSelectedFont().getFontDescriptor().getAscent() / 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -88,11 +88,9 @@ public class TextFlowUtil {
|
||||||
if (fragment instanceof AnnotationCharacters.AnnotationControlCharacter) {
|
if (fragment instanceof AnnotationCharacters.AnnotationControlCharacter) {
|
||||||
AnnotationCharacters.AnnotationControlCharacter<?> annotationControlCharacter = (AnnotationCharacters.AnnotationControlCharacter<?>) fragment;
|
AnnotationCharacters.AnnotationControlCharacter<?> annotationControlCharacter = (AnnotationCharacters.AnnotationControlCharacter<?>) fragment;
|
||||||
if (annotationMap.containsKey(annotationControlCharacter.getAnnotationType())) {
|
if (annotationMap.containsKey(annotationControlCharacter.getAnnotationType())) {
|
||||||
annotationMap.remove(annotationControlCharacter
|
annotationMap.remove(annotationControlCharacter.getAnnotationType());
|
||||||
.getAnnotationType());
|
|
||||||
} else {
|
} else {
|
||||||
annotationMap.put(
|
annotationMap.put(annotationControlCharacter.getAnnotationType(),
|
||||||
annotationControlCharacter.getAnnotationType(),
|
|
||||||
annotationControlCharacter.getAnnotation());
|
annotationControlCharacter.getAnnotation());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -205,7 +205,7 @@ public class TextLine implements TextSequence {
|
||||||
contentStream.endText();
|
contentStream.endText();
|
||||||
if (drawListener != null) {
|
if (drawListener != null) {
|
||||||
drawListener.drawn(styledText,
|
drawListener.drawn(styledText,
|
||||||
new Position(x, y + styledText.getAsent()),
|
new Position(x, y + styledText.getAscent()),
|
||||||
styledText.getWidthWithoutMargin(),
|
styledText.getWidthWithoutMargin(),
|
||||||
styledText.getHeight());
|
styledText.getHeight());
|
||||||
}
|
}
|
||||||
|
|
|
@ -210,7 +210,8 @@ public class AnnotationCharacters {
|
||||||
* constant for the system property
|
* constant for the system property
|
||||||
* <code>pdfbox.layout.underline.baseline.offset.scale.default</code>.
|
* <code>pdfbox.layout.underline.baseline.offset.scale.default</code>.
|
||||||
*/
|
*/
|
||||||
public final static String UNDERLINE_DEFAULT_BASELINE_OFFSET_SCALE_PROPERTY = "pdfbox.layout.underline.baseline.offset.scale.default";
|
public final static String UNDERLINE_DEFAULT_BASELINE_OFFSET_SCALE_PROPERTY =
|
||||||
|
"pdfbox.layout.underline.baseline.offset.scale.default";
|
||||||
|
|
||||||
private static Float defaultBaselineOffsetScale;
|
private static Float defaultBaselineOffsetScale;
|
||||||
private final UnderlineAnnotation line;
|
private final UnderlineAnnotation line;
|
||||||
|
@ -218,7 +219,6 @@ public class AnnotationCharacters {
|
||||||
protected UnderlineControlCharacter(String baselineOffsetScaleValue,
|
protected UnderlineControlCharacter(String baselineOffsetScaleValue,
|
||||||
String lineWeightValue) {
|
String lineWeightValue) {
|
||||||
super("UNDERLINE", UnderlineControlCharacterFactory.TO_ESCAPE);
|
super("UNDERLINE", UnderlineControlCharacterFactory.TO_ESCAPE);
|
||||||
|
|
||||||
float baselineOffsetScale = parseFloat(baselineOffsetScaleValue,
|
float baselineOffsetScale = parseFloat(baselineOffsetScaleValue,
|
||||||
getdefaultBaselineOffsetScale());
|
getdefaultBaselineOffsetScale());
|
||||||
float lineWeight = parseFloat(lineWeightValue, 1f);
|
float lineWeight = parseFloat(lineWeightValue, 1f);
|
||||||
|
@ -248,15 +248,11 @@ public class AnnotationCharacters {
|
||||||
|
|
||||||
private static float getdefaultBaselineOffsetScale() {
|
private static float getdefaultBaselineOffsetScale() {
|
||||||
if (defaultBaselineOffsetScale == null) {
|
if (defaultBaselineOffsetScale == null) {
|
||||||
defaultBaselineOffsetScale = Float
|
defaultBaselineOffsetScale =
|
||||||
.parseFloat(System
|
Float.parseFloat(System.getProperty(UNDERLINE_DEFAULT_BASELINE_OFFSET_SCALE_PROPERTY, "-0.1"));
|
||||||
.getProperty(
|
|
||||||
UNDERLINE_DEFAULT_BASELINE_OFFSET_SCALE_PROPERTY,
|
|
||||||
"-0.1"));
|
|
||||||
}
|
}
|
||||||
return defaultBaselineOffsetScale;
|
return defaultBaselineOffsetScale;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -267,7 +263,7 @@ public class AnnotationCharacters {
|
||||||
public interface AnnotationControlCharacterFactory<T extends AnnotationControlCharacter<? extends Annotation>>
|
public interface AnnotationControlCharacterFactory<T extends AnnotationControlCharacter<? extends Annotation>>
|
||||||
extends ControlCharacterFactory {
|
extends ControlCharacterFactory {
|
||||||
T createControlCharacter(String text, Matcher matcher,
|
T createControlCharacter(String text, Matcher matcher,
|
||||||
final List<CharSequence> charactersSoFar);
|
List<CharSequence> charactersSoFar);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -277,8 +273,8 @@ public class AnnotationCharacters {
|
||||||
public static abstract class AnnotationControlCharacter<T extends Annotation>
|
public static abstract class AnnotationControlCharacter<T extends Annotation>
|
||||||
extends ControlCharacter {
|
extends ControlCharacter {
|
||||||
|
|
||||||
protected AnnotationControlCharacter(final String description,
|
protected AnnotationControlCharacter(String description,
|
||||||
final String characterToEscape) {
|
String characterToEscape) {
|
||||||
super(description, characterToEscape);
|
super(description, characterToEscape);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ import org.xbib.graphics.pdfbox.layout.text.Position;
|
||||||
* This listener has to be passed to all
|
* This listener has to be passed to all
|
||||||
* {@link DrawableText#drawText(org.apache.pdfbox.pdmodel.PDPageContentStream, Position, Alignment, DrawListener)
|
* {@link DrawableText#drawText(org.apache.pdfbox.pdmodel.PDPageContentStream, Position, Alignment, DrawListener)
|
||||||
* draw()} methods, in order collect all annotation metadata. After all drawing
|
* draw()} methods, in order collect all annotation metadata. After all drawing
|
||||||
* is done, you have to call {@link #finalizeAnnotations()} which creates all
|
* is done, you have to call {@link #afterRender()} which creates all
|
||||||
* necessary annotations and sets them to the corresponding pages. This listener
|
* necessary annotations and sets them to the corresponding pages. This listener
|
||||||
* is used by the the rendering API, but you may also use it with the low-level
|
* is used by the the rendering API, but you may also use it with the low-level
|
||||||
* text API.
|
* text API.
|
||||||
|
@ -49,11 +49,6 @@ public class AnnotationDrawListener implements DrawListener, RenderListener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public void finalizeAnnotations() {
|
|
||||||
afterRender();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void beforePage(RenderContext renderContext) {
|
public void beforePage(RenderContext renderContext) {
|
||||||
for (AnnotationProcessor annotationProcessor : annotationProcessors) {
|
for (AnnotationProcessor annotationProcessor : annotationProcessors) {
|
||||||
|
@ -68,11 +63,9 @@ public class AnnotationDrawListener implements DrawListener, RenderListener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void afterRender() {
|
public void afterRender() {
|
||||||
for (AnnotationProcessor annotationProcessor : annotationProcessors) {
|
for (AnnotationProcessor annotationProcessor : annotationProcessors) {
|
||||||
annotationProcessor.afterRender(drawContext.getPdDocument());
|
annotationProcessor.afterRender(drawContext.getPdDocument());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,8 +10,9 @@ public class Annotations {
|
||||||
*/
|
*/
|
||||||
public static class UnderlineAnnotation implements Annotation {
|
public static class UnderlineAnnotation implements Annotation {
|
||||||
|
|
||||||
private float baselineOffsetScale = 0f;
|
private final float baselineOffsetScale;
|
||||||
private float lineWeight = 1f;
|
|
||||||
|
private final float lineWeight;
|
||||||
|
|
||||||
public UnderlineAnnotation(float baselineOffsetScale, float lineWeight) {
|
public UnderlineAnnotation(float baselineOffsetScale, float lineWeight) {
|
||||||
this.baselineOffsetScale = baselineOffsetScale;
|
this.baselineOffsetScale = baselineOffsetScale;
|
||||||
|
@ -31,7 +32,6 @@ public class Annotations {
|
||||||
return "UnderlineAnnotation [baselineOffsetScale="
|
return "UnderlineAnnotation [baselineOffsetScale="
|
||||||
+ baselineOffsetScale + ", lineWeight=" + lineWeight + "]";
|
+ baselineOffsetScale + ", lineWeight=" + lineWeight + "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -51,6 +51,7 @@ public class Annotations {
|
||||||
}
|
}
|
||||||
|
|
||||||
private final String hyperlinkUri;
|
private final String hyperlinkUri;
|
||||||
|
|
||||||
private final LinkStyle linkStyle;
|
private final LinkStyle linkStyle;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -34,37 +34,39 @@ import java.util.Map.Entry;
|
||||||
public class HyperlinkAnnotationProcessor implements AnnotationProcessor {
|
public class HyperlinkAnnotationProcessor implements AnnotationProcessor {
|
||||||
|
|
||||||
private final Map<String, PageAnchor> anchorMap = new HashMap<>();
|
private final Map<String, PageAnchor> anchorMap = new HashMap<>();
|
||||||
|
|
||||||
private final Map<PDPage, List<Hyperlink>> linkMap = new HashMap<>();
|
private final Map<PDPage, List<Hyperlink>> linkMap = new HashMap<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void annotatedObjectDrawn(Annotated drawnObject,
|
public void annotatedObjectDrawn(Annotated drawnObject,
|
||||||
DrawContext drawContext, Position upperLeft, float width,
|
DrawContext drawContext,
|
||||||
|
Position upperLeft,
|
||||||
|
float width,
|
||||||
float height) {
|
float height) {
|
||||||
|
|
||||||
if (!(drawnObject instanceof AnnotatedStyledText)) {
|
if (!(drawnObject instanceof AnnotatedStyledText)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
AnnotatedStyledText annotatedText = (AnnotatedStyledText) drawnObject;
|
AnnotatedStyledText annotatedText = (AnnotatedStyledText) drawnObject;
|
||||||
handleHyperlinkAnnotations(annotatedText, drawContext, upperLeft,
|
handleHyperlinkAnnotations(annotatedText, drawContext, upperLeft, width, height);
|
||||||
width, height);
|
|
||||||
handleAnchorAnnotations(annotatedText, drawContext, upperLeft);
|
handleAnchorAnnotations(annotatedText, drawContext, upperLeft);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void handleAnchorAnnotations(AnnotatedStyledText annotatedText,
|
protected void handleAnchorAnnotations(AnnotatedStyledText annotatedText,
|
||||||
DrawContext drawContext, Position upperLeft) {
|
DrawContext drawContext,
|
||||||
Iterable<AnchorAnnotation> anchorAnnotations = annotatedText
|
Position upperLeft) {
|
||||||
.getAnnotationsOfType(AnchorAnnotation.class);
|
Iterable<AnchorAnnotation> anchorAnnotations =
|
||||||
|
annotatedText.getAnnotationsOfType(AnchorAnnotation.class);
|
||||||
for (AnchorAnnotation anchorAnnotation : anchorAnnotations) {
|
for (AnchorAnnotation anchorAnnotation : anchorAnnotations) {
|
||||||
anchorMap.put(
|
anchorMap.put(anchorAnnotation.getAnchor(),
|
||||||
anchorAnnotation.getAnchor(),
|
new PageAnchor(drawContext.getCurrentPage(), upperLeft.getX(), upperLeft.getY()));
|
||||||
new PageAnchor(drawContext.getCurrentPage(), upperLeft
|
|
||||||
.getX(), upperLeft.getY()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void handleHyperlinkAnnotations(
|
protected void handleHyperlinkAnnotations(AnnotatedStyledText annotatedText,
|
||||||
AnnotatedStyledText annotatedText, DrawContext drawContext,
|
DrawContext drawContext,
|
||||||
Position upperLeft, float width, float height) {
|
Position upperLeft,
|
||||||
|
float width,
|
||||||
|
float height) {
|
||||||
Iterable<HyperlinkAnnotation> hyperlinkAnnotations = annotatedText
|
Iterable<HyperlinkAnnotation> hyperlinkAnnotations = annotatedText
|
||||||
.getAnnotationsOfType(HyperlinkAnnotation.class);
|
.getAnnotationsOfType(HyperlinkAnnotation.class);
|
||||||
for (HyperlinkAnnotation hyperlinkAnnotation : hyperlinkAnnotations) {
|
for (HyperlinkAnnotation hyperlinkAnnotation : hyperlinkAnnotations) {
|
||||||
|
@ -74,10 +76,8 @@ public class HyperlinkAnnotationProcessor implements AnnotationProcessor {
|
||||||
bounds.setLowerLeftY(upperLeft.getY() - height);
|
bounds.setLowerLeftY(upperLeft.getY() - height);
|
||||||
bounds.setUpperRightX(upperLeft.getX() + width);
|
bounds.setUpperRightX(upperLeft.getX() + width);
|
||||||
bounds.setUpperRightY(upperLeft.getY());
|
bounds.setUpperRightY(upperLeft.getY());
|
||||||
|
|
||||||
links.add(new Hyperlink(bounds, annotatedText.getColor(),
|
links.add(new Hyperlink(bounds, annotatedText.getColor(),
|
||||||
hyperlinkAnnotation.getLinkStyle(), hyperlinkAnnotation
|
hyperlinkAnnotation.getLinkStyle(), hyperlinkAnnotation.getHyperlinkURI()));
|
||||||
.getHyperlinkURI()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,8 +116,11 @@ public class HyperlinkAnnotationProcessor implements AnnotationProcessor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static PDAnnotationLink createLink(PDPage page, PDRectangle rect, Color color,
|
private static PDAnnotationLink createLink(PDPage page,
|
||||||
LinkStyle linkStyle, final String uri) {
|
PDRectangle rect,
|
||||||
|
Color color,
|
||||||
|
LinkStyle linkStyle,
|
||||||
|
String uri) {
|
||||||
PDAnnotationLink pdLink = createLink(page, rect, color, linkStyle);
|
PDAnnotationLink pdLink = createLink(page, rect, color, linkStyle);
|
||||||
PDActionURI actionUri = new PDActionURI();
|
PDActionURI actionUri = new PDActionURI();
|
||||||
actionUri.setURI(uri);
|
actionUri.setURI(uri);
|
||||||
|
@ -127,7 +130,9 @@ public class HyperlinkAnnotationProcessor implements AnnotationProcessor {
|
||||||
|
|
||||||
private static PDBorderStyleDictionary noBorder;
|
private static PDBorderStyleDictionary noBorder;
|
||||||
|
|
||||||
private static PDAnnotationLink createLink(PDPage page, PDRectangle rect, Color color,
|
private static PDAnnotationLink createLink(PDPage page,
|
||||||
|
PDRectangle rect,
|
||||||
|
Color color,
|
||||||
LinkStyle linkStyle) {
|
LinkStyle linkStyle) {
|
||||||
PDAnnotationLink pdLink = new PDAnnotationLink();
|
PDAnnotationLink pdLink = new PDAnnotationLink();
|
||||||
if (linkStyle == LinkStyle.none) {
|
if (linkStyle == LinkStyle.none) {
|
||||||
|
@ -146,8 +151,11 @@ public class HyperlinkAnnotationProcessor implements AnnotationProcessor {
|
||||||
return pdLink;
|
return pdLink;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static PDAnnotationLink createLink(PDPage page, PDRectangle rect, Color color,
|
private static PDAnnotationLink createLink(PDPage page,
|
||||||
LinkStyle linkStyle, final PDDestination destination) {
|
PDRectangle rect,
|
||||||
|
Color color,
|
||||||
|
LinkStyle linkStyle,
|
||||||
|
PDDestination destination) {
|
||||||
PDAnnotationLink pdLink = createLink(page, rect, color, linkStyle);
|
PDAnnotationLink pdLink = createLink(page, rect, color, linkStyle);
|
||||||
PDActionGoTo gotoAction = new PDActionGoTo();
|
PDActionGoTo gotoAction = new PDActionGoTo();
|
||||||
gotoAction.setDestination(destination);
|
gotoAction.setDestination(destination);
|
||||||
|
@ -155,12 +163,18 @@ public class HyperlinkAnnotationProcessor implements AnnotationProcessor {
|
||||||
return pdLink;
|
return pdLink;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static PDRectangle transformToPageRotation(final PDRectangle rect, final PDPage page) {
|
private static PDRectangle transformToPageRotation(PDRectangle rect,
|
||||||
|
PDPage page) {
|
||||||
AffineTransform transform = transformToPageRotation(page);
|
AffineTransform transform = transformToPageRotation(page);
|
||||||
if (transform == null) {
|
if (transform == null) {
|
||||||
return rect;
|
return rect;
|
||||||
}
|
}
|
||||||
float[] points = new float[]{rect.getLowerLeftX(), rect.getLowerLeftY(), rect.getUpperRightX(), rect.getUpperRightY()};
|
float[] points = {
|
||||||
|
rect.getLowerLeftX(),
|
||||||
|
rect.getLowerLeftY(),
|
||||||
|
rect.getUpperRightX(),
|
||||||
|
rect.getUpperRightY()
|
||||||
|
};
|
||||||
float[] rotatedPoints = new float[4];
|
float[] rotatedPoints = new float[4];
|
||||||
transform.transform(points, 0, rotatedPoints, 0, 2);
|
transform.transform(points, 0, rotatedPoints, 0, 2);
|
||||||
PDRectangle rotated = new PDRectangle();
|
PDRectangle rotated = new PDRectangle();
|
||||||
|
@ -171,7 +185,7 @@ public class HyperlinkAnnotationProcessor implements AnnotationProcessor {
|
||||||
return rotated;
|
return rotated;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static AffineTransform transformToPageRotation(final PDPage page) {
|
private static AffineTransform transformToPageRotation(PDPage page) {
|
||||||
int pageRotation = page.getRotation();
|
int pageRotation = page.getRotation();
|
||||||
if (pageRotation == 0) {
|
if (pageRotation == 0) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -179,8 +193,7 @@ public class HyperlinkAnnotationProcessor implements AnnotationProcessor {
|
||||||
float pageWidth = page.getMediaBox().getHeight();
|
float pageWidth = page.getMediaBox().getHeight();
|
||||||
float pageHeight = page.getMediaBox().getWidth();
|
float pageHeight = page.getMediaBox().getWidth();
|
||||||
AffineTransform transform = new AffineTransform();
|
AffineTransform transform = new AffineTransform();
|
||||||
transform.rotate(pageRotation * Math.PI / 180, pageHeight / 2,
|
transform.rotate(pageRotation * Math.PI / 180, pageHeight / 2, pageWidth / 2);
|
||||||
pageWidth / 2);
|
|
||||||
double offset = Math.abs(pageHeight - pageWidth) / 2;
|
double offset = Math.abs(pageHeight - pageWidth) / 2;
|
||||||
transform.translate(-offset, offset);
|
transform.translate(-offset, offset);
|
||||||
return transform;
|
return transform;
|
||||||
|
@ -197,8 +210,7 @@ public class HyperlinkAnnotationProcessor implements AnnotationProcessor {
|
||||||
String anchor = hyperlink.getHyperlinkURI().substring(1);
|
String anchor = hyperlink.getHyperlinkURI().substring(1);
|
||||||
PageAnchor pageAnchor = anchorMap.get(anchor);
|
PageAnchor pageAnchor = anchorMap.get(anchor);
|
||||||
if (pageAnchor == null) {
|
if (pageAnchor == null) {
|
||||||
throw new IllegalArgumentException(String.format(
|
throw new IllegalArgumentException(String.format("anchor named '%s' not found", anchor));
|
||||||
"anchor named '%s' not found", anchor));
|
|
||||||
}
|
}
|
||||||
PDPageXYZDestination xyzDestination = new PDPageXYZDestination();
|
PDPageXYZDestination xyzDestination = new PDPageXYZDestination();
|
||||||
xyzDestination.setPage(pageAnchor.getPage());
|
xyzDestination.setPage(pageAnchor.getPage());
|
||||||
|
@ -209,8 +221,11 @@ public class HyperlinkAnnotationProcessor implements AnnotationProcessor {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class PageAnchor {
|
private static class PageAnchor {
|
||||||
|
|
||||||
private final PDPage page;
|
private final PDPage page;
|
||||||
|
|
||||||
private final float x;
|
private final float x;
|
||||||
|
|
||||||
private final float y;
|
private final float y;
|
||||||
|
|
||||||
public PageAnchor(PDPage page, float x, float y) {
|
public PageAnchor(PDPage page, float x, float y) {
|
||||||
|
@ -238,9 +253,13 @@ public class HyperlinkAnnotationProcessor implements AnnotationProcessor {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class Hyperlink {
|
private static class Hyperlink {
|
||||||
|
|
||||||
private final PDRectangle rect;
|
private final PDRectangle rect;
|
||||||
|
|
||||||
private final Color color;
|
private final Color color;
|
||||||
|
|
||||||
private final String hyperlinkUri;
|
private final String hyperlinkUri;
|
||||||
|
|
||||||
private final LinkStyle linkStyle;
|
private final LinkStyle linkStyle;
|
||||||
|
|
||||||
public Hyperlink(PDRectangle rect, Color color, LinkStyle linkStyle,
|
public Hyperlink(PDRectangle rect, Color color, LinkStyle linkStyle,
|
||||||
|
|
|
@ -90,9 +90,20 @@ public class UnderlineAnnotationProcessor implements AnnotationProcessor {
|
||||||
}
|
}
|
||||||
contentStream.moveTo(start.getX(), start.getY());
|
contentStream.moveTo(start.getX(), start.getY());
|
||||||
contentStream.lineTo(end.getX(), end.getY());
|
contentStream.lineTo(end.getX(), end.getY());
|
||||||
|
contentStream.stroke();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new UncheckedIOException(e);
|
throw new UncheckedIOException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Line{" +
|
||||||
|
"start=" + start +
|
||||||
|
", end=" + end +
|
||||||
|
", stroke=" + stroke +
|
||||||
|
", color=" + color +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -243,8 +243,7 @@ public class CustomAnnotationTest {
|
||||||
float pageWidth = page.getMediaBox().getHeight();
|
float pageWidth = page.getMediaBox().getHeight();
|
||||||
float pageHeight = page.getMediaBox().getWidth();
|
float pageHeight = page.getMediaBox().getWidth();
|
||||||
AffineTransform transform = new AffineTransform();
|
AffineTransform transform = new AffineTransform();
|
||||||
transform.rotate(pageRotation * Math.PI / 180, pageHeight / 2,
|
transform.rotate(pageRotation * Math.PI / 180, pageHeight / 2, pageWidth / 2);
|
||||||
pageWidth / 2);
|
|
||||||
double offset = Math.abs(pageHeight - pageWidth) / 2;
|
double offset = Math.abs(pageHeight - pageWidth) / 2;
|
||||||
transform.translate(-offset, offset);
|
transform.translate(-offset, offset);
|
||||||
return transform;
|
return transform;
|
||||||
|
|
|
@ -7,10 +7,10 @@ import org.xbib.graphics.pdfbox.layout.font.BaseFont;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
|
||||||
public class Links {
|
public class LinksTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void main() throws Exception {
|
public void test() throws Exception {
|
||||||
String text1 = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, "
|
String text1 = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, "
|
||||||
+ "sed diam nonumy eirmod tempor invidunt ut labore et dolore magna "
|
+ "sed diam nonumy eirmod tempor invidunt ut labore et dolore magna "
|
||||||
+ "aliquyam erat, _sed diam_ voluptua. At vero eos et *accusam et justo* "
|
+ "aliquyam erat, _sed diam_ voluptua. At vero eos et *accusam et justo* "
|
||||||
|
@ -31,7 +31,6 @@ public class Links {
|
||||||
|
|
||||||
Document document = new Document(40, 60, 40, 60);
|
Document document = new Document(40, 60, 40, 60);
|
||||||
|
|
||||||
|
|
||||||
Paragraph paragraph0 = new Paragraph();
|
Paragraph paragraph0 = new Paragraph();
|
||||||
paragraph0.addMarkup("This is a link to {link[https://github.com/ralfstuckert/pdfbox-layout]}PDFBox-Layout{link}.\n\n", 11, BaseFont.TIMES);
|
paragraph0.addMarkup("This is a link to {link[https://github.com/ralfstuckert/pdfbox-layout]}PDFBox-Layout{link}.\n\n", 11, BaseFont.TIMES);
|
||||||
paragraph0.addMarkup("Now the same link with color instead of underline {color:#ff5000}{link:none[https://github.com/ralfstuckert/pdfbox-layout]}PDFBox-Layout{link}{color:#000000}.\n\n", 11, BaseFont.TIMES);
|
paragraph0.addMarkup("Now the same link with color instead of underline {color:#ff5000}{link:none[https://github.com/ralfstuckert/pdfbox-layout]}PDFBox-Layout{link}{color:#000000}.\n\n", 11, BaseFont.TIMES);
|
|
@ -24,9 +24,11 @@ public class MarkupTest {
|
||||||
+ "gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.\n\n";
|
+ "gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.\n\n";
|
||||||
|
|
||||||
Document document = new Document(40, 60, 40, 60);
|
Document document = new Document(40, 60, 40, 60);
|
||||||
|
|
||||||
Paragraph paragraph = new Paragraph();
|
Paragraph paragraph = new Paragraph();
|
||||||
paragraph.addMarkup(text1, 11, BaseFont.TIMES);
|
paragraph.addMarkup(text1, 11, BaseFont.TIMES);
|
||||||
document.add(paragraph);
|
document.add(paragraph);
|
||||||
|
|
||||||
paragraph = new Paragraph();
|
paragraph = new Paragraph();
|
||||||
paragraph.addMarkup("Markup supports *bold*, _italic_, and *even _mixed* markup_.\n\n",
|
paragraph.addMarkup("Markup supports *bold*, _italic_, and *even _mixed* markup_.\n\n",
|
||||||
11, BaseFont.TIMES);
|
11, BaseFont.TIMES);
|
||||||
|
@ -41,6 +43,11 @@ public class MarkupTest {
|
||||||
11, BaseFont.TIMES);
|
11, BaseFont.TIMES);
|
||||||
document.add(paragraph, new VerticalLayoutHint(Alignment.LEFT, 0, 0, 30, 0));
|
document.add(paragraph, new VerticalLayoutHint(Alignment.LEFT, 0, 0, 30, 0));
|
||||||
|
|
||||||
|
paragraph = new Paragraph();
|
||||||
|
paragraph.addMarkup("And here comes a link to an internal anchor name {color:#ff5000}{link[#hello]}hello{link}{color:#000000}.\n\n", 11, BaseFont.TIMES);
|
||||||
|
paragraph.addMarkup("\n\n{anchor:hello}Here{anchor} comes the internal anchor named *hello*\n\n", 11, BaseFont.COURIER);
|
||||||
|
document.add(paragraph);
|
||||||
|
|
||||||
paragraph = new Paragraph();
|
paragraph = new Paragraph();
|
||||||
text1 = "\nAlso, you can do all that indentation stuff much easier with markup, e.g. simple indentation\n"
|
text1 = "\nAlso, you can do all that indentation stuff much easier with markup, e.g. simple indentation\n"
|
||||||
+ "--At vero eos et accusam\n\n"
|
+ "--At vero eos et accusam\n\n"
|
||||||
|
|
|
@ -19,7 +19,8 @@ public class FontDrawerTest {
|
||||||
Font anyFontItalic = anyFont.deriveFont(Font.ITALIC);
|
Font anyFontItalic = anyFont.deriveFont(Font.ITALIC);
|
||||||
Font anyFontBoldItalic = anyFont.deriveFont(Font.BOLD | Font.ITALIC);
|
Font anyFontBoldItalic = anyFont.deriveFont(Font.BOLD | Font.ITALIC);
|
||||||
|
|
||||||
Assertions.assertEquals(PDType1Font.COURIER, CoreFontDrawer.chooseMatchingCourier(anyFont));
|
Assertions.assertEquals(PDType1Font.COURIER,
|
||||||
|
CoreFontDrawer.chooseMatchingCourier(anyFont));
|
||||||
assertEquals(PDType1Font.COURIER_BOLD,
|
assertEquals(PDType1Font.COURIER_BOLD,
|
||||||
CoreFontDrawer.chooseMatchingCourier(anyFontBold));
|
CoreFontDrawer.chooseMatchingCourier(anyFontBold));
|
||||||
assertEquals(PDType1Font.COURIER_OBLIQUE,
|
assertEquals(PDType1Font.COURIER_OBLIQUE,
|
||||||
|
@ -36,7 +37,8 @@ public class FontDrawerTest {
|
||||||
assertEquals(PDType1Font.HELVETICA_BOLD_OBLIQUE,
|
assertEquals(PDType1Font.HELVETICA_BOLD_OBLIQUE,
|
||||||
CoreFontDrawer.chooseMatchingHelvetica(anyFontBoldItalic));
|
CoreFontDrawer.chooseMatchingHelvetica(anyFontBoldItalic));
|
||||||
|
|
||||||
assertEquals(PDType1Font.TIMES_ROMAN, CoreFontDrawer.chooseMatchingTimes(anyFont));
|
assertEquals(PDType1Font.TIMES_ROMAN,
|
||||||
|
CoreFontDrawer.chooseMatchingTimes(anyFont));
|
||||||
assertEquals(PDType1Font.TIMES_BOLD,
|
assertEquals(PDType1Font.TIMES_BOLD,
|
||||||
CoreFontDrawer.chooseMatchingTimes(anyFontBold));
|
CoreFontDrawer.chooseMatchingTimes(anyFontBold));
|
||||||
assertEquals(PDType1Font.TIMES_ITALIC,
|
assertEquals(PDType1Font.TIMES_ITALIC,
|
||||||
|
|
Loading…
Reference in a new issue