diff options
author | Neil <nyamatongwe@gmail.com> | 2023-01-23 14:34:17 +1100 |
---|---|---|
committer | Neil <nyamatongwe@gmail.com> | 2023-01-23 14:34:17 +1100 |
commit | 1a9af9dcdfcc8b6c1124278f3c1d9d64075ae82b (patch) | |
tree | 88b46a550d5054d2c19959607c085294b497ba0f /src/EditView.cxx | |
parent | 887da82073d4ab855a3ba95deaa652d475df21e2 (diff) | |
download | scintilla-mirror-1a9af9dcdfcc8b6c1124278f3c1d9d64075ae82b.tar.gz |
Allow UTF-8 entries to coexist in the position cache alongside the document
encoding. Elements like character representations may be in UTF-8 while the
document is in a different encoding. UTF-8 will be used for additional features
and may later be the only encoding for the position cache.
This change does not change performance or the proportion of strings cached -
its purpose is to clean up callers and prepare for greater UTF-8 use.
Diffstat (limited to 'src/EditView.cxx')
-rw-r--r-- | src/EditView.cxx | 58 |
1 files changed, 20 insertions, 38 deletions
diff --git a/src/EditView.cxx b/src/EditView.cxx index 78d38f110..79c4206b2 100644 --- a/src/EditView.cxx +++ b/src/EditView.cxx @@ -339,10 +339,6 @@ inline char CaseForce(Style::CaseForce caseForce, char chDoc, char chPrevious) n } } -bool ViewIsASCII(std::string_view text) { - return std::all_of(text.cbegin(), text.cend(), IsASCII); -} - void LayoutSegments(IPositionCache *pCache, Surface *surface, const ViewStyle &vstyle, @@ -357,58 +353,44 @@ void LayoutSegments(IPositionCache *pCache, break; } const TextSegment &ts = segments[i]; - if (vstyle.styles[ll->styles[ts.start]].visible) { + const unsigned int styleSegment = ll->styles[ts.start]; + XYPOSITION *positions = &ll->positions[ts.start + 1]; + if (vstyle.styles[styleSegment].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 - // which will be filled in later. - representationWidth = 0; - } else { + XYPOSITION representationWidth = 0.0; + // Tab is a special case of representation, taking a variable amount of space + // which will be filled in later. + if (ll->chars[ts.start] != '\t') { + representationWidth = vstyle.controlCharWidth; if (representationWidth <= 0.0) { assert(ts.representation->stringRep.length() <= Representation::maxLength); XYPOSITION positionsRepr[Representation::maxLength + 1]; - // ts.representation->stringRep is UTF-8 which only matches cache if document is UTF-8 - // or it only contains ASCII which is a subset of all currently supported encodings. - if (textUnicode || ViewIsASCII(ts.representation->stringRep)) { - pCache->MeasureWidths(surface, vstyle, StyleControlChar, ts.representation->stringRep, - positionsRepr, multiThreaded); - } else { - surface->MeasureWidthsUTF8(vstyle.styles[StyleControlChar].font.get(), ts.representation->stringRep, positionsRepr); - } + // ts.representation->stringRep is UTF-8. + pCache->MeasureWidths(surface, vstyle, StyleControlChar, true, ts.representation->stringRep, + positionsRepr, multiThreaded); representationWidth = positionsRepr[ts.representation->stringRep.length() - 1]; if (FlagSet(ts.representation->appearance, RepresentationAppearance::Blob)) { representationWidth += vstyle.ctrlCharPadding; } } } - for (int ii = 0; ii < ts.length; ii++) { - ll->positions[ts.start + 1 + ii] = representationWidth; - } + std::fill(positions, positions + ts.length, 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; + positions[0] = vstyle.styles[styleSegment].spaceWidth; } else { - pCache->MeasureWidths(surface, vstyle, ll->styles[ts.start], - std::string_view(&ll->chars[ts.start], ts.length), &ll->positions[ts.start + 1], multiThreaded); + pCache->MeasureWidths(surface, vstyle, styleSegment, textUnicode, + std::string_view(&ll->chars[ts.start], ts.length), positions, multiThreaded); } } - } else if (vstyle.styles[ll->styles[ts.start]].invisibleRepresentation[0]) { - const int styleInvisible = ll->styles[ts.start]; - const std::string_view text = vstyle.styles[styleInvisible].invisibleRepresentation; + } else if (vstyle.styles[styleSegment].invisibleRepresentation[0]) { + const std::string_view text = vstyle.styles[styleSegment].invisibleRepresentation; XYPOSITION positionsRepr[Representation::maxLength + 1]; - // invisibleRepresentation is UTF-8 which only matches cache if document is UTF-8 - // or it only contains ASCII which is a subset of all currently supported encodings. - if (textUnicode || ViewIsASCII(text)) { - pCache->MeasureWidths(surface, vstyle, styleInvisible, text, positionsRepr, multiThreaded); - } else { - surface->MeasureWidthsUTF8(vstyle.styles[styleInvisible].font.get(), text, positionsRepr); - } + // invisibleRepresentation is UTF-8. + pCache->MeasureWidths(surface, vstyle, styleSegment, true, text, positionsRepr, multiThreaded); const XYPOSITION representationWidth = positionsRepr[text.length() - 1]; - for (int ii = 0; ii < ts.length; ii++) { - ll->positions[ts.start + 1 + ii] = representationWidth; - } + std::fill(positions, positions + ts.length, representationWidth); } } } |