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

Justin Luth justin.luth at collabora.com
Fri May 25 07:15:03 UTC 2018


 sw/qa/extras/ooxmlexport/data/fdo80800b_tableStyle.docx |binary
 sw/qa/extras/ooxmlexport/data/tdf117297_tableStyle.docx |binary
 sw/qa/extras/ooxmlexport/ooxmlexport5.cxx               |   47 ++++++++++++++++
 sw/source/core/unocore/unotbl.cxx                       |   31 ++++++++++
 sw/source/core/unocore/unotext.cxx                      |   26 --------
 writerfilter/source/dmapper/DomainMapper.cxx            |   18 ------
 6 files changed, 80 insertions(+), 42 deletions(-)

New commits:
commit 5e4d89f59614cec08376e1e77625f8610a1490e5
Author: Justin Luth <justin.luth at collabora.com>
Date:   Fri May 18 07:01:59 2018 +0300

    tdf#117297 sw unotbl XCell: apply char/para style props to text
    
    This is specifically for the benefit of DOCX import, but it
    also makes sense in general. If a SwXCell is given char/para
    properties, then apply those properties (without overwriting)
    to the cell's contents.
    
    This allows ANY paragraph or character properties that are applied
    to a table style to become the "default" for the table.
    
    This fixes a number of things:
    -remove one-off hack to get PROP_PARA_LINE_SPACING to work.
    -works for all character and paragraph properties (except those
    shared with tables like borders).
    -works in multi-paragraph cells. Previously those could return
    AMBIGUOUS state, in which case the style wasn't applied at all.
    
    Change-Id: Ia98c129879575c1aa8ca1fe2a64f4991c0a264e8
    Reviewed-on: https://gerrit.libreoffice.org/54511
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Justin Luth <justin_luth at sil.org>
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>

diff --git a/sw/qa/extras/ooxmlexport/data/fdo80800b_tableStyle.docx b/sw/qa/extras/ooxmlexport/data/fdo80800b_tableStyle.docx
new file mode 100644
index 000000000000..bde907cf227a
Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/fdo80800b_tableStyle.docx differ
diff --git a/sw/qa/extras/ooxmlexport/data/tdf117297_tableStyle.docx b/sw/qa/extras/ooxmlexport/data/tdf117297_tableStyle.docx
new file mode 100644
index 000000000000..57260f81609f
Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/tdf117297_tableStyle.docx differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport5.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport5.cxx
index 12483de3a041..b6125d78aedb 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport5.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport5.cxx
@@ -863,6 +863,53 @@ DECLARE_OOXMLEXPORT_TEST(testTableCellWithDirectFormatting, "fdo80800.docx")
 
 }
 
