diff org.eclipse.swt.gtk.linux.x86/src/org/eclipse/swt/graphics/TextLayout.d @ 120:536e43f63c81

Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661 ===D2=== * added [Try]Immutable/Const/Shared templates to work with differenses in D1/D2 instead of version statements used these templates to work with strict type storage rules of dmd-2.053 * com.ibm.icu now also compilable with D2, but not tested yet * small fixes Snippet288 - shared data is in TLS ===Phobos=== * fixed critical bugs in Phobos implemention completely incorrect segfault prone fromStringz (Linux's port ruthless killer) terrible, incorrect StringBuffer realization (StyledText killer) * fixed small bugs as well Snippet72 - misprint in the snippet * implemented missed functionality for Phobos ByteArrayOutputStream implemented (image loading available) formatting correctly works for all DWT's cases As a result, folowing snippets now works with Phobos (Snippet### - what is fixed): Snippet24, 42, 111, 115, 130, 235, 276 - bad string formatting Snippet48, 282 - crash on image loading Snippet163, 189, 211, 213, 217, 218, 222 - crash on copy/cut in StyledText Snippet244 - hang-up ===Tango=== * few changes for the latest Tango trunc-r5661 * few small performance improvments ===General=== * implMissing-s for only one version changed to implMissingInTango/InPhobos * incorrect calls to Format in toString-s fixed * fixed loading \uXXXX characters in ResourceBundle * added good UTF-8 support for StyledText, TextLayout (Win32) and friends UTF functions revised and tested. It is now in java.nonstandard.*Utf modules StyledText and TextLayout (Win32) modules revised for UTF-8 support * removed small diferences in most identical files in *.swt.* folders *.swt.internal.image, *.swt.events and *.swt.custom are identical in Win32/Linux32 now 179 of 576 (~31%) files in *.swt.* folders are fully identical * Win32: snippets now have right subsystem, pretty icons and native system style controls * small fixes in snippets Snippet44 - it's not Snippet44 Snippet212 - functions work with different images and offsets arrays Win32: Snippet282 - crash on close if the button has an image Snippet293 - setGrayed is commented and others Win32: As a result, folowing snippets now works Snippet68 - color doesn't change Snippet163, 189, 211, 213, 217, 218, 222 - UTF-8 issues (see above) Snippet193 - no tabel headers
author Denis Shelomovskij <verylonglogin.reg@gmail.com>
date Sat, 09 Jul 2011 15:50:20 +0300
parents 70388b0e6dad
children
line wrap: on
line diff
--- a/org.eclipse.swt.gtk.linux.x86/src/org/eclipse/swt/graphics/TextLayout.d	Sun Apr 17 17:58:36 2011 +0200
+++ b/org.eclipse.swt.gtk.linux.x86/src/org/eclipse/swt/graphics/TextLayout.d	Sat Jul 09 15:50:20 2011 +0300
@@ -12,8 +12,6 @@
  *******************************************************************************/
 module org.eclipse.swt.graphics.TextLayout;
 
-import java.lang.all;
-
 import org.eclipse.swt.internal.Compatibility;
 import org.eclipse.swt.internal.cairo.Cairo : Cairo;
 import org.eclipse.swt.internal.gtk.OS;
@@ -32,6 +30,7 @@
 import org.eclipse.swt.graphics.Resource;
 import org.eclipse.swt.graphics.TextStyle;
 import java.lang.all;
+import java.nonstandard.UnsafeUtf;
 
 version(Tango){
     import tango.stdc.string : memmove;
@@ -188,7 +187,7 @@
         int i = 0;
         while( i < chars.length ){
             int incr;
-            dchar c = firstCodePoint( chars[ i .. $ ], incr );
+            dchar c = chars.dcharAt(i, incr);
             if (c is LTR_MARK || c is RTL_MARK || c is ZWNBS || c is ZWS) {
                 offsetCount+=3;
             }
@@ -201,7 +200,7 @@
         int i = 0;
         while( i < chars.length ){
             int incr;
-            dchar c = firstCodePoint( chars[ i .. $ ], incr );
+            dchar c = chars.dcharAt(i, incr);
             if (c is LTR_MARK || c is RTL_MARK || c is ZWNBS || c is ZWS) {
                 invalidOffsets[offsetCount++] = i;
                 invalidOffsets[offsetCount++] = i+1;
@@ -617,7 +616,7 @@
                 if (color is null && style.foreground !is null) color = style.foreground.handle;
                 if (color is null) color = data.foreground;
                 int width = 1;
-                float[] dashes = null;
+                TryConst!(float)[] dashes = null;
                 switch (style.borderStyle) {
                     case SWT.BORDER_SOLID: break;
                     case SWT.BORDER_DASH: dashes = width !is 0 ? GC.LINE_DASH : GC.LINE_DASH_ZERO; break;
@@ -949,11 +948,11 @@
     end = translateOffset(end);
     auto ptr = OS.pango_layout_get_text(layout);
     auto cont = fromStringz(ptr);
-    start = cont.utf8AdjustOffset( start );
-    end = cont.utf8AdjustOffset( end );
+    cont.adjustUTF8index( start );
+    cont.adjustUTF8index( end );
     int incr = 1;
     if( end < cont.length ){
-        incr = cont.getRelativeCodePointOffset( end, 1 );
+        incr = cont.UTF8strideAt(end);
     }
     int byteStart = start;//(OS.g_utf8_offset_to_pointer (ptr, start) - ptr);
     int byteEnd = end + incr;//(OS.g_utf8_offset_to_pointer (ptr, end + 1) - ptr);
@@ -1289,7 +1288,7 @@
     offset = translateOffset(offset);
     auto ptr = OS.pango_layout_get_text(layout);
     auto cont = fromStringz(ptr);
-    offset = cont.utf8AdjustOffset(offset);
+    cont.adjustUTF8index(offset);
     // leading ZWS+ZWNBS are 2 codepoints in 6 bytes, so we miss 4 bytes here
     int byteOffset = offset;//(OS.g_utf8_offset_to_pointer(ptr, offset) - ptr);
     int slen = cont.length;
@@ -1345,8 +1344,8 @@
     if ((movement & SWT.MOVEMENT_CHAR) !is 0){
         //PORTING take care of utf8
         int toffset = translateOffset(offset);
-        toffset = dcont.utf8AdjustOffset( toffset );
-        int incr = dcont.getRelativeCodePointOffset( toffset, step );
+        dcont.adjustUTF8index( toffset );
+        int incr = dcont.toUTF8shift(toffset, step);
         return offset + incr;
     }
     PangoLogAttr* attrs;
@@ -1356,7 +1355,7 @@
     if (attrs is null) return offset + step;
     length_ = dcont.length;//OS.g_utf8_strlen(cont, -1);
     offset = translateOffset(offset);
-    offset = dcont.utf8AdjustOffset( offset );
+    dcont.adjustUTF8index( offset );
 
     PangoLogAttr* logAttr;
     offset = validateOffset( dcont, offset, step);
@@ -1971,8 +1970,8 @@
     if (start > end) return;
     start = Math.min(Math.max(0, start), length_ - 1);
     end = Math.min(Math.max(0, end), length_ - 1);
-    start = text.utf8AdjustOffset( start );
-    end = text.utf8AdjustOffset( end );
+    text.adjustUTF8index( start );
+    text.adjustUTF8index( end );
 
 
     /*
@@ -1982,12 +1981,11 @@
     *
     * NOTE that fix only LamAlef ligatures.
     */
-    int relIndex;
-    if ((start > 0 ) && isAlef(text[ start .. $ ].firstCodePoint()) && isLam(text.getRelativeCodePoint( start, -1, relIndex ))) {
-        start += relIndex;
+    if ((start > 0 ) && isAlef(text.dcharAt(start)) && isLam(text.dcharBefore(start))) {
+        start += text.offsetBefore(start);
     }
-    if ((end < length_ - 1) && isLam(text[ end .. $ ].firstCodePoint()) && isAlef(text.getRelativeCodePoint(end, 1,relIndex))) {
-        end += relIndex;
+    if ((end < length_ - 1) && isLam(text.dcharAt(end)) && isAlef(text.dcharAfter(end))) {
+        end = text.offsetAfter(end);
     }
 
     int low = -1;
@@ -2213,7 +2211,7 @@
     return offset - invalidOffsets.length;
 }
 
-int validateOffset( CString cont, int offset, int step) {
+int validateOffset( in char[] cont, int offset, int step) {
     if (invalidOffsets is null) return offset + step;
     int i = step > 0 ? 0 : invalidOffsets.length - 1;
     do {
@@ -2221,7 +2219,7 @@
             offset += step;
         }
         else{
-            offset += cont.getRelativeCodePointOffset( offset, step );
+            offset += cont.toUTF8shift( offset, step );
         }
         while (0 <= i && i < invalidOffsets.length) {
             if (invalidOffsets[i] is offset) break;