8189809: Large performance regression in Swing text layout
Reviewed-by: serb, pnarayanan
This commit is contained in:
parent
5f530a331b
commit
a110ef1d2f
@ -56,6 +56,7 @@ import sun.font.CreatedFontTracker;
|
||||
import sun.font.Font2D;
|
||||
import sun.font.Font2DHandle;
|
||||
import sun.font.FontAccess;
|
||||
import sun.font.FontDesignMetrics;
|
||||
import sun.font.FontManager;
|
||||
import sun.font.FontManagerFactory;
|
||||
import sun.font.FontUtilities;
|
||||
@ -2603,9 +2604,8 @@ public class Font implements java.io.Serializable
|
||||
}
|
||||
|
||||
if (simple) {
|
||||
GlyphVector gv = new StandardGlyphVector(this, chars, beginIndex,
|
||||
limit - beginIndex, frc);
|
||||
return gv.getLogicalBounds();
|
||||
FontDesignMetrics metrics = FontDesignMetrics.getMetrics(this, frc);
|
||||
return metrics.getSimpleBounds(chars, beginIndex, limit-beginIndex);
|
||||
} else {
|
||||
// need char array constructor on textlayout
|
||||
String str = new String(chars, beginIndex, limit - beginIndex);
|
||||
|
@ -33,6 +33,7 @@ import java.awt.Font;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.awt.geom.NoninvertibleTransformException;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.awt.font.FontRenderContext;
|
||||
import java.awt.font.TextLayout;
|
||||
|
||||
@ -518,6 +519,28 @@ public final class FontDesignMetrics extends FontMetrics {
|
||||
return (int) (0.5 + width);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called from java.awt.Font only after verifying
|
||||
* the arguments and that the text is simple and there are no
|
||||
* layout attributes, font transform etc.
|
||||
*/
|
||||
public Rectangle2D getSimpleBounds(char data[], int off, int len) {
|
||||
|
||||
float width = 0;
|
||||
int limit = off + len;
|
||||
for (int i=off; i < limit; i++) {
|
||||
char ch = data[i];
|
||||
if (ch < 0x100) {
|
||||
width += getLatinCharWidth(ch);
|
||||
} else {
|
||||
width += handleCharWidth(ch);
|
||||
}
|
||||
}
|
||||
|
||||
float height = ascent + descent + leading;
|
||||
return new Rectangle2D.Float(0f, -ascent, width, height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the advance widths of the first 256 characters in the
|
||||
* {@code Font}. The advance is the
|
||||
|
@ -890,8 +890,17 @@ public class SwingUtilities2 {
|
||||
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,
|
||||
|
Loading…
Reference in New Issue
Block a user