Java Code Examples for java.awt.GraphicsEnvironment#preferProportionalFonts()

The following examples show how to use java.awt.GraphicsEnvironment#preferProportionalFonts() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestSGEuseAlternateFontforJALocales.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String args[]) throws Exception {
     System.out.println("Default Charset = "
         + Charset.defaultCharset().name());
     System.out.println("Locale = " + Locale.getDefault());
     String os = System.getProperty("os.name");
     String encoding = System.getProperty("file.encoding");
     /* Want to test the JA locale uses alternate font for DialogInput. */
     boolean jaTest = encoding.equalsIgnoreCase("windows-31j");
     if (!os.startsWith("Win") && jaTest) {
         System.out.println("Skipping Windows only test");
         return;
     }

     String className = "sun.java2d.SunGraphicsEnvironment";
     String methodName = "useAlternateFontforJALocales";
     Class sge = Class.forName(className);
     Method uafMethod = sge.getMethod(methodName, (Class[])null);
     Object ret = uafMethod.invoke(null);
     GraphicsEnvironment ge =
         GraphicsEnvironment.getLocalGraphicsEnvironment();
     ge.preferLocaleFonts();
     ge.preferProportionalFonts();
     if (jaTest) {
         Font msMincho = new Font("MS Mincho", Font.PLAIN, 12);
         if (!msMincho.getFamily(Locale.ENGLISH).equals("MS Mincho")) {
              System.out.println("MS Mincho not installed. Skipping test");
              return;
         }
         Font dialogInput = new Font("DialogInput", Font.PLAIN, 12);
         Font courierNew = new Font("Courier New", Font.PLAIN, 12);
         Font msGothic = new Font("MS Gothic", Font.PLAIN, 12);
         BufferedImage bi = new BufferedImage(1,1,1);
         Graphics2D g2d = bi.createGraphics();
         FontMetrics cnMetrics = g2d.getFontMetrics(courierNew);
         FontMetrics diMetrics = g2d.getFontMetrics(dialogInput);
         FontMetrics mmMetrics = g2d.getFontMetrics(msMincho);
         FontMetrics mgMetrics = g2d.getFontMetrics(msGothic);
         // This tests to make sure we at least have applied
         //  "preferLocaleFonts for Japanese
         if (cnMetrics.charWidth('A') == diMetrics.charWidth('A')) {
              throw new RuntimeException
                    ("Courier New should not be used for DialogInput");
         }
         // This is supposed to make sure we are using MS Mincho instead
         //  of MS Gothic. However they are metrics identical so its
         // not definite proof.
         if (diMetrics.charWidth('A') != mmMetrics.charWidth('A')) {
              throw new RuntimeException
                  ("MS Mincho should be used for DialogInput");
         }
    }
}
 
Example 2
Source File: TestSGEuseAlternateFontforJALocales.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String args[]) throws Exception {
     System.out.println("Default Charset = "
         + Charset.defaultCharset().name());
     System.out.println("Locale = " + Locale.getDefault());
     String os = System.getProperty("os.name");
     String encoding = System.getProperty("file.encoding");
     /* Want to test the JA locale uses alternate font for DialogInput. */
     boolean jaTest = encoding.equalsIgnoreCase("windows-31j");
     if (!os.startsWith("Win") && jaTest) {
         System.out.println("Skipping Windows only test");
         return;
     }

     String className = "sun.java2d.SunGraphicsEnvironment";
     String methodName = "useAlternateFontforJALocales";
     Class sge = Class.forName(className);
     Method uafMethod = sge.getMethod(methodName, (Class[])null);
     Object ret = uafMethod.invoke(null);
     GraphicsEnvironment ge =
         GraphicsEnvironment.getLocalGraphicsEnvironment();
     ge.preferLocaleFonts();
     ge.preferProportionalFonts();
     if (jaTest) {
         Font msMincho = new Font("MS Mincho", Font.PLAIN, 12);
         if (!msMincho.getFamily(Locale.ENGLISH).equals("MS Mincho")) {
              System.out.println("MS Mincho not installed. Skipping test");
              return;
         }
         Font dialogInput = new Font("DialogInput", Font.PLAIN, 12);
         Font courierNew = new Font("Courier New", Font.PLAIN, 12);
         Font msGothic = new Font("MS Gothic", Font.PLAIN, 12);
         BufferedImage bi = new BufferedImage(1,1,1);
         Graphics2D g2d = bi.createGraphics();
         FontMetrics cnMetrics = g2d.getFontMetrics(courierNew);
         FontMetrics diMetrics = g2d.getFontMetrics(dialogInput);
         FontMetrics mmMetrics = g2d.getFontMetrics(msMincho);
         FontMetrics mgMetrics = g2d.getFontMetrics(msGothic);
         // This tests to make sure we at least have applied
         //  "preferLocaleFonts for Japanese
         if (cnMetrics.charWidth('A') == diMetrics.charWidth('A')) {
              throw new RuntimeException
                    ("Courier New should not be used for DialogInput");
         }
         // This is supposed to make sure we are using MS Mincho instead
         //  of MS Gothic. However they are metrics identical so its
         // not definite proof.
         if (diMetrics.charWidth('A') != mmMetrics.charWidth('A')) {
              throw new RuntimeException
                  ("MS Mincho should be used for DialogInput");
         }
    }
}
 
