< prev index next >

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

Print this page

        

@@ -522,19 +522,15 @@
                  * more evenly than directly laying out to the screen advances.
                  */
                 String trimmedText = trimTrailingSpaces(text);
                 if (!trimmedText.isEmpty()) {
                     float screenWidth = (float) g2d.getFont().getStringBounds
-                            (trimmedText, getFontRenderContext(c)).getWidth();
+                            (trimmedText, DEFAULT_FRC).getWidth();
                     TextLayout layout = createTextLayout(c, text, g2d.getFont(),
                                                        g2d.getFontRenderContext());
 
-                    // If text fits the screenWidth, then do not need to justify
-                    if (SwingUtilities2.stringWidth(c, g2d.getFontMetrics(),
-                                            trimmedText) > screenWidth) {
-                        layout = layout.getJustifiedLayout(screenWidth);
-                    }
+                    layout = layout.getJustifiedLayout(screenWidth);
                     /* Use alternate print color if specified */
                     Color col = g2d.getColor();
                     if (col instanceof PrintColorUIResource) {
                         g2d.setColor(((PrintColorUIResource)col).getPrintColor());
                     }

@@ -679,16 +675,12 @@
                     TextLayout layout =
                         createTextLayout(c, text, g2d.getFont(),
                                        g2d.getFontRenderContext());
                     if (isPrinting) {
                         float screenWidth = (float)g2d.getFont().
-                            getStringBounds(text, getFontRenderContext(c)).getWidth();
-                        // If text fits the screenWidth, then do not need to justify
-                        if (SwingUtilities2.stringWidth(c, g2d.getFontMetrics(),
-                                                        text) > screenWidth) {
-                            layout = layout.getJustifiedLayout(screenWidth);
-                        }
+                            getStringBounds(text, DEFAULT_FRC).getWidth();
+                        layout = layout.getJustifiedLayout(screenWidth);
                     }
                     TextHitInfo leading =
                         TextHitInfo.leading(underlinedIndex);
                     TextHitInfo trailing =
                         TextHitInfo.trailing(underlinedIndex);

@@ -869,15 +861,11 @@
                                     deviceFontRenderContext);
                     String trimmedText = trimTrailingSpaces(text);
                     if (!trimmedText.isEmpty()) {
                         float screenWidth = (float)g2d.getFont().
                             getStringBounds(trimmedText, frc).getWidth();
-                        // If text fits the screenWidth, then do not need to justify
-                        if (SwingUtilities2.stringWidth(c, g2d.getFontMetrics(),
-                                                trimmedText) > screenWidth) {
-                            layout = layout.getJustifiedLayout(screenWidth);
-                        }
+                        layout = layout.getJustifiedLayout(screenWidth);
 
                         /* Use alternate print color if specified */
                         Color col = g2d.getColor();
                         if (col instanceof PrintColorUIResource) {
                             g2d.setColor(((PrintColorUIResource)col).getPrintColor());
< prev index next >