summaryrefslogtreecommitdiff
path: root/starmath
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@suse.cz>2012-07-27 11:09:57 +0200
committerMiklos Vajna <vmiklos@suse.cz>2012-07-27 11:54:57 +0200
commit2f91b691e523385ff6350ea3524c7f795820612d (patch)
treebd56a8f0f3ebd812f1aa4fa8fa4b275225f019bb /starmath
parentebacc340796a6a99d363bd3f04c72106db7d6f7a (diff)
factor out common code of SmOoxmlExport and SmRtfExport to SmWordExportBase
Change-Id: I63ce6c57faf8568776d24ba1e8b13bd11b6c5532
Diffstat (limited to 'starmath')
-rw-r--r--starmath/Library_sm.mk1
-rw-r--r--starmath/source/ooxmlexport.cxx188
-rw-r--r--starmath/source/ooxmlexport.hxx33
-rw-r--r--starmath/source/rtfexport.cxx139
-rw-r--r--starmath/source/rtfexport.hxx33
-rw-r--r--starmath/source/wordexportbase.cxx212
-rw-r--r--starmath/source/wordexportbase.hxx67
7 files changed, 326 insertions, 347 deletions
diff --git a/starmath/Library_sm.mk b/starmath/Library_sm.mk
index 779895d4a294..e3727c8afdc3 100644
--- a/starmath/Library_sm.mk
+++ b/starmath/Library_sm.mk
@@ -90,6 +90,7 @@ $(eval $(call gb_Library_add_exception_objects,sm,\
starmath/source/utility \
starmath/source/view \
starmath/source/visitors \
+ starmath/source/wordexportbase \
))
diff --git a/starmath/source/ooxmlexport.cxx b/starmath/source/ooxmlexport.cxx
index 1eaf6c817c44..9cf7188543a7 100644
--- a/starmath/source/ooxmlexport.cxx
+++ b/starmath/source/ooxmlexport.cxx
@@ -36,19 +36,19 @@ using namespace oox;
using namespace oox::core;
SmOoxmlExport::SmOoxmlExport( const SmNode* pIn, OoxmlVersion v )
-: pTree( pIn )
+: SmWordExportBase( pIn )
, version( v )
{
}
bool SmOoxmlExport::ConvertFromStarMath( ::sax_fastparser::FSHelperPtr serializer )
{
- if( pTree == NULL )
+ if( m_pTree == NULL )
return false;
m_pSerializer = serializer;
m_pSerializer->startElementNS( XML_m, XML_oMath,
FSNS( XML_xmlns, XML_m ), "http://schemas.openxmlformats.org/officeDocument/2006/math", FSEND );
- HandleNode( pTree, 0 );
+ HandleNode( m_pTree, 0 );
m_pSerializer->endElementNS( XML_m, XML_oMath );
return true;
}
@@ -56,124 +56,6 @@ bool SmOoxmlExport::ConvertFromStarMath( ::sax_fastparser::FSHelperPtr serialize
// NOTE: This is still work in progress and unfinished, but it already covers a good
// part of the ooxml math stuff.
-void SmOoxmlExport::HandleNode( const SmNode* pNode, int nLevel )
-{
- SAL_INFO( "starmath.ooxml", "Node: " << nLevel << " " << int( pNode->GetType()) << " " << pNode->GetNumSubNodes());
- switch(pNode->GetType())
- {
- case NATTRIBUT:
- HandleAttribute( static_cast< const SmAttributNode* >( pNode ), nLevel );
- break;
- case NTEXT:
- HandleText(pNode,nLevel);
- break;
- case NVERTICAL_BRACE:
- HandleVerticalBrace( static_cast< const SmVerticalBraceNode* >( pNode ), nLevel );
- break;
- case NBRACE:
- HandleBrace( static_cast< const SmBraceNode* >( pNode ), nLevel );
- break;
- case NOPER:
- HandleOperator( static_cast< const SmOperNode* >( pNode ), nLevel );
- break;
- case NUNHOR:
- HandleUnaryOperation( static_cast< const SmUnHorNode* >( pNode ), nLevel );
- break;
- case NBINHOR:
- HandleBinaryOperation( static_cast< const SmBinHorNode* >( pNode ), nLevel );
- break;
- case NBINVER:
- HandleFractions(pNode,nLevel);
- break;
- case NROOT:
- HandleRoot( static_cast< const SmRootNode* >( pNode ), nLevel );
- break;
- case NSPECIAL:
- {
- const SmTextNode* pText= static_cast< const SmTextNode* >( pNode );
- //if the token str and the result text are the same then this
- //is to be seen as text, else assume its a mathchar
- if (pText->GetText() == pText->GetToken().aText)
- HandleText(pText,nLevel);
- else
- HandleMath(pText,nLevel);
- break;
- }
- case NMATH:
- HandleMath(pNode,nLevel);
- break;
- case NSUBSUP:
- HandleSubSupScript( static_cast< const SmSubSupNode* >( pNode ), nLevel );
- break;
- case NEXPRESSION:
- HandleAllSubNodes( pNode, nLevel );
- break;
- case NTABLE:
- //Root Node, PILE equivalent, i.e. vertical stack
- HandleTable(pNode,nLevel);
- break;
- case NMATRIX:
- HandleMatrix( static_cast< const SmMatrixNode* >( pNode ), nLevel );
- break;
- case NLINE:
- {
-// TODO
- HandleAllSubNodes( pNode, nLevel );
- }
- break;
-#if 0
- case NALIGN:
- HandleMAlign(pNode,nLevel);
- break;
-#endif
- case NPLACE:
- // explicitly do nothing, MSOffice treats that as a placeholder if item is missing
- break;
- case NBLANK:
- m_pSerializer->startElementNS( XML_m, XML_r, FSEND );
- m_pSerializer->startElementNS( XML_m, XML_t, FSNS( XML_xml, XML_space ), "preserve", FSEND );
- m_pSerializer->write( " " );
- m_pSerializer->endElementNS( XML_m, XML_t );
- m_pSerializer->endElementNS( XML_m, XML_r );
- break;
- default:
- HandleAllSubNodes( pNode, nLevel );
- break;
- }
-}
-
-//Root Node, PILE equivalent, i.e. vertical stack
-void SmOoxmlExport::HandleTable( const SmNode* pNode, int nLevel )
-{
- //The root of the starmath is a table, if
- //we convert this them each iteration of
- //conversion from starmath to OOXML will
- //add an extra unnecessary level to the
- //OOXML output stack which would grow
- //without bound in a multi step conversion
- if( nLevel || pNode->GetNumSubNodes() > 1 )
- HandleVerticalStack( pNode, nLevel );
- else
- HandleAllSubNodes( pNode, nLevel );
-}
-
-void SmOoxmlExport::HandleAllSubNodes( const SmNode* pNode, int nLevel )
-{
- int size = pNode->GetNumSubNodes();
- for( int i = 0;
- i < size;
- ++i )
- {
-// TODO remove when all types of nodes are handled properly
- if( pNode->GetSubNode( i ) == NULL )
- {
- OSL_FAIL( "Subnode is NULL, parent node not handled properly" );
- continue;
- }
- HandleNode( pNode->GetSubNode( i ), nLevel + 1 );
- }
-}
-
void SmOoxmlExport::HandleVerticalStack( const SmNode* pNode, int nLevel )
{
m_pSerializer->startElementNS( XML_m, XML_eqArr, FSEND );
@@ -278,34 +160,6 @@ void SmOoxmlExport::HandleFractions( const SmNode* pNode, int nLevel, const char
m_pSerializer->endElementNS( XML_m, XML_f );
}
-void SmOoxmlExport::HandleUnaryOperation( const SmUnHorNode* pNode, int nLevel )
-{
- // update HandleMath() when adding new items
- SAL_INFO( "starmath.ooxml", "Unary: " << int( pNode->GetToken().eType ));
-
-// Avoid MSVC warning C4065: switch statement contains 'default' but no 'case' labels
-// switch( pNode->GetToken().eType )
-// {
-// default:
- HandleAllSubNodes( pNode, nLevel );
-// break;
-// }
-}
-
-void SmOoxmlExport::HandleBinaryOperation( const SmBinHorNode* pNode, int nLevel )
-{
- SAL_INFO( "starmath.ooxml", "Binary: " << int( pNode->Symbol()->GetToken().eType ));
- // update HandleMath() when adding new items
- switch( pNode->Symbol()->GetToken().eType )
- {
- case TDIVIDEBY:
- return HandleFractions( pNode, nLevel, "lin" );
- default:
- HandleAllSubNodes( pNode, nLevel );
- break;
- }
-}
-
void SmOoxmlExport::HandleAttribute( const SmAttributNode* pNode, int nLevel )
{
switch( pNode->Attribute()->GetToken().eType )
@@ -370,21 +224,6 @@ void SmOoxmlExport::HandleAttribute( const SmAttributNode* pNode, int nLevel )
}
}
-void SmOoxmlExport::HandleMath( const SmNode* pNode, int nLevel )
-{
- SAL_INFO( "starmath.ooxml", "Math: " << int( pNode->GetToken().eType ));
- switch( pNode->GetToken().eType )
- {
- case TDIVIDEBY:
- case TACUTE:
- // these are handled elsewhere, e.g. when handling BINHOR
- OSL_ASSERT( false );
- default:
- HandleText( pNode, nLevel );
- break;
- }
-}
-
void SmOoxmlExport::HandleRoot( const SmRootNode* pNode, int nLevel )
{
m_pSerializer->startElementNS( XML_m, XML_rad, FSEND );
@@ -494,18 +333,6 @@ void SmOoxmlExport::HandleOperator( const SmOperNode* pNode, int nLevel )
}
}
-void SmOoxmlExport::HandleSubSupScript( const SmSubSupNode* pNode, int nLevel )
-{
- // set flags to a bitfield of which sub/sup items exists
- int flags = ( pNode->GetSubSup( CSUB ) != NULL ? ( 1 << CSUB ) : 0 )
- | ( pNode->GetSubSup( CSUP ) != NULL ? ( 1 << CSUP ) : 0 )
- | ( pNode->GetSubSup( RSUB ) != NULL ? ( 1 << RSUB ) : 0 )
- | ( pNode->GetSubSup( RSUP ) != NULL ? ( 1 << RSUP ) : 0 )
- | ( pNode->GetSubSup( LSUB ) != NULL ? ( 1 << LSUB ) : 0 )
- | ( pNode->GetSubSup( LSUP ) != NULL ? ( 1 << LSUP ) : 0 );
- HandleSubSupScriptInternal( pNode, nLevel, flags );
-}
-
void SmOoxmlExport::HandleSubSupScriptInternal( const SmSubSupNode* pNode, int nLevel, int flags )
{
// docx supports only a certain combination of sub/super scripts, but LO can have any,
@@ -714,4 +541,13 @@ void SmOoxmlExport::HandleVerticalBrace( const SmVerticalBraceNode* pNode, int n
}
}
+void SmOoxmlExport::HandleBlank()
+{
+ m_pSerializer->startElementNS( XML_m, XML_r, FSEND );
+ m_pSerializer->startElementNS( XML_m, XML_t, FSNS( XML_xml, XML_space ), "preserve", FSEND );
+ m_pSerializer->write( " " );
+ m_pSerializer->endElementNS( XML_m, XML_t );
+ m_pSerializer->endElementNS( XML_m, XML_r );
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/starmath/source/ooxmlexport.hxx b/starmath/source/ooxmlexport.hxx
index 6de792efaee1..f46a26ba3e2e 100644
--- a/starmath/source/ooxmlexport.hxx
+++ b/starmath/source/ooxmlexport.hxx
@@ -29,7 +29,7 @@
#ifndef SM_OOXMLEXPORT_HXX
#define SM_OOXMLEXPORT_HXX
-#include "node.hxx"
+#include "wordexportbase.hxx"
#include <sax/fshelper.hxx>
#include <oox/core/filterbase.hxx>
@@ -37,30 +37,23 @@
/**
Class implementing writing of formulas to OOXML.
*/
-class SmOoxmlExport
+class SmOoxmlExport : public SmWordExportBase
{
public:
SmOoxmlExport( const SmNode* pIn, oox::core::OoxmlVersion version );
bool ConvertFromStarMath( ::sax_fastparser::FSHelperPtr m_pSerializer );
private:
- void HandleNode( const SmNode* pNode, int nLevel );
- void HandleAllSubNodes( const SmNode* pNode, int nLevel );
- void HandleTable( const SmNode* pNode, int nLevel );
- void HandleVerticalStack( const SmNode* pNode, int nLevel );
- void HandleText( const SmNode* pNode, int nLevel );
- void HandleMath( const SmNode* pNode, int nLevel );
- void HandleFractions( const SmNode* pNode, int nLevel, const char* type = NULL );
- void HandleUnaryOperation( const SmUnHorNode* pNode, int nLevel );
- void HandleBinaryOperation( const SmBinHorNode* pNode, int nLevel );
- void HandleRoot( const SmRootNode* pNode, int nLevel );
- void HandleAttribute( const SmAttributNode* pNode, int nLevel );
- void HandleOperator( const SmOperNode* pNode, int nLevel );
- 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 );
- void HandleVerticalBrace( const SmVerticalBraceNode* pNode, int nLevel );
- const SmNode* const pTree;
+ virtual void HandleVerticalStack( const SmNode* pNode, int nLevel );
+ virtual void HandleText( const SmNode* pNode, int nLevel );
+ virtual void HandleFractions( const SmNode* pNode, int nLevel, const char* type = NULL );
+ virtual void HandleRoot( const SmRootNode* pNode, int nLevel );
+ virtual void HandleAttribute( const SmAttributNode* pNode, int nLevel );
+ virtual void HandleOperator( const SmOperNode* pNode, int nLevel );
+ virtual void HandleSubSupScriptInternal( const SmSubSupNode* pNode, int nLevel, int flags );
+ virtual void HandleMatrix( const SmMatrixNode* pNode, int nLevel );
+ virtual void HandleBrace( const SmBraceNode* pNode, int nLevel );
+ virtual void HandleVerticalBrace( const SmVerticalBraceNode* pNode, int nLevel );
+ virtual void HandleBlank();
::sax_fastparser::FSHelperPtr m_pSerializer;
oox::core::OoxmlVersion version;
};
diff --git a/starmath/source/rtfexport.cxx b/starmath/source/rtfexport.cxx
index b8cebd70d57e..5868e51bcd49 100644
--- a/starmath/source/rtfexport.cxx
+++ b/starmath/source/rtfexport.cxx
@@ -34,7 +34,7 @@
#include <filter/msfilter/rtfutil.hxx>
SmRtfExport::SmRtfExport(const SmNode* pIn)
- : m_pTree(pIn)
+ : SmWordExportBase(pIn)
, m_pBuffer(0)
{
}
@@ -53,90 +53,6 @@ bool SmRtfExport::ConvertFromStarMath(OStringBuffer& rBuffer)
// NOTE: This is still work in progress and unfinished, but it already covers a good
// part of the rtf math stuff.
-void SmRtfExport::HandleNode(const SmNode* pNode, int nLevel)
-{
- SAL_INFO("starmath.rtf", "Node: " << nLevel << " " << int(pNode->GetType()) << " " << pNode->GetNumSubNodes());
-
- switch(pNode->GetType())
- {
- case NATTRIBUT:
- HandleAttribute( static_cast< const SmAttributNode* >( pNode ), nLevel );
- break;
- case NTEXT:
- HandleText(pNode,nLevel);
- break;
- case NVERTICAL_BRACE:
- HandleVerticalBrace(static_cast<const SmVerticalBraceNode*>(pNode), nLevel);
- break;
- case NBRACE:
- HandleBrace( static_cast< const SmBraceNode* >( pNode ), nLevel );
- break;
- case NOPER:
- HandleOperator(static_cast<const SmOperNode*>(pNode), nLevel);
- break;
- case NUNHOR:
- HandleUnaryOperation(static_cast<const SmUnHorNode*>(pNode), nLevel);
- break;
- case NBINHOR:
- HandleBinaryOperation(static_cast<const SmBinHorNode*>(pNode), nLevel);
- break;
- case NBINVER:
- HandleFractions(pNode, nLevel);
- break;
- case NROOT:
- HandleRoot(static_cast<const SmRootNode*>(pNode), nLevel);
- break;
- case NMATH:
- HandleMath(pNode, nLevel);
- break;
- case NSUBSUP:
- HandleSubSupScript(static_cast<const SmSubSupNode*>(pNode), nLevel);
- break;
- case NEXPRESSION:
- HandleAllSubNodes(pNode, nLevel);
- break;
- case NTABLE:
- //Root Node, PILE equivalent, i.e. vertical stack
- HandleTable(pNode,nLevel);
- break;
- case NMATRIX:
- HandleMatrix(static_cast<const SmMatrixNode*>(pNode), nLevel);
- break;
- case NLINE:
- HandleAllSubNodes(pNode, nLevel);
- break;
- case NPLACE:
- // explicitly do nothing, MSOffice treats that as a placeholder if item is missing
- break;
- default:
- SAL_INFO("starmath.rtf", "TODO: " << OSL_THIS_FUNC << " unhandled node type");
- break;
- }
-}
-
-//Root Node, PILE equivalent, i.e. vertical stack
-void SmRtfExport::HandleTable(const SmNode* pNode, int nLevel)
-{
- if (nLevel || pNode->GetNumSubNodes() > 1)
- HandleVerticalStack(pNode, nLevel);
- else
- HandleAllSubNodes(pNode, nLevel);
-}
-
-void SmRtfExport::HandleAllSubNodes(const SmNode* pNode, int nLevel)
-{
- int size = pNode->GetNumSubNodes();
- for (int i = 0; i < size; ++i)
- {
- if (!pNode->GetSubNode(i))
- {
- OSL_FAIL("Subnode is NULL, parent node not handled properly");
- continue;
- }
- HandleNode(pNode->GetSubNode(i), nLevel + 1);
- }
-}
-
void SmRtfExport::HandleVerticalStack(const SmNode* pNode, int nLevel)
{
m_pBuffer->append("{\\meqArr ");
@@ -187,25 +103,6 @@ void SmRtfExport::HandleFractions(const SmNode* pNode, int nLevel, const char* t
m_pBuffer->append("}"); // mf
}
-void SmRtfExport::HandleUnaryOperation(const SmUnHorNode* pNode, int nLevel)
-{
- HandleAllSubNodes(pNode, nLevel);
-}
-
-void SmRtfExport::HandleBinaryOperation(const SmBinHorNode* pNode, int nLevel)
-{
- SAL_INFO("starmath.rtf", "Binary: " << int(pNode->Symbol()->GetToken().eType));
- // update HandleMath() when adding new items
- switch (pNode->Symbol()->GetToken().eType)
- {
- case TDIVIDEBY:
- return HandleFractions(pNode, nLevel, "lin");
- default:
- HandleAllSubNodes(pNode, nLevel);
- break;
- }
-}
-
void SmRtfExport::HandleAttribute(const SmAttributNode* pNode, int nLevel)
{
switch (pNode->Attribute()->GetToken().eType)
@@ -272,21 +169,6 @@ void SmRtfExport::HandleAttribute(const SmAttributNode* pNode, int nLevel)
}
}
-void SmRtfExport::HandleMath(const SmNode* pNode, int nLevel)
-{
- SAL_INFO("starmath.rtf", "Math: " << int(pNode->GetToken().eType));
- switch (pNode->GetToken().eType)
- {
- case TDIVIDEBY:
- case TACUTE:
- // these are handled elsewhere, e.g. when handling BINHOR
- OSL_ASSERT(false);
- default:
- HandleText(pNode, nLevel);
- break;
- }
-}
-
void SmRtfExport::HandleRoot(const SmRootNode* pNode, int nLevel)
{
m_pBuffer->append("{\\mrad ");
@@ -397,18 +279,6 @@ void SmRtfExport::HandleOperator(const SmOperNode* pNode, int nLevel)
}
}
-void SmRtfExport::HandleSubSupScript(const SmSubSupNode* pNode, int nLevel)
-{
- // set flags to a bitfield of which sub/sup items exists
- int flags = (pNode->GetSubSup(CSUB) ? (1 << CSUB) : 0)
- | (pNode->GetSubSup(CSUP) ? (1 << CSUP) : 0)
- | (pNode->GetSubSup(RSUB) ? (1 << RSUB) : 0)
- | (pNode->GetSubSup(RSUP) ? (1 << RSUP) : 0)
- | (pNode->GetSubSup(LSUB) ? (1 << LSUB) : 0)
- | (pNode->GetSubSup(LSUP) ? (1 << LSUP) : 0);
- HandleSubSupScriptInternal(pNode, nLevel, flags);
-}
-
void SmRtfExport::HandleSubSupScriptInternal(const SmSubSupNode* pNode, int nLevel, int flags)
{
// rtf supports only a certain combination of sub/super scripts, but LO can have any,
@@ -618,4 +488,11 @@ void SmRtfExport::HandleVerticalBrace(const SmVerticalBraceNode* pNode, int nLev
}
}
+void SmRtfExport::HandleBlank()
+{
+ m_pBuffer->append("{\\mr ");
+ m_pBuffer->append(" ");
+ m_pBuffer->append("}"); // mr
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/starmath/source/rtfexport.hxx b/starmath/source/rtfexport.hxx
index 9e1f6c355cd9..bf12b64a4d5b 100644
--- a/starmath/source/rtfexport.hxx
+++ b/starmath/source/rtfexport.hxx
@@ -29,38 +29,31 @@
#ifndef SM_RTFEXPORT_HXX
#define SM_RTFEXPORT_HXX
-#include "node.hxx"
+#include "wordexportbase.hxx"
#include <rtl/strbuf.hxx>
/**
Class implementing writing of formulas to RTF.
*/
-class SmRtfExport
+class SmRtfExport : public SmWordExportBase
{
public:
SmRtfExport(const SmNode* pIn);
bool ConvertFromStarMath(OStringBuffer& rBuffer);
private:
- void HandleNode(const SmNode* pNode, int nLevel);
- void HandleAllSubNodes(const SmNode* pNode, int nLevel);
- void HandleTable(const SmNode* pNode, int nLevel);
- void HandleVerticalStack(const SmNode* pNode, int nLevel);
- void HandleText(const SmNode* pNode, int nLevel);
- void HandleMath(const SmNode* pNode, int nLevel);
- void HandleFractions(const SmNode* pNode, int nLevel, const char* type = NULL);
- void HandleUnaryOperation(const SmUnHorNode* pNode, int nLevel);
- void HandleBinaryOperation(const SmBinHorNode* pNode, int nLevel);
- void HandleRoot(const SmRootNode* pNode, int nLevel);
- void HandleAttribute(const SmAttributNode* pNode, int nLevel);
- void HandleOperator(const SmOperNode* pNode, int nLevel);
- 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);
- void HandleVerticalBrace(const SmVerticalBraceNode* pNode, int nLevel);
+ virtual void HandleVerticalStack(const SmNode* pNode, int nLevel);
+ virtual void HandleText(const SmNode* pNode, int nLevel);
+ virtual void HandleFractions(const SmNode* pNode, int nLevel, const char* type = NULL);
+ virtual void HandleRoot(const SmRootNode* pNode, int nLevel);
+ virtual void HandleAttribute(const SmAttributNode* pNode, int nLevel);
+ virtual void HandleOperator(const SmOperNode* pNode, int nLevel);
+ virtual void HandleSubSupScriptInternal(const SmSubSupNode* pNode, int nLevel, int flags);
+ virtual void HandleMatrix(const SmMatrixNode* pNode, int nLevel);
+ virtual void HandleBrace(const SmBraceNode* pNode, int nLevel);
+ virtual void HandleVerticalBrace(const SmVerticalBraceNode* pNode, int nLevel);
+ virtual void HandleBlank();
- const SmNode* const m_pTree;
OStringBuffer* m_pBuffer;
};
diff --git a/starmath/source/wordexportbase.cxx b/starmath/source/wordexportbase.cxx
new file mode 100644
index 000000000000..9f5e54bd182f
--- /dev/null
+++ b/starmath/source/wordexportbase.cxx
@@ -0,0 +1,212 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * Version: MPL 1.1 / GPLv3+ / LGPLv3+
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License or as specified alternatively below. You may obtain a copy of
+ * the License at http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * Major Contributor(s):
+ * Copyright (C) 2011 Lubos Lunak <l.lunak@suse.cz> (initial developer)
+ *
+ * All Rights Reserved.
+ *
+ * For minor contributions see the git repository.
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
+ * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
+ * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
+ * instead of those above.
+ */
+
+
+#include "wordexportbase.hxx"
+
+#include <rtl/oustringostreaminserter.hxx>
+
+SmWordExportBase::SmWordExportBase( const SmNode* pIn )
+: m_pTree( pIn )
+{
+}
+
+SmWordExportBase::~SmWordExportBase()
+{
+}
+
+void SmWordExportBase::HandleNode( const SmNode* pNode, int nLevel )
+{
+ SAL_INFO( "starmath.wordbase", "Node: " << nLevel << " " << int( pNode->GetType()) << " " << pNode->GetNumSubNodes());
+ switch(pNode->GetType())
+ {
+ case NATTRIBUT:
+ HandleAttribute( static_cast< const SmAttributNode* >( pNode ), nLevel );
+ break;
+ case NTEXT:
+ HandleText(pNode,nLevel);
+ break;
+ case NVERTICAL_BRACE:
+ HandleVerticalBrace( static_cast< const SmVerticalBraceNode* >( pNode ), nLevel );
+ break;
+ case NBRACE:
+ HandleBrace( static_cast< const SmBraceNode* >( pNode ), nLevel );
+ break;
+ case NOPER:
+ HandleOperator( static_cast< const SmOperNode* >( pNode ), nLevel );
+ break;
+ case NUNHOR:
+ HandleUnaryOperation( static_cast< const SmUnHorNode* >( pNode ), nLevel );
+ break;
+ case NBINHOR:
+ HandleBinaryOperation( static_cast< const SmBinHorNode* >( pNode ), nLevel );
+ break;
+ case NBINVER:
+ HandleFractions(pNode,nLevel);
+ break;
+ case NROOT:
+ HandleRoot( static_cast< const SmRootNode* >( pNode ), nLevel );
+ break;
+ case NSPECIAL:
+ {
+ const SmTextNode* pText= static_cast< const SmTextNode* >( pNode );
+ //if the token str and the result text are the same then this
+ //is to be seen as text, else assume its a mathchar
+ if (pText->GetText() == pText->GetToken().aText)
+ HandleText(pText,nLevel);
+ else
+ HandleMath(pText,nLevel);
+ break;
+ }
+ case NMATH:
+ HandleMath(pNode,nLevel);
+ break;
+ case NSUBSUP:
+ HandleSubSupScript( static_cast< const SmSubSupNode* >( pNode ), nLevel );
+ break;
+ case NEXPRESSION:
+ HandleAllSubNodes( pNode, nLevel );
+ break;
+ case NTABLE:
+ //Root Node, PILE equivalent, i.e. vertical stack
+ HandleTable(pNode,nLevel);
+ break;
+ case NMATRIX:
+ HandleMatrix( static_cast< const SmMatrixNode* >( pNode ), nLevel );
+ break;
+ case NLINE:
+ {
+// TODO
+ HandleAllSubNodes( pNode, nLevel );
+ }
+ break;
+#if 0
+ case NALIGN:
+ HandleMAlign(pNode,nLevel);
+ break;
+#endif
+ case NPLACE:
+ // explicitly do nothing, MSOffice treats that as a placeholder if item is missing
+ break;
+ case NBLANK:
+ HandleBlank();
+ break;
+ default:
+ HandleAllSubNodes( pNode, nLevel );
+ break;
+ }
+}
+
+//Root Node, PILE equivalent, i.e. vertical stack
+void SmWordExportBase::HandleTable( const SmNode* pNode, int nLevel )
+{
+ //The root of the starmath is a table, if
+ //we convert this them each iteration of
+ //conversion from starmath to Word will
+ //add an extra unnecessary level to the
+ //Word output stack which would grow
+ //without bound in a multi step conversion
+ if( nLevel || pNode->GetNumSubNodes() > 1 )
+ HandleVerticalStack( pNode, nLevel );
+ else
+ HandleAllSubNodes( pNode, nLevel );
+}
+
+void SmWordExportBase::HandleAllSubNodes( const SmNode* pNode, int nLevel )
+{
+ int size = pNode->GetNumSubNodes();
+ for( int i = 0;
+ i < size;
+ ++i )
+ {
+// TODO remove when all types of nodes are handled properly
+ if( pNode->GetSubNode( i ) == NULL )
+ {
+ OSL_FAIL( "Subnode is NULL, parent node not handled properly" );
+ continue;
+ }
+ HandleNode( pNode->GetSubNode( i ), nLevel + 1 );
+ }
+}
+
+void SmWordExportBase::HandleUnaryOperation( const SmUnHorNode* pNode, int nLevel )
+{
+ // update HandleMath() when adding new items
+ SAL_INFO( "starmath.wordbase", "Unary: " << int( pNode->GetToken().eType ));
+
+// Avoid MSVC warning C4065: switch statement contains 'default' but no 'case' labels
+// switch( pNode->GetToken().eType )
+// {
+// default:
+ HandleAllSubNodes( pNode, nLevel );
+// break;
+// }
+}
+
+void SmWordExportBase::HandleBinaryOperation( const SmBinHorNode* pNode, int nLevel )
+{
+ SAL_INFO( "starmath.wordbase", "Binary: " << int( pNode->Symbol()->GetToken().eType ));
+ // update HandleMath() when adding new items
+ switch( pNode->Symbol()->GetToken().eType )
+ {
+ case TDIVIDEBY:
+ return HandleFractions( pNode, nLevel, "lin" );
+ default:
+ HandleAllSubNodes( pNode, nLevel );
+ break;
+ }
+}
+
+void SmWordExportBase::HandleMath( const SmNode* pNode, int nLevel )
+{
+ SAL_INFO( "starmath.wordbase", "Math: " << int( pNode->GetToken().eType ));
+ switch( pNode->GetToken().eType )
+ {
+ case TDIVIDEBY:
+ case TACUTE:
+ // these are handled elsewhere, e.g. when handling BINHOR
+ OSL_ASSERT( false );
+ default:
+ HandleText( pNode, nLevel );
+ break;
+ }
+}
+
+void SmWordExportBase::HandleSubSupScript( const SmSubSupNode* pNode, int nLevel )
+{
+ // set flags to a bitfield of which sub/sup items exists
+ int flags = ( pNode->GetSubSup( CSUB ) != NULL ? ( 1 << CSUB ) : 0 )
+ | ( pNode->GetSubSup( CSUP ) != NULL ? ( 1 << CSUP ) : 0 )
+ | ( pNode->GetSubSup( RSUB ) != NULL ? ( 1 << RSUB ) : 0 )
+ | ( pNode->GetSubSup( RSUP ) != NULL ? ( 1 << RSUP ) : 0 )
+ | ( pNode->GetSubSup( LSUB ) != NULL ? ( 1 << LSUB ) : 0 )
+ | ( pNode->GetSubSup( LSUP ) != NULL ? ( 1 << LSUP ) : 0 );
+ HandleSubSupScriptInternal( pNode, nLevel, flags );
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/starmath/source/wordexportbase.hxx b/starmath/source/wordexportbase.hxx
new file mode 100644
index 000000000000..36944b168cd8
--- /dev/null
+++ b/starmath/source/wordexportbase.hxx
@@ -0,0 +1,67 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * Version: MPL 1.1 / GPLv3+ / LGPLv3+
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License or as specified alternatively below. You may obtain a copy of
+ * the License at http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * Major Contributor(s):
+ * Copyright (C) 2011 Lubos Lunak <l.lunak@suse.cz> (initial developer)
+ *
+ * All Rights Reserved.
+ *
+ * For minor contributions see the git repository.
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
+ * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
+ * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
+ * instead of those above.
+ */
+
+#ifndef SM_WORDEXPORTBASE_HXX
+#define SM_WORDEXPORTBASE_HXX
+
+#include "node.hxx"
+
+/**
+ Base class implementing writing of formulas to Word.
+ */
+class SmWordExportBase
+{
+public:
+ SmWordExportBase( const SmNode* pIn );
+ virtual ~SmWordExportBase();
+protected:
+ void HandleNode( const SmNode* pNode, int nLevel );
+ void HandleAllSubNodes( const SmNode* pNode, int nLevel );
+ void HandleTable( const SmNode* pNode, int nLevel );
+ virtual void HandleVerticalStack( const SmNode* pNode, int nLevel ) = 0;
+ virtual void HandleText( const SmNode* pNode, int nLevel ) = 0;
+ void HandleMath( const SmNode* pNode, int nLevel );
+ virtual void HandleFractions( const SmNode* pNode, int nLevel, const char* type = NULL ) = 0;
+ void HandleUnaryOperation( const SmUnHorNode* pNode, int nLevel );
+ void HandleBinaryOperation( const SmBinHorNode* pNode, int nLevel );
+ virtual void HandleRoot( const SmRootNode* pNode, int nLevel ) = 0;
+ virtual void HandleAttribute( const SmAttributNode* pNode, int nLevel ) = 0;
+ virtual void HandleOperator( const SmOperNode* pNode, int nLevel ) = 0;
+ void HandleSubSupScript( const SmSubSupNode* pNode, int nLevel );
+ virtual void HandleSubSupScriptInternal( const SmSubSupNode* pNode, int nLevel, int flags ) = 0;
+ virtual void HandleMatrix( const SmMatrixNode* pNode, int nLevel ) = 0;
+ virtual void HandleBrace( const SmBraceNode* pNode, int nLevel ) = 0;
+ virtual void HandleVerticalBrace( const SmVerticalBraceNode* pNode, int nLevel ) = 0;
+ virtual void HandleBlank() = 0;
+ const SmNode* const m_pTree;
+};
+
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */