diff options
author | Chris Sherlock <chris.sherlock79@gmail.com> | 2014-10-04 21:55:58 +1000 |
---|---|---|
committer | Chris Sherlock <chris.sherlock79@gmail.com> | 2014-10-06 00:13:38 +0000 |
commit | 9177329a425cf70b515d1f266132838894fe54c6 (patch) | |
tree | dd064e9b56019046faa0966d0147c19a7fa2ca3e /vcl/source/gdi | |
parent | 36e1d19af8585bc2f36322ba32acbed46e58c4de (diff) |
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 <chris.sherlock79@gmail.com>
Tested-by: Chris Sherlock <chris.sherlock79@gmail.com>
Diffstat (limited to 'vcl/source/gdi')
-rw-r--r-- | vcl/source/gdi/impfont.cxx | 77 |
1 files changed, 30 insertions, 47 deletions
diff --git a/vcl/source/gdi/impfont.cxx b/vcl/source/gdi/impfont.cxx index d0d285be5694..e4e6fc809230 100644 --- a/vcl/source/gdi/impfont.cxx +++ b/vcl/source/gdi/impfont.cxx @@ -50,7 +50,7 @@ ImplFontCharMap::ImplFontCharMap( const CmapResult& rCR ) } } -static ImplFontCharMap* pDefaultImplFontCharMap = NULL; +static ImplFontCharMapPtr pDefaultImplFontCharMap; static const sal_UCS4 aDefaultUnicodeRanges[] = {0x0020,0xD800, 0xE000,0xFFF0}; static const sal_UCS4 aDefaultSymbolRanges[] = {0x0020,0x0100, 0xF020,0xF100}; @@ -69,40 +69,22 @@ ImplFontCharMap::~ImplFontCharMap() delete[] mpGlyphIds; } -ImplFontCharMap* ImplFontCharMap::GetDefaultMap( bool bSymbols) +ImplFontCharMapPtr ImplFontCharMap::GetDefaultMap( bool bSymbols) { - if( pDefaultImplFontCharMap ) - pDefaultImplFontCharMap->AddReference(); - else + const sal_UCS4* pRangeCodes = aDefaultUnicodeRanges; + int nCodesCount = sizeof(aDefaultUnicodeRanges) / sizeof(*pRangeCodes); + if( bSymbols ) { - const sal_UCS4* pRangeCodes = aDefaultUnicodeRanges; - int nCodesCount = sizeof(aDefaultUnicodeRanges) / sizeof(*pRangeCodes); - if( bSymbols ) - { - pRangeCodes = aDefaultSymbolRanges; - nCodesCount = sizeof(aDefaultSymbolRanges) / sizeof(*pRangeCodes); - } - - CmapResult aDefaultCR( bSymbols, pRangeCodes, nCodesCount/2 ); - pDefaultImplFontCharMap = new ImplFontCharMap( aDefaultCR ); + pRangeCodes = aDefaultSymbolRanges; + nCodesCount = sizeof(aDefaultSymbolRanges) / sizeof(*pRangeCodes); } - return pDefaultImplFontCharMap; -} + CmapResult aDefaultCR( bSymbols, pRangeCodes, nCodesCount/2 ); + pDefaultImplFontCharMap.reset( new ImplFontCharMap( aDefaultCR ) ); -void ImplFontCharMap::AddReference( void) const -{ - ++mnRefCount; -} - -void ImplFontCharMap::DeReference( void) const -{ - if( --mnRefCount <= 0 ) - if( this != pDefaultImplFontCharMap ) - delete this; + return pDefaultImplFontCharMap; } - int ImplFontCharMap::ImplFindRangeIndex( sal_UCS4 cChar ) const { int nLower = 0; @@ -561,73 +543,74 @@ bool ParseCMAP( const unsigned char* pCmap, int nLength, CmapResult& rResult ) } FontCharMap::FontCharMap() -: mpImpl( ImplFontCharMap::GetDefaultMap() ) +: mpImplFontCharMap( ImplFontCharMap::GetDefaultMap() ) {} FontCharMap::~FontCharMap() { - mpImpl->DeReference(); - mpImpl = NULL; + mpImplFontCharMap = 0; } int FontCharMap::GetCharCount() const { - return mpImpl->GetCharCount(); + return mpImplFontCharMap->GetCharCount(); } int FontCharMap::CountCharsInRange( sal_UCS4 cMin, sal_UCS4 cMax ) const { - return mpImpl->CountCharsInRange( cMin, cMax ); + return mpImplFontCharMap->CountCharsInRange( cMin, cMax ); } -void FontCharMap::Reset( const ImplFontCharMap* pNewMap ) +void FontCharMap::Reset( const ImplFontCharMapPtr pNewMap ) { if( pNewMap == NULL ) { - mpImpl->DeReference(); - mpImpl = ImplFontCharMap::GetDefaultMap(); + mpImplFontCharMap = ImplFontCharMap::GetDefaultMap(); } - else if( pNewMap != mpImpl ) + else if( pNewMap != mpImplFontCharMap ) { - mpImpl->DeReference(); - mpImpl = pNewMap; - mpImpl->AddReference(); + mpImplFontCharMap = pNewMap; } } bool FontCharMap::IsDefaultMap() const { - return mpImpl->IsDefaultMap(); + return mpImplFontCharMap->IsDefaultMap(); } bool FontCharMap::HasChar( sal_UCS4 cChar ) const { - return mpImpl->HasChar( cChar ); + return mpImplFontCharMap->HasChar( cChar ); } sal_UCS4 FontCharMap::GetFirstChar() const { - return mpImpl->GetFirstChar(); + return mpImplFontCharMap->GetFirstChar(); +} + +sal_UCS4 FontCharMap::GetLastChar() const +{ + return mpImplFontCharMap->GetLastChar(); } sal_UCS4 FontCharMap::GetNextChar( sal_UCS4 cChar ) const { - return mpImpl->GetNextChar( cChar ); + return mpImplFontCharMap->GetNextChar( cChar ); } sal_UCS4 FontCharMap::GetPrevChar( sal_UCS4 cChar ) const { - return mpImpl->GetPrevChar( cChar ); + return mpImplFontCharMap->GetPrevChar( cChar ); } int FontCharMap::GetIndexFromChar( sal_UCS4 cChar ) const { - return mpImpl->GetIndexFromChar( cChar ); + return mpImplFontCharMap->GetIndexFromChar( cChar ); } sal_UCS4 FontCharMap::GetCharFromIndex( int nIndex ) const { - return mpImpl->GetCharFromIndex( nIndex ); + return mpImplFontCharMap->GetCharFromIndex( nIndex ); } // on some systems we have to get the font attributes from the name table |