OSDN Git Service

メニューで使っている文字を表示できないフォントを除外する処理で、文字コードの判定にコードポイントを使うように修正。(surrogate文字でも使えるようらするため)
authorseraphy <seraphy@users.osdn.me>
Sat, 10 Nov 2018 12:32:58 +0000 (21:32 +0900)
committerseraphy <seraphy@users.osdn.me>
Sat, 10 Nov 2018 12:33:07 +0000 (21:33 +0900)
https://osdn.net/projects/charactermanaj/ticket/35347

src/main/java/charactermanaj/Main.java

index 44125ef..bcff24e 100644 (file)
@@ -155,13 +155,16 @@ public final class Main implements Runnable {
                // 少なくともメニューが表示できるようなフォントを選択する
                Properties strings = LocalizedResourcePropertyLoader.getCachedInstance()
                                .getLocalizedProperties("menu/menu");
-               HashSet<Character> useChars = new HashSet<Character>();
+               HashSet<Integer> useCodePoints = new HashSet<Integer>();
                Enumeration<?> enmStrings = strings.propertyNames();
                while (enmStrings.hasMoreElements()) {
                        String propertyName = (String) enmStrings.nextElement();
                        String propertyValue = strings.getProperty(propertyName);
-                       for (char ch : propertyValue.toCharArray()) {
-                               useChars.add(ch);
+                       int len = propertyValue.length();
+                       for (int idx = 0; idx < len;) {
+                               int codepoint = propertyValue.codePointAt(idx);
+                               useCodePoints.add(codepoint);
+                               idx += Character.charCount(codepoint);
                        }
                }
 
@@ -180,12 +183,11 @@ public final class Main implements Runnable {
                                                        Font font = Font.decode(availableFontFamily);
                                                        logger.log(Level.INFO, "実在するフォントの確認:" + availableFontFamily);
                                                        boolean canDisplay = false;
-                                                       for (char ch : useChars) {
-                                                               canDisplay = font.canDisplay(ch);
+                                                       for (Integer codepoint : useCodePoints) {
+                                                               canDisplay = font.canDisplay(codepoint);
                                                                if (!canDisplay) {
-                                                                       logger.log(Level.INFO,
-                                                                                       "このフォントはメニュー表示に使用できません: "
-                                                                                                       + selectedFontFamily + "/ch=" + ch);
+                                                                       logger.log(Level.INFO, "このフォントはメニュー表示に使用できません: "
+                                                                                       + selectedFontFamily + "/codepoint=0x" + Integer.toHexString(codepoint));
                                                                        break;
                                                                }
                                                        }