You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "Andreas Lehmkühler (Jira)" <ji...@apache.org> on 2022/10/21 05:47:00 UTC

[jira] [Resolved] (PDFBOX-5486) "RandomAccessBuffer already closed" when opening smaller fonts

     [ https://issues.apache.org/jira/browse/PDFBOX-5486?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Andreas Lehmkühler resolved PDFBOX-5486.
----------------------------------------
    Resolution: Fixed

Let us see how this ends up. It should be easier to implement some improvements if needed after simplifying the code. 


> "RandomAccessBuffer already closed" when opening smaller fonts
> --------------------------------------------------------------
>
>                 Key: PDFBOX-5486
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-5486
>             Project: PDFBox
>          Issue Type: Bug
>          Components: FontBox
>    Affects Versions: 3.0.0 PDFBox
>            Reporter: Tilman Hausherr
>            Assignee: Andreas Lehmkühler
>            Priority: Major
>             Fix For: 3.0.0 PDFBox
>
>
> I wonder if this is related to one of the memory management / inputstream changes, PDTrueTypeFont.load() can't load smaller ttf fonts (I discovered this while working with the font from PDFBOX-5484):
> {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}
> It does not happen with larger fonts, e.g. Arial.



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

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org