Tilman Hausherr created PDFBOX-5486:
---------------------------------------

             Summary: "RandomAccessBuffer already closed" when opening smaller 
fonts
                 Key: PDFBOX-5486
                 URL: https://issues.apache.org/jira/browse/PDFBOX-5486
             Project: PDFBox
          Issue Type: Bug
    Affects Versions: 3.0.0 PDFBox
            Reporter: Tilman Hausherr


I wonder if this is related to one of the memory management / inputstream 
changes, PDTrueTypeFont.load() can't load smaller ttf fonts:
{code}
    public static void main(String[] args) throws IOException
    {
        File fontDir = new File("C:/windows/fonts");
        File[] files = fontDir.listFiles((File dir, String name) -> 
name.toLowerCase().endsWith(".ttf"));
        for (File file : files)
        {
            PDDocument doc = new PDDocument();
            PDTrueTypeFont ttf = PDTrueTypeFont.load(doc, file, 
WinAnsiEncoding.INSTANCE);
            if (ttf.hasGlyph("A"))
            {
                try
                {
                    ttf.getPath("A");
                }
                catch (IOException ex)
                {
                    System.out.println("font " + ttf.getName() + " failed, 
size: " + file.length() +
                            ", glyphs: " + 
ttf.getTrueTypeFont().getNumberOfGlyphs() + ": " + ex.getMessage());
                    ex.printStackTrace();
                }
            }
        }
    }
{code}
{noformat}
font BookAntiqua-Bold failed, size: 151000, glyphs: 669: RandomAccessBuffer 
already closed
java.io.IOException: RandomAccessBuffer already closed
    at 
org.apache.pdfbox.io.RandomAccessReadBuffer.checkClosed(RandomAccessReadBuffer.java:337)
    at 
org.apache.pdfbox.io.RandomAccessReadBuffer.getPosition(RandomAccessReadBuffer.java:188)
    at 
org.apache.fontbox.ttf.RandomAccessReadDataStream.getCurrentPosition(RandomAccessReadDataStream.java:80)
    at org.apache.fontbox.ttf.GlyphTable.getGlyph(GlyphTable.java:135)
    at 
org.apache.pdfbox.pdmodel.font.PDTrueTypeFont.getPath(PDTrueTypeFont.java:498) 
{noformat}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to