+DECLARE_OOXMLEXPORT_TEST(testFdo80800b_tableStyle, "fdo80800b_tableStyle.docx")
+{
+    uno::Reference<text::XTextTable> xTable(getParagraphOrTable(1), uno::UNO_QUERY);
+    uno::Reference<text::XTextRange> xCell(xTable->getCellByName("A1"), uno::UNO_QUERY);
+    uno::Reference<container::XEnumerationAccess> xParaEnumAccess(xCell->getText(), uno::UNO_QUERY);
+    uno::Reference<container::XEnumeration> xParaEnum = xParaEnumAccess->createEnumeration();
+    uno::Reference<text::XTextRange> xPara(xParaEnum->nextElement(), uno::UNO_QUERY);
+    CPPUNIT_ASSERT_EQUAL(OUString("Cell1 1.5lines"), xPara->getString());
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("Cell A1 1.5 line spacing", sal_Int16(150), getProperty<style::LineSpacing>(xPara, "ParaLineSpacing").Height);
+
+    xCell.set(xTable->getCellByName("B1"), uno::UNO_QUERY);
+    xParaEnumAccess.set(xCell->getText(), uno::UNO_QUERY);
+    xParaEnum = xParaEnumAccess->createEnumeration();
+    xPara.set(xParaEnum->nextElement(), uno::UNO_QUERY);
+    CPPUNIT_ASSERT_EQUAL(OUString("Cell2 Implicit (Single)"), xPara->getString());
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("Cell B1 single line spacing", sal_Int16(100), getProperty<style::LineSpacing>(xPara, "ParaLineSpacing").Height);
+
+    xCell.set(xTable->getCellByName("C1"), uno::UNO_QUERY);
+    xParaEnumAccess.set(xCell->getText(), uno::UNO_QUERY);
+    xParaEnum = xParaEnumAccess->createEnumeration();
+    xPara.set(xParaEnum->nextElement(), uno::UNO_QUERY);
+    CPPUNIT_ASSERT_EQUAL(OUString("Cell3 Implicit (Single)"), xPara->getString());
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("C1 paragraph1 single line spacing", sal_Int16(100), getProperty<style::LineSpacing>(xPara, "ParaLineSpacing").Height);
+    xPara.set(xParaEnum->nextElement(), uno::UNO_QUERY);
+    xPara.set(xParaEnum->nextElement(), uno::UNO_QUERY);
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("C1 paragraph3 line spacing", sal_Int16(212), getProperty<style::LineSpacing>(xPara, "ParaLineSpacing").Height);
+}
+
+DECLARE_OOXMLEXPORT_TEST(testTdf117297_tableStyle, "tdf117297_tableStyle.docx")
+{
+    uno::Reference<text::XTextTable> xTable(getParagraphOrTable(1), uno::UNO_QUERY);
+    uno::Reference<text::XTextRange> xCell(xTable->getCellByName("B1"), uno::UNO_QUERY);
+    uno::Reference<container::XEnumerationAccess> xParaEnumAccess(xCell->getText(), uno::UNO_QUERY);
+    uno::Reference<container::XEnumeration> xParaEnum = xParaEnumAccess->createEnumeration();
+    uno::Reference<text::XTextRange> xPara(xParaEnum->nextElement(), uno::UNO_QUERY);
+    uno::Reference<text::XText> xText(xPara->getText(), uno::UNO_QUERY);
+    CPPUNIT_ASSERT_EQUAL(OUString("Green text, default size (9), 1.5 spaced"), xPara->getString());
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("Cell B1 Paragraph1 green font", sal_Int32(0x70AD47), getProperty<sal_Int32>(getRun(xPara, 1), "CharColor"));
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("Cell B1 Paragraph1 1.5 line spacing", sal_Int16(150), getProperty<style::LineSpacing>(xPara, "ParaLineSpacing").Height);
+    xPara.set(xParaEnum->nextElement(), uno::UNO_QUERY);
+    xPara.set(xParaEnum->nextElement(), uno::UNO_QUERY);
+    xText.set(xPara->getText(), uno::UNO_QUERY);
+    CPPUNIT_ASSERT_EQUAL(OUString("TableGrid color (blue), TableGrid size (9), double spacing"), xPara->getString());
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("Cell B1 Paragraph3 blue font", sal_Int32(0x00B0F0), getProperty<sal_Int32>(getRun(xPara, 1), "CharColor"));
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("Cell B1 Paragraph3 double spacing", sal_Int16(200), getProperty<style::LineSpacing>(xPara, "ParaLineSpacing").Height);
+}
+
 DECLARE_OOXMLEXPORT_TEST(test2colHeader, "2col-header.docx")
 {
     // Header was lost on export when the document had multiple columns.
diff --git a/sw/source/core/unocore/unotbl.cxx b/sw/source/core/unocore/unotbl.cxx
index 1d28972928c2..e12c40acf458 100644
--- a/sw/source/core/unocore/unotbl.cxx
+++ b/sw/source/core/unocore/unotbl.cxx
@@ -45,6 +45,7 @@
 #include <shellres.hxx>
 #include <docary.hxx>
 #include <ndole.hxx>
+#include <ndtxt.hxx>
 #include <frame.hxx>
 #include <vcl/svapp.hxx>
 #include <fmtfsize.hxx>
@@ -1043,6 +1044,36 @@ void SwXCell::setPropertyValue(const OUString& rPropertyName, const uno::Any& aV
     else
     {
         auto pEntry(m_pPropSet->getPropertyMap().getByName(rPropertyName));
+        if ( !pEntry )
+        {
+            // not a table property: if it is a paragraph/character property, consider applying it to the underlying text.
+            const SfxItemPropertySet& rParaPropSet = *aSwMapProvider.GetPropertySet(PROPERTY_MAP_PARAGRAPH);
+            pEntry = rParaPropSet.getPropertyMap().getByName(rPropertyName);
+
+            if ( pEntry )
+            {
+                SwNodeIndex aIdx( *GetStartNode(), 1 );
+                const SwNode* pEndNd = aIdx.GetNode().EndOfSectionNode();
+                while ( &aIdx.GetNode() != pEndNd )
+                {
+                    const SwTextNode* pNd = aIdx.GetNode().GetTextNode();
+                    if ( pNd )
+                    {
+                        //point and mark selecting the whole paragraph
+                        SwPaM aPaM(*pNd, 0, *pNd, pNd->GetText().getLength());
+                        const bool bHasAttrSet = pNd->HasSwAttrSet();
+                        const SfxItemSet& aSet = pNd->GetSwAttrSet();
+                        // isPARATR: replace DEFAULT_VALUE properties only
+                        // isCHRATR: change the base/auto SwAttr property, but don't remove the DIRECT hints
+                        if ( !bHasAttrSet || SfxItemState::DEFAULT == aSet.GetItemState(pEntry->nWID, /*bSrchInParent=*/false) )
+                            SwUnoCursorHelper::SetPropertyValue(aPaM, rParaPropSet, rPropertyName, aValue, SetAttrMode::DONTREPLACE);
+                    }
+                    ++aIdx;
+                }
+                return;
+            }
+        }
+
         if(!pEntry)
             throw beans::UnknownPropertyException(rPropertyName, static_cast<cppu::OWeakObject*>(this));
         if(pEntry->nWID != FN_UNO_CELL_ROW_SPAN)
diff --git a/sw/source/core/unocore/unotext.cxx b/sw/source/core/unocore/unotext.cxx
index 5ecc6fbf399b..b16ea0ab3d92 100644
--- a/sw/source/core/unocore/unotext.cxx
+++ b/sw/source/core/unocore/unotext.cxx
@@ -2037,32 +2037,10 @@ lcl_ApplyCellProperties(
             {
                 xCellPS->setPropertyValue(rName, rValue);
             }
-            catch (const uno::Exception&)
+            catch (const uno::Exception& e)
             {
-                // Apply the paragraph and char properties to the cell's content
-                const uno::Reference< text::XText > xCellText(xCell,
-                        uno::UNO_QUERY);
-                const uno::Reference< text::XTextCursor > xCellCurs =
-                    xCellText->createTextCursor();
-                xCellCurs->gotoStart( false );
-                xCellCurs->gotoEnd( true );
-                const uno::Reference< beans::XPropertyState >
-                    xCellTextPropState(xCellCurs, uno::UNO_QUERY);
-                try
-                {
-                    const beans::PropertyState state = xCellTextPropState->getPropertyState(rName);
-                    if (state == beans::PropertyState_DEFAULT_VALUE)
-                    {
-                        const uno::Reference< beans::XPropertySet >
-                            xCellTextProps(xCellCurs, uno::UNO_QUERY);
-                        xCellTextProps->setPropertyValue(rName, rValue);
-                    }
-                }
-                catch (const uno::Exception& e)
-                {
-                    SAL_WARN( "sw.uno", "Exception when getting PropertyState: "
+                SAL_WARN( "sw.uno", "Exception when getting PropertyState: "
                         + rName + ". Message: " + e.Message );
-                }
             }
         }
     }
diff --git a/writerfilter/source/dmapper/DomainMapper.cxx b/writerfilter/source/dmapper/DomainMapper.cxx
index cbcce6bda2ef..a203dc9d3312 100644
--- a/writerfilter/source/dmapper/DomainMapper.cxx
+++ b/writerfilter/source/dmapper/DomainMapper.cxx
@@ -451,14 +451,6 @@ void DomainMapper::lcl_attribute(Id nName, Value & val)
                     aSpacing.Height = sal_Int16(nIntValue * 100 / nSingleLineSpacing );
                 else
                     aSpacing.Height = sal_Int16(ConversionHelper::convertTwipToMM100( nIntValue ));
-
-                if (m_pImpl->hasTableManager() && m_pImpl->getTableManager().isInCell())
-                {
-                    // direct formatting is applied for table cell data
-                    TablePropertyMapPtr pTblCellWithDirectFormatting(new TablePropertyMap);
-                    pTblCellWithDirectFormatting->Insert(PROP_PARA_LINE_SPACING, uno::makeAny( aSpacing ), false);
-                    m_pImpl->getTableManager().cellProps(pTblCellWithDirectFormatting);
-                }
             }
             else //NS_ooxml::LN_CT_Spacing_lineRule:
             {
@@ -490,16 +482,6 @@ void DomainMapper::lcl_attribute(Id nName, Value & val)
                         m_pImpl->appendGrabBag(m_pImpl->m_aSubInteropGrabBag, "lineRule", "exact");
                         aSpacing.Mode = style::LineSpacingMode::FIX;
                     }
-
-                if (m_pImpl->hasTableManager() && m_pImpl->getTableManager().isInCell())
-                {
-                    // If the table manager got the line rule after
-                    // ooxml::CT_Spacing_line, then it should get the rule
-                    // after lineRule as well.
-                    TablePropertyMapPtr pTblCellWithDirectFormatting(new TablePropertyMap);
-                    pTblCellWithDirectFormatting->Insert(PROP_PARA_LINE_SPACING, uno::makeAny(aSpacing), false);
-                    m_pImpl->getTableManager().cellProps(pTblCellWithDirectFormatting);
-                }
             }
             if (pTopContext)
                 pTopContext->Insert(PROP_PARA_LINE_SPACING, uno::makeAny( aSpacing ));


More information about the Libreoffice-commits mailing list