Skip to content

Commit ad7dcb4

Browse files
committed
PDFBOX-6085: add test, based on code by Constantine Dokolas
git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1929292 13f79535-47bb-0310-9956-ffa450edef68
1 parent 97ac0ab commit ad7dcb4

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

pdfbox/src/test/java/org/apache/pdfbox/pdmodel/font/TestFontEmbedding.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,50 @@ void testDevanagari() throws IOException
296296
//assertEquals(expectedExtractedtext, extracted.replaceAll("\r", "").trim());
297297
}
298298

299+
/**
300+
* PDFBOX-6085: test with the Noto font, this one has a zero width GID between other GIDs and
301+
* failed in the past. This "fails before the fix" only with the version 2.004, size 204.336
302+
* Bytes.
303+
*
304+
* @throws IOException
305+
*/
306+
@Test
307+
void testDevanagari2() throws IOException
308+
{
309+
File pdf = new File(OUT_DIR, "Devanagari2.pdf");
310+
try (PDDocument doc = new PDDocument())
311+
{
312+
PDPage page = new PDPage(PDRectangle.A4);
313+
doc.addPage(page);
314+
int[] codepoints = new int[]
315+
{
316+
2305, 2306, 2309, 2310, 2311, 2312, 2313, 2315, 2319, 2324, 2325, 2326, 2327, 2328, 2329, 2330, 2331, 2332,
317+
2333, 2335, 2336, 2337, 2339, 2340, 2341, 2342, 2343, 2344, 2346, 2348, 2349, 2350, 2351, 2352, 2354, 2355,
318+
2357, 2358, 2359, 2360, 2361, 2364, 2366, 2367, 2368, 2369, 2370, 2375, 2376, 2379, 2380, 2381, 2396, 2404,
319+
2406, 2407, 2408, 2409, 2410, 2411, 2414, 8204,
320+
};
321+
try (PDPageContentStream cs = new PDPageContentStream(doc, page))
322+
{
323+
InputStream is = TestFontEmbedding.class.getResourceAsStream("/org/apache/pdfbox/ttf/NotoSansDevanagari-Regular.ttf");
324+
PDType0Font font = PDType0Font.load(doc, is);
325+
String s = new String(codepoints, 0, codepoints.length);
326+
cs.beginText();
327+
cs.newLineAtOffset(20, 800);
328+
cs.setFont(font, 18);
329+
cs.showText(s);
330+
cs.endText();
331+
}
332+
doc.save(pdf);
333+
}
334+
335+
// compare rendering
336+
if (!TestPDFToImage.doTestFile(pdf, IN_DIR.getAbsolutePath(), OUT_DIR.getAbsolutePath()))
337+
{
338+
// don't fail, rendering is different on different systems, result must be viewed manually
339+
System.err.println("Rendering of " + pdf + " failed or is not identical to expected rendering in " + IN_DIR + " directory");
340+
}
341+
}
342+
299343
@Test
300344
void testGujarati() throws IOException
301345
{
16.9 KB
Loading
Binary file not shown.

0 commit comments

Comments
 (0)