vcl/source/gdi/pdfwriter_impl.cxx |   35 ++++++++++++++++++++---------------
 1 file changed, 20 insertions(+), 15 deletions(-)

New commits:
commit 845fbfcce9091e541bab657163b026aad8648261
Author:     Khaled Hosny <kha...@libreoffice.org>
AuthorDate: Thu Jun 15 06:27:38 2023 +0300
Commit:     خالد حسني <kha...@libreoffice.org>
CommitDate: Thu Jun 15 13:12:39 2023 +0200

    Don’t add empty Fonts dictionary to Type 3 font resources
    
    If the Type 3 font does not use any other fonts, skip writing Fonts to
    its Resources dictionary.
    
    Change-Id: I1d0489debeb9f0e24022316551eb234b279381c1
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153100
    Tested-by: Jenkins
    Reviewed-by: خالد حسني <kha...@libreoffice.org>

diff --git a/vcl/source/gdi/pdfwriter_impl.cxx 
b/vcl/source/gdi/pdfwriter_impl.cxx
index 48ed2ffe3be5..0c5fc8401a43 100644
--- a/vcl/source/gdi/pdfwriter_impl.cxx
+++ b/vcl/source/gdi/pdfwriter_impl.cxx
@@ -2756,22 +2756,26 @@ bool PDFWriterImpl::emitType3Font(const 
vcl::font::PhysicalFontFace* pFace,
         }
 
         // write font dict
-        auto nFontDict = createObject();
-        aLine.setLength(0);
-        aLine.append(OString::number(nFontDict) + " 0 obj\n<<");
-        for (auto nFontID : aUsedFonts)
+        auto nFontDict = -1;
+        if (!aUsedFonts.empty())
         {
-            aLine.append("/F"
-                + OString::number(nFontID)
-                + " "
-                + OString::number(rFontIDToObject[nFontID])
-                + " 0 R");
+            nFontDict = createObject();
+            aLine.setLength(0);
+            aLine.append(OString::number(nFontDict) + " 0 obj\n<<");
+            for (auto nFontID : aUsedFonts)
+            {
+                aLine.append("/F"
+                    + OString::number(nFontID)
+                    + " "
+                    + OString::number(rFontIDToObject[nFontID])
+                    + " 0 R");
+            }
+            aLine.append(">>\nendobj\n\n");
+            if (!updateObject(nFontDict))
+                return false;
+            if (!writeBuffer(aLine))
+                return false;
         }
-        aLine.append(">>\nendobj\n\n");
-        if (!updateObject(nFontDict))
-            return false;
-        if (!writeBuffer(aLine))
-            return false;
 
         // write ExtGState objects
         if (!aUsedAlpha.empty())
@@ -2807,7 +2811,8 @@ bool PDFWriterImpl::emitType3Font(const 
vcl::font::PhysicalFontFace* pFace,
         // write resources dict
         aLine.setLength(0);
         aLine.append(OString::number(nResources) + " 0 obj\n");
-        aResourceDict.append(aLine, nFontDict);
+        if (!aUsedFonts.empty())
+            aResourceDict.append(aLine, nFontDict);
         aLine.append("endobj\n\n");
         if (!updateObject(nResources))
             return false;

Reply via email to