1 import javax.swing.*; 
   2 import java.awt.*; 
   3 import java.awt.font.*; 
   4 
   5 /* @test @(#)TestVS.java
   6  * @summary Verify two identical 'a's are rendered
   7  * @bug 8187100
   8  * @ignore Requires a special font installed.
   9  */
  10 public class VariationSelectorTest { 
  11     // A font supporting Unicode variation selectors is required 
  12     private static final Font FONT = new Font("DejaVu Sans", Font.PLAIN, 12); 
  13 
  14     public static void main(String[] args) { 
  15         SwingUtilities.invokeLater(() -> { 
  16             JFrame frame = new JFrame(); 
  17             frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
  18             frame.add(new MyComponent()); 
  19             frame.setSize(200, 200); 
  20             frame.setVisible(true); 
  21             frame.setLocationRelativeTo(null); 
  22         }); 
  23     } 
  24 
  25     private static class MyComponent extends JComponent { 
  26         @Override 
  27         protected void paintComponent(Graphics g) { 
  28             Graphics2D g2d = (Graphics2D) g; 
  29             FontRenderContext frc = g2d.getFontRenderContext(); 
  30             String text = "a"; 
  31             GlyphVector gv = FONT.layoutGlyphVector(frc, text.toCharArray(), 0, text.length(), Font.LAYOUT_LEFT_TO_RIGHT); 
  32             g2d.drawGlyphVector(gv, 80, 50); 
  33             String text2 = "a\ufe00"; 
  34             GlyphVector gv2 = FONT.layoutGlyphVector(frc, text2.toCharArray(), 0, text2.length(), Font.LAYOUT_LEFT_TO_RIGHT); 
  35             g2d.drawGlyphVector(gv2, 80, 100);
  36         } 
  37     } 
  38 } 
  39