Mercurial > projects > dwt-linux
comparison 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 |
comparison
equal
deleted
inserted
replaced
283:05e48e1e65d1 | 284:6956821fe8ed |
---|---|
138 String segmentsText = getSegmentsText(); | 138 String segmentsText = getSegmentsText(); |
139 OS.pango_layout_set_text (layout, segmentsText.ptr, segmentsText.length); | 139 OS.pango_layout_set_text (layout, segmentsText.ptr, segmentsText.length); |
140 if (styles.length is 2 && styles[0].style is null && ascent is -1 && descent is -1 && segments is null) return; | 140 if (styles.length is 2 && styles[0].style is null && ascent is -1 && descent is -1 && segments is null) return; |
141 auto ptr = OS.pango_layout_get_text(layout); | 141 auto ptr = OS.pango_layout_get_text(layout); |
142 attrList = OS.pango_attr_list_new(); | 142 attrList = OS.pango_attr_list_new(); |
143 //PangoAttribute* attribute = new PangoAttribute(); | 143 PangoAttribute* attribute; |
144 char[] chars = null; | 144 char[] chars = null; |
145 int segementsLength = segmentsText.length; | 145 int segementsLength = segmentsText.length; |
146 if ((ascent !is -1 || descent !is -1) && segementsLength > 0) { | 146 if ((ascent !is -1 || descent !is -1) && segementsLength > 0) { |
147 PangoRectangle rect; | 147 PangoRectangle rect; |
148 if (ascent !is -1) rect.y = -(ascent * OS.PANGO_SCALE); | 148 if (ascent !is -1) rect.y = -(ascent * OS.PANGO_SCALE); |
154 auto line = OS.pango_layout_get_line(layout, lineIndex); | 154 auto line = OS.pango_layout_get_line(layout, lineIndex); |
155 int bytePos = line.start_index; | 155 int bytePos = line.start_index; |
156 /* Note: The length in bytes of ZWS and ZWNBS are both equals to 3 */ | 156 /* Note: The length in bytes of ZWS and ZWNBS are both equals to 3 */ |
157 int offset = lineIndex * 6; | 157 int offset = lineIndex * 6; |
158 PangoAttribute* attr = OS.pango_attr_shape_new (&rect, &rect); | 158 PangoAttribute* attr = OS.pango_attr_shape_new (&rect, &rect); |
159 attr.start_index = bytePos + offset; | 159 attribute = attr; |
160 attr.end_index = bytePos + offset + 3; | 160 attribute.start_index = bytePos + offset; |
161 attribute.end_index = bytePos + offset + 3; | |
161 OS.pango_attr_list_insert(attrList, attr); | 162 OS.pango_attr_list_insert(attrList, attr); |
162 attr = OS.pango_attr_shape_new (&rect, &rect); | 163 attr = OS.pango_attr_shape_new (&rect, &rect); |
163 attr.start_index = bytePos + offset + 3; | 164 attribute = attr; |
164 attr.end_index = bytePos + offset + 6; | 165 attribute.start_index = bytePos + offset + 3; |
166 attribute.end_index = bytePos + offset + 6; | |
165 OS.pango_attr_list_insert(attrList, attr); | 167 OS.pango_attr_list_insert(attrList, attr); |
166 int pos = bytePos;//OS.g_utf8_pointer_to_offset(ptr, ptr + bytePos); | 168 int pos = bytePos;//OS.g_utf8_pointer_to_offset(ptr, ptr + bytePos); |
167 chars[pos + lineIndex * 6 +0 .. pos + lineIndex * 6 + 3] = STR_ZWS; | 169 chars[pos + lineIndex * 6 +0 .. pos + lineIndex * 6 + 3] = STR_ZWS; |
168 chars[pos + lineIndex * 6 +3 .. pos + lineIndex * 6 + 6] = STR_ZWNBS; | 170 chars[pos + lineIndex * 6 +3 .. pos + lineIndex * 6 + 6] = STR_ZWNBS; |
169 chars[ oldPos + lineIndex*6 .. oldPos + lineIndex*6 + pos - oldPos ] = | 171 chars[ oldPos + lineIndex*6 .. oldPos + lineIndex*6 + pos - oldPos ] = |
1345 int incr = dcont.getRelativeCodePointOffset( toffset, step ); | 1347 int incr = dcont.getRelativeCodePointOffset( toffset, step ); |
1346 return offset + incr; | 1348 return offset + incr; |
1347 } | 1349 } |
1348 PangoLogAttr* attrs; | 1350 PangoLogAttr* attrs; |
1349 int nAttrs; | 1351 int nAttrs; |
1352 // return one attr per codepoint (=char in pango) | |
1350 OS.pango_layout_get_log_attrs(layout, &attrs, &nAttrs); | 1353 OS.pango_layout_get_log_attrs(layout, &attrs, &nAttrs); |
1351 if (attrs is null) return offset + step; | 1354 if (attrs is null) return offset + step; |
1352 length_ = OS.g_utf8_strlen(cont, -1); | 1355 length_ = dcont.length;//OS.g_utf8_strlen(cont, -1); |
1353 offset = translateOffset(offset); | 1356 offset = translateOffset(offset); |
1354 offset = dcont.utf8AdjustOffset( offset ); | 1357 offset = dcont.utf8AdjustOffset( offset ); |
1355 PangoLogAttr* logAttr = new PangoLogAttr(); | 1358 |
1359 PangoLogAttr* logAttr; | |
1356 offset = validateOffset( dcont, offset, step); | 1360 offset = validateOffset( dcont, offset, step); |
1361 // the loop is byte oriented | |
1357 while (0 < offset && offset < length_) { | 1362 while (0 < offset && offset < length_) { |
1358 *logAttr = attrs[ offset ]; | 1363 logAttr = & attrs[ OS.g_utf8_pointer_to_offset( cont, cont+offset) ]; |
1359 if (((movement & DWT.MOVEMENT_CLUSTER) !is 0) && ( logAttr.bitfield0 & (1<<4/*is_cursor_position*/))) break; | 1364 if (((movement & DWT.MOVEMENT_CLUSTER) !is 0) && logAttr.is_cursor_position ) break; |
1360 if ((movement & DWT.MOVEMENT_WORD) !is 0) { | 1365 if ((movement & DWT.MOVEMENT_WORD) !is 0) { |
1361 if (forward) { | 1366 if (forward) { |
1362 if (logAttr.bitfield0 & (1<<6/*is_word_end*/)) break; | 1367 if (logAttr.is_word_end ) break; |
1363 } else { | 1368 } else { |
1364 if (logAttr.bitfield0 & (1<<5/*is_word_start*/)) break; | 1369 if (logAttr.is_word_start ) break; |
1365 } | 1370 } |
1366 } | 1371 } |
1367 if ((movement & DWT.MOVEMENT_WORD_START) !is 0) { | 1372 if ((movement & DWT.MOVEMENT_WORD_START) !is 0) { |
1368 if (logAttr.bitfield0 & (1<<5/*is_word_start*/)) break; | 1373 if (logAttr.is_word_start ) break; |
1369 } | 1374 } |
1370 if ((movement & DWT.MOVEMENT_WORD_END) !is 0) { | 1375 if ((movement & DWT.MOVEMENT_WORD_END) !is 0) { |
1371 if (logAttr.bitfield0 & (1<<6/*is_word_end*/)) break; | 1376 if (logAttr.is_word_end ) break; |
1372 } | 1377 } |
1373 offset = validateOffset( dcont, offset, step); | 1378 offset = validateOffset( dcont, offset, step); |
1374 } | 1379 } |
1375 OS.g_free(attrs); | 1380 OS.g_free(attrs); |
1376 return Math.min(Math.max(0, untranslateOffset(offset)), text.length); | 1381 return Math.min(Math.max(0, untranslateOffset(offset)), text.length); |