From a4ed33d6e60725d8b2908e81c5e7383d36c87494 Mon Sep 17 00:00:00 2001 From: Neil Date: Thu, 10 Jun 2021 16:56:08 +1000 Subject: Use the position cache when possibe for representations. --- src/EditView.cxx | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/EditView.cxx b/src/EditView.cxx index 92c1450cc..a71f385e7 100644 --- a/src/EditView.cxx +++ b/src/EditView.cxx @@ -366,6 +366,10 @@ constexpr bool IsControlCharacter(int ch) noexcept { return (ch >= 0 && ch < ' ') || (ch == 127); } +bool ViewIsASCII(std::string_view text) { + return std::all_of(text.cbegin(), text.cend(), IsASCII); +} + } /** @@ -475,7 +479,14 @@ void EditView::LayoutLine(const EditModel &model, Surface *surface, const ViewSt if (representationWidth <= 0.0) { assert(ts.representation->stringRep.length() <= Representation::maxLength); XYPOSITION positionsRepr[Representation::maxLength+1]; - surface->MeasureWidthsUTF8(vstyle.styles[StyleControlChar].font.get(), ts.representation->stringRep, positionsRepr); + // 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 ((CpUtf8 == model.pdoc->dbcsCodePage) || ViewIsASCII(ts.representation->stringRep)) { + posCache.MeasureWidths(surface, vstyle, StyleControlChar, ts.representation->stringRep, + positionsRepr); + } else { + surface->MeasureWidthsUTF8(vstyle.styles[StyleControlChar].font.get(), ts.representation->stringRep, positionsRepr); + } representationWidth = positionsRepr[ts.representation->stringRep.length() - 1]; if (FlagSet(ts.representation->appearance, RepresentationAppearance::Blob)) { representationWidth += vstyle.ctrlCharPadding; -- cgit v1.2.3