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/08/06 14:15:00 UTC
[jira] [Comment Edited] (PDFBOX-5486) "RandomAccessBuffer already closed" when opening smaller fonts
[ https://issues.apache.org/jira/browse/PDFBOX-5486?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17576238#comment-17576238 ]
Andreas Lehmkühler edited comment on PDFBOX-5486 at 8/6/22 2:14 PM:
--------------------------------------------------------------------
I've found the root cause and fixed it. The interesting part was the question why it happens with some fonts but aren't affected. It wasn't a question of size. Those big fonts don't support ps-names in the post table so that getPath("A") returns an empty GeneralPath and the problematic code isn't triggered at all.
[~tilman] thanks for your analysis and the valuable input. I've added you test with some minor changes
was (Author: lehmi):
I've found the root cause and fixed it. The interesting part was the question why it happens with some fonts but aren't affected. It wasn't a question of size. Those big fonts don't support ps-names in the post table so that getPath("A") returns an empty GeneralPath and the problematic code isn't triggered at all.
[~tilman] tnanmks for your analysis and the valuable input. I've added you test with some minor changes
> "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
> 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