sw/qa/extras/ooxmlexport/data/tdf130610_bold_in_2_styles.ott |binary
 sw/qa/extras/ooxmlexport/ooxmlexport14.cxx                   |   29 ++++
 sw/source/filter/ww8/wrtw8nds.cxx                            |   65 +++++++++++
 sw/source/filter/ww8/wrtww8.hxx                              |    2 
 4 files changed, 96 insertions(+)

New commits:
commit 0c6ef9ba325fc37f325a2848e013852d2780a5ca
Author:     Serge Krot <serge.k...@cib.de>
AuthorDate: Tue Feb 11 16:04:26 2020 +0100
Commit:     Thorsten Behrens <thorsten.behr...@cib.de>
CommitDate: Wed Feb 12 22:24:19 2020 +0100

    tdf#130610 docx export: handle bold as toggle properties
    
    Change-Id: I4c60b7eab6430a64ea1c8bcf40d0036d0b38516f
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/88460
    Reviewed-by: Michael Stahl <michael.st...@cib.de>
    Tested-by: Jenkins

diff --git a/sw/qa/extras/ooxmlexport/data/tdf130610_bold_in_2_styles.ott 
b/sw/qa/extras/ooxmlexport/data/tdf130610_bold_in_2_styles.ott
new file mode 100755
index 000000000000..35937d9a8aa3
Binary files /dev/null and 
b/sw/qa/extras/ooxmlexport/data/tdf130610_bold_in_2_styles.ott differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx
index 3bdae52c4d65..9fce4ad0e091 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx
@@ -20,6 +20,7 @@
 #include <com/sun/star/text/TableColumnSeparator.hpp>
 #include <com/sun/star/text/XDocumentIndex.hpp>
 #include <com/sun/star/text/RelOrientation.hpp>
+#include <com/sun/star/awt/FontWeight.hpp>
 #include <com/sun/star/style/LineSpacing.hpp>
 #include <com/sun/star/style/LineSpacingMode.hpp>
 #include <com/sun/star/text/XDependentTextField.hpp>
@@ -107,6 +108,34 @@ DECLARE_OOXMLEXPORT_TEST(testTdf87569d, 
"tdf87569_drawingml.docx")
                                  text::RelOrientation::FRAME, nValue);
 }
 
+DECLARE_OOXMLEXPORT_TEST(testTdf130610, "tdf130610_bold_in_2_styles.ott")
+{
+    // check character properties
+    {
+        uno::Reference<beans::XPropertySet> xStyle(
+            getStyles("CharacterStyles")->getByName("WollMuxRoemischeZiffer"),
+            uno::UNO_QUERY);
+        CPPUNIT_ASSERT_EQUAL_MESSAGE("Bold", awt::FontWeight::BOLD, 
getProperty<float>(xStyle, "CharWeight"));
+    }
+
+    // check paragraph properties
+    {
+        uno::Reference<beans::XPropertySet> xStyle(
+            getStyles("ParagraphStyles")->getByName("WollMuxVerfuegungspunkt"),
+            uno::UNO_QUERY);
+        CPPUNIT_ASSERT_EQUAL_MESSAGE("Bold", awt::FontWeight::BOLD, 
getProperty<float>(xStyle, "CharWeight"));
+    }
+
+    // check inline text properties
+    {
+        xmlDocPtr pXmlDoc =parseExport("word/document.xml");
+        if (pXmlDoc)
+        {
+            assertXPath(pXmlDoc, "/w:document/w:body/w:p[2]/w:r/w:rPr/w:b");
+        }
+    }
+}
+
 DECLARE_OOXMLEXPORT_TEST(testTdf120315, "tdf120315.docx")
 {
     // tdf#120315 cells of the second column weren't vertically merged
diff --git a/sw/source/filter/ww8/wrtw8nds.cxx 
b/sw/source/filter/ww8/wrtw8nds.cxx
index d06072c6de5a..70a855efc7ed 100644
--- a/sw/source/filter/ww8/wrtw8nds.cxx
+++ b/sw/source/filter/ww8/wrtw8nds.cxx
@@ -39,6 +39,7 @@
 #include <editeng/formatbreakitem.hxx>
 #include <editeng/frmdiritem.hxx>
 #include <editeng/tstpitem.hxx>
+#include <editeng/wghtitem.hxx>
 #include <svl/grabbagitem.hxx>
 #include <svl/urihelper.hxx>
 #include <svl/whiter.hxx>
@@ -466,6 +467,12 @@ void SwWW8AttrIter::OutAttr( sal_Int32 nSwPos, bool 
bWriteCombChars)
     if ( pCharFormatItem )
         ClearOverridesFromSet( *pCharFormatItem, aExportSet );
 
+    // check toggle properties in DOCX output
+    {
+        SvxWeightItem aBoldProperty(WEIGHT_BOLD, RES_CHRATR_WEIGHT);
+        handleToggleProperty(aExportSet, pCharFormatItem, RES_CHRATR_WEIGHT, 
&aBoldProperty);
+    }
+
     // tdf#113790: AutoFormat style overwrites char style, so remove all
     // elements from CHARFMT grab bag which are set in AUTOFMT grab bag
     if (const SfxGrabBagItem *pAutoFmtGrabBag = dynamic_cast<const 
SfxGrabBagItem*>(pGrabBag))
@@ -528,6 +535,64 @@ void SwWW8AttrIter::OutAttr( sal_Int32 nSwPos, bool 
bWriteCombChars)
         m_rExport.AttrOutput().OutputItem( *pGrabBag );
 }
 
