sw/CppunitTest_sw_odfimport.mk                     |   41 ------------
 sw/qa/extras/odfimport/data/vmerge-cell-border.odt |binary
 sw/qa/extras/odfimport/odfimport.cxx               |   36 ++++++++++
 sw/source/filter/xml/xmltble.cxx                   |   11 +++
 sw/source/filter/xml/xmltbli.cxx                   |   71 ++++++++++++++++++++-
 sw/source/filter/xml/xmltbli.hxx                   |   10 ++
 6 files changed, 129 insertions(+), 40 deletions(-)

New commits:
commit 4898eab739460448727da48d47f8837718317b70
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Fri Mar 19 16:27:28 2021 +0100
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Mon Mar 22 10:31:00 2021 +0100

    ODT export: handle style name of covered cells
    
    This is the export side of commit
    1001dbaef4dec2b51c25ed8343bab6910f1219e1 (ODT import: handle style name
    of covered cells, 2021-03-19). We already exported the autostyle, but
    <table:covered-table-cell> did not refer to it.
    
    This is useful when the covering and the covered table cells have
    different border settings.
    
    (cherry picked from commit 6fa6e19fdca29752492a5230b2a948075a347c87)
    
    Change-Id: I7773903fa62f53686f000473f7a03c68dd77602a

