【发布时间】:2022-08-08 00:14:13
【问题描述】:
更新到 FOP 2.6 后,在尝试使用 Apache FOP 来使用自定义字体 GT Super Display Light 时,我遇到了以下错误。
org.apache.fop.events.LoggingEventListener processEvent
WARNING: Font \"Symbol,normal,700\" not found. Substituting with \"Symbol,normal,400\".
org.apache.fop.events.LoggingEventListener processEvent
WARNING: Font \"ZapfDingbats,normal,700\" not found. Substituting with \"ZapfDingbats,normal,400\".
org.apache.fop.events.LoggingEventListener processEvent
WARNING: Font \"Arial,normal,700\" not found. Substituting with \"any,normal,700\".
org.apache.fop.events.LoggingEventListener processEvent
WARNING: Font \"GTSuperDisplayLight,normal,700\" not found. Substituting with \"any,normal,700\".
配置文件:
<fonts>
<!-- automatically detect operating system installed fonts -->
<auto-detect/>
<!-- embedded fonts -->
<!--
This information must exactly match the font specified
in the fo file. Otherwise it will use a default font.
For example,
<fo:inline font-family=\"Arial\" font-weight=\"bold\" font-style=\"normal\">
Arial-normal-normal font
</fo:inline>
for the font triplet specified by:
<font-triplet name=\"Arial\" style=\"normal\" weight=\"bold\"/>
If you do not want to embed the font in the pdf document
then do not include the \"embed-url\" attribute.
The font will be needed where the document is viewed
for it to be displayed properly.
possible styles: normal | italic | oblique | backslant
possible weights: normal | bold | 100 | 200 | 300 | 400
| 500 | 600 | 700 | 800 | 900
(normal = 400, bold = 700)
-->
<font kerning=\"yes\" embed-url=\"GTSuperDisplayLight.ttf\" embedding-mode=\"subset\">
<font-triplet name=\"GTSuperDisplayLight\" style=\"normal\" weight=\"700\" />
</font>
</fonts>
编辑:添加调用配置文件的 Java 文件并选择安装在用户计算机上的字体,但可以指定自定义字体。请参考Apache FOP官方
/*
* Register Apache FOP to use our fonts. By default we set this config file to auto-detect the fonts
*/
File xconf = new File( getConfigFileURI( xslFullName ) );
FopConfParser parser = new FopConfParser( xconf ); //parsing configuration
FopFactoryBuilder builder = parser.getFopFactoryBuilder(); //building the factory with the user options
fopFactory = builder.build();
fopFactory = FopFactory.newInstance( new File( \".\" ).toURI() );
foUserAgent = fopFactory.newFOUserAgent();
bufferedOutputStream = new FileOutputStream( pdfFilename );
bufferedOutputStream = new BufferedOutputStream(
bufferedOutputStream );
private String getConfigFileURI( String xslFilePath )
{
File f = new File( xslFilePath );
String configFileURI = f.getParent() + \"/userconfig.xml\";
return configFileURI;
}
-
您是在告诉 FOP 使用您的配置文件(在您的 java 代码中或使用
-c path/to/your.xconf,如果您从命令行调用它)? -
@lfurini 我们从我们的 Java 代码中调用它
-
是什么让您认为 GTSuperDisplayLight.ttf 包含粗体?仅仅因为你声明了重量并不意味着它会自动加粗。
-
您需要将真实字体(如在 TTF 中)与粗细和样式相匹配。就像我不能只说我有:TimesNewRoman.ttf 然后说有正常、粗体、斜体和粗体斜体。该字体只是“普通”,您需要其他具有粗体、斜体和粗体斜体的字体文件(表示不同的 TTF 文件)
-
@KevinBrown OP 已在配置文件中使用
weight=\"700\"显式注册字体,因此不应这问题;当然,注册一个带有粗体的“普通”字体不会使它变粗,但 pdf 仍然应该使用它。
标签: fonts xsl-fo apache-fop