@@ -95,4 +95,81 @@ public function testTextArrayObjects(): void
9595 // array.
9696 self ::assertSame ([' ' ], $ page4 ->getTextArray ());
9797 }
98+
99+ /**
100+ * Kerned TJ arrays split a word into many small string operands. Make sure
101+ * they end up in the right order again (issue #712).
102+ */
103+ public function testGetTextArrayReassemblesKernedTjArray (): void
104+ {
105+ $ document = new Document ();
106+ $ document ->init ();
107+
108+ $ content = 'BT /F1 12 Tf 10 10 Td '
109+ . '[(H)10(e)-5(l)3(l)20(o)-40( )30(W)5(o)-3(r)8(l)2(d)]TJ ET ' ;
110+
111+ $ form = new Form ($ document , null , $ content , new Config ());
112+ $ header = new Header ([
113+ 'Resources ' => new Header ([
114+ 'XObject ' => new Header ([
115+ 'Fr0 ' => $ form ,
116+ ])
117+ ]),
118+ 'Contents ' => new ElementArray ([new Element ('/Fr0 Do ' , $ document )], $ document ),
119+ ]);
120+ $ page = new Page ($ document , $ header );
121+
122+ self ::assertSame (['Hello World ' ], $ page ->getTextArray ());
123+ }
124+
125+ /**
126+ * A << ... >> BDC dictionary around a text block must not swallow the
127+ * text that follows it (issue #712).
128+ */
129+ public function testGetTextArrayRestoresMarkedContentDictionary (): void
130+ {
131+ $ document = new Document ();
132+ $ document ->init ();
133+
134+ $ content = '/OC << /MCID 0 /Foo (bar) >> BDC '
135+ . 'BT /F1 12 Tf 10 10 Td (Hello) Tj ET EMC ' ;
136+
137+ $ form = new Form ($ document , null , $ content , new Config ());
138+ $ header = new Header ([
139+ 'Resources ' => new Header ([
140+ 'XObject ' => new Header ([
141+ 'Fr0 ' => $ form ,
142+ ])
143+ ]),
144+ 'Contents ' => new ElementArray ([new Element ('/Fr0 Do ' , $ document )], $ document ),
145+ ]);
146+ $ page = new Page ($ document , $ header );
147+
148+ self ::assertSame (['Hello ' ], $ page ->getTextArray ());
149+ }
150+
151+ /**
152+ * A string can hold balanced unescaped parentheses; check they survive
153+ * extraction (issue #712).
154+ */
155+ public function testGetTextArrayKeepsBalancedParenthesesInsideString (): void
156+ {
157+ $ document = new Document ();
158+ $ document ->init ();
159+
160+ $ content = 'BT /F1 12 Tf 10 10 Td (a(b)c) Tj ET ' ;
161+
162+ $ form = new Form ($ document , null , $ content , new Config ());
163+ $ header = new Header ([
164+ 'Resources ' => new Header ([
165+ 'XObject ' => new Header ([
166+ 'Fr0 ' => $ form ,
167+ ])
168+ ]),
169+ 'Contents ' => new ElementArray ([new Element ('/Fr0 Do ' , $ document )], $ document ),
170+ ]);
171+ $ page = new Page ($ document , $ header );
172+
173+ self ::assertSame (['a(b)c ' ], $ page ->getTextArray ());
174+ }
98175}
0 commit comments