xref: /aoo4110/main/starmath/source/mathtype.hxx (revision b1cdbd2c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24  #ifndef MATHTYPE_HXX
25 #define MATHTYPE_HXX
26 
27 #include "node.hxx"
28 #include "eqnolefilehdr.hxx"
29 
30 #include <sot/storage.hxx>
31 
32 #include <set>
33 
34 class SfxMedium;
35 
36 class MathTypeFont
37 {
38 public:
39 	sal_uInt8 nTface;
40 	sal_uInt8 nStyle;
MathTypeFont()41 	MathTypeFont() : nTface(0),nStyle(0) {}
MathTypeFont(sal_uInt8 nFace)42 	MathTypeFont(sal_uInt8 nFace) : nTface(nFace),nStyle(0) {}
43 	void AppendStyleToText(String &rS);
44 };
45 
46 struct LessMathTypeFont
47 {
operator ()LessMathTypeFont48 	sal_Bool operator() (const MathTypeFont &rValue1,
49 		const MathTypeFont &rValue2) const
50 	{
51 		return rValue1.nTface < rValue2.nTface;
52 	}
53 };
54 
55 typedef ::std::set< MathTypeFont, LessMathTypeFont > MathTypeFontSet;
56 
57 class MathType
58 {
59 public:
MathType(String & rIn)60     MathType(String &rIn) :
61         rRet(rIn), nHAlign(0), nVAlign(0), nDefaultSize(12),
62         nLSize(0), nDSize(0), nCurSize(0), nLastSize(0), bIsSilent(sal_False)
63 	{
64 		Init();
65 	}
66 
MathType(String & rIn,SmNode * pIn)67     MathType(String &rIn,SmNode *pIn) :
68         rRet(rIn), pTree(pIn), nHAlign(2), nVAlign(0), nInsertion(0), nDefaultSize(12),
69         nLSize(0), nDSize(0), nCurSize(0), nLastSize(0), nSpec(0), bIsSilent(sal_False)
70     {
71 		Init();
72 	}
73 
74     int Parse( SotStorage* pStor );
75     int ConvertFromStarMath( SfxMedium& rMedium );
76 
77 private:
78 /*Ver 2 Header*/
79 	sal_uInt8 nVersion;
80 	sal_uInt8 nPlatform;
81 	sal_uInt8 nProduct;
82 	sal_uInt8 nProdVersion;
83 	sal_uInt8 nProdSubVersion;
84 
85 	SvStorageStream *pS;
86 
87 	void Init();
88 
89     int HandleRecords(int nLevel=0,sal_uInt8 nSelector=0xFF,
90         sal_uInt8 nVariation=0xFF,int nRows=0,int nCols=0);
91 	sal_Bool HandleSize(sal_Int16 nLSize,sal_Int16 nDSize, int &rSetSize);
92 	void HandleAlign(sal_uInt8 nHAlign,sal_uInt8 nVAlign, int &rSetAlign);
93 	int HandlePile(int &rSetAlign,int nLevel,sal_uInt8 nSelector,
94 		sal_uInt8 nVariation);
95 	int HandleMatrix(int nLevel,sal_uInt8 nSelector,sal_uInt8 nVariarion);
96 	void HandleMatrixSeperator(int nMatrixRows,int nMatrixCols,int &rCurCol,
97 		int &rCurRow);
98 	int HandleTemplate(int nLevel,sal_uInt8 &rSelector,sal_uInt8 &rVariation,
99 		xub_StrLen &rLastTemplateBracket);
100 	void HandleEmblishments();
101 	void HandleSetSize();
102 	int HandleChar(xub_StrLen &rTextStart,int &rSetSize,int nLevel,
103 		sal_uInt8 nTag,sal_uInt8 nSelector,sal_uInt8 nVariation,
104 		sal_Bool bSilent);
105 	void HandleNudge();
xfLMOVE(sal_uInt8 nTest)106 	int xfLMOVE(sal_uInt8 nTest) {return nTest&0x80;}
xfAUTO(sal_uInt8 nTest)107 	int xfAUTO(sal_uInt8 nTest) {return nTest&0x10;}
xfEMBELL(sal_uInt8 nTest)108 	int xfEMBELL(sal_uInt8 nTest) {return nTest&0x20;}
xfNULL(sal_uInt8 nTest)109 	int xfNULL(sal_uInt8 nTest) {return nTest&0x10;}
xfLSPACE(sal_uInt8 nTest)110 	int xfLSPACE(sal_uInt8 nTest) {return nTest&0x40;}
xfRULER(sal_uInt8 nTest)111 	int xfRULER(sal_uInt8 nTest) {return nTest&0x20;}
112 
113 	sal_uInt8 HandleNodes(SmNode *pNode,int nLevel=0);
114 	int StartTemplate(sal_uInt16 nSelector,sal_uInt16 nVariation=0);
115 	void EndTemplate(int nOldPendingAttributes);
116 	void HandleSmMatrix(SmMatrixNode *pMatrix,int nLevel);
117 	void HandleTable(SmNode *pNode,int nLevel);
118 	void HandleRoot(SmNode *pNode,int nLevel);
119 	void HandleSubSupScript(SmNode *pNode,int nLevel);
120 	sal_uInt8 HandleCScript(SmNode *pNode,SmNode *pContent,int nLevel,
121 		sal_uLong *pPos=NULL,sal_Bool bTest=sal_True);
122 	void HandleFractions(SmNode *pNode,int nLevel);
123 	void HandleBrace(SmNode *pNode,int nLevel);
124 	void HandleVerticalBrace(SmNode *pNode,int nLevel);
125 	void HandleOperator(SmNode *pNode,int nLevel);
126 	sal_Bool HandleLim(SmNode *pNode,int nLevel);
127 	void HandleMAlign(SmNode *pNode,int nLevel);
128 	void HandleMath(SmNode *pNode,int nLevel);
129 	void HandleText(SmNode *pNode,int nLevel);
130 	void HandleAttributes(SmNode *pNode,int nLevel);
131 	void TypeFaceToString(String &rRet,sal_uInt8 nFace);
132 
133 	String &rRet;
134 	SmNode *pTree;
135 
136 	sal_uInt8 nHAlign;
137 	sal_uInt8 nVAlign;
138 
139 	int nPendingAttributes;
140 	sal_uLong nInsertion;
141 
142 	sal_Int16 aSizeTable[7];
143 	sal_Int16 nDefaultSize;
144 	sal_Int16 nLSize;
145 	sal_Int16 nDSize;
146 	sal_Int16 nCurSize;
147 	sal_Int16 nLastSize;
148 	sal_uInt8 nSpec;
149     sal_Bool bIsSilent, bIsReInterpBrace;
150 	String sPost;
151 	xub_StrLen nPostSup;
152 	xub_StrLen nPostlSup;
153 	sal_uInt8 nTypeFace;
154 	MathTypeFontSet aUserStyles;
155 
156 	enum MTOKENS {END,LINE,CHAR,TMPL,PILE,MATRIX,EMBEL,RULER,FONT,SIZE};
157 	enum MTEMPLATES
158 	{
159 		tmANGLE,tmPAREN,tmBRACE,tmBRACK,tmBAR,tmDBAR,tmFLOOR,tmCEILING,
160 		tmLBLB,tmRBRB,tmRBLB,tmLBRP,tmLPRB,tmROOT,tmFRACT,tmSCRIPT,tmUBAR,
161 		tmOBAR,tmLARROW,tmRARROW,tmBARROW,tmSINT,tmDINT,tmTINT,tmSSINT,
162 		tmDSINT,tmTSINT,tmUHBRACE,tmLHBRACE,tmSUM
163 	};
164 public:
165 	static sal_Bool LookupChar(sal_Unicode nChar,String &rRet,
166 		sal_uInt8 nVersion=3,sal_uInt8 nTypeFace=0);
167 };
168 
169 
170 #endif
171