Skip to content

Commit a3a8862

Browse files
committed
feat: using deja vu fonts #580
1 parent 8f6fde2 commit a3a8862

File tree

4 files changed

+56
-10
lines changed

4 files changed

+56
-10
lines changed

fj-doc-mod-fop/src/test/java/test/org/fugerit/java/doc/mod/fop/TestIssue580SpecialCharacters.java

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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

739 KB
Binary file not shown.

fj-doc-mod-fop/src/test/resources/issue/gh580/fop-config-issue-580.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414

1515
<renderers>
1616
<renderer mime="application/pdf">
17+
<fonts>
18+
<font embed-url="classpath://issue/gh580/DejaVuSans.ttf" embedding-mode="full">
19+
<font-triplet name="DejaVuSans" style="normal" weight="normal"/>
20+
</font>
21+
</fonts>
1722
</renderer>
1823
</renderers>
1924

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+
<!-- working example using DejaVu Font https://dejavu-fonts.github.io/ -->
8+
<metadata>
9+
<info name="margins">10;10;10;30</info>
10+
<info name="doc-title">Basic example alt font</info>
11+
<info name="doc-subject">fj doc venus sample source xml</info>
12+
<info name="doc-author">fugerit79</info>
13+
<info name="doc-language">it</info>
14+
<info name="mod-fop-xslt-debug">true</info>
15+
<info name="default-font-name">DejaVuSans</info>
16+
</metadata>
17+
<body>
18+
<para font-name="DejaVuSans">Sample special characters reproducer ■ □ &#x25A0; &#x25A1; with font DejaVuSans</para>
19+
</body>
20+
21+
</doc>

0 commit comments

Comments
 (0)