Example 3
Source File: TestSGEuseAlternateFontforJALocales.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String args[]) throws Exception {
     System.out.println("Default Charset = "
         + Charset.defaultCharset().name());
     System.out.println("Locale = " + Locale.getDefault());
     String os = System.getProperty("os.name");
     String encoding = System.getProperty("file.encoding");
     /* Want to test the JA locale uses alternate font for DialogInput. */
     boolean jaTest = encoding.equalsIgnoreCase("windows-31j");
     if (!os.startsWith("Win") && jaTest) {
         System.out.println("Skipping Windows only test");
         return;
     }

     String className = "sun.java2d.SunGraphicsEnvironment";
     String methodName = "useAlternateFontforJALocales";
     Class sge = Class.forName(className);
     Method uafMethod = sge.getMethod(methodName, (Class[])null);
     Object ret = uafMethod.invoke(null);
     GraphicsEnvironment ge =
         GraphicsEnvironment.getLocalGraphicsEnvironment();
     ge.preferLocaleFonts();
     ge.preferProportionalFonts();
     if (jaTest) {
         Font msMincho = new Font("MS Mincho", Font.PLAIN, 12);
         if (!msMincho.getFamily(Locale.ENGLISH).equals("MS Mincho")) {
              System.out.println("MS Mincho not installed. Skipping test");
              return;
         }
         Font dialogInput = new Font("DialogInput", Font.PLAIN, 12);
         Font courierNew = new Font("Courier New", Font.PLAIN, 12);
         Font msGothic = new Font("MS Gothic", Font.PLAIN, 12);
         BufferedImage bi = new BufferedImage(1,1,1);
         Graphics2D g2d = bi.createGraphics();
         FontMetrics cnMetrics = g2d.getFontMetrics(courierNew);
         FontMetrics diMetrics = g2d.getFontMetrics(dialogInput);
         FontMetrics mmMetrics = g2d.getFontMetrics(msMincho);
         FontMetrics mgMetrics = g2d.getFontMetrics(msGothic);
         // This tests to make sure we at least have applied
         //  "preferLocaleFonts for Japanese
         if (cnMetrics.charWidth('A') == diMetrics.charWidth('A')) {
              throw new RuntimeException
                    ("Courier New should not be used for DialogInput");
         }
         // This is supposed to make sure we are using MS Mincho instead
         //  of MS Gothic. However they are metrics identical so its
         // not definite proof.
         if (diMetrics.charWidth('A') != mmMetrics.charWidth('A')) {
              throw new RuntimeException
                  ("MS Mincho should be used for DialogInput");
         }
    }
}
 
Example 4
Source File: TestSGEuseAlternateFontforJALocales.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String args[]) throws Exception {
     System.out.println("Default Charset = "
         + Charset.defaultCharset().name());
     System.out.println("Locale = " + Locale.getDefault());
     String os = System.getProperty("os.name");
     String encoding = System.getProperty("file.encoding");
     /* Want to test the JA locale uses alternate font for DialogInput. */
     boolean jaTest = encoding.equalsIgnoreCase("windows-31j");
     if (!os.startsWith("Win") && jaTest) {
         System.out.println("Skipping Windows only test");
         return;
     }

     String className = "sun.java2d.SunGraphicsEnvironment";
     String methodName = "useAlternateFontforJALocales";
     Class sge = Class.forName(className);
     Method uafMethod = sge.getMethod(methodName, (Class[])null);
     Object ret = uafMethod.invoke(null);
     GraphicsEnvironment ge =
         GraphicsEnvironment.getLocalGraphicsEnvironment();
     ge.preferLocaleFonts();
     ge.preferProportionalFonts();
     if (jaTest) {
         Font msMincho = new Font("MS Mincho", Font.PLAIN, 12);
         if (!msMincho.getFamily(Locale.ENGLISH).equals("MS Mincho")) {
              System.out.println("MS Mincho not installed. Skipping test");
              return;
         }
         Font dialogInput = new Font("DialogInput", Font.PLAIN, 12);
         Font courierNew = new Font("Courier New", Font.PLAIN, 12);
         Font msGothic = new Font("MS Gothic", Font.PLAIN, 12);
         BufferedImage bi = new BufferedImage(1,1,1);
         Graphics2D g2d = bi.createGraphics();
         FontMetrics cnMetrics = g2d.getFontMetrics(courierNew);
         FontMetrics diMetrics = g2d.getFontMetrics(dialogInput);
         FontMetrics mmMetrics = g2d.getFontMetrics(msMincho);
         FontMetrics mgMetrics = g2d.getFontMetrics(msGothic);
         // This tests to make sure we at least have applied
         //  "preferLocaleFonts for Japanese
         if (cnMetrics.charWidth('A') == diMetrics.charWidth('A')) {
              throw new RuntimeException
                    ("Courier New should not be used for DialogInput");
         }
         // This is supposed to make sure we are using MS Mincho instead
         //  of MS Gothic. However they are metrics identical so its
         // not definite proof.
         if (diMetrics.charWidth('A') != mmMetrics.charWidth('A')) {
              throw new RuntimeException
                  ("MS Mincho should be used for DialogInput");
         }
    }
}
 
Example 5
Source File: TestSGEuseAlternateFontforJALocales.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String args[]) throws Exception {
     System.out.println("Default Charset = "
         + Charset.defaultCharset().name());
     System.out.println("Locale = " + Locale.getDefault());
     String os = System.getProperty("os.name");
     String encoding = System.getProperty("file.encoding");
     /* Want to test the JA locale uses alternate font for DialogInput. */
     boolean jaTest = encoding.equalsIgnoreCase("windows-31j");
     if (!os.startsWith("Win") && jaTest) {
         System.out.println("Skipping Windows only test");
         return;
     }

     String className = "sun.java2d.SunGraphicsEnvironment";
     String methodName = "useAlternateFontforJALocales";
     Class sge = Class.forName(className);
     Method uafMethod = sge.getMethod(methodName, (Class[])null);
     Object ret = uafMethod.invoke(null);
     GraphicsEnvironment ge =
         GraphicsEnvironment.getLocalGraphicsEnvironment();
     ge.preferLocaleFonts();
     ge.preferProportionalFonts();
     if (jaTest) {
         Font msMincho = new Font("MS Mincho", Font.PLAIN, 12);
         if (!msMincho.getFamily(Locale.ENGLISH).equals("MS Mincho")) {
              System.out.println("MS Mincho not installed. Skipping test");
              return;
         }
         Font dialogInput = new Font("DialogInput", Font.PLAIN, 12);
         Font courierNew = new Font("Courier New", Font.PLAIN, 12);
         Font msGothic = new Font("MS Gothic", Font.PLAIN, 12);
         BufferedImage bi = new BufferedImage(1,1,1);
         Graphics2D g2d = bi.createGraphics();
         FontMetrics cnMetrics = g2d.getFontMetrics(courierNew);
         FontMetrics diMetrics = g2d.getFontMetrics(dialogInput);
         FontMetrics mmMetrics = g2d.getFontMetrics(msMincho);
         FontMetrics mgMetrics = g2d.getFontMetrics(msGothic);
         // This tests to make sure we at least have applied
         //  "preferLocaleFonts for Japanese
         if (cnMetrics.charWidth('A') == diMetrics.charWidth('A')) {
              throw new RuntimeException
                    ("Courier New should not be used for DialogInput");
         }
         // This is supposed to make sure we are using MS Mincho instead
         //  of MS Gothic. However they are metrics identical so its
         // not definite proof.
         if (diMetrics.charWidth('A') != mmMetrics.charWidth('A')) {
              throw new RuntimeException
                  ("MS Mincho should be used for DialogInput");
         }
    }
}
 
