[Libreoffice-commits] core.git: Branch 'libreoffice-4-3-5' - editeng/qa editeng/source

Michael Stahl mstahl at redhat.com
Tue Dec 2 12:22:22 PST 2014


 editeng/qa/unit/core-test.cxx      |   39 +++++++++++++++++++++++++++++++++++++
 editeng/source/editeng/editobj.cxx |   15 +++++++++++++-
 2 files changed, 53 insertions(+), 1 deletion(-)

New commits:
commit dc32ecf262fcba7dfb1e56356523f847f12f0e25
Author: Michael Stahl <mstahl at redhat.com>
Date:   Mon Dec 1 19:25:13 2014 +0100

    fdo#85496: editeng: avoid exporting duplicate attributes
    
    Since commit 0d57434180db6c8eda8c5b9b704f8a1c18b371df multiple 0-length
    attributes will be exported by the ODF filter as duplicate attributes.
    
    (cherry picked from commit 7a242b463132d67a4a2d6e69319e0da367145cc0)
    (cherry picked from commit 846b56b6b99e334dfa44f1a24640aa3158509854)
    
    This backport takes a different approach from the master fix and simply
    detects duplicates in EditTextObjectImpl::GetAllSections() which should
    be safe enough for 4.2.8.2.
    
    Change-Id: Iff787c8d2a71bc3082192cc98e3d916badee65dd
    Reviewed-on: https://gerrit.libreoffice.org/13260
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>
    (cherry picked from commit eba15473d5cadca30edba6989512ee3e331ad197)
    Reviewed-on: https://gerrit.libreoffice.org/13270
    Reviewed-by: Eike Rathke <erack at redhat.com>

diff --git a/editeng/qa/unit/core-test.cxx b/editeng/qa/unit/core-test.cxx
index 4e9b82b..0869344 100644
--- a/editeng/qa/unit/core-test.cxx
+++ b/editeng/qa/unit/core-test.cxx
@@ -573,6 +573,45 @@ void Test::testSectionAttributes()
         CPPUNIT_ASSERT_EQUAL(0, (int)pSecAttr->mnEnd);
         CPPUNIT_ASSERT_MESSAGE("Attribute array should be empty.", pSecAttr->maAttributes.empty());
     }
+
+
+    {
+        aEngine.Clear();
+        aEngine.SetText("one\ntwo");
+        CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aEngine.GetParagraphCount());
+
+        // embolden 2nd paragraph
+        pSet.reset(new SfxItemSet(aEngine.GetEmptyItemSet()));
+        pSet->Put(aBold);
+        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));
+
+        // now delete & join the paragraphs - this is fdo#85496 scenario
+        aEngine.QuickDelete(ESelection(0,0,1,3));
+        CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aEngine.GetParagraphCount());
+
+        boost::scoped_ptr<EditTextObject> pEditText(aEngine.CreateTextObject());
+        CPPUNIT_ASSERT_MESSAGE("Failed to create text object.", pEditText.get());
+        std::vector<editeng::Section> aAttrs;
+        pEditText->GetAllSections(aAttrs);
+
+        CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), aAttrs.size());
+
+        const editeng::Section* pSecAttr = &aAttrs[0];
+        CPPUNIT_ASSERT_EQUAL(0, (int)pSecAttr->mnParagraph);
+        CPPUNIT_ASSERT_EQUAL(0, (int)pSecAttr->mnStart);
+        CPPUNIT_ASSERT_EQUAL(0, (int)pSecAttr->mnEnd);
+        std::set<sal_uInt16> whiches;
+        for (size_t i = 0; i < pSecAttr->maAttributes.size(); ++i)
+        {
+            sal_uInt16 const nWhich(pSecAttr->maAttributes[i]->Which());
+            CPPUNIT_ASSERT_MESSAGE("duplicate item in text portion attributes",
+                whiches.insert(nWhich).second);
+        }
+    }
 }
 
 CPPUNIT_TEST_SUITE_REGISTRATION(Test);
diff --git a/editeng/source/editeng/editobj.cxx b/editeng/source/editeng/editobj.cxx
index 41fddb0..7dfd06f 100644
--- a/editeng/source/editeng/editobj.cxx
+++ b/editeng/source/editeng/editobj.cxx
@@ -1000,7 +1000,20 @@ void EditTextObjectImpl::GetAllSections( std::vector<editeng::Section>& rAttrs )
             for (; itCurAttr != aAttrs.end() && itCurAttr->mnParagraph == nPara && itCurAttr->mnEnd <= nEnd; ++itCurAttr)
             {
                 editeng::Section& rSecAttr = *itCurAttr;
-                rSecAttr.maAttributes.push_back(pItem);
+                bool bInsert(true);
+                for (size_t j = 0; j < rSecAttr.maAttributes.size(); ++j)
+                {
+                    if (rSecAttr.maAttributes[j]->Which() == pItem->Which())
+                    {
+                        SAL_WARN("editeng", "GetAllSections(): duplicate attribute suppressed");
+                        bInsert = false;
+                        break;
+                    }
+                }
+                if (bInsert)
+                {
+                    rSecAttr.maAttributes.push_back(pItem);
+                }
             }
         }
     }


More information about the Libreoffice-commits mailing list