It seems that PoDoFo is not thread-safe because of its use of
fontconfig, which according to this post I've found:
http://osdir.com/ml/fonts.fontconfig/2006-02/msg00135.html is not thread
thread-safe. Attached is a patch which uses PdfMutexWrapper with
PdfMutex in order to access fontconfig in a thread-safe manner.
Index: src/PdfFontCache.cpp
===================================================================
--- src/PdfFontCache.cpp (revision 1135)
+++ src/PdfFontCache.cpp (working copy)
@@ -54,6 +54,8 @@
#if defined(PODOFO_HAVE_FONTCONFIG)
#include <fontconfig/fontconfig.h>
+
+#include "util/PdfMutexWrapper.h"
#endif
using namespace std;
@@ -118,13 +120,20 @@
}
#endif // _WIN32
+#if defined(PODOFO_HAVE_FONTCONFIG)
+Util::PdfMutex PdfFontCache::m_FcMutex;
+#endif
+
PdfFontCache::PdfFontCache( PdfVecObjects* pParent )
: m_pParent( pParent )
{
// Initialize all the fonts stuff
#if defined(PODOFO_HAVE_FONTCONFIG)
+ {
+ Util::PdfMutexWrapper mutex(m_FcMutex);
m_pFcConfig = static_cast<void*>(FcInitLoadConfigAndFonts());
+ }
#endif
if( FT_Init_FreeType( &m_ftLibrary ) )
@@ -138,7 +147,10 @@
this->EmptyCache();
#if defined(PODOFO_HAVE_FONTCONFIG)
+ {
+ Util::PdfMutexWrapper mutex(m_FcMutex);
FcConfigDestroy( static_cast<FcConfig*>(m_pFcConfig) );
+ }
#endif
if( m_ftLibrary )
@@ -540,6 +552,7 @@
FcResult result = FcResultMatch;
FcValue v;
std::string sPath;
+ Util::PdfMutexWrapper mutex(m_FcMutex);
// Build a pattern to search using fontname, bold and italic
pattern = FcPatternBuild (0, FC_FAMILY, FcTypeString, pszFontName,
@@ -575,6 +588,7 @@
std::string PdfFontCache::GetFontPath( const char* pszFontName, bool bBold, bool bItalic )
{
#if defined(PODOFO_HAVE_FONTCONFIG)
+ Util::PdfMutexWrapper mutex(m_FcMutex);
FcConfig* pConfig = FcInitLoadConfigAndFonts();
std::string sPath = this->GetFontConfigFontPath( pConfig, pszFontName, bBold, bItalic );
FcConfigDestroy( pConfig );
Index: src/PdfFontCache.h
===================================================================
--- src/PdfFontCache.h (revision 1135)
+++ src/PdfFontCache.h (working copy)
@@ -27,6 +27,14 @@
#include "PdfEncodingFactory.h"
#include "PdfFont.h"
+#ifdef BUILDING_PODOFO
+#if defined(PODOFO_HAVE_FONTCONFIG)
+#include "util/PdfMutex.h"
+#endif
+#else // BUILDING_PODOFO
+class PdfMutex;
+#endif // BUILDING_PODOFO
+
namespace PoDoFo {
class PdfFontMetrics;
@@ -128,7 +136,11 @@
typedef TSortedFontList::iterator TISortedFontList;
typedef TSortedFontList::const_iterator TCISortedFontList;
+#if defined(PODOFO_HAVE_FONTCONFIG)
+ static Util::PdfMutex m_FcMutex;
+#endif
+
public:
/** Create an empty font cache
*
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Podofo-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/podofo-users