From c2dc72bc99b99959dce84466c5723894169e07b5 Mon Sep 17 00:00:00 2001 From: tknall Date: Tue, 25 Nov 2008 12:52:47 +0000 Subject: 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 --- pom.xml | 8 ----- .../wag/egov/egiz/pdf/PDFSignatureObjectIText.java | 35 +++++++++++++++++++++- src/site/changes.xml | 1 + 3 files changed, 35 insertions(+), 9 deletions(-) diff --git a/pom.xml b/pom.xml index d7b709b..fa6c239 100644 --- a/pom.xml +++ b/pom.xml @@ -301,14 +301,6 @@ 2.3 - - com.lowagie 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); diff --git a/src/site/changes.xml b/src/site/changes.xml index 96307b2..8e1016c 100644 --- a/src/site/changes.xml +++ b/src/site/changes.xml @@ -28,6 +28,7 @@ Preparation for multilingual support for web application. Minor updates of configuration. Sitemesh updates. + Minor support for TrueType fonts in preparation of PDF/A added. -- cgit v1.2.3