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                    |   30 +++++++++++-
 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(+), 8 deletions(-)

New commits:
commit 6c05cd186457c3356e9daf5fcddae77ae4260f8e
Author:     Vasily Melenchuk <vasily.melenc...@cib.de>
AuthorDate: Tue Aug 18 17:59:26 2020 +0200
Commit:     Michael Stahl <michael.st...@cib.de>
CommitDate: Fri Aug 28 20:25:32 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.st...@cib.de>
    Reviewed-by: Michael Stahl <michael.st...@cib.de>
    (cherry picked from commit c77b9c349f0a48392d8cb7a49532844b2cafb5ba)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/101560
    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 2942b74dd194..a20a93c93637 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/";
@@ -33,6 +34,58 @@ DECLARE_OOXMLEXPORT_TEST(testTdf133334_followPgStyle, 
"tdf133334_followPgStyle.o
     CPPUNIT_ASSERT_EQUAL(2, getPages());
 }
 
+DECLARE_OOXMLIMPORT_TEST(testTdf131801, "tdf131801.docx")
+{
+    CPPUNIT_ASSERT_EQUAL(1, getPages());
+
+    xmlDocPtr 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"));
+
+    xmlDocPtr 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 3870d7334afe..7cd6303ecef1 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>
@@ -402,6 +403,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 42d852a1e41e..ffa1b11a5931 100644
--- a/sw/source/core/text/txtfld.cxx
+++ b/sw/source/core/text/txtfld.cxx
@@ -57,6 +57,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>
@@ -466,9 +467,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 (SwTextNode::IsIgnoredCharFormatForNumbering(pItem->Which()))
                 pCleanedSet->ClearItem(pItem->Which());
@@ -476,7 +502,7 @@ static void 
checkApplyParagraphMarkFormatToNumbering(SwFont* pNumFnt, SwTextForm
                 pCleanedSet->ClearItem(pItem->Which());
 
             pItem = aIter.NextItem();
-        } while (pItem);
+        };
         // Highlightcolor also needed to be untouched, but we can't have that 
just by clearing the item
         Color nSaveHighlight = pNumFnt->GetHighlightColor();
         pNumFnt->SetDiffFnt(pCleanedSet.get(), pIDSA);
diff --git a/sw/source/core/unocore/unoobj.cxx 
b/sw/source/core/unocore/unoobj.cxx
index dc47a6d5dac2..1f8b4d02edfd 100644
--- a/sw/source/core/unocore/unoobj.cxx
+++ b/sw/source/core/unocore/unoobj.cxx
@@ -559,7 +559,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 (sal_Int32 i = 0; i < props.getLength(); ++i)
                     {
@@ -567,6 +570,11 @@ SwUnoCursorHelper::SetCursorPropertyValue(
                             rMap.getByName(props[i].Name);
                         if (!pEntry)
                         {
+                            if (props[i].Name == "CharStyleName")
+                            {
+                                lcl_setCharStyle(rPam.GetDoc(), 
props[i].Value, items);
+                                continue;
+                            }
                             throw beans::UnknownPropertyException(
                                 "Unknown property: " + props[i].Name);
                         }
@@ -580,6 +588,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 36026312a332..74783f3e7110 100644
--- a/sw/source/filter/ww8/wrtw8nds.cxx
+++ b/sw/source/filter/ww8/wrtw8nds.cxx
@@ -3097,9 +3097,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 3b95e006ffad..329999ca18ce 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -1545,9 +1545,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
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to