From cf60b6799dcf30c8b5cbc1cbb1f48eb45abfaf29 Mon Sep 17 00:00:00 2001 From: Neil Date: Sat, 10 Jan 2015 10:43:34 +1100 Subject: On Windows GDI, assume font names are encoded in UTF-8 and use wide character calls to allow use of Asian font names. --- doc/ScintillaDoc.html | 12 ++++++++---- doc/ScintillaHistory.html | 3 +++ win32/PlatWin.cxx | 20 ++++++++++++-------- win32/ScintillaWin.cxx | 12 +++++++----- 4 files changed, 30 insertions(+), 17 deletions(-) diff --git a/doc/ScintillaDoc.html b/doc/ScintillaDoc.html index 1afc6d77e..ed66afa69 100644 --- a/doc/ScintillaDoc.html +++ b/doc/ScintillaDoc.html @@ -82,7 +82,7 @@

Scintilla Documentation

-

Last edited 24 November 2014 NH

+

Last edited 10 January 2015 NH

There is an overview of the internal design of Scintilla.
@@ -2577,11 +2577,15 @@ struct Sci_TextToFind { SCI_STYLEGETITALIC(int styleNumber)
These messages (plus SCI_STYLESETCHARACTERSET) set the font - attributes that are used to match the fonts you request to those available. The + attributes that are used to match the fonts you request to those available.

+

The fontName is a zero terminated string holding the name of a font. Under Windows, - only the first 32 characters of the name are used and the name is not case sensitive. For + only the first 32 characters of the name are used, the name is decoded as UTF-8, and the name is not case sensitive. For internal caching, Scintilla tracks fonts by name and does care about the casing of font names, - so please be consistent. On GTK+, Pango is used to display text.

+ so please be consistent. + On GTK+, Pango is used to display text and the name is sent directly to Pango without transformation. + On Qt, the name is decoded as UTF-8. + On Cocoa, the name is decoded as MacRoman.

Sizes can be set to a whole number of points with SCI_STYLESETSIZE or to a fractional point size in hundredths of a point with SCI_STYLESETSIZEFRACTIONAL by multiplying the size by 100 (SC_FONT_SIZE_MULTIPLIER). diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html index c4d420452..b51dc04bd 100644 --- a/doc/ScintillaHistory.html +++ b/doc/ScintillaHistory.html @@ -510,6 +510,9 @@ When a text margin is displayed, for annotation lines, use the background colour of the base line.

  • + On Windows GDI, assume font names are encoded in UTF-8. This matches the Direct2D code path. +
  • +
  • Fix paste for GTK+ on OS X. Bug #1677.
  • diff --git a/win32/PlatWin.cxx b/win32/PlatWin.cxx index 4becdc507..7407d64f0 100644 --- a/win32/PlatWin.cxx +++ b/win32/PlatWin.cxx @@ -275,15 +275,15 @@ static D2D1_TEXT_ANTIALIAS_MODE DWriteMapFontQuality(int extraFontFlag) { } #endif -static void SetLogFont(LOGFONTA &lf, const char *faceName, int characterSet, float size, int weight, bool italic, int extraFontFlag) { - lf = LOGFONTA(); +static void SetLogFont(LOGFONTW &lf, const char *faceName, int characterSet, float size, int weight, bool italic, int extraFontFlag) { + lf = LOGFONTW(); // The negative is to allow for leading lf.lfHeight = -(abs(static_cast(size + 0.5))); lf.lfWeight = weight; lf.lfItalic = static_cast(italic ? 1 : 0); lf.lfCharSet = static_cast(characterSet); lf.lfQuality = Win32MapFontQuality(extraFontFlag); - StringCopy(lf.lfFaceName, faceName); + UTF16FromUTF8(faceName, strlen(faceName)+1, lf.lfFaceName, LF_FACESIZE); } /** @@ -306,7 +306,7 @@ class FontCached : Font { FontCached *next; int usage; float size; - LOGFONTA lf; + LOGFONTW lf; int technology; int hash; explicit FontCached(const FontParameters &fp); @@ -329,7 +329,7 @@ FontCached::FontCached(const FontParameters &fp) : hash = HashFont(fp); fid = 0; if (technology == SCWIN_TECH_GDI) { - HFONT hfont = ::CreateFontIndirectA(&lf); + HFONT hfont = ::CreateFontIndirectW(&lf); fid = reinterpret_cast(new FormatAndMetrics(hfont, fp.extraFontFlag, fp.characterSet)); } else { #if defined(USE_D2D) @@ -378,14 +378,18 @@ FontCached::FontCached(const FontParameters &fp) : } bool FontCached::SameAs(const FontParameters &fp) { - return + if ( (size == fp.size) && (lf.lfWeight == fp.weight) && (lf.lfItalic == static_cast(fp.italic ? 1 : 0)) && (lf.lfCharSet == fp.characterSet) && (lf.lfQuality == Win32MapFontQuality(fp.extraFontFlag)) && - (technology == fp.technology) && - 0 == strcmp(lf.lfFaceName,fp.faceName); + (technology == fp.technology)) { + wchar_t wszFace[LF_FACESIZE]; + UTF16FromUTF8(fp.faceName, strlen(fp.faceName)+1, wszFace, LF_FACESIZE); + return 0 == wcscmp(lf.lfFaceName,wszFace); + } + return false; } void FontCached::Release() { diff --git a/win32/ScintillaWin.cxx b/win32/ScintillaWin.cxx index 070ab0fb2..0dd715d6d 100644 --- a/win32/ScintillaWin.cxx +++ b/win32/ScintillaWin.cxx @@ -2459,7 +2459,7 @@ void ScintillaWin::ImeStartComposition() { // Since the style creation code has been made platform independent, // The logfont for the IME is recreated here. int styleHere = (pdoc->StyleAt(sel.MainCaret())) & 31; - LOGFONTA lf = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ""}; + LOGFONTW lf = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, L""}; int sizeZoomed = vs.styles[styleHere].size + vs.zoomLevel * SC_FONT_SIZE_MULTIPLIER; if (sizeZoomed <= 2 * SC_FONT_SIZE_MULTIPLIER) // Hangs if sizeZoomed <= 1 sizeZoomed = 2 * SC_FONT_SIZE_MULTIPLIER; @@ -2473,11 +2473,13 @@ void ScintillaWin::ImeStartComposition() { lf.lfWeight = vs.styles[styleHere].weight; lf.lfItalic = static_cast(vs.styles[styleHere].italic ? 1 : 0); lf.lfCharSet = DEFAULT_CHARSET; - lf.lfFaceName[0] = '\0'; - if (vs.styles[styleHere].fontName) - StringCopy(lf.lfFaceName, vs.styles[styleHere].fontName); + lf.lfFaceName[0] = L'\0'; + if (vs.styles[styleHere].fontName) { + const char* fontName = vs.styles[styleHere].fontName; + UTF16FromUTF8(fontName, strlen(fontName)+1, lf.lfFaceName, LF_FACESIZE); + } - ::ImmSetCompositionFontA(hIMC, &lf); + ::ImmSetCompositionFontW(hIMC, &lf); } ::ImmReleaseContext(MainHWND(), hIMC); // Caret is displayed in IME window. So, caret in Scintilla is useless. -- cgit v1.2.3