diff options
author | Attila Bakos <bakos.attilakaroly@nisz.hu> | 2020-05-07 10:40:44 +0200 |
---|---|---|
committer | László Németh <nemeth@numbertext.org> | 2020-05-12 12:03:35 +0200 |
commit | 1237acf9851f8b12d1ccd929e2aa8b184c06d552 (patch) | |
tree | ad6b438253aab2311e4ddcf5f75d5834d9d262d5 | |
parent | e21ef73de4591c0d8e11920b7c21d7bbfeddc701 (diff) |
tdf#132811 DOCX: fix formula alignment – part 2
Formula are aligned inline again, but in the
right position, fixing both import and export.
This partially reverts
commit 8b613c4603047dc24aa9b03fb49f4fe1b65af2a3
(tdf#121525 OOXML import: fix formula alignment).
Co-author: Tibor Nagy (NISZ)
Change-Id: If5c13db749fe5c3b1aee754b47dabc9fabd7ebb9
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/93631
Tested-by: László Németh <nemeth@numbertext.org>
Reviewed-by: László Németh <nemeth@numbertext.org>
-rw-r--r-- | sw/qa/extras/ooxmlexport/ooxmlexport14.cxx | 21 | ||||
-rw-r--r-- | writerfilter/source/dmapper/DomainMapper.cxx | 11 | ||||
-rw-r--r-- | writerfilter/source/dmapper/DomainMapper.hxx | 8 | ||||
-rw-r--r-- | writerfilter/source/dmapper/DomainMapper_Impl.cxx | 44 | ||||
-rw-r--r-- | writerfilter/source/dmapper/DomainMapper_Impl.hxx | 3 |
5 files changed, 29 insertions, 58 deletions
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx index 358ed59bd4ae..8c40788c3dd9 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx @@ -48,27 +48,30 @@ DECLARE_OOXMLIMPORT_TEST(Tdf130907,"tdf130907.docx") { uno::Reference<text::XTextRange> xPara1 = getParagraph(2); CPPUNIT_ASSERT(xPara1.is()); - uno::Reference<beans::XPropertySet> xFormula1Props = getParagraphAnchoredObject(0, xPara1); + uno::Reference<beans::XPropertySet> xFormula1Props(xPara1, uno::UNO_QUERY); CPPUNIT_ASSERT(xFormula1Props.is()); sal_Int16 nHOri1; - xFormula1Props->getPropertyValue("HoriOrient") >>= nHOri1; - CPPUNIT_ASSERT_EQUAL_MESSAGE("The alignment of the equation is not left!",sal_Int16(3),nHOri1); + xFormula1Props->getPropertyValue("ParaAdjust") >>= nHOri1; + CPPUNIT_ASSERT_EQUAL_MESSAGE("The alignment of the equation is not left!", + sal_Int16(style::ParagraphAdjust::ParagraphAdjust_LEFT), nHOri1); uno::Reference<text::XTextRange> xPara2 = getParagraph(3); CPPUNIT_ASSERT(xPara2.is()); - uno::Reference<beans::XPropertySet> xFormula2Props = getParagraphAnchoredObject(0, xPara2); + uno::Reference<beans::XPropertySet> xFormula2Props(xPara2, uno::UNO_QUERY); CPPUNIT_ASSERT(xFormula2Props.is()); sal_Int16 nHOri2; - xFormula2Props->getPropertyValue("HoriOrient") >>= nHOri2; - CPPUNIT_ASSERT_EQUAL_MESSAGE("The alignment of the equation is not center!", sal_Int16(2), nHOri2); + xFormula2Props->getPropertyValue("ParaAdjust") >>= nHOri2; + CPPUNIT_ASSERT_EQUAL_MESSAGE("The alignment of the equation is not center!", + sal_Int16(style::ParagraphAdjust::ParagraphAdjust_CENTER), nHOri2); uno::Reference<text::XTextRange> xPara3 = getParagraph(5); CPPUNIT_ASSERT(xPara3.is()); - uno::Reference<beans::XPropertySet> xFormula3Props = getParagraphAnchoredObject(0, xPara3); + uno::Reference<beans::XPropertySet> xFormula3Props(xPara3, uno::UNO_QUERY); CPPUNIT_ASSERT(xFormula3Props.is()); sal_Int16 nHOri3; - xFormula3Props->getPropertyValue("HoriOrient") >>= nHOri3; - CPPUNIT_ASSERT_EQUAL_MESSAGE("The alignment of the equation is not right!", sal_Int16(1), nHOri3); + xFormula3Props->getPropertyValue("ParaAdjust") >>= nHOri3; + CPPUNIT_ASSERT_EQUAL_MESSAGE("The alignment of the equation is not right!", + sal_Int16(style::ParagraphAdjust::ParagraphAdjust_RIGHT), nHOri3); } DECLARE_OOXMLEXPORT_EXPORTONLY_TEST(testTdf78749, "tdf78749.docx") diff --git a/writerfilter/source/dmapper/DomainMapper.cxx b/writerfilter/source/dmapper/DomainMapper.cxx index e2d497c8a8d4..8eab461992b6 100644 --- a/writerfilter/source/dmapper/DomainMapper.cxx +++ b/writerfilter/source/dmapper/DomainMapper.cxx @@ -734,16 +734,19 @@ void DomainMapper::lcl_attribute(Id nName, Value & val) break; case NS_ooxml::LN_Value_math_ST_Jc_centerGroup: case NS_ooxml::LN_Value_math_ST_Jc_center: - m_pImpl->appendStarMath(val, eMathParaJc::CENTER); + m_pImpl->appendStarMath(val); + m_pImpl->adjustLastPara(sal_Int8(style::ParagraphAdjust::ParagraphAdjust_CENTER)); break; case NS_ooxml::LN_Value_math_ST_Jc_left: - m_pImpl->appendStarMath(val, eMathParaJc::LEFT); + m_pImpl->appendStarMath(val); + m_pImpl->adjustLastPara(sal_Int8(style::ParagraphAdjust::ParagraphAdjust_LEFT)); break; case NS_ooxml::LN_Value_math_ST_Jc_right: - m_pImpl->appendStarMath(val, eMathParaJc::RIGHT); + m_pImpl->appendStarMath(val); + m_pImpl->adjustLastPara(sal_Int8(style::ParagraphAdjust::ParagraphAdjust_RIGHT)); break; case NS_ooxml::LN_starmath: - m_pImpl->appendStarMath( val, eMathParaJc::INLINE ); + m_pImpl->appendStarMath(val); break; case NS_ooxml::LN_CT_FramePr_dropCap: case NS_ooxml::LN_CT_FramePr_lines: diff --git a/writerfilter/source/dmapper/DomainMapper.hxx b/writerfilter/source/dmapper/DomainMapper.hxx index 31e5fa705838..c8281f9334ec 100644 --- a/writerfilter/source/dmapper/DomainMapper.hxx +++ b/writerfilter/source/dmapper/DomainMapper.hxx @@ -129,14 +129,6 @@ public: void HandleRedline( Sprm& rSprm ); - enum eMathParaJc - { - INLINE, - CENTER, - LEFT, - RIGHT - }; - private: // Stream virtual void lcl_startSectionGroup() override; diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx index fde30248f6d1..6d8f0822e7ce 100644 --- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx +++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx @@ -99,7 +99,6 @@ #include <tools/diagnose_ex.h> #include <sal/log.hxx> - using namespace ::com::sun::star; using namespace oox; namespace writerfilter::dmapper{ @@ -2207,7 +2206,7 @@ void DomainMapper_Impl::appendOLE( const OUString& rStreamName, const std::share } -void DomainMapper_Impl::appendStarMath( const Value& val , sal_uInt8 nAlign) +void DomainMapper_Impl::appendStarMath( const Value& val ) { uno::Reference< embed::XEmbeddedObject > formula; val.getAny() >>= formula; @@ -2251,41 +2250,8 @@ void DomainMapper_Impl::appendStarMath( const Value& val , sal_uInt8 nAlign) // mimic the treatment of graphics here... it seems anchoring as character // gives a better ( visually ) result appendTextContent(xStarMath, uno::Sequence<beans::PropertyValue>()); - if (nAlign != DomainMapper::eMathParaJc::INLINE) - { - xStarMathProperties->setPropertyValue( - getPropertyName(PROP_ANCHOR_TYPE), - uno::makeAny(text::TextContentAnchorType_AT_PARAGRAPH)); - switch (nAlign) - { - case DomainMapper::eMathParaJc::CENTER: - xStarMathProperties->setPropertyValue( - getPropertyName(PROP_HORI_ORIENT), - uno::makeAny(text::HoriOrientation::CENTER)); - break; - case DomainMapper::eMathParaJc::LEFT: - xStarMathProperties->setPropertyValue( - getPropertyName(PROP_HORI_ORIENT), - uno::makeAny(text::HoriOrientation::LEFT)); - break; - case DomainMapper::eMathParaJc::RIGHT: - xStarMathProperties->setPropertyValue( - getPropertyName(PROP_HORI_ORIENT), - uno::makeAny(text::HoriOrientation::RIGHT)); - break; - default: - break; - } - xStarMathProperties->setPropertyValue( - "Surround", - uno::makeAny(text::WrapTextMode_NONE)); - } - else - { - xStarMathProperties->setPropertyValue( - getPropertyName(PROP_ANCHOR_TYPE), + xStarMathProperties->setPropertyValue(getPropertyName(PROP_ANCHOR_TYPE), uno::makeAny(text::TextContentAnchorType_AS_CHARACTER)); - } } catch( const uno::Exception& ) { @@ -2294,6 +2260,12 @@ void DomainMapper_Impl::appendStarMath( const Value& val , sal_uInt8 nAlign) } } +void DomainMapper_Impl::adjustLastPara(sal_Int8 nAlign) +{ + PropertyMapPtr pLastPara = GetTopContextOfType(dmapper::CONTEXT_PARAGRAPH); + pLastPara->Insert(PROP_PARA_ADJUST, uno::makeAny(nAlign), true); +} + uno::Reference< beans::XPropertySet > DomainMapper_Impl::appendTextSectionAfter( uno::Reference< text::XTextRange > const & xBefore ) { diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.hxx b/writerfilter/source/dmapper/DomainMapper_Impl.hxx index 8f46234a44ba..d9e97d1764db 100644 --- a/writerfilter/source/dmapper/DomainMapper_Impl.hxx +++ b/writerfilter/source/dmapper/DomainMapper_Impl.hxx @@ -681,7 +681,8 @@ public: void appendTextPortion( const OUString& rString, const PropertyMapPtr& pPropertyMap ); void appendTextContent(const css::uno::Reference<css::text::XTextContent>&, const css::uno::Sequence<css::beans::PropertyValue>&); void appendOLE( const OUString& rStreamName, const std::shared_ptr<OLEHandler>& pOleHandler ); - void appendStarMath( const Value& v , sal_uInt8); + void appendStarMath( const Value& v); + void adjustLastPara(sal_Int8); css::uno::Reference<css::beans::XPropertySet> appendTextSectionAfter(css::uno::Reference<css::text::XTextRange> const & xBefore); /// AutoText import: each entry is placed in the separate section |