[Libreoffice-commits] core.git: vcl/generic vcl/headless vcl/inc vcl/quartz vcl/source vcl/unx vcl/win

Caolán McNamara caolanm at redhat.com
Tue Jan 27 02:46:00 PST 2015


 vcl/generic/print/genpspgraphics.cxx    |   16 ++++++++--------
 vcl/headless/svptext.cxx                |    3 ++-
 vcl/inc/cairotextrender.hxx             |    1 +
 vcl/inc/generic/genpspgraphics.h        |    3 ++-
 vcl/inc/headless/svpgdi.hxx             |    1 +
 vcl/inc/quartz/salgdi.h                 |    1 +
 vcl/inc/salgdi.hxx                      |    6 +++---
 vcl/inc/textrender.hxx                  |    1 +
 vcl/inc/unx/salgdi.h                    |    1 +
 vcl/inc/win/salgdi.h                    |    1 +
 vcl/quartz/salgdi.cxx                   |    1 +
 vcl/source/gdi/embeddedfontshelper.cxx  |    8 +-------
 vcl/source/gdi/pdfwriter_impl.cxx       |    5 +++--
 vcl/unx/generic/gdi/cairotextrender.cxx |    4 ++--
 vcl/unx/generic/gdi/salgdi3.cxx         |    4 ++--
 vcl/win/source/gdi/salgdi3.cxx          |    4 ++--
 16 files changed, 32 insertions(+), 28 deletions(-)

New commits:
commit dbf15c904425a4358b3c930ddff4c01982138ef6
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Mon Jan 26 21:11:21 2015 +0000

    add a length arg to GetEmbedFontData
    
    for the cases where we don't want the full result
    and mark some ultra-dubious code with a TODO
    
    Change-Id: I7cf57b8d44bbad2a6db86a8b862a757ae5062c50
    Reviewed-on: https://gerrit.libreoffice.org/14189
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/vcl/generic/print/genpspgraphics.cxx b/vcl/generic/print/genpspgraphics.cxx
index f9a6e3a..2269bcb 100644
--- a/vcl/generic/print/genpspgraphics.cxx
+++ b/vcl/generic/print/genpspgraphics.cxx
@@ -1226,7 +1226,7 @@ void GenPspGraphics::DoFreeEmbedFontData( const void* pData, long nLen )
 #endif
 }
 
