aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/ViewStyle.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'src/ViewStyle.cxx')
-rw-r--r--src/ViewStyle.cxx55
1 files changed, 27 insertions, 28 deletions
diff --git a/src/ViewStyle.cxx b/src/ViewStyle.cxx
index 92d084ee6..767e019f4 100644
--- a/src/ViewStyle.cxx
+++ b/src/ViewStyle.cxx
@@ -49,6 +49,8 @@ constexpr unsigned int mid = 0x80U;
constexpr unsigned int half = 0x7fU;
constexpr unsigned int quarter = 0x3fU;
+constexpr int startExtendedStyles = 0x100;
+
}
MarginStyle::MarginStyle(MarginType style_, int width_, int mask_) noexcept :
@@ -61,9 +63,8 @@ bool MarginStyle::ShowsFolding() const noexcept {
void FontRealised::Realise(Surface &surface, int zoomLevel, Technology technology, const FontSpecification &fs, const char *localeName) {
PLATFORM_ASSERT(fs.fontName);
- measurements.sizeZoomed = fs.size + zoomLevel * FontSizeMultiplier;
- if (measurements.sizeZoomed <= FontSizeMultiplier) // May fail if sizeZoomed < 1
- measurements.sizeZoomed = FontSizeMultiplier;
+ // If negative zoomLevel, ensure sizeZoomed at least minimum positive size
+ measurements.sizeZoomed = std::max(fs.size + (zoomLevel * FontSizeMultiplier), FontSizeMultiplier);
const float deviceHeight = static_cast<float>(surface.DeviceHeightFont(measurements.sizeZoomed));
const FontParameters fp(fs.fontName, deviceHeight / FontSizeMultiplier, fs.weight,
@@ -73,10 +74,11 @@ void FontRealised::Realise(Surface &surface, int zoomLevel, Technology technolog
// floor here is historical as platform layers have tweaked their values to match.
// ceil would likely be better to ensure (nearly) all of the ink of a character is seen
// but that would require platform layer changes.
- measurements.ascent = std::floor(surface.Ascent(font.get()));
+ const XYPOSITION ascent = surface.Ascent(font.get());
+ measurements.ascent = std::floor(ascent);
measurements.descent = std::floor(surface.Descent(font.get()));
- measurements.capitalHeight = surface.Ascent(font.get()) - surface.InternalLeading(font.get());
+ measurements.capitalHeight = ascent - surface.InternalLeading(font.get());
measurements.aveCharWidth = surface.AverageCharWidth(font.get());
measurements.monospaceCharacterWidth = measurements.aveCharWidth;
measurements.spaceWidth = surface.WidthText(font.get(), " ");
@@ -92,9 +94,9 @@ void FontRealised::Realise(Surface &surface, int zoomLevel, Technology technolog
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 / measurements.aveCharWidth;
constexpr XYPOSITION monospaceWidthEpsilon = 0.000001; // May need tweaking if monospace fonts vary more
- measurements.monospaceASCII = scaledVariance < monospaceWidthEpsilon;
+ const XYPOSITION scaledVariance = monospaceWidthEpsilon * minWidth;
+ measurements.monospaceASCII = variance < scaledVariance;
measurements.monospaceCharacterWidth = minWidth;
} else {
measurements.monospaceASCII = false;
@@ -107,7 +109,7 @@ ViewStyle::ViewStyle(size_t stylesSize_) :
indicators(static_cast<size_t>(IndicatorNumbers::Max) + 1),
ms(MaxMargin + 1) {
- nextExtendedStyle = 256;
+ nextExtendedStyle = startExtendedStyles;
ResetDefaultStyle();
// There are no image markers by default, so no need for calling CalcLargestMarkerHeight()
@@ -170,9 +172,11 @@ ViewStyle::ViewStyle(size_t stylesSize_) :
lineOverlap = 0;
maxAscent = 1;
maxDescent = 1;
- aveCharWidth = 8;
- spaceWidth = 8;
- tabWidth = spaceWidth * 8;
+ constexpr XYPOSITION defaultWidthChar = 8.F; // Reasonable initial approximation
+ aveCharWidth = defaultWidthChar;
+ spaceWidth = defaultWidthChar;
+ constexpr int defaultTabSpaces = 8;
+ tabWidth = spaceWidth * defaultTabSpaces;
// Default is for no selection foregrounds
// Shades of grey for selection backgrounds
@@ -220,7 +224,8 @@ ViewStyle::ViewStyle(size_t stylesSize_) :
leftMarginWidth = 1;
rightMarginWidth = 1;
ms[0] = MarginStyle(MarginType::Number);
- ms[1] = MarginStyle(MarginType::Symbol, 16, ~MaskFolders);
+ constexpr int widthMarks = 16;
+ ms[1] = MarginStyle(MarginType::Symbol, widthMarks, ~MaskFolders);
ms[2] = MarginStyle(MarginType::Symbol);
marginInside = true;
CalculateMarginWidthAndMask();
@@ -335,7 +340,7 @@ ViewStyle::~ViewStyle() = default;
void ViewStyle::CalculateMarginWidthAndMask() noexcept {
fixedColumnWidth = marginInside ? leftMarginWidth : 0;
- maskInLine = 0xffffffff;
+ maskInLine = UINT32_MAX;
int maskDefinedMarkers = 0;
for (const MarginStyle &m : ms) {
fixedColumnWidth += m.width;
@@ -413,11 +418,9 @@ void ViewStyle::Refresh(Surface &surface, int tabInChars) {
maxAscent = std::max(1.0, maxAscent + extraAscent);
maxDescent = std::max(0.0, maxDescent + extraDescent);
lineHeight = static_cast<int>(std::lround(maxAscent + maxDescent));
- lineOverlap = lineHeight / 10;
- if (lineOverlap < 2)
- lineOverlap = 2;
- if (lineOverlap > lineHeight)
- lineOverlap = lineHeight;
+ // lineHeight may rarely be less than 2, so can't use std::clamp
+ constexpr int overlapFraction = 10; // Allow up to a tenth of a line overlap
+ lineOverlap = std::min(std::max(lineHeight / overlapFraction, 2), lineHeight);
someStylesProtected = std::any_of(styles.cbegin(), styles.cend(),
[](const Style &style) noexcept { return style.IsProtected(); });
@@ -430,7 +433,7 @@ void ViewStyle::Refresh(Surface &surface, int tabInChars) {
tabWidth = spaceWidth * tabInChars;
controlCharWidth = 0.0;
- if (controlCharSymbol >= 32) {
+ if (controlCharSymbol >= ' ') {
const char cc[2] = { static_cast<char>(controlCharSymbol), '\0' };
controlCharWidth = surface.WidthText(styles[StyleControlChar].font.get(), cc);
}
@@ -440,7 +443,7 @@ void ViewStyle::Refresh(Surface &surface, int tabInChars) {
}
void ViewStyle::ReleaseAllExtendedStyles() noexcept {
- nextExtendedStyle = 256;
+ nextExtendedStyle = startExtendedStyles;
}
int ViewStyle::AllocateExtendedStyles(int numberStyles) {
@@ -571,9 +574,8 @@ ColourOptional ViewStyle::Background(int marksOfLine, bool caretActive, bool lin
}
if (background) {
return background->Opaque();
- } else {
- return {};
}
+ return {};
}
bool ViewStyle::SelectionBackgroundDrawn() const noexcept {
@@ -671,9 +673,8 @@ bool ViewStyle::SetElementColour(Element element, ColourRGBA colour) {
bool ViewStyle::SetElementColourOptional(Element element, uptr_t wParam, sptr_t lParam) {
if (wParam) {
return SetElementColour(element, ColourRGBA::FromIpRGB(lParam));
- } else {
- return ResetElement(element);
}
+ return ResetElement(element);
}
void ViewStyle::SetElementRGB(Element element, int rgb) {
@@ -801,9 +802,7 @@ void ViewStyle::FindMaxAscentDescent() noexcept {
const auto &style = styles[i];
- if (maxAscent < style.ascent)
- maxAscent = style.ascent;
- if (maxDescent < style.descent)
- maxDescent = style.descent;
+ maxAscent = std::max(style.ascent, maxAscent);
+ maxDescent = std::max(style.descent, maxDescent);
}
}