editeng/source/editeng/eertfpar.cxx | 2 editeng/source/editeng/eertfpar.hxx | 2 editeng/source/rtf/rtfitem.cxx | 46 ++++++++--------- editeng/source/rtf/svxrtf.cxx | 16 +++--- include/editeng/svxrtf.hxx | 10 +-- sw/qa/extras/rtfimport/data/fdo85812.rtf | 31 ++++++++++++ sw/qa/extras/rtfimport/rtfimport.cxx | 64 ++++++++++++++++++++++++- writerfilter/source/rtftok/rtfdocumentimpl.cxx | 5 + 8 files changed, 135 insertions(+), 41 deletions(-)
New commits: commit a9a9718bb1f64318429562ecdaa3d3763d9e2f4a Author: Michael Stahl <[email protected]> Date: Wed Nov 5 18:46:29 2014 +0100 fdo#85812: RTF import: better fix for run type in new groups Apparently Word treats \ltrch \rtlch differently from \loch \hich \dbch when groups are opened. Change-Id: I257712521e8e77fa66e76857489797ecc675506e diff --git a/sw/qa/extras/rtfimport/data/fdo85812.rtf b/sw/qa/extras/rtfimport/data/fdo85812.rtf index 2f3e10c..152971f 100644 --- a/sw/qa/extras/rtfimport/data/fdo85812.rtf +++ b/sw/qa/extras/rtfimport/data/fdo85812.rtf @@ -4,5 +4,36 @@ \pard\plain \lang1049\langfe2052\loch\hich\dbch\langnp1049\langfenp2052 {\lang1033\langfe2052\dbch\langnp1033 \hich\dbch\loch This } + +\par\pard\plain +\lang1049\langfe2052\loch\hich\dbch +{CharGroup} +\lang1033 AfterChar + +\par\pard\plain +\lang1049\langfe2052\loch\hich\dbch +{\*\bkmkstart foomark}{\*\bkmkend foomark} +\lang1033 AfterBookmark + +\par\pard\plain +\lang1049\langfe2052\loch\hich\lang5121\dbch\lang1049 +{CharGroup} +\lang1033 AfterChar + +\par\pard\plain +\lang1049\langfe2052\loch\hich\lang5121\dbch\lang1049 +{\*\bkmkstart foomark}{\*\bkmkend foomark} +\lang1033 AfterBookmark + +\par\pard\plain +\lang1049\langfe2052\ltrch\lang1033\rtlch\lang5121 +{CharGroup} +\lang3073 AfterChar + +\par\pard\plain +\lang1049\langfe2052\ltrch\lang1033\rtlch\lang5121 +{\*\bkmkstart foomark}{\*\bkmkend foomark} +\lang3073 AfterBookmark + {\lang1036\langfe2052\langnp1036 \par } } diff --git a/sw/qa/extras/rtfimport/rtfimport.cxx b/sw/qa/extras/rtfimport/rtfimport.cxx index a4dd898..3e28659 100644 --- a/sw/qa/extras/rtfimport/rtfimport.cxx +++ b/sw/qa/extras/rtfimport/rtfimport.cxx @@ -481,7 +481,69 @@ DECLARE_RTFIMPORT_TEST(testFdo85812, "fdo85812.rtf") // the \lang inside the group was applied to CJK not Western CPPUNIT_ASSERT_EQUAL(OUString("en"), locale.Language); CPPUNIT_ASSERT_EQUAL(OUString("US"), locale.Country); - + // further testing indicates that Word is doing really weird stuff + // \loch \hich \dbch is reset by opening a group + locale = getProperty<lang::Locale>( + getRun(getParagraph(2), 1, "CharGroup"), "CharLocale"); + CPPUNIT_ASSERT_EQUAL(OUString("ru"), locale.Language); + CPPUNIT_ASSERT_EQUAL(OUString("RU"), locale.Country); + locale = getProperty<lang::Locale>( + getRun(getParagraph(2), 2, "AfterChar"), "CharLocale"); + CPPUNIT_ASSERT_EQUAL(OUString("en"), locale.Language); + CPPUNIT_ASSERT_EQUAL(OUString("US"), locale.Country); + locale = getProperty<lang::Locale>( + getRun(getParagraph(3), 2, "AfterBookmark"), "CharLocale"); + CPPUNIT_ASSERT_EQUAL(OUString("en"), locale.Language); + CPPUNIT_ASSERT_EQUAL(OUString("US"), locale.Country); + locale = getProperty<lang::Locale>( + getRun(getParagraph(4), 1, "CharGroup"), "CharLocale"); + CPPUNIT_ASSERT_EQUAL(OUString("ru"), locale.Language); + CPPUNIT_ASSERT_EQUAL(OUString("RU"), locale.Country); + locale = getProperty<lang::Locale>( + getRun(getParagraph(4), 1, "CharGroup"), "CharLocaleComplex"); + CPPUNIT_ASSERT_EQUAL(OUString("ar"), locale.Language); + CPPUNIT_ASSERT_EQUAL(OUString("DZ"), locale.Country); + locale = getProperty<lang::Locale>( + getRun(getParagraph(4), 2, "AfterChar"), "CharLocale"); + CPPUNIT_ASSERT_EQUAL(OUString("en"), locale.Language); + CPPUNIT_ASSERT_EQUAL(OUString("US"), locale.Country); + locale = getProperty<lang::Locale>( + getRun(getParagraph(4), 2, "AfterChar"), "CharLocaleComplex"); + CPPUNIT_ASSERT_EQUAL(OUString("ar"), locale.Language); + CPPUNIT_ASSERT_EQUAL(OUString("DZ"), locale.Country); + locale = getProperty<lang::Locale>( + getRun(getParagraph(5), 2, "AfterBookmark"), "CharLocale"); + CPPUNIT_ASSERT_EQUAL(OUString("en"), locale.Language); + CPPUNIT_ASSERT_EQUAL(OUString("US"), locale.Country); + locale = getProperty<lang::Locale>( + getRun(getParagraph(5), 2, "AfterBookmark"), "CharLocaleComplex"); + CPPUNIT_ASSERT_EQUAL(OUString("ar"), locale.Language); + CPPUNIT_ASSERT_EQUAL(OUString("DZ"), locale.Country); + // \ltrch \rtlch works differently - it is sticky across groups + locale = getProperty<lang::Locale>( + getRun(getParagraph(6), 1, "CharGroup"), "CharLocale"); + CPPUNIT_ASSERT_EQUAL(OUString("en"), locale.Language); + CPPUNIT_ASSERT_EQUAL(OUString("US"), locale.Country); + locale = getProperty<lang::Locale>( + getRun(getParagraph(6), 1, "CharGroup"), "CharLocaleComplex"); + CPPUNIT_ASSERT_EQUAL(OUString("ar"), locale.Language); + CPPUNIT_ASSERT_EQUAL(OUString("DZ"), locale.Country); + locale = getProperty<lang::Locale>( + getRun(getParagraph(6), 2, "AfterChar"), "CharLocale"); + CPPUNIT_ASSERT_EQUAL(OUString("en"), locale.Language); + CPPUNIT_ASSERT_EQUAL(OUString("US"), locale.Country); + locale = getProperty<lang::Locale>( + getRun(getParagraph(6), 2, "AfterChar"), "CharLocaleComplex"); + CPPUNIT_ASSERT_EQUAL(OUString("ar"), locale.Language); + CPPUNIT_ASSERT_EQUAL(OUString("EG"), locale.Country); + locale = getProperty<lang::Locale>( + getRun(getParagraph(7), 2, "AfterBookmark"), "CharLocale"); + CPPUNIT_ASSERT_EQUAL(OUString("en"), locale.Language); + CPPUNIT_ASSERT_EQUAL(OUString("US"), locale.Country); + locale = getProperty<lang::Locale>( + getRun(getParagraph(7), 2, "AfterBookmark"), "CharLocaleComplex"); + CPPUNIT_ASSERT_EQUAL(OUString("ar"), locale.Language); + CPPUNIT_ASSERT_EQUAL(OUString("EG"), locale.Country); } DECLARE_RTFIMPORT_TEST(testFdo47764, "fdo47764.rtf") diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx index 99693f3..a568d95 100644 --- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx +++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx @@ -4823,13 +4823,14 @@ int RTFDocumentImpl::pushState() m_aStates.push(m_aDefaultState); else { + // fdo#85812 group resets run type of _current_ and new state (but not RTL) + m_aStates.top().eRunType = RTFParserState::LOCH; + if (m_aStates.top().nDestinationState == DESTINATION_MR) lcl_DestinationToMath(*m_aStates.top().pDestinationText, m_aMathBuffer, m_bMathNor); m_aStates.push(m_aStates.top()); } m_aStates.top().aDestinationText.setLength(0); // was copied: always reset! - m_aStates.top().isRightToLeft = false; // fdo#85812 group resets run type - m_aStates.top().eRunType = RTFParserState::LOCH; m_pTokenizer->pushGroup(); commit 33b5b467224fef8d99ba3f6f4cba3d404119c100 Author: Michael Stahl <[email protected]> Date: Wed Nov 5 14:22:27 2014 +0100 editeng: SvxRTFParser sal_Bool to bool Change-Id: I2159f5c45ec6e6df965836705792cf2d71abbc42 diff --git a/editeng/source/editeng/eertfpar.cxx b/editeng/source/editeng/eertfpar.cxx index 5b1d516..641b5b9 100644 --- a/editeng/source/editeng/eertfpar.cxx +++ b/editeng/source/editeng/eertfpar.cxx @@ -257,7 +257,7 @@ void EditRTFParser::InsertPara() nLastAction = ACTION_INSERTPARABRK; } -void EditRTFParser::MovePos( int bForward ) +void EditRTFParser::MovePos( bool const bForward ) { if( bForward ) aCurSel = mpEditEngine->CursorRight( diff --git a/editeng/source/editeng/eertfpar.hxx b/editeng/source/editeng/eertfpar.hxx index 1f1b9d5..59d215e 100644 --- a/editeng/source/editeng/eertfpar.hxx +++ b/editeng/source/editeng/eertfpar.hxx @@ -79,7 +79,7 @@ private: protected: virtual void InsertPara() SAL_OVERRIDE; virtual void InsertText() SAL_OVERRIDE; - virtual void MovePos( int bForward = sal_True ) SAL_OVERRIDE; + virtual void MovePos( bool bForward = true ) SAL_OVERRIDE; virtual void SetEndPrevPara( SvxNodeIdx*& rpNodePos, sal_Int32& rCntPos ) SAL_OVERRIDE; diff --git a/editeng/source/rtf/rtfitem.cxx b/editeng/source/rtf/rtfitem.cxx index 6d3c9eb..b58bd7c 100644 --- a/editeng/source/rtf/rtfitem.cxx +++ b/editeng/source/rtf/rtfitem.cxx @@ -204,7 +204,8 @@ void SvxRTFParser::SetScriptAttr( RTF_CharTypeDef eType, SfxItemSet& rSet, void SvxRTFParser::ReadAttr( int nToken, SfxItemSet* pSet ) { DBG_ASSERT( pSet, "A SfxItemSet has to be provided as argument!" ); - int bFirstToken = sal_True, bContinue = sal_True; + bool bFirstToken = true; + bool bContinue = true; sal_uInt16 nStyleNo = 0; // default FontUnderline eUnderline; FontUnderline eOverline; @@ -220,14 +221,14 @@ void SvxRTFParser::ReadAttr( int nToken, SfxItemSet* pSet ) switch( nToken ) { case RTF_PARD: - RTFPardPlain( sal_True, &pSet ); + RTFPardPlain( true, &pSet ); ResetPard(); nStyleNo = 0; bPardTokenRead = true; break; case RTF_PLAIN: - RTFPardPlain( sal_False, &pSet ); + RTFPardPlain( false, &pSet ); break; default: @@ -249,7 +250,7 @@ void SvxRTFParser::ReadAttr( int nToken, SfxItemSet* pSet ) { // Open a new Group SvxRTFItemStackType* pNew = new SvxRTFItemStackType( - *pAkt, *pInsPos, sal_True ); + *pAkt, *pInsPos, true ); pNew->SetRTFDefaults( GetRTFDefaults() ); // "Set" all valid attributes up until this point @@ -283,7 +284,7 @@ void SvxRTFParser::ReadAttr( int nToken, SfxItemSet* pSet ) { if( !bFirstToken ) SkipToken( -1 ); - bContinue = sal_False; + bContinue = false; } else { @@ -691,7 +692,7 @@ SET_FONTALIGNMENT: if( aPlainMap.nContour && IsAttrSttPos() ) // not in the text flow? { - pSet->Put( SvxContourItem( nTokenValue ? sal_True : sal_False, + pSet->Put( SvxContourItem(nTokenValue != 0, aPlainMap.nContour )); } break; @@ -700,7 +701,7 @@ SET_FONTALIGNMENT: if( aPlainMap.nShadowed && IsAttrSttPos() ) // not in the text flow? { - pSet->Put( SvxShadowedItem( nTokenValue ? sal_True : sal_False, + pSet->Put( SvxShadowedItem(nTokenValue != 0, aPlainMap.nShadowed )); } break; @@ -1139,10 +1140,9 @@ ATTR_SETEMPHASIS: case RTF_HYPHEN: { SvxHyphenZoneItem aHypenZone( - (nTokenValue & 1) ? sal_True : sal_False, + (nTokenValue & 1) != 0, aPardMap.nHyphenzone ); - aHypenZone.SetPageEnd( - (nTokenValue & 2) ? sal_True : sal_False ); + aHypenZone.SetPageEnd((nTokenValue & 2) != 0); if( aPardMap.nHyphenzone && RTF_HYPHLEAD == GetNextToken() && @@ -1165,7 +1165,7 @@ ATTR_SETEMPHASIS: case RTF_SHADOW: { - int bSkip = sal_True; + bool bSkip = true; do { // middle check loop SvxShadowLocation eSL = SvxShadowLocation( nTokenValue ); if( RTF_SHDW_DIST != GetNextToken() ) @@ -1188,7 +1188,7 @@ ATTR_SETEMPHASIS: pSet->Put( SvxShadowItem( aPardMap.nShadow, &aColor, nDist, eSL ) ); - bSkip = sal_False; + bSkip = false; } while( false ); if( bSkip ) @@ -1253,7 +1253,7 @@ ATTR_SETEMPHASIS: if (!bFirstToken) --nSkip; // BRACELEFT: is the next token SkipToken( nSkip ); - bContinue = sal_False; + bContinue = false; } } break; @@ -1269,7 +1269,7 @@ ATTR_SETEMPHASIS: // unknown token, so token "returned in Parser" if( !bFirstToken ) SkipToken( -1 ); - bContinue = sal_False; + bContinue = false; } } } @@ -1277,7 +1277,7 @@ ATTR_SETEMPHASIS: { nToken = GetNextToken(); } - bFirstToken = sal_False; + bFirstToken = false; } } @@ -1287,7 +1287,7 @@ void SvxRTFParser::ReadTabAttr( int nToken, SfxItemSet& rSet ) // then read all the TabStops SvxTabStop aTabStop; SvxTabStopItem aAttr( 0, 0, SVX_TAB_ADJUST_DEFAULT, aPardMap.nTabStop ); - int bContinue = sal_True; + bool bContinue = true; do { switch( nToken ) { @@ -1340,13 +1340,13 @@ void SvxRTFParser::ReadTabAttr( int nToken, SfxItemSet& rSet ) if( nSkip ) { SkipToken( nSkip ); // Ignore back again - bContinue = sal_False; + bContinue = false; } } break; default: - bContinue = sal_False; + bContinue = false; } if( bContinue ) { @@ -1703,15 +1703,15 @@ void SvxRTFParser::ReadBackgroundAttr( int nToken, SfxItemSet& rSet, } -// pard / plain abarbeiten -void SvxRTFParser::RTFPardPlain( int bPard, SfxItemSet** ppSet ) +// pard / plain handling +void SvxRTFParser::RTFPardPlain( bool const bPard, SfxItemSet** ppSet ) { if( !bNewGroup && !aAttrStack.empty() ) // not at the beginning of a new group { SvxRTFItemStackType* pAkt = aAttrStack.back(); int nLastToken = GetStackPtr(-1)->nTokenId; - int bNewStkEntry = sal_True; + bool bNewStkEntry = true; if( RTF_PARD != nLastToken && RTF_PLAIN != nLastToken && BRACELEFT != nLastToken ) @@ -1719,7 +1719,7 @@ void SvxRTFParser::RTFPardPlain( int bPard, SfxItemSet** ppSet ) if( pAkt->aAttrSet.Count() || pAkt->pChildList || pAkt->nStyleNo ) { // open a new group - SvxRTFItemStackType* pNew = new SvxRTFItemStackType( *pAkt, *pInsPos, sal_True ); + SvxRTFItemStackType* pNew = new SvxRTFItemStackType( *pAkt, *pInsPos, true ); pNew->SetRTFDefaults( GetRTFDefaults() ); // Set all until here valid attributes @@ -1733,7 +1733,7 @@ void SvxRTFParser::RTFPardPlain( int bPard, SfxItemSet** ppSet ) { // continue to use this entry as new pAkt->SetStartPos( *pInsPos ); - bNewStkEntry = sal_False; + bNewStkEntry = false; } } diff --git a/editeng/source/rtf/svxrtf.cxx b/editeng/source/rtf/svxrtf.cxx index 4489731..d67b49e 100644 --- a/editeng/source/rtf/svxrtf.cxx +++ b/editeng/source/rtf/svxrtf.cxx @@ -60,7 +60,7 @@ static rtl_TextEncoding lcl_GetDefaultTextEncodingForRTF() SvxRTFParser::SvxRTFParser( SfxItemPool& rPool, SvStream& rIn, uno::Reference<document::XDocumentProperties> i_xDocProps, - int bReadNewDoc ) + bool const bReadNewDoc ) : SvRTFParser( rIn, 5 ) , rStrm(rIn) , aPlainMap(rPool) @@ -822,7 +822,7 @@ const vcl::Font& SvxRTFParser::GetFont( sal_uInt16 nId ) return *pFont; } -SvxRTFItemStackType* SvxRTFParser::_GetAttrSet( int bCopyAttr ) +SvxRTFItemStackType* SvxRTFParser::_GetAttrSet( bool const bCopyAttr ) { SvxRTFItemStackType* pAkt = aAttrStack.empty() ? 0 : aAttrStack.back(); SvxRTFItemStackType* pNew; @@ -927,7 +927,7 @@ void SvxRTFParser::AttrGroupEnd() // process the current, delete from Stack { // at the beginning of a paragraph? Move back one position sal_Int32 nNd = pInsPos->GetNodeIdx(); - MovePos( sal_False ); + MovePos(false); // if can not move backward then later dont move forward ! bCrsrBack = nNd != pInsPos->GetNodeIdx(); } @@ -951,7 +951,7 @@ void SvxRTFParser::AttrGroupEnd() // process the current, delete from Stack // - all paragraph attributes to get the area // up to the previous paragraph SvxRTFItemStackType* pNew = new SvxRTFItemStackType( - *pOld, *pInsPos, sal_True ); + *pOld, *pInsPos, true ); pNew->aAttrSet.SetParent( pOld->aAttrSet.GetParent() ); // Delete all paragraph attributes from pNew @@ -1021,12 +1021,12 @@ void SvxRTFParser::AttrGroupEnd() // process the current, delete from Stack if( bCrsrBack && 50 < pAkt->pChildList->size() ) { // at the beginning of a paragraph? Move back one position - MovePos( sal_True ); + MovePos(true); bCrsrBack = false; // Open a new Group. SvxRTFItemStackType* pNew = new SvxRTFItemStackType( - *pAkt, *pInsPos, sal_True ); + *pAkt, *pInsPos, true ); pNew->SetRTFDefaults( GetRTFDefaults() ); // Set all until here valid Attributes @@ -1047,7 +1047,7 @@ void SvxRTFParser::AttrGroupEnd() // process the current, delete from Stack if( bCrsrBack ) // at the beginning of a paragraph? Move back one position - MovePos( sal_True ); + MovePos(true); } while( false ); @@ -1161,7 +1161,7 @@ SvxRTFItemStackType::SvxRTFItemStackType( SvxRTFItemStackType::SvxRTFItemStackType( const SvxRTFItemStackType& rCpy, const SvxPosition& rPos, - int bCopyAttr ) + bool const bCopyAttr ) : aAttrSet( *rCpy.aAttrSet.GetPool(), rCpy.aAttrSet.GetRanges() ), pChildList( 0 ), nStyleNo( rCpy.nStyleNo ) diff --git a/include/editeng/svxrtf.hxx b/include/editeng/svxrtf.hxx index 842cd11..4971578 100644 --- a/include/editeng/svxrtf.hxx +++ b/include/editeng/svxrtf.hxx @@ -214,7 +214,7 @@ class EDITENG_DLLPUBLIC SvxRTFParser : public SvRTFParser void ClearStyleTbl(); void ClearAttrStack(); - SvxRTFItemStackType* _GetAttrSet( int bCopyAttr=sal_False ); // Create new ItemStackType:s + SvxRTFItemStackType* _GetAttrSet(bool bCopyAttr = false); // Create new ItemStackType:s void _ClearStyleAttr( SvxRTFItemStackType& rStkType ); // Sets all the attributes that are different from the current @@ -223,7 +223,7 @@ class EDITENG_DLLPUBLIC SvxRTFParser : public SvRTFParser void SetDefault( int nToken, int nValue ); // Execute pard / plain - void RTFPardPlain( int bPard, SfxItemSet** ppSet ); + void RTFPardPlain( bool bPard, SfxItemSet** ppSet ); void BuildWhichTbl(); @@ -273,7 +273,7 @@ protected: virtual void InsertText() = 0; - virtual void MovePos( int bForward = sal_True ) = 0; + virtual void MovePos( bool bForward = true ) = 0; virtual void SetEndPrevPara( SvxNodeIdx*& rpNodePos, sal_Int32& rCntPos )=0; virtual void SetAttrInDoc( SvxRTFItemStackType &rSet ); @@ -287,7 +287,7 @@ protected: SvStream& rIn, ::com::sun::star::uno::Reference< ::com::sun::star::document::XDocumentProperties> i_xDocProps, - int bReadNewDoc = sal_True ); + bool bReadNewDoc = true ); virtual ~SvxRTFParser(); bool IsNewDoc() const { return bNewDoc; } @@ -364,7 +364,7 @@ class EDITENG_DLLPUBLIC SvxRTFItemStackType public: SvxRTFItemStackType( const SvxRTFItemStackType&, const SvxPosition&, - int bCopyAttr = sal_False ); + bool bCopyAttr = false ); ~SvxRTFItemStackType(); //cmc, I'm very suspicios about SetStartPos, it doesn't change //its children's starting position, and the implementation looks _______________________________________________ Libreoffice-commits mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
