diff -r 097245f7db08 -r 6758b915b581 jdk/src/share/classes/sun/swing/SwingUtilities2.java --- a/jdk/src/share/classes/sun/swing/SwingUtilities2.java Tue Sep 15 16:26:40 2009 +0400 +++ b/jdk/src/share/classes/sun/swing/SwingUtilities2.java Wed Sep 16 16:15:41 2009 +0400 @@ -193,6 +193,19 @@ } /** + * Fill the character buffer cache. Return the buffer length. + */ + private static int syncCharsBuffer(String s) { + int length = s.length(); + if ((charsBuffer == null) || (charsBuffer.length < length)) { + charsBuffer = s.toCharArray(); + } else { + s.getChars(0, length, charsBuffer, 0); + } + return length; + } + + /** * checks whether TextLayout is required to handle characters. * * @param text characters to be tested @@ -353,7 +366,21 @@ if (string == null || string.equals("")) { return 0; } - return fm.stringWidth(string); + boolean needsTextLayout = ((c != null) && + (c.getClientProperty(TextAttribute.NUMERIC_SHAPING) != null)); + if (needsTextLayout) { + synchronized(charsBufferLock) { + int length = syncCharsBuffer(string); + needsTextLayout = isComplexLayout(charsBuffer, 0, length); + } + } + if (needsTextLayout) { + TextLayout layout = createTextLayout(c, string, + fm.getFont(), fm.getFontRenderContext()); + return (int) layout.getAdvance(); + } else { + return fm.stringWidth(string); + } } @@ -394,21 +421,11 @@ String string, int availTextWidth) { // c may be null here. String clipString = "..."; - int stringLength = string.length(); availTextWidth -= SwingUtilities2.stringWidth(c, fm, clipString); - if (availTextWidth <= 0) { - //can not fit any characters - return clipString; - } - boolean needsTextLayout; synchronized (charsBufferLock) { - if (charsBuffer == null || charsBuffer.length < stringLength) { - charsBuffer = string.toCharArray(); - } else { - string.getChars(0, stringLength, charsBuffer, 0); - } + int stringLength = syncCharsBuffer(string); needsTextLayout = isComplexLayout(charsBuffer, 0, stringLength); if (!needsTextLayout) { @@ -425,6 +442,10 @@ if (needsTextLayout) { FontRenderContext frc = getFontRenderContext(c, fm); AttributedString aString = new AttributedString(string); + if (c != null) { + aString.addAttribute(TextAttribute.NUMERIC_SHAPING, + c.getClientProperty(TextAttribute.NUMERIC_SHAPING)); + } LineBreakMeasurer measurer = new LineBreakMeasurer(aString.getIterator(), frc); int nChars = measurer.nextOffset(availTextWidth); @@ -465,7 +486,7 @@ */ float screenWidth = (float) g2d.getFont().getStringBounds(text, DEFAULT_FRC).getWidth(); - TextLayout layout = new TextLayout(text, g2d.getFont(), + TextLayout layout = createTextLayout(c, text, g2d.getFont(), g2d.getFontRenderContext()); layout = layout.getJustifiedLayout(screenWidth); @@ -505,7 +526,21 @@ } } - g.drawString(text, x, y); + boolean needsTextLayout = ((c != null) && + (c.getClientProperty(TextAttribute.NUMERIC_SHAPING) != null)); + if (needsTextLayout) { + synchronized(charsBufferLock) { + int length = syncCharsBuffer(text); + needsTextLayout = isComplexLayout(charsBuffer, 0, length); + } + } + if (needsTextLayout) { + TextLayout layout = createTextLayout(c, text, g2.getFont(), + g2.getFontRenderContext()); + layout.draw(g2, x, y); + } else { + g.drawString(text, x, y); + } if (oldAAValue != null) { g2.setRenderingHint(KEY_TEXT_ANTIALIASING, oldAAValue); @@ -547,11 +582,7 @@ boolean needsTextLayout = isPrinting; if (!needsTextLayout) { synchronized (charsBufferLock) { - if (charsBuffer == null || charsBuffer.length < textLength) { - charsBuffer = text.toCharArray(); - } else { - text.getChars(0, textLength, charsBuffer, 0); - } + syncCharsBuffer(text); needsTextLayout = isComplexLayout(charsBuffer, 0, textLength); } @@ -567,7 +598,7 @@ Graphics2D g2d = getGraphics2D(g); if (g2d != null) { TextLayout layout = - new TextLayout(text, g2d.getFont(), + createTextLayout(c, text, g2d.getFont(), g2d.getFontRenderContext()); if (isPrinting) { float screenWidth = (float)g2d.getFont(). @@ -728,7 +759,7 @@ !isFontRenderContextPrintCompatible (deviceFontRenderContext, frc)) { TextLayout layout = - new TextLayout(new String(data,offset,length), + createTextLayout(c, new String(data, offset, length), g2d.getFont(), deviceFontRenderContext); float screenWidth = (float)g2d.getFont(). @@ -846,6 +877,20 @@ return retVal; } + private static TextLayout createTextLayout(JComponent c, String s, + Font f, FontRenderContext frc) { + Object shaper = (c == null ? + null : c.getClientProperty(TextAttribute.NUMERIC_SHAPING)); + if (shaper == null) { + return new TextLayout(s, f, frc); + } else { + Map a = new HashMap(); + a.put(TextAttribute.FONT, f); + a.put(TextAttribute.NUMERIC_SHAPING, shaper); + return new TextLayout(s, a, frc); + } + } + /* * Checks if two given FontRenderContexts are compatible for printing. * We can't just use equals as we want to exclude from the comparison :