@@ -46,6 +46,7 @@ This file is part of the iText (R) project.
46
46
import com .itextpdf .io .font .otf .GlyphLine ;
47
47
import com .itextpdf .kernel .colors .Color ;
48
48
import com .itextpdf .kernel .font .PdfFont ;
49
+ import com .itextpdf .kernel .font .PdfType0Font ;
49
50
import com .itextpdf .kernel .geom .LineSegment ;
50
51
import com .itextpdf .kernel .geom .Matrix ;
51
52
import com .itextpdf .kernel .geom .Vector ;
@@ -546,24 +547,28 @@ private int getCharCode(String string) {
546
547
/**
547
548
* Split PDF string into array of single character PDF strings.
548
549
*
549
- * @param string PDF string to be splitted .
550
- * @return splitted PDF string.
550
+ * @param string PDF string to be split .
551
+ * @return split PDF string.
551
552
*/
552
553
private PdfString [] splitString (PdfString string ) {
553
554
checkGraphicsState ();
554
- List <PdfString > strings = new ArrayList <>();
555
- String stringValue = string .getValue ();
556
- for (int i = 0 ; i < stringValue .length (); i ++) {
557
- PdfString newString = new PdfString (stringValue .substring (i , i + 1 ), string .getEncoding ());
558
-
559
- String text = gs .getFont ().decode (newString );
560
- if (text .length () == 0 && i < stringValue .length () - 1 ) {
561
- newString = new PdfString (stringValue .substring (i , i + 2 ), string .getEncoding ());
562
- i ++;
555
+ PdfFont font = gs .getFont ();
556
+ if (font instanceof PdfType0Font ) {
557
+ // Number of bytes forming one glyph can be arbitrary from [1; 4] range
558
+ List <PdfString > strings = new ArrayList <>();
559
+ GlyphLine glyphLine = gs .getFont ().decodeIntoGlyphLine (string );
560
+ for (int i = glyphLine .start ; i < glyphLine .end ; i ++) {
561
+ strings .add (new PdfString (gs .getFont ().convertToBytes (glyphLine .get (i ))));
563
562
}
564
- strings .add (newString );
563
+ return strings .toArray (new PdfString [strings .size ()]);
564
+ } else {
565
+ // One byte corresponds to one character
566
+ PdfString [] strings = new PdfString [string .getValue ().length ()];
567
+ for (int i = 0 ; i < string .getValue ().length (); i ++) {
568
+ strings [i ] = new PdfString (string .getValue ().substring (i , i + 1 ), string .getEncoding ());
569
+ }
570
+ return strings ;
565
571
}
566
- return strings .toArray (new PdfString [strings .size ()]);
567
572
}
568
573
569
574
private float [] getAscentDescent () {
0 commit comments