changeset 9045:7caa9eb87326 9-b65

RT-40473: isIdeographic missing on Android < api level 19 Reviewed-by: kcr
author jvos
date Fri, 15 May 2015 08:04:22 -0700
parents 138cf9ef8025
children 4be76fe05bf9 26dfe2d8e46b
files modules/graphics/src/main/java/com/sun/javafx/text/GlyphLayout.java
diffstat 1 files changed, 32 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/modules/graphics/src/main/java/com/sun/javafx/text/GlyphLayout.java	Thu May 14 16:28:49 2015 -0700
+++ b/modules/graphics/src/main/java/com/sun/javafx/text/GlyphLayout.java	Fri May 15 08:04:22 2015 -0700
@@ -71,6 +71,8 @@
 import com.sun.javafx.font.PGFont;
 import com.sun.javafx.font.PrismFontFactory;
 import com.sun.javafx.scene.text.TextSpan;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
 
 public abstract class GlyphLayout {
 
@@ -96,6 +98,23 @@
 
     public static final int HINTING = 1 << 4;
 
+    /**
+     * Android versions that still run a dalvik based on JDK 6 (API level 18 and
+     * before) don't have the method Character.isIdeographic.
+     * On devices with a JVM that does not have Character.isIdeographic, there will
+     * be non-optimal line breaking for CJKV.
+     * The reflection-based approach should be removed in a later version,
+     * when the Android base version moves to API level 19.
+     */
+    private static Method isIdeographicMethod = null;
+    static {
+        try {
+            isIdeographicMethod = Character.class.getMethod("isIdeographic", int.class);
+        } catch (NoSuchMethodException | SecurityException e) {
+            isIdeographicMethod = null;
+        }
+    }
+
     protected TextRun addTextRun(PrismTextLayout layout, char[] chars,
                                  int start, int length,
                                  PGFont font, TextSpan span, byte level) {
@@ -210,7 +229,7 @@
                         }
                     }
 
-                    if (Character.isIdeographic(codePoint)) {
+                    if (isIdeographic(codePoint)) {
                         flags |= FLAGS_HAS_CJK;
                     }
 
@@ -385,4 +404,16 @@
             inUse = false;
         }
     }
+
+    private static boolean isIdeographic(int codePoint) {
+        if (isIdeographicMethod != null) {
+            try {
+                return (boolean) isIdeographicMethod.invoke(null, codePoint);
+            } catch (IllegalAccessException | InvocationTargetException ex) {
+                return false;
+            }
+        }
+        return false;
+    }
+
 }