vcl/inc/win/saldata.hxx |    5 ++---
 vcl/win/app/salinst.cxx |    3 +--
 vcl/win/gdi/salfont.cxx |   37 ++++++++++---------------------------
 vcl/win/gdi/salgdi.cxx  |    6 +-----
 4 files changed, 14 insertions(+), 37 deletions(-)

New commits:
commit 87ef004115d07c16fe4899b3d423cc16a12a0fce
Author:     Mike Kaganski <[email protected]>
AuthorDate: Thu Aug 7 18:29:41 2025 +0500
Commit:     Mike Kaganski <[email protected]>
CommitDate: Thu Aug 7 20:26:49 2025 +0200

    tdf#167849: don't release embedded fonts in 
WinSalGraphics::ClearDevFontCache
    
    Commit 8e63934c398dd5065f3589c8a7d1b3008f5514d1 (WIN separate LO shared and
    embedded fonts, 2019-07-05) made the call only release embedded fonts, not
    all temporary fonts. But embedded fonts must not be released there, too:
    they are not re-added back by anything. Therefore, any reload of font data
    drops all open documents' embedded fonts: this could be opening another
    document with embedded font, or a user installing a font in their system.
    
    Clearing embedded fonts itself could be a useful operation, performed when
    a document ownong the font is closed. But that must be implemented properly
    for all platforms, counting references for each such font; additionally, it
    could handle restricted fonts correctly, not showing them in font list.
    
    Change-Id: I239f15cef64c94522e70e17e295b572664317bfc
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/189100
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <[email protected]>

diff --git a/vcl/inc/win/saldata.hxx b/vcl/inc/win/saldata.hxx
index 4f6dd1042676..e623e45ecd19 100644
--- a/vcl/inc/win/saldata.hxx
+++ b/vcl/inc/win/saldata.hxx
@@ -116,8 +116,7 @@ public:
     bool                    mbObjClassInit;         // is SALOBJECTCLASS 
initialised
     DWORD                   mnAppThreadId;          // Id from 
Application-Thread
     SalIcon*                mpFirstIcon;            // icon cache, points to 
first icon, NULL if none
-    TempFontItem*           mpSharedTempFontItem;   // LibreOffice shared fonts
-    TempFontItem*           mpOtherTempFontItem;    // other temporary fonts 
(embedded?)
+    TempFontItem*           mpTempFontItem;         // LibreOffice own fonts 
(shared and embedded)
     bool                    mbThemeChanged;         // true if visual theme 
was changed: throw away theme handles
     bool                    mbThemeMenuSupport;
 
@@ -146,7 +145,7 @@ void ImplClearHDCCache( SalData* pData );
 HDC ImplGetCachedDC( sal_uLong nID, HBITMAP hBmp = nullptr );
 void ImplReleaseCachedDC( sal_uLong nID );
 
-void ImplReleaseTempFonts(SalData&, bool bAll);
+void ImplReleaseTempFonts(SalData&);
 
 HCURSOR ImplLoadSalCursor( int nId );
 HBITMAP ImplLoadSalBitmap( int nId );
diff --git a/vcl/win/app/salinst.cxx b/vcl/win/app/salinst.cxx
index f0b7c0f510b6..aa36856ec78e 100644
--- a/vcl/win/app/salinst.cxx
+++ b/vcl/win/app/salinst.cxx
@@ -272,8 +272,7 @@ SalData::SalData()
     mbObjClassInit = false;     // is SALOBJECTCLASS initialised
     mnAppThreadId = 0;          // Id from Application-Thread
     mpFirstIcon = nullptr;      // icon cache, points to first icon, NULL if 
none
-    mpSharedTempFontItem = nullptr;
-    mpOtherTempFontItem = nullptr;
+    mpTempFontItem = nullptr;
     mbThemeChanged = false;     // true if visual theme was changed: throw 
away theme handles
     mbThemeMenuSupport = false;
 
diff --git a/vcl/win/gdi/salfont.cxx b/vcl/win/gdi/salfont.cxx
index e1794d888e01..7f5252adfbd9 100644
--- a/vcl/win/gdi/salfont.cxx
+++ b/vcl/win/gdi/salfont.cxx
@@ -904,7 +904,7 @@ struct TempFontItem
     TempFontItem* mpNextItem;
 };
 
