Skip to content

Commit 06824ad

Browse files
fix: typesetting in FontRenderer
1 parent fddce43 commit 06824ad

1 file changed

Lines changed: 16 additions & 17 deletions

File tree

patches/minecraft/net/minecraft/client/gui/FontRenderer.java.patch

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@
131131
{
132132
text = text.substring(0, text.length() - 1);
133133
}
134-
@@ -719,9 +730,88 @@
134+
@@ -719,9 +730,87 @@
135135

136136
public List<String> listFormattedStringToWidth(String str, int wrapWidth)
137137
{
@@ -143,10 +143,9 @@
143143
+ com.ibm.icu.segmenter.Segments segments = com.cleanroommc.client.ICU4JInstances.SEGMENTER.segment(str);
144144
+ List<String> list = new java.util.ArrayList<>();
145145
+ StringBuilder line = new StringBuilder();
146-
+ StringBuilder seg = new StringBuilder();
146+
+ StringBuilder current = new StringBuilder();
147147
+ StringBuilder format = new StringBuilder();
148148
+ StringBuilder segFormat = new StringBuilder();
149-
+ int formatSize = 0;
150149
+ boolean bold = false;
151150
+ int lineWidth = 0;
152151
+ int segmentWidth;
@@ -162,12 +161,11 @@
162161
+ char c = sequence.charAt(i);
163162
+ switch (c) {
164163
+ case '\n':
165-
+ line.append(seg);
166-
+ seg.setLength(0);
164+
+ line.append(current);
165+
+ current.setLength(0);
167166
+ list.add(line.toString());
168167
+ line.setLength(0);
169168
+ line.append(format);
170-
+ formatSize = format.length();
171169
+ lineWidth = 0;
172170
+ continue out;
173171
+ case '§':
@@ -182,35 +180,36 @@
182180
+ bold = false;
183181
+ }
184182
+ format.append('§').append(next);
185-
+ seg.append('§').append(next);
183+
+ current.append('§').append(next);
186184
+ continue;
187185
+ }
188186
+ default:
189187
+ int cWidth = getCharWidth(c);
190188
+ if (bold) cWidth++;
191189
+ if (lineWidth + cWidth > wrapWidth) {
192-
+ if (line.length() == formatSize) {
193-
+ line.append(seg);
194-
+ seg.setLength(0);
190+
+ if (i >= current.length()) {
195191
+ lineWidth = 0;
196192
+ segmentWidth = 0;
197-
+ } else {
198-
+ lineWidth = segmentWidth;
193+
+ line.append(current);
199194
+ format.setLength(0);
200195
+ 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);
201201
+ }
202202
+ list.add(line.toString());
203203
+ line.setLength(0);
204204
+ line.append(format);
205-
+ formatSize = format.length();
206205
+ }
207-
+ seg.append(c);
206+
+ current.append(c);
208207
+ lineWidth += cWidth;
209208
+ segmentWidth += cWidth;
210209
+ }
211210
+ }
212211
+ }
213-
+ line.append(seg);
212+
+ line.append(current);
214213
+ if (!line.isEmpty()) {
215214
+ list.add(line.toString());
216215
+ }
@@ -221,15 +220,15 @@
221220
String wrapFormattedStringToWidth(String str, int wrapWidth)
222221
{
223222
int i = this.sizeStringToWidth(str, wrapWidth);
224-
@@ -740,6 +830,7 @@
223+
@@ -740,6 +829,7 @@
225224
}
226225
}
227226

228227
+ @Deprecated
229228
private int sizeStringToWidth(String str, int wrapWidth)
230229
{
231230
int i = str.length();
232-
@@ -838,6 +929,26 @@
231+
@@ -838,6 +928,26 @@
233232
public boolean getBidiFlag()
234233
{
235234
return this.bidiFlag;

0 commit comments

Comments
 (0)