Skip to content

Commit e414356

Browse files
yulian-gaponenkoiText-CI
authored andcommitted
Make glyphs independent in bidi-reordered line from pre-reordering
DEVSIX-5161 Autoported commit. Original commit hash: [20a73e3e8]
1 parent 3e9c9d7 commit e414356

File tree

3 files changed

+58
-11
lines changed

3 files changed

+58
-11
lines changed

itext.tests/itext.layout.tests/itext/layout/renderer/TypographyUtilsTest.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ source product.
4040
For more information, please contact iText Software Corp. at this
4141
4242
*/
43+
using System.Collections.Generic;
44+
using iText.IO.Font.Otf;
45+
using iText.IO.Util;
4346
using iText.Test;
4447

4548
namespace iText.Layout.Renderer {
@@ -48,5 +51,41 @@ public class TypographyUtilsTest : ExtendedITextTest {
4851
public virtual void VerifyPdfCalligraphIsNotAvailable() {
4952
NUnit.Framework.Assert.IsFalse(TypographyUtils.IsPdfCalligraphAvailable());
5053
}
54+
55+
[NUnit.Framework.Test]
56+
public virtual void UpdateAnchorDeltaMarkNotReorderedTest() {
57+
// original line 'abm', and 'm' is a mark based on 'b'
58+
Glyph mGlyph = new Glyph(100, 'm');
59+
mGlyph.SetAnchorDelta((short)-1);
60+
mGlyph.SetXAdvance((short)15);
61+
mGlyph.SetYAdvance((short)25);
62+
LineRenderer.RendererGlyph b = new LineRenderer.RendererGlyph(new Glyph(100, 'b'), null);
63+
LineRenderer.RendererGlyph m = new LineRenderer.RendererGlyph(mGlyph, null);
64+
LineRenderer.RendererGlyph a = new LineRenderer.RendererGlyph(new Glyph(100, 'a'), null);
65+
IList<LineRenderer.RendererGlyph> reorderedLine = JavaUtil.ArraysAsList(b, m, a);
66+
int[] reorder = new int[] { 1, 2, 0 };
67+
int[] inverseReorder = new int[] { 2, 0, 1 };
68+
TypographyUtils.UpdateAnchorDeltaForReorderedLineGlyphs(reorder, inverseReorder, reorderedLine);
69+
NUnit.Framework.Assert.AreSame(mGlyph, m.glyph);
70+
NUnit.Framework.Assert.AreEqual(-1, m.glyph.GetAnchorDelta());
71+
}
72+
73+
[NUnit.Framework.Test]
74+
public virtual void UpdateAnchorDeltaMarkReorderedTest() {
75+
// original line 'abm', and 'm' is a mark based on 'b'
76+
Glyph mGlyph = new Glyph(100, 'm');
77+
mGlyph.SetAnchorDelta((short)-1);
78+
mGlyph.SetXAdvance((short)15);
79+
mGlyph.SetYAdvance((short)25);
80+
LineRenderer.RendererGlyph m = new LineRenderer.RendererGlyph(mGlyph, null);
81+
LineRenderer.RendererGlyph b = new LineRenderer.RendererGlyph(new Glyph(100, 'b'), null);
82+
LineRenderer.RendererGlyph a = new LineRenderer.RendererGlyph(new Glyph(100, 'a'), null);
83+
IList<LineRenderer.RendererGlyph> reorderedLine = JavaUtil.ArraysAsList(m, b, a);
84+
int[] reorder = new int[] { 2, 1, 0 };
85+
int[] inverseReorder = new int[] { 2, 1, 0 };
86+
TypographyUtils.UpdateAnchorDeltaForReorderedLineGlyphs(reorder, inverseReorder, reorderedLine);
87+
NUnit.Framework.Assert.AreNotSame(mGlyph, m.glyph);
88+
NUnit.Framework.Assert.AreEqual(1, m.glyph.GetAnchorDelta());
89+
}
5190
}
5291
}

itext/itext.layout/itext/layout/renderer/TypographyUtils.cs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -236,16 +236,7 @@ internal static int[] ReorderLine(IList<LineRenderer.RendererGlyph> line, byte[]
236236
}
237237
}
238238
}
239-
// fix anchorDelta
240-
for (int i = 0; i < reorderedLine.Count; i++) {
241-
Glyph glyph = reorderedLine[i].glyph;
242-
if (glyph.HasPlacement()) {
243-
int oldAnchor = reorder[i] + glyph.GetAnchorDelta();
244-
int newPos = inverseReorder[oldAnchor];
245-
int newAnchorDelta = newPos - i;
246-
glyph.SetAnchorDelta((short)newAnchorDelta);
247-
}
248-
}
239+
UpdateAnchorDeltaForReorderedLineGlyphs(reorder, inverseReorder, reorderedLine);
249240
line.Clear();
250241
line.AddAll(reorderedLine);
251242
return reorder;
@@ -279,6 +270,23 @@ internal static IList<int> GetPossibleBreaks(String str) {
279270
String) }, str);
280271
}
281272

273+
internal static void UpdateAnchorDeltaForReorderedLineGlyphs(int[] reorder, int[] inverseReorder, IList<LineRenderer.RendererGlyph
274+
> reorderedLine) {
275+
for (int i = 0; i < reorderedLine.Count; i++) {
276+
Glyph glyph = reorderedLine[i].glyph;
277+
if (glyph.HasPlacement()) {
278+
int oldAnchor = reorder[i] + glyph.GetAnchorDelta();
279+
int newPos = inverseReorder[oldAnchor];
280+
int newAnchorDelta = newPos - i;
281+
if (glyph.GetAnchorDelta() != newAnchorDelta) {
282+
glyph = new Glyph(glyph);
283+
reorderedLine[i].glyph = glyph;
284+
glyph.SetAnchorDelta((short)newAnchorDelta);
285+
}
286+
}
287+
}
288+
}
289+
282290
private static Object CallMethod(String className, String methodName, Type[] parameterTypes, params Object
283291
[] args) {
284292
return CallMethod(className, methodName, (Object)null, parameterTypes, args);

port-hash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
110246b0030a7779e696394f4b6435e4c3c81468
1+
20a73e3e8cd223bca411d62b4420115265218873

0 commit comments

Comments
 (0)