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

Leonard Wicke updated PDFBOX-5849:
----------------------------------
    Description: 
We are using Apache PDFBox 3.0.2 in our software and have the following issue.
We want to write a String using the font FreeSansBold.
The font is loaded via PDType0Font#load from a TTF-file.

If we load the font with embedSubset=true than the following exception occurs:
{code:java}
java.lang.ArrayIndexOutOfBoundsException: Index 2941 out of bounds for length 
2912
at 
org.apache.fontbox.ttf.TTFSubsetter.addCompoundReferences(TTFSubsetter.java:500)
at org.apache.fontbox.ttf.TTFSubsetter.getGIDMap(TTFSubsetter.java:147)
at 
org.apache.pdfbox.pdmodel.font.TrueTypeEmbedder.subset(TrueTypeEmbedder.java:336)
at org.apache.pdfbox.pdmodel.font.PDType0Font.subset(PDType0Font.java:304)
at 
org.apache.pdfbox.pdmodel.PDDocument.subsetDesignatedFonts(PDDocument.java:1046)
at org.apache.pdfbox.pdmodel.PDDocument.save(PDDocument.java:1034)
at org.apache.pdfbox.pdmodel.PDDocument.save(PDDocument.java:988)
at org.apache.pdfbox.pdmodel.PDDocument.save(PDDocument.java:944){code}
The reason is the question-mark-character "?". The character "!" also causes an 
exception.
Letters like a-zA-Z dont.

This character is first correctly identified as Glyph-ID 34 but then in 
PDAbstractContentStream#encodeForGsub converted to 2914 by 
GsubWorkerForDevanagari.
This glyph does not exist for this font.
This causes an exception when subsetting the font.
The exception does not occur when writing the text in the PDPageContentStream.

