vcl/source/gdi/embeddedfontsmanager.cxx | 44 ++++++++++---------------------- 1 file changed, 14 insertions(+), 30 deletions(-)
New commits: commit ab22883f9d2ee21c8f825435624d9cd4e630552f Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Wed Aug 13 16:03:20 2025 +0500 Commit: Mike Kaganski <mike.kagan...@collabora.com> CommitDate: Thu Aug 14 13:19:22 2025 +0200 Drop the local mutex; rely on solar mutex locked here The import and export code are guarded by the solar mutex. I also think, that font list code will be guarded by that. See https://gerrit.libreoffice.org/c/core/+/189347/comment/aa2b0bc4_7831c1b9/ This allowed to simplify the check if the font is pre-installed on the system. Change-Id: I29ea2b5ceca328034cc438530133a467cf9e23a9 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/189507 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> diff --git a/vcl/source/gdi/embeddedfontsmanager.cxx b/vcl/source/gdi/embeddedfontsmanager.cxx index 79e8068ac482..5fd98f917d8b 100644 --- a/vcl/source/gdi/embeddedfontsmanager.cxx +++ b/vcl/source/gdi/embeddedfontsmanager.cxx @@ -10,7 +10,6 @@ #include <sal/config.h> #include <memory> -#include <mutex> #include <set> #include <unordered_map> #include <frozen/bits/defines.h> @@ -24,6 +23,7 @@ #include <rtl/bootstrap.hxx> #include <rtl/uri.hxx> #include <sal/log.hxx> +#include <tools/debug.hxx> #include <vcl/svapp.hxx> #include <vcl/embeddedfontsmanager.hxx> #include <com/sun/star/io/XInputStream.hpp> @@ -77,28 +77,9 @@ struct EmbeddedFontData bool isActivated = false; }; -std::mutex s_EmbeddedFontsMutex; // file URL -> EmbeddedFontData std::unordered_map<OUString, EmbeddedFontData> s_EmbeddedFonts; -bool isFontAvailableUnrestricted(std::u16string_view family, const OUString& fileURL) -{ - // Check if the font is already installed on system. It is either available and not among - // existing embedded files; or it could be listed among embedded, but without restrictions - // (because it was checked here before, and restrictions were removed). The idea is, that - // you can always edit your files with the restricted fonts taken from your own system. - - if (Application::GetDefaultDevice()->IsFontAvailable(family)) - { - std::unique_lock lock(s_EmbeddedFontsMutex); - auto it = s_EmbeddedFonts.find(fileURL); - if (it == s_EmbeddedFonts.end() || !it->second.isRestricted) - return true; - } - - return false; -} - void clearDir( const OUString& path ) { osl::Directory dir( path ); @@ -346,18 +327,20 @@ bool EmbeddedFontsManager::addEmbeddedFont( const uno::Reference< io::XInputStre if (fileUrl.isEmpty()) return false; - // Must not call isFontAvailableUnrestricted under unique_lock: it will deadlock - if (!sufficientFontRights && isFontAvailableUnrestricted(fontName, fileUrl)) - sufficientFontRights = true; - // Register it / increase its refcount in s_EmbeddedFonts { - std::unique_lock lock(s_EmbeddedFontsMutex); + DBG_TESTSOLARMUTEX(); auto& rData = s_EmbeddedFonts[fileUrl]; if (rData.refcount == 0) { rData.familyName = fontName; - rData.isRestricted = !sufficientFontRights; + // Check if the font is already installed on system. At this point, we know that this + // restricted font hasn't yet been activated as embedded (rData.refcount == 0); if it + // is already available, it's pre-installed, meaning that there are sufficient rights + // to use the font. You can always edit with the restricted fonts taken from your own + // system. + rData.isRestricted = !sufficientFontRights + && !Application::GetDefaultDevice()->IsFontAvailable(fontName); } assert(rData.familyName == fontName); ++rData.refcount; @@ -395,7 +378,7 @@ void EmbeddedFontsManager::activateFonts(std::vector<std::pair<OUString, OUStrin std::vector<std::pair<OUString, OUString>> temp; { - std::unique_lock lock(s_EmbeddedFontsMutex); + DBG_TESTSOLARMUTEX(); // Handle restricted fonts for (auto it1 = fonts.begin(); it1 != fonts.end();) { @@ -451,7 +434,7 @@ void EmbeddedFontsManager::activateFonts(std::vector<std::pair<OUString, OUStrin } { - std::unique_lock lock(s_EmbeddedFontsMutex); + DBG_TESTSOLARMUTEX(); // Only activate fonts that need activation. It goes after restricted fonts handling, // because we must ask user about a second document embedding the same restricted font. // We do not remove from fonts: the unlocking must happen only when the document is closed, @@ -482,8 +465,9 @@ void EmbeddedFontsManager::activateFonts(std::vector<std::pair<OUString, OUStrin void EmbeddedFontsManager::releaseFonts(const std::vector<std::pair<OUString, OUString>>& fonts) { std::vector<std::pair<OUString, OUString>> unregister; + if (!fonts.empty()) { - std::unique_lock g(s_EmbeddedFontsMutex); + DBG_TESTSOLARMUTEX(); for (const auto& pair : fonts) { auto it = s_EmbeddedFonts.find(pair.second); @@ -548,7 +532,7 @@ bool EmbeddedFontsManager::sufficientTTFRights( const void* data, tools::Long si // static bool EmbeddedFontsManager::isEmbeddedAndRestricted(std::u16string_view familyName) { - std::unique_lock lock(s_EmbeddedFontsMutex); + DBG_TESTSOLARMUTEX(); for (const auto& pair : s_EmbeddedFonts) { if (pair.second.familyName == familyName && pair.second.isRestricted)