diff options
-rw-r--r-- | src/Style.cxx | 117 | ||||
-rw-r--r-- | src/Style.h | 46 | ||||
-rw-r--r-- | src/ViewStyle.cxx | 50 | ||||
-rw-r--r-- | src/ViewStyle.h | 10 |
4 files changed, 59 insertions, 164 deletions
diff --git a/src/Style.cxx b/src/Style.cxx index 3a57d1a08..76ffa4942 100644 --- a/src/Style.cxx +++ b/src/Style.cxx @@ -28,7 +28,8 @@ bool FontSpecification::operator==(const FontSpecification &other) const noexcep italic == other.italic && size == other.size && characterSet == other.characterSet && - extraFontFlag == other.extraFontFlag; + extraFontFlag == other.extraFontFlag && + checkMonospaced == other.checkMonospaced; } bool FontSpecification::operator<(const FontSpecification &other) const noexcept { @@ -44,108 +45,34 @@ bool FontSpecification::operator<(const FontSpecification &other) const noexcept return characterSet < other.characterSet; if (extraFontFlag != other.extraFontFlag) return extraFontFlag < other.extraFontFlag; + if (checkMonospaced != other.checkMonospaced) + return checkMonospaced < other.checkMonospaced; return false; } -FontMeasurements::FontMeasurements() noexcept { - ClearMeasurements(); -} - -void FontMeasurements::ClearMeasurements() noexcept { - ascent = 1; - descent = 1; - capitalHeight = 1; - aveCharWidth = 1; - spaceWidth = 1; - monospaceASCII = false; - sizeZoomed = 2; -} - -Style::Style() : FontSpecification() { - Clear(ColourRGBA(0, 0, 0), ColourRGBA(0xff, 0xff, 0xff), - Platform::DefaultFontSize() * FontSizeMultiplier, nullptr, CharacterSet::Default, - FontWeight::Normal, false, false, false, CaseForce::mixed, true, true, false); -} - -Style::Style(const Style &source) noexcept : FontSpecification(), FontMeasurements() { - Clear(ColourRGBA(0, 0, 0), ColourRGBA(0xff, 0xff, 0xff), - 0, nullptr, CharacterSet::Ansi, - FontWeight::Normal, false, false, false, CaseForce::mixed, true, true, false); - fore = source.fore; - back = source.back; - characterSet = source.characterSet; - weight = source.weight; - italic = source.italic; - size = source.size; - fontName = source.fontName; - eolFilled = source.eolFilled; - underline = source.underline; - caseForce = source.caseForce; - visible = source.visible; - changeable = source.changeable; - hotspot = source.hotspot; -} - -Style::~Style() = default; +namespace { -Style &Style::operator=(const Style &source) noexcept { - if (this == &source) - return * this; - Clear(ColourRGBA(0, 0, 0), ColourRGBA(0xff, 0xff, 0xff), - 0, nullptr, CharacterSet::Default, - FontWeight::Normal, false, false, false, CaseForce::mixed, true, true, false); - fore = source.fore; - back = source.back; - characterSet = source.characterSet; - weight = source.weight; - italic = source.italic; - size = source.size; - fontName = source.fontName; - eolFilled = source.eolFilled; - underline = source.underline; - caseForce = source.caseForce; - visible = source.visible; - changeable = source.changeable; - return *this; +// noexcept Platform::DefaultFontSize +int DefaultFontSize() noexcept { + try { + return Platform::DefaultFontSize(); + } catch (...) { + return 10; + } } -void Style::Clear(ColourRGBA fore_, ColourRGBA back_, int size_, - const char *fontName_, CharacterSet characterSet_, - FontWeight weight_, bool italic_, bool eolFilled_, - bool underline_, CaseForce caseForce_, - bool visible_, bool changeable_, bool hotspot_) noexcept { - fore = fore_; - back = back_; - characterSet = characterSet_; - weight = weight_; - italic = italic_; - size = size_; - fontName = fontName_; - eolFilled = eolFilled_; - underline = underline_; - caseForce = caseForce_; - visible = visible_; - changeable = changeable_; - hotspot = hotspot_; - font.reset(); - FontMeasurements::ClearMeasurements(); } -void Style::ClearTo(const Style &source) noexcept { - Clear( - source.fore, - source.back, - source.size, - source.fontName, - source.characterSet, - source.weight, - source.italic, - source.eolFilled, - source.underline, - source.caseForce, - source.visible, - source.changeable, - source.hotspot); +Style::Style(const char *fontName_) noexcept : + FontSpecification(fontName_, DefaultFontSize() * FontSizeMultiplier), + fore(0,0,0), + back(0xff, 0xff, 0xff), + eolFilled(false), + underline(false), + caseForce(CaseForce::mixed), + visible(true), + changeable(true), + hotspot(false) { } void Style::Copy(std::shared_ptr<Font> font_, const FontMeasurements &fm_) noexcept { diff --git a/src/Style.h b/src/Style.h index 087b13b2f..a3ce336ed 100644 --- a/src/Style.h +++ b/src/Style.h @@ -12,34 +12,28 @@ namespace Scintilla::Internal { struct FontSpecification { const char *fontName; - Scintilla::FontWeight weight; - bool italic; int size; - Scintilla::CharacterSet characterSet; - Scintilla::FontQuality extraFontFlag; + Scintilla::FontWeight weight = Scintilla::FontWeight::Normal; + bool italic = false; + Scintilla::CharacterSet characterSet = Scintilla::CharacterSet::Default; + Scintilla::FontQuality extraFontFlag = Scintilla::FontQuality::QualityDefault; bool checkMonospaced = false; - FontSpecification() noexcept : - fontName(nullptr), - weight(Scintilla::FontWeight::Normal), - italic(false), - size(10 * Scintilla::FontSizeMultiplier), - characterSet(Scintilla::CharacterSet::Ansi), - extraFontFlag(Scintilla::FontQuality::QualityDefault) { + + constexpr FontSpecification(const char *fontName_=nullptr, int size_=10*Scintilla::FontSizeMultiplier) noexcept : + fontName(fontName_), size(size_) { } bool operator==(const FontSpecification &other) const noexcept; bool operator<(const FontSpecification &other) const noexcept; }; struct FontMeasurements { - unsigned int ascent; - unsigned int descent; - XYPOSITION capitalHeight; // Top of capital letter to baseline: ascent - internal leading - XYPOSITION aveCharWidth; - XYPOSITION spaceWidth; + unsigned int ascent = 1; + unsigned int descent = 1; + XYPOSITION capitalHeight = 1; // Top of capital letter to baseline: ascent - internal leading + XYPOSITION aveCharWidth = 1; + XYPOSITION spaceWidth = 1; bool monospaceASCII = false; - int sizeZoomed; - FontMeasurements() noexcept; - void ClearMeasurements() noexcept; + int sizeZoomed = 2; }; /** @@ -58,19 +52,7 @@ public: std::shared_ptr<Font> font; - Style(); - Style(const Style &source) noexcept; - Style(Style &&) noexcept = default; - ~Style(); - Style &operator=(const Style &source) noexcept; - Style &operator=(Style &&) = delete; - void Clear(ColourRGBA fore_, ColourRGBA back_, - int size_, - const char *fontName_, Scintilla::CharacterSet characterSet_, - Scintilla::FontWeight weight_, bool italic_, bool eolFilled_, - bool underline_, CaseForce caseForce_, - bool visible_, bool changeable_, bool hotspot_) noexcept; - void ClearTo(const Style &source) noexcept; + Style(const char *fontName_=nullptr) noexcept; void Copy(std::shared_ptr<Font> font_, const FontMeasurements &fm_) noexcept; bool IsProtected() const noexcept { return !(changeable && visible);} }; diff --git a/src/ViewStyle.cxx b/src/ViewStyle.cxx index 366151cee..8c3872611 100644 --- a/src/ViewStyle.cxx +++ b/src/ViewStyle.cxx @@ -45,26 +45,22 @@ bool MarginStyle::ShowsFolding() const noexcept { return (mask & MaskFolders) != 0; } -FontRealised::FontRealised() noexcept = default; - -FontRealised::~FontRealised() = default; - void FontRealised::Realise(Surface &surface, int zoomLevel, Technology technology, const FontSpecification &fs, const char *localeName) { PLATFORM_ASSERT(fs.fontName); - sizeZoomed = fs.size + zoomLevel * FontSizeMultiplier; - if (sizeZoomed <= 2 * FontSizeMultiplier) // Hangs if sizeZoomed <= 1 - sizeZoomed = 2 * FontSizeMultiplier; + measurements.sizeZoomed = fs.size + zoomLevel * FontSizeMultiplier; + if (measurements.sizeZoomed <= 2 * FontSizeMultiplier) // Hangs if sizeZoomed <= 1 + measurements.sizeZoomed = 2 * FontSizeMultiplier; - const float deviceHeight = static_cast<float>(surface.DeviceHeightFont(sizeZoomed)); + const float deviceHeight = static_cast<float>(surface.DeviceHeightFont(measurements.sizeZoomed)); const FontParameters fp(fs.fontName, deviceHeight / FontSizeMultiplier, fs.weight, fs.italic, fs.extraFontFlag, technology, fs.characterSet, localeName); font = Font::Allocate(fp); - ascent = static_cast<unsigned int>(surface.Ascent(font.get())); - descent = static_cast<unsigned int>(surface.Descent(font.get())); - capitalHeight = surface.Ascent(font.get()) - surface.InternalLeading(font.get()); - aveCharWidth = surface.AverageCharWidth(font.get()); - spaceWidth = surface.WidthText(font.get(), " "); + measurements.ascent = static_cast<unsigned int>(surface.Ascent(font.get())); + measurements.descent = static_cast<unsigned int>(surface.Descent(font.get())); + measurements.capitalHeight = surface.Ascent(font.get()) - surface.InternalLeading(font.get()); + measurements.aveCharWidth = surface.AverageCharWidth(font.get()); + measurements.spaceWidth = surface.WidthText(font.get(), " "); if (fs.checkMonospaced) { std::string allASCIIGraphic("Ayfi"); // "Ay" is normally strongly kerned and "fi" may be a ligature @@ -77,11 +73,11 @@ 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 / aveCharWidth; + const XYPOSITION scaledVariance = variance / measurements.aveCharWidth; constexpr XYPOSITION monospaceWidthEpsilon = 0.000001; // May need tweaking if monospace fonts vary more - monospaceASCII = scaledVariance < monospaceWidthEpsilon; + measurements.monospaceASCII = scaledVariance < monospaceWidthEpsilon; } else { - monospaceASCII = false; + measurements.monospaceASCII = false; } } @@ -348,7 +344,7 @@ void ViewStyle::Refresh(Surface &surface, int tabInChars) { // Set the platform font handle and measurements for each style. for (Style &style : styles) { const FontRealised *fr = Find(style); - style.Copy(fr->font, *fr); + style.Copy(fr->font, fr->measurements); } indicatorsDynamic = std::any_of(indicators.cbegin(), indicators.cend(), @@ -398,7 +394,7 @@ int ViewStyle::AllocateExtendedStyles(int numberStyles) { nextExtendedStyle += numberStyles; EnsureStyle(nextExtendedStyle); for (int i=startRange; i<nextExtendedStyle; i++) { - styles[i].ClearTo(styles[StyleDefault]); + styles[i] = styles[StyleDefault]; } return startRange; } @@ -410,18 +406,14 @@ void ViewStyle::EnsureStyle(size_t index) { } void ViewStyle::ResetDefaultStyle() { - styles[StyleDefault].Clear(ColourRGBA(0,0,0), - ColourRGBA(0xff,0xff,0xff), - Platform::DefaultFontSize() * FontSizeMultiplier, fontNames.Save(Platform::DefaultFont()), - CharacterSet::Default, - FontWeight::Normal, false, false, false, Style::CaseForce::mixed, true, true, false); + styles[StyleDefault] = Style(fontNames.Save(Platform::DefaultFont())); } void ViewStyle::ClearStyles() { // Reset all styles to be like the default style for (size_t i=0; i<styles.size(); i++) { if (i != StyleDefault) { - styles[i].ClearTo(styles[StyleDefault]); + styles[i] = styles[StyleDefault]; } } styles[StyleLineNumber].back = Platform::Chrome(); @@ -701,7 +693,7 @@ void ViewStyle::AllocStyles(size_t sizeNew) { if (styles.size() > StyleDefault) { for (; i<sizeNew; i++) { if (i != StyleDefault) { - styles[i].ClearTo(styles[StyleDefault]); + styles[i] = styles[StyleDefault]; } } } @@ -729,9 +721,9 @@ FontRealised *ViewStyle::Find(const FontSpecification &fs) { void ViewStyle::FindMaxAscentDescent() { for (const auto &font : fonts) { - if (maxAscent < font.second->ascent) - maxAscent = font.second->ascent; - if (maxDescent < font.second->descent) - maxDescent = font.second->descent; + if (maxAscent < font.second->measurements.ascent) + maxAscent = font.second->measurements.ascent; + if (maxDescent < font.second->measurements.descent) + maxDescent = font.second->measurements.descent; } } diff --git a/src/ViewStyle.h b/src/ViewStyle.h index 843efc660..edebee7ce 100644 --- a/src/ViewStyle.h +++ b/src/ViewStyle.h @@ -28,16 +28,10 @@ public: */ -class FontRealised : public FontMeasurements { +class FontRealised { public: + FontMeasurements measurements; std::shared_ptr<Font> font; - FontRealised() noexcept; - // FontRealised objects can not be copied. - FontRealised(const FontRealised &) = delete; - FontRealised(FontRealised &&) = delete; - FontRealised &operator=(const FontRealised &) = delete; - FontRealised &operator=(FontRealised &&) = delete; - virtual ~FontRealised(); void Realise(Surface &surface, int zoomLevel, Scintilla::Technology technology, const FontSpecification &fs, const char *localeName); }; |