diff options
| author | Neil <nyamatongwe@gmail.com> | 2021-07-31 08:49:25 +1000 | 
|---|---|---|
| committer | Neil <nyamatongwe@gmail.com> | 2021-07-31 08:49:25 +1000 | 
| commit | 4d1a31d6a74019c3d43de1c33e2be093ed6dfd11 (patch) | |
| tree | d2b113b25d2cfcb751f4b5a961bb14a04261175f /src/ViewStyle.cxx | |
| parent | 297d17ace8501b23a32390163676c838dad71f9a (diff) | |
| download | scintilla-mirror-4d1a31d6a74019c3d43de1c33e2be093ed6dfd11.tar.gz | |
Implement StyleSetCheckMonospaced.
Diffstat (limited to 'src/ViewStyle.cxx')
| -rw-r--r-- | src/ViewStyle.cxx | 19 | 
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) { | 
