< prev index next >

src/java.desktop/share/classes/sun/swing/SwingUtilities2.java

Print this page

        

@@ -888,12 +888,21 @@
 
     public static float getFontCharsWidth(char[] data, int offset, int len,
                                           FontMetrics fm,
                                           boolean useFPAPI)
     {
-        return len == 0 ? 0 : getFontStringWidth(new String(data, offset, len),
-                                                 fm, useFPAPI);
+        if (len == 0) {
+           return 0;
+        }
+        if (useFPAPI) {
+            Rectangle2D bounds = fm.getFont().
+                                     getStringBounds(data, offset, offset + len,
+                                                     fm.getFontRenderContext());
+            return (float) bounds.getWidth();
+        } else {
+            return fm.charsWidth(data, offset, len);
+        }
     }
 
     public static float getFontStringWidth(String data, FontMetrics fm,
                                            boolean useFPAPI)
     {
< prev index next >