test/jdk/javax/swing/plaf/basic/BasicGraphicsUtils/8132119/bug8132119.java
changeset 51189 0ce279d8c9cd
parent 47216 71c04702a3d5
child 59180 d8888ab6c0ec
equal deleted inserted replaced
51188:630b5e06a947 51189:0ce279d8c9cd
    39 import javax.swing.plaf.basic.BasicGraphicsUtils;
    39 import javax.swing.plaf.basic.BasicGraphicsUtils;
    40 import javax.swing.plaf.metal.MetalLookAndFeel;
    40 import javax.swing.plaf.metal.MetalLookAndFeel;
    41 
    41 
    42 /**
    42 /**
    43  * @test
    43  * @test
    44  * @bug 8132119 8168992 8169897
    44  * @bug 8132119 8168992 8169897 8207941
    45  * @author Alexandr Scherbatiy
    45  * @author Alexandr Scherbatiy
    46  * @summary Provide public API for text related methods in SwingBasicGraphicsUtils2
    46  * @summary Provide public API for text related methods in SwingBasicGraphicsUtils2
    47  */
    47  */
    48 public class bug8132119 {
    48 public class bug8132119 {
    49 
    49 
   275         comp.putClientProperty(TextAttribute.NUMERIC_SHAPING, NUMERIC_SHAPER);
   275         comp.putClientProperty(TextAttribute.NUMERIC_SHAPING, NUMERIC_SHAPER);
   276         comp.setFont(getFont());
   276         comp.setFont(getFont());
   277         return comp;
   277         return comp;
   278     }
   278     }
   279 
   279 
       
   280     private static String getFontName(String fn, String[] fontNames) {
       
   281         String fontName = null;
       
   282         for (String name : fontNames) {
       
   283             if (fn.equals(name)) {
       
   284                 fontName = name;
       
   285                 break;
       
   286             }
       
   287         }
       
   288         return fontName;
       
   289     }
       
   290 
   280     private static Font getFont() {
   291     private static Font getFont() {
   281         GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
   292         GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
   282         String[] fontNames = ge.getAvailableFontFamilyNames();
   293         String[] fontNames = ge.getAvailableFontFamilyNames();
   283         String fontName = fontNames[0];
   294 
   284         for (String name : fontNames) {
   295         // We do not have Arial on all systems so provide some reasonable fallbacks.
   285             if ("Arial".equals(name)) {
   296         // In case the fallbacks are not available as well, choose as last fallback
   286                 fontName = name;
   297         // the first font - however this might be a problematic choice.
   287                 break;
   298         String fontName = getFontName("Arial", fontNames);
       
   299         if (fontName == null) {
       
   300             fontName = getFontName("Bitstream Charter", fontNames);
       
   301             if (fontName == null) {
       
   302                 fontName = getFontName("Dialog", fontNames);
       
   303                 if (fontName == null) {
       
   304                     fontName = fontNames[0];
       
   305                     System.out.println("warning - preferred fonts not on the system, fall back to first font " + fontName);
       
   306                 }
   288             }
   307             }
   289         }
   308         }
   290         return new Font(fontName, Font.PLAIN, 30);
   309         return new Font(fontName, Font.PLAIN, 30);
   291     }
   310     }
   292 
   311