Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / starmath / source / mathtype.hxx
blobcd06cfcddf879c9818b7ce660324c3b7d6c0e7a8
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #pragma once
22 #include <node.hxx>
24 #include <o3tl/sorted_vector.hxx>
26 class SfxMedium;
27 class SotStorage;
28 class SvStream;
30 class MathTypeFont
32 public:
33 sal_uInt8 nTface;
34 sal_uInt8 nStyle;
35 MathTypeFont() : nTface(0),nStyle(0) {}
36 explicit MathTypeFont(sal_uInt8 nFace) : nTface(nFace),nStyle(0) {}
37 void AppendStyleToText(OUString &rS);
40 struct LessMathTypeFont
42 bool operator() (const MathTypeFont &rValue1,
43 const MathTypeFont &rValue2) const
45 return rValue1.nTface < rValue2.nTface;
49 typedef o3tl::sorted_vector< MathTypeFont, LessMathTypeFont > MathTypeFontSet;
51 class MathType
53 public:
54 explicit MathType(OUStringBuffer &rIn)
55 : nVersion(0)
56 , pS(nullptr)
57 , rRet(rIn)
58 , pTree(nullptr)
59 , nHAlign(0)
60 , nPendingAttributes(0)
61 , nInsertion(0)
62 , nLSize(0)
63 , nDSize(0)
64 , nCurSize(0)
65 , nLastSize(0)
66 , nSpec(0)
67 , bIsReInterpBrace(false)
68 , nPostSup(0)
69 , nPostlSup(0)
70 , nTypeFace(0)
72 Init();
75 MathType(OUStringBuffer &rIn,SmNode *pIn)
76 : nVersion(0)
77 , pS(nullptr)
78 , rRet(rIn)
79 , pTree(pIn)
80 , nHAlign(2)
81 , nPendingAttributes(0)
82 , nInsertion(0)
83 , nLSize(0)
84 , nDSize(0)
85 , nCurSize(0)
86 , nLastSize(0)
87 , nSpec(0)
88 , bIsReInterpBrace(false)
89 , nPostSup(0)
90 , nPostlSup(0)
91 , nTypeFace(0)
93 Init();
96 bool Parse(SotStorage* pStor);
97 bool Parse(SvStream* pStream);
98 bool ConvertFromStarMath( SfxMedium& rMedium );
100 private:
101 /*Ver 2 Header*/
102 sal_uInt8 nVersion;
104 SvStream* pS;
106 void Init();
108 bool HandleRecords(int nLevel, sal_uInt8 nSelector =0xFF,
109 sal_uInt8 nVariation =0xFF, int nRows =0, int nCols =0);
110 bool HandleSize(sal_Int16 nLSize, sal_Int16 nDSize, int &rSetSize);
111 void HandleAlign(sal_uInt8 nHAlign, int &rSetAlign);
112 bool HandlePile(int &rSetAlign, int nLevel, sal_uInt8 nSelector, sal_uInt8 nVariation);
113 bool HandleMatrix(int nLevel, sal_uInt8 nSelector, sal_uInt8 nVariarion);
114 void HandleMatrixSeparator(int nMatrixRows, int nMatrixCols, int &rCurCol, int &rCurRow);
115 bool HandleTemplate(int nLevel, sal_uInt8 &rSelector, sal_uInt8 &rVariation,
116 sal_Int32 &rLastTemplateBracket);
117 void HandleEmblishments();
118 void HandleSetSize();
119 bool HandleChar(sal_Int32 &rTextStart, int &rSetSize, int nLevel,
120 sal_uInt8 nTag, sal_uInt8 nSelector, sal_uInt8 nVariation, bool bSilent);
121 void HandleNudge();
123 static int xfLMOVE(sal_uInt8 nTest) {return nTest&0x80;}
124 static int xfAUTO(sal_uInt8 nTest) {return nTest&0x10;}
125 static int xfEMBELL(sal_uInt8 nTest) {return nTest&0x20;}
126 static int xfNULL(sal_uInt8 nTest) {return nTest&0x10;}
128 void HandleNodes(SmNode *pNode,int nLevel);
129 int StartTemplate(sal_uInt16 nSelector,sal_uInt16 nVariation=0);
130 void EndTemplate(int nOldPendingAttributes);
131 void HandleSmMatrix(SmMatrixNode *pMatrix,int nLevel);
132 void HandleTable(SmNode *pNode,int nLevel);
133 void HandleRoot(SmNode *pNode,int nLevel);
134 void HandleSubSupScript(SmNode *pNode,int nLevel);
135 sal_uInt8 HandleCScript(SmNode *pNode,SmNode *pContent,int nLevel,
136 sal_uInt64 *pPos=nullptr,bool bTest=true);
137 void HandleFractions(SmNode *pNode,int nLevel);
138 void HandleBrace(SmNode *pNode,int nLevel);
139 void HandleVerticalBrace(SmNode *pNode,int nLevel);
140 void HandleOperator(SmNode *pNode,int nLevel);
141 bool HandleLim(SmNode *pNode,int nLevel);
142 void HandleMAlign(SmNode *pNode,int nLevel);
143 void HandleMath(SmNode *pNode);
144 void HandleText(SmNode *pNode);
145 void HandleAttributes(SmNode *pNode,int nLevel);
146 void TypeFaceToString(OUString &rRet,sal_uInt8 nFace);
148 OUStringBuffer &rRet;
149 SmNode *pTree;
151 sal_uInt8 nHAlign;
153 int nPendingAttributes;
154 sal_uInt64 nInsertion;
156 sal_Int16 nLSize;
157 sal_Int16 nDSize;
158 sal_Int16 nCurSize;
159 sal_Int16 nLastSize;
160 sal_uInt8 nSpec;
161 bool bIsReInterpBrace;
162 OUStringBuffer sPost;
163 sal_Int32 nPostSup;
164 sal_Int32 nPostlSup;
165 sal_uInt8 nTypeFace;
166 MathTypeFontSet aUserStyles;
168 enum MTOKENS {END,LINE,CHAR,TMPL,PILE,MATRIX,EMBEL,RULER,FONT,SIZE};
169 enum MTEMPLATES
171 tmANGLE,tmPAREN,tmBRACE,tmBRACK,tmBAR,tmDBAR,tmFLOOR,tmCEILING,
172 tmLBLB,tmRBRB,tmRBLB,tmLBRP,tmLPRB,tmROOT,tmFRACT,tmSCRIPT,tmUBAR,
173 tmOBAR,tmLARROW,tmRARROW,tmBARROW,tmSINT,tmDINT,tmTINT,tmSSINT,
174 tmDSINT,tmTSINT,tmUHBRACE,tmLHBRACE,tmSUM,tmISUM,tmPROD,tmIPROD,
175 tmCOPROD,tmICOPROD,tmUNION,tmIUNION,tmINTER,tmIINTER,tmLIM,tmLDIV,
176 tmSLFRACT,tmINTOP,tmSUMOP,tmLSCRIPT,tmDIRAC,tmUARROW,tmOARROW,
177 tmOARC
179 public:
180 static bool LookupChar(sal_Unicode nChar,OUStringBuffer &rRet,
181 sal_uInt8 nVersion,sal_uInt8 nTypeFace=0);
184 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */