當前位置: 首頁>>代碼示例>>Java>>正文


Java GraphicsEnvironment.preferLocaleFonts方法代碼示例

本文整理匯總了Java中java.awt.GraphicsEnvironment.preferLocaleFonts方法的典型用法代碼示例。如果您正苦於以下問題:Java GraphicsEnvironment.preferLocaleFonts方法的具體用法?Java GraphicsEnvironment.preferLocaleFonts怎麽用?Java GraphicsEnvironment.preferLocaleFonts使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.awt.GraphicsEnvironment的用法示例。


在下文中一共展示了GraphicsEnvironment.preferLocaleFonts方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: main

import java.awt.GraphicsEnvironment; //導入方法依賴的package包/類
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");
         }
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:53,代碼來源:TestSGEuseAlternateFontforJALocales.java


注:本文中的java.awt.GraphicsEnvironment.preferLocaleFonts方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。