Skip to content

Commit

Permalink
Increase test coverage #111
Browse files Browse the repository at this point in the history
  • Loading branch information
fugerit79 committed Feb 4, 2024
1 parent 9601d45 commit 37fd1c9
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
import org.fugerit.java.doc.base.model.DocBase;
import org.fugerit.java.doc.mod.openpdf.ext.helpers.OpenPDFConfigHelper;
import org.fugerit.java.doc.mod.openpdf.ext.helpers.OpenPpfDocHandler;
import org.w3c.dom.Element;

import com.lowagie.text.Document;
import com.lowagie.text.html.HtmlWriter;
import org.w3c.dom.Element;

public class HtmlTypeHandler extends DocTypeHandlerDefault {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
import org.fugerit.java.doc.base.model.DocBase;
import org.fugerit.java.doc.mod.openpdf.ext.helpers.OpenPDFConfigHelper;
import org.fugerit.java.doc.mod.openpdf.ext.helpers.OpenPpfDocHandler;
import org.w3c.dom.Element;

import com.lowagie.text.Document;
import com.lowagie.text.PageSize;
import com.lowagie.text.pdf.PdfWriter;
import org.w3c.dom.Element;

public class PdfTypeHandler extends DocTypeHandlerDefault {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package org.fugerit.java.doc.mod.openpdf.ext.helpers;

import lombok.extern.slf4j.Slf4j;
import org.fugerit.java.core.cfg.ConfigException;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class OpenPDFConfigHelper {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ protected static Font createFont( String fontName, String fontPath, int fontSize
} else {
bf = OpenPpfDocHandler.findFont( fontName );
if ( bf == null) {
bf = BaseFont.createFont( fontPath, BaseFont.CP1252, true );
OpenPpfDocHandler.registerFont( fontName, bf );
bf = OpenPpfDocHandler.registerFont( fontName , fontPath );
}
}
Color c = Color.BLACK;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import org.fugerit.java.core.cfg.ConfigRuntimeException;
import org.fugerit.java.core.function.SafeFunction;
import org.fugerit.java.core.lang.helpers.StringUtils;
import org.fugerit.java.core.log.LogFacade;
import org.fugerit.java.core.util.regex.ParamFinder;
import org.fugerit.java.doc.base.config.DocConfig;
import org.fugerit.java.doc.base.helper.SourceResolverHelper;
Expand Down Expand Up @@ -69,9 +68,10 @@ public class OpenPpfDocHandler {

private static HashMap<String, BaseFont> fonts = new HashMap<>();

public static void registerFont( String name, String path ) throws DocumentException, IOException {
public static BaseFont registerFont( String name, String path ) throws DocumentException, IOException {
BaseFont font = BaseFont.createFont( path, BaseFont.CP1252, true );
registerFont( name, font );
return font;
}

public static void registerFont( String name, BaseFont font ) {
Expand Down Expand Up @@ -414,11 +414,7 @@ private void handleHeaderFooterElement( DocElement docElement, float leading, Op
}
Font f = new Font( Font.HELVETICA, docPara.getSize() );
if ( docPara.getForeColor() != null ) {
try {
f.setColor( DocModelUtils.parseHtmlColor( docPara.getForeColor() ) );
} catch (Exception fe) {
LogFacade.getLog().warn( "Error setting fore color on footer : "+docPara.getForeColor(), fe );
}
SafeFunction.applySilent( () -> f.setColor( DocModelUtils.parseHtmlColor( docPara.getForeColor() ) ) );
}
Chunk ck = new Chunk( docPara.getText(), f );
phrase.add( ck );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public class TestDefaultDoc extends TestDocBase {

private static final String DEFAULT_DOC_ALT = "default_doc_alt";

private static final String DEFAULT_DOC_SIMPLE = "default_doc_simple";

private static final String DEFAULT_DOC_PDFA = "default_doc_pdfa";

@Test
Expand Down Expand Up @@ -52,6 +54,12 @@ public void testOpenAltHTML() {
Assert.assertTrue(ok);
}

@Test
public void testOpenSimple() {
boolean ok = this.testDocWorker( DEFAULT_DOC_SIMPLE , DocConfig.TYPE_PDF );
Assert.assertTrue(ok);
}

@Test
public void testOpenPDFA() {
// still working on font embedding
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
import org.fugerit.java.doc.base.config.DocInput;
import org.fugerit.java.doc.base.config.DocOutput;
import org.fugerit.java.doc.base.config.DocTypeHandler;

import lombok.extern.slf4j.Slf4j;
import org.fugerit.java.doc.freemarker.process.FreemarkerDocProcessConfig;
import org.fugerit.java.doc.freemarker.process.FreemarkerDocProcessConfigFacade;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class TestDocBase {

Expand Down
10 changes: 5 additions & 5 deletions fj-doc-mod-openpdf-ext/src/test/resources/xml/default_doc.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<doc
xmlns="http://javacoredoc.fugerit.org"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://javacoredoc.fugerit.org https://www.fugerit.org/data/java/doc/xsd/doc-2-0.xsd" >
xsi:schemaLocation="http://javacoredoc.fugerit.org https://www.fugerit.org/data/java/doc/xsd/doc-2-1.xsd" >

<metadata>
<!-- Margin for document : left;right;top;bottom -->
Expand Down Expand Up @@ -32,16 +32,16 @@
<para space-before="10" font-name="symbol" align="right" style="italic">Symbol</para>
<para leading="10" font-name="helvetica" align="center" style="underline">Symbol</para>
<para size="-1" align="left" fore-color="#dddddd">Test default font</para>
<table columns="3" colwidths="30;30;40" width="100" id="excel-table" padding="2">
<table columns="3" colwidths="30;30;40" width="100" id="excel-table" padding="2" space-before="10" space-after="10">
<row>
<cell align="center" border-color="#000000" border-width="1"><para style="bold">Name</para></cell>
<cell align="center" back-color="#eeeeee"><para style="bold">Surname</para></cell>
<cell align="center" fore-color="#111111"><para style="bold">Title</para></cell>
</row>
<row>
<cell><para><![CDATA[Luthien]]></para></cell>
<cell><para><![CDATA[Tinuviel]]></para></cell>
<cell><para><![CDATA[Queen]]></para></cell>
<cell header="true" valign="top"><para><![CDATA[Luthien]]></para></cell>
<cell header="true" valign="middle"><para><![CDATA[Tinuviel]]></para></cell>
<cell header="true" valign="bottom"><para><![CDATA[Queen]]></para></cell>
</row>
<row>
<cell><para><![CDATA[Thorin]]></para></cell>
Expand Down
14 changes: 10 additions & 4 deletions fj-doc-mod-openpdf-ext/src/test/resources/xml/default_doc_alt.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,16 @@
</row>
</table>
</cell>
</row>
</row>
<row>
<cell><barcode text="0123456789123"/></cell>
<cell><barcode size="10" text="0123456789123"/></cell>
<cell><barcode type="128" text="0123456789123"/></cell>
</row>
</table>
</body>

<page-break/>

<page-break/>

</body>

</doc>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<doc
xmlns="http://javacoredoc.fugerit.org"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://javacoredoc.fugerit.org https://www.fugerit.org/data/java/doc/xsd/doc-2-0.xsd" >

<metadata>
<info name="default-font-name">TitilliumWeb</info>
<header>
<image scaling="100" url="cl://test/img_test_teal.jpg"/>
</header>
</metadata>
<body>
<para font-name="TitilliumWeb">Test PDFA</para>
</body>

</doc>

0 comments on commit 37fd1c9

Please sign in to comment.