summaryrefslogtreecommitdiff
path: root/editeng
diff options
context:
space:
mode:
authorMichael Stahl <mstahl@redhat.com>2014-12-01 19:21:49 +0100
committerMichael Stahl <mstahl@redhat.com>2014-12-01 23:28:13 +0100
commit8fccff42616ac434c3d641a76c37f3a135cec97e (patch)
tree64a21add6ef3af66e6aa8d5e86e7ecfe13f6fb7d /editeng
parent8141936ccdb0aa71d7489ce232d954da89e5174b (diff)
fdo#85496: editeng: do not add multiple 0-length attributes...
... at the same position. Since commit 0d57434180db6c8eda8c5b9b704f8a1c18b371df these will be exported by the ODF filter as duplicate attributes. Change-Id: I8befe55f61c59ab968409fa03359540c300f9198 (cherry picked from commit 846b56b6b99e334dfa44f1a24640aa3158509854)
Diffstat (limited to 'editeng')
-rw-r--r--editeng/qa/unit/core-test.cxx39
-rw-r--r--editeng/source/editeng/editdoc.cxx23
2 files changed, 55 insertions, 7 deletions
diff --git a/editeng/qa/unit/core-test.cxx b/editeng/qa/unit/core-test.cxx
index 4090db4d8978..ae4a946bcd0f 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(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(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/editdoc.cxx b/editeng/source/editeng/editdoc.cxx
index e293425544f5..54cdb909312d 100644
--- a/editeng/source/editeng/editdoc.cxx
+++ b/editeng/source/editeng/editdoc.cxx
@@ -1579,14 +1579,23 @@ void ContentNode::AppendAttribs( ContentNode* pNextNode )
{
if ( pTmpAttrib->GetEnd() == nNewStart )
{
- if ( ( pTmpAttrib->Which() == pAttrib->Which() ) &&
- ( *(pTmpAttrib->GetItem()) == *(pAttrib->GetItem() ) ) )
+ if (pTmpAttrib->Which() == pAttrib->Which())
{
- pTmpAttrib->GetEnd() =
- pTmpAttrib->GetEnd() + pAttrib->GetLen();
- rNextAttribs.erase(rNextAttribs.begin()+nAttr);
- // Unsubscribe from the pool?!
- bMelted = true;
+ // prevent adding 2 0-length attributes at same position
+ if ((*(pTmpAttrib->GetItem()) == *(pAttrib->GetItem()))
+ || (0 == pAttrib->GetLen()))
+ {
+ pTmpAttrib->GetEnd() =
+ pTmpAttrib->GetEnd() + pAttrib->GetLen();
+ rNextAttribs.erase(rNextAttribs.begin()+nAttr);
+ // Unsubscribe from the pool?!
+ bMelted = true;
+ }
+ else if (0 == pTmpAttrib->GetLen())
+ {
+ aCharAttribList.Remove(nTmpAttr);
+ --nTmpAttr; // to cancel later increment...
+ }
}
}
++nTmpAttr;