@@ -20,22 +20,42 @@ class TestIssue580SpecialCharacters {
2020
2121 private static final String PATH_XML_SAMPLE = "issue/gh580/sample-gh580.xml" ;
2222
23+ private static final String PATH_XML_SAMPLE_ALT_FONT = "issue/gh580/sample-gh580-alt-font.xml" ;
24+
25+ private File testWorker ( DocTypeHandler handler , String xmlPath , String outputPath ) throws Exception {
26+ log .info ( "xml path : {}, handler: {}, type: {}" , xmlPath , handler .getClass ().getName (), handler .getType () );
27+ File outputFile = new File ( outputPath );
28+ log .info ( "output file: {}, delete : {}" , outputFile .getAbsolutePath (), outputFile .delete () );
29+ try (Reader reader = new InputStreamReader ( ClassHelper .loadFromDefaultClassLoader (xmlPath ) );
30+ OutputStream os = new FileOutputStream ( outputFile ) ) {
31+ handler .handle ( DocInput .newInput ( handler .getType (), reader ), DocOutput .newOutput ( os ) );
32+ }
33+ return outputFile ;
34+ }
35+
36+ /*
37+ * working example using SVG :
38+ * <svg xmlns="http://www.w3.org/2000/svg" fill="#000000" width="10px" height="10px" viewBox="0 0 24 24"><path d="M21,2H3A1,1,0,0,0,2,3V21a1,1,0,0,0,1,1H21a1,1,0,0,0,1-1V3A1,1,0,0,0,21,2ZM20,20H4V4H20Z"/></svg>
39+ */
2340 @ Test
2441 void testGeneratedPdf () throws Exception {
42+ DocTypeHandler handler = PdfFopTypeHandler .HANDLER_UTF8 ;
43+ File outputFile = this .testWorker ( handler , PATH_XML_SAMPLE , "target/issue-gh580.pdf" );
44+ Assertions .assertTrue ( outputFile .exists () ) ;
45+ }
46+
47+ /*
48+ * working example using DejaVu Font https://dejavu-fonts.github.io/
49+ */
50+ @ Test
51+ void testGeneratedPdfWithAlternateFont () throws Exception {
2552 DocTypeHandlerDefault handler = new PdfFopTypeHandler (StandardCharsets .UTF_8 );
26- String xmlConfig = "<docHandlerCustomConfig charset=\" UTF-8\" " +
53+ String xmlConfig = "<config>< docHandlerCustomConfig charset=\" UTF-8\" " +
2754 "fop-config-mode=\" classloader\" " +
28- "fop-config-classloader-path=\" issue/gh580/fop-config-issue-580.xml\" />\n " ;
55+ "fop-config-classloader-path=\" issue/gh580/fop-config-issue-580.xml\" /></config> \n " ;
2956 Element element = DOMIO .loadDOMDoc ( xmlConfig ).getDocumentElement ();
3057 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- }
58+ File outputFile = this .testWorker ( handler , PATH_XML_SAMPLE_ALT_FONT , "target/issue-gh580-alt-font.pdf" );
3959 Assertions .assertTrue ( outputFile .exists () ) ;
4060 }
4161
0 commit comments