Mercurial > projects > dwt-linux
comparison dwt/graphics/TextLayout.d @ 238:380bad9f6852
reverted char[] to String
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Mon, 05 May 2008 00:42:55 +0200 |
parents | 08789b28bdf3 |
children | ce446666f5a2 |
comparison
equal
deleted
inserted
replaced
237:98b80b00af79 | 238:380bad9f6852 |
---|---|
55 | 55 |
56 static class StyleItem { | 56 static class StyleItem { |
57 TextStyle style; | 57 TextStyle style; |
58 int start; | 58 int start; |
59 | 59 |
60 public override char[] toString () { | 60 public override String toString () { |
61 return Format( "StyleItem {{{}, {}}", start, style ); | 61 return Format( "StyleItem {{{}, {}}", start, style ); |
62 } | 62 } |
63 } | 63 } |
64 | 64 |
65 Font font; | 65 Font font; |
66 char[] text; | 66 String text; |
67 int ascent, descent; | 67 int ascent, descent; |
68 int[] segments; | 68 int[] segments; |
69 int[] tabs; | 69 int[] tabs; |
70 StyleItem[] styles; | 70 StyleItem[] styles; |
71 PangoLayout* layout; | 71 PangoLayout* layout; |
75 // LTR_MARK LEFT-TO-RIGHT MARK | 75 // LTR_MARK LEFT-TO-RIGHT MARK |
76 // RTL_MARK RIGHT-TO-LEFT MARK | 76 // RTL_MARK RIGHT-TO-LEFT MARK |
77 // ZWS ZERO WIDTH SPACE | 77 // ZWS ZERO WIDTH SPACE |
78 // ZWNBS ZERO WIDTH NO-BREAK SPACE | 78 // ZWNBS ZERO WIDTH NO-BREAK SPACE |
79 static const dchar LTR_MARK = '\u200E', RTL_MARK = '\u200F', ZWS = '\u200B', ZWNBS = '\uFEFF'; | 79 static const dchar LTR_MARK = '\u200E', RTL_MARK = '\u200F', ZWS = '\u200B', ZWNBS = '\uFEFF'; |
80 static const char[] STR_LTR_MARK = "\u200E", STR_RTL_MARK = "\u200F", STR_ZWS = "\u200B", STR_ZWNBS = "\uFEFF"; | 80 static const String STR_LTR_MARK = "\u200E", STR_RTL_MARK = "\u200F", STR_ZWS = "\u200B", STR_ZWNBS = "\uFEFF"; |
81 | 81 |
82 /** | 82 /** |
83 * Constructs a new instance of this class on the given device. | 83 * Constructs a new instance of this class on the given device. |
84 * <p> | 84 * <p> |
85 * You must dispose the text layout when it is no longer required. | 85 * You must dispose the text layout when it is no longer required. |
121 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); | 121 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); |
122 } | 122 } |
123 | 123 |
124 void computeRuns () { | 124 void computeRuns () { |
125 if (attrList !is null) return; | 125 if (attrList !is null) return; |
126 char[] segmentsText = getSegmentsText(); | 126 String segmentsText = getSegmentsText(); |
127 OS.pango_layout_set_text (layout, segmentsText.ptr, segmentsText.length); | 127 OS.pango_layout_set_text (layout, segmentsText.ptr, segmentsText.length); |
128 if (styles.length is 2 && styles[0].style is null && ascent is -1 && descent is -1 && segments is null) return; | 128 if (styles.length is 2 && styles[0].style is null && ascent is -1 && descent is -1 && segments is null) return; |
129 auto ptr = OS.pango_layout_get_text(layout); | 129 auto ptr = OS.pango_layout_get_text(layout); |
130 attrList = OS.pango_attr_list_new(); | 130 attrList = OS.pango_attr_list_new(); |
131 //PangoAttribute* attribute = new PangoAttribute(); | 131 //PangoAttribute* attribute = new PangoAttribute(); |
161 count++; | 161 count++; |
162 } while (OS.pango_layout_iter_next_line(iter)); | 162 } while (OS.pango_layout_iter_next_line(iter)); |
163 OS.pango_layout_iter_free (iter); | 163 OS.pango_layout_iter_free (iter); |
164 chars[ oldPos + count*6 .. oldPos + count*6 + segementsLength - oldPos ] = | 164 chars[ oldPos + count*6 .. oldPos + count*6 + segementsLength - oldPos ] = |
165 segmentsText[ oldPos .. segementsLength ]; | 165 segmentsText[ oldPos .. segementsLength ]; |
166 char[] buffer = chars;// Converter.wcsToMbcs(null, chars, false); | 166 String buffer = chars;// Converter.wcsToMbcs(null, chars, false); |
167 | 167 |
168 OS.pango_layout_set_text (layout, buffer.ptr, buffer.length); | 168 OS.pango_layout_set_text (layout, buffer.ptr, buffer.length); |
169 ptr = OS.pango_layout_get_text(layout); | 169 ptr = OS.pango_layout_get_text(layout); |
170 } else { | 170 } else { |
171 chars = segmentsText.dup; | 171 chars = segmentsText.dup; |
1196 public int[] getSegments() { | 1196 public int[] getSegments() { |
1197 checkLayout(); | 1197 checkLayout(); |
1198 return segments; | 1198 return segments; |
1199 } | 1199 } |
1200 | 1200 |
1201 char[] getSegmentsText() { | 1201 String getSegmentsText() { |
1202 if (segments is null) return text; | 1202 if (segments is null) return text; |
1203 int nSegments = segments.length; | 1203 int nSegments = segments.length; |
1204 if (nSegments <= 1) return text; | 1204 if (nSegments <= 1) return text; |
1205 int len = text.length; | 1205 int len = text.length; |
1206 if (len is 0) return text; | 1206 if (len is 0) return text; |
1208 if (segments[0] is 0 && segments[1] is len) return text; | 1208 if (segments[0] is 0 && segments[1] is len) return text; |
1209 } | 1209 } |
1210 char[] oldChars = text[0..len].dup; | 1210 char[] oldChars = text[0..len].dup; |
1211 char[] newChars = new char[len + nSegments*3]; | 1211 char[] newChars = new char[len + nSegments*3]; |
1212 int charCount = 0, segmentCount = 0; | 1212 int charCount = 0, segmentCount = 0; |
1213 char[] separator = getOrientation() is DWT.RIGHT_TO_LEFT ? STR_RTL_MARK : STR_LTR_MARK; | 1213 String separator = getOrientation() is DWT.RIGHT_TO_LEFT ? STR_RTL_MARK : STR_LTR_MARK; |
1214 while (charCount < len) { | 1214 while (charCount < len) { |
1215 if (segmentCount < nSegments && charCount is segments[segmentCount]) { | 1215 if (segmentCount < nSegments && charCount is segments[segmentCount]) { |
1216 newChars[charCount + segmentCount .. charCount + segmentCount + separator.length ] = separator; | 1216 newChars[charCount + segmentCount .. charCount + segmentCount + separator.length ] = separator; |
1217 segmentCount+=separator.length; | 1217 segmentCount+=separator.length; |
1218 } else { | 1218 } else { |
1320 * | 1320 * |
1321 * @exception DWTException <ul> | 1321 * @exception DWTException <ul> |
1322 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | 1322 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> |
1323 * </ul> | 1323 * </ul> |
1324 */ | 1324 */ |
1325 public char[] getText () { | 1325 public String getText () { |
1326 checkLayout (); | 1326 checkLayout (); |
1327 return text; | 1327 return text; |
1328 } | 1328 } |
1329 | 1329 |
1330 /** | 1330 /** |
1733 * | 1733 * |
1734 * @exception DWTException <ul> | 1734 * @exception DWTException <ul> |
1735 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | 1735 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> |
1736 * </ul> | 1736 * </ul> |
1737 */ | 1737 */ |
1738 public void setText (char[] text) { | 1738 public void setText (String text) { |
1739 checkLayout (); | 1739 checkLayout (); |
1740 if (text.equals(this.text)) return; | 1740 if (text.equals(this.text)) return; |
1741 freeRuns(); | 1741 freeRuns(); |
1742 this.text = text; | 1742 this.text = text; |
1743 styles = new StyleItem[2]; | 1743 styles = new StyleItem[2]; |
1795 * Returns a string containing a concise, human-readable | 1795 * Returns a string containing a concise, human-readable |
1796 * description of the receiver. | 1796 * description of the receiver. |
1797 * | 1797 * |
1798 * @return a string representation of the receiver | 1798 * @return a string representation of the receiver |
1799 */ | 1799 */ |
1800 public override char[] toString () { | 1800 public override String toString () { |
1801 if (isDisposed()) return "TextLayout {*DISPOSED*}"; | 1801 if (isDisposed()) return "TextLayout {*DISPOSED*}"; |
1802 return Format( "TextLayout {{{}}", layout ); | 1802 return Format( "TextLayout {{{}}", layout ); |
1803 } | 1803 } |
1804 | 1804 |
1805 /* | 1805 /* |
1833 } | 1833 } |
1834 } | 1834 } |
1835 return offset - invalidOffsets.length; | 1835 return offset - invalidOffsets.length; |
1836 } | 1836 } |
1837 | 1837 |
1838 int validateOffset( char[] cont, int offset, int step) { | 1838 int validateOffset( String cont, int offset, int step) { |
1839 if (invalidOffsets is null) return offset + step; | 1839 if (invalidOffsets is null) return offset + step; |
1840 int i = step > 0 ? 0 : invalidOffsets.length - 1; | 1840 int i = step > 0 ? 0 : invalidOffsets.length - 1; |
1841 do { | 1841 do { |
1842 if( offset is 0 && step < 0 ){ | 1842 if( offset is 0 && step < 0 ){ |
1843 offset += step; | 1843 offset += step; |