Example 6
Source File: TestSGEuseAlternateFontforJALocales.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String args[]) throws Exception {
     System.out.println("Default Charset = "
         + Charset.defaultCharset().name());
     System.out.println("Locale = " + Locale.getDefault());
     String os = System.getProperty("os.name");
     String encoding = System.getProperty("file.encoding");
     /* Want to test the JA locale uses alternate font for DialogInput. */
     boolean jaTest = encoding.equalsIgnoreCase("windows-31j");
     if (!os.startsWith("Win") && jaTest) {
         System.out.println("Skipping Windows only test");
         return;
     }

     String className = "sun.java2d.SunGraphicsEnvironment";
     String methodName = "useAlternateFontforJALocales";
     Class sge = Class.forName(className);
     Method uafMethod = sge.getMethod(methodName, (Class[])null);
     Object ret = uafMethod.invoke(null);
     GraphicsEnvironment ge =
         GraphicsEnvironment.getLocalGraphicsEnvironment();
     ge.preferLocaleFonts();
     ge.preferProportionalFonts();
     if (jaTest) {
         Font msMincho = new Font("MS Mincho", Font.PLAIN, 12);
         if (!msMincho.getFamily(Locale.ENGLISH).equals("MS Mincho")) {
              System.out.println("MS Mincho not installed. Skipping test");
              return;
         }
         Font dialogInput = new Font("DialogInput", Font.PLAIN, 12);
         Font courierNew = new Font("Courier New", Font.PLAIN, 12);
         Font msGothic = new Font("MS Gothic", Font.PLAIN, 12);
         BufferedImage bi = new BufferedImage(1,1,1);
         Graphics2D g2d = bi.createGraphics();
         FontMetrics cnMetrics = g2d.getFontMetrics(courierNew);
         FontMetrics diMetrics = g2d.getFontMetrics(dialogInput);
         FontMetrics mmMetrics = g2d.getFontMetrics(msMincho);
         FontMetrics mgMetrics = g2d.getFontMetrics(msGothic);
         // This tests to make sure we at least have applied
         //  "preferLocaleFonts for Japanese
         if (cnMetrics.charWidth('A') == diMetrics.charWidth('A')) {
              throw new RuntimeException
                    ("Courier New should not be used for DialogInput");
         }
         // This is supposed to make sure we are using MS Mincho instead
         //  of MS Gothic. However they are metrics identical so its
         // not definite proof.
         if (diMetrics.charWidth('A') != mmMetrics.charWidth('A')) {
              throw new RuntimeException
                  ("MS Mincho should be used for DialogInput");
         }
    }
}
 
