From f9518be5bf788b6f5b53075fee5bdf6b7f99cbbd Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Wed, 23 Nov 2016 10:41:39 +0200 Subject: replace CHAR flags with o3tl::typed_flags the usage of which looks a little dodgy, because this is a bitmask, but it's using == everywhere to check them Change-Id: I8e57d4f943a9048cc457a376ffbdfde0cffe22dd (cherry picked from commit 76ab8c76daa57d21288c3a90f017ea5ae51db564) (cherry picked from commit f54b392274cfe2f4b9fbfd5c9677c40ab1dc1322) --- editeng/source/editeng/editdoc.cxx | 2 +- editeng/source/editeng/editdoc.hxx | 17 ++++++++++++----- editeng/source/editeng/impedit.hxx | 2 +- editeng/source/editeng/impedit2.cxx | 10 +++++----- editeng/source/editeng/impedit3.cxx | 18 +++++++++--------- 5 files changed, 28 insertions(+), 21 deletions(-) (limited to 'editeng/source') diff --git a/editeng/source/editeng/editdoc.cxx b/editeng/source/editeng/editdoc.cxx index 8763b0733594..6c9a9f504fda 100644 --- a/editeng/source/editeng/editdoc.cxx +++ b/editeng/source/editeng/editdoc.cxx @@ -527,7 +527,7 @@ ExtraPortionInfo::ExtraPortionInfo() , nWidthFullCompression(0) , nPortionOffsetX(0) , nMaxCompression100thPercent(0) -, nAsianCompressionTypes(0) +, nAsianCompressionTypes(AsianCompressionFlags::Normal) , bFirstCharIsRightPunktuation(false) , bCompressed(false) , pOrgDXArray(nullptr) diff --git a/editeng/source/editeng/editdoc.hxx b/editeng/source/editeng/editdoc.hxx index e7e1be701ccd..2fa92d3f4f08 100644 --- a/editeng/source/editeng/editdoc.hxx +++ b/editeng/source/editeng/editdoc.hxx @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -342,10 +343,16 @@ enum class DeleteMode { Simple, RestOfWord, RestOfContent }; -#define CHAR_NORMAL 0x00 -#define CHAR_KANA 0x01 -#define CHAR_PUNCTUATIONLEFT 0x02 -#define CHAR_PUNCTUATIONRIGHT 0x04 +enum class AsianCompressionFlags { + Normal = 0x00, + Kana = 0x01, + PunctuationLeft = 0x02, + PunctuationRight = 0x04, +}; +namespace o3tl { + template<> struct typed_flags : is_typed_flags {}; +} + // struct ExtraPortionInfos @@ -359,7 +366,7 @@ struct ExtraPortionInfo sal_uInt16 nMaxCompression100thPercent; - sal_uInt8 nAsianCompressionTypes; + AsianCompressionFlags nAsianCompressionTypes; bool bFirstCharIsRightPunktuation; bool bCompressed; diff --git a/editeng/source/editeng/impedit.hxx b/editeng/source/editeng/impedit.hxx index b0658e0897b6..ac27e46e4f73 100644 --- a/editeng/source/editeng/impedit.hxx +++ b/editeng/source/editeng/impedit.hxx @@ -1222,7 +1222,7 @@ inline vcl::Cursor* ImpEditView::GetCursor() void ConvertItem( SfxPoolItem& rPoolItem, MapUnit eSourceUnit, MapUnit eDestUnit ); void ConvertAndPutItems( SfxItemSet& rDest, const SfxItemSet& rSource, const MapUnit* pSourceUnit = nullptr, const MapUnit* pDestUnit = nullptr ); -sal_uInt8 GetCharTypeForCompression( sal_Unicode cChar ); +AsianCompressionFlags GetCharTypeForCompression( sal_Unicode cChar ); Point Rotate( const Point& rPoint, short nOrientation, const Point& rOrigin ); #endif // INCLUDED_EDITENG_SOURCE_EDITENG_IMPEDIT_HXX diff --git a/editeng/source/editeng/impedit2.cxx b/editeng/source/editeng/impedit2.cxx index 3e40ef38d473..0cfb9ea38d07 100644 --- a/editeng/source/editeng/impedit2.cxx +++ b/editeng/source/editeng/impedit2.cxx @@ -3974,10 +3974,10 @@ long ImpEditEngine::GetXPos( if ( rPortion.GetExtraInfos() && rPortion.GetExtraInfos()->bCompressed ) { nX += rPortion.GetExtraInfos()->nPortionOffsetX; - if ( rPortion.GetExtraInfos()->nAsianCompressionTypes & CHAR_PUNCTUATIONRIGHT ) + if ( rPortion.GetExtraInfos()->nAsianCompressionTypes & AsianCompressionFlags::PunctuationRight ) { - sal_uInt8 nType = GetCharTypeForCompression( pParaPortion->GetNode()->GetChar( nIndex ) ); - if ( nType == CHAR_PUNCTUATIONRIGHT && !pLine->GetCharPosArray().empty() ) + AsianCompressionFlags nType = GetCharTypeForCompression( pParaPortion->GetNode()->GetChar( nIndex ) ); + if ( nType == AsianCompressionFlags::PunctuationRight && !pLine->GetCharPosArray().empty() ) { sal_Int32 n = nIndex - nTextPortionStart; const long* pDXArray = &pLine->GetCharPosArray()[0]+( nTextPortionStart-pLine->GetStart() ); @@ -3985,9 +3985,9 @@ long ImpEditEngine::GetXPos( - ( n ? pDXArray[n-1] : 0 ); if ( (n+1) < rPortion.GetLen() ) { - // smaller, when char behind is CHAR_PUNCTUATIONRIGHT also + // smaller, when char behind is AsianCompressionFlags::PunctuationRight also nType = GetCharTypeForCompression( pParaPortion->GetNode()->GetChar( nIndex+1 ) ); - if ( nType == CHAR_PUNCTUATIONRIGHT ) + if ( nType == AsianCompressionFlags::PunctuationRight ) { sal_Int32 nNextCharWidth = ( ( (n+2) < rPortion.GetLen() ) ? pDXArray[n+1] : rPortion.GetSize().Width() ) - pDXArray[n]; diff --git a/editeng/source/editeng/impedit3.cxx b/editeng/source/editeng/impedit3.cxx index 0da41d7af407..8f1d96933783 100644 --- a/editeng/source/editeng/impedit3.cxx +++ b/editeng/source/editeng/impedit3.cxx @@ -128,7 +128,7 @@ Point Rotate( const Point& rPoint, short nOrientation, const Point& rOrigin ) return aTranslatedPos; } -sal_uInt8 GetCharTypeForCompression( sal_Unicode cChar ) +AsianCompressionFlags GetCharTypeForCompression( sal_Unicode cChar ) { switch ( cChar ) { @@ -136,18 +136,18 @@ sal_uInt8 GetCharTypeForCompression( sal_Unicode cChar ) case 0x3010: case 0x3014: case 0x3016: case 0x3018: case 0x301A: case 0x301D: { - return CHAR_PUNCTUATIONRIGHT; + return AsianCompressionFlags::PunctuationRight; } case 0x3001: case 0x3002: case 0x3009: case 0x300B: case 0x300D: case 0x300F: case 0x3011: case 0x3015: case 0x3017: case 0x3019: case 0x301B: case 0x301E: case 0x301F: { - return CHAR_PUNCTUATIONLEFT; + return AsianCompressionFlags::PunctuationLeft; } default: { - return ( ( 0x3040 <= cChar ) && ( 0x3100 > cChar ) ) ? CHAR_KANA : CHAR_NORMAL; + return ( ( 0x3040 <= cChar ) && ( 0x3100 > cChar ) ) ? AsianCompressionFlags::Kana : AsianCompressionFlags::Normal; } } } @@ -4426,10 +4426,10 @@ bool ImpEditEngine::ImplCalcAsianCompression(ContentNode* pNode, sal_Int32 nPortionLen = pTextPortion->GetLen(); for ( sal_Int32 n = 0; n < nPortionLen; n++ ) { - sal_uInt8 nType = GetCharTypeForCompression( pNode->GetChar( n+nStartPos ) ); + AsianCompressionFlags nType = GetCharTypeForCompression( pNode->GetChar( n+nStartPos ) ); - bool bCompressPunctuation = ( nType == CHAR_PUNCTUATIONLEFT ) || ( nType == CHAR_PUNCTUATIONRIGHT ); - bool bCompressKana = ( nType == CHAR_KANA ) && ( GetAsianCompressionMode() == text::CharacterCompressionType::PUNCTUATION_AND_KANA ); + bool bCompressPunctuation = ( nType == AsianCompressionFlags::PunctuationLeft ) || ( nType == AsianCompressionFlags::PunctuationRight ); + bool bCompressKana = ( nType == AsianCompressionFlags::Kana ) && ( GetAsianCompressionMode() == text::CharacterCompressionType::PUNCTUATION_AND_KANA ); // create Extra infos only if needed... if ( bCompressPunctuation || bCompressKana ) @@ -4439,7 +4439,7 @@ bool ImpEditEngine::ImplCalcAsianCompression(ContentNode* pNode, ExtraPortionInfo* pExtraInfos = new ExtraPortionInfo; pTextPortion->SetExtraInfos( pExtraInfos ); pExtraInfos->nOrgWidth = pTextPortion->GetSize().Width(); - pExtraInfos->nAsianCompressionTypes = CHAR_NORMAL; + pExtraInfos->nAsianCompressionTypes = AsianCompressionFlags::Normal; } pTextPortion->GetExtraInfos()->nMaxCompression100thPercent = n100thPercentFromMax; pTextPortion->GetExtraInfos()->nAsianCompressionTypes |= nType; @@ -4489,7 +4489,7 @@ bool ImpEditEngine::ImplCalcAsianCompression(ContentNode* pNode, if ( !pTextPortion->GetExtraInfos()->pOrgDXArray ) pTextPortion->GetExtraInfos()->SaveOrgDXArray( pDXArray, pTextPortion->GetLen()-1 ); - if ( nType == CHAR_PUNCTUATIONRIGHT ) + if ( nType == AsianCompressionFlags::PunctuationRight ) { // If it's the first char, I must handle it in Paint()... if ( n ) -- cgit