diff options
author | Luboš Luňák <l.lunak@suse.cz> | 2011-08-17 14:31:42 +0200 |
---|---|---|
committer | Luboš Luňák <l.lunak@suse.cz> | 2011-08-18 15:33:47 +0200 |
commit | b80005b21226f1b01761a427be31d89dc49e2e02 (patch) | |
tree | 31dadab08c6321b0324b2f49e89c91f23c814433 /starmath | |
parent | ce5626277bc55c17db8322b81be1c5f2d1ad02f6 (diff) |
ooxml math export for vertical stack
Diffstat (limited to 'starmath')
-rw-r--r-- | starmath/source/ooxml.cxx | 50 | ||||
-rw-r--r-- | starmath/source/ooxml.hxx | 1 |
2 files changed, 33 insertions, 18 deletions
diff --git a/starmath/source/ooxml.cxx b/starmath/source/ooxml.cxx index 395d84d0f3c7..740a50c1c03a 100644 --- a/starmath/source/ooxml.cxx +++ b/starmath/source/ooxml.cxx @@ -92,7 +92,7 @@ bool SmOoxml::ConvertFromStarMath( ::sax_fastparser::FSHelperPtr serializer ) void SmOoxml::HandleNodes(SmNode *pNode,int nLevel) { - fprintf(stderr,"XX %d %d\n", nLevel, pNode->GetType()); + fprintf(stderr,"XX %d %d %d\n", nLevel, pNode->GetType(), pNode->GetNumSubNodes()); switch(pNode->GetType()) { #if 0 @@ -202,28 +202,42 @@ void SmOoxml::HandleTable(SmNode *pNode,int nLevel) sal_uInt16 nSize = pNode->GetNumSubNodes(); //The root of the starmath is a table, if //we convert this them each iteration of - //conversion from starmath to mathtype will + //conversion from starmath to OOXML will //add an extra unnecessary level to the - //mathtype output stack which would grow + //OOXML output stack which would grow //without bound in a multi step conversion - -// TODO -// if ( nLevel || (nSize >1)) -// { -// *pS << sal_uInt8(PILE); -// *pS << sal_uInt8(nHAlign); //vAlign ? -// *pS << sal_uInt8(0x01); //hAlign -// } - + if( nLevel || nSize > 1 ) + return HandleVerticalStack( pNode, nLevel, 0 ); for (sal_uInt16 i = 0; i < nSize; i++) if (SmNode *pTemp = pNode->GetSubNode(i)) - { -// *pS << sal_uInt8(LINE); HandleNodes(pTemp,nLevel+1); -// *pS << sal_uInt8(END); - } -// if (nLevel || (nSize>1)) -// *pS << sal_uInt8(END); +} + +// output vertical stack, firstItem says which child to use as first (if there +// are more than two children, OOXML can have only a vertical stack of two items, +// so create a bigger vertical stack recursively) +void SmOoxml::HandleVerticalStack( SmNode* pNode, int nLevel, int firstItem ) +{ + if( firstItem == pNode->GetNumSubNodes() - 1 ) // only one item, just output the item + { + if( SmNode *pTemp = pNode->GetSubNode( firstItem )) + HandleNodes( pTemp, nLevel + 1 ); + return; + } + m_pSerializer->startElementNS( XML_m, XML_f, FSEND ); + m_pSerializer->startElementNS( XML_m, XML_fPr, FSEND ); + m_pSerializer->singleElementNS( XML_m, XML_type, FSNS( XML_m, XML_val ), "noBar", FSEND ); + m_pSerializer->endElementNS( XML_m, XML_fPr ); + m_pSerializer->startElementNS( XML_m, XML_num, FSEND ); + if( SmNode* num = pNode->GetSubNode( firstItem )) + HandleNodes( num, nLevel + 1 ); + m_pSerializer->endElementNS( XML_m, XML_num ); + // TODO this nesting means MSOffice will use smaller fonts for nested items, + // not sure if there's another way to represent a bigger stack than 2 items + m_pSerializer->startElementNS( XML_m, XML_den, FSEND ); + HandleVerticalStack( pNode, nLevel, firstItem + 1 ); + m_pSerializer->endElementNS( XML_m, XML_den ); + m_pSerializer->endElementNS( XML_m, XML_f ); } void SmOoxml::HandleText(SmNode *pNode, int /*nLevel*/) diff --git a/starmath/source/ooxml.hxx b/starmath/source/ooxml.hxx index ba659ff4e432..e6e6d08e7084 100644 --- a/starmath/source/ooxml.hxx +++ b/starmath/source/ooxml.hxx @@ -45,6 +45,7 @@ public: private: void HandleNodes(SmNode *pNode,int nLevel); void HandleTable(SmNode *pNode,int nLevel); + void HandleVerticalStack( SmNode* pNode, int nLevel, int firstItem ); void HandleText(SmNode *pNode,int nLevel); void HandleMath(SmNode *pNode,int nLevel); void HandleFractions( SmNode *pNode,int nLevel, const char* type = NULL ); |