Skip to content

Commit 4e29669

Browse files
committed
Update cursor position after glyph with offset
DEVSIX-369
1 parent d2ff483 commit 4e29669

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

canvas/src/main/java/com/itextpdf/canvas/PdfCanvas.java

+13-14
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ public void applyKerning(GlyphLine text) {
201201
for (int i = 1; i < text.size(); i++) {
202202
int kern = font.getKerning(text.glyphs.get(i - 1), text.glyphs.get(i));
203203
if (kern != 0) {
204-
text.glyphs.set(i, new Glyph(text.glyphs.get(i), 0, 0, kern, 0, 0));
204+
text.glyphs.set(i - 1, new Glyph(text.glyphs.get(i - 1), 0, 0, kern, 0, 0));
205205
}
206206
}
207207
}
@@ -612,17 +612,16 @@ public PdfCanvas showText(GlyphLine text) {
612612
float w = 0;
613613
for (int i = 0; i < text.size(); i++) {
614614
Glyph glyph = text.glyphs.get(i);
615+
w += (glyph.getWidth() * fs + c) * h;
615616
if (glyph.hasOffsets()) {
616-
if (i - sub > 0) {
617-
font.writeText(text, sub, i - 1, contentStream.getOutputStream());
618-
contentStream.getOutputStream().writeBytes(Tj);
619-
contentStream.getOutputStream()
620-
.writeFloat(w)
621-
.writeSpace()
622-
.writeFloat(0)
623-
.writeSpace()
624-
.writeBytes(Td);
625-
}
617+
font.writeText(text, sub, i, contentStream.getOutputStream());
618+
contentStream.getOutputStream().writeBytes(Tj);
619+
contentStream.getOutputStream()
620+
.writeFloat(w)
621+
.writeSpace()
622+
.writeFloat(0)
623+
.writeSpace()
624+
.writeBytes(Td);
626625

627626
if (glyph.hasPlacement()) {
628627
//TODO
@@ -631,14 +630,14 @@ public PdfCanvas showText(GlyphLine text) {
631630
contentStream.getOutputStream()
632631
.writeFloat((glyph.getXAdvance()) * fs * h)
633632
.writeSpace()
634-
.writeFloat(glyph.getYAdvance() * fs)
633+
.writeFloat(0)//glyph.getYAdvance() * fs)// TODO we shall return previous y position
635634
.writeSpace()
636635
.writeBytes(Td);
637636
}
638-
sub = i;
637+
sub = i + 1;
639638
w = 0;
640639
}
641-
w += (glyph.getWidth() * fs + c) * h;
640+
642641
}
643642
if (text.size() - sub > 0) {
644643
font.writeText(text, sub, text.size() - 1, contentStream.getOutputStream());

0 commit comments

Comments
 (0)