本文整理汇总了Java中org.docx4j.fonts.PhysicalFonts.addPhysicalFonts方法的典型用法代码示例。如果您正苦于以下问题:Java PhysicalFonts.addPhysicalFonts方法的具体用法?Java PhysicalFonts.addPhysicalFonts怎么用?Java PhysicalFonts.addPhysicalFonts使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.docx4j.fonts.PhysicalFonts
的用法示例。
在下文中一共展示了PhysicalFonts.addPhysicalFonts方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: configSimSunFont
import org.docx4j.fonts.PhysicalFonts; //导入方法依赖的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: configInternalFonts
import org.docx4j.fonts.PhysicalFonts; //导入方法依赖的package包/类
public void configInternalFonts(){
ChineseFont[] fonts = ChineseFont.values();
for (ChineseFont font : fonts){
FontScheme fontScheme = COMPLIED_FONTSCHEME.get(font.getFontName());
if (fontScheme == null) {
fontScheme = new FontScheme(font.getFontName(), font.getFontAlias(), font.getFontURL());
COMPLIED_FONTSCHEME.putIfAbsent(font.getFontName(), fontScheme);
PhysicalFont physicalFont = PhysicalFonts.get(fontScheme.getFontName());
if(physicalFont == null){
//加载字体文件(解决linux环境下无中文字体问题)
PhysicalFonts.addPhysicalFonts(fontScheme.getFontName(), fontScheme.getFontURL());
LOG.debug("Add Internal " + fontScheme.toString() );
}
}
}
}
示例3: configExternalFonts
import org.docx4j.fonts.PhysicalFonts; //导入方法依赖的package包/类
public void configExternalFonts() {
/**
* 加载外部字体库:参数格式如:字体名称:字体别名:字体URL;多个以 ",; \t\n"分割
* 隶书:LiSu:URL,宋体:SimSun:URL
*/
String external_fonts_mapping = Docx4jProperties.getProperty(Docx4jConstants.DOCX4J_FONTS_EXTERNAL_MAPPING);
if(external_fonts_mapping!=null && external_fonts_mapping.length() > 0){
String[] fonts_mappings = StringUtils.tokenizeToStringArray(external_fonts_mapping);
if(fonts_mappings.length > 0){
for (String fonts_mapping : fonts_mappings) {
String[] font = fonts_mapping.split(":");
FontScheme fontScheme = COMPLIED_FONTSCHEME.get(font[0]);
if (fontScheme != null) {
continue;
}
try {
fontScheme = new FontScheme(font[0], font[1], new URL(font[2]));
COMPLIED_FONTSCHEME.putIfAbsent(font[0], fontScheme);
PhysicalFont physicalFont = PhysicalFonts.get(fontScheme.getFontName());
if(physicalFont == null){
//加载字体文件(解决linux环境下无中文字体问题)
PhysicalFonts.addPhysicalFonts(fontScheme.getFontName(), fontScheme.getFontURL());
LOG.debug("Add External " + fontScheme.toString() );
}
} catch (MalformedURLException e) {
// ignore
}
}
}
}
}