sw/qa/extras/odfexport/odfexport.cxx              |    4 -
 sw/qa/extras/ooxmlexport/data/chart.docx          |binary
 sw/qa/extras/ooxmlexport/ooxmlexport18.cxx        |   13 +++++
 sw/source/filter/ww8/docxattributeoutput.cxx      |   54 +++++++++++++---------
 writerfilter/source/dmapper/DomainMapper_Impl.cxx |   21 ++++++++
 writerfilter/source/dmapper/GraphicImport.cxx     |    1 
 6 files changed, 70 insertions(+), 23 deletions(-)

New commits:
commit fa1f2b7f5c65d66eaa5887acc9da5eb526570b18
Author:     Michael Stahl <michael.st...@allotropia.de>
AuthorDate: Wed Feb 1 19:45:54 2023 +0100
Commit:     Michael Stahl <michael.st...@allotropia.de>
CommitDate: Thu Feb 2 17:42:04 2023 +0000

    tdf#130782 tdf#153203 writerfilter,sw: DOCX import/export of a11y
    
    ... related attributes name/title/description on Chart embedded objects.
    
    DomainMapper first needs to apply the properties to an SdrOLE2Obj, then
    later copy it to SwXEmbeddedObject.
    
    Change-Id: Id766be1eedf348caf22640ab6c177d81a0971749
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/146494
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>

diff --git a/sw/qa/extras/odfexport/odfexport.cxx 
b/sw/qa/extras/odfexport/odfexport.cxx
index 4c8565b2d9f5..ceae429fae01 100644
--- a/sw/qa/extras/odfexport/odfexport.cxx
+++ b/sw/qa/extras/odfexport/odfexport.cxx
@@ -960,7 +960,7 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf134987)
     }
     // checking second object (chart)
     {
-        uno::Reference<document::XEmbeddedObjectSupplier> 
xEOSupplier(xAccess->getByName("Object2"), uno::UNO_QUERY);
+        uno::Reference<document::XEmbeddedObjectSupplier> 
xEOSupplier(xAccess->getByName("Diagram 1"), uno::UNO_QUERY);
         uno::Reference<lang::XComponent> 
xObj(xEOSupplier->getEmbeddedObject());
         CPPUNIT_ASSERT(xObj.is());
 
@@ -974,7 +974,7 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf134987)
     }
     // checking third object (chart)
     {
-        uno::Reference<document::XEmbeddedObjectSupplier> 
xEOSupplier(xAccess->getByName("Object3"), uno::UNO_QUERY);
+        uno::Reference<document::XEmbeddedObjectSupplier> 
xEOSupplier(xAccess->getByName("Diagram 2"), uno::UNO_QUERY);
         uno::Reference<lang::XComponent> 
xObj(xEOSupplier->getEmbeddedObject());
         CPPUNIT_ASSERT(xObj.is());
 
diff --git a/sw/qa/extras/ooxmlexport/data/chart.docx 
b/sw/qa/extras/ooxmlexport/data/chart.docx
new file mode 100644
index 000000000000..f984f0b17eea
Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/chart.docx differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx
index 1be945cb9f49..2441a7febfd8 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx
@@ -127,6 +127,19 @@ DECLARE_OOXMLEXPORT_TEST(testTdf147724, "tdf147724.docx")
     CPPUNIT_ASSERT(sFieldResult == "Placeholder -> *HERUNTERLADEN*" || 
sFieldResult == "Placeholder -> *ABC*");
 }
 
