Skip to content

Commit 6828a92

Browse files
ars18wrwiText-CI
authored andcommitted
If one glyph is substituted to many glyphs, actual text should be distributed
DEVSIX-4529 Autoported commit. Original commit hash: [99260f10c]
1 parent f0f185e commit 6828a92

File tree

4 files changed

+62
-1
lines changed

4 files changed

+62
-1
lines changed

itext.tests/itext.io.tests/itext/io/font/otf/GlyphLineTest.cs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,5 +175,54 @@ public virtual void TestContentReplacingWithNullActualText() {
175175
// Test that no exception has been thrown. Also check the content.
176176
NUnit.Framework.Assert.AreEqual("Belarus", lineToBeReplaced.ToString());
177177
}
178+
179+
[NUnit.Framework.Test]
180+
public virtual void TestActualTextForSubstitutedGlyphProcessingInSubstituteOneToMany01() {
181+
String expectedActualTextForFirstGlyph = "0";
182+
String expectedActualTextForSecondGlyph = "A";
183+
byte[] ttf = StreamUtil.InputStreamToArray(new FileStream(iText.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
184+
.CurrentContext.TestDirectory) + "/resources/itext/io/font/otf/FreeSans.ttf", FileMode.Open, FileAccess.Read
185+
));
186+
TrueTypeFont font = new TrueTypeFont(ttf);
187+
// no actual text for the second glyph is set - it should be created during substitution
188+
GlyphLine line = new GlyphLine(ConstructGlyphListFromString("AA", font));
189+
line.SetActualText(0, 1, expectedActualTextForFirstGlyph);
190+
line.idx = 1;
191+
line.SubstituteOneToMany(font.GetGsubTable(), new int[] { 39, 40 });
192+
NUnit.Framework.Assert.IsNotNull(line.actualText);
193+
NUnit.Framework.Assert.AreEqual(3, line.actualText.Count);
194+
NUnit.Framework.Assert.AreSame(line.actualText[1], line.actualText[2]);
195+
NUnit.Framework.Assert.AreEqual(expectedActualTextForSecondGlyph, line.actualText[1].value);
196+
// check that it hasn't been corrupted
197+
NUnit.Framework.Assert.AreEqual(expectedActualTextForFirstGlyph, line.actualText[0].value);
198+
}
199+
200+
[NUnit.Framework.Test]
201+
public virtual void TestActualTextForSubstitutedGlyphProcessingInSubstituteOneToMany02() {
202+
String expectedActualTextForFirstGlyph = "A";
203+
byte[] ttf = StreamUtil.InputStreamToArray(new FileStream(iText.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
204+
.CurrentContext.TestDirectory) + "/resources/itext/io/font/otf/FreeSans.ttf", FileMode.Open, FileAccess.Read
205+
));
206+
TrueTypeFont font = new TrueTypeFont(ttf);
207+
GlyphLine line = new GlyphLine(ConstructGlyphListFromString("A", font));
208+
line.SetActualText(0, 1, expectedActualTextForFirstGlyph);
209+
line.SubstituteOneToMany(font.GetGsubTable(), new int[] { 39, 40 });
210+
NUnit.Framework.Assert.IsNotNull(line.actualText);
211+
NUnit.Framework.Assert.AreEqual(2, line.actualText.Count);
212+
NUnit.Framework.Assert.AreSame(line.actualText[0], line.actualText[1]);
213+
NUnit.Framework.Assert.AreEqual(expectedActualTextForFirstGlyph, line.actualText[0].value);
214+
}
215+
216+
[NUnit.Framework.Test]
217+
public virtual void TestActualTextForSubstitutedGlyphProcessingInSubstituteOneToMany03() {
218+
byte[] ttf = StreamUtil.InputStreamToArray(new FileStream(iText.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
219+
.CurrentContext.TestDirectory) + "/resources/itext/io/font/otf/FreeSans.ttf", FileMode.Open, FileAccess.Read
220+
));
221+
TrueTypeFont font = new TrueTypeFont(ttf);
222+
// no actual text is set
223+
GlyphLine line = new GlyphLine(ConstructGlyphListFromString("A", font));
224+
line.SubstituteOneToMany(font.GetGsubTable(), new int[] { 39, 40 });
225+
NUnit.Framework.Assert.IsNull(line.actualText);
226+
}
178227
}
179228
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This software uses the following test resources under the following licenses:
2+
| FreeSans | GPL | https://www.gnu.org/licenses |
3+
| FreeSansBold | GPL | https://www.gnu.org/licenses |

itext/itext.io/itext/io/font/otf/GlyphLine.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ public virtual void SubstituteOneToOne(OpenTypeFontTableReader tableReader, int
290290
public virtual void SubstituteOneToMany(OpenTypeFontTableReader tableReader, int[] substGlyphIds) {
291291
//sequence length shall be at least 1
292292
int substCode = substGlyphIds[0];
293+
Glyph oldGlyph = glyphs[idx];
293294
Glyph glyph = tableReader.GetGlyph(substCode);
294295
glyphs[idx] = glyph;
295296
if (substGlyphIds.Length > 1) {
@@ -300,6 +301,14 @@ public virtual void SubstituteOneToMany(OpenTypeFontTableReader tableReader, int
300301
additionalGlyphs.Add(glyph);
301302
}
302303
AddAllGlyphs(idx + 1, additionalGlyphs);
304+
if (null != actualText) {
305+
if (null == actualText[idx]) {
306+
actualText[idx] = new GlyphLine.ActualText(oldGlyph.GetUnicodeString());
307+
}
308+
for (int i = 0; i < additionalGlyphs.Count; i++) {
309+
this.actualText[idx + 1 + i] = actualText[idx];
310+
}
311+
}
303312
idx += substGlyphIds.Length - 1;
304313
end += substGlyphIds.Length - 1;
305314
}

port-hash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1d721562c3563cdc12b0e86d75878c5f7e75acd1
1+
99260f10c6c7948795869681f085f9f5f9871784

0 commit comments

Comments
 (0)