[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.2' - 2 commits - oox/source sd/qa sw/qa writerfilter/source

Miklos Vajna (via logerrit) logerrit at kemper.freedesktop.org
Tue Jun 18 13:44:07 UTC 2019


 oox/source/export/drawingml.cxx                   |   59 ++++++++++++++++++++--
 sd/qa/unit/export-tests-ooxml1.cxx                |   34 ++++++++++++
 sd/qa/unit/import-tests.cxx                       |   33 ------------
 sw/qa/extras/uiwriter/uiwriter.cxx                |   10 +++
 writerfilter/source/dmapper/DomainMapper_Impl.cxx |    1 
 writerfilter/source/dmapper/DomainMapper_Impl.hxx |    4 +
 writerfilter/source/dmapper/PropertyMap.cxx       |   11 ++--
 7 files changed, 110 insertions(+), 42 deletions(-)

New commits:
commit 15395a58feec2e2b00dc3186cbc5713376c796bd
Author:     Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Wed Mar 13 17:51:07 2019 +0100
Commit:     Miklos Vajna <vmiklos at collabora.com>
CommitDate: Tue Jun 18 15:43:11 2019 +0200

    DOCX import: fix unexpected page break on autotext insert at end of doc
    
    The problem was that the page style was set on the first paragraph,
    which means a page break on the UI. So if you used a multi-paragraph
    autotext twice (insert autotext, press enter, insert autotext again)
    then you ended up with 2 pages instead of just 1.
    
    Fix the problem by tracking when we are in autotext import mode, and
    similar to pasting, don't set the page style in autotext import mode.
    
    Change-Id: I4fc551b3c1b999687eb80242e261f186fd1b6f13
    Reviewed-on: https://gerrit.libreoffice.org/69214
    Reviewed-by: Miklos Vajna <vmiklos at collabora.com>
    Tested-by: Jenkins
    (cherry picked from commit adcf656bb56e09fbb638a44b0cccc96f8cfced7f)

diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx
index e16e78beba22..c734ba823f6e 100644
--- a/sw/qa/extras/uiwriter/uiwriter.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter.cxx
@@ -1021,7 +1021,15 @@ void SwUiWriterTest::testDOCXAutoTextMultiple()
 
     // first line
     SwNode& rNode = aStart.GetNode();
-    CPPUNIT_ASSERT_EQUAL(OUString("Another "), rNode.GetTextNode()->GetText());
+    CPPUNIT_ASSERT(rNode.IsTextNode());
+    SwTextNode& rTextNode = *rNode.GetTextNode();
+    CPPUNIT_ASSERT_EQUAL(OUString("Another "), rTextNode.GetText());
+
+    // Make sure that autotext does not set a custom page style, leading to an unexpected page break
+    // on insertion.
+    // Without the accompanying fix in place, this test would have failed: the text node had an
+    // attribute set containing a page style item.
+    CPPUNIT_ASSERT(!rTextNode.HasSwAttrSet() || !rTextNode.GetSwAttrSet().HasItem(RES_PAGEDESC));
 
     // last line
     SwNodeIndex aLast(*aDocEnd.GetNode().EndOfSectionNode(), -1);
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index 4a700758a574..5d2272cdc5bc 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -239,6 +239,7 @@ DomainMapper_Impl::DomainMapper_Impl(
         m_aSmartTagHandler(m_xComponentContext, m_xTextDocument),
         m_xInsertTextRange(rMediaDesc.getUnpackedValueOrDefault("TextInsertModeRange", uno::Reference<text::XTextRange>())),
         m_bIsNewDoc(!rMediaDesc.getUnpackedValueOrDefault("InsertMode", false)),
+        m_bIsReadGlossaries(rMediaDesc.getUnpackedValueOrDefault("ReadGlossaries", false)),
         m_bInTableStyleRunProps(false),
         m_nTableDepth(0),
         m_nTableCellDepth(0),
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.hxx b/writerfilter/source/dmapper/DomainMapper_Impl.hxx
index 5d6f634bad10..52aeb82ab378 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.hxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.hxx
@@ -550,6 +550,7 @@ public:
     css::uno::Reference<css::text::XTextRange> m_xInsertTextRange;
 private:
     bool const m_bIsNewDoc;
+    bool const m_bIsReadGlossaries;
 public:
     DomainMapper_Impl(
             DomainMapper& rDMapper,
@@ -918,6 +919,9 @@ public:
     /// If we're importing into a new document, or just pasting to an existing one.
     bool IsNewDoc() { return m_bIsNewDoc;}
 
+    /// If we're importing autotext.
+    bool IsReadGlossaries() { return m_bIsReadGlossaries;}
+
     /// If we're inside <w:rPr>, inside <w:style w:type="table">
     bool m_bInTableStyleRunProps;
 
diff --git a/writerfilter/source/dmapper/PropertyMap.cxx b/writerfilter/source/dmapper/PropertyMap.cxx
index e965db4f919b..9bc6e3a8780c 100644
--- a/writerfilter/source/dmapper/PropertyMap.cxx
+++ b/writerfilter/source/dmapper/PropertyMap.cxx
@@ -1585,10 +1585,13 @@ void SectionPropertyMap::CloseSectionGroup( DomainMapper_Impl& rDM_Impl )
 
             if ( xRangeProperties.is() && rDM_Impl.IsNewDoc() )
             {
-                xRangeProperties->setPropertyValue(
-                    getPropertyName( PROP_PAGE_DESC_NAME ),
-                    uno::makeAny( m_bTitlePage ? m_sFirstPageStyleName
-                        : m_sFollowPageStyleName ) );
+                // Avoid setting page style in case of autotext: so inserting the autotext at the
+                // end of the document does not introduce an unwanted page break.
+                if (!rDM_Impl.IsReadGlossaries())
+                    xRangeProperties->setPropertyValue(
+                        getPropertyName( PROP_PAGE_DESC_NAME ),
+                        uno::makeAny( m_bTitlePage ? m_sFirstPageStyleName
+                            : m_sFollowPageStyleName ) );
 
                 if (0 <= m_nPageNumber)
                 {
commit c7239345e707a36dbebe7dcb100974b6898cf293
Author:     Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Mon Feb 4 17:34:39 2019 +0100
Commit:     Miklos Vajna <vmiklos at collabora.com>
CommitDate: Tue Jun 18 15:43:11 2019 +0200

    Related: tdf#94238 PPTX export: handle border and center of radial gradient
    
    Map Border to a gradient stop before the final one.
    
    Map X/YOffset to the focus rectangle of the center shade, i.e. the
    opposite of what the import already does.
    
    (cherry picked from commit 82365563fb2fd55d90d444a104fa475d4ffc4cf1)
    
    Conflicts:
            oox/source/export/drawingml.cxx
            sd/qa/unit/import-tests.cxx
    
    Reviewed-on: https://gerrit.libreoffice.org/67395
    Reviewed-by: Jan Holesovsky <kendy at collabora.com>
    Tested-by: Jan Holesovsky <kendy at collabora.com>
    
    Conflicts:
            oox/source/export/drawingml.cxx
            sd/qa/unit/export-tests-ooxml1.cxx
            sd/qa/unit/import-tests.cxx
    
    Change-Id: I88db7d579da7327e5e06b736a75a6892b338dd73

diff --git a/oox/source/export/drawingml.cxx b/oox/source/export/drawingml.cxx
index 0f4f75c155cc..b29fc4a5bc4b 100644
--- a/oox/source/export/drawingml.cxx
+++ b/oox/source/export/drawingml.cxx
@@ -162,6 +162,33 @@ static css::uno::Any getLineDash( const css::uno::Reference<css::frame::XModel>&
     }
 
 
+namespace
+{
+void WriteRadialGradientPath(const awt::Gradient& rGradient, const FSHelperPtr& pFS)
+{
+    pFS->startElementNS(XML_a, XML_path, XML_path, "circle", FSEND);
+
+    // Write the focus rectangle. Work with the focus point, and assume
+    // that it extends 50% in all directions.  The below
+    // left/top/right/bottom values are percentages, where 0 means the
+    // edge of the tile rectangle and 100% means the center of it.
+    rtl::Reference<sax_fastparser::FastAttributeList> pAttributeList(
+        sax_fastparser::FastSerializerHelper::createAttrList());
+    sal_Int32 nLeftPercent = rGradient.XOffset * 2 - 50;
+    pAttributeList->add(XML_l, OString::number(nLeftPercent * PER_PERCENT));
+    sal_Int32 nTopPercent = rGradient.YOffset * 2 - 50;
+    pAttributeList->add(XML_t, OString::number(nTopPercent * PER_PERCENT));
+    sal_Int32 nRightPercent = (100 - rGradient.XOffset) * 2 - 50;
+    pAttributeList->add(XML_r, OString::number(nRightPercent * PER_PERCENT));
+    sal_Int32 nBottomPercent = (100 - rGradient.YOffset) * 2 - 50;
+    pAttributeList->add(XML_b, OString::number(nBottomPercent * PER_PERCENT));
+    sax_fastparser::XFastAttributeListRef xAttributeList(pAttributeList.get());
+    pFS->singleElementNS(XML_a, XML_fillToRect, xAttributeList);
+
+    pFS->endElementNS(XML_a, XML_path);
+}
+}
+
 
 // not thread safe
 int DrawingML::mnImageCounter = 1;
@@ -511,9 +538,17 @@ void DrawingML::WriteGrabBagGradientFill( const Sequence< PropertyValue >& aGrad
     }
     mpFS->endElementNS( XML_a, XML_gsLst );
 
-    mpFS->singleElementNS( XML_a, XML_lin,
-                           XML_ang, I32S( ( ( ( 3600 - rGradient.Angle + 900 ) * 6000 ) % 21600000 ) ),
-                           FSEND );
+    switch (rGradient.Style)
+    {
+        default:
+            mpFS->singleElementNS( XML_a, XML_lin,
+                                   XML_ang, I32S( ( ( ( 3600 - rGradient.Angle + 900 ) * 6000 ) % 21600000 ) ),
+                                   FSEND );
+            break;
+        case awt::GradientStyle_RADIAL:
+            WriteRadialGradientPath(rGradient, mpFS);
+            break;
+    }
 }
 
 void DrawingML::WriteGradientFill( awt::Gradient rGradient )
@@ -542,10 +577,26 @@ void DrawingML::WriteGradientFill( awt::Gradient rGradient )
                     FSEND );
             break;
 
+        case awt::GradientStyle_RADIAL:
+        {
+            mpFS->startElementNS(XML_a, XML_gsLst, FSEND);
+            WriteGradientStop(0, ColorWithIntensity(rGradient.EndColor, rGradient.EndIntensity));
+            if (rGradient.Border > 0 && rGradient.Border < 100)
+                // Map border to an additional gradient stop, which has the
+                // same color as the final stop.
+                WriteGradientStop(
+                    100 - rGradient.Border,
+                    ColorWithIntensity(rGradient.StartColor, rGradient.StartIntensity));
+            WriteGradientStop(100,
+                              ColorWithIntensity(rGradient.StartColor, rGradient.StartIntensity));
+            mpFS->endElementNS(XML_a, XML_gsLst);
+
+            WriteRadialGradientPath(rGradient, mpFS);
+            break;
+        }
             /* I don't see how to apply transformation to gradients, so
              * elliptical will end as radial and square as
              * rectangular. also position offsets are not applied */
-        case awt::GradientStyle_RADIAL:
         case awt::GradientStyle_ELLIPTICAL:
         case awt::GradientStyle_RECT:
         case awt::GradientStyle_SQUARE:
diff --git a/sd/qa/unit/export-tests-ooxml1.cxx b/sd/qa/unit/export-tests-ooxml1.cxx
index fdad81af2307..601497cee2b3 100644
--- a/sd/qa/unit/export-tests-ooxml1.cxx
+++ b/sd/qa/unit/export-tests-ooxml1.cxx
@@ -102,6 +102,7 @@ public:
     void testTdf112633();
     void testCustomXml();
     void testPictureTransparency();
+    void testTdf94238();
 
     CPPUNIT_TEST_SUITE(SdOOXMLExportTest1);
 
@@ -133,6 +134,7 @@ public:
     CPPUNIT_TEST(testTdf112633);
     CPPUNIT_TEST(testCustomXml);
     CPPUNIT_TEST(testPictureTransparency);
+    CPPUNIT_TEST(testTdf94238);
 
     CPPUNIT_TEST_SUITE_END();
 
@@ -879,6 +881,38 @@ void SdOOXMLExportTest1::testPictureTransparency()
     xDocShRef->DoClose();
 }
 
+void SdOOXMLExportTest1::testTdf94238()
+{
+    // Load document and export it to a temporary file.
+    ::sd::DrawDocShellRef xDocShRef
+        = loadURL(m_directories.getURLFromSrc("sd/qa/unit/data/pptx/tdf94238.pptx"), PPTX);
+    utl::TempFile tempFile;
+    xDocShRef = saveAndReload(xDocShRef.get(), PPTX, &tempFile);
+    uno::Reference<drawing::XDrawPagesSupplier> xDoc(xDocShRef->GetDoc()->getUnoModel(),
+                                                     uno::UNO_QUERY);
+    CPPUNIT_ASSERT(xDoc.is());
+
+    uno::Reference<drawing::XDrawPage> xPage(xDoc->getDrawPages()->getByIndex(0), uno::UNO_QUERY);
+    CPPUNIT_ASSERT(xPage.is());
+
+    uno::Reference<beans::XPropertySet> xShape(getShape(0, xPage));
+    CPPUNIT_ASSERT(xShape.is());
+
+    awt::Gradient aGradient;
+    CPPUNIT_ASSERT(xShape->getPropertyValue("FillGradient") >>= aGradient);
+
+    // Without the accompanying fix in place, this test would have failed with
+    // the following details:
+    // - aGradient.Style was awt::GradientStyle_ELLIPTICAL
+    // - aGradient.YOffset was 70
+    // - aGradient.Border was 0
+    CPPUNIT_ASSERT_EQUAL(awt::GradientStyle_RADIAL, aGradient.Style);
+    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int16>(100), aGradient.YOffset);
+    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int16>(39), aGradient.Border);
+
+    xDocShRef->DoClose();
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(SdOOXMLExportTest1);
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sd/qa/unit/import-tests.cxx b/sd/qa/unit/import-tests.cxx
index 36d4806efdb2..362d67814d91 100644
--- a/sd/qa/unit/import-tests.cxx
+++ b/sd/qa/unit/import-tests.cxx
@@ -194,7 +194,6 @@ public:
     void testTdf120028();
     void testTdf120028b();
     void testCropToShape();
-    void testTdf94238();
 
     CPPUNIT_TEST_SUITE(SdImportTest);
 
@@ -281,7 +280,6 @@ public:
     CPPUNIT_TEST(testTdf120028);
     CPPUNIT_TEST(testTdf120028b);
     CPPUNIT_TEST(testCropToShape);
-    CPPUNIT_TEST(testTdf94238);
 
     CPPUNIT_TEST_SUITE_END();
 };
