diff dwt/graphics/TextLayout.d @ 284:6956821fe8ed

Fixes for StyledText
author Frank Benoit <benoit@tionex.de>
date Mon, 04 Aug 2008 02:06:13 +0200
parents edcf78db8722
children
line wrap: on
line diff
--- a/dwt/graphics/TextLayout.d	Mon Aug 04 02:05:58 2008 +0200
+++ b/dwt/graphics/TextLayout.d	Mon Aug 04 02:06:13 2008 +0200
@@ -140,7 +140,7 @@
     if (styles.length is 2 && styles[0].style is null && ascent is -1 && descent is -1 && segments is null) return;
     auto ptr = OS.pango_layout_get_text(layout);
     attrList = OS.pango_attr_list_new();
-    //PangoAttribute* attribute = new PangoAttribute();
+    PangoAttribute* attribute;
     char[] chars = null;
     int segementsLength = segmentsText.length;
     if ((ascent !is -1  || descent !is -1) && segementsLength > 0) {
@@ -156,12 +156,14 @@
             /* Note: The length in bytes of ZWS and ZWNBS are both equals to 3 */
             int offset = lineIndex * 6;
             PangoAttribute* attr = OS.pango_attr_shape_new (&rect, &rect);
-            attr.start_index = bytePos + offset;
-            attr.end_index = bytePos + offset + 3;
+            attribute = attr;
+            attribute.start_index = bytePos + offset;
+            attribute.end_index = bytePos + offset + 3;
             OS.pango_attr_list_insert(attrList, attr);
             attr = OS.pango_attr_shape_new (&rect, &rect);
-            attr.start_index = bytePos + offset + 3;
-            attr.end_index = bytePos + offset + 6;
+            attribute = attr;
+            attribute.start_index = bytePos + offset + 3;
+            attribute.end_index = bytePos + offset + 6;
             OS.pango_attr_list_insert(attrList, attr);
             int pos = bytePos;//OS.g_utf8_pointer_to_offset(ptr, ptr + bytePos);
             chars[pos + lineIndex * 6 +0 .. pos + lineIndex * 6 + 3] = STR_ZWS;
@@ -1347,28 +1349,31 @@
     }
     PangoLogAttr* attrs;
     int nAttrs;
+    // return one attr per codepoint (=char in pango)
     OS.pango_layout_get_log_attrs(layout, &attrs, &nAttrs);
     if (attrs is null) return offset + step;
-    length_ = OS.g_utf8_strlen(cont, -1);
+    length_ = dcont.length;//OS.g_utf8_strlen(cont, -1);
     offset = translateOffset(offset);
     offset = dcont.utf8AdjustOffset( offset );
-    PangoLogAttr* logAttr = new PangoLogAttr();
+
+    PangoLogAttr* logAttr;
     offset = validateOffset( dcont, offset, step);
+    // the loop is byte oriented
     while (0 < offset && offset < length_) {
-        *logAttr = attrs[ offset ];
-        if (((movement & DWT.MOVEMENT_CLUSTER) !is 0) && ( logAttr.bitfield0 & (1<<4/*is_cursor_position*/))) break;
+        logAttr = & attrs[ OS.g_utf8_pointer_to_offset( cont, cont+offset) ];
+        if (((movement & DWT.MOVEMENT_CLUSTER) !is 0) && logAttr.is_cursor_position ) break;
         if ((movement & DWT.MOVEMENT_WORD) !is 0) {
             if (forward) {
-                if (logAttr.bitfield0 & (1<<6/*is_word_end*/)) break;
+                if (logAttr.is_word_end ) break;
             } else {
-                if (logAttr.bitfield0 & (1<<5/*is_word_start*/)) break;
+                if (logAttr.is_word_start ) break;
             }
         }
         if ((movement & DWT.MOVEMENT_WORD_START) !is 0) {
-            if (logAttr.bitfield0 & (1<<5/*is_word_start*/)) break;
+            if (logAttr.is_word_start ) break;
         }
         if ((movement & DWT.MOVEMENT_WORD_END) !is 0) {
-            if (logAttr.bitfield0 & (1<<6/*is_word_end*/)) break;
+            if (logAttr.is_word_end ) break;
         }
         offset = validateOffset( dcont, offset, step);
     }