1 /* 2 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 import java.awt.Graphics; 25 import java.awt.Graphics2D; 26 import java.awt.Robot; 27 import java.awt.image.BufferedImage; 28 import java.io.File; 29 30 import javax.imageio.ImageIO; 31 import javax.swing.JFrame; 32 import javax.swing.JLabel; 33 import javax.swing.SwingUtilities; 34 35 import static java.awt.image.BufferedImage.TYPE_INT_ARGB; 36 37 /** 38 * @test 39 * @bug 8015085 40 * @summary Shortening via " ... " is broken for Strings containing a combining 41 * diaeresis. 42 * @author Sergey Bylokhov 43 */ 44 public class TestBadBreak { 45 46 static JFrame frame; 47 static Robot robot; 48 static final String withCombiningDiaeresis = "123p://.aaaaaaaaaaaaaaaaaaaaaa.123/a\u0308" ; 49 static final String withoutCombiningDiaeresis = "123p://.aaaaaaaaaaaaaaaaaaaaaa.123/\u00E4" ; 50 51 public static void main(final String[] args) throws Exception { 52 robot = new Robot(); 53 final BufferedImage bi1 = new BufferedImage(200, 90, TYPE_INT_ARGB); 54 final BufferedImage bi2 = new BufferedImage(200, 90, TYPE_INT_ARGB); 55 test(withCombiningDiaeresis, bi1); 56 test(withoutCombiningDiaeresis, bi2); 57 for (int x = 0; x < bi1.getWidth(); ++x) { 58 for (int y = 0; y < bi1.getHeight(); ++y) { 59 if (bi1.getRGB(x, y) != bi2.getRGB(x, y)) { 60 ImageIO.write(bi1, "png", new File("image1.png")); 61 ImageIO.write(bi2, "png", new File("image2.png")); 62 throw new RuntimeException("Wrong color"); 63 } 64 } 65 } 66 } 67 68 private static void test(final String text, final BufferedImage i1) 69 throws Exception { 70 SwingUtilities.invokeAndWait(new Runnable() { 71 @Override 72 public void run() { 73 frame = new JFrame(); 74 final JLabel label = new JLabel(text) { 75 @Override 76 protected void paintComponent(Graphics g) { 77 Graphics2D g2d = i1.createGraphics(); 78 super.paintComponent(g2d); 79 g2d.dispose(); 80 } 81 }; 82 frame.getContentPane().add(label); 83 frame.setBounds(200, 200, 200, 90); 84 } 85 }); 86 robot.waitForIdle(); 87 SwingUtilities.invokeAndWait(() -> frame.setVisible(true)); 88 robot.waitForIdle(); 89 SwingUtilities.invokeAndWait(frame::dispose); 90 robot.waitForIdle(); 91 } 92 }