[Libreoffice-commits] core.git: sw/qa writerfilter/source

Adam Co rattles2013 at gmail.com
Fri Jun 28 02:44:08 PDT 2013


 sw/qa/extras/ooxmlimport/data/table-auto-column-fixed-size.docx |binary
 sw/qa/extras/ooxmlimport/ooxmlimport.cxx                        |   12 ++
 writerfilter/source/dmapper/DomainMapperTableManager.cxx        |   44 +++++++++-
 writerfilter/source/dmapper/DomainMapperTableManager.hxx        |    1 
 4 files changed, 55 insertions(+), 2 deletions(-)

New commits:
commit 74c5ed19f430327988194cdcd6bdff09591a93fa
Author: Adam Co <rattles2013 at gmail.com>
Date:   Wed Jun 26 11:08:56 2013 +0300

    DOCX import fix for table with auto size
    
    Change-Id: Ic86f4f142e579bdef3e954492e1c1e382a545739
    Reviewed-on: https://gerrit.libreoffice.org/4496

diff --git a/sw/qa/extras/ooxmlimport/data/table-auto-column-fixed-size.docx b/sw/qa/extras/ooxmlimport/data/table-auto-column-fixed-size.docx
new file mode 100644
index 0000000..557edcb
Binary files /dev/null and b/sw/qa/extras/ooxmlimport/data/table-auto-column-fixed-size.docx differ
diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
index 4f23d92..985bd66 100644
--- a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
+++ b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
@@ -121,6 +121,7 @@ public:
     void testN820788();
     void testN820504();
     void testFdo43641();
+    void testTableAutoColumnFixedSize();
 
     CPPUNIT_TEST_SUITE(Test);
 #if !defined(MACOSX) && !defined(WNT)
@@ -208,6 +209,7 @@ void Test::run()
         {"n820788.docx", &Test::testN820788},
         {"n820504.docx", &Test::testN820504},
         {"fdo43641.docx", &Test::testFdo43641},
+        {"table-auto-column-fixed-size.docx", &Test::testTableAutoColumnFixedSize},
     };
     header();
     for (unsigned int i = 0; i < SAL_N_ELEMENTS(aMethods); ++i)
@@ -1462,6 +1464,16 @@ void Test::testFdo43641()
     CPPUNIT_ASSERT_EQUAL(sal_Int32(EMU_TO_MM100(928694)), xLine->getSize().Width);
 }
 
+void Test::testTableAutoColumnFixedSize()
+{
+    uno::Reference<text::XTextTablesSupplier> xTablesSupplier(mxComponent, uno::UNO_QUERY);
+    uno::Reference<container::XIndexAccess> xTables(xTablesSupplier->getTextTables(), uno::UNO_QUERY);
+    uno::Reference<text::XTextTable> xTextTable(xTables->getByIndex(0), uno::UNO_QUERY);
+
+    // Width was not recognized during import when table size was 'auto'
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(TWIP_TO_MM100(3996)), getProperty<sal_Int32>(xTextTable, "Width"));
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(Test);
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/writerfilter/source/dmapper/DomainMapperTableManager.cxx b/writerfilter/source/dmapper/DomainMapperTableManager.cxx
index 48d1e31..6aabf59 100644
--- a/writerfilter/source/dmapper/DomainMapperTableManager.cxx
+++ b/writerfilter/source/dmapper/DomainMapperTableManager.cxx
@@ -57,6 +57,7 @@ DomainMapperTableManager::DomainMapperTableManager(bool bOOXML) :
     m_bRowSizeTypeInserted(false),
     m_bTableSizeTypeInserted(false),
     m_nLayoutType(0),
+    m_nMaxFixedWidth(0),
     m_pTablePropsHandler( new TablePropertiesHandler( bOOXML ) )
 {
     m_pTablePropsHandler->SetTableManager( this );
@@ -132,8 +133,47 @@ bool DomainMapperTableManager::sprm(Sprm & rSprm)
                         }
                         else if( sal::static_int_cast<Id>(pMeasureHandler->getUnit()) == NS_ooxml::LN_Value_ST_TblWidth_auto )
                         {
-                            pPropMap->setValue( TablePropertyMap::TABLE_WIDTH_TYPE, text::SizeType::VARIABLE );
-                            pPropMap->setValue( TablePropertyMap::TABLE_WIDTH, 100 );
+                            /*
+                            This attribute specifies the width type of table. This is used as part of the table layout
+                            algorithm specified by the tblLayout element.(See 17.4.64 and 17.4.65 of the ISO/IEC 29500-1:2011.)
+                            If this valus is 'auto', the table layout has to uses the preferred widths on the table items to generate
+                            the final sizing of the table, but then must use the contents of each cell to determine final column widths.
+                            (See 17.18.87 of the ISO/IEC 29500-1:2011.)
+                            */
+                            bool bFixed = false;
+                            sal_Int32 nRowFixedWidth = 0;
+                            if (!m_aCellWidths.empty())
+                            {
+                                // Step 1. Check whether any cell has fixed width in the given row of table.
+                                ::std::vector< IntVectorPtr >::iterator itr;
+                                for (itr = m_aCellWidths.begin(); itr != m_aCellWidths.end(); itr ++)
+                                {
+                                    IntVectorPtr itrVal = (*itr);
+                                    for (std::vector<sal_Int32>::const_iterator aValIter = itrVal->begin(); aValIter != itrVal->end(); ++aValIter)
+                                    {
+                                        // Sum the width of cells to find the total width of given row
+                                        nRowFixedWidth += (*aValIter);
+                                        bFixed = true;
+                                    }
+                                }
+                            }
+
+                            // Check whether the total width of given row is compared with the maximum value of rows (m_nMaxFixedWidth).
+                            if (bFixed )
+                            {
+                                // Check if total width
+                                if (m_nMaxFixedWidth < nRowFixedWidth)
+                                    m_nMaxFixedWidth = nRowFixedWidth;
+
+                                pPropMap->setValue( TablePropertyMap::TABLE_WIDTH_TYPE, text::SizeType::FIX );
+                                pPropMap->setValue( TablePropertyMap::TABLE_WIDTH, m_nMaxFixedWidth );
+                            }
+                            else
+                            {
+                                // Set the width type of table with 'Auto' and set the width value to 100(%)
+                                pPropMap->setValue( TablePropertyMap::TABLE_WIDTH_TYPE, text::SizeType::VARIABLE );
+                                pPropMap->setValue( TablePropertyMap::TABLE_WIDTH, 100 );
+                            }
                         }
                         m_bTableSizeTypeInserted = true;
                     }
diff --git a/writerfilter/source/dmapper/DomainMapperTableManager.hxx b/writerfilter/source/dmapper/DomainMapperTableManager.hxx
index 1384197..6243b61 100644
--- a/writerfilter/source/dmapper/DomainMapperTableManager.hxx
+++ b/writerfilter/source/dmapper/DomainMapperTableManager.hxx
@@ -62,6 +62,7 @@ class DomainMapperTableManager : public DomainMapperTableManager_Base_t
     bool m_bTableSizeTypeInserted;
     /// Table layout algorithm, IOW if we should consider fixed column width or not.
     sal_uInt32 m_nLayoutType;
+    sal_Int32 m_nMaxFixedWidth;
 
     TablePropertiesHandler   *m_pTablePropsHandler;
     PropertyMapPtr            m_pStyleProps;


More information about the Libreoffice-commits mailing list