Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -119,21 +119,50 @@ public class PdfSignatureAppearance {
/**
* Commands to draw a yellow question mark in a stream content
*/
public static final String questionMark = "% DSUnknown\n" + "q\n" + "1 G\n"
+ "1 g\n" + "0.1 0 0 0.1 9 0 cm\n" + "0 J 0 j 4 M []0 d\n" + "1 i \n"
+ "0 g\n" + "313 292 m\n" + "313 404 325 453 432 529 c\n"
+ "478 561 504 597 504 645 c\n" + "504 736 440 760 391 760 c\n"
+ "286 760 271 681 265 626 c\n" + "265 625 l\n" + "100 625 l\n"
+ "100 828 253 898 381 898 c\n" + "451 898 679 878 679 650 c\n"
+ "679 555 628 499 538 435 c\n" + "488 399 467 376 467 292 c\n"
+ "313 292 l\n" + "h\n" + "308 214 170 -164 re\n" + "f\n" + "0.44 G\n"
+ "1.2 w\n" + "1 1 0.4 rg\n" + "287 318 m\n"
+ "287 430 299 479 406 555 c\n" + "451 587 478 623 478 671 c\n"
+ "478 762 414 786 365 786 c\n" + "260 786 245 707 239 652 c\n"
+ "239 651 l\n" + "74 651 l\n" + "74 854 227 924 355 924 c\n"
+ "425 924 653 904 653 676 c\n" + "653 581 602 525 512 461 c\n"
+ "462 425 441 402 441 318 c\n" + "287 318 l\n" + "h\n"
+ "282 240 170 -164 re\n" + "B\n" + "Q\n";
public static final String questionMark = """
% DSUnknown
q
1 G
1 g
0.1 0 0 0.1 9 0 cm
0 J 0 j 4 M []0 d
1 i\s
0 g
313 292 m
313 404 325 453 432 529 c
478 561 504 597 504 645 c
504 736 440 760 391 760 c
286 760 271 681 265 626 c
265 625 l
100 625 l
100 828 253 898 381 898 c
451 898 679 878 679 650 c
679 555 628 499 538 435 c
488 399 467 376 467 292 c
313 292 l
h
308 214 170 -164 re
f
0.44 G
1.2 w
1 1 0.4 rg
287 318 m
287 430 299 479 406 555 c
451 587 478 623 478 671 c
478 762 414 786 365 786 c
260 786 245 707 239 652 c
239 651 l
74 651 l
74 854 227 924 355 924 c
425 924 653 904 653 676 c
653 581 602 525 512 461 c
462 425 441 402 441 318 c
287 318 l
h
282 240 170 -164 re
B
Q
""";
private static final float TOP_SECTION = 0.3f;
private static final float MARGIN = 2;
private final PdfTemplate[] app = new PdfTemplate[5];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,19 +265,21 @@ private PdfStream getToUnicode(int[][] metrics) {
return null;
}
StringBuilder buf = new StringBuilder(
"/CIDInit /ProcSet findresource begin\n" +
"12 dict begin\n" +
"begincmap\n" +
"/CIDSystemInfo\n" +
"<< /Registry (TTX+0)\n" +
"/Ordering (T42UV)\n" +
"/Supplement 0\n" +
">> def\n" +
"/CMapName /TTX+0 def\n" +
"/CMapType 2 def\n" +
"1 begincodespacerange\n" +
"<0000><FFFF>\n" +
"endcodespacerange\n");
"""
/CIDInit /ProcSet findresource begin
12 dict begin
begincmap
/CIDSystemInfo
<< /Registry (TTX+0)
/Ordering (T42UV)
/Supplement 0
>> def
/CMapName /TTX+0 def
/CMapType 2 def
1 begincodespacerange
<0000><FFFF>
endcodespacerange
""");
int size = 0;
for (int k = 0; k < metrics.length; ++k) {
if (size == 0) {
Expand All @@ -295,10 +297,12 @@ private PdfStream getToUnicode(int[][] metrics) {
buf.append(fromTo).append(fromTo).append(hexString).append('\n');
}
buf.append(
"endbfrange\n" +
"endcmap\n" +
"CMapName currentdict /CMap defineresource pop\n" +
"end end\n");
"""
endbfrange
endcmap
CMapName currentdict /CMap defineresource pop
end end
""");
String s = buf.toString();
PdfStream stream = new PdfStream(PdfEncodings.convertToBytes(s, null));
stream.flateCompress(compressionLevel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,14 @@ void whenLayoutRightToLeftLatinThenRevertCharOrder() throws IOException {
PdfTextExtractor extractor = new PdfTextExtractor(new PdfReader(pdfOut.toByteArray()));
String textFromPage = extractor.getTextFromPage(1);
assertThat(textFromPage)
.isEqualTo("owTytnewt enOεytnewt ytnewt neetenin neethgie neetneves neetxis neetfif neetruof neetriht "
+ "evlewt nevele net enin thgie neves xis evif ruof eerht owt eno\n"
+ " evlewt nevele net enin thgie neves xis evif ruof eerht owt eno ytriht eniNytnewt thgiEytnewt "
+ "neveSytnewt xiSytnewt eviFytnewt ruoFytnewt eerhTytnewt\n"
+ " neveSytnewt xiSytnewt eviFytnewt ruoFytnewt eerhTytnewt owTytnewt enOεytnewt ytnewt neetenin n"
+ "eethgie neetneves neetxis neetfif neetruof neetriht\n"
+ " ytriht eniNytnewt thgiEytnewt");
.isEqualTo("""
owTytnewt enOεytnewt ytnewt neetenin neethgie neetneves neetxis neetfif neetruof neetriht \
evlewt nevele net enin thgie neves xis evif ruof eerht owt eno
evlewt nevele net enin thgie neves xis evif ruof eerht owt eno ytriht eniNytnewt thgiEytnewt \
neveSytnewt xiSytnewt eviFytnewt ruoFytnewt eerhTytnewt
neveSytnewt xiSytnewt eviFytnewt ruoFytnewt eerhTytnewt owTytnewt enOεytnewt ytnewt neetenin n\
eethgie neetneves neetxis neetfif neetruof neetriht
ytriht eniNytnewt thgiEytnewt""");
}

@Test
Expand All @@ -90,14 +91,15 @@ void whenLayoutRightToLeftHebrewThenRevertCharOrder() throws IOException {
// then
byte[] pdfBytes = pdfOut.toByteArray();
PdfTextExtractor extractor = new PdfTextExtractor(new PdfReader(pdfBytes));
String expected = ".ויה אלש םירבדה ןמ יושע ,דהדהמ ,לולח טקש היה וילאמ"
+ " שקבתמה קלחה.םיקלח השולש תב הממד וז התיהו ,ךרדה־ןבא קדנופב הררש הממד .הליל תעש וז התיה בוש\n"
+ " וליא .ויתס ילע תפרוג איהש יפכ ,ךרדה דרומב הממדהתא"
+ " תפחוסו ויריצ לע הקירחב קדנופה טלש תא תלטלטמ ,םיצעה ןיב הרבועב תחנאנ התיה זאיכ ,חור התיה וליא\n"
+ " וליא .תוכושחה הלילה תועשב,האבסמב םהל תופַצל"
+ " םוקמ היהש ןואשבו הלומהב ,קוחצבו החישב הממדה תא םיאלממ ויה זאיכ ,םישנא ץמוק וליפא ,קדנופב להק היה\n"
+ " .הניעב הממדה"
+ " הרתונ ןכלו ,םש היה הלאה םירבדהמ דחא אלףא ,תמאה ןעמל .הקיסומ התיה אלש יאדו , אל לבא ...הקיסומ התיה";
String expected = """
.ויה אלש םירבדה ןמ יושע ,דהדהמ ,לולח טקש היה וילאמ\
שקבתמה קלחה.םיקלח השולש תב הממד וז התיהו ,ךרדה־ןבא קדנופב הררש הממד .הליל תעש וז התיה בוש
וליא .ויתס ילע תפרוג איהש יפכ ,ךרדה דרומב הממדהתא\
תפחוסו ויריצ לע הקירחב קדנופה טלש תא תלטלטמ ,םיצעה ןיב הרבועב תחנאנ התיה זאיכ ,חור התיה וליא
וליא .תוכושחה הלילה תועשב,האבסמב םהל תופַצל\
םוקמ היהש ןואשבו הלומהב ,קוחצבו החישב הממדה תא םיאלממ ויה זאיכ ,םישנא ץמוק וליפא ,קדנופב להק היה
.הניעב הממדה\
הרתונ ןכלו ,םש היה הלאה םירבדהמ דחא אלףא ,תמאה ןעמל .הקיסומ התיה אלש יאדו , אל לבא ...הקיסומ התיה""";
assertThat(extractor.getTextFromPage(1))
.isEqualTo(expected);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -492,10 +492,11 @@ void testReadIssue60102PaeoeaaUtf8() throws IOException {
Assertions.assertTrue(isOwnerPasswordUsed(pdfReader), "PdfReader fails to report full permissions.");
Assertions.assertEquals(10, pdfReader.getNumberOfPages(),
"PdfReader fails to report the correct number of pages");
Assertions.assertEquals("Sample PDF Document\n"
+ " Robert Maron\n"
+ " Grzegorz Grudzi´ nski\n"
+ " February 20, 1999", new PdfTextExtractor(pdfReader).getTextFromPage(1),
Assertions.assertEquals("""
Sample PDF Document
Robert Maron
Grzegorz Grudzi´ nski
February 20, 1999""", new PdfTextExtractor(pdfReader).getTextFromPage(1),
"Wrong text extracted from page 1");
pdfReader.close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,33 @@ public static void main(String[] args) {
// step 6: put your drawing instruction in the painter canvas

// A star pattern taken from Adobe PDF Reference Book p.207
String star = "0.3 g\n15.000 27.000 m\n"
+ "7.947 5.292 l\n26.413 18.708 l\n"
+ "3.587 18.708 l\n22.053 5.292 l\nf\n"
+ "45.000 57.000 m\n37.947 35.292 l\n"
+ "56.413 48.708 l\n33.587 48.708 l\n"
+ "52.053 35.292 l\nf\n"
+ "0.7 g\n15.000 57.000 m\n"
+ "7.947 35.292 l\n26.413 48.708 l\n"
+ "3.587 48.708 l\n22.053 35.292 l\nf\n"
+ "45.000 27.000 m\n37.947 5.292 l\n"
+ "56.413 18.708 l\n33.587 18.708 l\n"
+ "52.053 5.292 l\nf";
String star = """
0.3 g
15.000 27.000 m
7.947 5.292 l
26.413 18.708 l
3.587 18.708 l
22.053 5.292 l
f
45.000 57.000 m
37.947 35.292 l
56.413 48.708 l
33.587 48.708 l
52.053 35.292 l
f
0.7 g
15.000 57.000 m
7.947 35.292 l
26.413 48.708 l
3.587 48.708 l
22.053 35.292 l
f
45.000 27.000 m
37.947 5.292 l
56.413 18.708 l
33.587 18.708 l
52.053 5.292 l
f""";

p.setLiteral(star);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,33 @@ public static void main(String[] args) {

// step 4: we grab the ContentByte and do some stuff with it
PdfContentByte cb = writer.getDirectContent();
String star = "0.3 g\n15.000 27.000 m\n"
+ "7.947 5.292 l\n26.413 18.708 l\n"
+ "3.587 18.708 l\n22.053 5.292 l\nf\n"
+ "45.000 57.000 m\n37.947 35.292 l\n"
+ "56.413 48.708 l\n33.587 48.708 l\n"
+ "52.053 35.292 l\nf\n"
+ "0.7 g\n15.000 57.000 m\n"
+ "7.947 35.292 l\n26.413 48.708 l\n"
+ "3.587 48.708 l\n22.053 35.292 l\nf\n"
+ "45.000 27.000 m\n37.947 5.292 l\n"
+ "56.413 18.708 l\n33.587 18.708 l\n"
+ "52.053 5.292 l\nf";
String star = """
0.3 g
15.000 27.000 m
7.947 5.292 l
26.413 18.708 l
3.587 18.708 l
22.053 5.292 l
f
45.000 57.000 m
37.947 35.292 l
56.413 48.708 l
33.587 48.708 l
52.053 35.292 l
f
0.7 g
15.000 57.000 m
7.947 35.292 l
26.413 48.708 l
3.587 48.708 l
22.053 35.292 l
f
45.000 27.000 m
37.947 5.292 l
56.413 18.708 l
33.587 18.708 l
52.053 5.292 l
f""";
cb.setLiteral(star);

// sanityCheck doesn't check literals.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@
public class GlyphLayoutDocumentBidi {

public static String INTRO_TEXT =
"Test of bidirectional text\n" +
"Using LayoutProcessor for glyph layout with Java built-in routines.\n\n";
"""
Test of bidirectional text
Using LayoutProcessor for glyph layout with Java built-in routines.

""";

/**
* Main method
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@
public class GlyphLayoutDocumentBidiPerFont {

public static String INTRO_TEXT =
"Test of bidirectional text\n" +
"Using LayoutProcessor for glyph layout with Java built-in routines.\n\n";
"""
Test of bidirectional text
Using LayoutProcessor for glyph layout with Java built-in routines.

""";

/**
* Main method
Expand Down
Loading