@@ -63,15 +63,16 @@ public boolean canDisplayCharacter(String character) {
63
63
@ Override
64
64
public FontRenderResult printCharacter (BufferedImage image , String character , int x , int y , float fontSize , int lastItalicExtraWidth , int color , List <TextDecoration > decorations ) {
65
65
decorations = sortDecorations (decorations );
66
- int advance = ( int ) Math . round ( charAdvances .get (character .codePointAt (0 )) * 0.75 );
66
+ int advance = charAdvances .get (character .codePointAt (0 ));
67
67
if (advance != 0 ) {
68
68
int sign = advance < 0 ? -1 : 1 ;
69
69
advance = Math .abs (advance );
70
70
int originalW = advance ;
71
71
int w = (int ) Math .round (originalW * ((double ) Math .round (fontSize ) / (double ) DEFAULT_HEIGHT ));
72
72
int h = Math .round (fontSize );
73
73
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 );
75
76
int strikeSize = (int ) (fontSize / 8 );
76
77
int boldSize = (int ) (fontSize / 16.0 * 2 );
77
78
int italicExtraWidth = 0 ;
@@ -126,15 +127,39 @@ public FontRenderResult printCharacter(BufferedImage image, String character, in
126
127
}
127
128
g .dispose ();
128
129
}
129
- return new FontRenderResult (image , w * sign + extraWidth , h , pixelSize , italicExtraWidth );
130
+ return new FontRenderResult (image , w * sign + extraWidth , h , 0 , italicExtraWidth );
130
131
} 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 );
132
157
}
133
158
}
134
159
135
160
@ Override
136
161
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 ));
138
163
if (advance == 0 ) {
139
164
return Optional .empty ();
140
165
}
0 commit comments