changeset 7139:05367a06c685

RT-36639: [RTL] PasswordField rendering issue when it's highlighted. - MAC
author Felipe Heidrich <felipe.heidrich@oracle.com>
date Tue, 27 May 2014 08:46:45 -0700
parents 83e8b46ae2bf
children 3a38a1ed0e23
files modules/graphics/src/main/java/com/sun/javafx/font/coretext/CTGlyphLayout.java modules/graphics/src/main/java/com/sun/javafx/font/coretext/OS.java modules/graphics/src/main/native-font/coretext.c
diffstat 3 files changed, 29 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/modules/graphics/src/main/java/com/sun/javafx/font/coretext/CTGlyphLayout.java	Tue May 27 11:43:16 2014 -0400
+++ b/modules/graphics/src/main/java/com/sun/javafx/font/coretext/CTGlyphLayout.java	Tue May 27 08:46:45 2014 -0700
@@ -35,7 +35,7 @@
 
 class CTGlyphLayout extends GlyphLayout {
 
-    private long createCTLine(long fontRef, char[] chars,
+    private long createCTLine(long fontRef, char[] chars, boolean rtl,
                               int start, int length) {
         /* Use CoreText to analize the run */
         long alloc = OS.kCFAllocatorDefault();
@@ -47,6 +47,13 @@
                                   OS.kCFTypeDictionaryValueCallBacks());
             if (attributes != 0) {
                 OS.CFDictionaryAddValue(attributes, OS.kCTFontAttributeName(), fontRef);
+                if (rtl) {
+                    long paragraphStyleRef = OS.CTParagraphStyleCreate(OS.kCTWritingDirectionRightToLeft);
+                    if (paragraphStyleRef != 0) {
+                        OS.CFDictionaryAddValue(attributes, OS.kCTParagraphStyleAttributeName(), paragraphStyleRef);
+                        OS.CFRelease(paragraphStyleRef);
+                    }
+                }
                 /* Note that by default CoreText will apply kerning depending on the font*/
                 long attString = OS.CFAttributedStringCreate(alloc, textRef, attributes);
                 if (attString != 0) {
@@ -93,7 +100,8 @@
         String fontName = strike.getFontResource().getFullName();
         long fontRef = ((CTFontStrike)strike).getFontRef();
         if (fontRef == 0) return;
-        long lineRef = createCTLine(fontRef, text, run.getStart(), run.getLength());
+        boolean rtl = (run.getLevel() & 1) != 0;
+        long lineRef = createCTLine(fontRef, text, rtl, run.getStart(), run.getLength());
         if (lineRef == 0) return;
         long runs = OS.CTLineGetGlyphRuns(lineRef);
         if (runs != 0) {
--- a/modules/graphics/src/main/java/com/sun/javafx/font/coretext/OS.java	Tue May 27 11:43:16 2014 -0400
+++ b/modules/graphics/src/main/java/com/sun/javafx/font/coretext/OS.java	Tue May 27 08:46:45 2014 -0700
@@ -48,6 +48,7 @@
     static final int kCGBitmapByteOrder32Host = ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN ? kCGBitmapByteOrder32Little : kCGBitmapByteOrder32Big;
     static final int kCGImageAlphaPremultipliedFirst = 2;
     static final int kCGImageAlphaNone = 0;
+    static final int kCTWritingDirectionRightToLeft = 1;
 
     static final long CFStringCreate(String string) {
         char[] buffer = string.toCharArray();
@@ -74,6 +75,7 @@
     static final native long kCFTypeDictionaryKeyCallBacks();
     static final native long kCFTypeDictionaryValueCallBacks();
     static final native long kCTFontAttributeName();
+    static final native long kCTParagraphStyleAttributeName();
     static final native long CFArrayGetCount(long theArray);
     static final native long CFArrayGetValueAtIndex(long theArray, long idx);
     static final native long CFAttributedStringCreate(long alloc, long str, long attributes);
@@ -105,5 +107,6 @@
     static final native double CTLineGetTypographicBounds(long line);
     static final native long CTRunGetGlyphCount(long run);
     static final native long CTRunGetAttributes(long run);
+    static final native long CTParagraphStyleCreate(int dir);
 
 }
--- a/modules/graphics/src/main/native-font/coretext.c	Tue May 27 11:43:16 2014 -0400
+++ b/modules/graphics/src/main/native-font/coretext.c	Tue May 27 08:46:45 2014 -0700
@@ -525,6 +525,12 @@
     return (jlong)kCTFontAttributeName;
 }
 
+JNIEXPORT jlong JNICALL OS_NATIVE(kCTParagraphStyleAttributeName)
+    (JNIEnv *env, jclass that)
+{
+    return (jlong)kCTParagraphStyleAttributeName;
+}
+
 JNIEXPORT jlong JNICALL OS_NATIVE(CFAttributedStringCreate)
     (JNIEnv *env, jclass that, jlong arg0, jlong arg1, jlong arg2)
 {
@@ -827,6 +833,16 @@
     return newCGRect(env, &result);
 }
 
+JNIEXPORT jlong JNICALL OS_NATIVE(CTParagraphStyleCreate)
+    (JNIEnv *env, jclass that, jint arg0)
+{
+    CTWritingDirection dir = (CTWritingDirection)arg0;
+    CTParagraphStyleSetting settings[] = {
+        {kCTParagraphStyleSpecifierBaseWritingDirection, sizeof(dir), &dir}
+    };
+    return (jlong)CTParagraphStyleCreate(settings, sizeof(settings) / sizeof(settings[0]));
+}
+
 /***********************************************/
 /*                Glyph Outline                */
 /***********************************************/