comparison dwt/graphics/TextLayout.d @ 230:c853f6513712

removed debug prints
author Frank Benoit <benoit@tionex.de>
date Sat, 24 May 2008 08:59:14 +0200
parents 5ff96efb6f4b
children fd9c62a2998e
comparison
equal deleted inserted replaced
229:5ff96efb6f4b 230:c853f6513712
9 * IBM Corporation - initial API and implementation 9 * IBM Corporation - initial API and implementation
10 * Port to the D programming language: 10 * Port to the D programming language:
11 * Frank Benoit <benoit@tionex.de> 11 * Frank Benoit <benoit@tionex.de>
12 *******************************************************************************/ 12 *******************************************************************************/
13 module dwt.graphics.TextLayout; 13 module dwt.graphics.TextLayout;
14
15 import tango.util.log.Trace;
16 14
17 import dwt.DWT; 15 import dwt.DWT;
18 import dwt.DWTException; 16 import dwt.DWTException;
19 import dwt.internal.Compatibility; 17 import dwt.internal.Compatibility;
20 import dwt.internal.gdip.Gdip; 18 import dwt.internal.gdip.Gdip;
2261 auto hHeap = OS.GetProcessHeap(); 2259 auto hHeap = OS.GetProcessHeap();
2262 auto pItems = cast(SCRIPT_ITEM*)OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, MAX_ITEM * SCRIPT_ITEM.sizeof); 2260 auto pItems = cast(SCRIPT_ITEM*)OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, MAX_ITEM * SCRIPT_ITEM.sizeof);
2263 if (pItems is null) DWT.error(DWT.ERROR_NO_HANDLES); 2261 if (pItems is null) DWT.error(DWT.ERROR_NO_HANDLES);
2264 int pcItems; 2262 int pcItems;
2265 wchar[] chars = StrToWCHARs( segmentsText ); 2263 wchar[] chars = StrToWCHARs( segmentsText );
2266 Trace.formatln( "{} {}: segmentsText='{}' chars='{}'", __FILE__,__LINE__, segmentsText, chars );
2267 OS.ScriptItemize(chars.ptr, chars.length, MAX_ITEM, &scriptControl, &scriptState, pItems, &pcItems); 2264 OS.ScriptItemize(chars.ptr, chars.length, MAX_ITEM, &scriptControl, &scriptState, pItems, &pcItems);
2268 // if (hr is E_OUTOFMEMORY) //TODO handle it 2265 // if (hr is E_OUTOFMEMORY) //TODO handle it
2269 2266
2270 // Translate the utf16 indices to utf8 indices 2267 // Translate the utf16 indices to utf8 indices
2271 Trace.formatln( "{} {}: pcItems={} chars.length={} segmentsText.length={}", __FILE__,__LINE__,pcItems, chars.length, segmentsText.length );
2272 int utf8idx = 0; 2268 int utf8idx = 0;
2273 SCRIPT_ITEM* si = pItems; 2269 SCRIPT_ITEM* si = pItems;
2274 foreach( uint utf16idx, char c; chars ){ 2270 foreach( uint utf16idx, char c; chars ){
2275 Trace.formatln( "{} {}: utf8idx={} utf16idx={} si.iCharPos={}", __FILE__,__LINE__,utf8idx, utf16idx, si.iCharPos );
2276 if( si.iCharPos is utf16idx ){ 2271 if( si.iCharPos is utf16idx ){
2277 si.iCharPos = utf8idx; 2272 si.iCharPos = utf8idx;
2278 si++; 2273 si++;
2279 } 2274 }
2280 utf8idx++; 2275 utf8idx++;
2293 StyleItem[] newStyles = new StyleItem[stylesCount]; 2288 StyleItem[] newStyles = new StyleItem[stylesCount];
2294 System.arraycopy(styles, 0, newStyles, 0, stylesCount); 2289 System.arraycopy(styles, 0, newStyles, 0, stylesCount);
2295 styles = newStyles; 2290 styles = newStyles;
2296 } 2291 }
2297 int count = 0, start = 0, end = segmentsText.length, itemIndex = 0, styleIndex = 0; 2292 int count = 0, start = 0, end = segmentsText.length, itemIndex = 0, styleIndex = 0;
2298 Trace.formatln( "{} {}: itemCount={} stylesCount={}", __FILE__,__LINE__,itemCount, stylesCount );
2299 StyleItem[] runs = new StyleItem[itemCount + stylesCount]; 2293 StyleItem[] runs = new StyleItem[itemCount + stylesCount];
2300 SCRIPT_ITEM* scriptItem = new SCRIPT_ITEM(); 2294 SCRIPT_ITEM* scriptItem = new SCRIPT_ITEM();
2301 bool linkBefore = false; 2295 bool linkBefore = false;
2302 Trace.formatln( "{} {}: start={} end={}", __FILE__,__LINE__,start, end );
2303 while (start < end) { 2296 while (start < end) {
2304 StyleItem item = new StyleItem(); 2297 StyleItem item = new StyleItem();
2305 item.start = start; 2298 item.start = start;
2306 item.style = styles[styleIndex].style; 2299 item.style = styles[styleIndex].style;
2307 Trace.formatln( "{} {}: count={}", __FILE__,__LINE__,count );
2308 runs[count++] = item; 2300 runs[count++] = item;
2309 OS.MoveMemory(scriptItem, (cast(void*)items) + itemIndex * SCRIPT_ITEM.sizeof, SCRIPT_ITEM.sizeof); 2301 OS.MoveMemory(scriptItem, (cast(void*)items) + itemIndex * SCRIPT_ITEM.sizeof, SCRIPT_ITEM.sizeof);
2310 item.analysis = scriptItem.a; 2302 item.analysis = scriptItem.a;
2311 if (linkBefore) { 2303 if (linkBefore) {
2312 item.analysis.fLinkBefore = true; 2304 item.analysis.fLinkBefore = true;
2331 if (itemLimit <= styleLimit) { 2323 if (itemLimit <= styleLimit) {
2332 itemIndex++; 2324 itemIndex++;
2333 start = itemLimit; 2325 start = itemLimit;
2334 } 2326 }
2335 item.length = start - item.start; 2327 item.length = start - item.start;
2336 Trace.formatln( "{} {}: start={} end={}", __FILE__,__LINE__,start, end );
2337 } 2328 }
2338 StyleItem item = new StyleItem(); 2329 StyleItem item = new StyleItem();
2339 item.start = end; 2330 item.start = end;
2340 OS.MoveMemory(scriptItem, (cast(void*)items) + itemCount * SCRIPT_ITEM.sizeof, SCRIPT_ITEM.sizeof); 2331 OS.MoveMemory(scriptItem, (cast(void*)items) + itemCount * SCRIPT_ITEM.sizeof, SCRIPT_ITEM.sizeof);
2341 item.analysis = scriptItem.a; 2332 item.analysis = scriptItem.a;
2342 Trace.formatln( "{} {}: count={}", __FILE__,__LINE__,count );
2343 runs[count++] = item; 2333 runs[count++] = item;
2344 if (runs.length !is count) { 2334 if (runs.length !is count) {
2345 StyleItem[] result = new StyleItem[count]; 2335 StyleItem[] result = new StyleItem[count];
2346 System.arraycopy(runs, 0, result, 0, count); 2336 System.arraycopy(runs, 0, result, 0, count);
2347 return result; 2337 return result;
2752 styles = new StyleItem[2]; 2742 styles = new StyleItem[2];
2753 styles[0] = new StyleItem(); 2743 styles[0] = new StyleItem();
2754 styles[1] = new StyleItem(); 2744 styles[1] = new StyleItem();
2755 styles[1].start = text.length; 2745 styles[1].start = text.length;
2756 stylesCount = 2; 2746 stylesCount = 2;
2757 Trace.formatln( "{} {}: text='{}'", __FILE__,__LINE__, text );
2758 } 2747 }
2759 2748
2760 /** 2749 /**
2761 * Sets the line width of the receiver, which determines how 2750 * Sets the line width of the receiver, which determines how
2762 * text should be wrapped and aligned. The default value is 2751 * text should be wrapped and aligned. The default value is