Example 7
Source File: TestSGEuseAlternateFontforJALocales.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String args[]) throws Exception {
     System.out.println("Default Charset = "
         + Charset.defaultCharset().name());
     System.out.println("Locale = " + Locale.getDefault());
     String os = System.getProperty("os.name");
     String encoding = System.getProperty("file.encoding");
     /* Want to test the JA locale uses alternate font for DialogInput. */
     boolean jaTest = encoding.equalsIgnoreCase("windows-31j");
     if (!os.startsWith("Win") && jaTest) {
         System.out.println("Skipping Windows only test");
         return;
     }

     String className = "sun.java2d.SunGraphicsEnvironment";
     String methodName = "useAlternateFontforJALocales";
     Class sge = Class.forName(className);
     Method uafMethod = sge.getMethod(methodName, (Class[])null);
     Object ret = uafMethod.invoke(null);
     GraphicsEnvironment ge =
         GraphicsEnvironment.getLocalGraphicsEnvironment();
     ge.preferLocaleFonts();
     ge.preferProportionalFonts();
     if (jaTest) {
         Font msMincho = new Font("MS Mincho", Font.PLAIN, 12);
         if (!msMincho.getFamily(Locale.ENGLISH).equals("MS Mincho")) {
              System.out.println("MS Mincho not installed. Skipping test");
              return;
         }
         Font dialogInput = new Font("DialogInput", Font.PLAIN, 12);
         Font courierNew = new Font("Courier New", Font.PLAIN, 12);
         Font msGothic = new Font("MS Gothic", Font.PLAIN, 12);
         BufferedImage bi = new BufferedImage(1,1,1);
         Graphics2D g2d = bi.createGraphics();
         FontMetrics cnMetrics = g2d.getFontMetrics(courierNew);
         FontMetrics diMetrics = g2d.getFontMetrics(dialogInput);
         FontMetrics mmMetrics = g2d.getFontMetrics(msMincho);
         FontMetrics mgMetrics = g2d.getFontMetrics(msGothic);
         // This tests to make sure we at least have applied
         //  "preferLocaleFonts for Japanese
         if (cnMetrics.charWidth('A') == diMetrics.charWidth('A')) {
              throw new RuntimeException
                    ("Courier New should not be used for DialogInput");
         }
         // This is supposed to make sure we are using MS Mincho instead
         //  of MS Gothic. However they are metrics identical so its
         // not definite proof.
         if (diMetrics.charWidth('A') != mmMetrics.charWidth('A')) {
              throw new RuntimeException
                  ("MS Mincho should be used for DialogInput");
         }
    }
}
 
Example 8
Source File: TestSGEuseAlternateFontforJALocales.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String args[]) throws Exception {
     System.out.println("Default Charset = "
         + Charset.defaultCharset().name());
     System.out.println("Locale = " + Locale.getDefault());
     String os = System.getProperty("os.name");
     String encoding = System.getProperty("file.encoding");
     /* Want to test the JA locale uses alternate font for DialogInput. */
     boolean jaTest = encoding.equalsIgnoreCase("windows-31j");
     if (!os.startsWith("Win") && jaTest) {
         System.out.println("Skipping Windows only test");
         return;
     }

     String className = "sun.java2d.SunGraphicsEnvironment";
     String methodName = "useAlternateFontforJALocales";
     Class sge = Class.forName(className);
     Method uafMethod = sge.getMethod(methodName, (Class[])null);
     Object ret = uafMethod.invoke(null);
     GraphicsEnvironment ge =
         GraphicsEnvironment.getLocalGraphicsEnvironment();
     ge.preferLocaleFonts();
     ge.preferProportionalFonts();
     if (jaTest) {
         Font msMincho = new Font("MS Mincho", Font.PLAIN, 12);
         if (!msMincho.getFamily(Locale.ENGLISH).equals("MS Mincho")) {
              System.out.println("MS Mincho not installed. Skipping test");
              return;
         }
         Font dialogInput = new Font("DialogInput", Font.PLAIN, 12);
         Font courierNew = new Font("Courier New", Font.PLAIN, 12);
         Font msGothic = new Font("MS Gothic", Font.PLAIN, 12);
         BufferedImage bi = new BufferedImage(1,1,1);
         Graphics2D g2d = bi.createGraphics();
         FontMetrics cnMetrics = g2d.getFontMetrics(courierNew);
         FontMetrics diMetrics = g2d.getFontMetrics(dialogInput);
         FontMetrics mmMetrics = g2d.getFontMetrics(msMincho);
         FontMetrics mgMetrics = g2d.getFontMetrics(msGothic);
         // This tests to make sure we at least have applied
         //  "preferLocaleFonts for Japanese
         if (cnMetrics.charWidth('A') == diMetrics.charWidth('A')) {
              throw new RuntimeException
                    ("Courier New should not be used for DialogInput");
         }
         // This is supposed to make sure we are using MS Mincho instead
         //  of MS Gothic. However they are metrics identical so its
         // not definite proof.
         if (diMetrics.charWidth('A') != mmMetrics.charWidth('A')) {
              throw new RuntimeException
                  ("MS Mincho should be used for DialogInput");
         }
    }
}
 
