test/jdk/javax/swing/plaf/basic/BasicGraphicsUtils/8132119/bug8132119.java
author mbaesken
Tue, 24 Jul 2018 09:27:42 +0200
changeset 51189 0ce279d8c9cd
parent 47216 71c04702a3d5
child 59180 d8888ab6c0ec
permissions -rw-r--r--
8207941: javax/swing/plaf/basic/BasicGraphicsUtils/8132119/bug8132119.java fails on machines without Arial font [testbug] Reviewed-by: goetz, psadhukhan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
42200
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
     1
/*
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
     4
 *
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
     7
 * published by the Free Software Foundation.
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
     8
 *
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    13
 * accompanied this code).
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    14
 *
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    18
 *
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    21
 * questions.
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    22
 */
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    23
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    24
import java.awt.Color;
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    25
import java.awt.Font;
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    26
import java.awt.FontMetrics;
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    27
import java.awt.Graphics2D;
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    28
import java.awt.GraphicsEnvironment;
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    29
import java.awt.font.FontRenderContext;
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    30
import java.awt.font.NumericShaper;
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    31
import java.awt.font.TextAttribute;
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    32
import java.awt.font.TextLayout;
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    33
import java.awt.image.BufferedImage;
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    34
import java.util.HashMap;
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    35
import javax.swing.JComponent;
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    36
import javax.swing.JLabel;
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    37
import javax.swing.SwingUtilities;
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    38
import javax.swing.UIManager;
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    39
import javax.swing.plaf.basic.BasicGraphicsUtils;
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    40
import javax.swing.plaf.metal.MetalLookAndFeel;
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    41
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    42
/**
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    43
 * @test
51189
0ce279d8c9cd 8207941: javax/swing/plaf/basic/BasicGraphicsUtils/8132119/bug8132119.java fails on machines without Arial font [testbug]
mbaesken
parents: 47216
diff changeset
    44
 * @bug 8132119 8168992 8169897 8207941
42200
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    45
 * @author Alexandr Scherbatiy
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    46
 * @summary Provide public API for text related methods in SwingBasicGraphicsUtils2
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    47
 */
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    48
public class bug8132119 {
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    49
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    50
    private static final int WIDTH = 50;
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    51
    private static final int HEIGHT = 50;
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    52
    private static final Color DRAW_COLOR = Color.RED;
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    53
    private static final Color BACKGROUND_COLOR = Color.GREEN;
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    54
    private static final NumericShaper NUMERIC_SHAPER = NumericShaper.getShaper(
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    55
            NumericShaper.ARABIC);
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    56
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    57
    public static void main(String[] args) throws Exception {
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    58
        SwingUtilities.invokeAndWait(bug8132119::testStringMethods);
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    59
    }
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    60
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    61
    private static void testStringMethods() {
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    62
        setMetalLAF();
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    63
        testStringWidth();
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    64
        testStringClip();
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    65
        testDrawEmptyString();
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    66
        testDrawString(false);
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    67
        testDrawString(true);
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    68
        checkNullArguments();
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    69
    }
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    70
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    71
    private static void testStringWidth() {
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    72
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    73
        String str = "12345678910\u036F";
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    74
        JComponent comp = createComponent(str);
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    75
        Font font = comp.getFont();
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    76
        FontMetrics fontMetrics = comp.getFontMetrics(font);
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    77
        float stringWidth = BasicGraphicsUtils.getStringWidth(comp, fontMetrics, str);
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    78
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    79
        if (stringWidth == fontMetrics.stringWidth(str)) {
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    80
            throw new RuntimeException("Numeric shaper is not used!");
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    81
        }
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    82
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    83
        if (stringWidth != getLayoutWidth(str, font, NUMERIC_SHAPER)) {
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    84
            throw new RuntimeException("Wrong text width!");
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    85
        }
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    86
    }
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    87
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    88
    private static void testStringClip() {
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    89
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    90
        String str = "1234567890";
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    91
        JComponent comp = createComponent(str);
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    92
        FontMetrics fontMetrics = comp.getFontMetrics(comp.getFont());
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    93
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    94
        int width = (int) BasicGraphicsUtils.getStringWidth(comp, fontMetrics, str);
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    95
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    96
        String clip = BasicGraphicsUtils.getClippedString(comp, fontMetrics, str, width);
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    97
        checkClippedString(str, clip, str);
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    98
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
    99
        clip = BasicGraphicsUtils.getClippedString(comp, fontMetrics, str, width + 1);
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   100
        checkClippedString(str, clip, str);
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   101
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   102
        clip = BasicGraphicsUtils.getClippedString(comp, fontMetrics, str, -1);
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   103
        checkClippedString(str, clip, "...");
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   104
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   105
        clip = BasicGraphicsUtils.getClippedString(comp, fontMetrics, str, 0);
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   106
        checkClippedString(str, clip, "...");
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   107
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   108
        clip = BasicGraphicsUtils.getClippedString(comp, fontMetrics,
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   109
                str, width - width / str.length());
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   110
        int endIndex = str.length() - 3;
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   111
        checkClippedString(str, clip, str.substring(0, endIndex) + "...");
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   112
    }
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   113
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   114
    private static void checkClippedString(String str, String res, String golden) {
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   115
        if (!golden.equals(res)) {
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   116
            throw new RuntimeException(String.format("The string '%s' is not "
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   117
                    + "properly clipped. The result is '%s' instead of '%s'",
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   118
                    str, res, golden));
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   119
        }
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   120
    }
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   121
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   122
    private static void testDrawEmptyString() {
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   123
        JLabel label = new JLabel();
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   124
        BufferedImage buffImage = createBufferedImage(50, 50);
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   125
        Graphics2D g2 = buffImage.createGraphics();
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   126
        g2.setColor(DRAW_COLOR);
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   127
        BasicGraphicsUtils.drawString(null, g2, null, 0, 0);
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   128
        BasicGraphicsUtils.drawString(label, g2, null, 0, 0);
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   129
        BasicGraphicsUtils.drawString(null, g2, "", 0, 0);
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   130
        BasicGraphicsUtils.drawString(label, g2, "", 0, 0);
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   131
        BasicGraphicsUtils.drawStringUnderlineCharAt(null, g2, null, 3, 0, 0);
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   132
        BasicGraphicsUtils.drawStringUnderlineCharAt(label, g2, null, 3, 0, 0);
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   133
        BasicGraphicsUtils.drawStringUnderlineCharAt(null, g2, "", 3, 0, 0);
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   134
        BasicGraphicsUtils.drawStringUnderlineCharAt(label, g2, "", 3, 0, 0);
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   135
        g2.dispose();
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   136
        checkImageIsEmpty(buffImage);
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   137
    }
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   138
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   139
    private static void testDrawString(boolean underlined) {
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   140
        String str = "AOB";
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   141
        JComponent comp = createComponent(str);
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   142
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   143
        BufferedImage buffImage = createBufferedImage(WIDTH, HEIGHT);
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   144
        Graphics2D g2 = buffImage.createGraphics();
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   145
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   146
        g2.setColor(DRAW_COLOR);
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   147
        g2.setFont(comp.getFont());
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   148
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   149
        FontMetrics fontMetrices = comp.getFontMetrics(comp.getFont());
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   150
        float width = BasicGraphicsUtils.getStringWidth(comp, fontMetrices, str);
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   151
        float x = (WIDTH - width) / 2;
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   152
        int y = 3 * HEIGHT / 4;
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   153
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   154
        if (underlined) {
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   155
            BasicGraphicsUtils.drawStringUnderlineCharAt(comp, g2, str, 1, x, y);
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   156
        } else {
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   157
            BasicGraphicsUtils.drawString(comp, g2, str, x, y);
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   158
        }
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   159
        g2.dispose();
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   160
45344
60b7b5f39580 8169897: [PIT] javax/swing/plaf/basic/BasicGraphicsUtils/8132119/bug8132119.java fails
psadhukhan
parents: 42200
diff changeset
   161
        float xx = BasicGraphicsUtils.getStringWidth(comp, fontMetrices, "A") +
60b7b5f39580 8169897: [PIT] javax/swing/plaf/basic/BasicGraphicsUtils/8132119/bug8132119.java fails
psadhukhan
parents: 42200
diff changeset
   162
                BasicGraphicsUtils.getStringWidth(comp, fontMetrices, "O")/2;
60b7b5f39580 8169897: [PIT] javax/swing/plaf/basic/BasicGraphicsUtils/8132119/bug8132119.java fails
psadhukhan
parents: 42200
diff changeset
   163
42200
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   164
        checkImageContainsSymbol(buffImage, (int) xx, underlined ? 3 : 2);
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   165
    }
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   166
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   167
    private static void checkNullArguments() {
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   168
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   169
        Graphics2D g = null;
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   170
        try {
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   171
            String text = "Test";
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   172
            JComponent component = new JLabel(text);
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   173
            BufferedImage img = createBufferedImage(100, 100);
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   174
            g = img.createGraphics();
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   175
            checkNullArguments(component, g, text);
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   176
        } finally {
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   177
            g.dispose();
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   178
        }
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   179
    }
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   180
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   181
    private static void checkNullArguments(JComponent comp, Graphics2D g,
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   182
            String text) {
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   183
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   184
        checkNullArgumentsDrawString(comp, g, text);
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   185
        checkNullArgumentsDrawStringUnderlineCharAt(comp, g, text);
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   186
        checkNullArgumentsGetClippedString(comp, text);
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   187
        checkNullArgumentsGetStringWidth(comp, text);
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   188
    }
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   189
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   190
    private static void checkNullArgumentsDrawString(JComponent comp, Graphics2D g,
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   191
            String text) {
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   192
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   193
        float x = 50;
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   194
        float y = 50;
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   195
        BasicGraphicsUtils.drawString(null, g, text, x, y);
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   196
        BasicGraphicsUtils.drawString(comp, g, null, x, y);
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   197
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   198
        try {
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   199
            BasicGraphicsUtils.drawString(comp, null, text, x, y);
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   200
        } catch (NullPointerException e) {
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   201
            return;
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   202
        }
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   203
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   204
        throw new RuntimeException("NPE is not thrown");
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   205
    }
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   206
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   207
    private static void checkNullArgumentsDrawStringUnderlineCharAt(
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   208
            JComponent comp, Graphics2D g, String text) {
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   209
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   210
        int x = 50;
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   211
        int y = 50;
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   212
        BasicGraphicsUtils.drawStringUnderlineCharAt(null, g, text, 1, x, y);
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   213
        BasicGraphicsUtils.drawStringUnderlineCharAt(comp, g, null, 1, x, y);
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   214
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   215
        try {
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   216
            BasicGraphicsUtils.drawStringUnderlineCharAt(comp, null, text, 1, x, y);
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   217
        } catch (NullPointerException e) {
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   218
            return;
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   219
        }
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   220
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   221
        throw new RuntimeException("NPE is not thrown");
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   222
    }
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   223
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   224
    private static void checkNullArgumentsGetClippedString(
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   225
            JComponent comp, String text) {
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   226
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   227
        FontMetrics fontMetrics = comp.getFontMetrics(comp.getFont());
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   228
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   229
        BasicGraphicsUtils.getClippedString(null, fontMetrics, text, 1);
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   230
        String result = BasicGraphicsUtils.getClippedString(comp, fontMetrics, null, 1);
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   231
        if (!"".equals(result)) {
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   232
            throw new RuntimeException("Empty string is not returned!");
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   233
        }
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   234
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   235
        try {
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   236
            BasicGraphicsUtils.getClippedString(comp, null, text, 1);
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   237
        } catch (NullPointerException e) {
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   238
            return;
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   239
        }
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   240
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   241
        throw new RuntimeException("NPE is not thrown");
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   242
    }
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   243
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   244
    private static void checkNullArgumentsGetStringWidth(JComponent comp,
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   245
            String text) {
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   246
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   247
        FontMetrics fontMetrics = comp.getFontMetrics(comp.getFont());
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   248
        BasicGraphicsUtils.getStringWidth(null, fontMetrics, text);
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   249
        float result = BasicGraphicsUtils.getStringWidth(comp, fontMetrics, null);
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   250
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   251
        if (result != 0) {
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   252
            throw new RuntimeException("The string length is not 0");
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   253
        }
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   254
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   255
        try {
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   256
            BasicGraphicsUtils.getStringWidth(comp, null, text);
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   257
        } catch (NullPointerException e) {
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   258
            return;
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   259
        }
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   260
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   261
        throw new RuntimeException("NPE is not thrown");
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   262
    }
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   263
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   264
    private static void setMetalLAF() {
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   265
        try {
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   266
            UIManager.setLookAndFeel(new MetalLookAndFeel());
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   267
        } catch (Exception e) {
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   268
            throw new RuntimeException(e);
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   269
        }
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   270
    }
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   271
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   272
    private static JComponent createComponent(String str) {
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   273
        JComponent comp = new JLabel(str);
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   274
        comp.setSize(WIDTH, HEIGHT);
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   275
        comp.putClientProperty(TextAttribute.NUMERIC_SHAPING, NUMERIC_SHAPER);
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   276
        comp.setFont(getFont());
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   277
        return comp;
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   278
    }
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   279
51189
0ce279d8c9cd 8207941: javax/swing/plaf/basic/BasicGraphicsUtils/8132119/bug8132119.java fails on machines without Arial font [testbug]
mbaesken
parents: 47216
diff changeset
   280
    private static String getFontName(String fn, String[] fontNames) {
0ce279d8c9cd 8207941: javax/swing/plaf/basic/BasicGraphicsUtils/8132119/bug8132119.java fails on machines without Arial font [testbug]
mbaesken
parents: 47216
diff changeset
   281
        String fontName = null;
0ce279d8c9cd 8207941: javax/swing/plaf/basic/BasicGraphicsUtils/8132119/bug8132119.java fails on machines without Arial font [testbug]
mbaesken
parents: 47216
diff changeset
   282
        for (String name : fontNames) {
0ce279d8c9cd 8207941: javax/swing/plaf/basic/BasicGraphicsUtils/8132119/bug8132119.java fails on machines without Arial font [testbug]
mbaesken
parents: 47216
diff changeset
   283
            if (fn.equals(name)) {
0ce279d8c9cd 8207941: javax/swing/plaf/basic/BasicGraphicsUtils/8132119/bug8132119.java fails on machines without Arial font [testbug]
mbaesken
parents: 47216
diff changeset
   284
                fontName = name;
0ce279d8c9cd 8207941: javax/swing/plaf/basic/BasicGraphicsUtils/8132119/bug8132119.java fails on machines without Arial font [testbug]
mbaesken
parents: 47216
diff changeset
   285
                break;
0ce279d8c9cd 8207941: javax/swing/plaf/basic/BasicGraphicsUtils/8132119/bug8132119.java fails on machines without Arial font [testbug]
mbaesken
parents: 47216
diff changeset
   286
            }
0ce279d8c9cd 8207941: javax/swing/plaf/basic/BasicGraphicsUtils/8132119/bug8132119.java fails on machines without Arial font [testbug]
mbaesken
parents: 47216
diff changeset
   287
        }
0ce279d8c9cd 8207941: javax/swing/plaf/basic/BasicGraphicsUtils/8132119/bug8132119.java fails on machines without Arial font [testbug]
mbaesken
parents: 47216
diff changeset
   288
        return fontName;
0ce279d8c9cd 8207941: javax/swing/plaf/basic/BasicGraphicsUtils/8132119/bug8132119.java fails on machines without Arial font [testbug]
mbaesken
parents: 47216
diff changeset
   289
    }
0ce279d8c9cd 8207941: javax/swing/plaf/basic/BasicGraphicsUtils/8132119/bug8132119.java fails on machines without Arial font [testbug]
mbaesken
parents: 47216
diff changeset
   290
42200
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   291
    private static Font getFont() {
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   292
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   293
        String[] fontNames = ge.getAvailableFontFamilyNames();
51189
0ce279d8c9cd 8207941: javax/swing/plaf/basic/BasicGraphicsUtils/8132119/bug8132119.java fails on machines without Arial font [testbug]
mbaesken
parents: 47216
diff changeset
   294
0ce279d8c9cd 8207941: javax/swing/plaf/basic/BasicGraphicsUtils/8132119/bug8132119.java fails on machines without Arial font [testbug]
mbaesken
parents: 47216
diff changeset
   295
        // We do not have Arial on all systems so provide some reasonable fallbacks.
0ce279d8c9cd 8207941: javax/swing/plaf/basic/BasicGraphicsUtils/8132119/bug8132119.java fails on machines without Arial font [testbug]
mbaesken
parents: 47216
diff changeset
   296
        // In case the fallbacks are not available as well, choose as last fallback
0ce279d8c9cd 8207941: javax/swing/plaf/basic/BasicGraphicsUtils/8132119/bug8132119.java fails on machines without Arial font [testbug]
mbaesken
parents: 47216
diff changeset
   297
        // the first font - however this might be a problematic choice.
0ce279d8c9cd 8207941: javax/swing/plaf/basic/BasicGraphicsUtils/8132119/bug8132119.java fails on machines without Arial font [testbug]
mbaesken
parents: 47216
diff changeset
   298
        String fontName = getFontName("Arial", fontNames);
0ce279d8c9cd 8207941: javax/swing/plaf/basic/BasicGraphicsUtils/8132119/bug8132119.java fails on machines without Arial font [testbug]
mbaesken
parents: 47216
diff changeset
   299
        if (fontName == null) {
0ce279d8c9cd 8207941: javax/swing/plaf/basic/BasicGraphicsUtils/8132119/bug8132119.java fails on machines without Arial font [testbug]
mbaesken
parents: 47216
diff changeset
   300
            fontName = getFontName("Bitstream Charter", fontNames);
0ce279d8c9cd 8207941: javax/swing/plaf/basic/BasicGraphicsUtils/8132119/bug8132119.java fails on machines without Arial font [testbug]
mbaesken
parents: 47216
diff changeset
   301
            if (fontName == null) {
0ce279d8c9cd 8207941: javax/swing/plaf/basic/BasicGraphicsUtils/8132119/bug8132119.java fails on machines without Arial font [testbug]
mbaesken
parents: 47216
diff changeset
   302
                fontName = getFontName("Dialog", fontNames);
0ce279d8c9cd 8207941: javax/swing/plaf/basic/BasicGraphicsUtils/8132119/bug8132119.java fails on machines without Arial font [testbug]
mbaesken
parents: 47216
diff changeset
   303
                if (fontName == null) {
0ce279d8c9cd 8207941: javax/swing/plaf/basic/BasicGraphicsUtils/8132119/bug8132119.java fails on machines without Arial font [testbug]
mbaesken
parents: 47216
diff changeset
   304
                    fontName = fontNames[0];
0ce279d8c9cd 8207941: javax/swing/plaf/basic/BasicGraphicsUtils/8132119/bug8132119.java fails on machines without Arial font [testbug]
mbaesken
parents: 47216
diff changeset
   305
                    System.out.println("warning - preferred fonts not on the system, fall back to first font " + fontName);
0ce279d8c9cd 8207941: javax/swing/plaf/basic/BasicGraphicsUtils/8132119/bug8132119.java fails on machines without Arial font [testbug]
mbaesken
parents: 47216
diff changeset
   306
                }
42200
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   307
            }
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   308
        }
45344
60b7b5f39580 8169897: [PIT] javax/swing/plaf/basic/BasicGraphicsUtils/8132119/bug8132119.java fails
psadhukhan
parents: 42200
diff changeset
   309
        return new Font(fontName, Font.PLAIN, 30);
42200
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   310
    }
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   311
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   312
    private static float getLayoutWidth(String text, Font font, NumericShaper shaper) {
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   313
        HashMap map = new HashMap();
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   314
        map.put(TextAttribute.FONT, font);
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   315
        map.put(TextAttribute.NUMERIC_SHAPING, shaper);
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   316
        FontRenderContext frc = new FontRenderContext(null, false, false);
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   317
        TextLayout layout = new TextLayout(text, map, frc);
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   318
        return layout.getAdvance();
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   319
    }
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   320
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   321
    private static void checkImageIsEmpty(BufferedImage buffImage) {
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   322
        int background = BACKGROUND_COLOR.getRGB();
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   323
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   324
        for (int i = 0; i < buffImage.getWidth(); i++) {
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   325
            for (int j = 0; j < buffImage.getHeight(); j++) {
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   326
                if (background != buffImage.getRGB(i, j)) {
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   327
                    throw new RuntimeException("Image is not empty!");
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   328
                }
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   329
            }
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   330
        }
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   331
    }
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   332
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   333
    private static void checkImageContainsSymbol(BufferedImage buffImage,
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   334
            int x, int intersections) {
45344
60b7b5f39580 8169897: [PIT] javax/swing/plaf/basic/BasicGraphicsUtils/8132119/bug8132119.java fails
psadhukhan
parents: 42200
diff changeset
   335
42200
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   336
        int background = BACKGROUND_COLOR.getRGB();
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   337
        boolean isBackground = true;
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   338
        int backgroundChangesCount = 0;
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   339
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   340
        for (int y = 0; y < buffImage.getHeight(); y++) {
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   341
            if (!(isBackground ^ (background != buffImage.getRGB(x, y)))) {
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   342
                isBackground = !isBackground;
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   343
                backgroundChangesCount++;
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   344
            }
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   345
        }
45344
60b7b5f39580 8169897: [PIT] javax/swing/plaf/basic/BasicGraphicsUtils/8132119/bug8132119.java fails
psadhukhan
parents: 42200
diff changeset
   346
42200
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   347
        if (backgroundChangesCount != intersections * 2) {
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   348
            throw new RuntimeException("String is not properly drawn!");
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   349
        }
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   350
    }
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   351
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   352
    private static BufferedImage createBufferedImage(int width, int height) {
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   353
        BufferedImage bufffImage = new BufferedImage(width, height,
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   354
                BufferedImage.TYPE_INT_RGB);
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   355
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   356
        Graphics2D g = bufffImage.createGraphics();
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   357
        g.setColor(BACKGROUND_COLOR);
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   358
        g.fillRect(0, 0, width, height);
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   359
        g.dispose();
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   360
        return bufffImage;
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   361
    }
0ab62056c933 8168992: Add floating point implementation for new BasicGraphicsUtils text related methods use floating point API
alexsch
parents:
diff changeset
   362
}