尽管指定了字体,但Apache FOP / Batik无法在SVG中呈现字形

时间:2018-11-29 17:14:34

标签: svg apache-fop batik

我们正在通过FO将DITA XML转换为PDF。 这曾经是一个复杂的批处理脚本,为了更好的可维护性,我们现在将其转换为.NET。第一步,我们保留所有工具的旧版本,以确保输出完全相同。

我们的某些文档包含MathML,我们将其提取并转换为SVG以在PDF中呈现。 包括以下SVG图片:

<fo:block id="unique_4_Connect_42_equation_972159C300BD467DB59037BB400830B2" keep-together.within-page="always">
    <fo:block xmlns:mml="http://www.w3.org/1998/Math/MathML" display-align="before" space-after="10pt" space-before="10pt" text-align="center">
        <fo:external-graphic src="url(mathml_equation_972159C300BD467DB59037BB400830B2.xml.pdf.svg)" vertical-align="middle"/>
    </fo:block>
</fo:block>

旧脚本通过将MathML转换为PDF,然后将PDF转换为SVG来创建SVG文件。 这导致文件包含应如何呈现符号的明确定义:

<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="49.995pt" height="13pt" viewBox="0 0 49.995 13" version="1.1">
    <defs>
        <g>
            <symbol overflow="visible" id="glyph0-0">
                <path style="stroke:none;" d="M 2.765625 -2.375 L 2.765625 -2.484375 C 2.765625 -2.554688 2.769531 -2.625 2.78125 -2.6875 C 2.789063 -2.746094 2.8125 -2.8125 2.84375 -2.875 C 2.882813 -2.945313 2.9375 -3.023438 3 -3.109375 C 3.070313 -3.191406 3.164063 -3.296875 3.28125 -3.421875 C 3.363281 -3.503906 3.429688 -3.582031 3.484375 -3.65625 C 3.542969 -3.738281 3.597656 -3.820313 3.640625 -3.90625 C 3.691406 -3.988281 3.726563 -4.078125 3.75 -4.171875 C 3.777344 -4.261719 3.796875 -4.367188 3.796875 -4.484375 C 3.796875 -4.722656 3.738281 -4.910156 3.625 -5.046875 C 3.519531 -5.179688 3.367188 -5.25 3.171875 -5.25 C 3.066406 -5.25 2.972656 -5.226563 2.890625 -5.1875 C 2.816406 -5.15625 2.746094 -5.105469 2.6875 -5.046875 C 2.632813 -4.992188 2.585938 -4.925781 2.546875 -4.84375 C 2.503906 -4.769531 2.464844 -4.679688 2.4375 -4.578125 L 1.96875 -4.578125 L 1.96875 -5.21875 C 2.164063 -5.308594 2.375 -5.394531 2.59375 -5.46875 C 2.820313 -5.550781 3.039063 -5.59375 3.25 -5.59375 C 3.476563 -5.59375 3.671875 -5.566406 3.828125 -5.515625 C 3.992188 -5.460938 4.128906 -5.394531 4.234375 -5.3125 C 4.335938 -5.238281 4.410156 -5.144531 4.453125 -5.03125 C 4.492188 -4.914063 4.515625 -4.789063 4.515625 -4.65625 C 4.515625 -4.53125 4.503906 -4.414063 4.484375 -4.3125 C 4.460938 -4.21875 4.417969 -4.117188 4.359375 -4.015625 C 4.296875 -3.921875 4.214844 -3.816406 4.125 -3.703125 C 4.03125 -3.585938 3.910156 -3.457031 3.765625 -3.3125 C 3.660156 -3.195313 3.574219 -3.101563 3.515625 -3.03125 C 3.453125 -2.96875 3.402344 -2.898438 3.375 -2.828125 C 3.34375 -2.765625 3.316406 -2.699219 3.296875 -2.640625 C 3.285156 -2.578125 3.28125 -2.496094 3.28125 -2.40625 L 3.28125 -2.375 Z M 3.375 -1.84375 L 3.375 -1.0625 L 2.671875 -1.0625 L 2.671875 -1.84375 Z M 5.15625 -0.453125 L 5.15625 -6.203125 L 1.4375 -6.203125 L 1.4375 -0.453125 Z M 5.65625 -6.65625 L 5.65625 0 L 0.921875 0 L 0.921875 -6.65625 Z "/>
            </symbol>
            <!-- Several other symbols omitted -->
        </g>
    </defs>
    <g id="surface1">
        <g style="fill:rgb(0%,0%,0%);fill-opacity:1;">
            <use xlink:href="#glyph0-1" x="0" y="7.77832"/>
        </g>
        <g style="fill:rgb(0%,0%,0%);fill-opacity:1;">
            <use xlink:href="#glyph1-1" x="5.29" y="11.22266"/>
        </g>
        <!-- Several other g elements omitted -->
    </g>
