aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ViewStyle.cxx46
1 files changed, 22 insertions, 24 deletions
diff --git a/src/ViewStyle.cxx b/src/ViewStyle.cxx
index 92d084ee6..f553bc825 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,
@@ -107,7 +108,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 +171,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 +223,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 +339,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 +417,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 +432,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 +442,7 @@ void ViewStyle::Refresh(Surface &surface, int tabInChars) {
}
void ViewStyle::ReleaseAllExtendedStyles() noexcept {
- nextExtendedStyle = 256;
+ nextExtendedStyle = startExtendedStyles;
}
int ViewStyle::AllocateExtendedStyles(int numberStyles) {
@@ -571,9 +573,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 +672,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 +801,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);
}
}