@@ -2677,37 +2675,6 @@ void SdImportTest::testCropToShape()
     CPPUNIT_ASSERT_EQUAL(css::drawing::BitmapMode_STRETCH, bitmapmode);
 }
 
-void SdImportTest::testTdf94238()
-{
-    // Assert how the gradient fill of the only shape in the document is
-    // imported.
-    ::sd::DrawDocShellRef xDocShRef
-        = loadURL(m_directories.getURLFromSrc("/sd/qa/unit/data/pptx/tdf94238.pptx"), PPTX);
-    uno::Reference<drawing::XDrawPagesSupplier> xDoc(xDocShRef->GetDoc()->getUnoModel(),
-                                                     uno::UNO_QUERY);
-    CPPUNIT_ASSERT(xDoc.is());
-
-    uno::Reference<drawing::XDrawPage> xPage(xDoc->getDrawPages()->getByIndex(0), uno::UNO_QUERY);
-    CPPUNIT_ASSERT(xPage.is());
-
-    uno::Reference<beans::XPropertySet> xShape(getShape(0, xPage));
-    CPPUNIT_ASSERT(xShape.is());
-
-    awt::Gradient aGradient;
-    CPPUNIT_ASSERT(xShape->getPropertyValue("FillGradient") >>= aGradient);
-
-    // Without the accompanying fix in place, this test would have failed with
-    // the following details:
-    // - aGradient.Style was awt::GradientStyle_ELLIPTICAL
-    // - aGradient.YOffset was 70
-    // - aGradient.Border was 0
-    CPPUNIT_ASSERT_EQUAL(awt::GradientStyle_RADIAL, aGradient.Style);
-    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int16>(100), aGradient.YOffset);
-    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int16>(39), aGradient.Border);
-
-    xDocShRef->DoClose();
-}
-
 CPPUNIT_TEST_SUITE_REGISTRATION(SdImportTest);
 
 CPPUNIT_PLUGIN_IMPLEMENT();


More information about the Libreoffice-commits mailing list