Skip to content

Commit 9b8dfa2

Browse files
authored
Add support for CJK fonts (#13)
1 parent 1ca05f7 commit 9b8dfa2

17 files changed

+41
-53
lines changed

data/fop/fonts/NotoSans-Bold.ttf

617 KB
Binary file not shown.
632 KB
Binary file not shown.

data/fop/fonts/NotoSans-Italic.ttf

625 KB
Binary file not shown.

data/fop/fonts/NotoSans-Regular.ttf

607 KB
Binary file not shown.

data/fop/fonts/NotoSansJP-Bold.otf

4.44 MB
Binary file not shown.

data/fop/fonts/NotoSansJP-Regular.otf

4.32 MB
Binary file not shown.

data/fop/fonts/NotoSansSC-Bold.otf

8.15 MB
Binary file not shown.

data/fop/fonts/NotoSansSC-Regular.otf

7.95 MB
Binary file not shown.
-222 KB
Binary file not shown.
-168 KB
Binary file not shown.
-224 KB
Binary file not shown.
-169 KB
Binary file not shown.

data/fop/fop.xconf

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,34 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<fop version="1.0">
3-
<accessibility>true</accessibility>
4-
<renderers>
5-
<renderer mime="application/pdf">
6-
<fonts>
7-
<font kerning="yes" embed-url="fonts/SourceSerifPro-Light.ttf" embedding-mode="subset">
8-
<font-triplet name="SourceSerifPro" style="normal" weight="normal"/>
9-
</font>
10-
<font kerning="yes" embed-url="fonts/SourceSerifPro-SemiBold.ttf" embedding-mode="subset">
11-
<font-triplet name="SourceSerifPro" style="normal" weight="700"/>
12-
</font>
13-
<font kerning="yes" embed-url="fonts/SourceSerifPro-LightItalic.ttf" embedding-mode="subset">
14-
<font-triplet name="SourceSerifPro" style="italic" weight="normal"/>
15-
</font>
16-
<font kerning="yes" embed-url="fonts/SourceSerifPro-SemiBoldItalic.ttf" embedding-mode="subset">
17-
<font-triplet name="SourceSerifPro" style="italic" weight="bold"/>
18-
</font>
19-
</fonts>
20-
</renderer>
21-
</renderers>
3+
<accessibility>true</accessibility>
4+
<renderers>
5+
<renderer mime="application/pdf">
6+
<fonts>
7+
<font embed-url="./fonts/NotoSans-Bold.ttf" kerning="yes">
8+
<font-triplet name="SourceSerifPro" style="normal" weight="bold"/>
9+
</font>
10+
<font embed-url="./fonts/NotoSans-BoldItalic.ttf" kerning="yes">
11+
<font-triplet name="SourceSerifPro" style="italic" weight="bold"/>
12+
</font>
13+
<font embed-url="./fonts/NotoSans-Italic.ttf" kerning="yes">
14+
<font-triplet name="SourceSerifPro" style="italic" weight="normal"/>
15+
</font>
16+
<font embed-url="./fonts/NotoSans-Regular.ttf" kerning="yes">
17+
<font-triplet name="SourceSerifPro" style="normal" weight="normal"/>
18+
</font>
19+
<font embed-url="./fonts/NotoSansJP-Regular.otf" kerning="yes">
20+
<font-triplet name="SourceSerifPro" style="normal" weight="normal"/>
21+
</font>
22+
<font embed-url="./fonts/NotoSansJP-Bold.otf" kerning="yes">
23+
<font-triplet name="SourceSerifPro" style="normal" weight="bold"/>
24+
</font>
25+
<font embed-url="./fonts/NotoSansSC-Regular.otf" kerning="yes">
26+
<font-triplet name="SourceSerifPro" style="normal" weight="normal"/>
27+
</font>
28+
<font embed-url="./fonts/NotoSansSC-Bold.otf" kerning="yes">
29+
<font-triplet name="SourceSerifPro" style="normal" weight="bold"/>
30+
</font>
31+
</fonts>
32+
</renderer>
33+
</renderers>
2234
</fop>

data/xsl/xr-pdf/lib/konstanten.xsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
== Schriften
1313
=========================================================================== -->
1414

15-
<xsl:variable name="fontSans">Helvetica</xsl:variable>
16-
<xsl:variable name="fontSerif">Helvetica</xsl:variable>
15+
<xsl:variable name="fontSans">SourceSerifPro</xsl:variable>
16+
<xsl:variable name="fontSerif">SourceSerifPro</xsl:variable>
1717

1818
<xsl:variable name="amount-picture" select="xrf:_('amount-format')"/>
1919
<xsl:variable name="percentage-picture" select="xrf:_('percentage-format')"/>

helvetica-font.patch

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/main/java/io/github/easybill/xrviz/XslTransformer.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
package io.github.easybill.xrviz;
22

3-
import org.apache.fop.apps.FOPException;
4-
import org.apache.fop.apps.Fop;
5-
import org.apache.fop.apps.FopFactory;
6-
import org.apache.fop.apps.MimeConstants;
7-
import org.apache.fop.fonts.FontManager;
3+
import org.apache.fop.apps.*;
84
import org.xml.sax.InputSource;
5+
import org.xml.sax.SAXException;
96

107
import javax.xml.transform.Source;
118
import javax.xml.transform.Transformer;
@@ -114,7 +111,7 @@ public static String transformToHtml(String inputXml, String language) throws Tr
114111
return outputString.toString();
115112
}
116113

117-
public static byte[] transformToPdf(String inputXml, String language) throws TransformerException, FOPException, IOException {
114+
public static byte[] transformToPdf(String inputXml, String language) throws TransformerException, SAXException, IOException {
118115
TransformerFactory factory = TransformerFactory.newInstance();
119116
StreamSource xslXrPdf = new StreamSource("data/xsl/xr-pdf.xsl");
120117
Transformer xslXrTransformer = factory.newTransformer(xslXrPdf);
@@ -129,9 +126,9 @@ public static byte[] transformToPdf(String inputXml, String language) throws Tra
129126

130127
ByteArrayOutputStream out = new ByteArrayOutputStream();
131128

132-
FopFactory fopFactory = FopFactory.newInstance(new File("data/fop/fop.xconf").toURI());
133-
FontManager fontManager = fopFactory.getFontManager();
134-
logger.info(fontManager.getResourceResolver().getBaseURI().toString());
129+
FopConfParser parser = new FopConfParser(new File("data/fop/fop.xconf"));
130+
FopFactoryBuilder builder = parser.getFopFactoryBuilder();
131+
FopFactory fopFactory = builder.build();
135132
Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, out);
136133

137134
InputSource src = new InputSource(new java.io.StringReader(foXmlString));

src/main/java/io/github/easybill/xrviz/handler/PdfHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import com.sun.net.httpserver.HttpExchange;
44
import com.sun.net.httpserver.HttpHandler;
55
import io.github.easybill.xrviz.XslTransformer;
6-
import org.apache.fop.apps.FOPException;
6+
import org.xml.sax.SAXException;
77

88
import javax.xml.transform.TransformerException;
99
import java.io.IOException;
@@ -26,7 +26,7 @@ public void handle(HttpExchange exchange) throws IOException {
2626
exchange.getResponseBody().write(response);
2727
exchange.getResponseBody().close();
2828

29-
} catch (TransformerException | FOPException e) {
29+
} catch (TransformerException | SAXException e) {
3030
exchange.sendResponseHeaders(500, -1);
3131

3232
logger.severe("Error while transforming XML to PDF: " + e.getMessage());

0 commit comments

Comments
 (0)