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 * @key headful 40 * @bug 8015085 41 * @summary Shortening via " ... " is broken for Strings containing a combining 42 * diaeresis. 43 * @author Sergey Bylokhov 44 */ 45 public class TestBadBreak { 46 47 static JFrame frame; 48 static Robot robot; 49 static final String withCombiningDiaeresis = "123p://.aaaaaaaaaaaaaaaaaaaaaa.123/a\u0308" ; 50 static final String withoutCombiningDiaeresis = "123p://.aaaaaaaaaaaaaaaaaaaaaa.123/\u00E4" ; 51 52 public static void main(final String[] args) throws Exception { 53 robot = new Robot(); 54 final BufferedImage bi1 = new BufferedImage(200, 90, TYPE_INT_ARGB); 55 final BufferedImage bi2 = new BufferedImage(200, 90, TYPE_INT_ARGB); 56 test(withCombiningDiaeresis, bi1); 57 test(withoutCombiningDiaeresis, bi2); 58 for (int x = 0; x < bi1.getWidth(); ++x) { 59 for (int y = 0; y < bi1.getHeight(); ++y) { 60 if (bi1.getRGB(x, y) != bi2.getRGB(x, y)) { 61 ImageIO.write(bi1, "png", new File("image1.png")); 62 ImageIO.write(bi2, "png", new File("image2.png")); 63 throw new RuntimeException("Wrong color"); 64 } 65 } 66 } 67 } 68 69 private static void test(final String text, final BufferedImage i1) 70 throws Exception { 71 SwingUtilities.invokeAndWait(new Runnable() { 72 @Override 73 public void run() { 74 frame = new JFrame(); 75 final JLabel label = new JLabel(text) { 76 @Override 77 protected void paintComponent(Graphics g) { 78 Graphics2D g2d = i1.createGraphics(); 79 super.paintComponent(g2d); 80 g2d.dispose(); 81 } 82 }; 83 frame.getContentPane().add(label); 84 frame.setBounds(200, 200, 200, 90); 85 } 86 }); 87 robot.waitForIdle(); 88 SwingUtilities.invokeAndWait(() -> frame.setVisible(true)); 89 robot.waitForIdle(); 90 SwingUtilities.invokeAndWait(frame::dispose); 91 robot.waitForIdle(); 92 } 93 }