aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--doc/ScintillaHistory.html3
-rw-r--r--win32/PlatWin.cxx114
2 files changed, 10 insertions, 107 deletions
diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html
index c14d090b3..2ee03447d 100644
--- a/doc/ScintillaHistory.html
+++ b/doc/ScintillaHistory.html
@@ -605,6 +605,9 @@
for rectangular or thin selection by performing no action.
<a href="https://sourceforge.net/p/scintilla/bugs/2078/">Bug #2078</a>.
</li>
+ <li>
+ Platform layer font cache removed on Win32 as there is a platform-independent cache.
+ </li>
</ul>
<h3>
<a href="https://www.scintilla.org/scite413.zip">Release 4.1.3</a>
diff --git a/win32/PlatWin.cxx b/win32/PlatWin.cxx
index aba2a73a2..8cb5e035a 100644
--- a/win32/PlatWin.cxx
+++ b/win32/PlatWin.cxx
@@ -292,51 +292,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<int>(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 {
@@ -382,67 +342,9 @@ FontCached::FontCached(const FontParameters &fp) :
}
#endif
}
- usage = 1;
-}
-
-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;
+ return fid;
}
-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{} {
@@ -451,18 +353,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.