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