本文整理汇总了Java中org.docx4j.openpackaging.packages.WordprocessingMLPackage.setFontMapper方法的典型用法代码示例。如果您正苦于以下问题:Java WordprocessingMLPackage.setFontMapper方法的具体用法?Java WordprocessingMLPackage.setFontMapper怎么用?Java WordprocessingMLPackage.setFontMapper使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.docx4j.openpackaging.packages.WordprocessingMLPackage
的用法示例。
在下文中一共展示了WordprocessingMLPackage.setFontMapper方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: configSimSunFont
import org.docx4j.openpackaging.packages.WordprocessingMLPackage; //导入方法依赖的package包/类
/**
* 为 {@link org.docx4j.openpackaging.packages.WordprocessingMLPackage} 配置中文字体
*
* @param wordMLPackage
* @throws Exception
*/
protected void configSimSunFont(WordprocessingMLPackage wordMLPackage) throws Exception {
Mapper fontMapper = new IdentityPlusMapper();
wordMLPackage.setFontMapper(fontMapper);
String fontFamily = "SimSun";
URL simsunUrl = this.getClass().getResource("/org/noahx/html2docx/simsun.ttc"); //加载字体文件(解决linux环境下无中文字体问题)
PhysicalFonts.addPhysicalFonts(fontFamily, simsunUrl);
PhysicalFont simsunFont = PhysicalFonts.get(fontFamily);
fontMapper.put(fontFamily, simsunFont);
RFonts rfonts = Context.getWmlObjectFactory().createRFonts(); //设置文件默认字体
rfonts.setAsciiTheme(null);
rfonts.setAscii(fontFamily);
wordMLPackage.getMainDocumentPart().getPropertyResolver()
.getDocumentDefaultRPr().setRFonts(rfonts);
}
示例2: setWmlPackageFonts
import org.docx4j.openpackaging.packages.WordprocessingMLPackage; //导入方法依赖的package包/类
/**
* 为 {@link org.docx4j.openpackaging.packages.WordprocessingMLPackage} 配置中文字体;解决中文乱码问题
*/
public static void setWmlPackageFonts(WordprocessingMLPackage wmlPackage) throws Docx4JException {
try {
//字体映射;
Mapper fontMapper = FONT_FACTORY.getFontMapper();;
//设置文档字体库
wmlPackage.setFontMapper(fontMapper, true);
} catch (Exception e) {
throw new Docx4JException(e.getMessage(),e.getCause());
}
}
示例3: setPhysicalFont
import org.docx4j.openpackaging.packages.WordprocessingMLPackage; //导入方法依赖的package包/类
/**
* 为 {@link org.docx4j.openpackaging.packages.WordprocessingMLPackage} 增加新的字体
*/
public static void setPhysicalFont(WordprocessingMLPackage wmlPackage,PhysicalFont physicalFont) throws Exception {
Mapper fontMapper = wmlPackage.getFontMapper() == null ? new IdentityPlusMapper() : wmlPackage.getFontMapper();
//分别设置字体名和别名对应的字体库
fontMapper.put(physicalFont.getName(), physicalFont );
//设置文档字体库
wmlPackage.setFontMapper(fontMapper, true);
}