diff options
author | Neil <nyamatongwe@gmail.com> | 2021-09-12 17:15:34 +1000 |
---|---|---|
committer | Neil <nyamatongwe@gmail.com> | 2021-09-12 17:15:34 +1000 |
commit | e1a52e49814cb1ab2efcdbd65dcb9a83976c2a54 (patch) | |
tree | c811e2fdd4f46e0dc955d71fba87a4f46e65be40 | |
parent | 3d017cb655c23d9dfb39cbecbcaddaf14bb25117 (diff) | |
download | scintilla-mirror-e1a52e49814cb1ab2efcdbd65dcb9a83976c2a54.tar.gz |
Make negative settings for extra ascent and descent safer by ensuring calculated
ascent and thus line height is at least 1 pixel.
Allow 1 point font minimum instead of 2 as this may help with document maps.
Document negative extra ascent and descent.
Use XYPOSITION for ascent and descent for more coherent types and fewer casts
but floor the values when retrieving from Surface so behaviour is unchanged.
-rw-r--r-- | doc/ScintillaDoc.html | 6 | ||||
-rw-r--r-- | doc/ScintillaHistory.html | 4 | ||||
-rw-r--r-- | src/EditView.cxx | 2 | ||||
-rw-r--r-- | src/Style.h | 4 | ||||
-rw-r--r-- | src/ViewStyle.cxx | 20 | ||||
-rw-r--r-- | src/ViewStyle.h | 4 |
6 files changed, 27 insertions, 13 deletions
diff --git a/doc/ScintillaDoc.html b/doc/ScintillaDoc.html index 5dfd16585..37a99a0f2 100644 --- a/doc/ScintillaDoc.html +++ b/doc/ScintillaDoc.html @@ -128,7 +128,7 @@ <h1>Scintilla Documentation</h1> - <p>Last edited 25 August 2021 NH</p> + <p>Last edited 12 September 2021 NH</p> <p style="background:#90F0C0">Scintilla 5 has moved the lexers from Scintilla into a new <a href="Lexilla.html">Lexilla</a> project.<br /> @@ -2448,6 +2448,10 @@ struct Sci_TextToFind { maximum descent (<code>SCI_SETEXTRADESCENT</code>) to allow for more space between lines. This may done to make the text easier to read or to accommodate underlines or highlights. </p> + <p> + The extra ascent and descent values can be negative but that should be done with care as it + may lead to unexpected interference when lines share space. + </p> <h2 id="Cursor">Cursor</h2> <a class="message" href="#SCI_SETCURSOR">SCI_SETCURSOR(int cursorType)</a><br /> diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html index 080c223a3..1b16f2d18 100644 --- a/doc/ScintillaHistory.html +++ b/doc/ScintillaHistory.html @@ -594,6 +594,10 @@ Allow SCI_HIDELINES to hide the first line or all lines which can be useful for filtered views. </li> <li> + Make negative settings for extra ascent and descent safer by ensuring calculated ascent and thus + line height is at least 1 pixel. + </li> + <li> Fix display of fold lines when wrapped so they are only drawn once per line, not on each subline. </li> <li> diff --git a/src/EditView.cxx b/src/EditView.cxx index 0f69dd7b3..732a0f72e 100644 --- a/src/EditView.cxx +++ b/src/EditView.cxx @@ -2700,7 +2700,7 @@ Sci::Position EditView::FormatRange(bool draw, const RangeToFormat *pfr, Surface vsPrint.styles[StyleLineNumber].font.get(), number); surface->FlushCachedState(); surface->DrawTextNoClip(rcNumber, vsPrint.styles[StyleLineNumber].font.get(), - static_cast<XYPOSITION>(ypos + vsPrint.maxAscent), number, + ypos + vsPrint.maxAscent, number, vsPrint.styles[StyleLineNumber].fore, vsPrint.styles[StyleLineNumber].back); } diff --git a/src/Style.h b/src/Style.h index a3ce336ed..14112e092 100644 --- a/src/Style.h +++ b/src/Style.h @@ -27,8 +27,8 @@ struct FontSpecification { }; struct FontMeasurements { - unsigned int ascent = 1; - unsigned int descent = 1; + XYPOSITION ascent = 1; + XYPOSITION descent = 1; XYPOSITION capitalHeight = 1; // Top of capital letter to baseline: ascent - internal leading XYPOSITION aveCharWidth = 1; XYPOSITION spaceWidth = 1; diff --git a/src/ViewStyle.cxx b/src/ViewStyle.cxx index 8c3872611..ad1340d0d 100644 --- a/src/ViewStyle.cxx +++ b/src/ViewStyle.cxx @@ -8,6 +8,7 @@ #include <cstddef> #include <cassert> #include <cstring> +#include <cmath> #include <stdexcept> #include <string> @@ -48,16 +49,20 @@ 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 <= 2 * FontSizeMultiplier) // Hangs if sizeZoomed <= 1 - measurements.sizeZoomed = 2 * FontSizeMultiplier; + if (measurements.sizeZoomed <= FontSizeMultiplier) // May fail if sizeZoomed < 1 + measurements.sizeZoomed = FontSizeMultiplier; 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); - measurements.ascent = static_cast<unsigned int>(surface.Ascent(font.get())); - measurements.descent = static_cast<unsigned int>(surface.Descent(font.get())); + // 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())); + measurements.descent = std::floor(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(), " "); @@ -356,9 +361,10 @@ void ViewStyle::Refresh(Surface &surface, int tabInChars) { maxAscent = 1; maxDescent = 1; FindMaxAscentDescent(); - maxAscent += extraAscent; - maxDescent += extraDescent; - lineHeight = maxAscent + maxDescent; + // Ensure reasonable values: lines less than 1 pixel high will not work + maxAscent = std::max(1.0, maxAscent + extraAscent); + maxDescent = std::max(0.0, maxDescent + extraDescent); + lineHeight = lround(maxAscent + maxDescent); lineOverlap = lineHeight / 10; if (lineOverlap < 2) lineOverlap = 2; diff --git a/src/ViewStyle.h b/src/ViewStyle.h index edebee7ce..f6d1bdbb4 100644 --- a/src/ViewStyle.h +++ b/src/ViewStyle.h @@ -122,8 +122,8 @@ public: Scintilla::Technology technology; int lineHeight; int lineOverlap; - unsigned int maxAscent; - unsigned int maxDescent; + XYPOSITION maxAscent; + XYPOSITION maxDescent; XYPOSITION aveCharWidth; XYPOSITION spaceWidth; XYPOSITION tabWidth; |