[Libreoffice-commits] core.git: Branch 'libreoffice-7-0' - sw/qa sw/source writerfilter/source

Vasily Melenchuk (via logerrit) logerrit at kemper.freedesktop.org
Fri Aug 28 18:43:14 UTC 2020


 sw/qa/extras/ooxmlexport/data/tdf131801.docx      |binary
 sw/qa/extras/ooxmlexport/ooxmlexport15.cxx        |   53 ++++++++++++++++++++++
 sw/source/core/attr/swatrset.cxx                  |   10 ++++
 sw/source/core/text/txtfld.cxx                    |   31 +++++++++++-
 sw/source/core/unocore/unoobj.cxx                 |   11 ++++
 sw/source/filter/ww8/wrtw8nds.cxx                 |    3 -
 writerfilter/source/dmapper/DomainMapper_Impl.cxx |    4 -
 7 files changed, 103 insertions(+), 9 deletions(-)

New commits:
commit 6aff5d2e913bebe858ced534ef059166683c7d6a
Author:     Vasily Melenchuk <vasily.melenchuk at cib.de>
AuthorDate: Tue Aug 18 17:59:26 2020 +0200
Commit:     Michael Stahl <michael.stahl at cib.de>
CommitDate: Fri Aug 28 20:42:41 2020 +0200

    tdf#131801: sw: support of style references in ListAutoFormat
    
    ListAutoFormat property did support char attributes, but not
    style references ("CharStyleName"). It is important for correct
    formatting of pilcrow symbol or list format in some DOCX scenarios.
    
    Export to DOCX already works, but not to RTF/DOC.
    
    Change-Id: I1bf23d1e45fcc213adcf9aa6f404be803919fbee
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/100893
    Tested-by: Michael Stahl <michael.stahl at cib.de>
    Reviewed-by: Michael Stahl <michael.stahl at cib.de>
    (cherry picked from commit c77b9c349f0a48392d8cb7a49532844b2cafb5ba)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/101559
    Tested-by: Jenkins

diff --git a/sw/qa/extras/ooxmlexport/data/tdf131801.docx b/sw/qa/extras/ooxmlexport/data/tdf131801.docx
new file mode 100644
index 000000000000..61872b5399f5
Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/tdf131801.docx differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport15.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport15.cxx
index f585934c896f..f17d9ad3f668 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport15.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport15.cxx
@@ -9,6 +9,7 @@
 
 #include <swmodeltestbase.hxx>
 
+#include <com/sun/star/beans/NamedValue.hpp>
 #include <com/sun/star/beans/XPropertySet.hpp>
 
 char const DATA_DIRECTORY[] = "/sw/qa/extras/ooxmlexport/data/";
@@ -39,6 +40,58 @@ DECLARE_OOXMLEXPORT_TEST(testTdf133370_columnBreak, "tdf133370_columnBreak.odt")
     CPPUNIT_ASSERT_EQUAL(1, getPages());
 }
 
