|
42 | 42 | */ |
43 | 43 | public final class TextLayout extends Resource { |
44 | 44 | Font font; |
45 | | - String text, segmentsText; |
46 | | - int lineSpacingInPoints; |
| 45 | + String text, segmentsText, originalText; |
| 46 | + int lineSpacingInPoints, previousCountNextLine, previousEnd; |
47 | 47 | int ascent, descent; |
48 | 48 | int alignment; |
49 | 49 | int wrapWidth; |
@@ -310,6 +310,8 @@ public TextLayout (Device device) { |
310 | 310 | styles[1] = new StyleItem(); |
311 | 311 | stylesCount = 2; |
312 | 312 | text = ""; //$NON-NLS-1$ |
| 313 | + previousCountNextLine = 0; |
| 314 | + previousEnd = -1; |
313 | 315 | long[] ppv = new long[1]; |
314 | 316 | OS.OleInitialize(0); |
315 | 317 | if (COM.CoCreateInstance(COM.CLSID_CMultiLanguage, 0, COM.CLSCTX_INPROC_SERVER, COM.IID_IMLangFontLink2, ppv) == OS.S_OK) { |
@@ -2952,15 +2954,11 @@ StyleItem[] merge (long items, int itemCount) { |
2952 | 2954 | linkBefore = false; |
2953 | 2955 | } |
2954 | 2956 | char ch = segmentsText.charAt(start); |
2955 | | - switch (ch) { |
2956 | | - case '\r': |
2957 | | - case '\n': |
2958 | | - item.lineBreak = true; |
2959 | | - break; |
2960 | | - case '\t': |
2961 | | - item.tab = true; |
2962 | | - break; |
| 2957 | + if (ch == '\r' && start + 1 < end) { |
| 2958 | + ch = segmentsText.charAt(start + 1); |
2963 | 2959 | } |
| 2960 | + item.lineBreak = ch == '\n'; |
| 2961 | + item.tab = ch == '\t'; |
2964 | 2962 | if (itemLimit == -1) { |
2965 | 2963 | nextItemIndex = itemIndex + 1; |
2966 | 2964 | OS.MoveMemory(scriptItem, items + nextItemIndex * SCRIPT_ITEM.sizeof, SCRIPT_ITEM.sizeof); |
@@ -3451,6 +3449,28 @@ public void setStyle (TextStyle style, int start, int end) { |
3451 | 3449 | int length = text.length(); |
3452 | 3450 | if (length == 0) return; |
3453 | 3451 | if (start > end) return; |
| 3452 | + int countNextLine = 0, noStyleCountNextLine = 0, loop = 0; |
| 3453 | + if (previousEnd < 0) |
| 3454 | + loop = previousEnd+1; |
| 3455 | + else |
| 3456 | + loop = previousEnd; |
| 3457 | + for (int i = loop; i < end; i++) { |
| 3458 | + if (originalText.charAt(i) == '\r' && originalText.charAt(i+1) =='\n') |
| 3459 | + { |
| 3460 | + countNextLine++; |
| 3461 | + if (i < start) |
| 3462 | + noStyleCountNextLine++; |
| 3463 | + } |
| 3464 | + } |
| 3465 | + previousCountNextLine = previousCountNextLine + countNextLine; |
| 3466 | + if (start == 0 || previousEnd < 0) { |
| 3467 | + start = start - noStyleCountNextLine; |
| 3468 | + } |
| 3469 | + else { |
| 3470 | + start = start - previousCountNextLine; |
| 3471 | + } |
| 3472 | + previousEnd = end; |
| 3473 | + end = end - previousCountNextLine; |
3454 | 3474 | start = Math.min(Math.max(0, start), length - 1); |
3455 | 3475 | end = Math.min(Math.max(0, end), length - 1); |
3456 | 3476 | int low = -1; |
@@ -3564,6 +3584,13 @@ public void setTabs (int[] tabs) { |
3564 | 3584 | */ |
3565 | 3585 | public void setText (String text) { |
3566 | 3586 | checkLayout(); |
| 3587 | + |
| 3588 | + this.originalText = text; |
| 3589 | + String[] strings = text.split("\r"); |
| 3590 | + text = ""; |
| 3591 | + for(int i = 0; i < strings.length; i++) |
| 3592 | + text += strings[i]; |
| 3593 | + |
3567 | 3594 | if (text == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); |
3568 | 3595 | if (text.equals(this.text)) return; |
3569 | 3596 | freeRuns(); |
|
0 commit comments