jdk/src/share/classes/java/awt/FontMetrics.java
Print this page
@@ -27,10 +27,12 @@
import java.awt.Graphics2D;
import java.awt.font.FontRenderContext;
import java.awt.font.LineMetrics;
import java.awt.geom.Rectangle2D;
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
import java.text.CharacterIterator;
/**
* The <code>FontMetrics</code> class defines a font metrics object, which
* encapsulates information about the rendering of a particular font on a
@@ -408,11 +410,11 @@
* the bounds of the <code>data</code> array.
* @see #charsWidth(char[], int, int)
* @see #stringWidth(String)
*/
public int bytesWidth(byte data[], int off, int len) {
- return stringWidth(new String(data, 0, off, len));
+ return stringWidth(new String(data, off, len, StandardCharsets.ISO_8859_1));
}
/**
* Gets the advance widths of the first 256 characters in the
* <code>Font</code>. The advance is the