@@ -112,8 +112,6 @@ public void render(Symbol symbol) {
112
112
TextAlignment alignment = (text .alignment == JUSTIFY && text .text .length () == 1 ? CENTER : text .alignment );
113
113
Font font = (alignment != JUSTIFY ? f : addTracking (f , text .width * magnification , text .text , g2d ));
114
114
g2d .setFont (font );
115
- FontMetrics fm = g2d .getFontMetrics ();
116
- Rectangle2D bounds = fm .getStringBounds (text .text , g2d );
117
115
float y = (float ) (text .y * magnification ) + marginY ;
118
116
float x ;
119
117
switch (alignment ) {
@@ -122,10 +120,10 @@ public void render(Symbol symbol) {
122
120
x = (float ) ((magnification * text .x ) + marginX );
123
121
break ;
124
122
case RIGHT :
125
- x = (float ) ((magnification * text .x ) + (magnification * text .width ) - bounds .getWidth () + marginX );
123
+ x = (float ) ((magnification * text .x ) + (magnification * text .width ) - getBounds ( text , g2d ) .getWidth () + marginX );
126
124
break ;
127
125
case CENTER :
128
- x = (float ) ((magnification * text .x ) + (magnification * text .width / 2 ) - (bounds .getWidth () / 2 ) + marginX );
126
+ x = (float ) ((magnification * text .x ) + (magnification * text .width / 2 ) - (getBounds ( text , g2d ) .getWidth () / 2 ) + marginX );
129
127
break ;
130
128
default :
131
129
throw new OkapiInternalException ("Unknown alignment: " + alignment );
@@ -155,6 +153,11 @@ public void render(Symbol symbol) {
155
153
g2d .setColor (oldColor );
156
154
}
157
155
156
+ private static Rectangle2D getBounds (TextBox text , Graphics2D g2d ) {
157
+ FontMetrics fm = g2d .getFontMetrics ();
158
+ return fm .getStringBounds (text .text , g2d );
159
+ }
160
+
158
161
private static Ellipse2D .Double adjust (Circle circle , double magnification , int marginX , int marginY ) {
159
162
double x = marginX + ((circle .centreX - circle .radius ) * magnification );
160
163
double y = marginY + ((circle .centreY - circle .radius ) * magnification );
0 commit comments