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