在ApacheFop生成的PDF中显示Unicode字符
我有一个包含名称列表的XML文件,其中一些使用默认PDF字体(Helvetica/Arial)中未表示的字符/字形: 我查看了文档,似乎认为可用的选项有:在ApacheFop生成的PDF中显示Unicode字符,unicode,fonts,apache-fop,Unicode,Fonts,Apache Fop,我有一个包含名称列表的XML文件,其中一些使用默认PDF字体(Helvetica/Arial)中未表示的字符/字形: 我查看了文档,似乎认为可用的选项有: 使用OpenType字体-除非FOP不支持这种字体 仅针对文本的非ASCII部分切换到其他字体 我不想对每种语言使用不同的字体,因为会有混合了中文和英文的PDF,据我所知,在XSLT/XSL-FO中无法确定哪个是哪个 是否可以嵌入一种字体来覆盖所有情况?目前我只需要英文和中文,但将来我可能需要扩展这两种语言 我在Ubuntu上使用Apache
<font kerning="yes" embed-url="../fonts/ubuntu/Ubuntu-R.ttf" embedding-mode="full">
<font-triplet name="Ubuntu" style="normal" weight="normal"/>
</font>
<font kerning="yes" embed-url="../fonts/ubuntu/Ubuntu-B.ttf" embedding-mode="subset">
<font-triplet name="Ubuntu" style="normal" weight="bold"/>
</font>
我知道Ubuntu Regular有这两个字形,因为它是我的标准系统字体
编辑2:如果使用,图示符将正确显示。然而,与文档相比,它似乎更适合于控制台使用。我的问题的答案是使用,即:
或者为英文和中文PDF制作单独的模板,并分别使用不同的字体。如果您找不到支持中文和英文的合适字体(或者您找到了,但您不太喜欢它的拉丁字形),请记住,
font-family
可以包含以逗号分隔的名称列表,以便按顺序使用
因此,您可以先列出英文文本所需的字体,然后列出中文文本所需的字体:
<!-- this has # instead of the missing Chinese glyphs -->
<fo:block font-family="Helvetica" space-after="1em" background-color="#AAFFFF">
Paul 你好</fo:block>
<!-- this has all the glyphs, but I don't like its latin glyphs -->
<fo:block font-family="SimSun" space-after="1em" background-color="#FFAAFF">
Paul 你好</fo:block>
<!-- the best of both worlds! -->
<fo:block font-family="Helvetica, SimSun" space-after="1em" background-color="#FFFFAA">
Paul 你好</fo:block>
保罗你好
保罗你好
保罗你好
输出如下所示:
Arial Unicode对我来说是一个问题,因为许可限制(我需要能够随软件提供任何嵌入式字体)。我试过使用Ubuntu Regular,它肯定会显示你好 当我在我的系统上使用它时,它是正确的,但我仍然得到一个关于glyph不可用的警告。好的,如果Ubuntu Regular不包括中文(尽管我仍然不完全确定为什么它在LibreOffice中工作,但在Apache FOP中不工作),我的选择是什么?关于LibreOffice,我认为它可能会自动使用一些默认的支持CJK字形的字体,只要用户选择了一个不支持CJK字形的字体(显然OpenOffice和MS Word也这样做)。证明:看看当你为你的中文文本选择一种肯定没有中文字形的字体时会发生什么(一种“花式”字体可能是一个很好的选择)。有多种免费的CJK字体。例如,源Hans Sans()或问题中标记为“[F]”的其他条目没有找到中文字体,而是找到了一种可以混合中文和英文(可能还有其他语言)的字体,因为我无法检测姓名将使用哪种语言。我不知道你可以使用这样的字体,我认为这是使用列表中第一种字体的情况,第二种字体只有在第一种字体未安装/嵌入的情况下才会使用。
<font kerning="yes" embed-url="../fonts/ubuntu/Ubuntu-R.ttf" embedding-mode="full">
<font-triplet name="Ubuntu" style="normal" weight="normal"/>
</font>
<font kerning="yes" embed-url="../fonts/ubuntu/Ubuntu-B.ttf" embedding-mode="subset">
<font-triplet name="Ubuntu" style="normal" weight="bold"/>
</font>
Jan 31, 2016 10:22:59 AM org.apache.fop.events.LoggingEventListener processEvent
WARNING: Glyph "你" (0x4f60) not available in font "Ubuntu".
Jan 31, 2016 10:22:59 AM org.apache.fop.events.LoggingEventListener processEvent
WARNING: Glyph "好" (0x597d) not available in font "Ubuntu".
<!-- this has # instead of the missing Chinese glyphs -->
<fo:block font-family="Helvetica" space-after="1em" background-color="#AAFFFF">
Paul 你好</fo:block>
<!-- this has all the glyphs, but I don't like its latin glyphs -->
<fo:block font-family="SimSun" space-after="1em" background-color="#FFAAFF">
Paul 你好</fo:block>
<!-- the best of both worlds! -->
<fo:block font-family="Helvetica, SimSun" space-after="1em" background-color="#FFFFAA">
Paul 你好</fo:block>