pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Itai <itai...@gmail.com>
Subject General method for converting code/unicode to GeneralPath?
Date Sun, 19 Nov 2017 16:01:21 GMT
I am trying to render PDFs in JavaFX using PDFBox, mostly as an exercise
for myself.
I am extending PDFGraphicsStreamEngine, and I have come across a
predicament in the method showFontGlyph(Matrix textRenderingMatrix, PDFont
font, int code, String unicode, Vector displacement), namely - how do I get
a GeneralPath for the glyph in question.
It seems each PDFont class has a slightly different way for achieving this,
and I couldn't find any succinct summary of all the methods. So far I have
come up with this bit of code:

        GeneralPath gp;
        if (font instanceof PDVectorFont) {
            PDVectorFont vFont = (PDVectorFont) font;
            gp = vFont.getPath(code);
        } else if (font instanceof PDSimpleFont) {
            if (font instanceof PDType1Font) {
                PDType1Font t1Font = (PDType1Font) font;
                gp = t1Font.getType1Font().getPath(t1Font.codeToName(code));
            } else if (font instanceof PDType1CFont) {
                PDType1CFont t1cFont = (PDType1CFont) font;
                gp = t1cFont.getPath(t1cFont.codeToName(code));
            } else {
                // Presumably this should only be PDType3Font, as
PDTrueTypeFont is also a PDVectorFont
                PDSimpleFont sFont = ((PDSimpleFont) font);
                gp = sFont.getPath(unicode);
        } else {
            // Should never happen?
            throw new RuntimeException("Unknown font type");

My question is - did I cover all possibilities? Am I doing this correctly?
Or is there some built-in method for achieving the same purpose, which is
agnostic to the type of PDFont given?


  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message