1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 /* 3 * This file is part of the LibreOffice project. 4 * 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/. 8 * 9 * This file incorporates work covered by the following license notice: 10 * 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 . 18 */ 19 20 #ifndef INCLUDED_STARMATH_SOURCE_MATHTYPE_HXX 21 #define INCLUDED_STARMATH_SOURCE_MATHTYPE_HXX 22 23 #include <rtl/ustring.hxx> 24 #include <rtl/ustrbuf.hxx> 25 26 #include <set> 27 #include <vector> 28 29 class SfxMedium; 30 class SmMatrixNode; 31 class SmNode; 32 class SotStorage; 33 class SvStream; 34 35 class MathTypeFont 36 { 37 public: 38 sal_uInt8 nTface; 39 sal_uInt8 nStyle; MathTypeFont()40 MathTypeFont() : nTface(0),nStyle(0) {} MathTypeFont(sal_uInt8 nFace)41 explicit MathTypeFont(sal_uInt8 nFace) : nTface(nFace),nStyle(0) {} 42 void AppendStyleToText(OUString &rS); 43 }; 44 45 struct LessMathTypeFont 46 { operator ()LessMathTypeFont47 bool operator() (const MathTypeFont &rValue1, 48 const MathTypeFont &rValue2) const 49 { 50 return rValue1.nTface < rValue2.nTface; 51 } 52 }; 53 54 typedef ::std::set< MathTypeFont, LessMathTypeFont > MathTypeFontSet; 55 56 class MathType 57 { 58 public: MathType(OUStringBuffer & rIn)59 explicit MathType(OUStringBuffer &rIn) 60 : nVersion(0) 61 , pS(nullptr) 62 , rRet(rIn) 63 , pTree(nullptr) 64 , nHAlign(0) 65 , nPendingAttributes(0) 66 , nInsertion(0) 67 , nLSize(0) 68 , nDSize(0) 69 , nCurSize(0) 70 , nLastSize(0) 71 , nSpec(0) 72 , bIsReInterpBrace(false) 73 , nPostSup(0) 74 , nPostlSup(0) 75 , nTypeFace(0) 76 { 77 Init(); 78 } 79 MathType(OUStringBuffer & rIn,SmNode * pIn)80 MathType(OUStringBuffer &rIn,SmNode *pIn) 81 : nVersion(0) 82 , pS(nullptr) 83 , rRet(rIn) 84 , pTree(pIn) 85 , nHAlign(2) 86 , nPendingAttributes(0) 87 , nInsertion(0) 88 , nLSize(0) 89 , nDSize(0) 90 , nCurSize(0) 91 , nLastSize(0) 92 , nSpec(0) 93 , bIsReInterpBrace(false) 94 , nPostSup(0) 95 , nPostlSup(0) 96 , nTypeFace(0) 97 { 98 Init(); 99 } 100 101 bool Parse(SotStorage* pStor); 102 bool Parse(SvStream* pStream); 103 bool ConvertFromStarMath( SfxMedium& rMedium ); 104 105 private: 106 /*Ver 2 Header*/ 107 sal_uInt8 nVersion; 108 109 SvStream* pS; 110 111 void Init(); 112 113 bool HandleRecords(int nLevel, sal_uInt8 nSelector =0xFF, 114 sal_uInt8 nVariation =0xFF, int nRows =0, int nCols =0); 115 bool HandleSize(sal_Int16 nLSize, sal_Int16 nDSize, int &rSetSize); 116 void HandleAlign(sal_uInt8 nHAlign, int &rSetAlign); 117 bool HandlePile(int &rSetAlign, int nLevel, sal_uInt8 nSelector, sal_uInt8 nVariation); 118 bool HandleMatrix(int nLevel, sal_uInt8 nSelector, sal_uInt8 nVariarion); 119 void HandleMatrixSeparator(int nMatrixRows, int nMatrixCols, int &rCurCol, int &rCurRow); 120 bool HandleTemplate(int nLevel, sal_uInt8 &rSelector, sal_uInt8 &rVariation, 121 sal_Int32 &rLastTemplateBracket); 122 void HandleEmblishments(); 123 void HandleSetSize(); 124 bool HandleChar(sal_Int32 &rTextStart, int &rSetSize, int nLevel, 125 sal_uInt8 nTag, sal_uInt8 nSelector, sal_uInt8 nVariation, bool bSilent); 126 void HandleNudge(); 127 xfLMOVE(sal_uInt8 nTest)128 static int xfLMOVE(sal_uInt8 nTest) {return nTest&0x80;} xfAUTO(sal_uInt8 nTest)129 static int xfAUTO(sal_uInt8 nTest) {return nTest&0x10;} xfEMBELL(sal_uInt8 nTest)130 static int xfEMBELL(sal_uInt8 nTest) {return nTest&0x20;} xfNULL(sal_uInt8 nTest)131 static int xfNULL(sal_uInt8 nTest) {return nTest&0x10;} 132 133 void HandleNodes(SmNode *pNode,int nLevel); 134 int StartTemplate(sal_uInt16 nSelector,sal_uInt16 nVariation=0); 135 void EndTemplate(int nOldPendingAttributes); 136 void HandleSmMatrix(SmMatrixNode *pMatrix,int nLevel); 137 void HandleTable(SmNode *pNode,int nLevel); 138 void HandleRoot(SmNode *pNode,int nLevel); 139 void HandleSubSupScript(SmNode *pNode,int nLevel); 140 sal_uInt8 HandleCScript(SmNode *pNode,SmNode *pContent,int nLevel, 141 sal_uInt64 *pPos=nullptr,bool bTest=true); 142 void HandleFractions(SmNode *pNode,int nLevel); 143 void HandleBrace(SmNode *pNode,int nLevel); 144 void HandleVerticalBrace(SmNode *pNode,int nLevel); 145 void HandleOperator(SmNode *pNode,int nLevel); 146 bool HandleLim(SmNode *pNode,int nLevel); 147 void HandleMAlign(SmNode *pNode,int nLevel); 148 void HandleMath(SmNode *pNode); 149 void HandleText(SmNode *pNode); 150 void HandleAttributes(SmNode *pNode,int nLevel); 151 void TypeFaceToString(OUString &rRet,sal_uInt8 nFace); 152 153 OUStringBuffer &rRet; 154 SmNode * const pTree; 155 156 sal_uInt8 nHAlign; 157 158 int nPendingAttributes; 159 sal_uInt64 nInsertion; 160 161 std::vector<sal_Int16> aSizeTable; 162 sal_Int16 nLSize; 163 sal_Int16 nDSize; 164 sal_Int16 nCurSize; 165 sal_Int16 nLastSize; 166 sal_uInt8 nSpec; 167 bool bIsReInterpBrace; 168 OUStringBuffer sPost; 169 sal_Int32 nPostSup; 170 sal_Int32 nPostlSup; 171 sal_uInt8 nTypeFace; 172 MathTypeFontSet aUserStyles; 173 174 enum MTOKENS {END,LINE,CHAR,TMPL,PILE,MATRIX,EMBEL,RULER,FONT,SIZE}; 175 enum MTEMPLATES 176 { 177 tmANGLE,tmPAREN,tmBRACE,tmBRACK,tmBAR,tmDBAR,tmFLOOR,tmCEILING, 178 tmLBLB,tmRBRB,tmRBLB,tmLBRP,tmLPRB,tmROOT,tmFRACT,tmSCRIPT,tmUBAR, 179 tmOBAR,tmLARROW,tmRARROW,tmBARROW,tmSINT,tmDINT,tmTINT,tmSSINT, 180 tmDSINT,tmTSINT,tmUHBRACE,tmLHBRACE,tmSUM,tmISUM,tmPROD,tmIPROD, 181 tmCOPROD,tmICOPROD,tmUNION,tmIUNION,tmINTER,tmIINTER,tmLIM,tmLDIV, 182 tmSLFRACT,tmINTOP,tmSUMOP,tmLSCRIPT,tmDIRAC,tmUARROW,tmOARROW, 183 tmOARC 184 }; 185 public: 186 static bool LookupChar(sal_Unicode nChar,OUStringBuffer &rRet, 187 sal_uInt8 nVersion,sal_uInt8 nTypeFace=0); 188 }; 189 190 191 #endif 192 193 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 194