From 5af1d89ff4f909e73db2aa3d3ef8a013785c9f2f Mon Sep 17 00:00:00 2001 From: Thomas <> Date: Fri, 8 Mar 2024 16:20:12 +0100 Subject: feat(core): add new page position parameter 'last' --- .../at/knowcenter/wag/egov/egiz/pdf/TablePos.java | 361 ++++++++++----------- 1 file changed, 166 insertions(+), 195 deletions(-) (limited to 'pdf-as-lib/src/main/java/at/knowcenter/wag') 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 index 86e270d0..33b6cf85 100644 --- 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 @@ -49,8 +49,12 @@ package at.knowcenter.wag.egov.egiz.pdf; import java.io.Serializable; +import java.text.MessageFormat; import at.gv.egiz.pdfas.common.exceptions.PdfAsException; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; /** * Class that holds the exact position where the table should be written to the @@ -59,9 +63,14 @@ import at.gv.egiz.pdfas.common.exceptions.PdfAsException; * @author wprinz * @author mruhmer */ +@NoArgsConstructor public class TablePos implements Serializable { + public enum PAGE_MODE {AUTO, LAST, EXACT, NEW}; + public enum POS_MODE {AUTO, EXACT}; + + /** * SVUID. */ @@ -71,198 +80,215 @@ public class TablePos implements Serializable * The page on which the block should be displayed. * */ + @Getter private int page = 0; /** * The x position. */ - private float pos_x = 0.0f; + @Getter + private float posX = 0.0f; /** * The y position. */ - private float pos_y = 0.0f; + @Getter + private float posY = 0.0f; /** * The width of the block. */ - public float width = 0.0f; + @Getter + @Setter + private float width = 0.0f; + /** * The top y position of the footer line. */ - public float footer_line = 0.0f; + private float footerLine = 0.0f; /** * The rotation of the signature block */ - public float rotation = 0.0f; - - /** - * The y position. - */ - public String myposstring = ""; + @Getter + private float rotation = 0.0f; - private boolean newpage = false; - private boolean autoX = true; - private boolean autoY = true; - private boolean autoW = true; - private boolean autoP = true; + + @Getter + private PAGE_MODE pageMode = PAGE_MODE.AUTO; + + @Getter + private POS_MODE xMode = POS_MODE.AUTO; + + @Getter + private POS_MODE yMode = POS_MODE.AUTO; + + @Getter + private POS_MODE wMode = POS_MODE.AUTO; + + public boolean isXauto() { + return xMode.equals(POS_MODE.AUTO); - public boolean isXauto() - { - return this.autoX; } - public boolean isYauto() - { - return this.autoY; + + public boolean isYauto() { + return yMode.equals(POS_MODE.AUTO); + } - public boolean isWauto() - { - return this.autoW; + + public boolean isWauto() { + return wMode.equals(POS_MODE.AUTO); } - public boolean isPauto() - { - return this.autoP; + + public float getFooterLine() { + //ignore if newpage and y is not auto + return yMode.equals(POS_MODE.EXACT) || pageMode.equals(PAGE_MODE.NEW) ? 0.0f : footerLine; + + } + + /** + * Constructor. + * + * @param pos_string The pos instruction. + * format : [x:x_algo];[y:y_algo];[w:w_algo][p:p_algo];[f:f_algo];[r:r_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 + * 'last' ... force last page + * intvalue ... pagenumber + * f_algo floatvalue ... consider footerline (only if y_algo is auto and p_algo is not 'new') + * r_algo floatvalue ... rotate the table arround the lower left corner anti clockwise in degree + * @throws PdfAsException + */ + public TablePos(String pos_string) throws PdfAsException { + parsePosString(pos_string); + } - public boolean isNewPage() - { - return this.newpage; + + /** + * Constructor + * @param pos_string The pos instruction. + * format : [x:x_algo];[y:y_algo];[w:w_algo][p:p_algo];[f:f_algo];[r:r_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 position + * 'new' ... new page + * 'last' ... force last page + * intvalue ... pagenumber + * f_algo floatvalue ... consider footerline (only if y_algo is auto and p_algo is not 'new') + * r_algo floatvalue ... rotate the table arround the lower left corner anti clockwise in degree + * @param basePosition The base Table Position these values are the base values + * @throws PdfAsException + */ + public TablePos(String pos_string, TablePos basePosition) throws PdfAsException { + if(basePosition != null) { + readFromPos(basePosition); + + } + parsePosString(pos_string); + } - public int getPage() - { - return this.page; + + public String toString() { + String thatsme = "pos_x:"+this.posX+" pos_y:"+this.posY+" page:"+this.page+" width:"+this.width+" footer:"+this.footerLine+" rotation:"+this.rotation+"\n "+" autoX:"+xMode+" autoY:"+yMode+" autoW:"+wMode+" pageMode:"+pageMode; + return thatsme; + + } + + + private float parseAndCheck(String commandval, int minValue, String errorMsg) + throws PdfAsException, NumberFormatException { + float value= Float.parseFloat(commandval); + if (value < minValue) { + throw new PdfAsException(MessageFormat.format(errorMsg, value)); + + } + return value; + } - 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 - } private void parsePosString(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