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

Miklos Vajna (via logerrit) logerrit at kemper.freedesktop.org
Wed Jan 22 07:52:09 UTC 2020


 sw/qa/extras/ooxmlexport/ooxmlexport14.cxx   |   33 +++++++++++++++++++++++++++
 sw/source/filter/ww8/docxattributeoutput.cxx |   20 +++++++++++++++-
 sw/source/filter/ww8/docxattributeoutput.hxx |    1 
 3 files changed, 53 insertions(+), 1 deletion(-)

New commits:
commit 6f6a64952d9aa4826e83ad94c2a6de2344cbe2de
Author:     Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Tue Jan 21 21:25:08 2020 +0100
Commit:     Miklos Vajna <vmiklos at collabora.com>
CommitDate: Wed Jan 22 08:51:34 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.
    
    Change-Id: I334333ec441644229540a358d7bf8811373618c7
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/87162
    Tested-by: Jenkins
    Reviewed-by: Miklos Vajna <vmiklos at collabora.com>

diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx
index 922cb9183adc..d582e777de06 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx
@@ -15,6 +15,7 @@
 #include <editsh.hxx>
 #include <frmatr.hxx>
 #include <tools/lineend.hxx>
+#include <oox/drawingml/drawingmltypes.hxx>
 #include <com/sun/star/table/ShadowFormat.hpp>
 #include <com/sun/star/text/TableColumnSeparator.hpp>
 #include <com/sun/star/text/XDocumentIndex.hpp>
@@ -218,6 +219,38 @@ DECLARE_OOXMLEXPORT_TEST(testTdf121658, "tdf121658.docx")
     assertXPath(pXmlSettings, "/w:settings/w:doNotHyphenateCaps");
 }
 
+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);
+}
+
 DECLARE_OOXMLEXPORT_TEST(testTdf124367, "tdf124367.docx")
 {
     uno::Reference<text::XTextTablesSupplier> xTablesSupplier(mxComponent, uno::UNO_QUERY);
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx
index e3146df0ed06..d30d19eaad66 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -2555,7 +2555,6 @@ void DocxAttributeOutput::WriteCollectedRunProperties()
     if ( m_pColorAttrList.is() )
     {
         XFastAttributeListRef xAttrList( m_pColorAttrList.get() );
-        m_pColorAttrList.clear();
 
         m_pSerializer->singleElementNS( XML_w, XML_color, xAttrList );
     }
@@ -2574,6 +2573,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);
+            m_pSerializer->startElementNS(XML_w14, XML_solidFill);
+            m_pSerializer->startElementNS(XML_w14, XML_srgbClr, FSNS(XML_w14, XML_val), pVal);
+            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));
+            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 (const beans::PropertyValue & i : m_aTextEffectsGrabBag)
     {
         o3tl::optional<sal_Int32> aElementId = lclGetElementIdForName(i.Name);
@@ -6800,6 +6817,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 e44adc02be40..f13c49e34f47 100644
--- a/sw/source/filter/ww8/docxattributeoutput.hxx
+++ b/sw/source/filter/ww8/docxattributeoutput.hxx
@@ -743,6 +743,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;


More information about the Libreoffice-commits mailing list