From fc44d4bcad00192f0df8f6086737b9b126094dcd Mon Sep 17 00:00:00 2001 From: Andreas Fitzek Date: Thu, 26 Sep 2013 15:48:43 +0200 Subject: initial code commit --- .../at/knowcenter/wag/egov/egiz/pdf/PDFPage.java | 502 ++++++++++++++++ .../knowcenter/wag/egov/egiz/pdf/PDFUtilities.java | 72 +++ .../java/at/knowcenter/wag/egov/egiz/pdf/Pos.java | 70 +++ .../wag/egov/egiz/pdf/PositioningInstruction.java | 182 ++++++ .../at/knowcenter/wag/egov/egiz/pdf/TablePos.java | 261 +++++++++ .../path/PathConstructionOperatorProcessor.java | 61 ++ .../path/PathPaintingOperatorProcessor.java | 42 ++ .../pdf/operator/path/construction/ClosePath.java | 67 +++ .../pdf/operator/path/construction/CurveTo.java | 84 +++ .../construction/CurveToReplicateFinalPoint.java | 81 +++ .../construction/CurveToReplicateInitialPoint.java | 83 +++ .../pdf/operator/path/construction/LineTo.java | 70 +++ .../pdf/operator/path/construction/MoveTo.java | 72 +++ .../operator/path/painting/CloseAndStrokePath.java | 58 ++ .../painting/CloseFillEvenOddAndStrokePath.java | 59 ++ .../painting/CloseFillNonZeroAndStrokePath.java | 59 ++ .../egiz/pdf/operator/path/painting/EndPath.java | 67 +++ .../path/painting/FillEvenOddAndStrokePath.java | 71 +++ .../path/painting/FillNonZeroAndStrokePath.java | 71 +++ .../path/painting/FillPathEvenOddRule.java | 70 +++ .../painting/FillPathNonZeroWindingNumberRule.java | 71 +++ .../pdf/operator/path/painting/StrokePath.java | 69 +++ .../wag/egov/egiz/pdf/sig/SignatureEntry.java | 163 ++++++ .../at/knowcenter/wag/egov/egiz/table/Entry.java | 235 ++++++++ .../at/knowcenter/wag/egov/egiz/table/Style.java | 630 +++++++++++++++++++++ .../at/knowcenter/wag/egov/egiz/table/Table.java | 223 ++++++++ 26 files changed, 3493 insertions(+) create mode 100644 pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/PDFPage.java create mode 100644 pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/PDFUtilities.java create mode 100644 pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/Pos.java create mode 100644 pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/PositioningInstruction.java create mode 100644 pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/TablePos.java create mode 100644 pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/operator/path/PathConstructionOperatorProcessor.java create mode 100644 pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/operator/path/PathPaintingOperatorProcessor.java create mode 100644 pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/operator/path/construction/ClosePath.java create mode 100644 pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/operator/path/construction/CurveTo.java create mode 100644 pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/operator/path/construction/CurveToReplicateFinalPoint.java create mode 100644 pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/operator/path/construction/CurveToReplicateInitialPoint.java create mode 100644 pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/operator/path/construction/LineTo.java create mode 100644 pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/operator/path/construction/MoveTo.java create mode 100644 pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/operator/path/painting/CloseAndStrokePath.java create mode 100644 pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/operator/path/painting/CloseFillEvenOddAndStrokePath.java create mode 100644 pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/operator/path/painting/CloseFillNonZeroAndStrokePath.java create mode 100644 pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/operator/path/painting/EndPath.java create mode 100644 pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/operator/path/painting/FillEvenOddAndStrokePath.java create mode 100644 pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/operator/path/painting/FillNonZeroAndStrokePath.java create mode 100644 pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/operator/path/painting/FillPathEvenOddRule.java create mode 100644 pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/operator/path/painting/FillPathNonZeroWindingNumberRule.java create mode 100644 pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/operator/path/painting/StrokePath.java create mode 100644 pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/sig/SignatureEntry.java create mode 100644 pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/table/Entry.java create mode 100644 pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/table/Style.java create mode 100644 pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/table/Table.java (limited to 'pdf-as-lib/src/main/java/at/knowcenter/wag/egov') diff --git a/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/PDFPage.java b/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/PDFPage.java new file mode 100644 index 00000000..b5928406 --- /dev/null +++ b/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/PDFPage.java @@ -0,0 +1,502 @@ +/** + * Copyright 2006 by Know-Center, Graz, Austria + * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a + * joint initiative of the Federal Chancellery Austria and Graz University of + * Technology. + * + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by + * the European Commission - subsequent versions of the EUPL (the "Licence"); + * You may not use this work except in compliance with the Licence. + * You may obtain a copy of the Licence at: + * http://www.osor.eu/eupl/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the Licence is distributed on an "AS IS" basis, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the Licence for the specific language governing permissions and + * limitations under the Licence. + * + * This product combines work with different licenses. See the "NOTICE" text + * file for details on the various modules and licenses. + * The "NOTICE" text file is part of the distribution. Any derivative works + * that you distribute must include a readable copy of the "NOTICE" text file. + * + * $Id: PDFPage.java,v 1.5 2006/10/31 08:09:33 wprinz Exp $ + */ +package at.knowcenter.wag.egov.egiz.pdf; + +import at.knowcenter.wag.egov.egiz.pdf.operator.path.construction.*; +import at.knowcenter.wag.egov.egiz.pdf.operator.path.painting.*; + +import org.apache.commons.lang3.math.NumberUtils; +import org.apache.pdfbox.cos.COSName; +import org.apache.pdfbox.cos.COSStream; +import org.apache.pdfbox.pdmodel.PDPage; +import org.apache.pdfbox.pdmodel.PDResources; +import org.apache.pdfbox.pdmodel.common.PDRectangle; +import org.apache.pdfbox.pdmodel.common.PDStream; +import org.apache.pdfbox.pdmodel.graphics.xobject.PDXObject; +import org.apache.pdfbox.pdmodel.graphics.xobject.PDXObjectForm; +import org.apache.pdfbox.util.Matrix; +import org.apache.pdfbox.util.PDFOperator; +import org.apache.pdfbox.util.PDFTextStripper; +import org.apache.pdfbox.util.TextPosition; +import org.apache.pdfbox.util.operator.OperatorProcessor; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.awt.*; +import java.awt.geom.GeneralPath; +import java.io.IOException; +import java.io.Writer; +import java.util.List; +import java.util.Map; + +/** + * PDFPage is an inner class that is used to calculate the page length of a PDF + * Document page. It extends the PDFTextStripper class and implement one + * interested method: {@link at.knowcenter.wag.egov.egiz.pdf.PDFPage#showCharacter(TextPosition)}
+ * This method is called when processing the FileStream. By calling the method + * {@link org.apache.pdfbox.util.PDFStreamEngine#processStream(org.apache.pdfbox.pdmodel.PDPage, org.apache.pdfbox.pdmodel.PDResources, org.pdfbox.cos.COSStream)} + * the implemented method showCharacter is called. + * + * @author wlackner + * @see PDFTextStripper + */ +public class PDFPage extends PDFTextStripper { + /** + * The logger definition. + */ + private static final Logger logger = LoggerFactory.getLogger(PDFPage.class); + + /** + * The maximum (lowest) y position of a character. + */ + protected float max_character_ypos = Float.NEGATIVE_INFINITY; + + /** + * The maximum (lowest y position of an image. + */ + protected float max_image_ypos = Float.NEGATIVE_INFINITY; + + /** + * The effective page height. + */ + protected float effectivePageHeight; + + /** + * The path currently being constructed. + */ + private GeneralPath currentPath = new GeneralPath(); + + /** + * The lowest position of a drawn path (originating from top). + */ + private float maxPathRelatedYPositionFromTop = Float.NEGATIVE_INFINITY; + + /** + * Constructor. + * + * @param effectivePageHeight + * The height of the page to be evaluated. PDF elements outside + * this height will not be considered. + * + * @throws java.io.IOException + */ + public PDFPage(float effectivePageHeight, boolean legacy32) throws IOException { + super(); + + this.effectivePageHeight = effectivePageHeight; + + OperatorProcessor newInvoke = new MyInvoke(this); + newInvoke.setContext(this); + this.registerOperatorProcessor("Do", newInvoke); + + if (!legacy32) { + registerCustomPathOperators(); + } + } + + /** + * Registers operators responsible for path construction and painting in + * order to fix auto positioning on pages with path elements. + * + * @author Datentechnik Innovation GmbH + */ + @SuppressWarnings("unchecked") + private void registerCustomPathOperators() { + + // *** path construction + + this.registerOperatorProcessor("m", new MoveTo(this)); + this.registerOperatorProcessor("l", new LineTo(this)); + this.registerOperatorProcessor("c", new CurveTo(this)); + this.registerOperatorProcessor("y", new CurveToReplicateFinalPoint(this)); + this.registerOperatorProcessor("v", new CurveToReplicateInitialPoint(this)); + this.registerOperatorProcessor("h", new ClosePath(this)); + + // *** path painting + + // "S": stroke path + this.registerOperatorProcessor("S", new StrokePath(this)); + this.registerOperatorProcessor("s", new CloseAndStrokePath(this)); + this.registerOperatorProcessor("f", new FillPathNonZeroWindingNumberRule(this)); + this.registerOperatorProcessor("F", new FillPathNonZeroWindingNumberRule(this)); + this.registerOperatorProcessor("f*", new FillPathEvenOddRule(this)); + this.registerOperatorProcessor("b", new CloseFillNonZeroAndStrokePath(this)); + this.registerOperatorProcessor("B", new FillNonZeroAndStrokePath(this)); + this.registerOperatorProcessor("b*", new CloseFillEvenOddAndStrokePath(this)); + this.registerOperatorProcessor("B*", new FillEvenOddAndStrokePath(this)); + this.registerOperatorProcessor("n", new EndPath(this)); + + // Note: The graphic context + // (org.pdfbox.pdmodel.graphics.PDGraphicsState) of the underlying + // pdfbox library does + // not yet support clipping. This prevents feasible usage of clipping + // operators (W, W*). + // operators.put("W", new ...(this)); + // operators.put("W*", new ...(this)); + + } + + /** + * Returns the path currently being constructed. + * + * @return The path currently being constructed. + */ + public GeneralPath getCurrentPath() { + return currentPath; + } + + /** + * Sets the current path. + * + * @param currentPath + * The new current path. + */ + public void setCurrentPath(GeneralPath currentPath) { + this.currentPath = currentPath; + } + + /** + * Registers a rectangle that bounds the path currently being drawn. + * + * @param bounds + * A rectangle depicting the bounds (coordinates originating from + * bottom left). + * @author Datentechnik Innovation GmbH + */ + public void registerPathBounds(Rectangle bounds) { + if (!bounds.isEmpty()) { + logger.debug("Registering path bounds: " + bounds); + + // vertical start of rectangle (counting from top of page) + float upperBoundYPositionFromTop; + + // vertical end of rectangle (counting from top of page) + // this depicts the current end of path-related page content + float lowerBoundYPositionFromTop; + + PDRectangle boundaryBox = this.getCurrentPage().findMediaBox(); + float pageHeight; + + switch (this.getCurrentPage().findRotation()) { + case 90: // CW + pageHeight = boundaryBox.getWidth(); + upperBoundYPositionFromTop = (float) bounds.getMinX(); + lowerBoundYPositionFromTop = (float) bounds.getMaxX(); + break; + case 180: + pageHeight = boundaryBox.getHeight(); + upperBoundYPositionFromTop = (float) bounds.getMinY(); + lowerBoundYPositionFromTop = (float) bounds.getMaxY(); + break; + case 270: // CCW + pageHeight = boundaryBox.getWidth(); + upperBoundYPositionFromTop = pageHeight + - (float) bounds.getMaxX(); + lowerBoundYPositionFromTop = pageHeight + - (float) bounds.getMinX(); + break; + default: + pageHeight = boundaryBox.getHeight(); + upperBoundYPositionFromTop = pageHeight + - (float) bounds.getMaxY(); + lowerBoundYPositionFromTop = pageHeight + - (float) bounds.getMinY(); + break; + } + + // new maximum ? + if (lowerBoundYPositionFromTop > maxPathRelatedYPositionFromTop) { + // Is the rectangle (at least partly) located above the footer + // line? + // (effective page height := page height - footer line) + if (upperBoundYPositionFromTop <= effectivePageHeight) { + // yes: update current end of path-related page content + maxPathRelatedYPositionFromTop = lowerBoundYPositionFromTop; + logger.trace("New max path related y position (from top): " + + maxPathRelatedYPositionFromTop); + } else { + // no: rectangle is fully located below the footer line -> + // ignore + logger.trace("Ignoring path bound below the footer line."); + } + } + } + } + + protected void processOperator(PDFOperator operator, List arguments) + throws IOException { + logger.trace("operator = " + operator); + super.processOperator(operator, arguments); + } + + @Override + protected void processTextPosition(TextPosition text) { + showCharacter(text); + } + + // exthex + /** + * A method provided as an event interface to allow a subclass to perform + * some specific functionality when a character needs to be displayed. This + * method is used to calculate the latest position of a text in the page. + * Sorry for this missinterpretation of the method, but it is the only way + * to do this (provided by PDFBox)!!! + * + * @param text + * the character to be displayed -> calculate there y position. + */ + protected void showCharacter(TextPosition text) { + float current_y = text.getY(); + final String character = text.getCharacter(); + + int pageRotation = this.getCurrentPage().findRotation(); + // logger_.debug("PageRotation = " + pageRotation); + if (pageRotation == 0) { + current_y = text.getY(); + } + if (pageRotation == 90) { + current_y = text.getX(); + } + if (pageRotation == 180) { + float page_height = this.getCurrentPage().findMediaBox().getHeight(); + current_y = page_height - text.getY(); + } + if (pageRotation == 270) { + float page_height = this.getCurrentPage().findMediaBox().getHeight(); + current_y = page_height - text.getX(); + } + + if (current_y > this.effectivePageHeight) { + // logger_.debug("character is below footer_line. footer_line = " + + // this.footer_line + ", text.character=" + character + ", y=" + + // current_y); + return; + } + + // store ypos of the char if it is not empty + if (!character.equals(" ") && current_y > this.max_character_ypos) { + this.max_character_ypos = current_y; + } + + } + + // use this funtion getting an unsorted text output + // public void showString(byte[] string) { + // logger_.debug(new String(string)); + // } + + /** + * Returns the calculated page length. + * + * @return the max page length value + */ + public float getMaxPageLength() { + if (logger.isDebugEnabled()) { + logger.debug("Determining page content length: text=" + + max_character_ypos + ", image=" + max_image_ypos + + ", path=" + maxPathRelatedYPositionFromTop); + } + return NumberUtils.max(max_character_ypos, max_image_ypos, + maxPathRelatedYPositionFromTop); + } + + public class MyInvoke extends OperatorProcessor { + + private PDFPage mypage; + + public MyInvoke(PDFPage page) { + this.mypage = page; + } + + public void process(PDFOperator operator, List arguments) + throws IOException { + COSName name = (COSName) arguments.get(0); + + // PDResources res = context.getResources(); + + Map xobjects = context.getXObjects(); + PDXObject xobject = (PDXObject) xobjects.get(name.getName()); + + PDStream stream = xobject.getPDStream(); + COSStream cos_stream = stream.getStream(); + + COSName subtype = (COSName) cos_stream + .getDictionaryObject(COSName.SUBTYPE); + if (subtype.equals(COSName.IMAGE)) { + logger.debug("XObject Image"); + + Matrix ctm = context.getGraphicsState() + .getCurrentTransformationMatrix(); + logger.debug("ctm = " + ctm); + + Pos[] coordinates = new Pos[] { new Pos(0, 0, 1), + new Pos(1, 0, 1), new Pos(0, 1, 1), new Pos(1, 1, 1) }; + + Pos[] transformed_coordinates = transtormCoordinates( + coordinates, ctm); + + /********************************************************** + * pdf-as fix: calculating min and max point of an image to look + * where the signature should be placed fix solves problems with + * footer and images and placement of the signature in an image + * only pdf document + **********************************************************/ + + float actual_lowest_point = Float.NaN; + float actual_starting_point = Float.NaN; + + int pageRotation = this.mypage.getCurrentPage().findRotation(); + logger.debug("PageRotation = " + pageRotation); + if (pageRotation == 0) { + float min_y = findMinY(transformed_coordinates); + logger.debug("min_y = " + min_y); + float page_height = this.mypage.getCurrentPage().findMediaBox().getHeight(); + logger.debug("page_height = " + page_height); + + actual_lowest_point = page_height - min_y; + actual_starting_point = page_height + - findMaxY(transformed_coordinates); + } + if (pageRotation == 90) { + float max_x = findMaxX(transformed_coordinates); + logger.debug("max_x = " + max_x); + float page_width = this.mypage.getCurrentPage().findMediaBox().getWidth(); + logger.debug("page_width = " + page_width); + + actual_lowest_point = max_x; + actual_starting_point = findMinX(transformed_coordinates); + } + if (pageRotation == 180) { + float min_y = findMinY(transformed_coordinates); + logger.debug("min_y = " + min_y); + float page_height = this.mypage.getCurrentPage().findMediaBox().getHeight(); + actual_lowest_point = page_height + - findMaxY(transformed_coordinates); + actual_starting_point = page_height - min_y; + } + if (pageRotation == 270) { + float min_x = findMinX(transformed_coordinates); + logger.debug("min_x = " + min_x); + + float page_width = this.mypage.getCurrentPage().findMediaBox().getWidth(); + logger.debug("page_width = " + page_width); + + actual_lowest_point = page_width - min_x; + actual_starting_point = page_width + - findMaxX(transformed_coordinates); + } + + logger.debug("actual_lowest_point = " + actual_lowest_point); + + if (actual_lowest_point > PDFPage.this.effectivePageHeight + && actual_starting_point > PDFPage.this.effectivePageHeight) { + logger.debug("image is below footer_line"); + return; + } + + if (actual_lowest_point > PDFPage.this.max_image_ypos) { + PDFPage.this.max_image_ypos = actual_lowest_point; + } + + return; + } + + if (xobject instanceof PDXObjectForm) { + PDXObjectForm form = (PDXObjectForm) xobject; + COSStream invoke = (COSStream) form.getCOSObject(); + PDResources pdResources = form.getResources(); + PDPage page = context.getCurrentPage(); + if (pdResources == null) { + pdResources = page.findResources(); + } + + getContext().processSubStream(page, pdResources, invoke); + } + } + } + + public static Pos[] transtormCoordinates(Pos[] coordinates, Matrix m) { + Pos[] transformed = new Pos[coordinates.length]; + for (int i = 0; i < coordinates.length; i++) { + transformed[i] = transtormCoordinate(coordinates[i], m); + } + return transformed; + } + + public static Pos transtormCoordinate(Pos pos, Matrix m) { + Pos transformed = new Pos(); + transformed.x = pos.x * m.getValue(0, 0) + pos.y * m.getValue(1, 0) + + pos.z * m.getValue(2, 0); + transformed.y = pos.x * m.getValue(0, 1) + pos.y * m.getValue(1, 1) + + pos.z * m.getValue(2, 1); + transformed.z = pos.x * m.getValue(0, 2) + pos.y * m.getValue(1, 2) + + pos.z * m.getValue(2, 2); + + logger.debug(" transformed " + pos + " --> " + transformed); + return transformed; + } + + public static float findMinY(Pos[] coordinates) { + float min = Float.POSITIVE_INFINITY; + for (int i = 0; i < coordinates.length; i++) { + if (coordinates[i].y < min) { + min = coordinates[i].y; + } + } + return min; + } + + public static float findMaxY(Pos[] coordinates) { + float max = 0; + for (int i = 0; i < coordinates.length; i++) { + if (coordinates[i].y > max) { + max = coordinates[i].y; + } + } + return max; + } + + public static float findMaxX(Pos[] coordinates) { + float max = Float.NEGATIVE_INFINITY; + for (int i = 0; i < coordinates.length; i++) { + if (coordinates[i].x > max) { + max = coordinates[i].x; + } + } + return max; + } + + public static float findMinX(Pos[] coordinates) { + float min = Float.POSITIVE_INFINITY; + for (int i = 0; i < coordinates.length; i++) { + if (coordinates[i].x < min) { + min = coordinates[i].x; + } + } + return min; + } + +} \ No newline at end of file diff --git a/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/PDFUtilities.java b/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/PDFUtilities.java new file mode 100644 index 00000000..7f223b40 --- /dev/null +++ b/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/PDFUtilities.java @@ -0,0 +1,72 @@ +/** + * Copyright 2006 by Know-Center, Graz, Austria + * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a + * joint initiative of the Federal Chancellery Austria and Graz University of + * Technology. + * + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by + * the European Commission - subsequent versions of the EUPL (the "Licence"); + * You may not use this work except in compliance with the Licence. + * You may obtain a copy of the Licence at: + * http://www.osor.eu/eupl/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the Licence is distributed on an "AS IS" basis, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the Licence for the specific language governing permissions and + * limitations under the Licence. + * + * This product combines work with different licenses. See the "NOTICE" text + * file for details on the various modules and licenses. + * The "NOTICE" text file is part of the distribution. Any derivative works + * that you distribute must include a readable copy of the "NOTICE" text file. + * + * $Id: PDFUtilities.java,v 1.3 2006/10/31 08:09:33 wprinz Exp $ + */ +package at.knowcenter.wag.egov.egiz.pdf; + +import java.io.IOException; +import java.util.List; + +import at.gv.egiz.pdfas.common.exceptions.PDFIOException; +import org.apache.pdfbox.cos.COSStream; +import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdmodel.PDPage; +import org.apache.pdfbox.pdmodel.PDResources; +import org.apache.pdfbox.pdmodel.interactive.pagenavigation.PDThreadBead; + + +/** + * Contains useful helpers for accessing PDF documents. + * + * @author wprinz + * @author mruhmer + */ +public abstract class PDFUtilities +{ + public static float calculatePageLength(PDDocument document, int page, float effectivePageHeight, /*int pagerotation,*/ boolean legacy32) throws PDFIOException { + //int last_page_id = document.getNumberOfPages(); + List allPages = document.getDocumentCatalog().getAllPages(); + PDPage pdpage = (PDPage) allPages.get(page); + //pdpage.setRotation(pagerotation); + return calculatePageLength(pdpage, effectivePageHeight, legacy32); + } + + public static float calculatePageLength(PDPage page, float effectivePageHeight, boolean legacy32) throws PDFIOException + { + try{ + PDFPage my_page = new PDFPage(effectivePageHeight, legacy32); + PDResources resources = page.findResources(); + COSStream stream = page.getContents().getStream(); + //List articles = page.getThreadBeads(); + //my_page.processMyPage(page); + my_page.processStream(page, resources, stream); + return my_page.getMaxPageLength(); + } + catch (IOException e) + { + throw new PDFIOException("calculatePageLength", e); + } + } + +} diff --git a/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/Pos.java b/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/Pos.java new file mode 100644 index 00000000..6f03fed4 --- /dev/null +++ b/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/Pos.java @@ -0,0 +1,70 @@ +/** + * Copyright 2006 by Know-Center, Graz, Austria + * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a + * joint initiative of the Federal Chancellery Austria and Graz University of + * Technology. + * + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by + * the European Commission - subsequent versions of the EUPL (the "Licence"); + * You may not use this work except in compliance with the Licence. + * You may obtain a copy of the Licence at: + * http://www.osor.eu/eupl/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the Licence is distributed on an "AS IS" basis, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the Licence for the specific language governing permissions and + * limitations under the Licence. + * + * This product combines work with different licenses. See the "NOTICE" text + * file for details on the various modules and licenses. + * The "NOTICE" text file is part of the distribution. Any derivative works + * that you distribute must include a readable copy of the "NOTICE" text file. + * + * $Id: Pos.java,v 1.1 2006/08/25 17:10:08 wprinz Exp $ + */ +package at.knowcenter.wag.egov.egiz.pdf; + +/** + * Encapsulation of a position on a PDF page. + * + * @author wprinz + */ +public class Pos +{ + + public float x; + + public float y; + + public float z; + + /** + * Default constructor. + */ + public Pos() + { + } + + /** + * Constructor that sets the coordinates. + * @param xx + * @param yy + * @param zz + */ + public Pos(float xx, float yy, float zz) + { + this.x = xx; + this.y = yy; + this.z = zz; + } + + /** + * @see Object#toString() + */ + public String toString() + { + return "(" + this.x + "," + this.y + "," + this.z + ")"; + } + +} diff --git a/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/PositioningInstruction.java b/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/PositioningInstruction.java new file mode 100644 index 00000000..0fe399c4 --- /dev/null +++ b/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/PositioningInstruction.java @@ -0,0 +1,182 @@ +/** + * Copyright 2006 by Know-Center, Graz, Austria + * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a + * joint initiative of the Federal Chancellery Austria and Graz University of + * Technology. + * + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by + * the European Commission - subsequent versions of the EUPL (the "Licence"); + * You may not use this work except in compliance with the Licence. + * You may obtain a copy of the Licence at: + * http://www.osor.eu/eupl/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the Licence is distributed on an "AS IS" basis, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the Licence for the specific language governing permissions and + * limitations under the Licence. + * + * This product combines work with different licenses. See the "NOTICE" text + * file for details on the various modules and licenses. + * The "NOTICE" text file is part of the distribution. Any derivative works + * that you distribute must include a readable copy of the "NOTICE" text file. + * + * $Id: $ + */ +package at.knowcenter.wag.egov.egiz.pdf; + +/** + * The positioning instruction holds information of where to place the signature + * block. + * + *

+ * This instruction is given to the PDF writer in order to place the signature. + *

+ * + * @author wprinz + */ +public class PositioningInstruction +{ + + /** + * Tells, if a new plain page should be appended. + * + *

+ * This command is executed before the signature block is positioned according + * to page, x and y. + *

+ */ + protected boolean make_new_page = false; + + /** + * The number of the page on which the signature block is to be placed. If + * specified to make a new page, the number of this newly created page can be + * used here as well. + */ + protected int page = 0; + + /** + * The x coordinate where the upper left corner of the signature block should + * be placed. + */ + protected float x = 0.0f; + + /** + * The y coordinate where the upper left corner of the signature block should + * be placed. + */ + protected float y = 0.0f; + + /** + * + * @param make_new_page + * Tells, if a new plain page should be appended. This command is + * executed before the signature block is positioned according to + * page, x and y. + * @param page + * The number of the page on which the signature block is to be + * placed. If specified to make a new page, the number of this newly + * created page can be used here as well. + * @param x + * The x coordinate where the upper left corner of the signature + * block should be placed. + * @param y + * The y coordinate where the upper left corner of the signature + * block should be placed. + */ + public PositioningInstruction(boolean make_new_page, int page, float x, float y) + { + this.make_new_page = make_new_page; + this.page = page; + this.x = x; + this.y = y; + } + + /** + * Tells, if a new plain page should be appended to the document. + * + * @return Returns true, if a new plain page should be appended. + */ + public boolean isMakeNewPage() + { + return this.make_new_page; + } + + /** + * Returns the page on which the signature is to be printed. + * + * @return Returns the page on which the signature is to be printed. + */ + public int getPage() + { + return this.page; + } + + /** + * Returns the x coordinate where the upper left corner of the signature block + * should be placed. + * + * @return Returns the x coordinate where the upper left corner of the + * signature block should be placed. + */ + public float getX() + { + return this.x; + } + + /** + * Returns the y coordinate where the upper left corner of the signature block + * should be placed. + * + * @return Returns the y coordinate where the upper left corner of the + * signature block should be placed. + */ + public float getY() + { + return this.y; + } + + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + (make_new_page ? 1231 : 1237); + result = prime * result + page; + result = prime * result + Float.floatToIntBits(x); + result = prime * result + Float.floatToIntBits(y); + return result; + } + + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (!(obj instanceof PositioningInstruction)) + return false; + PositioningInstruction other = (PositioningInstruction) obj; + if (make_new_page != other.make_new_page) + return false; + if (page != other.page) + return false; + if (Float.floatToIntBits(x) != Float.floatToIntBits(other.x)) + return false; + if (Float.floatToIntBits(y) != Float.floatToIntBits(other.y)) + return false; + return true; + } + + public String toString() { + StringBuffer buffer = new StringBuffer(); + buffer.append("PositioningInstruction [page="); + buffer.append(page); + buffer.append(", make_new_page="); + buffer.append(make_new_page); + buffer.append(", x="); + buffer.append(x); + buffer.append(", y="); + buffer.append(y); + buffer.append("]"); + return buffer.toString(); + } + +} diff --git a/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/TablePos.java b/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/TablePos.java new file mode 100644 index 00000000..92afaf98 --- /dev/null +++ b/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/TablePos.java @@ -0,0 +1,261 @@ +/** + * Copyright 2006 by Know-Center, Graz, Austria + * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a + * joint initiative of the Federal Chancellery Austria and Graz University of + * Technology. + * + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by + * the European Commission - subsequent versions of the EUPL (the "Licence"); + * You may not use this work except in compliance with the Licence. + * You may obtain a copy of the Licence at: + * http://www.osor.eu/eupl/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the Licence is distributed on an "AS IS" basis, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the Licence for the specific language governing permissions and + * limitations under the Licence. + * + * This product combines work with different licenses. See the "NOTICE" text + * file for details on the various modules and licenses. + * The "NOTICE" text file is part of the distribution. Any derivative works + * that you distribute must include a readable copy of the "NOTICE" text file. + * + * $Id: TablePos.java,v 1.1 2006/08/25 17:10:08 wprinz Exp $ + */ +package at.knowcenter.wag.egov.egiz.pdf; + +import java.io.Serializable; + +import at.gv.egiz.pdfas.common.exceptions.PdfAsException; + +/** + * Class that holds the exact position where the table should be written to the + * document. + * + * @author wprinz + * @author mruhmer + */ +public class TablePos implements Serializable +{ + + /** + * SVUID. + */ + private static final long serialVersionUID = -5299027706623518059L; + + /** + * The page on which the block should be displayed. + * + */ + private int page = 0; + + /** + * The x position. + */ + private float pos_x = 0.0f; + + /** + * The y position. + */ + private float pos_y = 0.0f; + + /** + * The width of the block. + */ + private float width = 0.0f; + /** + * The top y position of the footer line. + */ + public float footer_line = 0.0f; + + /** + * The y position. + */ + public String myposstring = ""; + + private boolean newpage = false; + private boolean autoX = true; + private boolean autoY = true; + private boolean autoW = true; + private boolean autoP = true; + + public boolean isXauto() + { + return this.autoX; + } + public boolean isYauto() + { + return this.autoY; + } + public boolean isWauto() + { + return this.autoW; + } + public boolean isPauto() + { + return this.autoP; + } + public boolean isNewPage() + { + return this.newpage; + } + public int getPage() + { + return this.page; + } + public float getFooterLine() + { + //ignore if newpage and y is not auto + if (!this.autoY || this.newpage) + { + return 0.0f; + } + return this.footer_line; + } + public float getPosX() + { + return this.pos_x; + } + public float getPosY() + { + return this.pos_y; + } + public float getWidth() + { + return this.width; + } + public TablePos() + { + //nothing to do --> default + } + + /** + * Constructor. + * + * @param pos_string The pos instruction. + * format : [x:x_algo];[y:y_algo];[w:w_algo][p:p_algo];[f:f_algo] + * x_algo:='auto' ... automatic positioning x + * floatvalue ... absolute x + * y_algo:='auto' ... automatic positioning y + * floatvalue ... absolute y + * w_algo:='auto' ... automatic width + * floatvalue ... absolute width + * p_algo:='auto' ... automatic last page + * 'new' ... new page + * intvalue ... pagenumber + * f_algo floatvalue ... consider footerline (only if y_algo is auto and p_algo is not 'new') + * @throws PdfAsException + */ + public TablePos(String pos_string) throws PdfAsException + { + //parse posstring and throw exception + //[x:x_algo];[y:y_algo];[w:w_algo][p:p_algo];[f:f_algo] + + String[] strs = pos_string.split(";"); + try + { + for (int cmds = 0;cmds Copyright 2006 by Know-Center, Graz, Austria + * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a + * joint initiative of the Federal Chancellery Austria and Graz University of + * Technology. + * + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by + * the European Commission - subsequent versions of the EUPL (the "Licence"); + * You may not use this work except in compliance with the Licence. + * You may obtain a copy of the Licence at: + * http://www.osor.eu/eupl/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the Licence is distributed on an "AS IS" basis, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the Licence for the specific language governing permissions and + * limitations under the Licence. + * + * This product combines work with different licenses. See the "NOTICE" text + * file for details on the various modules and licenses. + * The "NOTICE" text file is part of the distribution. Any derivative works + * that you distribute must include a readable copy of the "NOTICE" text file. + */ +package at.knowcenter.wag.egov.egiz.pdf.operator.path; + +import at.knowcenter.wag.egov.egiz.pdf.PDFPage; +import org.apache.pdfbox.util.operator.OperatorProcessor; + +import java.awt.geom.Point2D; + +/** + * Provides functions for path construction operators. + * + * @see "PDF 1.7 specification, Section 8.5.2 'Path Construction Operators'" + * @author Datentechnik Innovation GmbH + * + */ +public abstract class PathConstructionOperatorProcessor extends OperatorProcessor { + + public PathConstructionOperatorProcessor(PDFPage context) { + setContext(context); + } + + /** + * Transforms the given point from user space coordinates to device space coordinates based on the current + * transition matrix. + * + * @param x + * The x axis value of the user space coordinates. + * @param y + * The y axis value of the user space coordinates. + * @return The transformed point. + */ + public Point2D transform(double x, double y) { + double[] position = { x, y }; + context.getGraphicsState().getCurrentTransformationMatrix().createAffineTransform() + .transform(position, 0, position, 0, 1); + return new Point2D.Double(position[0], position[1]); + } + +} diff --git a/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/operator/path/PathPaintingOperatorProcessor.java b/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/operator/path/PathPaintingOperatorProcessor.java new file mode 100644 index 00000000..a0b73015 --- /dev/null +++ b/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/operator/path/PathPaintingOperatorProcessor.java @@ -0,0 +1,42 @@ +/** + * Copyright 2006 by Know-Center, Graz, Austria + * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a + * joint initiative of the Federal Chancellery Austria and Graz University of + * Technology. + * + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by + * the European Commission - subsequent versions of the EUPL (the "Licence"); + * You may not use this work except in compliance with the Licence. + * You may obtain a copy of the Licence at: + * http://www.osor.eu/eupl/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the Licence is distributed on an "AS IS" basis, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the Licence for the specific language governing permissions and + * limitations under the Licence. + * + * This product combines work with different licenses. See the "NOTICE" text + * file for details on the various modules and licenses. + * The "NOTICE" text file is part of the distribution. Any derivative works + * that you distribute must include a readable copy of the "NOTICE" text file. + */ +package at.knowcenter.wag.egov.egiz.pdf.operator.path; + +import at.knowcenter.wag.egov.egiz.pdf.PDFPage; +import org.apache.pdfbox.util.operator.OperatorProcessor; + +/** + * Provides functions for path painting operators. + * + * @see "PDF 1.7 specification, Section 8.5.2 'Path Construction Operators'" + * @author Datentechnik Innovation GmbH + * + */ +public abstract class PathPaintingOperatorProcessor extends OperatorProcessor { + + public PathPaintingOperatorProcessor(PDFPage context) { + setContext(context); + } + +} diff --git a/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/operator/path/construction/ClosePath.java b/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/operator/path/construction/ClosePath.java new file mode 100644 index 00000000..c663fb5d --- /dev/null +++ b/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/operator/path/construction/ClosePath.java @@ -0,0 +1,67 @@ +/** + * Copyright 2006 by Know-Center, Graz, Austria + * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a + * joint initiative of the Federal Chancellery Austria and Graz University of + * Technology. + * + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by + * the European Commission - subsequent versions of the EUPL (the "Licence"); + * You may not use this work except in compliance with the Licence. + * You may obtain a copy of the Licence at: + * http://www.osor.eu/eupl/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the Licence is distributed on an "AS IS" basis, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the Licence for the specific language governing permissions and + * limitations under the Licence. + * + * This product combines work with different licenses. See the "NOTICE" text + * file for details on the various modules and licenses. + * The "NOTICE" text file is part of the distribution. Any derivative works + * that you distribute must include a readable copy of the "NOTICE" text file. + */ +package at.knowcenter.wag.egov.egiz.pdf.operator.path.construction; + +import at.knowcenter.wag.egov.egiz.pdf.PDFPage; +import at.knowcenter.wag.egov.egiz.pdf.operator.path.PathConstructionOperatorProcessor; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.pdfbox.util.PDFOperator; + +import java.io.IOException; +import java.util.List; + +/** + * Close the current subpath by appending a straight line segment from the current point to the starting point of the + * subpath. If the current subpath is already closed, h shall donothing. This operator terminates the current subpath. + * Appending another segment to the current path shall begin a new subpath, even if the new segment begins at the + * endpoint reached by the h operation. + * + * @see "PDF 1.7 specification, Section 8.5.2 'Path Construction Operators'" + * @author PdfBox, modified by Datentechnik Innovation GmbH + */ +public class ClosePath extends PathConstructionOperatorProcessor { + + private Log log = LogFactory.getLog(getClass()); + + public ClosePath(PDFPage context) { + super(context); + } + + @Override + public void process(PDFOperator operator, List operands) throws IOException { + try { + PDFPage pdfPage = (PDFPage) context; + + pdfPage.getCurrentPath().closePath(); + + if (log.isTraceEnabled()) { + log.trace("Closing current path."); + } + } catch (Exception e) { + log.warn("Error processing operator 'h'.", e); + } + } + +} diff --git a/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/operator/path/construction/CurveTo.java b/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/operator/path/construction/CurveTo.java new file mode 100644 index 00000000..70f5ab20 --- /dev/null +++ b/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/operator/path/construction/CurveTo.java @@ -0,0 +1,84 @@ +/** + * Copyright 2006 by Know-Center, Graz, Austria + * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a + * joint initiative of the Federal Chancellery Austria and Graz University of + * Technology. + * + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by + * the European Commission - subsequent versions of the EUPL (the "Licence"); + * You may not use this work except in compliance with the Licence. + * You may obtain a copy of the Licence at: + * http://www.osor.eu/eupl/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the Licence is distributed on an "AS IS" basis, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the Licence for the specific language governing permissions and + * limitations under the Licence. + * + * This product combines work with different licenses. See the "NOTICE" text + * file for details on the various modules and licenses. + * The "NOTICE" text file is part of the distribution. Any derivative works + * that you distribute must include a readable copy of the "NOTICE" text file. + */ +package at.knowcenter.wag.egov.egiz.pdf.operator.path.construction; + +import at.knowcenter.wag.egov.egiz.pdf.PDFPage; +import at.knowcenter.wag.egov.egiz.pdf.operator.path.PathConstructionOperatorProcessor; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.pdfbox.cos.COSNumber; +import org.apache.pdfbox.util.PDFOperator; + +import java.awt.geom.Point2D; +import java.io.IOException; +import java.util.List; + +/** + * Append a cubic Bezier curve to the current path. The curve shall extend from the current point to the point (x3, y3), + * using (x1, y1) and (x2, y2) as the Bezier control points (see 8.5.2.2, "Cubic Bezier Curves"). The new current point + * shall be (x3, y3). + * + * @see "PDF 1.7 specification, Section 8.5.2 'Path Construction Operators'" + * @author PdfBox, modified by Datentechnik Innovation GmbH + */ +public class CurveTo extends PathConstructionOperatorProcessor { + + private Log log = LogFactory.getLog(getClass()); + + public CurveTo(PDFPage context) { + super(context); + } + + @Override + public void process(PDFOperator operator, List operands) throws IOException { + try { + PDFPage pdfPage = (PDFPage) context; + + COSNumber x1 = (COSNumber) operands.get(0); + COSNumber y1 = (COSNumber) operands.get(1); + COSNumber x2 = (COSNumber) operands.get(2); + COSNumber y2 = (COSNumber) operands.get(3); + COSNumber x3 = (COSNumber) operands.get(4); + COSNumber y3 = (COSNumber) operands.get(5); + + Point2D p1 = transform(x1.doubleValue(), y1.doubleValue()); + Point2D p2 = transform(x2.doubleValue(), y2.doubleValue()); + Point2D p3 = transform(x3.doubleValue(), y3.doubleValue()); + + pdfPage.getCurrentPath().curveTo( + (float) p1.getX(), (float) p1.getY(), + (float) p2.getX(), (float) p2.getY(), + (float) p3.getX(), (float) p3.getY() + ); + + if (log.isTraceEnabled()) { + log.trace("Appending cubic Bezier curve with x1:" + p1.getX() + ",y1:" + p1.getY() + ", x2:" + + p2.getX() + ",y2:" + p2.getY() + ", x3:" + p3.getX() + ",y3:" + p3.getY()); + } + } catch (Exception e) { + log.warn("Error processing operator 'c'.", e); + } + } + +} diff --git a/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/operator/path/construction/CurveToReplicateFinalPoint.java b/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/operator/path/construction/CurveToReplicateFinalPoint.java new file mode 100644 index 00000000..c6125751 --- /dev/null +++ b/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/operator/path/construction/CurveToReplicateFinalPoint.java @@ -0,0 +1,81 @@ +/** + * Copyright 2006 by Know-Center, Graz, Austria + * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a + * joint initiative of the Federal Chancellery Austria and Graz University of + * Technology. + * + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by + * the European Commission - subsequent versions of the EUPL (the "Licence"); + * You may not use this work except in compliance with the Licence. + * You may obtain a copy of the Licence at: + * http://www.osor.eu/eupl/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the Licence is distributed on an "AS IS" basis, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the Licence for the specific language governing permissions and + * limitations under the Licence. + * + * This product combines work with different licenses. See the "NOTICE" text + * file for details on the various modules and licenses. + * The "NOTICE" text file is part of the distribution. Any derivative works + * that you distribute must include a readable copy of the "NOTICE" text file. + */ +package at.knowcenter.wag.egov.egiz.pdf.operator.path.construction; + +import at.knowcenter.wag.egov.egiz.pdf.PDFPage; +import at.knowcenter.wag.egov.egiz.pdf.operator.path.PathConstructionOperatorProcessor; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.pdfbox.cos.COSNumber; +import org.apache.pdfbox.util.PDFOperator; + +import java.awt.geom.Point2D; +import java.io.IOException; +import java.util.List; + +/** + * Append a cubic Bezier curve to the current path. The curve shall extend from the current point to the point (x3, y3), + * using (x1, y1) and (x3, y3) as the Bezier control points (see 8.5.2.2, "Cubic Bezier Curves"). The new current point + * shall be (x3, y3). + * + * @see "PDF 1.7 specification, Section 8.5.2 'Path Construction Operators'" + * @author PdfBox, modified by Datentechnik Innovation GmbH + */ +public class CurveToReplicateFinalPoint extends PathConstructionOperatorProcessor { + + private Log log = LogFactory.getLog(getClass()); + + public CurveToReplicateFinalPoint(PDFPage context) { + super(context); + } + + @Override + public void process(PDFOperator operator, List operands) throws IOException { + try { + PDFPage pdfPage = (PDFPage) context; + + COSNumber x1 = (COSNumber) operands.get(0); + COSNumber y1 = (COSNumber) operands.get(1); + COSNumber x3 = (COSNumber) operands.get(2); + COSNumber y3 = (COSNumber) operands.get(3); + + Point2D p1 = transform(x1.doubleValue(), y1.doubleValue()); + Point2D p3 = transform(x3.doubleValue(), y3.doubleValue()); + + pdfPage.getCurrentPath().curveTo( + (float) p1.getX(), (float) p1.getY(), + (float) p3.getX(), (float) p3.getY(), + (float) p3.getX(), (float) p3.getY() + ); + + if (log.isTraceEnabled()) { + log.trace("Appending cubic Bezier curve with x1:" + p1.getX() + ",y1:" + p1.getY() + ", x3:" + + p3.getX() + ",y3:" + p3.getY()); + } + } catch (Exception e) { + log.warn("Error processing operator 'y'.", e); + } + } + +} diff --git a/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/operator/path/construction/CurveToReplicateInitialPoint.java b/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/operator/path/construction/CurveToReplicateInitialPoint.java new file mode 100644 index 00000000..1479bc7d --- /dev/null +++ b/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/operator/path/construction/CurveToReplicateInitialPoint.java @@ -0,0 +1,83 @@ +/** + * Copyright 2006 by Know-Center, Graz, Austria + * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a + * joint initiative of the Federal Chancellery Austria and Graz University of + * Technology. + * + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by + * the European Commission - subsequent versions of the EUPL (the "Licence"); + * You may not use this work except in compliance with the Licence. + * You may obtain a copy of the Licence at: + * http://www.osor.eu/eupl/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the Licence is distributed on an "AS IS" basis, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the Licence for the specific language governing permissions and + * limitations under the Licence. + * + * This product combines work with different licenses. See the "NOTICE" text + * file for details on the various modules and licenses. + * The "NOTICE" text file is part of the distribution. Any derivative works + * that you distribute must include a readable copy of the "NOTICE" text file. + */ +package at.knowcenter.wag.egov.egiz.pdf.operator.path.construction; + +import at.knowcenter.wag.egov.egiz.pdf.PDFPage; +import at.knowcenter.wag.egov.egiz.pdf.operator.path.PathConstructionOperatorProcessor; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.pdfbox.cos.COSNumber; +import org.apache.pdfbox.util.PDFOperator; + +import java.awt.geom.Point2D; +import java.io.IOException; +import java.util.List; + +/** + * Append a cubic Bezier curve to the current path. The curve shall extend from the current point to the point (x3, y3), + * using the current point and (x2, y2) as the Bezier control points (see 8.5.2.2, "Cubic Bezier Curves"). The new + * current point shall be (x3, y3). + * + * @see "PDF 1.7 specification, Section 8.5.2 'Path Construction Operators'" + * @author PdfBox, modified by Datentechnik Innovation GmbH + */ +public class CurveToReplicateInitialPoint extends PathConstructionOperatorProcessor { + + private Log log = LogFactory.getLog(getClass()); + + public CurveToReplicateInitialPoint(PDFPage context) { + super(context); + } + + @Override + public void process(PDFOperator operator, List operands) throws IOException { + try { + PDFPage pdfPage = (PDFPage) context; + + COSNumber x2 = (COSNumber) operands.get(0); + COSNumber y2 = (COSNumber) operands.get(1); + COSNumber x3 = (COSNumber) operands.get(2); + COSNumber y3 = (COSNumber) operands.get(3); + + Point2D currentPoint = pdfPage.getCurrentPath().getCurrentPoint(); + Point2D p2 = transform(x2.doubleValue(), y2.doubleValue()); + Point2D p3 = transform(x3.doubleValue(), y3.doubleValue()); + + pdfPage.getCurrentPath().curveTo( + (float)currentPoint.getX(), (float)currentPoint.getY(), + (float) p2.getX(), (float) p2.getY(), + (float) p3.getX(), (float) p3.getY() + ); + + if (log.isTraceEnabled()) { + log.trace("Appending cubic Bezier curve with x2:" + p2.getX() + ",y2:" + p2.getY() + ", x3:" + + p3.getX() + ",y3:" + p3.getY() + ", using current point x:" + currentPoint.getX() + ",y:" + + currentPoint.getY()); + } + } catch (Exception e) { + log.warn("Error processing operator 'v'.", e); + } + } + +} diff --git a/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/operator/path/construction/LineTo.java b/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/operator/path/construction/LineTo.java new file mode 100644 index 00000000..94f16b7f --- /dev/null +++ b/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/operator/path/construction/LineTo.java @@ -0,0 +1,70 @@ +/** + * Copyright 2006 by Know-Center, Graz, Austria + * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a + * joint initiative of the Federal Chancellery Austria and Graz University of + * Technology. + * + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by + * the European Commission - subsequent versions of the EUPL (the "Licence"); + * You may not use this work except in compliance with the Licence. + * You may obtain a copy of the Licence at: + * http://www.osor.eu/eupl/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the Licence is distributed on an "AS IS" basis, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the Licence for the specific language governing permissions and + * limitations under the Licence. + * + * This product combines work with different licenses. See the "NOTICE" text + * file for details on the various modules and licenses. + * The "NOTICE" text file is part of the distribution. Any derivative works + * that you distribute must include a readable copy of the "NOTICE" text file. + */ +package at.knowcenter.wag.egov.egiz.pdf.operator.path.construction; + +import at.knowcenter.wag.egov.egiz.pdf.PDFPage; +import at.knowcenter.wag.egov.egiz.pdf.operator.path.PathConstructionOperatorProcessor; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.pdfbox.cos.COSNumber; +import org.apache.pdfbox.util.PDFOperator; + +import java.awt.geom.Point2D; +import java.io.IOException; +import java.util.List; + +/** + * Append a straight line segment from the current point to the point (x, y). The new current point shall be (x, y). + * + * @see "PDF 1.7 specification, Section 8.5.2 'Path Construction Operators'" + * @author PdfBox, modified by Datentechnik Innovation GmbH + */ +public class LineTo extends PathConstructionOperatorProcessor { + + private Log log = LogFactory.getLog(getClass()); + + public LineTo(PDFPage context) { + super(context); + } + + @Override + public void process(PDFOperator operator, List operands) throws IOException { + try { + PDFPage pdfPage = (PDFPage) context; + + COSNumber x = (COSNumber) operands.get(0); + COSNumber y = (COSNumber) operands.get(1); + Point2D p = transform(x.doubleValue(), y.doubleValue()); + + pdfPage.getCurrentPath().lineTo((float) p.getX(), (float) p.getY()); + + if (log.isTraceEnabled()) { + log.trace("Adding line to x:" + p.getX() + ",y:" + p.getY()); + } + } catch (Exception e) { + log.warn("Error processing operator 'l'.", e); + } + } + +} diff --git a/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/operator/path/construction/MoveTo.java b/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/operator/path/construction/MoveTo.java new file mode 100644 index 00000000..97424e93 --- /dev/null +++ b/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/operator/path/construction/MoveTo.java @@ -0,0 +1,72 @@ +/** + * Copyright 2006 by Know-Center, Graz, Austria + * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a + * joint initiative of the Federal Chancellery Austria and Graz University of + * Technology. + * + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by + * the European Commission - subsequent versions of the EUPL (the "Licence"); + * You may not use this work except in compliance with the Licence. + * You may obtain a copy of the Licence at: + * http://www.osor.eu/eupl/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the Licence is distributed on an "AS IS" basis, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the Licence for the specific language governing permissions and + * limitations under the Licence. + * + * This product combines work with different licenses. See the "NOTICE" text + * file for details on the various modules and licenses. + * The "NOTICE" text file is part of the distribution. Any derivative works + * that you distribute must include a readable copy of the "NOTICE" text file. + */ +package at.knowcenter.wag.egov.egiz.pdf.operator.path.construction; + +import at.knowcenter.wag.egov.egiz.pdf.PDFPage; +import at.knowcenter.wag.egov.egiz.pdf.operator.path.PathConstructionOperatorProcessor; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.pdfbox.cos.COSNumber; +import org.apache.pdfbox.util.PDFOperator; + +import java.awt.geom.Point2D; +import java.io.IOException; +import java.util.List; + +/** + * Begin a new subpath by moving the current point to coordinates (x, y), omitting any connecting line segment. If the + * previous path construction operator in the current path was also m, the new m overrides it; no vestige of the + * previous m operation remains in the path. + * + * @see "PDF 1.7 specification, Section 8.5.2 'Path Construction Operators'" + * @author PdfBox, modified by Datentechnik Innovation GmbH + */ +public class MoveTo extends PathConstructionOperatorProcessor { + + private Log log = LogFactory.getLog(getClass()); + + public MoveTo(PDFPage context) { + super(context); + } + + @Override + public void process(PDFOperator operator, List operands) throws IOException { + try { + PDFPage pdfPage = (PDFPage) context; + + COSNumber x = (COSNumber) operands.get(0); + COSNumber y = (COSNumber) operands.get(1); + Point2D p = transform(x.doubleValue(), y.doubleValue()); + + pdfPage.getCurrentPath().moveTo((float) p.getX(), (float) p.getY()); + + if (log.isTraceEnabled()) { + log.trace("Moving current path to x:" + p.getX() + ",y:" + p.getY()); + } + } catch (Exception e) { + log.warn("Error processing operator 'm'.", e); + } + } + +} diff --git a/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/operator/path/painting/CloseAndStrokePath.java b/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/operator/path/painting/CloseAndStrokePath.java new file mode 100644 index 00000000..5a8de9d0 --- /dev/null +++ b/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/operator/path/painting/CloseAndStrokePath.java @@ -0,0 +1,58 @@ +/** + * Copyright 2006 by Know-Center, Graz, Austria + * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a + * joint initiative of the Federal Chancellery Austria and Graz University of + * Technology. + * + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by + * the European Commission - subsequent versions of the EUPL (the "Licence"); + * You may not use this work except in compliance with the Licence. + * You may obtain a copy of the Licence at: + * http://www.osor.eu/eupl/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the Licence is distributed on an "AS IS" basis, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the Licence for the specific language governing permissions and + * limitations under the Licence. + * + * This product combines work with different licenses. See the "NOTICE" text + * file for details on the various modules and licenses. + * The "NOTICE" text file is part of the distribution. Any derivative works + * that you distribute must include a readable copy of the "NOTICE" text file. + */ +package at.knowcenter.wag.egov.egiz.pdf.operator.path.painting; + +import at.knowcenter.wag.egov.egiz.pdf.PDFPage; +import at.knowcenter.wag.egov.egiz.pdf.operator.path.PathPaintingOperatorProcessor; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.pdfbox.util.PDFOperator; + +import java.io.IOException; +import java.util.List; + +/** + * Close and stroke the path. This operator shall have the same effect as the sequence h S. + * + * @see "PDF 1.7 specification, Section 8.5.3 'Path-Painting Operators'" + * @author PdfBox, modified by Datentechnik Innovation GmbH + */ +public class CloseAndStrokePath extends PathPaintingOperatorProcessor { + + private Log log = LogFactory.getLog(getClass()); + + public CloseAndStrokePath(PDFPage context) { + super(context); + } + + @Override + public void process(PDFOperator operator, List operands) throws IOException { + if (log.isTraceEnabled()) { + log.trace("Closing and stroking path."); + } + context.processOperator("h", operands); + context.processOperator("S", operands); + } + +} diff --git a/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/operator/path/painting/CloseFillEvenOddAndStrokePath.java b/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/operator/path/painting/CloseFillEvenOddAndStrokePath.java new file mode 100644 index 00000000..bdaaaa4a --- /dev/null +++ b/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/operator/path/painting/CloseFillEvenOddAndStrokePath.java @@ -0,0 +1,59 @@ +/** + * Copyright 2006 by Know-Center, Graz, Austria + * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a + * joint initiative of the Federal Chancellery Austria and Graz University of + * Technology. + * + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by + * the European Commission - subsequent versions of the EUPL (the "Licence"); + * You may not use this work except in compliance with the Licence. + * You may obtain a copy of the Licence at: + * http://www.osor.eu/eupl/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the Licence is distributed on an "AS IS" basis, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the Licence for the specific language governing permissions and + * limitations under the Licence. + * + * This product combines work with different licenses. See the "NOTICE" text + * file for details on the various modules and licenses. + * The "NOTICE" text file is part of the distribution. Any derivative works + * that you distribute must include a readable copy of the "NOTICE" text file. + */ +package at.knowcenter.wag.egov.egiz.pdf.operator.path.painting; + +import at.knowcenter.wag.egov.egiz.pdf.PDFPage; +import at.knowcenter.wag.egov.egiz.pdf.operator.path.PathPaintingOperatorProcessor; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.pdfbox.util.PDFOperator; + +import java.io.IOException; +import java.util.List; + +/** + * Close, fill, and then stroke the path, using the even-odd rule to determine the region to fill. This operator shall + * have the same effect as the sequence h B*. + * + * @see "PDF 1.7 specification, Section 8.5.3 'Path-Painting Operators'" + * @author PdfBox, modified by Datentechnik Innovation GmbH + */ +public class CloseFillEvenOddAndStrokePath extends PathPaintingOperatorProcessor { + + private Log log = LogFactory.getLog(getClass()); + + public CloseFillEvenOddAndStrokePath(PDFPage context) { + super(context); + } + + @Override + public void process(PDFOperator operator, List operands) throws IOException { + if (log.isTraceEnabled()) { + log.trace("Closing, filling (even odd rule) and stroking path."); + } + context.processOperator("h", operands); + context.processOperator("B*", operands); + } + +} diff --git a/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/operator/path/painting/CloseFillNonZeroAndStrokePath.java b/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/operator/path/painting/CloseFillNonZeroAndStrokePath.java new file mode 100644 index 00000000..4d4f3b68 --- /dev/null +++ b/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/operator/path/painting/CloseFillNonZeroAndStrokePath.java @@ -0,0 +1,59 @@ +/** + * Copyright 2006 by Know-Center, Graz, Austria + * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a + * joint initiative of the Federal Chancellery Austria and Graz University of + * Technology. + * + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by + * the European Commission - subsequent versions of the EUPL (the "Licence"); + * You may not use this work except in compliance with the Licence. + * You may obtain a copy of the Licence at: + * http://www.osor.eu/eupl/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the Licence is distributed on an "AS IS" basis, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the Licence for the specific language governing permissions and + * limitations under the Licence. + * + * This product combines work with different licenses. See the "NOTICE" text + * file for details on the various modules and licenses. + * The "NOTICE" text file is part of the distribution. Any derivative works + * that you distribute must include a readable copy of the "NOTICE" text file. + */ +package at.knowcenter.wag.egov.egiz.pdf.operator.path.painting; + +import at.knowcenter.wag.egov.egiz.pdf.PDFPage; +import at.knowcenter.wag.egov.egiz.pdf.operator.path.PathPaintingOperatorProcessor; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.pdfbox.util.PDFOperator; + +import java.io.IOException; +import java.util.List; + +/** + * Close, fill, and then stroke the path, using the nonzero winding number rule to determine the region to fill. This + * operator shall have the same effect as the sequence h B. + * + * @see "PDF 1.7 specification, Section 8.5.3 'Path-Painting Operators'" + * @author PdfBox, modified by Datentechnik Innovation GmbH + */ +public class CloseFillNonZeroAndStrokePath extends PathPaintingOperatorProcessor { + + private Log log = LogFactory.getLog(getClass()); + + public CloseFillNonZeroAndStrokePath(PDFPage context) { + super(context); + } + + @Override + public void process(PDFOperator operator, List operands) throws IOException { + if (log.isTraceEnabled()) { + log.trace("Closing, filling (non zero rule) and stroking path."); + } + context.processOperator("h", operands); + context.processOperator("B", operands); + } + +} diff --git a/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/operator/path/painting/EndPath.java b/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/operator/path/painting/EndPath.java new file mode 100644 index 00000000..291175aa --- /dev/null +++ b/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/operator/path/painting/EndPath.java @@ -0,0 +1,67 @@ +/** + * Copyright 2006 by Know-Center, Graz, Austria + * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a + * joint initiative of the Federal Chancellery Austria and Graz University of + * Technology. + * + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by + * the European Commission - subsequent versions of the EUPL (the "Licence"); + * You may not use this work except in compliance with the Licence. + * You may obtain a copy of the Licence at: + * http://www.osor.eu/eupl/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the Licence is distributed on an "AS IS" basis, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the Licence for the specific language governing permissions and + * limitations under the Licence. + * + * This product combines work with different licenses. See the "NOTICE" text + * file for details on the various modules and licenses. + * The "NOTICE" text file is part of the distribution. Any derivative works + * that you distribute must include a readable copy of the "NOTICE" text file. + */ +package at.knowcenter.wag.egov.egiz.pdf.operator.path.painting; + +import at.knowcenter.wag.egov.egiz.pdf.PDFPage; +import at.knowcenter.wag.egov.egiz.pdf.operator.path.PathPaintingOperatorProcessor; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.pdfbox.util.PDFOperator; + +import java.io.IOException; +import java.util.List; + +/** + * End the path object without filling or stroking it. This operator shall be a path-painting no-op, used primarily for + * the side effect of changing the current clipping path. + * + * @see "PDF 1.7 specification, Section 8.5.3 'Path-Painting Operators'" + * @author PdfBox, modified by Datentechnik Innovation GmbH + */ +public class EndPath extends PathPaintingOperatorProcessor { + + private Log log = LogFactory.getLog(getClass()); + + public EndPath(PDFPage context) { + super(context); + } + + @Override + public void process(PDFOperator operator, List operands) throws IOException { + try { + PDFPage pdfPage = (PDFPage) context; + + log.debug("Ending path " + pdfPage.getCurrentPath()); + pdfPage.getCurrentPath().reset(); + + if (log.isTraceEnabled()) { + log.trace("End path without filling or stroking."); + } + + } catch (Exception e) { + log.warn("Error processing operator 'n'.", e); + } + } + +} diff --git a/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/operator/path/painting/FillEvenOddAndStrokePath.java b/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/operator/path/painting/FillEvenOddAndStrokePath.java new file mode 100644 index 00000000..b1e836d5 --- /dev/null +++ b/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/operator/path/painting/FillEvenOddAndStrokePath.java @@ -0,0 +1,71 @@ +/** + * Copyright 2006 by Know-Center, Graz, Austria + * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a + * joint initiative of the Federal Chancellery Austria and Graz University of + * Technology. + * + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by + * the European Commission - subsequent versions of the EUPL (the "Licence"); + * You may not use this work except in compliance with the Licence. + * You may obtain a copy of the Licence at: + * http://www.osor.eu/eupl/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the Licence is distributed on an "AS IS" basis, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the Licence for the specific language governing permissions and + * limitations under the Licence. + * + * This product combines work with different licenses. See the "NOTICE" text + * file for details on the various modules and licenses. + * The "NOTICE" text file is part of the distribution. Any derivative works + * that you distribute must include a readable copy of the "NOTICE" text file. + */ +package at.knowcenter.wag.egov.egiz.pdf.operator.path.painting; + +import at.knowcenter.wag.egov.egiz.pdf.PDFPage; +import at.knowcenter.wag.egov.egiz.pdf.operator.path.PathPaintingOperatorProcessor; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.pdfbox.util.PDFOperator; + +import java.awt.geom.GeneralPath; +import java.io.IOException; +import java.util.List; + +/** + * Fill and then stroke the path, using the even-odd rule to determine the region to fill. This operator shall produce + * the same result as B, except that the path is filled as if with f* instead of + * f. + * + * @see "PDF 1.7 specification, Section 8.5.3 'Path-Painting Operators'" + * @author PdfBox, modified by Datentechnik Innovation GmbH + */ +public class FillEvenOddAndStrokePath extends PathPaintingOperatorProcessor { + + private Log log = LogFactory.getLog(getClass()); + + public FillEvenOddAndStrokePath(PDFPage context) { + super(context); + } + + @Override + public void process(PDFOperator operator, List operands) throws IOException { + try { + PDFPage pdfPage = (PDFPage) context; + + if (log.isTraceEnabled()) { + log.trace("Filling (even odd rule) and stroking path."); + } + + GeneralPath currentPath = (GeneralPath) pdfPage.getCurrentPath().clone(); + context.processOperator("f*", operands); + pdfPage.setCurrentPath(currentPath); + context.processOperator("S", operands); + + } catch (Exception e) { + log.warn("Error processing operator 'B*'.", e); + } + } + +} diff --git a/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/operator/path/painting/FillNonZeroAndStrokePath.java b/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/operator/path/painting/FillNonZeroAndStrokePath.java new file mode 100644 index 00000000..72719ec3 --- /dev/null +++ b/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/operator/path/painting/FillNonZeroAndStrokePath.java @@ -0,0 +1,71 @@ +/** + * Copyright 2006 by Know-Center, Graz, Austria + * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a + * joint initiative of the Federal Chancellery Austria and Graz University of + * Technology. + * + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by + * the European Commission - subsequent versions of the EUPL (the "Licence"); + * You may not use this work except in compliance with the Licence. + * You may obtain a copy of the Licence at: + * http://www.osor.eu/eupl/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the Licence is distributed on an "AS IS" basis, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the Licence for the specific language governing permissions and + * limitations under the Licence. + * + * This product combines work with different licenses. See the "NOTICE" text + * file for details on the various modules and licenses. + * The "NOTICE" text file is part of the distribution. Any derivative works + * that you distribute must include a readable copy of the "NOTICE" text file. + */ +package at.knowcenter.wag.egov.egiz.pdf.operator.path.painting; + +import at.knowcenter.wag.egov.egiz.pdf.PDFPage; +import at.knowcenter.wag.egov.egiz.pdf.operator.path.PathPaintingOperatorProcessor; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.pdfbox.util.PDFOperator; + +import java.awt.geom.GeneralPath; +import java.io.IOException; +import java.util.List; + +/** + * Fill and then stroke the path, using the nonzero winding number rule to determine the region to fill. This operator + * shall produce the same result as constructing two identical path objects, painting the first with f and + * the second with S. + * + * @see "PDF 1.7 specification, Section 8.5.3 'Path-Painting Operators'" + * @author PdfBox, modified by Datentechnik Innovation GmbH + */ +public class FillNonZeroAndStrokePath extends PathPaintingOperatorProcessor { + + private Log log = LogFactory.getLog(getClass()); + + public FillNonZeroAndStrokePath(PDFPage context) { + super(context); + } + + @Override + public void process(PDFOperator operator, List operands) throws IOException { + try { + PDFPage pdfPage = (PDFPage) context; + + if (log.isTraceEnabled()) { + log.trace("Filling (non zero rule) and stroking path."); + } + + GeneralPath currentPath = (GeneralPath) pdfPage.getCurrentPath().clone(); + context.processOperator("f", operands); + pdfPage.setCurrentPath(currentPath); + context.processOperator("S", operands); + + } catch (Exception e) { + log.warn("Error processing operator 'B'.", e); + } + } + +} diff --git a/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/operator/path/painting/FillPathEvenOddRule.java b/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/operator/path/painting/FillPathEvenOddRule.java new file mode 100644 index 00000000..28343c5a --- /dev/null +++ b/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/operator/path/painting/FillPathEvenOddRule.java @@ -0,0 +1,70 @@ +/** + * Copyright 2006 by Know-Center, Graz, Austria + * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a + * joint initiative of the Federal Chancellery Austria and Graz University of + * Technology. + * + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by + * the European Commission - subsequent versions of the EUPL (the "Licence"); + * You may not use this work except in compliance with the Licence. + * You may obtain a copy of the Licence at: + * http://www.osor.eu/eupl/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the Licence is distributed on an "AS IS" basis, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the Licence for the specific language governing permissions and + * limitations under the Licence. + * + * This product combines work with different licenses. See the "NOTICE" text + * file for details on the various modules and licenses. + * The "NOTICE" text file is part of the distribution. Any derivative works + * that you distribute must include a readable copy of the "NOTICE" text file. + */ +package at.knowcenter.wag.egov.egiz.pdf.operator.path.painting; + +import at.knowcenter.wag.egov.egiz.pdf.PDFPage; +import at.knowcenter.wag.egov.egiz.pdf.operator.path.PathPaintingOperatorProcessor; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.pdfbox.util.PDFOperator; + +import java.awt.*; +import java.io.IOException; +import java.util.List; + +/** + * Fill the path, using the even-odd rule to determine the region to fill. + * + * @see "PDF 1.7 specification, Section 8.5.3 'Path-Painting Operators'" + * @author PdfBox, modified by Datentechnik Innovation GmbH + */ +public class FillPathEvenOddRule extends PathPaintingOperatorProcessor { + + private Log log = LogFactory.getLog(getClass()); + + public FillPathEvenOddRule(PDFPage context) { + super(context); + } + + @Override + public void process(PDFOperator operator, List operands) throws IOException { + try { + PDFPage pdfPage = (PDFPage) context; + + pdfPage.getCurrentPath().setWindingRule(java.awt.geom.GeneralPath.WIND_EVEN_ODD); + Rectangle bounds = pdfPage.getCurrentPath().getBounds(); + pdfPage.getCurrentPath().reset(); + + if (log.isTraceEnabled()) { + log.trace("Filling path, using even-odd rule."); + } + + pdfPage.registerPathBounds(bounds); + + } catch (Exception e) { + log.warn("Error processing operator 'f*'.", e); + } + } + +} diff --git a/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/operator/path/painting/FillPathNonZeroWindingNumberRule.java b/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/operator/path/painting/FillPathNonZeroWindingNumberRule.java new file mode 100644 index 00000000..28e5c373 --- /dev/null +++ b/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/operator/path/painting/FillPathNonZeroWindingNumberRule.java @@ -0,0 +1,71 @@ +/** + * Copyright 2006 by Know-Center, Graz, Austria + * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a + * joint initiative of the Federal Chancellery Austria and Graz University of + * Technology. + * + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by + * the European Commission - subsequent versions of the EUPL (the "Licence"); + * You may not use this work except in compliance with the Licence. + * You may obtain a copy of the Licence at: + * http://www.osor.eu/eupl/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the Licence is distributed on an "AS IS" basis, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the Licence for the specific language governing permissions and + * limitations under the Licence. + * + * This product combines work with different licenses. See the "NOTICE" text + * file for details on the various modules and licenses. + * The "NOTICE" text file is part of the distribution. Any derivative works + * that you distribute must include a readable copy of the "NOTICE" text file. + */ +package at.knowcenter.wag.egov.egiz.pdf.operator.path.painting; + +import at.knowcenter.wag.egov.egiz.pdf.PDFPage; +import at.knowcenter.wag.egov.egiz.pdf.operator.path.PathPaintingOperatorProcessor; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.pdfbox.util.PDFOperator; + +import java.awt.*; +import java.io.IOException; +import java.util.List; + +/** + * Fill the path, using the nonzero winding number rule to determine the region to fill. Any subpaths that are open + * shall be implicitly closed before being filled. + * + * @see "PDF 1.7 specification, Section 8.5.3 'Path-Painting Operators'" + * @author PdfBox, modified by Datentechnik Innovation GmbH + */ +public class FillPathNonZeroWindingNumberRule extends PathPaintingOperatorProcessor { + + private Log log = LogFactory.getLog(getClass()); + + public FillPathNonZeroWindingNumberRule(PDFPage context) { + super(context); + } + + @Override + public void process(PDFOperator operator, List operands) throws IOException { + try { + PDFPage pdfPage = (PDFPage) context; + + pdfPage.getCurrentPath().setWindingRule(java.awt.geom.GeneralPath.WIND_NON_ZERO); + Rectangle bounds = pdfPage.getCurrentPath().getBounds(); + pdfPage.getCurrentPath().reset(); + + if (log.isTraceEnabled()) { + log.trace("Filling path, using nonzero winding number rule."); + } + + pdfPage.registerPathBounds(bounds); + + } catch (Exception e) { + log.warn("Error processing operator 'f/F'.", e); + } + } + +} diff --git a/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/operator/path/painting/StrokePath.java b/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/operator/path/painting/StrokePath.java new file mode 100644 index 00000000..0530a925 --- /dev/null +++ b/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/operator/path/painting/StrokePath.java @@ -0,0 +1,69 @@ +/** + * Copyright 2006 by Know-Center, Graz, Austria + * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a + * joint initiative of the Federal Chancellery Austria and Graz University of + * Technology. + * + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by + * the European Commission - subsequent versions of the EUPL (the "Licence"); + * You may not use this work except in compliance with the Licence. + * You may obtain a copy of the Licence at: + * http://www.osor.eu/eupl/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the Licence is distributed on an "AS IS" basis, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the Licence for the specific language governing permissions and + * limitations under the Licence. + * + * This product combines work with different licenses. See the "NOTICE" text + * file for details on the various modules and licenses. + * The "NOTICE" text file is part of the distribution. Any derivative works + * that you distribute must include a readable copy of the "NOTICE" text file. + */ +package at.knowcenter.wag.egov.egiz.pdf.operator.path.painting; + +import at.knowcenter.wag.egov.egiz.pdf.PDFPage; +import at.knowcenter.wag.egov.egiz.pdf.operator.path.PathPaintingOperatorProcessor; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.pdfbox.util.PDFOperator; + +import java.awt.*; +import java.io.IOException; +import java.util.List; + +/** + * Strokes the path. + * + * @see "PDF 1.7 specification, Section 8.5.3 'Path-Painting Operators'" + * @author PdfBox, modified by Datentechnik Innovation GmbH + */ +public class StrokePath extends PathPaintingOperatorProcessor { + + private Log log = LogFactory.getLog(getClass()); + + public StrokePath(PDFPage context) { + super(context); + } + + @Override + public void process(PDFOperator operator, List operands) throws IOException { + try { + PDFPage pdfPage = (PDFPage) context; + + Rectangle bounds = pdfPage.getCurrentPath().getBounds(); + pdfPage.getCurrentPath().reset(); + + if (log.isTraceEnabled()) { + log.trace("Stroking path."); + } + + pdfPage.registerPathBounds(bounds); + + } catch (Exception e) { + log.warn("Error processing operator 'S'.", e); + } + } + +} diff --git a/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/sig/SignatureEntry.java b/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/sig/SignatureEntry.java new file mode 100644 index 00000000..957e947f --- /dev/null +++ b/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/sig/SignatureEntry.java @@ -0,0 +1,163 @@ +/** + * Copyright 2006 by Know-Center, Graz, Austria + * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a + * joint initiative of the Federal Chancellery Austria and Graz University of + * Technology. + * + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by + * the European Commission - subsequent versions of the EUPL (the "Licence"); + * You may not use this work except in compliance with the Licence. + * You may obtain a copy of the Licence at: + * http://www.osor.eu/eupl/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the Licence is distributed on an "AS IS" basis, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the Licence for the specific language governing permissions and + * limitations under the Licence. + * + * This product combines work with different licenses. See the "NOTICE" text + * file for details on the various modules and licenses. + * The "NOTICE" text file is part of the distribution. Any derivative works + * that you distribute must include a readable copy of the "NOTICE" text file. + * + * $Id: SignatureEntry.java,v 1.3 2006/08/25 17:09:41 wprinz Exp $ + */ +package at.knowcenter.wag.egov.egiz.pdf.sig; + +import java.io.Serializable; + +/** + * This class is to store a signature entry. The signature entry is 3-tupel. A key that is defined + * or declarated in the settings file, an optional caption or a value.
+ * An additional helper value is a marker for the start index of the key, if the key is found in an + * analysing process extracting captions and values from a raw signature text. + * + * @author wlackner + * @see at.knowcenter.wag.egov.egiz.sig.SignatureObject + */ +public class SignatureEntry implements Serializable { + + /** + * SVUID. + */ + private static final long serialVersionUID = 4640380069301731879L; + + /** + * The signature key. + */ + private String key_ = null; + /** + * The signature caption for the key found or set in the signature text. + */ + private String caption_ = null; + /** + * The signature value for the key found or set in the signature text. + */ + private String value_ = null; + /** + * The starting index position of the key if it is found in the signature text. + */ + private int startIndex_ = -1; + + public boolean isPlaceholder = false; + + /** + * The empty constructor. + */ + public SignatureEntry() { + } + + /** + * A new SignatureEntry init with the key. + * + * @param key + */ + public SignatureEntry(String key) { + key_ = key; + } + + /** + * Returns the caption off the current key. + * + * @return Returns the caption. + */ + public String getCaption() { + return caption_; + } + + /** + * Set the caption of the current key. + * + * @param caption The caption to set. + */ + public void setCaption(String caption) { + caption_ = caption; + } + + /** + * Return the current key. + * + * @return Returns the key. + */ + public String getKey() { + return key_; + } + + /** + * Set the current key. + * + * @param key The key to set. + */ + public void setKey(String key) { + key_ = key; + } + + /** + * Return the start position of the key that caption is found in the signature text. + * + * @return Returns the startIndex. + */ + public int getStartIndex() { + return startIndex_; + } + + /** + * Set the start position of the current key. + * + * @param startIndex The startIndex to set. + */ + public void setStartIndex(int startIndex) { + startIndex_ = startIndex; + } + + /** + * Return the value of the current key. + * + * @return Returns the value. + */ + public String getValue() { + return value_; + } + + /** + * Set the value of the current key. + * + * @param value The value to set. + */ + public void setValue(String value) { + value_ = value; + } + + /** + * The toString method, used for tests or debugging. + */ + public String toString() { + String the_string = ""; + the_string += "\n Key:" + key_; + the_string += "\nCaption:" + caption_; + the_string += "\n Value:" + value_; +// the_string += "\nStart I:" + startIndex_; + return the_string; + } +} \ No newline at end of file diff --git a/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/table/Entry.java b/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/table/Entry.java new file mode 100644 index 00000000..289a7f6f --- /dev/null +++ b/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/table/Entry.java @@ -0,0 +1,235 @@ +/** + * Copyright 2006 by Know-Center, Graz, Austria + * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a + * joint initiative of the Federal Chancellery Austria and Graz University of + * Technology. + * + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by + * the European Commission - subsequent versions of the EUPL (the "Licence"); + * You may not use this work except in compliance with the Licence. + * You may obtain a copy of the Licence at: + * http://www.osor.eu/eupl/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the Licence is distributed on an "AS IS" basis, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the Licence for the specific language governing permissions and + * limitations under the Licence. + * + * This product combines work with different licenses. See the "NOTICE" text + * file for details on the various modules and licenses. + * The "NOTICE" text file is part of the distribution. Any derivative works + * that you distribute must include a readable copy of the "NOTICE" text file. + * + * $Id: Entry.java,v 1.3 2006/08/25 17:08:19 wprinz Exp $ + */ +package at.knowcenter.wag.egov.egiz.table; + +import java.io.Serializable; + +/** + * This class implements a table entry for different types. A table entry can be + * styled and setting there column dimensions. The default value for the column + * dimension is 1. To declare the type of the entry use the public + * TYPE_ definitions. + * + * @author wlackner + */ +public class Entry implements Serializable +{ + + /** + * SVUID. + */ + private static final long serialVersionUID = -7952755200668528348L; + + /** + * Type for a text entry. + */ + public final static int TYPE_CAPTION = 0; + + /** + * Type for a text entry. + */ + public final static int TYPE_VALUE = 1; + + /** + * Type for an image entry. + */ + public final static int TYPE_IMAGE = 2; + + /** + * Type for a table entry. + */ + public final static int TYPE_TABLE = 3; + + /** + * The type info holder, default value is 0! + */ + private int type_ = 0; + + /** + * The entry value. + */ + private Object value_ = null; + + /** + * The key value + */ + private String key_ = null; + + /** + * The entry style information. + */ + private Style style_ = null; + + /** + * The column dimension. + */ + private int colSpan_ = 1; + + /** + * Text wrap indicator, default is false. + */ + private boolean noWrap_ = false; + + /** + * The empty constructor. + */ + public Entry() + { + } + + /** + * A constructor setting the type and the value. + * + * @param type + * the entry type to set + * @param value + * the entry value to set + */ + public Entry(int type, Object value, String key) + { + type_ = type; + value_ = value; + key_ = key; + } + + /** + * @return Returns the entry style. + */ + public Style getStyle() + { + return style_; + } + + /** + * @param style + * The style to set. + */ + public void setStyle(Style style) + { + style_ = style; + } + + /** + * @return Returns the entry type. + */ + public int getType() + { + return type_; + } + + /** + * @param type + * The type to set. + */ + public void setType(int type) + { + type_ = type; + } + + /** + * @return Returns the entry value. + */ + public Object getValue() + { + return value_; + } + + /** + * @param value + * The value to set. + */ + public void setValue(Object value) + { + value_ = value; + } + + /** + * @return Returns the key. + */ + + public String getKey() + { + return key_; + } + + /** + * @param key + * The key to set. + */ + public void setKey(String key) + { + key_ = key; + } + + /** + * @return Returns the colSpan. + */ + public int getColSpan() + { + return colSpan_; + } + + /** + * @param colSpan + * The colSpan to set. + */ + public void setColSpan(int colSpan) + { + colSpan_ = colSpan; + } + + /** + * @return Returns the wrap indicator. + */ + public boolean isNoWrap() + { + return noWrap_; + } + + /** + * @param noWrap + * The wrap indicator to set. + */ + public void setNoWrap(boolean noWrap) + { + noWrap_ = noWrap; + } + + /** + * The toString method, used for tests or debugging. + */ + public String toString() + { + Object obj = getValue(); + String value = null; + if (obj != null) + { + value = obj.toString(); + } + return "Type:" + getType() + " Value:" + value + " ColSpan:" + getColSpan(); + } + +} \ No newline at end of file diff --git a/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/table/Style.java b/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/table/Style.java new file mode 100644 index 00000000..489c9419 --- /dev/null +++ b/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/table/Style.java @@ -0,0 +1,630 @@ +/** + * Copyright 2006 by Know-Center, Graz, Austria + * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a + * joint initiative of the Federal Chancellery Austria and Graz University of + * Technology. + * + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by + * the European Commission - subsequent versions of the EUPL (the "Licence"); + * You may not use this work except in compliance with the Licence. + * You may obtain a copy of the Licence at: + * http://www.osor.eu/eupl/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the Licence is distributed on an "AS IS" basis, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the Licence for the specific language governing permissions and + * limitations under the Licence. + * + * This product combines work with different licenses. See the "NOTICE" text + * file for details on the various modules and licenses. + * The "NOTICE" text file is part of the distribution. Any derivative works + * that you distribute must include a readable copy of the "NOTICE" text file. + * + * $Id: Style.java,v 1.3 2006/08/25 17:08:19 wprinz Exp $ + */ +package at.knowcenter.wag.egov.egiz.table; + +import java.awt.Color; +import java.io.Serializable; + +/** + * This class implements an abstract style definiton used in tables or table entrys. Predefined + * values exists for valign and halign. Color definitions uses the native awt color declarations. + *
+ * The predefined keys are used in the setting definition file to style tables and table entries. + *
+ * It provides an static method to inherit style informations from a given style object. + * {@link Style#doInherit} + * + * + * @author wlackner + * @see java.awt.Color + */ +public class Style implements Serializable { + +// 03.11.2010 changed by exthex - added valuevalign and valuehalign to allow separate layout for value and non-value cells. +// Also the hardcoded default values for halign and valign were removed to allow proper inheritment. +// 04.11.2010 changed by exthex - added imagevalign and imagehalign analog to valuevalign/valuehalign + + /** + * SVUID. + */ + private static final long serialVersionUID = 5855722896712428387L; + + /** + * valign statement key top + */ + public final static String TOP = "top"; + /** + * valign statement key middle + */ + public final static String MIDDLE = "middle"; + /** + * valign statement key bottom + */ + public final static String BOTTOM = "bottom"; + /** + * halign statement key left + */ + public final static String LEFT = "left"; + /** + * halign statement key center + */ + public final static String CENTER = "center"; + /** + * halign statement key right + */ + public final static String RIGHT = "right"; + + /** + * bgcolor key + */ + public final static String BGCOLOR = "bgcolor"; + /** + * halign key + */ + public final static String HALIGN = "halign"; + /** + * valign key + */ + public final static String VALIGN = "valign"; + + /** + * value halign key + */ + public final static String VALUEHALIGN = "valuehalign"; + /** + * value valign key + */ + public final static String VALUEVALIGN = "valuevalign"; + + /** + * image halign key + */ + public final static String IMAGEHALIGN = "imagehalign"; + /** + * image valign key + */ + public final static String IMAGEVALIGN = "imagevalign"; + /** + * padding key, default padding = 1 + */ + public final static String PADDING = "padding"; + /** + * border key, default border = 1;
+ * The border value is one value for all border lines of an entry or table!
+ * No separte definitions for top, right, bottom or left are possible. + */ + public final static String BORDER = "border"; + + /** + * Font key + */ + public final static String FONT = "font"; + + /** + * The value font key. + */ + public final static String VALUEFONT = "valuefont"; + + /** + * The imageScaleToFit key. + */ + public final static String IMAGE_SCALE_TO_FIT = "imagescaletofit"; + + /** + * Font name HELVETICA + */ + public final static String HELVETICA = "HELVETICA"; + /** + * Font name TIMES_ROMAN + */ + public final static String TIMES_ROMAN = "TIMES_ROMAN"; + /** + * Font name COURIER + */ + public final static String COURIER = "COURIER"; + /** + * Font type NORMAL + */ + public final static String NORMAL = "NORMAL"; + /** + * Font type BOLD + */ + public final static String BOLD = "BOLD"; + /** + * Font type ITALIC + */ + public final static String ITALIC = "ITALIC"; + /** + * Font type BOLDITALIC + */ + public final static String BOLDITALIC = "BOLDITALIC"; + /** + * Font type UNDERLINE + */ + public final static String UNDERLINE = "UNDERLINE"; + /** + * Font type STRIKETHRU + */ + public final static String STRIKETHRU = "STRIKETHRU"; + + + /** + * all paddings initialized with the default padding value (1) + */ + private static final float DEFAULT_PADDING = 1; + /** + * all borders initialized with the default border value (1) + */ + private static final float DEFAULT_BORDER = 1; + /** + * The background color definition. + */ + private Color bgColor_ = null; + /** + * The current padding value -> initialized with the default padding value + */ + private float padding_ = DEFAULT_PADDING; + /** + * The current halign value + */ + private String hAlign_ = null; + /** + * The current valign value + */ + private String vAlign_ = null; + /** + * The current valuehalign value + */ + private String valueHAlign_ = null; + /** + * The current valuevalign value + */ + private String valueVAlign_ = null; + /** + * The current imagehalign value + */ + private String imageHAlign_ = null; + /** + * The current imagevalign value + */ + private String imageVAlign_ = null; + /** + * The current border value -> initialized with the default border value + */ + private float border_ = DEFAULT_BORDER; + /** + * The font string of the style definition + */ + private String font_ = null; + /** + * The font string of the value font. + */ + private String valuefont_ = null; + /** + * The scaleToFit dimensions to be applied for image-cells. + */ + private ImageScaleToFit imageScaleToFit_ = null; + + /** + * The empty constructor. + */ + public Style() { + } + + /** + * Set a style attribute. The style attribute must be one of the public definitions + * + * @param id the style attribute to set + * @param value the style value to set for the given attribute + */ + public void setStyle(String id, String value) { + if (BGCOLOR.equals(id)) { + String[] col_strg = value.split(" "); + if (col_strg.length == 3) { + int r = Integer.parseInt(col_strg[0]); + int g = Integer.parseInt(col_strg[1]); + int b = Integer.parseInt(col_strg[2]); + if (r < 256 && g < 256 && b < 256 && r >= 0 && g >= 0 && b >= 0) { + bgColor_ = new Color(r, g, b); + } + } + } + if (HALIGN.equals(id)) { + if (LEFT.equals(value) || CENTER.equals(value) || RIGHT.equals(value)) { + hAlign_ = value; + } + } + if (VALIGN.equals(id)) { + if (TOP.equals(value) || MIDDLE.equals(value) || BOTTOM.equals(value)) { + vAlign_ = value; + } + } + if (VALUEHALIGN.equals(id)) { + if (LEFT.equals(value) || CENTER.equals(value) || RIGHT.equals(value)) { + valueHAlign_ = value; + } + } + if (VALUEVALIGN.equals(id)) { + if (TOP.equals(value) || MIDDLE.equals(value) || BOTTOM.equals(value)) { + valueVAlign_ = value; + } + } + if (IMAGEHALIGN.equals(id)) { + if (LEFT.equals(value) || CENTER.equals(value) || RIGHT.equals(value)) { + imageHAlign_ = value; + } + } + if (IMAGEVALIGN.equals(id)) { + if (TOP.equals(value) || MIDDLE.equals(value) || BOTTOM.equals(value)) { + imageVAlign_ = value; + } + } + if (PADDING.equals(id)) { + padding_ = Float.parseFloat(value); + } + if (BORDER.equals(id)) { + border_ = Float.parseFloat(value); + } + if (FONT.equals(id)) { + font_ = value; + } + if (VALUEFONT.equals(id)) { + valuefont_ = value; + } + if (IMAGE_SCALE_TO_FIT.equals(id)) + { + imageScaleToFit_ = parseImageScaleToFit(value); + } + } + + /** + * @return Returns the bgColor. + */ + public Color getBgColor() { + return bgColor_; + } + + /** + * @param bgColor The bgColor to set. + */ + public void setBgColor(Color bgColor) { + bgColor_ = bgColor; + } + + /** + * @return Returns the hAlign. + */ + public String getHAlign() { + return hAlign_; + } + + /** + * @param align The hAlign to set. + */ + public void setHAlign(String align) { + hAlign_ = align; + } + + /** + * @return Returns the padding. + */ + public float getPadding() { + return padding_; + } + + /** + * @param padding The padding to set. + */ + public void setPadding(float padding) { + padding_ = padding; + } + + /** + * @return Returns the vAlign. + */ + public String getVAlign() { + return vAlign_; + } + + /** + * @param align The vAlign to set. + */ + public void setVAlign(String align) { + vAlign_ = align; + } + + /** + * @return Returns the border. + */ + public float getBorder() { + return border_; + } + + /** + * @param border The border to set. + */ + public void setBorder(float border) { + border_ = border; + } + + + /** + * @return Returns the font. + */ + public String getFont() { + return font_; + } + + /** + * @param font The font to set. + */ + public void setFont(String font) { + font_ = font; + } + + + /** + * Returns the value font. + * @return Returns the value font. + */ + public String getValueFont() + { + return valuefont_; + } + + /** + * Sets the value font. + * @param valuefont The value font to be set. + */ + public void setValueFont(String valuefont) + { + this.valuefont_ = valuefont; + } + + /** + * @param align The valueHAlign to set. + */ + public void setValueHAlign(String align) { + valueHAlign_ = align; + } + + /** + * Returns the value halign + * @return Returns the value halign + */ + public String getValueHAlign() { + return valueHAlign_; + } + + /** + * @param align The valueVAlign to set. + */ + public void setValueVAlign(String align) { + valueVAlign_ = align; + } + + /** + * Returns the value valign + * @return Returns the value valign + */ + public String getValueVAlign() { + return valueVAlign_; + } + + /** + * @param align The imageHAlign to set. + */ + public void setImageHAlign(String align) { + imageHAlign_ = align; + } + + /** + * Returns the image halign + * @return Returns the image halign + */ + public String getImageHAlign() { + return imageHAlign_; + } + + /** + * @param align The imageVAlign to set. + */ + public void setImageVAlign(String align) { + imageVAlign_ = align; + } + + /** + * Returns the image valign + * @return Returns the image valign + */ + public String getImageVAlign() { + return imageVAlign_; + } + + /** + * Returns the scaleToFit dimensions to be applied for image-cells. + * @return Returns the scaleToFit dimensions to be applied for image-cells. + */ + public ImageScaleToFit getImageScaleToFit() + { + return this.imageScaleToFit_; + } + + /** + * Sets the scaleToFit dimensions to be applied for image-cells. + * @param imageScaleToFit_ The scaleToFit dimensions to be applied for image-cells. + */ + public void setImageScaleToFit(ImageScaleToFit imageScaleToFit) + { + this.imageScaleToFit_ = imageScaleToFit; + } + + /** + * The toString method, used for tests or debugging. + */ + public String toString() { + return "bgcolor:" + getBgColor() + " halign:" + getHAlign() + " valign:" + getVAlign() + " padding:" + getPadding() + " border:" + getBorder() + " font:" + getFont() + " valuefont:" + getValueFont() + " imageScaleToFit:" + getImageScaleToFit(); + } + + /** + * This method inherits all style attributes (values) from a given style object. + * + *

+ * A new style object is created that receives the properly inherited styles. + *

+ *

+ * If a value is not defined in the baseStyle object it would be inhert from the inheritStyle object. + *

+ * + * @param baseStyle the style object that serves as a primary style source. + * @param inheritStyle the style object that serves as a secondary style source in case a style attribute is not defined on the primary style source. + * @param isValue + * @return Returns a new Style object being fully equipped with styles. + */ + public static Style doInherit(Style baseStyle, Style inheritStyle) { + Style newStyle = new Style(); + + if (baseStyle != null) + { + newStyle.setBgColor(baseStyle.getBgColor()); + newStyle.setBorder(baseStyle.getBorder()); + newStyle.setFont(baseStyle.getFont()); + newStyle.setHAlign(baseStyle.getHAlign()); + newStyle.setImageHAlign(baseStyle.getImageHAlign()); + newStyle.setImageVAlign(baseStyle.getImageVAlign()); + newStyle.setPadding(baseStyle.getPadding()); + newStyle.setVAlign(baseStyle.getVAlign()); + newStyle.setValueFont(baseStyle.getValueFont()); + newStyle.setValueHAlign(baseStyle.getValueHAlign()); + newStyle.setValueVAlign(baseStyle.getValueVAlign()); + newStyle.setImageScaleToFit(baseStyle.getImageScaleToFit()); + } + + if (inheritStyle != null) + { + if (newStyle.getBgColor() == null) { newStyle.setBgColor(inheritStyle.getBgColor()); } + if (newStyle.getBorder() == DEFAULT_BORDER) { newStyle.setBorder(inheritStyle.getBorder()); } + if (newStyle.getFont() == null) { newStyle.setFont(inheritStyle.getFont()); } + if (newStyle.getHAlign() == null) { newStyle.setHAlign(inheritStyle.getHAlign()); } + if (newStyle.getImageHAlign() == null) { newStyle.setImageHAlign(inheritStyle.getImageHAlign()); } + if (newStyle.getImageVAlign() == null) { newStyle.setImageVAlign(inheritStyle.getImageVAlign()); } + if (newStyle.getPadding() == DEFAULT_PADDING) { newStyle.setPadding(inheritStyle.getPadding()); } + if (newStyle.getVAlign() == null) { newStyle.setVAlign(inheritStyle.getVAlign()); } + if (newStyle.getValueFont() == null) { newStyle.setValueFont(inheritStyle.getValueFont()); } + if (newStyle.getValueHAlign() == null) { newStyle.setValueHAlign(inheritStyle.getValueHAlign()); } + if (newStyle.getValueVAlign() == null) { newStyle.setValueVAlign(inheritStyle.getValueVAlign()); } + if (newStyle.getImageScaleToFit() == null) { newStyle.setImageScaleToFit(inheritStyle.getImageScaleToFit()); } + } + + return newStyle; + } + + protected static ImageScaleToFit parseImageScaleToFit (String imageScaleToFit) + { + if (imageScaleToFit == null || imageScaleToFit.length() == 0 || imageScaleToFit.trim().length() == 0) + { + return null; + } + + String [] dimensions = imageScaleToFit.split(";"); + if (dimensions.length != 2) + { + return null; + } + + float width = Float.parseFloat(dimensions[0]); + float height = Float.parseFloat(dimensions[0]); + + return new ImageScaleToFit(width, height); + } + + /** + * Holds the width and the height an image can be scaled to fit. + * + * @author wprinz + */ + public static class ImageScaleToFit + { + /** + * The width. + */ + protected float width; + + /** + * The height. + */ + protected float height; + + /** + * Constructor. + * + * @param width The width. + * @param height The height. + */ + public ImageScaleToFit(float width, float height) + { + this.width = width; + this.height = height; + } + + /** + * Returns the width. + * @return Returns the width. + */ + public float getWidth() + { + return this.width; + } + + /** + * Sets the width. + * @param width The width to set. + */ + public void setWidth(float width) + { + this.width = width; + } + + /** + * Returns the height. + * @return Returns the height. + */ + public float getHeight() + { + return this.height; + } + + /** + * Sets the height. + * @param height The height to set. + */ + public void setHeight(float height) + { + this.height = height; + } + + } +} \ No newline at end of file diff --git a/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/table/Table.java b/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/table/Table.java new file mode 100644 index 00000000..c5a0c58f --- /dev/null +++ b/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/table/Table.java @@ -0,0 +1,223 @@ +/** + * Copyright 2006 by Know-Center, Graz, Austria + * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a + * joint initiative of the Federal Chancellery Austria and Graz University of + * Technology. + * + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by + * the European Commission - subsequent versions of the EUPL (the "Licence"); + * You may not use this work except in compliance with the Licence. + * You may obtain a copy of the Licence at: + * http://www.osor.eu/eupl/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the Licence is distributed on an "AS IS" basis, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the Licence for the specific language governing permissions and + * limitations under the Licence. + * + * This product combines work with different licenses. See the "NOTICE" text + * file for details on the various modules and licenses. + * The "NOTICE" text file is part of the distribution. Any derivative works + * that you distribute must include a readable copy of the "NOTICE" text file. + * + * $Id: Table.java,v 1.2 2006/08/25 17:08:19 wprinz Exp $ + */ +package at.knowcenter.wag.egov.egiz.table; + +import java.io.Serializable; +import java.util.Map; +import java.util.HashMap; +import java.util.ArrayList; + +/** + * This class implements an abstract table definition. The table contains table + * rows and the table rows contains the table entries. A table can be styled and + * a relative column width can be set. + * + * @author wlackner + * @see Style + * @see at.knowcenter.wag.egov.egiz.table.Entry + */ +public class Table implements Serializable +{ + + /** + * SVUID. + */ + private static final long serialVersionUID = 8488947943674086618L; + + /** + * The table column settings. + */ + private float[] colsRelativeWith_ = null; + + /** + * The row definitions. + */ + private Map rows_ = new HashMap(); + + /** + * The table width. + */ + private float width_ = 100; + + /** + * The table style. + */ + private Style style_ = null; + + /** + * Number of columns that are defined for the current table. + */ + private int maxCols_ = 0; + + /** + * A table name. + */ + private String name_ = null; + + /** + * The table constructor init by a table name. + * + * @param name + * the name for the table. + */ + public Table(String name) + { + name_ = name; + } + + /** + * The width of the columns are relative to each other. This means the values + * are summarized and divided into portions of columns used.
+ * Example: [1,4] means the second column is four times wider + * than the first column. + * + * @return Returns the relative width of the columns + */ + public float[] getColsRelativeWith() + { + return colsRelativeWith_; + } + + /** + * The width of the columns are relative to each other. This means the values + * are summarized and divided into portions of columns used.
+ * Example: [10,90] means the first colum consumes 10% and the + * second column consumes 90% of the table width.
+ * The relative width of the columns to set. + */ + public void setColsRelativeWith(float[] cols) + { + colsRelativeWith_ = cols; + } + + /** + * @return Returns the style. + */ + public Style getStyle() + { + return style_; + } + + /** + * @param style + * The style to set. + */ + public void setStyle(Style style) + { + style_ = style; + } + + /** + * @return Returns the width. + */ + public float getWidth() + { + return width_; + } + + /** + * @param width + * The width to set. + */ + public void setWidth(float width) + { + width_ = width; + } + + /** + * @return Returns the maxCols. + */ + public int getMaxCols() + { + return maxCols_; + } + + /** + * @return Returns the name. + */ + public String getName() + { + return name_; + } + + /** + * This method returns a sorted row list beginning with the row number 1. The + * entrys in a row also stored in a {@link java.util.ArrayList}. + * + * @return Returns the sorted (by row number) table rows. + */ + public ArrayList getRows() + { + ArrayList rows = new ArrayList(); + for (int row_idx = 1; row_idx <= rows_.size(); row_idx++) + { + ArrayList row = (ArrayList) rows_.get("" + row_idx); + rows.add(row); + } + return rows; + } + + /** + * Add a comlete table row to the current table. Be carefull usding the + * correct row number because no check is done if a row with the given row + * number does exist! In that case the stored row would be replaced! + * + * @param rowNumber + * the row number to store the row entries + * @param row + * the entry list to store + */ + public void addRow(String rowNumber, ArrayList row) + { + rows_.put(rowNumber, row); + if (row.size() > maxCols_) + { + maxCols_ = row.size(); + } + } + + /** + * The toString method, used for tests or debugging. + */ + public String toString() + { + String the_string = "\n#### TABLE " + name_ + " BEGIN #####"; + the_string += " Width:" + width_ + " max cols:" + maxCols_ + " cols:" + colsRelativeWith_; + the_string += "\nStyle:" + style_; + ArrayList rows = getRows(); + for (int row_idx = 0; row_idx < rows.size(); row_idx++) + { + ArrayList row = (ArrayList) rows.get(row_idx); + String row_prefix = "\n ++ ROW " + row_idx + " ++ "; + for (int entry_idx = 0; entry_idx < row.size(); entry_idx++) + { + the_string += row_prefix + ((Entry) row.get(entry_idx)).toString(); + } + } + the_string += "\n#### TABLE " + name_ + " END #####"; + return the_string; + } +} \ No newline at end of file -- cgit v1.2.3