summaryrefslogtreecommitdiff
path: root/editeng/source/rtf
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2020-04-14 15:58:10 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2020-04-14 20:45:59 +0200
commitd72f963c0de0c2e48f1dc999cd8687e13a1f676f (patch)
tree9f5e314e1f9e504706cc18675f9408fe3c8db8ea /editeng/source/rtf
parent1c3929a0a1645e802ee18f9c3d3d380375500c72 (diff)
loplugin:flatten in editeng
Change-Id: I5c83183d1f9d2d8f5a25b976ead1a7598a75c641 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/92197 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'editeng/source/rtf')
-rw-r--r--editeng/source/rtf/rtfitem.cxx168
-rw-r--r--editeng/source/rtf/svxrtf.cxx276
2 files changed, 222 insertions, 222 deletions
diff --git a/editeng/source/rtf/rtfitem.cxx b/editeng/source/rtf/rtfitem.cxx
index 45a579d6e301..dab691d39f6c 100644
--- a/editeng/source/rtf/rtfitem.cxx
+++ b/editeng/source/rtf/rtfitem.cxx
@@ -1690,107 +1690,107 @@ void SvxRTFParser::ReadBackgroundAttr( int nToken, SfxItemSet& rSet,
// pard / plain handling
void SvxRTFParser::RTFPardPlain( bool const bPard, SfxItemSet** ppSet )
{
- if( !bNewGroup && !aAttrStack.empty() ) // not at the beginning of a new group
+ if( bNewGroup || aAttrStack.empty() ) // not at the beginning of a new group
+ return;
+
+ SvxRTFItemStackType* pCurrent = aAttrStack.back().get();
+
+ int nLastToken = GetStackPtr(-1)->nTokenId;
+ bool bNewStkEntry = true;
+ if( RTF_PARD != nLastToken &&
+ RTF_PLAIN != nLastToken &&
+ BRACELEFT != nLastToken )
{
- SvxRTFItemStackType* pCurrent = aAttrStack.back().get();
+ if (pCurrent->aAttrSet.Count() || pCurrent->m_pChildList || pCurrent->nStyleNo)
+ {
+ // open a new group
+ std::unique_ptr<SvxRTFItemStackType> pNew(new SvxRTFItemStackType( *pCurrent, *pInsPos, true ));
+ pNew->SetRTFDefaults( GetRTFDefaults() );
+
+ // Set all until here valid attributes
+ AttrGroupEnd();
+ pCurrent = aAttrStack.empty() ? nullptr : aAttrStack.back().get(); // can be changed after AttrGroupEnd!
+ pNew->aAttrSet.SetParent( pCurrent ? &pCurrent->aAttrSet : nullptr );
+ aAttrStack.push_back( std::move(pNew) );
+ pCurrent = aAttrStack.back().get();
+ }
+ else
+ {
+ // continue to use this entry as new
+ pCurrent->SetStartPos( *pInsPos );
+ bNewStkEntry = false;
+ }
+ }
- int nLastToken = GetStackPtr(-1)->nTokenId;
- bool bNewStkEntry = true;
- if( RTF_PARD != nLastToken &&
- RTF_PLAIN != nLastToken &&
- BRACELEFT != nLastToken )
+ // now reset all to default
+ if( bNewStkEntry &&
+ ( pCurrent->aAttrSet.GetParent() || pCurrent->aAttrSet.Count() ))
+ {
+ const SfxPoolItem *pItem, *pDef;
+ const sal_uInt16* pPtr;
+ sal_uInt16 nCnt;
+ const SfxItemSet* pDfltSet = &GetRTFDefaults();
+ if( bPard )
{
- if (pCurrent->aAttrSet.Count() || pCurrent->m_pChildList || pCurrent->nStyleNo)
- {
- // open a new group
- std::unique_ptr<SvxRTFItemStackType> pNew(new SvxRTFItemStackType( *pCurrent, *pInsPos, true ));
- pNew->SetRTFDefaults( GetRTFDefaults() );
-
- // Set all until here valid attributes
- AttrGroupEnd();
- pCurrent = aAttrStack.empty() ? nullptr : aAttrStack.back().get(); // can be changed after AttrGroupEnd!
- pNew->aAttrSet.SetParent( pCurrent ? &pCurrent->aAttrSet : nullptr );
- aAttrStack.push_back( std::move(pNew) );
- pCurrent = aAttrStack.back().get();
- }
- else
- {
- // continue to use this entry as new
- pCurrent->SetStartPos( *pInsPos );
- bNewStkEntry = false;
- }
+ pCurrent->nStyleNo = 0;
+ pPtr = reinterpret_cast<sal_uInt16*>(&aPardMap);
+ nCnt = sizeof(aPardMap) / sizeof(sal_uInt16);
+ }
+ else
+ {
+ pPtr = reinterpret_cast<sal_uInt16*>(&aPlainMap);
+ nCnt = sizeof(aPlainMap) / sizeof(sal_uInt16);
}
- // now reset all to default
- if( bNewStkEntry &&
- ( pCurrent->aAttrSet.GetParent() || pCurrent->aAttrSet.Count() ))
+ for( sal_uInt16 n = 0; n < nCnt; ++n, ++pPtr )
{
- const SfxPoolItem *pItem, *pDef;
- const sal_uInt16* pPtr;
- sal_uInt16 nCnt;
- const SfxItemSet* pDfltSet = &GetRTFDefaults();
- if( bPard )
+ // Item set and different -> Set the Default Pool
+ if( !*pPtr )
+ ;
+ else if (SfxItemPool::IsSlot(*pPtr))
+ pCurrent->aAttrSet.ClearItem( *pPtr );
+ else if( IsChkStyleAttr() )
+ pCurrent->aAttrSet.Put( pDfltSet->Get( *pPtr ) );
+ else if( !pCurrent->aAttrSet.GetParent() )
{
- pCurrent->nStyleNo = 0;
- pPtr = reinterpret_cast<sal_uInt16*>(&aPardMap);
- nCnt = sizeof(aPardMap) / sizeof(sal_uInt16);
+ if( SfxItemState::SET ==
+ pDfltSet->GetItemState( *pPtr, false, &pDef ))
+ pCurrent->aAttrSet.Put( *pDef );
+ else
+ pCurrent->aAttrSet.ClearItem( *pPtr );
}
+ else if( SfxItemState::SET == pCurrent->aAttrSet.GetParent()->
+ GetItemState( *pPtr, true, &pItem ) &&
+ *( pDef = &pDfltSet->Get( *pPtr )) != *pItem )
+ pCurrent->aAttrSet.Put( *pDef );
else
{
- pPtr = reinterpret_cast<sal_uInt16*>(&aPlainMap);
- nCnt = sizeof(aPlainMap) / sizeof(sal_uInt16);
- }
-
- for( sal_uInt16 n = 0; n < nCnt; ++n, ++pPtr )
- {
- // Item set and different -> Set the Default Pool
- if( !*pPtr )
- ;
- else if (SfxItemPool::IsSlot(*pPtr))
- pCurrent->aAttrSet.ClearItem( *pPtr );
- else if( IsChkStyleAttr() )
- pCurrent->aAttrSet.Put( pDfltSet->Get( *pPtr ) );
- else if( !pCurrent->aAttrSet.GetParent() )
- {
- if( SfxItemState::SET ==
- pDfltSet->GetItemState( *pPtr, false, &pDef ))
- pCurrent->aAttrSet.Put( *pDef );
- else
- pCurrent->aAttrSet.ClearItem( *pPtr );
- }
- else if( SfxItemState::SET == pCurrent->aAttrSet.GetParent()->
- GetItemState( *pPtr, true, &pItem ) &&
- *( pDef = &pDfltSet->Get( *pPtr )) != *pItem )
+ if( SfxItemState::SET ==
+ pDfltSet->GetItemState( *pPtr, false, &pDef ))
pCurrent->aAttrSet.Put( *pDef );
else
- {
- if( SfxItemState::SET ==
- pDfltSet->GetItemState( *pPtr, false, &pDef ))
- pCurrent->aAttrSet.Put( *pDef );
- else
- pCurrent->aAttrSet.ClearItem( *pPtr );
- }
+ pCurrent->aAttrSet.ClearItem( *pPtr );
}
}
- else if( bPard )
- pCurrent->nStyleNo = 0; // reset Style number
+ }
+ else if( bPard )
+ pCurrent->nStyleNo = 0; // reset Style number
- *ppSet = &pCurrent->aAttrSet;
+ *ppSet = &pCurrent->aAttrSet;
- if (!bPard)
- {
- //Once we have a default font, then any text without a font specifier is
- //in the default font, and thus has the default font charset, otherwise
- //we can fall back to the ansicpg set codeset
- if (nDfltFont != -1)
- {
- const vcl::Font& rSVFont = GetFont(sal_uInt16(nDfltFont));
- SetEncoding(rSVFont.GetCharSet());
- }
- else
- SetEncoding(GetCodeSet());
- }
+ if (bPard)
+ return;
+
+ //Once we have a default font, then any text without a font specifier is
+ //in the default font, and thus has the default font charset, otherwise
+ //we can fall back to the ansicpg set codeset
+ if (nDfltFont != -1)
+ {
+ const vcl::Font& rSVFont = GetFont(sal_uInt16(nDfltFont));
+ SetEncoding(rSVFont.GetCharSet());
}
+ else
+ SetEncoding(GetCodeSet());
}
void SvxRTFParser::SetDefault( int nToken, int nValue )
diff --git a/editeng/source/rtf/svxrtf.cxx b/editeng/source/rtf/svxrtf.cxx
index 6f57a5ddd29e..b766f4acc304 100644
--- a/editeng/source/rtf/svxrtf.cxx
+++ b/editeng/source/rtf/svxrtf.cxx
@@ -677,169 +677,169 @@ void SvxRTFParser::ClearStyleAttr_( SvxRTFItemStackType& rStkType )
void SvxRTFParser::AttrGroupEnd() // process the current, delete from Stack
{
- if( !aAttrStack.empty() )
- {
- std::unique_ptr<SvxRTFItemStackType> pOld = std::move(aAttrStack.back());
- aAttrStack.pop_back();
- SvxRTFItemStackType *pCurrent = aAttrStack.empty() ? nullptr : aAttrStack.back().get();
-
- do { // middle check loop
- sal_Int32 nOldSttNdIdx = pOld->pSttNd->GetIdx();
- if (!pOld->m_pChildList &&
- ((!pOld->aAttrSet.Count() && !pOld->nStyleNo ) ||
- (nOldSttNdIdx == pInsPos->GetNodeIdx() &&
- pOld->nSttCnt == pInsPos->GetCntIdx() )))
- break; // no attributes or Area
-
- // set only the attributes that are different from the parent
- if( pCurrent && pOld->aAttrSet.Count() )
- {
- SfxItemIter aIter( pOld->aAttrSet );
- const SfxPoolItem* pItem = aIter.GetCurItem(), *pGet;
- do
- {
- if( SfxItemState::SET == pCurrent->aAttrSet.GetItemState(
- pItem->Which(), false, &pGet ) &&
- *pItem == *pGet )
- pOld->aAttrSet.ClearItem( pItem->Which() );
+ if( aAttrStack.empty() )
+ return;
- pItem = aIter.NextItem();
- } while (pItem);
+ std::unique_ptr<SvxRTFItemStackType> pOld = std::move(aAttrStack.back());
+ aAttrStack.pop_back();
+ SvxRTFItemStackType *pCurrent = aAttrStack.empty() ? nullptr : aAttrStack.back().get();
- if (!pOld->aAttrSet.Count() && !pOld->m_pChildList &&
- !pOld->nStyleNo )
- break;
- }
+ do { // middle check loop
+ sal_Int32 nOldSttNdIdx = pOld->pSttNd->GetIdx();
+ if (!pOld->m_pChildList &&
+ ((!pOld->aAttrSet.Count() && !pOld->nStyleNo ) ||
+ (nOldSttNdIdx == pInsPos->GetNodeIdx() &&
+ pOld->nSttCnt == pInsPos->GetCntIdx() )))
+ break; // no attributes or Area
- // Set all attributes which have been defined from start until here
- bool bCrsrBack = !pInsPos->GetCntIdx();
- if( bCrsrBack )
+ // set only the attributes that are different from the parent
+ if( pCurrent && pOld->aAttrSet.Count() )
+ {
+ SfxItemIter aIter( pOld->aAttrSet );
+ const SfxPoolItem* pItem = aIter.GetCurItem(), *pGet;
+ do
{
- // at the beginning of a paragraph? Move back one position
- sal_Int32 nNd = pInsPos->GetNodeIdx();
- MovePos(false);
- // if can not move backward then later don't move forward !
- bCrsrBack = nNd != pInsPos->GetNodeIdx();
- }
+ if( SfxItemState::SET == pCurrent->aAttrSet.GetItemState(
+ pItem->Which(), false, &pGet ) &&
+ *pItem == *pGet )
+ pOld->aAttrSet.ClearItem( pItem->Which() );
+
+ pItem = aIter.NextItem();
+ } while (pItem);
- if( pOld->pSttNd->GetIdx() < pInsPos->GetNodeIdx() ||
- ( pOld->pSttNd->GetIdx() == pInsPos->GetNodeIdx() &&
- pOld->nSttCnt <= pInsPos->GetCntIdx() ) )
+ if (!pOld->aAttrSet.Count() && !pOld->m_pChildList &&
+ !pOld->nStyleNo )
+ break;
+ }
+
+ // Set all attributes which have been defined from start until here
+ bool bCrsrBack = !pInsPos->GetCntIdx();
+ if( bCrsrBack )
+ {
+ // at the beginning of a paragraph? Move back one position
+ sal_Int32 nNd = pInsPos->GetNodeIdx();
+ MovePos(false);
+ // if can not move backward then later don't move forward !
+ bCrsrBack = nNd != pInsPos->GetNodeIdx();
+ }
+
+ if( pOld->pSttNd->GetIdx() < pInsPos->GetNodeIdx() ||
+ ( pOld->pSttNd->GetIdx() == pInsPos->GetNodeIdx() &&
+ pOld->nSttCnt <= pInsPos->GetCntIdx() ) )
+ {
+ if( !bCrsrBack )
{
- if( !bCrsrBack )
+ // all pard attributes are only valid until the previous
+ // paragraph !!
+ if( nOldSttNdIdx == pInsPos->GetNodeIdx() )
+ {
+ }
+ else
{
- // all pard attributes are only valid until the previous
- // paragraph !!
- if( nOldSttNdIdx == pInsPos->GetNodeIdx() )
+ // Now it gets complicated:
+ // - all character attributes sre keep the area
+ // - all paragraph attributes to get the area
+ // up to the previous paragraph
+ std::unique_ptr<SvxRTFItemStackType> pNew(
+ new SvxRTFItemStackType(*pOld, *pInsPos, true));
+ pNew->aAttrSet.SetParent( pOld->aAttrSet.GetParent() );
+
+ // Delete all paragraph attributes from pNew
+ for( sal_uInt16 n = 0; n < (sizeof(aPardMap) / sizeof(sal_uInt16)) &&
+ pNew->aAttrSet.Count(); ++n )
+ if( reinterpret_cast<sal_uInt16*>(&aPardMap)[n] )
+ pNew->aAttrSet.ClearItem( reinterpret_cast<sal_uInt16*>(&aPardMap)[n] );
+ pNew->SetRTFDefaults( GetRTFDefaults() );
+
+ // Were there any?
+ if( pNew->aAttrSet.Count() == pOld->aAttrSet.Count() )
{
+ pNew.reset();
}
else
{
- // Now it gets complicated:
- // - all character attributes sre keep the area
- // - all paragraph attributes to get the area
- // up to the previous paragraph
- std::unique_ptr<SvxRTFItemStackType> pNew(
- new SvxRTFItemStackType(*pOld, *pInsPos, true));
- pNew->aAttrSet.SetParent( pOld->aAttrSet.GetParent() );
-
- // Delete all paragraph attributes from pNew
- for( sal_uInt16 n = 0; n < (sizeof(aPardMap) / sizeof(sal_uInt16)) &&
- pNew->aAttrSet.Count(); ++n )
- if( reinterpret_cast<sal_uInt16*>(&aPardMap)[n] )
- pNew->aAttrSet.ClearItem( reinterpret_cast<sal_uInt16*>(&aPardMap)[n] );
- pNew->SetRTFDefaults( GetRTFDefaults() );
-
- // Were there any?
- if( pNew->aAttrSet.Count() == pOld->aAttrSet.Count() )
+ pNew->nStyleNo = 0;
+
+ // Now span the real area of pNew from old
+ SetEndPrevPara( pOld->pEndNd, pOld->nEndCnt );
+ pNew->nSttCnt = 0;
+
+ if( IsChkStyleAttr() )
+ {
+ ClearStyleAttr_( *pOld );
+ ClearStyleAttr_( *pNew ); //#i10381#, methinks.
+ }
+
+ if( pCurrent )
{
- pNew.reset();
+ pCurrent->Add(std::move(pOld));
+ pCurrent->Add(std::move(pNew));
}
else
{
- pNew->nStyleNo = 0;
-
- // Now span the real area of pNew from old
- SetEndPrevPara( pOld->pEndNd, pOld->nEndCnt );
- pNew->nSttCnt = 0;
-
- if( IsChkStyleAttr() )
- {
- ClearStyleAttr_( *pOld );
- ClearStyleAttr_( *pNew ); //#i10381#, methinks.
- }
-
- if( pCurrent )
- {
- pCurrent->Add(std::move(pOld));
- pCurrent->Add(std::move(pNew));
- }
- else
- {
- // Last off the stack, thus cache it until the next text was
- // read. (Span no attributes!)
-
- m_AttrSetList.push_back(std::move(pOld));
- m_AttrSetList.push_back(std::move(pNew));
- }
- break;
+ // Last off the stack, thus cache it until the next text was
+ // read. (Span no attributes!)
+
+ m_AttrSetList.push_back(std::move(pOld));
+ m_AttrSetList.push_back(std::move(pNew));
}
+ break;
}
}
+ }
- pOld->pEndNd = pInsPos->MakeNodeIdx().release();
- pOld->nEndCnt = pInsPos->GetCntIdx();
-
- /*
- #i21422#
- If the parent (pCurrent) sets something e.g. , and the child (pOld)
- unsets it and the style both are based on has it unset then
- clearing the pOld by looking at the style is clearly a disaster
- as the text ends up with pCurrents bold and not pOlds no bold, this
- should be rethought out. For the moment its safest to just do
- the clean if we have no parent, all we suffer is too many
- redundant properties.
- */
- if (IsChkStyleAttr() && !pCurrent)
- ClearStyleAttr_( *pOld );
-
- if( pCurrent )
+ pOld->pEndNd = pInsPos->MakeNodeIdx().release();
+ pOld->nEndCnt = pInsPos->GetCntIdx();
+
+ /*
+ #i21422#
+ If the parent (pCurrent) sets something e.g. , and the child (pOld)
+ unsets it and the style both are based on has it unset then
+ clearing the pOld by looking at the style is clearly a disaster
+ as the text ends up with pCurrents bold and not pOlds no bold, this
+ should be rethought out. For the moment its safest to just do
+ the clean if we have no parent, all we suffer is too many
+ redundant properties.
+ */
+ if (IsChkStyleAttr() && !pCurrent)
+ ClearStyleAttr_( *pOld );
+
+ if( pCurrent )
+ {
+ pCurrent->Add(std::move(pOld));
+ // split up and create new entry, because it makes no sense
+ // to create a "so long" depend list. Bug 95010
+ if (bCrsrBack && 50 < pCurrent->m_pChildList->size())
{
- pCurrent->Add(std::move(pOld));
- // split up and create new entry, because it makes no sense
- // to create a "so long" depend list. Bug 95010
- if (bCrsrBack && 50 < pCurrent->m_pChildList->size())
- {
- // at the beginning of a paragraph? Move back one position
- MovePos();
- bCrsrBack = false;
-
- // Open a new Group.
- std::unique_ptr<SvxRTFItemStackType> pNew(new SvxRTFItemStackType(
- *pCurrent, *pInsPos, true ));
- pNew->SetRTFDefaults( GetRTFDefaults() );
-
- // Set all until here valid Attributes
- AttrGroupEnd();
- pCurrent = aAttrStack.empty() ? nullptr : aAttrStack.back().get(); // can be changed after AttrGroupEnd!
- pNew->aAttrSet.SetParent( pCurrent ? &pCurrent->aAttrSet : nullptr );
- aAttrStack.push_back( std::move(pNew) );
- }
+ // at the beginning of a paragraph? Move back one position
+ MovePos();
+ bCrsrBack = false;
+
+ // Open a new Group.
+ std::unique_ptr<SvxRTFItemStackType> pNew(new SvxRTFItemStackType(
+ *pCurrent, *pInsPos, true ));
+ pNew->SetRTFDefaults( GetRTFDefaults() );
+
+ // Set all until here valid Attributes
+ AttrGroupEnd();
+ pCurrent = aAttrStack.empty() ? nullptr : aAttrStack.back().get(); // can be changed after AttrGroupEnd!
+ pNew->aAttrSet.SetParent( pCurrent ? &pCurrent->aAttrSet : nullptr );
+ aAttrStack.push_back( std::move(pNew) );
}
- else
- // Last off the stack, thus cache it until the next text was
- // read. (Span no attributes!)
- m_AttrSetList.push_back(std::move(pOld));
}
+ else
+ // Last off the stack, thus cache it until the next text was
+ // read. (Span no attributes!)
+ m_AttrSetList.push_back(std::move(pOld));
+ }
- if( bCrsrBack )
- // at the beginning of a paragraph? Move back one position
- MovePos();
+ if( bCrsrBack )
+ // at the beginning of a paragraph? Move back one position
+ MovePos();
- } while( false );
+ } while( false );
- bNewGroup = false;
- }
+ bNewGroup = false;
}
void SvxRTFParser::SetAllAttrOfStk() // end all Attr. and set it into doc