Example 9
Source File: TestSGEuseAlternateFontforJALocales.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String args[]) throws Exception {
     System.out.println("Default Charset = "
         + Charset.defaultCharset().name());
     System.out.println("Locale = " + Locale.getDefault());
     String os = System.getProperty("os.name");
     String encoding = System.getProperty("file.encoding");
     /* Want to test the JA locale uses alternate font for DialogInput. */
     boolean jaTest = encoding.equalsIgnoreCase("windows-31j");
     if (!os.startsWith("Win") && jaTest) {
         System.out.println("Skipping Windows only test");
         return;
     }

     String className = "sun.java2d.SunGraphicsEnvironment";
     String methodName = "useAlternateFontforJALocales";
     Class sge = Class.forName(className);
     Method uafMethod = sge.getMethod(methodName, (Class[])null);
     Object ret = uafMethod.invoke(null);
     GraphicsEnvironment ge =
         GraphicsEnvironment.getLocalGraphicsEnvironment();
     ge.preferLocaleFonts();
     ge.preferProportionalFonts();
     if (jaTest) {
         Font msMincho = new Font("MS Mincho", Font.PLAIN, 12);
         if (!msMincho.getFamily(Locale.ENGLISH).equals("MS Mincho")) {
              System.out.println("MS Mincho not installed. Skipping test");
              return;
         }
         Font dialogInput = new Font("DialogInput", Font.PLAIN, 12);
         Font courierNew = new Font("Courier New", Font.PLAIN, 12);
         Font msGothic = new Font("MS Gothic", Font.PLAIN, 12);
         BufferedImage bi = new BufferedImage(1,1,1);
         Graphics2D g2d = bi.createGraphics();
         FontMetrics cnMetrics = g2d.getFontMetrics(courierNew);
         FontMetrics diMetrics = g2d.getFontMetrics(dialogInput);
         FontMetrics mmMetrics = g2d.getFontMetrics(msMincho);
         FontMetrics mgMetrics = g2d.getFontMetrics(msGothic);
         // This tests to make sure we at least have applied
         //  "preferLocaleFonts for Japanese
         if (cnMetrics.charWidth('A') == diMetrics.charWidth('A')) {
              throw new RuntimeException
                    ("Courier New should not be used for DialogInput");
         }
         // This is supposed to make sure we are using MS Mincho instead
         //  of MS Gothic. However they are metrics identical so its
         // not definite proof.
         if (diMetrics.charWidth('A') != mmMetrics.charWidth('A')) {
              throw new RuntimeException
                  ("MS Mincho should be used for DialogInput");
         }
    }
}
 
Example 10
Source File: TestSGEuseAlternateFontforJALocales.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String args[]) throws Exception {
     System.out.println("Default Charset = "
         + Charset.defaultCharset().name());
     System.out.println("Locale = " + Locale.getDefault());
     String os = System.getProperty("os.name");
     String encoding = System.getProperty("file.encoding");
     /* Want to test the JA locale uses alternate font for DialogInput. */
     boolean jaTest = encoding.equalsIgnoreCase("windows-31j");
     if (!os.startsWith("Win") && jaTest) {
         System.out.println("Skipping Windows only test");
         return;
     }

     String className = "sun.java2d.SunGraphicsEnvironment";
     String methodName = "useAlternateFontforJALocales";
     Class sge = Class.forName(className);
     Method uafMethod = sge.getMethod(methodName, (Class[])null);
     Object ret = uafMethod.invoke(null);
     GraphicsEnvironment ge =
         GraphicsEnvironment.getLocalGraphicsEnvironment();
     ge.preferLocaleFonts();
     ge.preferProportionalFonts();
     if (jaTest) {
         Font msMincho = new Font("MS Mincho", Font.PLAIN, 12);
         if (!msMincho.getFamily(Locale.ENGLISH).equals("MS Mincho")) {
              System.out.println("MS Mincho not installed. Skipping test");
              return;
         }
         Font dialogInput = new Font("DialogInput", Font.PLAIN, 12);
         Font courierNew = new Font("Courier New", Font.PLAIN, 12);
         Font msGothic = new Font("MS Gothic", Font.PLAIN, 12);
         BufferedImage bi = new BufferedImage(1,1,1);
         Graphics2D g2d = bi.createGraphics();
         FontMetrics cnMetrics = g2d.getFontMetrics(courierNew);
         FontMetrics diMetrics = g2d.getFontMetrics(dialogInput);
         FontMetrics mmMetrics = g2d.getFontMetrics(msMincho);
         FontMetrics mgMetrics = g2d.getFontMetrics(msGothic);
         // This tests to make sure we at least have applied
         //  "preferLocaleFonts for Japanese
         if (cnMetrics.charWidth('A') == diMetrics.charWidth('A')) {
              throw new RuntimeException
                    ("Courier New should not be used for DialogInput");
         }
         // This is supposed to make sure we are using MS Mincho instead
         //  of MS Gothic. However they are metrics identical so its
         // not definite proof.
         if (diMetrics.charWidth('A') != mmMetrics.charWidth('A')) {
              throw new RuntimeException
                  ("MS Mincho should be used for DialogInput");
         }
    }
}
 
