From 8c847dde89ba002a8c54fd757ae16a43247c9bd0 Mon Sep 17 00:00:00 2001 From: Zufu Liu Date: Tue, 14 Sep 2021 11:54:02 +1000 Subject: Avoid some allocations when checking whether font monospaced. --- src/ViewStyle.cxx | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/ViewStyle.cxx b/src/ViewStyle.cxx index ad1340d0d..cc65b16cb 100644 --- a/src/ViewStyle.cxx +++ b/src/ViewStyle.cxx @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -68,12 +69,12 @@ void FontRealised::Realise(Surface &surface, int zoomLevel, Technology technolog measurements.spaceWidth = surface.WidthText(font.get(), " "); if (fs.checkMonospaced) { - std::string allASCIIGraphic("Ayfi"); // "Ay" is normally strongly kerned and "fi" may be a ligature - for (unsigned char ch = 0x20; ch <= 0x7E; ch++) { - allASCIIGraphic.push_back(ch); - } - std::vector positions(allASCIIGraphic.length()); - surface.MeasureWidths(font.get(), allASCIIGraphic, positions.data()); + // "Ay" is normally strongly kerned and "fi" may be a ligature + constexpr std::string_view allASCIIGraphic("Ayfi" + // python: ''.join(chr(ch) for ch in range(32, 127)) + " !\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"); + std::array positions; + surface.MeasureWidthsUTF8(font.get(), allASCIIGraphic, positions.data()); std::adjacent_difference(positions.begin(), positions.end(), positions.begin()); const XYPOSITION maxWidth = *std::max_element(positions.begin(), positions.end()); const XYPOSITION minWidth = *std::min_element(positions.begin(), positions.end()); -- cgit v1.2.3