Mercurial > projects > dwt-win
annotate dwt/graphics/TextLayout.d @ 249:b3dbd786541a
Fix: compile errors
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 06 Jul 2008 17:23:35 +0200 |
parents | fd9c62a2998e |
children | 3f53ebb05b5b |
rev | line source |
---|---|
29 | 1 /******************************************************************************* |
246 | 2 * Copyright (c) 2000, 2008 IBM Corporation and others. |
29 | 3 * All rights reserved. This program and the accompanying materials |
4 * are made available under the terms of the Eclipse Public License v1.0 | |
5 * which accompanies this distribution, and is available at | |
6 * http://www.eclipse.org/legal/epl-v10.html | |
7 * | |
8 * Contributors: | |
9 * IBM Corporation - initial API and implementation | |
31
92c102dd64a3
Added all widgets modules as dummy. Most modules of accessible are equal to the linux version, except Accessible.
Frank Benoit <benoit@tionex.de>
parents:
30
diff
changeset
|
10 * Port to the D programming language: |
92c102dd64a3
Added all widgets modules as dummy. Most modules of accessible are equal to the linux version, except Accessible.
Frank Benoit <benoit@tionex.de>
parents:
30
diff
changeset
|
11 * Frank Benoit <benoit@tionex.de> |
29 | 12 *******************************************************************************/ |
13 module dwt.graphics.TextLayout; | |
14 | |
15 import dwt.DWT; | |
16 import dwt.DWTException; | |
17 import dwt.internal.Compatibility; | |
18 import dwt.internal.gdip.Gdip; | |
213 | 19 |
29 | 20 import dwt.internal.win32.OS; |
21 | |
22 import dwt.graphics.Color; | |
23 import dwt.graphics.Device; | |
24 import dwt.graphics.Font; | |
25 import dwt.graphics.FontMetrics; | |
26 import dwt.graphics.GC; | |
27 import dwt.graphics.GCData; | |
28 import dwt.graphics.GlyphMetrics; | |
29 import dwt.graphics.Point; | |
30 import dwt.graphics.Rectangle; | |
31 import dwt.graphics.Region; | |
32 import dwt.graphics.Resource; | |
33 import dwt.graphics.TextStyle; | |
34 | |
35 import tango.text.convert.Format; | |
36 import dwt.dwthelper.utils; | |
30 | 37 import dwt.dwthelper.System; |
29 | 38 |
227 | 39 |
29 | 40 /** |
41 * <code>TextLayout</code> is a graphic object that represents | |
42 * styled text. | |
43 * <p> | |
44 * Instances of this class provide support for drawing, cursor | |
45 * navigation, hit testing, text wrapping, alignment, tab expansion | |
46 * line breaking, etc. These are aspects required for rendering internationalized text. | |
47 * </p><p> | |
48 * Application code must explicitly invoke the <code>TextLayout#dispose()</code> | |
49 * method to release the operating system resources managed by each instance | |
50 * when those instances are no longer required. | |
51 * </p> | |
52 * | |
246 | 53 * @see <a href="http://www.eclipse.org/swt/snippets/#textlayout">TextLayout, TextStyle snippets</a> |
54 * @see <a href="http://www.eclipse.org/swt/examples.php">DWT Example: CustomControlExample, StyledText tab</a> | |
55 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> | |
56 * | |
57 * @since 3.0 | |
29 | 58 */ |
59 public final class TextLayout : Resource { | |
227 | 60 |
213 | 61 alias Resource.init_ init_; |
62 | |
227 | 63 /++ |
229 | 64 + DWT doku |
65 + The styles has at minimum 2 member, each with a start. The last element is the end marker. | |
66 + | |
67 + invariant{ | |
68 + assert( stylesCount >= 2 ); | |
69 + assert( stylesCount <= styles.length ); | |
70 + assert( styles[stylesCount-1] ); | |
71 + assert( styles[stylesCount-1].start is text.length ); | |
72 + } | |
73 +/ | |
227 | 74 |
75 | |
29 | 76 Font font; |
212
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
157
diff
changeset
|
77 String text, segmentsText; |
29 | 78 int lineSpacing; |
79 int ascent, descent; | |
80 int alignment; | |
81 int wrapWidth; | |
82 int orientation; | |
83 int indent; | |
84 bool justify; | |
85 int[] tabs; | |
86 int[] segments; | |
87 StyleItem[] styles; | |
213 | 88 int stylesCount; |
29 | 89 |
90 StyleItem[] allRuns; | |
91 StyleItem[][] runs; | |
92 int[] lineOffset, lineY, lineWidth; | |
30 | 93 void* mLangFontLink2; |
29 | 94 |
95 static const wchar LTR_MARK = '\u200E', RTL_MARK = '\u200F'; | |
96 static const int SCRIPT_VISATTR_SIZEOF = 2; | |
97 static const int GOFFSET_SIZEOF = 8; | |
80 | 98 private static byte[16] CLSID_CMultiLanguage; |
99 private static byte[16] IID_IMLangFontLink2; | |
100 private static bool static_this_completed = false; | |
101 private static void static_this() { | |
102 // in case of allready initialized, we can check and leave without lock | |
103 if( static_this_completed ){ | |
104 return; | |
105 } | |
106 synchronized { | |
107 if( !static_this_completed ){ | |
108 OS.IIDFromString("{275c23e2-3747-11d0-9fea-00aa003f8646}\0".toCharArray().ptr, CLSID_CMultiLanguage.ptr); | |
109 OS.IIDFromString("{DCCFC162-2B38-11d2-B7EC-00C04F8F5D9A}\0".toCharArray().ptr, IID_IMLangFontLink2.ptr); | |
110 static_this_completed = true; | |
111 } | |
112 } | |
29 | 113 } |
114 | |
213 | 115 /* IME has a copy of these constants */ |
116 static const int UNDERLINE_IME_DOT = 1 << 16; | |
117 static const int UNDERLINE_IME_DASH = 2 << 16; | |
118 static const int UNDERLINE_IME_THICK = 3 << 16; | |
119 | |
29 | 120 class StyleItem { |
121 TextStyle style; | |
122 int start, length; | |
123 bool lineBreak, softBreak, tab; | |
124 | |
125 /*Script cache and analysis */ | |
126 SCRIPT_ANALYSIS analysis; | |
127 SCRIPT_CACHE* psc; | |
128 | |
129 /*Shape info (malloc when the run is shaped) */ | |
130 WORD* glyphs; | |
131 int glyphCount; | |
132 WORD* clusters; | |
133 SCRIPT_VISATTR* visAttrs; | |
134 | |
135 /*Place info (malloc when the run is placed) */ | |
136 int* advances; | |
30 | 137 GOFFSET* goffsets; |
138 int width; | |
139 int ascent; | |
140 int descent; | |
141 int leading; | |
142 int x; | |
213 | 143 int underlinePos, underlineThickness; |
144 int strikeoutPos, strikeoutThickness; | |
29 | 145 |
146 /* Justify info (malloc during computeRuns) */ | |
147 int* justify; | |
148 | |
149 /* ScriptBreak */ | |
150 SCRIPT_LOGATTR* psla; | |
151 | |
30 | 152 HFONT fallbackFont; |
29 | 153 |
154 void free() { | |
155 auto hHeap = OS.GetProcessHeap(); | |
156 if (psc !is null) { | |
157 OS.ScriptFreeCache (psc); | |
158 OS.HeapFree(hHeap, 0, psc); | |
159 psc = null; | |
160 } | |
161 if (glyphs !is null) { | |
162 OS.HeapFree(hHeap, 0, glyphs); | |
163 glyphs = null; | |
164 glyphCount = 0; | |
165 } | |
166 if (clusters !is null) { | |
167 OS.HeapFree(hHeap, 0, clusters); | |
168 clusters = null; | |
169 } | |
170 if (visAttrs !is null) { | |
171 OS.HeapFree(hHeap, 0, visAttrs); | |
172 visAttrs = null; | |
173 } | |
174 if (advances !is null) { | |
175 OS.HeapFree(hHeap, 0, advances); | |
176 advances = null; | |
177 } | |
178 if (goffsets !is null) { | |
179 OS.HeapFree(hHeap, 0, goffsets); | |
180 goffsets = null; | |
181 } | |
182 if (justify !is null) { | |
183 OS.HeapFree(hHeap, 0, justify); | |
184 justify = null; | |
185 } | |
186 if (psla !is null) { | |
187 OS.HeapFree(hHeap, 0, psla); | |
188 psla = null; | |
189 } | |
190 if (fallbackFont !is null) { | |
246 | 191 OS.DeleteObject(fallbackFont); |
29 | 192 fallbackFont = null; |
193 } | |
30 | 194 width = 0; |
195 ascent = 0; | |
196 descent = 0; | |
197 x = 0; | |
29 | 198 lineBreak = softBreak = false; |
199 } | |
212
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
157
diff
changeset
|
200 override public String toString () { |
29 | 201 return Format( "StyleItem {{{}, {}}", start, style ); |
202 } | |
203 } | |
204 | |
205 /** | |
206 * Constructs a new instance of this class on the given device. | |
207 * <p> | |
208 * You must dispose the text layout when it is no longer required. | |
209 * </p> | |
210 * | |
211 * @param device the device on which to allocate the text layout | |
212 * | |
213 * @exception IllegalArgumentException <ul> | |
214 * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li> | |
215 * </ul> | |
216 * | |
217 * @see #dispose() | |
218 */ | |
219 public this (Device device) { | |
80 | 220 static_this(); |
213 | 221 super(device); |
29 | 222 wrapWidth = ascent = descent = -1; |
223 lineSpacing = 0; | |
224 orientation = DWT.LEFT_TO_RIGHT; | |
225 styles = new StyleItem[2]; | |
226 styles[0] = new StyleItem(); | |
227 styles[1] = new StyleItem(); | |
213 | 228 stylesCount = 2; |
29 | 229 text = ""; //$NON-NLS-1$ |
30 | 230 void* ppv; |
231 OS.OleInitialize(null); | |
232 if (OS.CoCreateInstance(CLSID_CMultiLanguage.ptr, null, OS.CLSCTX_INPROC_SERVER, IID_IMLangFontLink2.ptr, cast(void*)&ppv) is OS.S_OK) { | |
233 mLangFontLink2 = ppv; | |
29 | 234 } |
213 | 235 init_(); |
29 | 236 } |
237 | |
238 void breakRun(StyleItem run) { | |
30 | 239 if (run.psla !is null) return; |
59 | 240 wchar[] chars = StrToWCHARs( 0, segmentsText[ run.start .. run.start + run.length ] ); |
30 | 241 auto hHeap = OS.GetProcessHeap(); |
242 run.psla = cast(SCRIPT_LOGATTR*)OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, SCRIPT_LOGATTR.sizeof * chars.length); | |
243 if (run.psla is null) DWT.error(DWT.ERROR_NO_HANDLES); | |
244 OS.ScriptBreak(chars.ptr, chars.length, &run.analysis, run.psla); | |
29 | 245 } |
246 | |
247 void checkLayout () { | |
248 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); | |
249 } | |
250 | |
251 /* | |
252 * Compute the runs: itemize, shape, place, and reorder the runs. | |
253 * Break paragraphs into lines, wraps the text, and initialize caches. | |
254 */ | |
255 void computeRuns (GC gc) { | |
256 if (runs !is null) return; | |
30 | 257 auto hDC = gc !is null ? gc.handle : device.internal_new_GC(null); |
258 auto srcHdc = OS.CreateCompatibleDC(hDC); | |
29 | 259 allRuns = itemize(); |
260 for (int i=0; i<allRuns.length - 1; i++) { | |
261 StyleItem run = allRuns[i]; | |
262 OS.SelectObject(srcHdc, getItemFont(run)); | |
263 shape(srcHdc, run); | |
264 } | |
30 | 265 SCRIPT_LOGATTR* logAttr; |
266 SCRIPT_PROPERTIES* properties; | |
29 | 267 int lineWidth = indent, lineStart = 0, lineCount = 1; |
268 for (int i=0; i<allRuns.length - 1; i++) { | |
269 StyleItem run = allRuns[i]; | |
270 if (run.length is 1) { | |
271 char ch = segmentsText.charAt(run.start); | |
272 switch (ch) { | |
273 case '\t': { | |
274 run.tab = true; | |
275 if (tabs is null) break; | |
276 int tabsLength = tabs.length, j; | |
277 for (j = 0; j < tabsLength; j++) { | |
278 if (tabs[j] > lineWidth) { | |
279 run.width = tabs[j] - lineWidth; | |
280 break; | |
281 } | |
282 } | |
283 if (j is tabsLength) { | |
284 int tabX = tabs[tabsLength-1]; | |
285 int lastTabWidth = tabsLength > 1 ? tabs[tabsLength-1] - tabs[tabsLength-2] : tabs[0]; | |
286 if (lastTabWidth > 0) { | |
287 while (tabX <= lineWidth) tabX += lastTabWidth; | |
288 run.width = tabX - lineWidth; | |
289 } | |
290 } | |
291 break; | |
292 } | |
293 case '\n': { | |
294 run.lineBreak = true; | |
295 break; | |
296 } | |
297 case '\r': { | |
298 run.lineBreak = true; | |
299 StyleItem next = allRuns[i + 1]; | |
300 if (next.length !is 0 && segmentsText.charAt(next.start) is '\n') { | |
301 run.length += 1; | |
302 next.free(); | |
246 | 303 StyleItem[] newAllRuns = new StyleItem[allRuns.length - 1]; |
304 System.arraycopy(allRuns, 0, newAllRuns, 0, i + 1); | |
305 System.arraycopy(allRuns, i + 2, newAllRuns, i + 1, allRuns.length - i - 2); | |
306 allRuns = newAllRuns; | |
29 | 307 } |
308 break; | |
309 } | |
81 | 310 default: |
29 | 311 } |
312 } | |
313 if (wrapWidth !is -1 && lineWidth + run.width > wrapWidth && !run.tab) { | |
314 int start = 0; | |
315 int[] piDx = new int[run.length]; | |
316 if (run.style !is null && run.style.metrics !is null) { | |
317 piDx[0] = run.width; | |
318 } else { | |
30 | 319 OS.ScriptGetLogicalWidths(&run.analysis, run.length, run.glyphCount, run.advances, run.clusters, run.visAttrs, piDx.ptr); |
29 | 320 } |
321 int width = 0, maxWidth = wrapWidth - lineWidth; | |
322 while (width + piDx[start] < maxWidth) { | |
323 width += piDx[start++]; | |
324 } | |
325 int firstStart = start; | |
326 int firstIndice = i; | |
327 while (i >= lineStart) { | |
328 breakRun(run); | |
329 while (start >= 0) { | |
30 | 330 logAttr = run.psla + start; |
331 //OS.MoveMemory(logAttr, run.psla + (start * SCRIPT_LOGATTR.sizeof), SCRIPT_LOGATTR.sizeof); | |
29 | 332 if (logAttr.fSoftBreak || logAttr.fWhiteSpace) break; |
333 start--; | |
334 } | |
335 | |
336 /* | |
337 * Bug in Windows. For some reason Uniscribe sets the fSoftBreak flag for the first letter | |
338 * after a letter with an accent. This cause a break line to be set in the middle of a word. | |
339 * The fix is to detect the case and ignore fSoftBreak forcing the algorithm keep searching. | |
340 */ | |
341 if (start is 0 && i !is lineStart && !run.tab) { | |
342 if (logAttr.fSoftBreak && !logAttr.fWhiteSpace) { | |
30 | 343 properties = device.scripts[run.analysis.eScript]; |
344 //OS.MoveMemory(properties, device.scripts[run.analysis.eScript], SCRIPT_PROPERTIES.sizeof); | |
29 | 345 int langID = properties.langid; |
346 StyleItem pRun = allRuns[i - 1]; | |
30 | 347 //OS.MoveMemory(properties, device.scripts[pRun.analysis.eScript], SCRIPT_PROPERTIES.sizeof); |
29 | 348 if (properties.langid is langID || langID is OS.LANG_NEUTRAL || properties.langid is OS.LANG_NEUTRAL) { |
349 breakRun(pRun); | |
30 | 350 logAttr = pRun.psla + (pRun.length - 1); |
351 //OS.MoveMemory(logAttr, pRun.psla + ((pRun.length - 1) * SCRIPT_LOGATTR.sizeof), SCRIPT_LOGATTR.sizeof); | |
29 | 352 if (!logAttr.fWhiteSpace) start = -1; |
353 } | |
354 } | |
355 } | |
356 if (start >= 0 || i is lineStart) break; | |
357 run = allRuns[--i]; | |
358 start = run.length - 1; | |
359 } | |
360 if (start is 0 && i !is lineStart && !run.tab) { | |
361 run = allRuns[--i]; | |
362 } else if (start <= 0 && i is lineStart) { | |
213 | 363 if (lineWidth is wrapWidth && firstIndice > 0) { |
364 i = firstIndice - 1; | |
365 run = allRuns[i]; | |
366 start = run.length; | |
367 } else { | |
368 i = firstIndice; | |
369 run = allRuns[i]; | |
370 start = Math.max(1, firstStart); | |
371 } | |
29 | 372 } |
373 breakRun(run); | |
374 while (start < run.length) { | |
30 | 375 logAttr = run.psla + start; |
376 //OS.MoveMemory(logAttr, run.psla + (start * SCRIPT_LOGATTR.sizeof), SCRIPT_LOGATTR.sizeof); | |
29 | 377 if (!logAttr.fWhiteSpace) break; |
378 start++; | |
379 } | |
380 if (0 < start && start < run.length) { | |
381 StyleItem newRun = new StyleItem(); | |
382 newRun.start = run.start + start; | |
383 newRun.length = run.length - start; | |
384 newRun.style = run.style; | |
246 | 385 newRun.analysis = cloneScriptAnalysis(run.analysis); |
29 | 386 run.free(); |
387 run.length = start; | |
388 OS.SelectObject(srcHdc, getItemFont(run)); | |
246 | 389 run.analysis.fNoGlyphIndex = false; |
29 | 390 shape (srcHdc, run); |
391 OS.SelectObject(srcHdc, getItemFont(newRun)); | |
246 | 392 newRun.analysis.fNoGlyphIndex = false; |
29 | 393 shape (srcHdc, newRun); |
394 StyleItem[] newAllRuns = new StyleItem[allRuns.length + 1]; | |
395 System.arraycopy(allRuns, 0, newAllRuns, 0, i + 1); | |
396 System.arraycopy(allRuns, i + 1, newAllRuns, i + 2, allRuns.length - i - 1); | |
397 allRuns = newAllRuns; | |
398 allRuns[i + 1] = newRun; | |
399 } | |
400 if (i !is allRuns.length - 2) { | |
401 run.softBreak = run.lineBreak = true; | |
402 } | |
403 } | |
404 lineWidth += run.width; | |
405 if (run.lineBreak) { | |
406 lineStart = i + 1; | |
407 lineWidth = run.softBreak ? 0 : indent; | |
408 lineCount++; | |
409 } | |
410 } | |
411 lineWidth = 0; | |
30 | 412 runs = new StyleItem[][](lineCount); |
29 | 413 lineOffset = new int[lineCount + 1]; |
414 lineY = new int[lineCount + 1]; | |
415 this.lineWidth = new int[lineCount]; | |
416 int lineRunCount = 0, line = 0; | |
417 int ascent = Math.max(0, this.ascent); | |
418 int descent = Math.max(0, this.descent); | |
419 StyleItem[] lineRuns = new StyleItem[allRuns.length]; | |
420 for (int i=0; i<allRuns.length; i++) { | |
421 StyleItem run = allRuns[i]; | |
422 lineRuns[lineRunCount++] = run; | |
423 lineWidth += run.width; | |
424 ascent = Math.max(ascent, run.ascent); | |
425 descent = Math.max(descent, run.descent); | |
426 if (run.lineBreak || i is allRuns.length - 1) { | |
427 /* Update the run metrics if the last run is a hard break. */ | |
428 if (lineRunCount is 1 && i is allRuns.length - 1) { | |
429 TEXTMETRIC lptm; | |
430 OS.SelectObject(srcHdc, getItemFont(run)); | |
431 OS.GetTextMetrics(srcHdc, &lptm); | |
432 run.ascent = lptm.tmAscent; | |
433 run.descent = lptm.tmDescent; | |
434 ascent = Math.max(ascent, run.ascent); | |
435 descent = Math.max(descent, run.descent); | |
436 } | |
437 runs[line] = new StyleItem[lineRunCount]; | |
438 System.arraycopy(lineRuns, 0, runs[line], 0, lineRunCount); | |
439 | |
440 if (justify && wrapWidth !is -1 && run.softBreak && lineWidth > 0) { | |
441 if (line is 0) { | |
442 lineWidth += indent; | |
443 } else { | |
444 StyleItem[] previousLine = runs[line - 1]; | |
445 StyleItem previousRun = previousLine[previousLine.length - 1]; | |
446 if (previousRun.lineBreak && !previousRun.softBreak) { | |
447 lineWidth += indent; | |
448 } | |
449 } | |
30 | 450 auto hHeap = OS.GetProcessHeap(); |
29 | 451 int newLineWidth = 0; |
452 for (int j = 0; j < runs[line].length; j++) { | |
453 StyleItem item = runs[line][j]; | |
454 int iDx = item.width * wrapWidth / lineWidth; | |
455 if (iDx !is item.width) { | |
30 | 456 item.justify = cast(int*)OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, item.glyphCount * 4); |
457 if (item.justify is null) DWT.error(DWT.ERROR_NO_HANDLES); | |
29 | 458 OS.ScriptJustify(item.visAttrs, item.advances, item.glyphCount, iDx - item.width, 2, item.justify); |
459 item.width = iDx; | |
460 } | |
461 newLineWidth += item.width; | |
462 } | |
463 lineWidth = newLineWidth; | |
464 } | |
465 this.lineWidth[line] = lineWidth; | |
466 | |
467 StyleItem lastRun = runs[line][lineRunCount - 1]; | |
468 int lastOffset = lastRun.start + lastRun.length; | |
469 runs[line] = reorder(runs[line], i is allRuns.length - 1); | |
470 lastRun = runs[line][lineRunCount - 1]; | |
471 if (run.softBreak && run !is lastRun) { | |
472 run.softBreak = run.lineBreak = false; | |
473 lastRun.softBreak = lastRun.lineBreak = true; | |
474 } | |
475 | |
476 lineWidth = getLineIndent(line); | |
477 for (int j = 0; j < runs[line].length; j++) { | |
478 runs[line][j].x = lineWidth; | |
479 lineWidth += runs[line][j].width; | |
480 } | |
481 line++; | |
482 lineY[line] = lineY[line - 1] + ascent + descent + lineSpacing; | |
483 lineOffset[line] = lastOffset; | |
484 lineRunCount = lineWidth = 0; | |
485 ascent = Math.max(0, this.ascent); | |
486 descent = Math.max(0, this.descent); | |
487 } | |
488 } | |
30 | 489 if (srcHdc !is null) OS.DeleteDC(srcHdc); |
29 | 490 if (gc is null) device.internal_dispose_GC(hDC, null); |
491 } | |
492 | |
213 | 493 void destroy () { |
29 | 494 freeRuns(); |
495 font = null; | |
496 text = null; | |
497 segmentsText = null; | |
498 tabs = null; | |
499 styles = null; | |
500 runs = null; | |
501 lineOffset = null; | |
502 lineY = null; | |
503 lineWidth = null; | |
30 | 504 if (mLangFontLink2 !is null) { |
29 | 505 /* Release() */ |
506 OS.VtblCall(2, mLangFontLink2); | |
30 | 507 mLangFontLink2 = null; |
29 | 508 } |
509 OS.OleUninitialize(); | |
510 } | |
511 | |
249 | 512 SCRIPT_ANALYSIS cloneScriptAnalysis ( inout SCRIPT_ANALYSIS src) { |
513 SCRIPT_ANALYSIS dst; | |
246 | 514 dst.eScript = src.eScript; |
515 dst.fRTL = src.fRTL; | |
516 dst.fLayoutRTL = src.fLayoutRTL; | |
517 dst.fLinkBefore = src.fLinkBefore; | |
518 dst.fLinkAfter = src.fLinkAfter; | |
519 dst.fLogicalOrder = src.fLogicalOrder; | |
520 dst.fNoGlyphIndex = src.fNoGlyphIndex; | |
521 dst.s.uBidiLevel = src.s.uBidiLevel; | |
522 dst.s.fOverrideDirection = src.s.fOverrideDirection; | |
523 dst.s.fInhibitSymSwap = src.s.fInhibitSymSwap; | |
524 dst.s.fCharShape = src.s.fCharShape; | |
525 dst.s.fDigitSubstitute = src.s.fDigitSubstitute; | |
526 dst.s.fInhibitLigate = src.s.fInhibitLigate; | |
527 dst.s.fDisplayZWG = src.s.fDisplayZWG; | |
528 dst.s.fArabicNumContext = src.s.fArabicNumContext; | |
529 dst.s.fGcpClusters = src.s.fGcpClusters; | |
530 dst.s.fReserved = src.s.fReserved; | |
531 dst.s.fEngineReserved = src.s.fEngineReserved; | |
532 return dst; | |
533 } | |
534 | |
29 | 535 /** |
536 * Draws the receiver's text using the specified GC at the specified | |
537 * point. | |
538 * | |
539 * @param gc the GC to draw | |
540 * @param x the x coordinate of the top left corner of the rectangular area where the text is to be drawn | |
541 * @param y the y coordinate of the top left corner of the rectangular area where the text is to be drawn | |
542 * | |
543 * @exception DWTException <ul> | |
544 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
545 * </ul> | |
546 * @exception IllegalArgumentException <ul> | |
547 * <li>ERROR_NULL_ARGUMENT - if the gc is null</li> | |
548 * </ul> | |
549 */ | |
550 public void draw (GC gc, int x, int y) { | |
551 draw(gc, x, y, -1, -1, null, null); | |
552 } | |
553 | |
554 /** | |
555 * Draws the receiver's text using the specified GC at the specified | |
556 * point. | |
557 * | |
558 * @param gc the GC to draw | |
559 * @param x the x coordinate of the top left corner of the rectangular area where the text is to be drawn | |
560 * @param y the y coordinate of the top left corner of the rectangular area where the text is to be drawn | |
561 * @param selectionStart the offset where the selections starts, or -1 indicating no selection | |
562 * @param selectionEnd the offset where the selections ends, or -1 indicating no selection | |
563 * @param selectionForeground selection foreground, or NULL to use the system default color | |
564 * @param selectionBackground selection background, or NULL to use the system default color | |
565 * | |
566 * @exception DWTException <ul> | |
567 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
568 * </ul> | |
569 * @exception IllegalArgumentException <ul> | |
570 * <li>ERROR_NULL_ARGUMENT - if the gc is null</li> | |
571 * </ul> | |
572 */ | |
573 public void draw (GC gc, int x, int y, int selectionStart, int selectionEnd, Color selectionForeground, Color selectionBackground) { | |
574 draw(gc, x, y, selectionStart, selectionEnd, selectionForeground, selectionBackground, 0); | |
575 } | |
576 | |
577 /** | |
578 * Draws the receiver's text using the specified GC at the specified | |
579 * point. | |
580 * <p> | |
581 * The parameter <code>flags</code> can include one of <code>DWT.DELIMITER_SELECTION</code> | |
582 * or <code>DWT.FULL_SELECTION</code> to specify the selection behavior on all lines except | |
583 * for the last line, and can also include <code>DWT.LAST_LINE_SELECTION</code> to extend | |
584 * the specified selection behavior to the last line. | |
585 * </p> | |
586 * @param gc the GC to draw | |
587 * @param x the x coordinate of the top left corner of the rectangular area where the text is to be drawn | |
588 * @param y the y coordinate of the top left corner of the rectangular area where the text is to be drawn | |
589 * @param selectionStart the offset where the selections starts, or -1 indicating no selection | |
590 * @param selectionEnd the offset where the selections ends, or -1 indicating no selection | |
591 * @param selectionForeground selection foreground, or NULL to use the system default color | |
592 * @param selectionBackground selection background, or NULL to use the system default color | |
593 * @param flags drawing options | |
594 * | |
595 * @exception DWTException <ul> | |
596 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
597 * </ul> | |
598 * @exception IllegalArgumentException <ul> | |
599 * <li>ERROR_NULL_ARGUMENT - if the gc is null</li> | |
600 * </ul> | |
601 * | |
602 * @since 3.3 | |
603 */ | |
604 public void draw (GC gc, int x, int y, int selectionStart, int selectionEnd, Color selectionForeground, Color selectionBackground, int flags) { | |
605 checkLayout(); | |
606 computeRuns(gc); | |
607 if (gc is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); | |
608 if (gc.isDisposed()) DWT.error(DWT.ERROR_INVALID_ARGUMENT); | |
609 if (selectionForeground !is null && selectionForeground.isDisposed()) DWT.error(DWT.ERROR_INVALID_ARGUMENT); | |
610 if (selectionBackground !is null && selectionBackground.isDisposed()) DWT.error(DWT.ERROR_INVALID_ARGUMENT); | |
30 | 611 int length = text.length; |
29 | 612 if (length is 0 && flags is 0) return; |
30 | 613 auto hdc = gc.handle; |
29 | 614 Rectangle clip = gc.getClipping(); |
615 GCData data = gc.data; | |
30 | 616 auto gdipGraphics = data.gdipGraphics; |
617 auto foreground = data.foreground; | |
618 auto alpha = data.alpha; | |
619 bool gdip = gdipGraphics !is null && (alpha !is 0xFF || data.foregroundPattern !is null); | |
620 HRGN clipRgn; | |
29 | 621 float[] lpXform = null; |
30 | 622 Gdip.Rect gdipRect; |
623 if (gdipGraphics !is null && !gdip) { | |
624 auto matrix = Gdip.Matrix_new(1, 0, 0, 1, 0, 0); | |
625 if (matrix is null) DWT.error(DWT.ERROR_NO_HANDLES); | |
29 | 626 Gdip.Graphics_GetTransform(gdipGraphics, matrix); |
30 | 627 auto identity_ = gc.identity(); |
628 Gdip.Matrix_Invert(identity_); | |
629 Gdip.Matrix_Multiply(matrix, identity_, Gdip.MatrixOrderAppend); | |
630 Gdip.Matrix_delete(identity_); | |
29 | 631 if (!Gdip.Matrix_IsIdentity(matrix)) { |
632 lpXform = new float[6]; | |
213 | 633 Gdip.Matrix_GetElements(matrix, lpXform.ptr); |
29 | 634 } |
635 Gdip.Matrix_delete(matrix); | |
636 if ((data.style & DWT.MIRRORED) !is 0 && lpXform !is null) { | |
637 gdip = true; | |
638 lpXform = null; | |
639 } else { | |
640 Gdip.Graphics_SetPixelOffsetMode(gdipGraphics, Gdip.PixelOffsetModeNone); | |
30 | 641 auto rgn = Gdip.Region_new(); |
29 | 642 Gdip.Graphics_GetClip(gdipGraphics, rgn); |
643 if (!Gdip.Region_IsInfinite(rgn, gdipGraphics)) { | |
644 clipRgn = Gdip.Region_GetHRGN(rgn, gdipGraphics); | |
645 } | |
646 Gdip.Region_delete(rgn); | |
647 Gdip.Graphics_SetPixelOffsetMode(gdipGraphics, Gdip.PixelOffsetModeHalf); | |
648 hdc = Gdip.Graphics_GetHDC(gdipGraphics); | |
649 } | |
650 } | |
53
0405e18fec7f
Gdiplus implemented - test build of dwt.lib successful; updated graphics package as necessary
John Reimer <terminal.node@gmail.com
parents:
48
diff
changeset
|
651 Gdip.Brush foregroundBrush; |
30 | 652 int state = 0; |
29 | 653 if (gdip) { |
654 gc.checkGC(GC.FOREGROUND); | |
655 foregroundBrush = gc.getFgBrush(); | |
656 } else { | |
657 state = OS.SaveDC(hdc); | |
658 if ((data.style & DWT.MIRRORED) !is 0) { | |
659 OS.SetLayout(hdc, OS.GetLayout(hdc) | OS.LAYOUT_RTL); | |
660 } | |
661 if (lpXform !is null) { | |
662 OS.SetGraphicsMode(hdc, OS.GM_ADVANCED); | |
30 | 663 OS.SetWorldTransform(hdc, cast(XFORM*)lpXform.ptr); |
29 | 664 } |
30 | 665 if (clipRgn !is null) { |
29 | 666 OS.SelectClipRgn(hdc, clipRgn); |
667 OS.DeleteObject(clipRgn); | |
668 } | |
669 } | |
670 bool hasSelection = selectionStart <= selectionEnd && selectionStart !is -1 && selectionEnd !is -1; | |
671 if (hasSelection || (flags & DWT.LAST_LINE_SELECTION) !is 0) { | |
672 selectionStart = Math.min(Math.max(0, selectionStart), length - 1); | |
673 selectionEnd = Math.min(Math.max(0, selectionEnd), length - 1); | |
674 if (selectionForeground is null) selectionForeground = device.getSystemColor(DWT.COLOR_LIST_SELECTION_TEXT); | |
675 if (selectionBackground is null) selectionBackground = device.getSystemColor(DWT.COLOR_LIST_SELECTION); | |
676 selectionStart = translateOffset(selectionStart); | |
677 selectionEnd = translateOffset(selectionEnd); | |
678 } | |
30 | 679 RECT rect; |
213 | 680 Gdip.Brush selBrush; |
681 Gdip.Pen selPen; | |
682 Gdip.Brush selBrushFg; | |
30 | 683 |
29 | 684 if (hasSelection || (flags & DWT.LAST_LINE_SELECTION) !is 0) { |
685 if (gdip) { | |
30 | 686 auto bg = selectionBackground.handle; |
687 auto argb = ((alpha & 0xFF) << 24) | ((bg >> 16) & 0xFF) | (bg & 0xFF00) | ((bg & 0xFF) << 16); | |
688 auto color = Gdip.Color_new(argb); | |
213 | 689 selBrush = cast(Gdip.Brush)Gdip.SolidBrush_new(color); |
29 | 690 Gdip.Color_delete(color); |
30 | 691 auto fg = selectionForeground.handle; |
29 | 692 argb = ((alpha & 0xFF) << 24) | ((fg >> 16) & 0xFF) | (fg & 0xFF00) | ((fg & 0xFF) << 16); |
693 color = Gdip.Color_new(argb); | |
213 | 694 selBrushFg = cast(Gdip.Brush)Gdip.SolidBrush_new(color); |
695 selPen = cast(Gdip.Pen) Gdip.Pen_new( cast(Gdip.Brush)selBrushFg, 1); | |
29 | 696 Gdip.Color_delete(color); |
697 } else { | |
213 | 698 selBrush = cast(Gdip.Brush)OS.CreateSolidBrush(selectionBackground.handle); |
699 selPen = cast(Gdip.Pen)OS.CreatePen(OS.PS_SOLID, 1, selectionForeground.handle); | |
29 | 700 } |
701 } | |
702 int offset = (orientation & DWT.RIGHT_TO_LEFT) !is 0 ? -1 : 0; | |
703 OS.SetBkMode(hdc, OS.TRANSPARENT); | |
704 for (int line=0; line<runs.length; line++) { | |
705 int drawX = x + getLineIndent(line); | |
706 int drawY = y + lineY[line]; | |
707 StyleItem[] lineRuns = runs[line]; | |
213 | 708 int lineHeight = lineY[line+1] - lineY[line] - lineSpacing; |
29 | 709 if (flags !is 0 && (hasSelection || (flags & DWT.LAST_LINE_SELECTION) !is 0)) { |
710 bool extents = false; | |
711 if (line is runs.length - 1 && (flags & DWT.LAST_LINE_SELECTION) !is 0) { | |
712 extents = true; | |
713 } else { | |
714 StyleItem run = lineRuns[lineRuns.length - 1]; | |
715 if (run.lineBreak && !run.softBreak) { | |
716 if (selectionStart <= run.start && run.start <= selectionEnd) extents = true; | |
717 } else { | |
718 int endOffset = run.start + run.length - 1; | |
719 if (selectionStart <= endOffset && endOffset < selectionEnd && (flags & DWT.FULL_SELECTION) !is 0) { | |
720 extents = true; | |
721 } | |
722 } | |
723 } | |
724 if (extents) { | |
725 int width; | |
726 if ((flags & DWT.FULL_SELECTION) !is 0) { | |
727 width = OS.IsWin95 ? 0x7FFF : 0x6FFFFFF; | |
728 } else { | |
213 | 729 width = lineHeight / 3; |
29 | 730 } |
731 if (gdip) { | |
213 | 732 Gdip.Graphics_FillRectangle(gdipGraphics, cast(Gdip.Brush)selBrush, drawX + lineWidth[line], drawY, width, lineHeight); |
29 | 733 } else { |
734 OS.SelectObject(hdc, selBrush); | |
213 | 735 OS.PatBlt(hdc, drawX + lineWidth[line], drawY, width, lineHeight, OS.PATCOPY); |
29 | 736 } |
737 } | |
738 } | |
739 if (drawX > clip.x + clip.width) continue; | |
740 if (drawX + lineWidth[line] < clip.x) continue; | |
741 int baseline = Math.max(0, this.ascent); | |
213 | 742 int lineUnderlinePos = 0; |
29 | 743 for (int i = 0; i < lineRuns.length; i++) { |
744 baseline = Math.max(baseline, lineRuns[i].ascent); | |
213 | 745 lineUnderlinePos = Math.min(lineUnderlinePos, lineRuns[i].underlinePos); |
29 | 746 } |
747 int alignmentX = drawX; | |
748 for (int i = 0; i < lineRuns.length; i++) { | |
749 StyleItem run = lineRuns[i]; | |
750 if (run.length is 0) continue; | |
751 if (drawX > clip.x + clip.width) break; | |
752 if (drawX + run.width >= clip.x) { | |
753 if (!run.lineBreak || run.softBreak) { | |
754 int end = run.start + run.length - 1; | |
755 bool fullSelection = hasSelection && selectionStart <= run.start && selectionEnd >= end; | |
756 if (fullSelection) { | |
757 if (gdip) { | |
213 | 758 Gdip.Graphics_FillRectangle(gdipGraphics, cast(Gdip.Brush)selBrush, drawX, drawY, run.width, lineHeight); |
29 | 759 } else { |
760 OS.SelectObject(hdc, selBrush); | |
213 | 761 OS.PatBlt(hdc, drawX, drawY, run.width, lineHeight, OS.PATCOPY); |
29 | 762 } |
763 } else { | |
764 if (run.style !is null && run.style.background !is null) { | |
30 | 765 auto bg = run.style.background.handle; |
29 | 766 if (gdip) { |
767 int argb = ((alpha & 0xFF) << 24) | ((bg >> 16) & 0xFF) | (bg & 0xFF00) | ((bg & 0xFF) << 16); | |
30 | 768 auto color = Gdip.Color_new(argb); |
769 auto brush = Gdip.SolidBrush_new(color); | |
213 | 770 Gdip.Graphics_FillRectangle(gdipGraphics, cast(Gdip.Brush)brush, drawX, drawY, run.width, lineHeight); |
29 | 771 Gdip.Color_delete(color); |
772 Gdip.SolidBrush_delete(brush); | |
773 } else { | |
30 | 774 auto hBrush = OS.CreateSolidBrush (bg); |
775 auto oldBrush = OS.SelectObject(hdc, hBrush); | |
213 | 776 OS.PatBlt(hdc, drawX, drawY, run.width, lineHeight, OS.PATCOPY); |
29 | 777 OS.SelectObject(hdc, oldBrush); |
778 OS.DeleteObject(hBrush); | |
779 } | |
780 } | |
781 bool partialSelection = hasSelection && !(selectionStart > end || run.start > selectionEnd); | |
782 if (partialSelection) { | |
783 int selStart = Math.max(selectionStart, run.start) - run.start; | |
784 int selEnd = Math.min(selectionEnd, end) - run.start; | |
785 int cChars = run.length; | |
786 int gGlyphs = run.glyphCount; | |
30 | 787 int piX; |
788 int* advances = run.justify !is null ? run.justify : run.advances; | |
789 OS.ScriptCPtoX(selStart, false, cChars, gGlyphs, run.clusters, run.visAttrs, advances, &run.analysis, &piX); | |
790 int runX = (orientation & DWT.RIGHT_TO_LEFT) !is 0 ? run.width - piX : piX; | |
29 | 791 rect.left = drawX + runX; |
792 rect.top = drawY; | |
30 | 793 OS.ScriptCPtoX(selEnd, true, cChars, gGlyphs, run.clusters, run.visAttrs, advances, &run.analysis, &piX); |
794 runX = (orientation & DWT.RIGHT_TO_LEFT) !is 0 ? run.width - piX : piX; | |
29 | 795 rect.right = drawX + runX; |
213 | 796 rect.bottom = drawY + lineHeight; |
29 | 797 if (gdip) { |
213 | 798 if (rect.left > rect.right) { |
799 int tmp = rect.left; | |
800 rect.left = rect.right; | |
801 rect.right = tmp; | |
802 } | |
53
0405e18fec7f
Gdiplus implemented - test build of dwt.lib successful; updated graphics package as necessary
John Reimer <terminal.node@gmail.com
parents:
48
diff
changeset
|
803 Gdip.Graphics_FillRectangle(gdipGraphics, cast(Gdip.Brush)selBrush, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top); |
29 | 804 } else { |
805 OS.SelectObject(hdc, selBrush); | |
806 OS.PatBlt(hdc, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, OS.PATCOPY); | |
807 } | |
808 } | |
809 } | |
810 } | |
811 } | |
812 drawX += run.width; | |
813 } | |
213 | 814 RECT* borderClip = null; |
29 | 815 drawX = alignmentX; |
816 for (int i = 0; i < lineRuns.length; i++) { | |
817 StyleItem run = lineRuns[i]; | |
818 if (run.length is 0) continue; | |
819 if (drawX > clip.x + clip.width) break; | |
820 if (drawX + run.width >= clip.x) { | |
821 if (!run.tab && (!run.lineBreak || run.softBreak) && !(run.style !is null && run.style.metrics !is null)) { | |
822 int end = run.start + run.length - 1; | |
823 bool fullSelection = hasSelection && selectionStart <= run.start && selectionEnd >= end; | |
824 bool partialSelection = hasSelection && !fullSelection && !(selectionStart > end || run.start > selectionEnd); | |
825 OS.SelectObject(hdc, getItemFont(run)); | |
826 int drawRunY = drawY + (baseline - run.ascent); | |
827 if (partialSelection) { | |
828 int selStart = Math.max(selectionStart, run.start) - run.start; | |
829 int selEnd = Math.min(selectionEnd, end) - run.start; | |
830 int cChars = run.length; | |
831 int gGlyphs = run.glyphCount; | |
30 | 832 int piX; |
833 int* advances = run.justify !is null ? run.justify : run.advances; | |
834 OS.ScriptCPtoX(selStart, false, cChars, gGlyphs, run.clusters, run.visAttrs, advances, &run.analysis, &piX); | |
835 int runX = (orientation & DWT.RIGHT_TO_LEFT) !is 0 ? run.width - piX : piX; | |
29 | 836 rect.left = drawX + runX; |
837 rect.top = drawY; | |
30 | 838 OS.ScriptCPtoX(selEnd, true, cChars, gGlyphs, run.clusters, run.visAttrs, advances, &run.analysis, &piX); |
839 runX = (orientation & DWT.RIGHT_TO_LEFT) !is 0 ? run.width - piX : piX; | |
29 | 840 rect.right = drawX + runX; |
841 rect.bottom = drawY + lineHeight; | |
842 } | |
843 if (gdip) { | |
844 OS.BeginPath(hdc); | |
30 | 845 OS.ScriptTextOut(hdc, run.psc, drawX, drawRunY, 0, null, &run.analysis , null, 0, run.glyphs, run.glyphCount, run.advances, run.justify, run.goffsets); |
29 | 846 OS.EndPath(hdc); |
847 int count = OS.GetPath(hdc, null, null, 0); | |
848 int[] points = new int[count*2]; | |
30 | 849 ubyte[] types = new ubyte[count]; |
850 OS.GetPath(hdc, cast(POINT*)points.ptr, types.ptr, count); | |
29 | 851 for (int typeIndex = 0; typeIndex < types.length; typeIndex++) { |
852 int newType = 0; | |
853 int type = types[typeIndex] & 0xFF; | |
854 switch (type & ~OS.PT_CLOSEFIGURE) { | |
855 case OS.PT_MOVETO: newType = Gdip.PathPointTypeStart; break; | |
856 case OS.PT_LINETO: newType = Gdip.PathPointTypeLine; break; | |
857 case OS.PT_BEZIERTO: newType = Gdip.PathPointTypeBezier; break; | |
81 | 858 default: |
29 | 859 } |
860 if ((type & OS.PT_CLOSEFIGURE) !is 0) newType |= Gdip.PathPointTypeCloseSubpath; | |
861 types[typeIndex] = cast(byte)newType; | |
862 } | |
213 | 863 auto path = Gdip.GraphicsPath_new(cast(Gdip.Point*)points.ptr, types.ptr, count, Gdip.FillModeAlternate); |
30 | 864 if (path is null) DWT.error(DWT.ERROR_NO_HANDLES); |
865 auto brush = foregroundBrush; | |
29 | 866 if (fullSelection) { |
53
0405e18fec7f
Gdiplus implemented - test build of dwt.lib successful; updated graphics package as necessary
John Reimer <terminal.node@gmail.com
parents:
48
diff
changeset
|
867 brush = cast(Gdip.Brush)selBrushFg; |
29 | 868 } else { |
869 if (run.style !is null && run.style.foreground !is null) { | |
30 | 870 auto fg = run.style.foreground.handle; |
29 | 871 int argb = ((alpha & 0xFF) << 24) | ((fg >> 16) & 0xFF) | (fg & 0xFF00) | ((fg & 0xFF) << 16); |
30 | 872 auto color = Gdip.Color_new(argb); |
53
0405e18fec7f
Gdiplus implemented - test build of dwt.lib successful; updated graphics package as necessary
John Reimer <terminal.node@gmail.com
parents:
48
diff
changeset
|
873 brush = cast(Gdip.Brush)Gdip.SolidBrush_new(color); |
29 | 874 Gdip.Color_delete(color); |
875 } | |
876 } | |
877 int gstate = 0; | |
878 if (partialSelection) { | |
879 gdipRect.X = rect.left; | |
880 gdipRect.Y = rect.top; | |
881 gdipRect.Width = rect.right - rect.left; | |
882 gdipRect.Height = rect.bottom - rect.top; | |
883 gstate = Gdip.Graphics_Save(gdipGraphics); | |
30 | 884 Gdip.Graphics_SetClip(gdipGraphics, &gdipRect, Gdip.CombineModeExclude); |
29 | 885 } |
886 int antialias = Gdip.Graphics_GetSmoothingMode(gdipGraphics), textAntialias = 0; | |
887 int mode = Gdip.Graphics_GetTextRenderingHint(data.gdipGraphics); | |
888 switch (mode) { | |
889 case Gdip.TextRenderingHintSystemDefault: textAntialias = Gdip.SmoothingModeAntiAlias; break; | |
890 case Gdip.TextRenderingHintSingleBitPerPixel: | |
891 case Gdip.TextRenderingHintSingleBitPerPixelGridFit: textAntialias = Gdip.SmoothingModeNone; break; | |
892 case Gdip.TextRenderingHintAntiAlias: | |
893 case Gdip.TextRenderingHintAntiAliasGridFit: | |
894 case Gdip.TextRenderingHintClearTypeGridFit: textAntialias = Gdip.SmoothingModeAntiAlias; break; | |
81 | 895 default: |
29 | 896 } |
897 Gdip.Graphics_SetSmoothingMode(gdipGraphics, textAntialias); | |
898 int gstate2 = 0; | |
899 if ((data.style & DWT.MIRRORED) !is 0) { | |
900 gstate2 = Gdip.Graphics_Save(gdipGraphics); | |
901 Gdip.Graphics_ScaleTransform(gdipGraphics, -1, 1, Gdip.MatrixOrderPrepend); | |
902 Gdip.Graphics_TranslateTransform(gdipGraphics, -2 * drawX - run.width, 0, Gdip.MatrixOrderPrepend); | |
903 } | |
904 Gdip.Graphics_FillPath(gdipGraphics, brush, path); | |
905 if ((data.style & DWT.MIRRORED) !is 0) { | |
906 Gdip.Graphics_Restore(gdipGraphics, gstate2); | |
907 } | |
908 Gdip.Graphics_SetSmoothingMode(gdipGraphics, antialias); | |
213 | 909 drawLines(gdip, gdipGraphics, x, drawY + baseline, lineUnderlinePos, drawY + lineHeight, lineRuns, i, brush, null, alpha); |
29 | 910 if (partialSelection) { |
911 Gdip.Graphics_Restore(gdipGraphics, gstate); | |
912 gstate = Gdip.Graphics_Save(gdipGraphics); | |
30 | 913 Gdip.Graphics_SetClip(gdipGraphics, &gdipRect, Gdip.CombineModeIntersect); |
29 | 914 Gdip.Graphics_SetSmoothingMode(gdipGraphics, textAntialias); |
213 | 915 if ((data.style & DWT.MIRRORED) !is 0) { |
916 gstate2 = Gdip.Graphics_Save(gdipGraphics); | |
917 Gdip.Graphics_ScaleTransform(gdipGraphics, -1, 1, Gdip.MatrixOrderPrepend); | |
918 Gdip.Graphics_TranslateTransform(gdipGraphics, -2 * drawX - run.width, 0, Gdip.MatrixOrderPrepend); | |
919 } | |
920 Gdip.Graphics_FillPath(gdipGraphics, selBrushFg, path); | |
921 if ((data.style & DWT.MIRRORED) !is 0) { | |
922 Gdip.Graphics_Restore(gdipGraphics, gstate2); | |
923 } | |
29 | 924 Gdip.Graphics_SetSmoothingMode(gdipGraphics, antialias); |
213 | 925 drawLines(gdip, gdipGraphics, x, drawY + baseline, lineUnderlinePos, drawY + lineHeight, lineRuns, i, selBrushFg, &rect, alpha); |
29 | 926 Gdip.Graphics_Restore(gdipGraphics, gstate); |
927 } | |
213 | 928 borderClip = drawBorder(gdip, gdipGraphics, x, drawY, lineHeight, foregroundBrush, selBrushFg, fullSelection, borderClip, partialSelection ? &rect : null, alpha, lineRuns, i, selectionStart, selectionEnd); |
29 | 929 Gdip.GraphicsPath_delete(path); |
53
0405e18fec7f
Gdiplus implemented - test build of dwt.lib successful; updated graphics package as necessary
John Reimer <terminal.node@gmail.com
parents:
48
diff
changeset
|
930 if ( brush !is cast(Gdip.Brush)selBrushFg && brush !is cast(Gdip.Brush)foregroundBrush) |
0405e18fec7f
Gdiplus implemented - test build of dwt.lib successful; updated graphics package as necessary
John Reimer <terminal.node@gmail.com
parents:
48
diff
changeset
|
931 Gdip.SolidBrush_delete(cast(Gdip.SolidBrush)brush); |
0405e18fec7f
Gdiplus implemented - test build of dwt.lib successful; updated graphics package as necessary
John Reimer <terminal.node@gmail.com
parents:
48
diff
changeset
|
932 } else { |
213 | 933 auto fg = foreground; |
53
0405e18fec7f
Gdiplus implemented - test build of dwt.lib successful; updated graphics package as necessary
John Reimer <terminal.node@gmail.com
parents:
48
diff
changeset
|
934 if (fullSelection) { |
0405e18fec7f
Gdiplus implemented - test build of dwt.lib successful; updated graphics package as necessary
John Reimer <terminal.node@gmail.com
parents:
48
diff
changeset
|
935 fg = selectionForeground.handle; |
0405e18fec7f
Gdiplus implemented - test build of dwt.lib successful; updated graphics package as necessary
John Reimer <terminal.node@gmail.com
parents:
48
diff
changeset
|
936 } else { |
0405e18fec7f
Gdiplus implemented - test build of dwt.lib successful; updated graphics package as necessary
John Reimer <terminal.node@gmail.com
parents:
48
diff
changeset
|
937 if (run.style !is null && run.style.foreground !is null) fg = run.style.foreground.handle; |
29 | 938 } |
939 OS.SetTextColor(hdc, fg); | |
30 | 940 OS.ScriptTextOut(hdc, run.psc, drawX + offset, drawRunY, 0, null, &run.analysis , null, 0, run.glyphs, run.glyphCount, run.advances, run.justify, run.goffsets); |
213 | 941 drawLines(gdip, hdc, x, drawY + baseline, lineUnderlinePos, drawY + lineHeight, lineRuns, i, cast(void*)fg, null, alpha); |
29 | 942 if (partialSelection && fg !is selectionForeground.handle) { |
943 OS.SetTextColor(hdc, selectionForeground.handle); | |
30 | 944 OS.ScriptTextOut(hdc, run.psc, drawX + offset, drawRunY, OS.ETO_CLIPPED, &rect, &run.analysis , null, 0, run.glyphs, run.glyphCount, run.advances, run.justify, run.goffsets); |
213 | 945 drawLines(gdip, hdc, x, drawY + baseline, lineUnderlinePos, drawY + lineHeight, lineRuns, i, cast(void*)selectionForeground.handle, &rect, alpha); |
29 | 946 } |
213 | 947 int selForeground = selectionForeground !is null ? selectionForeground.handle : 0; |
948 borderClip = drawBorder(gdip, hdc, x, drawY, lineHeight, cast(void*)foreground, cast(void*)selForeground, fullSelection, borderClip, partialSelection ? &rect : null, alpha, lineRuns, i, selectionStart, selectionEnd); | |
29 | 949 } |
950 } | |
951 } | |
952 drawX += run.width; | |
953 } | |
954 } | |
955 if (gdip) { | |
53
0405e18fec7f
Gdiplus implemented - test build of dwt.lib successful; updated graphics package as necessary
John Reimer <terminal.node@gmail.com
parents:
48
diff
changeset
|
956 if (selBrush !is null) Gdip.SolidBrush_delete(cast(Gdip.SolidBrush)selBrush); |
0405e18fec7f
Gdiplus implemented - test build of dwt.lib successful; updated graphics package as necessary
John Reimer <terminal.node@gmail.com
parents:
48
diff
changeset
|
957 if (selBrushFg !is null) Gdip.SolidBrush_delete(cast(Gdip.SolidBrush)selBrushFg); |
213 | 958 if (selPen !is null) Gdip.Pen_delete(selPen); |
29 | 959 } else { |
960 OS.RestoreDC(hdc, state); | |
30 | 961 if (gdipGraphics !is null) Gdip.Graphics_ReleaseHDC(gdipGraphics, hdc); |
962 if (selBrush !is null) OS.DeleteObject (selBrush); | |
963 if (selPen !is null) OS.DeleteObject (selPen); | |
29 | 964 } |
965 } | |
966 | |
213 | 967 void drawLines(bool advance, void* graphics, int x, int lineBaseline, int lineUnderlinePos, int lineBottom, StyleItem[] line, int index, void* color, RECT* clipRect, int alpha) { |
968 StyleItem run = line[index]; | |
969 TextStyle style = run.style; | |
970 if (style is null) return; | |
971 if (!style.underline && !style.strikeout) return; | |
972 int runX = x + run.x; | |
973 int underlineY = lineBaseline - lineUnderlinePos; | |
974 int strikeoutY = lineBaseline - run.strikeoutPos; | |
975 if (advance) { | |
976 Gdip.Graphics_SetPixelOffsetMode(cast(Gdip.Graphics)graphics, Gdip.PixelOffsetModeNone); | |
977 auto brush = color; | |
978 if (style.underline) { | |
979 if (style.underlineColor !is null) { | |
980 int fg = style.underlineColor.handle; | |
981 int argb = ((alpha & 0xFF) << 24) | ((fg >> 16) & 0xFF) | (fg & 0xFF00) | ((fg & 0xFF) << 16); | |
982 auto gdiColor = Gdip.Color_new(argb); | |
983 brush = Gdip.SolidBrush_new(gdiColor); | |
984 Gdip.Color_delete(gdiColor); | |
985 } | |
986 switch (style.underlineStyle) { | |
987 case DWT.UNDERLINE_SQUIGGLE: | |
988 case DWT.UNDERLINE_ERROR: { | |
989 int squigglyThickness = 1; | |
990 int squigglyHeight = 2 * squigglyThickness; | |
991 int squigglyY = Math.min(underlineY - squigglyHeight / 2, lineBottom - squigglyHeight - 1); | |
992 int squigglyX = runX; | |
993 for (int i = index; i > 0 && style.isAdherentUnderline(line[i - 1].style); i--) { | |
994 squigglyX = x + line[i - 1].x; | |
995 } | |
996 int gstate = 0; | |
997 if (clipRect is null) { | |
998 gstate = Gdip.Graphics_Save(cast(Gdip.Graphics)graphics); | |
999 Gdip.Rect gdipRect; | |
1000 gdipRect.X = runX; | |
1001 gdipRect.Y = squigglyY; | |
1002 gdipRect.Width = run.width + 1; | |
1003 gdipRect.Height = squigglyY + squigglyHeight + 1; | |
1004 Gdip.Graphics_SetClip(cast(Gdip.Graphics)graphics, &gdipRect, Gdip.CombineModeIntersect); | |
1005 } | |
1006 int[] points = computePolyline(squigglyX, squigglyY, runX + run.width, squigglyY + squigglyHeight); | |
1007 auto pen = Gdip.Pen_new(cast(Gdip.Brush)brush, squigglyThickness); | |
1008 Gdip.Graphics_DrawLines(cast(Gdip.Graphics)graphics, pen, cast(Gdip.Point*)points.ptr, points.length / 2); | |
1009 Gdip.Pen_delete(pen); | |
1010 if (gstate !is 0) Gdip.Graphics_Restore(cast(Gdip.Graphics)graphics, gstate); | |
1011 break; | |
1012 } | |
1013 case DWT.UNDERLINE_SINGLE: | |
1014 Gdip.Graphics_FillRectangle(cast(Gdip.Graphics)graphics, cast(Gdip.Brush)brush, runX, underlineY, run.width, run.underlineThickness); | |
1015 break; | |
1016 case DWT.UNDERLINE_DOUBLE: | |
1017 Gdip.Graphics_FillRectangle(cast(Gdip.Graphics)graphics, cast(Gdip.Brush)brush, runX, underlineY, run.width, run.underlineThickness); | |
1018 Gdip.Graphics_FillRectangle(cast(Gdip.Graphics)graphics, cast(Gdip.Brush)brush, runX, underlineY + run.underlineThickness * 2, run.width, run.underlineThickness); | |
1019 break; | |
1020 case UNDERLINE_IME_THICK: | |
1021 Gdip.Graphics_FillRectangle(cast(Gdip.Graphics)graphics, cast(Gdip.Brush)brush, runX - run.underlineThickness, underlineY, run.width, run.underlineThickness * 2); | |
1022 break; | |
1023 case UNDERLINE_IME_DOT: | |
1024 case UNDERLINE_IME_DASH: { | |
1025 auto pen = Gdip.Pen_new(cast(Gdip.Brush)brush, 1); | |
1026 int dashStyle = style.underlineStyle is UNDERLINE_IME_DOT ? Gdip.DashStyleDot : Gdip.DashStyleDash; | |
1027 Gdip.Pen_SetDashStyle(pen, dashStyle); | |
1028 Gdip.Graphics_DrawLine(cast(Gdip.Graphics)graphics, pen, runX, underlineY, runX + run.width, underlineY); | |
1029 Gdip.Pen_delete(pen); | |
1030 break; | |
1031 } | |
214
a8fed3e56433
Fix link error and added missing switch defaults
Frank Benoit <benoit@tionex.de>
parents:
213
diff
changeset
|
1032 default: |
213 | 1033 } |
1034 if (brush !is color) Gdip.SolidBrush_delete(cast(Gdip.SolidBrush)brush); | |
1035 } | |
1036 if (style.strikeout) { | |
1037 if (style.strikeoutColor !is null) { | |
1038 int fg = style.strikeoutColor.handle; | |
1039 int argb = ((alpha & 0xFF) << 24) | ((fg >> 16) & 0xFF) | (fg & 0xFF00) | ((fg & 0xFF) << 16); | |
1040 auto gdiColor = Gdip.Color_new(argb); | |
1041 brush = Gdip.SolidBrush_new(gdiColor); | |
1042 Gdip.Color_delete(gdiColor); | |
1043 } | |
1044 Gdip.Graphics_FillRectangle(cast(Gdip.Graphics)graphics, cast(Gdip.Brush)brush, runX, strikeoutY, run.width, run.strikeoutThickness); | |
1045 if (brush !is color) Gdip.SolidBrush_delete(cast(Gdip.SolidBrush)brush); | |
1046 } | |
1047 Gdip.Graphics_SetPixelOffsetMode(cast(Gdip.Graphics)graphics, Gdip.PixelOffsetModeHalf); | |
1048 } else { | |
1049 uint colorRefUnderline = cast(uint)color; | |
1050 uint colorRefStrikeout = cast(uint)color; | |
1051 int /*long*/ brushUnderline = 0; | |
1052 int /*long*/ brushStrikeout = 0; | |
1053 RECT rect; | |
1054 if (style.underline) { | |
1055 if (style.underlineColor !is null) { | |
1056 colorRefUnderline = style.underlineColor.handle; | |
1057 } | |
1058 switch (style.underlineStyle) { | |
1059 case DWT.UNDERLINE_SQUIGGLE: | |
1060 case DWT.UNDERLINE_ERROR: { | |
1061 int squigglyThickness = 1; | |
1062 int squigglyHeight = 2 * squigglyThickness; | |
1063 int squigglyY = Math.min(underlineY - squigglyHeight / 2, lineBottom - squigglyHeight - 1); | |
1064 int squigglyX = runX; | |
1065 for (int i = index; i > 0 && style.isAdherentUnderline(line[i - 1].style); i--) { | |
1066 squigglyX = x + line[i - 1].x; | |
1067 } | |
1068 int state = OS.SaveDC(graphics); | |
1069 if (clipRect !is null) { | |
1070 OS.IntersectClipRect(graphics, clipRect.left, clipRect.top, clipRect.right, clipRect.bottom); | |
1071 } else { | |
1072 OS.IntersectClipRect(graphics, runX, squigglyY, runX + run.width + 1, squigglyY + squigglyHeight + 1); | |
1073 } | |
1074 int[] points = computePolyline(squigglyX, squigglyY, runX + run.width, squigglyY + squigglyHeight); | |
1075 auto pen = OS.CreatePen(OS.PS_SOLID, squigglyThickness, colorRefUnderline); | |
1076 auto oldPen = OS.SelectObject(graphics, pen); | |
1077 OS.Polyline(graphics, cast(POINT*)points.ptr, points.length / 2); | |
1078 int length_ = points.length; | |
1079 if (length_ >= 2 && squigglyThickness <= 1) { | |
1080 OS.SetPixel (graphics, points[length_ - 2], points[length_ - 1], colorRefUnderline); | |
1081 } | |
1082 OS.RestoreDC(graphics, state); | |
1083 OS.SelectObject(graphics, oldPen); | |
1084 OS.DeleteObject(pen); | |
1085 break; | |
1086 } | |
1087 case DWT.UNDERLINE_SINGLE: | |
1088 brushUnderline = cast(uint) OS.CreateSolidBrush(colorRefUnderline); | |
1089 OS.SetRect(&rect, runX, underlineY, runX + run.width, underlineY + run.underlineThickness); | |
1090 if (clipRect !is null) { | |
1091 rect.left = Math.max(rect.left, clipRect.left); | |
1092 rect.right = Math.min(rect.right, clipRect.right); | |
1093 } | |
1094 OS.FillRect(graphics, &rect, cast(void*)brushUnderline); | |
1095 break; | |
1096 case DWT.UNDERLINE_DOUBLE: | |
1097 brushUnderline = cast(uint)OS.CreateSolidBrush(colorRefUnderline); | |
1098 OS.SetRect(&rect, runX, underlineY, runX + run.width, underlineY + run.underlineThickness); | |
1099 if (clipRect !is null) { | |
1100 rect.left = Math.max(rect.left, clipRect.left); | |
1101 rect.right = Math.min(rect.right, clipRect.right); | |
1102 } | |
1103 OS.FillRect(graphics, &rect, cast(void*)brushUnderline); | |
1104 OS.SetRect(&rect, runX, underlineY + run.underlineThickness * 2, runX + run.width, underlineY + run.underlineThickness * 3); | |
1105 if (clipRect !is null) { | |
1106 rect.left = Math.max(rect.left, clipRect.left); | |
1107 rect.right = Math.min(rect.right, clipRect.right); | |
1108 } | |
1109 OS.FillRect(graphics, &rect, cast(void*)brushUnderline); | |
1110 break; | |
1111 case UNDERLINE_IME_THICK: | |
1112 brushUnderline = cast(uint)OS.CreateSolidBrush(colorRefUnderline); | |
1113 OS.SetRect(&rect, runX, underlineY - run.underlineThickness, runX + run.width, underlineY + run.underlineThickness); | |
1114 if (clipRect !is null) { | |
1115 rect.left = Math.max(rect.left, clipRect.left); | |
1116 rect.right = Math.min(rect.right, clipRect.right); | |
1117 } | |
1118 OS.FillRect(graphics, &rect, cast(void*)brushUnderline); | |
1119 break; | |
1120 case UNDERLINE_IME_DASH: | |
1121 case UNDERLINE_IME_DOT: { | |
1122 underlineY = lineBaseline + run.descent; | |
1123 int penStyle = style.underlineStyle is UNDERLINE_IME_DASH ? OS.PS_DASH : OS.PS_DOT; | |
1124 auto pen = OS.CreatePen(penStyle, 1, colorRefUnderline); | |
1125 auto oldPen = OS.SelectObject(graphics, pen); | |
1126 OS.SetRect(&rect, runX, underlineY, runX + run.width, underlineY + run.underlineThickness); | |
1127 if (clipRect !is null) { | |
1128 rect.left = Math.max(rect.left, clipRect.left); | |
1129 rect.right = Math.min(rect.right, clipRect.right); | |
1130 } | |
1131 OS.MoveToEx(graphics, rect.left, rect.top, null); | |
1132 OS.LineTo(graphics, rect.right, rect.top); | |
1133 OS.SelectObject(graphics, oldPen); | |
1134 OS.DeleteObject(pen); | |
1135 break; | |
1136 } | |
214
a8fed3e56433
Fix link error and added missing switch defaults
Frank Benoit <benoit@tionex.de>
parents:
213
diff
changeset
|
1137 default: |
213 | 1138 } |
1139 } | |
1140 if (style.strikeout) { | |
1141 if (style.strikeoutColor !is null) { | |
1142 colorRefStrikeout = style.strikeoutColor.handle; | |
1143 } | |
1144 if (brushUnderline !is 0 && colorRefStrikeout is colorRefUnderline) { | |
1145 brushStrikeout = brushUnderline; | |
1146 } else { | |
1147 brushStrikeout = cast(int) OS.CreateSolidBrush(colorRefStrikeout); | |
1148 } | |
1149 OS.SetRect(&rect, runX, strikeoutY, runX + run.width, strikeoutY + run.strikeoutThickness); | |
1150 if (clipRect !is null) { | |
1151 rect.left = Math.max(rect.left, clipRect.left); | |
1152 rect.right = Math.min(rect.right, clipRect.right); | |
1153 } | |
1154 OS.FillRect(graphics, &rect, cast(void*)brushStrikeout); | |
1155 } | |
1156 if (brushUnderline !is 0) OS.DeleteObject(cast(void*)brushUnderline); | |
1157 if (brushStrikeout !is 0 && brushStrikeout !is brushUnderline) OS.DeleteObject(cast(void*)brushStrikeout); | |
1158 } | |
1159 } | |
1160 | |
1161 RECT* drawBorder(bool advance, void* graphics, int x, int y, int lineHeight, void* color, void* selectionColor, bool fullSelection, RECT* clipRect, RECT* rect, int alpha, StyleItem[] line, int index, int selectionStart, int selectionEnd) { | |
1162 StyleItem run = line[index]; | |
1163 TextStyle style = run.style; | |
1164 if (style is null) return null; | |
1165 if (style.borderStyle is DWT.NONE) return null; | |
1166 if (rect !is null) { | |
1167 if (clipRect is null) { | |
1168 clipRect = new RECT (); | |
1169 OS.SetRect(clipRect, -1, rect.top, -1, rect.bottom); | |
1170 } | |
1171 bool isRTL = (orientation & DWT.RIGHT_TO_LEFT) !is 0; | |
1172 if (run.start <= selectionStart && selectionStart <= run.start + run.length) { | |
1173 if (run.analysis.fRTL ^ isRTL) { | |
1174 clipRect.right = rect.left; | |
1175 } else { | |
1176 clipRect.left = rect.left; | |
1177 } | |
1178 } | |
1179 if (run.start <= selectionEnd && selectionEnd <= run.start + run.length) { | |
1180 if (run.analysis.fRTL ^ isRTL) { | |
1181 clipRect.left = rect.right; | |
1182 } else { | |
1183 clipRect.right = rect.right; | |
1184 } | |
1185 } | |
1186 } | |
1187 if (index + 1 >= line.length || !style.isAdherentBorder(line[index + 1].style)) { | |
1188 int left = run.x; | |
1189 for (int i = index; i > 0 && style.isAdherentBorder(line[i - 1].style); i--) { | |
1190 left = line[i - 1].x; | |
1191 } | |
1192 if (advance) { | |
1193 auto brush = color; | |
1194 int customColor = -1; | |
1195 if (style.borderColor !is null) { | |
1196 customColor = style.borderColor.handle; | |
1197 } else { | |
1198 if (style.foreground !is null) { | |
1199 customColor = style.foreground.handle; | |
1200 } | |
1201 if (fullSelection && clipRect is null) { | |
1202 customColor = -1; | |
1203 brush = selectionColor; | |
1204 } | |
1205 } | |
1206 if (customColor !is -1) { | |
1207 int argb = ((alpha & 0xFF) << 24) | ((customColor >> 16) & 0xFF) | (customColor & 0xFF00) | ((customColor & 0xFF) << 16); | |
1208 auto gdiColor = Gdip.Color_new(argb); | |
1209 brush = Gdip.SolidBrush_new(gdiColor); | |
1210 Gdip.Color_delete(gdiColor); | |
1211 } | |
1212 int lineWidth = 1; | |
1213 int lineStyle = Gdip.DashStyleSolid; | |
1214 switch (style.borderStyle) { | |
1215 case DWT.BORDER_SOLID: break; | |
1216 case DWT.BORDER_DASH: lineStyle = Gdip.DashStyleDash; break; | |
1217 case DWT.BORDER_DOT: lineStyle = Gdip.DashStyleDot; break; | |
214
a8fed3e56433
Fix link error and added missing switch defaults
Frank Benoit <benoit@tionex.de>
parents:
213
diff
changeset
|
1218 default: |
213 | 1219 } |
1220 auto pen = Gdip.Pen_new(cast(Gdip.Brush)brush, lineWidth); | |
1221 Gdip.Pen_SetDashStyle(pen, lineStyle); | |
1222 float gdipXOffset = 0.5f, gdipYOffset = 0.5f; | |
1223 Gdip.Graphics_TranslateTransform(cast(Gdip.Graphics)graphics, gdipXOffset, gdipYOffset, Gdip.MatrixOrderPrepend); | |
1224 if (style.borderColor is null && clipRect !is null) { | |
1225 int gstate = Gdip.Graphics_Save(cast(Gdip.Graphics)graphics); | |
1226 if (clipRect.left is -1) clipRect.left = 0; | |
1227 if (clipRect.right is -1) clipRect.right = 0x7ffff; | |
1228 Gdip.Rect gdipRect; | |
1229 gdipRect.X = clipRect.left; | |
1230 gdipRect.Y = clipRect.top; | |
1231 gdipRect.Width = clipRect.right - clipRect.left; | |
1232 gdipRect.Height = clipRect.bottom - clipRect.top; | |
1233 Gdip.Graphics_SetClip(cast(Gdip.Graphics)graphics, &gdipRect, Gdip.CombineModeExclude); | |
1234 Gdip.Graphics_DrawRectangle(cast(Gdip.Graphics)graphics, pen, x + left, y, run.x + run.width - left - 1, lineHeight - 1); | |
1235 Gdip.Graphics_Restore(cast(Gdip.Graphics)graphics, gstate); | |
1236 gstate = Gdip.Graphics_Save(cast(Gdip.Graphics)graphics); | |
1237 Gdip.Graphics_SetClip(cast(Gdip.Graphics)graphics, &gdipRect, Gdip.CombineModeIntersect); | |
1238 auto selPen = Gdip.Pen_new(cast(Gdip.Brush)selectionColor, lineWidth); | |
1239 Gdip.Pen_SetDashStyle(pen, lineStyle); | |
1240 Gdip.Graphics_DrawRectangle(cast(Gdip.Graphics)graphics, selPen, x + left, y, run.x + run.width - left - 1, lineHeight - 1); | |
1241 Gdip.Pen_delete(selPen); | |
1242 Gdip.Graphics_Restore(cast(Gdip.Graphics)graphics, gstate); | |
1243 } else { | |
1244 Gdip.Graphics_DrawRectangle(cast(Gdip.Graphics)graphics, pen, x + left, y, run.x + run.width - left - 1, lineHeight - 1); | |
1245 } | |
1246 Gdip.Graphics_TranslateTransform(cast(Gdip.Graphics)graphics, -gdipXOffset, -gdipYOffset, Gdip.MatrixOrderPrepend); | |
1247 Gdip.Pen_delete(pen); | |
1248 if (customColor !is -1) Gdip.SolidBrush_delete(cast(Gdip.SolidBrush)brush); | |
1249 } else { | |
1250 if (style.borderColor !is null) { | |
1251 color = cast(void*)style.borderColor.handle; | |
1252 } else { | |
1253 if (style.foreground !is null) { | |
1254 color = cast(void*)style.foreground.handle; | |
1255 } | |
1256 if (fullSelection && clipRect is null) { | |
1257 color = selectionColor; | |
1258 } | |
1259 } | |
1260 int lineWidth = 1; | |
1261 int lineStyle = OS.PS_SOLID; | |
1262 switch (style.borderStyle) { | |
1263 case DWT.BORDER_SOLID: break; | |
1264 case DWT.BORDER_DASH: lineStyle = OS.PS_DASH; break; | |
1265 case DWT.BORDER_DOT: lineStyle = OS.PS_DOT; break; | |
214
a8fed3e56433
Fix link error and added missing switch defaults
Frank Benoit <benoit@tionex.de>
parents:
213
diff
changeset
|
1266 default: |
213 | 1267 } |
1268 LOGBRUSH logBrush; | |
1269 logBrush.lbStyle = OS.BS_SOLID; | |
1270 logBrush.lbColor = cast(uint)color; | |
1271 auto newPen = OS.ExtCreatePen(lineStyle | OS.PS_GEOMETRIC, Math.max(1, lineWidth), &logBrush, 0, null); | |
1272 auto oldPen = OS.SelectObject(graphics, newPen); | |
1273 auto oldBrush = OS.SelectObject(graphics, OS.GetStockObject(OS.NULL_BRUSH)); | |
1274 OS.Rectangle(graphics, x + left, y, x + run.x + run.width, y + lineHeight); | |
1275 if (style.borderColor is null && clipRect !is null && color !is selectionColor) { | |
1276 int state = OS.SaveDC(graphics); | |
1277 if (clipRect.left is -1) clipRect.left = 0; | |
1278 if (clipRect.right is -1) clipRect.right = 0x7ffff; | |
1279 OS.IntersectClipRect(graphics, clipRect.left, clipRect.top, clipRect.right, clipRect.bottom); | |
1280 logBrush.lbColor = cast(uint)selectionColor; | |
1281 auto selPen = OS.ExtCreatePen (lineStyle | OS.PS_GEOMETRIC, Math.max(1, lineWidth), &logBrush, 0, null); | |
1282 OS.SelectObject(graphics, selPen); | |
1283 OS.Rectangle(graphics, x + left, y, x + run.x + run.width, y + lineHeight); | |
1284 OS.RestoreDC(graphics, state); | |
1285 OS.SelectObject(graphics, newPen); | |
1286 OS.DeleteObject(selPen); | |
1287 } | |
1288 OS.SelectObject(graphics, oldBrush); | |
1289 OS.SelectObject(graphics, oldPen); | |
1290 OS.DeleteObject(newPen); | |
1291 } | |
1292 return null; | |
1293 } | |
1294 return clipRect; | |
1295 } | |
1296 | |
1297 int[] computePolyline(int left, int top, int right, int bottom) { | |
1298 int height = bottom - top; // can be any number | |
1299 int width = 2 * height; // must be even | |
1300 int peaks = Compatibility.ceil(right - left, width); | |
1301 if (peaks is 0 && right - left > 2) { | |
1302 peaks = 1; | |
1303 } | |
1304 int length_ = ((2 * peaks) + 1) * 2; | |
1305 if (length_ < 0) return new int[0]; | |
1306 | |
1307 int[] coordinates = new int[length_]; | |
1308 for (int i = 0; i < peaks; i++) { | |
1309 int index = 4 * i; | |
1310 coordinates[index] = left + (width * i); | |
1311 coordinates[index+1] = bottom; | |
1312 coordinates[index+2] = coordinates[index] + width / 2; | |
1313 coordinates[index+3] = top; | |
1314 } | |
1315 coordinates[length_-2] = left + (width * peaks); | |
1316 coordinates[length_-1] = bottom; | |
1317 return coordinates; | |
1318 } | |
1319 | |
29 | 1320 void freeRuns () { |
1321 if (allRuns is null) return; | |
1322 for (int i=0; i<allRuns.length; i++) { | |
1323 StyleItem run = allRuns[i]; | |
1324 run.free(); | |
1325 } | |
1326 allRuns = null; | |
1327 runs = null; | |
1328 segmentsText = null; | |
1329 } | |
1330 | |
1331 /** | |
1332 * Returns the receiver's horizontal text alignment, which will be one | |
1333 * of <code>DWT.LEFT</code>, <code>DWT.CENTER</code> or | |
1334 * <code>DWT.RIGHT</code>. | |
1335 * | |
1336 * @return the alignment used to positioned text horizontally | |
1337 * | |
1338 * @exception DWTException <ul> | |
1339 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
1340 * </ul> | |
1341 */ | |
1342 public int getAlignment () { | |
1343 checkLayout(); | |
1344 return alignment; | |
1345 } | |
1346 | |
1347 /** | |
1348 * Returns the ascent of the receiver. | |
1349 * | |
1350 * @return the ascent | |
1351 * | |
1352 * @exception DWTException <ul> | |
1353 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
1354 * </ul> | |
1355 * | |
1356 * @see #getDescent() | |
1357 * @see #setDescent(int) | |
1358 * @see #setAscent(int) | |
1359 * @see #getLineMetrics(int) | |
1360 */ | |
1361 public int getAscent () { | |
1362 checkLayout(); | |
1363 return ascent; | |
1364 } | |
1365 | |
1366 /** | |
213 | 1367 * Returns the bounds of the receiver. The width returned is either the |
1368 * width of the longest line or the width set using {@link TextLayout#setWidth(int)}. | |
1369 * To obtain the text bounds of a line use {@link TextLayout#getLineBounds(int)}. | |
29 | 1370 * |
1371 * @return the bounds of the receiver | |
1372 * | |
1373 * @exception DWTException <ul> | |
1374 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
1375 * </ul> | |
213 | 1376 * |
1377 * @see #setWidth(int) | |
1378 * @see #getLineBounds(int) | |
29 | 1379 */ |
1380 public Rectangle getBounds () { | |
1381 checkLayout(); | |
1382 computeRuns(null); | |
1383 int width = 0; | |
1384 if (wrapWidth !is -1) { | |
1385 width = wrapWidth; | |
1386 } else { | |
1387 for (int line=0; line<runs.length; line++) { | |
1388 width = Math.max(width, lineWidth[line] + getLineIndent(line)); | |
1389 } | |
1390 } | |
1391 return new Rectangle (0, 0, width, lineY[lineY.length - 1]); | |
1392 } | |
1393 | |
1394 /** | |
1395 * Returns the bounds for the specified range of characters. The | |
1396 * bounds is the smallest rectangle that encompasses all characters | |
1397 * in the range. The start and end offsets are inclusive and will be | |
1398 * clamped if out of range. | |
1399 * | |
1400 * @param start the start offset | |
1401 * @param end the end offset | |
1402 * @return the bounds of the character range | |
1403 * | |
1404 * @exception DWTException <ul> | |
1405 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
1406 * </ul> | |
1407 */ | |
1408 public Rectangle getBounds (int start, int end) { | |
1409 checkLayout(); | |
1410 computeRuns(null); | |
227 | 1411 int length = text.length; |
1412 if (length is 0) return new Rectangle(0, 0, 0, 0); | |
29 | 1413 if (start > end) return new Rectangle(0, 0, 0, 0); |
227 | 1414 start = Math.min(Math.max(0, start), length - 1); |
1415 end = Math.min(Math.max(0, end), length - 1); | |
29 | 1416 start = translateOffset(start); |
1417 end = translateOffset(end); | |
1418 int left = 0x7fffffff, right = 0; | |
1419 int top = 0x7fffffff, bottom = 0; | |
1420 bool isRTL = (orientation & DWT.RIGHT_TO_LEFT) !is 0; | |
1421 for (int i = 0; i < allRuns.length - 1; i++) { | |
1422 StyleItem run = allRuns[i]; | |
1423 int runEnd = run.start + run.length; | |
1424 if (runEnd <= start) continue; | |
1425 if (run.start > end) break; | |
1426 int runLead = run.x; | |
1427 int runTrail = run.x + run.width; | |
1428 if (run.start <= start && start < runEnd) { | |
1429 int cx = 0; | |
1430 if (run.style !is null && run.style.metrics !is null) { | |
1431 GlyphMetrics metrics = run.style.metrics; | |
1432 cx = metrics.width * (start - run.start); | |
1433 } else if (!run.tab) { | |
30 | 1434 int piX; |
1435 int* advances = run.justify !is null ? run.justify : run.advances; | |
1436 OS.ScriptCPtoX(start - run.start, false, run.length, run.glyphCount, run.clusters, run.visAttrs, advances, &run.analysis, &piX); | |
1437 cx = isRTL ? run.width - piX : piX; | |
29 | 1438 } |
1439 if (run.analysis.fRTL ^ isRTL) { | |
1440 runTrail = run.x + cx; | |
1441 } else { | |
1442 runLead = run.x + cx; | |
1443 } | |
1444 } | |
1445 if (run.start <= end && end < runEnd) { | |
1446 int cx = run.width; | |
1447 if (run.style !is null && run.style.metrics !is null) { | |
1448 GlyphMetrics metrics = run.style.metrics; | |
1449 cx = metrics.width * (end - run.start + 1); | |
1450 } else if (!run.tab) { | |
30 | 1451 int piX; |
1452 int* advances = run.justify !is null ? run.justify : run.advances; | |
1453 OS.ScriptCPtoX(end - run.start, true, run.length, run.glyphCount, run.clusters, run.visAttrs, advances, &run.analysis, &piX); | |
1454 cx = isRTL ? run.width - piX : piX; | |
29 | 1455 } |
1456 if (run.analysis.fRTL ^ isRTL) { | |
1457 runLead = run.x + cx; | |
1458 } else { | |
1459 runTrail = run.x + cx; | |
1460 } | |
1461 } | |
1462 int lineIndex = 0; | |
1463 while (lineIndex < runs.length && lineOffset[lineIndex + 1] <= run.start) { | |
1464 lineIndex++; | |
1465 } | |
1466 left = Math.min(left, runLead); | |
1467 right = Math.max(right, runTrail); | |
1468 top = Math.min(top, lineY[lineIndex]); | |
1469 bottom = Math.max(bottom, lineY[lineIndex + 1] - lineSpacing); | |
1470 } | |
1471 return new Rectangle(left, top, right - left, bottom - top); | |
1472 } | |
1473 | |
1474 /** | |
1475 * Returns the descent of the receiver. | |
1476 * | |
1477 * @return the descent | |
1478 * | |
1479 * @exception DWTException <ul> | |
1480 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
1481 * </ul> | |
1482 * | |
1483 * @see #getAscent() | |
1484 * @see #setAscent(int) | |
1485 * @see #setDescent(int) | |
1486 * @see #getLineMetrics(int) | |
1487 */ | |
1488 public int getDescent () { | |
1489 checkLayout(); | |
1490 return descent; | |
1491 } | |
1492 | |
1493 /** | |
1494 * Returns the default font currently being used by the receiver | |
1495 * to draw and measure text. | |
1496 * | |
1497 * @return the receiver's font | |
1498 * | |
1499 * @exception DWTException <ul> | |
1500 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
1501 * </ul> | |
1502 */ | |
1503 public Font getFont () { | |
1504 checkLayout(); | |
1505 return font; | |
1506 } | |
1507 | |
1508 /** | |
1509 * Returns the receiver's indent. | |
1510 * | |
1511 * @return the receiver's indent | |
1512 * | |
1513 * @exception DWTException <ul> | |
1514 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
1515 * </ul> | |
1516 * | |
1517 * @since 3.2 | |
1518 */ | |
1519 public int getIndent () { | |
1520 checkLayout(); | |
1521 return indent; | |
1522 } | |
1523 | |
1524 /** | |
1525 * Returns the receiver's justification. | |
1526 * | |
1527 * @return the receiver's justification | |
1528 * | |
1529 * @exception DWTException <ul> | |
1530 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
1531 * </ul> | |
1532 * | |
1533 * @since 3.2 | |
1534 */ | |
1535 public bool getJustify () { | |
1536 checkLayout(); | |
1537 return justify; | |
1538 } | |
1539 | |
30 | 1540 HFONT getItemFont (StyleItem item) { |
1541 if (item.fallbackFont !is null) return cast(HFONT) item.fallbackFont; | |
29 | 1542 if (item.style !is null && item.style.font !is null) { |
1543 return item.style.font.handle; | |
1544 } | |
1545 if (this.font !is null) { | |
1546 return this.font.handle; | |
1547 } | |
213 | 1548 return device.systemFont.handle; |
29 | 1549 } |
1550 | |
1551 /** | |
1552 * Returns the embedding level for the specified character offset. The | |
1553 * embedding level is usually used to determine the directionality of a | |
1554 * character in bidirectional text. | |
1555 * | |
1556 * @param offset the character offset | |
1557 * @return the embedding level | |
1558 * | |
1559 * @exception IllegalArgumentException <ul> | |
1560 * <li>ERROR_INVALID_ARGUMENT - if the character offset is out of range</li> | |
1561 * </ul> | |
1562 * @exception DWTException <ul> | |
1563 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
1564 */ | |
1565 public int getLevel (int offset) { | |
1566 checkLayout(); | |
1567 computeRuns(null); | |
227 | 1568 int length = text.length; |
1569 if (!(0 <= offset && offset <= length)) DWT.error(DWT.ERROR_INVALID_RANGE); | |
29 | 1570 offset = translateOffset(offset); |
1571 for (int i=1; i<allRuns.length; i++) { | |
1572 if (allRuns[i].start > offset) { | |
1573 return allRuns[i - 1].analysis.s.uBidiLevel; | |
1574 } | |
1575 } | |
1576 return (orientation & DWT.RIGHT_TO_LEFT) !is 0 ? 1 : 0; | |
1577 } | |
1578 | |
1579 /** | |
1580 * Returns the bounds of the line for the specified line index. | |
1581 * | |
1582 * @param lineIndex the line index | |
1583 * @return the line bounds | |
1584 * | |
1585 * @exception IllegalArgumentException <ul> | |
1586 * <li>ERROR_INVALID_ARGUMENT - if the line index is out of range</li> | |
1587 * </ul> | |
1588 * @exception DWTException <ul> | |
1589 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
1590 * </ul> | |
1591 */ | |
1592 public Rectangle getLineBounds(int lineIndex) { | |
1593 checkLayout(); | |
1594 computeRuns(null); | |
1595 if (!(0 <= lineIndex && lineIndex < runs.length)) DWT.error(DWT.ERROR_INVALID_RANGE); | |
1596 int x = getLineIndent(lineIndex); | |
1597 int y = lineY[lineIndex]; | |
1598 int width = lineWidth[lineIndex]; | |
1599 int height = lineY[lineIndex + 1] - y - lineSpacing; | |
1600 return new Rectangle (x, y, width, height); | |
1601 } | |
1602 | |
1603 /** | |
1604 * Returns the receiver's line count. This includes lines caused | |
1605 * by wrapping. | |
1606 * | |
1607 * @return the line count | |
1608 * | |
1609 * @exception DWTException <ul> | |
1610 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
1611 * </ul> | |
1612 */ | |
1613 public int getLineCount () { | |
1614 checkLayout(); | |
1615 computeRuns(null); | |
1616 return runs.length; | |
1617 } | |
1618 | |
1619 int getLineIndent (int lineIndex) { | |
1620 int lineIndent = 0; | |
1621 if (lineIndex is 0) { | |
1622 lineIndent = indent; | |
1623 } else { | |
1624 StyleItem[] previousLine = runs[lineIndex - 1]; | |
1625 StyleItem previousRun = previousLine[previousLine.length - 1]; | |
1626 if (previousRun.lineBreak && !previousRun.softBreak) { | |
1627 lineIndent = indent; | |
1628 } | |
1629 } | |
1630 if (wrapWidth !is -1) { | |
1631 bool partialLine = true; | |
1632 if (justify) { | |
1633 StyleItem[] lineRun = runs[lineIndex]; | |
1634 if (lineRun[lineRun.length - 1].softBreak) { | |
1635 partialLine = false; | |
1636 } | |
1637 } | |
1638 if (partialLine) { | |
1639 int lineWidth = this.lineWidth[lineIndex] + lineIndent; | |
1640 switch (alignment) { | |
1641 case DWT.CENTER: lineIndent += (wrapWidth - lineWidth) / 2; break; | |
1642 case DWT.RIGHT: lineIndent += wrapWidth - lineWidth; break; | |
81 | 1643 default: |
29 | 1644 } |
1645 } | |
1646 } | |
1647 return lineIndent; | |
1648 } | |
1649 | |
1650 /** | |
1651 * Returns the index of the line that contains the specified | |
1652 * character offset. | |
1653 * | |
1654 * @param offset the character offset | |
1655 * @return the line index | |
1656 * | |
1657 * @exception IllegalArgumentException <ul> | |
1658 * <li>ERROR_INVALID_ARGUMENT - if the character offset is out of range</li> | |
1659 * </ul> | |
1660 * @exception DWTException <ul> | |
1661 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
1662 * </ul> | |
1663 */ | |
1664 public int getLineIndex (int offset) { | |
1665 checkLayout(); | |
1666 computeRuns(null); | |
227 | 1667 int length = text.length; |
1668 if (!(0 <= offset && offset <= length)) DWT.error(DWT.ERROR_INVALID_RANGE); | |
29 | 1669 offset = translateOffset(offset); |
1670 for (int line=0; line<runs.length; line++) { | |
1671 if (lineOffset[line + 1] > offset) { | |
1672 return line; | |
1673 } | |
1674 } | |
1675 return runs.length - 1; | |
1676 } | |
1677 | |
1678 /** | |
1679 * Returns the font metrics for the specified line index. | |
1680 * | |
1681 * @param lineIndex the line index | |
1682 * @return the font metrics | |
1683 * | |
1684 * @exception IllegalArgumentException <ul> | |
1685 * <li>ERROR_INVALID_ARGUMENT - if the line index is out of range</li> | |
1686 * </ul> | |
1687 * @exception DWTException <ul> | |
1688 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
1689 * </ul> | |
1690 */ | |
1691 public FontMetrics getLineMetrics (int lineIndex) { | |
1692 checkLayout(); | |
1693 computeRuns(null); | |
1694 if (!(0 <= lineIndex && lineIndex < runs.length)) DWT.error(DWT.ERROR_INVALID_RANGE); | |
30 | 1695 auto hDC = device.internal_new_GC(null); |
1696 auto srcHdc = OS.CreateCompatibleDC(hDC); | |
29 | 1697 TEXTMETRIC lptm; |
213 | 1698 OS.SelectObject(srcHdc, font !is null ? font.handle : device.systemFont.handle); |
29 | 1699 OS.GetTextMetrics(srcHdc, &lptm); |
1700 OS.DeleteDC(srcHdc); | |
1701 device.internal_dispose_GC(hDC, null); | |
1702 | |
1703 int ascent = Math.max(lptm.tmAscent, this.ascent); | |
1704 int descent = Math.max(lptm.tmDescent, this.descent); | |
1705 int leading = lptm.tmInternalLeading; | |
30 | 1706 if (text.length !is 0) { |
29 | 1707 StyleItem[] lineRuns = runs[lineIndex]; |
1708 for (int i = 0; i<lineRuns.length; i++) { | |
1709 StyleItem run = lineRuns[i]; | |
1710 if (run.ascent > ascent) { | |
1711 ascent = run.ascent; | |
1712 leading = run.leading; | |
1713 } | |
1714 descent = Math.max(descent, run.descent); | |
1715 } | |
1716 } | |
1717 lptm.tmAscent = ascent; | |
1718 lptm.tmDescent = descent; | |
1719 lptm.tmHeight = ascent + descent; | |
1720 lptm.tmInternalLeading = leading; | |
1721 lptm.tmAveCharWidth = 0; | |
30 | 1722 return FontMetrics.win32_new(&lptm); |
29 | 1723 } |
1724 | |
1725 /** | |
1726 * Returns the line offsets. Each value in the array is the | |
1727 * offset for the first character in a line except for the last | |
1728 * value, which contains the length of the text. | |
1729 * | |
1730 * @return the line offsets | |
1731 * | |
1732 * @exception DWTException <ul> | |
1733 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
1734 * </ul> | |
1735 */ | |
1736 public int[] getLineOffsets () { | |
1737 checkLayout(); | |
1738 computeRuns(null); | |
1739 int[] offsets = new int[lineOffset.length]; | |
1740 for (int i = 0; i < offsets.length; i++) { | |
1741 offsets[i] = untranslateOffset(lineOffset[i]); | |
1742 } | |
1743 return offsets; | |
1744 } | |
1745 | |
1746 /** | |
1747 * Returns the location for the specified character offset. The | |
1748 * <code>trailing</code> argument indicates whether the offset | |
1749 * corresponds to the leading or trailing edge of the cluster. | |
1750 * | |
1751 * @param offset the character offset | |
1752 * @param trailing the trailing flag | |
1753 * @return the location of the character offset | |
1754 * | |
1755 * @exception DWTException <ul> | |
1756 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
1757 * </ul> | |
1758 * | |
1759 * @see #getOffset(Point, int[]) | |
1760 * @see #getOffset(int, int, int[]) | |
1761 */ | |
1762 public Point getLocation (int offset, bool trailing) { | |
1763 checkLayout(); | |
1764 computeRuns(null); | |
227 | 1765 int length = text.length; |
1766 if (!(0 <= offset && offset <= length)) DWT.error(DWT.ERROR_INVALID_RANGE); | |
1767 length = segmentsText.length; | |
29 | 1768 offset = translateOffset(offset); |
1769 int line; | |
1770 for (line=0; line<runs.length; line++) { | |
1771 if (lineOffset[line + 1] > offset) break; | |
1772 } | |
1773 line = Math.min(line, runs.length - 1); | |
227 | 1774 if (offset is length) { |
213 | 1775 return new Point(getLineIndent(line) + lineWidth[line], lineY[line]); |
1776 } | |
1777 int low = -1; | |
1778 int high = allRuns.length; | |
1779 while (high - low > 1) { | |
1780 int index = ((high + low) / 2); | |
1781 StyleItem run = allRuns[index]; | |
1782 if (run.start > offset) { | |
1783 high = index; | |
1784 } else if (run.start + run.length <= offset) { | |
1785 low = index; | |
1786 } else { | |
1787 int width; | |
1788 if (run.style !is null && run.style.metrics !is null) { | |
1789 GlyphMetrics metrics = run.style.metrics; | |
1790 width = metrics.width * (offset - run.start + (trailing ? 1 : 0)); | |
1791 } else if (run.tab) { | |
227 | 1792 width = (trailing || (offset is length)) ? run.width : 0; |
213 | 1793 } else { |
1794 int runOffset = offset - run.start; | |
1795 int cChars = run.length; | |
1796 int gGlyphs = run.glyphCount; | |
1797 int piX; | |
1798 int* advances = run.justify !is null ? run.justify : run.advances; | |
1799 OS.ScriptCPtoX(runOffset, trailing, cChars, gGlyphs, run.clusters, run.visAttrs, advances, &run.analysis, &piX); | |
1800 width = (orientation & DWT.RIGHT_TO_LEFT) !is 0 ? run.width - piX : piX; | |
29 | 1801 } |
213 | 1802 return new Point(run.x + width, lineY[line]); |
29 | 1803 } |
1804 } | |
213 | 1805 return new Point(0, 0); |
29 | 1806 } |
1807 | |
1808 /** | |
1809 * Returns the next offset for the specified offset and movement | |
1810 * type. The movement is one of <code>DWT.MOVEMENT_CHAR</code>, | |
1811 * <code>DWT.MOVEMENT_CLUSTER</code>, <code>DWT.MOVEMENT_WORD</code>, | |
1812 * <code>DWT.MOVEMENT_WORD_END</code> or <code>DWT.MOVEMENT_WORD_START</code>. | |
1813 * | |
1814 * @param offset the start offset | |
1815 * @param movement the movement type | |
1816 * @return the next offset | |
1817 * | |
1818 * @exception IllegalArgumentException <ul> | |
1819 * <li>ERROR_INVALID_ARGUMENT - if the offset is out of range</li> | |
1820 * </ul> | |
1821 * @exception DWTException <ul> | |
1822 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
1823 * </ul> | |
1824 * | |
1825 * @see #getPreviousOffset(int, int) | |
1826 */ | |
1827 public int getNextOffset (int offset, int movement) { | |
1828 checkLayout(); | |
1829 return _getOffset (offset, movement, true); | |
1830 } | |
1831 | |
1832 int _getOffset(int offset, int movement, bool forward) { | |
1833 computeRuns(null); | |
227 | 1834 int length = text.length; |
1835 if (!(0 <= offset && offset <= length)) DWT.error(DWT.ERROR_INVALID_RANGE); | |
1836 if (forward && offset is length) return length; | |
29 | 1837 if (!forward && offset is 0) return 0; |
1838 int step = forward ? 1 : -1; | |
1839 if ((movement & DWT.MOVEMENT_CHAR) !is 0) return offset + step; | |
227 | 1840 length = segmentsText.length; |
29 | 1841 offset = translateOffset(offset); |
227 | 1842 SCRIPT_LOGATTR* logAttr = new SCRIPT_LOGATTR(); |
1843 SCRIPT_PROPERTIES* properties = new SCRIPT_PROPERTIES(); | |
29 | 1844 int i = forward ? 0 : allRuns.length - 1; |
1845 offset = validadeOffset(offset, step); | |
1846 do { | |
1847 StyleItem run = allRuns[i]; | |
1848 if (run.start <= offset && offset < run.start + run.length) { | |
1849 if (run.lineBreak && !run.softBreak) return untranslateOffset(run.start); | |
1850 if (run.tab) return untranslateOffset(run.start); | |
227 | 1851 OS.MoveMemory(properties, device.scripts[run.analysis.eScript], SCRIPT_PROPERTIES.sizeof); |
29 | 1852 bool isComplex = properties.fNeedsCaretInfo || properties.fNeedsWordBreaking; |
1853 if (isComplex) breakRun(run); | |
1854 while (run.start <= offset && offset < run.start + run.length) { | |
1855 if (isComplex) { | |
227 | 1856 OS.MoveMemory(logAttr, run.psla + (offset - run.start), SCRIPT_LOGATTR.sizeof); |
29 | 1857 } |
1858 switch (movement) { | |
1859 case DWT.MOVEMENT_CLUSTER: { | |
1860 if (properties.fNeedsCaretInfo) { | |
1861 if (!logAttr.fInvalid && logAttr.fCharStop) return untranslateOffset(offset); | |
1862 } else { | |
1863 return untranslateOffset(offset); | |
1864 } | |
1865 break; | |
1866 } | |
1867 case DWT.MOVEMENT_WORD_START: | |
1868 case DWT.MOVEMENT_WORD: { | |
1869 if (properties.fNeedsWordBreaking) { | |
1870 if (!logAttr.fInvalid && logAttr.fWordStop) return untranslateOffset(offset); | |
1871 } else { | |
1872 if (offset > 0) { | |
1873 bool letterOrDigit = Compatibility.isLetterOrDigit(segmentsText.charAt(offset)); | |
1874 bool previousLetterOrDigit = Compatibility.isLetterOrDigit(segmentsText.charAt(offset - 1)); | |
1875 if (letterOrDigit !is previousLetterOrDigit || !letterOrDigit) { | |
1876 if (!Compatibility.isWhitespace(segmentsText.charAt(offset))) { | |
1877 return untranslateOffset(offset); | |
1878 } | |
1879 } | |
1880 } | |
1881 } | |
1882 break; | |
1883 } | |
1884 case DWT.MOVEMENT_WORD_END: { | |
1885 if (offset > 0) { | |
1886 bool isLetterOrDigit = Compatibility.isLetterOrDigit(segmentsText.charAt(offset)); | |
1887 bool previousLetterOrDigit = Compatibility.isLetterOrDigit(segmentsText.charAt(offset - 1)); | |
1888 if (!isLetterOrDigit && previousLetterOrDigit) { | |
1889 return untranslateOffset(offset); | |
1890 } | |
1891 } | |
1892 break; | |
1893 } | |
81 | 1894 default: |
29 | 1895 } |
1896 offset = validadeOffset(offset, step); | |
1897 } | |
1898 } | |
1899 i += step; | |
227 | 1900 } while (0 <= i && i < allRuns.length - 1 && 0 <= offset && offset < length); |
30 | 1901 return forward ? text.length : 0; |
29 | 1902 } |
1903 | |
1904 /** | |
1905 * Returns the character offset for the specified point. | |
1906 * For a typical character, the trailing argument will be filled in to | |
1907 * indicate whether the point is closer to the leading edge (0) or | |
1908 * the trailing edge (1). When the point is over a cluster composed | |
1909 * of multiple characters, the trailing argument will be filled with the | |
1910 * position of the character in the cluster that is closest to | |
1911 * the point. | |
1912 * | |
1913 * @param point the point | |
1914 * @param trailing the trailing buffer | |
1915 * @return the character offset | |
1916 * | |
1917 * @exception IllegalArgumentException <ul> | |
1918 * <li>ERROR_INVALID_ARGUMENT - if the trailing length is less than <code>1</code></li> | |
1919 * <li>ERROR_NULL_ARGUMENT - if the point is null</li> | |
1920 * </ul> | |
1921 * @exception DWTException <ul> | |
1922 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
1923 * </ul> | |
1924 * | |
1925 * @see #getLocation(int, bool) | |
1926 */ | |
1927 public int getOffset (Point point, int[] trailing) { | |
1928 checkLayout(); | |
1929 if (point is null) DWT.error (DWT.ERROR_NULL_ARGUMENT); | |
1930 return getOffset (point.x, point.y, trailing) ; | |
1931 } | |
1932 | |
1933 /** | |
1934 * Returns the character offset for the specified point. | |
1935 * For a typical character, the trailing argument will be filled in to | |
1936 * indicate whether the point is closer to the leading edge (0) or | |
1937 * the trailing edge (1). When the point is over a cluster composed | |
1938 * of multiple characters, the trailing argument will be filled with the | |
1939 * position of the character in the cluster that is closest to | |
1940 * the point. | |
1941 * | |
1942 * @param x the x coordinate of the point | |
1943 * @param y the y coordinate of the point | |
1944 * @param trailing the trailing buffer | |
1945 * @return the character offset | |
1946 * | |
1947 * @exception IllegalArgumentException <ul> | |
1948 * <li>ERROR_INVALID_ARGUMENT - if the trailing length is less than <code>1</code></li> | |
1949 * </ul> | |
1950 * @exception DWTException <ul> | |
1951 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
1952 * </ul> | |
1953 * | |
1954 * @see #getLocation(int, bool) | |
1955 */ | |
1956 public int getOffset (int x, int y, int[] trailing) { | |
1957 checkLayout(); | |
1958 computeRuns(null); | |
1959 if (trailing !is null && trailing.length < 1) DWT.error(DWT.ERROR_INVALID_ARGUMENT); | |
1960 int line; | |
1961 int lineCount = runs.length; | |
1962 for (line=0; line<lineCount; line++) { | |
1963 if (lineY[line + 1] > y) break; | |
1964 } | |
1965 line = Math.min(line, runs.length - 1); | |
1966 StyleItem[] lineRuns = runs[line]; | |
213 | 1967 int lineIndent = getLineIndent(line); |
1968 if (x >= lineIndent + lineWidth[line]) x = lineIndent + lineWidth[line] - 1; | |
1969 if (x < lineIndent) x = lineIndent; | |
1970 int low = -1; | |
1971 int high = lineRuns.length; | |
1972 while (high - low > 1) { | |
1973 int index = ((high + low) / 2); | |
1974 StyleItem run = lineRuns[index]; | |
1975 if (run.x > x) { | |
1976 high = index; | |
1977 } else if (run.x + run.width <= x) { | |
1978 low = index; | |
1979 } else { | |
1980 if (run.lineBreak && !run.softBreak) return untranslateOffset(run.start); | |
1981 int xRun = x - run.x; | |
29 | 1982 if (run.style !is null && run.style.metrics !is null) { |
1983 GlyphMetrics metrics = run.style.metrics; | |
1984 if (metrics.width > 0) { | |
1985 if (trailing !is null) { | |
1986 trailing[0] = (xRun % metrics.width < metrics.width / 2) ? 0 : 1; | |
1987 } | |
1988 return untranslateOffset(run.start + xRun / metrics.width); | |
1989 } | |
1990 } | |
1991 if (run.tab) { | |
213 | 1992 if (trailing !is null) trailing[0] = x < (run.x + run.width / 2) ? 0 : 1; |
29 | 1993 return untranslateOffset(run.start); |
1994 } | |
1995 int cChars = run.length; | |
1996 int cGlyphs = run.glyphCount; | |
30 | 1997 int piCP; |
1998 int piTrailing; | |
29 | 1999 if ((orientation & DWT.RIGHT_TO_LEFT) !is 0) { |
2000 xRun = run.width - xRun; | |
2001 } | |
30 | 2002 int* advances = run.justify !is null ? run.justify : run.advances; |
2003 OS.ScriptXtoCP(xRun, cChars, cGlyphs, run.clusters, run.visAttrs, advances, &run.analysis, &piCP, &piTrailing); | |
2004 if (trailing !is null) trailing[0] = piTrailing; | |
2005 return untranslateOffset(run.start + piCP); | |
29 | 2006 } |
2007 } | |
2008 if (trailing !is null) trailing[0] = 0; | |
2009 return untranslateOffset(lineOffset[line + 1]); | |
2010 } | |
2011 | |
2012 /** | |
2013 * Returns the orientation of the receiver. | |
2014 * | |
2015 * @return the orientation style | |
2016 * | |
2017 * @exception DWTException <ul> | |
2018 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
2019 * </ul> | |
2020 */ | |
2021 public int getOrientation () { | |
2022 checkLayout(); | |
2023 return orientation; | |
2024 } | |
2025 | |
2026 /** | |
2027 * Returns the previous offset for the specified offset and movement | |
2028 * type. The movement is one of <code>DWT.MOVEMENT_CHAR</code>, | |
2029 * <code>DWT.MOVEMENT_CLUSTER</code> or <code>DWT.MOVEMENT_WORD</code>, | |
2030 * <code>DWT.MOVEMENT_WORD_END</code> or <code>DWT.MOVEMENT_WORD_START</code>. | |
2031 * | |
2032 * @param offset the start offset | |
2033 * @param movement the movement type | |
2034 * @return the previous offset | |
2035 * | |
2036 * @exception IllegalArgumentException <ul> | |
2037 * <li>ERROR_INVALID_ARGUMENT - if the offset is out of range</li> | |
2038 * </ul> | |
2039 * @exception DWTException <ul> | |
2040 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
2041 * </ul> | |
2042 * | |
2043 * @see #getNextOffset(int, int) | |
2044 */ | |
2045 public int getPreviousOffset (int offset, int movement) { | |
2046 checkLayout(); | |
2047 return _getOffset (offset, movement, false); | |
2048 } | |
2049 | |
2050 /** | |
2051 * Gets the ranges of text that are associated with a <code>TextStyle</code>. | |
2052 * | |
2053 * @return the ranges, an array of offsets representing the start and end of each | |
2054 * text style. | |
2055 * | |
2056 * @exception DWTException <ul> | |
2057 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
2058 * </ul> | |
2059 * | |
2060 * @see #getStyles() | |
2061 * | |
2062 * @since 3.2 | |
2063 */ | |
2064 public int[] getRanges () { | |
2065 checkLayout(); | |
213 | 2066 int[] result = new int[stylesCount * 2]; |
29 | 2067 int count = 0; |
213 | 2068 for (int i=0; i<stylesCount - 1; i++) { |
29 | 2069 if (styles[i].style !is null) { |
2070 result[count++] = styles[i].start; | |
2071 result[count++] = styles[i + 1].start - 1; | |
2072 } | |
2073 } | |
2074 if (count !is result.length) { | |
2075 int[] newResult = new int[count]; | |
2076 System.arraycopy(result, 0, newResult, 0, count); | |
2077 result = newResult; | |
2078 } | |
2079 return result; | |
2080 } | |
2081 | |
2082 /** | |
2083 * Returns the text segments offsets of the receiver. | |
2084 * | |
2085 * @return the text segments offsets | |
2086 * | |
2087 * @exception DWTException <ul> | |
2088 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
2089 * </ul> | |
2090 */ | |
2091 public int[] getSegments () { | |
2092 checkLayout(); | |
2093 return segments; | |
2094 } | |
2095 | |
212
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
157
diff
changeset
|
2096 String getSegmentsText() { |
29 | 2097 if (segments is null) return text; |
2098 int nSegments = segments.length; | |
2099 if (nSegments <= 1) return text; | |
213 | 2100 int length_ = text.length; |
2101 if (length_ is 0) return text; | |
29 | 2102 if (nSegments is 2) { |
213 | 2103 if (segments[0] is 0 && segments[1] is length_) return text; |
29 | 2104 } |
213 | 2105 char[] oldChars = new char[length_]; |
2106 text.getChars(0, length_, oldChars, 0); | |
2107 char[] newChars = new char[length_ + nSegments]; | |
29 | 2108 int charCount = 0, segmentCount = 0; |
30 | 2109 wchar separator = orientation is DWT.RIGHT_TO_LEFT ? RTL_MARK : LTR_MARK; |
213 | 2110 while (charCount < length_) { |
29 | 2111 if (segmentCount < nSegments && charCount is segments[segmentCount]) { |
2112 newChars[charCount + segmentCount++] = separator; | |
2113 } else { | |
2114 newChars[charCount + segmentCount] = oldChars[charCount++]; | |
2115 } | |
2116 } | |
2117 if (segmentCount < nSegments) { | |
2118 segments[segmentCount] = charCount; | |
2119 newChars[charCount + segmentCount++] = separator; | |
2120 } | |
30 | 2121 return newChars[ 0 .. Math.min(charCount + segmentCount, newChars.length)].dup; |
29 | 2122 } |
2123 | |
2124 /** | |
2125 * Returns the line spacing of the receiver. | |
2126 * | |
2127 * @return the line spacing | |
2128 * | |
2129 * @exception DWTException <ul> | |
2130 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
2131 * </ul> | |
2132 */ | |
2133 public int getSpacing () { | |
2134 checkLayout(); | |
2135 return lineSpacing; | |
2136 } | |
2137 | |
2138 /** | |
2139 * Gets the style of the receiver at the specified character offset. | |
2140 * | |
2141 * @param offset the text offset | |
2142 * @return the style or <code>null</code> if not set | |
2143 * | |
2144 * @exception IllegalArgumentException <ul> | |
2145 * <li>ERROR_INVALID_ARGUMENT - if the character offset is out of range</li> | |
2146 * </ul> | |
2147 * @exception DWTException <ul> | |
2148 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
2149 * </ul> | |
2150 */ | |
2151 public TextStyle getStyle (int offset) { | |
2152 checkLayout(); | |
227 | 2153 int length = text.length; |
2154 if (!(0 <= offset && offset < length)) DWT.error(DWT.ERROR_INVALID_RANGE); | |
213 | 2155 for (int i=1; i<stylesCount; i++) { |
29 | 2156 if (styles[i].start > offset) { |
2157 return styles[i - 1].style; | |
2158 } | |
2159 } | |
2160 return null; | |
2161 } | |
2162 | |
2163 /** | |
2164 * Gets all styles of the receiver. | |
2165 * | |
2166 * @return the styles | |
2167 * | |
2168 * @exception DWTException <ul> | |
2169 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
2170 * </ul> | |
2171 * | |
2172 * @see #getRanges() | |
2173 * | |
2174 * @since 3.2 | |
2175 */ | |
2176 public TextStyle[] getStyles () { | |
2177 checkLayout(); | |
213 | 2178 TextStyle[] result = new TextStyle[stylesCount]; |
29 | 2179 int count = 0; |
213 | 2180 for (int i=0; i<stylesCount; i++) { |
29 | 2181 if (styles[i].style !is null) { |
2182 result[count++] = styles[i].style; | |
2183 } | |
2184 } | |
2185 if (count !is result.length) { | |
2186 TextStyle[] newResult = new TextStyle[count]; | |
2187 System.arraycopy(result, 0, newResult, 0, count); | |
2188 result = newResult; | |
2189 } | |
2190 return result; | |
2191 } | |
2192 | |
2193 /** | |
2194 * Returns the tab list of the receiver. | |
2195 * | |
2196 * @return the tab list | |
2197 * | |
2198 * @exception DWTException <ul> | |
2199 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
2200 * </ul> | |
2201 */ | |
2202 public int[] getTabs () { | |
2203 checkLayout(); | |
2204 return tabs; | |
2205 } | |
2206 | |
2207 /** | |
2208 * Gets the receiver's text, which will be an empty | |
2209 * string if it has never been set. | |
2210 * | |
2211 * @return the receiver's text | |
2212 * | |
2213 * @exception DWTException <ul> | |
2214 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
2215 * </ul> | |
2216 */ | |
212
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
157
diff
changeset
|
2217 public String getText () { |
29 | 2218 checkLayout(); |
2219 return text; | |
2220 } | |
2221 | |
2222 /** | |
2223 * Returns the width of the receiver. | |
2224 * | |
2225 * @return the width | |
2226 * | |
2227 * @exception DWTException <ul> | |
2228 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
2229 * </ul> | |
2230 */ | |
2231 public int getWidth () { | |
2232 checkLayout(); | |
2233 return wrapWidth; | |
2234 } | |
2235 | |
2236 /** | |
2237 * Returns <code>true</code> if the text layout has been disposed, | |
2238 * and <code>false</code> otherwise. | |
2239 * <p> | |
2240 * This method gets the dispose state for the text layout. | |
2241 * When a text layout has been disposed, it is an error to | |
2242 * invoke any other method using the text layout. | |
2243 * </p> | |
2244 * | |
2245 * @return <code>true</code> when the text layout is disposed and <code>false</code> otherwise | |
2246 */ | |
48
9a64a7781bab
Added override and alias, first chunk. Thanks torhu for doing this patch.
Frank Benoit <benoit@tionex.de>
parents:
31
diff
changeset
|
2247 override public bool isDisposed () { |
29 | 2248 return device is null; |
2249 } | |
2250 | |
2251 /* | |
2252 * Itemize the receiver text | |
2253 */ | |
2254 StyleItem[] itemize () { | |
2255 segmentsText = getSegmentsText(); | |
227 | 2256 int length = segmentsText.length; |
30 | 2257 SCRIPT_CONTROL scriptControl; |
2258 SCRIPT_STATE scriptState; | |
227 | 2259 final int MAX_ITEM = length + 1; |
29 | 2260 |
2261 if ((orientation & DWT.RIGHT_TO_LEFT) !is 0) { | |
2262 scriptState.uBidiLevel = 1; | |
2263 scriptState.fArabicNumContext = true; | |
30 | 2264 SCRIPT_DIGITSUBSTITUTE psds; |
2265 OS.ScriptRecordDigitSubstitution(OS.LOCALE_USER_DEFAULT, &psds); | |
2266 OS.ScriptApplyDigitSubstitution(&psds, &scriptControl, &scriptState); | |
29 | 2267 } |
2268 | |
30 | 2269 auto hHeap = OS.GetProcessHeap(); |
2270 auto pItems = cast(SCRIPT_ITEM*)OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, MAX_ITEM * SCRIPT_ITEM.sizeof); | |
2271 if (pItems is null) DWT.error(DWT.ERROR_NO_HANDLES); | |
2272 int pcItems; | |
2273 wchar[] chars = StrToWCHARs( segmentsText ); | |
2274 OS.ScriptItemize(chars.ptr, chars.length, MAX_ITEM, &scriptControl, &scriptState, pItems, &pcItems); | |
29 | 2275 // if (hr is E_OUTOFMEMORY) //TODO handle it |
2276 | |
229 | 2277 // Translate the utf16 indices to utf8 indices |
2278 int utf8idx = 0; | |
2279 SCRIPT_ITEM* si = pItems; | |
2280 foreach( uint utf16idx, char c; chars ){ | |
2281 if( si.iCharPos is utf16idx ){ | |
2282 si.iCharPos = utf8idx; | |
2283 si++; | |
2284 } | |
2285 utf8idx++; | |
2286 } | |
2287 | |
30 | 2288 StyleItem[] runs = merge(pItems, pcItems); |
29 | 2289 OS.HeapFree(hHeap, 0, pItems); |
2290 return runs; | |
2291 } | |
2292 | |
2293 /* | |
2294 * Merge styles ranges and script items | |
2295 */ | |
30 | 2296 StyleItem[] merge (SCRIPT_ITEM* items, int itemCount) { |
213 | 2297 if (styles.length > stylesCount) { |
2298 StyleItem[] newStyles = new StyleItem[stylesCount]; | |
2299 System.arraycopy(styles, 0, newStyles, 0, stylesCount); | |
2300 styles = newStyles; | |
2301 } | |
30 | 2302 int count = 0, start = 0, end = segmentsText.length, itemIndex = 0, styleIndex = 0; |
213 | 2303 StyleItem[] runs = new StyleItem[itemCount + stylesCount]; |
2304 SCRIPT_ITEM* scriptItem = new SCRIPT_ITEM(); | |
29 | 2305 bool linkBefore = false; |
2306 while (start < end) { | |
2307 StyleItem item = new StyleItem(); | |
2308 item.start = start; | |
2309 item.style = styles[styleIndex].style; | |
2310 runs[count++] = item; | |
227 | 2311 OS.MoveMemory(scriptItem, (cast(void*)items) + itemIndex * SCRIPT_ITEM.sizeof, SCRIPT_ITEM.sizeof); |
29 | 2312 item.analysis = scriptItem.a; |
2313 if (linkBefore) { | |
2314 item.analysis.fLinkBefore = true; | |
2315 linkBefore = false; | |
2316 } | |
30 | 2317 //scriptItem.a = new SCRIPT_ANALYSIS(); |
227 | 2318 OS.MoveMemory(scriptItem, (cast(void*)items) + (itemIndex + 1) * SCRIPT_ITEM.sizeof, SCRIPT_ITEM.sizeof); |
29 | 2319 int itemLimit = scriptItem.iCharPos; |
2320 int styleLimit = translateOffset(styles[styleIndex + 1].start); | |
2321 if (styleLimit <= itemLimit) { | |
2322 styleIndex++; | |
2323 start = styleLimit; | |
2324 if (start < itemLimit && 0 < start && start < end) { | |
2325 char pChar = segmentsText.charAt(start - 1); | |
2326 char tChar = segmentsText.charAt(start); | |
213 | 2327 if (Compatibility.isLetter(pChar) && Compatibility.isLetter(tChar)) { |
29 | 2328 item.analysis.fLinkAfter = true; |
2329 linkBefore = true; | |
2330 } | |
2331 } | |
2332 } | |
2333 if (itemLimit <= styleLimit) { | |
2334 itemIndex++; | |
2335 start = itemLimit; | |
2336 } | |
2337 item.length = start - item.start; | |
2338 } | |
2339 StyleItem item = new StyleItem(); | |
2340 item.start = end; | |
227 | 2341 OS.MoveMemory(scriptItem, (cast(void*)items) + itemCount * SCRIPT_ITEM.sizeof, SCRIPT_ITEM.sizeof); |
29 | 2342 item.analysis = scriptItem.a; |
2343 runs[count++] = item; | |
2344 if (runs.length !is count) { | |
2345 StyleItem[] result = new StyleItem[count]; | |
2346 System.arraycopy(runs, 0, result, 0, count); | |
2347 return result; | |
2348 } | |
2349 return runs; | |
2350 } | |
2351 | |
2352 /* | |
2353 * Reorder the run | |
2354 */ | |
2355 StyleItem[] reorder (StyleItem[] runs, bool terminate) { | |
30 | 2356 int length_ = runs.length; |
2357 if (length_ <= 1) return runs; | |
2358 ubyte[] bidiLevels = new ubyte[length_]; | |
2359 for (int i=0; i<length_; i++) { | |
29 | 2360 bidiLevels[i] = cast(byte)(runs[i].analysis.s.uBidiLevel & 0x1F); |
2361 } | |
2362 /* | |
2363 * Feature in Windows. If the orientation is RTL Uniscribe will | |
2364 * resolve the level of line breaks to 1, this can cause the line | |
2365 * break to be reorder to the middle of the line. The fix is to set | |
2366 * the level to zero to prevent it to be reordered. | |
2367 */ | |
30 | 2368 StyleItem lastRun = runs[length_ - 1]; |
29 | 2369 if (lastRun.lineBreak && !lastRun.softBreak) { |
30 | 2370 bidiLevels[length_ - 1] = 0; |
29 | 2371 } |
30 | 2372 int[] log2vis = new int[length_]; |
2373 OS.ScriptLayout(length_, bidiLevels.ptr, null, log2vis.ptr); | |
2374 StyleItem[] result = new StyleItem[length_]; | |
2375 for (int i=0; i<length_; i++) { | |
29 | 2376 result[log2vis[i]] = runs[i]; |
2377 } | |
2378 if ((orientation & DWT.RIGHT_TO_LEFT) !is 0) { | |
30 | 2379 if (terminate) length_--; |
2380 for (int i = 0; i < length_ / 2 ; i++) { | |
29 | 2381 StyleItem tmp = result[i]; |
30 | 2382 result[i] = result[length_ - i - 1]; |
2383 result[length_ - i - 1] = tmp; | |
29 | 2384 } |
2385 } | |
2386 return result; | |
2387 } | |
2388 | |
2389 /** | |
2390 * Sets the text alignment for the receiver. The alignment controls | |
2391 * how a line of text is positioned horizontally. The argument should | |
2392 * be one of <code>DWT.LEFT</code>, <code>DWT.RIGHT</code> or <code>DWT.CENTER</code>. | |
2393 * <p> | |
2394 * The default alignment is <code>DWT.LEFT</code>. Note that the receiver's | |
2395 * width must be set in order to use <code>DWT.RIGHT</code> or <code>DWT.CENTER</code> | |
2396 * alignment. | |
2397 * </p> | |
2398 * | |
2399 * @param alignment the new alignment | |
2400 * | |
2401 * @exception DWTException <ul> | |
2402 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
2403 * </ul> | |
2404 * | |
2405 * @see #setWidth(int) | |
2406 */ | |
2407 public void setAlignment (int alignment) { | |
2408 checkLayout(); | |
2409 int mask = DWT.LEFT | DWT.CENTER | DWT.RIGHT; | |
2410 alignment &= mask; | |
2411 if (alignment is 0) return; | |
2412 if ((alignment & DWT.LEFT) !is 0) alignment = DWT.LEFT; | |
2413 if ((alignment & DWT.RIGHT) !is 0) alignment = DWT.RIGHT; | |
2414 if (this.alignment is alignment) return; | |
2415 freeRuns(); | |
2416 this.alignment = alignment; | |
2417 } | |
2418 | |
2419 /** | |
2420 * Sets the ascent of the receiver. The ascent is distance in pixels | |
2421 * from the baseline to the top of the line and it is applied to all | |
2422 * lines. The default value is <code>-1</code> which means that the | |
2423 * ascent is calculated from the line fonts. | |
2424 * | |
2425 * @param ascent the new ascent | |
2426 * | |
2427 * @exception IllegalArgumentException <ul> | |
2428 * <li>ERROR_INVALID_ARGUMENT - if the ascent is less than <code>-1</code></li> | |
2429 * </ul> | |
2430 * @exception DWTException <ul> | |
2431 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
2432 * </ul> | |
2433 * | |
2434 * @see #setDescent(int) | |
2435 * @see #getLineMetrics(int) | |
2436 */ | |
2437 public void setAscent(int ascent) { | |
2438 checkLayout(); | |
2439 if (ascent < -1) DWT.error(DWT.ERROR_INVALID_ARGUMENT); | |
2440 if (this.ascent is ascent) return; | |
2441 freeRuns(); | |
2442 this.ascent = ascent; | |
2443 } | |
2444 | |
2445 /** | |
2446 * Sets the descent of the receiver. The descent is distance in pixels | |
2447 * from the baseline to the bottom of the line and it is applied to all | |
2448 * lines. The default value is <code>-1</code> which means that the | |
2449 * descent is calculated from the line fonts. | |
2450 * | |
2451 * @param descent the new descent | |
2452 * | |
2453 * @exception IllegalArgumentException <ul> | |
2454 * <li>ERROR_INVALID_ARGUMENT - if the descent is less than <code>-1</code></li> | |
2455 * </ul> | |
2456 * @exception DWTException <ul> | |
2457 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
2458 * </ul> | |
2459 * | |
2460 * @see #setAscent(int) | |
2461 * @see #getLineMetrics(int) | |
2462 */ | |
2463 public void setDescent(int descent) { | |
2464 checkLayout(); | |
2465 if (descent < -1) DWT.error(DWT.ERROR_INVALID_ARGUMENT); | |
2466 if (this.descent is descent) return; | |
2467 freeRuns(); | |
2468 this.descent = descent; | |
2469 } | |
2470 | |
2471 /** | |
2472 * Sets the default font which will be used by the receiver | |
2473 * to draw and measure text. If the | |
2474 * argument is null, then a default font appropriate | |
2475 * for the platform will be used instead. Note that a text | |
2476 * style can override the default font. | |
2477 * | |
2478 * @param font the new font for the receiver, or null to indicate a default font | |
2479 * | |
2480 * @exception IllegalArgumentException <ul> | |
2481 * <li>ERROR_INVALID_ARGUMENT - if the font has been disposed</li> | |
2482 * </ul> | |
2483 * @exception DWTException <ul> | |
2484 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
2485 * </ul> | |
2486 */ | |
2487 public void setFont (Font font) { | |
2488 checkLayout(); | |
2489 if (font !is null && font.isDisposed()) DWT.error(DWT.ERROR_INVALID_ARGUMENT); | |
213 | 2490 Font oldFont = this.font; |
2491 if (oldFont is font) return; | |
2492 this.font = font; | |
2493 if (oldFont !is null && oldFont.opEquals(font)) return; | |
29 | 2494 freeRuns(); |
2495 } | |
2496 | |
2497 /** | |
2498 * Sets the indent of the receiver. This indent it applied of the first line of | |
2499 * each paragraph. | |
2500 * | |
2501 * @param indent new indent | |
2502 * | |
2503 * @exception DWTException <ul> | |
2504 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
2505 * </ul> | |
2506 * | |
2507 * @since 3.2 | |
2508 */ | |
2509 public void setIndent (int indent) { | |
2510 checkLayout(); | |
2511 if (indent < 0) return; | |
2512 if (this.indent is indent) return; | |
2513 freeRuns(); | |
2514 this.indent = indent; | |
2515 } | |
2516 | |
2517 /** | |
2518 * Sets the justification of the receiver. Note that the receiver's | |
2519 * width must be set in order to use justification. | |
2520 * | |
2521 * @param justify new justify | |
2522 * | |
2523 * @exception DWTException <ul> | |
2524 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
2525 * </ul> | |
2526 * | |
2527 * @since 3.2 | |
2528 */ | |
2529 public void setJustify (bool justify) { | |
2530 checkLayout(); | |
2531 if (this.justify is justify) return; | |
2532 freeRuns(); | |
2533 this.justify = justify; | |
2534 } | |
2535 | |
2536 /** | |
2537 * Sets the orientation of the receiver, which must be one | |
2538 * of <code>DWT.LEFT_TO_RIGHT</code> or <code>DWT.RIGHT_TO_LEFT</code>. | |
2539 * | |
2540 * @param orientation new orientation style | |
2541 * | |
2542 * @exception DWTException <ul> | |
2543 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
2544 * </ul> | |
2545 */ | |
2546 public void setOrientation (int orientation) { | |
2547 checkLayout(); | |
2548 int mask = DWT.LEFT_TO_RIGHT | DWT.RIGHT_TO_LEFT; | |
2549 orientation &= mask; | |
2550 if (orientation is 0) return; | |
2551 if ((orientation & DWT.LEFT_TO_RIGHT) !is 0) orientation = DWT.LEFT_TO_RIGHT; | |
2552 if (this.orientation is orientation) return; | |
2553 this.orientation = orientation; | |
2554 freeRuns(); | |
2555 } | |
2556 | |
2557 /** | |
2558 * Sets the offsets of the receiver's text segments. Text segments are used to | |
2559 * override the default behaviour of the bidirectional algorithm. | |
2560 * Bidirectional reordering can happen within a text segment but not | |
2561 * between two adjacent segments. | |
2562 * <p> | |
2563 * Each text segment is determined by two consecutive offsets in the | |
2564 * <code>segments</code> arrays. The first element of the array should | |
2565 * always be zero and the last one should always be equals to length of | |
2566 * the text. | |
2567 * </p> | |
2568 * | |
2569 * @param segments the text segments offset | |
2570 * | |
2571 * @exception DWTException <ul> | |
2572 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
2573 * </ul> | |
2574 */ | |
2575 public void setSegments(int[] segments) { | |
2576 checkLayout(); | |
2577 if (this.segments is null && segments is null) return; | |
2578 if (this.segments !is null && segments !is null) { | |
2579 if (this.segments.length is segments.length) { | |
2580 int i; | |
2581 for (i = 0; i <segments.length; i++) { | |
2582 if (this.segments[i] !is segments[i]) break; | |
2583 } | |
2584 if (i is segments.length) return; | |
2585 } | |
2586 } | |
2587 freeRuns(); | |
2588 this.segments = segments; | |
2589 } | |
2590 | |
2591 /** | |
2592 * Sets the line spacing of the receiver. The line spacing | |
2593 * is the space left between lines. | |
2594 * | |
2595 * @param spacing the new line spacing | |
2596 * | |
2597 * @exception IllegalArgumentException <ul> | |
2598 * <li>ERROR_INVALID_ARGUMENT - if the spacing is negative</li> | |
2599 * </ul> | |
2600 * @exception DWTException <ul> | |
2601 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
2602 * </ul> | |
2603 */ | |
2604 public void setSpacing (int spacing) { | |
2605 checkLayout(); | |
2606 if (spacing < 0) DWT.error(DWT.ERROR_INVALID_ARGUMENT); | |
2607 if (this.lineSpacing is spacing) return; | |
2608 freeRuns(); | |
2609 this.lineSpacing = spacing; | |
2610 } | |
2611 | |
2612 /** | |
2613 * Sets the style of the receiver for the specified range. Styles previously | |
2614 * set for that range will be overwritten. The start and end offsets are | |
2615 * inclusive and will be clamped if out of range. | |
2616 * | |
2617 * @param style the style | |
2618 * @param start the start offset | |
2619 * @param end the end offset | |
2620 * | |
2621 * @exception DWTException <ul> | |
2622 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
2623 * </ul> | |
2624 */ | |
2625 public void setStyle (TextStyle style, int start, int end) { | |
2626 checkLayout(); | |
227 | 2627 int length = text.length; |
2628 if (length is 0) return; | |
29 | 2629 if (start > end) return; |
227 | 2630 start = Math.min(Math.max(0, start), length - 1); |
2631 end = Math.min(Math.max(0, end), length - 1); | |
29 | 2632 int low = -1; |
213 | 2633 int high = stylesCount; |
29 | 2634 while (high - low > 1) { |
2635 int index = (high + low) / 2; | |
2636 if (styles[index + 1].start > start) { | |
2637 high = index; | |
2638 } else { | |
2639 low = index; | |
2640 } | |
2641 } | |
213 | 2642 if (0 <= high && high < stylesCount) { |
29 | 2643 StyleItem item = styles[high]; |
2644 if (item.start is start && styles[high + 1].start - 1 is end) { | |
2645 if (style is null) { | |
2646 if (item.style is null) return; | |
2647 } else { | |
227 | 2648 if (style.opEquals(item.style)) return; |
29 | 2649 } |
2650 } | |
2651 } | |
2652 freeRuns(); | |
2653 int modifyStart = high; | |
2654 int modifyEnd = modifyStart; | |
213 | 2655 while (modifyEnd < stylesCount) { |
29 | 2656 if (styles[modifyEnd + 1].start > end) break; |
2657 modifyEnd++; | |
2658 } | |
2659 if (modifyStart is modifyEnd) { | |
2660 int styleStart = styles[modifyStart].start; | |
2661 int styleEnd = styles[modifyEnd + 1].start - 1; | |
2662 if (styleStart is start && styleEnd is end) { | |
2663 styles[modifyStart].style = style; | |
2664 return; | |
2665 } | |
2666 if (styleStart !is start && styleEnd !is end) { | |
213 | 2667 int newLength = stylesCount + 2; |
2668 if (newLength > styles.length) { | |
2669 int newSize = Math.min(newLength + 1024, Math.max(64, newLength * 2)); | |
2670 StyleItem[] newStyles = new StyleItem[newSize]; | |
2671 System.arraycopy(styles, 0, newStyles, 0, stylesCount); | |
2672 styles = newStyles; | |
2673 } | |
2674 System.arraycopy(styles, modifyEnd + 1, styles, modifyEnd + 3, stylesCount - modifyEnd - 1); | |
29 | 2675 StyleItem item = new StyleItem(); |
2676 item.start = start; | |
2677 item.style = style; | |
213 | 2678 styles[modifyStart + 1] = item; |
29 | 2679 item = new StyleItem(); |
2680 item.start = end + 1; | |
2681 item.style = styles[modifyStart].style; | |
213 | 2682 styles[modifyStart + 2] = item; |
2683 stylesCount = newLength; | |
29 | 2684 return; |
2685 } | |
2686 } | |
2687 if (start is styles[modifyStart].start) modifyStart--; | |
2688 if (end is styles[modifyEnd + 1].start - 1) modifyEnd++; | |
213 | 2689 int newLength = stylesCount + 1 - (modifyEnd - modifyStart - 1); |
2690 if (newLength > styles.length) { | |
2691 int newSize = Math.min(newLength + 1024, Math.max(64, newLength * 2)); | |
2692 StyleItem[] newStyles = new StyleItem[newSize]; | |
2693 System.arraycopy(styles, 0, newStyles, 0, stylesCount); | |
2694 styles = newStyles; | |
2695 } | |
2696 System.arraycopy(styles, modifyEnd, styles, modifyStart + 2, stylesCount - modifyEnd); | |
29 | 2697 StyleItem item = new StyleItem(); |
2698 item.start = start; | |
2699 item.style = style; | |
213 | 2700 styles[modifyStart + 1] = item; |
2701 styles[modifyStart + 2].start = end + 1; | |
2702 stylesCount = newLength; | |
29 | 2703 } |
2704 | |
2705 /** | |
2706 * Sets the receiver's tab list. Each value in the tab list specifies | |
2707 * the space in pixels from the origin of the text layout to the respective | |
2708 * tab stop. The last tab stop width is repeated continuously. | |
2709 * | |
2710 * @param tabs the new tab list | |
2711 * | |
2712 * @exception DWTException <ul> | |
2713 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
2714 * </ul> | |
2715 */ | |
2716 public void setTabs (int[] tabs) { | |
2717 checkLayout(); | |
2718 if (this.tabs is null && tabs is null) return; | |
2719 if (this.tabs !is null && tabs !is null) { | |
2720 if (this.tabs.length is tabs.length) { | |
2721 int i; | |
2722 for (i = 0; i <tabs.length; i++) { | |
2723 if (this.tabs[i] !is tabs[i]) break; | |
2724 } | |
2725 if (i is tabs.length) return; | |
2726 } | |
2727 } | |
2728 freeRuns(); | |
2729 this.tabs = tabs; | |
2730 } | |
2731 | |
2732 /** | |
2733 * Sets the receiver's text. | |
2734 * | |
2735 * @param text the new text | |
2736 * | |
2737 * @exception IllegalArgumentException <ul> | |
2738 * <li>ERROR_NULL_ARGUMENT - if the text is null</li> | |
2739 * </ul> | |
2740 * @exception DWTException <ul> | |
2741 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
2742 * </ul> | |
2743 */ | |
212
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
157
diff
changeset
|
2744 public void setText (String text) { |
29 | 2745 checkLayout(); |
229 | 2746 |
157
f8001bf383d2
TextLayout allow null for setText
Frank Benoit <benoit@tionex.de>
parents:
81
diff
changeset
|
2747 //PORTING_CHANGE: allow null argument |
f8001bf383d2
TextLayout allow null for setText
Frank Benoit <benoit@tionex.de>
parents:
81
diff
changeset
|
2748 //if (text is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); |
227 | 2749 if (text.equals(this.text)) return; |
29 | 2750 freeRuns(); |
2751 this.text = text; | |
2752 styles = new StyleItem[2]; | |
2753 styles[0] = new StyleItem(); | |
2754 styles[1] = new StyleItem(); | |
30 | 2755 styles[1].start = text.length; |
213 | 2756 stylesCount = 2; |
29 | 2757 } |
2758 | |
2759 /** | |
2760 * Sets the line width of the receiver, which determines how | |
2761 * text should be wrapped and aligned. The default value is | |
2762 * <code>-1</code> which means wrapping is disabled. | |
2763 * | |
2764 * @param width the new width | |
2765 * | |
2766 * @exception IllegalArgumentException <ul> | |
2767 * <li>ERROR_INVALID_ARGUMENT - if the width is <code>0</code> or less than <code>-1</code></li> | |
2768 * </ul> | |
2769 * @exception DWTException <ul> | |
2770 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
2771 * </ul> | |
2772 * | |
2773 * @see #setAlignment(int) | |
2774 */ | |
2775 public void setWidth (int width) { | |
2776 checkLayout(); | |
2777 if (width < -1 || width is 0) DWT.error(DWT.ERROR_INVALID_ARGUMENT); | |
2778 if (this.wrapWidth is width) return; | |
2779 freeRuns(); | |
2780 this.wrapWidth = width; | |
2781 } | |
2782 | |
249 | 2783 bool shape (HDC hdc, StyleItem run, wchar[] wchars, int[] glyphCount, int maxGlyphs, SCRIPT_PROPERTIES* sp) { |
2784 //wchar[] wchars = StrToWCHARs( chars ); | |
246 | 2785 bool useCMAPcheck = !sp.fComplex && !run.analysis.fNoGlyphIndex; |
2786 if (useCMAPcheck) { | |
249 | 2787 ushort[] glyphs = new ushort[wchars.length]; |
2788 scope(exit) delete glyphs; | |
2789 if (OS.ScriptGetCMap(hdc, run.psc, wchars.ptr, wchars.length, 0, glyphs.ptr) !is OS.S_OK) { | |
2790 if (run.psc !is null) { | |
246 | 2791 OS.ScriptFreeCache(run.psc); |
2792 glyphCount[0] = 0; | |
249 | 2793 *cast(int*)run.psc = 1; |
246 | 2794 } |
2795 return false; | |
2796 } | |
2797 } | |
30 | 2798 auto hr = OS.ScriptShape(hdc, run.psc, wchars.ptr, wchars.length, maxGlyphs, &run.analysis, run.glyphs, run.clusters, run.visAttrs, glyphCount.ptr); |
29 | 2799 run.glyphCount = glyphCount[0]; |
246 | 2800 if (useCMAPcheck) return true; |
2801 | |
29 | 2802 if (hr !is OS.USP_E_SCRIPT_NOT_IN_FONT) { |
246 | 2803 if (run.analysis.fNoGlyphIndex) return true; |
30 | 2804 SCRIPT_FONTPROPERTIES fp; |
29 | 2805 fp.cBytes = SCRIPT_FONTPROPERTIES.sizeof; |
30 | 2806 OS.ScriptGetFontProperties(hdc, run.psc, &fp); |
2807 ushort[] glyphs = run.glyphs[ 0 .. glyphCount[0] ]; | |
29 | 2808 int i; |
2809 for (i = 0; i < glyphs.length; i++) { | |
2810 if (glyphs[i] is fp.wgDefault) break; | |
2811 } | |
2812 if (i is glyphs.length) return true; | |
2813 } | |
30 | 2814 if (run.psc !is null) { |
29 | 2815 OS.ScriptFreeCache(run.psc); |
2816 glyphCount[0] = 0; | |
30 | 2817 *cast(int*)run.psc = 0; |
29 | 2818 } |
2819 run.glyphCount = 0; | |
2820 return false; | |
2821 } | |
2822 | |
213 | 2823 struct CallbackDataEnumFontFamExProc { |
2824 int delegate ( ENUMLOGFONTEX* lpelfe, NEWTEXTMETRICEX* lpntme, int FontType, int lParam) EnumFontFamExProc; | |
2825 int lParam; | |
2826 } | |
2827 extern(Windows) private static int EnumFontFamExProcFunc( ENUMLOGFONTEX* lpelfe, NEWTEXTMETRICEX* lpntme, int FontType, int lParam) { | |
2828 auto cb = cast(CallbackDataEnumFontFamExProc*)cast(void*)lParam; | |
2829 return cb.EnumFontFamExProc( lpelfe, lpntme, FontType, cb.lParam ); | |
2830 } | |
2831 | |
29 | 2832 /* |
2833 * Generate glyphs for one Run. | |
2834 */ | |
2835 void shape (HDC hdc, StyleItem run) { | |
213 | 2836 final int[] buffer = new int[1]; |
2837 final char[] chars = new char[run.length]; | |
29 | 2838 segmentsText.getChars(run.start, run.start + run.length, chars, 0); |
30 | 2839 wchar[] wchars = StrToWCHARs( chars ); |
249 | 2840 int maxGlyphs = (wchars.length * 3 / 2) + 16; |
30 | 2841 auto hHeap = OS.GetProcessHeap(); |
2842 run.glyphs = cast(ushort*)OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, maxGlyphs * 2); | |
2843 if (run.glyphs is null) DWT.error(DWT.ERROR_NO_HANDLES); | |
2844 run.clusters = cast(WORD*)OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, maxGlyphs * 2); | |
2845 if (run.clusters is null) DWT.error(DWT.ERROR_NO_HANDLES); | |
2846 run.visAttrs = cast(SCRIPT_VISATTR*)OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, maxGlyphs * SCRIPT_VISATTR_SIZEOF); | |
2847 if (run.visAttrs is null) DWT.error(DWT.ERROR_NO_HANDLES); | |
213 | 2848 run.psc = cast(SCRIPT_CACHE*)OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, (void*).sizeof); |
30 | 2849 if (run.psc is null) DWT.error(DWT.ERROR_NO_HANDLES); |
249 | 2850 short script = run.analysis.eScript; |
2851 auto sp = device.scripts[script]; | |
2852 bool shapeSucceed = shape(hdc, run, wchars, buffer, maxGlyphs, sp); | |
213 | 2853 if (!shapeSucceed) { |
249 | 2854 auto hFont = OS.GetCurrentObject(hdc, OS.OBJ_FONT); |
2855 auto ssa = cast(SCRIPT_STRING_ANALYSIS*) OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, SCRIPT_STRING_ANALYSIS.sizeof); | |
2856 auto metaFileDc = OS.CreateEnhMetaFile(hdc, null, null, null); | |
2857 auto oldMetaFont = OS.SelectObject(metaFileDc, hFont); | |
246 | 2858 int flags = OS.SSA_METAFILE | OS.SSA_FALLBACK | OS.SSA_GLYPHS | OS.SSA_LINK; |
249 | 2859 if (OS.ScriptStringAnalyse(metaFileDc, wchars.ptr, wchars.length, 0, -1, flags, 0, null, null, null, null, null, ssa) is OS.S_OK) { |
246 | 2860 OS.ScriptStringOut(ssa, 0, 0, 0, null, 0, 0, false); |
2861 OS.ScriptStringFree(ssa); | |
2862 } | |
2863 OS.HeapFree(hHeap, 0, ssa); | |
2864 OS.SelectObject(metaFileDc, oldMetaFont); | |
249 | 2865 auto metaFile = OS.CloseEnhMetaFile(metaFileDc); |
2866 EMREXTCREATEFONTINDIRECTW emr; | |
2867 static extern(Windows) int metaFileEnumProc (HDC hDC, HANDLETABLE* table, ENHMETARECORD* record, int nObj, LPARAM lpData) { | |
2868 EMREXTCREATEFONTINDIRECTW* emr_; | |
2869 OS.MoveMemory(&emr_.emr, record, EMR.sizeof); | |
2870 switch (emr_.emr.iType) { | |
2871 case OS.EMR_EXTCREATEFONTINDIRECTW: | |
2872 OS.MoveMemory(emr_, record, EMREXTCREATEFONTINDIRECTW.sizeof); | |
2873 break; | |
2874 case OS.EMR_EXTTEXTOUTW: | |
2875 return 0; | |
246 | 2876 } |
249 | 2877 return 1; |
2878 } | |
2879 OS.EnumEnhMetaFile(null, metaFile, &metaFileEnumProc, &emr, null); | |
246 | 2880 OS.DeleteEnhMetaFile(metaFile); |
2881 | |
249 | 2882 auto newFont = OS.CreateFontIndirectW(&emr.elfw.elfLogFont); |
246 | 2883 OS.SelectObject(hdc, newFont); |
249 | 2884 if ((shapeSucceed = shape(hdc, run, wchars, buffer, maxGlyphs, sp)) is true ) { |
246 | 2885 run.fallbackFont = newFont; |
2886 } | |
2887 if (!shapeSucceed) { | |
2888 if (!sp.fComplex) { | |
2889 run.analysis.fNoGlyphIndex = true; | |
249 | 2890 if ((shapeSucceed = shape(hdc, run, wchars, buffer, maxGlyphs, sp)) is true ) { |
246 | 2891 run.fallbackFont = newFont; |
29 | 2892 } else { |
246 | 2893 run.analysis.fNoGlyphIndex = false; |
29 | 2894 } |
2895 } | |
2896 } | |
246 | 2897 if (!shapeSucceed) { |
2898 if (mLangFontLink2 !is null) { | |
2899 HANDLE hNewFont; | |
2900 int dwCodePages, cchCodePages; | |
2901 /* GetStrCodePages() */ | |
2902 OS.VtblCall(4, mLangFontLink2, cast(int)wchars.ptr, wchars.length, 0, cast(int)&dwCodePages, cast(int)&cchCodePages); | |
2903 /* MapFont() */ | |
2904 if (OS.VtblCall(10, mLangFontLink2, cast(int)hdc, dwCodePages, cast(int)wchars[0], cast(int)&hNewFont) is OS.S_OK) { | |
2905 LOGFONT logFont; | |
2906 OS.GetObject( hNewFont, LOGFONT.sizeof, &logFont ); | |
2907 /* ReleaseFont() */ | |
2908 OS.VtblCall(8, mLangFontLink2, cast(int)hNewFont); | |
249 | 2909 auto mLangFont = OS.CreateFontIndirect(&logFont); |
246 | 2910 auto oldFont = OS.SelectObject(hdc, mLangFont); |
249 | 2911 if ((shapeSucceed = shape(hdc, run, wchars, buffer, maxGlyphs, sp)) is true ) { |
246 | 2912 run.fallbackFont = mLangFont; |
2913 } else { | |
2914 OS.SelectObject(hdc, oldFont); | |
2915 OS.DeleteObject(mLangFont); | |
2916 } | |
2917 } | |
213 | 2918 } |
2919 } | |
246 | 2920 if (!shapeSucceed) OS.SelectObject(hdc, hFont); |
2921 if (newFont !is run.fallbackFont) OS.DeleteObject(newFont); | |
213 | 2922 } |
2923 | |
2924 if (!shapeSucceed) { | |
2925 /* | |
2926 * Shape Failed. | |
2927 * Give up and shape the run with the default font. | |
2928 * Missing glyphs typically will be represent as black boxes in the text. | |
2929 */ | |
2930 auto wchars_ = StrToWCHARs(chars); | |
2931 OS.ScriptShape(hdc, run.psc, wchars_.ptr, wchars_.length, maxGlyphs, &run.analysis, run.glyphs, run.clusters, run.visAttrs, buffer.ptr); | |
2932 run.glyphCount = buffer[0]; | |
2933 } | |
2934 int[3] abc; | |
30 | 2935 run.advances = cast(int*)OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, run.glyphCount * 4); |
2936 if (run.advances is null) DWT.error(DWT.ERROR_NO_HANDLES); | |
2937 run.goffsets = cast(GOFFSET*)OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, run.glyphCount * GOFFSET_SIZEOF); | |
2938 if (run.goffsets is null) DWT.error(DWT.ERROR_NO_HANDLES); | |
213 | 2939 OS.ScriptPlace(hdc, run.psc, run.glyphs, run.glyphCount, run.visAttrs, &run.analysis, run.advances, run.goffsets, cast(ABC*)abc.ptr); |
2940 run.width = abc[0] + abc[1] + abc[2]; | |
2941 TextStyle style = run.style; | |
2942 if (style !is null) { | |
2943 OUTLINETEXTMETRIC* lotm = null; | |
2944 if (style.underline || style.strikeout) { | |
2945 lotm = new OUTLINETEXTMETRIC(); | |
2946 if (OS.GetOutlineTextMetrics(hdc, OUTLINETEXTMETRIC.sizeof, lotm) is 0) { | |
2947 lotm = null; | |
2948 } | |
2949 } | |
2950 if (style.metrics !is null) { | |
2951 GlyphMetrics metrics = style.metrics; | |
2952 /* | |
2953 * Bug in Windows, on a Japanese machine, Uniscribe returns glyphcount | |
2954 * equals zero for FFFC (possibly other unicode code points), the fix | |
2955 * is to make sure the glyph is at least one pixel wide. | |
2956 */ | |
2957 run.width = metrics.width * Math.max (1, run.glyphCount); | |
2958 run.ascent = metrics.ascent; | |
2959 run.descent = metrics.descent; | |
2960 run.leading = 0; | |
2961 } else { | |
2962 TEXTMETRIC lptm; | |
2963 if (lotm !is null) { | |
2964 lptm = lotm.otmTextMetrics; | |
2965 } else { | |
2966 lptm = TEXTMETRIC.init; | |
2967 OS.GetTextMetrics(hdc, &lptm); | |
2968 } | |
2969 run.ascent = lptm.tmAscent; | |
2970 run.descent = lptm.tmDescent; | |
2971 run.leading = lptm.tmInternalLeading; | |
2972 } | |
2973 if (lotm !is null) { | |
2974 run.underlinePos = lotm.otmsUnderscorePosition; | |
2975 run.underlineThickness = Math.max(1, lotm.otmsUnderscoreSize); | |
2976 run.strikeoutPos = lotm.otmsStrikeoutPosition; | |
2977 run.strikeoutThickness = Math.max(1, lotm.otmsStrikeoutSize); | |
2978 } else { | |
2979 run.underlinePos = 1; | |
2980 run.underlineThickness = 1; | |
2981 run.strikeoutPos = run.ascent / 2; | |
2982 run.strikeoutThickness = 1; | |
2983 } | |
2984 run.ascent += style.rise; | |
2985 run.descent -= style.rise; | |
29 | 2986 } else { |
2987 TEXTMETRIC lptm; | |
2988 OS.GetTextMetrics(hdc, &lptm); | |
2989 run.ascent = lptm.tmAscent; | |
2990 run.descent = lptm.tmDescent; | |
2991 run.leading = lptm.tmInternalLeading; | |
2992 } | |
2993 } | |
2994 | |
2995 int validadeOffset(int offset, int step) { | |
2996 offset += step; | |
2997 if (segments !is null && segments.length > 2) { | |
2998 for (int i = 0; i < segments.length; i++) { | |
2999 if (translateOffset(segments[i]) - 1 is offset) { | |
3000 offset += step; | |
3001 break; | |
3002 } | |
3003 } | |
3004 } | |
3005 return offset; | |
3006 } | |
3007 | |
3008 /** | |
3009 * Returns a string containing a concise, human-readable | |
3010 * description of the receiver. | |
3011 * | |
3012 * @return a string representation of the receiver | |
3013 */ | |
212
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
157
diff
changeset
|
3014 override public String toString () { |
29 | 3015 if (isDisposed()) return "TextLayout {*DISPOSED*}"; |
3016 return "TextLayout {}"; | |
3017 } | |
3018 | |
3019 int translateOffset(int offset) { | |
3020 if (segments is null) return offset; | |
3021 int nSegments = segments.length; | |
3022 if (nSegments <= 1) return offset; | |
227 | 3023 int length = text.length; |
3024 if (length is 0) return offset; | |
29 | 3025 if (nSegments is 2) { |
227 | 3026 if (segments[0] is 0 && segments[1] is length) return offset; |
29 | 3027 } |
3028 for (int i = 0; i < nSegments && offset - i >= segments[i]; i++) { | |
3029 offset++; | |
3030 } | |
3031 return offset; | |
3032 } | |
3033 | |
3034 int untranslateOffset(int offset) { | |
3035 if (segments is null) return offset; | |
3036 int nSegments = segments.length; | |
3037 if (nSegments <= 1) return offset; | |
227 | 3038 int length = text.length; |
3039 if (length is 0) return offset; | |
29 | 3040 if (nSegments is 2) { |
227 | 3041 if (segments[0] is 0 && segments[1] is length) return offset; |
29 | 3042 } |
3043 for (int i = 0; i < nSegments && offset > segments[i]; i++) { | |
3044 offset--; | |
3045 } | |
3046 return offset; | |
3047 } | |
3048 } |