From 9177329a425cf70b515d1f266132838894fe54c6 Mon Sep 17 00:00:00 2001 From: Chris Sherlock Date: Sat, 4 Oct 2014 21:55:58 +1000 Subject: vcl: FontCharMap to use intrusive_ptr ImplFontCharMap ImplFontCharMap was using it's own reference counting mechanism, however we can use intrusive_ptr more effectively. Added a unit test around FontCharMap. Change-Id: Ifab6ce002fd1df8feb7e017dea3012ff9ea7f18a Reviewed-on: https://gerrit.libreoffice.org/11804 Reviewed-by: Chris Sherlock Tested-by: Chris Sherlock --- vcl/generic/fontmanager/fontmanager.cxx | 6 +++--- vcl/generic/glyphs/gcach_ftyp.cxx | 15 ++++++++++----- vcl/generic/glyphs/gcach_ftyp.hxx | 4 ++-- vcl/generic/print/genpspgraphics.cxx | 4 ++-- 4 files changed, 17 insertions(+), 12 deletions(-) (limited to 'vcl/generic') diff --git a/vcl/generic/fontmanager/fontmanager.cxx b/vcl/generic/fontmanager/fontmanager.cxx index 273707699350..05fc829d0e5e 100644 --- a/vcl/generic/fontmanager/fontmanager.cxx +++ b/vcl/generic/fontmanager/fontmanager.cxx @@ -2088,11 +2088,11 @@ void PrintFontManager::getGlyphWidths( fontID nFont, CmapResult aCmapResult; if( ParseCMAP( pCmapData, nCmapSize, aCmapResult ) ) { - const ImplFontCharMap aCharMap( aCmapResult ); + const ImplFontCharMapPtr pCharMap( new ImplFontCharMap(aCmapResult) ); for( sal_uInt32 cOld = 0;;) { // get next unicode covered by font - const sal_uInt32 c = aCharMap.GetNextChar( cOld ); + const sal_uInt32 c = pCharMap->GetNextChar( cOld ); if( c == cOld ) break; cOld = c; @@ -2101,7 +2101,7 @@ void PrintFontManager::getGlyphWidths( fontID nFont, break; #endif // get the matching glyph index - const sal_GlyphId aGlyphId = aCharMap.GetGlyphIndex( c ); + const sal_GlyphId aGlyphId = pCharMap->GetGlyphIndex( c ); // update the requested map rUnicodeEnc[ (sal_Unicode)c ] = aGlyphId; } diff --git a/vcl/generic/glyphs/gcach_ftyp.cxx b/vcl/generic/glyphs/gcach_ftyp.cxx index 9db574ee407b..fa93fc603738 100644 --- a/vcl/generic/glyphs/gcach_ftyp.cxx +++ b/vcl/generic/glyphs/gcach_ftyp.cxx @@ -242,7 +242,7 @@ FtFontInfo::FtFontInfo( const ImplDevFontAttributes& rDevFontAttributes, FtFontInfo::~FtFontInfo() { if( mpFontCharMap ) - mpFontCharMap->DeReference(); + mpFontCharMap = 0; delete mpChar2Glyph; delete mpGlyph2Char; #if ENABLE_GRAPHITE @@ -1265,13 +1265,13 @@ bool ServerFont::GetGlyphBitmap8( sal_GlyphId aGlyphId, RawBitmap& rRawBitmap ) // determine unicode ranges in font -const ImplFontCharMap* ServerFont::GetImplFontCharMap( void ) const +const ImplFontCharMapPtr ServerFont::GetImplFontCharMap( void ) const { - const ImplFontCharMap* pIFCMap = mpFontInfo->GetImplFontCharMap(); + const ImplFontCharMapPtr pIFCMap = mpFontInfo->GetImplFontCharMap(); return pIFCMap; } -const ImplFontCharMap* FtFontInfo::GetImplFontCharMap( void ) +const ImplFontCharMapPtr FtFontInfo::GetImplFontCharMap( void ) { // check if the charmap is already cached if( mpFontCharMap ) @@ -1281,9 +1281,14 @@ const ImplFontCharMap* FtFontInfo::GetImplFontCharMap( void ) CmapResult aCmapResult; bool bOK = GetFontCodeRanges( aCmapResult ); if( bOK ) - mpFontCharMap = new ImplFontCharMap( aCmapResult ); + { + ImplFontCharMapPtr pFontCharMap( new ImplFontCharMap( aCmapResult ) ); + mpFontCharMap = pFontCharMap; + } else + { mpFontCharMap = ImplFontCharMap::GetDefaultMap(); + } // mpFontCharMap on either branch now has a refcount of 1 return mpFontCharMap; } diff --git a/vcl/generic/glyphs/gcach_ftyp.hxx b/vcl/generic/glyphs/gcach_ftyp.hxx index b43d47b39397..803ce072a955 100644 --- a/vcl/generic/glyphs/gcach_ftyp.hxx +++ b/vcl/generic/glyphs/gcach_ftyp.hxx @@ -84,7 +84,7 @@ public: void CacheGlyphIndex( sal_UCS4 cChar, int nGI ) const; bool GetFontCodeRanges( CmapResult& ) const; - const ImplFontCharMap* GetImplFontCharMap( void ); + const ImplFontCharMapPtr GetImplFontCharMap( void ); private: FT_FaceRec_* maFaceFT; @@ -99,7 +99,7 @@ private: sal_IntPtr mnFontId; ImplDevFontAttributes maDevFontAttributes; - const ImplFontCharMap* mpFontCharMap; + ImplFontCharMapPtr mpFontCharMap; // cache unicode->glyphid mapping because looking it up is expensive // TODO: change to boost::unordered_multimap when a use case requires a m:n mapping diff --git a/vcl/generic/print/genpspgraphics.cxx b/vcl/generic/print/genpspgraphics.cxx index 401f5c7af5e8..759519b3cefa 100644 --- a/vcl/generic/print/genpspgraphics.cxx +++ b/vcl/generic/print/genpspgraphics.cxx @@ -777,12 +777,12 @@ void GenPspGraphics::DrawServerFontLayout( const ServerFontLayout& rLayout ) DrawPrinterLayout( rLayout, *m_pPrinterGfx, true ); } -const ImplFontCharMap* GenPspGraphics::GetImplFontCharMap() const +const ImplFontCharMapPtr GenPspGraphics::GetImplFontCharMap() const { if( !m_pServerFont[0] ) return NULL; - const ImplFontCharMap* pIFCMap = m_pServerFont[0]->GetImplFontCharMap(); + const ImplFontCharMapPtr pIFCMap = m_pServerFont[0]->GetImplFontCharMap(); return pIFCMap; } -- cgit v1.2.3