From 42eae314b5ff1b0aa511a01edde369906f6674dd Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Mon, 25 Feb 2019 12:48:46 +0100 Subject: [PATCH] + upd: current scintilla development --- ced/ced/compact_enc_det/compact_enc_det.h | 2 +- scintilla/doc/ScintillaHistory.html | 3 + scintilla/win32/PlatWin.cxx | 201 +++++----------------- scintilla/win32/PlatWin.h | 6 +- 4 files changed, 53 insertions(+), 159 deletions(-) diff --git a/ced/ced/compact_enc_det/compact_enc_det.h b/ced/ced/compact_enc_det/compact_enc_det.h index 379652072..05f0f9817 100644 --- a/ced/ced/compact_enc_det/compact_enc_det.h +++ b/ced/ced/compact_enc_det/compact_enc_det.h @@ -78,6 +78,6 @@ namespace CompactEncDet { Encoding TopEncodingOfTLDHint(const char* name); Encoding TopEncodingOfCharsetHint(const char* name); const char* Version(); -}; // End namespace CompactEncDet +} // End namespace CompactEncDet #endif // COMPACT_ENC_DET_COMPACT_ENC_DET_H_ diff --git a/scintilla/doc/ScintillaHistory.html b/scintilla/doc/ScintillaHistory.html index c14d090b3..2ee03447d 100644 --- a/scintilla/doc/ScintillaHistory.html +++ b/scintilla/doc/ScintillaHistory.html @@ -605,6 +605,9 @@ for rectangular or thin selection by performing no action. Bug #2078. +
  • + Platform layer font cache removed on Win32 as there is a platform-independent cache. +
  • Release 4.1.3 diff --git a/scintilla/win32/PlatWin.cxx b/scintilla/win32/PlatWin.cxx index 67307bbaf..35fcb899a 100644 --- a/scintilla/win32/PlatWin.cxx +++ b/scintilla/win32/PlatWin.cxx @@ -62,12 +62,6 @@ namespace Scintilla { UINT CodePageFromCharSet(DWORD characterSet, UINT documentCodePage); -RECT RectFromPRectangle(PRectangle prc) noexcept { - RECT rc = {static_cast(prc.left), static_cast(prc.top), - static_cast(prc.right), static_cast(prc.bottom)}; - return rc; -} - #if defined(USE_D2D) IDWriteFactory *pIDWriteFactory = nullptr; ID2D1Factory *pD2DFactory = nullptr; @@ -152,7 +146,7 @@ struct FormatAndMetrics { FLOAT yAscent; FLOAT yDescent; FLOAT yInternalLeading; - FormatAndMetrics(HFONT hfont_, int extraFontFlag_, int characterSet_) : + FormatAndMetrics(HFONT hfont_, int extraFontFlag_, int characterSet_) noexcept : technology(SCWIN_TECH_GDI), hfont(hfont_), #if defined(USE_D2D) pTextFormat(nullptr), @@ -165,7 +159,7 @@ struct FormatAndMetrics { int characterSet_, FLOAT yAscent_, FLOAT yDescent_, - FLOAT yInternalLeading_) : + FLOAT yInternalLeading_) noexcept : technology(SCWIN_TECH_DIRECTWRITE), hfont{}, pTextFormat(pTextFormat_), @@ -228,11 +222,11 @@ HFONT FormatAndMetrics::HFont() { namespace { -void *PointerFromWindow(HWND hWnd) { +void *PointerFromWindow(HWND hWnd) noexcept { return reinterpret_cast(::GetWindowLongPtr(hWnd, 0)); } -void SetWindowPointer(HWND hWnd, void *ptr) { +void SetWindowPointer(HWND hWnd, void *ptr) noexcept { ::SetWindowLongPtr(hWnd, 0, reinterpret_cast(ptr)); } @@ -241,11 +235,11 @@ HINSTANCE hinstPlatformRes {}; HCURSOR reverseArrowCursor {}; -FormatAndMetrics *FamFromFontID(void *fid) { +FormatAndMetrics *FamFromFontID(void *fid) noexcept { return static_cast(fid); } -BYTE Win32MapFontQuality(int extraFontFlag) { +constexpr BYTE Win32MapFontQuality(int extraFontFlag) noexcept { switch (extraFontFlag & SC_EFF_QUALITY_MASK) { case SC_EFF_QUALITY_NON_ANTIALIASED: @@ -263,7 +257,7 @@ BYTE Win32MapFontQuality(int extraFontFlag) { } #if defined(USE_D2D) -D2D1_TEXT_ANTIALIAS_MODE DWriteMapFontQuality(int extraFontFlag) { +constexpr D2D1_TEXT_ANTIALIAS_MODE DWriteMapFontQuality(int extraFontFlag) noexcept { switch (extraFontFlag & SC_EFF_QUALITY_MASK) { case SC_EFF_QUALITY_NON_ANTIALIASED: @@ -292,51 +286,11 @@ void SetLogFont(LOGFONTW &lf, const char *faceName, int characterSet, float size UTF16FromUTF8(faceName, lf.lfFaceName, LF_FACESIZE); } -/** - * Create a hash from the parameters for a font to allow easy checking for identity. - * If one font is the same as another, its hash will be the same, but if the hash is the - * same then they may still be different. - */ -int HashFont(const FontParameters &fp) noexcept { - return - static_cast(fp.size) ^ - (fp.characterSet << 10) ^ - ((fp.extraFontFlag & SC_EFF_QUALITY_MASK) << 9) ^ - ((fp.weight/100) << 12) ^ - (fp.italic ? 0x20000000 : 0) ^ - (fp.technology << 15) ^ - fp.faceName[0]; -} - -} - -class FontCached : Font { - FontCached *next; - int usage; - float size; +FontID CreateFontFromParameters(const FontParameters &fp) { LOGFONTW lf; - int technology; - int hash; - explicit FontCached(const FontParameters &fp); - bool SameAs(const FontParameters &fp); - void Release() override; - - static FontCached *first; -public: - ~FontCached() override {} - static FontID FindOrCreate(const FontParameters &fp); - static void ReleaseId(FontID fid_); -}; - -FontCached *FontCached::first = nullptr; - -FontCached::FontCached(const FontParameters &fp) : - next(nullptr), usage(0), size(1.0), hash(0) { SetLogFont(lf, fp.faceName, fp.characterSet, fp.size, fp.weight, fp.italic, fp.extraFontFlag); - technology = fp.technology; - hash = HashFont(fp); - fid = 0; - if (technology == SCWIN_TECH_GDI) { + FontID fid = nullptr; + if (fp.technology == SCWIN_TECH_GDI) { HFONT hfont = ::CreateFontIndirectW(&lf); fid = new FormatAndMetrics(hfont, fp.extraFontFlag, fp.characterSet); } else { @@ -347,18 +301,11 @@ FontCached::FontCached(const FontParameters &fp) : UTF16FromUTF8(fp.faceName, wszFace, faceSize); const FLOAT fHeight = fp.size; const DWRITE_FONT_STYLE style = fp.italic ? DWRITE_FONT_STYLE_ITALIC : DWRITE_FONT_STYLE_NORMAL; - - //HRESULT hr = pIDWriteFactory->CreateTextFormat(wszFace, nullptr, - // static_cast(fp.weight), - // style, - // DWRITE_FONT_STRETCH_NORMAL, fHeight, L"en-us", &pTextFormat); - // patch for rendering chineese fonts: (https://sourceforge.net/p/scintilla/bugs/2027/) - HRESULT hr = pIDWriteFactory->CreateTextFormat(wszFace, nullptr, - static_cast(fp.weight), - style, - DWRITE_FONT_STRETCH_NORMAL, fHeight, L"", &pTextFormat); - - if (SUCCEEDED(hr)) { + HRESULT hr = pIDWriteFactory->CreateTextFormat(wszFace, nullptr, + static_cast(fp.weight), + style, + DWRITE_FONT_STRETCH_NORMAL, fHeight, L"en-us", &pTextFormat); + if (SUCCEEDED(hr)) { pTextFormat->SetWordWrapping(DWRITE_WORD_WRAPPING_NO_WRAP); FLOAT yAscent = 1.0f; @@ -389,67 +336,9 @@ FontCached::FontCached(const FontParameters &fp) : } #endif } - usage = 1; + return fid; } -bool FontCached::SameAs(const FontParameters &fp) { - if ( - (size == fp.size) && - (lf.lfWeight == fp.weight) && - (lf.lfItalic == (fp.italic ? 1 : 0)) && - (lf.lfCharSet == fp.characterSet) && - (lf.lfQuality == Win32MapFontQuality(fp.extraFontFlag)) && - (technology == fp.technology)) { - wchar_t wszFace[LF_FACESIZE] = L""; - UTF16FromUTF8(fp.faceName, wszFace, LF_FACESIZE); - return 0 == wcscmp(lf.lfFaceName,wszFace); - } - return false; -} - -void FontCached::Release() { - delete FamFromFontID(fid); - fid = nullptr; -} - -FontID FontCached::FindOrCreate(const FontParameters &fp) { - FontID ret {}; - ::EnterCriticalSection(&crPlatformLock); - const int hashFind = HashFont(fp); - for (FontCached *cur=first; cur; cur=cur->next) { - if ((cur->hash == hashFind) && - cur->SameAs(fp)) { - cur->usage++; - ret = cur->fid; - } - } - if (!ret) { - FontCached *fc = new FontCached(fp); - fc->next = first; - first = fc; - ret = fc->fid; - } - ::LeaveCriticalSection(&crPlatformLock); - return ret; -} - -void FontCached::ReleaseId(FontID fid_) { - ::EnterCriticalSection(&crPlatformLock); - FontCached **pcur=&first; - for (FontCached *cur=first; cur; cur=cur->next) { - if (cur->fid == fid_) { - cur->usage--; - if (cur->usage == 0) { - *pcur = cur->next; - cur->Release(); - cur->next = nullptr; - delete cur; - } - break; - } - pcur=&cur->next; - } - ::LeaveCriticalSection(&crPlatformLock); } Font::Font() noexcept : fid{} { @@ -458,18 +347,16 @@ Font::Font() noexcept : fid{} { Font::~Font() { } -#define FONTS_CACHED - void Font::Create(const FontParameters &fp) { Release(); if (fp.faceName) - fid = FontCached::FindOrCreate(fp); + fid = CreateFontFromParameters(fp); } void Font::Release() { if (fid) - FontCached::ReleaseId(fid); - fid = 0; + delete FamFromFontID(fid); + fid = nullptr; } // Buffer to hold strings and string position arrays without always allocating on heap. @@ -538,17 +425,17 @@ class SurfaceGDI : public Surface { void BrushColor(ColourDesired back); void SetFont(Font &font_); - void Clear(); + void Clear() noexcept; public: - SurfaceGDI(); + SurfaceGDI() noexcept; // Deleted so SurfaceGDI objects can not be copied. SurfaceGDI(const SurfaceGDI &) = delete; SurfaceGDI(SurfaceGDI &&) = delete; SurfaceGDI &operator=(const SurfaceGDI &) = delete; SurfaceGDI &operator=(SurfaceGDI &&) = delete; - ~SurfaceGDI() override; + ~SurfaceGDI() noexcept override; void Init(WindowID wid) override; void Init(SurfaceID sid, WindowID wid) override; @@ -595,14 +482,14 @@ public: void SetBidiR2L(bool bidiR2L_) override; }; -SurfaceGDI::SurfaceGDI() { +SurfaceGDI::SurfaceGDI() noexcept { } -SurfaceGDI::~SurfaceGDI() { +SurfaceGDI::~SurfaceGDI() noexcept { Clear(); } -void SurfaceGDI::Clear() { +void SurfaceGDI::Clear() noexcept { if (penOld) { ::SelectObject(hdc, penOld); ::DeleteObject(pen); @@ -769,7 +656,7 @@ void SurfaceGDI::RoundedRectangle(PRectangle rc, ColourDesired fore, ColourDesir namespace { // Plot a point into a DWORD buffer symmetrically to all 4 quadrants -void __forceinline AllFour(DWORD *pixels, int width, int height, int x, int y, DWORD val) { +void AllFour(DWORD *pixels, int width, int height, int x, int y, DWORD val) noexcept { pixels[y*width+x] = val; pixels[y*width+width-1-x] = val; pixels[(height-1-y)*width+x] = val; @@ -788,7 +675,7 @@ DWORD dwordFromBGRA(byte b, byte g, byte r, byte a) noexcept { return converter.val; } -DWORD dwordMultiplied(ColourDesired colour, unsigned int alpha) { +DWORD dwordMultiplied(ColourDesired colour, unsigned int alpha) noexcept { return dwordFromBGRA( static_cast(colour.GetBlue() * alpha / 255), static_cast(colour.GetGreen() * alpha / 255), @@ -1104,11 +991,11 @@ class SurfaceD2D : public Surface { float dpiScaleX; float dpiScaleY; - void Clear(); + void Clear() noexcept; void SetFont(Font &font_); public: - SurfaceD2D(); + SurfaceD2D() noexcept; // Deleted so SurfaceD2D objects can not be copied. SurfaceD2D(const SurfaceD2D &) = delete; SurfaceD2D(SurfaceD2D &&) = delete; @@ -1166,7 +1053,7 @@ public: void SetBidiR2L(bool bidiR2L_) override; }; -SurfaceD2D::SurfaceD2D() : +SurfaceD2D::SurfaceD2D() noexcept : unicodeMode(false), x(0), y(0) { @@ -1194,7 +1081,7 @@ SurfaceD2D::~SurfaceD2D() { Clear(); } -void SurfaceD2D::Clear() { +void SurfaceD2D::Clear() noexcept { if (pBrush) { pBrush->Release(); pBrush = nullptr; @@ -1326,7 +1213,7 @@ void SurfaceD2D::MoveTo(int x_, int y_) { y = y_; } -static int Delta(int difference) { +static constexpr int Delta(int difference) noexcept { if (difference < 0) return -1; else if (difference > 0) @@ -2227,7 +2114,7 @@ Surface *Surface::Allocate(int technology) { namespace { -HWND HwndFromWindowID(WindowID wid) { +HWND HwndFromWindowID(WindowID wid) noexcept { return static_cast(wid); } @@ -2256,14 +2143,14 @@ void Window::SetPosition(PRectangle rc) { namespace { -static RECT RectFromMonitor(HMONITOR hMonitor) { +static RECT RectFromMonitor(HMONITOR hMonitor) noexcept { MONITORINFO mi = {}; mi.cbSize = sizeof(mi); if (GetMonitorInfo(hMonitor, &mi)) { return mi.rcWork; } RECT rc = {0, 0, 0, 0}; - if (::SystemParametersInfo(SPI_GETWORKAREA, 0, &rc, 0) == 0) { + if (::SystemParametersInfoA(SPI_GETWORKAREA, 0, &rc, 0) == 0) { rc.left = 0; rc.top = 0; rc.right = 0; @@ -2335,7 +2222,7 @@ void Window::SetFont(Font &font) { namespace { -void FlipBitmap(HBITMAP bitmap, int width, int height) { +void FlipBitmap(HBITMAP bitmap, int width, int height) noexcept { HDC hdc = ::CreateCompatibleDC(NULL); if (hdc) { HBITMAP prevBmp = SelectBitmap(hdc, bitmap); @@ -2345,7 +2232,7 @@ void FlipBitmap(HBITMAP bitmap, int width, int height) { } } -HCURSOR GetReverseArrowCursor() { +HCURSOR GetReverseArrowCursor() noexcept { if (reverseArrowCursor) return reverseArrowCursor; @@ -2440,7 +2327,7 @@ class LineToItem { std::vector data; public: - void Clear() { + void Clear() noexcept { words.clear(); data.clear(); } @@ -2453,7 +2340,7 @@ public: return missing; } } - int Count() const { + int Count() const noexcept { return static_cast(data.size()); } @@ -3303,7 +3190,7 @@ LRESULT PASCAL ListBoxX::StaticWndProc( namespace { -bool ListBoxX_Register() { +bool ListBoxX_Register() noexcept { WNDCLASSEX wndclassc; wndclassc.cbSize = sizeof(wndclassc); // We need CS_HREDRAW and CS_VREDRAW because of the ellipsis that might be drawn for @@ -3324,7 +3211,7 @@ bool ListBoxX_Register() { return ::RegisterClassEx(&wndclassc) != 0; } -bool ListBoxX_Unregister() { +bool ListBoxX_Unregister() noexcept { return ::UnregisterClass(ListBoxX_ClassName, hinstPlatformRes) != 0; } @@ -3355,7 +3242,7 @@ class DynamicLibraryImpl : public DynamicLibrary { protected: HMODULE h; public: - explicit DynamicLibraryImpl(const char *modulePath) { + explicit DynamicLibraryImpl(const char *modulePath) noexcept { h = ::LoadLibraryA(modulePath); } @@ -3365,7 +3252,7 @@ public: } // Use GetProcAddress to get a pointer to the relevant function. - Function FindFunction(const char *name) override { + Function FindFunction(const char *name) noexcept override { if (h) { // C++ standard doesn't like casts between function pointers and void pointers so use a union union { @@ -3379,7 +3266,7 @@ public: } } - bool IsValid() override { + bool IsValid() noexcept override { return h != NULL; } }; diff --git a/scintilla/win32/PlatWin.h b/scintilla/win32/PlatWin.h index cf357f72d..62b87fa3c 100644 --- a/scintilla/win32/PlatWin.h +++ b/scintilla/win32/PlatWin.h @@ -13,7 +13,11 @@ namespace Scintilla { extern void Platform_Initialise(void *hInstance); extern void Platform_Finalise(bool fromDllMain); -RECT RectFromPRectangle(PRectangle prc) noexcept; +constexpr RECT RectFromPRectangle(PRectangle prc) noexcept { + RECT rc = { static_cast(prc.left), static_cast(prc.top), + static_cast(prc.right), static_cast(prc.bottom) }; + return rc; +} #if defined(USE_D2D) extern bool LoadD2D();