THausherr commented on PR #203:
URL: https://github.com/apache/pdfbox/pull/203#issuecomment-2691116655
This test passes:
```
@Test
void testEmbeddedFontWithZeroWidthChars() throws IOException
{
String text = "AAA\u200CBBB";
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int code;
try (PDDocument document = new PDDocument())
{
PDPage page = new PDPage();
document.addPage(page);
InputStream input = PDFont.class.getResourceAsStream(
"/org/apache/pdfbox/resources/ttf/LiberationSans-Regular.ttf");
PDType0Font font = PDType0Font.load(document, input);
byte[] encoded = font.encode('\u200C');
assertEquals(2, encoded.length);
code = ((encoded[0] & 0xFF) << 8) | (encoded[1] & 0xFF);
try (PDPageContentStream stream = new PDPageContentStream(document,
page))
{
stream.beginText();
stream.setFont(font, 20);
stream.newLineAtOffset(50, 600);
stream.showText(text);
stream.endText();
}
document.save(baos);
}
try (PDDocument document = Loader.loadPDF(baos.toByteArray()))
{
// verify that the text still contains zero-width characters
PDFTextStripper stripper = new PDFTextStripper();
String extractedText = stripper.getText(document);
assertEquals(text, extractedText.trim());
// verify that the zero-width characters are invisible
PDPage page = document.getPage(0);
PDResources resources = page.getResources();
Iterable< COSName > fontNames = resources.getFontNames();
COSName fontName = fontNames.iterator().next();
PDType0Font font = (PDType0Font) resources.getFont(fontName);
assertEquals(0, font.getWidth(code));
assertEquals(0, font.getWidthFromFont(code));
assertTrue(font.getPath(code).getBounds2D().isEmpty());
}
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]