diff options
author | Luboš Luňák <l.lunak@suse.cz> | 2011-08-30 15:24:25 +0200 |
---|---|---|
committer | Luboš Luňák <l.lunak@suse.cz> | 2011-08-30 16:56:37 +0200 |
commit | 41fae7dc55878a49571888aff3c29a36bddb834d (patch) | |
tree | 3fc41566c9df094c3bd573fa0b3cbdabc7eb0747 /starmath | |
parent | bf33a26a1a29f33532289f55a9c87930f534ae4e (diff) |
implement math braces export for .docx
Diffstat (limited to 'starmath')
-rw-r--r-- | starmath/inc/node.hxx | 35 | ||||
-rw-r--r-- | starmath/source/ooxml.cxx | 55 | ||||
-rw-r--r-- | starmath/source/ooxml.hxx | 1 |
3 files changed, 89 insertions, 2 deletions
diff --git a/starmath/inc/node.hxx b/starmath/inc/node.hxx index 1b3dbd91ae08..38d46d49f8d7 100644 --- a/starmath/inc/node.hxx +++ b/starmath/inc/node.hxx @@ -1001,6 +1001,13 @@ public: SetNumSubNodes(3); } + SmMathSymbolNode* OpeningBrace(); + const SmMathSymbolNode* OpeningBrace() const; + SmNode* Body(); + const SmNode* Body() const; + SmMathSymbolNode* ClosingBrace(); + const SmMathSymbolNode* ClosingBrace() const; + virtual void Arrange(const OutputDevice &rDev, const SmFormat &rFormat); void CreateTextFromNode(String &rText); void Accept(SmVisitor* pVisitor); @@ -1337,6 +1344,34 @@ inline const SmNode* SmAttributNode::Body() const return const_cast< SmAttributNode* >( this )->Body(); } +inline SmMathSymbolNode* SmBraceNode::OpeningBrace() +{ + OSL_ASSERT( GetNumSubNodes() > 0 && GetSubNode( 0 )->GetType() == NMATH ); + return static_cast< SmMathSymbolNode* >( GetSubNode( 0 )); +} +inline const SmMathSymbolNode* SmBraceNode::OpeningBrace() const +{ + return const_cast< SmBraceNode* >( this )->OpeningBrace(); +} +inline SmNode* SmBraceNode::Body() +{ + OSL_ASSERT( GetNumSubNodes() > 1 ); + return GetSubNode( 1 ); +} +inline const SmNode* SmBraceNode::Body() const +{ + return const_cast< SmBraceNode* >( this )->Body(); +} +inline SmMathSymbolNode* SmBraceNode::ClosingBrace() +{ + OSL_ASSERT( GetNumSubNodes() > 2 && GetSubNode( 2 )->GetType() == NMATH ); + return static_cast< SmMathSymbolNode* >( GetSubNode( 2 )); +} +inline const SmMathSymbolNode* SmBraceNode::ClosingBrace() const +{ + return const_cast< SmBraceNode* >( this )->ClosingBrace(); +} + #endif diff --git a/starmath/source/ooxml.cxx b/starmath/source/ooxml.cxx index 9febf6507db3..c5acb47987cf 100644 --- a/starmath/source/ooxml.cxx +++ b/starmath/source/ooxml.cxx @@ -108,10 +108,10 @@ void SmOoxml::HandleNode( const SmNode* pNode, int nLevel ) case NVERTICAL_BRACE: HandleVerticalBrace(pNode,nLevel); break; +#endif case NBRACE: - HandleBrace(pNode,nLevel); + HandleBrace( static_cast< const SmBraceNode* >( pNode ), nLevel ); break; -#endif case NOPER: HandleOperator( static_cast< const SmOperNode* >( pNode ), nLevel ); break; @@ -551,4 +551,55 @@ void SmOoxml::HandleMatrix( const SmMatrixNode* pNode, int nLevel ) m_pSerializer->endElementNS( XML_m, XML_m ); } +void SmOoxml::HandleBrace( const SmBraceNode* pNode, int nLevel ) +{ + m_pSerializer->startElementNS( XML_m, XML_d, FSEND ); + m_pSerializer->startElementNS( XML_m, XML_dPr, FSEND ); + const SmMathSymbolNode* opening = pNode->OpeningBrace(); + OSL_ASSERT( static_cast< const SmTextNode* >( opening )->GetText().Len() == 1 ); + sal_Unicode chr = Convert( static_cast< const SmTextNode* >( opening )->GetText().GetChar( 0 )); + rtl::OString chrValue = rtl::OUStringToOString( rtl::OUString( chr ), RTL_TEXTENCODING_UTF8 ); + m_pSerializer->singleElementNS( XML_m, XML_begChr, FSNS( XML_m, XML_val ), chrValue.getStr(), FSEND ); + + std::vector< const SmNode* > subnodes; + if( pNode->Body()->GetType() == NBRACEBODY ) + { + const SmBracebodyNode* body = static_cast< const SmBracebodyNode* >( pNode->Body()); + bool separatorWritten = false; // assume all separators are the same + for( int i = 0; i < body->GetNumSubNodes(); ++i ) + { + const SmNode* subnode = body->GetSubNode( i ); + if( subnode->GetType() == NMATH ) + { // do not write, but write what separator it is + const SmMathSymbolNode* math = static_cast< const SmMathSymbolNode* >( subnode ); + if( !separatorWritten ) + { + OSL_ASSERT( static_cast< const SmTextNode* >( math )->GetText().Len() == 1 ); + sal_Unicode chr3 = Convert( static_cast< const SmTextNode* >( math )->GetText().GetChar( 0 )); + rtl::OString chrValue3 = rtl::OUStringToOString( rtl::OUString( chr3 ), RTL_TEXTENCODING_UTF8 ); + m_pSerializer->singleElementNS( XML_m, XML_sepChr, FSNS( XML_m, XML_val ), chrValue3.getStr(), FSEND ); + separatorWritten = true; + } + } + else + subnodes.push_back( subnode ); + } + } + else + subnodes.push_back( pNode->Body()); + const SmMathSymbolNode* closing = pNode->ClosingBrace(); + OSL_ASSERT( static_cast< const SmTextNode* >( closing )->GetText().Len() == 1 ); + sal_Unicode chr2 = Convert( static_cast< const SmTextNode* >( closing )->GetText().GetChar( 0 )); + rtl::OString chrValue2 = rtl::OUStringToOString( rtl::OUString( chr2 ), RTL_TEXTENCODING_UTF8 ); + m_pSerializer->singleElementNS( XML_m, XML_endChr, FSNS( XML_m, XML_val ), chrValue2.getStr(), FSEND ); + m_pSerializer->endElementNS( XML_m, XML_dPr ); + for( unsigned int i = 0; i < subnodes.size(); ++i ) + { + m_pSerializer->startElementNS( XML_m, XML_e, FSEND ); + HandleNode( subnodes[ i ], nLevel + 1 ); + m_pSerializer->endElementNS( XML_m, XML_e ); + } + m_pSerializer->endElementNS( XML_m, XML_d ); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/starmath/source/ooxml.hxx b/starmath/source/ooxml.hxx index 2b651ed81f34..a88d7173a0ec 100644 --- a/starmath/source/ooxml.hxx +++ b/starmath/source/ooxml.hxx @@ -58,6 +58,7 @@ private: void HandleSubSupScript( const SmSubSupNode* pNode, int nLevel ); void HandleSubSupScriptInternal( const SmSubSupNode* pNode, int nLevel, int flags ); void HandleMatrix( const SmMatrixNode* pNode, int nLevel ); + void HandleBrace( const SmBraceNode* pNode, int nLevel ); String str; const SmNode* const pTree; ::sax_fastparser::FSHelperPtr m_pSerializer; |