本文整理汇总了Java中org.docx4j.fonts.PhysicalFonts.get方法的典型用法代码示例。如果您正苦于以下问题:Java PhysicalFonts.get方法的具体用法?Java PhysicalFonts.get怎么用?Java PhysicalFonts.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.docx4j.fonts.PhysicalFonts
的用法示例。
在下文中一共展示了PhysicalFonts.get方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
}
}
}
}
}
示例4: setPhysicalFont
import org.docx4j.fonts.PhysicalFonts; //导入方法依赖的package包/类
/**
* 为 {@link org.docx4j.openpackaging.packages.WordprocessingMLPackage} 增加新的字体
*/
public static void setPhysicalFont(WordprocessingMLPackage wmlPackage,String fontName) throws Exception {
//Mapper fontMapper = new BestMatchingMapper();
Mapper fontMapper = wmlPackage.getFontMapper() == null ? new IdentityPlusMapper() : wmlPackage.getFontMapper();
//获取字体库
PhysicalFont physicalFont = PhysicalFonts.get(fontName);
//分别设置字体名和别名对应的字体库
fontMapper.put(fontName, physicalFont );
//设置文档字体库
wmlPackage.setFontMapper(fontMapper, true);
}
示例5: getFontMapper
import org.docx4j.fonts.PhysicalFonts; //导入方法依赖的package包/类
public Mapper getFontMapper() throws Exception {
// Set up font mapper (optional)
// example of mapping font Times New Roman which doesn't have certain Arabic glyphs
// eg Glyph "ي" (0x64a, afii57450) not available in font "TimesNewRomanPS-ItalicMT".
// eg Glyph "ج" (0x62c, afii57420) not available in font "TimesNewRomanPS-ItalicMT".
// to a font which does
PhysicalFonts.get("Arial Unicode MS");
/*
* This mapper uses Panose to guess the physical font which is a closest fit for the font used in the document.
* (这个映射器使用Panose算法猜测最适合这个文档使用的物理字体。)
*
* Panose是一种依照字体外观来进行分类的方法。我们可以通过PANOSE体系将字体的外观特征进行整理,并且与其它字体归类比较。
* Panose的原形在1985年由Benjamin Bauermeister开发,当时一种字体由7位16进制数字定义,现在则发展为10位,也就是字体的十种特征。这每一位数字都给出了它定义的一种视觉外观的量度,如笔划的粗细或是字体衬线的样式等。
* Panose定义的范围:Latin Text,Latin Script,Latin Decorative,Iconographic,Japanese Text,Cyrillic Text,Hebrew。
*
* It is most likely to be suitable on Linux or OSX systems which don't have Microsoft's fonts installed.
* (它很可能适用于没有安装Microsoft字体的Linux或OSX系统。)
*
* 1、获取Microsoft字体我们需要这些:a.在Microsoft平台上,嵌入PDF输出; b. docx4all - 所有平台 - 填充字体下拉列表
* setupMicrosoftFontFilenames();
* 2、 自动检测系统上可用的字体
* PhysicalFonts.discoverPhysicalFonts();
*
*/
//Mapper fontMapper = new BestMatchingMapper();
/*
*
* This mapper automatically maps document fonts for which the exact font is physically available.
* Think of this as an identity mapping. For this reason, it will work best on Windows, or a system on
* which Microsoft fonts have been installed.
* (此映射器自动映射确切可用的文档字体,将此视为标识映射;基于这个原因,它在Windows系统或安装了微软字体库的系统运行的更好。)
* You can manually add your own additional mappings if you wish.
* 如果需要,你可以手动添加自己的字体映射
*
* 1、 自动检测系统上可用的字体
* PhysicalFonts.discoverPhysicalFonts();
*
*/
Mapper fontMapper = new IdentityPlusMapper();
//遍历自定义的字体库信息
for (FontScheme fontScheme : COMPLIED_FONTSCHEME.values()) {
//获取字体库
PhysicalFont physicalFont = PhysicalFonts.get(fontScheme.getFontName());
//分别设置字体名和别名对应的字体库
fontMapper.put(fontScheme.getFontName(), physicalFont );
fontMapper.put(fontScheme.getFontAlias(), physicalFont );
}
//进行中文字体兼容处理
fontMapper.put("微软雅黑",PhysicalFonts.get("Microsoft Yahei"));
fontMapper.put("黑体",PhysicalFonts.get("SimHei"));
fontMapper.put("楷体",PhysicalFonts.get("KaiTi"));
fontMapper.put("隶书", PhysicalFonts.get("LiSu"));
fontMapper.put("宋体",PhysicalFonts.get("SimSun"));
fontMapper.put("宋体扩展",PhysicalFonts.get("simsun-extB"));
fontMapper.put("新宋体",PhysicalFonts.get("NSimSun"));
fontMapper.put("仿宋",PhysicalFonts.get("FangSong"));
fontMapper.put("仿宋_GB2312",PhysicalFonts.get("FangSong_GB2312"));
fontMapper.put("幼圆",PhysicalFonts.get("YouYuan"));
fontMapper.put("华文宋体",PhysicalFonts.get("STSong"));
fontMapper.put("华文仿宋", PhysicalFonts.get("STFangsong"));
fontMapper.put("华文中宋",PhysicalFonts.get("STZhongsong"));
fontMapper.put("华文行楷", PhysicalFonts.get("STXingkai"));
return fontMapper;
}
示例6: writeToPDFWhithFo
import org.docx4j.fonts.PhysicalFonts; //导入方法依赖的package包/类
/**
* 将 {@link org.docx4j.openpackaging.packages.WordprocessingMLPackage} 存为 pdf
*/
public void writeToPDFWhithFo(WordprocessingMLPackage wmlPackage,OutputStream output) throws IOException, Docx4JException {
Assert.notNull(wmlPackage, " wmlPackage is not specified!");
Assert.notNull(output, " output is not specified!");
try {
// Font regex (optional)
// Set regex if you want to restrict to some defined subset of fonts
// Here we have to do this before calling createContent,
// since that discovers fonts
//String regex = null;
// Refresh the values of DOCPROPERTY fields
FieldUpdater updater = new FieldUpdater(wmlPackage);
updater.update(true);
// .. example of mapping font Times New Roman which doesn't have certain Arabic glyphs
// eg Glyph "ي" (0x64a, afii57450) not available in font "TimesNewRomanPS-ItalicMT".
// eg Glyph "ج" (0x62c, afii57420) not available in font "TimesNewRomanPS-ItalicMT".
// to a font which does
PhysicalFonts.get("Arial Unicode MS");
// FO exporter setup (required)
// .. the FOSettings object
FOSettings foSettings = Docx4J.createFOSettings();
foSettings.setWmlPackage(wmlPackage);
foSettings.setApacheFopMime("application/pdf");
// Document format:
// The default implementation of the FORenderer that uses Apache Fop will output
// a PDF document if nothing is passed via
// foSettings.setApacheFopMime(apacheFopMime)
// apacheFopMime can be any of the output formats defined in org.apache.fop.apps.MimeConstants eg org.apache.fop.apps.MimeConstants.MIME_FOP_IF or
// FOSettings.INTERNAL_FO_MIME if you want the fo document as the result.
//foSettings.setApacheFopMime(FOSettings.INTERNAL_FO_MIME);
// Specify whether PDF export uses XSLT or not to create the FO
// (XSLT takes longer, but is more complete).
// Don't care what type of exporter you use
Docx4J.toFO(foSettings, output, Docx4J.FLAG_EXPORT_PREFER_XSL);
// Prefer the exporter, that uses a xsl transformation
// Docx4J.toFO(foSettings, os, Docx4J.FLAG_EXPORT_PREFER_XSL);
// Prefer the exporter, that doesn't use a xsl transformation (= uses a visitor)
// faster, but not yet at feature parity
// Docx4J.toFO(foSettings, os, Docx4J.FLAG_EXPORT_PREFER_NONXSL);
// Clean up, so any ObfuscatedFontPart temp files can be deleted
// if (wordMLPackage.getMainDocumentPart().getFontTablePart()!=null) {
// wordMLPackage.getMainDocumentPart().getFontTablePart().deleteEmbeddedFontTempFiles();
// }
// This would also do it, via finalize() methods
updater = null;
foSettings = null;
wmlPackage = null;
} finally{
IOUtils.closeQuietly(output);
}
}