vcl/source/gdi/embeddedfontsmanager.cxx |   22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)

New commits:
commit 63cf8557b79cbcb82a562e4be0a485d26fd6aff7
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Wed Aug 13 18:28:49 2025 +0500
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Wed Aug 13 20:42:52 2025 +0200

    Factor out filename creation for export to a separate function
    
    Khaled suggested that in https://gerrit.libreoffice.org/c/core/+/153007.
    The change also adds percent-encoding, similar to commit
    
      501a1491e3e48c30c2e977841976431bbd4e0d67
      Percent-encode temp font filename in the file URL
      2025-08-09
    
    Also drop the obsolete comment about ttf extension. As Khaled explained
    in tdf#155486:
    
    > When we embed the font, we don’t know what its original file extension is,
    > and on some systems (namely Windows and macOS) we never get access to the
    > original file, only its data loaded in memory.
    
    > So whatever file extension we use will always be a guess. We can add some
    > code to detect if the font has a CFF table and change the file extension
    > accordingly, but that is so much work for something users are not supposed
    > to see any way (I don’t think extracting the ODT file and looking at its
    > content is a general practice that we need to worry so much about).
    
    Change-Id: Idacefec5f1dc885f867a2ff6d96dec6463bc68b5
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/189513
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>
    Tested-by: Jenkins

diff --git a/vcl/source/gdi/embeddedfontsmanager.cxx 
b/vcl/source/gdi/embeddedfontsmanager.cxx
index f5fd519360bf..79e8068ac482 100644
--- a/vcl/source/gdi/embeddedfontsmanager.cxx
+++ b/vcl/source/gdi/embeddedfontsmanager.cxx
@@ -211,6 +211,17 @@ OUString writeFontBytesToFile(const std::vector<char>& 
bytes, std::u16string_vie
 
     return url;
 }
+
+OUString getFilenameForExport(std::u16string_view familyName, FontFamily 
family, FontItalic italic,
+                              FontWeight weight, FontPitch pitch)
+{
+    OUString filename = OUString::Concat(familyName) + "_" + 
OUString::number(family) + "_"
+                        + OUString::number(italic) + "_" + 
OUString::number(weight) + "_"
+                        + OUString::number(pitch) + ".ttf";
+    return rtl::Uri::encode(filename, rtl_UriCharClassPchar, 
rtl_UriEncodeIgnoreEscapes,
+                            RTL_TEXTENCODING_UTF8);
+}
+
 }
 
 EmbeddedFontsManager::EmbeddedFontsManager(const 
uno::Reference<frame::XModel>& xModel)
@@ -555,10 +566,7 @@ OUString EmbeddedFontsManager::fontFileUrl( 
std::u16string_view familyName, Font
 
     OUString path = GetEmbeddedFontsRoot() + "fromsystem/";
     osl::Directory::createPath( path );
-    OUString filename = OUString::Concat(familyName) + "_" + OUString::number( 
family ) + "_" + OUString::number( italic )
-        + "_" + OUString::number( weight ) + "_" + OUString::number( pitch )
-        + ".ttf"; // TODO is it always ttf?
-    OUString url = path + filename;
+    OUString url = path + getFilenameForExport(familyName, family, italic, 
weight, pitch);
     if( osl::File( url ).open( osl_File_OpenFlag_Read ) == osl::File::E_None ) 
// = exists()
     {
         // File with contents of the font file already exists, assume it's 
been created by a previous call.
@@ -618,10 +626,8 @@ OUString EmbeddedFontsManager::fontFileUrl( 
std::u16string_view familyName, Font
     for (vcl::font::PhysicalFontFace* f : fontsToAdd)
     {
         if (!selected) { // recalculate file name for "not perfect match"
-            filename = OUString::Concat(familyName) + "_" + 
OUString::number(f->GetFamilyType()) + "_" +
-                OUString::number(f->GetItalic()) + "_" + 
OUString::number(f->GetWeight()) + "_" +
-                OUString::number(f->GetPitch()) + ".ttf"; // TODO is it always 
ttf?
-            url = path + filename;
+            url = path + getFilenameForExport(familyName, f->GetFamilyType(), 
f->GetItalic(),
+                                              f->GetWeight(), f->GetPitch());
             if (osl::File(url).open(osl_File_OpenFlag_Read) == 
osl::File::E_None) // = exists()
             {
                 // File with contents of the font file already exists, assume 
it's been created by a previous call.

Reply via email to