aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorNeil <nyamatongwe@gmail.com>2021-04-20 10:57:59 +1000
committerNeil <nyamatongwe@gmail.com>2021-04-20 10:57:59 +1000
commit79585e218c40f9010601e8af442b573ece40c5ea (patch)
treed64cab27d7ee75ef5a2a2e567dbe9c8ebd3823e9
parented434975e5de00e91718b075f04492f69c1bb04a (diff)
downloadscintilla-mirror-79585e218c40f9010601e8af442b573ece40c5ea.tar.gz
Bug [#2027]. Implement font locale SCI_SETFONTLOCALE on Win32 using DirectWrite.
-rw-r--r--doc/ScintillaDoc.html20
-rw-r--r--doc/ScintillaHistory.html4
-rw-r--r--include/Scintilla.h2
-rw-r--r--include/Scintilla.iface6
-rw-r--r--src/CallTip.cxx7
-rw-r--r--src/CallTip.h3
-rw-r--r--src/Editor.cxx10
-rw-r--r--src/ScintillaBase.cxx1
-rw-r--r--src/ViewStyle.cxx15
-rw-r--r--src/ViewStyle.h5
-rw-r--r--test/simpleTests.py7
11 files changed, 71 insertions, 9 deletions
diff --git a/doc/ScintillaDoc.html b/doc/ScintillaDoc.html
index f3b26b88f..0443c7a24 100644
--- a/doc/ScintillaDoc.html
+++ b/doc/ScintillaDoc.html
@@ -120,7 +120,7 @@
<h1>Scintilla Documentation</h1>
- <p>Last edited 9 April 2021 NH</p>
+ <p>Last edited 20 April 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 />
@@ -2970,6 +2970,9 @@ struct Sci_TextToFind {
<a class="message" href="#SCI_STYLESETHOTSPOT">SCI_STYLESETHOTSPOT(int style, bool
hotspot)</a><br />
<a class="message" href="#SCI_STYLEGETHOTSPOT">SCI_STYLEGETHOTSPOT(int style) &rarr; bool</a><br />
+ <a class="message" href="#SCI_SETFONTLOCALE">SCI_SETFONTLOCALE(&lt;unused&gt;, const char
+ *fontName)</a><br />
+ <a class="message" href="#SCI_GETFONTLOCALE">SCI_GETFONTLOCALE(&lt;unused&gt;, char *fontName) &rarr; int</a><br />
</code>
<p><b id="SCI_STYLERESETDEFAULT">SCI_STYLERESETDEFAULT</b><br />
@@ -3298,6 +3301,15 @@ struct Sci_TextToFind {
</tbody>
</table>
+ <p><b id="SCI_SETFONTLOCALE">SCI_SETFONTLOCALE(&lt;unused&gt;, const char *localeName)</b><br />
+ <b id="SCI_GETFONTLOCALE">SCI_GETFONTLOCALE(&lt;unused&gt;, char *localeName NUL-terminated) &rarr; int</b><br />
+ These messages set the locale used for font selection with language-dependent glyphs.
+ It may, depending on platform and other circumstances influence the display of text, so setting "zh-Hant" may result in traditional
+ Chinese display and "zh-Hans" may result in simplified Chinese display.
+ It is currently only implemented for Win32 using DirectWrite where the value is passed as the localeName argument to CreateTextFormat.
+ The default value is US English "en-us".
+ </p>
+
<h2 id="CaretAndSelectionStyles">Caret, selection, and hotspot styles</h2>
<p>The selection is shown by changing the foreground and/or background colours. If one of these
@@ -4121,7 +4133,11 @@ struct Sci_TextToFind {
<code>SC_TECHNOLOGY_DIRECTWRITEDC</code> differs from
<code>SC_TECHNOLOGY_DIRECTWRITE</code> by using DirectWrite to draw into a GDI DC.
Since Direct2D buffers drawing, Scintilla's buffering can be turned off with
- <code>SCI_SETBUFFEREDDRAW(0)</code>.</p>
+ <code>SCI_SETBUFFEREDDRAW(0)</code>.
+ When using DirectWrite, you can use
+ <a class="message" href="#SCI_SETFONTLOCALE"><code>SCI_SETFONTLOCALE</code></a>
+ to set an appropriate font locale to draw text with expected language-dependent glyphs.
+ </p>
<p><b id="SCI_SETFONTQUALITY">SCI_SETFONTQUALITY(int fontQuality)</b><br />
<b id="SCI_GETFONTQUALITY">SCI_GETFONTQUALITY &rarr; int</b><br />
diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html
index a63ac8fc3..5ced2dd86 100644
--- a/doc/ScintillaHistory.html
+++ b/doc/ScintillaHistory.html
@@ -582,6 +582,10 @@
On Windows, fix encoding used for text display with DirectWrite.
<a href="https://sourceforge.net/p/scintilla/bugs/2246/">Bug #2246</a>.
</li>
+ <li>
+ Implement font locale SCI_SETFONTLOCALE. Initially only for DirectWrite on Win32.
+ <a href="https://sourceforge.net/p/scintilla/bugs/2027/">Bug #2027</a>.
+ </li>
</ul>
<h3>
<a href="https://www.scintilla.org/scintilla501.zip">Release 5.0.1</a>
diff --git a/include/Scintilla.h b/include/Scintilla.h
index 1ea5d3fa1..ca512ab71 100644
--- a/include/Scintilla.h
+++ b/include/Scintilla.h
@@ -103,6 +103,8 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam,
#define SCI_GETNEXTTABSTOP 2677
#define SC_CP_UTF8 65001
#define SCI_SETCODEPAGE 2037
+#define SCI_SETFONTLOCALE 2760
+#define SCI_GETFONTLOCALE 2761
#define SC_IME_WINDOWED 0
#define SC_IME_INLINE 1
#define SCI_GETIMEINTERACTION 2678
diff --git a/include/Scintilla.iface b/include/Scintilla.iface
index 8cce965cc..946ba1ec8 100644
--- a/include/Scintilla.iface
+++ b/include/Scintilla.iface
@@ -282,6 +282,12 @@ val SC_CP_UTF8=65001
# The SC_CP_UTF8 value can be used to enter Unicode mode.
set void SetCodePage=2037(int codePage,)
+# Set the locale for displaying text.
+set void SetFontLocale=2760(, string localeName)
+
+# Set the locale for displaying text.
+set void GetFontLocale=2761(, stringresult localeName)
+
enu IMEInteraction=SC_IME_
val SC_IME_WINDOWED=0
val SC_IME_INLINE=1
diff --git a/src/CallTip.cxx b/src/CallTip.cxx
index 22f559ef7..f9f3ce7f7 100644
--- a/src/CallTip.cxx
+++ b/src/CallTip.cxx
@@ -272,7 +272,9 @@ void CallTip::MouseClick(Point pt) noexcept {
PRectangle CallTip::CallTipStart(Sci::Position pos, Point pt, int textHeight, const char *defn,
const char *faceName, int size,
int codePage_, int characterSet,
- int technology, const Window &wParent) {
+ int technology,
+ const char *localeName,
+ const Window &wParent) {
clickPlace = 0;
val = defn;
codePage = codePage_;
@@ -283,7 +285,8 @@ PRectangle CallTip::CallTipStart(Sci::Position pos, Point pt, int textHeight, co
inCallTipMode = true;
posStartCallTip = pos;
const XYPOSITION deviceHeight = static_cast<XYPOSITION>(surfaceMeasure->DeviceHeightFont(size));
- const FontParameters fp(faceName, deviceHeight / SC_FONT_SIZE_MULTIPLIER, SC_WEIGHT_NORMAL, false, 0, technology, characterSet);
+ const FontParameters fp(faceName, deviceHeight / SC_FONT_SIZE_MULTIPLIER, SC_WEIGHT_NORMAL,
+ false, 0, technology, characterSet, localeName);
font = Font::Allocate(fp);
// Look for multiple lines in the text
// Only support \n here - simply means container must avoid \r!
diff --git a/src/CallTip.h b/src/CallTip.h
index 6cc89d3a5..f1358a94a 100644
--- a/src/CallTip.h
+++ b/src/CallTip.h
@@ -72,7 +72,8 @@ public:
/// Setup the calltip and return a rectangle of the area required.
PRectangle CallTipStart(Sci::Position pos, Point pt, int textHeight, const char *defn,
const char *faceName, int size, int codePage_,
- int characterSet, int technology, const Window &wParent);
+ int characterSet, int technology, const char *localeName,
+ const Window &wParent);
void CallTipCancel();
diff --git a/src/Editor.cxx b/src/Editor.cxx
index 63ed979d9..208a075aa 100644
--- a/src/Editor.cxx
+++ b/src/Editor.cxx
@@ -7199,6 +7199,16 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) {
case SCI_GETELEMENTALLOWSTRANSLUCENT:
return vs.ElementAllowsTranslucent(static_cast<int>(wParam));
+ case SCI_SETFONTLOCALE:
+ if (lParam) {
+ vs.SetFontLocaleName(CharPtrFromSPtr(lParam));
+ InvalidateStyleRedraw();
+ }
+ break;
+
+ case SCI_GETFONTLOCALE:
+ return StringResult(lParam, vs.localeName.c_str());
+
#ifdef INCLUDE_DEPRECATED_FEATURES
case SCI_SETSTYLEBITS:
vs.EnsureStyle(0xff);
diff --git a/src/ScintillaBase.cxx b/src/ScintillaBase.cxx
index e2fb58206..72bb5f6e0 100644
--- a/src/ScintillaBase.cxx
+++ b/src/ScintillaBase.cxx
@@ -478,6 +478,7 @@ void ScintillaBase::CallTipShow(Point pt, const char *defn) {
CodePage(),
vs.styles[ctStyle].characterSet,
vs.technology,
+ vs.localeName.c_str(),
wMain);
// If the call-tip window would be out of the client
// space
diff --git a/src/ViewStyle.cxx b/src/ViewStyle.cxx
index f553f4205..aa6779728 100644
--- a/src/ViewStyle.cxx
+++ b/src/ViewStyle.cxx
@@ -42,14 +42,15 @@ FontRealised::FontRealised() noexcept = default;
FontRealised::~FontRealised() {
}
-void FontRealised::Realise(Surface &surface, int zoomLevel, int technology, const FontSpecification &fs) {
+void FontRealised::Realise(Surface &surface, int zoomLevel, int technology, const FontSpecification &fs, const char *localeName) {
PLATFORM_ASSERT(fs.fontName);
sizeZoomed = fs.size + zoomLevel * SC_FONT_SIZE_MULTIPLIER;
if (sizeZoomed <= 2 * SC_FONT_SIZE_MULTIPLIER) // Hangs if sizeZoomed <= 1
sizeZoomed = 2 * SC_FONT_SIZE_MULTIPLIER;
const float deviceHeight = static_cast<float>(surface.DeviceHeightFont(sizeZoomed));
- const FontParameters fp(fs.fontName, deviceHeight / SC_FONT_SIZE_MULTIPLIER, fs.weight, fs.italic, fs.extraFontFlag, technology, fs.characterSet);
+ const FontParameters fp(fs.fontName, deviceHeight / SC_FONT_SIZE_MULTIPLIER, fs.weight,
+ fs.italic, fs.extraFontFlag, technology, fs.characterSet, localeName);
font = Font::Allocate(fp);
ascent = static_cast<unsigned int>(surface.Ascent(font.get()));
@@ -152,6 +153,8 @@ ViewStyle::ViewStyle(const ViewStyle &source) : markers(MARKER_MAX + 1), indicat
wrapVisualFlagsLocation = source.wrapVisualFlagsLocation;
wrapVisualStartIndent = source.wrapVisualStartIndent;
wrapIndentMode = source.wrapIndentMode;
+
+ localeName = source.localeName;
}
ViewStyle::~ViewStyle() {
@@ -286,6 +289,8 @@ void ViewStyle::Init(size_t stylesSize_) {
wrapVisualFlagsLocation = 0;
wrapVisualStartIndent = 0;
wrapIndentMode = SC_WRAPINDENT_FIXED;
+
+ localeName = localeNameDefault;
}
void ViewStyle::Refresh(Surface &surface, int tabInChars) {
@@ -307,7 +312,7 @@ void ViewStyle::Refresh(Surface &surface, int tabInChars) {
// Ask platform to allocate each unique font.
for (std::pair<const FontSpecification, std::unique_ptr<FontRealised>> &font : fonts) {
- font.second->Realise(surface, zoomLevel, technology, font.first);
+ font.second->Realise(surface, zoomLevel, technology, font.first, localeName.c_str());
}
// Set the platform font handle and measurements for each style.
@@ -400,6 +405,10 @@ void ViewStyle::SetStyleFontName(int styleIndex, const char *name) {
styles[styleIndex].fontName = fontNames.Save(name);
}
+void ViewStyle::SetFontLocaleName(const char *name) {
+ localeName = name;
+}
+
bool ViewStyle::ProtectionActive() const noexcept {
return someStylesProtected;
}
diff --git a/src/ViewStyle.h b/src/ViewStyle.h
index 7f50804c2..946bd6c60 100644
--- a/src/ViewStyle.h
+++ b/src/ViewStyle.h
@@ -37,7 +37,7 @@ public:
FontRealised &operator=(const FontRealised &) = delete;
FontRealised &operator=(FontRealised &&) = delete;
virtual ~FontRealised();
- void Realise(Surface &surface, int zoomLevel, int technology, const FontSpecification &fs);
+ void Realise(Surface &surface, int zoomLevel, int technology, const FontSpecification &fs, const char *localeName);
};
enum class IndentView {none, real, lookForward, lookBoth};
@@ -168,6 +168,8 @@ public:
int wrapVisualStartIndent;
int wrapIndentMode; // SC_WRAPINDENT_FIXED, _SAME, _INDENT
+ std::string localeName;
+
ViewStyle();
ViewStyle(const ViewStyle &source);
ViewStyle(ViewStyle &&) = delete;
@@ -184,6 +186,7 @@ public:
void ResetDefaultStyle();
void ClearStyles();
void SetStyleFontName(int styleIndex, const char *name);
+ void SetFontLocaleName(const char *name);
bool ProtectionActive() const noexcept;
int ExternalMarginWidth() const noexcept;
int MarginFromLocation(Point pt) const noexcept;
diff --git a/test/simpleTests.py b/test/simpleTests.py
index 89e2ff69c..63efc8019 100644
--- a/test/simpleTests.py
+++ b/test/simpleTests.py
@@ -1916,6 +1916,13 @@ class TestStyleAttributes(unittest.TestCase):
self.ed.SetDefaultFoldDisplayText(0, b"...")
self.assertEquals(self.ed.GetDefaultFoldDisplayText(), b"...")
+ def testFontLocale(self):
+ initialLocale = "en-us".encode("UTF-8")
+ testLocale = "zh-Hans".encode("UTF-8")
+ self.assertEquals(self.ed.GetFontLocale(), initialLocale)
+ self.ed.FontLocale = testLocale
+ self.assertEquals(self.ed.GetFontLocale(), testLocale)
+
class TestIndices(unittest.TestCase):
def setUp(self):
self.xite = Xite.xiteFrame