Skip to content

Commit 6c8ab95

Browse files
LodrKumquatyulian-gaponenko
authored andcommitted
Support word-break property
DEVSIX-4422 Autoported commit. Original commit hash: [2af1b9a972] Manual files: io/src/main/java/com/itextpdf/io/util/TextUtil.java
1 parent 572ba63 commit 6c8ab95

File tree

12 files changed

+449
-79
lines changed

12 files changed

+449
-79
lines changed

itext.tests/itext.io.tests/itext/io/util/TextUtilTest.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,37 @@ public virtual void CarriageReturnPrecededByTextFollowedByLineFeedTest() {
8585
Helper(true, 1, new Glyph(0, 0, 'a'), carriageReturn, lineFeed);
8686
}
8787

88+
[NUnit.Framework.Test]
89+
public virtual void IsLetterPositiveTest() {
90+
Glyph glyph = new Glyph(0, 0, 'a');
91+
NUnit.Framework.Assert.IsTrue(iText.IO.Util.TextUtil.IsLetterOrDigit(glyph));
92+
}
93+
94+
[NUnit.Framework.Test]
95+
public virtual void IsDigitPositiveTest() {
96+
Glyph glyph = new Glyph(0, 0, '8');
97+
NUnit.Framework.Assert.IsTrue(iText.IO.Util.TextUtil.IsLetterOrDigit(glyph));
98+
}
99+
100+
[NUnit.Framework.Test]
101+
public virtual void IsLetterOrDigitNegativeTest() {
102+
Glyph glyph = new Glyph(0, 0, '-');
103+
NUnit.Framework.Assert.IsFalse(iText.IO.Util.TextUtil.IsLetterOrDigit(glyph));
104+
}
105+
106+
[NUnit.Framework.Test]
107+
public virtual void IsMarkPositiveTest() {
108+
// TAI THAM SIGN KHUEN TONE-3
109+
Glyph glyph = new Glyph(0, 0, 0x1A77);
110+
NUnit.Framework.Assert.IsTrue(iText.IO.Util.TextUtil.IsMark(glyph));
111+
}
112+
113+
[NUnit.Framework.Test]
114+
public virtual void IsMarkNegativeTest() {
115+
Glyph glyph = new Glyph(0, 0, '-');
116+
NUnit.Framework.Assert.IsFalse(iText.IO.Util.TextUtil.IsMark(glyph));
117+
}
118+
88119
private void Helper(bool expected, int currentCRPosition, params Glyph[] glyphs) {
89120
GlyphLine glyphLine = new GlyphLine(JavaUtil.ArraysAsList(glyphs));
90121
NUnit.Framework.Assert.IsTrue(expected == iText.IO.Util.TextUtil.IsCarriageReturnFollowedByLineFeed(glyphLine
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
This file is part of the iText (R) project.
3+
Copyright (c) 1998-2020 iText Group NV
4+
Authors: iText Software.
5+
6+
This program is offered under a commercial and under the AGPL license.
7+
For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below.
8+
9+
AGPL licensing:
10+
This program is free software: you can redistribute it and/or modify
11+
it under the terms of the GNU Affero General Public License as published by
12+
the Free Software Foundation, either version 3 of the License, or
13+
(at your option) any later version.
14+
15+
This program is distributed in the hope that it will be useful,
16+
but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
GNU Affero General Public License for more details.
19+
20+
You should have received a copy of the GNU Affero General Public License
21+
along with this program. If not, see <https://www.gnu.org/licenses/>.
22+
*/
23+
using System.Collections.Generic;
24+
using iText.IO.Font.Otf;
25+
using iText.Test;
26+
27+
namespace iText.Layout.Splitting {
28+
public class BreakAllSplitCharactersTest : ExtendedITextTest {
29+
private const char charWithFalse = '\u201b';
30+
31+
[NUnit.Framework.Test]
32+
public virtual void LastCharTest() {
33+
NUnit.Framework.Assert.IsFalse(IsSplitCharacter(new int[] { charWithFalse, charWithFalse, charWithFalse },
34+
1));
35+
NUnit.Framework.Assert.IsTrue(IsSplitCharacter(new int[] { charWithFalse, charWithFalse, charWithFalse },
36+
2));
37+
}
38+
39+
[NUnit.Framework.Test]
40+
public virtual void CurrentIsNotUnicodeTest() {
41+
NUnit.Framework.Assert.IsTrue(IsSplitCharacter(new int[] { charWithFalse, -1, charWithFalse }, 1));
42+
}
43+
44+
[NUnit.Framework.Test]
45+
public virtual void NextIsNotUnicodeTest() {
46+
NUnit.Framework.Assert.IsTrue(IsSplitCharacter(new int[] { charWithFalse, charWithFalse, -1 }, 1));
47+
}
48+
49+
[NUnit.Framework.Test]
50+
public virtual void BeforeSpaceTest() {
51+
NUnit.Framework.Assert.IsTrue(IsSplitCharacter(new int[] { 'a', 'a', ' ' }, 0));
52+
NUnit.Framework.Assert.IsFalse(IsSplitCharacter(new int[] { 'a', 'a', ' ' }, 1));
53+
NUnit.Framework.Assert.IsTrue(IsSplitCharacter(new int[] { 'a', ' ', ' ' }, 1));
54+
NUnit.Framework.Assert.IsTrue(IsSplitCharacter(new int[] { 'a', '-', ' ' }, 1));
55+
NUnit.Framework.Assert.IsTrue(IsSplitCharacter(new int[] { 'a', '\u2010', ' ' }, 1));
56+
NUnit.Framework.Assert.IsTrue(IsSplitCharacter(new int[] { 'a', '\u2004', ' ' }, 1));
57+
}
58+
59+
[NUnit.Framework.Test]
60+
public virtual void BeforeSymbolTest() {
61+
NUnit.Framework.Assert.IsFalse(IsSplitCharacter(new int[] { charWithFalse, charWithFalse }, 0));
62+
NUnit.Framework.Assert.IsTrue(IsSplitCharacter(new int[] { charWithFalse, 'a' }, 0));
63+
// non spacing mark
64+
NUnit.Framework.Assert.IsTrue(IsSplitCharacter(new int[] { charWithFalse, '\u0303' }, 0));
65+
// combining mark
66+
NUnit.Framework.Assert.IsTrue(IsSplitCharacter(new int[] { charWithFalse, '\u093e' }, 0));
67+
// enclosing mark
68+
NUnit.Framework.Assert.IsTrue(IsSplitCharacter(new int[] { charWithFalse, '\u0488' }, 0));
69+
}
70+
71+
private static bool IsSplitCharacter(int[] unicodes, int glyphPosition) {
72+
return new BreakAllSplitCharacters().IsSplitCharacter(CreateGlyphLine(unicodes), glyphPosition);
73+
}
74+
75+
private static GlyphLine CreateGlyphLine(int[] unicodes) {
76+
IList<Glyph> glyphs = new List<Glyph>();
77+
foreach (int unicode in unicodes) {
78+
glyphs.Add(new Glyph(1, unicode));
79+
}
80+
return new GlyphLine(glyphs);
81+
}
82+
}
83+
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/*
2+
This file is part of the iText (R) project.
3+
Copyright (c) 1998-2020 iText Group NV
4+
Authors: iText Software.
5+
6+
This program is offered under a commercial and under the AGPL license.
7+
For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below.
8+
9+
AGPL licensing:
10+
This program is free software: you can redistribute it and/or modify
11+
it under the terms of the GNU Affero General Public License as published by
12+
the Free Software Foundation, either version 3 of the License, or
13+
(at your option) any later version.
14+
15+
This program is distributed in the hope that it will be useful,
16+
but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
GNU Affero General Public License for more details.
19+
20+
You should have received a copy of the GNU Affero General Public License
21+
along with this program. If not, see <https://www.gnu.org/licenses/>.
22+
*/
23+
using System.Collections.Generic;
24+
using iText.IO.Font.Otf;
25+
using iText.Test;
26+
27+
namespace iText.Layout.Splitting {
28+
public class KeepAllSplitCharactersTest : ExtendedITextTest {
29+
[NUnit.Framework.Test]
30+
public virtual void DashAtStartTest() {
31+
NUnit.Framework.Assert.IsTrue(IsSplitCharacter(new int[] { '-', 'a' }, 0));
32+
}
33+
34+
[NUnit.Framework.Test]
35+
public virtual void MinusSignAtStartTest() {
36+
NUnit.Framework.Assert.IsFalse(IsSplitCharacter(new int[] { '-', '5' }, 0));
37+
}
38+
39+
[NUnit.Framework.Test]
40+
public virtual void DashBeforeLetterInTheMiddleTest() {
41+
NUnit.Framework.Assert.IsTrue(IsSplitCharacter(new int[] { 'a', ' ', '-', 'a' }, 2));
42+
}
43+
44+
[NUnit.Framework.Test]
45+
public virtual void MinusSignInTheMiddleTest() {
46+
// TODO: DEVSIX-4863 minus sign for digests should not be split
47+
NUnit.Framework.Assert.IsTrue(IsSplitCharacter(new int[] { 'a', ' ', '-', '5' }, 2));
48+
}
49+
50+
[NUnit.Framework.Test]
51+
public virtual void DashBeforeDigitInTheMiddleTest() {
52+
NUnit.Framework.Assert.IsTrue(IsSplitCharacter(new int[] { 'a', 'a', '-', '5' }, 2));
53+
}
54+
55+
[NUnit.Framework.Test]
56+
public virtual void DashAtTheEndTest() {
57+
int[] unicodes = new int[] { 'a', '-' };
58+
NUnit.Framework.Assert.IsTrue(IsSplitCharacter(unicodes, unicodes.Length - 1));
59+
}
60+
61+
[NUnit.Framework.Test]
62+
public virtual void DashCharacterTest() {
63+
NUnit.Framework.Assert.IsTrue(IsSplitCharacter(new int[] { 'a', '-', 'a' }, 1));
64+
}
65+
66+
[NUnit.Framework.Test]
67+
public virtual void NoUnicodeTest() {
68+
NUnit.Framework.Assert.IsFalse(IsSplitCharacter(new int[] { 'a', -1, 'a' }, 1));
69+
}
70+
71+
[NUnit.Framework.Test]
72+
public virtual void Unicode2010CharacterTest() {
73+
NUnit.Framework.Assert.IsTrue(IsSplitCharacter(new int[] { 'a', '\u2010', 'a' }, 1));
74+
}
75+
76+
[NUnit.Framework.Test]
77+
public virtual void Unicode2003CharacterTest() {
78+
NUnit.Framework.Assert.IsTrue(IsSplitCharacter(new int[] { 'a', '\u2003', 'a' }, 1));
79+
}
80+
81+
[NUnit.Framework.Test]
82+
public virtual void Unicode2e81CharacterTest() {
83+
NUnit.Framework.Assert.IsFalse(IsSplitCharacter(new int[] { 'a', '\u2e81', 'a' }, 1));
84+
}
85+
86+
private static bool IsSplitCharacter(int[] unicodes, int glyphPosition) {
87+
return new KeepAllSplitCharacters().IsSplitCharacter(CreateGlyphLine(unicodes), glyphPosition);
88+
}
89+
90+
private static GlyphLine CreateGlyphLine(int[] unicodes) {
91+
IList<Glyph> glyphs = new List<Glyph>();
92+
foreach (int unicode in unicodes) {
93+
glyphs.Add(new Glyph(1, unicode));
94+
}
95+
return new GlyphLine(glyphs);
96+
}
97+
}
98+
}

itext.tests/itext.styledxmlparser.tests/itext/styledxmlparser/css/validate/CssDeclarationValidationMasterTest.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,5 +323,27 @@ public virtual void OverflowWrapTest() {
323323
, "norm")));
324324
}
325325
}
326+
327+
[NUnit.Framework.Test]
328+
public virtual void WordWrapTest() {
329+
NUnit.Framework.Assert.IsTrue(CssDeclarationValidationMaster.CheckDeclaration(new CssDeclaration(CommonCssConstants
330+
.WORD_BREAK, "normal")));
331+
NUnit.Framework.Assert.IsTrue(CssDeclarationValidationMaster.CheckDeclaration(new CssDeclaration(CommonCssConstants
332+
.WORD_BREAK, "break-all")));
333+
NUnit.Framework.Assert.IsTrue(CssDeclarationValidationMaster.CheckDeclaration(new CssDeclaration(CommonCssConstants
334+
.WORD_BREAK, "keep-all")));
335+
NUnit.Framework.Assert.IsTrue(CssDeclarationValidationMaster.CheckDeclaration(new CssDeclaration(CommonCssConstants
336+
.WORD_BREAK, "break-word")));
337+
NUnit.Framework.Assert.IsTrue(CssDeclarationValidationMaster.CheckDeclaration(new CssDeclaration(CommonCssConstants
338+
.WORD_BREAK, "inherit")));
339+
NUnit.Framework.Assert.IsTrue(CssDeclarationValidationMaster.CheckDeclaration(new CssDeclaration(CommonCssConstants
340+
.WORD_BREAK, "unset")));
341+
NUnit.Framework.Assert.IsTrue(CssDeclarationValidationMaster.CheckDeclaration(new CssDeclaration(CommonCssConstants
342+
.WORD_BREAK, "initial")));
343+
NUnit.Framework.Assert.IsFalse(CssDeclarationValidationMaster.CheckDeclaration(new CssDeclaration(CommonCssConstants
344+
.WORD_BREAK, "auto")));
345+
NUnit.Framework.Assert.IsFalse(CssDeclarationValidationMaster.CheckDeclaration(new CssDeclaration(CommonCssConstants
346+
.WORD_BREAK, "norm")));
347+
}
326348
}
327349
}

0 commit comments

Comments
 (0)