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