summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorAttila Bakos <bakos.attilakaroly@nisz.hu>2020-05-07 17:23:48 +0200
committerLászló Németh <nemeth@numbertext.org>2020-05-26 09:37:46 +0200
commit46695f3d66cc77b38865c1817b09d95e9c4b6683 (patch)
treea5046041dda09549aba26bc315458aa32e384fbc /sw
parentfd238380ae7820f12ac1f7c52d0f7180a93f3ba3 (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 'sw')
-rw-r--r--sw/qa/extras/ooxmlexport/data/tdf133030.docxbin0 -> 12451 bytes
-rw-r--r--sw/qa/extras/ooxmlexport/ooxmlexport14.cxx9
-rw-r--r--sw/qa/extras/ooxmlexport/ooxmlexport3.cxx2
-rw-r--r--sw/qa/extras/ooxmlexport/ooxmlexport4.cxx2
-rw-r--r--sw/source/filter/ww8/docxattributeoutput.cxx55
-rw-r--r--sw/source/filter/ww8/docxattributeoutput.hxx13
6 files changed, 67 insertions, 14 deletions
diff --git a/sw/qa/extras/ooxmlexport/data/tdf133030.docx b/sw/qa/extras/ooxmlexport/data/tdf133030.docx
new file mode 100644
index 000000000000..e23f09adfc4b
--- /dev/null
+++ b/sw/qa/extras/ooxmlexport/data/tdf133030.docx
Binary files differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx
index 60725f041b32..10b55a397111 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx
@@ -193,6 +193,15 @@ DECLARE_OOXMLEXPORT_EXPORTONLY_TEST(testTdf130120, "tdf130120.docx")
"mc:Choice/w:drawing/wp:anchor", "layoutInCell", "0");
}
+DECLARE_OOXMLEXPORT_EXPORTONLY_TEST(Tdf133030, "tdf133030.docx")
+{
+ auto pExport = parseExport("word/document.xml");
+ CPPUNIT_ASSERT(pExport);
+
+ assertXPath(pExport, "/w:document/w:body/w:p[3]/m:oMathPara/m:oMathParaPr/m:jc", "val", "center");
+ assertXPath(pExport, "/w:document/w:body/w:p[5]/m:oMathPara/m:oMathParaPr/m:jc", "val", "left");
+ assertXPath(pExport, "/w:document/w:body/w:p[7]/m:oMathPara/m:oMathParaPr/m:jc", "val", "right");
+}
DECLARE_OOXMLEXPORT_TEST(testTdf87569v, "tdf87569_vml.docx")
{
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport3.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport3.cxx
index 109c961c5fbc..4df9baf213ea 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport3.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport3.cxx
@@ -998,7 +998,7 @@ DECLARE_OOXMLEXPORT_EXPORTONLY_TEST(testFileOpenInputOutputError,"floatingtbl_wi
assertXPath(pXmlDoc, "/w:document/w:body/w:p[1]/w:pPr/w:pStyle", "val", "Normal");
// let's also assert that the formula was exported properly
- assertXPathContent(pXmlDoc, "//w:tbl/w:tr/w:tc[2]/w:p/m:oMath/m:sSubSup/m:e/m:r/m:t", u"\u03C3");
+ assertXPathContent(pXmlDoc, "//w:tbl/w:tr/w:tc[2]/w:p/m:oMathPara/m:oMath/m:sSubSup/m:e/m:r/m:t", u"\u03C3");
}
DECLARE_OOXMLEXPORT_TEST(testSingleCellTableBorders, "tdf124399_SingleCellTableBorders.docx")
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport4.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport4.cxx
index 621cc1325e6b..4dd7062c6e17 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport4.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport4.cxx
@@ -619,7 +619,7 @@ DECLARE_OOXMLEXPORT_EXPORTONLY_TEST(test_Tdf115030, "tdf115030.docx")
sal_Unicode aDobleDot = {0x00A8};
assertXPath(pXmlDoc, "/w:document/w:body/w:p[1]/m:oMath[1]/m:acc/m:accPr/m:chr", "val", OUString(aDot));
assertXPath(pXmlDoc, "/w:document/w:body/w:p[1]/m:oMath[2]/m:acc/m:accPr/m:chr", "val", OUString(aDobleDot));
- assertXPath(pXmlDoc, "/w:document/w:body/w:p[2]/m:oMath[1]/m:acc/m:accPr/m:chr", "val", OUString(aDot));
+ assertXPath(pXmlDoc, "/w:document/w:body/w:p[2]/m:oMathPara/m:oMath[1]/m:acc/m:accPr/m:chr", "val", OUString(aDot));
}
DECLARE_OOXMLEXPORT_EXPORTONLY_TEST(test_OpeningBrace, "2120112713_OpenBrace.docx")
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx
index 590fcfdad6ae..16c9e518f544 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -143,6 +143,7 @@
#include <stdarg.h>
#include <toolkit/helper/vclunohelper.hxx>
+#include <oox/mathml/export.hxx>
using ::editeng::SvxBorderLine;
@@ -1559,7 +1560,7 @@ void DocxAttributeOutput::EndRun(const SwTextNode* pNode, sal_Int32 nPos, bool /
DoWritePermissionsEnd();
for (const auto& rpMath : m_aPostponedMaths)
- WritePostponedMath(rpMath);
+ WritePostponedMath(rpMath.pMathObject, rpMath.nMathObjAlignment);
m_aPostponedMaths.clear();
for (const auto& rpControl : m_aPostponedFormControls)
@@ -5086,11 +5087,11 @@ void DocxAttributeOutput::FlyFrameGraphic( const SwGrfNode* pGrfNode, const Size
m_rExport.SdrExporter().endDMLAnchorInline(pFrameFormat);
}
-void DocxAttributeOutput::WriteOLE2Obj( const SdrObject* pSdrObj, SwOLENode& rOLENode, const Size& rSize, const SwFlyFrameFormat* pFlyFrameFormat )
+void DocxAttributeOutput::WriteOLE2Obj( const SdrObject* pSdrObj, SwOLENode& rOLENode, const Size& rSize, const SwFlyFrameFormat* pFlyFrameFormat, const sal_Int8 nFormulaAlignment )
{
if( WriteOLEChart( pSdrObj, rSize, pFlyFrameFormat ))
return;
- if( WriteOLEMath( rOLENode ))
+ if( WriteOLEMath( rOLENode , nFormulaAlignment))
return;
PostponeOLE( rOLENode, rSize, pFlyFrameFormat );
}
@@ -5185,18 +5186,28 @@ void DocxAttributeOutput::WritePostponedChart()
m_aPostponedCharts.clear();
}
-bool DocxAttributeOutput::WriteOLEMath( const SwOLENode& rOLENode )
+bool DocxAttributeOutput::WriteOLEMath( const SwOLENode& rOLENode ,const sal_Int8 nAlign)
{
uno::Reference < embed::XEmbeddedObject > xObj(const_cast<SwOLENode&>(rOLENode).GetOLEObj().GetOleRef());
SvGlobalName aObjName(xObj->getClassID());
if( !SotExchange::IsMath(aObjName) )
return false;
- m_aPostponedMaths.push_back(&rOLENode);
+
+ PostponedMathObjects aPostponedMathObject;
+ try
+ {
+ aPostponedMathObject.pMathObject = const_cast<SwOLENode*>( &rOLENode);
+ aPostponedMathObject.nMathObjAlignment = nAlign;
+ m_aPostponedMaths.push_back(aPostponedMathObject);
+ }
+ catch (const uno::Exception&)
+ {
+ }
return true;
}
-void DocxAttributeOutput::WritePostponedMath(const SwOLENode* pPostponedMath)
+void DocxAttributeOutput::WritePostponedMath(const SwOLENode* pPostponedMath, sal_Int8 nAlign)
{
uno::Reference < embed::XEmbeddedObject > xObj(const_cast<SwOLENode*>(pPostponedMath)->GetOLEObj().GetOleRef());
if (embed::EmbedStates::LOADED == xObj->getCurrentState())
@@ -5223,7 +5234,7 @@ void DocxAttributeOutput::WritePostponedMath(const SwOLENode* pPostponedMath)
assert( formulaexport != nullptr );
if (formulaexport)
formulaexport->writeFormulaOoxml( m_pSerializer, GetExport().GetFilter().getVersion(),
- oox::drawingml::DOCUMENT_DOCX);
+ oox::drawingml::DOCUMENT_DOCX, nAlign);
}
void DocxAttributeOutput::WritePostponedFormControl(const SdrObject* pObject)
@@ -5765,7 +5776,35 @@ void DocxAttributeOutput::OutputFlyFrame_Impl( const ww8::Frame &rFrame, const P
{
SwNodeIndex aIdx(*rFrameFormat.GetContent().GetContentIdx(), 1);
SwOLENode& rOLENd = *aIdx.GetNode().GetOLENode();
- WriteOLE2Obj( pSdrObj, rOLENd, rFrame.GetLayoutSize(), dynamic_cast<const SwFlyFrameFormat*>( &rFrameFormat ));
+
+ //output variable for the formula alignment (default inline)
+ sal_Int8 nAlign(FormulaExportBase::eFormulaAlign::INLINE);
+ auto xObj(rOLENd.GetOLEObj().GetOleRef()); //get the xObject of the forumla
+
+ //tdf133030: Export formula position
+ //If we have a formula with inline anchor...
+ if(SotExchange::IsMath(xObj->getClassID()) && rFrame.IsInline())
+ {
+ SwPosition const* const aAPos = rFrameFormat.GetAnchor().GetContentAnchor();
+ if(aAPos)
+ {
+ //Get the text node what the forumla anchored to
+ const SwTextNode* pTextNode = aAPos->nNode.GetNode().GetTextNode();
+ if(pTextNode && pTextNode->Len() == 1)
+ {
+ //Get the paragraph alignment
+ auto aParaAdjust = pTextNode->GetSwAttrSet().GetAdjust().GetAdjust();
+ //And set the formula according to the paragraph alignment
+ if (aParaAdjust == SvxAdjust::Center)
+ nAlign = FormulaExportBase::eFormulaAlign::CENTER;
+ else if (aParaAdjust == SvxAdjust::Right)
+ nAlign = FormulaExportBase::eFormulaAlign::RIGHT;
+ else // left in the case of left and justified paragraph alignments
+ nAlign = FormulaExportBase::eFormulaAlign::LEFT;
+ }
+ }
+ }
+ WriteOLE2Obj( pSdrObj, rOLENd, rFrame.GetLayoutSize(), dynamic_cast<const SwFlyFrameFormat*>( &rFrameFormat ), nAlign);
m_bPostponedProcessingFly = false ;
}
}
diff --git a/sw/source/filter/ww8/docxattributeoutput.hxx b/sw/source/filter/ww8/docxattributeoutput.hxx
index 083a0fd0035c..83e3110734ba 100644
--- a/sw/source/filter/ww8/docxattributeoutput.hxx
+++ b/sw/source/filter/ww8/docxattributeoutput.hxx
@@ -403,9 +403,9 @@ private:
/// @see WriteOLE2Obj()
void FlyFrameGraphic( const SwGrfNode* pGrfNode, const Size& rSize, const SwFlyFrameFormat* pOLEFrameFormat, SwOLENode* pOLENode, const SdrObject* pSdrObj = nullptr);
void WriteSrcRect( const SdrObject* pSdrObj, const SwFrameFormat* pFrameFormat );
- void WriteOLE2Obj( const SdrObject* pSdrObj, SwOLENode& rNode, const Size& rSize, const SwFlyFrameFormat* pFlyFrameFormat);
+ void WriteOLE2Obj( const SdrObject* pSdrObj, SwOLENode& rNode, const Size& rSize, const SwFlyFrameFormat* pFlyFrameFormat, const sal_Int8 nFormulaAlignment);
bool WriteOLEChart( const SdrObject* pSdrObj, const Size& rSize, const SwFlyFrameFormat* pFlyFrameFormat);
- bool WriteOLEMath( const SwOLENode& rNode );
+ bool WriteOLEMath( const SwOLENode& rNode, const sal_Int8 nAlign );
void PostponeOLE( SwOLENode& rNode, const Size& rSize, const SwFlyFrameFormat* pFlyFrameFormat );
void WriteOLE( SwOLENode& rNode, const Size& rSize, const SwFlyFrameFormat* rFlyFrameFormat );
@@ -700,7 +700,7 @@ private:
void DoWriteAnnotationMarks( );
void WritePostponedGraphic();
- void WritePostponedMath(const SwOLENode* pObject);
+ void WritePostponedMath(const SwOLENode* pObject, sal_Int8 /*nAlign*/);
void WritePostponedFormControl(const SdrObject* pObject);
void WritePostponedActiveXControl(bool bInsideRun);
void WritePostponedDiagram();
@@ -901,7 +901,12 @@ private:
};
std::unique_ptr< std::vector<PostponedOLE> > m_pPostponedOLEs;
- std::vector<const SwOLENode*> m_aPostponedMaths;
+ struct PostponedMathObjects
+ {
+ SwOLENode* pMathObject;
+ sal_Int8 nMathObjAlignment;
+ };
+ std::vector<PostponedMathObjects> m_aPostponedMaths;
/// count charts consistently for unit tests
unsigned int m_nChartCount;
struct PostponedChart