diff options
-rw-r--r-- | editeng/qa/unit/core-test.cxx | 1386 | ||||
-rw-r--r-- | editeng/source/editeng/impedit2.cxx | 51 | ||||
-rw-r--r-- | include/svx/svdotable.hxx | 2 | ||||
-rw-r--r-- | include/svx/svdotext.hxx | 2 | ||||
-rw-r--r-- | sd/source/ui/inc/View.hxx | 1 | ||||
-rw-r--r-- | sd/source/ui/inc/tablefunction.hxx | 1 | ||||
-rw-r--r-- | sd/source/ui/table/tablefunction.cxx | 26 | ||||
-rw-r--r-- | sd/source/ui/view/sdview3.cxx | 101 | ||||
-rw-r--r-- | svx/Library_svx.mk | 1 | ||||
-rw-r--r-- | svx/source/table/tablehtmlimporter.cxx | 509 |
10 files changed, 1384 insertions, 696 deletions
diff --git a/editeng/qa/unit/core-test.cxx b/editeng/qa/unit/core-test.cxx index e40d5f0bf4c9..9cec620ed291 100644 --- a/editeng/qa/unit/core-test.cxx +++ b/editeng/qa/unit/core-test.cxx @@ -37,12 +37,13 @@ #include <com/sun/star/text/textfield/Type.hpp> #include <memory> +#include <vector> #include <editeng/outliner.hxx> using namespace com::sun::star; -namespace { - +namespace +{ class Test : public test::BootstrapFixture { public: @@ -86,6 +87,12 @@ public: /// Test Paste using an HTML fragment void testHTMLFragmentPaste(); + /// Test Paste using an RTF + void testRTFPaste(); + + /// Test Paste preference HTML/ + void testRTFHTMLPaste(); + /// Test Copy/Paste with selective selection over multiple paragraphs void testMultiParaSelCopyPaste(); @@ -124,7 +131,7 @@ public: void testCreateLines(); void testTdf154248MultilineFieldWrapping(); - DECL_STATIC_LINK( Test, CalcFieldValueHdl, EditFieldInfo*, void ); + DECL_STATIC_LINK(Test, CalcFieldValueHdl, EditFieldInfo*, void); CPPUNIT_TEST_SUITE(Test); #if HAVE_MORE_FONTS @@ -137,6 +144,8 @@ public: CPPUNIT_TEST(testCopyPaste); CPPUNIT_TEST(testHTMLPaste); CPPUNIT_TEST(testHTMLFragmentPaste); + CPPUNIT_TEST(testRTFPaste); + CPPUNIT_TEST(testRTFHTMLPaste); CPPUNIT_TEST(testMultiParaSelCopyPaste); CPPUNIT_TEST(testTabsCopyPaste); CPPUNIT_TEST(testHyperlinkSearch); @@ -166,12 +175,12 @@ void Test::testLineSpacing() // Create EditEngine's instance EditEngine aEditEngine(mpItemPool.get()); - if(aEditEngine.GetRefDevice()->GetDPIY() != 96 + if (aEditEngine.GetRefDevice()->GetDPIY() != 96 || aEditEngine.GetRefDevice()->GetDPIScaleFactor() != 1.0) return; // Get EditDoc for current EditEngine's instance - EditDoc &rDoc = aEditEngine.GetEditDoc(); + EditDoc& rDoc = aEditEngine.GetEditDoc(); // Initially no text should be there CPPUNIT_ASSERT_EQUAL(sal_Int32(0), rDoc.GetTextLen()); @@ -190,8 +199,7 @@ void Test::testLineSpacing() // Select all paragraphs ESelection aSelection(0, 0, 0, aTextLen); - auto doTest = [&](sal_uInt16 nSpace, sal_uInt16 nExpMaxAscent, sal_uInt32 nExpLineHeight) - { + auto doTest = [&](sal_uInt16 nSpace, sal_uInt16 nExpMaxAscent, sal_uInt32 nExpLineHeight) { std::unique_ptr<SfxItemSet> pSet(new SfxItemSet(aEditEngine.GetEmptyItemSet())); SvxLineSpacingItem aLineSpacing(LINE_SPACE_DEFAULT_HEIGHT, EE_PARA_SBL); aLineSpacing.SetPropLineSpace(nSpace); @@ -248,7 +256,7 @@ void Test::testConstruction() bool includes(const uno::Sequence<OUString>& rSeq, std::u16string_view rVal) { - for (OUString const & s : rSeq) + for (OUString const& s : rSeq) if (s == rVal) return true; @@ -299,7 +307,8 @@ void Test::testUnoTextFields() { // FILE - rtl::Reference<SvxUnoTextField> xField(new SvxUnoTextField(text::textfield::Type::DOCINFO_TITLE)); + rtl::Reference<SvxUnoTextField> xField( + new SvxUnoTextField(text::textfield::Type::DOCINFO_TITLE)); uno::Sequence<OUString> aSvcs = xField->getSupportedServiceNames(); bool bGood = includes(aSvcs, u"com.sun.star.text.textfield.docinfo.Title"); CPPUNIT_ASSERT_MESSAGE("expected service is not present.", bGood); @@ -315,7 +324,8 @@ void Test::testUnoTextFields() { // EXTENDED TIME - rtl::Reference<SvxUnoTextField> xField(new SvxUnoTextField(text::textfield::Type::EXTENDED_TIME)); + rtl::Reference<SvxUnoTextField> xField( + new SvxUnoTextField(text::textfield::Type::EXTENDED_TIME)); uno::Sequence<OUString> aSvcs = xField->getSupportedServiceNames(); bool bGood = includes(aSvcs, u"com.sun.star.text.textfield.DateTime"); CPPUNIT_ASSERT_MESSAGE("expected service is not present.", bGood); @@ -323,7 +333,8 @@ void Test::testUnoTextFields() { // EXTENDED FILE - rtl::Reference<SvxUnoTextField> xField(new SvxUnoTextField(text::textfield::Type::EXTENDED_FILE)); + rtl::Reference<SvxUnoTextField> xField( + new SvxUnoTextField(text::textfield::Type::EXTENDED_FILE)); uno::Sequence<OUString> aSvcs = xField->getSupportedServiceNames(); bool bGood = includes(aSvcs, u"com.sun.star.text.textfield.FileName"); CPPUNIT_ASSERT_MESSAGE("expected service is not present.", bGood); @@ -347,7 +358,8 @@ void Test::testUnoTextFields() { // PRESENTATION HEADER - rtl::Reference<SvxUnoTextField> xField(new SvxUnoTextField(text::textfield::Type::PRESENTATION_HEADER)); + rtl::Reference<SvxUnoTextField> xField( + new SvxUnoTextField(text::textfield::Type::PRESENTATION_HEADER)); uno::Sequence<OUString> aSvcs = xField->getSupportedServiceNames(); bool bGood = includes(aSvcs, u"com.sun.star.presentation.textfield.Header"); CPPUNIT_ASSERT_MESSAGE("expected service is not present.", bGood); @@ -355,7 +367,8 @@ void Test::testUnoTextFields() { // PRESENTATION FOOTER - rtl::Reference<SvxUnoTextField> xField(new SvxUnoTextField(text::textfield::Type::PRESENTATION_FOOTER)); + rtl::Reference<SvxUnoTextField> xField( + new SvxUnoTextField(text::textfield::Type::PRESENTATION_FOOTER)); uno::Sequence<OUString> aSvcs = xField->getSupportedServiceNames(); bool bGood = includes(aSvcs, u"com.sun.star.presentation.textfield.Footer"); CPPUNIT_ASSERT_MESSAGE("expected service is not present.", bGood); @@ -363,7 +376,8 @@ void Test::testUnoTextFields() { // PRESENTATION DATE TIME - rtl::Reference<SvxUnoTextField> xField(new SvxUnoTextField(text::textfield::Type::PRESENTATION_DATE_TIME)); + rtl::Reference<SvxUnoTextField> xField( + new SvxUnoTextField(text::textfield::Type::PRESENTATION_DATE_TIME)); uno::Sequence<OUString> aSvcs = xField->getSupportedServiceNames(); bool bGood = includes(aSvcs, u"com.sun.star.presentation.textfield.DateTime"); CPPUNIT_ASSERT_MESSAGE("expected service is not present.", bGood); @@ -374,46 +388,44 @@ class TestAutoCorrDoc : public SvxAutoCorrDoc { public: /// just like the real thing, this dummy modifies the rText parameter :( - TestAutoCorrDoc(OUString &rText, LanguageType eLang) + TestAutoCorrDoc(OUString& rText, LanguageType eLang) : m_rText(rText) , m_eLang(eLang) { } - OUString const& getResult() const - { - return m_rText; - } + OUString const& getResult() const { return m_rText; } + private: - OUString & m_rText; + OUString& m_rText; LanguageType m_eLang; - virtual bool Delete( sal_Int32 nStt, sal_Int32 nEnd ) override + virtual bool Delete(sal_Int32 nStt, sal_Int32 nEnd) override { //fprintf(stderr, "TestAutoCorrDoc::Delete\n"); - m_rText = m_rText.replaceAt(nStt, nEnd-nStt, u""); + m_rText = m_rText.replaceAt(nStt, nEnd - nStt, u""); return true; } - virtual bool Insert( sal_Int32 nPos, const OUString& rTxt ) override + virtual bool Insert(sal_Int32 nPos, const OUString& rTxt) override { //fprintf(stderr, "TestAutoCorrDoc::Insert\n"); m_rText = m_rText.replaceAt(nPos, 0, rTxt); return true; } - virtual bool Replace( sal_Int32 nPos, const OUString& rTxt ) override + virtual bool Replace(sal_Int32 nPos, const OUString& rTxt) override { //fprintf(stderr, "TestAutoCorrDoc::Replace\n"); - return ReplaceRange( nPos, rTxt.getLength(), rTxt ); + return ReplaceRange(nPos, rTxt.getLength(), rTxt); } - virtual bool ReplaceRange( sal_Int32 nPos, sal_Int32 nLen, const OUString& rTxt ) override + virtual bool ReplaceRange(sal_Int32 nPos, sal_Int32 nLen, const OUString& rTxt) override { //fprintf(stderr, "TestAutoCorrDoc::ReplaceRange %d %d %s\n", nPos, nLen, OUStringToOString(rTxt, RTL_TEXTENCODING_UTF8).getStr()); m_rText = m_rText.replaceAt(nPos, nLen, rTxt); return true; } - virtual void SetAttr( sal_Int32, sal_Int32, sal_uInt16, SfxPoolItem& ) override + virtual void SetAttr(sal_Int32, sal_Int32, sal_uInt16, SfxPoolItem&) override { //fprintf(stderr, "TestAutoCorrDoc::SetAttr\n"); } - virtual bool SetINetAttr( sal_Int32, sal_Int32, const OUString& ) override + virtual bool SetINetAttr(sal_Int32, sal_Int32, const OUString&) override { //fprintf(stderr, "TestAutoCorrDoc::SetINetAttr\n"); return true; @@ -423,30 +435,29 @@ private: //fprintf(stderr, "TestAutoCorrDoc::GetPrevPara\n"); return nullptr; } - virtual bool ChgAutoCorrWord( sal_Int32& rSttPos, - sal_Int32 nEndPos, SvxAutoCorrect& rACorrect, - OUString* pPara ) override + virtual bool ChgAutoCorrWord(sal_Int32& rSttPos, sal_Int32 nEndPos, SvxAutoCorrect& rACorrect, + OUString* pPara) override { //fprintf(stderr, "TestAutoCorrDoc::ChgAutoCorrWord\n"); if (m_rText.isEmpty()) return false; - LanguageTag aLanguageTag( m_eLang); - const SvxAutocorrWord* pFnd = rACorrect.SearchWordsInList( - m_rText, rSttPos, nEndPos, *this, aLanguageTag); + LanguageTag aLanguageTag(m_eLang); + const SvxAutocorrWord* pFnd + = rACorrect.SearchWordsInList(m_rText, rSttPos, nEndPos, *this, aLanguageTag); if (pFnd && pFnd->IsTextOnly()) { m_rText = m_rText.replaceAt(rSttPos, nEndPos, pFnd->GetLong()); - if( pPara ) + if (pPara) pPara->clear(); // =&pCurNode->GetString(); return true; } return false; } - virtual bool TransliterateRTLWord( sal_Int32& /*rSttPos*/, - sal_Int32 /*nEndPos*/, bool /*bApply*/ ) override + virtual bool TransliterateRTLWord(sal_Int32& /*rSttPos*/, sal_Int32 /*nEndPos*/, + bool /*bApply*/) override { return false; } @@ -530,10 +541,9 @@ void Test::testAutocorrect() CPPUNIT_ASSERT_EQUAL_MESSAGE("autocorrect", OUString(sExpected), aFoo.getResult()); } - } -IMPL_STATIC_LINK( Test, CalcFieldValueHdl, EditFieldInfo*, pInfo, void ) +IMPL_STATIC_LINK(Test, CalcFieldValueHdl, EditFieldInfo*, pInfo, void) { if (!pInfo) return; @@ -544,18 +554,18 @@ IMPL_STATIC_LINK( Test, CalcFieldValueHdl, EditFieldInfo*, pInfo, void ) { // URLField OUString aURL = pURLField->GetURL(); - switch ( pURLField->GetFormat() ) + switch (pURLField->GetFormat()) { case SvxURLFormat::AppDefault: case SvxURLFormat::Repr: { - pInfo->SetRepresentation( pURLField->GetRepresentation() ); + pInfo->SetRepresentation(pURLField->GetRepresentation()); } break; case SvxURLFormat::Url: { - pInfo->SetRepresentation( aURL ); + pInfo->SetRepresentation(aURL); } break; } @@ -571,17 +581,17 @@ void Test::testHyperlinkCopyPaste() { // Create Outliner instance Outliner aOutliner(mpItemPool.get(), OutlinerMode::TextObject); - aOutliner.SetCalcFieldValueHdl( LINK( nullptr, Test, CalcFieldValueHdl ) ); + aOutliner.SetCalcFieldValueHdl(LINK(nullptr, Test, CalcFieldValueHdl)); // Create EditEngine's instance - EditEngine& aEditEngine = const_cast<EditEngine&> (aOutliner.GetEditEngine()); + EditEngine& aEditEngine = const_cast<EditEngine&>(aOutliner.GetEditEngine()); // Get EditDoc for current EditEngine's instance - EditDoc &rDoc = aEditEngine.GetEditDoc(); + EditDoc& rDoc = aEditEngine.GetEditDoc(); // New instance must be empty - no initial text - CPPUNIT_ASSERT_EQUAL( sal_Int32(0), rDoc.GetTextLen() ); - CPPUNIT_ASSERT_EQUAL( OUString(), rDoc.GetParaAsString(sal_Int32(0)) ); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), rDoc.GetTextLen()); + CPPUNIT_ASSERT_EQUAL(OUString(), rDoc.GetParaAsString(sal_Int32(0))); // Get corresponding Field Item for inserting URLs in text // URL 1 @@ -599,26 +609,26 @@ void Test::testHyperlinkCopyPaste() OUString aParaText = u"sampletextfortestingfeaturefields"_ustr; // Positions Ref .............*13....*20.......... sal_Int32 aTextLen = aParaText.getLength(); - aEditEngine.SetText( aParaText ); + aEditEngine.SetText(aParaText); // Assert changes - CPPUNIT_ASSERT_EQUAL( aTextLen, rDoc.GetTextLen() ); - CPPUNIT_ASSERT_EQUAL( aParaText, rDoc.GetParaAsString(sal_Int32(0)) ); + CPPUNIT_ASSERT_EQUAL(aTextLen, rDoc.GetTextLen()); + CPPUNIT_ASSERT_EQUAL(aParaText, rDoc.GetParaAsString(sal_Int32(0))); // Insert URL 1 - ContentNode *pNode = rDoc.GetObject(0); - EditSelection aSel1( EditPaM(pNode, 13), EditPaM(pNode, 13) ); - aEditEngine.InsertField( aSel1, aField1 ); + ContentNode* pNode = rDoc.GetObject(0); + EditSelection aSel1(EditPaM(pNode, 13), EditPaM(pNode, 13)); + aEditEngine.InsertField(aSel1, aField1); // Assert Field Count - CPPUNIT_ASSERT_EQUAL( sal_uInt16(1), aEditEngine.GetFieldCount(0) ); + CPPUNIT_ASSERT_EQUAL(sal_uInt16(1), aEditEngine.GetFieldCount(0)); // Insert URL 2 - EditSelection aSel2( EditPaM(pNode, 20 + 1), EditPaM(pNode, 20 + 1) ); - aEditEngine.InsertField( aSel2, aField2 ); + EditSelection aSel2(EditPaM(pNode, 20 + 1), EditPaM(pNode, 20 + 1)); + aEditEngine.InsertField(aSel2, aField2); // Assert Field Count - CPPUNIT_ASSERT_EQUAL( sal_uInt16(2), aEditEngine.GetFieldCount(0) ); + CPPUNIT_ASSERT_EQUAL(sal_uInt16(2), aEditEngine.GetFieldCount(0)); // Assert URL Fields and text before copy // Check text @@ -626,36 +636,40 @@ void Test::testHyperlinkCopyPaste() CPPUNIT_ASSERT_EQUAL( u"sampletextforuser@example.comtestingexample@domain.comfeaturefields"_ustr, rDoc.GetParaAsString(sal_Int32(0)) ); // Check Field 1 - EFieldInfo aURLFieldInfo1 = aEditEngine.GetFieldInfo( sal_Int32(0), sal_uInt16(0) ); - CPPUNIT_ASSERT_EQUAL( sal_Int32(13), aURLFieldInfo1.aPosition.nIndex ); - CPPUNIT_ASSERT_EQUAL( sal_uInt16(EE_FEATURE_FIELD), aURLFieldInfo1.pFieldItem->Which() ); - SvxURLField* pURLField1 = dynamic_cast<SvxURLField*> ( const_cast<SvxFieldData*> (aURLFieldInfo1.pFieldItem->GetField()) ); + EFieldInfo aURLFieldInfo1 = aEditEngine.GetFieldInfo(sal_Int32(0), sal_uInt16(0)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(13), aURLFieldInfo1.aPosition.nIndex); + CPPUNIT_ASSERT_EQUAL(sal_uInt16(EE_FEATURE_FIELD), aURLFieldInfo1.pFieldItem->Which()); + SvxURLField* pURLField1 = dynamic_cast<SvxURLField*>( + const_cast<SvxFieldData*>(aURLFieldInfo1.pFieldItem->GetField())); CPPUNIT_ASSERT(pURLField1); - CPPUNIT_ASSERT_EQUAL( aURL1, pURLField1->GetURL() ); - CPPUNIT_ASSERT_EQUAL( aRepres1, pURLField1->GetRepresentation() ); + CPPUNIT_ASSERT_EQUAL(aURL1, pURLField1->GetURL()); + CPPUNIT_ASSERT_EQUAL(aRepres1, pURLField1->GetRepresentation()); // Check Field 2 - EFieldInfo aURLFieldInfo2 = aEditEngine.GetFieldInfo( sal_Int32(0), sal_uInt16(1) ); - CPPUNIT_ASSERT_EQUAL( sal_Int32(21), aURLFieldInfo2.aPosition.nIndex ); - CPPUNIT_ASSERT_EQUAL( sal_uInt16(EE_FEATURE_FIELD), aURLFieldInfo2.pFieldItem->Which() ); - SvxURLField* pURLField2 = dynamic_cast<SvxURLField*> ( const_cast<SvxFieldData*> (aURLFieldInfo2.pFieldItem->GetField()) ); + EFieldInfo aURLFieldInfo2 = aEditEngine.GetFieldInfo(sal_Int32(0), sal_uInt16(1)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(21), aURLFieldInfo2.aPosition.nIndex); + CPPUNIT_ASSERT_EQUAL(sal_uInt16(EE_FEATURE_FIELD), aURLFieldInfo2.pFieldItem->Which()); + SvxURLField* pURLField2 = dynamic_cast<SvxURLField*>( + const_cast<SvxFieldData*>(aURLFieldInfo2.pFieldItem->GetField())); CPPUNIT_ASSERT(pURLField2); - CPPUNIT_ASSERT_EQUAL( aURL2, pURLField2->GetURL() ); - CPPUNIT_ASSERT_EQUAL( aRepres2, pURLField2->GetRepresentation() ); + CPPUNIT_ASSERT_EQUAL(aURL2, pURLField2->GetURL()); + CPPUNIT_ASSERT_EQUAL(aRepres2, pURLField2->GetRepresentation()); // Copy text using legacy format - uno::Reference< datatransfer::XTransferable > xData = aEditEngine.CreateTransferable( ESelection(0,10,0,21) ); + uno::Reference<datatransfer::XTransferable> xData + = aEditEngine.CreateTransferable(ESelection(0, 10, 0, 21)); // Paste text at the end - aEditEngine.InsertText( xData, OUString(), rDoc.GetEndPaM(), true ); + aEditEngine.InsertText(xData, OUString(), rDoc.GetEndPaM(), true); // Assert Changes ACP, ACP: after Copy/Paste // Check the fields count - CPPUNIT_ASSERT_EQUAL( sal_uInt16(3), aEditEngine.GetFieldCount(0) ); + CPPUNIT_ASSERT_EQUAL(sal_uInt16(3), aEditEngine.GetFieldCount(0)); // Check the updated text length - CPPUNIT_ASSERT_EQUAL( aTextLen + 10 + aRepres1.getLength()*2 + aRepres2.getLength(), rDoc.GetTextLen() ); + CPPUNIT_ASSERT_EQUAL(aTextLen + 10 + aRepres1.getLength() * 2 + aRepres2.getLength(), + rDoc.GetTextLen()); // Check the updated text contents CPPUNIT_ASSERT_EQUAL( u"sampletextforuser@example.comtestingexample@domain.comfeaturefieldsforuser@example.comtesting"_ustr, rDoc.GetParaAsString(sal_Int32(0)) ); @@ -663,118 +677,142 @@ void Test::testHyperlinkCopyPaste() // Check the Fields and their values // Field 1 - EFieldInfo aACPURLFieldInfo1 = aEditEngine.GetFieldInfo( sal_Int32(0), sal_uInt16(0) ); - CPPUNIT_ASSERT_EQUAL( sal_Int32(13), aACPURLFieldInfo1.aPosition.nIndex ); - CPPUNIT_ASSERT_EQUAL( sal_uInt16(EE_FEATURE_FIELD), aACPURLFieldInfo1.pFieldItem->Which() ); - SvxURLField* pACPURLField1 = dynamic_cast<SvxURLField*> ( const_cast<SvxFieldData*> (aACPURLFieldInfo1.pFieldItem->GetField()) ); + EFieldInfo aACPURLFieldInfo1 = aEditEngine.GetFieldInfo(sal_Int32(0), sal_uInt16(0)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(13), aACPURLFieldInfo1.aPosition.nIndex); + CPPUNIT_ASSERT_EQUAL(sal_uInt16(EE_FEATURE_FIELD), aACPURLFieldInfo1.pFieldItem->Which()); + SvxURLField* pACPURLField1 = dynamic_cast<SvxURLField*>( + const_cast<SvxFieldData*>(aACPURLFieldInfo1.pFieldItem->GetField())); CPPUNIT_ASSERT(pACPURLField1); - CPPUNIT_ASSERT_EQUAL( aURL1, pACPURLField1->GetURL() ); - CPPUNIT_ASSERT_EQUAL( aRepres1, pACPURLField1->GetRepresentation() ); + CPPUNIT_ASSERT_EQUAL(aURL1, pACPURLField1->GetURL()); + CPPUNIT_ASSERT_EQUAL(aRepres1, pACPURLField1->GetRepresentation()); // Field 2 - EFieldInfo aACPURLFieldInfo2 = aEditEngine.GetFieldInfo( sal_Int32(0), sal_uInt16(1) ); - CPPUNIT_ASSERT_EQUAL( sal_Int32(21), aACPURLFieldInfo2.aPosition.nIndex ); - CPPUNIT_ASSERT_EQUAL( sal_uInt16(EE_FEATURE_FIELD), aACPURLFieldInfo2.pFieldItem->Which() ); - SvxURLField* pACPURLField2 = dynamic_cast<SvxURLField*> ( const_cast<SvxFieldData*> (aACPURLFieldInfo2.pFieldItem->GetField()) ); + EFieldInfo aACPURLFieldInfo2 = aEditEngine.GetFieldInfo(sal_Int32(0), sal_uInt16(1)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(21), aACPURLFieldInfo2.aPosition.nIndex); + CPPUNIT_ASSERT_EQUAL(sal_uInt16(EE_FEATURE_FIELD), aACPURLFieldInfo2.pFieldItem->Which()); + SvxURLField* pACPURLField2 = dynamic_cast<SvxURLField*>( + const_cast<SvxFieldData*>(aACPURLFieldInfo2.pFieldItem->GetField())); CPPUNIT_ASSERT(pACPURLField2); - CPPUNIT_ASSERT_EQUAL( aURL2, pACPURLField2->GetURL() ); - CPPUNIT_ASSERT_EQUAL( aRepres2, pACPURLField2->GetRepresentation() ) ; + CPPUNIT_ASSERT_EQUAL(aURL2, pACPURLField2->GetURL()); + CPPUNIT_ASSERT_EQUAL(aRepres2, pACPURLField2->GetRepresentation()); // Field 3 - EFieldInfo aACPURLFieldInfo3 = aEditEngine.GetFieldInfo( sal_Int32(0), sal_uInt16(2) ); - CPPUNIT_ASSERT_EQUAL( sal_Int32(38), aACPURLFieldInfo3.aPosition.nIndex ); - CPPUNIT_ASSERT_EQUAL( sal_uInt16(EE_FEATURE_FIELD), aACPURLFieldInfo3.pFieldItem->Which() ); - SvxURLField* pACPURLField3 = dynamic_cast<SvxURLField*> ( const_cast<SvxFieldData*> (aACPURLFieldInfo3.pFieldItem->GetField()) ); + EFieldInfo aACPURLFieldInfo3 = aEditEngine.GetFieldInfo(sal_Int32(0), sal_uInt16(2)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(38), aACPURLFieldInfo3.aPosition.nIndex); + CPPUNIT_ASSERT_EQUAL(sal_uInt16(EE_FEATURE_FIELD), aACPURLFieldInfo3.pFieldItem->Which()); + SvxURLField* pACPURLField3 = dynamic_cast<SvxURLField*>( + const_cast<SvxFieldData*>(aACPURLFieldInfo3.pFieldItem->GetField())); CPPUNIT_ASSERT(pACPURLField3); - CPPUNIT_ASSERT_EQUAL( aURL1, pACPURLField3->GetURL() ); - CPPUNIT_ASSERT_EQUAL( aRepres1, pACPURLField3->GetRepresentation() ); + CPPUNIT_ASSERT_EQUAL(aURL1, pACPURLField3->GetURL()); + CPPUNIT_ASSERT_EQUAL(aRepres1, pACPURLField3->GetRepresentation()); } void Test::testCopyPaste() { // Create EditEngine's instance - EditEngine aEditEngine( mpItemPool.get() ); + EditEngine aEditEngine(mpItemPool.get()); // Get EditDoc for current EditEngine's instance - EditDoc &rDoc = aEditEngine.GetEditDoc(); + EditDoc& rDoc = aEditEngine.GetEditDoc(); // Initially no text should be there - CPPUNIT_ASSERT_EQUAL( sal_Int32(0), rDoc.GetTextLen() ); - CPPUNIT_ASSERT_EQUAL( OUString(), rDoc.GetParaAsString(sal_Int32(0)) ); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), rDoc.GetTextLen()); + CPPUNIT_ASSERT_EQUAL(OUString(), rDoc.GetParaAsString(sal_Int32(0))); // Set initial text OUString aText = u"This is custom initial text"_ustr; sal_Int32 aTextLen = aText.getLength(); - aEditEngine.SetText( aText ); + aEditEngine.SetText(aText); // Assert changes - CPPUNIT_ASSERT_EQUAL( aTextLen, rDoc.GetTextLen() ); - CPPUNIT_ASSERT_EQUAL( aText, rDoc.GetParaAsString(sal_Int32(0)) ); + CPPUNIT_ASSERT_EQUAL(aTextLen, rDoc.GetTextLen()); + CPPUNIT_ASSERT_EQUAL(aText, rDoc.GetParaAsString(sal_Int32(0))); // Copy initial text using legacy format - uno::Reference< datatransfer::XTransferable > xData = aEditEngine.CreateTransferable( ESelection(0,0,0,aTextLen) ); + uno::Reference<datatransfer::XTransferable> xData + = aEditEngine.CreateTransferable(ESelection(0, 0, 0, aTextLen)); // Paste text at the end - aEditEngine.InsertText( xData, OUString(), rDoc.GetEndPaM(), true ); + aEditEngine.InsertText(xData, OUString(), rDoc.GetEndPaM(), true); // Assert changes - CPPUNIT_ASSERT_EQUAL( aTextLen + aTextLen, rDoc.GetTextLen() ); - CPPUNIT_ASSERT_EQUAL( OUString(aText + aText), rDoc.GetParaAsString(sal_Int32(0)) ); + CPPUNIT_ASSERT_EQUAL(aTextLen + aTextLen, rDoc.GetTextLen()); + CPPUNIT_ASSERT_EQUAL(OUString(aText + aText), rDoc.GetParaAsString(sal_Int32(0))); } /// XTransferable implementation that provides simple HTML content. -class TestHTMLTransferable : public cppu::WeakImplHelper<datatransfer::XTransferable> +class TestTransferable : public cppu::WeakImplHelper<datatransfer::XTransferable> { - OString m_aHTML; + std::vector<OString> m_aContent; + std::vector<OUString> m_aMimeType; + public: - TestHTMLTransferable(const OString& rHTML); + TestTransferable(std::vector<OString>& rContent, std::vector<OUString>& rMimeType); uno::Any SAL_CALL getTransferData(const datatransfer::DataFlavor& rFlavor) override; uno::Sequence<datatransfer::DataFlavor> SAL_CALL getTransferDataFlavors() override; sal_Bool SAL_CALL isDataFlavorSupported(const datatransfer::DataFlavor& rFlavor) override; }; -TestHTMLTransferable::TestHTMLTransferable(const OString& rHTML) - : m_aHTML(rHTML) +TestTransferable::TestTransferable(std::vector<OString>& rContent, std::vector<OUString>& rMimeType) + : m_aContent(rContent) + , m_aMimeType(rMimeType) { + CPPUNIT_ASSERT_EQUAL(m_aContent.size(), m_aMimeType.size()); } -uno::Any TestHTMLTransferable::getTransferData(const datatransfer::DataFlavor& rFlavor) +uno::Any TestTransferable::getTransferData(const datatransfer::DataFlavor& rFlavor) { - if (rFlavor.MimeType != "text/html") + for (size_t nType = 0; nType < m_aMimeType.size(); ++nType) { - return {}; + if (rFlavor.MimeType == m_aMimeType[nType]) + { + uno::Any aRet; + SvMemoryStream aStream; + aStream.WriteOString(m_aContent[nType]); + aRet <<= uno::Sequence<sal_Int8>(static_cast<const sal_Int8*>(aStream.GetData()), + aStream.GetSize()); + return aRet; + } } - - uno::Any aRet; - SvMemoryStream aStream; - aStream.WriteOString(m_aHTML); - aRet <<= uno::Sequence<sal_Int8>(static_cast<const sal_Int8*>(aStream.GetData()), aStream.GetSize()); - return aRet; + return {}; } -uno::Sequence<datatransfer::DataFlavor> TestHTMLTransferable::getTransferDataFlavors() +uno::Sequence<datatransfer::DataFlavor> TestTransferable::getTransferDataFlavors() { - datatransfer::DataFlavor aFlavor; - aFlavor.DataType = cppu::UnoType<uno::Sequence<sal_Int8>>::get(); - aFlavor.MimeType = "text/html"; - aFlavor.HumanPresentableName = aFlavor.MimeType; - return { aFlavor }; + std::vector<datatransfer::DataFlavor> aFlavourVac; + for (size_t nType = 0; nType < m_aMimeType.size(); ++nType) + { + datatransfer::DataFlavor aFlavor; + aFlavor.DataType = cppu::UnoType<uno::Sequence<sal_Int8>>::get(); + aFlavor.MimeType = m_aMimeType[nType]; + aFlavor.HumanPresentableName = aFlavor.MimeType; + aFlavourVac.push_back(aFlavor); + } + uno::Sequence<datatransfer::DataFlavor> aFlavors(aFlavourVac.data(), m_aMimeType.size()); + return aFlavors; } -sal_Bool TestHTMLTransferable::isDataFlavorSupported(const datatransfer::DataFlavor& rFlavor) +sal_Bool TestTransferable::isDataFlavorSupported(const datatransfer::DataFlavor& rFlavor) { - return rFlavor.MimeType == "text/html" - && rFlavor.DataType == cppu::UnoType<uno::Sequence<sal_Int8>>::get(); + for (size_t nType = 0; nType < m_aMimeType.size(); ++nType) + { + if (rFlavor.MimeType == m_aMimeType[nType] + && rFlavor.DataType == cppu::UnoType<uno::Sequence<sal_Int8>>::get()) + return true; + } + return false; } void Test::testHTMLPaste() { // Given an empty editeng document: EditEngine aEditEngine(mpItemPool.get()); - EditDoc &rDoc = aEditEngine.GetEditDoc(); - OString aHTML("<!DOCTYPE html>\n<html><body>test</body></html>"_ostr); - uno::Reference< datatransfer::XTransferable > xData(new TestHTMLTransferable(aHTML)); + EditDoc& rDoc = aEditEngine.GetEditDoc(); + //OString aHTML("<!DOCTYPE html>\n<html><body>test</body></html>"_ostr); + std::vector<OString> aContent({ "<!DOCTYPE html>\n<html><body>test</body></html>"_ostr }); + std::vector<OUString> aMime({ "text/html" }); + uno::Reference<datatransfer::XTransferable> xData(new TestTransferable(aContent, aMime)); // When trying to paste HTML: aEditEngine.InsertText(xData, OUString(), rDoc.GetEndPaM(), true); @@ -790,9 +828,11 @@ void Test::testHTMLFragmentPaste() { // Given an empty editeng document: EditEngine aEditEngine(mpItemPool.get()); - EditDoc &rDoc = aEditEngine.GetEditDoc(); - OString aHTML("a<b>b</b>c"_ostr); - uno::Reference< datatransfer::XTransferable > xData(new TestHTMLTransferable(aHTML)); + EditDoc& rDoc = aEditEngine.GetEditDoc(); + std::vector<OString> aContent({ "a<b>b</b>c"_ostr }); + std::vector<OUString> aMime({ "text/html" }); + + uno::Reference<datatransfer::XTransferable> xData(new TestTransferable(aContent, aMime)); // When trying to paste an HTML fragment: aEditEngine.InsertText(xData, OUString(), rDoc.GetEndPaM(), true); @@ -805,17 +845,71 @@ void Test::testHTMLFragmentPaste() CPPUNIT_ASSERT_EQUAL(u"abc"_ustr, rDoc.GetParaAsString(static_cast<sal_Int32>(0))); } +void Test::testRTFPaste() +{ + // Given an empty editeng document: + EditEngine aEditEngine(mpItemPool.get()); + EditDoc& rDoc = aEditEngine.GetEditDoc(); + std::vector<OString> aContent( + { "{\\rtf1\\adeflang1025\\ansi{\\ul www.libreoffice.org}}"_ostr }); + std::vector<OUString> aMime({ "text/richtext" }); + uno::Reference<datatransfer::XTransferable> xData(new TestTransferable(aContent, aMime)); + + // When trying to paste HTML: + aEditEngine.InsertText(xData, OUString(), rDoc.GetEndPaM(), true); + + // Then make sure the text gets pasted: + // Without the accompanying fix in place, this test would have failed with: + // - Expected: www.libreoffice.org + // - Actual : + // i.e. RTF and plain text paste worked, but not HTML. + CPPUNIT_ASSERT_EQUAL(OUString("www.libreoffice.org"), + rDoc.GetParaAsString(static_cast<sal_Int32>(0))); +} + +void Test::testRTFHTMLPaste() +{ + // Given an empty editeng document: + EditEngine aEditEngine(mpItemPool.get()); + EditDoc& rDoc = aEditEngine.GetEditDoc(); + std::vector<OString> aContent( + { "{\\rtf1\\adeflang1025\\ansi{\\ul www.libreoffice.org}}"_ostr, + "Version:1.0\nStartHTML:0000000121\n" + "EndHTML:0000000596\n" + "StartFragment:0000000519\n" + "EndFragment:0000000579\n" + "<!DOCTYPE html><html><head><meta http-equiv=\"content-type\" content=\"text/html; " + "charset=utf-8\"/>" + "<title></title><meta name=\"generator\" content=\"LibreOffice 7.4.5.1 (Windows)\"/>" + "<style type=\"text/css\">@page { size: 21cm 29.7cm; margin: 2cm }" + "p{ line-height: 115%; margin-bottom: 0.25cm; background: transparent }</style>" + "</head><body lang=\"de-DE\" link=\"#000080\" vlink=\"#800000\" dir=\"ltr\">" + "<p style=\"line-height: 100%; margin-bottom: 0cm\">abc</p></body></html>"_ostr }); + std::vector<OUString> aMime( + { "text/richtext", + "application/x-openoffice-html-simple;windows_formatname=\"HTML Format\"" }); + uno::Reference<datatransfer::XTransferable> xData(new TestTransferable(aContent, aMime)); + + // When trying to paste HTML: + aEditEngine.InsertText(xData, OUString(), rDoc.GetEndPaM(), true); + + // Then make sure the text gets pasted: + // expected "abc" + // wrong: www.libreoffice.org + // i.e. HTML is preferred over HTML. + CPPUNIT_ASSERT_EQUAL(OUString("abc"), rDoc.GetParaAsString(static_cast<sal_Int32>(0))); +} void Test::testMultiParaSelCopyPaste() { // Create EditEngine's instance - EditEngine aEditEngine( mpItemPool.get() ); + EditEngine aEditEngine(mpItemPool.get()); // Get EditDoc for current EditEngine's instance - EditDoc &rDoc = aEditEngine.GetEditDoc(); + EditDoc& rDoc = aEditEngine.GetEditDoc(); // Initially no text should be there - CPPUNIT_ASSERT_EQUAL( sal_Int32(0), rDoc.GetTextLen() ); - CPPUNIT_ASSERT_EQUAL( OUString(), rDoc.GetParaAsString(sal_Int32(0)) ); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), rDoc.GetTextLen()); + CPPUNIT_ASSERT_EQUAL(OUString(), rDoc.GetParaAsString(sal_Int32(0))); // Insert initial text OUString aFirstPara = u"This is first paragraph"_ustr; @@ -830,16 +924,17 @@ void Test::testMultiParaSelCopyPaste() sal_Int32 aCopyTextLen = aCopyText.getLength(); // Assert changes - CPPUNIT_ASSERT_EQUAL( aTextLen, rDoc.GetTextLen() ); - CPPUNIT_ASSERT_EQUAL( aFirstPara, rDoc.GetParaAsString(sal_Int32(0)) ); - CPPUNIT_ASSERT_EQUAL( aSecondPara, rDoc.GetParaAsString(sal_Int32(1)) ); - CPPUNIT_ASSERT_EQUAL( aThirdPara, rDoc.GetParaAsString(sal_Int32(2)) ); + CPPUNIT_ASSERT_EQUAL(aTextLen, rDoc.GetTextLen()); + CPPUNIT_ASSERT_EQUAL(aFirstPara, rDoc.GetParaAsString(sal_Int32(0))); + CPPUNIT_ASSERT_EQUAL(aSecondPara, rDoc.GetParaAsString(sal_Int32(1))); + CPPUNIT_ASSERT_EQUAL(aThirdPara, rDoc.GetParaAsString(sal_Int32(2))); // Copy initial text using legacy format - uno::Reference< datatransfer::XTransferable > xData = aEditEngine.CreateTransferable( ESelection(0,8,1,14) ); + uno::Reference<datatransfer::XTransferable> xData + = aEditEngine.CreateTransferable(ESelection(0, 8, 1, 14)); // Paste text at the end - aEditEngine.InsertText( xData, OUString(), rDoc.GetEndPaM(), true ); + aEditEngine.InsertText(xData, OUString(), rDoc.GetEndPaM(), true); // Assert changes OUString aThirdParaAfterCopyPaste = aThirdPara + "first paragraph"; @@ -853,50 +948,51 @@ void Test::testMultiParaSelCopyPaste() void Test::testTabsCopyPaste() { // Create EditEngine's instance - EditEngine aEditEngine( mpItemPool.get() ); + EditEngine aEditEngine(mpItemPool.get()); // Get EditDoc for current EditEngine's instance - EditDoc &rDoc = aEditEngine.GetEditDoc(); + EditDoc& rDoc = aEditEngine.GetEditDoc(); // New instance must be empty - no initial text - CPPUNIT_ASSERT_EQUAL( sal_Int32(0), rDoc.GetTextLen() ); - CPPUNIT_ASSERT_EQUAL( OUString(), rDoc.GetParaAsString(sal_Int32(0)) ); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), rDoc.GetTextLen()); + CPPUNIT_ASSERT_EQUAL(OUString(), rDoc.GetParaAsString(sal_Int32(0))); // Get corresponding Item for inserting tabs in the text - SfxVoidItem aTab( EE_FEATURE_TAB ); + SfxVoidItem aTab(EE_FEATURE_TAB); // Insert initial text OUString aParaText = u"sampletextfortestingtab"_ustr; // Positions Ref ......*6...............*23 sal_Int32 aTextLen = aParaText.getLength(); - aEditEngine.SetText( aParaText ); + aEditEngine.SetText(aParaText); // Assert changes - CPPUNIT_ASSERT_EQUAL( aTextLen, rDoc.GetTextLen() ); - CPPUNIT_ASSERT_EQUAL( aParaText, rDoc.GetParaAsString(sal_Int32(0)) ); + CPPUNIT_ASSERT_EQUAL(aTextLen, rDoc.GetTextLen()); + CPPUNIT_ASSERT_EQUAL(aParaText, rDoc.GetParaAsString(sal_Int32(0))); // Insert tab 1 at desired position - ContentNode *pNode = rDoc.GetObject(0); - EditSelection aSel1( EditPaM(pNode, 6), EditPaM(pNode, 6) ); - aEditEngine.InsertFeature( aSel1, aTab ); + ContentNode* pNode = rDoc.GetObject(0); + EditSelection aSel1(EditPaM(pNode, 6), EditPaM(pNode, 6)); + aEditEngine.InsertFeature(aSel1, aTab); // Assert changes CPPUNIT_ASSERT_EQUAL( aTextLen + 1, rDoc.GetTextLen() ); CPPUNIT_ASSERT_EQUAL( u"sample\ttextfortestingtab"_ustr, rDoc.GetParaAsString(sal_Int32(0)) ); // Insert tab 2 at desired position - EditSelection aSel2( EditPaM(pNode, 23+1), EditPaM(pNode, 23+1) ); - aEditEngine.InsertFeature( aSel2, aTab ); + EditSelection aSel2(EditPaM(pNode, 23 + 1), EditPaM(pNode, 23 + 1)); + aEditEngine.InsertFeature(aSel2, aTab); // Assert changes CPPUNIT_ASSERT_EQUAL( aTextLen + 2, rDoc.GetTextLen() ); CPPUNIT_ASSERT_EQUAL( u"sample\ttextfortestingtab\t"_ustr, rDoc.GetParaAsString(sal_Int32(0)) ); // Copy text using legacy format - uno::Reference< datatransfer::XTransferable > xData = aEditEngine.CreateTransferable( ESelection(0,6,0,aTextLen+2) ); + uno::Reference<datatransfer::XTransferable> xData + = aEditEngine.CreateTransferable(ESelection(0, 6, 0, aTextLen + 2)); // Paste text at the end - aEditEngine.InsertText( xData, OUString(), rDoc.GetEndPaM(), true ); + aEditEngine.InsertText(xData, OUString(), rDoc.GetEndPaM(), true); // Assert changes CPPUNIT_ASSERT_EQUAL( aTextLen + aTextLen - 6 + 4, rDoc.GetTextLen() ); @@ -906,9 +1002,14 @@ void Test::testTabsCopyPaste() class UrlEditEngine : public EditEngine { public: - explicit UrlEditEngine(SfxItemPool *pPool) : EditEngine(pPool) {} + explicit UrlEditEngine(SfxItemPool* pPool) + : EditEngine(pPool) + { + } - virtual OUString CalcFieldValue( const SvxFieldItem&, sal_Int32, sal_Int32, std::optional<Color>&, std::optional<Color>&, std::optional<FontLineStyle>& ) override + virtual OUString CalcFieldValue(const SvxFieldItem&, sal_Int32, sal_Int32, + std::optional<Color>&, std::optional<Color>&, + std::optional<FontLineStyle>&) override { return u"jim@bob.com"_ustr; // a sophisticated view of value: } @@ -919,14 +1020,14 @@ public: void Test::testHyperlinkSearch() { UrlEditEngine aEngine(mpItemPool.get()); - EditDoc &rDoc = aEngine.GetEditDoc(); + EditDoc& rDoc = aEngine.GetEditDoc(); OUString aSampleText = u"Please write email to . if you find a fish(not a dog)."_ustr; aEngine.SetText(aSampleText); CPPUNIT_ASSERT_EQUAL_MESSAGE("set text", aSampleText, rDoc.GetParaAsString(sal_Int32(0))); - ContentNode *pNode = rDoc.GetObject(0); + ContentNode* pNode = rDoc.GetObject(0); EditSelection aSel(EditPaM(pNode, 22), EditPaM(pNode, 22)); SvxURLField aURLField(u"mailto:///jim@bob.com"_ustr, u"jim@bob.com"_ustr, SvxURLFormat::Repr); @@ -940,37 +1041,33 @@ void Test::testHyperlinkSearch() CPPUNIT_ASSERT_EQUAL_MESSAGE("wrong length", aContent.getLength(), rDoc.GetTextLen()); // Check expansion and positioning re-work - CPPUNIT_ASSERT_EQUAL_MESSAGE("wrong length", aContent.getLength(), - pNode->GetExpandedLen()); + CPPUNIT_ASSERT_EQUAL_MESSAGE("wrong length", aContent.getLength(), pNode->GetExpandedLen()); for (sal_Int32 n = 0; n < aContent.getLength(); n++) { sal_Int32 nStart = n, nEnd = n; - pNode->UnExpandPositions(nStart,nEnd); + pNode->UnExpandPositions(nStart, nEnd); CPPUNIT_ASSERT_MESSAGE("out of bound start", nStart < pNode->Len()); CPPUNIT_ASSERT_MESSAGE("out of bound end", nEnd <= pNode->Len()); } - static const struct { + static const struct + { sal_Int32 mnStart, mnEnd; sal_Int32 mnNewStart, mnNewEnd; - } aTrickyOnes[] = { - { 0, 1, /* -> */ 0, 1 }, - { 21, 25, /* -> */ 21, 23 }, // the field is really just one char - { 25, 27, /* -> */ 22, 23 }, - { 50, 56, /* -> */ 40, 46 } - }; + } aTrickyOnes[] = { { 0, 1, /* -> */ 0, 1 }, + { 21, 25, /* -> */ 21, 23 }, // the field is really just one char + { 25, 27, /* -> */ 22, 23 }, + { 50, 56, /* -> */ 40, 46 } }; for (size_t n = 0; n < SAL_N_ELEMENTS(aTrickyOnes); n++) { sal_Int32 nStart = aTrickyOnes[n].mnStart; sal_Int32 nEnd = aTrickyOnes[n].mnEnd; - pNode->UnExpandPositions(nStart,nEnd); - - CPPUNIT_ASSERT_EQUAL_MESSAGE( - OString("in row " + OString::number(n)).getStr(), - aTrickyOnes[n].mnNewStart, nStart); - CPPUNIT_ASSERT_EQUAL_MESSAGE( - OString("in row " + OString::number(n)).getStr(), - aTrickyOnes[n].mnNewEnd, nEnd); + pNode->UnExpandPositions(nStart, nEnd); + + CPPUNIT_ASSERT_EQUAL_MESSAGE(OString("in row " + OString::number(n)).getStr(), + aTrickyOnes[n].mnNewStart, nStart); + CPPUNIT_ASSERT_EQUAL_MESSAGE(OString("in row " + OString::number(n)).getStr(), + aTrickyOnes[n].mnNewEnd, nEnd); } SvxSearchItem aItem(1); //SID_SEARCH_ITEM); @@ -984,38 +1081,38 @@ void Test::testHyperlinkSearch() bool hasBold(const editeng::Section& rSecAttr) { - return std::any_of(rSecAttr.maAttributes.begin(), rSecAttr.maAttributes.end(), - [](const SfxPoolItem* p) { + return std::any_of( + rSecAttr.maAttributes.begin(), rSecAttr.maAttributes.end(), [](const SfxPoolItem* p) { return p->Which() == EE_CHAR_WEIGHT - && static_cast<const SvxWeightItem*>(p)->GetWeight() == WEIGHT_BOLD; + && static_cast<const SvxWeightItem*>(p)->GetWeight() == WEIGHT_BOLD; }); } bool hasItalic(const editeng::Section& rSecAttr) { - return std::any_of(rSecAttr.maAttributes.begin(), rSecAttr.maAttributes.end(), - [](const SfxPoolItem* p) { + return std::any_of( + rSecAttr.maAttributes.begin(), rSecAttr.maAttributes.end(), [](const SfxPoolItem* p) { return p->Which() == EE_CHAR_ITALIC - && static_cast<const SvxPostureItem*>(p)->GetPosture() == ITALIC_NORMAL; + && static_cast<const SvxPostureItem*>(p)->GetPosture() == ITALIC_NORMAL; }); } void Test::testBoldItalicCopyPaste() { // Create EditEngine's instance - EditEngine aEditEngine( mpItemPool.get() ); + EditEngine aEditEngine(mpItemPool.get()); // Get EditDoc for current EditEngine's instance - EditDoc &rDoc = aEditEngine.GetEditDoc(); + EditDoc& rDoc = aEditEngine.GetEditDoc(); // New instance must be empty - no initial text - CPPUNIT_ASSERT_EQUAL( sal_Int32(0), rDoc.GetTextLen() ); - CPPUNIT_ASSERT_EQUAL( OUString(), rDoc.GetParaAsString(sal_Int32(0)) ); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), rDoc.GetTextLen()); + CPPUNIT_ASSERT_EQUAL(OUString(), rDoc.GetParaAsString(sal_Int32(0))); // Get corresponding ItemSet for inserting Bold/Italic text - std::unique_ptr<SfxItemSet> pSet( new SfxItemSet(aEditEngine.GetEmptyItemSet()) ); - SvxWeightItem aBold( WEIGHT_BOLD, EE_CHAR_WEIGHT ); - SvxPostureItem aItalic( ITALIC_NORMAL, EE_CHAR_ITALIC ); + std::unique_ptr<SfxItemSet> pSet(new SfxItemSet(aEditEngine.GetEmptyItemSet())); + SvxWeightItem aBold(WEIGHT_BOLD, EE_CHAR_WEIGHT); + SvxPostureItem aItalic(ITALIC_NORMAL, EE_CHAR_ITALIC); // Insert initial text OUString aParaText = u"boldeditengineitalic"_ustr; @@ -1023,268 +1120,272 @@ void Test::testBoldItalicCopyPaste() // Bold Ref ..[ BOLD ]...... // Italic Ref ........[ ITALIC ].. sal_Int32 aTextLen = aParaText.getLength(); - aEditEngine.SetText( aParaText ); + aEditEngine.SetText(aParaText); // Assert changes - text insertion - CPPUNIT_ASSERT_EQUAL( aTextLen, rDoc.GetTextLen() ); - CPPUNIT_ASSERT_EQUAL( aParaText, rDoc.GetParaAsString(sal_Int32(0)) ); + CPPUNIT_ASSERT_EQUAL(aTextLen, rDoc.GetTextLen()); + CPPUNIT_ASSERT_EQUAL(aParaText, rDoc.GetParaAsString(sal_Int32(0))); // Apply Bold to appropriate selection pSet->Put(aBold); - CPPUNIT_ASSERT_EQUAL( static_cast<sal_uInt16>(1), pSet->Count() ); - aEditEngine.QuickSetAttribs( *pSet, ESelection(0,2,0,14) ); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(1), pSet->Count()); + aEditEngine.QuickSetAttribs(*pSet, ESelection(0, 2, 0, 14)); // Assert changes - std::unique_ptr<EditTextObject> pEditText1( aEditEngine.CreateTextObject() ); + std::unique_ptr<EditTextObject> pEditText1(aEditEngine.CreateTextObject()); std::vector<editeng::Section> aAttrs1; - pEditText1->GetAllSections( aAttrs1 ); + pEditText1->GetAllSections(aAttrs1); // There should be 3 sections - woBold - wBold - woBold (w - with, wo - without) - CPPUNIT_ASSERT_EQUAL( size_t(3), aAttrs1.size() ); + CPPUNIT_ASSERT_EQUAL(size_t(3), aAttrs1.size()); - CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(aAttrs1[0].mnParagraph) ); - CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(aAttrs1[0].mnStart) ); - CPPUNIT_ASSERT_EQUAL( 2, static_cast<int>(aAttrs1[0].mnEnd) ); - CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(aAttrs1[0].maAttributes.size()) ); + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs1[0].mnParagraph)); + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs1[0].mnStart)); + CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(aAttrs1[0].mnEnd)); + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs1[0].maAttributes.size())); - CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(aAttrs1[1].mnParagraph) ); - CPPUNIT_ASSERT_EQUAL( 2, static_cast<int>(aAttrs1[1].mnStart) ); - CPPUNIT_ASSERT_EQUAL( 14, static_cast<int>(aAttrs1[1].mnEnd) ); - CPPUNIT_ASSERT_EQUAL( 1, static_cast<int>(aAttrs1[1].maAttributes.size()) ); - CPPUNIT_ASSERT_MESSAGE( "This section must be bold.", hasBold(aAttrs1[1]) ); + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs1[1].mnParagraph)); + CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(aAttrs1[1].mnStart)); + CPPUNIT_ASSERT_EQUAL(14, static_cast<int>(aAttrs1[1].mnEnd)); + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aAttrs1[1].maAttributes.size())); + CPPUNIT_ASSERT_MESSAGE("This section must be bold.", hasBold(aAttrs1[1])); - CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(aAttrs1[2].mnParagraph) ); - CPPUNIT_ASSERT_EQUAL( 14, static_cast<int>(aAttrs1[2].mnStart) ); - CPPUNIT_ASSERT_EQUAL( 20, static_cast<int>(aAttrs1[2].mnEnd) ); - CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(aAttrs1[2].maAttributes.size()) ); + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs1[2].mnParagraph)); + CPPUNIT_ASSERT_EQUAL(14, static_cast<int>(aAttrs1[2].mnStart)); + CPPUNIT_ASSERT_EQUAL(20, static_cast<int>(aAttrs1[2].mnEnd)); + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs1[2].maAttributes.size())); // Apply Italic to appropriate selection - pSet.reset( new SfxItemSet(aEditEngine.GetEmptyItemSet()) ); + pSet.reset(new SfxItemSet(aEditEngine.GetEmptyItemSet())); pSet->Put(aItalic); - CPPUNIT_ASSERT_EQUAL( static_cast<sal_uInt16>(1), pSet->Count() ); - aEditEngine.QuickSetAttribs( *pSet, ESelection(0,8,0,18) ); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(1), pSet->Count()); + aEditEngine.QuickSetAttribs(*pSet, ESelection(0, 8, 0, 18)); // Assert changes - std::unique_ptr<EditTextObject> pEditText2( aEditEngine.CreateTextObject() ); + std::unique_ptr<EditTextObject> pEditText2(aEditEngine.CreateTextObject()); std::vector<editeng::Section> aAttrs2; - pEditText2->GetAllSections( aAttrs2 ); + pEditText2->GetAllSections(aAttrs2); // There should be 5 sections - woBold&woItalic - wBold&woItalic - wBold&wItalic - woBold&wItalic - woBold&woItalic (w - with, wo - without) - CPPUNIT_ASSERT_EQUAL( size_t(5), aAttrs2.size() ); - - CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(aAttrs2[0].mnParagraph) ); - CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(aAttrs2[0].mnStart) ); - CPPUNIT_ASSERT_EQUAL( 2, static_cast<int>(aAttrs2[0].mnEnd) ); - CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(aAttrs2[0].maAttributes.size()) ); - - CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(aAttrs2[1].mnParagraph) ); - CPPUNIT_ASSERT_EQUAL( 2, static_cast<int>(aAttrs2[1].mnStart) ); - CPPUNIT_ASSERT_EQUAL( 8, static_cast<int>(aAttrs2[1].mnEnd) ); - CPPUNIT_ASSERT_EQUAL( 1, static_cast<int>(aAttrs2[1].maAttributes.size()) ); - CPPUNIT_ASSERT_MESSAGE( "This section must be bold.", hasBold(aAttrs2[1]) ); - - CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(aAttrs2[2].mnParagraph) ); - CPPUNIT_ASSERT_EQUAL( 8, static_cast<int>(aAttrs2[2].mnStart) ); - CPPUNIT_ASSERT_EQUAL( 14, static_cast<int>(aAttrs2[2].mnEnd) ); - CPPUNIT_ASSERT_EQUAL( 2, static_cast<int>(aAttrs2[2].maAttributes.size()) ); - CPPUNIT_ASSERT_MESSAGE( "This section must be bold and italic.", hasBold(aAttrs2[2]) ); - CPPUNIT_ASSERT_MESSAGE( "This section must be bold and italic.", hasItalic(aAttrs2[2]) ); - - CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(aAttrs2[3].mnParagraph) ); - CPPUNIT_ASSERT_EQUAL( 14, static_cast<int>(aAttrs2[3].mnStart) ); - CPPUNIT_ASSERT_EQUAL( 18, static_cast<int>(aAttrs2[3].mnEnd) ); - CPPUNIT_ASSERT_EQUAL( 1, static_cast<int>(aAttrs2[3].maAttributes.size()) ); - CPPUNIT_ASSERT_MESSAGE( "This section must be italic.", hasItalic(aAttrs2[3]) ); - - CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(aAttrs2[4].mnParagraph) ); - CPPUNIT_ASSERT_EQUAL( 18, static_cast<int>(aAttrs2[4].mnStart) ); - CPPUNIT_ASSERT_EQUAL( 20, static_cast<int>(aAttrs2[4].mnEnd) ); - CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(aAttrs2[4].maAttributes.size()) ); + CPPUNIT_ASSERT_EQUAL(size_t(5), aAttrs2.size()); + + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs2[0].mnParagraph)); + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs2[0].mnStart)); + CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(aAttrs2[0].mnEnd)); + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs2[0].maAttributes.size())); + + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs2[1].mnParagraph)); + CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(aAttrs2[1].mnStart)); + CPPUNIT_ASSERT_EQUAL(8, static_cast<int>(aAttrs2[1].mnEnd)); + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aAttrs2[1].maAttributes.size())); + CPPUNIT_ASSERT_MESSAGE("This section must be bold.", hasBold(aAttrs2[1])); + + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs2[2].mnParagraph)); + CPPUNIT_ASSERT_EQUAL(8, static_cast<int>(aAttrs2[2].mnStart)); + CPPUNIT_ASSERT_EQUAL(14, static_cast<int>(aAttrs2[2].mnEnd)); + CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(aAttrs2[2].maAttributes.size())); + CPPUNIT_ASSERT_MESSAGE("This section must be bold and italic.", hasBold(aAttrs2[2])); + CPPUNIT_ASSERT_MESSAGE("This section must be bold and italic.", hasItalic(aAttrs2[2])); + + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs2[3].mnParagraph)); + CPPUNIT_ASSERT_EQUAL(14, static_cast<int>(aAttrs2[3].mnStart)); + CPPUNIT_ASSERT_EQUAL(18, static_cast<int>(aAttrs2[3].mnEnd)); + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aAttrs2[3].maAttributes.size())); + CPPUNIT_ASSERT_MESSAGE("This section must be italic.", hasItalic(aAttrs2[3])); + + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs2[4].mnParagraph)); + CPPUNIT_ASSERT_EQUAL(18, static_cast<int>(aAttrs2[4].mnStart)); + CPPUNIT_ASSERT_EQUAL(20, static_cast<int>(aAttrs2[4].mnEnd)); + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs2[4].maAttributes.size())); // Copy text using legacy format - uno::Reference< datatransfer::XTransferable > xData = aEditEngine.CreateTransferable( ESelection(0,1,0,aTextLen-1) ); + uno::Reference<datatransfer::XTransferable> xData + = aEditEngine.CreateTransferable(ESelection(0, 1, 0, aTextLen - 1)); // Paste text at the end - aEditEngine.InsertText( xData, OUString(), rDoc.GetEndPaM(), true ); + aEditEngine.InsertText(xData, OUString(), rDoc.GetEndPaM(), true); // Assert changes - CPPUNIT_ASSERT_EQUAL( aTextLen + aTextLen - 2, rDoc.GetTextLen() ); - CPPUNIT_ASSERT_EQUAL( OUString(aParaText + "oldeditengineitali" ), rDoc.GetParaAsString(sal_Int32(0)) ); + CPPUNIT_ASSERT_EQUAL(aTextLen + aTextLen - 2, rDoc.GetTextLen()); + CPPUNIT_ASSERT_EQUAL(OUString(aParaText + "oldeditengineitali"), + rDoc.GetParaAsString(sal_Int32(0))); // Check updated text for appropriate Bold/Italics - std::unique_ptr<EditTextObject> pEditText3( aEditEngine.CreateTextObject() ); + std::unique_ptr<EditTextObject> pEditText3(aEditEngine.CreateTextObject()); std::vector<editeng::Section> aAttrs3; - pEditText3->GetAllSections( aAttrs3 ); + pEditText3->GetAllSections(aAttrs3); // There should be 9 sections - woBold&woItalic - wBold&woItalic - wBold&wItalic - woBold&wItalic - woBold&woItalic - wBold&woItalic // - wBold&wItalic - woBold&wItalic - woBold&woItalic(w - with, wo - without) - CPPUNIT_ASSERT_EQUAL( size_t(9), aAttrs3.size() ); - - CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(aAttrs3[0].mnParagraph) ); - CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(aAttrs3[0].mnStart) ); - CPPUNIT_ASSERT_EQUAL( 2, static_cast<int>(aAttrs3[0].mnEnd) ); - CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(aAttrs3[0].maAttributes.size()) ); - - CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(aAttrs3[1].mnParagraph) ); - CPPUNIT_ASSERT_EQUAL( 2, static_cast<int>(aAttrs3[1].mnStart) ); - CPPUNIT_ASSERT_EQUAL( 8, static_cast<int>(aAttrs3[1].mnEnd) ); - CPPUNIT_ASSERT_EQUAL( 1, static_cast<int>(aAttrs3[1].maAttributes.size()) ); - CPPUNIT_ASSERT_MESSAGE( "This section must be bold.", hasBold(aAttrs3[1]) ); - - CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(aAttrs3[2].mnParagraph) ); - CPPUNIT_ASSERT_EQUAL( 8, static_cast<int>(aAttrs3[2].mnStart) ); - CPPUNIT_ASSERT_EQUAL( 14, static_cast<int>(aAttrs3[2].mnEnd) ); - CPPUNIT_ASSERT_EQUAL( 2, static_cast<int>(aAttrs3[2].maAttributes.size()) ); - CPPUNIT_ASSERT_MESSAGE( "This section must be bold and italic.", hasBold(aAttrs3[2]) ); - CPPUNIT_ASSERT_MESSAGE( "This section must be bold and italic.", hasItalic(aAttrs3[2]) ); - - CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(aAttrs3[3].mnParagraph) ); - CPPUNIT_ASSERT_EQUAL( 14, static_cast<int>(aAttrs3[3].mnStart) ); - CPPUNIT_ASSERT_EQUAL( 18, static_cast<int>(aAttrs3[3].mnEnd) ); - CPPUNIT_ASSERT_EQUAL( 1, static_cast<int>(aAttrs3[3].maAttributes.size()) ); - CPPUNIT_ASSERT_MESSAGE( "This section must be italic.", hasItalic(aAttrs3[3]) ); - - CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(aAttrs3[4].mnParagraph) ); - CPPUNIT_ASSERT_EQUAL( 18, static_cast<int>(aAttrs3[4].mnStart) ); - CPPUNIT_ASSERT_EQUAL( 21, static_cast<int>(aAttrs3[4].mnEnd) ); - CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(aAttrs3[4].maAttributes.size()) ); - - CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(aAttrs3[5].mnParagraph) ); - CPPUNIT_ASSERT_EQUAL( 21, static_cast<int>(aAttrs3[5].mnStart) ); - CPPUNIT_ASSERT_EQUAL( 27, static_cast<int>(aAttrs3[5].mnEnd) ); - CPPUNIT_ASSERT_EQUAL( 1, static_cast<int>(aAttrs3[5].maAttributes.size()) ); - CPPUNIT_ASSERT_MESSAGE( "This section must be bold.", hasBold(aAttrs3[5]) ); - - CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(aAttrs3[6].mnParagraph) ); - CPPUNIT_ASSERT_EQUAL( 27, static_cast<int>(aAttrs3[6].mnStart) ); - CPPUNIT_ASSERT_EQUAL( 33, static_cast<int>(aAttrs3[6].mnEnd) ); - CPPUNIT_ASSERT_EQUAL( 2, static_cast<int>(aAttrs3[6].maAttributes.size()) ); - CPPUNIT_ASSERT_MESSAGE( "This section must be bold and italic.", hasBold(aAttrs3[6]) ); - CPPUNIT_ASSERT_MESSAGE( "This section must be bold and italic.", hasItalic(aAttrs3[6]) ); - - CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(aAttrs3[7].mnParagraph) ); - CPPUNIT_ASSERT_EQUAL( 33, static_cast<int>(aAttrs3[7].mnStart) ); - CPPUNIT_ASSERT_EQUAL( 37, static_cast<int>(aAttrs3[7].mnEnd) ); - CPPUNIT_ASSERT_EQUAL( 1, static_cast<int>(aAttrs3[7].maAttributes.size()) ); - CPPUNIT_ASSERT_MESSAGE( "This section must be italic.", hasItalic(aAttrs3[7]) ); - - CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(aAttrs3[8].mnParagraph) ); - CPPUNIT_ASSERT_EQUAL( 37, static_cast<int>(aAttrs3[8].mnStart) ); - CPPUNIT_ASSERT_EQUAL( 38, static_cast<int>(aAttrs3[8].mnEnd) ); - CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(aAttrs3[8].maAttributes.size()) ); + CPPUNIT_ASSERT_EQUAL(size_t(9), aAttrs3.size()); + + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs3[0].mnParagraph)); + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs3[0].mnStart)); + CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(aAttrs3[0].mnEnd)); + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs3[0].maAttributes.size())); + + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs3[1].mnParagraph)); + CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(aAttrs3[1].mnStart)); + CPPUNIT_ASSERT_EQUAL(8, static_cast<int>(aAttrs3[1].mnEnd)); + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aAttrs3[1].maAttributes.size())); + CPPUNIT_ASSERT_MESSAGE("This section must be bold.", hasBold(aAttrs3[1])); + + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs3[2].mnParagraph)); + CPPUNIT_ASSERT_EQUAL(8, static_cast<int>(aAttrs3[2].mnStart)); + CPPUNIT_ASSERT_EQUAL(14, static_cast<int>(aAttrs3[2].mnEnd)); + CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(aAttrs3[2].maAttributes.size())); + CPPUNIT_ASSERT_MESSAGE("This section must be bold and italic.", hasBold(aAttrs3[2])); + CPPUNIT_ASSERT_MESSAGE("This section must be bold and italic.", hasItalic(aAttrs3[2])); + + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs3[3].mnParagraph)); + CPPUNIT_ASSERT_EQUAL(14, static_cast<int>(aAttrs3[3].mnStart)); + CPPUNIT_ASSERT_EQUAL(18, static_cast<int>(aAttrs3[3].mnEnd)); + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aAttrs3[3].maAttributes.size())); + CPPUNIT_ASSERT_MESSAGE("This section must be italic.", hasItalic(aAttrs3[3])); + + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs3[4].mnParagraph)); + CPPUNIT_ASSERT_EQUAL(18, static_cast<int>(aAttrs3[4].mnStart)); + CPPUNIT_ASSERT_EQUAL(21, static_cast<int>(aAttrs3[4].mnEnd)); + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs3[4].maAttributes.size())); + + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs3[5].mnParagraph)); + CPPUNIT_ASSERT_EQUAL(21, static_cast<int>(aAttrs3[5].mnStart)); + CPPUNIT_ASSERT_EQUAL(27, static_cast<int>(aAttrs3[5].mnEnd)); + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aAttrs3[5].maAttributes.size())); + CPPUNIT_ASSERT_MESSAGE("This section must be bold.", hasBold(aAttrs3[5])); + + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs3[6].mnParagraph)); + CPPUNIT_ASSERT_EQUAL(27, static_cast<int>(aAttrs3[6].mnStart)); + CPPUNIT_ASSERT_EQUAL(33, static_cast<int>(aAttrs3[6].mnEnd)); + CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(aAttrs3[6].maAttributes.size())); + CPPUNIT_ASSERT_MESSAGE("This section must be bold and italic.", hasBold(aAttrs3[6])); + CPPUNIT_ASSERT_MESSAGE("This section must be bold and italic.", hasItalic(aAttrs3[6])); + + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs3[7].mnParagraph)); + CPPUNIT_ASSERT_EQUAL(33, static_cast<int>(aAttrs3[7].mnStart)); + CPPUNIT_ASSERT_EQUAL(37, static_cast<int>(aAttrs3[7].mnEnd)); + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aAttrs3[7].maAttributes.size())); + CPPUNIT_ASSERT_MESSAGE("This section must be italic.", hasItalic(aAttrs3[7])); + + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs3[8].mnParagraph)); + CPPUNIT_ASSERT_EQUAL(37, static_cast<int>(aAttrs3[8].mnStart)); + CPPUNIT_ASSERT_EQUAL(38, static_cast<int>(aAttrs3[8].mnEnd)); + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs3[8].maAttributes.size())); } // Auxiliary function to test Underline text Copy/Paste using Legacy Format bool hasUnderline(const editeng::Section& rSecAttr) { - return std::any_of(rSecAttr.maAttributes.begin(), rSecAttr.maAttributes.end(), - [](const SfxPoolItem* p) { + return std::any_of( + rSecAttr.maAttributes.begin(), rSecAttr.maAttributes.end(), [](const SfxPoolItem* p) { return p->Which() == EE_CHAR_UNDERLINE - && static_cast<const SvxUnderlineItem*>(p)->GetLineStyle() == LINESTYLE_SINGLE; + && static_cast<const SvxUnderlineItem*>(p)->GetLineStyle() == LINESTYLE_SINGLE; }); } void Test::testUnderlineCopyPaste() { // Create EditEngine's instance - EditEngine aEditEngine( mpItemPool.get() ); + EditEngine aEditEngine(mpItemPool.get()); // Get EditDoc for current EditEngine's instance - EditDoc &rDoc = aEditEngine.GetEditDoc(); + EditDoc& rDoc = aEditEngine.GetEditDoc(); // New instance must be empty - no initial text - CPPUNIT_ASSERT_EQUAL( sal_Int32(0), rDoc.GetTextLen() ); - CPPUNIT_ASSERT_EQUAL( OUString(), rDoc.GetParaAsString(sal_Int32(0)) ); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), rDoc.GetTextLen()); + CPPUNIT_ASSERT_EQUAL(OUString(), rDoc.GetParaAsString(sal_Int32(0))); // Get corresponding ItemSet for inserting Underline text - std::unique_ptr<SfxItemSet> pSet( new SfxItemSet(aEditEngine.GetEmptyItemSet()) ); - SvxUnderlineItem aULine( LINESTYLE_SINGLE, EE_CHAR_UNDERLINE ); + std::unique_ptr<SfxItemSet> pSet(new SfxItemSet(aEditEngine.GetEmptyItemSet())); + SvxUnderlineItem aULine(LINESTYLE_SINGLE, EE_CHAR_UNDERLINE); // Insert initial text OUString aParaText = u"sampletextforunderline"_ustr; // Positions Ref ......*6.........*17.. // Underline Ref ......[UNDERLINE ].... sal_Int32 aTextLen = aParaText.getLength(); - aEditEngine.SetText( aParaText ); + aEditEngine.SetText(aParaText); // Apply Underline style - pSet->Put( aULine ); - CPPUNIT_ASSERT_EQUAL( static_cast<sal_uInt16>(1), pSet->Count() ); - aEditEngine.QuickSetAttribs( *pSet, ESelection(0,6,0,18) ); + pSet->Put(aULine); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(1), pSet->Count()); + aEditEngine.QuickSetAttribs(*pSet, ESelection(0, 6, 0, 18)); // Assert changes - std::unique_ptr<EditTextObject> pEditText1( aEditEngine.CreateTextObject() ); + std::unique_ptr<EditTextObject> pEditText1(aEditEngine.CreateTextObject()); std::vector<editeng::Section> aAttrs1; - pEditText1->GetAllSections( aAttrs1 ); + pEditText1->GetAllSections(aAttrs1); // There should be 3 sections - woUnderline - wUnderline - woUnderline (w - with, wo - without) - CPPUNIT_ASSERT_EQUAL( size_t(3), aAttrs1.size() ); + CPPUNIT_ASSERT_EQUAL(size_t(3), aAttrs1.size()); - CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(aAttrs1[0].mnParagraph) ); - CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(aAttrs1[0].mnStart) ); - CPPUNIT_ASSERT_EQUAL( 6, static_cast<int>(aAttrs1[0].mnEnd) ); - CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(aAttrs1[0].maAttributes.size()) ); + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs1[0].mnParagraph)); + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs1[0].mnStart)); + CPPUNIT_ASSERT_EQUAL(6, static_cast<int>(aAttrs1[0].mnEnd)); + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs1[0].maAttributes.size())); - CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(aAttrs1[1].mnParagraph) ); - CPPUNIT_ASSERT_EQUAL( 6, static_cast<int>(aAttrs1[1].mnStart) ); - CPPUNIT_ASSERT_EQUAL( 18, static_cast<int>(aAttrs1[1].mnEnd) ); - CPPUNIT_ASSERT_EQUAL( 1, static_cast<int>(aAttrs1[1].maAttributes.size()) ); - CPPUNIT_ASSERT_MESSAGE( "This section must be underlined.", hasUnderline(aAttrs1[1]) ); + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs1[1].mnParagraph)); + CPPUNIT_ASSERT_EQUAL(6, static_cast<int>(aAttrs1[1].mnStart)); + CPPUNIT_ASSERT_EQUAL(18, static_cast<int>(aAttrs1[1].mnEnd)); + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aAttrs1[1].maAttributes.size())); + CPPUNIT_ASSERT_MESSAGE("This section must be underlined.", hasUnderline(aAttrs1[1])); - CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(aAttrs1[2].mnParagraph) ); - CPPUNIT_ASSERT_EQUAL( 18, static_cast<int>(aAttrs1[2].mnStart) ); - CPPUNIT_ASSERT_EQUAL( 22, static_cast<int>(aAttrs1[2].mnEnd) ); - CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(aAttrs1[2].maAttributes.size()) ); + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs1[2].mnParagraph)); + CPPUNIT_ASSERT_EQUAL(18, static_cast<int>(aAttrs1[2].mnStart)); + CPPUNIT_ASSERT_EQUAL(22, static_cast<int>(aAttrs1[2].mnEnd)); + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs1[2].maAttributes.size())); // Copy text using legacy format - uno::Reference< datatransfer::XTransferable > xData = aEditEngine.CreateTransferable( ESelection(0,6,0,aTextLen-4) ); + uno::Reference<datatransfer::XTransferable> xData + = aEditEngine.CreateTransferable(ESelection(0, 6, 0, aTextLen - 4)); // Paste text at the end - aEditEngine.InsertText( xData, OUString(), rDoc.GetEndPaM(), true ); + aEditEngine.InsertText(xData, OUString(), rDoc.GetEndPaM(), true); // Assert changes - CPPUNIT_ASSERT_EQUAL( static_cast<sal_Int32>(aTextLen + strlen("textforunder")), rDoc.GetTextLen() ); - CPPUNIT_ASSERT_EQUAL( OUString(aParaText + "textforunder" ), rDoc.GetParaAsString(sal_Int32(0)) ); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(aTextLen + strlen("textforunder")), + rDoc.GetTextLen()); + CPPUNIT_ASSERT_EQUAL(OUString(aParaText + "textforunder"), rDoc.GetParaAsString(sal_Int32(0))); // Check updated text for appropriate Underline - std::unique_ptr<EditTextObject> pEditText2( aEditEngine.CreateTextObject() ); + std::unique_ptr<EditTextObject> pEditText2(aEditEngine.CreateTextObject()); std::vector<editeng::Section> aAttrs2; - pEditText2->GetAllSections( aAttrs2 ); + pEditText2->GetAllSections(aAttrs2); // There should be 4 sections - woUnderline - wUnderline - woUnderline - wUnderline (w - with, wo - without) - CPPUNIT_ASSERT_EQUAL( size_t(4), aAttrs2.size() ); - - CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(aAttrs2[0].mnParagraph) ); - CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(aAttrs2[0].mnStart) ); - CPPUNIT_ASSERT_EQUAL( 6, static_cast<int>(aAttrs2[0].mnEnd) ); - CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(aAttrs2[0].maAttributes.size()) ); - - CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(aAttrs2[1].mnParagraph) ); - CPPUNIT_ASSERT_EQUAL( 6, static_cast<int>(aAttrs2[1].mnStart) ); - CPPUNIT_ASSERT_EQUAL( 18, static_cast<int>(aAttrs2[1].mnEnd) ); - CPPUNIT_ASSERT_EQUAL( 1, static_cast<int>(aAttrs2[1].maAttributes.size()) ); - CPPUNIT_ASSERT_MESSAGE( "This section must be underlined.", hasUnderline(aAttrs2[1]) ); - - CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(aAttrs2[2].mnParagraph) ); - CPPUNIT_ASSERT_EQUAL( 18, static_cast<int>(aAttrs2[2].mnStart) ); - CPPUNIT_ASSERT_EQUAL( 22, static_cast<int>(aAttrs2[2].mnEnd) ); - CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(aAttrs2[2].maAttributes.size()) ); - - CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(aAttrs2[3].mnParagraph) ); - CPPUNIT_ASSERT_EQUAL( 22, static_cast<int>(aAttrs2[3].mnStart) ); - CPPUNIT_ASSERT_EQUAL( 34, static_cast<int>(aAttrs2[3].mnEnd) ); - CPPUNIT_ASSERT_EQUAL( 1, static_cast<int>(aAttrs2[3].maAttributes.size()) ); - CPPUNIT_ASSERT_MESSAGE( "This section must be underlined.", hasUnderline(aAttrs2[3]) ); + CPPUNIT_ASSERT_EQUAL(size_t(4), aAttrs2.size()); + + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs2[0].mnParagraph)); + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs2[0].mnStart)); + CPPUNIT_ASSERT_EQUAL(6, static_cast<int>(aAttrs2[0].mnEnd)); + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs2[0].maAttributes.size())); + + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs2[1].mnParagraph)); + CPPUNIT_ASSERT_EQUAL(6, static_cast<int>(aAttrs2[1].mnStart)); + CPPUNIT_ASSERT_EQUAL(18, static_cast<int>(aAttrs2[1].mnEnd)); + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aAttrs2[1].maAttributes.size())); + CPPUNIT_ASSERT_MESSAGE("This section must be underlined.", hasUnderline(aAttrs2[1])); + + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs2[2].mnParagraph)); + CPPUNIT_ASSERT_EQUAL(18, static_cast<int>(aAttrs2[2].mnStart)); + CPPUNIT_ASSERT_EQUAL(22, static_cast<int>(aAttrs2[2].mnEnd)); + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs2[2].maAttributes.size())); + + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs2[3].mnParagraph)); + CPPUNIT_ASSERT_EQUAL(22, static_cast<int>(aAttrs2[3].mnStart)); + CPPUNIT_ASSERT_EQUAL(34, static_cast<int>(aAttrs2[3].mnEnd)); + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aAttrs2[3].maAttributes.size())); + CPPUNIT_ASSERT_MESSAGE("This section must be underlined.", hasUnderline(aAttrs2[3])); } void Test::testMultiParaCopyPaste() { // Create EditEngine's instance - EditEngine aEditEngine( mpItemPool.get() ); + EditEngine aEditEngine(mpItemPool.get()); // Get EditDoc for current EditEngine's instance - EditDoc &rDoc = aEditEngine.GetEditDoc(); + EditDoc& rDoc = aEditEngine.GetEditDoc(); // Initially no text should be there - CPPUNIT_ASSERT_EQUAL( sal_Int32(0), rDoc.GetTextLen() ); - CPPUNIT_ASSERT_EQUAL( OUString(), rDoc.GetParaAsString(sal_Int32(0)) ); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), rDoc.GetTextLen()); + CPPUNIT_ASSERT_EQUAL(OUString(), rDoc.GetParaAsString(sal_Int32(0))); // Insert initial text OUString aFirstPara = u"This is first paragraph"_ustr; @@ -1292,46 +1393,47 @@ void Test::testMultiParaCopyPaste() OUString aThirdPara = u"This is third paragraph"_ustr; OUString aText = aFirstPara + "\n" + aSecondPara + "\n" + aThirdPara; sal_Int32 aTextLen = aFirstPara.getLength() + aSecondPara.getLength() + aThirdPara.getLength(); - aEditEngine.SetText( aText ); + aEditEngine.SetText(aText); sal_Int32 aCopyTextLen = aFirstPara.getLength() + aSecondPara.getLength(); // Assert changes - CPPUNIT_ASSERT_EQUAL( aTextLen, rDoc.GetTextLen() ); - CPPUNIT_ASSERT_EQUAL( aFirstPara, rDoc.GetParaAsString(sal_Int32(0)) ); - CPPUNIT_ASSERT_EQUAL( aSecondPara, rDoc.GetParaAsString(sal_Int32(1)) ); - CPPUNIT_ASSERT_EQUAL( aThirdPara, rDoc.GetParaAsString(sal_Int32(2)) ); + CPPUNIT_ASSERT_EQUAL(aTextLen, rDoc.GetTextLen()); + CPPUNIT_ASSERT_EQUAL(aFirstPara, rDoc.GetParaAsString(sal_Int32(0))); + CPPUNIT_ASSERT_EQUAL(aSecondPara, rDoc.GetParaAsString(sal_Int32(1))); + CPPUNIT_ASSERT_EQUAL(aThirdPara, rDoc.GetParaAsString(sal_Int32(2))); // Copy initial text using legacy format - uno::Reference< datatransfer::XTransferable > xData = aEditEngine.CreateTransferable( ESelection(0,0,1,aSecondPara.getLength()) ); + uno::Reference<datatransfer::XTransferable> xData + = aEditEngine.CreateTransferable(ESelection(0, 0, 1, aSecondPara.getLength())); // Paste text at the end - aEditEngine.InsertText( xData, OUString(), rDoc.GetEndPaM(), true ); + aEditEngine.InsertText(xData, OUString(), rDoc.GetEndPaM(), true); // Assert changes OUString aThirdParaAfterCopyPaste = aThirdPara + aFirstPara; - CPPUNIT_ASSERT_EQUAL( aTextLen + aCopyTextLen, rDoc.GetTextLen() ); - CPPUNIT_ASSERT_EQUAL( aFirstPara, rDoc.GetParaAsString(sal_Int32(0)) ); - CPPUNIT_ASSERT_EQUAL( aSecondPara, rDoc.GetParaAsString(sal_Int32(1)) ); - CPPUNIT_ASSERT_EQUAL( aThirdParaAfterCopyPaste, rDoc.GetParaAsString(sal_Int32(2)) ); - CPPUNIT_ASSERT_EQUAL( aSecondPara, rDoc.GetParaAsString(sal_Int32(3)) ); + CPPUNIT_ASSERT_EQUAL(aTextLen + aCopyTextLen, rDoc.GetTextLen()); + CPPUNIT_ASSERT_EQUAL(aFirstPara, rDoc.GetParaAsString(sal_Int32(0))); + CPPUNIT_ASSERT_EQUAL(aSecondPara, rDoc.GetParaAsString(sal_Int32(1))); + CPPUNIT_ASSERT_EQUAL(aThirdParaAfterCopyPaste, rDoc.GetParaAsString(sal_Int32(2))); + CPPUNIT_ASSERT_EQUAL(aSecondPara, rDoc.GetParaAsString(sal_Int32(3))); } void Test::testParaBoldItalicCopyPaste() { // Create EditEngine's instance - EditEngine aEditEngine( mpItemPool.get() ); + EditEngine aEditEngine(mpItemPool.get()); // Get EditDoc for current EditEngine's instance - EditDoc &rDoc = aEditEngine.GetEditDoc(); + EditDoc& rDoc = aEditEngine.GetEditDoc(); // Initially no text should be there - CPPUNIT_ASSERT_EQUAL( sal_Int32(0), rDoc.GetTextLen() ); - CPPUNIT_ASSERT_EQUAL( OUString(), rDoc.GetParaAsString(sal_Int32(0)) ); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), rDoc.GetTextLen()); + CPPUNIT_ASSERT_EQUAL(OUString(), rDoc.GetParaAsString(sal_Int32(0))); // Get corresponding ItemSet for inserting Bold/Italic text - std::unique_ptr<SfxItemSet> pSet( new SfxItemSet(aEditEngine.GetEmptyItemSet()) ); - SvxWeightItem aBold( WEIGHT_BOLD, EE_CHAR_WEIGHT ); - SvxPostureItem aItalic( ITALIC_NORMAL, EE_CHAR_ITALIC ); + std::unique_ptr<SfxItemSet> pSet(new SfxItemSet(aEditEngine.GetEmptyItemSet())); + SvxWeightItem aBold(WEIGHT_BOLD, EE_CHAR_WEIGHT); + SvxPostureItem aItalic(ITALIC_NORMAL, EE_CHAR_ITALIC); // Insert initial text OUString aFirstPara = u"This is first paragraph"_ustr; @@ -1352,132 +1454,133 @@ void Test::testParaBoldItalicCopyPaste() sal_Int32 aCopyTextLen = aCopyText.getLength(); // Assert changes - text insertion - CPPUNIT_ASSERT_EQUAL( aTextLen, rDoc.GetTextLen() ); - CPPUNIT_ASSERT_EQUAL( aFirstPara, rDoc.GetParaAsString(sal_Int32(0)) ); - CPPUNIT_ASSERT_EQUAL( aSecondPara, rDoc.GetParaAsString(sal_Int32(1)) ); - CPPUNIT_ASSERT_EQUAL( aThirdPara, rDoc.GetParaAsString(sal_Int32(2)) ); + CPPUNIT_ASSERT_EQUAL(aTextLen, rDoc.GetTextLen()); + CPPUNIT_ASSERT_EQUAL(aFirstPara, rDoc.GetParaAsString(sal_Int32(0))); + CPPUNIT_ASSERT_EQUAL(aSecondPara, rDoc.GetParaAsString(sal_Int32(1))); + CPPUNIT_ASSERT_EQUAL(aThirdPara, rDoc.GetParaAsString(sal_Int32(2))); // Apply Bold to appropriate selections pSet->Put(aBold); - CPPUNIT_ASSERT_EQUAL( static_cast<sal_uInt16>(1), pSet->Count() ); - aEditEngine.QuickSetAttribs( *pSet, ESelection(0,5,0,18) ); - aEditEngine.QuickSetAttribs( *pSet, ESelection(1,5,1,19) ); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(1), pSet->Count()); + aEditEngine.QuickSetAttribs(*pSet, ESelection(0, 5, 0, 18)); + aEditEngine.QuickSetAttribs(*pSet, ESelection(1, 5, 1, 19)); // Assert changes - std::unique_ptr<EditTextObject> pEditText1( aEditEngine.CreateTextObject() ); + std::unique_ptr<EditTextObject> pEditText1(aEditEngine.CreateTextObject()); std::vector<editeng::Section> aAttrs1; - pEditText1->GetAllSections( aAttrs1 ); + pEditText1->GetAllSections(aAttrs1); // There should be 7 sections - woB - wB - woB -woB -wB -woB -woB (w - with, wo - without, B - Bold, I - Italic) - CPPUNIT_ASSERT_EQUAL( size_t(7), aAttrs1.size() ); - - CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(aAttrs1[0].mnParagraph) ); - CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(aAttrs1[0].mnStart) ); - CPPUNIT_ASSERT_EQUAL( 5, static_cast<int>(aAttrs1[0].mnEnd) ); - CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(aAttrs1[0].maAttributes.size()) ); - - CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(aAttrs1[1].mnParagraph) ); - CPPUNIT_ASSERT_EQUAL( 5, static_cast<int>(aAttrs1[1].mnStart) ); - CPPUNIT_ASSERT_EQUAL( 18, static_cast<int>(aAttrs1[1].mnEnd) ); - CPPUNIT_ASSERT_EQUAL( 1, static_cast<int>(aAttrs1[1].maAttributes.size()) ); - CPPUNIT_ASSERT_MESSAGE( "This section must be bold.", hasBold(aAttrs1[1]) ); - - CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(aAttrs1[2].mnParagraph) ); - CPPUNIT_ASSERT_EQUAL( 18, static_cast<int>(aAttrs1[2].mnStart) ); - CPPUNIT_ASSERT_EQUAL( 23, static_cast<int>(aAttrs1[2].mnEnd) ); - CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(aAttrs1[2].maAttributes.size()) ); - - CPPUNIT_ASSERT_EQUAL( 1, static_cast<int>(aAttrs1[3].mnParagraph) ); - CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(aAttrs1[3].mnStart) ); - CPPUNIT_ASSERT_EQUAL( 5, static_cast<int>(aAttrs1[3].mnEnd) ); - CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(aAttrs1[3].maAttributes.size()) ); - - CPPUNIT_ASSERT_EQUAL( 1, static_cast<int>(aAttrs1[4].mnParagraph) ); - CPPUNIT_ASSERT_EQUAL( 5, static_cast<int>(aAttrs1[4].mnStart) ); - CPPUNIT_ASSERT_EQUAL( 19, static_cast<int>(aAttrs1[4].mnEnd) ); - CPPUNIT_ASSERT_EQUAL( 1, static_cast<int>(aAttrs1[4].maAttributes.size()) ); - CPPUNIT_ASSERT_MESSAGE( "This section must be bold.", hasBold(aAttrs1[4]) ); - - CPPUNIT_ASSERT_EQUAL( 1, static_cast<int>(aAttrs1[5].mnParagraph) ); - CPPUNIT_ASSERT_EQUAL( 19, static_cast<int>(aAttrs1[5].mnStart) ); - CPPUNIT_ASSERT_EQUAL( 24, static_cast<int>(aAttrs1[5].mnEnd) ); - CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(aAttrs1[5].maAttributes.size()) ); - - CPPUNIT_ASSERT_EQUAL( 2, static_cast<int>(aAttrs1[6].mnParagraph) ); - CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(aAttrs1[6].mnStart) ); - CPPUNIT_ASSERT_EQUAL( 23, static_cast<int>(aAttrs1[6].mnEnd) ); - CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(aAttrs1[6].maAttributes.size()) ); + CPPUNIT_ASSERT_EQUAL(size_t(7), aAttrs1.size()); + + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs1[0].mnParagraph)); + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs1[0].mnStart)); + CPPUNIT_ASSERT_EQUAL(5, static_cast<int>(aAttrs1[0].mnEnd)); + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs1[0].maAttributes.size())); + + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs1[1].mnParagraph)); + CPPUNIT_ASSERT_EQUAL(5, static_cast<int>(aAttrs1[1].mnStart)); + CPPUNIT_ASSERT_EQUAL(18, static_cast<int>(aAttrs1[1].mnEnd)); + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aAttrs1[1].maAttributes.size())); + CPPUNIT_ASSERT_MESSAGE("This section must be bold.", hasBold(aAttrs1[1])); + + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs1[2].mnParagraph)); + CPPUNIT_ASSERT_EQUAL(18, static_cast<int>(aAttrs1[2].mnStart)); + CPPUNIT_ASSERT_EQUAL(23, static_cast<int>(aAttrs1[2].mnEnd)); + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs1[2].maAttributes.size())); + + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aAttrs1[3].mnParagraph)); + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs1[3].mnStart)); + CPPUNIT_ASSERT_EQUAL(5, static_cast<int>(aAttrs1[3].mnEnd)); + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs1[3].maAttributes.size())); + + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aAttrs1[4].mnParagraph)); + CPPUNIT_ASSERT_EQUAL(5, static_cast<int>(aAttrs1[4].mnStart)); + CPPUNIT_ASSERT_EQUAL(19, static_cast<int>(aAttrs1[4].mnEnd)); + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aAttrs1[4].maAttributes.size())); + CPPUNIT_ASSERT_MESSAGE("This section must be bold.", hasBold(aAttrs1[4])); + + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aAttrs1[5].mnParagraph)); + CPPUNIT_ASSERT_EQUAL(19, static_cast<int>(aAttrs1[5].mnStart)); + CPPUNIT_ASSERT_EQUAL(24, static_cast<int>(aAttrs1[5].mnEnd)); + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs1[5].maAttributes.size())); + + CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(aAttrs1[6].mnParagraph)); + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs1[6].mnStart)); + CPPUNIT_ASSERT_EQUAL(23, static_cast<int>(aAttrs1[6].mnEnd)); + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs1[6].maAttributes.size())); // Apply Italic to appropriate selection - pSet.reset( new SfxItemSet(aEditEngine.GetEmptyItemSet()) ); + pSet.reset(new SfxItemSet(aEditEngine.GetEmptyItemSet())); pSet->Put(aItalic); - CPPUNIT_ASSERT_EQUAL( static_cast<sal_uInt16>(1), pSet->Count() ); - aEditEngine.QuickSetAttribs( *pSet, ESelection(0,14,1,9) ); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(1), pSet->Count()); + aEditEngine.QuickSetAttribs(*pSet, ESelection(0, 14, 1, 9)); // Assert changes - std::unique_ptr<EditTextObject> pEditText2( aEditEngine.CreateTextObject() ); + std::unique_ptr<EditTextObject> pEditText2(aEditEngine.CreateTextObject()); std::vector<editeng::Section> aAttrs2; - pEditText2->GetAllSections( aAttrs2 ); + pEditText2->GetAllSections(aAttrs2); // There should be 9 sections - woB&woI - wB&woI - wB&wI -woB&wI - woB&wI - wB&wI - wB&woI - woB&woI - woB&woI (w - with, wo - without, B - Bold, I - Italic) - CPPUNIT_ASSERT_EQUAL( size_t(9), aAttrs2.size() ); - - CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(aAttrs2[0].mnParagraph) ); - CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(aAttrs2[0].mnStart) ); - CPPUNIT_ASSERT_EQUAL( 5, static_cast<int>(aAttrs2[0].mnEnd) ); - CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(aAttrs2[0].maAttributes.size()) ); - - CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(aAttrs2[1].mnParagraph) ); - CPPUNIT_ASSERT_EQUAL( 5, static_cast<int>(aAttrs2[1].mnStart) ); - CPPUNIT_ASSERT_EQUAL( 14, static_cast<int>(aAttrs2[1].mnEnd) ); - CPPUNIT_ASSERT_EQUAL( 1, static_cast<int>(aAttrs2[1].maAttributes.size()) ); - CPPUNIT_ASSERT_MESSAGE( "This section must be bold.", hasBold(aAttrs2[1]) ); - - CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(aAttrs2[2].mnParagraph) ); - CPPUNIT_ASSERT_EQUAL( 14, static_cast<int>(aAttrs2[2].mnStart) ); - CPPUNIT_ASSERT_EQUAL( 18, static_cast<int>(aAttrs2[2].mnEnd) ); - CPPUNIT_ASSERT_EQUAL( 2, static_cast<int>(aAttrs2[2].maAttributes.size()) ); - CPPUNIT_ASSERT_MESSAGE( "This section must be bold and italic.", hasBold(aAttrs2[2]) ); - CPPUNIT_ASSERT_MESSAGE( "This section must be bold and italic.", hasItalic(aAttrs2[2]) ); - - CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(aAttrs2[3].mnParagraph) ); - CPPUNIT_ASSERT_EQUAL( 18, static_cast<int>(aAttrs2[3].mnStart) ); - CPPUNIT_ASSERT_EQUAL( 23, static_cast<int>(aAttrs2[3].mnEnd) ); - CPPUNIT_ASSERT_EQUAL( 1, static_cast<int>(aAttrs2[3].maAttributes.size()) ); - CPPUNIT_ASSERT_MESSAGE( "This section must be italic.", hasItalic(aAttrs2[3]) ); - - CPPUNIT_ASSERT_EQUAL( 1, static_cast<int>(aAttrs2[4].mnParagraph) ); - CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(aAttrs2[4].mnStart) ); - CPPUNIT_ASSERT_EQUAL( 5, static_cast<int>(aAttrs2[4].mnEnd) ); - CPPUNIT_ASSERT_EQUAL( 1, static_cast<int>(aAttrs2[4].maAttributes.size()) ); - CPPUNIT_ASSERT_MESSAGE( "This section must be italic.", hasItalic(aAttrs2[4]) ); - - CPPUNIT_ASSERT_EQUAL( 1, static_cast<int>(aAttrs2[5].mnParagraph) ); - CPPUNIT_ASSERT_EQUAL( 5, static_cast<int>(aAttrs2[5].mnStart) ); - CPPUNIT_ASSERT_EQUAL( 9, static_cast<int>(aAttrs2[5].mnEnd) ); - CPPUNIT_ASSERT_EQUAL( 2, static_cast<int>(aAttrs2[5].maAttributes.size()) ); - CPPUNIT_ASSERT_MESSAGE( "This section must be bold and italic.", hasBold(aAttrs2[5]) ); - CPPUNIT_ASSERT_MESSAGE( "This section must be bold and italic.", hasItalic(aAttrs2[5]) ); - - CPPUNIT_ASSERT_EQUAL( 1, static_cast<int>(aAttrs2[6].mnParagraph) ); - CPPUNIT_ASSERT_EQUAL( 9, static_cast<int>(aAttrs2[6].mnStart) ); - CPPUNIT_ASSERT_EQUAL( 19, static_cast<int>(aAttrs2[6].mnEnd) ); - CPPUNIT_ASSERT_EQUAL( 1, static_cast<int>(aAttrs2[6].maAttributes.size()) ); - CPPUNIT_ASSERT_MESSAGE( "This section must be bold.", hasBold(aAttrs2[6]) ); - - CPPUNIT_ASSERT_EQUAL( 1, static_cast<int>(aAttrs2[7].mnParagraph) ); - CPPUNIT_ASSERT_EQUAL( 19, static_cast<int>(aAttrs2[7].mnStart) ); - CPPUNIT_ASSERT_EQUAL( 24, static_cast<int>(aAttrs2[7].mnEnd) ); - CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(aAttrs2[7].maAttributes.size()) ); - - CPPUNIT_ASSERT_EQUAL( 2, static_cast<int>(aAttrs2[8].mnParagraph) ); - CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(aAttrs2[8].mnStart) ); - CPPUNIT_ASSERT_EQUAL( 23, static_cast<int>(aAttrs2[8].mnEnd) ); - CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(aAttrs2[8].maAttributes.size()) ); + CPPUNIT_ASSERT_EQUAL(size_t(9), aAttrs2.size()); + + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs2[0].mnParagraph)); + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs2[0].mnStart)); + CPPUNIT_ASSERT_EQUAL(5, static_cast<int>(aAttrs2[0].mnEnd)); + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs2[0].maAttributes.size())); + + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs2[1].mnParagraph)); + CPPUNIT_ASSERT_EQUAL(5, static_cast<int>(aAttrs2[1].mnStart)); + CPPUNIT_ASSERT_EQUAL(14, static_cast<int>(aAttrs2[1].mnEnd)); + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aAttrs2[1].maAttributes.size())); + CPPUNIT_ASSERT_MESSAGE("This section must be bold.", hasBold(aAttrs2[1])); + + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs2[2].mnParagraph)); + CPPUNIT_ASSERT_EQUAL(14, static_cast<int>(aAttrs2[2].mnStart)); + CPPUNIT_ASSERT_EQUAL(18, static_cast<int>(aAttrs2[2].mnEnd)); + CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(aAttrs2[2].maAttributes.size())); + CPPUNIT_ASSERT_MESSAGE("This section must be bold and italic.", hasBold(aAttrs2[2])); + CPPUNIT_ASSERT_MESSAGE("This section must be bold and italic.", hasItalic(aAttrs2[2])); + + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs2[3].mnParagraph)); + CPPUNIT_ASSERT_EQUAL(18, static_cast<int>(aAttrs2[3].mnStart)); + CPPUNIT_ASSERT_EQUAL(23, static_cast<int>(aAttrs2[3].mnEnd)); + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aAttrs2[3].maAttributes.size())); + CPPUNIT_ASSERT_MESSAGE("This section must be italic.", hasItalic(aAttrs2[3])); + + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aAttrs2[4].mnParagraph)); + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs2[4].mnStart)); + CPPUNIT_ASSERT_EQUAL(5, static_cast<int>(aAttrs2[4].mnEnd)); + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aAttrs2[4].maAttributes.size())); + CPPUNIT_ASSERT_MESSAGE("This section must be italic.", hasItalic(aAttrs2[4])); + + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aAttrs2[5].mnParagraph)); + CPPUNIT_ASSERT_EQUAL(5, static_cast<int>(aAttrs2[5].mnStart)); + CPPUNIT_ASSERT_EQUAL(9, static_cast<int>(aAttrs2[5].mnEnd)); + CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(aAttrs2[5].maAttributes.size())); + CPPUNIT_ASSERT_MESSAGE("This section must be bold and italic.", hasBold(aAttrs2[5])); + CPPUNIT_ASSERT_MESSAGE("This section must be bold and italic.", hasItalic(aAttrs2[5])); + + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aAttrs2[6].mnParagraph)); + CPPUNIT_ASSERT_EQUAL(9, static_cast<int>(aAttrs2[6].mnStart)); + CPPUNIT_ASSERT_EQUAL(19, static_cast<int>(aAttrs2[6].mnEnd)); + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aAttrs2[6].maAttributes.size())); + CPPUNIT_ASSERT_MESSAGE("This section must be bold.", hasBold(aAttrs2[6])); + + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aAttrs2[7].mnParagraph)); + CPPUNIT_ASSERT_EQUAL(19, static_cast<int>(aAttrs2[7].mnStart)); + CPPUNIT_ASSERT_EQUAL(24, static_cast<int>(aAttrs2[7].mnEnd)); + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs2[7].maAttributes.size())); + + CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(aAttrs2[8].mnParagraph)); + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs2[8].mnStart)); + CPPUNIT_ASSERT_EQUAL(23, static_cast<int>(aAttrs2[8].mnEnd)); + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs2[8].maAttributes.size())); // Copy text using legacy format - uno::Reference< datatransfer::XTransferable > xData = aEditEngine.CreateTransferable( ESelection(0,8,1,14) ); + uno::Reference<datatransfer::XTransferable> xData + = aEditEngine.CreateTransferable(ESelection(0, 8, 1, 14)); // Paste text at the end - aEditEngine.InsertText( xData, OUString(), rDoc.GetEndPaM(), true ); + aEditEngine.InsertText(xData, OUString(), rDoc.GetEndPaM(), true); // Assert changes OUString aThirdParaAfterCopyPaste = aThirdPara + "first paragraph"; @@ -1488,116 +1591,116 @@ void Test::testParaBoldItalicCopyPaste() CPPUNIT_ASSERT_EQUAL( u"This is second"_ustr, rDoc.GetParaAsString(sal_Int32(3)) ); // Check updated text for appropriate Bold/Italics - std::unique_ptr<EditTextObject> pEditText3( aEditEngine.CreateTextObject() ); + std::unique_ptr<EditTextObject> pEditText3(aEditEngine.CreateTextObject()); std::vector<editeng::Section> aAttrs3; - pEditText3->GetAllSections( aAttrs3 ); + pEditText3->GetAllSections(aAttrs3); // There should be 15 sections - woB&woI - wB&woI - wB&wI -woB&wI - woB&wI - wB&wI - wB&woI - woB&woI - woB&woI // - wB&woI - wB&wI - woB&wI - -woB&wI - wB&wI - wB&woI (w - with, wo - without, B - Bold, I - Italic) - CPPUNIT_ASSERT_EQUAL( size_t(15), aAttrs3.size() ); - - CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(aAttrs3[0].mnParagraph) ); - CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(aAttrs3[0].mnStart) ); - CPPUNIT_ASSERT_EQUAL( 5, static_cast<int>(aAttrs3[0].mnEnd) ); - CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(aAttrs3[0].maAttributes.size()) ); - - CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(aAttrs3[1].mnParagraph) ); - CPPUNIT_ASSERT_EQUAL( 5, static_cast<int>(aAttrs3[1].mnStart) ); - CPPUNIT_ASSERT_EQUAL( 14, static_cast<int>(aAttrs3[1].mnEnd) ); - CPPUNIT_ASSERT_EQUAL( 1, static_cast<int>(aAttrs3[1].maAttributes.size()) ); - CPPUNIT_ASSERT_MESSAGE( "This section must be bold.", hasBold(aAttrs3[1]) ); - - CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(aAttrs3[2].mnParagraph) ); - CPPUNIT_ASSERT_EQUAL( 14, static_cast<int>(aAttrs3[2].mnStart) ); - CPPUNIT_ASSERT_EQUAL( 18, static_cast<int>(aAttrs3[2].mnEnd) ); - CPPUNIT_ASSERT_EQUAL( 2, static_cast<int>(aAttrs3[2].maAttributes.size()) ); - CPPUNIT_ASSERT_MESSAGE( "This section must be bold and italic.", hasBold(aAttrs3[2]) ); - CPPUNIT_ASSERT_MESSAGE( "This section must be bold and italic.", hasItalic(aAttrs3[2]) ); - - CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(aAttrs3[3].mnParagraph) ); - CPPUNIT_ASSERT_EQUAL( 18, static_cast<int>(aAttrs3[3].mnStart) ); - CPPUNIT_ASSERT_EQUAL( 23, static_cast<int>(aAttrs3[3].mnEnd) ); - CPPUNIT_ASSERT_EQUAL( 1, static_cast<int>(aAttrs3[3].maAttributes.size()) ); - CPPUNIT_ASSERT_MESSAGE( "This section must be italic.", hasItalic(aAttrs3[3]) ); - - CPPUNIT_ASSERT_EQUAL( 1, static_cast<int>(aAttrs3[4].mnParagraph) ); - CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(aAttrs3[4].mnStart) ); - CPPUNIT_ASSERT_EQUAL( 5, static_cast<int>(aAttrs3[4].mnEnd) ); - CPPUNIT_ASSERT_EQUAL( 1, static_cast<int>(aAttrs3[4].maAttributes.size()) ); - CPPUNIT_ASSERT_MESSAGE( "This section must be italic.", hasItalic(aAttrs3[4]) ); - - CPPUNIT_ASSERT_EQUAL( 1, static_cast<int>(aAttrs3[5].mnParagraph) ); - CPPUNIT_ASSERT_EQUAL( 5, static_cast<int>(aAttrs3[5].mnStart) ); - CPPUNIT_ASSERT_EQUAL( 9, static_cast<int>(aAttrs3[5].mnEnd) ); - CPPUNIT_ASSERT_EQUAL( 2, static_cast<int>(aAttrs3[5].maAttributes.size()) ); - CPPUNIT_ASSERT_MESSAGE( "This section must be bold and italic.", hasBold(aAttrs3[5]) ); - CPPUNIT_ASSERT_MESSAGE( "This section must be bold and italic.", hasItalic(aAttrs3[5]) ); - - CPPUNIT_ASSERT_EQUAL( 1, static_cast<int>(aAttrs3[6].mnParagraph) ); - CPPUNIT_ASSERT_EQUAL( 9, static_cast<int>(aAttrs3[6].mnStart) ); - CPPUNIT_ASSERT_EQUAL( 19, static_cast<int>(aAttrs3[6].mnEnd) ); - CPPUNIT_ASSERT_EQUAL( 1, static_cast<int>(aAttrs3[6].maAttributes.size()) ); - CPPUNIT_ASSERT_MESSAGE( "This section must be bold.", hasBold(aAttrs3[6]) ); - - CPPUNIT_ASSERT_EQUAL( 1, static_cast<int>(aAttrs3[7].mnParagraph) ); - CPPUNIT_ASSERT_EQUAL( 19, static_cast<int>(aAttrs3[7].mnStart) ); - CPPUNIT_ASSERT_EQUAL( 24, static_cast<int>(aAttrs3[7].mnEnd) ); - CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(aAttrs3[7].maAttributes.size()) ); - - CPPUNIT_ASSERT_EQUAL( 2, static_cast<int>(aAttrs3[8].mnParagraph) ); - CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(aAttrs3[8].mnStart) ); - CPPUNIT_ASSERT_EQUAL( 23, static_cast<int>(aAttrs3[8].mnEnd) ); - CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(aAttrs3[8].maAttributes.size()) ); - - CPPUNIT_ASSERT_EQUAL( 2, static_cast<int>(aAttrs3[9].mnParagraph) ); - CPPUNIT_ASSERT_EQUAL( 23, static_cast<int>(aAttrs3[9].mnStart) ); - CPPUNIT_ASSERT_EQUAL( 29, static_cast<int>(aAttrs3[9].mnEnd) ); - CPPUNIT_ASSERT_EQUAL( 1, static_cast<int>(aAttrs3[9].maAttributes.size()) ); - CPPUNIT_ASSERT_MESSAGE( "This section must be bold.", hasBold(aAttrs3[9]) ); - - CPPUNIT_ASSERT_EQUAL( 2, static_cast<int>(aAttrs3[10].mnParagraph) ); - CPPUNIT_ASSERT_EQUAL( 29, static_cast<int>(aAttrs3[10].mnStart) ); - CPPUNIT_ASSERT_EQUAL( 33, static_cast<int>(aAttrs3[10].mnEnd) ); - CPPUNIT_ASSERT_EQUAL( 2, static_cast<int>(aAttrs3[10].maAttributes.size()) ); - CPPUNIT_ASSERT_MESSAGE( "This section must be bold and italic.", hasBold(aAttrs3[10]) ); - CPPUNIT_ASSERT_MESSAGE( "This section must be bold and italic.", hasItalic(aAttrs3[10]) ); - - CPPUNIT_ASSERT_EQUAL( 2, static_cast<int>(aAttrs3[11].mnParagraph) ); - CPPUNIT_ASSERT_EQUAL( 33, static_cast<int>(aAttrs3[11].mnStart) ); - CPPUNIT_ASSERT_EQUAL( 38, static_cast<int>(aAttrs3[11].mnEnd) ); - CPPUNIT_ASSERT_EQUAL( 1, static_cast<int>(aAttrs3[11].maAttributes.size()) ); - CPPUNIT_ASSERT_MESSAGE( "This section must be italic.", hasItalic(aAttrs3[11]) ); - - CPPUNIT_ASSERT_EQUAL( 3, static_cast<int>(aAttrs3[12].mnParagraph) ); - CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(aAttrs3[12].mnStart) ); - CPPUNIT_ASSERT_EQUAL( 5, static_cast<int>(aAttrs3[12].mnEnd) ); - CPPUNIT_ASSERT_EQUAL( 1, static_cast<int>(aAttrs3[12].maAttributes.size()) ); - CPPUNIT_ASSERT_MESSAGE( "This section must be italic.", hasItalic(aAttrs3[12]) ); - - CPPUNIT_ASSERT_EQUAL( 3, static_cast<int>(aAttrs3[13].mnParagraph) ); - CPPUNIT_ASSERT_EQUAL( 5, static_cast<int>(aAttrs3[13].mnStart) ); - CPPUNIT_ASSERT_EQUAL( 9, static_cast<int>(aAttrs3[13].mnEnd) ); - CPPUNIT_ASSERT_EQUAL( 2, static_cast<int>(aAttrs3[13].maAttributes.size()) ); - CPPUNIT_ASSERT_MESSAGE( "This section must be bold and italic.", hasBold(aAttrs3[13]) ); - CPPUNIT_ASSERT_MESSAGE( "This section must be bold and italic.", hasItalic(aAttrs3[13]) ); - - CPPUNIT_ASSERT_EQUAL( 3, static_cast<int>(aAttrs3[14].mnParagraph) ); - CPPUNIT_ASSERT_EQUAL( 9, static_cast<int>(aAttrs3[14].mnStart) ); - CPPUNIT_ASSERT_EQUAL( 14, static_cast<int>(aAttrs3[14].mnEnd) ); - CPPUNIT_ASSERT_EQUAL( 1, static_cast<int>(aAttrs3[14].maAttributes.size()) ); - CPPUNIT_ASSERT_MESSAGE( "This section must be bold.", hasBold(aAttrs3[14]) ); + CPPUNIT_ASSERT_EQUAL(size_t(15), aAttrs3.size()); + + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs3[0].mnParagraph)); + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs3[0].mnStart)); + CPPUNIT_ASSERT_EQUAL(5, static_cast<int>(aAttrs3[0].mnEnd)); + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs3[0].maAttributes.size())); + + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs3[1].mnParagraph)); + CPPUNIT_ASSERT_EQUAL(5, static_cast<int>(aAttrs3[1].mnStart)); + CPPUNIT_ASSERT_EQUAL(14, static_cast<int>(aAttrs3[1].mnEnd)); + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aAttrs3[1].maAttributes.size())); + CPPUNIT_ASSERT_MESSAGE("This section must be bold.", hasBold(aAttrs3[1])); + + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs3[2].mnParagraph)); + CPPUNIT_ASSERT_EQUAL(14, static_cast<int>(aAttrs3[2].mnStart)); + CPPUNIT_ASSERT_EQUAL(18, static_cast<int>(aAttrs3[2].mnEnd)); + CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(aAttrs3[2].maAttributes.size())); + CPPUNIT_ASSERT_MESSAGE("This section must be bold and italic.", hasBold(aAttrs3[2])); + CPPUNIT_ASSERT_MESSAGE("This section must be bold and italic.", hasItalic(aAttrs3[2])); + + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs3[3].mnParagraph)); + CPPUNIT_ASSERT_EQUAL(18, static_cast<int>(aAttrs3[3].mnStart)); + CPPUNIT_ASSERT_EQUAL(23, static_cast<int>(aAttrs3[3].mnEnd)); + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aAttrs3[3].maAttributes.size())); + CPPUNIT_ASSERT_MESSAGE("This section must be italic.", hasItalic(aAttrs3[3])); + + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aAttrs3[4].mnParagraph)); + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs3[4].mnStart)); + CPPUNIT_ASSERT_EQUAL(5, static_cast<int>(aAttrs3[4].mnEnd)); + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aAttrs3[4].maAttributes.size())); + CPPUNIT_ASSERT_MESSAGE("This section must be italic.", hasItalic(aAttrs3[4])); + + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aAttrs3[5].mnParagraph)); + CPPUNIT_ASSERT_EQUAL(5, static_cast<int>(aAttrs3[5].mnStart)); + CPPUNIT_ASSERT_EQUAL(9, static_cast<int>(aAttrs3[5].mnEnd)); + CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(aAttrs3[5].maAttributes.size())); + CPPUNIT_ASSERT_MESSAGE("This section must be bold and italic.", hasBold(aAttrs3[5])); + CPPUNIT_ASSERT_MESSAGE("This section must be bold and italic.", hasItalic(aAttrs3[5])); + + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aAttrs3[6].mnParagraph)); + CPPUNIT_ASSERT_EQUAL(9, static_cast<int>(aAttrs3[6].mnStart)); + CPPUNIT_ASSERT_EQUAL(19, static_cast<int>(aAttrs3[6].mnEnd)); + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aAttrs3[6].maAttributes.size())); + CPPUNIT_ASSERT_MESSAGE("This section must be bold.", hasBold(aAttrs3[6])); + + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aAttrs3[7].mnParagraph)); + CPPUNIT_ASSERT_EQUAL(19, static_cast<int>(aAttrs3[7].mnStart)); + CPPUNIT_ASSERT_EQUAL(24, static_cast<int>(aAttrs3[7].mnEnd)); + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs3[7].maAttributes.size())); + + CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(aAttrs3[8].mnParagraph)); + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs3[8].mnStart)); + CPPUNIT_ASSERT_EQUAL(23, static_cast<int>(aAttrs3[8].mnEnd)); + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs3[8].maAttributes.size())); + + CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(aAttrs3[9].mnParagraph)); + CPPUNIT_ASSERT_EQUAL(23, static_cast<int>(aAttrs3[9].mnStart)); + CPPUNIT_ASSERT_EQUAL(29, static_cast<int>(aAttrs3[9].mnEnd)); + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aAttrs3[9].maAttributes.size())); + CPPUNIT_ASSERT_MESSAGE("This section must be bold.", hasBold(aAttrs3[9])); + + CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(aAttrs3[10].mnParagraph)); + CPPUNIT_ASSERT_EQUAL(29, static_cast<int>(aAttrs3[10].mnStart)); + CPPUNIT_ASSERT_EQUAL(33, static_cast<int>(aAttrs3[10].mnEnd)); + CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(aAttrs3[10].maAttributes.size())); + CPPUNIT_ASSERT_MESSAGE("This section must be bold and italic.", hasBold(aAttrs3[10])); + CPPUNIT_ASSERT_MESSAGE("This section must be bold and italic.", hasItalic(aAttrs3[10])); + + CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(aAttrs3[11].mnParagraph)); + CPPUNIT_ASSERT_EQUAL(33, static_cast<int>(aAttrs3[11].mnStart)); + CPPUNIT_ASSERT_EQUAL(38, static_cast<int>(aAttrs3[11].mnEnd)); + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aAttrs3[11].maAttributes.size())); + CPPUNIT_ASSERT_MESSAGE("This section must be italic.", hasItalic(aAttrs3[11])); + + CPPUNIT_ASSERT_EQUAL(3, static_cast<int>(aAttrs3[12].mnParagraph)); + CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs3[12].mnStart)); + CPPUNIT_ASSERT_EQUAL(5, static_cast<int>(aAttrs3[12].mnEnd)); + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aAttrs3[12].maAttributes.size())); + CPPUNIT_ASSERT_MESSAGE("This section must be italic.", hasItalic(aAttrs3[12])); + + CPPUNIT_ASSERT_EQUAL(3, static_cast<int>(aAttrs3[13].mnParagraph)); + CPPUNIT_ASSERT_EQUAL(5, static_cast<int>(aAttrs3[13].mnStart)); + CPPUNIT_ASSERT_EQUAL(9, static_cast<int>(aAttrs3[13].mnEnd)); + CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(aAttrs3[13].maAttributes.size())); + CPPUNIT_ASSERT_MESSAGE("This section must be bold and italic.", hasBold(aAttrs3[13])); + CPPUNIT_ASSERT_MESSAGE("This section must be bold and italic.", hasItalic(aAttrs3[13])); + + CPPUNIT_ASSERT_EQUAL(3, static_cast<int>(aAttrs3[14].mnParagraph)); + CPPUNIT_ASSERT_EQUAL(9, static_cast<int>(aAttrs3[14].mnStart)); + CPPUNIT_ASSERT_EQUAL(14, static_cast<int>(aAttrs3[14].mnEnd)); + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aAttrs3[14].maAttributes.size())); + CPPUNIT_ASSERT_MESSAGE("This section must be bold.", hasBold(aAttrs3[14])); } void Test::testParaStartCopyPaste() { // Create EditEngine's instance - EditEngine aEditEngine( mpItemPool.get() ); + EditEngine aEditEngine(mpItemPool.get()); // Get EditDoc for current EditEngine's instance - EditDoc &rDoc = aEditEngine.GetEditDoc(); + EditDoc& rDoc = aEditEngine.GetEditDoc(); // Initially no text should be there - CPPUNIT_ASSERT_EQUAL( sal_Int32(0), rDoc.GetTextLen() ); - CPPUNIT_ASSERT_EQUAL( OUString(), rDoc.GetParaAsString(sal_Int32(0)) ); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), rDoc.GetTextLen()); + CPPUNIT_ASSERT_EQUAL(OUString(), rDoc.GetParaAsString(sal_Int32(0))); // Insert initial text OUString aFirstPara = u"This is first paragraph"_ustr; @@ -1612,16 +1715,17 @@ void Test::testParaStartCopyPaste() sal_Int32 aCopyTextLen = aCopyText.getLength(); // Assert changes - CPPUNIT_ASSERT_EQUAL( aTextLen, rDoc.GetTextLen() ); - CPPUNIT_ASSERT_EQUAL( aFirstPara, rDoc.GetParaAsString(sal_Int32(0)) ); - CPPUNIT_ASSERT_EQUAL( aSecondPara, rDoc.GetParaAsString(sal_Int32(1)) ); - CPPUNIT_ASSERT_EQUAL( aThirdPara, rDoc.GetParaAsString(sal_Int32(2)) ); + CPPUNIT_ASSERT_EQUAL(aTextLen, rDoc.GetTextLen()); + CPPUNIT_ASSERT_EQUAL(aFirstPara, rDoc.GetParaAsString(sal_Int32(0))); + CPPUNIT_ASSERT_EQUAL(aSecondPara, rDoc.GetParaAsString(sal_Int32(1))); + CPPUNIT_ASSERT_EQUAL(aThirdPara, rDoc.GetParaAsString(sal_Int32(2))); // Copy initial text using legacy format - uno::Reference< datatransfer::XTransferable > xData = aEditEngine.CreateTransferable( ESelection(0,8,1,14) ); + uno::Reference<datatransfer::XTransferable> xData + = aEditEngine.CreateTransferable(ESelection(0, 8, 1, 14)); // Paste text at the start - aEditEngine.InsertText( xData, OUString(), rDoc.GetStartPaM(), true ); + aEditEngine.InsertText(xData, OUString(), rDoc.GetStartPaM(), true); // Assert changes OUString aSecondParaAfterCopyPaste = "This is second" + aFirstPara; @@ -1643,20 +1747,24 @@ void Test::testSectionAttributes() { aEngine.SetText(u"aaabbbccc"_ustr); pSet->Put(aBold); - CPPUNIT_ASSERT_EQUAL_MESSAGE("There should be exactly one item.", static_cast<sal_uInt16>(1), pSet->Count()); - aEngine.QuickSetAttribs(*pSet, ESelection(0,0,0,6)); // 'aaabbb' - end point is not inclusive. + CPPUNIT_ASSERT_EQUAL_MESSAGE("There should be exactly one item.", + static_cast<sal_uInt16>(1), pSet->Count()); + aEngine.QuickSetAttribs(*pSet, + ESelection(0, 0, 0, 6)); // 'aaabbb' - end point is not inclusive. pSet.reset(new SfxItemSet(aEngine.GetEmptyItemSet())); pSet->Put(aItalic); - CPPUNIT_ASSERT_EQUAL_MESSAGE("There should be exactly one item.", static_cast<sal_uInt16>(1), pSet->Count()); + CPPUNIT_ASSERT_EQUAL_MESSAGE("There should be exactly one item.", + static_cast<sal_uInt16>(1), pSet->Count()); - aEngine.QuickSetAttribs(*pSet, ESelection(0,3,0,9)); // 'bbbccc' + aEngine.QuickSetAttribs(*pSet, ESelection(0, 3, 0, 9)); // 'bbbccc' std::unique_ptr<EditTextObject> pEditText(aEngine.CreateTextObject()); CPPUNIT_ASSERT_MESSAGE("Failed to create text object.", pEditText); std::vector<editeng::Section> aAttrs; pEditText->GetAllSections(aAttrs); // Now, we should have a total of 3 sections. - CPPUNIT_ASSERT_EQUAL_MESSAGE("There should be 3 sections.", static_cast<size_t>(3), aAttrs.size()); + CPPUNIT_ASSERT_EQUAL_MESSAGE("There should be 3 sections.", static_cast<size_t>(3), + aAttrs.size()); // First section should be 0-3 of paragraph 0, and it should only have boldness applied. CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(aAttrs[0].mnParagraph)); @@ -1692,10 +1800,11 @@ void Test::testSectionAttributes() // Apply boldness to paragraphs 1, 3, 5 only. Leave 2 and 4 unformatted. pSet.reset(new SfxItemSet(aEngine.GetEmptyItemSet())); pSet->Put(aBold); - CPPUNIT_ASSERT_EQUAL_MESSAGE("There should be exactly one item.", static_cast<sal_uInt16>(1), pSet->Count()); - aEngine.QuickSetAttribs(*pSet, ESelection(0,0,0,3)); - aEngine.QuickSetAttribs(*pSet, ESelection(2,0,2,3)); - aEngine.QuickSetAttribs(*pSet, ESelection(4,0,4,5)); + CPPUNIT_ASSERT_EQUAL_MESSAGE("There should be exactly one item.", + static_cast<sal_uInt16>(1), pSet->Count()); + aEngine.QuickSetAttribs(*pSet, ESelection(0, 0, 0, 3)); + aEngine.QuickSetAttribs(*pSet, ESelection(2, 0, 2, 3)); + aEngine.QuickSetAttribs(*pSet, ESelection(4, 0, 4, 5)); std::unique_ptr<EditTextObject> pEditText(aEngine.CreateTextObject()); CPPUNIT_ASSERT_MESSAGE("Failed to create text object.", pEditText); @@ -1734,7 +1843,6 @@ void Test::testSectionAttributes() CPPUNIT_ASSERT_MESSAGE("Attribute array should be empty.", aAttrs[3].maAttributes.empty()); } - { aEngine.Clear(); aEngine.SetText(u"one\ntwo"_ustr); @@ -1743,14 +1851,14 @@ void Test::testSectionAttributes() // embolden 2nd paragraph pSet.reset(new SfxItemSet(aEngine.GetEmptyItemSet())); pSet->Put(aBold); - aEngine.QuickSetAttribs(*pSet, ESelection(1,0,1,3)); + aEngine.QuickSetAttribs(*pSet, ESelection(1, 0, 1, 3)); // disboldify 1st paragraph SvxWeightItem aNotSoBold(WEIGHT_NORMAL, EE_CHAR_WEIGHT); pSet->Put(aNotSoBold); - aEngine.QuickSetAttribs(*pSet, ESelection(0,0,0,3)); + aEngine.QuickSetAttribs(*pSet, ESelection(0, 0, 0, 3)); // now delete & join the paragraphs - this is fdo#85496 scenario - aEngine.QuickDelete(ESelection(0,0,1,3)); + aEngine.QuickDelete(ESelection(0, 0, 1, 3)); CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), aEngine.GetParagraphCount()); std::unique_ptr<EditTextObject> pEditText(aEngine.CreateTextObject()); @@ -1768,7 +1876,7 @@ void Test::testSectionAttributes() { sal_uInt16 const nWhich(aAttrs[0].maAttributes[i]->Which()); CPPUNIT_ASSERT_MESSAGE("duplicate item in text portion attributes", - whiches.insert(nWhich).second); + whiches.insert(nWhich).second); } } } @@ -1776,14 +1884,14 @@ void Test::testSectionAttributes() void Test::testLargeParaCopyPaste() { // Create EditEngine's instance - EditEngine aEditEngine( mpItemPool.get() ); + EditEngine aEditEngine(mpItemPool.get()); // Get EditDoc for current EditEngine's instance - EditDoc &rDoc = aEditEngine.GetEditDoc(); + EditDoc& rDoc = aEditEngine.GetEditDoc(); // Initially no text should be there - CPPUNIT_ASSERT_EQUAL( sal_Int32(0), rDoc.GetTextLen() ); - CPPUNIT_ASSERT_EQUAL( OUString(), rDoc.GetParaAsString(sal_Int32(0)) ); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), rDoc.GetTextLen()); + CPPUNIT_ASSERT_EQUAL(OUString(), rDoc.GetParaAsString(sal_Int32(0))); // Insert initial text OUString aFirstPara = u"This is first paragraph"_ustr; @@ -1809,24 +1917,25 @@ void Test::testLargeParaCopyPaste() sal_Int32 aCopyTextLen = aCopyText.getLength(); // Assert changes - CPPUNIT_ASSERT_EQUAL( aTextLen, rDoc.GetTextLen() ); - CPPUNIT_ASSERT_EQUAL( aFirstPara, rDoc.GetParaAsString(sal_Int32(0)) ); - CPPUNIT_ASSERT_EQUAL( aSecondPara, rDoc.GetParaAsString(sal_Int32(1)) ); - CPPUNIT_ASSERT_EQUAL( aThirdPara, rDoc.GetParaAsString(sal_Int32(2)) ); - CPPUNIT_ASSERT_EQUAL( aFourthPara, rDoc.GetParaAsString(sal_Int32(3)) ); - CPPUNIT_ASSERT_EQUAL( aFifthPara, rDoc.GetParaAsString(sal_Int32(4)) ); - CPPUNIT_ASSERT_EQUAL( aSixthPara, rDoc.GetParaAsString(sal_Int32(5)) ); - CPPUNIT_ASSERT_EQUAL( aSeventhPara, rDoc.GetParaAsString(sal_Int32(6)) ); - CPPUNIT_ASSERT_EQUAL( aEighthPara, rDoc.GetParaAsString(sal_Int32(7)) ); - CPPUNIT_ASSERT_EQUAL( aNinthPara, rDoc.GetParaAsString(sal_Int32(8)) ); - CPPUNIT_ASSERT_EQUAL( aTenthPara, rDoc.GetParaAsString(sal_Int32(9)) ); + CPPUNIT_ASSERT_EQUAL(aTextLen, rDoc.GetTextLen()); + CPPUNIT_ASSERT_EQUAL(aFirstPara, rDoc.GetParaAsString(sal_Int32(0))); + CPPUNIT_ASSERT_EQUAL(aSecondPara, rDoc.GetParaAsString(sal_Int32(1))); + CPPUNIT_ASSERT_EQUAL(aThirdPara, rDoc.GetParaAsString(sal_Int32(2))); + CPPUNIT_ASSERT_EQUAL(aFourthPara, rDoc.GetParaAsString(sal_Int32(3))); + CPPUNIT_ASSERT_EQUAL(aFifthPara, rDoc.GetParaAsString(sal_Int32(4))); + CPPUNIT_ASSERT_EQUAL(aSixthPara, rDoc.GetParaAsString(sal_Int32(5))); + CPPUNIT_ASSERT_EQUAL(aSeventhPara, rDoc.GetParaAsString(sal_Int32(6))); + CPPUNIT_ASSERT_EQUAL(aEighthPara, rDoc.GetParaAsString(sal_Int32(7))); + CPPUNIT_ASSERT_EQUAL(aNinthPara, rDoc.GetParaAsString(sal_Int32(8))); + CPPUNIT_ASSERT_EQUAL(aTenthPara, rDoc.GetParaAsString(sal_Int32(9))); // Copy initial text using legacy format - uno::Reference< datatransfer::XTransferable > xData = aEditEngine.CreateTransferable( ESelection(5,8,7,14) ); + uno::Reference<datatransfer::XTransferable> xData + = aEditEngine.CreateTransferable(ESelection(5, 8, 7, 14)); // Paste text at the end of 4th Para ContentNode* pLastNode = rDoc.GetObject(3); - aEditEngine.InsertText( xData, OUString(), EditPaM( pLastNode, pLastNode->Len() ), true ); + aEditEngine.InsertText(xData, OUString(), EditPaM(pLastNode, pLastNode->Len()), true); // Assert changes OUString aFourthParaAfterCopyPaste = aFourthPara + "sixth paragraph"; @@ -1845,18 +1954,18 @@ void Test::testLargeParaCopyPaste() CPPUNIT_ASSERT_EQUAL( aTenthPara, rDoc.GetParaAsString(sal_Int32(11)) ); } -OUString lcl_translitTest(EditEngine& aEditEngine, const OUString& text, const ESelection& esel, const TransliterationFlags nType) +OUString lcl_translitTest(EditEngine& aEditEngine, const OUString& text, const ESelection& esel, + const TransliterationFlags nType) { aEditEngine.SetText(text); aEditEngine.TransliterateText(esel, nType); return aEditEngine.GetText(); } - void Test::testTransliterate() { // Create EditEngine's instance - EditEngine editEng( mpItemPool.get() ); + EditEngine editEng(mpItemPool.get()); OUString sText(u"one (two) three"_ustr); editEng.SetText(sText); @@ -1935,7 +2044,6 @@ void Test::testTransliterate() CPPUNIT_ASSERT_EQUAL(u"Mary Jones MEt joe Smith. Time Passed."_ustr, lcl_translitTest(editEng, sText2, esel, TF::LOWERCASE_UPPERCASE)); CPPUNIT_ASSERT_EQUAL(u"Mary Jones met joe Smith. Time Passed."_ustr, lcl_translitTest(editEng, sText2, esel, TF::UPPERCASE_LOWERCASE)); - /* Test behavior when there is a selection that crosses a word boundary: "nes met joe Sm" */ selStart = 7; selEnd = 21; @@ -1984,7 +2092,7 @@ void Test::testTdf147196() void Test::testTdf148148() { using TF = TransliterationFlags; - EditEngine editEng( mpItemPool.get() ); + EditEngine editEng(mpItemPool.get()); /* Test what happens when node contains text but selection does not contain any text */ int selStart = 0; @@ -2066,7 +2174,7 @@ void Test::testTdf148148() void Test::testSingleLine() { - EditEngine aEditEngine( mpItemPool.get() ); + EditEngine aEditEngine(mpItemPool.get()); aEditEngine.SetSingleLine(true); aEditEngine.SetText(u"Bolivian\nSanta Cruz de la Sierra"_ustr); @@ -2145,7 +2253,8 @@ void Test::testMoveParagraph() CPPUNIT_ASSERT_EQUAL(u"Paragraph 4"_ustr, aEditEngine.GetText(3)); CPPUNIT_ASSERT_EQUAL(u"Paragraph 5"_ustr, aEditEngine.GetText(4)); - aEditEngine.MoveParagraphs(Range(0, 0), 8); // Move paragraph 1 -> to before index 8 but 8 is out of bounds + aEditEngine.MoveParagraphs(Range(0, 0), + 8); // Move paragraph 1 -> to before index 8 but 8 is out of bounds CPPUNIT_ASSERT_EQUAL(sal_Int32(5), aEditEngine.GetParagraphCount()); CPPUNIT_ASSERT_EQUAL(u"Paragraph 2"_ustr, aEditEngine.GetText(0)); @@ -2294,7 +2403,6 @@ void Test::testTdf154248MultilineFieldWrapping() } CPPUNIT_TEST_SUITE_REGISTRATION(Test); - } CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/editeng/source/editeng/impedit2.cxx b/editeng/source/editeng/impedit2.cxx index 4e56da97f706..7635a061c297 100644 --- a/editeng/source/editeng/impedit2.cxx +++ b/editeng/source/editeng/impedit2.cxx @@ -3927,6 +3927,32 @@ EditSelection ImpEditEngine::PasteText( uno::Reference< datatransfer::XTransfera } } + if (!bDone) { + // HTML_SIMPLE + SotExchange::GetFormatDataFlavor(SotClipboardFormatId::HTML_SIMPLE, aFlavor); + bool bHtmlSupported = rxDataObj->isDataFlavorSupported(aFlavor); + if (bHtmlSupported && (SotClipboardFormatId::NONE == format || SotClipboardFormatId::HTML_SIMPLE == format)) { + MSE40HTMLClipFormatObj aMSE40HTMLClipFormatObj; + try + { + uno::Any aData = rxDataObj->getTransferData(aFlavor); + uno::Sequence< sal_Int8 > aSeq; + aData >>= aSeq; + { + SvMemoryStream aHtmlStream(aSeq.getArray(), aSeq.getLength(), StreamMode::READ); + SvStream* pHtmlStream = aMSE40HTMLClipFormatObj.IsValid(aHtmlStream); + if (pHtmlStream != nullptr) { + aNewSelection = Read(*pHtmlStream, rBaseURL, EETextFormat::Html, rPaM); + } + } + bDone = true; + } + catch (const css::uno::Exception&) + { + } + } + } + if ( !bDone ) { // RTF @@ -3958,31 +3984,6 @@ EditSelection ImpEditEngine::PasteText( uno::Reference< datatransfer::XTransfera } } } - if (!bDone) { - // HTML_SIMPLE - SotExchange::GetFormatDataFlavor(SotClipboardFormatId::HTML_SIMPLE, aFlavor); - bool bHtmlSupported = rxDataObj->isDataFlavorSupported(aFlavor); - if (bHtmlSupported && (SotClipboardFormatId::NONE == format || SotClipboardFormatId::HTML_SIMPLE == format)) { - MSE40HTMLClipFormatObj aMSE40HTMLClipFormatObj; - try - { - uno::Any aData = rxDataObj->getTransferData(aFlavor); - uno::Sequence< sal_Int8 > aSeq; - aData >>= aSeq; - { - SvMemoryStream aHtmlStream(aSeq.getArray(), aSeq.getLength(), StreamMode::READ); - SvStream* pHtmlStream = aMSE40HTMLClipFormatObj.IsValid(aHtmlStream); - if (pHtmlStream != nullptr) { - aNewSelection = Read(*pHtmlStream, rBaseURL, EETextFormat::Html, rPaM); - } - } - bDone = true; - } - catch (const css::uno::Exception&) - { - } - } - } if (!bDone) { diff --git a/include/svx/svdotable.hxx b/include/svx/svdotable.hxx index 4a25ae970d7e..3f3573466651 100644 --- a/include/svx/svdotable.hxx +++ b/include/svx/svdotable.hxx @@ -284,6 +284,8 @@ private: SVX_DLLPUBLIC void ExportAsRTF( SvStream& rStrm, SdrTableObj& rObj ); SVX_DLLPUBLIC void ImportAsRTF( SvStream& rStrm, SdrTableObj& rObj ); +SVX_DLLPUBLIC void ImportAsHTML( SvStream& rStrm, SdrTableObj& rObj ); + } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/svx/svdotext.hxx b/include/svx/svdotext.hxx index aeb99556f097..9ff8a3e67f8b 100644 --- a/include/svx/svdotext.hxx +++ b/include/svx/svdotext.hxx @@ -78,6 +78,7 @@ namespace sdr::table { class Cell; class SdrTableRtfExporter; class SdrTableRTFParser; + class SdrTableHTMLParser; } @@ -128,6 +129,7 @@ private: friend class sdr::table::Cell; friend class sdr::table::SdrTableRtfExporter; friend class sdr::table::SdrTableRTFParser; + friend class sdr::table::SdrTableHTMLParser; friend class TextChain; friend class TextChainFlow; friend class EditingTextChainFlow; diff --git a/sd/source/ui/inc/View.hxx b/sd/source/ui/inc/View.hxx index 596816931c15..493756871998 100644 --- a/sd/source/ui/inc/View.hxx +++ b/sd/source/ui/inc/View.hxx @@ -176,6 +176,7 @@ public: const Point& rPos, const Size& rSize ); bool PasteRTFTable( SvStream& rOStm, SdrPage* pPage, SdrInsertFlags nPasteOptions ); + bool PasteHTMLTable( SvStream& rOStm, SdrPage* pPage, SdrInsertFlags nPasteOptions ); bool IsPresObjSelected(bool bOnPage = true, bool bOnMasterPage = true, bool bCheckPresObjListOnly = false, bool bCheckLayoutOnly = false) const; diff --git a/sd/source/ui/inc/tablefunction.hxx b/sd/source/ui/inc/tablefunction.hxx index fe32f16b51b6..68c037eb9318 100644 --- a/sd/source/ui/inc/tablefunction.hxx +++ b/sd/source/ui/inc/tablefunction.hxx @@ -27,6 +27,7 @@ namespace sd { void CreateTableFromRTF(SvStream& rStream, SdDrawDocument* pModel); +void CreateTableFromHTML(SvStream& rStream, SdDrawDocument* pModel); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sd/source/ui/table/tablefunction.cxx b/sd/source/ui/table/tablefunction.cxx index 6f886c1becec..5670ffb1fd86 100644 --- a/sd/source/ui/table/tablefunction.cxx +++ b/sd/source/ui/table/tablefunction.cxx @@ -286,6 +286,32 @@ void CreateTableFromRTF( SvStream& rStream, SdDrawDocument* pModel ) sdr::table::ImportAsRTF( rStream, *pObj ); } +void CreateTableFromHTML(SvStream& rStream, SdDrawDocument* pModel) +{ + rStream.Seek( 0 ); + + if( !pModel ) + return; + + SdrPage* pPage = pModel->GetPage(0); + if( !pPage ) + return; + + Size aSize( 200, 200 ); + ::tools::Rectangle aRect (Point(), aSize); + rtl::Reference<sdr::table::SdrTableObj> pObj = new sdr::table::SdrTableObj( + *pModel, + aRect, + 1, + 1); + pObj->NbcSetStyleSheet( pModel->GetDefaultStyleSheet(), true ); + apply_table_style( pObj.get(), pModel, OUString() ); + + pPage->NbcInsertObject( pObj.get() ); + + sdr::table::ImportAsHTML( rStream, *pObj ); +} + } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sd/source/ui/view/sdview3.cxx b/sd/source/ui/view/sdview3.cxx index 6a205211161d..4f7a52b0a9c3 100644 --- a/sd/source/ui/view/sdview3.cxx +++ b/sd/source/ui/view/sdview3.cxx @@ -1411,8 +1411,28 @@ bool View::InsertData( const TransferableDataHelper& rDataHelper, if (std::unique_ptr<SvStream> xStm = aDataHelper.GetSotStorageStream( SotClipboardFormatId::HTML )) { xStm->Seek( 0 ); - // mba: clipboard always must contain absolute URLs (could be from alien source) - bReturn = SdrView::Paste( *xStm, EETextFormat::Html, maDropPos, pPage, nPasteOptions ); + + OStringBuffer aLine; + while (xStm->ReadLine(aLine)) + { + if (std::string_view(aLine).find( "<table>" ) != std::string_view::npos || + std::string_view(aLine).find( "<table " ) != std::string_view::npos) + { + bTable = true; + break; + } + } + + xStm->Seek( 0 ); + if (bTable) + { + bReturn = PasteHTMLTable(*xStm, pPage, nPasteOptions); + } + else + { + // mba: clipboard always must contain absolute URLs (could be from alien source) + bReturn = SdrView::Paste( *xStm, EETextFormat::Html, maDropPos, pPage, nPasteOptions ); + } } } @@ -1445,8 +1465,38 @@ bool View::InsertData( const TransferableDataHelper& rDataHelper, if(!bReturn && !bLink) { + bool bIsHtmlSimple = CHECK_FORMAT_TRANS(SotClipboardFormatId::HTML_SIMPLE); + if (bIsHtmlSimple) + { + if (std::unique_ptr<SvStream> xStm = aDataHelper.GetSotStorageStream(SotClipboardFormatId::HTML_SIMPLE)) + { + xStm->Seek(0); + + OutlinerView* pOLV = GetTextEditOutlinerView(); + MSE40HTMLClipFormatObj aMSE40HTMLClipFormatObj; + SvStream* pHtmlStream = aMSE40HTMLClipFormatObj.IsValid(*xStm); + + if (pOLV) + { + ::tools::Rectangle aRect(pOLV->GetOutputArea()); + Point aPos(pOLV->GetWindow()->PixelToLogic(maDropPos)); + + if (aRect.Contains(aPos) || (!bDrag && IsTextEdit())) + { + // mba: clipboard always must contain absolute URLs (could be from alien source) + pOLV->Read(*pHtmlStream, EETextFormat::Html, mpDocSh->GetHeaderAttributes()); + bReturn = true; + } + } + + if (!bReturn) + // mba: clipboard always must contain absolute URLs (could be from alien source) + bReturn = SdrView::Paste(*pHtmlStream, EETextFormat::Html, maDropPos, pPage, nPasteOptions); + } + } + bool bIsRTF = CHECK_FORMAT_TRANS(SotClipboardFormatId::RTF); - if (bIsRTF || CHECK_FORMAT_TRANS(SotClipboardFormatId::RICHTEXT)) + if (!bReturn && (bIsRTF || CHECK_FORMAT_TRANS(SotClipboardFormatId::RICHTEXT))) { auto nFormatId = bIsRTF ? SotClipboardFormatId::RTF : SotClipboardFormatId::RICHTEXT; if (std::unique_ptr<SvStream> xStm = aDataHelper.GetSotStorageStream( nFormatId )) @@ -1481,35 +1531,6 @@ bool View::InsertData( const TransferableDataHelper& rDataHelper, } } - bool bIsHtmlSimple = CHECK_FORMAT_TRANS(SotClipboardFormatId::HTML_SIMPLE); - if (bIsHtmlSimple) - { - if (std::unique_ptr<SvStream> xStm = aDataHelper.GetSotStorageStream(SotClipboardFormatId::HTML_SIMPLE)) - { - xStm->Seek(0); - - OutlinerView* pOLV = GetTextEditOutlinerView(); - MSE40HTMLClipFormatObj aMSE40HTMLClipFormatObj; - SvStream* pHtmlStream = aMSE40HTMLClipFormatObj.IsValid(*xStm); - - if (pOLV) - { - ::tools::Rectangle aRect(pOLV->GetOutputArea()); - Point aPos(pOLV->GetWindow()->PixelToLogic(maDropPos)); - - if (aRect.Contains(aPos) || (!bDrag && IsTextEdit())) - { - // mba: clipboard always must contain absolute URLs (could be from alien source) - pOLV->Read(*pHtmlStream, EETextFormat::Html, mpDocSh->GetHeaderAttributes()); - bReturn = true; - } - } - - if (!bReturn) - // mba: clipboard always must contain absolute URLs (could be from alien source) - bReturn = SdrView::Paste(*pHtmlStream, EETextFormat::Html, maDropPos, pPage, nPasteOptions); - } - } } if(!bReturn && CHECK_FORMAT_TRANS(SotClipboardFormatId::FILE_LIST)) @@ -1601,6 +1622,22 @@ bool View::PasteRTFTable( SvStream& rStm, SdrPage* pPage, SdrInsertFlags nPasteO return bRet; } +bool View::PasteHTMLTable( SvStream& rStm, SdrPage* pPage, SdrInsertFlags nPasteOptions ) +{ + DrawDocShellRef xShell = new DrawDocShell(SfxObjectCreateMode::INTERNAL, false, DocumentType::Impress); + xShell->DoInitNew(); + + SdDrawDocument* pModel = xShell->GetDoc(); + pModel->GetItemPool().SetDefaultMetric(MapUnit::Map100thMM); + pModel->InsertPage(pModel->AllocPage(false).get()); + + CreateTableFromHTML(rStm, pModel); + bool bRet = Paste(*pModel, maDropPos, pPage, nPasteOptions); + + xShell->DoClose(); + + return bRet; +} } // end of namespace sd /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svx/Library_svx.mk b/svx/Library_svx.mk index 54ff74c9568b..75b20d54506d 100644 --- a/svx/Library_svx.mk +++ b/svx/Library_svx.mk @@ -263,6 +263,7 @@ $(eval $(call gb_Library_add_exception_objects,svx,\ svx/source/table/tabledesign \ svx/source/table/tablertfexporter \ svx/source/table/tablertfimporter \ + svx/source/table/tablehtmlimporter \ svx/source/tbxctrls/bulletsnumbering \ svx/source/tbxctrls/colrctrl \ svx/source/tbxctrls/SvxColorChildWindow \ diff --git a/svx/source/table/tablehtmlimporter.cxx b/svx/source/table/tablehtmlimporter.cxx new file mode 100644 index 000000000000..12b6a84ad94b --- /dev/null +++ b/svx/source/table/tablehtmlimporter.cxx @@ -0,0 +1,509 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <memory> +#include <vector> + +#include <com/sun/star/table/XTable.hpp> +#include <com/sun/star/table/XMergeableCellRange.hpp> + +#include <tools/stream.hxx> +#include <tools/UnitConversion.hxx> + +#include <svx/svdetc.hxx> +#include <editeng/outlobj.hxx> + +#include <cell.hxx> +#include <svx/svdotable.hxx> +#include <svx/svdoutl.hxx> +#include <editeng/editeng.hxx> +#include <editeng/editdata.hxx> +#include <svx/svdmodel.hxx> +#include <editeng/editids.hrc> +#include <sal/log.hxx> +#include <tools/debug.hxx> +#include <comphelper/diagnose_ex.hxx> +#include <svtools/htmltokn.h> +#include <svtools/parhtml.hxx> + +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::table; +using namespace ::com::sun::star::container; +using namespace ::com::sun::star::beans; + +namespace sdr::table +{ +namespace +{ +struct RowColSpan +{ + sal_Int32 mnRowSpan; + sal_Int32 mnColSpan; + explicit RowColSpan() + : mnRowSpan(1) + , mnColSpan(1) + { + } +}; + +struct HTMLCellDefault +{ + sal_Int32 mnRowSpan; + sal_Int32 mnColSpan; // MergeCell if >1, merged cells if 0 + sal_Int32 mnCellX; + + explicit HTMLCellDefault() + : mnRowSpan(1) + , mnColSpan(1) + , mnCellX(0) + { + } +}; +} + +typedef std::vector<std::shared_ptr<HTMLCellDefault>> HTMLCellDefaultVector; + +namespace +{ +struct HTMLCellInfo +{ + SfxItemSet maItemSet; + sal_Int32 mnStartPara; + sal_Int32 mnParaCount; + sal_Int32 mnCellX; + sal_Int32 mnRowSpan; + std::shared_ptr<HTMLCellInfo> mxVMergeCell; + + explicit HTMLCellInfo(SfxItemPool& rPool) + : maItemSet(rPool) + , mnStartPara(0) + , mnParaCount(0) + , mnCellX(0) + , mnRowSpan(1) + { + } +}; +} + +typedef std::shared_ptr<HTMLCellInfo> HTMLCellInfoPtr; +typedef std::vector<HTMLCellInfoPtr> HTMLColumnVector; + +typedef std::shared_ptr<HTMLColumnVector> HTMLColumnVectorPtr; + +class SdrTableHTMLParser +{ +public: + explicit SdrTableHTMLParser(SdrTableObj& rTableObj); + + void Read(SvStream& rStream); + + void ProcToken(HtmlImportInfo* pInfo); + + void NextRow(); + void NextColumn(); + void NewCellRow(); + + void InsertCell(sal_Int32 nStartPara, sal_Int32 nEndPara); + void InsertColumnEdge(sal_Int32 nEdge); + + void FillTable(); + + DECL_LINK(HTMLImportHdl, HtmlImportInfo&, void); + +private: + SdrTableObj& mrTableObj; + std::unique_ptr<SdrOutliner> mpOutliner; + SfxItemPool& mrItemPool; + + HTMLCellDefaultVector maDefaultList; + HTMLCellDefaultVector::iterator maDefaultIterator; + + HtmlTokenId mnLastToken; + bool mbNewDef; + + sal_Int32 mnCellStartPara; + + sal_Int32 mnRowCnt; + sal_Int32 mnLastEdge; + sal_Int32 mnVMergeIdx; + + std::vector<sal_Int32> maColumnEdges; + std::vector<sal_Int32>::iterator maLastEdge; + std::vector<HTMLColumnVectorPtr> maRows; + + std::unique_ptr<HTMLCellDefault> mpInsDefault; + HTMLCellDefault* mpActDefault; + sal_Int32 mnCellInRow; + + Reference<XTable> mxTable; + + HTMLColumnVectorPtr mxLastRow; + // Copy assignment is forbidden and not implemented. + SdrTableHTMLParser(const SdrTableHTMLParser&) = delete; + SdrTableHTMLParser& operator=(const SdrTableHTMLParser&) = delete; +}; + +SdrTableHTMLParser::SdrTableHTMLParser(SdrTableObj& rTableObj) + : mrTableObj(rTableObj) + , mpOutliner(SdrMakeOutliner(OutlinerMode::TextObject, rTableObj.getSdrModelFromSdrObject())) + , mrItemPool(rTableObj.getSdrModelFromSdrObject().GetItemPool()) + , mnLastToken(HtmlTokenId::NONE) + , mbNewDef(false) + , mnCellStartPara(0) + , mnRowCnt(0) + , mnLastEdge(0) + , mnVMergeIdx(0) + , mpActDefault(nullptr) + , mnCellInRow(-1) + , mxTable(rTableObj.getTable()) +{ + mpOutliner->SetUpdateLayout(true); + mpOutliner->SetStyleSheet(0, mrTableObj.GetStyleSheet()); + mpInsDefault.reset(new HTMLCellDefault()); +} + +void SdrTableHTMLParser::Read(SvStream& rStream) +{ + EditEngine& rEdit = const_cast<EditEngine&>(mpOutliner->GetEditEngine()); + + Link<HtmlImportInfo&, void> aOldLink(rEdit.GetHtmlImportHdl()); + rEdit.SetHtmlImportHdl(LINK(this, SdrTableHTMLParser, HTMLImportHdl)); + mpOutliner->Read(rStream, OUString(), EETextFormat::Html); + rEdit.SetHtmlImportHdl(aOldLink); + + FillTable(); +} + +IMPL_LINK(SdrTableHTMLParser, HTMLImportHdl, HtmlImportInfo&, rInfo, void) +{ + switch (rInfo.eState) + { + case HtmlImportState::NextToken: + ProcToken(&rInfo); + break; + case HtmlImportState::End: + if (rInfo.aSelection.nEndPos) + { + mpActDefault = nullptr; + //TODO: ?? + // rInfo.nToken = RTF_PAR; + rInfo.aSelection.nEndPara++; + ProcToken(&rInfo); + } + break; + case HtmlImportState::SetAttr: + case HtmlImportState::InsertText: + case HtmlImportState::InsertPara: + break; + default: + SAL_WARN("svx.table", "unknown ImportInfo.eState"); + } +} + +void SdrTableHTMLParser::NextRow() +{ + mxLastRow = maRows.back(); + mnVMergeIdx = 0; + ++mnRowCnt; +} + +void SdrTableHTMLParser::InsertCell(sal_Int32 nStartPara, sal_Int32 nEndPara) +{ + HTMLCellInfoPtr xCellInfo = std::make_shared<HTMLCellInfo>(mrItemPool); + xCellInfo->mnStartPara = nStartPara; + xCellInfo->mnParaCount = nEndPara - nStartPara; + xCellInfo->mnCellX = mpActDefault->mnCellX; + xCellInfo->mnRowSpan = mpActDefault->mnRowSpan; + + if (mxLastRow != nullptr) + { + sal_Int32 nSize = mxLastRow->size(); + while (mnVMergeIdx < nSize && (*mxLastRow)[mnVMergeIdx]->mnCellX < xCellInfo->mnCellX) + ++mnVMergeIdx; + + if (xCellInfo->mnRowSpan == 0 && mnVMergeIdx < nSize) + { + HTMLCellInfoPtr xLastCell((*mxLastRow)[mnVMergeIdx]); + if (xLastCell->mnRowSpan) + xCellInfo->mxVMergeCell = xLastCell; + else + xCellInfo->mxVMergeCell = xLastCell->mxVMergeCell; + } + } + + if (!maRows.empty()) + { + HTMLColumnVectorPtr xColumn(maRows.back()); + if (xCellInfo->mxVMergeCell) + { + if (xColumn->empty() || xColumn->back()->mxVMergeCell != xCellInfo->mxVMergeCell) + xCellInfo->mxVMergeCell->mnRowSpan++; + } + + xColumn->push_back(xCellInfo); + } +} + +void SdrTableHTMLParser::InsertColumnEdge(sal_Int32 nEdge) +{ + auto aNextEdge = std::lower_bound(maLastEdge, maColumnEdges.end(), nEdge); + + if (aNextEdge == maColumnEdges.end() || nEdge != *aNextEdge) + { + maLastEdge = maColumnEdges.insert(aNextEdge, nEdge); + mnLastEdge = nEdge; + } +} + +void SdrTableHTMLParser::FillTable() +{ + try + { + sal_Int32 nColCount = mxTable->getColumnCount(); + Reference<XTableColumns> xCols(mxTable->getColumns(), UNO_SET_THROW); + sal_Int32 nColMax = maColumnEdges.size(); + if (nColCount < nColMax) + { + xCols->insertByIndex(nColCount, nColMax - nColCount); + nColCount = mxTable->getColumnCount(); + } + + static constexpr OUStringLiteral sWidth(u"Width"); + sal_Int32 nCol, nLastEdge = 0; + for (nCol = 0; nCol < nColCount; nCol++) + { + Reference<XPropertySet> xSet(xCols->getByIndex(nCol), UNO_QUERY_THROW); + sal_Int32 nWidth = maColumnEdges[nCol] - nLastEdge; + + xSet->setPropertyValue(sWidth, Any(nWidth)); + nLastEdge += nWidth; + } + + const sal_Int32 nRowCount = mxTable->getRowCount(); + if (nRowCount < mnRowCnt) + { + Reference<XTableRows> xRows(mxTable->getRows(), UNO_SET_THROW); + xRows->insertByIndex(nRowCount, mnRowCnt - nRowCount); + } + + for (sal_Int32 nRow = 0; nRow < static_cast<sal_Int32>(maRows.size()); nRow++) + { + HTMLColumnVectorPtr xColumn(maRows[nRow]); + nCol = 0; + auto aEdge = maColumnEdges.begin(); + for (sal_Int32 nIdx = 0; + nCol < nColMax && nIdx < static_cast<sal_Int32>(xColumn->size()); nIdx++) + { + HTMLCellInfoPtr xCellInfo((*xColumn)[nIdx]); + + CellRef xCell(dynamic_cast<Cell*>(mxTable->getCellByPosition(nCol, nRow).get())); + if (xCell.is() && xCellInfo) + { + const SfxPoolItem* pPoolItem = nullptr; + if (xCellInfo->maItemSet.GetItemState(SDRATTR_TABLE_BORDER, false, &pPoolItem) + == SfxItemState::SET) + xCell->SetMergedItem(*pPoolItem); + + std::optional<OutlinerParaObject> pTextObject(mpOutliner->CreateParaObject( + xCellInfo->mnStartPara, xCellInfo->mnParaCount)); + if (pTextObject) + { + SdrOutliner& rOutliner = mrTableObj.ImpGetDrawOutliner(); + rOutliner.SetUpdateLayout(true); + rOutliner.SetText(*pTextObject); + mrTableObj.NbcSetOutlinerParaObjectForText(rOutliner.CreateParaObject(), + xCell.get()); + } + + sal_Int32 nLastRow = nRow; + if (xCellInfo->mnRowSpan) + nLastRow += xCellInfo->mnRowSpan - 1; + + aEdge = std::lower_bound(aEdge, maColumnEdges.end(), xCellInfo->mnCellX); + sal_Int32 nLastCol = nCol; + if (aEdge != maColumnEdges.end()) + { + nLastCol = std::distance(maColumnEdges.begin(), aEdge); + ++aEdge; + } + + if (nLastCol > nCol || nLastRow > nRow) + { + Reference<XMergeableCellRange> xRange( + mxTable->createCursorByRange( + mxTable->getCellRangeByPosition(nCol, nRow, nLastCol, nLastRow)), + UNO_QUERY_THROW); + if (xRange->isMergeable()) + xRange->merge(); + } + nCol = nLastCol + 1; + } + } + } + + tools::Rectangle aRect(mrTableObj.GetSnapRect()); + aRect.SetRight(aRect.Left() + nLastEdge); + mrTableObj.NbcSetSnapRect(aRect); + } + catch (Exception&) + { + TOOLS_WARN_EXCEPTION("svx", ""); + } +} + +void SdrTableHTMLParser::NewCellRow() +{ + if (mbNewDef) + { + mbNewDef = false; + + maRows.push_back(std::make_shared<std::vector<std::shared_ptr<HTMLCellInfo>>>()); + } + maDefaultIterator = maDefaultList.begin(); + + NextColumn(); + + DBG_ASSERT(mpActDefault, "NewCellRow: pActDefault==0"); +} + +void SdrTableHTMLParser::NextColumn() +{ + if (maDefaultIterator != maDefaultList.end()) + mpActDefault = (*maDefaultIterator++).get(); + else + mpActDefault = nullptr; +} + +static RowColSpan lcl_GetRowColSpan(const HTMLOptions& options) +{ + RowColSpan aRowColSpan; + for (HTMLOptions::const_iterator optionIt = options.begin(); optionIt != options.end(); + ++optionIt) + { + if (optionIt->GetToken() == HtmlOptionId::COLSPAN) + { + aRowColSpan.mnColSpan = optionIt->GetNumber(); + } + else if (optionIt->GetToken() == HtmlOptionId::ROWSPAN) + { + aRowColSpan.mnRowSpan = optionIt->GetNumber(); + } + } + return aRowColSpan; +} + +//TODO: width is pixel - detect document pixel with to determine real width +static sal_Int32 lcl_GetWidth(const HTMLOptions& options) +{ + for (HTMLOptions::const_iterator optionIt = options.begin(); optionIt != options.end(); + ++optionIt) + { + if (optionIt->GetToken() == HtmlOptionId::WIDTH) + { + //const OUString& value = optionIt->GetString(); + //TODO: Which conversion is required? + return 1000; + } + } + return 1000; +} +void SdrTableHTMLParser::ProcToken(HtmlImportInfo* pInfo) +{ + HTMLParser* pHtmlParser = static_cast<HTMLParser*>(pInfo->pParser); + const HTMLOptions& options = pHtmlParser->GetOptions(); + switch (pInfo->nToken) + { + case HtmlTokenId::TABLE_ON: + maDefaultList.clear(); + mnLastToken = pInfo->nToken; + maLastEdge = maColumnEdges.begin(); + mnLastEdge = 0; + break; + case HtmlTokenId::TABLE_OFF: + break; + case HtmlTokenId::TABLEHEADER_ON: + case HtmlTokenId::TABLEDATA_ON: + { + ++mnCellInRow; + DBG_ASSERT(mpActDefault, "TABLEDATA_OFF: pActDefault==0"); + RowColSpan aRowColSpan = lcl_GetRowColSpan(options); + mpActDefault->mnColSpan = aRowColSpan.mnColSpan; + mpActDefault->mnRowSpan = aRowColSpan.mnRowSpan; + mnCellStartPara = pInfo->aSelection.nStartPara; + } + break; + case HtmlTokenId::TABLEDATA_OFF: + case HtmlTokenId::TABLEHEADER_OFF: + { + DBG_ASSERT(mpActDefault, "TABLEDATA_OFF: pActDefault==0"); + if (mbNewDef || !mpActDefault) + NewCellRow(); + if (!mpActDefault) + mpActDefault = mpInsDefault.get(); + if (mpActDefault->mnColSpan > 0) + { + mpActDefault->mnCellX = maColumnEdges[mnCellInRow + mpActDefault->mnColSpan - 1]; + InsertCell(mnCellStartPara, pInfo->aSelection.nEndPara); + } + NextColumn(); + mnLastToken = pInfo->nToken; + } + break; + case HtmlTokenId::TABLEROW_ON: + mbNewDef = true; + NewCellRow(); + mnLastToken = pInfo->nToken; + break; + case HtmlTokenId::TABLEROW_OFF: + { + NextRow(); + mnCellInRow = -1; + mnLastToken = pInfo->nToken; + } + break; + case HtmlTokenId::COL_ON: + { + std::shared_ptr<HTMLCellDefault> pDefault(mpInsDefault.release()); + maDefaultList.push_back(pDefault); + + const sal_Int32 nSize = lcl_GetWidth(options) + mnLastEdge; + if (nSize > mnLastEdge) + InsertColumnEdge(nSize); + + mpInsDefault.reset(new HTMLCellDefault()); + mnLastEdge = nSize; + mnLastToken = pInfo->nToken; + } + break; + case HtmlTokenId::COL_OFF: + break; + + default: + break; + } +} + +void ImportAsHTML(SvStream& rStream, SdrTableObj& rObj) +{ + SdrTableHTMLParser aParser(rObj); + aParser.Read(rStream); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |