aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/TableFactory.java10
-rw-r--r--pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFBoxTable.java4
-rw-r--r--pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/TableDrawUtils.java28
-rw-r--r--pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/table/Table.java78
4 files changed, 102 insertions, 18 deletions
diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/TableFactory.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/TableFactory.java
index 838d9d5a..939c2b3a 100644
--- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/TableFactory.java
+++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/TableFactory.java
@@ -34,6 +34,7 @@ import java.util.Vector;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import at.gv.egiz.pdfas.common.exceptions.PdfAsSettingsException;
import at.gv.egiz.pdfas.common.settings.IProfileConstants;
import at.gv.egiz.pdfas.common.settings.ISettings;
import at.gv.egiz.pdfas.common.settings.SignatureProfileSettings;
@@ -97,12 +98,13 @@ public class TableFactory implements IProfileConstants {
* @param tableID
* is the name of the table definition in the settings file
* @return a new abstract signature table
+ * @throws PdfAsSettingsException
* @see at.knowcenter.wag.egov.egiz.table.Style
* @see at.knowcenter.wag.egov.egiz.table.Table
* @see at.knowcenter.wag.egov.egiz.table.Entry
*/
public static Table createSigTable(SignatureProfileSettings profile, String tableID, OperationStatus operationStatus,
- ICertificateProvider certProvider)
+ ICertificateProvider certProvider) throws PdfAsSettingsException
{
String table_key_prefix = SIG_OBJ + profile.getProfileID() + "." + TABLE;
String table_key = table_key_prefix + tableID;
@@ -198,7 +200,7 @@ public class TableFactory implements IProfileConstants {
resolver.resolve(key, value, profile), key);
if (entry != null)
{
- //entry.setColSpan(2);
+ entry.setColSpan(2);
entry.setStyle(defaultValueStyle_);
row.add(entry);
}
@@ -212,7 +214,7 @@ public class TableFactory implements IProfileConstants {
resolver.resolve(key, value, profile), key);
if (entry != null)
{
- //entry.setColSpan(2);
+ entry.setColSpan(2);
entry.setStyle(defaultCaptionStyle_);
row.add(entry);
}
@@ -260,7 +262,7 @@ public class TableFactory implements IProfileConstants {
sig_table.addRow(table_def, row);
}
}
-
+ sig_table.normalize();
return sig_table;
}
diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFBoxTable.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFBoxTable.java
index 38a883fe..e84bd498 100644
--- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFBoxTable.java
+++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFBoxTable.java
@@ -197,9 +197,9 @@ public class PDFBoxTable {
for (int j = 0; j < row.size(); j++) {
Entry cell = (Entry) row.get(j);
- float colWidth = colWidths[j];
+ float colWidth = 0;//colWidths[j];
- int colsleft = cell.getColSpan() - 1;
+ int colsleft = cell.getColSpan();
if (j + colsleft > colWidths.length) {
throw new IOException(
diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/TableDrawUtils.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/TableDrawUtils.java
index bc21c266..88eb798a 100644
--- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/TableDrawUtils.java
+++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/TableDrawUtils.java
@@ -93,23 +93,36 @@ public class TableDrawUtils {
Style inherit_style = Style.doInherit(abstractTable.style, cell.getStyle());
cell.setStyle(inherit_style);
+ float colWidth = 0;//colWidths[j];
+
+ int colsleft = cell.getColSpan();
+
+ if (j + colsleft > colsSizes.length) {
+ throw new PdfAsException(
+ "Configuration is wrong. Cannot determine column width!");
+ }
+
+ for (int k = 0; k < colsleft; k++) {
+ colWidth = colWidth + colsSizes[j + k];
+ }
+
drawDebugPadding(contentStream, contentx, contenty, padding,
- colsSizes[j], abstractTable.getRowHeights()[i], settings);
+ colWidth, abstractTable.getRowHeights()[i], settings);
switch (cell.getType()) {
case Entry.TYPE_CAPTION:
drawCaption(page, contentStream, contentx, contenty,
- colsSizes[j], abstractTable.getRowHeights()[i],
+ colWidth, abstractTable.getRowHeights()[i],
padding, abstractTable, doc, cell, formResources, settings);
break;
case Entry.TYPE_VALUE:
drawValue(page, contentStream, contentx, contenty,
- colsSizes[j], abstractTable.getRowHeights()[i],
+ colWidth, abstractTable.getRowHeights()[i],
padding, abstractTable, doc, cell, formResources, settings);
break;
case Entry.TYPE_IMAGE:
drawImage(page, contentStream, contentx, contenty,
- colsSizes[j], abstractTable.getRowHeights()[i],
+ colWidth, abstractTable.getRowHeights()[i],
padding, abstractTable, doc, cell, formResources,
images, settings);
break;
@@ -122,7 +135,7 @@ public class TableDrawUtils {
tbl_value.table.setStyle(inherit_styletab);
drawTable(page, contentStream, contentx, contenty
- - abstractTable.getRowHeights()[i], colsSizes[j],
+ - abstractTable.getRowHeights()[i], colWidth,
abstractTable.getRowHeights()[i], tbl_value, doc,
true, formResources, images, settings);
break;
@@ -132,7 +145,10 @@ public class TableDrawUtils {
}
// Move content pointer
- contentx += colsSizes[j];
+ contentx += colWidth;
+
+ int span = cell.getColSpan() - 1;
+ j += span;
}
// Move content pointer
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
index 6db7ff3a..12d0e2ee 100644
--- 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
@@ -49,9 +49,12 @@
package at.knowcenter.wag.egov.egiz.table;
import java.io.Serializable;
-import java.util.Map;
-import java.util.HashMap;
import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import at.gv.egiz.pdfas.common.exceptions.PdfAsSettingsException;
/**
* This class implements an abstract table definition. The table contains table
@@ -216,12 +219,75 @@ public class Table implements Serializable
public void addRow(String rowNumber, ArrayList<Entry> row)
{
rows_.put(rowNumber, row);
- if (row.size() > maxCols_)
- {
- maxCols_ = row.size();
- }
+ calculateMaxCols(row);
}
+ private void calculateMaxCols(ArrayList<Entry> newrow) {
+ int colCount = calculateRowSize(newrow);
+ if (colCount > maxCols_)
+ {
+ maxCols_ = colCount;
+ }
+ }
+
+ private int calculateRowSize(ArrayList<Entry> newrow) {
+ int colCount = 0;
+ for(int i = 0; i < newrow.size(); i++) {
+ colCount += newrow.get(i).getColSpan();
+ }
+ return colCount;
+ }
+
+ private void recalculateMaxCol() {
+ Iterator<ArrayList<Entry>> rowIt = getRows().iterator();
+ while(rowIt.hasNext()) {
+ ArrayList<Entry> row = rowIt.next();
+ calculateMaxCols(row);
+ }
+ }
+
+ private boolean recursiveNorm = false;
+
+ /**
+ * Expands the last cell of each column to fill the table
+ * @throws PdfAsSettingsException
+ */
+ public void normalize() throws PdfAsSettingsException {
+ Iterator<ArrayList<Entry>> rowIt = getRows().iterator();
+ while(rowIt.hasNext()) {
+ ArrayList<Entry> row = rowIt.next();
+
+ // This row fits just fine
+ if(row.size() == maxCols_) {
+ continue;
+ }
+
+ int rowSize = calculateRowSize(row);
+
+ // This row fits just fine including row spans
+ if(rowSize == maxCols_) {
+ continue;
+ }
+
+ int missingColumns = maxCols_ - rowSize;
+
+ if(missingColumns < 0) {
+ // wrong max Col value!
+ // recalculate the maximum Columns and normalize again!
+ if(recursiveNorm) {
+ throw new PdfAsSettingsException("Failed to build virtual model of signatur block table.");
+ }
+ recalculateMaxCol();
+ recursiveNorm = true;
+ normalize();
+ recursiveNorm = false;
+ break;
+ } else {
+ row.get(row.size() - 1).setColSpan(row.get(row.size() - 1).getColSpan() + missingColumns);
+ }
+ }
+ }
+
/**
* The toString method, used for tests or debugging.
*/