Search in sources :

Example 6 with Mapper

use of org.docx4j.fonts.Mapper in project docx4j-template by vindell.

the class PhysicalFontUtils method setPhysicalFont.

/**
 * 为 {@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);
}
Also used : Mapper(org.docx4j.fonts.Mapper) IdentityPlusMapper(org.docx4j.fonts.IdentityPlusMapper) PhysicalFont(org.docx4j.fonts.PhysicalFont) IdentityPlusMapper(org.docx4j.fonts.IdentityPlusMapper)

Aggregations

IdentityPlusMapper (org.docx4j.fonts.IdentityPlusMapper)6 Mapper (org.docx4j.fonts.Mapper)6 PhysicalFont (org.docx4j.fonts.PhysicalFont)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 URL (java.net.URL)1 PdfSettings (org.docx4j.convert.out.pdf.viaXSLFO.PdfSettings)1 Docx4JException (org.docx4j.openpackaging.exceptions.Docx4JException)1 RFonts (org.docx4j.wml.RFonts)1