aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorpdanner <pdanner@7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c>2010-11-03 16:39:22 +0000
committerpdanner <pdanner@7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c>2010-11-03 16:39:22 +0000
commitab57bf058107ad9ea251dfb8e3fc576834ea9f68 (patch)
tree3a3567bc01683f5aec7be0c672ff27f7a87e0a50 /src
parentdc8b7fd3ecfdcefbaa8625c94ed48a22ce095940 (diff)
downloadpdf-as-3-ab57bf058107ad9ea251dfb8e3fc576834ea9f68.tar.gz
pdf-as-3-ab57bf058107ad9ea251dfb8e3fc576834ea9f68.tar.bz2
pdf-as-3-ab57bf058107ad9ea251dfb8e3fc576834ea9f68.zip
Bug Nr. #534 fixed. Alignment params are now properly inherited to all table cells.
Also added the Style params valuevalign and valuehalign to allow separate alignment for value cells. If those are not set value cells are aligned as any other cell. git-svn-id: https://joinup.ec.europa.eu/svn/pdf-as/trunk@600 7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c
Diffstat (limited to 'src')
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/pdf/PDFSignatureObjectIText.java40
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/sig/SignatureObject.java4
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/sig/SignatureTypes.java64
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/table/Style.java74
4 files changed, 131 insertions, 51 deletions
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/pdf/PDFSignatureObjectIText.java b/src/main/java/at/knowcenter/wag/egov/egiz/pdf/PDFSignatureObjectIText.java
index 39b5daf..85abd73 100644
--- a/src/main/java/at/knowcenter/wag/egov/egiz/pdf/PDFSignatureObjectIText.java
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/pdf/PDFSignatureObjectIText.java
@@ -63,6 +63,10 @@ import com.lowagie.text.pdf.SubsetLocal;
public class PDFSignatureObjectIText implements PDFSignatureObject
{
+// 03.11.2010 changed by exthex to allow setting separate hAlign and vAlign for value and non-value cells.
+// If no value for valuevalign or valuehalign is set the values from valign and halign are taken.
+// Also fixed a minor bug which prevented proper style inheritment (Bug Nr. #534).
+
private static final String SIG_PDFA1_B_VALID = "SIG_PDFA1B_VALID";
/**
@@ -178,10 +182,12 @@ public class PDFSignatureObjectIText implements PDFSignatureObject
* the pdf cell to be styled
* @param cellStyle
* the abstract style definition
+ * @param isValue
+ * true if the pdfCell is a value cell - the appropriate style will be set
* @see com.lowagie.text.pdf.PdfPCell
* @see at.knowcenter.wag.egov.egiz.table.Style
*/
- private void setCellStyle(PdfPCell pdfCell, Style cellStyle)
+ private void setCellStyle(PdfPCell pdfCell, Style cellStyle, boolean isValue)
{
if (cellStyle != null)
{
@@ -198,16 +204,21 @@ public class PDFSignatureObjectIText implements PDFSignatureObject
{
pdfCell.setBorder(0);
}
- if (cellStyle.getVAlign() != null)
- {
- int align = ((Integer) alignMap_.get(cellStyle.getVAlign())).intValue();
+ int align = -1;
+ if (isValue && cellStyle.getValueVAlign() != null)
+ align = ((Integer) alignMap_.get(cellStyle.getValueVAlign())).intValue();
+ else if (cellStyle.getVAlign() != null)
+ align = ((Integer) alignMap_.get(cellStyle.getVAlign())).intValue();
+ if (align != -1)
pdfCell.setVerticalAlignment(align);
- }
- if (cellStyle.getHAlign() != null)
- {
- int align = ((Integer) alignMap_.get(cellStyle.getHAlign())).intValue();
+
+ align = -1;
+ if (isValue && cellStyle.getValueHAlign() != null)
+ align = ((Integer) alignMap_.get(cellStyle.getValueHAlign())).intValue();
+ else if (cellStyle.getHAlign() != null)
+ align = ((Integer) alignMap_.get(cellStyle.getHAlign())).intValue();
+ if (align != -1)
pdfCell.setHorizontalAlignment(align);
- }
}
}
@@ -331,9 +342,11 @@ public class PDFSignatureObjectIText implements PDFSignatureObject
PdfPCell pdf_cell = null;
Style cell_style = abstractCell.getStyle();
+ boolean isValue = true;
switch (abstractCell.getType())
{
case Entry.TYPE_CAPTION:
+ isValue = false;
case Entry.TYPE_VALUE:
String text = (String) abstractCell.getValue();
if (text == null)
@@ -362,7 +375,7 @@ public class PDFSignatureObjectIText implements PDFSignatureObject
}
Phrase text_phrase = new Phrase(text, cell_font);
pdf_cell = new PdfPCell(text_phrase);
- setCellStyle(pdf_cell, cell_style);
+ setCellStyle(pdf_cell, cell_style, isValue);
break;
case Entry.TYPE_IMAGE:
try
@@ -395,7 +408,7 @@ public class PDFSignatureObjectIText implements PDFSignatureObject
fit = false;
}
pdf_cell = new PdfPCell(image, fit);
- setCellStyle(pdf_cell, cell_style);
+ setCellStyle(pdf_cell, cell_style, false);
}
catch (BadElementException e)
{
@@ -477,7 +490,7 @@ public class PDFSignatureObjectIText implements PDFSignatureObject
pdf_table = new PdfPTable(cols);
pdf_table.setWidthPercentage(abstractTable.getWidth());
Style table_style = abstractTable.getStyle();
- setCellStyle(pdf_table.getDefaultCell(), table_style);
+ setCellStyle(pdf_table.getDefaultCell(), table_style, false);
ArrayList rows = abstractTable.getRows();
for (int row_idx = 0; row_idx < rows.size(); row_idx++)
@@ -488,7 +501,8 @@ public class PDFSignatureObjectIText implements PDFSignatureObject
for (int entry_idx = 0; entry_idx < row.size(); entry_idx++)
{
Entry cell = (Entry) row.get(entry_idx);
- Style inherit_style = Style.doInherit(cell.getStyle(), table_style);
+ // 03.11.2010 changed by exthex - swapped the two params, was probably a bug
+ Style inherit_style = Style.doInherit(table_style, cell.getStyle());
cell.setStyle(inherit_style);
// logger_.debug(cell.toString());
PdfPCell pdf_cell = renderCell(cell);
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/sig/SignatureObject.java b/src/main/java/at/knowcenter/wag/egov/egiz/sig/SignatureObject.java
index 0b39a5b..859e54e 100644
--- a/src/main/java/at/knowcenter/wag/egov/egiz/sig/SignatureObject.java
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/sig/SignatureObject.java
@@ -72,6 +72,8 @@ import at.knowcenter.wag.egov.egiz.tools.Normalizer;
public class SignatureObject implements Serializable
{
+// 03.11.2010 changed by exthex - added default for defaultValueStyle_.hAlign since we had to remove the hardcoded default in Style
+
/**
* SVUID.
*/
@@ -271,11 +273,11 @@ public class SignatureObject implements Serializable
defaultImageStyle_.setPadding(3);
defaultImageStyle_.setHAlign(Style.CENTER);
defaultImageStyle_.setVAlign(Style.MIDDLE);
- defaultImageStyle_.setBgColor(null);
defaultCaptionStyle_.setHAlign(Style.CENTER);
defaultCaptionStyle_.setVAlign(Style.MIDDLE);
+ defaultValueStyle_.setHAlign(Style.LEFT);
defaultValueStyle_.setVAlign(Style.MIDDLE);
}
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/sig/SignatureTypes.java b/src/main/java/at/knowcenter/wag/egov/egiz/sig/SignatureTypes.java
index fcd704d..860120e 100644
--- a/src/main/java/at/knowcenter/wag/egov/egiz/sig/SignatureTypes.java
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/sig/SignatureTypes.java
@@ -17,7 +17,6 @@
*/
package at.knowcenter.wag.egov.egiz.sig;
-import java.awt.Color;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -31,12 +30,13 @@ import at.knowcenter.wag.egov.egiz.cfg.SettingsReader;
import at.knowcenter.wag.egov.egiz.exceptions.SettingsException;
import at.knowcenter.wag.egov.egiz.exceptions.SignatureException;
import at.knowcenter.wag.egov.egiz.exceptions.SignatureTypesException;
-import at.knowcenter.wag.egov.egiz.table.Style;
import at.knowcenter.wag.exactparser.ByteArrayUtils;
public class SignatureTypes
{
+// 03.11.2010 changed by exthex - commented unneded setDefaultStyles method to reduce confusion
+
/**
* The settings key prefix for signature definitions. <code>"sig_obj."</code>
*/
@@ -108,20 +108,20 @@ public class SignatureTypes
*/
public final static String STYLE = "Style";
- /**
- * The default style definition for images.
- */
- private Style defaultImageStyle_ = new Style();
-
- /**
- * The default style definition for captions.
- */
- private Style defaultCaptionStyle_ = new Style();
-
- /**
- * The default style definition for values.
- */
- private Style defaultValueStyle_ = new Style();
+// /**
+// * The default style definition for images.
+// */
+// private Style defaultImageStyle_ = new Style();
+//
+// /**
+// * The default style definition for captions.
+// */
+// private Style defaultCaptionStyle_ = new Style();
+//
+// /**
+// * The default style definition for values.
+// */
+// private Style defaultValueStyle_ = new Style();
/**
* Standard key get/set the singature name
@@ -304,7 +304,7 @@ public class SignatureTypes
{
throw new SignatureTypesException(e);
}
- setDefaultStyles();
+// setDefaultStyles();
loadSignatureTypes();
}
@@ -352,21 +352,21 @@ public class SignatureTypes
// pTree_ = settings_.getPTree();
}
- /**
- * This method set the default styles for images, captions and values.
- */
- private void setDefaultStyles()
- {
- defaultImageStyle_.setPadding(3);
- defaultImageStyle_.setHAlign(Style.CENTER);
- defaultImageStyle_.setVAlign(Style.MIDDLE);
- defaultImageStyle_.setBgColor(new Color(255, 255, 255));
-
- defaultCaptionStyle_.setHAlign(Style.CENTER);
- defaultCaptionStyle_.setVAlign(Style.MIDDLE);
-
- defaultValueStyle_.setVAlign(Style.MIDDLE);
- }
+// /**
+// * This method set the default styles for images, captions and values.
+// */
+// private void setDefaultStyles()
+// {
+// defaultImageStyle_.setPadding(3);
+// defaultImageStyle_.setHAlign(Style.CENTER);
+// defaultImageStyle_.setVAlign(Style.MIDDLE);
+// defaultImageStyle_.setBgColor(new Color(255, 255, 255));
+//
+// defaultCaptionStyle_.setHAlign(Style.CENTER);
+// defaultCaptionStyle_.setVAlign(Style.MIDDLE);
+//
+// defaultValueStyle_.setVAlign(Style.MIDDLE);
+// }
/**
* This method load the configured signature types. It stores the definition
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/table/Style.java b/src/main/java/at/knowcenter/wag/egov/egiz/table/Style.java
index f5881e5..5b3db7d 100644
--- a/src/main/java/at/knowcenter/wag/egov/egiz/table/Style.java
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/table/Style.java
@@ -36,6 +36,10 @@ import java.io.Serializable;
* @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.
+
/**
* SVUID.
*/
@@ -78,6 +82,15 @@ public class Style implements Serializable {
* valign key
*/
public final static String VALIGN = "valign";
+
+ /**
+ * halign key
+ */
+ public final static String VALUEHALIGN = "valuehalign";
+ /**
+ * valign key
+ */
+ public final static String VALUEVALIGN = "valuevalign";
/**
* padding key, default padding = 1
*/
@@ -159,13 +172,21 @@ public class Style implements Serializable {
*/
private float padding_ = DEFAULT_PADDING;
/**
- * The current halign value -> initialized with left
+ * The current halign value
*/
- private String hAlign_ = LEFT;
+ private String hAlign_ = null;
/**
- * The current valign value -> initialized with top
+ * The current valign value
*/
- private String vAlign_ = TOP;
+ private String vAlign_ = null;
+ /**
+ * The current valuehalign value
+ */
+ private String valueHAlign_ = null;
+ /**
+ * The current valuevalign value
+ */
+ private String valueVAlign_ = null;
/**
* The current border value -> initialized with the default border value
*/
@@ -217,6 +238,16 @@ public class Style implements Serializable {
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 (PADDING.equals(id)) {
padding_ = Float.parseFloat(value);
}
@@ -339,7 +370,35 @@ public class Style implements Serializable {
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_;
+ }
/**
* Returns the scaleToFit dimensions to be applied for image-cells.
@@ -378,6 +437,7 @@ public class Style implements Serializable {
*
* @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) {
@@ -392,6 +452,8 @@ public class Style implements Serializable {
newStyle.setPadding(baseStyle.getPadding());
newStyle.setVAlign(baseStyle.getVAlign());
newStyle.setValueFont(baseStyle.getValueFont());
+ newStyle.setValueHAlign(baseStyle.getValueHAlign());
+ newStyle.setValueVAlign(baseStyle.getValueVAlign());
newStyle.setImageScaleToFit(baseStyle.getImageScaleToFit());
}
@@ -404,6 +466,8 @@ public class Style implements Serializable {
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()); }
}