我正在尝试在AFP中使用带有Apache FOP 2.2的TrueType字体。
我相信我的配置正确,但我遇到以下异常:
java.lang.ClassCastException: org.apache.fop.afp.modca.MapDataResource cannot be cast to org.apache.fop.afp.modca.MapCodedFont
at org.apache.fop.afp.modca.ActiveEnvironmentGroup.getCurrentMapCodedFont(ActiveEnvironmentGroup.java:286)
at org.apache.fop.afp.modca.ActiveEnvironmentGroup.createFont(ActiveEnvironmentGroup.java:201)
at org.apache.fop.afp.modca.AbstractPageObject.createFont(AbstractPageObject.java:149)
at org.apache.fop.afp.DataStream.createFont(DataStream.java:331)
at org.apache.fop.afp.DataStream.addFontsToCurrentPage(DataStream.java:313)
at org.apache.fop.render.afp.AFPDocumentHandler.endPage(AFPDocumentHandler.java:310)
at org.apache.fop.render.intermediate.util.IFDocumentHandlerProxy.endPage(IFDocumentHandlerProxy.java:167)
at org.apache.fop.render.intermediate.EventProducingFilter.endPage(EventProducingFilter.java:48)
at org.apache.fop.render.intermediate.IFRenderer.renderPage(IFRenderer.java:603)
at org.apache.fop.area.RenderPagesModel.renderPage(RenderPagesModel.java:193)
at org.apache.fop.area.RenderPagesModel.checkPreparedPages(RenderPagesModel.java:174)
at org.apache.fop.area.RenderPagesModel.addPage(RenderPagesModel.java:146)
at org.apache.fop.layoutmgr.AbstractPageSequenceLayoutManager.finishPage(AbstractPageSequenceLayoutManager.java:316)
at org.apache.fop.layoutmgr.PageSequenceLayoutManager.finishPage(PageSequenceLayoutManager.java:226)
at org.apache.fop.layoutmgr.PageSequenceLayoutManager.activateLayout(PageSequenceLayoutManager.java:145)
at org.apache.fop.area.AreaTreeHandler.endPageSequence(AreaTreeHandler.java:267)
at org.apache.fop.fo.pagination.PageSequence.endOfNode(PageSequence.java:130)
at org.apache.fop.fo.FOTreeBuilder$MainFOHandler.endElement(FOTreeBuilder.java:360)
at org.apache.fop.fo.FOTreeBuilder.endElement(FOTreeBuilder.java:190)
以下是我的conf.xml配置的片段:
<renderer mime="application/x-afp">
<fonts>
<font name="Script MT Bold" kerning="yes" embed-url="/fonts/SCRIPTBL.TTF">
<font-triplet name="Script MT Bold" style="normal" weight="normal"/>
</font>
</fonts>
</renderer>
我是否需要其他配置?
此外,我必须在AFP中嵌入TrueType字体,还是只需要包含一个引用并依靠大型机打印机来解决它?
答案 0 :(得分:2)
我也遇到了同样的例外。看起来在创建用于渲染当前页面的字体时,FOP会填充一个AbstractStructuredObject列表。
加载True Type字体时,FOP为它创建一个MapDataResource,并在AbstractStructuredObject列表中填充它。
但是,如果页面有其他字体(如光栅字体),那么在加载此光栅字体之前,它会从列表中获取最新的AbstractStructuredObject并将其强制转换为MapCodedFont。因为,最近的大多数对象是MapDataResource类型,我们得到ClassCastException。
作为一种解决方法,我目前在AFP文档中仅使用True Type字体,并将默认字体三元组添加到其中一种字体配置中。
<font name="Script MT Bold" kerning="yes" embed-url="/fonts/SCRIPTBL.TTF">
<font-triplet name="Script MT Bold" style="normal" weight="normal"/>
<font-triplet name="any" style="normal" weight="normal"/>
</font>