-static int lcl_AddFontResource(SalData& rSalData, const OUString& 
rFontFileURL, bool bShared)
+static int lcl_AddFontResource(SalData& rSalData, const OUString& rFontFileURL)
 {
     OUString aFontSystemPath;
     OSL_VERIFY(!osl::FileBase::getSystemPathFromFileURL(rFontFileURL, 
aFontSystemPath));
@@ -916,35 +916,19 @@ static int lcl_AddFontResource(SalData& rSalData, const 
OUString& rFontFileURL,
 
     TempFontItem* pNewItem = new TempFontItem;
     pNewItem->maFontResourcePath = aFontSystemPath;
-    if (bShared)
-    {
-        pNewItem->mpNextItem = rSalData.mpSharedTempFontItem;
-        rSalData.mpSharedTempFontItem = pNewItem;
-    }
-    else
-    {
-        pNewItem->mpNextItem = rSalData.mpOtherTempFontItem;
-        rSalData.mpOtherTempFontItem = pNewItem;
-    }
+
+    pNewItem->mpNextItem = rSalData.mpTempFontItem;
+    rSalData.mpTempFontItem = pNewItem;
+
     return nRet;
 }
 
-void ImplReleaseTempFonts(SalData& rSalData, bool bAll)
+void ImplReleaseTempFonts(SalData& rSalData)
 {
-    while (TempFontItem* p = rSalData.mpOtherTempFontItem)
-    {
-        RemoveFontResourceExW(o3tl::toW(p->maFontResourcePath.getStr()), 
FR_PRIVATE, nullptr);
-        rSalData.mpOtherTempFontItem = p->mpNextItem;
-        delete p;
-    }
-
-    if (!bAll)
-        return;
-
-    while (TempFontItem* p = rSalData.mpSharedTempFontItem)
+    while (TempFontItem* p = rSalData.mpTempFontItem)
     {
         RemoveFontResourceExW(o3tl::toW(p->maFontResourcePath.getStr()), 
FR_PRIVATE, nullptr);
-        rSalData.mpSharedTempFontItem = p->mpNextItem;
+        rSalData.mpTempFontItem = p->mpNextItem;
         delete p;
     }
 }
@@ -1017,7 +1001,7 @@ bool 
WinSalGraphics::AddTempDevFont(vcl::font::PhysicalFontCollection* pFontColl
         return false;
     }
 
-    int nFonts = lcl_AddFontResource(*GetSalData(), rFontFileURL, false);
+    int nFonts = lcl_AddFontResource(*GetSalData(), rFontFileURL);
     if (nFonts <= 0)
         return false;
 
@@ -1061,7 +1045,7 @@ void WinSalGraphics::GetDevFontList( 
vcl::font::PhysicalFontCollection* pFontCol
                     osl::FileStatus aFileStatus(osl_FileStatus_Mask_FileURL);
                     rcOSL = aDirItem.getFileStatus(aFileStatus);
                     if (rcOSL == osl::FileBase::E_None)
-                        lcl_AddFontResource(*pSalData, 
aFileStatus.getFileURL(), true);
+                        lcl_AddFontResource(*pSalData, 
aFileStatus.getFileURL());
                 }
             }
         };
@@ -1103,7 +1087,6 @@ void WinSalGraphics::GetDevFontList( 
vcl::font::PhysicalFontCollection* pFontCol
 void WinSalGraphics::ClearDevFontCache()
 {
     mWinSalGraphicsImplBase->ClearDevFontCache();
-    ImplReleaseTempFonts(*GetSalData(), false);
 }
 
 bool WinFontInstance::GetGlyphOutline(sal_GlyphId nId, 
basegfx::B2DPolyPolygon& rB2DPolyPoly, bool) const
diff --git a/vcl/win/gdi/salgdi.cxx b/vcl/win/gdi/salgdi.cxx
index 592bf110b50a..b93c08f3b5b1 100644
--- a/vcl/win/gdi/salgdi.cxx
+++ b/vcl/win/gdi/salgdi.cxx
@@ -72,10 +72,6 @@ void ImplInitSalGDI()
     pSalData->mhStockBrushAry[2]        = CreateSolidBrush( 
pSalData->maStockBrushColorAry[2] );
     pSalData->mhStockBrushAry[3]        = CreateSolidBrush( 
pSalData->maStockBrushColorAry[3] );
     pSalData->mnStockBrushCount = 4;
-
-    // initialize temporary font lists
-    pSalData->mpSharedTempFontItem = nullptr;
-    pSalData->mpOtherTempFontItem = nullptr;
 }
 
 void ImplFreeSalGDI()
@@ -121,7 +117,7 @@ void ImplFreeSalGDI()
     }
 
     // delete temporary font list
-    ImplReleaseTempFonts(*pSalData, true);
+    ImplReleaseTempFonts(*pSalData);
 
     pSalData->mbResourcesAlreadyFreed = true;
 }

Reply via email to