vcl/inc/win/salgdi.h | 1 - vcl/win/gdi/salfont.cxx | 18 ++++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-)
New commits: commit 5d85e4810839de525f8add9a49968c11e04dbd5d Author: Mike Kaganski <[email protected]> AuthorDate: Mon Aug 4 16:50:41 2025 +0500 Commit: Mike Kaganski <[email protected]> CommitDate: Mon Aug 4 16:00:13 2025 +0200 Make FontId of WinFontFace monothonically increasing It was generated from the position in font collection; that meant, that after rebuilding the collection, the same id could refer to a different font. (The collection gets refreshed when a document is loaded with embedded fonts; or when a user installs fonts.) The ids are used as keys in a blob cache (WinFontFace::GetHbTable); and that cache isn't rebuilt when the collection is refreshed; it could make a wrong cache entry be used. This fix is from code reading; I don't have a repro scenario. It is unlikely that this would overflow even on 32-bit architecture; and then, it would be no worse than previously. Change-Id: Ifd09cdbcb98b7f739da871fbe47ce1d107f0e886 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/188916 Reviewed-by: Mike Kaganski <[email protected]> Tested-by: Jenkins diff --git a/vcl/inc/win/salgdi.h b/vcl/inc/win/salgdi.h index fdf999e9352a..20e28c7c03bb 100644 --- a/vcl/inc/win/salgdi.h +++ b/vcl/inc/win/salgdi.h @@ -67,7 +67,6 @@ public: rtl::Reference<LogicalFontInstance> CreateFontInstance( const vcl::font::FontSelectPattern& ) const override; sal_IntPtr GetFontId() const override; - void SetFontId( sal_IntPtr nId ) { mnId = nId; } BYTE GetCharSet() const { return meWinCharSet; } BYTE GetPitchAndFamily() const { return mnPitchAndFamily; } diff --git a/vcl/win/gdi/salfont.cxx b/vcl/win/gdi/salfont.cxx index 813d168cae66..4b70a141d6c4 100644 --- a/vcl/win/gdi/salfont.cxx +++ b/vcl/win/gdi/salfont.cxx @@ -250,7 +250,6 @@ struct ImplEnumInfo vcl::font::PhysicalFontCollection* mpList; OUString* mpName; bool mbPrinter; - int mnFontCount; }; } @@ -504,9 +503,15 @@ void ImplSalLogFontToFontW( HDC hDC, const LOGFONTW& rLogFont, Font& rFont ) rFont.SetStrikeout( STRIKEOUT_NONE ); } +static sal_IntPtr getNextFontId() +{ + static sal_IntPtr id; + return ++id; +} + WinFontFace::WinFontFace(const ENUMLOGFONTEXW& rEnumFont, const NEWTEXTMETRICW& rMetric) : vcl::font::PhysicalFontFace(WinFont2DevFontAttributes(rEnumFont, rMetric)), - mnId( 0 ), + mnId(getNextFontId()), meWinCharSet(rEnumFont.elfLogFont.lfCharSet), mnPitchAndFamily(rMetric.tmPitchAndFamily), maLogFont(rEnumFont.elfLogFont) @@ -884,7 +889,6 @@ static int CALLBACK SalEnumFontsProcExW( const LOGFONTW* lpelfe, rtl::Reference<WinFontFace> pData = new WinFontFace(*reinterpret_cast<ENUMLOGFONTEXW const*>(lpelfe), *pMetric); - pData->SetFontId( sal_IntPtr( pInfo->mnFontCount++ ) ); pInfo->mpList->Add( pData.get() ); SAL_INFO("vcl.fonts", "SalEnumFontsProcExW: font added: " << pData->GetFamilyName() << " " << pData->GetStyleName()); @@ -1019,9 +1023,8 @@ bool WinSalGraphics::AddTempDevFont(vcl::font::PhysicalFontCollection* pFontColl ImplEnumInfo aInfo{ .mhDC = getHDC(), .mpList = pFontCollection, .mpName = &aFontFamily, - .mbPrinter = mbPrinter, - .mnFontCount = pFontCollection->Count() }; - const int nExpectedFontCount = aInfo.mnFontCount + nFonts; + .mbPrinter = mbPrinter }; + const int nExpectedFontCount = pFontCollection->Count() + nFonts; LOGFONTW aLogFont = { .lfCharSet = DEFAULT_CHARSET }; @@ -1080,8 +1083,7 @@ void WinSalGraphics::GetDevFontList( vcl::font::PhysicalFontCollection* pFontCol ImplEnumInfo aInfo{ .mhDC = getHDC(), .mpList = pFontCollection, .mpName = nullptr, - .mbPrinter = mbPrinter, - .mnFontCount = 0 }; + .mbPrinter = mbPrinter }; LOGFONTW aLogFont = { .lfCharSet = DEFAULT_CHARSET };
