aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authortknall <tknall@7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c>2008-11-25 12:52:47 +0000
committertknall <tknall@7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c>2008-11-25 12:52:47 +0000
commitc2dc72bc99b99959dce84466c5723894169e07b5 (patch)
tree82f0c305d5067c3255fcf9a3787a23608af00259 /src/main
parentea60aae139c666c610c1af5cfd0b616d3f4a535c (diff)
downloadpdf-as-3-c2dc72bc99b99959dce84466c5723894169e07b5.tar.gz
pdf-as-3-c2dc72bc99b99959dce84466c5723894169e07b5.tar.bz2
pdf-as-3-c2dc72bc99b99959dce84466c5723894169e07b5.zip
Minor support for TrueType fonts in preparation of PDF/A added.
git-svn-id: https://joinup.ec.europa.eu/svn/pdf-as/trunk@313 7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/pdf/PDFSignatureObjectIText.java35
1 files changed, 34 insertions, 1 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 75e90c5..5bc748d 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
@@ -26,6 +26,7 @@ import java.util.HashMap;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
+import at.gv.egiz.pdfas.exceptions.ErrorCode;
import at.knowcenter.wag.egov.egiz.cfg.ConfigLogger;
import at.knowcenter.wag.egov.egiz.cfg.SettingsReader;
import at.knowcenter.wag.egov.egiz.exceptions.PDFDocumentException;
@@ -36,10 +37,12 @@ import at.knowcenter.wag.egov.egiz.table.Style;
import at.knowcenter.wag.egov.egiz.table.Table;
import com.lowagie.text.BadElementException;
+import com.lowagie.text.DocumentException;
import com.lowagie.text.Element;
import com.lowagie.text.Font;
import com.lowagie.text.Image;
import com.lowagie.text.Phrase;
+import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.pdf.PdfPCell;
import com.lowagie.text.pdf.PdfPTable;
@@ -242,11 +245,37 @@ public class PDFSignatureObjectIText implements PDFSignatureObject
int face = ((Integer) font_face).intValue();
float height = Float.parseFloat(font_arr[1]);
int weight = ((Integer) font_weight).intValue();
-
+
font = new Font(face, height, weight);
fontMap_.put(fontString, font);
return font;
}
+
+ /**
+ * Creates a custom
+ * @param fontString
+ * @return
+ * @throws PDFDocumentException
+ */
+ private Font getCellTrueTypeFont(String fontString) throws PDFDocumentException {
+ // TODO[tknall-PDF/A]: Remove hardcoded TTF. Impement TTF usage based on configuration.
+ logger_.warn("TrueType Fonts are activated. This is only for testing purposes. Deactivate in final release!");
+ try {
+ Font font = (Font) fontMap_.get(fontString);
+ if (font == null) {
+ logger_.debug("Font \"" + fontString + "\" not in cache. Instantiating font.");
+ String fontPath = SettingsReader.RESOURCES_PATH + "fonts" + File.separator + "DejaVuSansCondensed.ttf";
+ logger_.debug("Instantiating \"" + fontPath + "\".");
+ font = new Font(BaseFont.createFont(fontPath, BaseFont.WINANSI, true), 8);
+ fontMap_.put(fontString, font);
+ }
+ return font;
+ } catch (DocumentException e) {
+ throw new PDFDocumentException(ErrorCode.FONT_NOT_FOUND, e.getMessage());
+ } catch (IOException e) {
+ throw new PDFDocumentException(ErrorCode.FONT_NOT_FOUND, e.getMessage());
+ }
+ }
/**
* This method visualize an abstract table cell into a corresponding pdf table
@@ -284,7 +313,11 @@ public class PDFSignatureObjectIText implements PDFSignatureObject
{
font_string = cell_style.getValueFont();
}
+
+ // TODO[tknall-PDF/A]: Deactivate temporary TTF test.
Font cell_font = getCellFont(font_string);
+// Font cell_font = getCellTrueTypeFont(font_string);
+
Phrase text_phrase = new Phrase(text, cell_font);
pdf_cell = new PdfPCell(text_phrase);
setCellStyle(pdf_cell, cell_style);