Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
444 views
in Technique[技术] by (71.8m points)

java - Font (Myanmar3) not rendering correctly in iText

In section there is this jasper-report-character-encoding-in-pdf question.

The problem can not be solved in jasper report since it seems to be an problem (using iText v. 5.5.4)

Example code:

public class FontTest {

    /** The resulting PDF file. */
    public static final String RESULT = "pdf/fontTest.pdf";
    /** the text to render. */
    public static final String TEST = "u1005u101Bu1004u103Au1038u1021u1004u103Au1038u1019u103Bu102Cu1038u1011u100Au103Au101Eu103Du1004u103Au1038u1001u103Cu1004u103Au1038";

    public void createPdf(String filename) throws IOException, DocumentException {
        Document document = new Document();
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename));
        document.open();
        BaseFont bf = BaseFont.createFont(
            "lib/mm3.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
        Font font = new Font(bf, 20);
        ColumnText column = new ColumnText(writer.getDirectContent());
        column.setSimpleColumn(36, 730, 569, 36);
        column.addElement(new Paragraph(TEST, font));
        column.go();
        document.close();
    }

    public static void main(String[] args) throws IOException, DocumentException {
        new FontTest().createPdf(RESULT);
    }
}

The font can be downloaded at mm3.ttf

Will render incorrectly as:

PDF RESULT

it should render as (in browser using same ttf)

Correct rendering

Just out of curiosity what is happening? (seems like certain char, with dotted circles should move backwards but this is not happening).

Is this a problem with .tff or that iText does not support these kind of fonts?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Converting Bruno Lowagie (Original developer of ) comment into answer (community wiki)

The behavior you see is caused by the fact that iText doesn't support ligatures. (Current version on github.com 5.5.8)

You need one of the next, unreleased versions of iText. We'll release beta versions next year (2016) but only to customers

Thanks to some bounty offered by @Rad Lexus this other question about accessing directly openType glyph in iText has an answer Accessing OpenType glyph variants in iText


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...