sw/qa/extras/ooxmlexport/ooxmlexport13.cxx   |   33 +++++++++++++++++
 sw/source/filter/ww8/docxattributeoutput.cxx |   52 ++++++++++++++++-----------
 sw/source/filter/ww8/docxattributeoutput.hxx |    1 
 3 files changed, 66 insertions(+), 20 deletions(-)

New commits:
commit 2b306411d6d0d2f3d791f2f2957fe245e420fc8f
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Tue Jan 21 21:25:08 2020 +0100
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Mon Feb 24 09:15:41 2020 +0100

    sw: add DOCX export for semi-transparent text
    
    This is the case when the value is not in the grab-bag, that was already
    supported.
    
    (cherry picked from commit 6f6a64952d9aa4826e83ad94c2a6de2344cbe2de)
    
    Conflicts:
            sw/qa/extras/ooxmlexport/ooxmlexport14.cxx
            sw/source/filter/ww8/docxattributeoutput.cxx
    
    Change-Id: I334333ec441644229540a358d7bf8811373618c7
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/89222
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>

diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx
index f5fd6bc70b80..9dcc609fcf6a 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx
@@ -27,6 +27,7 @@
 #include <IDocumentSettingAccess.hxx>
 #include <tools/lineend.hxx>
 #include <xmloff/odffields.hxx>
+#include <oox/drawingml/drawingmltypes.hxx>
 
 #include <editsh.hxx>
 #include <frmatr.hxx>
@@ -510,6 +511,38 @@ CPPUNIT_TEST_FIXTURE(SwModelTestBase, 
testTableStyleConfNested)
     assertXPath(pXmlDoc, 
"//w:body/w:tbl/w:tr/w:tc[2]/w:tcPr/w:tcBorders/w:top", "val", "nil");
 }
 
+CPPUNIT_TEST_FIXTURE(SwModelTestBase, testSemiTransparentText)
+{
+    // Create an in-memory empty document.
+    loadURL("private:factory/swriter", nullptr);
+
+    // Set text to half-transparent and type a character.
+    uno::Reference<beans::XPropertySet> xParagraph(getParagraph(1), 
uno::UNO_QUERY);
+    CPPUNIT_ASSERT(xParagraph.is());
+    sal_Int16 nTransparence = 75;
+    xParagraph->setPropertyValue("CharTransparence", 
uno::makeAny(nTransparence));
+    uno::Reference<text::XTextRange> xTextRange(xParagraph, uno::UNO_QUERY);
+    CPPUNIT_ASSERT(xTextRange.is());
+    xTextRange->setString("x");
+
+    // Export to docx.
+    uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY);
+    utl::MediaDescriptor aMediaDescriptor;
+    aMediaDescriptor["FilterName"] <<= OUString("Office Open XML Text");
+    xStorable->storeToURL(maTempFile.GetURL(), 
aMediaDescriptor.getAsConstPropertyValueList());
+    mbExported = true;
+    xmlDocPtr pXmlDoc = parseExport("word/document.xml");
+    CPPUNIT_ASSERT(pXmlDoc);
+    OString aXPath
+        = 
"/w:document/w:body/w:p/w:r/w:rPr/w14:textFill/w14:solidFill/w14:srgbClr/w14:alpha";
+    double fValue = getXPath(pXmlDoc, aXPath, "val").toDouble();
+    sal_Int16 nActual = basegfx::fround(fValue / oox::drawingml::PER_PERCENT);
+
+    // Without the accompanying fix in place, this test would have failed, as 
the w14:textFill
+    // element was missing.
+    CPPUNIT_ASSERT_EQUAL(nTransparence, nActual);
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx 
b/sw/source/filter/ww8/docxattributeoutput.cxx
index c29326b8a287..d0ad6a0c11df 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -2577,7 +2577,6 @@ void DocxAttributeOutput::WriteCollectedRunProperties()
     if ( m_pColorAttrList.is() )
     {
         XFastAttributeListRef xAttrList( m_pColorAttrList.get() );
-        m_pColorAttrList.clear();
 
         m_pSerializer->singleElementNS( XML_w, XML_color, xAttrList );
     }
@@ -2596,6 +2595,24 @@ void DocxAttributeOutput::WriteCollectedRunProperties()
         m_pSerializer->singleElementNS( XML_w, XML_lang, xAttrList );
     }
 
