-
Notifications
You must be signed in to change notification settings - Fork 170
/
EditView.cxx
2543 lines (2320 loc) · 105 KB
/
EditView.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Scintilla source code edit control
/** @file EditView.cxx
** Defines the appearance of the main text area of the editor window.
**/
// Copyright 1998-2014 by Neil Hodgson <neilh@scintilla.org>
// The License.txt file describes the conditions under which this software may be distributed.
#include <cstddef>
#include <cstdlib>
#include <cassert>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <stdexcept>
#include <string>
#include <string_view>
#include <vector>
#include <map>
#include <forward_list>
#include <algorithm>
#include <iterator>
#include <memory>
#include <chrono>
#include "Platform.h"
#include "ILoader.h"
#include "ILexer.h"
#include "Scintilla.h"
#include "CharacterSet.h"
#include "Position.h"
#include "IntegerRectangle.h"
#include "UniqueString.h"
#include "SplitVector.h"
#include "Partitioning.h"
#include "RunStyles.h"
#include "ContractionState.h"
#include "CellBuffer.h"
#include "PerLine.h"
#include "KeyMap.h"
#include "Indicator.h"
#include "LineMarker.h"
#include "Style.h"
#include "ViewStyle.h"
#include "CharClassify.h"
#include "Decoration.h"
#include "CaseFolder.h"
#include "Document.h"
#include "UniConversion.h"
#include "Selection.h"
#include "PositionCache.h"
#include "EditModel.h"
#include "MarginView.h"
#include "EditView.h"
#include "ElapsedPeriod.h"
using namespace Scintilla;
static constexpr bool IsControlCharacter(int ch) noexcept {
// iscntrl returns true for lots of chars > 127 which are displayable
return ch >= 0 && ch < ' ';
}
PrintParameters::PrintParameters() noexcept {
magnification = 100;
colourMode = SC_PRINT_NORMAL;
wrapState = eWrapWord;
}
namespace Scintilla {
bool ValidStyledText(const ViewStyle &vs, size_t styleOffset, const StyledText &st) noexcept {
if (st.multipleStyles) {
for (size_t iStyle = 0; iStyle < st.length; iStyle++) {
if (!vs.ValidStyle(styleOffset + st.styles[iStyle]))
return false;
}
} else {
if (!vs.ValidStyle(styleOffset + st.style))
return false;
}
return true;
}
int WidthStyledText(Surface *surface, const ViewStyle &vs, int styleOffset,
const char *text, const unsigned char *styles, size_t len) {
int width = 0;
size_t start = 0;
while (start < len) {
const unsigned char style = styles[start];
size_t endSegment = start;
while ((endSegment + 1 < len) && (styles[endSegment + 1] == style)) {
endSegment++;
}
FontAlias fontText = vs.styles[style + styleOffset].font;
const std::string_view sv(text + start, endSegment - start + 1);
width += static_cast<int>(surface->WidthText(fontText, sv));
start = endSegment + 1;
}
return width;
}
int WidestLineWidth(Surface *surface, const ViewStyle &vs, int styleOffset, const StyledText &st) {
int widthMax = 0;
size_t start = 0;
while (start < st.length) {
const size_t lenLine = st.LineLength(start);
int widthSubLine;
if (st.multipleStyles) {
widthSubLine = WidthStyledText(surface, vs, styleOffset, st.text + start, st.styles + start, lenLine);
} else {
FontAlias fontText = vs.styles[styleOffset + st.style].font;
const std::string_view text(st.text + start, lenLine);
widthSubLine = static_cast<int>(surface->WidthText(fontText, text));
}
if (widthSubLine > widthMax)
widthMax = widthSubLine;
start += lenLine + 1;
}
return widthMax;
}
void DrawTextNoClipPhase(Surface *surface, PRectangle rc, const Style &style, XYPOSITION ybase,
std::string_view text, DrawPhase phase) {
FontAlias fontText = style.font;
if (phase & drawBack) {
if (phase & drawText) {
// Drawing both
surface->DrawTextNoClip(rc, fontText, ybase, text,
style.fore, style.back);
} else {
surface->FillRectangle(rc, style.back);
}
} else if (phase & drawText) {
surface->DrawTextTransparent(rc, fontText, ybase, text, style.fore);
}
}
void DrawStyledText(Surface *surface, const ViewStyle &vs, int styleOffset, PRectangle rcText,
const StyledText &st, size_t start, size_t length, DrawPhase phase) {
if (st.multipleStyles) {
int x = static_cast<int>(rcText.left);
size_t i = 0;
while (i < length) {
size_t end = i;
size_t style = st.styles[i + start];
while (end < length - 1 && st.styles[start + end + 1] == style) {
end++;
}
style += styleOffset;
FontAlias fontText = vs.styles[style].font;
const std::string_view text(st.text + start + i, end - i + 1);
const int width = static_cast<int>(surface->WidthText(fontText, text));
PRectangle rcSegment = rcText;
rcSegment.left = static_cast<XYPOSITION>(x);
rcSegment.right = static_cast<XYPOSITION>(x + width + 1);
DrawTextNoClipPhase(surface, rcSegment, vs.styles[style],
rcText.top + vs.maxAscent, text, phase);
x += width;
i = end + 1;
}
} else {
const size_t style = st.style + styleOffset;
DrawTextNoClipPhase(surface, rcText, vs.styles[style],
rcText.top + vs.maxAscent,
std::string_view(st.text + start, length), phase);
}
}
}
const XYPOSITION epsilon = 0.0001f; // A small nudge to avoid floating point precision issues
EditView::EditView() {
tabWidthMinimumPixels = 2; // needed for calculating tab stops for fractional proportional fonts
hideSelection = false;
drawOverstrikeCaret = true;
bufferedDraw = true;
phasesDraw = phasesTwo;
lineWidthMaxSeen = 0;
additionalCaretsBlink = true;
additionalCaretsVisible = true;
imeCaretBlockOverride = false;
llc.SetLevel(LineLayoutCache::llcCaret);
tabArrowHeight = 4;
customDrawTabArrow = nullptr;
customDrawWrapMarker = nullptr;
}
EditView::~EditView() = default;
bool EditView::SetTwoPhaseDraw(bool twoPhaseDraw) noexcept {
const PhasesDraw phasesDrawNew = twoPhaseDraw ? phasesTwo : phasesOne;
const bool redraw = phasesDraw != phasesDrawNew;
phasesDraw = phasesDrawNew;
return redraw;
}
bool EditView::SetPhasesDraw(int phases) noexcept {
const PhasesDraw phasesDrawNew = static_cast<PhasesDraw>(phases);
const bool redraw = phasesDraw != phasesDrawNew;
phasesDraw = phasesDrawNew;
return redraw;
}
bool EditView::LinesOverlap() const noexcept {
return phasesDraw == phasesMultiple;
}
void EditView::ClearAllTabstops() noexcept {
ldTabstops.reset();
}
XYPOSITION EditView::NextTabstopPos(Sci::Line line, XYPOSITION x, XYPOSITION tabWidth) const noexcept {
const int next = GetNextTabstop(line, static_cast<int>(x + tabWidthMinimumPixels));
if (next > 0)
return static_cast<XYPOSITION>(next);
return (static_cast<int>((x + tabWidthMinimumPixels) / tabWidth) + 1) * tabWidth;
}
bool EditView::ClearTabstops(Sci::Line line) noexcept {
return ldTabstops && ldTabstops->ClearTabstops(line);
}
bool EditView::AddTabstop(Sci::Line line, int x) {
if (!ldTabstops) {
ldTabstops = std::make_unique<LineTabstops>();
}
return ldTabstops && ldTabstops->AddTabstop(line, x);
}
int EditView::GetNextTabstop(Sci::Line line, int x) const noexcept {
if (ldTabstops) {
return ldTabstops->GetNextTabstop(line, x);
} else {
return 0;
}
}
void EditView::LinesAddedOrRemoved(Sci::Line lineOfPos, Sci::Line linesAdded) {
if (ldTabstops) {
if (linesAdded > 0) {
for (Sci::Line line = lineOfPos; line < lineOfPos + linesAdded; line++) {
ldTabstops->InsertLine(line);
}
} else {
for (Sci::Line line = (lineOfPos + -linesAdded) - 1; line >= lineOfPos; line--) {
ldTabstops->RemoveLine(line);
}
}
}
}
void EditView::DropGraphics(bool freeObjects) noexcept {
if (freeObjects) {
pixmapLine.reset();
pixmapIndentGuide.reset();
pixmapIndentGuideHighlight.reset();
} else {
if (pixmapLine)
pixmapLine->Release();
if (pixmapIndentGuide)
pixmapIndentGuide->Release();
if (pixmapIndentGuideHighlight)
pixmapIndentGuideHighlight->Release();
}
}
void EditView::AllocateGraphics(const ViewStyle &vsDraw) {
if (!pixmapLine)
pixmapLine.reset(Surface::Allocate(vsDraw.technology));
if (!pixmapIndentGuide)
pixmapIndentGuide.reset(Surface::Allocate(vsDraw.technology));
if (!pixmapIndentGuideHighlight)
pixmapIndentGuideHighlight.reset(Surface::Allocate(vsDraw.technology));
}
static const char *ControlCharacterString(unsigned char ch) noexcept {
static const char * const reps[] = {
"NUL", "SOH", "STX", "ETX", "EOT", "ENQ", "ACK", "BEL",
"BS", "HT", "LF", "VT", "FF", "CR", "SO", "SI",
"DLE", "DC1", "DC2", "DC3", "DC4", "NAK", "SYN", "ETB",
"CAN", "EM", "SUB", "ESC", "FS", "GS", "RS", "US"
};
if (ch < std::size(reps)) {
return reps[ch];
} else {
return "BAD";
}
}
static void DrawTabArrow(Surface *surface, PRectangle rcTab, int ymid, const ViewStyle &vsDraw) noexcept {
const IntegerRectangle ircTab(rcTab);
if ((rcTab.left + 2) < (rcTab.right - 1))
surface->MoveTo(ircTab.left + 2, ymid);
else
surface->MoveTo(ircTab.right - 1, ymid);
surface->LineTo(ircTab.right - 1, ymid);
// Draw the arrow head if needed
if (vsDraw.tabDrawMode == tdLongArrow) {
int ydiff = (ircTab.bottom - ircTab.top) / 2;
int xhead = ircTab.right - 1 - ydiff;
if (xhead <= rcTab.left) {
ydiff -= ircTab.left - xhead - 1;
xhead = ircTab.left - 1;
}
surface->LineTo(xhead, ymid - ydiff);
surface->MoveTo(ircTab.right - 1, ymid);
surface->LineTo(xhead, ymid + ydiff);
}
}
void EditView::RefreshPixMaps(Surface *surfaceWindow, WindowID wid, const ViewStyle &vsDraw) {
if (!pixmapIndentGuide->Initialised()) {
// 1 extra pixel in height so can handle odd/even positions and so produce a continuous line
pixmapIndentGuide->InitPixMap(1, vsDraw.lineHeight + 1, surfaceWindow, wid);
pixmapIndentGuideHighlight->InitPixMap(1, vsDraw.lineHeight + 1, surfaceWindow, wid);
const PRectangle rcIG = PRectangle::FromInts(0, 0, 1, vsDraw.lineHeight);
pixmapIndentGuide->FillRectangle(rcIG, vsDraw.styles[STYLE_INDENTGUIDE].back);
pixmapIndentGuide->PenColour(vsDraw.styles[STYLE_INDENTGUIDE].fore);
pixmapIndentGuideHighlight->FillRectangle(rcIG, vsDraw.styles[STYLE_BRACELIGHT].back);
pixmapIndentGuideHighlight->PenColour(vsDraw.styles[STYLE_BRACELIGHT].fore);
for (int stripe = 1; stripe < vsDraw.lineHeight + 1; stripe += 2) {
const PRectangle rcPixel = PRectangle::FromInts(0, stripe, 1, stripe + 1);
pixmapIndentGuide->FillRectangle(rcPixel, vsDraw.styles[STYLE_INDENTGUIDE].fore);
pixmapIndentGuideHighlight->FillRectangle(rcPixel, vsDraw.styles[STYLE_BRACELIGHT].fore);
}
}
}
LineLayout *EditView::RetrieveLineLayout(Sci::Line lineNumber, const EditModel &model) {
const Sci::Position posLineStart = model.pdoc->LineStart(lineNumber);
const Sci::Position posLineEnd = model.pdoc->LineStart(lineNumber + 1);
PLATFORM_ASSERT(posLineEnd >= posLineStart);
const Sci::Line lineCaret = model.pdoc->SciLineFromPosition(model.sel.MainCaret());
return llc.Retrieve(lineNumber, lineCaret,
static_cast<int>(posLineEnd - posLineStart), model.pdoc->GetStyleClock(),
model.LinesOnScreen() + 1, model.pdoc->LinesTotal());
}
/**
* Fill in the LineLayout data for the given line.
* Copy the given @a line and its styles from the document into local arrays.
* Also determine the x position at which each character starts.
*/
void EditView::LayoutLine(const EditModel &model, Sci::Line line, Surface *surface, const ViewStyle &vstyle, LineLayout *ll, int width) {
if (!ll)
return;
PLATFORM_ASSERT(line < model.pdoc->LinesTotal());
PLATFORM_ASSERT(ll->chars != nullptr);
const Sci::Position posLineStart = model.pdoc->LineStart(line);
Sci::Position posLineEnd = model.pdoc->LineStart(line + 1);
// If the line is very long, limit the treatment to a length that should fit in the viewport
if (posLineEnd > (posLineStart + ll->maxLineLength)) {
posLineEnd = posLineStart + ll->maxLineLength;
}
if (ll->validity == LineLayout::llCheckTextAndStyle) {
Sci::Position lineLength = posLineEnd - posLineStart;
if (!vstyle.viewEOL) {
lineLength = model.pdoc->LineEnd(line) - posLineStart;
}
if (lineLength == ll->numCharsInLine) {
// See if chars, styles, indicators, are all the same
bool allSame = true;
// Check base line layout
int styleByte = 0;
int numCharsInLine = 0;
while (numCharsInLine < lineLength) {
const Sci::Position charInDoc = numCharsInLine + posLineStart;
const char chDoc = model.pdoc->CharAt(charInDoc);
styleByte = model.pdoc->StyleIndexAt(charInDoc);
allSame = allSame &&
(ll->styles[numCharsInLine] == styleByte);
if (vstyle.styles[ll->styles[numCharsInLine]].caseForce == Style::caseMixed)
allSame = allSame &&
(ll->chars[numCharsInLine] == chDoc);
else if (vstyle.styles[ll->styles[numCharsInLine]].caseForce == Style::caseLower)
allSame = allSame &&
(ll->chars[numCharsInLine] == MakeLowerCase(chDoc));
else if (vstyle.styles[ll->styles[numCharsInLine]].caseForce == Style::caseUpper)
allSame = allSame &&
(ll->chars[numCharsInLine] == MakeUpperCase(chDoc));
else { // Style::caseCamel
if ((model.pdoc->IsASCIIWordByte(ll->chars[numCharsInLine])) &&
((numCharsInLine == 0) || (!model.pdoc->IsASCIIWordByte(ll->chars[numCharsInLine - 1])))) {
allSame = allSame && (ll->chars[numCharsInLine] == MakeUpperCase(chDoc));
} else {
allSame = allSame && (ll->chars[numCharsInLine] == MakeLowerCase(chDoc));
}
}
numCharsInLine++;
}
allSame = allSame && (ll->styles[numCharsInLine] == styleByte); // For eolFilled
if (allSame) {
ll->validity = LineLayout::llPositions;
} else {
ll->validity = LineLayout::llInvalid;
}
} else {
ll->validity = LineLayout::llInvalid;
}
}
if (ll->validity == LineLayout::llInvalid) {
ll->widthLine = LineLayout::wrapWidthInfinite;
ll->lines = 1;
if (vstyle.edgeState == EDGE_BACKGROUND) {
Sci::Position edgePosition = model.pdoc->FindColumn(line, vstyle.theEdge.column);
if (edgePosition >= posLineStart) {
edgePosition -= posLineStart;
}
ll->edgeColumn = static_cast<int>(edgePosition);
} else {
ll->edgeColumn = -1;
}
// Fill base line layout
const int lineLength = static_cast<int>(posLineEnd - posLineStart);
model.pdoc->GetCharRange(ll->chars.get(), posLineStart, lineLength);
model.pdoc->GetStyleRange(ll->styles.get(), posLineStart, lineLength);
const int numCharsBeforeEOL = static_cast<int>(model.pdoc->LineEnd(line) - posLineStart);
const int numCharsInLine = (vstyle.viewEOL) ? lineLength : numCharsBeforeEOL;
for (Sci::Position styleInLine = 0; styleInLine < numCharsInLine; styleInLine++) {
const unsigned char styleByte = ll->styles[styleInLine];
ll->styles[styleInLine] = styleByte;
}
const unsigned char styleByteLast = (lineLength > 0) ? ll->styles[lineLength - 1] : 0;
if (vstyle.someStylesForceCase) {
for (int charInLine = 0; charInLine < lineLength; charInLine++) {
const char chDoc = ll->chars[charInLine];
if (vstyle.styles[ll->styles[charInLine]].caseForce == Style::caseUpper)
ll->chars[charInLine] = MakeUpperCase(chDoc);
else if (vstyle.styles[ll->styles[charInLine]].caseForce == Style::caseLower)
ll->chars[charInLine] = MakeLowerCase(chDoc);
else if (vstyle.styles[ll->styles[charInLine]].caseForce == Style::caseCamel) {
if ((model.pdoc->IsASCIIWordByte(ll->chars[charInLine])) &&
((charInLine == 0) || (!model.pdoc->IsASCIIWordByte(ll->chars[charInLine - 1])))) {
ll->chars[charInLine] = MakeUpperCase(chDoc);
} else {
ll->chars[charInLine] = MakeLowerCase(chDoc);
}
}
}
}
ll->xHighlightGuide = 0;
// Extra element at the end of the line to hold end x position and act as
ll->chars[numCharsInLine] = 0; // Also triggers processing in the loops as this is a control character
ll->styles[numCharsInLine] = styleByteLast; // For eolFilled
// Layout the line, determining the position of each character,
// with an extra element at the end for the end of the line.
ll->positions[0] = 0;
bool lastSegItalics = false;
BreakFinder bfLayout(ll, nullptr, Range(0, numCharsInLine), posLineStart, 0, false, model.pdoc, &model.reprs, nullptr);
while (bfLayout.More()) {
const TextSegment ts = bfLayout.Next();
std::fill(&ll->positions[ts.start + 1], &ll->positions[ts.end() + 1], 0.0f);
if (vstyle.styles[ll->styles[ts.start]].visible) {
if (ts.representation) {
XYPOSITION representationWidth = vstyle.controlCharWidth;
if (ll->chars[ts.start] == '\t') {
// Tab is a special case of representation, taking a variable amount of space
const XYPOSITION x = ll->positions[ts.start];
representationWidth = NextTabstopPos(line, x, vstyle.tabWidth) - ll->positions[ts.start];
} else {
if (representationWidth <= 0.0) {
XYPOSITION positionsRepr[256]; // Should expand when needed
posCache.MeasureWidths(surface, vstyle, STYLE_CONTROLCHAR, ts.representation->stringRep.c_str(),
static_cast<unsigned int>(ts.representation->stringRep.length()), positionsRepr, model.pdoc);
representationWidth = positionsRepr[ts.representation->stringRep.length() - 1] + vstyle.ctrlCharPadding;
}
}
for (int ii = 0; ii < ts.length; ii++) {
ll->positions[ts.start + 1 + ii] = representationWidth;
}
} else {
if ((ts.length == 1) && (' ' == ll->chars[ts.start])) {
// Over half the segments are single characters and of these about half are space characters.
ll->positions[ts.start + 1] = vstyle.styles[ll->styles[ts.start]].spaceWidth;
} else {
posCache.MeasureWidths(surface, vstyle, ll->styles[ts.start], &ll->chars[ts.start],
ts.length, &ll->positions[ts.start + 1], model.pdoc);
}
}
lastSegItalics = (!ts.representation) && ((ll->chars[ts.end() - 1] != ' ') && vstyle.styles[ll->styles[ts.start]].italic);
}
for (Sci::Position posToIncrease = ts.start + 1; posToIncrease <= ts.end(); posToIncrease++) {
ll->positions[posToIncrease] += ll->positions[ts.start];
}
}
// Small hack to make lines that end with italics not cut off the edge of the last character
if (lastSegItalics) {
ll->positions[numCharsInLine] += vstyle.lastSegItalicsOffset;
}
ll->numCharsInLine = numCharsInLine;
ll->numCharsBeforeEOL = numCharsBeforeEOL;
ll->validity = LineLayout::llPositions;
}
// Hard to cope when too narrow, so just assume there is space
if (width < 20) {
width = 20;
}
if ((ll->validity == LineLayout::llPositions) || (ll->widthLine != width)) {
ll->widthLine = width;
if (width == LineLayout::wrapWidthInfinite) {
ll->lines = 1;
} else if (width > ll->positions[ll->numCharsInLine]) {
// Simple common case where line does not need wrapping.
ll->lines = 1;
} else {
if (vstyle.wrapVisualFlags & SC_WRAPVISUALFLAG_END) {
width -= static_cast<int>(vstyle.aveCharWidth); // take into account the space for end wrap mark
}
XYPOSITION wrapAddIndent = 0; // This will be added to initial indent of line
switch (vstyle.wrapIndentMode) {
case SC_WRAPINDENT_FIXED:
wrapAddIndent = vstyle.wrapVisualStartIndent * vstyle.aveCharWidth;
break;
case SC_WRAPINDENT_INDENT:
wrapAddIndent = model.pdoc->IndentSize() * vstyle.spaceWidth;
break;
case SC_WRAPINDENT_DEEPINDENT:
wrapAddIndent = model.pdoc->IndentSize() * 2 * vstyle.spaceWidth;
break;
}
ll->wrapIndent = wrapAddIndent;
if (vstyle.wrapIndentMode != SC_WRAPINDENT_FIXED) {
for (int i = 0; i < ll->numCharsInLine; i++) {
if (!IsSpaceOrTab(ll->chars[i])) {
ll->wrapIndent += ll->positions[i]; // Add line indent
break;
}
}
}
// Check for text width minimum
if (ll->wrapIndent > width - static_cast<int>(vstyle.aveCharWidth) * 15)
ll->wrapIndent = wrapAddIndent;
// Check for wrapIndent minimum
if ((vstyle.wrapVisualFlags & SC_WRAPVISUALFLAG_START) && (ll->wrapIndent < vstyle.aveCharWidth))
ll->wrapIndent = vstyle.aveCharWidth; // Indent to show start visual
ll->lines = 0;
// Calculate line start positions based upon width.
Sci::Position lastGoodBreak = 0;
Sci::Position lastLineStart = 0;
XYACCUMULATOR startOffset = 0;
Sci::Position p = 0;
while (p < ll->numCharsInLine) {
if ((ll->positions[p + 1] - startOffset) >= width) {
if (lastGoodBreak == lastLineStart) {
// Try moving to start of last character
if (p > 0) {
lastGoodBreak = model.pdoc->MovePositionOutsideChar(p + posLineStart, -1)
- posLineStart;
}
if (lastGoodBreak == lastLineStart) {
// Ensure at least one character on line.
lastGoodBreak = model.pdoc->MovePositionOutsideChar(lastGoodBreak + posLineStart + 1, 1)
- posLineStart;
}
}
lastLineStart = lastGoodBreak;
ll->lines++;
ll->SetLineStart(ll->lines, static_cast<int>(lastGoodBreak));
startOffset = ll->positions[lastGoodBreak];
// take into account the space for start wrap mark and indent
startOffset -= ll->wrapIndent;
p = lastGoodBreak + 1;
continue;
}
if (p > 0) {
if (vstyle.wrapState == eWrapChar) {
lastGoodBreak = model.pdoc->MovePositionOutsideChar(p + posLineStart, -1)
- posLineStart;
p = model.pdoc->MovePositionOutsideChar(p + 1 + posLineStart, 1) - posLineStart;
continue;
} else if ((vstyle.wrapState == eWrapWord) && (ll->styles[p] != ll->styles[p - 1])) {
lastGoodBreak = p;
} else if (IsSpaceOrTab(ll->chars[p - 1]) && !IsSpaceOrTab(ll->chars[p])) {
lastGoodBreak = p;
}
}
p++;
}
ll->lines++;
}
ll->validity = LineLayout::llLines;
}
}
// Fill the LineLayout bidirectional data fields according to each char style
void EditView::UpdateBidiData(const EditModel &model, const ViewStyle &vstyle, LineLayout *ll) {
if (model.BidirectionalEnabled()) {
ll->EnsureBidiData();
for (int stylesInLine = 0; stylesInLine < ll->numCharsInLine; stylesInLine++) {
ll->bidiData->stylesFonts[stylesInLine].MakeAlias(vstyle.styles[ll->styles[stylesInLine]].font);
}
ll->bidiData->stylesFonts[ll->numCharsInLine].ClearFont();
for (int charsInLine = 0; charsInLine < ll->numCharsInLine; charsInLine++) {
const int charWidth = UTF8DrawBytes(reinterpret_cast<unsigned char *>(&ll->chars[charsInLine]), ll->numCharsInLine - charsInLine);
const Representation *repr = model.reprs.RepresentationFromCharacter(&ll->chars[charsInLine], charWidth);
ll->bidiData->widthReprs[charsInLine] = 0.0f;
if (repr && ll->chars[charsInLine] != '\t') {
ll->bidiData->widthReprs[charsInLine] = ll->positions[charsInLine + charWidth] - ll->positions[charsInLine];
}
if (charWidth > 1) {
for (int c = 1; c < charWidth; c++) {
charsInLine++;
ll->bidiData->widthReprs[charsInLine] = 0.0f;
}
}
}
ll->bidiData->widthReprs[ll->numCharsInLine] = 0.0f;
} else {
ll->bidiData.reset();
}
}
Point EditView::LocationFromPosition(Surface *surface, const EditModel &model, SelectionPosition pos, Sci::Line topLine,
const ViewStyle &vs, PointEnd pe, PRectangle rcClient) {
Point pt;
if (pos.Position() == INVALID_POSITION)
return pt;
Sci::Line lineDoc = model.pdoc->SciLineFromPosition(pos.Position());
Sci::Position posLineStart = model.pdoc->LineStart(lineDoc);
if ((pe & peLineEnd) && (lineDoc > 0) && (pos.Position() == posLineStart)) {
// Want point at end of first line
lineDoc--;
posLineStart = model.pdoc->LineStart(lineDoc);
}
const Sci::Line lineVisible = model.pcs->DisplayFromDoc(lineDoc);
AutoLineLayout ll(llc, RetrieveLineLayout(lineDoc, model));
if (surface && ll) {
LayoutLine(model, lineDoc, surface, vs, ll, model.wrapWidth);
const int posInLine = static_cast<int>(pos.Position() - posLineStart);
pt = ll->PointFromPosition(posInLine, vs.lineHeight, pe);
pt.x += vs.textStart - model.xOffset;
if (model.BidirectionalEnabled()) {
// Fill the line bidi data
UpdateBidiData(model, vs, ll);
// Find subLine
const int subLine = ll->SubLineFromPosition(posInLine, pe);
const int caretPosition = posInLine - ll->LineStart(subLine);
// Get the point from current position
const ScreenLine screenLine(ll, subLine, vs, rcClient.right, tabWidthMinimumPixels);
std::unique_ptr<IScreenLineLayout> slLayout = surface->Layout(&screenLine);
pt.x = slLayout->XFromPosition(caretPosition);
pt.x += vs.textStart - model.xOffset;
pt.y = 0;
if (posInLine >= ll->LineStart(subLine)) {
pt.y = static_cast<XYPOSITION>(subLine*vs.lineHeight);
}
}
pt.y += (lineVisible - topLine) * vs.lineHeight;
}
pt.x += pos.VirtualSpace() * vs.styles[ll->EndLineStyle()].spaceWidth;
return pt;
}
Range EditView::RangeDisplayLine(Surface *surface, const EditModel &model, Sci::Line lineVisible, const ViewStyle &vs) {
Range rangeSubLine = Range(0, 0);
if (lineVisible < 0) {
return rangeSubLine;
}
const Sci::Line lineDoc = model.pcs->DocFromDisplay(lineVisible);
const Sci::Position positionLineStart = model.pdoc->LineStart(lineDoc);
AutoLineLayout ll(llc, RetrieveLineLayout(lineDoc, model));
if (surface && ll) {
LayoutLine(model, lineDoc, surface, vs, ll, model.wrapWidth);
const Sci::Line lineStartSet = model.pcs->DisplayFromDoc(lineDoc);
const int subLine = static_cast<int>(lineVisible - lineStartSet);
if (subLine < ll->lines) {
rangeSubLine = ll->SubLineRange(subLine, LineLayout::Scope::visibleOnly);
if (subLine == ll->lines - 1) {
rangeSubLine.end = model.pdoc->LineStart(lineDoc + 1) -
positionLineStart;
}
}
}
rangeSubLine.start += positionLineStart;
rangeSubLine.end += positionLineStart;
return rangeSubLine;
}
SelectionPosition EditView::SPositionFromLocation(Surface *surface, const EditModel &model, PointDocument pt, bool canReturnInvalid,
bool charPosition, bool virtualSpace, const ViewStyle &vs, PRectangle rcClient) {
pt.x = pt.x - vs.textStart;
Sci::Line visibleLine = static_cast<int>(floor(pt.y / vs.lineHeight));
if (!canReturnInvalid && (visibleLine < 0))
visibleLine = 0;
const Sci::Line lineDoc = model.pcs->DocFromDisplay(visibleLine);
if (canReturnInvalid && (lineDoc < 0))
return SelectionPosition(INVALID_POSITION);
if (lineDoc >= model.pdoc->LinesTotal())
return SelectionPosition(canReturnInvalid ? INVALID_POSITION :
model.pdoc->Length());
const Sci::Position posLineStart = model.pdoc->LineStart(lineDoc);
AutoLineLayout ll(llc, RetrieveLineLayout(lineDoc, model));
if (surface && ll) {
LayoutLine(model, lineDoc, surface, vs, ll, model.wrapWidth);
const Sci::Line lineStartSet = model.pcs->DisplayFromDoc(lineDoc);
const int subLine = static_cast<int>(visibleLine - lineStartSet);
if (subLine < ll->lines) {
const Range rangeSubLine = ll->SubLineRange(subLine, LineLayout::Scope::visibleOnly);
const XYPOSITION subLineStart = ll->positions[rangeSubLine.start];
if (subLine > 0) // Wrapped
pt.x -= ll->wrapIndent;
Sci::Position positionInLine = 0;
if (model.BidirectionalEnabled()) {
// Fill the line bidi data
UpdateBidiData(model, vs, ll);
const ScreenLine screenLine(ll, subLine, vs, rcClient.right, tabWidthMinimumPixels);
std::unique_ptr<IScreenLineLayout> slLayout = surface->Layout(&screenLine);
positionInLine = slLayout->PositionFromX(static_cast<XYPOSITION>(pt.x), charPosition) +
rangeSubLine.start;
} else {
positionInLine = ll->FindPositionFromX(static_cast<XYPOSITION>(pt.x + subLineStart),
rangeSubLine, charPosition);
}
if (positionInLine < rangeSubLine.end) {
return SelectionPosition(model.pdoc->MovePositionOutsideChar(positionInLine + posLineStart, 1));
}
if (virtualSpace) {
const XYPOSITION spaceWidth = vs.styles[ll->EndLineStyle()].spaceWidth;
const int spaceOffset = static_cast<int>(
(pt.x + subLineStart - ll->positions[rangeSubLine.end] + spaceWidth / 2) / spaceWidth);
return SelectionPosition(rangeSubLine.end + posLineStart, spaceOffset);
} else if (canReturnInvalid) {
if (pt.x < (ll->positions[rangeSubLine.end] - subLineStart)) {
return SelectionPosition(model.pdoc->MovePositionOutsideChar(rangeSubLine.end + posLineStart, 1));
}
} else {
return SelectionPosition(rangeSubLine.end + posLineStart);
}
}
if (!canReturnInvalid)
return SelectionPosition(ll->numCharsInLine + posLineStart);
}
return SelectionPosition(canReturnInvalid ? INVALID_POSITION : posLineStart);
}
/**
* Find the document position corresponding to an x coordinate on a particular document line.
* Ensure is between whole characters when document is in multi-byte or UTF-8 mode.
* This method is used for rectangular selections and does not work on wrapped lines.
*/
SelectionPosition EditView::SPositionFromLineX(Surface *surface, const EditModel &model, Sci::Line lineDoc, int x, const ViewStyle &vs) {
AutoLineLayout ll(llc, RetrieveLineLayout(lineDoc, model));
if (surface && ll) {
const Sci::Position posLineStart = model.pdoc->LineStart(lineDoc);
LayoutLine(model, lineDoc, surface, vs, ll, model.wrapWidth);
const Range rangeSubLine = ll->SubLineRange(0, LineLayout::Scope::visibleOnly);
const XYPOSITION subLineStart = ll->positions[rangeSubLine.start];
const Sci::Position positionInLine = ll->FindPositionFromX(x + subLineStart, rangeSubLine, false);
if (positionInLine < rangeSubLine.end) {
return SelectionPosition(model.pdoc->MovePositionOutsideChar(positionInLine + posLineStart, 1));
}
const XYPOSITION spaceWidth = vs.styles[ll->EndLineStyle()].spaceWidth;
const int spaceOffset = static_cast<int>(
(x + subLineStart - ll->positions[rangeSubLine.end] + spaceWidth / 2) / spaceWidth);
return SelectionPosition(rangeSubLine.end + posLineStart, spaceOffset);
}
return SelectionPosition(0);
}
Sci::Line EditView::DisplayFromPosition(Surface *surface, const EditModel &model, Sci::Position pos, const ViewStyle &vs) {
const Sci::Line lineDoc = model.pdoc->SciLineFromPosition(pos);
Sci::Line lineDisplay = model.pcs->DisplayFromDoc(lineDoc);
AutoLineLayout ll(llc, RetrieveLineLayout(lineDoc, model));
if (surface && ll) {
LayoutLine(model, lineDoc, surface, vs, ll, model.wrapWidth);
const Sci::Position posLineStart = model.pdoc->LineStart(lineDoc);
const Sci::Position posInLine = pos - posLineStart;
lineDisplay--; // To make up for first increment ahead.
for (int subLine = 0; subLine < ll->lines; subLine++) {
if (posInLine >= ll->LineStart(subLine)) {
lineDisplay++;
}
}
}
return lineDisplay;
}
Sci::Position EditView::StartEndDisplayLine(Surface *surface, const EditModel &model, Sci::Position pos, bool start, const ViewStyle &vs) {
const Sci::Line line = model.pdoc->SciLineFromPosition(pos);
AutoLineLayout ll(llc, RetrieveLineLayout(line, model));
Sci::Position posRet = INVALID_POSITION;
if (surface && ll) {
const Sci::Position posLineStart = model.pdoc->LineStart(line);
LayoutLine(model, line, surface, vs, ll, model.wrapWidth);
const Sci::Position posInLine = pos - posLineStart;
if (posInLine <= ll->maxLineLength) {
for (int subLine = 0; subLine < ll->lines; subLine++) {
if ((posInLine >= ll->LineStart(subLine)) &&
(posInLine <= ll->LineStart(subLine + 1)) &&
(posInLine <= ll->numCharsBeforeEOL)) {
if (start) {
posRet = ll->LineStart(subLine) + posLineStart;
} else {
if (subLine == ll->lines - 1)
posRet = ll->numCharsBeforeEOL + posLineStart;
else
posRet = ll->LineStart(subLine + 1) + posLineStart - 1;
}
}
}
}
}
return posRet;
}
static ColourDesired SelectionBackground(const ViewStyle &vsDraw, bool main, bool primarySelection) noexcept {
return main ?
(primarySelection ? vsDraw.selColours.back : vsDraw.selBackground2) :
vsDraw.selAdditionalBackground;
}
static ColourDesired TextBackground(const EditModel &model, const ViewStyle &vsDraw, const LineLayout *ll,
ColourOptional background, int inSelection, bool inHotspot, int styleMain, Sci::Position i) {
if (inSelection == 1) {
if (vsDraw.selColours.back.isSet && (vsDraw.selAlpha == SC_ALPHA_NOALPHA)) {
return SelectionBackground(vsDraw, true, model.primarySelection);
}
} else if (inSelection == 2) {
if (vsDraw.selColours.back.isSet && (vsDraw.selAdditionalAlpha == SC_ALPHA_NOALPHA)) {
return SelectionBackground(vsDraw, false, model.primarySelection);
}
} else {
if ((vsDraw.edgeState == EDGE_BACKGROUND) &&
(i >= ll->edgeColumn) &&
(i < ll->numCharsBeforeEOL))
return vsDraw.theEdge.colour;
if (inHotspot && vsDraw.hotspotColours.back.isSet)
return vsDraw.hotspotColours.back;
}
if (background.isSet && (styleMain != STYLE_BRACELIGHT) && (styleMain != STYLE_BRACEBAD)) {
return background;
} else {
return vsDraw.styles[styleMain].back;
}
}
void EditView::DrawIndentGuide(Surface *surface, Sci::Line lineVisible, int lineHeight, XYPOSITION start, PRectangle rcSegment, bool highlight) {
const Point from = Point::FromInts(0, ((lineVisible & 1) && (lineHeight & 1)) ? 1 : 0);
const PRectangle rcCopyArea(start + 1, rcSegment.top,
start + 2, rcSegment.bottom);
surface->Copy(rcCopyArea, from,
highlight ? *pixmapIndentGuideHighlight : *pixmapIndentGuide);
}
static void SimpleAlphaRectangle(Surface *surface, PRectangle rc, ColourDesired fill, int alpha) {
if (alpha != SC_ALPHA_NOALPHA) {
surface->AlphaRectangle(rc, 0, fill, alpha, fill, alpha, 0);
}
}
static void DrawTextBlob(Surface *surface, const ViewStyle &vsDraw, PRectangle rcSegment,
std::string_view text, ColourDesired textBack, ColourDesired textFore, bool fillBackground) {
if (rcSegment.Empty())
return;
if (fillBackground) {
surface->FillRectangle(rcSegment, textBack);
}
FontAlias ctrlCharsFont = vsDraw.styles[STYLE_CONTROLCHAR].font;
const int normalCharHeight = static_cast<int>(std::ceil(vsDraw.styles[STYLE_CONTROLCHAR].capitalHeight));
PRectangle rcCChar = rcSegment;
rcCChar.left = rcCChar.left + 1;
rcCChar.top = rcSegment.top + vsDraw.maxAscent - normalCharHeight;
rcCChar.bottom = rcSegment.top + vsDraw.maxAscent + 1;
PRectangle rcCentral = rcCChar;
rcCentral.top++;
rcCentral.bottom--;
surface->FillRectangle(rcCentral, textFore);
PRectangle rcChar = rcCChar;
rcChar.left++;
rcChar.right--;
surface->DrawTextClipped(rcChar, ctrlCharsFont,
rcSegment.top + vsDraw.maxAscent, text,
textBack, textFore);
}
static void DrawFrame(Surface *surface, ColourDesired colour, int alpha, PRectangle rcFrame) {
if (alpha != SC_ALPHA_NOALPHA)
surface->AlphaRectangle(rcFrame, 0, colour, alpha, colour, alpha, 0);
else
surface->FillRectangle(rcFrame, colour);
}
static void DrawCaretLineFramed(Surface *surface, const ViewStyle &vsDraw, const LineLayout *ll, PRectangle rcLine, int subLine) {
const int width = vsDraw.GetFrameWidth();
if (subLine == 0 || ll->wrapIndent == 0 || vsDraw.caretLineAlpha != SC_ALPHA_NOALPHA) {
// Left
DrawFrame(surface, vsDraw.caretLineBackground, vsDraw.caretLineAlpha,
PRectangle(rcLine.left, rcLine.top, rcLine.left + width, rcLine.bottom));
}
if (subLine == 0) {
// Top
DrawFrame(surface, vsDraw.caretLineBackground, vsDraw.caretLineAlpha,
PRectangle(rcLine.left + width, rcLine.top, rcLine.right - width, rcLine.top + width));
}
if (subLine == ll->lines - 1 || vsDraw.caretLineAlpha != SC_ALPHA_NOALPHA) {
// Right
DrawFrame(surface, vsDraw.caretLineBackground, vsDraw.caretLineAlpha,
PRectangle(rcLine.right - width, rcLine.top, rcLine.right, rcLine.bottom));
}
if (subLine == ll->lines - 1) {
// Bottom
DrawFrame(surface, vsDraw.caretLineBackground, vsDraw.caretLineAlpha,
PRectangle(rcLine.left + width, rcLine.bottom - width, rcLine.right - width, rcLine.bottom));
}
}
void EditView::DrawEOL(Surface *surface, const EditModel &model, const ViewStyle &vsDraw, const LineLayout *ll,
PRectangle rcLine, Sci::Line line, Sci::Position lineEnd, int xStart, int subLine, XYACCUMULATOR subLineStart,
ColourOptional background) {
const Sci::Position posLineStart = model.pdoc->LineStart(line);
PRectangle rcSegment = rcLine;
const bool lastSubLine = subLine == (ll->lines - 1);
XYPOSITION virtualSpace = 0;
if (lastSubLine) {
const XYPOSITION spaceWidth = vsDraw.styles[ll->EndLineStyle()].spaceWidth;
virtualSpace = model.sel.VirtualSpaceFor(model.pdoc->LineEnd(line)) * spaceWidth;
}
const XYPOSITION xEol = static_cast<XYPOSITION>(ll->positions[lineEnd] - subLineStart);
// Fill the virtual space and show selections within it
if (virtualSpace > 0.0f) {
rcSegment.left = xEol + xStart;
rcSegment.right = xEol + xStart + virtualSpace;
surface->FillRectangle(rcSegment, background.isSet ? background : vsDraw.styles[ll->styles[ll->numCharsInLine]].back);
if (!hideSelection && ((vsDraw.selAlpha == SC_ALPHA_NOALPHA) || (vsDraw.selAdditionalAlpha == SC_ALPHA_NOALPHA))) {
const SelectionSegment virtualSpaceRange(SelectionPosition(model.pdoc->LineEnd(line)),
SelectionPosition(model.pdoc->LineEnd(line),
model.sel.VirtualSpaceFor(model.pdoc->LineEnd(line))));
for (size_t r = 0; r < model.sel.Count(); r++) {
const int alpha = (r == model.sel.Main()) ? vsDraw.selAlpha : vsDraw.selAdditionalAlpha;
if (alpha == SC_ALPHA_NOALPHA) {
const SelectionSegment portion = model.sel.Range(r).Intersect(virtualSpaceRange);
if (!portion.Empty()) {
const XYPOSITION spaceWidth = vsDraw.styles[ll->EndLineStyle()].spaceWidth;
rcSegment.left = xStart + ll->positions[portion.start.Position() - posLineStart] -
static_cast<XYPOSITION>(subLineStart) + portion.start.VirtualSpace() * spaceWidth;
rcSegment.right = xStart + ll->positions[portion.end.Position() - posLineStart] -
static_cast<XYPOSITION>(subLineStart) + portion.end.VirtualSpace() * spaceWidth;
rcSegment.left = (rcSegment.left > rcLine.left) ? rcSegment.left : rcLine.left;
rcSegment.right = (rcSegment.right < rcLine.right) ? rcSegment.right : rcLine.right;
surface->FillRectangle(rcSegment, SelectionBackground(vsDraw, r == model.sel.Main(), model.primarySelection));
}
}
}
}
}
int eolInSelection = 0;
int alpha = SC_ALPHA_NOALPHA;
if (!hideSelection) {
const Sci::Position posAfterLineEnd = model.pdoc->LineStart(line + 1);
eolInSelection = lastSubLine ? model.sel.InSelectionForEOL(posAfterLineEnd) : 0;
alpha = (eolInSelection == 1) ? vsDraw.selAlpha : vsDraw.selAdditionalAlpha;
}
// Draw the [CR], [LF], or [CR][LF] blobs if visible line ends are on
XYPOSITION blobsWidth = 0;
if (lastSubLine) {
for (Sci::Position eolPos = ll->numCharsBeforeEOL; eolPos < ll->numCharsInLine; eolPos++) {
rcSegment.left = xStart + ll->positions[eolPos] - static_cast<XYPOSITION>(subLineStart) + virtualSpace;
rcSegment.right = xStart + ll->positions[eolPos + 1] - static_cast<XYPOSITION>(subLineStart) + virtualSpace;
blobsWidth += rcSegment.Width();
char hexits[4] = "";
const char *ctrlChar;
const unsigned char chEOL = ll->chars[eolPos];
const int styleMain = ll->styles[eolPos];
const ColourDesired textBack = TextBackground(model, vsDraw, ll, background, eolInSelection, false, styleMain, eolPos);
if (UTF8IsAscii(chEOL)) {
ctrlChar = ControlCharacterString(chEOL);
} else {
const Representation *repr = model.reprs.RepresentationFromCharacter(&ll->chars[eolPos], ll->numCharsInLine - eolPos);
if (repr) {
ctrlChar = repr->stringRep.c_str();
eolPos = ll->numCharsInLine;
} else {