@@ -1746,9 +1746,7 @@ public float textAscent() {
17461746
17471747 Font font = (Font ) textFont .getNative ();
17481748 if (font != null ) {
1749- @ SuppressWarnings ("deprecation" )
1750- FontMetrics metrics = Toolkit .getDefaultToolkit ().getFontMetrics (font );
1751- return metrics .getAscent ();
1749+ return getFontMetrics (font ).getAscent ();
17521750 }
17531751 return super .textAscent ();
17541752 }
@@ -1761,9 +1759,7 @@ public float textDescent() {
17611759 }
17621760 Font font = (Font ) textFont .getNative ();
17631761 if (font != null ) {
1764- @ SuppressWarnings ("deprecation" )
1765- FontMetrics metrics = Toolkit .getDefaultToolkit ().getFontMetrics (font );
1766- return metrics .getDescent ();
1762+ return getFontMetrics (font ).getDescent ();
17671763 }
17681764 return super .textDescent ();
17691765 }
@@ -1852,7 +1848,7 @@ protected float textWidthImpl(char buffer[], int start, int stop) {
18521848 if (font != null ) {
18531849 // maybe should use one of the newer/fancier functions for this?
18541850 int length = stop - start ;
1855- FontMetrics metrics = g2 . getFontMetrics (font );
1851+ FontMetrics metrics = getFontMetrics (font );
18561852 // Using fractional metrics makes the measurement worse, not better,
18571853 // at least on OS X 10.6 (November, 2010).
18581854 // TextLayout returns the same value as charsWidth().
@@ -1964,6 +1960,11 @@ protected void textLineImpl(char buffer[], int start, int stop,
19641960 }
19651961
19661962
1963+ @ Override
1964+ public FontMetrics getFontMetrics (Font font ) {
1965+ return (g2 != null ) ? g2 .getFontMetrics (font ) : super .getFontMetrics (font );
1966+ }
1967+
19671968
19681969 //////////////////////////////////////////////////////////////
19691970
0 commit comments