+DECLARE_OOXMLEXPORT_TEST(testTdf130782, "chart.docx")
+{
+    uno::Reference<text::XTextEmbeddedObjectsSupplier> 
xTEOSupplier(mxComponent, uno::UNO_QUERY);
+    uno::Reference<container::XIndexAccess> 
xAccess(xTEOSupplier->getEmbeddedObjects(), uno::UNO_QUERY);
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xAccess->getCount());
+    uno::Reference<container::XNamed> xObj(xAccess->getByIndex(0), 
uno::UNO_QUERY);
+
+    // these properties were not imported
+    CPPUNIT_ASSERT_EQUAL(OUString("Diagramm 1"), xObj->getName());
+    CPPUNIT_ASSERT_EQUAL(OUString("uninspired default chart"), 
getProperty<OUString>(xObj, "Title"));
+    CPPUNIT_ASSERT_EQUAL(OUString("the description is here"), 
getProperty<OUString>(xObj, "Description"));
+}
+
 CPPUNIT_TEST_FIXTURE(Test, testNumberPortionFormatFromODT)
 {
     // Given a document with a single paragraph, direct formatting asks 24pt 
font size for the
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx 
b/sw/source/filter/ww8/docxattributeoutput.cxx
index aafde6a8bf0c..0aef9a066741 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -5646,6 +5646,30 @@ uno::Reference<css::text::XTextFrame> 
DocxAttributeOutput::GetUnoTextFrame(
     return SwTextBoxHelper::getUnoTextFrame(xShape);
 }
 
+static rtl::Reference<::sax_fastparser::FastAttributeList> CreateDocPrAttrList(
+    DocxExport & rExport, int const nAnchorId, std::u16string_view const& 
rName,
+    std::u16string_view const& rTitle, std::u16string_view const& rDescription)
+{
+    rtl::Reference<::sax_fastparser::FastAttributeList> const 
pAttrs(FastSerializerHelper::createAttrList());
+    pAttrs->add(XML_id, OString::number(nAnchorId).getStr());
+    pAttrs->add(XML_name, OUStringToOString(rName, RTL_TEXTENCODING_UTF8));
+    if (rExport.GetFilter().getVersion() != oox::core::ECMA_376_1ST_EDITION)
+    {
+        pAttrs->add(XML_descr, OUStringToOString(rDescription, 
RTL_TEXTENCODING_UTF8));
+        pAttrs->add(XML_title, OUStringToOString(rTitle, 
RTL_TEXTENCODING_UTF8));
+    }
+    else
+    {   // tdf#148952 no title attribute, merge it into descr
+        OUString const value(rTitle.empty()
+            ? OUString(rDescription)
+            : rDescription.empty()
+                ? OUString(rTitle)
+                : OUString::Concat(rTitle) + OUString::Concat("\n") + 
OUString::Concat(rDescription));
+        pAttrs->add(XML_descr, OUStringToOString(value, 
RTL_TEXTENCODING_UTF8));
+    }
+    return pAttrs;
+}
+
 void DocxAttributeOutput::FlyFrameGraphic( const SwGrfNode* pGrfNode, const 
Size& rSize, const SwFlyFrameFormat* pOLEFrameFormat, SwOLENode* pOLENode, 
const SdrObject* pSdrObj )
 {
     SAL_INFO("sw.ww8", "TODO DocxAttributeOutput::FlyFrameGraphic( const 
SwGrfNode* pGrfNode, const Size& rSize, const SwFlyFrameFormat* 
pOLEFrameFormat, SwOLENode* pOLENode, const SdrObject* pSdrObj  ) - some stuff 
still missing" );
@@ -5744,25 +5768,10 @@ void DocxAttributeOutput::FlyFrameGraphic( const 
SwGrfNode* pGrfNode, const Size
     m_rExport.SdrExporter().startDMLAnchorInline(pFrameFormat, aSize);
 
     // picture description (used for pic:cNvPr later too)
-    rtl::Reference<::sax_fastparser::FastAttributeList> docPrattrList = 
FastSerializerHelper::createAttrList();
-    docPrattrList->add( XML_id, OString::number( m_anchorId++).getStr());
-    docPrattrList->add( XML_name, OUStringToOString( pFrameFormat->GetName(), 
RTL_TEXTENCODING_UTF8 ) );
     OUString const descr(pGrfNode ? pGrfNode->GetDescription() : 
pOLEFrameFormat->GetObjDescription());
     OUString const title(pGrfNode ? pGrfNode->GetTitle() : 
pOLEFrameFormat->GetObjTitle());
-    if (GetExport().GetFilter().getVersion() != 
oox::core::ECMA_376_1ST_EDITION)
-    {
-        docPrattrList->add(XML_descr, OUStringToOString(descr, 
RTL_TEXTENCODING_UTF8));
-        docPrattrList->add(XML_title, OUStringToOString(title, 
RTL_TEXTENCODING_UTF8));
-    }
-    else
-    {   // tdf#148952 no title attribute, merge it into descr
-        OUString const value(title.isEmpty()
-            ? descr
-            : descr.isEmpty()
-                ? title
-                : title + OUString::Concat("\n") + descr);
-        docPrattrList->add(XML_descr, OUStringToOString(value, 
RTL_TEXTENCODING_UTF8));
-    }
+    auto const docPrattrList(CreateDocPrAttrList(
+        GetExport(), m_anchorId++, pFrameFormat->GetName(), title, descr));
     m_pSerializer->startElementNS( XML_wp, XML_docPr, docPrattrList );
 
     OUString sURL, sRelId;
@@ -5965,14 +5974,19 @@ void DocxAttributeOutput::WritePostponedChart()
             if( xNamed.is() )
                 sName = xNamed->getName();
 
+            // tdf#153203  export a11y related properties
+            uno::Reference<beans::XPropertySet> xShapeProps(xShape, 
uno::UNO_QUERY);
+            OUString const 
title(xShapeProps->getPropertyValue("Title").get<OUString>());
+            OUString const 
descr(xShapeProps->getPropertyValue("Description").get<OUString>());
+
             /* If there is a scenario where a chart is followed by a shape
                which is being exported as an alternate content then, the
                docPr Id is being repeated, ECMA 20.4.2.5 says that the
                docPr Id should be unique, ensuring the same here.
                */
-            m_pSerializer->singleElementNS( XML_wp, XML_docPr,
-                    XML_id, OString::number(m_anchorId++),
-                    XML_name, sName );
+            auto const docPrattrList(CreateDocPrAttrList(
+                GetExport(), m_anchorId++, sName, title, descr));
+            m_pSerializer->singleElementNS(XML_wp, XML_docPr, docPrattrList);
 
             m_pSerializer->singleElementNS(XML_wp, XML_cNvGraphicFramePr);
 
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx 
b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index d25e3463d7f5..8c424e12dda8 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -4165,9 +4165,28 @@ void DomainMapper_Impl::UpdateEmbeddedShapeProps(const 
uno::Reference< drawing::
     awt::Size aSize = xShape->getSize( );
     xEmbeddedProperties->setPropertyValue(getPropertyName(PROP_WIDTH), 
uno::Any(sal_Int32(aSize.Width)));
     xEmbeddedProperties->setPropertyValue(getPropertyName(PROP_HEIGHT), 
uno::Any(sal_Int32(aSize.Height)));
+    uno::Reference<beans::XPropertySet> const xShapeProps(xShape, 
uno::UNO_QUERY);
+    // tdf#130782 copy a11y related properties
+    xEmbeddedProperties->setPropertyValue(getPropertyName(PROP_DESCRIPTION),
+        xShapeProps->getPropertyValue(getPropertyName(PROP_DESCRIPTION)));
+    xEmbeddedProperties->setPropertyValue(getPropertyName(PROP_TITLE),
+        xShapeProps->getPropertyValue(getPropertyName(PROP_TITLE)));
+    uno::Reference<container::XNamed> const xEmbedName(m_xEmbedded, 
uno::UNO_QUERY);
+    uno::Reference<container::XNamed> const xShapeName(xShape, uno::UNO_QUERY);
+    OUString const name(xShapeName->getName());
+    if (!name.isEmpty()) // setting empty name will throw
+    {
+        try
+        {
+            xEmbedName->setName(name);
+        }
+        catch (uno::RuntimeException const&)
+        {
+            // ignore - document may contain duplicates 
(testchartoleobjectembeddings.docx)
+        }
+    }
 }
 
-
 void DomainMapper_Impl::PopShapeContext()
 {
     if (hasTableManager())
diff --git a/writerfilter/source/dmapper/GraphicImport.cxx 
b/writerfilter/source/dmapper/GraphicImport.cxx
index ba1408f2093e..31efcfe068d5 100644
--- a/writerfilter/source/dmapper/GraphicImport.cxx
+++ b/writerfilter/source/dmapper/GraphicImport.cxx
@@ -1347,6 +1347,7 @@ void GraphicImport::lcl_attribute(Id nName, Value& rValue)
                         uno::Reference< beans::XPropertySet > 
xShapeProps(m_xShape, uno::UNO_QUERY_THROW);
                         m_pImpl->applyMargins(xShapeProps);
                         m_pImpl->applyZOrder(xShapeProps);
+                        m_pImpl->applyName(xShapeProps);
                         comphelper::SequenceAsHashMap 
aInteropGrabBag(xShapeProps->getPropertyValue("InteropGrabBag"));
                         aInteropGrabBag.update(m_pImpl->getInteropGrabBag());
                         xShapeProps->setPropertyValue("InteropGrabBag", 
uno::Any(aInteropGrabBag.getAsConstPropertyValueList()));

Reply via email to