Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🀄 Add support for CJK fonts #13

Merged
merged 1 commit into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added data/fop/fonts/NotoSans-Bold.ttf
Binary file not shown.
Binary file added data/fop/fonts/NotoSans-BoldItalic.ttf
Binary file not shown.
Binary file added data/fop/fonts/NotoSans-Italic.ttf
Binary file not shown.
Binary file added data/fop/fonts/NotoSans-Regular.ttf
Binary file not shown.
Binary file added data/fop/fonts/NotoSansJP-Bold.otf
Binary file not shown.
Binary file added data/fop/fonts/NotoSansJP-Regular.otf
Binary file not shown.
Binary file added data/fop/fonts/NotoSansSC-Bold.otf
Binary file not shown.
Binary file added data/fop/fonts/NotoSansSC-Regular.otf
Binary file not shown.
Binary file removed data/fop/fonts/SourceSerifPro-Light.ttf
Binary file not shown.
Binary file removed data/fop/fonts/SourceSerifPro-LightItalic.ttf
Binary file not shown.
Binary file removed data/fop/fonts/SourceSerifPro-SemiBold.ttf
Binary file not shown.
Binary file removed data/fop/fonts/SourceSerifPro-SemiBoldItalic.ttf
Binary file not shown.
50 changes: 31 additions & 19 deletions data/fop/fop.xconf
Original file line number Diff line number Diff line change
@@ -1,22 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<fop version="1.0">
<accessibility>true</accessibility>
<renderers>
<renderer mime="application/pdf">
<fonts>
<font kerning="yes" embed-url="fonts/SourceSerifPro-Light.ttf" embedding-mode="subset">
<font-triplet name="SourceSerifPro" style="normal" weight="normal"/>
</font>
<font kerning="yes" embed-url="fonts/SourceSerifPro-SemiBold.ttf" embedding-mode="subset">
<font-triplet name="SourceSerifPro" style="normal" weight="700"/>
</font>
<font kerning="yes" embed-url="fonts/SourceSerifPro-LightItalic.ttf" embedding-mode="subset">
<font-triplet name="SourceSerifPro" style="italic" weight="normal"/>
</font>
<font kerning="yes" embed-url="fonts/SourceSerifPro-SemiBoldItalic.ttf" embedding-mode="subset">
<font-triplet name="SourceSerifPro" style="italic" weight="bold"/>
</font>
</fonts>
</renderer>
</renderers>
<accessibility>true</accessibility>
<renderers>
<renderer mime="application/pdf">
<fonts>
<font embed-url="./fonts/NotoSans-Bold.ttf" kerning="yes">
<font-triplet name="SourceSerifPro" style="normal" weight="bold"/>
</font>
<font embed-url="./fonts/NotoSans-BoldItalic.ttf" kerning="yes">
<font-triplet name="SourceSerifPro" style="italic" weight="bold"/>
</font>
<font embed-url="./fonts/NotoSans-Italic.ttf" kerning="yes">
<font-triplet name="SourceSerifPro" style="italic" weight="normal"/>
</font>
<font embed-url="./fonts/NotoSans-Regular.ttf" kerning="yes">
<font-triplet name="SourceSerifPro" style="normal" weight="normal"/>
</font>
<font embed-url="./fonts/NotoSansJP-Regular.otf" kerning="yes">
<font-triplet name="SourceSerifPro" style="normal" weight="normal"/>
</font>
<font embed-url="./fonts/NotoSansJP-Bold.otf" kerning="yes">
<font-triplet name="SourceSerifPro" style="normal" weight="bold"/>
</font>
<font embed-url="./fonts/NotoSansSC-Regular.otf" kerning="yes">
<font-triplet name="SourceSerifPro" style="normal" weight="normal"/>
</font>
<font embed-url="./fonts/NotoSansSC-Bold.otf" kerning="yes">
<font-triplet name="SourceSerifPro" style="normal" weight="bold"/>
</font>
</fonts>
</renderer>
</renderers>
</fop>
4 changes: 2 additions & 2 deletions data/xsl/xr-pdf/lib/konstanten.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
== Schriften
=========================================================================== -->

<xsl:variable name="fontSans">Helvetica</xsl:variable>
<xsl:variable name="fontSerif">Helvetica</xsl:variable>
<xsl:variable name="fontSans">SourceSerifPro</xsl:variable>
<xsl:variable name="fontSerif">SourceSerifPro</xsl:variable>

<xsl:variable name="amount-picture" select="xrf:_('amount-format')"/>
<xsl:variable name="percentage-picture" select="xrf:_('percentage-format')"/>
Expand Down
21 changes: 0 additions & 21 deletions helvetica-font.patch

This file was deleted.

15 changes: 6 additions & 9 deletions src/main/java/io/github/easybill/xrviz/XslTransformer.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package io.github.easybill.xrviz;

import org.apache.fop.apps.FOPException;
import org.apache.fop.apps.Fop;
import org.apache.fop.apps.FopFactory;
import org.apache.fop.apps.MimeConstants;
import org.apache.fop.fonts.FontManager;
import org.apache.fop.apps.*;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
Expand Down Expand Up @@ -114,7 +111,7 @@ public static String transformToHtml(String inputXml, String language) throws Tr
return outputString.toString();
}

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

ByteArrayOutputStream out = new ByteArrayOutputStream();

FopFactory fopFactory = FopFactory.newInstance(new File("data/fop/fop.xconf").toURI());
FontManager fontManager = fopFactory.getFontManager();
logger.info(fontManager.getResourceResolver().getBaseURI().toString());
FopConfParser parser = new FopConfParser(new File("data/fop/fop.xconf"));
FopFactoryBuilder builder = parser.getFopFactoryBuilder();
FopFactory fopFactory = builder.build();
Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, out);

InputSource src = new InputSource(new java.io.StringReader(foXmlString));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import io.github.easybill.xrviz.XslTransformer;
import org.apache.fop.apps.FOPException;
import org.xml.sax.SAXException;

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

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

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