xref: /aoo41x/main/starmath/source/mathtype.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28  #ifndef MATHTYPE_HXX
29 #define MATHTYPE_HXX
30 
31 #include "node.hxx"
32 #include "eqnolefilehdr.hxx"
33 
34 #include <sot/storage.hxx>
35 
36 #include <set>
37 
38 class SfxMedium;
39 
40 class MathTypeFont
41 {
42 public:
43 	sal_uInt8 nTface;
44 	sal_uInt8 nStyle;
45 	MathTypeFont() : nTface(0),nStyle(0) {}
46 	MathTypeFont(sal_uInt8 nFace) : nTface(nFace),nStyle(0) {}
47 	void AppendStyleToText(String &rS);
48 };
49 
50 struct LessMathTypeFont
51 {
52 	sal_Bool operator() (const MathTypeFont &rValue1,
53 		const MathTypeFont &rValue2) const
54 	{
55 		return rValue1.nTface < rValue2.nTface;
56 	}
57 };
58 
59 typedef ::std::set< MathTypeFont, LessMathTypeFont > MathTypeFontSet;
60 
61 class MathType
62 {
63 public:
64     MathType(String &rIn) :
65         rRet(rIn), nHAlign(0), nVAlign(0), nDefaultSize(12),
66         nLSize(0), nDSize(0), nCurSize(0), nLastSize(0), bIsSilent(sal_False)
67 	{
68 		Init();
69 	}
70 
71     MathType(String &rIn,SmNode *pIn) :
72         rRet(rIn), pTree(pIn), nHAlign(2), nVAlign(0), nInsertion(0), nDefaultSize(12),
73         nLSize(0), nDSize(0), nCurSize(0), nLastSize(0), nSpec(0), bIsSilent(sal_False)
74     {
75 		Init();
76 	}
77 
78     int Parse( SotStorage* pStor );
79     int ConvertFromStarMath( SfxMedium& rMedium );
80 
81 private:
82 /*Ver 2 Header*/
83 	sal_uInt8 nVersion;
84 	sal_uInt8 nPlatform;
85 	sal_uInt8 nProduct;
86 	sal_uInt8 nProdVersion;
87 	sal_uInt8 nProdSubVersion;
88 
89 	SvStorageStream *pS;
90 
91 	void Init();
92 
93     int HandleRecords(int nLevel=0,sal_uInt8 nSelector=0xFF,
94         sal_uInt8 nVariation=0xFF,int nRows=0,int nCols=0);
95 	sal_Bool HandleSize(sal_Int16 nLSize,sal_Int16 nDSize, int &rSetSize);
96 	void HandleAlign(sal_uInt8 nHAlign,sal_uInt8 nVAlign, int &rSetAlign);
97 	int HandlePile(int &rSetAlign,int nLevel,sal_uInt8 nSelector,
98 		sal_uInt8 nVariation);
99 	int HandleMatrix(int nLevel,sal_uInt8 nSelector,sal_uInt8 nVariarion);
100 	void HandleMatrixSeperator(int nMatrixRows,int nMatrixCols,int &rCurCol,
101 		int &rCurRow);
102 	int HandleTemplate(int nLevel,sal_uInt8 &rSelector,sal_uInt8 &rVariation,
103 		xub_StrLen &rLastTemplateBracket);
104 	void HandleEmblishments();
105 	void HandleSetSize();
106 	int HandleChar(xub_StrLen &rTextStart,int &rSetSize,int nLevel,
107 		sal_uInt8 nTag,sal_uInt8 nSelector,sal_uInt8 nVariation,
108 		sal_Bool bSilent);
109 	void HandleNudge();
110 	int xfLMOVE(sal_uInt8 nTest) {return nTest&0x80;}
111 	int xfAUTO(sal_uInt8 nTest) {return nTest&0x10;}
112 	int xfEMBELL(sal_uInt8 nTest) {return nTest&0x20;}
113 	int xfNULL(sal_uInt8 nTest) {return nTest&0x10;}
114 	int xfLSPACE(sal_uInt8 nTest) {return nTest&0x40;}
115 	int xfRULER(sal_uInt8 nTest) {return nTest&0x20;}
116 
117 	sal_uInt8 HandleNodes(SmNode *pNode,int nLevel=0);
118 	int StartTemplate(sal_uInt16 nSelector,sal_uInt16 nVariation=0);
119 	void EndTemplate(int nOldPendingAttributes);
120 	void HandleSmMatrix(SmMatrixNode *pMatrix,int nLevel);
121 	void HandleTable(SmNode *pNode,int nLevel);
122 	void HandleRoot(SmNode *pNode,int nLevel);
123 	void HandleSubSupScript(SmNode *pNode,int nLevel);
124 	sal_uInt8 HandleCScript(SmNode *pNode,SmNode *pContent,int nLevel,
125 		sal_uLong *pPos=NULL,sal_Bool bTest=sal_True);
126 	void HandleFractions(SmNode *pNode,int nLevel);
127 	void HandleBrace(SmNode *pNode,int nLevel);
128 	void HandleVerticalBrace(SmNode *pNode,int nLevel);
129 	void HandleOperator(SmNode *pNode,int nLevel);
130 	sal_Bool HandleLim(SmNode *pNode,int nLevel);
131 	void HandleMAlign(SmNode *pNode,int nLevel);
132 	void HandleMath(SmNode *pNode,int nLevel);
133 	void HandleText(SmNode *pNode,int nLevel);
134 	void HandleAttributes(SmNode *pNode,int nLevel);
135 	void TypeFaceToString(String &rRet,sal_uInt8 nFace);
136 
137 	String &rRet;
138 	SmNode *pTree;
139 
140 	sal_uInt8 nHAlign;
141 	sal_uInt8 nVAlign;
142 
143 	int nPendingAttributes;
144 	sal_uLong nInsertion;
145 
146 	sal_Int16 aSizeTable[7];
147 	sal_Int16 nDefaultSize;
148 	sal_Int16 nLSize;
149 	sal_Int16 nDSize;
150 	sal_Int16 nCurSize;
151 	sal_Int16 nLastSize;
152 	sal_uInt8 nSpec;
153     sal_Bool bIsSilent, bIsReInterpBrace;
154 	String sPost;
155 	xub_StrLen nPostSup;
156 	xub_StrLen nPostlSup;
157 	sal_uInt8 nTypeFace;
158 	MathTypeFontSet aUserStyles;
159 
160 	enum MTOKENS {END,LINE,CHAR,TMPL,PILE,MATRIX,EMBEL,RULER,FONT,SIZE};
161 	enum MTEMPLATES
162 	{
163 		tmANGLE,tmPAREN,tmBRACE,tmBRACK,tmBAR,tmDBAR,tmFLOOR,tmCEILING,
164 		tmLBLB,tmRBRB,tmRBLB,tmLBRP,tmLPRB,tmROOT,tmFRACT,tmSCRIPT,tmUBAR,
165 		tmOBAR,tmLARROW,tmRARROW,tmBARROW,tmSINT,tmDINT,tmTINT,tmSSINT,
166 		tmDSINT,tmTSINT,tmUHBRACE,tmLHBRACE,tmSUM
167 	};
168 public:
169 	static sal_Bool LookupChar(sal_Unicode nChar,String &rRet,
170 		sal_uInt8 nVersion=3,sal_uInt8 nTypeFace=0);
171 };
172 
173 
174 #endif
175