Skip to content

Commit d1877c0

Browse files
LodrKumquatyulian-gaponenko
authored andcommitted
Support word-break property
DEVSIX-4422 Autoported commit. Original commit hash: [7788e66a56]
1 parent b26fa9c commit d1877c0

File tree

10 files changed

+41
-22
lines changed

10 files changed

+41
-22
lines changed

itext.tests/itext.html2pdf.tests/itext/html2pdf/css/WordBreakTest.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ public static void BeforeClass() {
4747

4848
[NUnit.Framework.Test]
4949
public virtual void WordBreakCommonScenarioTest() {
50-
// TODO: update cmp file after implementing DEVSIX-1438
5150
FontProvider fontProvider = new DefaultFontProvider();
5251
fontProvider.AddFont(fontsFolder + "NotoSansCJKjp-Regular.otf");
5352
ConverterProperties converterProperties = new ConverterProperties();
@@ -60,7 +59,6 @@ public virtual void WordBreakCommonScenarioTest() {
6059

6160
[NUnit.Framework.Test]
6261
public virtual void OverflowXWordBreakTest() {
63-
// TODO: update cmp file after implementing DEVSIX-1438
6462
FontProvider fontProvider = new DefaultFontProvider();
6563
fontProvider.AddFont(fontsFolder + "NotoSansCJKjp-Regular.otf");
6664
ConverterProperties converterProperties = new ConverterProperties();
@@ -73,7 +71,6 @@ public virtual void OverflowXWordBreakTest() {
7371

7472
[NUnit.Framework.Test]
7573
public virtual void WhiteSpaceAndWordBreakTest() {
76-
// TODO: update cmp file after implementing DEVSIX-1438
7774
HtmlConverter.ConvertToPdf(new FileInfo(sourceFolder + "whiteSpaceAndWordBreak.html"), new FileInfo(destinationFolder
7875
+ "whiteSpaceAndWordBreak.pdf"));
7976
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + "whiteSpaceAndWordBreak.pdf"
@@ -82,7 +79,6 @@ public virtual void WhiteSpaceAndWordBreakTest() {
8279

8380
[NUnit.Framework.Test]
8481
public virtual void WordBreakMidNumbersTest() {
85-
// TODO: update cmp file after implementing DEVSIX-1438
8682
FontProvider fontProvider = new DefaultFontProvider();
8783
fontProvider.AddFont(fontsFolder + "NotoSansCJKjp-Regular.otf");
8884
ConverterProperties converterProperties = new ConverterProperties();
@@ -95,7 +91,6 @@ public virtual void WordBreakMidNumbersTest() {
9591

9692
[NUnit.Framework.Test]
9793
public virtual void WordBreakMidPunctuationTest() {
98-
// TODO: update cmp file after implementing DEVSIX-1438
9994
HtmlConverter.ConvertToPdf(new FileInfo(sourceFolder + "wordBreakMidPunctuation.html"), new FileInfo(destinationFolder
10095
+ "wordBreakMidPunctuation.pdf"));
10196
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + "wordBreakMidPunctuation.pdf"
@@ -104,7 +99,6 @@ public virtual void WordBreakMidPunctuationTest() {
10499

105100
[NUnit.Framework.Test]
106101
public virtual void WordBreakAllAndFloatTest() {
107-
// TODO: update cmp file after implementing DEVSIX-1438
108102
HtmlConverter.ConvertToPdf(new FileInfo(sourceFolder + "wordBreakAllAndFloat.html"), new FileInfo(destinationFolder
109103
+ "wordBreakAllAndFloat.pdf"));
110104
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + "wordBreakAllAndFloat.pdf"
@@ -114,7 +108,6 @@ public virtual void WordBreakAllAndFloatTest() {
114108
[NUnit.Framework.Test]
115109
[LogMessage(iText.IO.LogMessageConstant.TABLE_WIDTH_IS_MORE_THAN_EXPECTED_DUE_TO_MIN_WIDTH, Count = 3)]
116110
public virtual void WordBreakTableScenarioTest() {
117-
// TODO: update cmp file after implementing DEVSIX-1438
118111
HtmlConverter.ConvertToPdf(new FileInfo(sourceFolder + "wordBreakTableScenario.html"), new FileInfo(destinationFolder
119112
+ "wordBreakTableScenario.pdf"));
120113
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + "wordBreakTableScenario.pdf"

itext.tests/itext.html2pdf.tests/resources/itext/html2pdf/css/WordBreakTest/wordBreakMidNumbers.html

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,29 @@
2525
</head>
2626
<body>
2727
<h3>1. word-break: normal</h3>
28-
<p class="normal">Lorem 12345.678912345 -6789 ipsum dolor sit ametconsecteturadipiscingelitseddoeiusmodtempor incididunt ut labore et dolore magna aliqua</p>
28+
<p class="normal">Lorem 1234.6789.23 -6789 ipsum dolor sit ametconsecteturadipiscingelitseddoeiusmodtempor incididunt ut labore et dolore magna aliqua</p>
2929

3030
<h3>2. word-break: break-all</h3>
31-
<p class="breakAll">Lorem 12345.678912345 -6789 ipsum dolor sit ametconsecteturadipiscingelitseddoeiusmodtempor incididunt ut labore et dolore magna aliqua</p>
31+
<p class="breakAll">Lorem 1234.6789.23 -6789 ipsum dolor sit ametconsecteturadipiscingelitseddoeiusmodtempor incididunt ut labore et dolore magna aliqua</p>
3232

3333
<h3>3. word-break: keep-all</h3>
34-
<p class="keepAll">Lorem 12345.678912345 -6789 ipsum dolor sit ametconsecteturadipiscingelitseddoeiusmodtempor incididunt ut labore et dolore magna aliqua</p>
34+
<p class="keepAll">Lorem 1234.6789.23 -6789 ipsum dolor sit ametconsecteturadipiscingelitseddoeiusmodtempor incididunt ut labore et dolore magna aliqua</p>
3535

3636
<h3>4. word-break: break-word</h3>
37-
<p class="breakWord">Lorem 12345.678912345-6789 ipsum dolor sit ametconsecteturadipiscingelitseddoeiusmodtempor incididunt ut labore et dolore magna aliqua</p>
37+
<p class="breakWord">Lorem 1234.6789.23 -6789 ipsum dolor sit ametconsecteturadipiscingelitseddoeiusmodtempor incididunt ut labore et dolore magna aliqua</p>
3838

3939
<h3>Chinese script</h3>
40-
<h3>1. word-break: break-word</h3>
41-
<p class="breakWord">只不过是绝大多数人生来就有12345.678912345 -6789根手指这样一个解剖学事实的结果</p>
42-
<h3>1. word-break: keep-all</h3>
43-
<p class="keepAll">只不过是绝大多数人生来就有12345.678912345 -6789根手指这样一个解剖学事实的结果</p>
44-
<h3>1. word-break: break-all</h3>
45-
<p class="breakAll">只不过是绝大多数人生来就有12345.678912345 -6789根手指这样一个解剖学事实的结果</p>
4640
<h3>1. word-break: normal</h3>
4741
<p class="normal">只不过是绝大多数人生来就有12345.678912345 -6789根手指这样一个解剖学事实的结果</p>
4842

43+
<h3>1. word-break: break-all</h3>
44+
<p class="breakAll">只不过是绝大多数人生来就有12345.678912345 -6789根手指这样一个解剖学事实的结果</p>
45+
46+
<h3>1. word-break: keep-all</h3>
47+
<p class="keepAll">只不过是绝大多数人生来就有12345.678912345 -6789根手指这样一个解剖学事实的结果</p>
48+
49+
<h3>1. word-break: break-word</h3>
50+
<p class="breakWord">只不过是绝大多数人生来就有12345.678912345 -6789根手指这样一个解剖学事实的结果</p>
4951

5052
</body>
5153
</html>

itext.tests/itext.html2pdf.tests/resources/itext/html2pdf/css/WordBreakTest/wordBreakMidPunctuation.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@
2525
</head>
2626
<body>
2727
<h3>1. word-break: normal</h3>
28-
<p class="normal">Lorem ipsum dolor, sit ametconsecteturadipiscingelitseddoeiusmodtempor? Incididunt, - ut labore et dolore magna. Aliqua??????</p>
28+
<p class="normal">Lorem ipsum dolor, sit ametconse.....................cte$$$$$$$$$$dipiscingelitsed--------------eiusmodtempor?? Aliqua????????????</p>
2929

3030
<h3>2. word-break: break-all</h3>
31-
<p class="breakAll">Lorem ipsum dolor, sit ametconsecteturadipiscingelitseddoeiusmodtempor? Incididunt, - ut labore et dolore magna. Aliqua??????</p>
31+
<p class="breakAll">Lorem ipsum dolor, sit ametconse.....................cte$$$$$$$$$$dipiscingelitsed--------------eiusmodtempor?? Aliqua????????????</p>
3232

3333
<h3>3. word-break: keep-all</h3>
34-
<p class="keepAll">Lorem ipsum dolor, sit ametconsecteturadipiscingelitseddoeiusmodtempor? Incididunt, - ut labore et dolore magna. Aliqua??????</p>
34+
<p class="keepAll">Lorem ipsum dolor, sit ametconse.....................cte$$$$$$$$$$dipiscingelitsed--------------eiusmodtempor?? Aliqua????????????</p>
3535

3636
<h3>4. word-break: break-word</h3>
37-
<p class="breakWord">Lorem ipsum dolor, sit ametconsecteturadipiscingelitseddoeiusmodtempor? Incididunt, - ut labore et dolore magna. Aliqua??????</p>
37+
<p class="breakWord">Lorem ipsum dolor, sit ametconse.....................cte$$$$$$$$$$dipiscingelitsed--------------eiusmodtempor?? Aliqua????????????</p>
3838
</body>
3939
</html>

itext/itext.html2pdf/itext/html2pdf/css/apply/util/FontStyleApplierUtil.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ source product.
5151
using iText.Layout;
5252
using iText.Layout.Font;
5353
using iText.Layout.Properties;
54+
using iText.Layout.Splitting;
5455
using iText.StyledXmlParser.Css.Util;
5556
using iText.StyledXmlParser.Node;
5657

@@ -163,6 +164,29 @@ public static void ApplyFontStyles(IDictionary<String, String> cssProps, Process
163164
element.SetProperty(Property.OVERFLOW_WRAP, OverflowWrapPropertyValue.NORMAL);
164165
}
165166
}
167+
String wordBreak = cssProps.Get(CssConstants.WORD_BREAK);
168+
if (CssConstants.BREAK_ALL.Equals(wordBreak)) {
169+
element.SetProperty(Property.SPLIT_CHARACTERS, new BreakAllSplitCharacters());
170+
}
171+
else {
172+
if (CssConstants.KEEP_ALL.Equals(wordBreak)) {
173+
element.SetProperty(Property.SPLIT_CHARACTERS, new KeepAllSplitCharacters());
174+
}
175+
else {
176+
if (CssConstants.BREAK_WORD.Equals(wordBreak)) {
177+
// CSS specification cite that describes the reason for overflow-wrap overriding:
178+
// "For compatibility with legacy content, the word-break property also supports
179+
// a deprecated break-word keyword. When specified, this has the same effect
180+
// as word-break: normal and overflow-wrap: anywhere, regardless of the actual value
181+
// of the overflow-wrap property."
182+
element.SetProperty(Property.OVERFLOW_WRAP, OverflowWrapPropertyValue.BREAK_WORD);
183+
element.SetProperty(Property.SPLIT_CHARACTERS, new DefaultSplitCharacters());
184+
}
185+
else {
186+
element.SetProperty(Property.SPLIT_CHARACTERS, new DefaultSplitCharacters());
187+
}
188+
}
189+
}
166190
}
167191
float[] colors = new float[4];
168192
Color textDecorationColor;

port-hash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
5315d19fd0c116ba0b14812d2fe9b072504684ee
1+
7788e66a5699f2fd75ee1c66e1ea64fea51c58c2

0 commit comments

Comments
 (0)