diff options
author | Neil <nyamatongwe@gmail.com> | 2024-08-15 19:02:46 +1000 |
---|---|---|
committer | Neil <nyamatongwe@gmail.com> | 2024-08-15 19:02:46 +1000 |
commit | dcbc339899911e1a3a743de1c0c25d0c253dd39a (patch) | |
tree | 3d4fcd3405e7b4620476c36b0102031114bf65ad | |
parent | 6f51f5975920272f5f691d690107d15291a335f2 (diff) | |
download | scintilla-mirror-dcbc339899911e1a3a743de1c0c25d0c253dd39a.tar.gz |
Add SCI_STYLESETSTRETCH to support condensed and expanded text styles.
-rw-r--r-- | call/ScintillaCall.cxx | 8 | ||||
-rw-r--r-- | cocoa/PlatCocoa.mm | 2 | ||||
-rw-r--r-- | cocoa/QuartzTextStyleAttribute.h | 11 | ||||
-rw-r--r-- | doc/ScintillaDoc.html | 66 | ||||
-rw-r--r-- | doc/ScintillaHistory.html | 3 | ||||
-rwxr-xr-x | gtk/PlatGTK.cxx | 2 | ||||
-rw-r--r-- | include/Scintilla.h | 11 | ||||
-rw-r--r-- | include/Scintilla.iface | 17 | ||||
-rw-r--r-- | include/ScintillaCall.h | 2 | ||||
-rw-r--r-- | include/ScintillaMessages.h | 2 | ||||
-rw-r--r-- | include/ScintillaTypes.h | 12 | ||||
-rw-r--r-- | qt/ScintillaEditBase/PlatQt.cpp | 27 | ||||
-rw-r--r-- | src/Editor.cxx | 7 | ||||
-rw-r--r-- | src/Platform.h | 7 | ||||
-rw-r--r-- | src/Style.cxx | 3 | ||||
-rw-r--r-- | src/Style.h | 1 | ||||
-rw-r--r-- | src/ViewStyle.cxx | 2 | ||||
-rw-r--r-- | win32/PlatWin.cxx | 6 |
18 files changed, 181 insertions, 8 deletions
diff --git a/call/ScintillaCall.cxx b/call/ScintillaCall.cxx index 4508210db..64c9728e2 100644 --- a/call/ScintillaCall.cxx +++ b/call/ScintillaCall.cxx @@ -655,6 +655,14 @@ bool ScintillaCall::StyleGetCheckMonospaced(int style) { return Call(Message::StyleGetCheckMonospaced, style); } +void ScintillaCall::StyleSetStretch(int style, Scintilla::FontStretch stretch) { + Call(Message::StyleSetStretch, style, static_cast<intptr_t>(stretch)); +} + +FontStretch ScintillaCall::StyleGetStretch(int style) { + return static_cast<Scintilla::FontStretch>(Call(Message::StyleGetStretch, style)); +} + void ScintillaCall::StyleSetInvisibleRepresentation(int style, const char *representation) { CallString(Message::StyleSetInvisibleRepresentation, style, representation); } diff --git a/cocoa/PlatCocoa.mm b/cocoa/PlatCocoa.mm index 6eb12f4ad..4753f6a5f 100644 --- a/cocoa/PlatCocoa.mm +++ b/cocoa/PlatCocoa.mm @@ -106,7 +106,7 @@ public: FontQuartz(const FontParameters &fp) { style = std::make_unique<QuartzTextStyle>(); // Create the font with attributes - QuartzFont font(fp.faceName, strlen(fp.faceName), fp.size, fp.weight, fp.italic); + QuartzFont font(fp.faceName, strlen(fp.faceName), fp.size, fp.weight, fp.stretch, fp.italic); CTFontRef fontRef = font.getFontID(); style->setFontRef(fontRef, fp.characterSet); } diff --git a/cocoa/QuartzTextStyleAttribute.h b/cocoa/QuartzTextStyleAttribute.h index d9c0e5a15..22af29b4a 100644 --- a/cocoa/QuartzTextStyleAttribute.h +++ b/cocoa/QuartzTextStyleAttribute.h @@ -15,14 +15,14 @@ class QuartzFont { public: /** Create a font style from a name. */ - QuartzFont(const char *name, size_t length, float size, Scintilla::FontWeight weight, bool italic) { + QuartzFont(const char *name, size_t length, float size, Scintilla::FontWeight weight, Scintilla::FontStretch stretch, bool italic) { assert(name != NULL && length > 0 && name[length] == '\0'); CFStringRef fontName = CFStringCreateWithCString(kCFAllocatorDefault, name, kCFStringEncodingMacRoman); assert(fontName != NULL); bool bold = weight > Scintilla::FontWeight::Normal; - if (bold || italic) { + if (bold || italic || stretch != Scintilla::FontStretch::Normal) { CTFontSymbolicTraits desiredTrait = 0; CTFontSymbolicTraits traitMask = 0; @@ -37,6 +37,13 @@ public: desiredTrait |= kCTFontItalicTrait; traitMask |= kCTFontItalicTrait; } + if (stretch < Scintilla::FontStretch::Normal) { + desiredTrait |= kCTFontCondensedTrait; + traitMask |= kCTFontCondensedTrait; + } else if (stretch > Scintilla::FontStretch::Normal) { + desiredTrait |= kCTFontExpandedTrait; + traitMask |= kCTFontExpandedTrait; + } // create a font and then a copy of it with the sym traits CTFontRef iFont = ::CTFontCreateWithName(fontName, size, NULL); diff --git a/doc/ScintillaDoc.html b/doc/ScintillaDoc.html index b320621cf..95a830beb 100644 --- a/doc/ScintillaDoc.html +++ b/doc/ScintillaDoc.html @@ -3348,6 +3348,8 @@ struct Sci_TextToFindFull { <a class="message" href="#SCI_STYLESETWEIGHT">SCI_STYLESETWEIGHT(int style, int weight)</a><br /> <a class="message" href="#SCI_STYLEGETWEIGHT">SCI_STYLEGETWEIGHT(int style) → int</a><br /> + <a class="message" href="#SCI_STYLESETSTRETCH">SCI_STYLESETSTRETCH(int style, int stretch)</a><br /> + <a class="message" href="#SCI_STYLEGETSTRETCH">SCI_STYLEGETSTRETCH(int style) → int</a><br /> <a class="message" href="#SCI_STYLESETITALIC">SCI_STYLESETITALIC(int style, bool italic)</a><br /> <a class="message" href="#SCI_STYLEGETITALIC">SCI_STYLEGETITALIC(int style) → bool</a><br /> @@ -3407,6 +3409,8 @@ struct Sci_TextToFindFull { <b id="SCI_STYLEGETBOLD">SCI_STYLEGETBOLD(int style) → bool</b><br /> <b id="SCI_STYLESETWEIGHT">SCI_STYLESETWEIGHT(int style, int weight)</b><br /> <b id="SCI_STYLEGETWEIGHT">SCI_STYLEGETWEIGHT(int style) → int</b><br /> + <b id="SCI_STYLESETSTRETCH">SCI_STYLESETSTRETCH(int style, int stretch)</b><br /> + <b id="SCI_STYLEGETSTRETCH">SCI_STYLEGETSTRETCH(int style) → int</b><br /> <b id="SCI_STYLESETITALIC">SCI_STYLESETITALIC(int style, bool italic)</b><br /> <b id="SCI_STYLEGETITALIC">SCI_STYLEGETITALIC(int style) → bool</b><br /> These messages (plus <a class="message" @@ -3435,6 +3439,68 @@ struct Sci_TextToFindFull { The <code>SCI_STYLESETBOLD</code> message takes a boolean argument with 0 choosing <code>SC_WEIGHT_NORMAL</code> and 1 <code>SC_WEIGHT_BOLD</code>. </p> + <p>The stretch of a font can be set with <code>SCI_STYLESETSTRETCH</code> which can produce condensed or expanded text. + The weight is a number between 1 and 9 which corresponds to a horizontal magnification between 50% and 200% + with 1 being very condensed, 5 normal, and 9 very expanded. + While any value can be used, fonts and platforms often only support between 2 and 3 stretches. + The best supported and useful values are + <code>SC_STRETCH_CONDENSED</code>, + <code>SC_STRETCH_NORMAL</code>, and + <code>SC_STRETCH_EXPANDED</code>. + The Inconsolata variable font supports many stretch values and can be useful for experimenting. + Condensed text can be used to display more text in a narrower window and expanded text may be used + for clearer text that is easier to read. + The API is based on the Cascading Style Sheets font-stretch property. + </p> + <table class="standard" summary="Stretch"> + <tbody valign="top"> + <tr> + <th align="left"><code>SC_STRETCH_ULTRA_CONDENSED</code></th> + <td>1</td> + <td>50%</td> + </tr> + <tr> + <th align="left"><code>SC_STRETCH_EXTRA_CONDENSED</code></th> + <td>2</td> + <td>62.5%</td> + </tr> + <tr> + <th align="left"><code>SC_STRETCH_CONDENSED</code></th> + <td>3</td> + <td>75%</td> + </tr> + <tr> + <th align="left"><code>SC_STRETCH_SEMI_CONDENSED</code></th> + <td>4</td> + <td>87.5%</td> + </tr> + <tr> + <th align="left"><code>SC_STRETCH_NORMAL</code></th> + <td>5</td> + <td>100%</td> + </tr> + <tr> + <th align="left"><code>SC_STRETCH_SEMI_EXPANDED</code></th> + <td>6</td> + <td>112.5%</td> + </tr> + <tr> + <th align="left"><code>SC_STRETCH_EXPANDED</code></th> + <td>7</td> + <td>125%</td> + </tr> + <tr> + <th align="left"><code>SC_STRETCH_EXTRA_EXPANDED</code></th> + <td>8</td> + <td>150%</td> + </tr> + <tr> + <th align="left"><code>SC_STRETCH_ULTRA_EXPANDED</code></th> + <td>9</td> + <td>200%</td> + </tr> + </tbody> + </table> <p><b id="SCI_STYLESETUNDERLINE">SCI_STYLESETUNDERLINE(int style, bool underline)</b><br /> diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html index a1abe6ccf..67795148c 100644 --- a/doc/ScintillaHistory.html +++ b/doc/ScintillaHistory.html @@ -600,6 +600,9 @@ Add SCI_GETUNDOSEQUENCE to determine whether an undo sequence is active and its nesting depth. </li> <li> + Add SCI_STYLESETSTRETCH to support condensed and expanded text styles. + </li> + <li> Add SCI_LINEINDENT and SCI_LINEDEDENT. <a href="https://sourceforge.net/p/scintilla/feature-requests/1524/">Feature #1524</a>. </li> diff --git a/gtk/PlatGTK.cxx b/gtk/PlatGTK.cxx index 563fa9c81..8419521c9 100755 --- a/gtk/PlatGTK.cxx +++ b/gtk/PlatGTK.cxx @@ -100,6 +100,8 @@ public: pango_font_description_set_size(fd.get(), pango_units_from_double(fp.size)); pango_font_description_set_weight(fd.get(), static_cast<PangoWeight>(fp.weight)); pango_font_description_set_style(fd.get(), fp.italic ? PANGO_STYLE_ITALIC : PANGO_STYLE_NORMAL); + pango_font_description_set_stretch(fd.get(), + static_cast<PangoStretch>(static_cast<int>(fp.stretch)-1)); } } ~FontHandle() override = default; diff --git a/include/Scintilla.h b/include/Scintilla.h index 6fec9be58..d7c08fa25 100644 --- a/include/Scintilla.h +++ b/include/Scintilla.h @@ -282,6 +282,17 @@ typedef sptr_t (*SciFnDirectStatus)(sptr_t ptr, unsigned int iMessage, uptr_t wP #define SCI_STYLESETHOTSPOT 2409 #define SCI_STYLESETCHECKMONOSPACED 2254 #define SCI_STYLEGETCHECKMONOSPACED 2255 +#define SC_STRETCH_ULTRA_CONDENSED 1 +#define SC_STRETCH_EXTRA_CONDENSED 2 +#define SC_STRETCH_CONDENSED 3 +#define SC_STRETCH_SEMI_CONDENSED 4 +#define SC_STRETCH_NORMAL 5 +#define SC_STRETCH_SEMI_EXPANDED 6 +#define SC_STRETCH_EXPANDED 7 +#define SC_STRETCH_EXTRA_EXPANDED 8 +#define SC_STRETCH_ULTRA_EXPANDED 9 +#define SCI_STYLESETSTRETCH 2258 +#define SCI_STYLEGETSTRETCH 2259 #define SCI_STYLESETINVISIBLEREPRESENTATION 2256 #define SCI_STYLEGETINVISIBLEREPRESENTATION 2257 #define SC_ELEMENT_LIST 0 diff --git a/include/Scintilla.iface b/include/Scintilla.iface index 25201cf47..4a3d15b63 100644 --- a/include/Scintilla.iface +++ b/include/Scintilla.iface @@ -700,6 +700,23 @@ set void StyleSetCheckMonospaced=2254(int style, bool checkMonospaced) # Get whether a style may be monospaced. get bool StyleGetCheckMonospaced=2255(int style,) +enu FontStretch=SC_STRETCH_ +val SC_STRETCH_ULTRA_CONDENSED=1 +val SC_STRETCH_EXTRA_CONDENSED=2 +val SC_STRETCH_CONDENSED=3 +val SC_STRETCH_SEMI_CONDENSED=4 +val SC_STRETCH_NORMAL=5 +val SC_STRETCH_SEMI_EXPANDED=6 +val SC_STRETCH_EXPANDED=7 +val SC_STRETCH_EXTRA_EXPANDED=8 +val SC_STRETCH_ULTRA_EXPANDED=9 + +# Set the stretch of characters of a style. +set void StyleSetStretch=2258(int style, FontStretch stretch) + +# Get the stretch of characters of a style. +get FontStretch StyleGetStretch=2259(int style,) + # Set the invisible representation for a style. set void StyleSetInvisibleRepresentation=2256(int style, string representation) diff --git a/include/ScintillaCall.h b/include/ScintillaCall.h index 065a60ac5..c1f35571f 100644 --- a/include/ScintillaCall.h +++ b/include/ScintillaCall.h @@ -209,6 +209,8 @@ public: void StyleSetHotSpot(int style, bool hotspot); void StyleSetCheckMonospaced(int style, bool checkMonospaced); bool StyleGetCheckMonospaced(int style); + void StyleSetStretch(int style, Scintilla::FontStretch stretch); + Scintilla::FontStretch StyleGetStretch(int style); void StyleSetInvisibleRepresentation(int style, const char *representation); int StyleGetInvisibleRepresentation(int style, char *representation); std::string StyleGetInvisibleRepresentation(int style); diff --git a/include/ScintillaMessages.h b/include/ScintillaMessages.h index 847ec0881..df7f2e743 100644 --- a/include/ScintillaMessages.h +++ b/include/ScintillaMessages.h @@ -137,6 +137,8 @@ enum class Message { StyleSetHotSpot = 2409, StyleSetCheckMonospaced = 2254, StyleGetCheckMonospaced = 2255, + StyleSetStretch = 2258, + StyleGetStretch = 2259, StyleSetInvisibleRepresentation = 2256, StyleGetInvisibleRepresentation = 2257, SetElementColour = 2753, diff --git a/include/ScintillaTypes.h b/include/ScintillaTypes.h index 4b7773a26..6d3e2a705 100644 --- a/include/ScintillaTypes.h +++ b/include/ScintillaTypes.h @@ -165,6 +165,18 @@ enum class FontWeight { Bold = 700, }; +enum class FontStretch { + UltraCondensed = 1, + ExtraCondensed = 2, + Condensed = 3, + SemiCondensed = 4, + Normal = 5, + SemiExpanded = 6, + Expanded = 7, + ExtraExpanded = 8, + UltraExpanded = 9, +}; + enum class Element { List = 0, ListBack = 1, diff --git a/qt/ScintillaEditBase/PlatQt.cpp b/qt/ScintillaEditBase/PlatQt.cpp index 652c7c305..83e78a631 100644 --- a/qt/ScintillaEditBase/PlatQt.cpp +++ b/qt/ScintillaEditBase/PlatQt.cpp @@ -113,6 +113,32 @@ static QFont::StyleStrategy ChooseStrategy(FontQuality eff) } } +static QFont::Stretch QStretchFromFontStretch(Scintilla::FontStretch stretch) +{ + switch (stretch) { + case FontStretch::UltraCondensed: + return QFont::Stretch::UltraCondensed; + case FontStretch::ExtraCondensed: + return QFont::Stretch::ExtraCondensed; + case FontStretch::Condensed: + return QFont::Stretch::Condensed; + case FontStretch::SemiCondensed: + return QFont::Stretch::SemiCondensed; + case FontStretch::Normal: + return QFont::Stretch::Unstretched; + case FontStretch::SemiExpanded: + return QFont::Stretch::SemiExpanded; + case FontStretch::Expanded: + return QFont::Stretch::Expanded; + case FontStretch::ExtraExpanded: + return QFont::Stretch::ExtraExpanded; + case FontStretch::UltraExpanded: + return QFont::Stretch::UltraExpanded; + default: + return QFont::Stretch::Unstretched; + } +} + class FontAndCharacterSet : public Font { public: CharacterSet characterSet = CharacterSet::Ansi; @@ -123,6 +149,7 @@ public: pfont->setFamily(QString::fromUtf8(fp.faceName)); pfont->setPointSizeF(fp.size); pfont->setBold(static_cast<int>(fp.weight) > 500); + pfont->setStretch(QStretchFromFontStretch(fp.stretch)); pfont->setItalic(fp.italic); } }; diff --git a/src/Editor.cxx b/src/Editor.cxx index a185d7f08..356f73baa 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -5953,6 +5953,9 @@ void Editor::StyleSetMessage(Message iMessage, uptr_t wParam, sptr_t lParam) { case Message::StyleSetWeight: vs.styles[wParam].weight = static_cast<FontWeight>(lParam); break; + case Message::StyleSetStretch: + vs.styles[wParam].stretch = static_cast<FontStretch>(lParam); + break; case Message::StyleSetItalic: vs.styles[wParam].italic = lParam != 0; break; @@ -6022,6 +6025,8 @@ sptr_t Editor::StyleGetMessage(Message iMessage, uptr_t wParam, sptr_t lParam) { return vs.styles[wParam].weight > FontWeight::Normal; case Message::StyleGetWeight: return static_cast<sptr_t>(vs.styles[wParam].weight); + case Message::StyleGetStretch: + return static_cast<sptr_t>(vs.styles[wParam].stretch); case Message::StyleGetItalic: return vs.styles[wParam].italic ? 1 : 0; case Message::StyleGetEOLFilled: @@ -7580,6 +7585,7 @@ sptr_t Editor::WndProc(Message iMessage, uptr_t wParam, sptr_t lParam) { case Message::StyleSetBack: case Message::StyleSetBold: case Message::StyleSetWeight: + case Message::StyleSetStretch: case Message::StyleSetItalic: case Message::StyleSetEOLFilled: case Message::StyleSetSize: @@ -7600,6 +7606,7 @@ sptr_t Editor::WndProc(Message iMessage, uptr_t wParam, sptr_t lParam) { case Message::StyleGetBack: case Message::StyleGetBold: case Message::StyleGetWeight: + case Message::StyleGetStretch: case Message::StyleGetItalic: case Message::StyleGetEOLFilled: case Message::StyleGetSize: diff --git a/src/Platform.h b/src/Platform.h index b0d12888d..585ddd14c 100644 --- a/src/Platform.h +++ b/src/Platform.h @@ -108,6 +108,7 @@ struct FontParameters { Scintilla::Technology technology; Scintilla::CharacterSet characterSet; const char *localeName; + Scintilla::FontStretch stretch; constexpr FontParameters( const char *faceName_, @@ -117,7 +118,8 @@ struct FontParameters { Scintilla::FontQuality extraFontFlag_= Scintilla::FontQuality::QualityDefault, Scintilla::Technology technology_= Scintilla::Technology::Default, Scintilla::CharacterSet characterSet_= Scintilla::CharacterSet::Ansi, - const char *localeName_=localeNameDefault) noexcept : + const char *localeName_=localeNameDefault, + Scintilla::FontStretch stretch_=Scintilla::FontStretch::Normal) noexcept : faceName(faceName_), size(size_), @@ -126,7 +128,8 @@ struct FontParameters { extraFontFlag(extraFontFlag_), technology(technology_), characterSet(characterSet_), - localeName(localeName_) + localeName(localeName_), + stretch(stretch_) { } diff --git a/src/Style.cxx b/src/Style.cxx index fcde6398e..228b3db74 100644 --- a/src/Style.cxx +++ b/src/Style.cxx @@ -27,6 +27,7 @@ bool FontSpecification::operator==(const FontSpecification &other) const noexcep weight == other.weight && italic == other.italic && size == other.size && + stretch == other.stretch && characterSet == other.characterSet && extraFontFlag == other.extraFontFlag && checkMonospaced == other.checkMonospaced; @@ -41,6 +42,8 @@ bool FontSpecification::operator<(const FontSpecification &other) const noexcept return !italic; if (size != other.size) return size < other.size; + if (stretch != other.stretch) + return stretch < other.stretch; if (characterSet != other.characterSet) return characterSet < other.characterSet; if (extraFontFlag != other.extraFontFlag) diff --git a/src/Style.h b/src/Style.h index da8159d6c..19679cd04 100644 --- a/src/Style.h +++ b/src/Style.h @@ -15,6 +15,7 @@ struct FontSpecification { const char *fontName; int size; Scintilla::FontWeight weight = Scintilla::FontWeight::Normal; + Scintilla::FontStretch stretch = Scintilla::FontStretch::Normal; bool italic = false; Scintilla::CharacterSet characterSet = Scintilla::CharacterSet::Default; Scintilla::FontQuality extraFontFlag = Scintilla::FontQuality::QualityDefault; diff --git a/src/ViewStyle.cxx b/src/ViewStyle.cxx index f20645251..921463931 100644 --- a/src/ViewStyle.cxx +++ b/src/ViewStyle.cxx @@ -66,7 +66,7 @@ void FontRealised::Realise(Surface &surface, int zoomLevel, Technology technolog 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); + fs.italic, fs.extraFontFlag, technology, fs.characterSet, localeName, fs.stretch); font = Font::Allocate(fp); // floor here is historical as platform layers have tweaked their values to match. diff --git a/win32/PlatWin.cxx b/win32/PlatWin.cxx index ac1fcb51d..176acab10 100644 --- a/win32/PlatWin.cxx +++ b/win32/PlatWin.cxx @@ -347,13 +347,15 @@ struct FontDirectWrite : public FontWin { HRESULT hr = pIDWriteFactory->CreateTextFormat(wsFace.c_str(), nullptr, static_cast<DWRITE_FONT_WEIGHT>(fp.weight), style, - DWRITE_FONT_STRETCH_NORMAL, fHeight, wsLocale.c_str(), &pTextFormat); + static_cast<DWRITE_FONT_STRETCH>(fp.stretch), + fHeight, wsLocale.c_str(), &pTextFormat); if (hr == E_INVALIDARG) { // Possibly a bad locale name like "/" so try "en-us". hr = pIDWriteFactory->CreateTextFormat(wsFace.c_str(), nullptr, static_cast<DWRITE_FONT_WEIGHT>(fp.weight), style, - DWRITE_FONT_STRETCH_NORMAL, fHeight, L"en-us", &pTextFormat); + static_cast<DWRITE_FONT_STRETCH>(fp.stretch), + fHeight, L"en-us", &pTextFormat); } if (SUCCEEDED(hr)) { pTextFormat->SetWordWrapping(DWRITE_WORD_WRAPPING_NO_WRAP); |