xref: /AOO41X/main/starmath/source/mathtype.cxx (revision d107581f588b53ce11339a8a18091c0f86ec8bb4)
1*d107581fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*d107581fSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*d107581fSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*d107581fSAndrew Rist  * distributed with this work for additional information
6*d107581fSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*d107581fSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*d107581fSAndrew Rist  * "License"); you may not use this file except in compliance
9*d107581fSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*d107581fSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*d107581fSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*d107581fSAndrew Rist  * software distributed under the License is distributed on an
15*d107581fSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*d107581fSAndrew Rist  * KIND, either express or implied.  See the License for the
17*d107581fSAndrew Rist  * specific language governing permissions and limitations
18*d107581fSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*d107581fSAndrew Rist  *************************************************************/
21*d107581fSAndrew Rist 
22*d107581fSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_starmath.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil -*- */
28cdf0e10cSrcweir #include <mathtype.hxx>
29cdf0e10cSrcweir 
30cdf0e10cSrcweir #ifndef _TOOLS_DEBUG_H
31cdf0e10cSrcweir #include <tools/debug.hxx>
32cdf0e10cSrcweir #endif
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #include <sfx2/docfile.hxx>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #define APPEND(str,ascii) str.AppendAscii(RTL_CONSTASCII_STRINGPARAM(ascii))
37cdf0e10cSrcweir 
38cdf0e10cSrcweir #if 0
39cdf0e10cSrcweir String aEmbelList[21] =
40cdf0e10cSrcweir {
41cdf0e10cSrcweir     " ",
42cdf0e10cSrcweir     " ",
43cdf0e10cSrcweir     "single dot",
44cdf0e10cSrcweir     "double dot",
45cdf0e10cSrcweir     "triple dot",
46cdf0e10cSrcweir     "single prime",
47cdf0e10cSrcweir     "double prime",
48cdf0e10cSrcweir     "backwards prime (left of character)",
49cdf0e10cSrcweir     "tilde",
50cdf0e10cSrcweir     "hat (circumflex)",
51cdf0e10cSrcweir     "diagonal slash through character",
52cdf0e10cSrcweir     "right arrow",
53cdf0e10cSrcweir     "left arrow",
54cdf0e10cSrcweir     "double-headed arrow",
55cdf0e10cSrcweir     "right single-barbed arrow",
56cdf0e10cSrcweir     "left single-barbed arrow",
57cdf0e10cSrcweir     "mid-height horizontal bar",
58cdf0e10cSrcweir     "over-bar",
59cdf0e10cSrcweir     "triple prime",
60cdf0e10cSrcweir     "over-arc, concave downward",
61cdf0e10cSrcweir     "over-arc, concave upward"
62cdf0e10cSrcweir };
63cdf0e10cSrcweir 
64cdf0e10cSrcweir String aSelectorList[49] =
65cdf0e10cSrcweir {
66cdf0e10cSrcweir     "angle brackets",
67cdf0e10cSrcweir     "parentheses",
68cdf0e10cSrcweir     "braces (curly brackets)",
69cdf0e10cSrcweir     "square brackets",
70cdf0e10cSrcweir     "vertical bars",
71cdf0e10cSrcweir     "double vertical bars",
72cdf0e10cSrcweir     "floor brackets",
73cdf0e10cSrcweir     "ceiling brackets",
74cdf0e10cSrcweir     "left brace, left brace",
75cdf0e10cSrcweir     "right brace, right brace",
76cdf0e10cSrcweir     "right brace, left brace",
77cdf0e10cSrcweir     "left brace, right parenthesis",
78cdf0e10cSrcweir     "left parenthesis, right brace",
79cdf0e10cSrcweir     "radical",
80cdf0e10cSrcweir     "fractions",
81cdf0e10cSrcweir     "subscript/superscript",
82cdf0e10cSrcweir     "underbar",
83cdf0e10cSrcweir     "overbar",
84cdf0e10cSrcweir     "left-pointing arrow",
85cdf0e10cSrcweir     "right-pointing arrow",
86cdf0e10cSrcweir     "left- and right-pointing arrow",
87cdf0e10cSrcweir     "single integral",
88cdf0e10cSrcweir     "double integral",
89cdf0e10cSrcweir     "triple integral",
90cdf0e10cSrcweir     "single summation-style integral",
91cdf0e10cSrcweir     "double summation-style integral",
92cdf0e10cSrcweir     "triple summation-style integral",
93cdf0e10cSrcweir     "upper horizontal brace",
94cdf0e10cSrcweir     "lower horizontal brace",
95cdf0e10cSrcweir     "summation",
96cdf0e10cSrcweir     "summation (integral-style limits)",
97cdf0e10cSrcweir     "product",
98cdf0e10cSrcweir     "product (integral-style limits)",
99cdf0e10cSrcweir     "coproduct",
100cdf0e10cSrcweir     "coproduct (integral-style limits)",
101cdf0e10cSrcweir     "union",
102cdf0e10cSrcweir     "union (integral-style limits)",
103cdf0e10cSrcweir     "intersection",
104cdf0e10cSrcweir     "intersection (integral-style limits)",
105cdf0e10cSrcweir     "limit",
106cdf0e10cSrcweir     "long division",
107cdf0e10cSrcweir     "slash fractions",
108cdf0e10cSrcweir     "big integral-style operators",
109cdf0e10cSrcweir     "big summation-style operators",
110cdf0e10cSrcweir     "leading sub- and superscripts",
111cdf0e10cSrcweir     "Dirac delta",
112cdf0e10cSrcweir     "under arrow",
113cdf0e10cSrcweir     "over arrow",
114cdf0e10cSrcweir     "over arc"
115cdf0e10cSrcweir };
116cdf0e10cSrcweir 
117cdf0e10cSrcweir String aIntegralOpt[2] =
118cdf0e10cSrcweir {
119cdf0e10cSrcweir     "fixed-size integral",
120cdf0e10cSrcweir     "integral expands vertically to fit its contents"
121cdf0e10cSrcweir };
122cdf0e10cSrcweir 
123cdf0e10cSrcweir String aFenceOpt[3] =
124cdf0e10cSrcweir {
125cdf0e10cSrcweir     "center fence on math axis",
126cdf0e10cSrcweir     "center fence on contents, place math axis of contents on math axis of containing line",
127cdf0e10cSrcweir     "center fence on contents, center contents on math axis of containing line"
128cdf0e10cSrcweir };
129cdf0e10cSrcweir 
130cdf0e10cSrcweir String aTypeFaces[12] =
131cdf0e10cSrcweir {
132cdf0e10cSrcweir     "",
133cdf0e10cSrcweir     "fnTEXT",
134cdf0e10cSrcweir     "fnFUNCTION",
135cdf0e10cSrcweir     "fnVARIABLE",
136cdf0e10cSrcweir     "fnLCGREEK",
137cdf0e10cSrcweir     "fnUCGREEK",
138cdf0e10cSrcweir     "fnSYMBOL",
139cdf0e10cSrcweir     "fnVECTOR",
140cdf0e10cSrcweir     "fnNUMBER",
141cdf0e10cSrcweir     "fnUSER1",
142cdf0e10cSrcweir     "fnUSER2",
143cdf0e10cSrcweir     "fnMTEXTRA"
144cdf0e10cSrcweir };
145cdf0e10cSrcweir 
146cdf0e10cSrcweir String aSizes[7] =
147cdf0e10cSrcweir {
148cdf0e10cSrcweir     "full",
149cdf0e10cSrcweir     "subscript",
150cdf0e10cSrcweir     "sub-subscript",
151cdf0e10cSrcweir     "symbol",
152cdf0e10cSrcweir     "sub-symbol",
153cdf0e10cSrcweir     "user 1",
154cdf0e10cSrcweir     "user 2"
155cdf0e10cSrcweir };
156cdf0e10cSrcweir #endif
157cdf0e10cSrcweir 
Convert(sal_Unicode nIn)158cdf0e10cSrcweir static sal_Unicode Convert(sal_Unicode nIn)
159cdf0e10cSrcweir {
160cdf0e10cSrcweir     //Find the best match in accepted unicode for our private area symbols
161cdf0e10cSrcweir     static sal_Unicode aStarMathPrivateToUnicode[] =
162cdf0e10cSrcweir     {
163cdf0e10cSrcweir         0x2030, 0xF613, 0xF612, 0x002B, 0x003C, 0x003E, 0xE425, 0xE421, 0xE088, 0x2208,
164cdf0e10cSrcweir         0x0192, 0x2026, 0x2192, 0x221A, 0x221A, 0x221A, 0xE090, 0x005E, 0x02C7, 0x02D8,
165cdf0e10cSrcweir         0x00B4, 0x0060, 0x02DC, 0x00AF, 0x0362, 0xE099, 0xE09A, 0x20DB, 0xE09C, 0xE09D,
166cdf0e10cSrcweir         0x0028, 0x0029, 0x2220, 0x22AF, 0xE0A2, 0xE0A3, 0xE0A4, 0xE0A5, 0xE0A6, 0xE0A7,
167cdf0e10cSrcweir         0x002F, 0x005C, 0x274F, 0xE0AB, 0x0393, 0x0394, 0x0398, 0x039b, 0x039e, 0x03A0,
168cdf0e10cSrcweir         0x03a3, 0x03a5, 0x03a6, 0x03a8, 0x03A9, 0x03B1, 0x03B2, 0x03b3, 0x03b4, 0x03b5,
169cdf0e10cSrcweir         0x03b6, 0x03b7, 0x03b8, 0x03b9, 0x03ba, 0x03bb, 0x03bc, 0x03bd, 0x03be, 0x03bf,
170cdf0e10cSrcweir         0x03c0, 0x03c1, 0x03c3, 0x03c4, 0x03c5, 0x03c6, 0x03c7, 0x03c8, 0x03c9, 0x03b5,
171cdf0e10cSrcweir         0x03d1, 0x03d6, 0xE0D2, 0x03db, 0x2118, 0x2202, 0x2129, 0xE0D7, 0xE0D8, 0x22A4,
172cdf0e10cSrcweir         0xE0DA, 0x2190, 0x2191, 0x2193
173cdf0e10cSrcweir     };
174cdf0e10cSrcweir     if ((nIn >= 0xE080) && (nIn <= 0xE0DD))
175cdf0e10cSrcweir         nIn = aStarMathPrivateToUnicode[nIn-0xE080];
176cdf0e10cSrcweir 
177cdf0e10cSrcweir     //For whatever unicode glyph that equation editor doesn't ship with that
178cdf0e10cSrcweir     //we have a possible match we can munge it to.
179cdf0e10cSrcweir     switch (nIn)
180cdf0e10cSrcweir     {
181cdf0e10cSrcweir         case 0x2223:
182cdf0e10cSrcweir             nIn = '|';
183cdf0e10cSrcweir             break;
184cdf0e10cSrcweir         default:
185cdf0e10cSrcweir             break;
186cdf0e10cSrcweir     }
187cdf0e10cSrcweir 
188cdf0e10cSrcweir     return nIn;
189cdf0e10cSrcweir }
190cdf0e10cSrcweir 
Init()191cdf0e10cSrcweir void MathType::Init()
192cdf0e10cSrcweir {
193cdf0e10cSrcweir     //These are the default MathType sizes
194cdf0e10cSrcweir     aSizeTable[0]=12;
195cdf0e10cSrcweir     aSizeTable[1]=8;
196cdf0e10cSrcweir     aSizeTable[2]=6;
197cdf0e10cSrcweir     aSizeTable[3]=24;
198cdf0e10cSrcweir     aSizeTable[4]=10;
199cdf0e10cSrcweir     aSizeTable[5]=12;
200cdf0e10cSrcweir     aSizeTable[6]=12;
201cdf0e10cSrcweir 
202cdf0e10cSrcweir     /*
203cdf0e10cSrcweir     These are the default MathType italic/bold settings If mathtype is changed
204cdf0e10cSrcweir     from its defaults, there is nothing we can do, as this information is not
205cdf0e10cSrcweir     stored in the document
206cdf0e10cSrcweir     */
207cdf0e10cSrcweir     MathTypeFont aFont;
208cdf0e10cSrcweir     for(sal_uInt8 i=1;i<=11;i++)
209cdf0e10cSrcweir     {
210cdf0e10cSrcweir         aFont.nTface = i+128;
211cdf0e10cSrcweir         switch (i)
212cdf0e10cSrcweir         {
213cdf0e10cSrcweir             default:
214cdf0e10cSrcweir                 aFont.nStyle=0;
215cdf0e10cSrcweir                 break;
216cdf0e10cSrcweir             case 3:
217cdf0e10cSrcweir             case 4:
218cdf0e10cSrcweir                 aFont.nStyle=1;
219cdf0e10cSrcweir                 break;
220cdf0e10cSrcweir             case 7:
221cdf0e10cSrcweir                 aFont.nStyle=2;
222cdf0e10cSrcweir                 break;
223cdf0e10cSrcweir         }
224cdf0e10cSrcweir         aUserStyles.insert(aFont);
225cdf0e10cSrcweir     }
226cdf0e10cSrcweir }
227cdf0e10cSrcweir 
228cdf0e10cSrcweir 
229cdf0e10cSrcweir /*ToDo replace with table rather than switch, returns
230cdf0e10cSrcweir  sal_True in the case that the char is just a char, and
231cdf0e10cSrcweir  sal_False if the character is an operator which must not be
232cdf0e10cSrcweir  placed inside the quote sequence designed to protect
233cdf0e10cSrcweir  against being parsed as a keyword
234cdf0e10cSrcweir 
235cdf0e10cSrcweir  General solution required to force starmath to handle
236cdf0e10cSrcweir  unicode math chars the way it handles its own math
237cdf0e10cSrcweir  chars rathar than handle them as text as it will do
238cdf0e10cSrcweir  for the default case below, i.e. incorrect spacing
239cdf0e10cSrcweir  between math symbols and ordinary text e.g. 1=2 rather
240cdf0e10cSrcweir  than 1 = 2
241cdf0e10cSrcweir  */
LookupChar(sal_Unicode nChar,String & rRet,sal_uInt8 nVersion,sal_uInt8 nTypeFace)242cdf0e10cSrcweir sal_Bool MathType::LookupChar(sal_Unicode nChar,String &rRet,sal_uInt8 nVersion,
243cdf0e10cSrcweir     sal_uInt8 nTypeFace)
244cdf0e10cSrcweir {
245cdf0e10cSrcweir     sal_Bool bRet=sal_False;
246cdf0e10cSrcweir     const char *pC = NULL;
247cdf0e10cSrcweir     switch(nChar)
248cdf0e10cSrcweir     {
249cdf0e10cSrcweir         case 0x0000:
250cdf0e10cSrcweir             pC = " none ";
251cdf0e10cSrcweir             break;
252cdf0e10cSrcweir         case 0x00ac:
253cdf0e10cSrcweir             pC = " neg ";
254cdf0e10cSrcweir             break;
255cdf0e10cSrcweir         case 0x00b1:
256cdf0e10cSrcweir             pC = " +- ";
257cdf0e10cSrcweir             break;
258cdf0e10cSrcweir         case '(':
259cdf0e10cSrcweir             pC = " \\( ";
260cdf0e10cSrcweir             break;
261cdf0e10cSrcweir         case ')':
262cdf0e10cSrcweir             pC = " \\) ";
263cdf0e10cSrcweir             break;
264cdf0e10cSrcweir         case '[':
265cdf0e10cSrcweir             pC = " \\[ ";
266cdf0e10cSrcweir             break;
267cdf0e10cSrcweir         case ']':
268cdf0e10cSrcweir             pC = " \\] ";
269cdf0e10cSrcweir             break;
270cdf0e10cSrcweir         case '.':
271cdf0e10cSrcweir             pC = " \".\" ";
272cdf0e10cSrcweir             break;
273cdf0e10cSrcweir         case 0xae:
274cdf0e10cSrcweir             if ((nVersion < 3) && (nTypeFace == 0x86))
275cdf0e10cSrcweir                 pC = " rightarrow ";
276cdf0e10cSrcweir             else
277cdf0e10cSrcweir             {
278cdf0e10cSrcweir                 rRet.Append(nChar);
279cdf0e10cSrcweir                 bRet=sal_True;
280cdf0e10cSrcweir             }
281cdf0e10cSrcweir             break;
282cdf0e10cSrcweir         case 0x00fb:
283cdf0e10cSrcweir             if ((nVersion < 3) && (nTypeFace == 0x81))
284cdf0e10cSrcweir                 nChar = 0xDF;
285cdf0e10cSrcweir             rRet.Append(nChar);
286cdf0e10cSrcweir             bRet=sal_True;
287cdf0e10cSrcweir             break;
288cdf0e10cSrcweir         case 'a':
289cdf0e10cSrcweir             if ((nVersion < 3) && (nTypeFace == 0x84))
290cdf0e10cSrcweir                 nChar = 0x3b1;
291cdf0e10cSrcweir             rRet.Append(nChar);
292cdf0e10cSrcweir             bRet=sal_True;
293cdf0e10cSrcweir             break;
294cdf0e10cSrcweir         case 'b':
295cdf0e10cSrcweir             if ((nVersion < 3) && (nTypeFace == 0x84))
296cdf0e10cSrcweir                 nChar = 0x3b2;
297cdf0e10cSrcweir             rRet.Append(nChar);
298cdf0e10cSrcweir             bRet=sal_True;
299cdf0e10cSrcweir             break;
300cdf0e10cSrcweir         case 'l':
301cdf0e10cSrcweir             if ((nVersion < 3) && (nTypeFace == 0x84))
302cdf0e10cSrcweir                 nChar = 0x3bb;
303cdf0e10cSrcweir             rRet.Append(nChar);
304cdf0e10cSrcweir             bRet=sal_True;
305cdf0e10cSrcweir             break;
306cdf0e10cSrcweir         case 'n':
307cdf0e10cSrcweir             if ((nVersion < 3) && (nTypeFace == 0x84))
308cdf0e10cSrcweir                 nChar = 0x3bd;
309cdf0e10cSrcweir             rRet.Append(nChar);
310cdf0e10cSrcweir             bRet=sal_True;
311cdf0e10cSrcweir             break;
312cdf0e10cSrcweir         case 'r':
313cdf0e10cSrcweir             if ((nVersion < 3) && (nTypeFace == 0x84))
314cdf0e10cSrcweir                 nChar = 0x3c1;
315cdf0e10cSrcweir             rRet.Append(nChar);
316cdf0e10cSrcweir             bRet=sal_True;
317cdf0e10cSrcweir             break;
318cdf0e10cSrcweir         case 'D':
319cdf0e10cSrcweir             if ((nVersion < 3) && (nTypeFace == 0x84))
320cdf0e10cSrcweir                 nChar = 0x394;
321cdf0e10cSrcweir             rRet.Append(nChar);
322cdf0e10cSrcweir             bRet=sal_True;
323cdf0e10cSrcweir             break;
324cdf0e10cSrcweir         case 0xa9:
325cdf0e10cSrcweir             if ((nVersion < 3) && (nTypeFace == 0x82))
326cdf0e10cSrcweir                 nChar = '\'';
327cdf0e10cSrcweir             rRet.Append(nChar);
328cdf0e10cSrcweir             bRet=sal_True;
329cdf0e10cSrcweir             break;
330cdf0e10cSrcweir         case 0x00f1:
331cdf0e10cSrcweir             if ((nVersion < 3) && (nTypeFace == 0x86))
332cdf0e10cSrcweir                 pC = " \\rangle ";
333cdf0e10cSrcweir             else
334cdf0e10cSrcweir             {
335cdf0e10cSrcweir                 rRet.Append(nChar);
336cdf0e10cSrcweir                 bRet=sal_True;
337cdf0e10cSrcweir             }
338cdf0e10cSrcweir             break;
339cdf0e10cSrcweir         case 0x00a3:
340cdf0e10cSrcweir             if ((nVersion < 3) && (nTypeFace == 0x86))
341cdf0e10cSrcweir                 pC = " <= ";
342cdf0e10cSrcweir             else
343cdf0e10cSrcweir             {
344cdf0e10cSrcweir                 rRet.Append(nChar);
345cdf0e10cSrcweir                 bRet=sal_True;
346cdf0e10cSrcweir             }
347cdf0e10cSrcweir             break;
348cdf0e10cSrcweir         case 0x00de:
349cdf0e10cSrcweir             if ((nVersion < 3) && (nTypeFace == 0x86))
350cdf0e10cSrcweir                 pC = " drarrow ";
351cdf0e10cSrcweir             else
352cdf0e10cSrcweir             {
353cdf0e10cSrcweir                 rRet.Append(nChar);
354cdf0e10cSrcweir                 bRet=sal_True;
355cdf0e10cSrcweir             }
356cdf0e10cSrcweir             break;
357cdf0e10cSrcweir         case 0x0057:
358cdf0e10cSrcweir             if ((nVersion < 3) && (nTypeFace == 0x85))
359cdf0e10cSrcweir                 pC = " %OMEGA ";
360cdf0e10cSrcweir             else
361cdf0e10cSrcweir             {
362cdf0e10cSrcweir                 rRet.Append(nChar);
363cdf0e10cSrcweir                 bRet=sal_True;
364cdf0e10cSrcweir             }
365cdf0e10cSrcweir             break;
366cdf0e10cSrcweir         case 0x007b:
367cdf0e10cSrcweir             pC = " lbrace ";
368cdf0e10cSrcweir             break;
369cdf0e10cSrcweir         case 0x007c:
370cdf0e10cSrcweir             pC = " \\lline ";
371cdf0e10cSrcweir             break;
372cdf0e10cSrcweir         case 0x007d:
373cdf0e10cSrcweir             pC = " rbrace ";
374cdf0e10cSrcweir             break;
375cdf0e10cSrcweir         case 0x007e:
376cdf0e10cSrcweir             pC = " \"~\" ";
377cdf0e10cSrcweir             break;
378cdf0e10cSrcweir         case 0x2224:
379cdf0e10cSrcweir             pC = " ndivides ";
380cdf0e10cSrcweir             break;
381cdf0e10cSrcweir         case 0x2225:
382cdf0e10cSrcweir             pC = " parallel ";
383cdf0e10cSrcweir             break;
384cdf0e10cSrcweir         case 0x00d7:
385cdf0e10cSrcweir             if (nVersion < 3)
386cdf0e10cSrcweir                 pC = " cdot ";
387cdf0e10cSrcweir             else
388cdf0e10cSrcweir                 pC = " times ";
389cdf0e10cSrcweir             break;
390cdf0e10cSrcweir         case 0x00f7:
391cdf0e10cSrcweir             pC = " div ";
392cdf0e10cSrcweir             break;
393cdf0e10cSrcweir         case 0x019b:
394cdf0e10cSrcweir             pC = " lambdabar ";
395cdf0e10cSrcweir             break;
396cdf0e10cSrcweir         case 0x2026:
397cdf0e10cSrcweir             pC = " dotslow ";
398cdf0e10cSrcweir             break;
399cdf0e10cSrcweir         case 0x2022:
400cdf0e10cSrcweir             pC = " cdot ";
401cdf0e10cSrcweir             break;
402cdf0e10cSrcweir         case 0x2102:
403cdf0e10cSrcweir             pC = " setC ";
404cdf0e10cSrcweir             break;
405cdf0e10cSrcweir         case 0x210f:
406cdf0e10cSrcweir             pC = " hbar ";
407cdf0e10cSrcweir             break;
408cdf0e10cSrcweir         case 0x2111:
409cdf0e10cSrcweir             pC = " Im ";
410cdf0e10cSrcweir             break;
411cdf0e10cSrcweir         case 0x2115:
412cdf0e10cSrcweir             pC = " setN ";
413cdf0e10cSrcweir             break;
414cdf0e10cSrcweir         case 0x2118:
415cdf0e10cSrcweir             pC = " wp ";
416cdf0e10cSrcweir             break;
417cdf0e10cSrcweir         case 0x211a:
418cdf0e10cSrcweir             pC = " setQ ";
419cdf0e10cSrcweir             break;
420cdf0e10cSrcweir         case 0x211c:
421cdf0e10cSrcweir             pC = " Re ";
422cdf0e10cSrcweir             break;
423cdf0e10cSrcweir         case 0x211d:
424cdf0e10cSrcweir             pC = " setR ";
425cdf0e10cSrcweir             break;
426cdf0e10cSrcweir         case 0x2124:
427cdf0e10cSrcweir             pC = " setZ ";
428cdf0e10cSrcweir             break;
429cdf0e10cSrcweir         case 0x2135:
430cdf0e10cSrcweir             pC = " aleph ";
431cdf0e10cSrcweir             break;
432cdf0e10cSrcweir         case 0x2190:
433cdf0e10cSrcweir             pC = " leftarrow ";
434cdf0e10cSrcweir             break;
435cdf0e10cSrcweir         case 0x2191:
436cdf0e10cSrcweir             pC = " uparrow ";
437cdf0e10cSrcweir             break;
438cdf0e10cSrcweir         case 0x2192:
439cdf0e10cSrcweir             pC = " rightarrow ";
440cdf0e10cSrcweir             break;
441cdf0e10cSrcweir         case 0x0362:
442cdf0e10cSrcweir             pC = " widevec ";
443cdf0e10cSrcweir             break;
444cdf0e10cSrcweir         case 0x2193:
445cdf0e10cSrcweir             pC = " downarrow ";
446cdf0e10cSrcweir             break;
447cdf0e10cSrcweir         case 0x21d0:
448cdf0e10cSrcweir             pC = " dlarrow ";
449cdf0e10cSrcweir             break;
450cdf0e10cSrcweir         case 0x21d2:
451cdf0e10cSrcweir             pC = " drarrow ";
452cdf0e10cSrcweir             break;
453cdf0e10cSrcweir         case 0x21d4:
454cdf0e10cSrcweir             pC = " dlrarrow ";
455cdf0e10cSrcweir             break;
456cdf0e10cSrcweir         case 0x2200:
457cdf0e10cSrcweir             pC = " forall ";
458cdf0e10cSrcweir             break;
459cdf0e10cSrcweir         case 0x2202:
460cdf0e10cSrcweir             pC = " partial ";
461cdf0e10cSrcweir             break;
462cdf0e10cSrcweir         case 0x2203:
463cdf0e10cSrcweir             pC = " exists ";
464cdf0e10cSrcweir             break;
465cdf0e10cSrcweir         case 0x2205:
466cdf0e10cSrcweir             pC = " emptyset ";
467cdf0e10cSrcweir             break;
468cdf0e10cSrcweir         case 0x2207:
469cdf0e10cSrcweir             pC = " nabla ";
470cdf0e10cSrcweir             break;
471cdf0e10cSrcweir         case 0x2208:
472cdf0e10cSrcweir             pC = " in ";
473cdf0e10cSrcweir             break;
474cdf0e10cSrcweir         case 0x2209:
475cdf0e10cSrcweir             pC = " notin ";
476cdf0e10cSrcweir             break;
477cdf0e10cSrcweir         case 0x220d:
478cdf0e10cSrcweir             pC = " owns ";
479cdf0e10cSrcweir             break;
480cdf0e10cSrcweir         case 0x220f:
481cdf0e10cSrcweir             pC = " prod ";
482cdf0e10cSrcweir             break;
483cdf0e10cSrcweir         case 0x2210:
484cdf0e10cSrcweir             pC = " coprod ";
485cdf0e10cSrcweir             break;
486cdf0e10cSrcweir         case 0x2211:
487cdf0e10cSrcweir             pC = " sum ";
488cdf0e10cSrcweir             break;
489cdf0e10cSrcweir         case 0x2212:
490cdf0e10cSrcweir             pC = " - ";
491cdf0e10cSrcweir             break;
492cdf0e10cSrcweir         case 0x2213:
493cdf0e10cSrcweir             pC = " -+ ";
494cdf0e10cSrcweir             break;
495cdf0e10cSrcweir         case 0x2217:
496cdf0e10cSrcweir             pC = " * ";
497cdf0e10cSrcweir             break;
498cdf0e10cSrcweir         case 0x2218:
499cdf0e10cSrcweir             pC = " circ ";
500cdf0e10cSrcweir             break;
501cdf0e10cSrcweir         case 0x221d:
502cdf0e10cSrcweir             pC = " prop ";
503cdf0e10cSrcweir             break;
504cdf0e10cSrcweir         case 0x221e:
505cdf0e10cSrcweir             pC = " infinity ";
506cdf0e10cSrcweir             break;
507cdf0e10cSrcweir         case 0x2227:
508cdf0e10cSrcweir             pC = " and ";
509cdf0e10cSrcweir             break;
510cdf0e10cSrcweir         case 0x2228:
511cdf0e10cSrcweir             pC = " or ";
512cdf0e10cSrcweir             break;
513cdf0e10cSrcweir         case 0x2229:
514cdf0e10cSrcweir             pC = " intersection ";
515cdf0e10cSrcweir             break;
516cdf0e10cSrcweir         case 0x222a:
517cdf0e10cSrcweir             pC = " union ";
518cdf0e10cSrcweir             break;
519cdf0e10cSrcweir         case 0x222b:
520cdf0e10cSrcweir             pC = " int ";
521cdf0e10cSrcweir             break;
522cdf0e10cSrcweir         case 0x222c:
523cdf0e10cSrcweir             pC = " iint ";
524cdf0e10cSrcweir             break;
525cdf0e10cSrcweir         case 0x222d:
526cdf0e10cSrcweir             pC = " iiint ";
527cdf0e10cSrcweir             break;
528cdf0e10cSrcweir         case 0x222e:
529cdf0e10cSrcweir             pC = " lint ";
530cdf0e10cSrcweir             break;
531cdf0e10cSrcweir         case 0x222f:
532cdf0e10cSrcweir             pC = " llint ";
533cdf0e10cSrcweir             break;
534cdf0e10cSrcweir         case 0x2230:
535cdf0e10cSrcweir             pC = " lllint ";
536cdf0e10cSrcweir             break;
537cdf0e10cSrcweir         case 0x2245:
538cdf0e10cSrcweir             pC = " simeq ";
539cdf0e10cSrcweir             break;
540cdf0e10cSrcweir         case 0x2248:
541cdf0e10cSrcweir             pC = " approx ";
542cdf0e10cSrcweir             break;
543cdf0e10cSrcweir         case 0x2260:
544cdf0e10cSrcweir             pC = " <> ";
545cdf0e10cSrcweir             break;
546cdf0e10cSrcweir         case 0x2261:
547cdf0e10cSrcweir             pC = " equiv ";
548cdf0e10cSrcweir             break;
549cdf0e10cSrcweir         case 0x2264:
550cdf0e10cSrcweir             pC = " <= ";
551cdf0e10cSrcweir             break;
552cdf0e10cSrcweir         case 0x2265:
553cdf0e10cSrcweir             pC = " >= ";
554cdf0e10cSrcweir             break;
555cdf0e10cSrcweir         case 0x2282:
556cdf0e10cSrcweir             pC = " subset ";
557cdf0e10cSrcweir             break;
558cdf0e10cSrcweir         case 0x2283:
559cdf0e10cSrcweir             pC = " supset ";
560cdf0e10cSrcweir             break;
561cdf0e10cSrcweir         case 0x2284:
562cdf0e10cSrcweir             pC = " nsubset ";
563cdf0e10cSrcweir             break;
564cdf0e10cSrcweir         case 0x2285:
565cdf0e10cSrcweir             pC = " nsupset ";
566cdf0e10cSrcweir             break;
567cdf0e10cSrcweir         case 0x2286:
568cdf0e10cSrcweir             pC = " subseteq ";
569cdf0e10cSrcweir             break;
570cdf0e10cSrcweir         case 0x2287:
571cdf0e10cSrcweir             pC = " supseteq ";
572cdf0e10cSrcweir             break;
573cdf0e10cSrcweir         case 0x2288:
574cdf0e10cSrcweir             pC = " nsubseteq ";
575cdf0e10cSrcweir             break;
576cdf0e10cSrcweir         case 0x2289:
577cdf0e10cSrcweir             pC = " nsupseteq ";
578cdf0e10cSrcweir             break;
579cdf0e10cSrcweir         case 0x227a:
580cdf0e10cSrcweir         case 0x227b:
581cdf0e10cSrcweir         case 0x22b2:
582cdf0e10cSrcweir         case 0x22b3:
583cdf0e10cSrcweir             rRet += ' ';
584cdf0e10cSrcweir             rRet.Append(nChar);
585cdf0e10cSrcweir             rRet += ' ';
586cdf0e10cSrcweir             break;
587cdf0e10cSrcweir         case 0x22a5:
588cdf0e10cSrcweir             pC = " ortho ";
589cdf0e10cSrcweir             break;
590cdf0e10cSrcweir         case 0x22c5:
591cdf0e10cSrcweir             pC = " cdot ";
592cdf0e10cSrcweir             break;
593cdf0e10cSrcweir         case 0x22ee:
594cdf0e10cSrcweir             pC = " dotsvert ";
595cdf0e10cSrcweir             break;
596cdf0e10cSrcweir         case 0x22ef:
597cdf0e10cSrcweir             pC = " dotsaxis ";
598cdf0e10cSrcweir             break;
599cdf0e10cSrcweir         case 0x22f0:
600cdf0e10cSrcweir             pC = " dotsup ";
601cdf0e10cSrcweir             break;
602cdf0e10cSrcweir         case 0x22f1:
603cdf0e10cSrcweir             pC = " dotsdown ";
604cdf0e10cSrcweir             break;
605cdf0e10cSrcweir         case 0x2329:
606cdf0e10cSrcweir             pC = " langle ";
607cdf0e10cSrcweir             break;
608cdf0e10cSrcweir         case 0x232a:
609cdf0e10cSrcweir             pC = " rangle ";
610cdf0e10cSrcweir             break;
611cdf0e10cSrcweir         case 0x301a:
612cdf0e10cSrcweir             pC = " ldbracket ";
613cdf0e10cSrcweir             break;
614cdf0e10cSrcweir         case 0x301b:
615cdf0e10cSrcweir             pC = " rdbracket ";
616cdf0e10cSrcweir             break;
617cdf0e10cSrcweir         case 0xe083:
618cdf0e10cSrcweir             rRet.Append('+');
619cdf0e10cSrcweir             bRet=sal_True;
620cdf0e10cSrcweir             break;
621cdf0e10cSrcweir         case '^':
622cdf0e10cSrcweir         case 0xe091:
623cdf0e10cSrcweir             pC = " widehat ";
624cdf0e10cSrcweir             break;
625cdf0e10cSrcweir         case 0xe096:
626cdf0e10cSrcweir             pC = " widetilde ";
627cdf0e10cSrcweir             break;
628cdf0e10cSrcweir         case 0xe098:
629cdf0e10cSrcweir             pC = " widevec ";
630cdf0e10cSrcweir             break;
631cdf0e10cSrcweir         case 0xE421:
632cdf0e10cSrcweir             pC = " geslant ";
633cdf0e10cSrcweir             break;
634cdf0e10cSrcweir         case 0xE425:
635cdf0e10cSrcweir             pC = " leslant ";
636cdf0e10cSrcweir             break;
637cdf0e10cSrcweir         case 0xeb01:    //no space
638cdf0e10cSrcweir         case 0xeb08:    //normal space
639cdf0e10cSrcweir             bRet=sal_True;
640cdf0e10cSrcweir             break;
641cdf0e10cSrcweir         case 0xef04:    //tiny space
642cdf0e10cSrcweir         case 0xef05:    //tiny space
643cdf0e10cSrcweir         case 0xeb02:    //small space
644cdf0e10cSrcweir         case 0xeb04:    //medium space
645cdf0e10cSrcweir             rRet.Append('`');
646cdf0e10cSrcweir             break;
647cdf0e10cSrcweir         case 0xeb05:    //large space
648cdf0e10cSrcweir             rRet.Append('~');
649cdf0e10cSrcweir             break;
650cdf0e10cSrcweir         case 0x3a9:
651cdf0e10cSrcweir             pC = " %OMEGA ";
652cdf0e10cSrcweir             break;
653cdf0e10cSrcweir         default:
654cdf0e10cSrcweir             rRet.Append(nChar);
655cdf0e10cSrcweir             bRet=sal_True;
656cdf0e10cSrcweir             break;
657cdf0e10cSrcweir     }
658cdf0e10cSrcweir     if (pC)
659cdf0e10cSrcweir         rRet.AppendAscii(pC);
660cdf0e10cSrcweir     return bRet;
661cdf0e10cSrcweir }
662cdf0e10cSrcweir 
AppendStyleToText(String & rRet)663cdf0e10cSrcweir void MathTypeFont::AppendStyleToText(String &rRet)
664cdf0e10cSrcweir {
665cdf0e10cSrcweir     const char *pC = NULL;
666cdf0e10cSrcweir     switch (nStyle)
667cdf0e10cSrcweir     {
668cdf0e10cSrcweir         default:
669cdf0e10cSrcweir         case 0:
670cdf0e10cSrcweir             break;
671cdf0e10cSrcweir         case 1:
672cdf0e10cSrcweir             pC = " ital ";
673cdf0e10cSrcweir             break;
674cdf0e10cSrcweir         case 2:
675cdf0e10cSrcweir             pC = " bold ";
676cdf0e10cSrcweir             break;
677cdf0e10cSrcweir         case 3:
678cdf0e10cSrcweir             pC = " bold italic";
679cdf0e10cSrcweir             break;
680cdf0e10cSrcweir     }
681cdf0e10cSrcweir     if (pC)
682cdf0e10cSrcweir         rRet.AppendAscii(pC);
683cdf0e10cSrcweir }
684cdf0e10cSrcweir 
TypeFaceToString(String & rTxt,sal_uInt8 nFace)685cdf0e10cSrcweir void MathType::TypeFaceToString(String &rTxt,sal_uInt8 nFace)
686cdf0e10cSrcweir {
687cdf0e10cSrcweir     MathTypeFont aFont(nFace);
688cdf0e10cSrcweir     MathTypeFontSet::iterator aItr = aUserStyles.find(aFont);
689cdf0e10cSrcweir     if (aItr != aUserStyles.end())
690cdf0e10cSrcweir         aFont.nStyle = aItr->nStyle;
691cdf0e10cSrcweir     aFont.AppendStyleToText(rTxt);
692cdf0e10cSrcweir }
693cdf0e10cSrcweir 
Parse(SotStorage * pStor)694cdf0e10cSrcweir int MathType::Parse(SotStorage *pStor)
695cdf0e10cSrcweir {
696cdf0e10cSrcweir     SvStorageStreamRef xSrc = pStor->OpenSotStream(
697cdf0e10cSrcweir         String::CreateFromAscii("Equation Native"),
698cdf0e10cSrcweir         STREAM_STD_READ | STREAM_NOCREATE);
699cdf0e10cSrcweir     if ( (!xSrc.Is()) || (SVSTREAM_OK != xSrc->GetError()))
700cdf0e10cSrcweir         return 0;
701cdf0e10cSrcweir     pS = &xSrc;
702cdf0e10cSrcweir     pS->SetNumberFormatInt( NUMBERFORMAT_INT_LITTLEENDIAN );
703cdf0e10cSrcweir 
704cdf0e10cSrcweir     EQNOLEFILEHDR aHdr;
705cdf0e10cSrcweir     aHdr.Read(pS);
706cdf0e10cSrcweir     *pS >> nVersion;
707cdf0e10cSrcweir     *pS >> nPlatform;
708cdf0e10cSrcweir     *pS >> nProduct;
709cdf0e10cSrcweir     *pS >> nProdVersion;
710cdf0e10cSrcweir     *pS >> nProdSubVersion;
711cdf0e10cSrcweir 
712cdf0e10cSrcweir     if (nVersion > 3)   // allow only supported versions of MathType to be parsed
713cdf0e10cSrcweir         return 0;
714cdf0e10cSrcweir 
715cdf0e10cSrcweir #ifdef STANDALONE
716cdf0e10cSrcweir     *pOut << "Format Version is " << int(nVersion) << endl;
717cdf0e10cSrcweir     *pOut << "Generating Platform is " << (nPlatform ? "Windows"
718cdf0e10cSrcweir         : "Mac") << endl;
719cdf0e10cSrcweir     *pOut << "Generating Product is " << (nPlatform ? "Equation Editor"
720cdf0e10cSrcweir         : "Equation Editor") << endl;
721cdf0e10cSrcweir     *pOut << "Prod Version is " << int(nProdVersion) << "." <<
722cdf0e10cSrcweir         int(nProdSubVersion) << endl << endl;
723cdf0e10cSrcweir #endif
724cdf0e10cSrcweir 
725cdf0e10cSrcweir     int nRet = HandleRecords();
726cdf0e10cSrcweir     //little crude hack to close ocassionally open expressions
727cdf0e10cSrcweir     //a sophisticated system to determine what expressions are
728cdf0e10cSrcweir     //opened is required, but this is as much work as rewriting
729cdf0e10cSrcweir     //starmaths internals.
730cdf0e10cSrcweir     APPEND(rRet,"{}");
731cdf0e10cSrcweir 
732cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
733cdf0e10cSrcweir #   ifdef CAOLAN
734cdf0e10cSrcweir     //sanity check
735cdf0e10cSrcweir 
736cdf0e10cSrcweir     //sigh, theres no point! MathType (in some bizarre subvarient) pads
737cdf0e10cSrcweir     //the end of the formula with ENDs (0)'s
738cdf0e10cSrcweir     sal_uLong nEnd = pS->Tell();
739cdf0e10cSrcweir     DBG_ASSERT(nEnd == pS->Seek(STREAM_SEEK_TO_END),
740cdf0e10cSrcweir         "Possibly unfully parsed formula");
741cdf0e10cSrcweir #   endif
742cdf0e10cSrcweir #endif
743cdf0e10cSrcweir     return nRet;
744cdf0e10cSrcweir }
745cdf0e10cSrcweir 
lcl_PrependDummyTerm(String & rRet,xub_StrLen & rTextStart)746cdf0e10cSrcweir static void lcl_PrependDummyTerm(String &rRet, xub_StrLen &rTextStart)
747cdf0e10cSrcweir {
748cdf0e10cSrcweir     if ((rRet.GetChar(rTextStart) == '=') &&
749cdf0e10cSrcweir         ((rTextStart == 0) ||
750cdf0e10cSrcweir         (rRet.GetChar(rTextStart-1) == '{'))
751cdf0e10cSrcweir        )
752cdf0e10cSrcweir     {
753cdf0e10cSrcweir         rRet.InsertAscii(" {}",rTextStart);
754cdf0e10cSrcweir         rTextStart+=3;
755cdf0e10cSrcweir     }
756cdf0e10cSrcweir }
757cdf0e10cSrcweir 
lcl_AppendDummyTerm(String & rRet)758cdf0e10cSrcweir static void lcl_AppendDummyTerm(String &rRet)
759cdf0e10cSrcweir {
760cdf0e10cSrcweir     sal_Bool bOk=sal_False;
761cdf0e10cSrcweir     for(int nI=rRet.Len()-1;nI >= 0; nI--)
762cdf0e10cSrcweir     {
763cdf0e10cSrcweir         xub_StrLen nIdx = sal::static_int_cast< xub_StrLen >(nI);
764cdf0e10cSrcweir         sal_Unicode nChar = rRet.GetChar(nIdx);
765cdf0e10cSrcweir         if (nChar == ' ')
766cdf0e10cSrcweir             continue;
767cdf0e10cSrcweir         if (rRet.GetChar(nIdx) != '{')
768cdf0e10cSrcweir             bOk=sal_True;
769cdf0e10cSrcweir         break;
770cdf0e10cSrcweir     }
771cdf0e10cSrcweir     if (!bOk)   //No term, use dummy
772cdf0e10cSrcweir         APPEND(rRet," {}");
773cdf0e10cSrcweir }
774cdf0e10cSrcweir 
HandleNudge()775cdf0e10cSrcweir void MathType::HandleNudge()
776cdf0e10cSrcweir {
777cdf0e10cSrcweir     sal_uInt8 nXNudge;
778cdf0e10cSrcweir     *pS >> nXNudge;
779cdf0e10cSrcweir     sal_uInt8 nYNudge;
780cdf0e10cSrcweir     *pS >> nYNudge;
781cdf0e10cSrcweir     if (nXNudge == 128 && nYNudge == 128)
782cdf0e10cSrcweir     {
783cdf0e10cSrcweir         sal_uInt16 nXLongNudge;
784cdf0e10cSrcweir         sal_uInt16 nYLongNudge;
785cdf0e10cSrcweir         *pS >> nXLongNudge;
786cdf0e10cSrcweir         *pS >> nYLongNudge;
787cdf0e10cSrcweir     }
788cdf0e10cSrcweir }
789cdf0e10cSrcweir /*Fabously complicated as many tokens have to be reordered and generally
790cdf0e10cSrcweir  *moved around from mathtypes paradigm to starmaths.*/
HandleRecords(int nLevel,sal_uInt8 nSelector,sal_uInt8 nVariation,int nMatrixRows,int nMatrixCols)791cdf0e10cSrcweir int MathType::HandleRecords(int nLevel,sal_uInt8 nSelector,
792cdf0e10cSrcweir     sal_uInt8 nVariation, int nMatrixRows,int nMatrixCols)
793cdf0e10cSrcweir {
794cdf0e10cSrcweir     sal_uInt8 nTag,nRecord;
795cdf0e10cSrcweir     sal_uInt8 nTabType,nTabStops;
796cdf0e10cSrcweir     sal_uInt16 nTabOffset;
797cdf0e10cSrcweir     sal_Char nChar8;
798cdf0e10cSrcweir     String sFontName;
799cdf0e10cSrcweir     int i,nRet=1,newline=0;
800cdf0e10cSrcweir     sal_Bool bSilent=sal_False;
801cdf0e10cSrcweir     int nPart=0;
802cdf0e10cSrcweir     String sPush,sMainTerm;
803cdf0e10cSrcweir     int nSetSize=0,nSetAlign=0;
804cdf0e10cSrcweir     int nCurRow=0,nCurCol=0;
805cdf0e10cSrcweir     sal_Bool bOpenString=sal_False;
806cdf0e10cSrcweir     xub_StrLen nTextStart = 0;
807cdf0e10cSrcweir     xub_StrLen nSubSupStartPos = 0;
808cdf0e10cSrcweir     xub_StrLen nLastTemplateBracket=STRING_NOTFOUND;
809cdf0e10cSrcweir 
810cdf0e10cSrcweir     do
811cdf0e10cSrcweir     {
812cdf0e10cSrcweir         *pS >> nTag;
813cdf0e10cSrcweir         nRecord = nTag&0x0F;
814cdf0e10cSrcweir 
815cdf0e10cSrcweir         /*MathType strings can of course include words which
816cdf0e10cSrcweir          *are StarMath keywords, the simplest solution is
817cdf0e10cSrcweir          to escape strings of greater than len 1 with double
818cdf0e10cSrcweir          quotes to avoid scanning the TokenTable for matches
819cdf0e10cSrcweir 
820cdf0e10cSrcweir          Unfortunately it may turn out that the string gets
821cdf0e10cSrcweir          split during the handling of a character emblishment
822cdf0e10cSrcweir          so this special case must be handled in the
823cdf0e10cSrcweir          character handler case 2:
824cdf0e10cSrcweir          */
825cdf0e10cSrcweir         if ((nRecord == CHAR) && (!bIsSilent) && (!bOpenString))
826cdf0e10cSrcweir         {
827cdf0e10cSrcweir             bOpenString=sal_True;
828cdf0e10cSrcweir             nTextStart = rRet.Len();
829cdf0e10cSrcweir         }
830cdf0e10cSrcweir         else if ((nRecord != CHAR) && (bOpenString))
831cdf0e10cSrcweir         {
832cdf0e10cSrcweir             bOpenString=sal_False;
833cdf0e10cSrcweir             if ((rRet.Len() - nTextStart) > 1)
834cdf0e10cSrcweir             {
835cdf0e10cSrcweir                 String aStr;
836cdf0e10cSrcweir                 TypeFaceToString(aStr,nTypeFace);
837cdf0e10cSrcweir                 aStr += '\"';
838cdf0e10cSrcweir                 rRet.Insert(aStr,nTextStart);
839cdf0e10cSrcweir                 rRet += '\"';
840cdf0e10cSrcweir             }
841cdf0e10cSrcweir             else
842cdf0e10cSrcweir             {
843cdf0e10cSrcweir                 if (nRecord == END)
844cdf0e10cSrcweir                 {
845cdf0e10cSrcweir                     sal_Unicode cChar = 0;
846cdf0e10cSrcweir                     xub_StrLen nI = rRet.Len()-1;
847cdf0e10cSrcweir                     while (nI && ((cChar = rRet.GetChar(nI)) == ' '))
848cdf0e10cSrcweir                         --nI;
849cdf0e10cSrcweir                     if ((cChar == '=') || (cChar == '+') || (cChar == '-'))
850cdf0e10cSrcweir                         APPEND(rRet,"{}");
851cdf0e10cSrcweir                 }
852cdf0e10cSrcweir             }
853cdf0e10cSrcweir         }
854cdf0e10cSrcweir 
855cdf0e10cSrcweir         switch(nRecord)
856cdf0e10cSrcweir         {
857cdf0e10cSrcweir             case LINE:
858cdf0e10cSrcweir                 {
859cdf0e10cSrcweir                     if (xfLMOVE(nTag))
860cdf0e10cSrcweir                         HandleNudge();
861cdf0e10cSrcweir                     //if (xfLSPACE(nTag))
862cdf0e10cSrcweir                     //if (xfRULER(nTag))
863cdf0e10cSrcweir 
864cdf0e10cSrcweir                     if (newline>0)
865cdf0e10cSrcweir                         APPEND(rRet,"\nnewline\n");
866cdf0e10cSrcweir                     if (!(xfNULL(nTag)))
867cdf0e10cSrcweir                     {
868cdf0e10cSrcweir                         switch (nSelector)
869cdf0e10cSrcweir                         {
870cdf0e10cSrcweir                         case 0x0:
871cdf0e10cSrcweir                             if (nVariation==0)
872cdf0e10cSrcweir                                 APPEND(rRet," langle ");
873cdf0e10cSrcweir                             else if (nVariation==1)
874cdf0e10cSrcweir                                 APPEND(rRet," \\langle ");
875cdf0e10cSrcweir                             break;
876cdf0e10cSrcweir                         case 0x1:
877cdf0e10cSrcweir                             if (nVariation==0)
878cdf0e10cSrcweir                                 APPEND(rRet," left (");
879cdf0e10cSrcweir                             else if (nVariation==1)
880cdf0e10cSrcweir                                 APPEND(rRet,"\\(");
881cdf0e10cSrcweir                             break;
882cdf0e10cSrcweir                         case 0x2:
883cdf0e10cSrcweir                             if ((nVariation==0) || (nVariation==1))
884cdf0e10cSrcweir                                 APPEND(rRet," left lbrace ");
885cdf0e10cSrcweir                             else
886cdf0e10cSrcweir                                 APPEND(rRet," left none ");
887cdf0e10cSrcweir                             break;
888cdf0e10cSrcweir                         case 0x3:
889cdf0e10cSrcweir                             if (nVariation==0)
890cdf0e10cSrcweir                                 APPEND(rRet," left [");
891cdf0e10cSrcweir                             else if (nVariation==1)
892cdf0e10cSrcweir                                 APPEND(rRet,"\\[");
893cdf0e10cSrcweir                             break;
894cdf0e10cSrcweir                         case 0x8:
895cdf0e10cSrcweir                         case 0xb:
896cdf0e10cSrcweir                             APPEND(rRet," \\[");
897cdf0e10cSrcweir                             break;
898cdf0e10cSrcweir                         case 0x4:
899cdf0e10cSrcweir                             if (nVariation==0)
900cdf0e10cSrcweir                                 APPEND(rRet," lline ");
901cdf0e10cSrcweir                             else if (nVariation==1)
902cdf0e10cSrcweir                                 APPEND(rRet," \\lline ");
903cdf0e10cSrcweir                             break;
904cdf0e10cSrcweir                         case 0x5:
905cdf0e10cSrcweir                             if (nVariation==0)
906cdf0e10cSrcweir                                 APPEND(rRet," ldline ");
907cdf0e10cSrcweir                             else if (nVariation==1)
908cdf0e10cSrcweir                                 APPEND(rRet," \\ldline ");
909cdf0e10cSrcweir                             break;
910cdf0e10cSrcweir                         case 0x6:
911cdf0e10cSrcweir                             if (nVariation == 0 || nVariation == 1)
912cdf0e10cSrcweir                                 APPEND(rRet," left lfloor ");
913cdf0e10cSrcweir                             else if (nVariation==1)
914cdf0e10cSrcweir                                 APPEND(rRet," left none ");
915cdf0e10cSrcweir                             break;
916cdf0e10cSrcweir                         case 0x7:
917cdf0e10cSrcweir                             if (nVariation==0)
918cdf0e10cSrcweir                                 APPEND(rRet," lceil ");
919cdf0e10cSrcweir                             else if (nVariation==1)
920cdf0e10cSrcweir                                 APPEND(rRet," \\lceil ");
921cdf0e10cSrcweir                             break;
922cdf0e10cSrcweir                         case 0x9:
923cdf0e10cSrcweir                         case 0xa:
924cdf0e10cSrcweir                             APPEND(rRet," \\]");
925cdf0e10cSrcweir                             break;
926cdf0e10cSrcweir                         case 0xc:
927cdf0e10cSrcweir                             APPEND(rRet," \\(");
928cdf0e10cSrcweir                             break;
929cdf0e10cSrcweir                         case 0xd:
930cdf0e10cSrcweir                             if (nPart == 0)
931cdf0e10cSrcweir                             {
932cdf0e10cSrcweir                                 if (nVariation == 0)
933cdf0e10cSrcweir                                     APPEND(rRet," sqrt");
934cdf0e10cSrcweir                                 else
935cdf0e10cSrcweir                                 {
936cdf0e10cSrcweir                                     APPEND(rRet," nroot");
937cdf0e10cSrcweir                                     sPush = rRet;
938cdf0e10cSrcweir                                     rRet.Erase();
939cdf0e10cSrcweir                                 }
940cdf0e10cSrcweir                             }
941cdf0e10cSrcweir                             APPEND(rRet," {");
942cdf0e10cSrcweir                             break;
943cdf0e10cSrcweir                         case 0xe:
944cdf0e10cSrcweir                             if (nPart == 0)
945cdf0e10cSrcweir                                 APPEND(rRet," { ");
946cdf0e10cSrcweir 
947cdf0e10cSrcweir 
948cdf0e10cSrcweir                             if (nPart == 1)
949cdf0e10cSrcweir                                 APPEND(rRet," over ");
950cdf0e10cSrcweir                             APPEND(rRet," {");
951cdf0e10cSrcweir                             break;
952cdf0e10cSrcweir                         case 0xf:
953cdf0e10cSrcweir                             nSubSupStartPos = rRet.Len();
954cdf0e10cSrcweir                             if ((nVariation == 0) ||
955cdf0e10cSrcweir                                     ((nVariation == 2) && (nPart==1)))
956cdf0e10cSrcweir                             {
957cdf0e10cSrcweir                                 lcl_AppendDummyTerm(rRet);
958cdf0e10cSrcweir                                 APPEND(rRet," rSup");
959cdf0e10cSrcweir                             }
960cdf0e10cSrcweir                             else if ((nVariation == 1) ||
961cdf0e10cSrcweir                                     ((nVariation == 2) && (nPart==0)))
962cdf0e10cSrcweir                             {
963cdf0e10cSrcweir                                 lcl_AppendDummyTerm(rRet);
964cdf0e10cSrcweir                                 APPEND(rRet," rSub");
965cdf0e10cSrcweir                             }
966cdf0e10cSrcweir                             APPEND(rRet," {");
967cdf0e10cSrcweir                             break;
968cdf0e10cSrcweir                         case 0x10:
969cdf0e10cSrcweir                             if (nVariation == 0)
970cdf0e10cSrcweir                                 APPEND(rRet," {underline ");
971cdf0e10cSrcweir                             else if (nVariation == 1)
972cdf0e10cSrcweir                                 APPEND(rRet," {underline underline ");
973cdf0e10cSrcweir                             APPEND(rRet," {");
974cdf0e10cSrcweir                             break;
975cdf0e10cSrcweir                         case 0x11:
976cdf0e10cSrcweir                             if (nVariation == 0)
977cdf0e10cSrcweir                                 APPEND(rRet," {overline ");
978cdf0e10cSrcweir                             else if (nVariation == 1)
979cdf0e10cSrcweir                                 APPEND(rRet," {overline overline ");
980cdf0e10cSrcweir                             APPEND(rRet," {");
981cdf0e10cSrcweir                             break;
982cdf0e10cSrcweir                         case 0x12:
983cdf0e10cSrcweir                             if (nPart == 0)
984cdf0e10cSrcweir                             {
985cdf0e10cSrcweir                                 if (nVariation == 0)
986cdf0e10cSrcweir                                     APPEND(rRet," widevec ");//left arrow above
987cdf0e10cSrcweir                                 else if (nVariation == 1)
988cdf0e10cSrcweir                                     APPEND(rRet," widevec ");//left arrow below
989cdf0e10cSrcweir                                 APPEND(rRet," {");
990cdf0e10cSrcweir                             }
991cdf0e10cSrcweir                             break;
992cdf0e10cSrcweir                         case 0x13:
993cdf0e10cSrcweir                             if (nPart == 0)
994cdf0e10cSrcweir                             {
995cdf0e10cSrcweir                                 if (nVariation == 0)
996cdf0e10cSrcweir                                     APPEND(rRet," widevec ");//right arrow above
997cdf0e10cSrcweir                                 else if (nVariation == 1)
998cdf0e10cSrcweir                                     APPEND(rRet," widevec ");//right arrow below
999cdf0e10cSrcweir                                 APPEND(rRet," {");
1000cdf0e10cSrcweir                             }
1001cdf0e10cSrcweir                             break;
1002cdf0e10cSrcweir                         case 0x14:
1003cdf0e10cSrcweir                             if (nPart == 0)
1004cdf0e10cSrcweir                             {
1005cdf0e10cSrcweir                                 if (nVariation == 0)
1006cdf0e10cSrcweir                                     APPEND(rRet," widevec ");//double arrow above
1007cdf0e10cSrcweir                                 else if (nVariation == 1)
1008cdf0e10cSrcweir                                     APPEND(rRet," widevec ");//double arrow below
1009cdf0e10cSrcweir                                 APPEND(rRet," {");
1010cdf0e10cSrcweir                             }
1011cdf0e10cSrcweir                             break;
1012cdf0e10cSrcweir                         case 0x15:
1013cdf0e10cSrcweir                             if (nPart == 0)
1014cdf0e10cSrcweir                             {
1015cdf0e10cSrcweir                                 if ((nVariation == 3) || (nVariation == 4))
1016cdf0e10cSrcweir                                     APPEND(rRet," lInt");
1017cdf0e10cSrcweir                                 else
1018cdf0e10cSrcweir                                     APPEND(rRet," Int");
1019cdf0e10cSrcweir                                 if ( (nVariation != 0) && (nVariation != 3))
1020cdf0e10cSrcweir                                 {
1021cdf0e10cSrcweir                                     sPush = rRet;
1022cdf0e10cSrcweir                                     rRet.Erase();
1023cdf0e10cSrcweir                                 }
1024cdf0e10cSrcweir                             }
1025cdf0e10cSrcweir                             if (((nVariation == 1) ||
1026cdf0e10cSrcweir                                     (nVariation == 4)) && (nPart==1))
1027cdf0e10cSrcweir                                 APPEND(rRet," rSub");
1028cdf0e10cSrcweir                             else if ((nVariation == 2) && (nPart==2))
1029cdf0e10cSrcweir                                 APPEND(rRet," rSup");
1030cdf0e10cSrcweir                             else if ((nVariation == 2) && (nPart==1))
1031cdf0e10cSrcweir                                 APPEND(rRet," rSub");
1032cdf0e10cSrcweir                             APPEND(rRet," {");
1033cdf0e10cSrcweir                             break;
1034cdf0e10cSrcweir                         case 0x16:
1035cdf0e10cSrcweir                             if (nPart == 0)
1036cdf0e10cSrcweir                             {
1037cdf0e10cSrcweir                                 if ((nVariation == 2) || (nVariation == 3))
1038cdf0e10cSrcweir                                     APPEND(rRet," llInt");
1039cdf0e10cSrcweir                                 else
1040cdf0e10cSrcweir                                     APPEND(rRet," iInt");
1041cdf0e10cSrcweir                                 if ( (nVariation != 0) && (nVariation != 2))
1042cdf0e10cSrcweir                                 {
1043cdf0e10cSrcweir                                     sPush = rRet;
1044cdf0e10cSrcweir                                     rRet.Erase();
1045cdf0e10cSrcweir                                 }
1046cdf0e10cSrcweir                             }
1047cdf0e10cSrcweir                             if (((nVariation == 1) ||
1048cdf0e10cSrcweir                                     (nVariation == 3)) && (nPart==1))
1049cdf0e10cSrcweir                                 APPEND(rRet," rSub");
1050cdf0e10cSrcweir                             APPEND(rRet," {");
1051cdf0e10cSrcweir                             break;
1052cdf0e10cSrcweir                         case 0x17:
1053cdf0e10cSrcweir                             if (nPart == 0)
1054cdf0e10cSrcweir                             {
1055cdf0e10cSrcweir                                 if ((nVariation == 2) || (nVariation == 3))
1056cdf0e10cSrcweir                                     APPEND(rRet," lllInt");
1057cdf0e10cSrcweir                                 else
1058cdf0e10cSrcweir                                     APPEND(rRet," iiInt");
1059cdf0e10cSrcweir                                 if ( (nVariation != 0) && (nVariation != 2))
1060cdf0e10cSrcweir                                 {
1061cdf0e10cSrcweir                                     sPush = rRet;
1062cdf0e10cSrcweir                                     rRet.Erase();
1063cdf0e10cSrcweir                                 }
1064cdf0e10cSrcweir                             }
1065cdf0e10cSrcweir                             if (((nVariation == 1) ||
1066cdf0e10cSrcweir                                     (nVariation == 3)) && (nPart==1))
1067cdf0e10cSrcweir                                 APPEND(rRet," rSub");
1068cdf0e10cSrcweir                             APPEND(rRet," {");
1069cdf0e10cSrcweir                             break;
1070cdf0e10cSrcweir                         case 0x18:
1071cdf0e10cSrcweir                             if (nPart == 0)
1072cdf0e10cSrcweir                             {
1073cdf0e10cSrcweir                                 if (nVariation == 2)
1074cdf0e10cSrcweir                                     APPEND(rRet," lInt");
1075cdf0e10cSrcweir                                 else
1076cdf0e10cSrcweir                                     APPEND(rRet," Int");
1077cdf0e10cSrcweir                                 sPush = rRet;
1078cdf0e10cSrcweir                                 rRet.Erase();
1079cdf0e10cSrcweir                             }
1080cdf0e10cSrcweir                             if (((nVariation == 1) ||
1081cdf0e10cSrcweir                                     (nVariation == 2)) && (nPart==1))
1082cdf0e10cSrcweir                                 APPEND(rRet," cSub");
1083cdf0e10cSrcweir                             else if ((nVariation == 0) && (nPart==2))
1084cdf0e10cSrcweir                                 APPEND(rRet," cSup");
1085cdf0e10cSrcweir                             else if ((nVariation == 0) && (nPart==1))
1086cdf0e10cSrcweir                                 APPEND(rRet," cSub");
1087cdf0e10cSrcweir                             APPEND(rRet," {");
1088cdf0e10cSrcweir                             break;
1089cdf0e10cSrcweir                         case 0x19:
1090cdf0e10cSrcweir                             if (nPart == 0)
1091cdf0e10cSrcweir                             {
1092cdf0e10cSrcweir                                 if (nVariation == 0)
1093cdf0e10cSrcweir                                     APPEND(rRet," llInt");
1094cdf0e10cSrcweir                                 else
1095cdf0e10cSrcweir                                     APPEND(rRet," iInt");
1096cdf0e10cSrcweir                                 sPush = rRet;
1097cdf0e10cSrcweir                                 rRet.Erase();
1098cdf0e10cSrcweir                             }
1099cdf0e10cSrcweir                             if (nPart==1)
1100cdf0e10cSrcweir                                 APPEND(rRet," cSub");
1101cdf0e10cSrcweir                             APPEND(rRet," {");
1102cdf0e10cSrcweir                             break;
1103cdf0e10cSrcweir                         case 0x1a:
1104cdf0e10cSrcweir                             if (nPart == 0)
1105cdf0e10cSrcweir                             {
1106cdf0e10cSrcweir                                 if (nVariation == 0)
1107cdf0e10cSrcweir                                     APPEND(rRet," lllInt");
1108cdf0e10cSrcweir                                 else
1109cdf0e10cSrcweir                                     APPEND(rRet," iiInt");
1110cdf0e10cSrcweir                                 sPush = rRet;
1111cdf0e10cSrcweir                                 rRet.Erase();
1112cdf0e10cSrcweir                             }
1113cdf0e10cSrcweir                             if (nPart==1)
1114cdf0e10cSrcweir                                 APPEND(rRet," cSub");
1115cdf0e10cSrcweir                             APPEND(rRet," {");
1116cdf0e10cSrcweir                             break;
1117cdf0e10cSrcweir                         case 0x1b:
1118cdf0e10cSrcweir                         case 0x1c:
1119cdf0e10cSrcweir                             APPEND(rRet," {");
1120cdf0e10cSrcweir                             break;
1121cdf0e10cSrcweir                         case 0x1d:
1122cdf0e10cSrcweir                             if (nPart == 0)
1123cdf0e10cSrcweir                             {
1124cdf0e10cSrcweir                                 APPEND(rRet," Sum");
1125cdf0e10cSrcweir                                 if (nVariation != 2)
1126cdf0e10cSrcweir                                 {
1127cdf0e10cSrcweir                                     sPush = rRet;
1128cdf0e10cSrcweir                                     rRet.Erase();
1129cdf0e10cSrcweir                                 }
1130cdf0e10cSrcweir                             }
1131cdf0e10cSrcweir                             if ((nVariation == 0) && (nPart==1))
1132cdf0e10cSrcweir                                 APPEND(rRet," cSub");
1133cdf0e10cSrcweir                             else if ((nVariation == 1) && (nPart==2))
1134cdf0e10cSrcweir                                 APPEND(rRet," cSup");
1135cdf0e10cSrcweir                             else if ((nVariation == 1) && (nPart==1))
1136cdf0e10cSrcweir                                 APPEND(rRet," cSub");
1137cdf0e10cSrcweir                             APPEND(rRet," {");
1138cdf0e10cSrcweir                             break;
1139cdf0e10cSrcweir                         case 0x1e:
1140cdf0e10cSrcweir                             if (nPart == 0)
1141cdf0e10cSrcweir                             {
1142cdf0e10cSrcweir                                 APPEND(rRet," Sum");
1143cdf0e10cSrcweir                                 sPush = rRet;
1144cdf0e10cSrcweir                                 rRet.Erase();
1145cdf0e10cSrcweir                             }
1146cdf0e10cSrcweir                             if ((nVariation == 0) && (nPart==1))
1147cdf0e10cSrcweir                                 APPEND(rRet," rSub");
1148cdf0e10cSrcweir                             else if ((nVariation == 1) && (nPart==2))
1149cdf0e10cSrcweir                                 APPEND(rRet," rSup");
1150cdf0e10cSrcweir                             else if ((nVariation == 1) && (nPart==1))
1151cdf0e10cSrcweir                                 APPEND(rRet," rSub");
1152cdf0e10cSrcweir                             APPEND(rRet," {");
1153cdf0e10cSrcweir                             break;
1154cdf0e10cSrcweir                         case 0x1f:
1155cdf0e10cSrcweir                             if (nPart == 0)
1156cdf0e10cSrcweir                             {
1157cdf0e10cSrcweir                                 APPEND(rRet," Prod");
1158cdf0e10cSrcweir                                 if (nVariation != 2)
1159cdf0e10cSrcweir                                 {
1160cdf0e10cSrcweir                                     sPush = rRet;
1161cdf0e10cSrcweir                                     rRet.Erase();
1162cdf0e10cSrcweir                                 }
1163cdf0e10cSrcweir                             }
1164cdf0e10cSrcweir                             if ((nVariation == 0) && (nPart==1))
1165cdf0e10cSrcweir                                 APPEND(rRet," cSub");
1166cdf0e10cSrcweir                             else if ((nVariation == 1) && (nPart==2))
1167cdf0e10cSrcweir                                 APPEND(rRet," cSup");
1168cdf0e10cSrcweir                             else if ((nVariation == 1) && (nPart==1))
1169cdf0e10cSrcweir                                 APPEND(rRet," cSub");
1170cdf0e10cSrcweir                             APPEND(rRet," {");
1171cdf0e10cSrcweir                             break;
1172cdf0e10cSrcweir                         case 0x20:
1173cdf0e10cSrcweir                             if (nPart == 0)
1174cdf0e10cSrcweir                             {
1175cdf0e10cSrcweir                                 APPEND(rRet," Prod");
1176cdf0e10cSrcweir                                 sPush = rRet;
1177cdf0e10cSrcweir                                 rRet.Erase();
1178cdf0e10cSrcweir                             }
1179cdf0e10cSrcweir                             if ((nVariation == 0) && (nPart==1))
1180cdf0e10cSrcweir                                 APPEND(rRet," rSub");
1181cdf0e10cSrcweir                             else if ((nVariation == 1) && (nPart==2))
1182cdf0e10cSrcweir                                 APPEND(rRet," rSup");
1183cdf0e10cSrcweir                             else if ((nVariation == 1) && (nPart==1))
1184cdf0e10cSrcweir                                 APPEND(rRet," rSub");
1185cdf0e10cSrcweir                             APPEND(rRet," {");
1186cdf0e10cSrcweir                             break;
1187cdf0e10cSrcweir                         case 0x21:
1188cdf0e10cSrcweir                             if (nPart == 0)
1189cdf0e10cSrcweir                             {
1190cdf0e10cSrcweir                                 APPEND(rRet," coProd");
1191cdf0e10cSrcweir                                 if (nVariation != 2)
1192cdf0e10cSrcweir                                 {
1193cdf0e10cSrcweir                                     sPush = rRet;
1194cdf0e10cSrcweir                                     rRet.Erase();
1195cdf0e10cSrcweir                                 }
1196cdf0e10cSrcweir                             }
1197cdf0e10cSrcweir                             if ((nVariation == 0) && (nPart==1))
1198cdf0e10cSrcweir                                 APPEND(rRet," cSub");
1199cdf0e10cSrcweir                             else if ((nVariation == 1) && (nPart==2))
1200cdf0e10cSrcweir                                 APPEND(rRet," cSup");
1201cdf0e10cSrcweir                             else if ((nVariation == 1) && (nPart==1))
1202cdf0e10cSrcweir                                 APPEND(rRet," cSub");
1203cdf0e10cSrcweir                             APPEND(rRet," {");
1204cdf0e10cSrcweir                             break;
1205cdf0e10cSrcweir                         case 0x22:
1206cdf0e10cSrcweir                             if (nPart == 0)
1207cdf0e10cSrcweir                             {
1208cdf0e10cSrcweir                                 APPEND(rRet," coProd");
1209cdf0e10cSrcweir                                 sPush = rRet;
1210cdf0e10cSrcweir                                 rRet.Erase();
1211cdf0e10cSrcweir                             }
1212cdf0e10cSrcweir                             if ((nVariation == 0) && (nPart==1))
1213cdf0e10cSrcweir                                 APPEND(rRet," rSub");
1214cdf0e10cSrcweir                             else if ((nVariation == 1) && (nPart==2))
1215cdf0e10cSrcweir                                 APPEND(rRet," rSup");
1216cdf0e10cSrcweir                             else if ((nVariation == 1) && (nPart==1))
1217cdf0e10cSrcweir                                 APPEND(rRet," rSub");
1218cdf0e10cSrcweir                             APPEND(rRet," {");
1219cdf0e10cSrcweir                             break;
1220cdf0e10cSrcweir                         case 0x23:
1221cdf0e10cSrcweir                             if (nPart == 0)
1222cdf0e10cSrcweir                             {
1223cdf0e10cSrcweir                                 APPEND(rRet," union"); //union
1224cdf0e10cSrcweir                                 if (nVariation != 2)
1225cdf0e10cSrcweir                                 {
1226cdf0e10cSrcweir                                     sPush = rRet;
1227cdf0e10cSrcweir                                     rRet.Erase();
1228cdf0e10cSrcweir                                 }
1229cdf0e10cSrcweir                             }
1230cdf0e10cSrcweir                             if ((nVariation == 0) && (nPart==1))
1231cdf0e10cSrcweir                                 APPEND(rRet," cSub");
1232cdf0e10cSrcweir                             else if ((nVariation == 1) && (nPart==2))
1233cdf0e10cSrcweir                                 APPEND(rRet," cSup");
1234cdf0e10cSrcweir                             else if ((nVariation == 1) && (nPart==1))
1235cdf0e10cSrcweir                                 APPEND(rRet," cSub");
1236cdf0e10cSrcweir                             APPEND(rRet," {");
1237cdf0e10cSrcweir                             break;
1238cdf0e10cSrcweir                         case 0x24:
1239cdf0e10cSrcweir                             if (nPart == 0)
1240cdf0e10cSrcweir                             {
1241cdf0e10cSrcweir                                 APPEND(rRet," union"); //union
1242cdf0e10cSrcweir                                 sPush = rRet;
1243cdf0e10cSrcweir                                 rRet.Erase();
1244cdf0e10cSrcweir                             }
1245cdf0e10cSrcweir                             if ((nVariation == 0) && (nPart==1))
1246cdf0e10cSrcweir                                 APPEND(rRet," rSub");
1247cdf0e10cSrcweir                             else if ((nVariation == 1) && (nPart==2))
1248cdf0e10cSrcweir                                 APPEND(rRet," rSup");
1249cdf0e10cSrcweir                             else if ((nVariation == 1) && (nPart==1))
1250cdf0e10cSrcweir                                 APPEND(rRet," rSub");
1251cdf0e10cSrcweir                             APPEND(rRet," {");
1252cdf0e10cSrcweir                             break;
1253cdf0e10cSrcweir                         case 0x25:
1254cdf0e10cSrcweir                             if (nPart == 0)
1255cdf0e10cSrcweir                             {
1256cdf0e10cSrcweir                                 APPEND(rRet," intersect"); //intersect
1257cdf0e10cSrcweir                                 if (nVariation != 2)
1258cdf0e10cSrcweir                                 {
1259cdf0e10cSrcweir                                     sPush = rRet;
1260cdf0e10cSrcweir                                     rRet.Erase();
1261cdf0e10cSrcweir                                 }
1262cdf0e10cSrcweir                             }
1263cdf0e10cSrcweir                             if ((nVariation == 0) && (nPart==1))
1264cdf0e10cSrcweir                                 APPEND(rRet," cSub");
1265cdf0e10cSrcweir                             else if ((nVariation == 1) && (nPart==2))
1266cdf0e10cSrcweir                                 APPEND(rRet," cSup");
1267cdf0e10cSrcweir                             else if ((nVariation == 1) && (nPart==1))
1268cdf0e10cSrcweir                                 APPEND(rRet," cSub");
1269cdf0e10cSrcweir                             APPEND(rRet," {");
1270cdf0e10cSrcweir                             break;
1271cdf0e10cSrcweir                         case 0x26:
1272cdf0e10cSrcweir                             if (nPart == 0)
1273cdf0e10cSrcweir                             {
1274cdf0e10cSrcweir                                 APPEND(rRet," intersect"); //intersect
1275cdf0e10cSrcweir                                 sPush = rRet;
1276cdf0e10cSrcweir                                 rRet.Erase();
1277cdf0e10cSrcweir                             }
1278cdf0e10cSrcweir                             if ((nVariation == 0) && (nPart==1))
1279cdf0e10cSrcweir                                 APPEND(rRet," rSub");
1280cdf0e10cSrcweir                             else if ((nVariation == 1) && (nPart==2))
1281cdf0e10cSrcweir                                 APPEND(rRet," rSup");
1282cdf0e10cSrcweir                             else if ((nVariation == 1) && (nPart==1))
1283cdf0e10cSrcweir                                 APPEND(rRet," rSub");
1284cdf0e10cSrcweir                             APPEND(rRet," {");
1285cdf0e10cSrcweir                             break;
1286cdf0e10cSrcweir                         case 0x27:
1287cdf0e10cSrcweir                             if ((nVariation == 0) && (nPart==1))
1288cdf0e10cSrcweir                                 APPEND(rRet," cSup");
1289cdf0e10cSrcweir                             else if ((nVariation == 1) && (nPart==1))
1290cdf0e10cSrcweir                                 APPEND(rRet," cSub");
1291cdf0e10cSrcweir                             else if ((nVariation == 2) && (nPart==1))
1292cdf0e10cSrcweir                                 APPEND(rRet," cSub");
1293cdf0e10cSrcweir                             else if ((nVariation == 2) && (nPart==2))
1294cdf0e10cSrcweir                                 APPEND(rRet," cSup");
1295cdf0e10cSrcweir                             APPEND(rRet," {");
1296cdf0e10cSrcweir                             break;
1297cdf0e10cSrcweir                         case 0x28:
1298cdf0e10cSrcweir                             if (nVariation == 0)
1299cdf0e10cSrcweir                             {
1300cdf0e10cSrcweir                                 if (nPart == 0)
1301cdf0e10cSrcweir                                 {
1302cdf0e10cSrcweir                                     sPush = rRet;
1303cdf0e10cSrcweir                                     rRet.Erase();
1304cdf0e10cSrcweir                                 }
1305cdf0e10cSrcweir                             }
1306cdf0e10cSrcweir                             APPEND(rRet," {");
1307cdf0e10cSrcweir                             if (nVariation == 0)
1308cdf0e10cSrcweir                             {
1309cdf0e10cSrcweir                                 if (nPart == 1)
1310cdf0e10cSrcweir                                     APPEND(rRet,"alignr ");
1311cdf0e10cSrcweir                             }
1312cdf0e10cSrcweir                             if (nPart == 0)
1313cdf0e10cSrcweir                                 APPEND(rRet,"\\lline ");
1314cdf0e10cSrcweir                             if (nVariation == 1)
1315cdf0e10cSrcweir                                 APPEND(rRet,"overline ");
1316cdf0e10cSrcweir                             break;
1317cdf0e10cSrcweir                         case 0x29:
1318cdf0e10cSrcweir                             APPEND(rRet," {");
1319cdf0e10cSrcweir                             break;
1320cdf0e10cSrcweir                         case 0x2a:
1321cdf0e10cSrcweir                             if (nPart == 0)
1322cdf0e10cSrcweir                             {
1323cdf0e10cSrcweir                                 sPush = rRet;
1324cdf0e10cSrcweir                                 rRet.Erase();
1325cdf0e10cSrcweir                             }
1326cdf0e10cSrcweir                             if ((nVariation == 0) && (nPart==0))
1327cdf0e10cSrcweir                                 APPEND(rRet," rSup");
1328cdf0e10cSrcweir                             else if ((nVariation == 2) && (nPart==1))
1329cdf0e10cSrcweir                                 APPEND(rRet," rSup");
1330cdf0e10cSrcweir                             else if ((nVariation == 1) && (nPart==0))
1331cdf0e10cSrcweir                                 APPEND(rRet," rSub");
1332cdf0e10cSrcweir                             else if ((nVariation == 2) && (nPart==0))
1333cdf0e10cSrcweir                                 APPEND(rRet," rSub");
1334cdf0e10cSrcweir                             APPEND(rRet," {");
1335cdf0e10cSrcweir                             break;
1336cdf0e10cSrcweir                         case 0x2b:
1337cdf0e10cSrcweir                             if (nPart == 0)
1338cdf0e10cSrcweir                             {
1339cdf0e10cSrcweir                                 sPush = rRet;
1340cdf0e10cSrcweir                                 rRet.Erase();
1341cdf0e10cSrcweir                             }
1342cdf0e10cSrcweir                             if ((nVariation == 0) && (nPart==0))
1343cdf0e10cSrcweir                                 APPEND(rRet," cSup");
1344cdf0e10cSrcweir                             else if ((nVariation == 2) && (nPart==1))
1345cdf0e10cSrcweir                                 APPEND(rRet," cSup");
1346cdf0e10cSrcweir                             else if ((nVariation == 1) && (nPart==0))
1347cdf0e10cSrcweir                                 APPEND(rRet," cSub");
1348cdf0e10cSrcweir                             else if ((nVariation == 2) && (nPart==0))
1349cdf0e10cSrcweir                                 APPEND(rRet," cSub");
1350cdf0e10cSrcweir                             APPEND(rRet," {");
1351cdf0e10cSrcweir                             break;
1352cdf0e10cSrcweir                         case 0x2c:
1353cdf0e10cSrcweir                             if (nPart == 0)
1354cdf0e10cSrcweir                                 APPEND(rRet,"\"\"");
1355cdf0e10cSrcweir                             if ((nVariation == 0)
1356cdf0e10cSrcweir                                     || ((nVariation == 2) && (nPart==1)))
1357cdf0e10cSrcweir                                 APPEND(rRet," lSup");
1358cdf0e10cSrcweir                             else if ((nVariation == 1)
1359cdf0e10cSrcweir                                     || ((nVariation == 2) && (nPart==0)))
1360cdf0e10cSrcweir                                 APPEND(rRet," lSub");
1361cdf0e10cSrcweir                             APPEND(rRet," {");
1362cdf0e10cSrcweir                             break;
1363cdf0e10cSrcweir                         case 0x2d:
1364cdf0e10cSrcweir                             if (nVariation==0)
1365cdf0e10cSrcweir                             {
1366cdf0e10cSrcweir                                 if (nPart == 0)
1367cdf0e10cSrcweir                                     APPEND(rRet," langle ");
1368cdf0e10cSrcweir                             }
1369cdf0e10cSrcweir                             else if (nVariation==1)
1370cdf0e10cSrcweir                             {
1371cdf0e10cSrcweir                                 APPEND(rRet," \\langle ");
1372cdf0e10cSrcweir                                 newline--;
1373cdf0e10cSrcweir                             }
1374cdf0e10cSrcweir                             else if (nVariation==2)
1375cdf0e10cSrcweir                             {
1376cdf0e10cSrcweir                                 APPEND(rRet," \\lline ");
1377cdf0e10cSrcweir                                 newline--;
1378cdf0e10cSrcweir                             }
1379cdf0e10cSrcweir                             break;
1380cdf0e10cSrcweir                         case 0x2e:
1381cdf0e10cSrcweir                             if (nVariation == 0)
1382cdf0e10cSrcweir                                 APPEND(rRet," widevec ");//left below
1383cdf0e10cSrcweir                             else if (nVariation == 1)
1384cdf0e10cSrcweir                                 APPEND(rRet," widevec ");//right below
1385cdf0e10cSrcweir                             else if (nVariation == 2)
1386cdf0e10cSrcweir                                 APPEND(rRet," widevec ");//double headed below
1387cdf0e10cSrcweir                             APPEND(rRet," {");
1388cdf0e10cSrcweir                             break;
1389cdf0e10cSrcweir                         case 0x2f:
1390cdf0e10cSrcweir                             if (nVariation == 0)
1391cdf0e10cSrcweir                                 APPEND(rRet," widevec ");//left above
1392cdf0e10cSrcweir                             else if (nVariation == 1)
1393cdf0e10cSrcweir                                 APPEND(rRet," widevec ");//right above
1394cdf0e10cSrcweir                             else if (nVariation == 2)
1395cdf0e10cSrcweir                                 APPEND(rRet," widevec ");//double headed above
1396cdf0e10cSrcweir                             APPEND(rRet," {");
1397cdf0e10cSrcweir                             break;
1398cdf0e10cSrcweir                         default:
1399cdf0e10cSrcweir                             break;
1400cdf0e10cSrcweir                         }
1401cdf0e10cSrcweir                         sal_Int16 nOldCurSize=nCurSize;
1402cdf0e10cSrcweir                         xub_StrLen nSizeStartPos = rRet.Len();
1403cdf0e10cSrcweir                         HandleSize(nLSize,nDSize,nSetSize);
1404cdf0e10cSrcweir                         nRet = HandleRecords(nLevel+1);
1405cdf0e10cSrcweir                         while (nSetSize)
1406cdf0e10cSrcweir                         {
1407cdf0e10cSrcweir                             sal_Bool bOk=sal_False;
1408cdf0e10cSrcweir                             xub_StrLen nI = rRet.SearchBackward('{');
1409cdf0e10cSrcweir                             if (nI != STRING_NOTFOUND)
1410cdf0e10cSrcweir                             {
1411cdf0e10cSrcweir                                 for(nI=nI+1;nI<rRet.Len();nI++)
1412cdf0e10cSrcweir                                     if (rRet.GetChar(nI) != ' ')
1413cdf0e10cSrcweir                                     {
1414cdf0e10cSrcweir                                         bOk=sal_True;
1415cdf0e10cSrcweir                                         break;
1416cdf0e10cSrcweir                                     }
1417cdf0e10cSrcweir                             }
1418cdf0e10cSrcweir                             else
1419cdf0e10cSrcweir                                 bOk=sal_True;
1420cdf0e10cSrcweir 
1421cdf0e10cSrcweir                             if (bOk)
1422cdf0e10cSrcweir                                 APPEND(rRet,"} ");
1423cdf0e10cSrcweir                             else
1424cdf0e10cSrcweir                                 rRet.Erase(nSizeStartPos);
1425cdf0e10cSrcweir                             nSetSize--;
1426cdf0e10cSrcweir                             nCurSize=nOldCurSize;
1427cdf0e10cSrcweir                         }
1428cdf0e10cSrcweir 
1429cdf0e10cSrcweir 
1430cdf0e10cSrcweir                         HandleMatrixSeperator(nMatrixRows,nMatrixCols,
1431cdf0e10cSrcweir                             nCurCol,nCurRow);
1432cdf0e10cSrcweir 
1433cdf0e10cSrcweir                         switch (nSelector)
1434cdf0e10cSrcweir                         {
1435cdf0e10cSrcweir                         case 0x0:
1436cdf0e10cSrcweir                             if (nVariation==0)
1437cdf0e10cSrcweir                                 APPEND(rRet," rangle ");
1438cdf0e10cSrcweir                             else if (nVariation==2)
1439cdf0e10cSrcweir                                 APPEND(rRet," \\rangle ");
1440cdf0e10cSrcweir                             break;
1441cdf0e10cSrcweir                         case 0x1:
1442cdf0e10cSrcweir                             if (nVariation==0)
1443cdf0e10cSrcweir                                 APPEND(rRet," right )");
1444cdf0e10cSrcweir                             else if (nVariation==2)
1445cdf0e10cSrcweir                                 APPEND(rRet,"\\)");
1446cdf0e10cSrcweir                             break;
1447cdf0e10cSrcweir                         case 0x2:
1448cdf0e10cSrcweir                             if ((nVariation==0) || (nVariation==2))
1449cdf0e10cSrcweir                                 APPEND(rRet," right rbrace ");
1450cdf0e10cSrcweir                             else
1451cdf0e10cSrcweir                                 APPEND(rRet," right none ");
1452cdf0e10cSrcweir                             break;
1453cdf0e10cSrcweir                         case 0x3:
1454cdf0e10cSrcweir                             if (nVariation==0)
1455cdf0e10cSrcweir                                 APPEND(rRet," right ]");
1456cdf0e10cSrcweir                             else if (nVariation==2)
1457cdf0e10cSrcweir                                 APPEND(rRet,"\\]");
1458cdf0e10cSrcweir                             break;
1459cdf0e10cSrcweir                         case 0x4:
1460cdf0e10cSrcweir                             if (nVariation==0)
1461cdf0e10cSrcweir                                 APPEND(rRet," rline ");
1462cdf0e10cSrcweir                             else if (nVariation==2)
1463cdf0e10cSrcweir                                 APPEND(rRet," \\rline ");
1464cdf0e10cSrcweir                             break;
1465cdf0e10cSrcweir                         case 0x5:
1466cdf0e10cSrcweir                             if (nVariation==0)
1467cdf0e10cSrcweir                                 APPEND(rRet," rdline ");
1468cdf0e10cSrcweir                             else if (nVariation==2)
1469cdf0e10cSrcweir                                 APPEND(rRet," \\rdline ");
1470cdf0e10cSrcweir                             break;
1471cdf0e10cSrcweir                         case 0x6:
1472cdf0e10cSrcweir                             if (nVariation == 0 || nVariation == 2)
1473cdf0e10cSrcweir                                 APPEND(rRet," right rfloor ");
1474cdf0e10cSrcweir                             else if (nVariation==2)
1475cdf0e10cSrcweir                                 APPEND(rRet," right none ");
1476cdf0e10cSrcweir                             break;
1477cdf0e10cSrcweir                         case 0x7:
1478cdf0e10cSrcweir                             if (nVariation==0)
1479cdf0e10cSrcweir                                 APPEND(rRet," rceil ");
1480cdf0e10cSrcweir                             else if (nVariation==2)
1481cdf0e10cSrcweir                                 APPEND(rRet," \\rceil ");
1482cdf0e10cSrcweir                             break;
1483cdf0e10cSrcweir                         case 0x8:
1484cdf0e10cSrcweir                         case 0xa:
1485cdf0e10cSrcweir                             APPEND(rRet,"\\[");
1486cdf0e10cSrcweir                             break;
1487cdf0e10cSrcweir                         case 0x9:
1488cdf0e10cSrcweir                         case 0xc:
1489cdf0e10cSrcweir                             APPEND(rRet,"\\]");
1490cdf0e10cSrcweir                             break;
1491cdf0e10cSrcweir                         case 0xd:
1492cdf0e10cSrcweir                             APPEND(rRet,"} ");
1493cdf0e10cSrcweir                             if (nVariation == 1)
1494cdf0e10cSrcweir                             {
1495cdf0e10cSrcweir                                 if (nPart == 0)
1496cdf0e10cSrcweir                                 {
1497cdf0e10cSrcweir                                     newline--;
1498cdf0e10cSrcweir                                     sMainTerm = rRet;
1499cdf0e10cSrcweir                                     rRet.Erase();
1500cdf0e10cSrcweir                                 }
1501cdf0e10cSrcweir                                 else
1502cdf0e10cSrcweir                                 {
1503cdf0e10cSrcweir                                     sPush += rRet;
1504cdf0e10cSrcweir                                     rRet = sPush;
1505cdf0e10cSrcweir                                     rRet += sMainTerm;
1506cdf0e10cSrcweir                                 }
1507cdf0e10cSrcweir                             }
1508cdf0e10cSrcweir                             else
1509cdf0e10cSrcweir                             {
1510cdf0e10cSrcweir                                 if (nPart == 0)
1511cdf0e10cSrcweir                                     newline--;
1512cdf0e10cSrcweir                             }
1513cdf0e10cSrcweir                             nPart++;
1514cdf0e10cSrcweir                             break;
1515cdf0e10cSrcweir                         case 0xb:
1516cdf0e10cSrcweir                             APPEND(rRet,"\\)");
1517cdf0e10cSrcweir                             break;
1518cdf0e10cSrcweir                         case 0xe:
1519cdf0e10cSrcweir                             APPEND(rRet,"} ");
1520cdf0e10cSrcweir                             if (nPart == 0)
1521cdf0e10cSrcweir                                 newline--;
1522cdf0e10cSrcweir                             else
1523cdf0e10cSrcweir                                 APPEND(rRet,"} ");
1524cdf0e10cSrcweir                             nPart++;
1525cdf0e10cSrcweir                             break;
1526cdf0e10cSrcweir                         case 0xf:
1527cdf0e10cSrcweir                             {
1528cdf0e10cSrcweir                             if ((nPart == 0) &&
1529cdf0e10cSrcweir                                     ((nVariation == 2) || (nVariation == 1)))
1530cdf0e10cSrcweir                                 newline--;
1531cdf0e10cSrcweir 
1532cdf0e10cSrcweir                             sal_Bool bOk=sal_False;
1533cdf0e10cSrcweir                             xub_StrLen nI = rRet.SearchBackward('{');
1534cdf0e10cSrcweir                             if (nI != STRING_NOTFOUND)
1535cdf0e10cSrcweir                             {
1536cdf0e10cSrcweir                                 for(nI=nI+1;nI<rRet.Len();nI++)
1537cdf0e10cSrcweir                                     if (rRet.GetChar(nI) != ' ')
1538cdf0e10cSrcweir                                     {
1539cdf0e10cSrcweir                                         bOk=sal_True;
1540cdf0e10cSrcweir                                         break;
1541cdf0e10cSrcweir                                     }
1542cdf0e10cSrcweir                             }
1543cdf0e10cSrcweir                             else
1544cdf0e10cSrcweir                                 bOk=sal_True;
1545cdf0e10cSrcweir 
1546cdf0e10cSrcweir                             if (bOk)
1547cdf0e10cSrcweir                                 APPEND(rRet,"} ");
1548cdf0e10cSrcweir                             else
1549cdf0e10cSrcweir                                 rRet.Erase(nSubSupStartPos);
1550cdf0e10cSrcweir                             nPart++;
1551cdf0e10cSrcweir                             }
1552cdf0e10cSrcweir                             break;
1553cdf0e10cSrcweir                         case 0x2c:
1554cdf0e10cSrcweir                             if ((nPart == 0) &&
1555cdf0e10cSrcweir                                     ((nVariation == 2) || (nVariation == 1)))
1556cdf0e10cSrcweir                                 newline--;
1557cdf0e10cSrcweir                             APPEND(rRet,"} ");
1558cdf0e10cSrcweir                             nPart++;
1559cdf0e10cSrcweir                             break;
1560cdf0e10cSrcweir                         case 0x2e:
1561cdf0e10cSrcweir                         case 0x2f:
1562cdf0e10cSrcweir                             APPEND(rRet,"} ");
1563cdf0e10cSrcweir                             break;
1564cdf0e10cSrcweir                         case 0x10:
1565cdf0e10cSrcweir                         case 0x11:
1566cdf0e10cSrcweir                             APPEND(rRet,"}} ");
1567cdf0e10cSrcweir                             break;
1568cdf0e10cSrcweir                         case 0x12:
1569cdf0e10cSrcweir                         case 0x13:
1570cdf0e10cSrcweir                         case 0x14:
1571cdf0e10cSrcweir                             if (nPart == 0)
1572cdf0e10cSrcweir                             {
1573cdf0e10cSrcweir                                 newline--;
1574cdf0e10cSrcweir                                 APPEND(rRet,"} ");
1575cdf0e10cSrcweir                             }
1576cdf0e10cSrcweir                             nPart++;
1577cdf0e10cSrcweir                             break;
1578cdf0e10cSrcweir                         case 0x1b:
1579cdf0e10cSrcweir                             APPEND(rRet,"} ");
1580cdf0e10cSrcweir                             if (nPart == 0)
1581cdf0e10cSrcweir                             {
1582cdf0e10cSrcweir                                 newline--;
1583cdf0e10cSrcweir                                 APPEND(rRet,"overbrace");
1584cdf0e10cSrcweir                             }
1585cdf0e10cSrcweir                             nPart++;
1586cdf0e10cSrcweir                             break;
1587cdf0e10cSrcweir                         case 0x1c:
1588cdf0e10cSrcweir                             APPEND(rRet,"} ");
1589cdf0e10cSrcweir                             if (nPart == 0)
1590cdf0e10cSrcweir                             {
1591cdf0e10cSrcweir                                 newline--;
1592cdf0e10cSrcweir                                 APPEND(rRet,"underbrace");
1593cdf0e10cSrcweir                             }
1594cdf0e10cSrcweir                             nPart++;
1595cdf0e10cSrcweir                             break;
1596cdf0e10cSrcweir                         case 0x27:
1597cdf0e10cSrcweir                             if (nPart==0)
1598cdf0e10cSrcweir                                 newline--;
1599cdf0e10cSrcweir                             else if ((nPart==1) &&
1600cdf0e10cSrcweir                                     ((nVariation == 2) || (nVariation == 1)))
1601cdf0e10cSrcweir                                 newline--;
1602cdf0e10cSrcweir                             APPEND(rRet,"} ");
1603cdf0e10cSrcweir                             nPart++;
1604cdf0e10cSrcweir                             break;
1605cdf0e10cSrcweir                         case 0x28:
1606cdf0e10cSrcweir                             APPEND(rRet,"} ");
1607cdf0e10cSrcweir                             if (nVariation == 0)
1608cdf0e10cSrcweir                             {
1609cdf0e10cSrcweir                                 if (nPart == 0)
1610cdf0e10cSrcweir                                 {
1611cdf0e10cSrcweir                                     sMainTerm = rRet;
1612cdf0e10cSrcweir                                     rRet.Erase();
1613cdf0e10cSrcweir                                 }
1614cdf0e10cSrcweir                                 else
1615cdf0e10cSrcweir                                 {
1616cdf0e10cSrcweir                                     sPush += rRet;
1617cdf0e10cSrcweir                                     rRet = sPush;
1618cdf0e10cSrcweir                                     APPEND(rRet," over ");
1619cdf0e10cSrcweir                                     rRet += sMainTerm;
1620cdf0e10cSrcweir                                 }
1621cdf0e10cSrcweir                             }
1622cdf0e10cSrcweir                             if (nPart == 0)
1623cdf0e10cSrcweir                                 newline--;
1624cdf0e10cSrcweir                             nPart++;
1625cdf0e10cSrcweir                             break;
1626cdf0e10cSrcweir                         case 0x29:
1627cdf0e10cSrcweir                             APPEND(rRet,"} ");
1628cdf0e10cSrcweir                             if (nPart == 0)
1629cdf0e10cSrcweir                             {
1630cdf0e10cSrcweir                                 newline--;
1631cdf0e10cSrcweir                                 switch (nVariation)
1632cdf0e10cSrcweir                                 {
1633cdf0e10cSrcweir                                 case 1:
1634cdf0e10cSrcweir                                     APPEND(rRet,"slash");
1635cdf0e10cSrcweir                                     break;
1636cdf0e10cSrcweir                                 default:
1637cdf0e10cSrcweir                                     APPEND(rRet,"wideslash");
1638cdf0e10cSrcweir                                     break;
1639cdf0e10cSrcweir                                 }
1640cdf0e10cSrcweir                             }
1641cdf0e10cSrcweir                             nPart++;
1642cdf0e10cSrcweir                             break;
1643cdf0e10cSrcweir                         case 0x1d:
1644cdf0e10cSrcweir                         case 0x1e:
1645cdf0e10cSrcweir                         case 0x1f:
1646cdf0e10cSrcweir                         case 0x20:
1647cdf0e10cSrcweir                         case 0x21:
1648cdf0e10cSrcweir                         case 0x22:
1649cdf0e10cSrcweir                         case 0x23:
1650cdf0e10cSrcweir                         case 0x24:
1651cdf0e10cSrcweir                         case 0x25:
1652cdf0e10cSrcweir                         case 0x26:
1653cdf0e10cSrcweir                             APPEND(rRet,"} ");
1654cdf0e10cSrcweir                             if (nPart == 0)
1655cdf0e10cSrcweir                             {
1656cdf0e10cSrcweir                                 if (nVariation != 2)
1657cdf0e10cSrcweir                                 {
1658cdf0e10cSrcweir                                     sMainTerm = rRet;
1659cdf0e10cSrcweir                                     rRet.Erase();
1660cdf0e10cSrcweir                                 }
1661cdf0e10cSrcweir                                 newline--;
1662cdf0e10cSrcweir                             }
1663cdf0e10cSrcweir                             else if ((nPart == 1) && (nVariation == 0))
1664cdf0e10cSrcweir                             {
1665cdf0e10cSrcweir                                 sPush += rRet;
1666cdf0e10cSrcweir                                 rRet = sPush;
1667cdf0e10cSrcweir                                 rRet += sMainTerm;
1668cdf0e10cSrcweir                                 newline--;
1669cdf0e10cSrcweir                             }
1670cdf0e10cSrcweir                             else if ((nPart == 1) && (nVariation == 1))
1671cdf0e10cSrcweir                                 newline--;
1672cdf0e10cSrcweir                             else if ((nPart == 2) && (nVariation == 1))
1673cdf0e10cSrcweir                             {
1674cdf0e10cSrcweir                                 sPush += rRet;
1675cdf0e10cSrcweir                                 rRet = sPush;
1676cdf0e10cSrcweir                                 rRet += sMainTerm;
1677cdf0e10cSrcweir                                 newline--;
1678cdf0e10cSrcweir                             }
1679cdf0e10cSrcweir                             nPart++;
1680cdf0e10cSrcweir                             break;
1681cdf0e10cSrcweir                         case 0x15:
1682cdf0e10cSrcweir                             APPEND(rRet,"} ");
1683cdf0e10cSrcweir                             if (nPart == 0)
1684cdf0e10cSrcweir                             {
1685cdf0e10cSrcweir                                 if ((nVariation != 0) && (nVariation != 3))
1686cdf0e10cSrcweir                                 {
1687cdf0e10cSrcweir                                     sMainTerm = rRet;
1688cdf0e10cSrcweir                                     rRet.Erase();
1689cdf0e10cSrcweir                                 }
1690cdf0e10cSrcweir                                 newline--;
1691cdf0e10cSrcweir                             }
1692cdf0e10cSrcweir                             else if ((nPart == 1) &&
1693cdf0e10cSrcweir                                     ((nVariation == 1) || (nVariation==4)))
1694cdf0e10cSrcweir                             {
1695cdf0e10cSrcweir                                 sPush += rRet;
1696cdf0e10cSrcweir                                 rRet = sPush;
1697cdf0e10cSrcweir                                 rRet += sMainTerm;
1698cdf0e10cSrcweir                                 newline--;
1699cdf0e10cSrcweir                             }
1700cdf0e10cSrcweir                             else if ((nPart == 1) && (nVariation == 2))
1701cdf0e10cSrcweir                                 newline--;
1702cdf0e10cSrcweir                             else if ((nPart == 2) && (nVariation == 2))
1703cdf0e10cSrcweir                             {
1704cdf0e10cSrcweir                                 sPush += rRet;
1705cdf0e10cSrcweir                                 rRet = sPush;
1706cdf0e10cSrcweir                                 rRet += sMainTerm;
1707cdf0e10cSrcweir                                 newline--;
1708cdf0e10cSrcweir                             }
1709cdf0e10cSrcweir                             nPart++;
1710cdf0e10cSrcweir                             break;
1711cdf0e10cSrcweir                         case 0x16:
1712cdf0e10cSrcweir                         case 0x17:
1713cdf0e10cSrcweir                             APPEND(rRet,"} ");
1714cdf0e10cSrcweir                             if (nPart == 0)
1715cdf0e10cSrcweir                             {
1716cdf0e10cSrcweir                                 if ((nVariation != 0) && (nVariation != 2))
1717cdf0e10cSrcweir                                 {
1718cdf0e10cSrcweir                                     sMainTerm = rRet;
1719cdf0e10cSrcweir                                     rRet.Erase();
1720cdf0e10cSrcweir                                 }
1721cdf0e10cSrcweir                                 newline--;
1722cdf0e10cSrcweir                             }
1723cdf0e10cSrcweir                             else if ((nPart == 1) &&
1724cdf0e10cSrcweir                                     ((nVariation == 1) || (nVariation==3)))
1725cdf0e10cSrcweir                             {
1726cdf0e10cSrcweir                                 sPush += rRet;
1727cdf0e10cSrcweir                                 rRet = sPush;
1728cdf0e10cSrcweir                                 rRet += sMainTerm;
1729cdf0e10cSrcweir                                 newline--;
1730cdf0e10cSrcweir                             }
1731cdf0e10cSrcweir                             nPart++;
1732cdf0e10cSrcweir                             break;
1733cdf0e10cSrcweir                         case 0x18:
1734cdf0e10cSrcweir                             APPEND(rRet,"} ");
1735cdf0e10cSrcweir                             if (nPart == 0)
1736cdf0e10cSrcweir                             {
1737cdf0e10cSrcweir                                 sMainTerm = rRet;
1738cdf0e10cSrcweir                                 rRet.Erase();
1739cdf0e10cSrcweir                                 newline--;
1740cdf0e10cSrcweir                             }
1741cdf0e10cSrcweir                             else if ((nPart == 1) &&
1742cdf0e10cSrcweir                                     ((nVariation == 1) || (nVariation==2)))
1743cdf0e10cSrcweir                             {
1744cdf0e10cSrcweir                                 sPush += rRet;
1745cdf0e10cSrcweir                                 rRet = sPush;
1746cdf0e10cSrcweir                                 rRet += sMainTerm;
1747cdf0e10cSrcweir                                 newline--;
1748cdf0e10cSrcweir                             }
1749cdf0e10cSrcweir                             else if ((nPart == 1) && (nVariation == 0))
1750cdf0e10cSrcweir                                 newline--;
1751cdf0e10cSrcweir                             else if ((nPart == 2) && (nVariation == 0))
1752cdf0e10cSrcweir                             {
1753cdf0e10cSrcweir                                 sPush += rRet;
1754cdf0e10cSrcweir                                 rRet = sPush;
1755cdf0e10cSrcweir                                 rRet += sMainTerm;
1756cdf0e10cSrcweir                                 newline--;
1757cdf0e10cSrcweir                             }
1758cdf0e10cSrcweir                             nPart++;
1759cdf0e10cSrcweir                             break;
1760cdf0e10cSrcweir                         case 0x19:
1761cdf0e10cSrcweir                         case 0x1a:
1762cdf0e10cSrcweir                             APPEND(rRet,"} ");
1763cdf0e10cSrcweir                             if (nPart == 0)
1764cdf0e10cSrcweir                             {
1765cdf0e10cSrcweir                                 sMainTerm = rRet;
1766cdf0e10cSrcweir                                 rRet.Erase();
1767cdf0e10cSrcweir                                 newline--;
1768cdf0e10cSrcweir                             }
1769cdf0e10cSrcweir                             else if (nPart == 1)
1770cdf0e10cSrcweir                             {
1771cdf0e10cSrcweir                                 sPush += rRet;
1772cdf0e10cSrcweir                                 rRet = sPush;
1773cdf0e10cSrcweir                                 rRet += sMainTerm;
1774cdf0e10cSrcweir                                 newline--;
1775cdf0e10cSrcweir                             }
1776cdf0e10cSrcweir                             nPart++;
1777cdf0e10cSrcweir                             break;
1778cdf0e10cSrcweir                         case 0x2a:
1779cdf0e10cSrcweir                         case 0x2b:
1780cdf0e10cSrcweir                             APPEND(rRet,"} ");
1781cdf0e10cSrcweir 
1782cdf0e10cSrcweir                             if ((nPart == 0) &&
1783cdf0e10cSrcweir                                     ((nVariation == 0) || (nVariation == 1)))
1784cdf0e10cSrcweir                             {
1785cdf0e10cSrcweir                                 sMainTerm = rRet;
1786cdf0e10cSrcweir                                 rRet.Erase();
1787cdf0e10cSrcweir                                 newline--;
1788cdf0e10cSrcweir                             }
1789cdf0e10cSrcweir                             else if ((nPart == 0) && (nVariation == 2))
1790cdf0e10cSrcweir                                 newline--;
1791cdf0e10cSrcweir                             else if ((nPart == 1) && (nVariation == 2))
1792cdf0e10cSrcweir                             {
1793cdf0e10cSrcweir                                 sMainTerm = rRet;
1794cdf0e10cSrcweir                                 rRet.Erase();
1795cdf0e10cSrcweir                                 newline--;
1796cdf0e10cSrcweir                             }
1797cdf0e10cSrcweir                             else if ((nPart == 2) || ((((nPart == 1) &&
1798cdf0e10cSrcweir                                     (nVariation == 0)) || (nVariation == 1))))
1799cdf0e10cSrcweir                             {
1800cdf0e10cSrcweir                                 sPush+=rRet;
1801cdf0e10cSrcweir                                 rRet = sPush;
1802cdf0e10cSrcweir                                 rRet += sMainTerm;
1803cdf0e10cSrcweir                             }
1804cdf0e10cSrcweir                             nPart++;
1805cdf0e10cSrcweir                             break;
1806cdf0e10cSrcweir                         case 0x2d:
1807cdf0e10cSrcweir                             if (nVariation==0)
1808cdf0e10cSrcweir                             {
1809cdf0e10cSrcweir                                 if (nPart == 0)
1810cdf0e10cSrcweir                                 {
1811cdf0e10cSrcweir                                     newline--; //there is another term to arrive
1812cdf0e10cSrcweir                                     APPEND(rRet," mline ");
1813cdf0e10cSrcweir                                 }
1814cdf0e10cSrcweir                                 else
1815cdf0e10cSrcweir                                     APPEND(rRet," rangle ");
1816cdf0e10cSrcweir                             }
1817cdf0e10cSrcweir                             else if (nVariation==1)
1818cdf0e10cSrcweir                                 APPEND(rRet," \\lline ");
1819cdf0e10cSrcweir                             else if (nVariation==2)
1820cdf0e10cSrcweir                                 APPEND(rRet," \\rangle ");
1821cdf0e10cSrcweir                             nPart++;
1822cdf0e10cSrcweir                             break;
1823cdf0e10cSrcweir                         default:
1824cdf0e10cSrcweir                             break;
1825cdf0e10cSrcweir                         }
1826cdf0e10cSrcweir                         bSilent = sal_True; //Skip the optional brackets and/or
1827cdf0e10cSrcweir                                         //symbols that follow some of these
1828cdf0e10cSrcweir                                         //records. Foo Data.
1829cdf0e10cSrcweir 
1830cdf0e10cSrcweir                         /*In matrices and piles we cannot seperate equation
1831cdf0e10cSrcweir                          *lines with the newline keyword*/
1832cdf0e10cSrcweir                         if (nMatrixCols==0)
1833cdf0e10cSrcweir                             newline++;
1834cdf0e10cSrcweir                     }
1835cdf0e10cSrcweir                 }
1836cdf0e10cSrcweir                 break;
1837cdf0e10cSrcweir             case CHAR:
1838cdf0e10cSrcweir                 if (xfLMOVE(nTag))
1839cdf0e10cSrcweir                     HandleNudge();
1840cdf0e10cSrcweir                 nRet = HandleChar(nTextStart,nSetSize,nLevel,nTag,nSelector,
1841cdf0e10cSrcweir                     nVariation,bSilent);
1842cdf0e10cSrcweir                 break;
1843cdf0e10cSrcweir             case TMPL:
1844cdf0e10cSrcweir                 if (xfLMOVE(nTag))
1845cdf0e10cSrcweir                     HandleNudge();
1846cdf0e10cSrcweir                 nRet = HandleTemplate(nLevel,nSelector,nVariation,
1847cdf0e10cSrcweir                     nLastTemplateBracket);
1848cdf0e10cSrcweir                 break;
1849cdf0e10cSrcweir             case PILE:
1850cdf0e10cSrcweir                 if (xfLMOVE(nTag))
1851cdf0e10cSrcweir                     HandleNudge();
1852cdf0e10cSrcweir                 nRet = HandlePile(nSetAlign,nLevel,nSelector,nVariation);
1853cdf0e10cSrcweir                 HandleMatrixSeperator(nMatrixRows,nMatrixCols,nCurCol,nCurRow);
1854cdf0e10cSrcweir                 break;
1855cdf0e10cSrcweir             case MATRIX:
1856cdf0e10cSrcweir                 if (xfLMOVE(nTag))
1857cdf0e10cSrcweir                     HandleNudge();
1858cdf0e10cSrcweir                 nRet = HandleMatrix(nLevel,nSelector,nVariation);
1859cdf0e10cSrcweir                 HandleMatrixSeperator(nMatrixRows,nMatrixCols,nCurCol,nCurRow);
1860cdf0e10cSrcweir                 break;
1861cdf0e10cSrcweir             case EMBEL:
1862cdf0e10cSrcweir                 if (xfLMOVE(nTag))
1863cdf0e10cSrcweir                     HandleNudge();
1864cdf0e10cSrcweir                 HandleEmblishments();
1865cdf0e10cSrcweir                 break;
1866cdf0e10cSrcweir             case RULER:
1867cdf0e10cSrcweir                 *pS >> nTabStops;
1868cdf0e10cSrcweir                 for (i=0;i<nTabStops;i++)
1869cdf0e10cSrcweir                 {
1870cdf0e10cSrcweir                     *pS >> nTabType;
1871cdf0e10cSrcweir                     *pS >> nTabOffset;
1872cdf0e10cSrcweir                 }
1873cdf0e10cSrcweir                 DBG_ASSERT(sal_False,"Not seen in the wild Equation Ruler Field");
1874cdf0e10cSrcweir                 break;
1875cdf0e10cSrcweir             case FONT:
1876cdf0e10cSrcweir                 {
1877cdf0e10cSrcweir                     MathTypeFont aFont;
1878cdf0e10cSrcweir                     *pS >> aFont.nTface;
1879cdf0e10cSrcweir                     /*
1880cdf0e10cSrcweir                     The typeface number is the negative (which makes it
1881cdf0e10cSrcweir                     positive) of the typeface value (unbiased) that appears in
1882cdf0e10cSrcweir                     CHAR records that might follow a given FONT record
1883cdf0e10cSrcweir                     */
1884cdf0e10cSrcweir                     aFont.nTface = 128-aFont.nTface;
1885cdf0e10cSrcweir                     *pS >> aFont.nStyle;
1886cdf0e10cSrcweir                     aUserStyles.insert(aFont);
1887cdf0e10cSrcweir                     sFontName.Erase();
1888cdf0e10cSrcweir                     do
1889cdf0e10cSrcweir                     {
1890cdf0e10cSrcweir                         *pS >> nChar8;
1891cdf0e10cSrcweir                         sFontName.Append(ByteString::ConvertToUnicode(
1892cdf0e10cSrcweir                             nChar8,RTL_TEXTENCODING_MS_1252));
1893cdf0e10cSrcweir                     }
1894cdf0e10cSrcweir                     while(nChar8);
1895cdf0e10cSrcweir                 }
1896cdf0e10cSrcweir                 break;
1897cdf0e10cSrcweir             case SIZE:
1898cdf0e10cSrcweir                 HandleSetSize();
1899cdf0e10cSrcweir                 break;
1900cdf0e10cSrcweir             case 10:
1901cdf0e10cSrcweir             case 11:
1902cdf0e10cSrcweir             case 12:
1903cdf0e10cSrcweir             case 13:
1904cdf0e10cSrcweir             case 14:
1905cdf0e10cSrcweir                 nLSize=nRecord-10;
1906cdf0e10cSrcweir                 break;
1907cdf0e10cSrcweir             case END:
1908cdf0e10cSrcweir             default:
1909cdf0e10cSrcweir                 break;
1910cdf0e10cSrcweir         }
1911cdf0e10cSrcweir     }
1912cdf0e10cSrcweir     while (nRecord != END && !pS->IsEof());
1913cdf0e10cSrcweir     while (nSetSize)
1914cdf0e10cSrcweir     {
1915cdf0e10cSrcweir         rRet += '}';
1916cdf0e10cSrcweir         nSetSize--;
1917cdf0e10cSrcweir     }
1918cdf0e10cSrcweir     return nRet;
1919cdf0e10cSrcweir }
1920cdf0e10cSrcweir 
1921cdf0e10cSrcweir /*Simply determine if we are at the end of a record or the end of a line,
1922cdf0e10cSrcweir  *with fiddley logic to see if we are in a matrix or a pile or neither
1923cdf0e10cSrcweir 
1924cdf0e10cSrcweir  Note we cannot tell until after the event that this is the last entry
1925cdf0e10cSrcweir  of a pile, so we must strip the last seperator of a pile after this
1926cdf0e10cSrcweir  is detected in the PILE handler
1927cdf0e10cSrcweir  */
HandleMatrixSeperator(int nMatrixRows,int nMatrixCols,int & rCurCol,int & rCurRow)1928cdf0e10cSrcweir void MathType::HandleMatrixSeperator(int nMatrixRows,int nMatrixCols,
1929cdf0e10cSrcweir     int &rCurCol,int &rCurRow)
1930cdf0e10cSrcweir {
1931cdf0e10cSrcweir     if (nMatrixRows!=0)
1932cdf0e10cSrcweir     {
1933cdf0e10cSrcweir         if (rCurCol == nMatrixCols-1)
1934cdf0e10cSrcweir         {
1935cdf0e10cSrcweir             if (rCurRow != nMatrixRows-1)
1936cdf0e10cSrcweir                 APPEND(rRet," {} ##\n");
1937cdf0e10cSrcweir             if (nMatrixRows!=-1)
1938cdf0e10cSrcweir             {
1939cdf0e10cSrcweir                 rCurCol=0;
1940cdf0e10cSrcweir                 rCurRow++;
1941cdf0e10cSrcweir             }
1942cdf0e10cSrcweir         }
1943cdf0e10cSrcweir         else
1944cdf0e10cSrcweir         {
1945cdf0e10cSrcweir             APPEND(rRet," {} # ");
1946cdf0e10cSrcweir             if (nMatrixRows!=-1)
1947cdf0e10cSrcweir                 rCurCol++;
1948cdf0e10cSrcweir             else
1949cdf0e10cSrcweir                 rRet += '\n';
1950cdf0e10cSrcweir         }
1951cdf0e10cSrcweir     }
1952cdf0e10cSrcweir }
1953cdf0e10cSrcweir 
1954cdf0e10cSrcweir /* set the alignment of the following term, but starmath currently
1955cdf0e10cSrcweir  * cannot handle vertical alignment */
HandleAlign(sal_uInt8 nHorAlign,sal_uInt8,int & rSetAlign)1956cdf0e10cSrcweir void MathType::HandleAlign(sal_uInt8 nHorAlign, sal_uInt8 /*nVAlign*/, int &rSetAlign)
1957cdf0e10cSrcweir {
1958cdf0e10cSrcweir     switch(nHorAlign)
1959cdf0e10cSrcweir     {
1960cdf0e10cSrcweir     case 1:
1961cdf0e10cSrcweir     default:
1962cdf0e10cSrcweir         APPEND(rRet,"alignl {");
1963cdf0e10cSrcweir         break;
1964cdf0e10cSrcweir     case 2:
1965cdf0e10cSrcweir         APPEND(rRet,"alignc {");
1966cdf0e10cSrcweir         break;
1967cdf0e10cSrcweir     case 3:
1968cdf0e10cSrcweir         APPEND(rRet,"alignr {");
1969cdf0e10cSrcweir         break;
1970cdf0e10cSrcweir     }
1971cdf0e10cSrcweir #if 0
1972cdf0e10cSrcweir     switch(nVAlign)
1973cdf0e10cSrcweir     {
1974cdf0e10cSrcweir     }
1975cdf0e10cSrcweir     rSetAlign+=2;
1976cdf0e10cSrcweir #endif
1977cdf0e10cSrcweir     rSetAlign++;
1978cdf0e10cSrcweir }
1979cdf0e10cSrcweir 
1980cdf0e10cSrcweir /* set size of text, complexity due to overuse of signedness as a flag
1981cdf0e10cSrcweir  * indicator by mathtype file format*/
HandleSize(sal_Int16 nLstSize,sal_Int16 nDefSize,int & rSetSize)1982cdf0e10cSrcweir sal_Bool MathType::HandleSize(sal_Int16 nLstSize,sal_Int16 nDefSize, int &rSetSize)
1983cdf0e10cSrcweir {
1984cdf0e10cSrcweir     sal_Bool bRet=sal_False;
1985cdf0e10cSrcweir     if (nLstSize < 0)
1986cdf0e10cSrcweir     {
1987cdf0e10cSrcweir         if ((-nLstSize/32 != nDefaultSize) && (-nLstSize/32 != nCurSize))
1988cdf0e10cSrcweir         {
1989cdf0e10cSrcweir             if (rSetSize)
1990cdf0e10cSrcweir             {
1991cdf0e10cSrcweir                 rSetSize--;
1992cdf0e10cSrcweir                 rRet += '}';
1993cdf0e10cSrcweir                 bRet=sal_True;
1994cdf0e10cSrcweir             }
1995cdf0e10cSrcweir             if (-nLstSize/32 != nLastSize)
1996cdf0e10cSrcweir             {
1997cdf0e10cSrcweir                 nLastSize = nCurSize;
1998cdf0e10cSrcweir                 APPEND(rRet," size ");
1999cdf0e10cSrcweir                 rRet += String::CreateFromInt32(-nLstSize/32);
2000cdf0e10cSrcweir                 rRet += '{';
2001cdf0e10cSrcweir                 bRet=sal_True;
2002cdf0e10cSrcweir                 rSetSize++;
2003cdf0e10cSrcweir             }
2004cdf0e10cSrcweir             nCurSize = -nLstSize/32;
2005cdf0e10cSrcweir         }
2006cdf0e10cSrcweir     }
2007cdf0e10cSrcweir     else
2008cdf0e10cSrcweir     {
2009cdf0e10cSrcweir         /*sizetable should theoreticaly be filled with the default sizes
2010cdf0e10cSrcweir          *of the various font groupings matching starmaths equivalents
2011cdf0e10cSrcweir          in aTypeFaces, and a test would be done to see if the new font
2012cdf0e10cSrcweir          size would be the same as what starmath would have chosen for
2013cdf0e10cSrcweir          itself anyway in which case the size setting could be ignored*/
2014cdf0e10cSrcweir         nLstSize = aSizeTable[nLstSize];
2015cdf0e10cSrcweir         nLstSize = nLstSize + nDefSize;
2016cdf0e10cSrcweir         //if (nLstSize != nDefaultSize)
2017cdf0e10cSrcweir         if (nLstSize != nCurSize)
2018cdf0e10cSrcweir         {
2019cdf0e10cSrcweir             if (rSetSize)
2020cdf0e10cSrcweir             {
2021cdf0e10cSrcweir                 rSetSize--;
2022cdf0e10cSrcweir                 rRet += '}';
2023cdf0e10cSrcweir                 bRet=sal_True;
2024cdf0e10cSrcweir             }
2025cdf0e10cSrcweir             if (nLstSize != nLastSize)
2026cdf0e10cSrcweir             {
2027cdf0e10cSrcweir                 nLastSize = nCurSize;
2028cdf0e10cSrcweir                 APPEND(rRet," size ");
2029cdf0e10cSrcweir                 rRet += String::CreateFromInt32(nLstSize);
2030cdf0e10cSrcweir                 rRet += '{';
2031cdf0e10cSrcweir                 bRet=sal_True;
2032cdf0e10cSrcweir                 rSetSize++;
2033cdf0e10cSrcweir             }
2034cdf0e10cSrcweir             nCurSize = nLstSize;
2035cdf0e10cSrcweir         }
2036cdf0e10cSrcweir     }
2037cdf0e10cSrcweir     return bRet;
2038cdf0e10cSrcweir }
2039cdf0e10cSrcweir 
ConvertFromStarMath(SfxMedium & rMedium)2040cdf0e10cSrcweir int MathType::ConvertFromStarMath( SfxMedium& rMedium )
2041cdf0e10cSrcweir {
2042cdf0e10cSrcweir     if (!pTree)
2043cdf0e10cSrcweir         return 0;
2044cdf0e10cSrcweir 
2045cdf0e10cSrcweir     SvStream *pStream = rMedium.GetOutStream();
2046cdf0e10cSrcweir     if ( pStream )
2047cdf0e10cSrcweir     {
2048cdf0e10cSrcweir         SvStorageRef pStor = new SotStorage( pStream, sal_False );
2049cdf0e10cSrcweir 
2050cdf0e10cSrcweir         SvGlobalName aGName(0x0002ce02L, 0x0000, 0x0000,0xc0,0x00,
2051cdf0e10cSrcweir             0x00,0x00,0x00,0x00,0x00,0x46 );
2052cdf0e10cSrcweir         pStor->SetClass( aGName, 0, C2S("Microsoft Equation 3.0"));
2053cdf0e10cSrcweir 
2054cdf0e10cSrcweir         static sal_uInt8 __READONLY_DATA aCompObj[] = {
2055cdf0e10cSrcweir             0x01, 0x00, 0xFE, 0xFF, 0x03, 0x0A, 0x00, 0x00,
2056cdf0e10cSrcweir             0xFF, 0xFF, 0xFF, 0xFF, 0x02, 0xCE, 0x02, 0x00,
2057cdf0e10cSrcweir             0x00, 0x00, 0x00, 0x00, 0xC0, 0x00, 0x00, 0x00,
2058cdf0e10cSrcweir             0x00, 0x00, 0x00, 0x46, 0x17, 0x00, 0x00, 0x00,
2059cdf0e10cSrcweir             0x4D, 0x69, 0x63, 0x72, 0x6F, 0x73, 0x6F, 0x66,
2060cdf0e10cSrcweir             0x74, 0x20, 0x45, 0x71, 0x75, 0x61, 0x74, 0x69,
2061cdf0e10cSrcweir             0x6F, 0x6E, 0x20, 0x33, 0x2E, 0x30, 0x00, 0x0C,
2062cdf0e10cSrcweir             0x00, 0x00, 0x00, 0x44, 0x53, 0x20, 0x45, 0x71,
2063cdf0e10cSrcweir             0x75, 0x61, 0x74, 0x69, 0x6F, 0x6E, 0x00, 0x0B,
2064cdf0e10cSrcweir             0x00, 0x00, 0x00, 0x45, 0x71, 0x75, 0x61, 0x74,
2065cdf0e10cSrcweir             0x69, 0x6F, 0x6E, 0x2E, 0x33, 0x00, 0xF4, 0x39,
2066cdf0e10cSrcweir             0xB2, 0x71, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2067cdf0e10cSrcweir             0x00, 0x00, 0x00, 0x00, 0x00, 0x00
2068cdf0e10cSrcweir         };
2069cdf0e10cSrcweir         SvStorageStreamRef xStor( pStor->OpenSotStream( C2S("\1CompObj")));
2070cdf0e10cSrcweir         xStor->Write(aCompObj,sizeof(aCompObj));
2071cdf0e10cSrcweir 
2072cdf0e10cSrcweir         static sal_uInt8 __READONLY_DATA aOle[] = {
2073cdf0e10cSrcweir             0x01, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00,
2074cdf0e10cSrcweir             0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2075cdf0e10cSrcweir             0x00, 0x00, 0x00, 0x00
2076cdf0e10cSrcweir             };
2077cdf0e10cSrcweir         SvStorageStreamRef xStor2( pStor->OpenSotStream( C2S("\1Ole")));
2078cdf0e10cSrcweir         xStor2->Write(aOle,sizeof(aOle));
2079cdf0e10cSrcweir         xStor.Clear();
2080cdf0e10cSrcweir         xStor2.Clear();
2081cdf0e10cSrcweir 
2082cdf0e10cSrcweir         SvStorageStreamRef xSrc = pStor->OpenSotStream(C2S("Equation Native"));
2083cdf0e10cSrcweir         if ( (!xSrc.Is()) || (SVSTREAM_OK != xSrc->GetError()))
2084cdf0e10cSrcweir             return 0;
2085cdf0e10cSrcweir 
2086cdf0e10cSrcweir         pS = &xSrc;
2087cdf0e10cSrcweir         pS->SetNumberFormatInt( NUMBERFORMAT_INT_LITTLEENDIAN );
2088cdf0e10cSrcweir 
2089cdf0e10cSrcweir         pS->SeekRel(EQNOLEFILEHDR_SIZE); //Skip 28byte Header and fill it in later
2090cdf0e10cSrcweir         *pS << sal_uInt8(0x03);
2091cdf0e10cSrcweir         *pS << sal_uInt8(0x01);
2092cdf0e10cSrcweir         *pS << sal_uInt8(0x01);
2093cdf0e10cSrcweir         *pS << sal_uInt8(0x03);
2094cdf0e10cSrcweir         *pS << sal_uInt8(0x00);
2095cdf0e10cSrcweir         sal_uInt32 nSize = pS->Tell();
2096cdf0e10cSrcweir         nPendingAttributes=0;
2097cdf0e10cSrcweir 
2098cdf0e10cSrcweir         HandleNodes(pTree);
2099cdf0e10cSrcweir         *pS << sal_uInt8(END);
2100cdf0e10cSrcweir 
2101cdf0e10cSrcweir         nSize = pS->Tell()-nSize;
2102cdf0e10cSrcweir         pS->Seek(0);
2103cdf0e10cSrcweir         EQNOLEFILEHDR aHdr(nSize+4+1);
2104cdf0e10cSrcweir         aHdr.Write(pS);
2105cdf0e10cSrcweir 
2106cdf0e10cSrcweir         pStor->Commit();
2107cdf0e10cSrcweir     }
2108cdf0e10cSrcweir 
2109cdf0e10cSrcweir     return 1;
2110cdf0e10cSrcweir }
2111cdf0e10cSrcweir 
2112cdf0e10cSrcweir 
HandleNodes(SmNode * pNode,int nLevel)2113cdf0e10cSrcweir sal_uInt8 MathType::HandleNodes(SmNode *pNode,int nLevel)
2114cdf0e10cSrcweir {
2115cdf0e10cSrcweir     sal_Bool bRet=sal_False;
2116cdf0e10cSrcweir     switch(pNode->GetType())
2117cdf0e10cSrcweir     {
2118cdf0e10cSrcweir         case NATTRIBUT:
2119cdf0e10cSrcweir             HandleAttributes(pNode,nLevel);
2120cdf0e10cSrcweir             break;
2121cdf0e10cSrcweir         case NTEXT:
2122cdf0e10cSrcweir             HandleText(pNode,nLevel);
2123cdf0e10cSrcweir             break;
2124cdf0e10cSrcweir         case NVERTICAL_BRACE:
2125cdf0e10cSrcweir             HandleVerticalBrace(pNode,nLevel);
2126cdf0e10cSrcweir             break;
2127cdf0e10cSrcweir         case NBRACE:
2128cdf0e10cSrcweir             HandleBrace(pNode,nLevel);
2129cdf0e10cSrcweir             break;
2130cdf0e10cSrcweir         case NOPER:
2131cdf0e10cSrcweir             HandleOperator(pNode,nLevel);
2132cdf0e10cSrcweir             break;
2133cdf0e10cSrcweir         case NBINVER:
2134cdf0e10cSrcweir             HandleFractions(pNode,nLevel);
2135cdf0e10cSrcweir             break;
2136cdf0e10cSrcweir         case NROOT:
2137cdf0e10cSrcweir             HandleRoot(pNode,nLevel);
2138cdf0e10cSrcweir             break;
2139cdf0e10cSrcweir         case NSPECIAL:
2140cdf0e10cSrcweir             {
2141cdf0e10cSrcweir             SmTextNode *pText=(SmTextNode *)pNode;
2142cdf0e10cSrcweir             //if the token str and the result text are the same then this
2143cdf0e10cSrcweir             //is to be seen as text, else assume its a mathchar
2144cdf0e10cSrcweir             if (pText->GetText() == pText->GetToken().aText)
2145cdf0e10cSrcweir                 HandleText(pText,nLevel);
2146cdf0e10cSrcweir             else
2147cdf0e10cSrcweir                 HandleMath(pText,nLevel);
2148cdf0e10cSrcweir             }
2149cdf0e10cSrcweir             break;
2150cdf0e10cSrcweir         case NMATH:
2151cdf0e10cSrcweir             HandleMath(pNode,nLevel);
2152cdf0e10cSrcweir             break;
2153cdf0e10cSrcweir         case NSUBSUP:
2154cdf0e10cSrcweir             HandleSubSupScript(pNode,nLevel);
2155cdf0e10cSrcweir             break;
2156cdf0e10cSrcweir         case NEXPRESSION:
2157cdf0e10cSrcweir             {
2158cdf0e10cSrcweir             sal_uInt16  nSize = pNode->GetNumSubNodes();
2159cdf0e10cSrcweir             for (sal_uInt16 i = 0; i < nSize; i++)
2160cdf0e10cSrcweir                 if (SmNode *pTemp = pNode->GetSubNode(i))
2161cdf0e10cSrcweir                     HandleNodes(pTemp,nLevel+1);
2162cdf0e10cSrcweir             }
2163cdf0e10cSrcweir             break;
2164cdf0e10cSrcweir         case NTABLE:
2165cdf0e10cSrcweir             //Root Node, PILE equivalent, i.e. vertical stack
2166cdf0e10cSrcweir             HandleTable(pNode,nLevel);
2167cdf0e10cSrcweir             break;
2168cdf0e10cSrcweir         case NMATRIX:
2169cdf0e10cSrcweir             HandleSmMatrix((SmMatrixNode *)pNode,nLevel);
2170cdf0e10cSrcweir             break;
2171cdf0e10cSrcweir         case NLINE:
2172cdf0e10cSrcweir             {
2173cdf0e10cSrcweir             *pS << sal_uInt8(0x0a);
2174cdf0e10cSrcweir             *pS << sal_uInt8(LINE);
2175cdf0e10cSrcweir             sal_uInt16  nSize = pNode->GetNumSubNodes();
2176cdf0e10cSrcweir             for (sal_uInt16 i = 0; i < nSize; i++)
2177cdf0e10cSrcweir                 if (SmNode *pTemp = pNode->GetSubNode(i))
2178cdf0e10cSrcweir                     HandleNodes(pTemp,nLevel+1);
2179cdf0e10cSrcweir             *pS << sal_uInt8(END);
2180cdf0e10cSrcweir             }
2181cdf0e10cSrcweir             break;
2182cdf0e10cSrcweir         case NALIGN:
2183cdf0e10cSrcweir             HandleMAlign(pNode,nLevel);
2184cdf0e10cSrcweir             break;
2185cdf0e10cSrcweir         case NBLANK:
2186cdf0e10cSrcweir             *pS << sal_uInt8(CHAR);
2187cdf0e10cSrcweir             *pS << sal_uInt8(0x98);
2188cdf0e10cSrcweir             if (pNode->GetToken().eType == TSBLANK)
2189cdf0e10cSrcweir                 *pS << sal_uInt16(0xEB04);
2190cdf0e10cSrcweir             else
2191cdf0e10cSrcweir                 *pS << sal_uInt16(0xEB05);
2192cdf0e10cSrcweir             break;
2193cdf0e10cSrcweir         default:
2194cdf0e10cSrcweir             {
2195cdf0e10cSrcweir             sal_uInt16  nSize = pNode->GetNumSubNodes();
2196cdf0e10cSrcweir             for (sal_uInt16 i = 0; i < nSize; i++)
2197cdf0e10cSrcweir                 if (SmNode *pTemp = pNode->GetSubNode(i))
2198cdf0e10cSrcweir                     HandleNodes(pTemp,nLevel+1);
2199cdf0e10cSrcweir             }
2200cdf0e10cSrcweir             break;
2201cdf0e10cSrcweir     }
2202cdf0e10cSrcweir     return bRet;
2203cdf0e10cSrcweir }
2204cdf0e10cSrcweir 
2205cdf0e10cSrcweir 
StartTemplate(sal_uInt16 nSelector,sal_uInt16 nVariation)2206cdf0e10cSrcweir int MathType::StartTemplate(sal_uInt16 nSelector,sal_uInt16 nVariation)
2207cdf0e10cSrcweir {
2208cdf0e10cSrcweir     int nOldPending=nPendingAttributes;
2209cdf0e10cSrcweir     *pS << sal_uInt8(TMPL); //Template
2210cdf0e10cSrcweir     *pS << sal_uInt8(nSelector); //selector
2211cdf0e10cSrcweir     *pS << sal_uInt8(nVariation); //variation
2212cdf0e10cSrcweir     *pS << sal_uInt8(0x00); //options
2213cdf0e10cSrcweir     *pS << sal_uInt8(LINE);
2214cdf0e10cSrcweir     //theres just no way we can now handle any character
2215cdf0e10cSrcweir     //attributes (from mathtypes perspective) centered
2216cdf0e10cSrcweir     //over an expression but above template attribute
2217cdf0e10cSrcweir     //such as widevec and similiar constructs
2218cdf0e10cSrcweir     //we have to drop them
2219cdf0e10cSrcweir     nPendingAttributes=0;
2220cdf0e10cSrcweir     return nOldPending;
2221cdf0e10cSrcweir }
2222cdf0e10cSrcweir 
EndTemplate(int nOldPendingAttributes)2223cdf0e10cSrcweir void MathType::EndTemplate(int nOldPendingAttributes)
2224cdf0e10cSrcweir {
2225cdf0e10cSrcweir     *pS << sal_uInt8(END); //end line
2226cdf0e10cSrcweir     *pS << sal_uInt8(END); //end template
2227cdf0e10cSrcweir     nPendingAttributes=nOldPendingAttributes;
2228cdf0e10cSrcweir }
2229cdf0e10cSrcweir 
2230cdf0e10cSrcweir 
HandleSmMatrix(SmMatrixNode * pMatrix,int nLevel)2231cdf0e10cSrcweir void MathType::HandleSmMatrix(SmMatrixNode *pMatrix,int nLevel)
2232cdf0e10cSrcweir {
2233cdf0e10cSrcweir     *pS << sal_uInt8(MATRIX);
2234cdf0e10cSrcweir     *pS << sal_uInt8(0x00); //vAlign ?
2235cdf0e10cSrcweir     *pS << sal_uInt8(0x00); //h_just
2236cdf0e10cSrcweir     *pS << sal_uInt8(0x00); //v_just
2237cdf0e10cSrcweir     *pS << sal_uInt8(pMatrix->GetNumRows()); //v_just
2238cdf0e10cSrcweir     *pS << sal_uInt8(pMatrix->GetNumCols()); //v_just
2239cdf0e10cSrcweir     int nBytes=(pMatrix->GetNumRows()+1)*2/8;
2240cdf0e10cSrcweir     if (((pMatrix->GetNumRows()+1)*2)%8)
2241cdf0e10cSrcweir         nBytes++;
2242cdf0e10cSrcweir     for (sal_uInt16 j = 0; j < nBytes; j++)
2243cdf0e10cSrcweir         *pS << sal_uInt8(0x00); //row_parts
2244cdf0e10cSrcweir     nBytes=(pMatrix->GetNumCols()+1)*2/8;
2245cdf0e10cSrcweir     if (((pMatrix->GetNumCols()+1)*2)%8)
2246cdf0e10cSrcweir         nBytes++;
2247cdf0e10cSrcweir     for (sal_uInt16 k = 0; k < nBytes; k++)
2248cdf0e10cSrcweir         *pS << sal_uInt8(0x00); //col_parts
2249cdf0e10cSrcweir     sal_uInt16  nSize = pMatrix->GetNumSubNodes();
2250cdf0e10cSrcweir     for (sal_uInt16 i = 0; i < nSize; i++)
2251cdf0e10cSrcweir         if (SmNode *pTemp = pMatrix->GetSubNode(i))
2252cdf0e10cSrcweir         {
2253cdf0e10cSrcweir             *pS << sal_uInt8(LINE); //line
2254cdf0e10cSrcweir             HandleNodes(pTemp,nLevel+1);
2255cdf0e10cSrcweir             *pS << sal_uInt8(END); //end line
2256cdf0e10cSrcweir         }
2257cdf0e10cSrcweir     *pS << sal_uInt8(END);
2258cdf0e10cSrcweir }
2259cdf0e10cSrcweir 
2260cdf0e10cSrcweir 
2261cdf0e10cSrcweir //Root Node, PILE equivalent, i.e. vertical stack
HandleTable(SmNode * pNode,int nLevel)2262cdf0e10cSrcweir void MathType::HandleTable(SmNode *pNode,int nLevel)
2263cdf0e10cSrcweir {
2264cdf0e10cSrcweir     sal_uInt16  nSize = pNode->GetNumSubNodes();
2265cdf0e10cSrcweir     //The root of the starmath is a table, if
2266cdf0e10cSrcweir     //we convert this them each iteration of
2267cdf0e10cSrcweir     //conversion from starmath to mathtype will
2268cdf0e10cSrcweir     //add an extra unnecessary level to the
2269cdf0e10cSrcweir     //mathtype output stack which would grow
2270cdf0e10cSrcweir     //without bound in a multi step conversion
2271cdf0e10cSrcweir 
2272cdf0e10cSrcweir     if (nLevel == 0)
2273cdf0e10cSrcweir         *pS << sal_uInt8(0x0A); //initial size
2274cdf0e10cSrcweir 
2275cdf0e10cSrcweir     if ( nLevel || (nSize >1))
2276cdf0e10cSrcweir     {
2277cdf0e10cSrcweir         *pS << sal_uInt8(PILE);
2278cdf0e10cSrcweir         *pS << sal_uInt8(nHAlign); //vAlign ?
2279cdf0e10cSrcweir         *pS << sal_uInt8(0x01); //hAlign
2280cdf0e10cSrcweir     }
2281cdf0e10cSrcweir 
2282cdf0e10cSrcweir     for (sal_uInt16 i = 0; i < nSize; i++)
2283cdf0e10cSrcweir         if (SmNode *pTemp = pNode->GetSubNode(i))
2284cdf0e10cSrcweir         {
2285cdf0e10cSrcweir             *pS << sal_uInt8(LINE);
2286cdf0e10cSrcweir             HandleNodes(pTemp,nLevel+1);
2287cdf0e10cSrcweir             *pS << sal_uInt8(END);
2288cdf0e10cSrcweir         }
2289cdf0e10cSrcweir     if (nLevel || (nSize>1))
2290cdf0e10cSrcweir         *pS << sal_uInt8(END);
2291cdf0e10cSrcweir }
2292cdf0e10cSrcweir 
2293cdf0e10cSrcweir 
HandleRoot(SmNode * pNode,int nLevel)2294cdf0e10cSrcweir void MathType::HandleRoot(SmNode *pNode,int nLevel)
2295cdf0e10cSrcweir {
2296cdf0e10cSrcweir     //sal_uInt16  nSize = pNode->GetNumSubNodes();
2297cdf0e10cSrcweir     SmNode *pTemp;
2298cdf0e10cSrcweir     *pS << sal_uInt8(TMPL); //Template
2299cdf0e10cSrcweir     *pS << sal_uInt8(0x0D); //selector
2300cdf0e10cSrcweir     if (pNode->GetSubNode(0))
2301cdf0e10cSrcweir         *pS << sal_uInt8(0x01); //variation
2302cdf0e10cSrcweir     else
2303cdf0e10cSrcweir         *pS << sal_uInt8(0x00); //variation
2304cdf0e10cSrcweir     *pS << sal_uInt8(0x00); //options
2305cdf0e10cSrcweir 
2306cdf0e10cSrcweir     /*
2307cdf0e10cSrcweir     if (pTemp = pNode->GetSubNode(1))
2308cdf0e10cSrcweir             HandleNodes(pTemp,nLevel+1);
2309cdf0e10cSrcweir     */
2310cdf0e10cSrcweir     if (NULL != (pTemp = pNode->GetSubNode(2)))
2311cdf0e10cSrcweir     {
2312cdf0e10cSrcweir         *pS << sal_uInt8(LINE); //line
2313cdf0e10cSrcweir         HandleNodes(pTemp,nLevel+1);
2314cdf0e10cSrcweir         *pS << sal_uInt8(END);
2315cdf0e10cSrcweir     }
2316cdf0e10cSrcweir 
2317cdf0e10cSrcweir     if (NULL != (pTemp = pNode->GetSubNode(0)))
2318cdf0e10cSrcweir     {
2319cdf0e10cSrcweir         *pS << sal_uInt8(LINE); //line
2320cdf0e10cSrcweir         HandleNodes(pTemp,nLevel+1);
2321cdf0e10cSrcweir         *pS << sal_uInt8(END);
2322cdf0e10cSrcweir     }
2323cdf0e10cSrcweir     else
2324cdf0e10cSrcweir         *pS << sal_uInt8(LINE|0x10); //dummy line
2325cdf0e10cSrcweir 
2326cdf0e10cSrcweir 
2327cdf0e10cSrcweir 
2328cdf0e10cSrcweir     *pS << sal_uInt8(END);
2329cdf0e10cSrcweir }
2330cdf0e10cSrcweir 
HandleCScript(SmNode * pNode,SmNode * pContent,int nLevel,sal_uLong * pPos,sal_Bool bTest)2331cdf0e10cSrcweir sal_uInt8 MathType::HandleCScript(SmNode *pNode,SmNode *pContent,int nLevel,
2332cdf0e10cSrcweir     sal_uLong *pPos,sal_Bool bTest)
2333cdf0e10cSrcweir {
2334cdf0e10cSrcweir     sal_uInt8 nVariation2=0xff;
2335cdf0e10cSrcweir 
2336cdf0e10cSrcweir     if (bTest && pNode->GetSubNode(CSUP+1))
2337cdf0e10cSrcweir     {
2338cdf0e10cSrcweir         nVariation2=0;
2339cdf0e10cSrcweir         if (pNode->GetSubNode(CSUB+1))
2340cdf0e10cSrcweir             nVariation2=2;
2341cdf0e10cSrcweir     }
2342cdf0e10cSrcweir     else if (pNode->GetSubNode(CSUB+1))
2343cdf0e10cSrcweir         nVariation2=1;
2344cdf0e10cSrcweir 
2345cdf0e10cSrcweir     if (nVariation2!=0xff)
2346cdf0e10cSrcweir     {
2347cdf0e10cSrcweir         if (pPos)
2348cdf0e10cSrcweir             *pPos = pS->Tell();
2349cdf0e10cSrcweir         *pS << sal_uInt8(TMPL); //Template
2350cdf0e10cSrcweir         *pS << sal_uInt8(0x2B); //selector
2351cdf0e10cSrcweir         *pS << nVariation2;
2352cdf0e10cSrcweir         *pS << sal_uInt8(0x00); //options
2353cdf0e10cSrcweir 
2354cdf0e10cSrcweir         if (pContent)
2355cdf0e10cSrcweir         {
2356cdf0e10cSrcweir             *pS << sal_uInt8(LINE); //line
2357cdf0e10cSrcweir             HandleNodes(pContent,nLevel+1);
2358cdf0e10cSrcweir             *pS << sal_uInt8(END); //line
2359cdf0e10cSrcweir         }
2360cdf0e10cSrcweir         else
2361cdf0e10cSrcweir             *pS << sal_uInt8(LINE|0x10);
2362cdf0e10cSrcweir 
2363cdf0e10cSrcweir         *pS << sal_uInt8(0x0B);
2364cdf0e10cSrcweir 
2365cdf0e10cSrcweir         SmNode *pTemp;
2366cdf0e10cSrcweir         if (NULL != (pTemp = pNode->GetSubNode(CSUB+1)))
2367cdf0e10cSrcweir         {
2368cdf0e10cSrcweir             *pS << sal_uInt8(LINE); //line
2369cdf0e10cSrcweir             HandleNodes(pTemp,nLevel+1);
2370cdf0e10cSrcweir             *pS << sal_uInt8(END); //line
2371cdf0e10cSrcweir         }
2372cdf0e10cSrcweir         else
2373cdf0e10cSrcweir             *pS << sal_uInt8(LINE|0x10);
2374cdf0e10cSrcweir         if (bTest && NULL != (pTemp = pNode->GetSubNode(CSUP+1)))
2375cdf0e10cSrcweir         {
2376cdf0e10cSrcweir             *pS << sal_uInt8(LINE); //line
2377cdf0e10cSrcweir             HandleNodes(pTemp,nLevel+1);
2378cdf0e10cSrcweir             *pS << sal_uInt8(END); //line
2379cdf0e10cSrcweir         }
2380cdf0e10cSrcweir         else
2381cdf0e10cSrcweir             *pS << sal_uInt8(LINE|0x10);
2382cdf0e10cSrcweir     }
2383cdf0e10cSrcweir     return nVariation2;
2384cdf0e10cSrcweir }
2385cdf0e10cSrcweir 
2386cdf0e10cSrcweir 
2387cdf0e10cSrcweir 
2388cdf0e10cSrcweir /*
2389cdf0e10cSrcweir  Sub and Sup scripts and another problem area, StarMath
2390cdf0e10cSrcweir  can have all possible options used at the same time, whereas
2391cdf0e10cSrcweir  Mathtype cannot. The ordering of the nodes for each system
2392cdf0e10cSrcweir  is quite different as well leading to some complexity
2393cdf0e10cSrcweir  */
HandleSubSupScript(SmNode * pNode,int nLevel)2394cdf0e10cSrcweir void MathType::HandleSubSupScript(SmNode *pNode,int nLevel)
2395cdf0e10cSrcweir {
2396cdf0e10cSrcweir     //sal_uInt16  nSize = pNode->GetNumSubNodes();
2397cdf0e10cSrcweir     SmNode *pTemp;
2398cdf0e10cSrcweir 
2399cdf0e10cSrcweir     sal_uInt8 nVariation=0xff;
2400cdf0e10cSrcweir     if (pNode->GetSubNode(LSUP+1))
2401cdf0e10cSrcweir     {
2402cdf0e10cSrcweir         nVariation=0;
2403cdf0e10cSrcweir         if (pNode->GetSubNode(LSUB+1))
2404cdf0e10cSrcweir             nVariation=2;
2405cdf0e10cSrcweir     }
2406cdf0e10cSrcweir     else if (NULL != (pTemp = pNode->GetSubNode(LSUB+1)))
2407cdf0e10cSrcweir         nVariation=1;
2408cdf0e10cSrcweir 
2409cdf0e10cSrcweir     if (nVariation!=0xff)
2410cdf0e10cSrcweir     {
2411cdf0e10cSrcweir         *pS << sal_uInt8(TMPL); //Template
2412cdf0e10cSrcweir         *pS << sal_uInt8(0x2c); //selector
2413cdf0e10cSrcweir         *pS << nVariation;
2414cdf0e10cSrcweir         *pS << sal_uInt8(0x00); //options
2415cdf0e10cSrcweir         *pS << sal_uInt8(0x0B);
2416cdf0e10cSrcweir 
2417cdf0e10cSrcweir         if (NULL != (pTemp = pNode->GetSubNode(LSUB+1)))
2418cdf0e10cSrcweir         {
2419cdf0e10cSrcweir             *pS << sal_uInt8(LINE); //line
2420cdf0e10cSrcweir             HandleNodes(pTemp,nLevel+1);
2421cdf0e10cSrcweir             *pS << sal_uInt8(END); //line
2422cdf0e10cSrcweir         }
2423cdf0e10cSrcweir         else
2424cdf0e10cSrcweir             *pS << sal_uInt8(LINE|0x10);
2425cdf0e10cSrcweir         if (NULL != (pTemp = pNode->GetSubNode(LSUP+1)))
2426cdf0e10cSrcweir         {
2427cdf0e10cSrcweir             *pS << sal_uInt8(LINE); //line
2428cdf0e10cSrcweir             HandleNodes(pTemp,nLevel+1);
2429cdf0e10cSrcweir             *pS << sal_uInt8(END); //line
2430cdf0e10cSrcweir         }
2431cdf0e10cSrcweir         else
2432cdf0e10cSrcweir             *pS << sal_uInt8(LINE|0x10);
2433cdf0e10cSrcweir         *pS << sal_uInt8(END);
2434cdf0e10cSrcweir         nVariation=0xff;
2435cdf0e10cSrcweir     }
2436cdf0e10cSrcweir 
2437cdf0e10cSrcweir 
2438cdf0e10cSrcweir     sal_uInt8 nVariation2=HandleCScript(pNode,NULL,nLevel);
2439cdf0e10cSrcweir 
2440cdf0e10cSrcweir     if (NULL != (pTemp = pNode->GetSubNode(0)))
2441cdf0e10cSrcweir     {
2442cdf0e10cSrcweir //      *pS << sal_uInt8(0x0A);
2443cdf0e10cSrcweir //      *pS << sal_uInt8(LINE);
2444cdf0e10cSrcweir         HandleNodes(pTemp,nLevel+1);
2445cdf0e10cSrcweir //      *pS << sal_uInt8(END);
2446cdf0e10cSrcweir     }
2447cdf0e10cSrcweir 
2448cdf0e10cSrcweir     if (nVariation2 != 0xff)
2449cdf0e10cSrcweir         *pS << sal_uInt8(END);
2450cdf0e10cSrcweir 
2451cdf0e10cSrcweir     if (NULL != (pNode->GetSubNode(RSUP+1)))
2452cdf0e10cSrcweir     {
2453cdf0e10cSrcweir         nVariation=0;
2454cdf0e10cSrcweir         if (pNode->GetSubNode(RSUB+1))
2455cdf0e10cSrcweir             nVariation=2;
2456cdf0e10cSrcweir     }
2457cdf0e10cSrcweir     else if (NULL != (pTemp = pNode->GetSubNode(RSUB+1)))
2458cdf0e10cSrcweir         nVariation=1;
2459cdf0e10cSrcweir 
2460cdf0e10cSrcweir     if (nVariation!=0xff)
2461cdf0e10cSrcweir     {
2462cdf0e10cSrcweir         *pS << sal_uInt8(TMPL); //Template
2463cdf0e10cSrcweir         *pS << sal_uInt8(0x0F); //selector
2464cdf0e10cSrcweir         *pS << nVariation;
2465cdf0e10cSrcweir         *pS << sal_uInt8(0x00); //options
2466cdf0e10cSrcweir         *pS << sal_uInt8(0x0B);
2467cdf0e10cSrcweir 
2468cdf0e10cSrcweir         if (NULL != (pTemp = pNode->GetSubNode(RSUB+1)))
2469cdf0e10cSrcweir         {
2470cdf0e10cSrcweir             *pS << sal_uInt8(LINE); //line
2471cdf0e10cSrcweir             HandleNodes(pTemp,nLevel+1);
2472cdf0e10cSrcweir             *pS << sal_uInt8(END); //line
2473cdf0e10cSrcweir         }
2474cdf0e10cSrcweir         else
2475cdf0e10cSrcweir             *pS << sal_uInt8(LINE|0x10);
2476cdf0e10cSrcweir         if (NULL != (pTemp = pNode->GetSubNode(RSUP+1)))
2477cdf0e10cSrcweir         {
2478cdf0e10cSrcweir             *pS << sal_uInt8(LINE); //line
2479cdf0e10cSrcweir             HandleNodes(pTemp,nLevel+1);
2480cdf0e10cSrcweir             *pS << sal_uInt8(END); //line
2481cdf0e10cSrcweir         }
2482cdf0e10cSrcweir         else
2483cdf0e10cSrcweir             *pS << sal_uInt8(LINE|0x10);
2484cdf0e10cSrcweir     *pS << sal_uInt8(END); //line
2485cdf0e10cSrcweir     }
2486cdf0e10cSrcweir 
2487cdf0e10cSrcweir     //After subscript mathtype will keep the size of
2488cdf0e10cSrcweir     //normal text at the subscript size, sigh.
2489cdf0e10cSrcweir     *pS << sal_uInt8(0x0A);
2490cdf0e10cSrcweir }
2491cdf0e10cSrcweir 
2492cdf0e10cSrcweir 
HandleFractions(SmNode * pNode,int nLevel)2493cdf0e10cSrcweir void MathType::HandleFractions(SmNode *pNode,int nLevel)
2494cdf0e10cSrcweir {
2495cdf0e10cSrcweir     //sal_uInt16  nSize = pNode->GetNumSubNodes();
2496cdf0e10cSrcweir     SmNode *pTemp;
2497cdf0e10cSrcweir     *pS << sal_uInt8(TMPL); //Template
2498cdf0e10cSrcweir     *pS << sal_uInt8(0x0E); //selector
2499cdf0e10cSrcweir     *pS << sal_uInt8(0x00); //variation
2500cdf0e10cSrcweir     *pS << sal_uInt8(0x00); //options
2501cdf0e10cSrcweir 
2502cdf0e10cSrcweir     *pS << sal_uInt8(0x0A);
2503cdf0e10cSrcweir     *pS << sal_uInt8(LINE); //line
2504cdf0e10cSrcweir     if (NULL != (pTemp = pNode->GetSubNode(0)))
2505cdf0e10cSrcweir         HandleNodes(pTemp,nLevel+1);
2506cdf0e10cSrcweir     *pS << sal_uInt8(END);
2507cdf0e10cSrcweir 
2508cdf0e10cSrcweir     *pS << sal_uInt8(0x0A);
2509cdf0e10cSrcweir     *pS << sal_uInt8(LINE); //line
2510cdf0e10cSrcweir     if (NULL != (pTemp = pNode->GetSubNode(2)))
2511cdf0e10cSrcweir         HandleNodes(pTemp,nLevel+1);
2512cdf0e10cSrcweir     *pS << sal_uInt8(END);
2513cdf0e10cSrcweir 
2514cdf0e10cSrcweir     *pS << sal_uInt8(END);
2515cdf0e10cSrcweir }
2516cdf0e10cSrcweir 
2517cdf0e10cSrcweir 
HandleBrace(SmNode * pNode,int nLevel)2518cdf0e10cSrcweir void MathType::HandleBrace(SmNode *pNode,int nLevel)
2519cdf0e10cSrcweir {
2520cdf0e10cSrcweir     //sal_uInt16  nSize = pNode->GetNumSubNodes();
2521cdf0e10cSrcweir     SmNode *pTemp;
2522cdf0e10cSrcweir     SmNode *pLeft=pNode->GetSubNode(0);
2523cdf0e10cSrcweir     SmNode *pRight=pNode->GetSubNode(2);
2524cdf0e10cSrcweir 
2525cdf0e10cSrcweir     *pS << sal_uInt8(TMPL); //Template
2526cdf0e10cSrcweir     bIsReInterpBrace=0;
2527cdf0e10cSrcweir     sal_uInt8 nBSpec=0x10;
2528cdf0e10cSrcweir     sal_uLong nLoc = pS->Tell();
2529cdf0e10cSrcweir     if (pLeft)
2530cdf0e10cSrcweir     {
2531cdf0e10cSrcweir         switch (pLeft->GetToken().eType)
2532cdf0e10cSrcweir         {
2533cdf0e10cSrcweir             case TLANGLE:
2534cdf0e10cSrcweir                 *pS << sal_uInt8(tmANGLE); //selector
2535cdf0e10cSrcweir                 *pS << sal_uInt8(0x00); //variation
2536cdf0e10cSrcweir                 *pS << sal_uInt8(0x00); //options
2537cdf0e10cSrcweir                 break;
2538cdf0e10cSrcweir             case TLBRACE:
2539cdf0e10cSrcweir                 *pS << sal_uInt8(tmBRACE); //selector
2540cdf0e10cSrcweir                 *pS << sal_uInt8(0x00); //variation
2541cdf0e10cSrcweir                 *pS << sal_uInt8(0x00); //options
2542cdf0e10cSrcweir                 nBSpec+=3;
2543cdf0e10cSrcweir                 break;
2544cdf0e10cSrcweir             case TLBRACKET:
2545cdf0e10cSrcweir                 *pS << sal_uInt8(tmBRACK); //selector
2546cdf0e10cSrcweir                 *pS << sal_uInt8(0x00); //variation
2547cdf0e10cSrcweir                 *pS << sal_uInt8(0x00); //options
2548cdf0e10cSrcweir                 nBSpec+=3;
2549cdf0e10cSrcweir                 break;
2550cdf0e10cSrcweir             case TLFLOOR:
2551cdf0e10cSrcweir                 *pS << sal_uInt8(tmFLOOR); //selector
2552cdf0e10cSrcweir                 *pS << sal_uInt8(0x00); //variation
2553cdf0e10cSrcweir                 *pS << sal_uInt8(0x00); //options
2554cdf0e10cSrcweir                 break;
2555cdf0e10cSrcweir             case TLLINE:
2556cdf0e10cSrcweir                 *pS << sal_uInt8(tmBAR); //selector
2557cdf0e10cSrcweir                 *pS << sal_uInt8(0x00); //variation
2558cdf0e10cSrcweir                 *pS << sal_uInt8(0x00); //options
2559cdf0e10cSrcweir                 nBSpec+=3;
2560cdf0e10cSrcweir                 break;
2561cdf0e10cSrcweir             case TLDLINE:
2562cdf0e10cSrcweir                 *pS << sal_uInt8(tmDBAR); //selector
2563cdf0e10cSrcweir                 *pS << sal_uInt8(0x00); //variation
2564cdf0e10cSrcweir                 *pS << sal_uInt8(0x00); //options
2565cdf0e10cSrcweir                 break;
2566cdf0e10cSrcweir             default:
2567cdf0e10cSrcweir                 *pS << sal_uInt8(tmPAREN); //selector
2568cdf0e10cSrcweir                 *pS << sal_uInt8(0x00); //variation
2569cdf0e10cSrcweir                 *pS << sal_uInt8(0x00); //options
2570cdf0e10cSrcweir                 nBSpec+=3;
2571cdf0e10cSrcweir                 break;
2572cdf0e10cSrcweir         }
2573cdf0e10cSrcweir     }
2574cdf0e10cSrcweir 
2575cdf0e10cSrcweir     if (NULL != (pTemp = pNode->GetSubNode(1)))
2576cdf0e10cSrcweir     {
2577cdf0e10cSrcweir         *pS << sal_uInt8(LINE); //line
2578cdf0e10cSrcweir         HandleNodes(pTemp,nLevel+1);
2579cdf0e10cSrcweir         *pS << sal_uInt8(END); //options
2580cdf0e10cSrcweir     }
2581cdf0e10cSrcweir     nSpec=nBSpec;
2582cdf0e10cSrcweir     if (pLeft)
2583cdf0e10cSrcweir         HandleNodes(pLeft,nLevel+1);
2584cdf0e10cSrcweir     if (bIsReInterpBrace)
2585cdf0e10cSrcweir     {
2586cdf0e10cSrcweir         sal_uLong nLoc2 = pS->Tell();
2587cdf0e10cSrcweir         pS->Seek(nLoc);
2588cdf0e10cSrcweir         *pS << sal_uInt8(0x2D);
2589cdf0e10cSrcweir         pS->Seek(nLoc2);
2590cdf0e10cSrcweir         *pS << sal_uInt8(CHAR);
2591cdf0e10cSrcweir         *pS << sal_uInt8(0x96);
2592cdf0e10cSrcweir         *pS << sal_uInt16(0xEC07);
2593cdf0e10cSrcweir         bIsReInterpBrace=0;
2594cdf0e10cSrcweir     }
2595cdf0e10cSrcweir     if (pRight)
2596cdf0e10cSrcweir         HandleNodes(pRight,nLevel+1);
2597cdf0e10cSrcweir     nSpec=0x0;
2598cdf0e10cSrcweir     *pS << sal_uInt8(END);
2599cdf0e10cSrcweir }
2600cdf0e10cSrcweir 
2601cdf0e10cSrcweir 
HandleVerticalBrace(SmNode * pNode,int nLevel)2602cdf0e10cSrcweir void MathType::HandleVerticalBrace(SmNode *pNode,int nLevel)
2603cdf0e10cSrcweir {
2604cdf0e10cSrcweir     SmNode *pTemp;
2605cdf0e10cSrcweir     *pS << sal_uInt8(TMPL); //Template
2606cdf0e10cSrcweir     if (pNode->GetToken().eType == TUNDERBRACE)
2607cdf0e10cSrcweir         *pS << sal_uInt8(tmLHBRACE); //selector
2608cdf0e10cSrcweir     else
2609cdf0e10cSrcweir         *pS << sal_uInt8(tmUHBRACE); //selector
2610cdf0e10cSrcweir     *pS << sal_uInt8(0x01); //variation
2611cdf0e10cSrcweir     *pS << sal_uInt8(0x00); //options
2612cdf0e10cSrcweir 
2613cdf0e10cSrcweir     if (NULL != (pTemp = pNode->GetSubNode(0)))
2614cdf0e10cSrcweir     {
2615cdf0e10cSrcweir         *pS << sal_uInt8(LINE); //line
2616cdf0e10cSrcweir         HandleNodes(pTemp,nLevel+1);
2617cdf0e10cSrcweir         *pS << sal_uInt8(END); //options
2618cdf0e10cSrcweir     }
2619cdf0e10cSrcweir 
2620cdf0e10cSrcweir     if (NULL != (pTemp = pNode->GetSubNode(2)))
2621cdf0e10cSrcweir     {
2622cdf0e10cSrcweir         *pS << sal_uInt8(LINE); //line
2623cdf0e10cSrcweir         HandleNodes(pTemp,nLevel+1);
2624cdf0e10cSrcweir         *pS << sal_uInt8(END); //options
2625cdf0e10cSrcweir     }
2626cdf0e10cSrcweir     *pS << sal_uInt8(END);
2627cdf0e10cSrcweir }
2628cdf0e10cSrcweir 
HandleOperator(SmNode * pNode,int nLevel)2629cdf0e10cSrcweir void MathType::HandleOperator(SmNode *pNode,int nLevel)
2630cdf0e10cSrcweir {
2631cdf0e10cSrcweir     //sal_uInt16  nSize = pNode->GetNumSubNodes();
2632cdf0e10cSrcweir 
2633cdf0e10cSrcweir     if (HandleLim(pNode,nLevel))
2634cdf0e10cSrcweir         return;
2635cdf0e10cSrcweir 
2636cdf0e10cSrcweir     sal_uLong nPos;
2637cdf0e10cSrcweir     sal_uInt8 nVariation;
2638cdf0e10cSrcweir 
2639cdf0e10cSrcweir     switch (pNode->GetToken().eType)
2640cdf0e10cSrcweir     {
2641cdf0e10cSrcweir         case TIINT:
2642cdf0e10cSrcweir         case TIIINT:
2643cdf0e10cSrcweir         case TLINT:
2644cdf0e10cSrcweir         case TLLINT:
2645cdf0e10cSrcweir         case TLLLINT:
2646cdf0e10cSrcweir             nVariation=HandleCScript(pNode->GetSubNode(0),
2647cdf0e10cSrcweir                 pNode->GetSubNode(1),nLevel,&nPos,0);
2648cdf0e10cSrcweir             break;
2649cdf0e10cSrcweir         default:
2650cdf0e10cSrcweir             nVariation=HandleCScript(pNode->GetSubNode(0),
2651cdf0e10cSrcweir                 pNode->GetSubNode(1),nLevel,&nPos);
2652cdf0e10cSrcweir             break;
2653cdf0e10cSrcweir     }
2654cdf0e10cSrcweir 
2655cdf0e10cSrcweir     sal_uInt8 nOldVariation=nVariation;
2656cdf0e10cSrcweir     sal_uInt8 nIntVariation=nVariation;
2657cdf0e10cSrcweir 
2658cdf0e10cSrcweir     sal_uLong nPos2=0;
2659cdf0e10cSrcweir     if (nVariation != 0xff)
2660cdf0e10cSrcweir     {
2661cdf0e10cSrcweir         nPos2 = pS->Tell();
2662cdf0e10cSrcweir         pS->Seek(nPos);
2663cdf0e10cSrcweir         if (nVariation == 2)
2664cdf0e10cSrcweir         {
2665cdf0e10cSrcweir             nIntVariation=0;
2666cdf0e10cSrcweir             nVariation = 1;
2667cdf0e10cSrcweir         }
2668cdf0e10cSrcweir         else if (nVariation == 0)
2669cdf0e10cSrcweir             nVariation = 1;
2670cdf0e10cSrcweir         else if (nVariation == 1)
2671cdf0e10cSrcweir             nVariation = 0;
2672cdf0e10cSrcweir     }
2673cdf0e10cSrcweir     else
2674cdf0e10cSrcweir     {
2675cdf0e10cSrcweir         nVariation = 2;
2676cdf0e10cSrcweir         nIntVariation=0;
2677cdf0e10cSrcweir     }
2678cdf0e10cSrcweir     *pS << sal_uInt8(TMPL);
2679cdf0e10cSrcweir     switch(pNode->GetToken().eType)
2680cdf0e10cSrcweir     {
2681cdf0e10cSrcweir     case TINT:
2682cdf0e10cSrcweir         if (nOldVariation != 0xff)
2683cdf0e10cSrcweir             *pS << sal_uInt8(0x18); //selector
2684cdf0e10cSrcweir         else
2685cdf0e10cSrcweir             *pS << sal_uInt8(0x15); //selector
2686cdf0e10cSrcweir         *pS << nIntVariation; //variation
2687cdf0e10cSrcweir         break;
2688cdf0e10cSrcweir     case TIINT:
2689cdf0e10cSrcweir         if (nOldVariation != 0xff)
2690cdf0e10cSrcweir         {
2691cdf0e10cSrcweir             *pS << sal_uInt8(0x19);
2692cdf0e10cSrcweir             *pS << sal_uInt8(0x01);
2693cdf0e10cSrcweir         }
2694cdf0e10cSrcweir         else
2695cdf0e10cSrcweir         {
2696cdf0e10cSrcweir             *pS << sal_uInt8(0x16);
2697cdf0e10cSrcweir             *pS << sal_uInt8(0x00);
2698cdf0e10cSrcweir         }
2699cdf0e10cSrcweir         break;
2700cdf0e10cSrcweir     case TIIINT:
2701cdf0e10cSrcweir         if (nOldVariation != 0xff)
2702cdf0e10cSrcweir         {
2703cdf0e10cSrcweir             *pS << sal_uInt8(0x1a);
2704cdf0e10cSrcweir             *pS << sal_uInt8(0x01);
2705cdf0e10cSrcweir         }
2706cdf0e10cSrcweir         else
2707cdf0e10cSrcweir         {
2708cdf0e10cSrcweir             *pS << sal_uInt8(0x17);
2709cdf0e10cSrcweir             *pS << sal_uInt8(0x00);
2710cdf0e10cSrcweir         }
2711cdf0e10cSrcweir         break;
2712cdf0e10cSrcweir     case TLINT:
2713cdf0e10cSrcweir         if (nOldVariation != 0xff)
2714cdf0e10cSrcweir         {
2715cdf0e10cSrcweir             *pS << sal_uInt8(0x18);
2716cdf0e10cSrcweir             *pS << sal_uInt8(0x02);
2717cdf0e10cSrcweir         }
2718cdf0e10cSrcweir         else
2719cdf0e10cSrcweir         {
2720cdf0e10cSrcweir             *pS << sal_uInt8(0x15);
2721cdf0e10cSrcweir             *pS << sal_uInt8(0x03);
2722cdf0e10cSrcweir         }
2723cdf0e10cSrcweir         break;
2724cdf0e10cSrcweir     case TLLINT:
2725cdf0e10cSrcweir         if (nOldVariation != 0xff)
2726cdf0e10cSrcweir         {
2727cdf0e10cSrcweir             *pS << sal_uInt8(0x19);
2728cdf0e10cSrcweir             *pS << sal_uInt8(0x00);
2729cdf0e10cSrcweir         }
2730cdf0e10cSrcweir         else
2731cdf0e10cSrcweir         {
2732cdf0e10cSrcweir             *pS << sal_uInt8(0x16);
2733cdf0e10cSrcweir             *pS << sal_uInt8(0x02);
2734cdf0e10cSrcweir         }
2735cdf0e10cSrcweir         break;
2736cdf0e10cSrcweir     case TLLLINT:
2737cdf0e10cSrcweir         if (nOldVariation != 0xff)
2738cdf0e10cSrcweir         {
2739cdf0e10cSrcweir             *pS << sal_uInt8(0x1a);
2740cdf0e10cSrcweir             *pS << sal_uInt8(0x00);
2741cdf0e10cSrcweir         }
2742cdf0e10cSrcweir         else
2743cdf0e10cSrcweir         {
2744cdf0e10cSrcweir             *pS << sal_uInt8(0x17);
2745cdf0e10cSrcweir             *pS << sal_uInt8(0x02);
2746cdf0e10cSrcweir         }
2747cdf0e10cSrcweir         break;
2748cdf0e10cSrcweir     case TSUM:
2749cdf0e10cSrcweir     default:
2750cdf0e10cSrcweir         *pS << sal_uInt8(0x1d);
2751cdf0e10cSrcweir         *pS << nVariation;
2752cdf0e10cSrcweir         break;
2753cdf0e10cSrcweir     case TPROD:
2754cdf0e10cSrcweir         *pS << sal_uInt8(0x1f);
2755cdf0e10cSrcweir         *pS << nVariation;
2756cdf0e10cSrcweir         break;
2757cdf0e10cSrcweir     case TCOPROD:
2758cdf0e10cSrcweir         *pS << sal_uInt8(0x21);
2759cdf0e10cSrcweir         *pS << nVariation;
2760cdf0e10cSrcweir         break;
2761cdf0e10cSrcweir     }
2762cdf0e10cSrcweir     *pS << sal_uInt8(0x00); //options
2763cdf0e10cSrcweir 
2764cdf0e10cSrcweir     if (nPos2)
2765cdf0e10cSrcweir         pS->Seek(nPos2);
2766cdf0e10cSrcweir     else
2767cdf0e10cSrcweir     {
2768cdf0e10cSrcweir         *pS << sal_uInt8(LINE); //line
2769cdf0e10cSrcweir         HandleNodes(pNode->GetSubNode(1),nLevel+1);
2770cdf0e10cSrcweir         *pS << sal_uInt8(END); //line
2771cdf0e10cSrcweir         *pS << sal_uInt8(LINE|0x10);
2772cdf0e10cSrcweir         *pS << sal_uInt8(LINE|0x10);
2773cdf0e10cSrcweir     }
2774cdf0e10cSrcweir 
2775cdf0e10cSrcweir 
2776cdf0e10cSrcweir     *pS << sal_uInt8(0x0D);
2777cdf0e10cSrcweir     switch(pNode->GetToken().eType)
2778cdf0e10cSrcweir     {
2779cdf0e10cSrcweir     case TSUM:
2780cdf0e10cSrcweir     default:
2781cdf0e10cSrcweir         *pS << sal_uInt8(CHAR);
2782cdf0e10cSrcweir         *pS << sal_uInt8(0x86);
2783cdf0e10cSrcweir         *pS << sal_uInt16(0x2211);
2784cdf0e10cSrcweir         break;
2785cdf0e10cSrcweir     case TPROD:
2786cdf0e10cSrcweir         *pS << sal_uInt8(CHAR);
2787cdf0e10cSrcweir         *pS << sal_uInt8(0x86);
2788cdf0e10cSrcweir         *pS << sal_uInt16(0x220F);
2789cdf0e10cSrcweir         break;
2790cdf0e10cSrcweir     case TCOPROD:
2791cdf0e10cSrcweir         *pS << sal_uInt8(CHAR);
2792cdf0e10cSrcweir         *pS << sal_uInt8(0x8B);
2793cdf0e10cSrcweir         *pS << sal_uInt16(0x2210);
2794cdf0e10cSrcweir         break;
2795cdf0e10cSrcweir     case TIIINT:
2796cdf0e10cSrcweir     case TLLLINT:
2797cdf0e10cSrcweir         *pS << sal_uInt8(CHAR);
2798cdf0e10cSrcweir         *pS << sal_uInt8(0x86);
2799cdf0e10cSrcweir         *pS << sal_uInt16(0x222B);
2800cdf0e10cSrcweir     case TIINT:
2801cdf0e10cSrcweir     case TLLINT:
2802cdf0e10cSrcweir         *pS << sal_uInt8(CHAR);
2803cdf0e10cSrcweir         *pS << sal_uInt8(0x86);
2804cdf0e10cSrcweir         *pS << sal_uInt16(0x222B);
2805cdf0e10cSrcweir     case TINT:
2806cdf0e10cSrcweir     case TLINT:
2807cdf0e10cSrcweir         *pS << sal_uInt8(CHAR);
2808cdf0e10cSrcweir         *pS << sal_uInt8(0x86);
2809cdf0e10cSrcweir         *pS << sal_uInt16(0x222B);
2810cdf0e10cSrcweir         break;
2811cdf0e10cSrcweir     }
2812cdf0e10cSrcweir     *pS << sal_uInt8(END);
2813cdf0e10cSrcweir     *pS << sal_uInt8(0x0A);
2814cdf0e10cSrcweir }
2815cdf0e10cSrcweir 
2816cdf0e10cSrcweir 
HandlePile(int & rSetAlign,int nLevel,sal_uInt8 nSelector,sal_uInt8 nVariation)2817cdf0e10cSrcweir int MathType::HandlePile(int &rSetAlign,int nLevel,sal_uInt8 nSelector,
2818cdf0e10cSrcweir     sal_uInt8 nVariation)
2819cdf0e10cSrcweir {
2820cdf0e10cSrcweir     *pS >> nHAlign;
2821cdf0e10cSrcweir     *pS >> nVAlign;
2822cdf0e10cSrcweir 
2823cdf0e10cSrcweir     HandleAlign(nHAlign,nVAlign,rSetAlign);
2824cdf0e10cSrcweir 
2825cdf0e10cSrcweir     APPEND(rRet," stack {\n");
2826cdf0e10cSrcweir     int nRet = HandleRecords(nLevel+1,nSelector,nVariation,-1,-1);
2827cdf0e10cSrcweir     rRet.Erase(rRet.Len()-3,2);
2828cdf0e10cSrcweir     APPEND(rRet,"} ");
2829cdf0e10cSrcweir 
2830cdf0e10cSrcweir     while (rSetAlign)
2831cdf0e10cSrcweir     {
2832cdf0e10cSrcweir         APPEND(rRet,"} ");
2833cdf0e10cSrcweir         rSetAlign--;
2834cdf0e10cSrcweir     }
2835cdf0e10cSrcweir     return nRet;
2836cdf0e10cSrcweir }
2837cdf0e10cSrcweir 
HandleMatrix(int nLevel,sal_uInt8 nSelector,sal_uInt8 nVariation)2838cdf0e10cSrcweir int MathType::HandleMatrix(int nLevel,sal_uInt8 nSelector,
2839cdf0e10cSrcweir     sal_uInt8 nVariation)
2840cdf0e10cSrcweir {
2841cdf0e10cSrcweir     sal_uInt8 nH_just,nV_just,nRows,nCols;
2842cdf0e10cSrcweir     *pS >> nVAlign;
2843cdf0e10cSrcweir     *pS >> nH_just;
2844cdf0e10cSrcweir     *pS >> nV_just;
2845cdf0e10cSrcweir     *pS >> nRows;
2846cdf0e10cSrcweir     *pS >> nCols;
2847cdf0e10cSrcweir     int nBytes = ((nRows+1)*2)/8;
2848cdf0e10cSrcweir     if (((nRows+1)*2)%8)
2849cdf0e10cSrcweir         nBytes++;
2850cdf0e10cSrcweir     pS->SeekRel(nBytes);
2851cdf0e10cSrcweir     nBytes = ((nCols+1)*2)/8;
2852cdf0e10cSrcweir     if (((nCols+1)*2)%8)
2853cdf0e10cSrcweir         nBytes++;
2854cdf0e10cSrcweir     pS->SeekRel(nBytes);
2855cdf0e10cSrcweir     APPEND(rRet," matrix {\n");
2856cdf0e10cSrcweir     int nRet = HandleRecords(nLevel+1,nSelector,nVariation,nRows,nCols);
2857cdf0e10cSrcweir 
2858cdf0e10cSrcweir     xub_StrLen nI = rRet.SearchBackward('#');
2859cdf0e10cSrcweir     if ((nI != STRING_NOTFOUND) && (nI > 0))
2860cdf0e10cSrcweir         if (rRet.GetChar(nI-1) != '#')  //missing column
2861cdf0e10cSrcweir             APPEND(rRet,"{}");
2862cdf0e10cSrcweir 
2863cdf0e10cSrcweir     APPEND(rRet,"\n} ");
2864cdf0e10cSrcweir     return nRet;
2865cdf0e10cSrcweir }
2866cdf0e10cSrcweir 
HandleTemplate(int nLevel,sal_uInt8 & rSelector,sal_uInt8 & rVariation,xub_StrLen & rLastTemplateBracket)2867cdf0e10cSrcweir int MathType::HandleTemplate(int nLevel,sal_uInt8 &rSelector,
2868cdf0e10cSrcweir     sal_uInt8 &rVariation, xub_StrLen &rLastTemplateBracket)
2869cdf0e10cSrcweir {
2870cdf0e10cSrcweir     sal_uInt8 nOption; //This appears utterly unused
2871cdf0e10cSrcweir     *pS >> rSelector;
2872cdf0e10cSrcweir     *pS >> rVariation;
2873cdf0e10cSrcweir     *pS >> nOption;
2874cdf0e10cSrcweir     DBG_ASSERT(rSelector < 48,"Selector out of range");
2875cdf0e10cSrcweir     if ((rSelector >= 21) && (rSelector <=26))
2876cdf0e10cSrcweir     {
2877cdf0e10cSrcweir         DBG_ASSERT(nOption < 2,"Option out of range");
2878cdf0e10cSrcweir     }
2879cdf0e10cSrcweir     else if (/*(rSelector >= 0) &&*/ (rSelector <=12))
2880cdf0e10cSrcweir     {
2881cdf0e10cSrcweir         DBG_ASSERT(nOption < 3,"Option out of range");
2882cdf0e10cSrcweir     }
2883cdf0e10cSrcweir 
2884cdf0e10cSrcweir     //For the (broken) case where one subscript template ends, and there is
2885cdf0e10cSrcweir     //another one after it, mathtype handles it as if the second one was
2886cdf0e10cSrcweir     //inside the first one and renders it as sub of sub
2887cdf0e10cSrcweir     sal_Bool bRemove=sal_False;
2888cdf0e10cSrcweir     if ( (rSelector == 0xf) && (rLastTemplateBracket != STRING_NOTFOUND) )
2889cdf0e10cSrcweir     {
2890cdf0e10cSrcweir         bRemove=sal_True;
2891cdf0e10cSrcweir         for (xub_StrLen nI = rLastTemplateBracket+1; nI < rRet.Len(); nI++ )
2892cdf0e10cSrcweir             if (rRet.GetChar(nI) != ' ')
2893cdf0e10cSrcweir             {
2894cdf0e10cSrcweir                 bRemove=sal_False;
2895cdf0e10cSrcweir                 break;
2896cdf0e10cSrcweir             }
2897cdf0e10cSrcweir     }
2898cdf0e10cSrcweir 
2899cdf0e10cSrcweir     //suborderlist
2900cdf0e10cSrcweir     int nRet = HandleRecords(nLevel+1,rSelector,rVariation);
2901cdf0e10cSrcweir 
2902cdf0e10cSrcweir     if (bRemove)
2903cdf0e10cSrcweir     {
2904cdf0e10cSrcweir         rRet.Erase(rLastTemplateBracket,1);
2905cdf0e10cSrcweir         APPEND(rRet,"} ");
2906cdf0e10cSrcweir         rLastTemplateBracket = STRING_NOTFOUND;
2907cdf0e10cSrcweir     }
2908cdf0e10cSrcweir     if (rSelector == 0xf)
2909cdf0e10cSrcweir         rLastTemplateBracket = rRet.SearchBackward('}');
2910cdf0e10cSrcweir     else
2911cdf0e10cSrcweir         rLastTemplateBracket = STRING_NOTFOUND;
2912cdf0e10cSrcweir 
2913cdf0e10cSrcweir     rSelector = sal::static_int_cast< sal_uInt8 >(-1);
2914cdf0e10cSrcweir     return nRet;
2915cdf0e10cSrcweir }
2916cdf0e10cSrcweir 
HandleEmblishments()2917cdf0e10cSrcweir void MathType::HandleEmblishments()
2918cdf0e10cSrcweir {
2919cdf0e10cSrcweir     sal_uInt8 nEmbel;
2920cdf0e10cSrcweir     do
2921cdf0e10cSrcweir     {
2922cdf0e10cSrcweir         *pS >> nEmbel;
2923cdf0e10cSrcweir         switch (nEmbel)
2924cdf0e10cSrcweir         {
2925cdf0e10cSrcweir         case 0x02:
2926cdf0e10cSrcweir             APPEND(rRet," dot ");
2927cdf0e10cSrcweir             break;
2928cdf0e10cSrcweir         case 0x03:
2929cdf0e10cSrcweir             APPEND(rRet," ddot ");
2930cdf0e10cSrcweir             break;
2931cdf0e10cSrcweir         case 0x04:
2932cdf0e10cSrcweir             APPEND(rRet," dddot ");
2933cdf0e10cSrcweir             break;
2934cdf0e10cSrcweir         case 0x05:
2935cdf0e10cSrcweir             if (nPostSup == 0)
2936cdf0e10cSrcweir             {
2937cdf0e10cSrcweir                 APPEND(sPost," sup {}");
2938cdf0e10cSrcweir                 nPostSup = sPost.Len();
2939cdf0e10cSrcweir             }
2940cdf0e10cSrcweir             sPost.InsertAscii(" ' ",nPostSup-1);
2941cdf0e10cSrcweir             nPostSup += 3;
2942cdf0e10cSrcweir             break;
2943cdf0e10cSrcweir         case 0x06:
2944cdf0e10cSrcweir             if (nPostSup == 0)
2945cdf0e10cSrcweir             {
2946cdf0e10cSrcweir                 APPEND(sPost," sup {}");
2947cdf0e10cSrcweir                 nPostSup = sPost.Len();
2948cdf0e10cSrcweir             }
2949cdf0e10cSrcweir             sPost.InsertAscii(" '' ",nPostSup-1);
2950cdf0e10cSrcweir             nPostSup += 4;
2951cdf0e10cSrcweir             break;
2952cdf0e10cSrcweir         case 0x07:
2953cdf0e10cSrcweir             if (nPostlSup == 0)
2954cdf0e10cSrcweir             {
2955cdf0e10cSrcweir                 APPEND(sPost," lsup {}");
2956cdf0e10cSrcweir                 nPostlSup = sPost.Len();
2957cdf0e10cSrcweir             }
2958cdf0e10cSrcweir             sPost.InsertAscii(" ' ",nPostlSup-1);
2959cdf0e10cSrcweir             nPostlSup += 3;
2960cdf0e10cSrcweir             break;
2961cdf0e10cSrcweir         case 0x08:
2962cdf0e10cSrcweir             APPEND(rRet," tilde ");
2963cdf0e10cSrcweir             break;
2964cdf0e10cSrcweir         case 0x09:
2965cdf0e10cSrcweir             APPEND(rRet," hat ");
2966cdf0e10cSrcweir             break;
2967cdf0e10cSrcweir         case 0x0b:
2968cdf0e10cSrcweir             APPEND(rRet," vec ");
2969cdf0e10cSrcweir             break;
2970cdf0e10cSrcweir         case 0x10:
2971cdf0e10cSrcweir             APPEND(rRet," overstrike ");
2972cdf0e10cSrcweir             break;
2973cdf0e10cSrcweir         case 0x11:
2974cdf0e10cSrcweir             APPEND(rRet," bar ");
2975cdf0e10cSrcweir             break;
2976cdf0e10cSrcweir         case 0x12:
2977cdf0e10cSrcweir             if (nPostSup == 0)
2978cdf0e10cSrcweir             {
2979cdf0e10cSrcweir                 APPEND(sPost," sup {}");
2980cdf0e10cSrcweir                 nPostSup = sPost.Len();
2981cdf0e10cSrcweir             }
2982cdf0e10cSrcweir             sPost.InsertAscii(" ''' ",nPostSup-1);
2983cdf0e10cSrcweir             nPostSup += 5;
2984cdf0e10cSrcweir             break;
2985cdf0e10cSrcweir         case 0x14:
2986cdf0e10cSrcweir             APPEND(rRet," breve ");
2987cdf0e10cSrcweir             break;
2988cdf0e10cSrcweir         default:
2989cdf0e10cSrcweir             DBG_ASSERT(nEmbel < 21,"Embel out of range");
2990cdf0e10cSrcweir             break;
2991cdf0e10cSrcweir         }
2992cdf0e10cSrcweir         if (nVersion < 3)
2993cdf0e10cSrcweir             break;
2994cdf0e10cSrcweir     }while (nEmbel);
2995cdf0e10cSrcweir }
2996cdf0e10cSrcweir 
HandleSetSize()2997cdf0e10cSrcweir void MathType::HandleSetSize()
2998cdf0e10cSrcweir {
2999cdf0e10cSrcweir     sal_uInt8 nTemp;
3000cdf0e10cSrcweir     *pS >> nTemp;
3001cdf0e10cSrcweir     switch (nTemp)
3002cdf0e10cSrcweir     {
3003cdf0e10cSrcweir         case 101:
3004cdf0e10cSrcweir             *pS >> nLSize;
3005cdf0e10cSrcweir             nLSize = -nLSize;
3006cdf0e10cSrcweir             break;
3007cdf0e10cSrcweir         case 100:
3008cdf0e10cSrcweir             *pS >> nTemp;
3009cdf0e10cSrcweir             nLSize = nTemp;
3010cdf0e10cSrcweir             *pS >> nDSize;
3011cdf0e10cSrcweir             break;
3012cdf0e10cSrcweir         default:
3013cdf0e10cSrcweir             nLSize = nTemp;
3014cdf0e10cSrcweir             *pS >> nTemp;
3015cdf0e10cSrcweir             nDSize = nTemp-128;
3016cdf0e10cSrcweir             break;
3017cdf0e10cSrcweir     }
3018cdf0e10cSrcweir }
3019cdf0e10cSrcweir 
HandleChar(xub_StrLen & rTextStart,int & rSetSize,int nLevel,sal_uInt8 nTag,sal_uInt8 nSelector,sal_uInt8 nVariation,sal_Bool bSilent)3020cdf0e10cSrcweir int MathType::HandleChar(xub_StrLen &rTextStart,int &rSetSize,int nLevel,
3021cdf0e10cSrcweir     sal_uInt8 nTag,sal_uInt8 nSelector,sal_uInt8 nVariation, sal_Bool bSilent)
3022cdf0e10cSrcweir {
3023cdf0e10cSrcweir     sal_Unicode nChar;
3024cdf0e10cSrcweir     int nRet=1;
3025cdf0e10cSrcweir 
3026cdf0e10cSrcweir     if (xfAUTO(nTag))
3027cdf0e10cSrcweir     {
3028cdf0e10cSrcweir     //This is a candidate for function recognition, whatever
3029cdf0e10cSrcweir     //that is!
3030cdf0e10cSrcweir     }
3031cdf0e10cSrcweir 
3032cdf0e10cSrcweir     sal_uInt8 nOldTypeFace = nTypeFace;
3033cdf0e10cSrcweir     *pS >> nTypeFace;
3034cdf0e10cSrcweir     if (nVersion < 3)
3035cdf0e10cSrcweir     {
3036cdf0e10cSrcweir         sal_uInt8 nChar8;
3037cdf0e10cSrcweir         *pS >> nChar8;
3038cdf0e10cSrcweir         nChar = nChar8;
3039cdf0e10cSrcweir     }
3040cdf0e10cSrcweir     else
3041cdf0e10cSrcweir         *pS >> nChar;
3042cdf0e10cSrcweir 
3043cdf0e10cSrcweir     /*
3044cdf0e10cSrcweir     ##912##
3045cdf0e10cSrcweir     bad character, old mathtype < 3 has these
3046cdf0e10cSrcweir     */
3047cdf0e10cSrcweir     if (nChar < 0x20)
3048cdf0e10cSrcweir         return nRet;
3049cdf0e10cSrcweir 
3050cdf0e10cSrcweir     if (xfEMBELL(nTag))
3051cdf0e10cSrcweir     {
3052cdf0e10cSrcweir         //A bit tricky, the character emblishments for
3053cdf0e10cSrcweir         //mathtype can all be listed after eachother, in
3054cdf0e10cSrcweir         //starmath some must go before the character and some
3055cdf0e10cSrcweir         //must go after. In addition some of the emblishments
3056cdf0e10cSrcweir         //may repeated and in starmath some of these groups
3057cdf0e10cSrcweir         //must be gathered together. sPost is the portion that
3058cdf0e10cSrcweir         //follows the char and nPostSup and nPostlSup are the
3059cdf0e10cSrcweir         //indexes at which this class of emblishment is
3060cdf0e10cSrcweir         //collated together
3061cdf0e10cSrcweir         sPost.Erase();
3062cdf0e10cSrcweir         nPostSup = nPostlSup = 0;
3063cdf0e10cSrcweir         int nOriglen=rRet.Len()-rTextStart;
3064cdf0e10cSrcweir         APPEND(rRet," {");  // #i24340# make what would be "vec {A}_n" become "{vec {A}}_n"
3065cdf0e10cSrcweir         if ((!bSilent) && ((nOriglen) > 1))
3066cdf0e10cSrcweir             rRet += '\"';
3067cdf0e10cSrcweir         nRet = HandleRecords(nLevel+1,nSelector,nVariation);
3068cdf0e10cSrcweir         if (!bSilent)
3069cdf0e10cSrcweir         {
3070cdf0e10cSrcweir             if (nOriglen > 1)
3071cdf0e10cSrcweir             {
3072cdf0e10cSrcweir                 String aStr;
3073cdf0e10cSrcweir                 TypeFaceToString(aStr,nOldTypeFace);
3074cdf0e10cSrcweir                 aStr += '\"';
3075cdf0e10cSrcweir                 rRet.Insert(aStr,rTextStart);
3076cdf0e10cSrcweir 
3077cdf0e10cSrcweir                 aStr.Erase();
3078cdf0e10cSrcweir                 TypeFaceToString(aStr,nTypeFace);
3079cdf0e10cSrcweir                 rRet.Append(aStr);
3080cdf0e10cSrcweir                 rRet += '{';
3081cdf0e10cSrcweir             }
3082cdf0e10cSrcweir             else
3083cdf0e10cSrcweir                 APPEND(rRet," {");
3084cdf0e10cSrcweir             rTextStart = rRet.Len();
3085cdf0e10cSrcweir         }
3086cdf0e10cSrcweir     }
3087cdf0e10cSrcweir 
3088cdf0e10cSrcweir     if (!bSilent)
3089cdf0e10cSrcweir     {
3090cdf0e10cSrcweir         xub_StrLen nOldLen = rRet.Len();
3091cdf0e10cSrcweir         //nLastSize = nCurSize;
3092cdf0e10cSrcweir         if (
3093cdf0e10cSrcweir             HandleSize(nLSize,nDSize,rSetSize) ||
3094cdf0e10cSrcweir             (nOldTypeFace != nTypeFace)
3095cdf0e10cSrcweir            )
3096cdf0e10cSrcweir         {
3097cdf0e10cSrcweir             if ((nOldLen - rTextStart) > 1)
3098cdf0e10cSrcweir             {
3099cdf0e10cSrcweir                 rRet.InsertAscii("\"",nOldLen);
3100cdf0e10cSrcweir                 String aStr;
3101cdf0e10cSrcweir                 TypeFaceToString(aStr,nOldTypeFace);
3102cdf0e10cSrcweir                 aStr += '\"';
3103cdf0e10cSrcweir                 rRet.Insert(aStr,rTextStart);
3104cdf0e10cSrcweir             }
3105cdf0e10cSrcweir             rTextStart = rRet.Len();
3106cdf0e10cSrcweir         }
3107cdf0e10cSrcweir         nOldLen = rRet.Len();
3108cdf0e10cSrcweir         if (!LookupChar(nChar,rRet,nVersion,nTypeFace))
3109cdf0e10cSrcweir         {
3110cdf0e10cSrcweir             if (nOldLen - rTextStart > 1)
3111cdf0e10cSrcweir             {
3112cdf0e10cSrcweir                 rRet.InsertAscii("\"",nOldLen);
3113cdf0e10cSrcweir                 String aStr;
3114cdf0e10cSrcweir                 TypeFaceToString(aStr,nOldTypeFace);
3115cdf0e10cSrcweir                 aStr += '\"';
3116cdf0e10cSrcweir                 rRet.Insert(aStr,rTextStart);
3117cdf0e10cSrcweir             }
3118cdf0e10cSrcweir             rTextStart = rRet.Len();
3119cdf0e10cSrcweir         }
3120cdf0e10cSrcweir         lcl_PrependDummyTerm(rRet, rTextStart);
3121cdf0e10cSrcweir     }
3122cdf0e10cSrcweir 
3123cdf0e10cSrcweir     if ((xfEMBELL(nTag)) && (!bSilent))
3124cdf0e10cSrcweir     {
3125cdf0e10cSrcweir         rRet += '}';    // #i24340# make what would be "vec {A}_n" become "{vec {A}}_n"
3126cdf0e10cSrcweir         rRet += '}';
3127cdf0e10cSrcweir         rRet += sPost;
3128cdf0e10cSrcweir         rTextStart = rRet.Len();
3129cdf0e10cSrcweir     }
3130cdf0e10cSrcweir     return nRet;
3131cdf0e10cSrcweir }
3132cdf0e10cSrcweir 
HandleLim(SmNode * pNode,int nLevel)3133cdf0e10cSrcweir sal_Bool MathType::HandleLim(SmNode *pNode,int nLevel)
3134cdf0e10cSrcweir {
3135cdf0e10cSrcweir     sal_Bool bRet=0;
3136cdf0e10cSrcweir     //Special case for the "lim" option in StarMath
3137cdf0e10cSrcweir     if ((pNode->GetToken().eType == TLIM)
3138cdf0e10cSrcweir         || (pNode->GetToken().eType == TLIMSUP)
3139cdf0e10cSrcweir         || (pNode->GetToken().eType == TLIMINF)
3140cdf0e10cSrcweir         )
3141cdf0e10cSrcweir     {
3142cdf0e10cSrcweir         if (pNode->GetSubNode(1))
3143cdf0e10cSrcweir         {
3144cdf0e10cSrcweir             sal_uInt8 nVariation2=HandleCScript(pNode->GetSubNode(0),NULL,
3145cdf0e10cSrcweir                 nLevel);
3146cdf0e10cSrcweir 
3147cdf0e10cSrcweir             *pS << sal_uInt8(0x0A);
3148cdf0e10cSrcweir             *pS << sal_uInt8(LINE); //line
3149cdf0e10cSrcweir             *pS << sal_uInt8(CHAR|0x10);
3150cdf0e10cSrcweir             *pS << sal_uInt8(0x82);
3151cdf0e10cSrcweir             *pS << sal_uInt16('l');
3152cdf0e10cSrcweir             *pS << sal_uInt8(CHAR|0x10);
3153cdf0e10cSrcweir             *pS << sal_uInt8(0x82);
3154cdf0e10cSrcweir             *pS << sal_uInt16('i');
3155cdf0e10cSrcweir             *pS << sal_uInt8(CHAR|0x10);
3156cdf0e10cSrcweir             *pS << sal_uInt8(0x82);
3157cdf0e10cSrcweir             *pS << sal_uInt16('m');
3158cdf0e10cSrcweir 
3159cdf0e10cSrcweir             if (pNode->GetToken().eType == TLIMSUP)
3160cdf0e10cSrcweir             {
3161cdf0e10cSrcweir                 *pS << sal_uInt8(CHAR); //some space
3162cdf0e10cSrcweir                 *pS << sal_uInt8(0x98);
3163cdf0e10cSrcweir                 *pS << sal_uInt16(0xEB04);
3164cdf0e10cSrcweir 
3165cdf0e10cSrcweir                 *pS << sal_uInt8(CHAR|0x10);
3166cdf0e10cSrcweir                 *pS << sal_uInt8(0x82);
3167cdf0e10cSrcweir                 *pS << sal_uInt16('s');
3168cdf0e10cSrcweir                 *pS << sal_uInt8(CHAR|0x10);
3169cdf0e10cSrcweir                 *pS << sal_uInt8(0x82);
3170cdf0e10cSrcweir                 *pS << sal_uInt16('u');
3171cdf0e10cSrcweir                 *pS << sal_uInt8(CHAR|0x10);
3172cdf0e10cSrcweir                 *pS << sal_uInt8(0x82);
3173cdf0e10cSrcweir                 *pS << sal_uInt16('p');
3174cdf0e10cSrcweir             }
3175cdf0e10cSrcweir             else if (pNode->GetToken().eType == TLIMINF)
3176cdf0e10cSrcweir             {
3177cdf0e10cSrcweir                 *pS << sal_uInt8(CHAR); //some space
3178cdf0e10cSrcweir                 *pS << sal_uInt8(0x98);
3179cdf0e10cSrcweir                 *pS << sal_uInt16(0xEB04);
3180cdf0e10cSrcweir 
3181cdf0e10cSrcweir                 *pS << sal_uInt8(CHAR|0x10);
3182cdf0e10cSrcweir                 *pS << sal_uInt8(0x82);
3183cdf0e10cSrcweir                 *pS << sal_uInt16('i');
3184cdf0e10cSrcweir                 *pS << sal_uInt8(CHAR|0x10);
3185cdf0e10cSrcweir                 *pS << sal_uInt8(0x82);
3186cdf0e10cSrcweir                 *pS << sal_uInt16('n');
3187cdf0e10cSrcweir                 *pS << sal_uInt8(CHAR|0x10);
3188cdf0e10cSrcweir                 *pS << sal_uInt8(0x82);
3189cdf0e10cSrcweir                 *pS << sal_uInt16('f');
3190cdf0e10cSrcweir             }
3191cdf0e10cSrcweir 
3192cdf0e10cSrcweir 
3193cdf0e10cSrcweir             *pS << sal_uInt8(CHAR); //some space
3194cdf0e10cSrcweir             *pS << sal_uInt8(0x98);
3195cdf0e10cSrcweir             *pS << sal_uInt16(0xEB04);
3196cdf0e10cSrcweir 
3197cdf0e10cSrcweir             if (nVariation2 != 0xff)
3198cdf0e10cSrcweir             {
3199cdf0e10cSrcweir                 *pS << sal_uInt8(END);
3200cdf0e10cSrcweir                 *pS << sal_uInt8(END);
3201cdf0e10cSrcweir             }
3202cdf0e10cSrcweir             HandleNodes(pNode->GetSubNode(1),nLevel+1);
3203cdf0e10cSrcweir             //*pS << sal_uInt8(END); //options
3204cdf0e10cSrcweir             bRet = 1;
3205cdf0e10cSrcweir         }
3206cdf0e10cSrcweir     }
3207cdf0e10cSrcweir     return bRet;
3208cdf0e10cSrcweir }
3209cdf0e10cSrcweir 
HandleMAlign(SmNode * pNode,int nLevel)3210cdf0e10cSrcweir void MathType::HandleMAlign(SmNode *pNode,int nLevel)
3211cdf0e10cSrcweir {
3212cdf0e10cSrcweir     sal_uInt8 nPushedHAlign=nHAlign;
3213cdf0e10cSrcweir     switch(pNode->GetToken().eType)
3214cdf0e10cSrcweir     {
3215cdf0e10cSrcweir         case TALIGNC:
3216cdf0e10cSrcweir             nHAlign=2;
3217cdf0e10cSrcweir             break;
3218cdf0e10cSrcweir         case TALIGNR:
3219cdf0e10cSrcweir             nHAlign=3;
3220cdf0e10cSrcweir             break;
3221cdf0e10cSrcweir         default:
3222cdf0e10cSrcweir             nHAlign=1;
3223cdf0e10cSrcweir             break;
3224cdf0e10cSrcweir     }
3225cdf0e10cSrcweir     sal_uInt16  nSize = pNode->GetNumSubNodes();
3226cdf0e10cSrcweir     for (sal_uInt16 i = 0; i < nSize; i++)
3227cdf0e10cSrcweir         if (SmNode *pTemp = pNode->GetSubNode(i))
3228cdf0e10cSrcweir             HandleNodes(pTemp,nLevel+1);
3229cdf0e10cSrcweir     nHAlign=nPushedHAlign;
3230cdf0e10cSrcweir }
3231cdf0e10cSrcweir 
HandleMath(SmNode * pNode,int)3232cdf0e10cSrcweir void MathType::HandleMath(SmNode *pNode, int /*nLevel*/)
3233cdf0e10cSrcweir {
3234cdf0e10cSrcweir     if (pNode->GetToken().eType == TMLINE)
3235cdf0e10cSrcweir     {
3236cdf0e10cSrcweir         *pS << sal_uInt8(END);
3237cdf0e10cSrcweir         *pS << sal_uInt8(LINE);
3238cdf0e10cSrcweir         bIsReInterpBrace=1;
3239cdf0e10cSrcweir         return;
3240cdf0e10cSrcweir     }
3241cdf0e10cSrcweir     SmMathSymbolNode *pTemp=(SmMathSymbolNode *)pNode;
3242cdf0e10cSrcweir     for(xub_StrLen i=0;i<pTemp->GetText().Len();i++)
3243cdf0e10cSrcweir     {
3244cdf0e10cSrcweir         sal_Unicode nArse = Convert(pTemp->GetText().GetChar(i));
3245cdf0e10cSrcweir         if ((nArse == 0x2224) || (nArse == 0x2288) || (nArse == 0x2285) ||
3246cdf0e10cSrcweir             (nArse == 0x2289))
3247cdf0e10cSrcweir         {
3248cdf0e10cSrcweir             *pS << sal_uInt8(CHAR|0x20);
3249cdf0e10cSrcweir         }
3250cdf0e10cSrcweir         else if ((nPendingAttributes) &&
3251cdf0e10cSrcweir                 (i == ((pTemp->GetText().Len()+1)/2)-1))
3252cdf0e10cSrcweir             {
3253cdf0e10cSrcweir                 *pS << sal_uInt8(0x22);
3254cdf0e10cSrcweir             }
3255cdf0e10cSrcweir         else
3256cdf0e10cSrcweir             *pS << sal_uInt8(CHAR); //char without formula recognition
3257cdf0e10cSrcweir         //The typeface seems to be MTEXTRA for unicode characters,
3258cdf0e10cSrcweir         //though how to determine when mathtype chooses one over
3259cdf0e10cSrcweir         //the other is unknown. This should do the trick
3260cdf0e10cSrcweir         //nevertheless.
3261cdf0e10cSrcweir         sal_uInt8 nBias;
3262cdf0e10cSrcweir         if ( (nArse == 0x2213) || (nArse == 0x2218) ||
3263cdf0e10cSrcweir             (nArse == 0x210F) || (
3264cdf0e10cSrcweir                 (nArse >= 0x22EE) && (nArse <= 0x22FF)
3265cdf0e10cSrcweir             ))
3266cdf0e10cSrcweir         {
3267cdf0e10cSrcweir             nBias = 0xB; //typeface
3268cdf0e10cSrcweir         }
3269cdf0e10cSrcweir         else if ((nArse > 0x2000) || (nArse == 0x00D7))
3270cdf0e10cSrcweir             nBias = 0x6; //typeface
3271cdf0e10cSrcweir         else if (nArse == 0x3d1)
3272cdf0e10cSrcweir             nBias = 0x4;
3273cdf0e10cSrcweir         else if ((nArse > 0xFF) && ((nArse < 0x393) || (nArse > 0x3c9)))
3274cdf0e10cSrcweir             nBias = 0xB; //typeface
3275cdf0e10cSrcweir         else if ((nArse == 0x2F) || (nArse == 0x2225))
3276cdf0e10cSrcweir             nBias = 0x2; //typeface
3277cdf0e10cSrcweir         else
3278cdf0e10cSrcweir             nBias = 0x3; //typeface
3279cdf0e10cSrcweir 
3280cdf0e10cSrcweir         *pS << sal_uInt8(nSpec+nBias+128); //typeface
3281cdf0e10cSrcweir 
3282cdf0e10cSrcweir         if (nArse == 0x2224)
3283cdf0e10cSrcweir         {
3284cdf0e10cSrcweir             *pS << sal_uInt16(0x7C);
3285cdf0e10cSrcweir             *pS << sal_uInt8(EMBEL);
3286cdf0e10cSrcweir             *pS << sal_uInt8(0x0A);
3287cdf0e10cSrcweir             *pS << sal_uInt8(END); //end embel
3288cdf0e10cSrcweir             *pS << sal_uInt8(END); //end embel
3289cdf0e10cSrcweir         }
3290cdf0e10cSrcweir         else if (nArse == 0x2225)
3291cdf0e10cSrcweir             *pS << sal_uInt16(0xEC09);
3292cdf0e10cSrcweir         else if (nArse == 0xE421)
3293cdf0e10cSrcweir             *pS << sal_uInt16(0x2265);
3294cdf0e10cSrcweir         else if (nArse == 0x230A)
3295cdf0e10cSrcweir             *pS << sal_uInt16(0xF8F0);
3296cdf0e10cSrcweir         else if (nArse == 0x230B)
3297cdf0e10cSrcweir             *pS << sal_uInt16(0xF8FB);
3298cdf0e10cSrcweir         else if (nArse == 0xE425)
3299cdf0e10cSrcweir             *pS << sal_uInt16(0x2264);
3300cdf0e10cSrcweir         else if (nArse == 0x226A)
3301cdf0e10cSrcweir         {
3302cdf0e10cSrcweir             *pS << sal_uInt16(0x3C);
3303cdf0e10cSrcweir             *pS << sal_uInt8(CHAR);
3304cdf0e10cSrcweir             *pS << sal_uInt8(0x98);
3305cdf0e10cSrcweir             *pS << sal_uInt16(0xEB01);
3306cdf0e10cSrcweir             *pS << sal_uInt8(CHAR);
3307cdf0e10cSrcweir             *pS << sal_uInt8(0x86);
3308cdf0e10cSrcweir             *pS << sal_uInt16(0x3c);
3309cdf0e10cSrcweir         }
3310cdf0e10cSrcweir         else if (nArse == 0x2288)
3311cdf0e10cSrcweir         {
3312cdf0e10cSrcweir             *pS << sal_uInt16(0x2286);
3313cdf0e10cSrcweir             *pS << sal_uInt8(EMBEL);
3314cdf0e10cSrcweir             *pS << sal_uInt8(0x0A);
3315cdf0e10cSrcweir             *pS << sal_uInt8(END); //end embel
3316cdf0e10cSrcweir             *pS << sal_uInt8(END); //end embel
3317cdf0e10cSrcweir         }
3318cdf0e10cSrcweir         else if (nArse == 0x2289)
3319cdf0e10cSrcweir         {
3320cdf0e10cSrcweir             *pS << sal_uInt16(0x2287);
3321cdf0e10cSrcweir             *pS << sal_uInt8(EMBEL);
3322cdf0e10cSrcweir             *pS << sal_uInt8(0x0A);
3323cdf0e10cSrcweir             *pS << sal_uInt8(END); //end embel
3324cdf0e10cSrcweir             *pS << sal_uInt8(END); //end embel
3325cdf0e10cSrcweir         }
3326cdf0e10cSrcweir         else if (nArse == 0x2285)
3327cdf0e10cSrcweir         {
3328cdf0e10cSrcweir             *pS << sal_uInt16(0x2283);
3329cdf0e10cSrcweir             *pS << sal_uInt8(EMBEL);
3330cdf0e10cSrcweir             *pS << sal_uInt8(0x0A);
3331cdf0e10cSrcweir             *pS << sal_uInt8(END); //end embel
3332cdf0e10cSrcweir             *pS << sal_uInt8(END); //end embel
3333cdf0e10cSrcweir         }
3334cdf0e10cSrcweir         else
3335cdf0e10cSrcweir             *pS << nArse;
3336cdf0e10cSrcweir     }
3337cdf0e10cSrcweir     nPendingAttributes = 0;
3338cdf0e10cSrcweir }
3339cdf0e10cSrcweir 
HandleAttributes(SmNode * pNode,int nLevel)3340cdf0e10cSrcweir void MathType::HandleAttributes(SmNode *pNode,int nLevel)
3341cdf0e10cSrcweir {
3342cdf0e10cSrcweir     int nOldPending = 0;
3343cdf0e10cSrcweir     //sal_uInt16  nSize = pNode->GetNumSubNodes();
3344cdf0e10cSrcweir     SmNode *pTemp       = 0;
3345cdf0e10cSrcweir     SmTextNode *pIsText = 0;
3346cdf0e10cSrcweir 
3347cdf0e10cSrcweir     //SmTextNode *pTemp=(SmTextNode *)pNode;
3348cdf0e10cSrcweir     //for(int i=0;i<pTemp->GetText().Len();i++)
3349cdf0e10cSrcweir 
3350cdf0e10cSrcweir     if (NULL != (pTemp = pNode->GetSubNode(0)))
3351cdf0e10cSrcweir     {
3352cdf0e10cSrcweir         pIsText = (SmTextNode *)pNode->GetSubNode(1);
3353cdf0e10cSrcweir 
3354cdf0e10cSrcweir         switch (pTemp->GetToken().eType)
3355cdf0e10cSrcweir         {
3356cdf0e10cSrcweir         case TWIDEVEC:
3357cdf0e10cSrcweir             //theres just no way we can now handle any character
3358cdf0e10cSrcweir             //attributes (from mathtypes perspective) centered
3359cdf0e10cSrcweir             //over an expression but above template attributes
3360cdf0e10cSrcweir             //such as widevec and similiar constructs
3361cdf0e10cSrcweir             //we have to drop them
3362cdf0e10cSrcweir             nOldPending = StartTemplate(0x2f,0x01);
3363cdf0e10cSrcweir             break;
3364cdf0e10cSrcweir         case TCHECK: //Not Exportable
3365cdf0e10cSrcweir         case TACUTE: //Not Exportable
3366cdf0e10cSrcweir         case TGRAVE: //Not Exportable
3367cdf0e10cSrcweir         case TCIRCLE: //Not Exportable
3368cdf0e10cSrcweir         case TWIDETILDE: //Not Exportable
3369cdf0e10cSrcweir         case TWIDEHAT: //Not Exportable
3370cdf0e10cSrcweir             break;
3371cdf0e10cSrcweir         case TUNDERLINE:
3372cdf0e10cSrcweir             nOldPending = StartTemplate(0x10);
3373cdf0e10cSrcweir             break;
3374cdf0e10cSrcweir         case TOVERLINE: //If the next node is not text
3375cdf0e10cSrcweir                         //or text with more than one char
3376cdf0e10cSrcweir             if ((pIsText->GetToken().eType != TTEXT) ||
3377cdf0e10cSrcweir                 (pIsText->GetText().Len() > 1))
3378cdf0e10cSrcweir                 nOldPending = StartTemplate(0x11);
3379cdf0e10cSrcweir             break;
3380cdf0e10cSrcweir         default:
3381cdf0e10cSrcweir             nPendingAttributes++;
3382cdf0e10cSrcweir             break;
3383cdf0e10cSrcweir         }
3384cdf0e10cSrcweir     }
3385cdf0e10cSrcweir 
3386cdf0e10cSrcweir     if (pIsText)
3387cdf0e10cSrcweir         HandleNodes(pIsText,nLevel+1);
3388cdf0e10cSrcweir 
3389cdf0e10cSrcweir     switch (pTemp->GetToken().eType)
3390cdf0e10cSrcweir     {
3391cdf0e10cSrcweir         case TWIDEVEC:
3392cdf0e10cSrcweir         case TUNDERLINE:
3393cdf0e10cSrcweir             EndTemplate(nOldPending);
3394cdf0e10cSrcweir             break;
3395cdf0e10cSrcweir         case TOVERLINE:
3396cdf0e10cSrcweir             if ((pIsText->GetToken().eType != TTEXT) ||
3397cdf0e10cSrcweir                 (pIsText->GetText().Len() > 1))
3398cdf0e10cSrcweir                 EndTemplate(nOldPending);
3399cdf0e10cSrcweir             break;
3400cdf0e10cSrcweir         default:
3401cdf0e10cSrcweir             break;
3402cdf0e10cSrcweir     }
3403cdf0e10cSrcweir 
3404cdf0e10cSrcweir     //if there was no suitable place to put the attribute,
3405cdf0e10cSrcweir     //then we have to just give up on it
3406cdf0e10cSrcweir     if (nPendingAttributes)
3407cdf0e10cSrcweir         nPendingAttributes--;
3408cdf0e10cSrcweir     else
3409cdf0e10cSrcweir     {
3410cdf0e10cSrcweir         if ((nInsertion != 0) && NULL != (pTemp = pNode->GetSubNode(0)))
3411cdf0e10cSrcweir         {
3412cdf0e10cSrcweir             sal_uLong nPos = pS->Tell();
3413cdf0e10cSrcweir             nInsertion--;
3414cdf0e10cSrcweir             pS->Seek(nInsertion);
3415cdf0e10cSrcweir             switch(pTemp->GetToken().eType)
3416cdf0e10cSrcweir             {
3417cdf0e10cSrcweir             case TACUTE: //Not Exportable
3418cdf0e10cSrcweir             case TGRAVE: //Not Exportable
3419cdf0e10cSrcweir             case TCIRCLE: //Not Exportable
3420cdf0e10cSrcweir                 break;
3421cdf0e10cSrcweir             case TCDOT:
3422cdf0e10cSrcweir                 *pS << sal_uInt8(2);
3423cdf0e10cSrcweir                 break;
3424cdf0e10cSrcweir             case TDDOT:
3425cdf0e10cSrcweir                 *pS << sal_uInt8(3);
3426cdf0e10cSrcweir                 break;
3427cdf0e10cSrcweir             case TDDDOT:
3428cdf0e10cSrcweir                 *pS << sal_uInt8(4);
3429cdf0e10cSrcweir                 break;
3430cdf0e10cSrcweir             case TTILDE:
3431cdf0e10cSrcweir                 *pS << sal_uInt8(8);
3432cdf0e10cSrcweir                 break;
3433cdf0e10cSrcweir             case THAT:
3434cdf0e10cSrcweir                 *pS << sal_uInt8(9);
3435cdf0e10cSrcweir                 break;
3436cdf0e10cSrcweir             case TVEC:
3437cdf0e10cSrcweir                 *pS << sal_uInt8(11);
3438cdf0e10cSrcweir                 break;
3439cdf0e10cSrcweir             case TOVERSTRIKE:
3440cdf0e10cSrcweir                 *pS << sal_uInt8(16);
3441cdf0e10cSrcweir                 break;
3442cdf0e10cSrcweir             case TOVERLINE:
3443cdf0e10cSrcweir                 if ((pIsText->GetToken().eType == TTEXT) &&
3444cdf0e10cSrcweir                     (pIsText->GetText().Len() == 1))
3445cdf0e10cSrcweir                     *pS << sal_uInt8(17);
3446cdf0e10cSrcweir                 break;
3447cdf0e10cSrcweir             case TBREVE:
3448cdf0e10cSrcweir                 *pS << sal_uInt8(20);
3449cdf0e10cSrcweir                 break;
3450cdf0e10cSrcweir             case TWIDEVEC:
3451cdf0e10cSrcweir             case TUNDERLINE:
3452cdf0e10cSrcweir             case TWIDETILDE:
3453cdf0e10cSrcweir             case TWIDEHAT:
3454cdf0e10cSrcweir                 break;
3455cdf0e10cSrcweir             case TBAR:
3456cdf0e10cSrcweir                 *pS << sal_uInt8(17);
3457cdf0e10cSrcweir                 break;
3458cdf0e10cSrcweir             default:
3459cdf0e10cSrcweir                 *pS << sal_uInt8(0x2);
3460cdf0e10cSrcweir                 break;
3461cdf0e10cSrcweir             }
3462cdf0e10cSrcweir         pS->Seek(nPos);
3463cdf0e10cSrcweir         }
3464cdf0e10cSrcweir     }
3465cdf0e10cSrcweir }
3466cdf0e10cSrcweir 
HandleText(SmNode * pNode,int)3467cdf0e10cSrcweir void MathType::HandleText(SmNode *pNode, int /*nLevel*/)
3468cdf0e10cSrcweir {
3469cdf0e10cSrcweir     SmTextNode *pTemp=(SmTextNode *)pNode;
3470cdf0e10cSrcweir     for(xub_StrLen i=0;i<pTemp->GetText().Len();i++)
3471cdf0e10cSrcweir     {
3472cdf0e10cSrcweir         if ((nPendingAttributes) &&
3473cdf0e10cSrcweir             (i == ((pTemp->GetText().Len()+1)/2)-1))
3474cdf0e10cSrcweir         {
3475cdf0e10cSrcweir             *pS << sal_uInt8(0x22);     //char, with attributes right
3476cdf0e10cSrcweir                                 //after the character
3477cdf0e10cSrcweir         }
3478cdf0e10cSrcweir         else
3479cdf0e10cSrcweir             *pS << sal_uInt8(CHAR);
3480cdf0e10cSrcweir             //*pS << sal_uInt8(CHAR|0x10); //char with formula recognition
3481cdf0e10cSrcweir 
3482cdf0e10cSrcweir #if 1
3483cdf0e10cSrcweir         sal_uInt8 nFace = 0x1;
3484cdf0e10cSrcweir         if (pNode->GetFont().GetItalic() == ITALIC_NORMAL)
3485cdf0e10cSrcweir             nFace = 0x3;
3486cdf0e10cSrcweir         else if (pNode->GetFont().GetWeight() == WEIGHT_BOLD)
3487cdf0e10cSrcweir             nFace = 0x7;
3488cdf0e10cSrcweir         *pS << sal_uInt8(nFace+128); //typeface
3489cdf0e10cSrcweir #else
3490cdf0e10cSrcweir         if ((pTemp->GetText().GetChar(i) >= '0') &&
3491cdf0e10cSrcweir             (pTemp->GetText().GetChar(i) <= '9'))
3492cdf0e10cSrcweir             *pS << sal_uInt8(0x8+128); //typeface
3493cdf0e10cSrcweir         else
3494cdf0e10cSrcweir             *pS << sal_uInt8(0x3+128); //typeface
3495cdf0e10cSrcweir #endif
3496cdf0e10cSrcweir         sal_uInt16 nChar = pTemp->GetText().GetChar(i);
3497cdf0e10cSrcweir         *pS << Convert(nChar);
3498cdf0e10cSrcweir 
3499cdf0e10cSrcweir         //Mathtype can only have these sort of character
3500cdf0e10cSrcweir         //attributes on a single character, starmath can put them
3501cdf0e10cSrcweir         //anywhere, when the entity involved is a text run this is
3502cdf0e10cSrcweir         //a large effort to place the character attribute on the
3503cdf0e10cSrcweir         //central mathtype character so that it does pretty much
3504cdf0e10cSrcweir         //what the user probably has in mind. The attributes
3505cdf0e10cSrcweir         //filled in here are dummy ones which are replaced in the
3506cdf0e10cSrcweir         //ATTRIBUT handler if a suitable location for the
3507cdf0e10cSrcweir         //attributes was found here. Unfortunately it is
3508cdf0e10cSrcweir         //possible for starmath to place character attributes on
3509cdf0e10cSrcweir         //entities which cannot occur in mathtype e.g. a Summation
3510cdf0e10cSrcweir         //symbol so these attributes may be lost
3511cdf0e10cSrcweir         if ((nPendingAttributes) &&
3512cdf0e10cSrcweir             (i == ((pTemp->GetText().Len()+1)/2)-1))
3513cdf0e10cSrcweir         {
3514cdf0e10cSrcweir             *pS << sal_uInt8(EMBEL);
3515cdf0e10cSrcweir             while (nPendingAttributes)
3516cdf0e10cSrcweir             {
3517cdf0e10cSrcweir                 *pS << sal_uInt8(2);
3518cdf0e10cSrcweir                 //wedge the attributes in here and clear
3519cdf0e10cSrcweir                 //the pending stack
3520cdf0e10cSrcweir                 nPendingAttributes--;
3521cdf0e10cSrcweir             }
3522cdf0e10cSrcweir             nInsertion=pS->Tell();
3523cdf0e10cSrcweir             *pS << sal_uInt8(END); //end embel
3524cdf0e10cSrcweir             *pS << sal_uInt8(END); //end embel
3525cdf0e10cSrcweir         }
3526cdf0e10cSrcweir     }
3527cdf0e10cSrcweir }
3528cdf0e10cSrcweir 
3529cdf0e10cSrcweir /* vi:set tabstop=4 shiftwidth=4 expandtab: */
3530