Skip to content

Commit fd7d9e6

Browse files
committed
fix: special character handling #580
1 parent 9ab19c9 commit fd7d9e6

File tree

3 files changed

+93
-0
lines changed

3 files changed

+93
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package test.org.fugerit.java.doc.mod.fop;
2+
3+
import lombok.extern.slf4j.Slf4j;
4+
import org.fugerit.java.core.lang.helpers.ClassHelper;
5+
import org.fugerit.java.core.xml.dom.DOMIO;
6+
import org.fugerit.java.doc.base.config.DocInput;
7+
import org.fugerit.java.doc.base.config.DocOutput;
8+
import org.fugerit.java.doc.base.config.DocTypeHandler;
9+
import org.fugerit.java.doc.base.config.DocTypeHandlerDefault;
10+
import org.fugerit.java.doc.mod.fop.PdfFopTypeHandler;
11+
import org.junit.jupiter.api.Assertions;
12+
import org.junit.jupiter.api.Test;
13+
import org.w3c.dom.Element;
14+
15+
import java.io.*;
16+
import java.nio.charset.StandardCharsets;
17+
18+
@Slf4j
19+
class TestIssue580SpecialCharacters {
20+
21+
private static final String PATH_XML_SAMPLE = "issue/gh580/sample-gh580.xml";
22+
23+
@Test
24+
void testGeneratedPdf() throws Exception {
25+
DocTypeHandlerDefault handler = new PdfFopTypeHandler(StandardCharsets.UTF_8);
26+
String xmlConfig = "<docHandlerCustomConfig charset=\"UTF-8\" " +
27+
"fop-config-mode=\"classloader\" " +
28+
"fop-config-classloader-path=\"issue/gh580/fop-config-issue-580.xml\" />\n";
29+
Element element = DOMIO.loadDOMDoc( xmlConfig ).getDocumentElement();
30+
handler.configure( element );
31+
32+
log.info( "handler: {}, type: {}", handler.getClass().getName(), handler.getType() );
33+
File outputFile = new File( "target/issue-gh580.pdf" );
34+
log.info( "output file: {}, delete : {}", outputFile.getAbsolutePath(), outputFile.delete() );
35+
try (Reader reader = new InputStreamReader( ClassHelper.loadFromDefaultClassLoader(PATH_XML_SAMPLE) );
36+
OutputStream os = new FileOutputStream( outputFile ) ) {
37+
handler.handle( DocInput.newInput( handler.getType(), reader ), DocOutput.newOutput( os ) );
38+
}
39+
Assertions.assertTrue( outputFile.exists() ) ;
40+
}
41+
42+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<fop version="1.0">
2+
3+
<!-- Strict user configuration -->
4+
<strict-configuration>true</strict-configuration>
5+
6+
<!-- Strict FO validation -->
7+
<strict-validation>true</strict-validation>
8+
9+
<!-- Base URL for resolving relative URLs -->
10+
<base>.</base>
11+
12+
<!-- Font Base URL for resolving relative font URLs -->
13+
<font-base>.</font-base>
14+
15+
<renderers>
16+
<renderer mime="application/pdf">
17+
</renderer>
18+
</renderers>
19+
20+
21+
<!-- Source resolution in dpi (dots/pixels per inch) for determining the size of pixels in SVG and bitmap images, default: 72dpi -->
22+
<source-resolution>72</source-resolution>
23+
<!-- Target resolution in dpi (dots/pixels per inch) for specifying the target resolution for generated bitmaps, default: 72dpi -->
24+
<target-resolution>72</target-resolution>
25+
26+
<!-- default page-height and page-width, in case
27+
value is specified as auto -->
28+
<default-page-settings height="11in" width="8.26in"/>
29+
30+
</fop>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<doc
3+
xmlns="http://javacoredoc.fugerit.org"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://javacoredoc.fugerit.org https://www.fugerit.org/data/java/doc/xsd/doc-2-1.xsd" >
6+
7+
<metadata>
8+
<info name="margins">10;10;10;30</info>
9+
<info name="doc-title">Basic example</info>
10+
<info name="doc-subject">fj doc venus sample source xml</info>
11+
<info name="doc-author">fugerit79</info>
12+
<info name="doc-language">it</info>
13+
<info name="mod-fop-xslt-debug">true</info>
14+
</metadata>
15+
<body>
16+
<para>Sample special characters reproducer ■ □ &#x25A0; &#x25A1;</para>
17+
<phrase>Working POC with SVG : </phrase>
18+
<image type="svg" alt="blank square" base64="PHN2ZyBmaWxsPSIjMDAwMDAwIiB3aWR0aD0iMTBweCIgaGVpZ2h0PSIxMHB4IiB2aWV3Qm94PSIwIDAgMjQgMjQiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PHBhdGggZD0iTTIxLDJIM0ExLDEsMCwwLDAsMiwzVjIxYTEsMSwwLDAsMCwxLDFIMjFhMSwxLDAsMCwwLDEtMVYzQTEsMSwwLDAsMCwyMSwyWk0yMCwyMEg0VjRIMjBaIi8+PC9zdmc+"/>
19+
</body>
20+
21+
</doc>

0 commit comments

Comments
 (0)