If we load the font with embetSubst=false then no exception occurs but the 
character is not visible/skipped in the pdf.
I have only found old and fixed issues with ArrayIndexOutOfBoundsExceptions 
(https://issues.apache.org/jira/browse/PDFBOX-4946).

Code to redproduce (you need the font FreeSansBold):
{code:java}
PDDocument document = new PDDocument();
File boldF = new File("src/test/resources/fonts", "FreeSansBold.ttf");
TrueTypeFont boldT = new TTFParser().parse(new 
RandomAccessReadBufferedFile(boldF));
PDFont bold = PDType0Font.load(document, boldT, true);
PDPage page = new PDPage(PDRectangle.A4);
PDPageContentStream contentStream = new PDPageContentStream(document, page, 
PDPageContentStream.AppendMode.APPEND, true, true);
contentStream.setFont(bold, 11);
contentStream.beginText();
contentStream.newLineAtOffset(50, 50);
contentStream.showText("?");
contentStream.endText();
contentStream.close();
document.addPage(page);
document.save(new File("Test.pdf"));{code}

  was:
We are using Apache PDFBox 3.0.2 in our software and have the following issue.
We want to write a String using the font FreeSansBold.
The font is loaded via PDType0Font#load from a TTF-file.

If we load the font with embedSubset=true than the following exception occurs:

   
{code:java}
java.lang.ArrayIndexOutOfBoundsException: Index 2941 out of bounds for length 
2912
at 
org.apache.fontbox.ttf.TTFSubsetter.addCompoundReferences(TTFSubsetter.java:500)
at org.apache.fontbox.ttf.TTFSubsetter.getGIDMap(TTFSubsetter.java:147)
at 
org.apache.pdfbox.pdmodel.font.TrueTypeEmbedder.subset(TrueTypeEmbedder.java:336)
at org.apache.pdfbox.pdmodel.font.PDType0Font.subset(PDType0Font.java:304)
at 
org.apache.pdfbox.pdmodel.PDDocument.subsetDesignatedFonts(PDDocument.java:1046)
at org.apache.pdfbox.pdmodel.PDDocument.save(PDDocument.java:1034)
at org.apache.pdfbox.pdmodel.PDDocument.save(PDDocument.java:988)
at org.apache.pdfbox.pdmodel.PDDocument.save(PDDocument.java:944){code}
The reason is the question-mark-character "?". The character "!" also causes an 
exception.
Letters like a-zA-Z dont.

This character is first correctly identified as Glyph-ID 34 but then in 
PDAbstractContentStream#encodeForGsub converted to 2914 by 
GsubWorkerForDevanagari.
This glyph does not exist for this font.
This causes an exception when subsetting the font.
The exception does not occur when writing the text in the PDPageContentStream.

If we load the font with embetSubst=false then no exception occurs but the 
character is not visible/skipped in the pdf.
I have only found old and fixed issues with ArrayIndexOutOfBoundsExceptions 
(https://issues.apache.org/jira/browse/PDFBOX-4946).

Code to redproduce (you need the font FreeSansBold):
{code:java}
PDDocument document = new PDDocument();
File boldF = new File("src/test/resources/fonts", "FreeSansBold.ttf");
TrueTypeFont boldT = new TTFParser().parse(new 
RandomAccessReadBufferedFile(boldF));
PDFont bold = PDType0Font.load(document, boldT, true);
PDPage page = new PDPage(PDRectangle.A4);
PDPageContentStream contentStream = new PDPageContentStream(document, page, 
PDPageContentStream.AppendMode.APPEND, true, true);
contentStream.setFont(bold, 11);
contentStream.beginText();
contentStream.newLineAtOffset(50, 50);
contentStream.showText("?");
contentStream.endText();
contentStream.close();
document.addPage(page);
document.save(new File("Test.pdf"));{code}


> ArrayIndexOutOfBoundsException in Apache PDFBox 3 in connection with Font
> -------------------------------------------------------------------------
>
>                 Key: PDFBOX-5849
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-5849
>             Project: PDFBox
>          Issue Type: Bug
>          Components: FontBox, Rendering
>    Affects Versions: 3.0.2 PDFBox
>            Reporter: Leonard Wicke
>            Priority: Major
>
> We are using Apache PDFBox 3.0.2 in our software and have the following issue.
> We want to write a String using the font FreeSansBold.
> The font is loaded via PDType0Font#load from a TTF-file.
> If we load the font with embedSubset=true than the following exception occurs:
> {code:java}
> java.lang.ArrayIndexOutOfBoundsException: Index 2941 out of bounds for length 
> 2912
> at 
> org.apache.fontbox.ttf.TTFSubsetter.addCompoundReferences(TTFSubsetter.java:500)
> at org.apache.fontbox.ttf.TTFSubsetter.getGIDMap(TTFSubsetter.java:147)
> at 
> org.apache.pdfbox.pdmodel.font.TrueTypeEmbedder.subset(TrueTypeEmbedder.java:336)
> at org.apache.pdfbox.pdmodel.font.PDType0Font.subset(PDType0Font.java:304)
> at 
> org.apache.pdfbox.pdmodel.PDDocument.subsetDesignatedFonts(PDDocument.java:1046)
> at org.apache.pdfbox.pdmodel.PDDocument.save(PDDocument.java:1034)
> at org.apache.pdfbox.pdmodel.PDDocument.save(PDDocument.java:988)
> at org.apache.pdfbox.pdmodel.PDDocument.save(PDDocument.java:944){code}
> The reason is the question-mark-character "?". The character "!" also causes 
> an exception.
> Letters like a-zA-Z dont.
> This character is first correctly identified as Glyph-ID 34 but then in 
> PDAbstractContentStream#encodeForGsub converted to 2914 by 
> GsubWorkerForDevanagari.
> This glyph does not exist for this font.
> This causes an exception when subsetting the font.
> The exception does not occur when writing the text in the PDPageContentStream.
> If we load the font with embetSubst=false then no exception occurs but the 
> character is not visible/skipped in the pdf.
> I have only found old and fixed issues with ArrayIndexOutOfBoundsExceptions 
> (https://issues.apache.org/jira/browse/PDFBOX-4946).
> Code to redproduce (you need the font FreeSansBold):
> {code:java}
> PDDocument document = new PDDocument();
> File boldF = new File("src/test/resources/fonts", "FreeSansBold.ttf");
> TrueTypeFont boldT = new TTFParser().parse(new 
> RandomAccessReadBufferedFile(boldF));
> PDFont bold = PDType0Font.load(document, boldT, true);
> PDPage page = new PDPage(PDRectangle.A4);
> PDPageContentStream contentStream = new PDPageContentStream(document, page, 
> PDPageContentStream.AppendMode.APPEND, true, true);
> contentStream.setFont(bold, 11);
> contentStream.beginText();
> contentStream.newLineAtOffset(50, 50);
> contentStream.showText("?");
> contentStream.endText();
> contentStream.close();
> document.addPage(page);
> document.save(new File("Test.pdf"));{code}



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

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

Reply via email to