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