Skip to content

Commit b73b292

Browse files
committed
Fix a small bug in GlyphLine#equals
DEVSIX-1983
1 parent 72b3a94 commit b73b292

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

io/src/main/java/com/itextpdf/io/font/otf/GlyphLine.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,12 +338,12 @@ public boolean equals(Object obj) {
338338
int otherPos = other.start + i - start;
339339
Glyph myGlyph = get(i);
340340
Glyph otherGlyph = other.get(otherPos);
341-
if (myGlyph == null && otherGlyph != null || !myGlyph.equals(otherGlyph)) {
341+
if (myGlyph == null && otherGlyph != null || myGlyph != null && !myGlyph.equals(otherGlyph)) {
342342
return false;
343343
}
344344
ActualText myAT = actualText == null ? null : actualText.get(i);
345345
ActualText otherAT = other.actualText == null ? null : other.actualText.get(otherPos);
346-
if (myAT == null && otherAT != null || !myAT.equals(otherAT)) {
346+
if (myAT == null && otherAT != null || myAT != null && !myAT.equals(otherAT)) {
347347
return false;
348348
}
349349
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.itextpdf.io.font.otf;
2+
3+
import com.itextpdf.test.annotations.type.UnitTest;
4+
import org.junit.Assert;
5+
import org.junit.Test;
6+
import org.junit.experimental.categories.Category;
7+
8+
import java.util.ArrayList;
9+
import java.util.Arrays;
10+
11+
@Category(UnitTest.class)
12+
public class GlyphLineTest {
13+
14+
@Test
15+
public void testEquals() {
16+
Glyph glyph = new Glyph(200, 200, 200);
17+
GlyphLine.ActualText actualText = new GlyphLine.ActualText("-");
18+
19+
GlyphLine one = new GlyphLine(new ArrayList<Glyph>(Arrays.asList(glyph)), new ArrayList<GlyphLine.ActualText>(Arrays.asList(actualText)), 0, 1);
20+
GlyphLine two = new GlyphLine(new ArrayList<Glyph>(Arrays.asList(glyph)), new ArrayList<GlyphLine.ActualText>(Arrays.asList(actualText)), 0, 1);
21+
22+
one.add(glyph);
23+
two.add(glyph);
24+
25+
one.end++;
26+
two.end++;
27+
28+
Assert.assertTrue(one.equals(two));
29+
}
30+
31+
}

0 commit comments

Comments
 (0)