include/vcl/embeddedfontsmanager.hxx | 11 ++++++++++- svtools/source/control/ctrltool.cxx | 8 ++++++++ vcl/source/gdi/embeddedfontsmanager.cxx | 18 +++++++++++++----- 3 files changed, 31 insertions(+), 6 deletions(-)
New commits: commit d96dbe1e0e1897a8906dcc910ba58d8fc959255a Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Wed Aug 13 01:31:27 2025 +0500 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Fri Aug 15 10:43:36 2025 +0200 Do not show in UI restricted fonts from documents If a font is not available locally (i.e., it only appeared among our fonts because if was embedded in one of the opened documents), and it is restricted (it does not allow editing), it must not be available for picking from the font lists. Change-Id: I97b90e9594f3763c754a14d87d4d37184e6edf03 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/189457 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> (cherry picked from commit 0d0399a567d4870ba431d172c54a818fdb22bc07) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/189464 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Miklos Vajna <vmik...@collabora.com> diff --git a/include/vcl/embeddedfontsmanager.hxx b/include/vcl/embeddedfontsmanager.hxx index a1cb9e3021aa..826fe532ec9e 100644 --- a/include/vcl/embeddedfontsmanager.hxx +++ b/include/vcl/embeddedfontsmanager.hxx @@ -11,6 +11,8 @@ #include <vcl/dllapi.h> +#include <com/sun/star/uno/Reference.hxx> + #include <rtl/ustring.hxx> #include <tools/fontenum.hxx> #include <tools/long.hxx> @@ -21,7 +23,6 @@ namespace com::sun::star::frame { class XModel; } namespace com::sun::star::io { class XInputStream; } namespace com::sun::star::task { class XInteractionHandler; } -namespace com::sun::star::uno { template <typename > class Reference; } /** Helper functions for handling embedded fonts in documents. */ class VCL_DLLPUBLIC EmbeddedFontsManager @@ -103,6 +104,14 @@ public: */ static bool isCommonFont(std::u16string_view aFontName); + /** + Returns true, only if the passed font family is among the embedded fonts, and is restricted. + Since the "restricted" flag is always set after checking that there was no such family + prior to adding the new embedded font file, this flag means that the family is definitely + from an opened document, and is not available locally. + */ + static bool isEmbeddedAndRestricted(std::u16string_view familyName); + static void releaseFonts(const std::vector<std::pair<OUString, OUString>>& fonts); EmbeddedFontsManager(const css::uno::Reference<css::frame::XModel>& xModel); diff --git a/svtools/source/control/ctrltool.cxx b/svtools/source/control/ctrltool.cxx index a117b75123b9..0dd18f746bca 100644 --- a/svtools/source/control/ctrltool.cxx +++ b/svtools/source/control/ctrltool.cxx @@ -27,6 +27,7 @@ #include <i18nlangtag/languagetag.hxx> #include <i18nlangtag/mslangid.hxx> #include <utility> +#include <vcl/embeddedfontsmanager.hxx> #include <vcl/outdev.hxx> #include <vcl/svapp.hxx> #include <vcl/settings.hxx> @@ -265,6 +266,13 @@ void FontList::ImplInsertFonts(OutputDevice* pDevice, bool bInsertData) { FontMetric aFontMetric = pDevice->GetFontMetricFromCollection( i ); OUString aSearchName(aFontMetric.GetFamilyName()); + + // If this font is embedded in a document, is restricted, and is not installed locally + // (which is returned from EmbeddedFontsManager::isEmbeddedAndRestricted), we must not + // display this family name in the UI. + if (EmbeddedFontsManager::isEmbeddedAndRestricted(aSearchName)) + continue; + ImplFontListNameInfo* pData; sal_uInt32 nIndex; aSearchName = ImplMakeSearchString(aSearchName); diff --git a/vcl/source/gdi/embeddedfontsmanager.cxx b/vcl/source/gdi/embeddedfontsmanager.cxx index fd4f3eef8e50..b49fe3cce94b 100644 --- a/vcl/source/gdi/embeddedfontsmanager.cxx +++ b/vcl/source/gdi/embeddedfontsmanager.cxx @@ -530,16 +530,24 @@ bool EmbeddedFontsManager::sufficientTTFRights( const void* data, tools::Long si return true; // no known restriction } -OUString EmbeddedFontsManager::fontFileUrl( std::u16string_view familyName, FontFamily family, FontItalic italic, - FontWeight weight, FontPitch pitch, FontRights rights ) +// static +bool EmbeddedFontsManager::isEmbeddedAndRestricted(std::u16string_view familyName) { - // Do not embed restricted fonts coming from another document. If a font is among embedded, and - // is restricted, it means that it isn't installed locally. See isFontAvailableUnrestricted. + std::unique_lock lock(s_EmbeddedFontsMutex); for (const auto& pair : s_EmbeddedFonts) { if (pair.second.familyName == familyName && pair.second.isRestricted) - return {}; + return true; } + return false; +} + +OUString EmbeddedFontsManager::fontFileUrl( std::u16string_view familyName, FontFamily family, FontItalic italic, + FontWeight weight, FontPitch pitch, FontRights rights ) +{ + // Do not embed restricted fonts not installed locally. + if (isEmbeddedAndRestricted(familyName)) + return {}; OUString path = GetEmbeddedFontsRoot() + "fromsystem/"; osl::Directory::createPath( path );