1 /* @test 2 * @summary Verify two identical 'a's are rendered 3 * @bug 8187100 4 * @ignore Requires a special font installed. 5 */ 6 import javax.swing.JFrame; 7 import javax.swing.JComponent; 8 import javax.swing.SwingUtilities; 9 import javax.swing.WindowConstants; 10 import java.awt.Font; 11 import java.awt.Graphics; 12 import java.awt.Graphics2D; 13 import java.awt.font.FontRenderContext; 14 import java.awt.font.GlyphVector; 15 16 public class VariationSelectorTest { 17 // A font supporting Unicode variation selectors is required 18 private static final Font FONT = new Font("DejaVu Sans", Font.PLAIN, 12); 19 20 public static void main(String[] args) { 21 final String fontName = FONT.getFontName(); 22 if (!fontName.equals("DejaVuSans")) { 23 System.err.println("*** Warning: Font DejaVuSans not installed."); 24 System.err.println("*** Using font: " + fontName); 25 } 26 SwingUtilities.invokeLater(() -> { 27 JFrame frame = new JFrame(); 28 frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); 29 frame.add(new MyComponent()); 30 frame.setSize(200, 200); 31 frame.setVisible(true); 32 frame.setLocationRelativeTo(null); 33 }); 34 } 35 36 private static class MyComponent extends JComponent { 37 @Override 38 protected void paintComponent(Graphics g) { 39 Graphics2D g2d = (Graphics2D) g; 40 FontRenderContext frc = g2d.getFontRenderContext(); 41 String text = "a"; 42 GlyphVector gv = FONT.layoutGlyphVector( 43 frc, text.toCharArray(), 0, text.length(), 44 Font.LAYOUT_LEFT_TO_RIGHT); 45 System.out.println("'a'=" + gv.getNumGlyphs()); 46 g2d.drawString("=" + gv.getNumGlyphs() + " ('a')", 100, 50); 47 g2d.drawGlyphVector(gv, 80, 50); 48 String text2 = "a\ufe00"; 49 GlyphVector gv2 = FONT.layoutGlyphVector( 50 frc, text2.toCharArray(), 0, text2.length(), 51 Font.LAYOUT_LEFT_TO_RIGHT); 52 g2d.drawGlyphVector(gv2, 80, 100); 53 System.out.println("'a'+VS=" + gv2.getNumGlyphs()); 54 g2d.drawString("=" + gv2.getNumGlyphs() + " ('a'+VS)", 100, 100); 55 if ((gv.getNumGlyphs() == 1) && (gv2.getNumGlyphs() == 1)) { 56 System.out.println("PASS"); 57 g2d.drawString("PASS", 10, 15); 58 } else { 59 System.err.println("FAIL"); 60 g2d.drawString("FAIL", 10, 15); 61 } 62 } 63 } 64 }