+DECLARE_OOXMLIMPORT_TEST(testTdf131801, "tdf131801.docx")
+{
+    CPPUNIT_ASSERT_EQUAL(1, getPages());
+
+    xmlDocUniquePtr pDump = parseLayoutDump();
+    // "1." is red
+    CPPUNIT_ASSERT_EQUAL(OUString("1."), getXPath(pDump, "//page[1]/body/txt[1]/Special", "rText"));
+    CPPUNIT_ASSERT_EQUAL(OUString("00ff0000"), getXPath(pDump, "//page[1]/body/txt[1]/Special/SwFont", "color"));
+    // "2." is red
+    CPPUNIT_ASSERT_EQUAL(OUString("2."), getXPath(pDump, "//page[1]/body/txt[2]/Special", "rText"));
+    CPPUNIT_ASSERT_EQUAL(OUString("00ff0000"), getXPath(pDump, "//page[1]/body/txt[2]/Special/SwFont", "color"));
+    // "3." is black
+    CPPUNIT_ASSERT_EQUAL(OUString("3."), getXPath(pDump, "//page[1]/body/txt[3]/Special", "rText"));
+    CPPUNIT_ASSERT_EQUAL(OUString("ffffffff"), getXPath(pDump, "//page[1]/body/txt[3]/Special/SwFont", "color"));
+    // "4." is black
+    CPPUNIT_ASSERT_EQUAL(OUString("4."), getXPath(pDump, "//page[1]/body/txt[4]/Special", "rText"));
+    CPPUNIT_ASSERT_EQUAL(OUString("ffffffff"), getXPath(pDump, "//page[1]/body/txt[4]/Special/SwFont", "color"));
+    // "5." is red
+    CPPUNIT_ASSERT_EQUAL(OUString("5."), getXPath(pDump, "//page[1]/body/txt[5]/Special", "rText"));
+    CPPUNIT_ASSERT_EQUAL(OUString("00ff0000"), getXPath(pDump, "//page[1]/body/txt[5]/Special/SwFont", "color"));
+    // "6." is red
+    CPPUNIT_ASSERT_EQUAL(OUString("6."), getXPath(pDump, "//page[1]/body/txt[6]/Special", "rText"));
+    CPPUNIT_ASSERT_EQUAL(OUString("00ff0000"), getXPath(pDump, "//page[1]/body/txt[6]/Special/SwFont", "color"));
+    // "7." is black
+    CPPUNIT_ASSERT_EQUAL(OUString("7."), getXPath(pDump, "//page[1]/body/txt[7]/Special", "rText"));
+    CPPUNIT_ASSERT_EQUAL(OUString("ffffffff"), getXPath(pDump, "//page[1]/body/txt[7]/Special/SwFont", "color"));
+    // "8." is black
+    CPPUNIT_ASSERT_EQUAL(OUString("8."), getXPath(pDump, "//page[1]/body/txt[8]/Special[1]", "rText"));
+    CPPUNIT_ASSERT_EQUAL(OUString("ffffffff"), getXPath(pDump, "//page[1]/body/txt[8]/Special[1]/SwFont", "color"));
+
+    xmlDocUniquePtr pXmlDocument = parseExport("word/document.xml");
+    if (!pXmlDocument)
+        return;
+
+    assertXPath(pXmlDocument, "/w:document/w:body/w:p[1]/w:pPr/w:rPr/w:rStyle",
+        "val", "Emphasis");
+    assertXPath(pXmlDocument, "/w:document/w:body/w:p[2]/w:pPr/w:rPr/w:rStyle",
+        "val", "Emphasis");
+    assertXPath(pXmlDocument, "/w:document/w:body/w:p[3]/w:pPr/w:rPr/w:rStyle", 0);
+    assertXPath(pXmlDocument, "/w:document/w:body/w:p[4]/w:pPr/w:rPr/w:rStyle", 0);
+    assertXPath(pXmlDocument, "/w:document/w:body/w:p[5]/w:pPr/w:rPr/w:rStyle",
+        "val", "Emphasis");
+    assertXPath(pXmlDocument, "/w:document/w:body/w:p[5]/w:pPr/w:rPr/w:sz",
+        "val", "32");
+    assertXPath(pXmlDocument, "/w:document/w:body/w:p[6]/w:pPr/w:rPr/w:rStyle",
+        "val", "Emphasis");
+    assertXPath(pXmlDocument, "/w:document/w:body/w:p[6]/w:pPr/w:rPr/w:sz",
+        "val", "32");
+    assertXPath(pXmlDocument, "/w:document/w:body/w:p[7]/w:pPr/w:rPr/w:rStyle", 0);
+    assertXPath(pXmlDocument, "/w:document/w:body/w:p[8]/w:pPr/w:rPr/w:rStyle", 0);
+}
+
 DECLARE_OOXMLEXPORT_TEST(testTdf135973, "tdf135973.odt")
 {
     CPPUNIT_ASSERT_EQUAL(1, getPages());
diff --git a/sw/source/core/attr/swatrset.cxx b/sw/source/core/attr/swatrset.cxx
index d62df7e94719..aa6d9f1ad088 100644
--- a/sw/source/core/attr/swatrset.cxx
+++ b/sw/source/core/attr/swatrset.cxx
@@ -21,6 +21,7 @@
 
 #include <cellatr.hxx>
 #include <charfmt.hxx>
+#include <fchrfmt.hxx>
 #include <doc.hxx>
 #include <IDocumentListsAccess.hxx>
 #include <editeng/editeng.hxx>
@@ -404,6 +405,15 @@ void SwAttrSet::CopyToModify( SwModify& rMod ) const
                 SfxItemSet const& rAutoStyle(*static_cast<SwFormatAutoFormat const&>(*pItem).GetStyleHandle());
                 std::shared_ptr<SfxItemSet> const pNewSet(
                     rAutoStyle.SfxItemSet::Clone(true, &pDstDoc->GetAttrPool()));
+
+                // fix up character style, it contains pointers to pSrcDoc
+                if (SfxItemState::SET == pNewSet->GetItemState(RES_TXTATR_CHARFMT, false, &pItem))
+                {
+                    auto const* pChar(static_cast<SwFormatCharFormat const*>(pItem));
+                    SwCharFormat *const pCopy(pDstDoc->CopyCharFormat(*pChar->GetCharFormat()));
+                    const_cast<SwFormatCharFormat*>(pChar)->SetCharFormat(pCopy);
+                }
+
                 SwFormatAutoFormat item(RES_PARATR_LIST_AUTOFMT);
                 // TODO: for ODF export we'd need to add it to the autostyle pool
                 item.SetStyleHandle(pNewSet);
diff --git a/sw/source/core/text/txtfld.cxx b/sw/source/core/text/txtfld.cxx
index e81ec0e36232..4eac15a4848a 100644
--- a/sw/source/core/text/txtfld.cxx
+++ b/sw/source/core/text/txtfld.cxx
@@ -53,6 +53,7 @@
 #include <redline.hxx>
 #include <sfx2/docfile.hxx>
 #include <svl/itemiter.hxx>
+#include <svl/whiter.hxx>
 #include <editeng/colritem.hxx>
 #include <editeng/udlnitem.hxx>
 #include <editeng/crossedoutitem.hxx>
@@ -462,9 +463,34 @@ static void checkApplyParagraphMarkFormatToNumbering(SwFont* pNumFnt, SwTextForm
     {
         std::unique_ptr<SfxItemSet> const pCleanedSet = pSet->Clone();
 
+        if (pCleanedSet->HasItem(RES_TXTATR_CHARFMT))
+        {
+            // Insert attributes of referenced char format into current set
+            const SwFormatCharFormat& rCharFormat = pCleanedSet->Get(RES_TXTATR_CHARFMT);
+            const SwAttrSet& rStyleAttrs = static_cast<const SwCharFormat *>(rCharFormat.GetRegisteredIn())->GetAttrSet();
+            SfxWhichIter aIter(rStyleAttrs);
+            sal_uInt16 nWhich = aIter.FirstWhich();
+            while (nWhich)
+            {
+                if (!SwTextNode::IsIgnoredCharFormatForNumbering(nWhich)
+                    && !pCleanedSet->HasItem(nWhich)
+                    && !(pFormat && pFormat->HasItem(nWhich)) )
+                {
+                    // Copy from parent sets only allowed items which will not overwrite
+                    // values explicitly defined in current set (pCleanedSet) or in pFormat
+                    const SfxPoolItem* pItem = rStyleAttrs.GetItem(nWhich, true);
+                    pCleanedSet->Put(*pItem);
+                }
+                nWhich = aIter.NextWhich();
+            }
+
+            // It is not required here anymore, all referenced items are inserted
+            pCleanedSet->ClearItem(RES_TXTATR_CHARFMT);
+        };
+
         SfxItemIter aIter(*pSet);
         const SfxPoolItem* pItem = aIter.GetCurItem();
-        do
+        while (pItem)
         {
             if (pItem->Which() != RES_CHRATR_BACKGROUND)
             {
@@ -473,9 +499,8 @@ static void checkApplyParagraphMarkFormatToNumbering(SwFont* pNumFnt, SwTextForm
                 else if (pFormat && pFormat->HasItem(pItem->Which()))
                     pCleanedSet->ClearItem(pItem->Which());
             }
-
             pItem = aIter.NextItem();
-        } while (pItem);
+        };
         pNumFnt->SetDiffFnt(pCleanedSet.get(), pIDSA);
     }
 }
diff --git a/sw/source/core/unocore/unoobj.cxx b/sw/source/core/unocore/unoobj.cxx
index 5b6a296c6065..a7046660851a 100644
--- a/sw/source/core/unocore/unoobj.cxx
+++ b/sw/source/core/unocore/unoobj.cxx
@@ -519,7 +519,10 @@ SwUnoCursorHelper::SetCursorPropertyValue(
                     // TODO create own map for this, it contains UNO_NAME_DISPLAY_NAME? or make property readable so ODF export can map it to a automatic style?
                     SfxItemPropertySet const& rPropSet(*aSwMapProvider.GetPropertySet(PROPERTY_MAP_CHAR_AUTO_STYLE));
                     SfxItemPropertyMap const& rMap(rPropSet.getPropertyMap());
-                    SfxItemSet items{rPam.GetDoc()->GetAttrPool(), aCharAutoFormatSetRange};
+                    SfxItemSet items( rPam.GetDoc()->GetAttrPool(),
+                        svl::Items<RES_CHRATR_BEGIN, RES_CHRATR_END-1,
+                            RES_TXTATR_CHARFMT, RES_TXTATR_CHARFMT,
+                            RES_UNKNOWNATR_BEGIN, RES_UNKNOWNATR_END-1>{} );
 
                     for (beans::NamedValue const & prop : std::as_const(props))
                     {
@@ -527,6 +530,11 @@ SwUnoCursorHelper::SetCursorPropertyValue(
                             rMap.getByName(prop.Name);
                         if (!pEntry)
                         {
+                            if (prop.Name == "CharStyleName")
+                            {
+                                lcl_setCharStyle(rPam.GetDoc(), prop.Value, items);
+                                continue;
+                            }
                             throw beans::UnknownPropertyException(
                                 "Unknown property: " + prop.Name);
                         }
@@ -540,6 +548,7 @@ SwUnoCursorHelper::SetCursorPropertyValue(
 
                     SwFormatAutoFormat item(RES_PARATR_LIST_AUTOFMT);
                     // TODO: for ODF export we'd need to add it to the autostyle pool
+                    // note: paragraph auto styles have ParaStyleName property for the parent style; character auto styles currently do not because there's a separate hint, but for this it would be a good way to add it in order to export it as style:parent-style-name, see XMLTextParagraphExport::Add()
                     item.SetStyleHandle(std::make_shared<SfxItemSet>(items));
                     pTextNd->SetAttr(item);
                 }
diff --git a/sw/source/filter/ww8/wrtw8nds.cxx b/sw/source/filter/ww8/wrtw8nds.cxx
index b520279b7345..8dda14c16677 100644
--- a/sw/source/filter/ww8/wrtw8nds.cxx
+++ b/sw/source/filter/ww8/wrtw8nds.cxx
@@ -3094,9 +3094,8 @@ void MSWordExportBase::OutputTextNode( SwTextNode& rNode )
         {
             aParagraphMarkerProperties.Put(*pSet);
             bCharFormatOnly = false;
-            // TODO: still need to check for a RES_TXTATR_CHARFMT hint...
         }
-        if (const SwpHints* pTextAttrs = rNode.GetpSwpHints())
+        else if (const SwpHints* pTextAttrs = rNode.GetpSwpHints())
         {
             for( size_t i = 0; i < pTextAttrs->Count(); ++i )
             {
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index a52151a60c0e..61b3becc0c68 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -1602,9 +1602,7 @@ void DomainMapper_Impl::finishParagraph( const PropertyMapPtr& pPropertyMap, con
                 {
                     // this condition isn't ideal but as it happens all
                     // RES_CHRATR_* have names that start with "Char"
-                    if (it->Name.startsWith("Char")
-// TODO testParagraphMark *wants* this but it's some effort to create a real SwFormatCharFormat...
-                        && !it->Name.startsWith("CharStyleName"))
+                    if (it->Name.startsWith("Char"))
                     {
                         charProperties.emplace_back(it->Name, it->Value);
                         // as testN793262 demonstrates, font size in rPr must


More information about the Libreoffice-commits mailing list