summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorLászló Németh <nemeth@numbertext.org>2020-05-15 13:32:07 +0200
committerLászló Németh <nemeth@numbertext.org>2020-05-18 17:57:43 +0200
commitfb001eab98934c5a4d0a8c6b9563f91337561b87 (patch)
tree6a34134f2d7b0def729b8002bbe6d9be4cedeb05 /sw
parent92289c5f121499959b6f5edf859e5f34b5b96a78 (diff)
tdf#127616 DOCX import: fix char style of empty paragraph
When direct character formatting defined in w:pPr/w:rPr overwrites some character style properties (character style defined by w:pPr/w:rPr/w:rStyle), empty paragraphs lost such direct formatting, resulting for example, different page layout by different height of empty paragraphs. Also text of that originally empty paragraphs got different formatting during typing. Co-authored-by: Justin Luth <justin_luth@sil.org> Change-Id: Ic7b3a73d4d7364993cc58073c9e1a09a2711d1b3 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/94308 Tested-by: Jenkins Reviewed-by: László Németh <nemeth@numbertext.org>
Diffstat (limited to 'sw')
-rw-r--r--sw/qa/extras/ooxmlexport/data/paragraph-mark2.docxbin0 -> 31782 bytes
-rw-r--r--sw/qa/extras/ooxmlexport/ooxmlexport.cxx10
-rw-r--r--sw/source/core/unocore/unotext.cxx20
3 files changed, 30 insertions, 0 deletions
diff --git a/sw/qa/extras/ooxmlexport/data/paragraph-mark2.docx b/sw/qa/extras/ooxmlexport/data/paragraph-mark2.docx
new file mode 100644
index 000000000000..a465813dc668
--- /dev/null
+++ b/sw/qa/extras/ooxmlexport/data/paragraph-mark2.docx
Binary files differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
index 5f521b8067c4..ed5216c15a10 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
@@ -633,6 +633,16 @@ DECLARE_OOXMLEXPORT_TEST(testParagraphMark, "paragraph-mark.docx")
CPPUNIT_ASSERT_EQUAL(OUString("Emphasis"), getProperty<OUString>(getRun(getParagraph(1), 1), "CharStyleName"));
}
+DECLARE_OOXMLEXPORT_TEST(testParagraphMark2, "paragraph-mark2.docx")
+{
+ // The problem was that we didn't handle the situation when an empty paragraph's marker had both a char style and some direct formatting.
+
+ // This was Segoe UI, set by Char Style FontStyle11 presumably.
+ CPPUNIT_ASSERT_EQUAL(OUString("Arial"), getProperty<OUString>(getRun(getParagraph(1), 1), "CharFontName"));
+ // This was 11, set by Char Style FontStyle11 presumably.
+ CPPUNIT_ASSERT_EQUAL(10.f, getProperty<float>(getRun(getParagraph(1), 1), "CharHeight"));
+}
+
DECLARE_OOXMLEXPORT_TEST(testParagraphMarkNonempty, "paragraph-mark-nonempty.odt")
{
CPPUNIT_ASSERT_EQUAL(1, getPages());
diff --git a/sw/source/core/unocore/unotext.cxx b/sw/source/core/unocore/unotext.cxx
index 9ef0f55dc08c..ee5185b12f2b 100644
--- a/sw/source/core/unocore/unotext.cxx
+++ b/sw/source/core/unocore/unotext.cxx
@@ -1275,6 +1275,26 @@ SwXText::Impl::finishOrAppendParagraph(
aSwMapProvider.GetPropertySet(PROPERTY_MAP_PARAGRAPH);
SwUnoCursorHelper::SetPropertyValues(aPam, *pParaPropSet, rProperties);
+
+ // tdf#127616 keep direct character formatting of empty paragraphs,
+ // if character style of the paragraph sets also the same attributes
+ if (aPam.Start()->nNode.GetNode().GetTextNode()->Len() == 0)
+ {
+ auto itCharStyle = std::find_if(rProperties.begin(), rProperties.end(), [](const beans::PropertyValue& rValue)
+ {
+ return rValue.Name == "CharStyleName";
+ });
+ if ( itCharStyle != rProperties.end() )
+ {
+ for (const auto& rValue : rProperties)
+ {
+ if ( rValue != *itCharStyle && rValue.Name.startsWith("Char") )
+ {
+ SwUnoCursorHelper::SetPropertyValue(aPam, *pParaPropSet, rValue.Name, rValue.Value);
+ }
+ }
+ }
+ }
}
catch (const lang::IllegalArgumentException& rIllegal)
{