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