diff options
author | Attila Bakos <bakos.attilakaroly@nisz.hu> | 2020-05-07 17:23:48 +0200 |
---|---|---|
committer | László Németh <nemeth@numbertext.org> | 2020-05-26 09:37:46 +0200 |
commit | 46695f3d66cc77b38865c1817b09d95e9c4b6683 (patch) | |
tree | a5046041dda09549aba26bc315458aa32e384fbc /starmath | |
parent | fd238380ae7820f12ac1f7c52d0f7180a93f3ba3 (diff) |
tdf#133030: DOCX export: fix formula alignment - part 3
Follow-up of commit 1237acf9851f8b12d1ccd929e2aa8b184c06d552
(tdf#132811 DOCX: fix formula alignment – part 2)
Co-authored-by: Tibor Nagy (NISZ)
Change-Id: I5466649a2aa6b7ffdb0def723f79dfbecdf1495f
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/93665
Tested-by: László Németh <nemeth@numbertext.org>
Reviewed-by: László Németh <nemeth@numbertext.org>
Diffstat (limited to 'starmath')
-rw-r--r-- | starmath/inc/document.hxx | 3 | ||||
-rw-r--r-- | starmath/inc/unomodel.hxx | 2 | ||||
-rw-r--r-- | starmath/source/document.cxx | 9 | ||||
-rw-r--r-- | starmath/source/ooxmlexport.cxx | 53 | ||||
-rw-r--r-- | starmath/source/ooxmlexport.hxx | 2 | ||||
-rw-r--r-- | starmath/source/unomodel.cxx | 4 |
6 files changed, 61 insertions, 12 deletions
diff --git a/starmath/inc/document.hxx b/starmath/inc/document.hxx index 3fedfb13db17..1b425c91e7d1 100644 --- a/starmath/inc/document.hxx +++ b/starmath/inc/document.hxx @@ -207,7 +207,8 @@ public: void writeFormulaOoxml(const ::sax_fastparser::FSHelperPtr& pSerializer, oox::core::OoxmlVersion version, - oox::drawingml::DocumentType documentType); + oox::drawingml::DocumentType documentType, + const sal_Int8 nAlign); void writeFormulaRtf(OStringBuffer& rBuffer, rtl_TextEncoding nEncoding); void readFormulaOoxml( oox::formulaimport::XmlStream& stream ); diff --git a/starmath/inc/unomodel.hxx b/starmath/inc/unomodel.hxx index b2b536dd6d62..f18b09381c38 100644 --- a/starmath/inc/unomodel.hxx +++ b/starmath/inc/unomodel.hxx @@ -86,7 +86,7 @@ public: // oox::FormulaExportBase virtual void writeFormulaOoxml(::sax_fastparser::FSHelperPtr pSerializer, oox::core::OoxmlVersion version, - oox::drawingml::DocumentType documentType) override; + oox::drawingml::DocumentType documentType, sal_Int8 nAlign) override; virtual void writeFormulaRtf(OStringBuffer& rBuffer, rtl_TextEncoding nEncoding) override; // oox::FormulaImportBase virtual void readFormulaOoxml( oox::formulaimport::XmlStream& stream ) override; diff --git a/starmath/source/document.cxx b/starmath/source/document.cxx index 644942126c31..8f9925c3c024 100644 --- a/starmath/source/document.cxx +++ b/starmath/source/document.cxx @@ -83,6 +83,7 @@ #include "cfgitem.hxx" #include <memory> #include <utility> +#include <oox/mathml/export.hxx> using namespace ::com::sun::star; using namespace ::com::sun::star::accessibility; @@ -854,14 +855,18 @@ bool SmDocShell::ConvertTo( SfxMedium &rMedium ) void SmDocShell::writeFormulaOoxml( ::sax_fastparser::FSHelperPtr const& pSerializer, oox::core::OoxmlVersion const version, - oox::drawingml::DocumentType const documentType) + oox::drawingml::DocumentType const documentType, + const sal_Int8 nAlign) { if( !mpTree ) Parse(); if( mpTree ) ArrangeFormula(); SmOoxmlExport aEquation(mpTree.get(), version, documentType); - aEquation.ConvertFromStarMath( pSerializer ); + if(documentType == oox::drawingml::DOCUMENT_DOCX) + aEquation.ConvertFromStarMath( pSerializer, nAlign); + else + aEquation.ConvertFromStarMath(pSerializer, oox::FormulaExportBase::eFormulaAlign::INLINE); } void SmDocShell::writeFormulaRtf(OStringBuffer& rBuffer, rtl_TextEncoding nEncoding) diff --git a/starmath/source/ooxmlexport.cxx b/starmath/source/ooxmlexport.cxx index f52c7275b399..fff9cd7c598c 100644 --- a/starmath/source/ooxmlexport.cxx +++ b/starmath/source/ooxmlexport.cxx @@ -13,6 +13,7 @@ #include <oox/token/tokens.hxx> #include <rtl/ustring.hxx> #include <sal/log.hxx> +#include <oox/mathml/export.hxx> using namespace oox; using namespace oox::core; @@ -25,15 +26,57 @@ SmOoxmlExport::SmOoxmlExport(const SmNode *const pIn, OoxmlVersion const v, { } -void SmOoxmlExport::ConvertFromStarMath( const ::sax_fastparser::FSHelperPtr& serializer ) +void SmOoxmlExport::ConvertFromStarMath( const ::sax_fastparser::FSHelperPtr& serializer, const sal_Int8 nAlign ) { if( m_pTree == nullptr ) return; m_pSerializer = serializer; - m_pSerializer->startElementNS( XML_m, XML_oMath, - FSNS( XML_xmlns, XML_m ), "http://schemas.openxmlformats.org/officeDocument/2006/math" ); - HandleNode( m_pTree, 0 ); - m_pSerializer->endElementNS( XML_m, XML_oMath ); + + //Formula alignment situations: + // + // 1)Inline(as before): + // + // <m:oMath> + // <m:r> ... </m:r> + // </m:oMath> + // + // 2)Aligned: + // + // <m:oMathPara> + // <m:oMathParaPr> + // <m:jc m:val="left|right|center"> + // </m:oMathParaPr> + // <m:oMath> + // <m:r> ... </m:r> + // </m:oMath> + // </m:oMathPara> + + if (nAlign != FormulaExportBase::eFormulaAlign::INLINE) + { + m_pSerializer->startElementNS(XML_m, XML_oMathPara, + FSNS(XML_xmlns, XML_m), "http://schemas.openxmlformats.org/officeDocument/2006/math"); + m_pSerializer->startElementNS(XML_m, XML_oMathParaPr); + if (nAlign == FormulaExportBase::eFormulaAlign::CENTER) + m_pSerializer->singleElementNS(XML_m, XML_jc, FSNS(XML_m, XML_val), "center"); + if (nAlign == FormulaExportBase::eFormulaAlign::GROUPEDCENTER) + m_pSerializer->singleElementNS(XML_m, XML_jc, FSNS(XML_m, XML_val), "center"); + if (nAlign == FormulaExportBase::eFormulaAlign::LEFT) + m_pSerializer->singleElementNS(XML_m, XML_jc, FSNS(XML_m, XML_val), "left"); + if (nAlign == FormulaExportBase::eFormulaAlign::RIGHT) + m_pSerializer->singleElementNS(XML_m, XML_jc, FSNS(XML_m, XML_val), "right"); + m_pSerializer->endElementNS(XML_m, XML_oMathParaPr); + m_pSerializer->startElementNS(XML_m, XML_oMath); + HandleNode(m_pTree, 0); + m_pSerializer->endElementNS(XML_m, XML_oMath); + m_pSerializer->endElementNS(XML_m, XML_oMathPara); + } + else //else, inline as was before + { + m_pSerializer->startElementNS(XML_m, XML_oMath, + FSNS(XML_xmlns, XML_m), "http://schemas.openxmlformats.org/officeDocument/2006/math"); + HandleNode( m_pTree, 0 ); + m_pSerializer->endElementNS( XML_m, XML_oMath ); + } } // NOTE: This is still work in progress and unfinished, but it already covers a good diff --git a/starmath/source/ooxmlexport.hxx b/starmath/source/ooxmlexport.hxx index f7e05d7d165f..fec33ab8e37b 100644 --- a/starmath/source/ooxmlexport.hxx +++ b/starmath/source/ooxmlexport.hxx @@ -24,7 +24,7 @@ class SmOoxmlExport : public SmWordExportBase public: SmOoxmlExport(const SmNode* pIn, oox::core::OoxmlVersion version, oox::drawingml::DocumentType documentType); - void ConvertFromStarMath( const ::sax_fastparser::FSHelperPtr& m_pSerializer ); + void ConvertFromStarMath( const ::sax_fastparser::FSHelperPtr& m_pSerializer, const sal_Int8 ); private: void HandleVerticalStack( const SmNode* pNode, int nLevel ) override; void HandleText( const SmNode* pNode, int nLevel ) override; diff --git a/starmath/source/unomodel.cxx b/starmath/source/unomodel.cxx index 62c2aeb60303..17d52ce7b4d6 100644 --- a/starmath/source/unomodel.cxx +++ b/starmath/source/unomodel.cxx @@ -1077,9 +1077,9 @@ void SAL_CALL SmModel::setParent( const uno::Reference< uno::XInterface >& xPare void SmModel::writeFormulaOoxml( ::sax_fastparser::FSHelperPtr const pSerializer, oox::core::OoxmlVersion const version, - oox::drawingml::DocumentType const documentType) + oox::drawingml::DocumentType const documentType, sal_Int8 nAlign) { - static_cast<SmDocShell*>(GetObjectShell())->writeFormulaOoxml(pSerializer, version, documentType); + static_cast<SmDocShell*>(GetObjectShell())->writeFormulaOoxml(pSerializer, version, documentType, nAlign); } void SmModel::writeFormulaRtf(OStringBuffer& rBuffer, rtl_TextEncoding nEncoding) |