@@ -42,10 +42,13 @@ This file is part of the iText (R) project.
42
42
*/
43
43
package com .itextpdf .io .font .otf ;
44
44
45
+ import com .itextpdf .io .font .PdfEncodings ;
45
46
import com .itextpdf .io .font .TrueTypeFont ;
46
47
import com .itextpdf .io .util .StreamUtil ;
47
48
import com .itextpdf .test .ExtendedITextTest ;
48
49
import com .itextpdf .test .annotations .type .UnitTest ;
50
+
51
+ import java .io .FileNotFoundException ;
49
52
import org .junit .Assert ;
50
53
import org .junit .Test ;
51
54
import org .junit .experimental .categories .Category ;
@@ -192,4 +195,59 @@ public void testContentReplacingWithNullActualText() throws IOException {
192
195
// Test that no exception has been thrown. Also check the content.
193
196
Assert .assertEquals ("Belarus" , lineToBeReplaced .toString ());
194
197
}
198
+
199
+ @ Test
200
+ public void testActualTextForSubstitutedGlyphProcessingInSubstituteOneToMany01 () throws IOException {
201
+ String expectedActualTextForFirstGlyph = "0" ;
202
+ String expectedActualTextForSecondGlyph = "A" ;
203
+
204
+ byte [] ttf = StreamUtil .inputStreamToArray (new FileInputStream ("./src/test/resources/com/itextpdf/io/font/otf/FreeSans.ttf" ));
205
+ TrueTypeFont font = new TrueTypeFont (ttf );
206
+
207
+ // no actual text for the second glyph is set - it should be created during substitution
208
+ GlyphLine line = new GlyphLine (constructGlyphListFromString ("AA" , font ));
209
+ line .setActualText (0 , 1 , expectedActualTextForFirstGlyph );
210
+ line .idx = 1 ;
211
+
212
+ line .substituteOneToMany (font .getGsubTable (), new int [] {39 , 40 });
213
+
214
+ Assert .assertNotNull (line .actualText );
215
+ Assert .assertEquals (3 , line .actualText .size ());
216
+ Assert .assertSame (line .actualText .get (1 ), line .actualText .get (2 ));
217
+ Assert .assertEquals (expectedActualTextForSecondGlyph , line .actualText .get (1 ).value );
218
+ // check that it hasn't been corrupted
219
+ Assert .assertEquals (expectedActualTextForFirstGlyph , line .actualText .get (0 ).value );
220
+ }
221
+
222
+ @ Test
223
+ public void testActualTextForSubstitutedGlyphProcessingInSubstituteOneToMany02 () throws IOException {
224
+ String expectedActualTextForFirstGlyph = "A" ;
225
+
226
+ byte [] ttf = StreamUtil .inputStreamToArray (new FileInputStream ("./src/test/resources/com/itextpdf/io/font/otf/FreeSans.ttf" ));
227
+ TrueTypeFont font = new TrueTypeFont (ttf );
228
+
229
+ GlyphLine line = new GlyphLine (constructGlyphListFromString ("A" , font ));
230
+ line .setActualText (0 , 1 , expectedActualTextForFirstGlyph );
231
+
232
+ line .substituteOneToMany (font .getGsubTable (), new int [] {39 , 40 });
233
+
234
+ Assert .assertNotNull (line .actualText );
235
+ Assert .assertEquals (2 , line .actualText .size ());
236
+ Assert .assertSame (line .actualText .get (0 ), line .actualText .get (1 ));
237
+ Assert .assertEquals (expectedActualTextForFirstGlyph , line .actualText .get (0 ).value );
238
+ }
239
+
240
+ @ Test
241
+ public void testActualTextForSubstitutedGlyphProcessingInSubstituteOneToMany03 () throws IOException {
242
+ byte [] ttf = StreamUtil .inputStreamToArray (new FileInputStream ("./src/test/resources/com/itextpdf/io/font/otf/FreeSans.ttf" ));
243
+ TrueTypeFont font = new TrueTypeFont (ttf );
244
+
245
+ // no actual text is set
246
+ GlyphLine line = new GlyphLine (constructGlyphListFromString ("A" , font ));
247
+
248
+ line .substituteOneToMany (font .getGsubTable (), new int [] {39 , 40 });
249
+
250
+ Assert .assertNull (line .actualText );
251
+ }
195
252
}
253
+
0 commit comments