+// Toggle Properties
+//
+// If the value of the toggle property appears at multiple levels of the style 
hierarchy (17.7.2), their
+// effective values shall be combined as follows:
+//
+//     value_{effective} = val_{table} XOR val_{paragraph} XOR val_{character}
+//
+// If the value specified by the document defaults is true, the effective 
value is true.
+// Otherwise, the values are combined by a Boolean XOR as follows:
+// i.e., the effective value to be applied to the content shall be true if its 
effective value is true for
+// an odd number of levels of the style hierarchy.
+//
+// To prevent such logic inside output, it is required to write inline w:b 
token on content level.
+void SwWW8AttrIter::handleToggleProperty(SfxItemSet& rExportSet, const 
SwFormatCharFormat* pCharFormatItem,
+    sal_uInt16 nWhich, const SfxPoolItem* pValue)
+{
+    if (!rExportSet.HasItem(nWhich) && pValue)
+    {
+        bool hasPropertyInCharStyle = false;
+        bool hasPropertyInParaStyle = false;
+
+        // get bold flag from specified character style
+        if (pCharFormatItem)
+        {
+            if (const SwCharFormat* pCharFormat = 
pCharFormatItem->GetCharFormat())
+            {
+                const SfxPoolItem* pItem = nullptr;
+                if (pCharFormat->GetAttrSet().HasItem(nWhich, &pItem))
+                {
+                    hasPropertyInCharStyle = (*pItem == *pValue);
+                }
+            }
+        }
+
+        // get bold flag from specified paragraph style
+        {
+            SwTextFormatColl& rTextColl = static_cast<SwTextFormatColl&>( 
rNd.GetAnyFormatColl() );
+            sal_uInt16 nStyle = m_rExport.m_pStyles->GetSlot( &rTextColl );
+            nStyle = ( nStyle != 0xfff ) ? nStyle : 0;
+            const SwFormat* pFormat = m_rExport.m_pStyles->GetSwFormat(nStyle);
+            if (pFormat)
+            {
+                const SfxPoolItem* pItem = nullptr;
+                if (pFormat->GetAttrSet().HasItem(nWhich, &pItem))
+                {
+                    hasPropertyInParaStyle = (*pItem == *pValue);
+                }
+            }
+        }
+
+        // add inline property
+        if (hasPropertyInCharStyle && hasPropertyInParaStyle)
+        {
+            rExportSet.Put(*pValue);
+        }
+    }
+}
+
 bool SwWW8AttrIter::IsWatermarkFrame()
 {
     if (maFlyFrames.size() != 1)
diff --git a/sw/source/filter/ww8/wrtww8.hxx b/sw/source/filter/ww8/wrtww8.hxx
index 5dfd181f2135..6ca1eb7d8717 100644
--- a/sw/source/filter/ww8/wrtww8.hxx
+++ b/sw/source/filter/ww8/wrtww8.hxx
@@ -1526,6 +1526,8 @@ private:
 
     SwWW8AttrIter(const SwWW8AttrIter&) = delete;
     SwWW8AttrIter& operator=(const SwWW8AttrIter&) = delete;
+
+    void handleToggleProperty(SfxItemSet& rExportSet, const 
SwFormatCharFormat* pCharFormatItem, sal_uInt16 nWhich, const SfxPoolItem* 
pValue);
 public:
     SwWW8AttrIter( MSWordExportBase& rWr, const SwTextNode& rNd );
 
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to