自定义字体哥谭凌乱与动态碧玉报告

时间:2019-06-28 11:04:16

标签: java jasper-reports dynamic-reports

如何在JasperReports中使用Gotham-Book.ttf修复凌乱的自定义字体?

自定义字体arial(成功): custom font arial (succeed)

字体声明:

<fontFamily name="FreeUniversal">
    <normal>jasperutils/fonts/Arial.ttf</normal>
    <bold>jasperutils/fonts/Arial.ttf</bold>
    <italic>jasperutils/fonts/Arial.ttf</italic>
    <boldItalic>jasperutils/fonts/Arial.ttf</boldItalic>
    <pdfEncoding>Cp1252</pdfEncoding>
    <pdfEmbedded>true</pdfEmbedded>
</fontFamily>

自定义字体哥谭(messy): custom font Gotham (messy)

字体声明:

<fontFamily name="FreeUniversal">
    <normal>jasperutils/fonts/gotham/GothamBook.ttf</normal>
    <bold>jasperutils/fonts/gotham/GothamBook.ttf</bold>
    <italic>jasperutils/fonts/gotham/GothamBook.ttf</italic>
    <boldItalic>jasperutils/fonts/gotham/GothamBook.ttf</boldItalic>
    <pdfEncoding>Cp1252</pdfEncoding>
    <pdfEmbedded>true</pdfEmbedded>
</fontFamily>

我正在使用DynamicReports生成报告,示例代码:

private void build() {
    FontBuilder defaultFont = stl.font()
        .setFontName("FreeUniversal");
    StyleBuilder boldStyle = stl.style()
        .bold();
    StyleBuilder italicStyle = stl.style()
        .italic();
    StyleBuilder boldItalicStyle = stl.style()
        .boldItalic();

    try {
        report()
            .setDefaultFont(defaultFont)
          .title(
            Templates.createTitleComponent("DefaultFont"),
            cmp.text("FreeUniversal font - plain"),
            cmp.text("FreeUniversal font - bold").setStyle(boldStyle),
            cmp.text("FreeUniversal font - italic").setStyle(italicStyle),
            cmp.text("FreeUniversal font - bolditalic").setStyle(boldItalicStyle))
          .show();
    } catch (DRException e) {
        e.printStackTrace();
    }
}

0 个答案:

没有答案