</svg>

这很好用。

但是现在我们决定简单一些,将MathML直接转换为SVG。 这为我们提供了一个更加“清晰”的SVG文件:

<?xml version="1.0"?>
<!--AH Formatter V6.2 MR5 (6,2,7,18952) for Windows (x64) Copyright (c) 1999-2014 Antenna House, Inc.-->
<svg xml:space="preserve" version="1.1" fill="black" fill-rule="evenodd" font-style="normal" font-weight="normal" font-stretch="normal" font-family="'Cambria Math'" width="49.995pt" height="13pt" viewBox="0 0 49.995 13" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
    <g>
        <view viewBox="0 0 49.995 13" id="AH-SVG-page-1"/>
    </g><g transform="matrix(1,0,0,1,0,5.22168)" font-size="10">
        <text y="2.557" fill-rule="nonzero"></text>
    </g><g transform="matrix(1,0,0,1,0,5.22168)" font-size="8">
        <text x="5.293" y="6.001" fill-rule="nonzero"></text>
        <text x="9.93" y="6.001" fill-rule="nonzero"></text>
    </g><g transform="matrix(1,0,0,1,0,5.22168)" font-size="10">
        <text x="15.243" y="2.557" fill-rule="nonzero">=</text>
        <text x="25.491" y="2.557" fill-rule="nonzero"></text>
    </g><g transform="matrix(1,0,0,1,0,5.22168)" font-size="8">
        <text x="30.819" y="6.001" fill-rule="nonzero"></text>
        <text x="35.218" y="6.001" fill-rule="nonzero"></text>
    </g><g transform="matrix(1,0,0,1,0,5.22168)" font-size="10">
        <text x="37.753" y="2.557" fill-rule="nonzero"></text>
    </g><g transform="matrix(1,0,0,1,0,5.22168)" font-size="8">
        <text x="43.046" y="6.001" fill-rule="nonzero"></text>
        <text x="47.46" y="6.001" fill-rule="nonzero"></text>
    </g>
    <font horiz-adv-x="0">
        <font-face font-family="'Cambria Math'" font-weight="normal" font- style="normal" units-per-em="2048"/>
        <missing-glyph d="M570.4 487.6L570.4 509.4Q570.4 531.2 573.3 549.5Q576.3 567.8 587 588.6Q597.7 609.4 618.2 635.6Q638.7 661.9 673.9 700.5Q696.3 725.2 714.8 748.5Q733.4 771.8 746.6 797Q759.8 822.3 767.1 850.5Q774.4 878.7 774.4 913.4Q774.4 987.6 742 1028.2Q709.7 1068.8 648 1068.8Q616.2 1068.8 592.3 1058.9Q568.4 1049 550.5 1031.2Q532.6 1013.5 520.1 988.7Q507.7 964 498.7 934.4L403.2 934.4L403.2 1063.6Q462.7 1093.5 530.6 1116.3Q598.5 1139.2 664.9 1139.2Q734.3 1139.2 783.3 1124.8Q832.4 1110.4 863.1 1085.1Q893.8 1059.9 907.7 1025.1Q921.6 990.4 921.6 949.8Q921.6 912.1 914.4 881.3Q907.3 850.6 890 820.3Q872.8 790.1 844.1 755.4Q815.4 720.7 773.3 676Q742.7 643.3 724.5 621.5Q706.4 599.7 696.3 580.3Q686.3 561 682.9 541.1Q679.6 521.3 679.6 493.6L679.6 487.6L570.4 487.6ZM697.6 377.6L697.6 217.6L550.4 217.6L550.4 377.6L697.6 377.6ZM1056 96L1056 1267.2L294.4 1267.2L294.4 96L1056 96ZM1158.4 1363.2L1158.4 0L192 0L192 1363.2L1158.4 1363.2Z" horiz-adv-x="1350"/>
        <glyph unicode="=" d="M149 729.6L149 864L1381 864L1381 729.6L149 729.6ZM149 300.8L149 435.2L1381 435.2L1381 300.8L149 300.8ZM1423 582.4L1423 582.4Z" horiz-adv-x="1529"/>
    </font>
</svg>

因此,该文件两次明确提及“ Cambria Math”(应包含符号),并且在运行代码的计算机上安装了“ Cambria Math Regular”(我认为可以省略“ Regular”吗?)。

但是Apache-FOP仅将SVG文件中的公式呈现为“ ###”,只有'='正确呈现。

我们在做什么错了?

0 个答案:

没有答案