Skip to content

Commit 6335722

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents cb5d432 + 55ddeb1 commit 6335722

File tree

1 file changed

+30
-5
lines changed
  • common/src/main/java/com/loohp/multichatdiscordsrvaddon/resources/fonts

1 file changed

+30
-5
lines changed

Diff for: common/src/main/java/com/loohp/multichatdiscordsrvaddon/resources/fonts/SpaceFont.java

+30-5
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,16 @@ public boolean canDisplayCharacter(String character) {
6363
@Override
6464
public FontRenderResult printCharacter(BufferedImage image, String character, int x, int y, float fontSize, int lastItalicExtraWidth, int color, List<TextDecoration> decorations) {
6565
decorations = sortDecorations(decorations);
66-
int advance = (int) Math.round(charAdvances.get(character.codePointAt(0)) * 0.75);
66+
int advance = charAdvances.get(character.codePointAt(0));
6767
if (advance != 0) {
6868
int sign = advance < 0 ? -1 : 1;
6969
advance = Math.abs(advance);
7070
int originalW = advance;
7171
int w = (int) Math.round(originalW * ((double) Math.round(fontSize) / (double) DEFAULT_HEIGHT));
7272
int h = Math.round(fontSize);
7373
int beforeTransformW = w;
74-
int pixelSize = Math.round((float) beforeTransformW / (float) originalW);
74+
double accuratePixelSize = (double) beforeTransformW / (double) originalW;
75+
int pixelSize = (int) Math.round(accuratePixelSize);
7576
int strikeSize = (int) (fontSize / 8);
7677
int boldSize = (int) (fontSize / 16.0 * 2);
7778
int italicExtraWidth = 0;
@@ -126,15 +127,39 @@ public FontRenderResult printCharacter(BufferedImage image, String character, in
126127
}
127128
g.dispose();
128129
}
129-
return new FontRenderResult(image, w * sign + extraWidth, h, pixelSize, italicExtraWidth);
130+
return new FontRenderResult(image, w * sign + extraWidth, h, 0, italicExtraWidth);
130131
} else {
131-
return new FontRenderResult(image, 0, 0, 0, lastItalicExtraWidth);
132+
int w = 0;
133+
int h = Math.round(fontSize);
134+
int beforeTransformW = w;
135+
int strikeSize = (int) (fontSize / 8);
136+
int boldSize = (int) (fontSize / 16.0 * 2);
137+
int italicExtraWidth = 0;
138+
boolean italic = false;
139+
Color awtColor = new Color(color);
140+
boolean underlineStrikethroughExpanded = false;
141+
for (TextDecoration decoration : decorations) {
142+
switch (decoration) {
143+
case BOLD:
144+
w += boldSize - 1;
145+
break;
146+
case ITALIC:
147+
int extraWidth = (int) ((double) h * (4.0 / 14.0));
148+
italicExtraWidth = (int) Math.round(-ITALIC_SHEAR_X * h);
149+
italic = true;
150+
break;
151+
default:
152+
break;
153+
}
154+
}
155+
int extraWidth = italic ? 0 : lastItalicExtraWidth;
156+
return new FontRenderResult(image, w + extraWidth, h, 0, italicExtraWidth);
132157
}
133158
}
134159

135160
@Override
136161
public Optional<BufferedImage> getCharacterImage(String character, float fontSize, int color) {
137-
int advance = (int) Math.round(charAdvances.get(character.codePointAt(0)) * 0.75);
162+
int advance = charAdvances.get(character.codePointAt(0));
138163
if (advance == 0) {
139164
return Optional.empty();
140165
}

0 commit comments

Comments
 (0)