font-family not working when running XSL-FO via XProc

Here should go questions about transforming XML with XSLT and FOP.
Martin de la Iglesia
Posts: 10
Joined: Tue Aug 22, 2017 5:43 pm

font-family not working when running XSL-FO via XProc

Post by Martin de la Iglesia » Thu Jun 06, 2019 5:46 pm

Hi,
I have written an FO stylesheet to transform XML to PDF, which works fine when I execute it as an XSLT Transformation Scenario. Now I'd like to integrate this stylesheet into my XProc pipeline. However, when I invoke the exact same FO stylesheet via an XProc Transformation Scenario, the resulting PDF contains the wrong font. Instead of a sans-serif font it's now a serif font, and some special characters are displayed as "#" (e.g. "Kou#im" instead of "Kouřim"). Everything else about the PDF is correct. It looks like the setting

<fo:root font-family="Arial Unicode MS">

in the XSL-FO gets ignored. No error messages or warnings are shown. Any idea why the same XSL-FO behaves differently in the XSLT Transformation Scenario and XProc? (And how to fix that?)

Radu
Posts: 6343
Joined: Fri Jul 09, 2004 5:18 pm

Re: font-family not working when running XSL-FO via XProc

Post by Radu » Thu Jun 13, 2019 9:16 pm

Hi Martin,

We are not very familiar with using XProc to generate PDF. Are you using Apache FOP for this or the XEP formatter? How did you set this up? Can you also give us a sample XProc script to test on our side. For Apache FOP there usually can be specified a "fop.xconf" configuration file which usually has an auto-detect statement for fonts installed in the system. But I'm not sure how this can be done with Calabash, maybe you can ask around on the Calabash users list.
Also for RenderX XEP there is an xep.xml which might need some tinkering:
https://www.oxygenxml.com/doc/versions/ ... h_xep.html

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com

Martin de la Iglesia
Posts: 10
Joined: Tue Aug 22, 2017 5:43 pm

Re: font-family not working when running XSL-FO via XProc

Post by Martin de la Iglesia » Mon Jun 17, 2019 3:24 pm

Hi Radu,

here's an XProc:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<p:declare-step xmlns:p="http://www.w3.org/ns/xproc" xmlns:c="http://www.w3.org/ns/xproc-step" version="1.0" name="myPipeline">
    <p:input port="source">
        <p:empty/>
    </p:input>

    <p:xslt name="xsl-fo-test">
        <p:input port="source">
            <p:document href="fonttest.xpl"/>           
        </p:input>
        <p:input port="stylesheet">
            <p:document href="fonttest_tei2xsl-fo.xsl"/>
        </p:input>
        <p:input port="parameters">
            <p:empty/>
        </p:input>
    </p:xslt>
    <p:xsl-formatter name="test" href="fonttest.pdf" content-type="application/pdf">
        <p:with-param name="UserConfig" select="resolve-uri('fop.xconf', static-base-uri())"/>
        <p:input port="source">
            <p:pipe port="result" step="xsl-fo-test"/>
        </p:input>
        <p:input port="parameters">
            <p:empty/>
        </p:input>
    </p:xsl-formatter>

</p:declare-step>
This is the XSLT:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fo="http://www.w3.org/1999/XSL/Format" exclude-result-prefixes="xs" version="2.0">

    <xsl:template match="/">
        <fo:root font-family="Arial Unicode MS">
            <fo:layout-master-set>
                <fo:simple-page-master master-name="test" page-height="297mm" page-width="210mm" margin-top="3cm" margin-bottom="5cm" margin-left="3cm" margin-right="3cm">
                    <fo:region-body/>
                </fo:simple-page-master>
            </fo:layout-master-set>

            <fo:page-sequence master-reference="test">
                <fo:flow flow-name="xsl-region-body">
                    <fo:block-container font-family="serif">
                        <fo:block>
                            <xsl:text>Gallia est omnis divisa in pařtes třes</xsl:text>
                        </fo:block>
                    </fo:block-container>
                    <fo:block-container>
                        <fo:block>
                            <xsl:text>Quařum unam incolunt Belgae, aliam Aquitani</xsl:text>
                        </fo:block>                       
                    </fo:block-container>
                </fo:flow>
            </fo:page-sequence>
        </fo:root>
    </xsl:template>

</xsl:stylesheet>
Here's the xconf file:

Code: Select all

<?xml version="1.0"?>
<fop version="1.0">
    <renderers>
        <renderer mime="application/pdf">
            <fonts>
                <directory recursive="true">fonts</directory> <!-- contains ARIALUNI.TTF -->
            </fonts>
        </renderer>
    </renderers>
</fop>
As I have described in my previous post, the XSLT works when executed as a Transformation Scenario, but not via XProc.

In the (non-XProc) Transformation Scenario, I have set Transformator to Saxon-PE 9.8.0.12, checked the FO Transformation checkbox, set Method to pdf and Processor to Apache FOP.

In the XProc Transformation Scenario, I have set the XProc processor to Add-on for Calabash XProc Engine. All other settings are default.

Radu
Posts: 6343
Joined: Fri Jul 09, 2004 5:18 pm

Re: font-family not working when running XSL-FO via XProc

Post by Radu » Fri Jun 21, 2019 10:39 am

Hello Martin,

Sorry for the delay. In my opinion the user config file is not passed at all to the Apache FOP.
What is my opinion based on:

1) I can change the name of the fop.xconf file to something else in the Xproc file and is still works.
2) Looking at the Java code Norman Walsh has for running FOP 2.x:

https://github.com/ndw/xmlcalabash1-pri ... FoFOP.java

the code which was supposed to send the parameter to the FOP engine is commented out:

Code: Select all

            /* FIXME:
            s = getStringProp("UserConfig");
            if (s != null) {
                fopFactory.setUserConfig(s);
            }
            */
So I'm not sure if there is a workaround for this.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com

Post Reply