-const void* GenPspGraphics::DoGetEmbedFontData( psp::fontID aFont, const sal_Ucs* pUnicodes, sal_Int32* pWidths, FontSubsetInfo& rInfo, long* pDataLen )
+const void* GenPspGraphics::DoGetEmbedFontData( psp::fontID aFont, const sal_Ucs* pUnicodes, sal_Int32* pWidths, size_t nLen, FontSubsetInfo& rInfo, long* pDataLen )
 {
 
     psp::PrintFontManager& rMgr = psp::PrintFontManager::get();
@@ -1243,15 +1243,15 @@ const void* GenPspGraphics::DoGetEmbedFontData( psp::fontID aFont, const sal_Ucs
     int xMin, yMin, xMax, yMax;
     rMgr.getFontBoundingBox( aFont, xMin, yMin, xMax, yMax );
 
-    psp::CharacterMetric aMetrics[256];
-    sal_Ucs aUnicodes[256];
+    psp::CharacterMetric aMetrics[nLen];
+    sal_Ucs aUnicodes[nLen];
     if( aFontInfo.m_aEncoding == RTL_TEXTENCODING_SYMBOL && aFontInfo.m_eType == psp::fonttype::Type1 )
     {
-        for( int i = 0; i < 256; i++ )
+        for (size_t i = 0; i < nLen; ++i)
             aUnicodes[i] = pUnicodes[i] < 0x0100 ? pUnicodes[i] + 0xf000 : pUnicodes[i];
         pUnicodes = aUnicodes;
     }
-    if( ! rMgr.getMetrics( aFont, pUnicodes, 256, aMetrics ) )
+    if (!rMgr.getMetrics(aFont, pUnicodes, nLen, aMetrics))
         return NULL;
 
     OString aSysPath = rMgr.getFontFileSysPath( aFont );
@@ -1294,7 +1294,7 @@ const void* GenPspGraphics::DoGetEmbedFontData( psp::fontID aFont, const sal_Ucs
     rInfo.m_aFontBBox   = Rectangle( Point( xMin, yMin ), Size( xMax-xMin, yMax-yMin ) );
     rInfo.m_nCapHeight  = yMax; // Well ...
 
-    for( int i = 0; i < 256; i++ )
+    for (size_t i = 0; i < nLen; ++i)
         pWidths[i] = (aMetrics[i].width > 0 ? aMetrics[i].width : 0);
 
     switch( aFontInfo.m_eType )
@@ -1320,7 +1320,7 @@ void GenPspGraphics::FreeEmbedFontData( const void* pData, long nLen )
     DoFreeEmbedFontData( pData, nLen );
 }
 
-const void* GenPspGraphics::GetEmbedFontData( const PhysicalFontFace* pFont, const sal_Ucs* pUnicodes, sal_Int32* pWidths, FontSubsetInfo& rInfo, long* pDataLen )
+const void* GenPspGraphics::GetEmbedFontData( const PhysicalFontFace* pFont, const sal_Ucs* pUnicodes, sal_Int32* pWidths, size_t nLen, FontSubsetInfo& rInfo, long* pDataLen )
 {
     // in this context the pFont->GetFontId() is a valid PSP
     // font since they are the only ones left after the PDF
@@ -1328,7 +1328,7 @@ const void* GenPspGraphics::GetEmbedFontData( const PhysicalFontFace* pFont, con
     // which this method was created). The correct way would
     // be to have the GlyphCache search for the PhysicalFontFace pFont
     psp::fontID aFont = pFont->GetFontId();
-    return DoGetEmbedFontData( aFont, pUnicodes, pWidths, rInfo, pDataLen );
+    return DoGetEmbedFontData(aFont, pUnicodes, pWidths, nLen, rInfo, pDataLen);
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/headless/svptext.cxx b/vcl/headless/svptext.cxx
index 8fc51ce..84a35e1 100644
--- a/vcl/headless/svptext.cxx
+++ b/vcl/headless/svptext.cxx
@@ -336,6 +336,7 @@ const void* SvpSalGraphics::GetEmbedFontData(
     const PhysicalFontFace* pFont,
     const sal_Ucs* pUnicodes,
     sal_Int32* pWidths,
+    size_t nLen,
     FontSubsetInfo& rInfo,
     long* pDataLen
     )
@@ -346,7 +347,7 @@ const void* SvpSalGraphics::GetEmbedFontData(
     // which this method was created). The correct way would
     // be to have the GlyphCache search for the PhysicalFontFace pFont
     psp::fontID aFont = pFont->GetFontId();
-    return GenPspGraphics::DoGetEmbedFontData( aFont, pUnicodes, pWidths, rInfo, pDataLen );
+    return GenPspGraphics::DoGetEmbedFontData( aFont, pUnicodes, pWidths, nLen, rInfo, pDataLen );
 }
 
 void SvpSalGraphics::FreeEmbedFontData( const void* pData, long nLen )
diff --git a/vcl/inc/cairotextrender.hxx b/vcl/inc/cairotextrender.hxx
index d59d75c..d945968 100644
--- a/vcl/inc/cairotextrender.hxx
+++ b/vcl/inc/cairotextrender.hxx
@@ -114,6 +114,7 @@ public:
                                     const PhysicalFontFace*,
                                     const sal_Ucs* pUnicodes,
                                     sal_Int32* pWidths,
+                                    size_t nLen,
                                     FontSubsetInfo& rInfo,
                                     long* pDataLen ) SAL_OVERRIDE;
 
diff --git a/vcl/inc/generic/genpspgraphics.h b/vcl/inc/generic/genpspgraphics.h
index 3478238..b4ac313 100644
--- a/vcl/inc/generic/genpspgraphics.h
+++ b/vcl/inc/generic/genpspgraphics.h
@@ -54,7 +54,7 @@ public:
 
     // helper methods
     static const void *     DoGetEmbedFontData ( psp::fontID aFont, const sal_Ucs* pUnicodes,
-                                                 sal_Int32* pWidths, FontSubsetInfo& rInfo,
+                                                 sal_Int32* pWidths, size_t nLen, FontSubsetInfo& rInfo,
                                                  long* pDataLen );
     static void             DoFreeEmbedFontData( const void* pData, long nLen );
 
@@ -111,6 +111,7 @@ public:
     virtual const void*     GetEmbedFontData( const PhysicalFontFace*,
                                               const sal_Ucs* pUnicodes,
                                               sal_Int32* pWidths,
+                                              size_t nLen,
                                               FontSubsetInfo& rInfo,
                                               long* pDataLen ) SAL_OVERRIDE;
     virtual void            FreeEmbedFontData( const void* pData, long nDataLen ) SAL_OVERRIDE;
diff --git a/vcl/inc/headless/svpgdi.hxx b/vcl/inc/headless/svpgdi.hxx
index 39f8176..dc0c62f 100644
--- a/vcl/inc/headless/svpgdi.hxx
+++ b/vcl/inc/headless/svpgdi.hxx
@@ -131,6 +131,7 @@ public:
     virtual const void*     GetEmbedFontData( const PhysicalFontFace*,
                                               const sal_Ucs* pUnicodes,
                                               sal_Int32* pWidths,
+                                              size_t nLen,
                                               FontSubsetInfo& rInfo,
                                               long* pDataLen ) SAL_OVERRIDE;
     virtual void            FreeEmbedFontData( const void* pData, long nDataLen ) SAL_OVERRIDE;
diff --git a/vcl/inc/quartz/salgdi.h b/vcl/inc/quartz/salgdi.h
index 87c35c1..9c9c741 100644
--- a/vcl/inc/quartz/salgdi.h
+++ b/vcl/inc/quartz/salgdi.h
@@ -393,6 +393,7 @@ public:
     virtual const void*     GetEmbedFontData( const PhysicalFontFace*,
                                               const sal_Ucs* pUnicodes,
                                               sal_Int32* pWidths,
+                                              size_t nLen,
                                               FontSubsetInfo& rInfo,
                                               long* pDataLen ) SAL_OVERRIDE;
     // frees the font data again
diff --git a/vcl/inc/salgdi.hxx b/vcl/inc/salgdi.hxx
index 17e2233..b42e0b4 100644
--- a/vcl/inc/salgdi.hxx
+++ b/vcl/inc/salgdi.hxx
@@ -193,16 +193,16 @@ public:
     // GetEmbedFontData: gets the font data for a font marked
     // embeddable by GetDevFontList or NULL in case of error
     // parameters: pFont: describes the font in question
-    //             pUnicodes: contains the Unicodes assigned to
-    //             code points 0 to 255; must contain at least 256 members
+    //             pUnicodes: contains the Unicodes assigned to code points 0 to 255
     //             pWidths: the widths of all glyphs from char code 0 to 255
-    //                      pWidths MUST support at least 256 members;
+    //             nLen: the number of elements in each of pWidths and pUnicodes
     //             rInfo: additional outgoing information
     //             pDataLen: out parameter, contains the byte length of the returned buffer
     virtual const void*         GetEmbedFontData(
                                     const PhysicalFontFace* pFont,
                                     const sal_Ucs* pUnicodes,
                                     sal_Int32* pWidths,
+                                    size_t nLen,
                                     FontSubsetInfo& rInfo,
                                     long* pDataLen ) = 0;
 
diff --git a/vcl/inc/textrender.hxx b/vcl/inc/textrender.hxx
index bdb55bd..4a635c5 100644
--- a/vcl/inc/textrender.hxx
+++ b/vcl/inc/textrender.hxx
@@ -64,6 +64,7 @@ public:
                                         const PhysicalFontFace*,
                                         const sal_Ucs* pUnicodes,
                                         sal_Int32* pWidths,
+                                        size_t nLen,
                                         FontSubsetInfo& rInfo,
                                         long* pDataLen ) = 0;
 
diff --git a/vcl/inc/unx/salgdi.h b/vcl/inc/unx/salgdi.h
index 2ca876e..4486e8c 100644
--- a/vcl/inc/unx/salgdi.h
+++ b/vcl/inc/unx/salgdi.h
@@ -138,6 +138,7 @@ public:
                                         const PhysicalFontFace*,
                                         const sal_Ucs* pUnicodes,
                                         sal_Int32* pWidths,
+                                        size_t nLen,
                                         FontSubsetInfo& rInfo,
                                         long* pDataLen ) SAL_OVERRIDE;
 
diff --git a/vcl/inc/win/salgdi.h b/vcl/inc/win/salgdi.h
index 6ce3a61..5ff9530 100644
--- a/vcl/inc/win/salgdi.h
+++ b/vcl/inc/win/salgdi.h
@@ -423,6 +423,7 @@ public:
     virtual const void* GetEmbedFontData( const PhysicalFontFace*,
                                           const sal_Ucs* pUnicodes,
                                           sal_Int32* pWidths,
+                                          size_t nLen,
                                           FontSubsetInfo& rInfo,
                                           long* pDataLen );
     // frees the font data again
diff --git a/vcl/quartz/salgdi.cxx b/vcl/quartz/salgdi.cxx
index 2cb8271..49ad051 100644
--- a/vcl/quartz/salgdi.cxx
+++ b/vcl/quartz/salgdi.cxx
@@ -738,6 +738,7 @@ const Ucs2SIntMap* AquaSalGraphics::GetFontEncodingVector(
 const void* AquaSalGraphics::GetEmbedFontData( const PhysicalFontFace*,
                               const sal_Ucs* /*pUnicodes*/,
                               sal_Int32* /*pWidths*/,
+                              size_t /*nLen*/,
                               FontSubsetInfo&,
                               long* /*pDataLen*/ )
 {
diff --git a/vcl/source/gdi/embeddedfontshelper.cxx b/vcl/source/gdi/embeddedfontshelper.cxx
index 037cfcf..ba67e76 100644
--- a/vcl/source/gdi/embeddedfontshelper.cxx
+++ b/vcl/source/gdi/embeddedfontshelper.cxx
@@ -265,15 +265,9 @@ OUString EmbeddedFontsHelper::fontFileUrl( const OUString& familyName, FontFamil
     }
     if( selected != NULL )
     {
-        sal_Ucs unicodes[ 256 ];
-        for( int i = 0;
-             i < 256;
-             ++i )
-            unicodes[ i ] = 'A'; // Just something, not needed, but GetEmbedFontData() needs it.
-        sal_Int32 widths[ 256 ];
         FontSubsetInfo info;
         long size;
-        if( const void* data = graphics->GetEmbedFontData( selected, unicodes, widths, info, &size ))
+        if( const void* data = graphics->GetEmbedFontData( selected, NULL, NULL, 0, info, &size ))
         {
             if( sufficientTTFRights( data, size, rights ))
             {
diff --git a/vcl/source/gdi/pdfwriter_impl.cxx b/vcl/source/gdi/pdfwriter_impl.cxx
index 528a74c..2affdd4 100644
--- a/vcl/source/gdi/pdfwriter_impl.cxx
+++ b/vcl/source/gdi/pdfwriter_impl.cxx
@@ -2969,7 +2969,8 @@ std::map< sal_Int32, sal_Int32 > PDFWriterImpl::emitSystemFont( const PhysicalFo
         sal_Ucs nEncodedCodes[256];
         sal_Int32 pEncWidths[256];
 
-        pFontData = (const unsigned char*)pGraphics->GetEmbedFontData( pFont, nEncodedCodes, pEncWidths, aInfo, &nFontLen );
+        //TODO: surely this is utterly broken because GetEmbedFontData loops over the uninitialized nEncodedCodes as input
+        pFontData = (const unsigned char*)pGraphics->GetEmbedFontData( pFont, nEncodedCodes, pEncWidths, 256, aInfo, &nFontLen );
 
         if( pFontData )
         {
@@ -3147,7 +3148,7 @@ std::map< sal_Int32, sal_Int32 > PDFWriterImpl::emitEmbeddedFont( const Physical
     sal_Int32 nLength1, nLength2;
     try
     {
-        if( (pFontData = (const unsigned char*)pGraphics->GetEmbedFontData( pFont, nEncodedCodes, pWidths, aInfo, &nFontLen )) != NULL )
+        if( (pFontData = (const unsigned char*)pGraphics->GetEmbedFontData(pFont, nEncodedCodes, pWidths, 256, aInfo, &nFontLen)) != NULL )
         {
             if( (aInfo.m_nFontType & FontSubsetInfo::ANY_TYPE1) == 0 )
                 throw FontException();
diff --git a/vcl/unx/generic/gdi/cairotextrender.cxx b/vcl/unx/generic/gdi/cairotextrender.cxx
index 7b0438e..2e83c39 100644
--- a/vcl/unx/generic/gdi/cairotextrender.cxx
+++ b/vcl/unx/generic/gdi/cairotextrender.cxx
@@ -621,7 +621,7 @@ bool CairoTextRender::CreateFontSubset(
     return bSuccess;
 }
 
-const void* CairoTextRender::GetEmbedFontData( const PhysicalFontFace* pFont, const sal_Ucs* pUnicodes, sal_Int32* pWidths, FontSubsetInfo& rInfo, long* pDataLen )
+const void* CairoTextRender::GetEmbedFontData( const PhysicalFontFace* pFont, const sal_Ucs* pUnicodes, sal_Int32* pWidths, size_t nLen, FontSubsetInfo& rInfo, long* pDataLen )
 {
     // in this context the pFont->GetFontId() is a valid PSP
     // font since they are the only ones left after the PDF
@@ -629,7 +629,7 @@ const void* CairoTextRender::GetEmbedFontData( const PhysicalFontFace* pFont, co
     // which this method was created). The correct way would
     // be to have the GlyphCache search for the PhysicalFontFace pFont
     psp::fontID aFont = pFont->GetFontId();
-    return GenPspGraphics::DoGetEmbedFontData( aFont, pUnicodes, pWidths, rInfo, pDataLen );
+    return GenPspGraphics::DoGetEmbedFontData( aFont, pUnicodes, pWidths, nLen, rInfo, pDataLen );
 }
 
 void CairoTextRender::FreeEmbedFontData( const void* pData, long nLen )
diff --git a/vcl/unx/generic/gdi/salgdi3.cxx b/vcl/unx/generic/gdi/salgdi3.cxx
index f0a69ee..6f5eadf 100644
--- a/vcl/unx/generic/gdi/salgdi3.cxx
+++ b/vcl/unx/generic/gdi/salgdi3.cxx
@@ -177,9 +177,9 @@ bool X11SalGraphics::CreateFontSubset(
             pGlyphIds, pEncoding, pWidths, nGlyphCount, rInfo);
 }
 
-const void* X11SalGraphics::GetEmbedFontData( const PhysicalFontFace* pFont, const sal_Ucs* pUnicodes, sal_Int32* pWidths, FontSubsetInfo& rInfo, long* pDataLen )
+const void* X11SalGraphics::GetEmbedFontData( const PhysicalFontFace* pFont, const sal_Ucs* pUnicodes, sal_Int32* pWidths, size_t nLen, FontSubsetInfo& rInfo, long* pDataLen )
 {
-    return mpTextRenderImpl->GetEmbedFontData(pFont, pUnicodes, pWidths, rInfo, pDataLen);
+    return mpTextRenderImpl->GetEmbedFontData(pFont, pUnicodes, pWidths, nLen, rInfo, pDataLen);
 }
 
 void X11SalGraphics::FreeEmbedFontData( const void* pData, long nLen )
diff --git a/vcl/win/source/gdi/salgdi3.cxx b/vcl/win/source/gdi/salgdi3.cxx
index 01e31a1..763e2ea 100644
--- a/vcl/win/source/gdi/salgdi3.cxx
+++ b/vcl/win/source/gdi/salgdi3.cxx
@@ -2596,7 +2596,7 @@ bool WinSalGraphics::CreateFontSubset( const OUString& rToFile,
 }
 
 const void* WinSalGraphics::GetEmbedFontData( const PhysicalFontFace* pFont,
-    const sal_Unicode* pUnicodes, sal_Int32* pCharWidths,
+    const sal_Unicode* pUnicodes, sal_Int32* pCharWidths, size_t nLen,
     FontSubsetInfo& rInfo, long* pDataLen )
 {
     // create matching FontSelectPattern
@@ -2634,7 +2634,7 @@ const void* WinSalGraphics::GetEmbedFontData( const PhysicalFontFace* pFont,
     rInfo.m_nCapHeight  = aTm.tmAscent; // Well ...
 
     // get individual character widths
-    for( int i = 0; i < 256; ++i )
+    for (size_t i = 0; i < nLen; ++i)
     {
         int nCharWidth = 0;
         const sal_Unicode cChar = pUnicodes[i];


More information about the Libreoffice-commits mailing list