comparison org.eclipse.swt.win32.win32.x86/src/org/eclipse/swt/graphics/TextLayout.d @ 39:0ecb2b338560

further work on phobosification
author Frank Benoit <benoit@tionex.de>
date Wed, 25 Mar 2009 13:20:43 +0100
parents d46287db17ed
children 9f4c18c268b2
comparison
equal deleted inserted replaced
38:2e09b0e6857a 39:0ecb2b338560
84 +/ 84 +/
85 85
86 86
87 Font font; 87 Font font;
88 String text; 88 String text;
89 wchar[] wtext; 89 String16 wtext;
90 char[] segmentsText; 90 String segmentsText;
91 wchar[] segmentsWText; // SWT 91 String16 segmentsWText; // DWT
92 int[] index8to16; // SWT 92 int[] index8to16; // DWT
93 int[] index16to8; // SWT 93 int[] index16to8; // DWT
94 int lineSpacing; 94 int lineSpacing;
95 int ascent, descent; 95 int ascent, descent;
96 int alignment; 96 int alignment;
97 int wrapWidth; 97 int wrapWidth;
98 int orientation; 98 int orientation;
259 init_(); 259 init_();
260 } 260 }
261 261
262 void breakRun(StyleItem run) { 262 void breakRun(StyleItem run) {
263 if (run.psla !is null) return; 263 if (run.psla !is null) return;
264 wchar[] chars = segmentsWText[ index8to16[ run.start ] .. index8to16[ run.start + run.length ] ]; 264 String16 chars = segmentsWText[ index8to16[ run.start ] .. index8to16[ run.start + run.length ] ];
265 auto hHeap = OS.GetProcessHeap(); 265 auto hHeap = OS.GetProcessHeap();
266 run.psla = cast(SCRIPT_LOGATTR*)OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, SCRIPT_LOGATTR.sizeof * chars.length); 266 run.psla = cast(SCRIPT_LOGATTR*)OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, SCRIPT_LOGATTR.sizeof * chars.length);
267 if (run.psla is null) SWT.error(SWT.ERROR_NO_HANDLES); 267 if (run.psla is null) SWT.error(SWT.ERROR_NO_HANDLES);
268 OS.ScriptBreak(chars.ptr, chars.length, &run.analysis, run.psla); 268 OS.ScriptBreak(chars.ptr, chars.length, &run.analysis, run.psla);
269 } 269 }
2125 public int[] getSegments () { 2125 public int[] getSegments () {
2126 checkLayout(); 2126 checkLayout();
2127 return segments; 2127 return segments;
2128 } 2128 }
2129 2129
2130 void getSegmentsText( out char[] resUtf8, out wchar[] resUtf16 ) { 2130 void getSegmentsText( out String resUtf8, out String16 resUtf16 ) {
2131 2131
2132 void buildIndexTables() { // build the index translation tables. 2132 void buildIndexTables() { // build the index translation tables.
2133 index8to16.length = resUtf8.length + 1; 2133 index8to16.length = resUtf8.length + 1;
2134 index16to8.length = resUtf16.length + 1; 2134 index16to8.length = resUtf16.length + 1;
2135 2135
2176 buildIndexTables(); 2176 buildIndexTables();
2177 return; 2177 return;
2178 } 2178 }
2179 } 2179 }
2180 { 2180 {
2181 char[] oldChars = text; 2181 auto oldChars = text;
2182 // SWT: MARK is now 3 chars long 2182 // SWT: MARK is now 3 chars long
2183 String separator = orientation is SWT.RIGHT_TO_LEFT ? STR_RTL_MARK : STR_LTR_MARK; 2183 String separator = orientation is SWT.RIGHT_TO_LEFT ? STR_RTL_MARK : STR_LTR_MARK;
2184 assert( separator.length is MARK_SIZE ); 2184 assert( separator.length is MARK_SIZE );
2185 char[] newChars = new char[length_ + nSegments*MARK_SIZE]; 2185 char[] newChars = new char[length_ + nSegments*MARK_SIZE];
2186 2186
2199 segments[segmentCount] = charCount; 2199 segments[segmentCount] = charCount;
2200 int start = charCount + (segmentCount*MARK_SIZE); 2200 int start = charCount + (segmentCount*MARK_SIZE);
2201 newChars[ start .. start + MARK_SIZE ] = separator; 2201 newChars[ start .. start + MARK_SIZE ] = separator;
2202 segmentCount++; 2202 segmentCount++;
2203 } 2203 }
2204 resUtf8 = newChars[ 0 .. Math.min(charCount + (segmentCount*MARK_SIZE), newChars.length)]; 2204 resUtf8 = cast(String)newChars[ 0 .. Math.min(charCount + (segmentCount*MARK_SIZE), newChars.length)];
2205 } 2205 }
2206 // now for the wide chars 2206 // now for the wide chars
2207 { 2207 {
2208 wchar[] oldWChars = wtext; 2208 String16 oldWChars = wtext;
2209 wchar[] wseparator = orientation is SWT.RIGHT_TO_LEFT ? WSTR_RTL_MARK : WSTR_LTR_MARK; 2209 auto wseparator = orientation is SWT.RIGHT_TO_LEFT ? WSTR_RTL_MARK : WSTR_LTR_MARK;
2210 assert( wseparator.length is 1 ); 2210 assert( wseparator.length is 1 );
2211 wchar[] newWChars = new wchar[wlength_ + nSegments]; 2211 wchar[] newWChars = new wchar[wlength_ + nSegments];
2212 2212
2213 int charCount = 0, segmentCount = 0; 2213 int charCount = 0, segmentCount = 0;
2214 while (charCount < wlength_) { 2214 while (charCount < wlength_) {
2225 wsegments[segmentCount] = charCount; 2225 wsegments[segmentCount] = charCount;
2226 int start = charCount + (segmentCount*WMARK_SIZE); 2226 int start = charCount + (segmentCount*WMARK_SIZE);
2227 newWChars[ start .. start + WMARK_SIZE ] = wseparator; 2227 newWChars[ start .. start + WMARK_SIZE ] = wseparator;
2228 segmentCount++; 2228 segmentCount++;
2229 } 2229 }
2230 resUtf16 = newWChars[ 0 .. Math.min(charCount + (segmentCount*WMARK_SIZE), newWChars.length)]; 2230 resUtf16 = cast(String16)newWChars[ 0 .. Math.min(charCount + (segmentCount*WMARK_SIZE), newWChars.length)];
2231 } 2231 }
2232 buildIndexTables(); 2232 buildIndexTables();
2233 } 2233 }
2234 2234
2235 /** 2235 /**
2380 2380
2381 auto hHeap = OS.GetProcessHeap(); 2381 auto hHeap = OS.GetProcessHeap();
2382 auto pItems = cast(SCRIPT_ITEM*)OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, MAX_ITEM * SCRIPT_ITEM.sizeof); 2382 auto pItems = cast(SCRIPT_ITEM*)OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, MAX_ITEM * SCRIPT_ITEM.sizeof);
2383 if (pItems is null) SWT.error(SWT.ERROR_NO_HANDLES); 2383 if (pItems is null) SWT.error(SWT.ERROR_NO_HANDLES);
2384 int pcItems; 2384 int pcItems;
2385 wchar[] chars = segmentsWText; 2385 String16 chars = segmentsWText;
2386 OS.ScriptItemize(chars.ptr, chars.length, MAX_ITEM, &scriptControl, &scriptState, pItems, &pcItems); 2386 OS.ScriptItemize(chars.ptr, chars.length, MAX_ITEM, &scriptControl, &scriptState, pItems, &pcItems);
2387 // if (hr is E_OUTOFMEMORY) //TODO handle it 2387 // if (hr is E_OUTOFMEMORY) //TODO handle it
2388 // SWT pcItems is not inclusive the trailing item 2388 // SWT pcItems is not inclusive the trailing item
2389 2389
2390 StyleItem[] runs = merge(pItems, pcItems); 2390 StyleItem[] runs = merge(pItems, pcItems);
2869 2869
2870 //PORTING_CHANGE: allow null argument 2870 //PORTING_CHANGE: allow null argument
2871 //if (text is null) SWT.error(SWT.ERROR_NULL_ARGUMENT); 2871 //if (text is null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
2872 if (text.equals(this.text)) return; 2872 if (text.equals(this.text)) return;
2873 freeRuns(); 2873 freeRuns();
2874 this.text = text.dup; 2874 this.text = text._idup();
2875 this.wtext = StrToWCHARs(text); 2875 this.wtext = StrToWCHARs(text);
2876 styles = new StyleItem[2]; 2876 styles = new StyleItem[2];
2877 styles[0] = new StyleItem(); 2877 styles[0] = new StyleItem();
2878 styles[1] = new StyleItem(); 2878 styles[1] = new StyleItem();
2879 styles[1].start = text.length; 2879 styles[1].start = text.length;
2902 if (this.wrapWidth is width) return; 2902 if (this.wrapWidth is width) return;
2903 freeRuns(); 2903 freeRuns();
2904 this.wrapWidth = width; 2904 this.wrapWidth = width;
2905 } 2905 }
2906 2906
2907 bool shape (HDC hdc, StyleItem run, wchar[] wchars, int[] glyphCount, int maxGlyphs, SCRIPT_PROPERTIES* sp) { 2907 bool shape (HDC hdc, StyleItem run, String16 wchars, int[] glyphCount, int maxGlyphs, SCRIPT_PROPERTIES* sp) {
2908 bool useCMAPcheck = !sp.fComplex && !run.analysis.fNoGlyphIndex; 2908 bool useCMAPcheck = !sp.fComplex && !run.analysis.fNoGlyphIndex;
2909 if (useCMAPcheck) { 2909 if (useCMAPcheck) {
2910 scope ushort[] glyphs = new ushort[wchars.length]; 2910 scope ushort[] glyphs = new ushort[wchars.length];
2911 if (OS.ScriptGetCMap(hdc, run.psc, wchars.ptr, wchars.length, 0, glyphs.ptr) !is OS.S_OK) { 2911 if (OS.ScriptGetCMap(hdc, run.psc, wchars.ptr, wchars.length, 0, glyphs.ptr) !is OS.S_OK) {
2912 if (run.psc !is null) { 2912 if (run.psc !is null) {
2947 /* 2947 /*
2948 * Generate glyphs for one Run. 2948 * Generate glyphs for one Run.
2949 */ 2949 */
2950 void shape (HDC hdc, StyleItem run) { 2950 void shape (HDC hdc, StyleItem run) {
2951 int[1] buffer; 2951 int[1] buffer;
2952 wchar[] wchars = segmentsWText[ index8to16[ run.start ] .. index8to16[ run.start + run.length ] ]; 2952 auto wchars = segmentsWText[ index8to16[ run.start ] .. index8to16[ run.start + run.length ] ];
2953 int maxGlyphs = (wchars.length * 3 / 2) + 16; 2953 int maxGlyphs = (wchars.length * 3 / 2) + 16;
2954 auto hHeap = OS.GetProcessHeap(); 2954 auto hHeap = OS.GetProcessHeap();
2955 run.glyphs = cast(ushort*)OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, maxGlyphs * 2); 2955 run.glyphs = cast(ushort*)OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, maxGlyphs * 2);
2956 if (run.glyphs is null) SWT.error(SWT.ERROR_NO_HANDLES); 2956 if (run.glyphs is null) SWT.error(SWT.ERROR_NO_HANDLES);
2957 run.clusters = cast(WORD*)OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, maxGlyphs * 2); 2957 run.clusters = cast(WORD*)OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, maxGlyphs * 2);