diff --git a/sw/CppunitTest_sw_odfimport.mk b/sw/CppunitTest_sw_odfimport.mk
index c3a3b535c8a4..80549d1c32e8 100644
--- a/sw/CppunitTest_sw_odfimport.mk
+++ b/sw/CppunitTest_sw_odfimport.mk
@@ -54,44 +54,7 @@ $(eval $(call gb_CppunitTest_use_api,sw_odfimport,\
 $(eval $(call gb_CppunitTest_use_ure,sw_odfimport))
 $(eval $(call gb_CppunitTest_use_vcl,sw_odfimport))
 
-$(eval $(call gb_CppunitTest_use_components,sw_odfimport,\
-       basic/util/sb \
-    comphelper/util/comphelp \
-    configmgr/source/configmgr \
-       embeddedobj/util/embobj \
-    filter/source/config/cache/filterconfig1 \
-    filter/source/storagefilterdetect/storagefd \
-       filter/source/odfflatxml/odfflatxml \
-       filter/source/xmlfilterdetect/xmlfd \
-       filter/source/xmlfilteradaptor/xmlfa \
-    framework/util/fwk \
-    i18npool/util/i18npool \
-       lingucomponent/source/languageguessing/guesslang \
-    linguistic/source/lng \
-    package/util/package2 \
-    package/source/xstor/xstor \
-    sw/util/sw \
-    sw/util/swd \
-    sax/source/expatwrap/expwrap \
-    sfx2/util/sfx \
-    svl/source/fsstor/fsstorage \
-    svtools/util/svt \
-    toolkit/util/tk \
-    ucb/source/core/ucb1 \
-    ucb/source/ucp/file/ucpfile1 \
-    unotools/util/utl \
-    unoxml/source/service/unoxml \
-    uui/util/uui \
-    $(if $(filter-out MACOSX WNT,$(OS)), \
-               $(if $(DISABLE_GUI),, \
-                       vcl/vcl.unx \
-               ) \
-    ) \
-       $(if $(filter DESKTOP,$(BUILD_TYPE)),xmlhelp/util/ucpchelp1) \
-       vcl/vcl.common \
-    xmloff/util/xo \
-    svgio/svgio \
-))
+$(eval $(call gb_CppunitTest_use_rdb,sw_odfimport,services))
 
 $(eval $(call gb_CppunitTest_use_configuration,sw_odfimport))
 
diff --git a/sw/qa/extras/odfimport/odfimport.cxx 
b/sw/qa/extras/odfimport/odfimport.cxx
index 3aea453dfb2e..40369b6e4609 100644
--- a/sw/qa/extras/odfimport/odfimport.cxx
+++ b/sw/qa/extras/odfimport/odfimport.cxx
@@ -959,6 +959,16 @@ DECLARE_ODFIMPORT_TEST(testVerticallyMergedCellBorder, 
"vmerge-cell-border.odt")
     // right border, even if <table:covered-table-cell table:style-name="..."> 
explicitly disabled
     // it.
     CPPUNIT_ASSERT(!rA2Set.GetBox().GetRight());
+
+    // Given this document model, when exporting to ODT:
+    save("writer8", maTempFile);
+    mbExported = true;
+
+    // Then make sure the covered cell has a style.
+    xmlDocPtr pXmlSettings = parseExport("content.xml");
+    // Without the accompanying fix in place, this test would have failed with:
+    // - In <...>, XPath '//table:covered-table-cell' no attribute 
'style-name' exist
+    assertXPath(pXmlSettings, "//table:covered-table-cell", "style-name", 
"Table1.A2");
 }
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/source/filter/xml/xmltble.cxx b/sw/source/filter/xml/xmltble.cxx
index 58ef026cf7e1..237d43d0ac6b 100644
--- a/sw/source/filter/xml/xmltble.cxx
+++ b/sw/source/filter/xml/xmltble.cxx
@@ -918,6 +918,17 @@ void SwXMLExport::ExportTableLine( const SwTableLine& 
rLine,
             const long nRowSpan = pBox->getRowSpan();
             if( nRowSpan < 1 )
             {
+                // Export style of covered cell, it includes border 
information.
+                const SwFrameFormat* pFormat = pBox->GetFrameFormat();
+                if (pFormat)
+                {
+                    const OUString& sName = pFormat->GetName();
+                    if (!sName.isEmpty())
+                    {
+                        AddAttribute(XML_NAMESPACE_TABLE, XML_STYLE_NAME, 
EncodeStyleName(sName));
+                    }
+                }
+
                 SvXMLElementExport aElem2( *this, rTableInfo.GetPrefix(),
                                           XML_COVERED_TABLE_CELL, true,
                                           false );
commit 60e43bafe25a8352b1658b0e12c855a48db4d2a2
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Fri Mar 19 08:42:35 2021 +0100
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Mon Mar 22 10:28:00 2021 +0100

    ODT import: handle style name of covered cells
    
    Similar to commit 66ac8e60896f6306bed8fbb34606fd14474f19ce (sw: fix
    unwanted long vertical border around vertically merged Word cell,
    2021-03-04), but that one was for the DOCX import / rendering.
    
    (cherry picked from commit 1001dbaef4dec2b51c25ed8343bab6910f1219e1)
    
    Conflicts:
            sw/qa/extras/odfimport/odfimport.cxx
            sw/source/filter/xml/xmltbli.cxx
    
    Change-Id: I394a4f062544a9774b9b40ec757cb37e72220561

diff --git a/sw/CppunitTest_sw_odfimport.mk b/sw/CppunitTest_sw_odfimport.mk
index bf227939f074..c3a3b535c8a4 100644
--- a/sw/CppunitTest_sw_odfimport.mk
+++ b/sw/CppunitTest_sw_odfimport.mk
@@ -17,11 +17,13 @@ $(eval $(call 
gb_CppunitTest_add_exception_objects,sw_odfimport, \
 
 $(eval $(call gb_CppunitTest_use_libraries,sw_odfimport, \
     comphelper \
+    editeng \
     cppu \
     cppuhelper \
     sal \
        svt \
        sfx \
+       svl \
        sw \
     test \
     unotest \
diff --git a/sw/qa/extras/odfimport/data/vmerge-cell-border.odt 
b/sw/qa/extras/odfimport/data/vmerge-cell-border.odt
new file mode 100644
index 000000000000..bf387bcb183e
Binary files /dev/null and b/sw/qa/extras/odfimport/data/vmerge-cell-border.odt 
differ
diff --git a/sw/qa/extras/odfimport/odfimport.cxx 
b/sw/qa/extras/odfimport/odfimport.cxx
index 4df20d9e42a8..3aea453dfb2e 100644
--- a/sw/qa/extras/odfimport/odfimport.cxx
+++ b/sw/qa/extras/odfimport/odfimport.cxx
@@ -22,6 +22,7 @@
 #include <com/sun/star/text/XTextTable.hpp>
 #include <com/sun/star/text/PageNumberType.hpp>
 #include <com/sun/star/text/VertOrientation.hpp>
+#include <editeng/boxitem.hxx>
 
 #include <IDocumentSettingAccess.hxx>
 #include <wrtsh.hxx>
@@ -31,6 +32,7 @@
 #include <edtwin.hxx>
 #include <olmenu.hxx>
 #include <cmdid.h>
+#include <frmatr.hxx>
 
 typedef std::map<OUString, css::uno::Sequence< css::table::BorderLine> > 
AllBordersMap;
 typedef std::pair<OUString, css::uno::Sequence< css::table::BorderLine> > 
StringSequencePair;
@@ -935,5 +937,29 @@ DECLARE_ODFIMPORT_TEST(testTdf113289, "tdf113289.odt")
 }
 
 
+DECLARE_ODFIMPORT_TEST(testVerticallyMergedCellBorder, 
"vmerge-cell-border.odt")
+{
+    // Given a document with two cells, vertically merged, when loading the 
document:
+    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
+    CPPUNIT_ASSERT(pTextDoc);
+    SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+
+    // Then make sure that the first cell has a right border while the second 
has no right border:
+    SwDocShell* pDocShell = pDoc->GetDocShell();
+    SwWrtShell* pWrtShell = pDocShell->GetWrtShell();
+    pWrtShell->Down(/*bSelect=*/false, /*nCount=*/1);
+    SwShellCursor* pShellCursor = pWrtShell->getShellCursor(/*bBlock=*/false);
+    SwStartNode* pA1 = 
pShellCursor->Start()->nNode.GetNode().StartOfSectionNode();
+    const SwAttrSet& rA1Set = 
pA1->GetTableBox()->GetFrameFormat()->GetAttrSet();
+    CPPUNIT_ASSERT(rA1Set.GetBox().GetRight());
+    SwNodeIndex aA2(*pA1->EndOfSectionNode(), 1);
+    const SwAttrSet& rA2Set = 
aA2.GetNode().GetTableBox()->GetFrameFormat()->GetAttrSet();
+
+    // Without the accompanying fix in place, this test would have failed, as 
the A2 cell also had a
+    // right border, even if <table:covered-table-cell table:style-name="..."> 
explicitly disabled
+    // it.
+    CPPUNIT_ASSERT(!rA2Set.GetBox().GetRight());
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/xml/xmltbli.cxx b/sw/source/filter/xml/xmltbli.cxx
index 2207d929a9c4..ed73304a7e5d 100644
--- a/sw/source/filter/xml/xmltbli.cxx
+++ b/sw/source/filter/xml/xmltbli.cxx
@@ -218,6 +218,7 @@ public:
     sal_uInt32 GetRowSpan() const { return nRowSpan; }
     void SetRowSpan( sal_uInt32 nSet ) { nRowSpan = nSet; }
     sal_uInt32 GetColSpan() const { return nColSpan; }
+    void SetStyleName(const OUString& rStyleName) { aStyleName = rStyleName; }
     const OUString& GetStyleName() const { return aStyleName; }
     const OUString& GetFormula() const { return sFormula; }
     double GetValue() const { return dValue; }
@@ -436,6 +437,47 @@ public:
     SwXMLImport& GetSwImport() { return 
static_cast<SwXMLImport&>(GetImport()); }
 };
 
+/// Handles <table:covered-table-cell>.
+class SwXMLCoveredTableCellContext : public SvXMLImportContext
+{
+public:
+    SwXMLCoveredTableCellContext(SwXMLImport& rImport,
+                                 const Reference<xml::sax::XAttributeList>& 
xAttrList,
+                                 SwXMLTableContext& rTable);
+};
+
+SwXMLCoveredTableCellContext::SwXMLCoveredTableCellContext(
+    SwXMLImport& rImport, const Reference<xml::sax::XAttributeList>& xAttrList,
+    SwXMLTableContext& rTable)
+    : SvXMLImportContext(rImport)
+{
+    OUString aStyleName;
+    sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
+    for( sal_Int16 i=0; i < nAttrCount; i++ )
+    {
+        const OUString& rAttrName = xAttrList->getNameByIndex( i );
+
+        OUString aLocalName;
+        const sal_uInt16 nPrefix =
+            GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
+                                                            &aLocalName );
+        const OUString& rValue = xAttrList->getValueByIndex( i );
+        const SvXMLTokenMap& rTokenMap =
+            rImport.GetTableCellAttrTokenMap();
+        switch( rTokenMap.Get( nPrefix, aLocalName ) )
+        {
+            case XML_TOK_TABLE_STYLE_NAME:
+                aStyleName = rValue;
+                break;
+        }
+    }
+
+    if (!aStyleName.isEmpty())
+    {
+        rTable.InsertCoveredCell(aStyleName);
+    }
+}
+
 SwXMLTableCellContext_Impl::SwXMLTableCellContext_Impl(
         SwXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLName,
         const Reference< xml::sax::XAttributeList > & xAttrList,
@@ -966,8 +1008,17 @@ SvXMLImportContextRef 
SwXMLTableRowContext_Impl::CreateChildContext(
                                                            GetTable() );
         }
         else if( IsXMLToken( rLocalName, XML_COVERED_TABLE_CELL ) )
-            pContext = new SvXMLImportContext( GetImport(), nPrefix,
-                                               rLocalName );
+        {
+            if (GetTable()->IsValid() && 
GetTable()->IsInsertCoveredCellPossible())
+            {
+                pContext = new SwXMLCoveredTableCellContext(GetSwImport(), 
xAttrList, *GetTable());
+            }
+            else
+            {
+                pContext = new SvXMLImportContext( GetImport(), nPrefix,
+                                                   rLocalName );
+            }
+        }
     }
 
     if( !pContext )
@@ -1262,6 +1313,7 @@ SwXMLTableContext::SwXMLTableContext( SwXMLImport& 
rImport,
     m_nHeaderRows( 0 ),
     m_nCurRow( 0 ),
     m_nCurCol( 0 ),
+    m_nNonMergedCurCol( 0 ),
     m_nWidth( 0 )
 {
     OUString aName;
@@ -1402,6 +1454,7 @@ SwXMLTableContext::SwXMLTableContext( SwXMLImport& 
rImport,
     m_nHeaderRows( 0 ),
     m_nCurRow( 0 ),
     m_nCurCol( 0 ),
+    m_nNonMergedCurCol( 0 ),
     m_nWidth( 0 )
 {
 }
@@ -1634,10 +1687,23 @@ void SwXMLTableContext::InsertCell( const OUString& 
rStyleName,
 
     // Set current col to the next (free) column
     m_nCurCol = nColsReq;
+    m_nNonMergedCurCol = nColsReq;
     while( m_nCurCol<GetColumnCount() && 
GetCell(m_nCurRow,m_nCurCol)->IsUsed() )
         m_nCurCol++;
 }
 
+void SwXMLTableContext::InsertCoveredCell(const OUString& rStyleName)
+{
+    SwXMLTableCell_Impl* pCell = GetCell(m_nCurRow, m_nNonMergedCurCol);
+    ++m_nNonMergedCurCol;
+    if (!pCell)
+    {
+        return;
+    }
+
+    pCell->SetStyleName(rStyleName);
+}
+
 void SwXMLTableContext::InsertRow( const OUString& rStyleName,
                                    const OUString& rDfltCellStyleName,
                                    bool bInHead,
@@ -1669,6 +1735,7 @@ void SwXMLTableContext::InsertRow( const OUString& 
rStyleName,
 
     // We start at the first column ...
     m_nCurCol=0;
+    m_nNonMergedCurCol = 0;
 
     // ... but this cell may be occupied already.
     while( m_nCurCol<GetColumnCount() && 
GetCell(m_nCurRow,m_nCurCol)->IsUsed() )
diff --git a/sw/source/filter/xml/xmltbli.hxx b/sw/source/filter/xml/xmltbli.hxx
index 157be580f67f..a2e39f0d2c47 100644
--- a/sw/source/filter/xml/xmltbli.hxx
+++ b/sw/source/filter/xml/xmltbli.hxx
@@ -90,6 +90,8 @@ class SwXMLTableContext : public XMLTextTableContext
     sal_uInt16              m_nHeaderRows;
     sal_uInt32          m_nCurRow;
     sal_uInt32          m_nCurCol;
+    /// Same as m_nCurCol, but not incremented multiple times for table cells 
with row span.
+    sal_uInt32 m_nNonMergedCurCol;
     sal_Int32           m_nWidth;
 
     // The maximum table width (i.e., maximum value for m_nWidth); must be >= 
MINLAY and must also
@@ -156,6 +158,10 @@ public:
     inline sal_uInt32 GetColumnCount() const;
 
     bool IsInsertCellPossible() const { return m_nCurCol < GetColumnCount(); }
+
+    /// Determines if it's OK to insert a covered cell, given the total column 
count.
+    bool IsInsertCoveredCellPossible() const { return m_nNonMergedCurCol < 
GetColumnCount(); }
+
     bool IsInsertColPossible() const { return m_nCurCol < USHRT_MAX; }
     bool IsInsertRowPossible() const { return m_nCurRow < USHRT_MAX; }
     bool IsValid() const { return m_pTableNode != nullptr; }
@@ -170,6 +176,10 @@ public:
                      bool bHasValue = false,
                      double fValue = 0.0,
                      OUString const*const pStringValue = nullptr);
+
+    /// Sets formatting of an already created covered cell.
+    void InsertCoveredCell(const OUString& rStyleName);
+
     void InsertRow( const OUString& rStyleName,
                     const OUString& rDfltCellStyleName,
                     bool bInHead,
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to