Skip to content

Commit a3fb5cc

Browse files
committed
Support Japanese line breaking rules
DEVSIX-8978
1 parent d76ea83 commit a3fb5cc

File tree

10 files changed

+484
-15
lines changed

10 files changed

+484
-15
lines changed
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-2025 Apryse Group NV
4+
Authors: Apryse 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+
package com.itextpdf.html2pdf.css;
24+
25+
import com.itextpdf.html2pdf.ConverterProperties;
26+
import com.itextpdf.html2pdf.ExtendedHtmlConversionITextTest;
27+
import com.itextpdf.layout.font.FontProvider;
28+
29+
import java.io.IOException;
30+
import org.junit.jupiter.api.BeforeAll;
31+
import org.junit.jupiter.api.Tag;
32+
import org.junit.jupiter.api.Test;
33+
34+
@Tag("IntegrationTest")
35+
public class JapaneseLineBreakingRulesTest extends ExtendedHtmlConversionITextTest {
36+
private static final String SOURCE_FOLDER = "./src/test/resources/com/itextpdf/html2pdf/css/JapaneseLineBreakingRulesTest/";
37+
private static final String DESTINATION_FOLDER = "./target/test/com/itextpdf/html2pdf/css/JapaneseLineBreakingRulesTest/";
38+
private static final String FONTS_FOLDER = "./src/test/resources/com/itextpdf/html2pdf/fonts/";
39+
40+
@BeforeAll
41+
public static void beforeClass() {
42+
createDestinationFolder(DESTINATION_FOLDER);
43+
}
44+
45+
// See https://www.w3.org/TR/jlreq/?lang=en#characters_not_starting_a_line
46+
@Test
47+
public void charsNotStartingLineTest() throws IOException, InterruptedException {
48+
FontProvider fontProvider = new FontProvider();
49+
fontProvider.addFont(FONTS_FOLDER + "NotoSansJP-Regular.ttf");
50+
51+
ConverterProperties props = new ConverterProperties();
52+
props.setFontProvider(fontProvider);
53+
54+
convertToPdfAndCompare("charsNotStartingLine", SOURCE_FOLDER, DESTINATION_FOLDER, false, props);
55+
}
56+
57+
// See https://www.w3.org/TR/jlreq/?lang=en#characters_not_ending_a_line
58+
@Test
59+
public void charsNotEndingLineTest() throws IOException, InterruptedException {
60+
FontProvider fontProvider = new FontProvider();
61+
fontProvider.addFont(FONTS_FOLDER + "NotoSansJP-Regular.ttf");
62+
63+
ConverterProperties props = new ConverterProperties();
64+
props.setFontProvider(fontProvider);
65+
66+
// There is a bug in browsers that they handle left and right (double) quotes as same chars.
67+
// It's why browsers don't allow to start a line from '“' (Left Double Quotation Mark)
68+
convertToPdfAndCompare("charsNotEndingLine", SOURCE_FOLDER, DESTINATION_FOLDER, false, props);
69+
}
70+
71+
// See https://www.w3.org/TR/jlreq/?lang=en#unbreakable_character_sequences
72+
@Test
73+
// TODO DEVSIX-4863 Layout splitting logic handles negative values incorrectly if they are not in the very beginning of Text element
74+
public void unseparableSequenceTest() throws IOException, InterruptedException {
75+
FontProvider fontProvider = new FontProvider();
76+
fontProvider.addFont(FONTS_FOLDER + "NotoSansJP-Regular.ttf");
77+
78+
ConverterProperties props = new ConverterProperties();
79+
props.setFontProvider(fontProvider);
80+
81+
convertToPdfAndCompare("unseparableSequence", SOURCE_FOLDER, DESTINATION_FOLDER, false, props);
82+
}
83+
}
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<body>
4+
<div>
5+
<p>End line character for check is '‘'</p>
6+
<div style="border: 1px solid red; width: 183px">
7+
<p style="font-size: 14px;">に関連する主要なステーク‘以下の項目</p>
8+
</div>
9+
</div>
10+
11+
<div>
12+
<p>End line character for check is '“'</p>
13+
<div style="border: 1px solid red; width: 183px">
14+
<p style="font-size: 14px;">に関連する主要なステーク“以下の項目</p>
15+
</div>
16+
</div>
17+
18+
<div>
19+
<p>End line character for check is '('</p>
20+
<div style="border: 1px solid red; width: 183px">
21+
<p style="font-size: 14px;">に関連する主要なステーク(以下の項目</p>
22+
</div>
23+
</div>
24+
25+
<div>
26+
<p>End line character for check is '〔'</p>
27+
<div style="border: 1px solid red; width: 183px">
28+
<p style="font-size: 14px;">に関連する主要なステーク〔以下の項目</p>
29+
</div>
30+
</div>
31+
32+
<div>
33+
<p>End line character for check is '['</p>
34+
<div style="border: 1px solid red; width: 183px">
35+
<p style="font-size: 14px;">に関連する主要なステーク[以下の項目</p>
36+
</div>
37+
</div>
38+
39+
<div>
40+
<p>End line character for check is '{'</p>
41+
<div style="border: 1px solid red; width: 183px">
42+
<p style="font-size: 14px;">に関連する主要なステーク{以下の項目</p>
43+
</div>
44+
</div>
45+
46+
<div>
47+
<p>End line character for check is '〈'</p>
48+
<div style="border: 1px solid red; width: 183px">
49+
<p style="font-size: 14px;">に関連する主要なステーク〈以下の項目</p>
50+
</div>
51+
</div>
52+
53+
<div>
54+
<p>End line character for check is '《'</p>
55+
<div style="border: 1px solid red; width: 183px">
56+
<p style="font-size: 14px;">に関連する主要なステーク《以下の項目</p>
57+
</div>
58+
</div>
59+
60+
<div>
61+
<p>End line character for check is '「'</p>
62+
<div style="border: 1px solid red; width: 183px">
63+
<p style="font-size: 14px;">に関連する主要なステーク「以下の項目</p>
64+
</div>
65+
</div>
66+
67+
<div>
68+
<p>End line character for check is '『'</p>
69+
<div style="border: 1px solid red; width: 183px">
70+
<p style="font-size: 14px;">に関連する主要なステーク『以下の項目</p>
71+
</div>
72+
</div>
73+
74+
<div>
75+
<p>End line character for check is '【'</p>
76+
<div style="border: 1px solid red; width: 183px">
77+
<p style="font-size: 14px;">に関連する主要なステーク【以下の項目</p>
78+
</div>
79+
</div>
80+
81+
<div>
82+
<p>End line character for check is '⦅'</p>
83+
<div style="border: 1px solid red; width: 183px">
84+
<p style="font-size: 14px;">に関連する主要なステーク⦅以下の項目</p>
85+
</div>
86+
</div>
87+
88+
<div>
89+
<p>End line character for check is '〘'</p>
90+
<div style="border: 1px solid red; width: 183px">
91+
<p style="font-size: 14px;">に関連する主要なステーク〘以下の項目</p>
92+
</div>
93+
</div>
94+
95+
<div>
96+
<p>End line character for check is '〖'</p>
97+
<div style="border: 1px solid red; width: 183px">
98+
<p style="font-size: 14px;">に関連する主要なステーク〖以下の項目</p>
99+
</div>
100+
</div>
101+
102+
<div>
103+
<p>End line character for check is '«'</p>
104+
<div style="border: 1px solid red; width: 183px">
105+
<p style="font-size: 14px;">に関連する主要なステーク«以下の項目</p>
106+
</div>
107+
</div>
108+
109+
<div>
110+
<p>End line character for check is '〝'</p>
111+
<div style="border: 1px solid red; width: 183px">
112+
<p style="font-size: 14px;">に関連する主要なステーク〝以下の項目</p>
113+
</div>
114+
</div>
115+
116+
117+
</body>
118+
</html>
119+
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<body>
4+
<div>
5+
<p>Start line character for check is '’'</p>
6+
<div style="border: 1px solid red; width: 183px">
7+
<p style="font-size: 14px;">に関連する主要なステークホ’以下の項目</p>
8+
</div>
9+
</div>
10+
11+
<div>
12+
<p>Start line character for check is ']'</p>
13+
<div style="border: 1px solid red; width: 183px">
14+
<p style="font-size: 14px;">に関連する主要なステークホ]以下の項目</p>
15+
</div>
16+
</div>
17+
18+
<div>
19+
<p>Start line character for check is '」'</p>
20+
<div style="border: 1px solid red; width: 183px">
21+
<p style="font-size: 14px;">に関連する主要なステークホ」以下の項目</p>
22+
</div>
23+
</div>
24+
25+
<div>
26+
<p>Start line character for check is '»'</p>
27+
<div style="border: 1px solid red; width: 183px">
28+
<p style="font-size: 14px;">に関連する主要なステークホ»以下の項目</p>
29+
</div>
30+
</div>
31+
32+
<div>
33+
<p>Start line character for check is '‐'</p>
34+
<div style="border: 1px solid red; width: 183px">
35+
<p style="font-size: 14px;">に関連する主要なステークホ‐以下の項目</p>
36+
</div>
37+
</div>
38+
39+
<div>
40+
<p>Start line character for check is '゠'</p>
41+
<div style="border: 1px solid red; width: 183px">
42+
<p style="font-size: 14px;">に関連する主要なステークホ゠以下の項目</p>
43+
</div>
44+
</div>
45+
46+
<div>
47+
<p>Start line character for check is '‼'</p>
48+
<div style="border: 1px solid red; width: 183px">
49+
<p style="font-size: 14px;">に関連する主要なステークホ‼以下の項目</p>
50+
</div>
51+
</div>
52+
53+
<div>
54+
<p>Start line character for check is '⁉'</p>
55+
<div style="border: 1px solid red; width: 183px">
56+
<p style="font-size: 14px;">に関連する主要なステークホ⁉以下の項目</p>
57+
</div>
58+
</div>
59+
60+
<div>
61+
<p>Start line character for check is '・'</p>
62+
<div style="border: 1px solid red; width: 183px">
63+
<p style="font-size: 14px;">に関連する主要なステークホ・以下の項目</p>
64+
</div>
65+
</div>
66+
67+
<div>
68+
<p>Start line character for check is '。'</p>
69+
<div style="border: 1px solid red; width: 183px">
70+
<p style="font-size: 14px;">に関連する主要なステークホ。以下の項目</p>
71+
</div>
72+
</div>
73+
74+
<div>
75+
<p>Start line character for check is '.'</p>
76+
<div style="border: 1px solid red; width: 183px">
77+
<p style="font-size: 14px;">に関連する主要なステークホ.以下の項目</p>
78+
</div>
79+
</div>
80+
81+
<div>
82+
<p>Start line character for check is '、'</p>
83+
<div style="border: 1px solid red; width: 183px">
84+
<p style="font-size: 14px;">に関連する主要なステークホ、以下の項目</p>
85+
</div>
86+
</div>
87+
88+
<div>
89+
<p>Start line character for check is 'ヾ'</p>
90+
<div style="border: 1px solid red; width: 183px">
91+
<p style="font-size: 14px;">に関連する主要なステークホヾ以下の項目</p>
92+
</div>
93+
</div>
94+
95+
<div>
96+
<p>Start line character for check is 'ゞ'</p>
97+
<div style="border: 1px solid red; width: 183px">
98+
<p style="font-size: 14px;">に関連する主要なステークぁゞ以下の項目</p>
99+
</div>
100+
</div>
101+
102+
<div>
103+
<p>Start line character for check is '〻'</p>
104+
<div style="border: 1px solid red; width: 183px">
105+
<p style="font-size: 14px;">に関連する主要なステーク〥〻以下の項目</p>
106+
</div>
107+
</div>
108+
109+
<div>
110+
<p>Start line character for check is 'ー'</p>
111+
<div style="border: 1px solid red; width: 183px">
112+
<p style="font-size: 14px;">に関連する主要なステークホー以下の項目</p>
113+
</div>
114+
</div>
115+
116+
<div>
117+
<p>Start line character for check is 'ぁ'</p>
118+
<div style="border: 1px solid red; width: 183px">
119+
<p style="font-size: 14px;">に関連する主要なステークぜぁ以下の項目</p>
120+
</div>
121+
</div>
122+
123+
<div>
124+
<p>Start line character for check is 'ゅ'</p>
125+
<div style="border: 1px solid red; width: 183px">
126+
<p style="font-size: 14px;">に関連する主要なステークぜゅ以下の項目</p>
127+
</div>
128+
</div>
129+
130+
<div>
131+
<p>Start line character for check is 'ㇰ'</p>
132+
<div style="border: 1px solid red; width: 183px">
133+
<p style="font-size: 14px;">に関連する主要なステークオㇰ以下の項目</p>
134+
</div>
135+
</div>
136+
137+
<div>
138+
<p>Start line character for check is 'ㇿ'</p>
139+
<div style="border: 1px solid red; width: 183px">
140+
<p style="font-size: 14px;">に関連する主要なステークオㇿ以下の項目</p>
141+
</div>
142+
</div>
143+
144+
<div>
145+
<p>Start line character for check is '〕'</p>
146+
<div style="border: 1px solid red; width: 183px">
147+
<p style="font-size: 14px;">に関連する主要なステークホ〕以下の項目</p>
148+
</div>
149+
</div>
150+
151+
</body>
152+
</html>
153+

0 commit comments

Comments
 (0)