Example 11
Source File: TestSGEuseAlternateFontforJALocales.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String args[]) throws Exception {
     System.out.println("Default Charset = "
         + Charset.defaultCharset().name());
     System.out.println("Locale = " + Locale.getDefault());
     String os = System.getProperty("os.name");
     String encoding = System.getProperty("file.encoding");
     /* Want to test the JA locale uses alternate font for DialogInput. */
     boolean jaTest = encoding.equalsIgnoreCase("windows-31j");
     if (!os.startsWith("Win") && jaTest) {
         System.out.println("Skipping Windows only test");
         return;
     }

     String className = "sun.java2d.SunGraphicsEnvironment";
     String methodName = "useAlternateFontforJALocales";
     Class sge = Class.forName(className);
     Method uafMethod = sge.getMethod(methodName, (Class[])null);
     Object ret = uafMethod.invoke(null);
     GraphicsEnvironment ge =
         GraphicsEnvironment.getLocalGraphicsEnvironment();
     ge.preferLocaleFonts();
     ge.preferProportionalFonts();
     if (jaTest) {
         Font msMincho = new Font("MS Mincho", Font.PLAIN, 12);
         if (!msMincho.getFamily(Locale.ENGLISH).equals("MS Mincho")) {
              System.out.println("MS Mincho not installed. Skipping test");
              return;
         }
         Font dialogInput = new Font("DialogInput", Font.PLAIN, 12);
         Font courierNew = new Font("Courier New", Font.PLAIN, 12);
         Font msGothic = new Font("MS Gothic", Font.PLAIN, 12);
         BufferedImage bi = new BufferedImage(1,1,1);
         Graphics2D g2d = bi.createGraphics();
         FontMetrics cnMetrics = g2d.getFontMetrics(courierNew);
         FontMetrics diMetrics = g2d.getFontMetrics(dialogInput);
         FontMetrics mmMetrics = g2d.getFontMetrics(msMincho);
         FontMetrics mgMetrics = g2d.getFontMetrics(msGothic);
         // This tests to make sure we at least have applied
         //  "preferLocaleFonts for Japanese
         if (cnMetrics.charWidth('A') == diMetrics.charWidth('A')) {
              throw new RuntimeException
                    ("Courier New should not be used for DialogInput");
         }
         // This is supposed to make sure we are using MS Mincho instead
         //  of MS Gothic. However they are metrics identical so its
         // not definite proof.
         if (diMetrics.charWidth('A') != mmMetrics.charWidth('A')) {
              throw new RuntimeException
                  ("MS Mincho should be used for DialogInput");
         }
    }
}
 
