You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "Tilman Hausherr (JIRA)" <ji...@apache.org> on 2017/07/14 15:26:00 UTC

[jira] [Comment Edited] (PDFBOX-3826) NPE if RAFDataStream.getCurrentPosition() when TrueTypeFont created from file is reused

    [ https://issues.apache.org/jira/browse/PDFBOX-3826?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16087472#comment-16087472 ] 

Tilman Hausherr edited comment on PDFBOX-3826 at 7/14/17 3:25 PM:
------------------------------------------------------------------

I looked at the issue again. We don't know in buildFontFile2 how the font was created.

What we could do is to pass some boolean (e.g. "closeOriginal" or "closeOnSubset") to TrueTypeEmbedder telling whether the font is to be closed or not. 

It isn't needed for the first TrueTypeEmbedder constructor / PDCIDFontType2Embedder constructor (which calls buildFontFile2) because ttf is null. So it's only the second constructor.

The good thing is that it's not public so we can do whatever we want.


was (Author: tilman):
I looked at the issue again. We don't know at in buildFontFile2 how the font was created.

What we could do is to pass some boolean (e.g. "closeOriginal" or "closeOnSubset") to TrueTypeEmbedder telling whether the font is to be closed or not. 

It isn't needed for the first TrueTypeEmbedder constructor / PDCIDFontType2Embedder constructor (which calls buildFontFile2) because ttf is null. So it's only the second constructor.

The good thing is that it's not public so we can do whatever we want.

> NPE if RAFDataStream.getCurrentPosition() when TrueTypeFont created from file is reused
> ---------------------------------------------------------------------------------------
>
>                 Key: PDFBOX-3826
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-3826
>             Project: PDFBox
>          Issue Type: Bug
>          Components: FontBox
>    Affects Versions: 2.0.6
>            Reporter: Tilman Hausherr
>              Labels: regression
>             Fix For: 2.0.7, 3.0.0
>
>
> {code}
> java.lang.NullPointerException: null
> 	at org.apache.fontbox.ttf.RAFDataStream.getCurrentPosition(RAFDataStream.java:88)
> 	at org.apache.fontbox.ttf.TrueTypeFont.getTableBytes(TrueTypeFont.java:121)
> 	at org.apache.fontbox.ttf.TTFSubsetter.writeToStream(TTFSubsetter.java:1012)
> 	at org.apache.pdfbox.pdmodel.font.TrueTypeEmbedder.subset(TrueTypeEmbedder.java:329)
> 	at org.apache.pdfbox.pdmodel.font.PDType0Font.subset(PDType0Font.java:162)
> 	at org.apache.pdfbox.pdmodel.PDDocument.save(PDDocument.java:1275)
> 	at org.apache.pdfbox.pdmodel.font.PDFontTest.testMultipleFontFileReuse(PDFontTest.java:160)
> {code}
> {code}
>     @Test
>     public void testMultipleFontFileReuse() throws IOException, URISyntaxException
>     {
>         URL url = PDFontTest.class.getClassLoader().getResource(
>                 "org/apache/pdfbox/ttf/LiberationSans-Regular.ttf");
>         File file = new File(url.toURI());
>         TrueTypeFont ttf = new TTFParser().parse(file);
>         for (int i = 0; i < 32; ++i)
>         {
>             try (PDDocument doc = new PDDocument())
>             {
>                 PDPage page = new PDPage();
>                 doc.addPage(page);
>                 PDFont font = PDType0Font.load(doc, ttf, true);
>                 try (PDPageContentStream cs = new PDPageContentStream(doc, page))
>                 {
>                     cs.beginText();
>                     cs.setFont(font, 10);
>                     cs.showText("testMultipleFontFileReuse");
>                     cs.endText();
>                 }
>                 doc.save(new ByteArrayOutputStream());
>             }
>         }
>     }
> {code}
> This happens only if the TrueTypeFont is created from a file, not when it is created from a stream (PDFBOX-3337). It worked in 2.0.0 but no longer since 2.0.1.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

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