summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Stahl <michael.stahl@allotropia.de>2023-02-01 19:45:54 +0100
committerCaolán McNamara <caolanm@redhat.com>2023-02-08 14:56:41 +0000
commit35d5a64fc3b507e83b037dd35f856069a742a254 (patch)
tree8a71c4ea3f0c6121a2d0ee5a6310daeede84455a
parent8e3eb90ffc50bb1b53214d6953765ebb4ce47690 (diff)
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.stahl@allotropia.de> (cherry picked from commit fa1f2b7f5c65d66eaa5887acc9da5eb526570b18) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/146509 Reviewed-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r--sw/qa/extras/odfexport/odfexport.cxx4
-rw-r--r--sw/qa/extras/ooxmlexport/data/chart.docxbin0 -> 24453 bytes
-rw-r--r--sw/qa/extras/ooxmlexport/ooxmlexport18.cxx13
-rw-r--r--sw/source/filter/ww8/docxattributeoutput.cxx54
-rw-r--r--writerfilter/source/dmapper/DomainMapper_Impl.cxx21
-rw-r--r--writerfilter/source/dmapper/GraphicImport.cxx1
6 files changed, 70 insertions, 23 deletions
diff --git a/sw/qa/extras/odfexport/odfexport.cxx b/sw/qa/extras/odfexport/odfexport.cxx
index f8c774b3053d..bfc75df25ad7 100644
--- a/sw/qa/extras/odfexport/odfexport.cxx
+++ b/sw/qa/extras/odfexport/odfexport.cxx
@@ -954,7 +954,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());
@@ -968,7 +968,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
--- /dev/null
+++ b/sw/qa/extras/ooxmlexport/data/chart.docx
Binary files differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx
index 984f29bbd905..be8e5cf663bd 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx
@@ -121,6 +121,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 538e861352c8..2079e6c631e9 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -5581,6 +5581,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_DIALECT)
+ {
+ 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" );
@@ -5679,25 +5703,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_DIALECT )
- {
- 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;
@@ -5900,14 +5909,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 5a0adad967c9..5d4cff125ce4 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -4137,9 +4137,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()));