vcl/inc/pdf/pdfwriter_impl.hxx    |    5 ++++-
 vcl/source/gdi/pdfwriter_impl.cxx |   33 +++++++++++++++------------------
 2 files changed, 19 insertions(+), 19 deletions(-)

New commits:
commit fe87b2a2cccbc99d001705fdd8f8dc2e9997f211
Author:     Khaled Hosny <kha...@aliftype.com>
AuthorDate: Mon Sep 5 21:25:29 2022 +0200
Commit:     خالد حسني <kha...@aliftype.com>
CommitDate: Tue Sep 6 15:06:41 2022 +0200

    vcl: Use GetGlyphWidth() when emitting system fonts
    
    Change-Id: I152afc51b771d09c8b1d7a220f4706afb9407337
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/139457
    Tested-by: Jenkins
    Reviewed-by: خالد حسني <kha...@aliftype.com>

diff --git a/vcl/inc/pdf/pdfwriter_impl.hxx b/vcl/inc/pdf/pdfwriter_impl.hxx
index 94a52bb07431..048b03cf2351 100644
--- a/vcl/inc/pdf/pdfwriter_impl.hxx
+++ b/vcl/inc/pdf/pdfwriter_impl.hxx
@@ -338,8 +338,11 @@ struct FontSubset
 struct EmbedFont
 {
     sal_Int32                       m_nNormalFontID;
+    LogicalFontInstance*            m_pFontInstance;
 
-    EmbedFont() : m_nNormalFontID( 0 ) {}
+    EmbedFont()
+        : m_nNormalFontID(0)
+        , m_pFontInstance(nullptr) {}
 };
 
 struct PDFDest
diff --git a/vcl/source/gdi/pdfwriter_impl.cxx 
b/vcl/source/gdi/pdfwriter_impl.cxx
index 76c47b54ba45..1e7869dfe1dc 100644
--- a/vcl/source/gdi/pdfwriter_impl.cxx
+++ b/vcl/source/gdi/pdfwriter_impl.cxx
@@ -2325,35 +2325,28 @@ std::map< sal_Int32, sal_Int32 > 
PDFWriterImpl::emitSystemFont( const vcl::font:
     aInfo.m_nCapHeight = 1000;
     aInfo.m_aFontBBox = tools::Rectangle( Point( -200, -200 ), Size( 1700, 
1700 ) );
     aInfo.m_aPSName = pFont->GetFamilyName();
-    sal_Int32 pWidths[256] = {};
 
     SalGraphics *pGraphics = GetGraphics();
-
     assert(pGraphics);
 
     aSubType = OString( "/TrueType" );
-    std::vector< sal_Int32 > aGlyphWidths;
-    Ucs2UIntMap aUnicodeMap;
-    pGraphics->GetGlyphWidths( pFont, false, aGlyphWidths, aUnicodeMap );
 
     OUString aTmpName;
     osl_createTempFile( nullptr, nullptr, &aTmpName.pData );
-    sal_GlyphId aGlyphIds[ 256 ] = {};
-    sal_uInt8 pEncoding[ 256 ] = {};
-    sal_Int32 pDuWidths[ 256 ] = {};
 
+    sal_Int32 pWidths[256] = {};
+    FontCharMapRef xFontCharMap = pFont->GetFontCharMap();
+    const LogicalFontInstance* pFontInstance = rEmbed.m_pFontInstance;
     for( sal_Ucs c = 32; c < 256; c++ )
     {
-        pEncoding[c] = c;
-        aGlyphIds[c] = 0;
-        if( aUnicodeMap.find( c ) != aUnicodeMap.end() )
-            pWidths[ c ] = aGlyphWidths[ aUnicodeMap[ c ] ];
+        sal_GlyphId nGlyph = xFontCharMap->GetGlyphIndex(c);
+        pWidths[c] = pFontInstance->GetGlyphWidth(nGlyph, false, true);
     }
-    //TODO: surely this is utterly broken because aGlyphIds is just all zeros, 
if we
-    //had the right glyphids here then I imagine we could replace pDuWidths 
with
-    //pWidths and remove pWidths assignment above. i.e. start with the glyph 
ids
-    //and map those to unicode rather than try and reverse map them ?
-    pGraphics->CreateFontSubset( aTmpName, pFont, aGlyphIds, pEncoding, 
pDuWidths, 256, aInfo );
+
+    // We are interested only in filling aInfo
+    sal_GlyphId aGlyphIds[256] = { 0 };
+    sal_uInt8 pEncoding[256] = { 0 };
+    pGraphics->CreateFontSubset(aTmpName, pFont, aGlyphIds, pEncoding, 
nullptr, 256, aInfo);
     osl_removeFile( aTmpName.pData );
 
     // write font descriptor
@@ -2876,6 +2869,8 @@ bool PDFWriterImpl::emitFonts()
     }
     osl_removeFile( aTmpName.pData );
 
+    if (g_bDebugDisableCompression)
+        emitComment( "PDFWriterImpl::emitSystemFonts" );
     // emit system fonts
     for (auto const& systemFont : m_aSystemFonts)
     {
@@ -5788,7 +5783,8 @@ sal_Int32 PDFWriterImpl::getSystemFont( const vcl::Font& 
i_rFont )
 
     SetFont( i_rFont );
 
-    const vcl::font::PhysicalFontFace* pDevFont = 
GetFontInstance()->GetFontFace();
+    const LogicalFontInstance* pFontInstance = GetFontInstance();
+    const vcl::font::PhysicalFontFace* pDevFont = pFontInstance->GetFontFace();
     sal_Int32 nFontID = 0;
     auto it = m_aSystemFonts.find( pDevFont );
     if( it != m_aSystemFonts.end() )
@@ -5797,6 +5793,7 @@ sal_Int32 PDFWriterImpl::getSystemFont( const vcl::Font& 
i_rFont )
     {
         nFontID = m_nNextFID++;
         m_aSystemFonts[ pDevFont ] = EmbedFont();
+        m_aSystemFonts[ pDevFont ].m_pFontInstance = 
const_cast<LogicalFontInstance*>(pFontInstance);
         m_aSystemFonts[ pDevFont ].m_nNormalFontID = nFontID;
     }
 

Reply via email to