+    if (m_nCharTransparence != 0 && m_pColorAttrList && 
m_aTextEffectsGrabBag.empty())
+    {
+        const char* pVal = nullptr;
+        m_pColorAttrList->getAsChar(FSNS(XML_w, XML_val), pVal);
+        if (OString("auto") != pVal)
+        {
+            m_pSerializer->startElementNS(XML_w14, XML_textFill, FSEND);
+            m_pSerializer->startElementNS(XML_w14, XML_solidFill, FSEND);
+            m_pSerializer->startElementNS(XML_w14, XML_srgbClr, FSNS(XML_w14, 
XML_val), pVal, FSEND);
+            sal_Int32 nTransparence = m_nCharTransparence * 
oox::drawingml::MAX_PERCENT / 255.0;
+            m_pSerializer->singleElementNS(XML_w14, XML_alpha, FSNS(XML_w14, 
XML_val), OString::number(nTransparence), FSEND);
+            m_pSerializer->endElementNS(XML_w14, XML_srgbClr);
+            m_pSerializer->endElementNS(XML_w14, XML_solidFill);
+            m_pSerializer->endElementNS(XML_w14, XML_textFill);
+            m_nCharTransparence = 0;
+        }
+    }
+    m_pColorAttrList.clear();
     for (beans::PropertyValue & i : m_aTextEffectsGrabBag)
     {
         boost::optional<sal_Int32> aElementId = lclGetElementIdForName(i.Name);
@@ -6993,6 +7010,7 @@ void DocxAttributeOutput::CharColor( const SvxColorItem& 
rColor )
     }
 
     AddToAttrList( m_pColorAttrList, FSNS( XML_w, XML_val ), 
aColorString.getStr() );
+    m_nCharTransparence = aColor.GetTransparency();
 }
 
 void DocxAttributeOutput::CharContour( const SvxContourItem& rContour )
diff --git a/sw/source/filter/ww8/docxattributeoutput.hxx 
b/sw/source/filter/ww8/docxattributeoutput.hxx
index 8994517184fa..7ecbf3202214 100644
--- a/sw/source/filter/ww8/docxattributeoutput.hxx
+++ b/sw/source/filter/ww8/docxattributeoutput.hxx
@@ -732,6 +732,7 @@ private:
     bool m_bStartedParaSdt;
     /// Attributes of the run color
     rtl::Reference<sax_fastparser::FastAttributeList> m_pColorAttrList;
+    sal_uInt8 m_nCharTransparence = 0;
     /// Attributes of the paragraph background
     rtl::Reference<sax_fastparser::FastAttributeList> m_pBackgroundAttrList;
     OUString m_sOriginalBackgroundColor;
commit f7f12d1a736daf26e7961db137bcd3e492c76e82
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Wed Nov 28 15:13:42 2018 +0200
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Mon Feb 24 09:15:23 2020 +0100

    remove unnecessary "if (!empty()" checks before loops
    
    found with
       git grep -n -A4 'if.*!.*empty' | grep -B3 -P
    '(\bfor)|(\bwhile)|(\bdo)'
    
    (cherry picked from commit 21de55596c0fdc2be736c6d0369bd9d3783020be)
    
    Change-Id: I582235b7cf977a0f9fb4099eb306fdb4a07b5334
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/89221
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>

diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx 
b/sw/source/filter/ww8/docxattributeoutput.cxx
index a8c2c08fcfe1..c29326b8a287 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -783,17 +783,14 @@ void DocxAttributeOutput::EndParagraph( 
ww8::WW8TableNodeInfoInner::Pointer_t pT
     m_pSerializer->mergeTopMarks(Tag_StartParagraph_1);
 
     // Write framePr
-    if(!aFramePrTextbox.empty())
+    for ( const auto & pFrame : aFramePrTextbox )
     {
-        for ( const auto & pFrame : aFramePrTextbox )
-        {
-            DocxTableExportContext aTableExportContext(*this);
-            m_pCurrentFrame = pFrame.get();
-            m_rExport.SdrExporter().writeOnlyTextOfFrame(pFrame.get());
-            m_pCurrentFrame = nullptr;
-        }
-        aFramePrTextbox.clear();
+        DocxTableExportContext aTableExportContext(*this);
+        m_pCurrentFrame = pFrame.get();
+        m_rExport.SdrExporter().writeOnlyTextOfFrame(pFrame.get());
+        m_pCurrentFrame = nullptr;
     }
+    aFramePrTextbox.clear();
     // Check for end of cell, rows, tables here
     FinishTableRowCell( pTextNodeInfoInner );
 
@@ -2599,20 +2596,17 @@ void DocxAttributeOutput::WriteCollectedRunProperties()
         m_pSerializer->singleElementNS( XML_w, XML_lang, xAttrList );
     }
 
-    if (!m_aTextEffectsGrabBag.empty())
+    for (beans::PropertyValue & i : m_aTextEffectsGrabBag)
     {
-        for (beans::PropertyValue & i : m_aTextEffectsGrabBag)
+        boost::optional<sal_Int32> aElementId = lclGetElementIdForName(i.Name);
+        if(aElementId)
         {
-            boost::optional<sal_Int32> aElementId = 
lclGetElementIdForName(i.Name);
-            if(aElementId)
-            {
-                uno::Sequence<beans::PropertyValue> aGrabBagSeq;
-                i.Value >>= aGrabBagSeq;
-                lclProcessRecursiveGrabBag(*aElementId, aGrabBagSeq, 
m_pSerializer);
-            }
+            uno::Sequence<beans::PropertyValue> aGrabBagSeq;
+            i.Value >>= aGrabBagSeq;
+            lclProcessRecursiveGrabBag(*aElementId, aGrabBagSeq, 
m_pSerializer);
         }
-        m_aTextEffectsGrabBag.clear();
     }
+    m_aTextEffectsGrabBag.clear();
 }
 
 void DocxAttributeOutput::EndRunProperties( const SwRedlineData* pRedlineData )
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to