summaryrefslogtreecommitdiff
path: root/writerfilter
diff options
context:
space:
mode:
authorAttila Bakos <bakos.attilakaroly@nisz.hu>2020-03-31 18:48:58 +0200
committerLászló Németh <nemeth@numbertext.org>2020-04-29 16:53:23 +0200
commit8b613c4603047dc24aa9b03fb49f4fe1b65af2a3 (patch)
tree5a21dc6001fc31281e4b5e86482f1a20b5c63496 /writerfilter
parentd0124728059088cd72cb173e33df89d785ae2ab5 (diff)
tdf#121525 OOXML import: fix formula alignment
Formula alignment was not handled at all. Now "oMathPara", "oMathParaPr" elements and m:jc attribute are handled using paragraph alignment, as a workaround. Co-author: Tibor Nagy Change-Id: I71546755492e0f9187c77f5324bada6f3c68f0dc Reviewed-on: https://gerrit.libreoffice.org/c/core/+/91435 Tested-by: László Németh <nemeth@numbertext.org> Reviewed-by: László Németh <nemeth@numbertext.org>
Diffstat (limited to 'writerfilter')
-rw-r--r--writerfilter/source/dmapper/DomainMapper.cxx12
-rw-r--r--writerfilter/source/dmapper/DomainMapper.hxx8
-rw-r--r--writerfilter/source/dmapper/DomainMapper_Impl.cxx41
-rw-r--r--writerfilter/source/dmapper/DomainMapper_Impl.hxx2
-rw-r--r--writerfilter/source/ooxml/OOXMLFastContextHandler.cxx40
-rw-r--r--writerfilter/source/ooxml/OOXMLFastContextHandler.hxx10
-rw-r--r--writerfilter/source/ooxml/model.xml9
7 files changed, 114 insertions, 8 deletions
diff --git a/writerfilter/source/dmapper/DomainMapper.cxx b/writerfilter/source/dmapper/DomainMapper.cxx
index 4b9c1d13aa88..07bd913f6773 100644
--- a/writerfilter/source/dmapper/DomainMapper.cxx
+++ b/writerfilter/source/dmapper/DomainMapper.cxx
@@ -732,8 +732,18 @@ void DomainMapper::lcl_attribute(Id nName, Value & val)
m_pImpl->ImportGraphic( val.getProperties(), IMPORT_AS_DETECTED_INLINE );
}
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);
+ break;
+ case NS_ooxml::LN_Value_math_ST_Jc_left:
+ m_pImpl->appendStarMath(val, eMathParaJc::LEFT);
+ break;
+ case NS_ooxml::LN_Value_math_ST_Jc_right:
+ m_pImpl->appendStarMath(val, eMathParaJc::RIGHT);
+ break;
case NS_ooxml::LN_starmath:
- m_pImpl->appendStarMath( val );
+ m_pImpl->appendStarMath( val, eMathParaJc::INLINE );
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 6fdb44e5c9c0..dfabf1e0aab2 100644
--- a/writerfilter/source/dmapper/DomainMapper.hxx
+++ b/writerfilter/source/dmapper/DomainMapper.hxx
@@ -129,6 +129,14 @@ 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 c46fb12139c7..4ef7b844d58b 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -2176,7 +2176,7 @@ void DomainMapper_Impl::appendOLE( const OUString& rStreamName, const std::share
}
-void DomainMapper_Impl::appendStarMath( const Value& val )
+void DomainMapper_Impl::appendStarMath( const Value& val , sal_uInt8 nAlign)
{
uno::Reference< embed::XEmbeddedObject > formula;
val.getAny() >>= formula;
@@ -2219,9 +2219,42 @@ void DomainMapper_Impl::appendStarMath( const Value& val )
uno::makeAny( sal_Int32(size.Height())));
// mimic the treatment of graphics here... it seems anchoring as character
// gives a better ( visually ) result
- xStarMathProperties->setPropertyValue(getPropertyName( PROP_ANCHOR_TYPE ),
- uno::makeAny( text::TextContentAnchorType_AS_CHARACTER ) );
- appendTextContent( xStarMath, uno::Sequence< beans::PropertyValue >() );
+ 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),
+ uno::makeAny(text::TextContentAnchorType_AS_CHARACTER));
+ }
}
catch( const uno::Exception& )
{
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.hxx b/writerfilter/source/dmapper/DomainMapper_Impl.hxx
index c96a68b00bbd..33a4eb5fa95f 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.hxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.hxx
@@ -678,7 +678,7 @@ 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 );
+ void appendStarMath( const Value& v , sal_uInt8);
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
diff --git a/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx b/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx
index f05f305797ec..4cb719818012 100644
--- a/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx
+++ b/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx
@@ -66,6 +66,8 @@ OOXMLFastContextHandler::OOXMLFastContextHandler
mId(0),
mnDefine(0),
mnToken(oox::XML_TOKEN_COUNT),
+ mnMathJcVal(0),
+ mbIsMathPara(false),
mpStream(nullptr),
mnTableDepth(0),
inPositionV(false),
@@ -87,6 +89,8 @@ OOXMLFastContextHandler::OOXMLFastContextHandler(OOXMLFastContextHandler * pCont
mId(0),
mnDefine(0),
mnToken(oox::XML_TOKEN_COUNT),
+ mnMathJcVal(pContext->mnMathJcVal),
+ mbIsMathPara(pContext->mbIsMathPara),
mpStream(pContext->mpStream),
mpParserState(pContext->mpParserState),
mnTableDepth(pContext->mnTableDepth),
@@ -162,6 +166,19 @@ void SAL_CALL OOXMLFastContextHandler::startFastElement
mbPreserveSpace = Attribs->getValue(oox::NMSP_xml | oox::XML_space) == "preserve";
mbPreserveSpaceSet = true;
}
+ if (Element == (NMSP_officeMath | XML_oMathPara))
+ {
+ mnMathJcVal = eMathParaJc::CENTER;
+ mbIsMathPara = true;
+ }
+ if (Element == (NMSP_officeMath | XML_jc) && mpParent && mpParent->mpParent )
+ {
+ mbIsMathPara = true;
+ auto aAttrLst = Attribs->getFastAttributes();
+ if (aAttrLst[0].Value == "center") mpParent->mpParent->mnMathJcVal = eMathParaJc::CENTER;
+ if (aAttrLst[0].Value == "left") mpParent->mpParent->mnMathJcVal = eMathParaJc::LEFT;
+ if (aAttrLst[0].Value == "right") mpParent->mpParent->mnMathJcVal = eMathParaJc::RIGHT;
+ }
if (oox::getNamespace(Element) == NMSP_mce)
m_bDiscardChildren = prepareMceContext(Element, Attribs);
@@ -2143,7 +2160,28 @@ void OOXMLFastContextHandlerMath::process()
{
OOXMLPropertySet::Pointer_t pProps(new OOXMLPropertySet);
OOXMLValue::Pointer_t pVal( new OOXMLStarMathValue( ref ));
- pProps->add(NS_ooxml::LN_starmath, pVal, OOXMLProperty::ATTRIBUTE);
+ if (mbIsMathPara)
+ {
+ switch (mnMathJcVal)
+ {
+ case eMathParaJc::CENTER:
+ pProps->add(NS_ooxml::LN_Value_math_ST_Jc_centerGroup, pVal,
+ OOXMLProperty::ATTRIBUTE);
+ break;
+ case eMathParaJc::LEFT:
+ pProps->add(NS_ooxml::LN_Value_math_ST_Jc_left, pVal,
+ OOXMLProperty::ATTRIBUTE);
+ break;
+ case eMathParaJc::RIGHT:
+ pProps->add(NS_ooxml::LN_Value_math_ST_Jc_right, pVal,
+ OOXMLProperty::ATTRIBUTE);
+ break;
+ default:
+ break;
+ }
+ }
+ else
+ pProps->add(NS_ooxml::LN_starmath, pVal, OOXMLProperty::ATTRIBUTE);
mpStream->props( pProps.get() );
}
}
diff --git a/writerfilter/source/ooxml/OOXMLFastContextHandler.hxx b/writerfilter/source/ooxml/OOXMLFastContextHandler.hxx
index 5bc4ea382f12..ca6e6507ecba 100644
--- a/writerfilter/source/ooxml/OOXMLFastContextHandler.hxx
+++ b/writerfilter/source/ooxml/OOXMLFastContextHandler.hxx
@@ -195,6 +195,16 @@ protected:
Id mnDefine;
Token_t mnToken;
+ // the formula insertion mode: inline/newline(left, center, right)
+ sal_Int8 mnMathJcVal;
+ bool mbIsMathPara;
+ enum eMathParaJc
+ {
+ INLINE, //The equation is anchored as inline to the text
+ CENTER, //The equation is center aligned
+ LEFT, //The equation is left aligned
+ RIGHT //The equation is right aligned
+ };
// the stream to send the stream events to.
Stream * mpStream;
diff --git a/writerfilter/source/ooxml/model.xml b/writerfilter/source/ooxml/model.xml
index b3899472d5e3..380fc3f01086 100644
--- a/writerfilter/source/ooxml/model.xml
+++ b/writerfilter/source/ooxml/model.xml
@@ -8127,6 +8127,11 @@
<ref name="CT_OMath"/>
</element>
</define>
+ <define name="oMathParaPr">
+ <element name="oMathParaPr">
+ <ref name="CT_OMathParaPr"/>
+ </element>
+ </define>
</grammar>
<resource name="ST_Integer255" resource="Integer"/>
<resource name="CT_Integer255" resource="Value">
@@ -8232,7 +8237,7 @@
<resource name="CT_Style" resource="Value">
<attribute name="val" tokenid="ooxml:CT_Style_val" action="setValue"/>
</resource>
- <resource name="ST_Jc" resource="List">
+ <resource name="ST_Jc" resource="String">
<value tokenid="ooxml:Value_math_ST_Jc_start">left</value>
<value tokenid="ooxml:Value_math_ST_Jc_end">right</value>
<value tokenid="ooxml:Value_math_ST_Jc_left">left</value>
@@ -19184,6 +19189,8 @@
</resource>
<resource name="CT_OMath" resource="Math"/>
<resource name="CT_OMathPara" resource="Stream"/>
+ <resource name="CT_OMathParaPr" resource="Properties"/>
+ <resource name="CT_OMathJc" resource="Value"/>
</namespace>
</model>
<!-- vim: shiftwidth=2 softtabstop=2 expandtab: