|
131 | 131 | { |
132 | 132 | text = text.substring(0, text.length() - 1); |
133 | 133 | } |
134 | | -@@ -719,9 +730,88 @@ |
| 134 | +@@ -719,9 +730,87 @@ |
135 | 135 |
|
136 | 136 | public List<String> listFormattedStringToWidth(String str, int wrapWidth) |
137 | 137 | { |
|
143 | 143 | + com.ibm.icu.segmenter.Segments segments = com.cleanroommc.client.ICU4JInstances.SEGMENTER.segment(str); |
144 | 144 | + List<String> list = new java.util.ArrayList<>(); |
145 | 145 | + StringBuilder line = new StringBuilder(); |
146 | | -+ StringBuilder seg = new StringBuilder(); |
| 146 | ++ StringBuilder current = new StringBuilder(); |
147 | 147 | + StringBuilder format = new StringBuilder(); |
148 | 148 | + StringBuilder segFormat = new StringBuilder(); |
149 | | -+ int formatSize = 0; |
150 | 149 | + boolean bold = false; |
151 | 150 | + int lineWidth = 0; |
152 | 151 | + int segmentWidth; |
|
162 | 161 | + char c = sequence.charAt(i); |
163 | 162 | + switch (c) { |
164 | 163 | + case '\n': |
165 | | -+ line.append(seg); |
166 | | -+ seg.setLength(0); |
| 164 | ++ line.append(current); |
| 165 | ++ current.setLength(0); |
167 | 166 | + list.add(line.toString()); |
168 | 167 | + line.setLength(0); |
169 | 168 | + line.append(format); |
170 | | -+ formatSize = format.length(); |
171 | 169 | + lineWidth = 0; |
172 | 170 | + continue out; |
173 | 171 | + case '§': |
|
182 | 180 | + bold = false; |
183 | 181 | + } |
184 | 182 | + format.append('§').append(next); |
185 | | -+ seg.append('§').append(next); |
| 183 | ++ current.append('§').append(next); |
186 | 184 | + continue; |
187 | 185 | + } |
188 | 186 | + default: |
189 | 187 | + int cWidth = getCharWidth(c); |
190 | 188 | + if (bold) cWidth++; |
191 | 189 | + if (lineWidth + cWidth > wrapWidth) { |
192 | | -+ if (line.length() == formatSize) { |
193 | | -+ line.append(seg); |
194 | | -+ seg.setLength(0); |
| 190 | ++ if (i >= current.length()) { |
195 | 191 | + lineWidth = 0; |
196 | 192 | + segmentWidth = 0; |
197 | | -+ } else { |
198 | | -+ lineWidth = segmentWidth; |
| 193 | ++ line.append(current); |
199 | 194 | + format.setLength(0); |
200 | 195 | + format.append(segFormat); |
| 196 | ++ current.setLength(0); |
| 197 | ++ } else { |
| 198 | ++ lineWidth = segmentWidth; |
| 199 | ++ line.append(current, 0, current.length() - i); |
| 200 | ++ current.delete(0, current.length() - i); |
201 | 201 | + } |
202 | 202 | + list.add(line.toString()); |
203 | 203 | + line.setLength(0); |
204 | 204 | + line.append(format); |
205 | | -+ formatSize = format.length(); |
206 | 205 | + } |
207 | | -+ seg.append(c); |
| 206 | ++ current.append(c); |
208 | 207 | + lineWidth += cWidth; |
209 | 208 | + segmentWidth += cWidth; |
210 | 209 | + } |
211 | 210 | + } |
212 | 211 | + } |
213 | | -+ line.append(seg); |
| 212 | ++ line.append(current); |
214 | 213 | + if (!line.isEmpty()) { |
215 | 214 | + list.add(line.toString()); |
216 | 215 | + } |
|
221 | 220 | String wrapFormattedStringToWidth(String str, int wrapWidth) |
222 | 221 | { |
223 | 222 | int i = this.sizeStringToWidth(str, wrapWidth); |
224 | | -@@ -740,6 +830,7 @@ |
| 223 | +@@ -740,6 +829,7 @@ |
225 | 224 | } |
226 | 225 | } |
227 | 226 |
|
228 | 227 | + @Deprecated |
229 | 228 | private int sizeStringToWidth(String str, int wrapWidth) |
230 | 229 | { |
231 | 230 | int i = str.length(); |
232 | | -@@ -838,6 +929,26 @@ |
| 231 | +@@ -838,6 +928,26 @@ |
233 | 232 | public boolean getBidiFlag() |
234 | 233 | { |
235 | 234 | return this.bidiFlag; |
|
0 commit comments