Changeset 96
- Timestamp:
- 02/07/06 11:38:33 (3 years ago)
- Files:
-
- trunk/current/win32/import/dwt/custom/clabel.d (modified) (3 diffs)
- trunk/current/win32/import/dwt/custom/ctabitem.d (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/current/win32/import/dwt/custom/clabel.d
r95 r96 705 705 * Override if you need a different strategy. 706 706 */ 707 protected char[] shortenText(GC gc, char[] ts, int width) { 708 709 if (ts is null) return null; 707 protected char[] shortenText(GC gc, char[] text, int width) { 708 709 if (text.length == 0) return text; 710 if (gc.textExtent(text).x <= width) return text; 710 711 711 712 // <Shawn> 712 // must make a copy of the the original text, otherwise the orginal text will be changed !!! 713 char[] t = ts.dup; 713 // 20060207 : when strip character by char in UTF8 will cut MBCS such as Chinese character 714 // to half and may cause UTF convert error when call OS API to draw, the fix is convert to 715 // wchar[] during shorten the Text 716 wchar[] t = std.utf.toUTF16(text); 717 wchar[] wELLIPSIS = std.utf.toUTF16(ELLIPSIS); 714 718 int w = gc.textExtent(ELLIPSIS).x; 715 719 int l = t.length; … … 718 722 int e = pivot+1; 719 723 while (s >= 0 && e < l) { 720 char[] s1 = t[0..s];721 char[] s2 = Converter.substring(t, e,l);722 int l1 = gc.textExtent(s 1).x;723 int l2 = gc.textExtent(s 2).x;724 wchar[] s1 = t[0..s]; 725 wchar[] s2 = t[e..l]; 726 int l1 = gc.textExtent(std.utf.toUTF8(s1)).x; 727 int l2 = gc.textExtent(std.utf.toUTF8(s2)).x; 724 728 if (l1+w+l2 < width) { 725 t = s1 ~ ELLIPSIS ~ s2;729 t = s1 ~ wELLIPSIS ~ s2; 726 730 break; 727 731 } … … 729 733 e++; 730 734 } 731 return t;732 } 733 } 735 return std.utf.toUTF8(t); 736 } 737 } trunk/current/win32/import/dwt/custom/ctabitem.d
r95 r96 141 141 } 142 142 static char[] shortenText(GC gc, char[] string, int width) { 143 if( string is null) return null;143 if( string.length == 0) return string; 144 144 if (gc.textExtent(string, FLAGS).x <= width) return string; 145 145 146 146 // <Shawn> 147 // must make a copy of the the original text, otherwise the orginal text will be cut short !!! 148 char[] t = string.dup; 147 // 20060207 : when strip character by char in UTF8 will cut MBCS such as Chinese character 148 // to half and may cause UTF convert error when call OS API to draw, the fix is convert to 149 // wchar[] during shorten the Text 150 149 151 int ellipseWidth = gc.textExtent(ELLIPSIS, FLAGS).x; 152 wchar[] t = std.utf.toUTF16(string); 150 153 int length = t.length; 151 154 int end = length - 1; 152 155 while (end > 0) { 153 t = Converter.substring(t, 0, end);154 int l = gc.textExtent( t, FLAGS).x;156 t = t[0..end]; 157 int l = gc.textExtent(std.utf.toUTF8(t), FLAGS).x; 155 158 if (l + ellipseWidth <= width) { 156 return t~ ELLIPSIS;159 return std.utf.toUTF8(t) ~ ELLIPSIS; 157 160 } 158 161 end--; 159 162 } 160 return Converter.substring(t, 0, 1); 161 } 163 return std.utf.toUTF8(t[0..1]); 164 } 165 162 166 public void dispose() { 163 167 if (isDisposed ()) return;