Example 12
Source File: TestSGEuseAlternateFontforJALocales.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String args[]) throws Exception {
     System.out.println("Default Charset = "
         + Charset.defaultCharset().name());
     System.out.println("Locale = " + Locale.getDefault());
     String os = System.getProperty("os.name");
     String encoding = System.getProperty("file.encoding");
     /* Want to test the JA locale uses alternate font for DialogInput. */
     boolean jaTest = encoding.equalsIgnoreCase("windows-31j");
     if (!os.startsWith("Win") && jaTest) {
         System.out.println("Skipping Windows only test");
         return;
     }

     String className = "sun.java2d.SunGraphicsEnvironment";
     String methodName = "useAlternateFontforJALocales";
     Class sge = Class.forName(className);
     Method uafMethod = sge.getMethod(methodName, (Class[])null);
     Object ret = uafMethod.invoke(null);
     GraphicsEnvironment ge =
         GraphicsEnvironment.getLocalGraphicsEnvironment();
     ge.preferLocaleFonts();
     ge.preferProportionalFonts();
     if (jaTest) {
         Font msMincho = new Font("MS Mincho", Font.PLAIN, 12);
         if (!msMincho.getFamily(Locale.ENGLISH).equals("MS Mincho")) {
              System.out.println("MS Mincho not installed. Skipping test");
              return;
         }
         Font dialogInput = new Font("DialogInput", Font.PLAIN, 12);
         Font courierNew = new Font("Courier New", Font.PLAIN, 12);
         Font msGothic = new Font("MS Gothic", Font.PLAIN, 12);
         BufferedImage bi = new BufferedImage(1,1,1);
         Graphics2D g2d = bi.createGraphics();
         FontMetrics cnMetrics = g2d.getFontMetrics(courierNew);
         FontMetrics diMetrics = g2d.getFontMetrics(dialogInput);
         FontMetrics mmMetrics = g2d.getFontMetrics(msMincho);
         FontMetrics mgMetrics = g2d.getFontMetrics(msGothic);
         // This tests to make sure we at least have applied
         //  "preferLocaleFonts for Japanese
         if (cnMetrics.charWidth('A') == diMetrics.charWidth('A')) {
              throw new RuntimeException
                    ("Courier New should not be used for DialogInput");
         }
         // This is supposed to make sure we are using MS Mincho instead
         //  of MS Gothic. However they are metrics identical so its
         // not definite proof.
         if (diMetrics.charWidth('A') != mmMetrics.charWidth('A')) {
              throw new RuntimeException
                  ("MS Mincho should be used for DialogInput");
         }
    }
}
 
Example 13
Source File: TestSGEuseAlternateFontforJALocales.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String args[]) throws Exception {
     System.out.println("Default Charset = "
         + Charset.defaultCharset().name());
     System.out.println("Locale = " + Locale.getDefault());
     String os = System.getProperty("os.name");
     String encoding = System.getProperty("file.encoding");
     /* Want to test the JA locale uses alternate font for DialogInput. */
     boolean jaTest = encoding.equalsIgnoreCase("windows-31j");
     if (!os.startsWith("Win") && jaTest) {
         System.out.println("Skipping Windows only test");
         return;
     }

     String className = "sun.java2d.SunGraphicsEnvironment";
     String methodName = "useAlternateFontforJALocales";
     Class sge = Class.forName(className);
     Method uafMethod = sge.getMethod(methodName, (Class[])null);
     Object ret = uafMethod.invoke(null);
     GraphicsEnvironment ge =
         GraphicsEnvironment.getLocalGraphicsEnvironment();
     ge.preferLocaleFonts();
     ge.preferProportionalFonts();
     if (jaTest) {
         Font msMincho = new Font("MS Mincho", Font.PLAIN, 12);
         if (!msMincho.getFamily(Locale.ENGLISH).equals("MS Mincho")) {
              System.out.println("MS Mincho not installed. Skipping test");
              return;
         }
         Font dialogInput = new Font("DialogInput", Font.PLAIN, 12);
         Font courierNew = new Font("Courier New", Font.PLAIN, 12);
         Font msGothic = new Font("MS Gothic", Font.PLAIN, 12);
         BufferedImage bi = new BufferedImage(1,1,1);
         Graphics2D g2d = bi.createGraphics();
         FontMetrics cnMetrics = g2d.getFontMetrics(courierNew);
         FontMetrics diMetrics = g2d.getFontMetrics(dialogInput);
         FontMetrics mmMetrics = g2d.getFontMetrics(msMincho);
         FontMetrics mgMetrics = g2d.getFontMetrics(msGothic);
         // This tests to make sure we at least have applied
         //  "preferLocaleFonts for Japanese
         if (cnMetrics.charWidth('A') == diMetrics.charWidth('A')) {
              throw new RuntimeException
                    ("Courier New should not be used for DialogInput");
         }
         // This is supposed to make sure we are using MS Mincho instead
         //  of MS Gothic. However they are metrics identical so its
         // not definite proof.
         if (diMetrics.charWidth('A') != mmMetrics.charWidth('A')) {
              throw new RuntimeException
                  ("MS Mincho should be used for DialogInput");
         }
    }
}