aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/ViewStyle.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'src/ViewStyle.cxx')
-rw-r--r--src/ViewStyle.cxx19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/ViewStyle.cxx b/src/ViewStyle.cxx
index 33b861445..47f76d357 100644
--- a/src/ViewStyle.cxx
+++ b/src/ViewStyle.cxx
@@ -18,6 +18,7 @@
#include <optional>
#include <algorithm>
#include <memory>
+#include <numeric>
#include "ScintillaTypes.h"
@@ -64,6 +65,24 @@ void FontRealised::Realise(Surface &surface, int zoomLevel, Technology technolog
capitalHeight = surface.Ascent(font.get()) - surface.InternalLeading(font.get());
aveCharWidth = surface.AverageCharWidth(font.get());
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<XYPOSITION> positions(allASCIIGraphic.length());
+ surface.MeasureWidths(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());
+ const XYPOSITION variance = maxWidth - minWidth;
+ const XYPOSITION scaledVariance = variance / aveCharWidth;
+ constexpr XYPOSITION monospaceWidthEpsilon = 0.000001; // May need tweaking if monospace fonts vary more
+ monospaceASCII = scaledVariance < monospaceWidthEpsilon;
+ } else {
+ monospaceASCII = false;
+ }
}
ViewStyle::ViewStyle() : markers(MarkerMax + 1), indicators(static_cast<size_t>(IndicatorNumbers::Max) + 1) {