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 0d0399a567d4870ba431d172c54a818fdb22bc07
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Wed Aug 13 01:31:27 2025 +0500
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Wed Aug 13 06:12:38 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>

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 76f8c975747c..f8a4e7249229 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 3a74c6ee4049..cc39d01514b5 100644
--- a/vcl/source/gdi/embeddedfontsmanager.cxx
+++ b/vcl/source/gdi/embeddedfontsmanager.cxx
@@ -534,16 +534,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 );

Reply via email to