Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
core
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
LibreOffice
core
Commits
2f91b691
Kaydet (Commit)
2f91b691
authored
Tem 27, 2012
tarafından
Miklos Vajna
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
factor out common code of SmOoxmlExport and SmRtfExport to SmWordExportBase
Change-Id: I63ce6c57faf8568776d24ba1e8b13bd11b6c5532
üst
ebacc340
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
326 additions
and
347 deletions
+326
-347
Library_sm.mk
starmath/Library_sm.mk
+1
-0
ooxmlexport.cxx
starmath/source/ooxmlexport.cxx
+12
-176
ooxmlexport.hxx
starmath/source/ooxmlexport.hxx
+13
-20
rtfexport.cxx
starmath/source/rtfexport.cxx
+8
-131
rtfexport.hxx
starmath/source/rtfexport.hxx
+13
-20
wordexportbase.cxx
starmath/source/wordexportbase.cxx
+212
-0
wordexportbase.hxx
starmath/source/wordexportbase.hxx
+67
-0
No files found.
starmath/Library_sm.mk
Dosyayı görüntüle @
2f91b691
...
...
@@ -90,6 +90,7 @@ $(eval $(call gb_Library_add_exception_objects,sm,\
starmath/source/utility \
starmath/source/view \
starmath/source/visitors \
starmath/source/wordexportbase \
))
...
...
starmath/source/ooxmlexport.cxx
Dosyayı görüntüle @
2f91b691
...
...
@@ -36,19 +36,19 @@ using namespace oox;
using
namespace
oox
::
core
;
SmOoxmlExport
::
SmOoxmlExport
(
const
SmNode
*
pIn
,
OoxmlVersion
v
)
:
pTre
e
(
pIn
)
:
SmWordExportBas
e
(
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: */
starmath/source/ooxmlexport.hxx
Dosyayı görüntüle @
2f91b691
...
...
@@ -29,7 +29,7 @@
#ifndef SM_OOXMLEXPORT_HXX
#define SM_OOXMLEXPORT_HXX
#include "
nod
e.hxx"
#include "
wordexportbas
e.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
;
};
...
...
starmath/source/rtfexport.cxx
Dosyayı görüntüle @
2f91b691
...
...
@@ -34,7 +34,7 @@
#include <filter/msfilter/rtfutil.hxx>
SmRtfExport
::
SmRtfExport
(
const
SmNode
*
pIn
)
:
m_pTre
e
(
pIn
)
:
SmWordExportBas
e
(
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: */
starmath/source/rtfexport.hxx
Dosyayı görüntüle @
2f91b691
...
...
@@ -29,38 +29,31 @@
#ifndef SM_RTFEXPORT_HXX
#define SM_RTFEXPORT_HXX
#include "
nod
e.hxx"
#include "
wordexportbas
e.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
;
};
...
...
starmath/source/wordexportbase.cxx
0 → 100644
Dosyayı görüntüle @
2f91b691
/* -*- 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: */
starmath/source/wordexportbase.hxx
0 → 100644
Dosyayı görüntüle @
2f91b691
/* -*- 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: */
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment