Annotation of Amaya/amaya/MathMLbuilder.c, revision 1.70
1.1 cvs 1: /*
2: *
1.60 cvs 3: * (c) COPYRIGHT MIT and INRIA, 1996-2000
1.1 cvs 4: * Please first read the full copyright statement in file COPYRIGHT.
5: *
6: */
7:
8: /*
9: *
10: * MathMLbuilder
11: *
12: * Author: V. Quint
13: */
14:
1.51 cvs 15:
1.1 cvs 16: #define THOT_EXPORT extern
1.4 cvs 17: #include "amaya.h"
1.25 cvs 18: #include "css.h"
1.59 cvs 19: #include "html2thot_f.h"
1.25 cvs 20: #include "MathML.h"
21: #include "parser.h"
1.59 cvs 22: #include "styleparser_f.h"
23: #include "style.h"
24: #include "undo.h"
1.1 cvs 25:
1.44 cvs 26: typedef CHAR_T MathEntityName[30];
1.1 cvs 27: typedef struct _MathEntity
28: { /* a Math entity representing an operator char */
29: MathEntityName MentityName; /* entity name */
30: int charCode; /* decimal code of char */
1.15 cvs 31: CHAR_T alphabet; /* 'L' = ISO-Latin-1, 'G' = Symbol */
1.1 cvs 32: }
33: MathEntity;
34:
35: static MathEntity MathEntityTable[] =
36: {
37: /* This table MUST be in alphabetical order */
38: /* This table contains characters from the Symbol font plus some
39: specific MathML entities */
1.44 cvs 40: {TEXT("Agr"), 65, 'G'},
41: {TEXT("And"), 217, 'G'},
42: {TEXT("ApplyFunction"), 32, 'L'}, /* render as white space */
43: {TEXT("Backslash"), 92, 'L'},
44: {TEXT("Bgr"), 66, 'G'},
45: {TEXT("Cap"), 199, 'G'},
46: {TEXT("CenterDot"), 215, 'G'},
47: {TEXT("CirclePlus"), 197, 'G'},
48: {TEXT("CircleTimes"), 196, 'G'},
49: {TEXT("Colon"), 58, 'G'},
50: {TEXT("Congruent"), 64, 'G'},
51: {TEXT("Cup"), 200, 'G'},
1.52 cvs 52: {TEXT("Del"), 209, 'G'},
1.44 cvs 53: {TEXT("Delta"), 68, 'G'},
54: {TEXT("Diamond"), 168, 'G'},
1.53 cvs 55: {TEXT("DifferentialD"), 100, 'L'},
1.44 cvs 56: {TEXT("DoubleDownArrow"), 223, 'G'},
57: {TEXT("DoubleLeftArrow"), 220, 'G'},
58: {TEXT("DoubleLeftRightArrow"), 219, 'G'},
59: {TEXT("DoubleRightArrow"), 222, 'G'},
60: {TEXT("DoubleUpArrow"), 221, 'G'},
61: {TEXT("DownArrow"), 175, 'G'},
62: {TEXT("DownTee"), 94, 'G'},
63: {TEXT("EEgr"), 72, 'G'},
64: {TEXT("Egr"), 69, 'G'},
65: {TEXT("Element"), 206, 'G'},
66: {TEXT("Equal"), 61, 'L'},
67: {TEXT("EqualTilde"), 64, 'G'},
68: {TEXT("Exists"), 36, 'G'},
1.53 cvs 69: {TEXT("ExponentialE"), 101, 'L'},
1.44 cvs 70: {TEXT("ForAll"), 34, 'G'},
71: {TEXT("Gamma"), 71, 'G'},
72: {TEXT("GreaterEqual"), 179, 'G'},
1.53 cvs 73: {TEXT("Hat"), 94, 'L'},
1.44 cvs 74: {TEXT("Igr"), 73, 'G'},
1.53 cvs 75: {TEXT("ImaginaryI"), 105, 'L'},
1.44 cvs 76: {TEXT("Integral"), 242, 'G'},
77: {TEXT("Intersection"), 199, 'G'},
1.53 cvs 78: {TEXT("InvisibleComma"), 129, 'L'},
1.44 cvs 79: {TEXT("InvisibleTimes"), 0, SPACE},
80: {TEXT("Kgr"), 75, 'G'},
81: {TEXT("KHgr"), 67, 'G'},
82: {TEXT("Lambda"), 76, 'G'},
83: {TEXT("LeftArrow"), 172, 'G'},
1.52 cvs 84: {TEXT("LeftCeiling"), 233, 'G'},
85: {TEXT("LeftFloor"), 235, 'G'},
1.44 cvs 86: {TEXT("LeftRightArrow"), 171, 'G'},
87: {TEXT("Mgr"), 77, 'G'},
88: {TEXT("Ngr"), 78, 'G'},
89: {TEXT("NonBreakingSpace"), 160, 'L'},
90: {TEXT("Not"), 216, 'G'},
91: {TEXT("NotElement"), 207, 'G'},
92: {TEXT("NotEqual"), 185, 'G'},
93: {TEXT("NotSubset"), 203, 'G'},
94: {TEXT("Ogr"), 79, 'G'},
95: {TEXT("Omega"), 87, 'G'},
96: {TEXT("Or"), 218, 'G'},
1.55 cvs 97: {TEXT("OverBar"), 45, 'G'},
1.44 cvs 98: {TEXT("PI"), 213, 'G'},
99: {TEXT("PartialD"), 182, 'G'},
100: {TEXT("Phi"), 70, 'G'},
101: {TEXT("Pi"), 80, 'G'},
102: {TEXT("PlusMinus"), 177, 'G'},
1.57 cvs 103: {TEXT("Prime"), 178, 'G'},
1.44 cvs 104: {TEXT("Product"), 213, 'G'},
105: {TEXT("Proportional"), 181, 'G'},
106: {TEXT("Psi"), 89, 'G'},
1.52 cvs 107: {TEXT("RightAngleBracket"), 241, 'G'},
108: {TEXT("RightCeiling"), 249, 'G'},
109: {TEXT("RightFloor"), 251, 'G'},
1.44 cvs 110: {TEXT("Rgr"), 82, 'G'},
111: {TEXT("RightArrow"), 174, 'G'},
112: {TEXT("Sigma"), 83, 'G'},
113: {TEXT("Sol"), 164, 'G'},
114: {TEXT("Star"), 42, 'L'},
115: {TEXT("Subset"), 204, 'G'},
116: {TEXT("SubsetEqual"), 205, 'G'},
117: {TEXT("SuchThat"), 39, 'G'},
118: {TEXT("Sum"), 229, 'G'},
119: {TEXT("Superset"), 201, 'G'},
120: {TEXT("SupersetEqual"), 202, 'G'},
121: {TEXT("Tgr"), 84, 'G'},
122: {TEXT("Therefore"), 92, 'G'},
123: {TEXT("Theta"), 81, 'G'},
1.53 cvs 124: {TEXT("ThickSpace"), 130, 'L'},
125: {TEXT("ThinSpace"), 129, 'L'},
1.44 cvs 126: {TEXT("Tilde"), 126, 'L'},
127: {TEXT("TripleDot"), 188, 'G'},
1.55 cvs 128: {TEXT("UnderBar"), 45, 'G'},
1.44 cvs 129: {TEXT("Union"), 200, 'G'},
130: {TEXT("UpArrow"), 173, 'G'},
131: {TEXT("Upsi"), 85, 'G'},
132: {TEXT("Upsi1"), 161, 'G'},
133: {TEXT("Vee"), 218, 'G'},
134: {TEXT("Verbar"), 189, 'G'},
135: {TEXT("VerticalBar"), 124, 'L'},
136: {TEXT("Xi"), 88, 'G'},
137: {TEXT("Zgr"), 90, 'G'},
138: {TEXT("af"), 32, 'L'}, /* render as white space */
139: {TEXT("aleph"), 192, 'G'},
140: {TEXT("alpha"), 97, 'G'},
141: {TEXT("and"), 217, 'G'},
142: {TEXT("angle"), 208, 'G'},
143: {TEXT("ap"), 187, 'G'},
144: {TEXT("beta"), 98, 'G'},
1.52 cvs 145: {TEXT("bot"), 94, 'G'},
1.44 cvs 146: {TEXT("bottom"), 94, 'G'},
147: {TEXT("bull"), 183, 'G'},
148: {TEXT("cap"), 199, 'G'},
149: {TEXT("chi"), 99, 'G'},
1.52 cvs 150: {TEXT("circ"), 94, 'L'},
1.44 cvs 151: {TEXT("clubs"), 167, 'G'},
152: {TEXT("cong"), 64, 'G'},
153: {TEXT("copysf"), 211, 'G'},
154: {TEXT("copyssf"), 227, 'G'},
155: {TEXT("cr"), 191, 'G'},
156: {TEXT("cup"), 200, 'G'},
1.52 cvs 157: {TEXT("dArr"), 223, 'G'},
1.44 cvs 158: {TEXT("darr"), 175, 'G'},
159: {TEXT("dd"), 100, 'L'},
160: {TEXT("deg"), 176, 'G'},
161: {TEXT("delta"), 100, 'G'},
162: {TEXT("diams"), 168, 'G'},
163: {TEXT("divide"), 184, 'G'},
164: {TEXT("dtri"), 209, 'G'},
165: {TEXT("ee"), 101, 'L'},
166: {TEXT("empty"), 198, 'G'},
1.52 cvs 167: {TEXT("emptyset"), 198, 'G'},
1.44 cvs 168: {TEXT("emsp"), 32, 'G'},
169: {TEXT("epsiv"), 101, 'G'},
170: {TEXT("equiv"), 186, 'G'},
171: {TEXT("eta"), 104, 'G'},
172: {TEXT("exist"), 36, 'G'},
173: {TEXT("florin"), 166, 'G'},
174: {TEXT("forall"), 34, 'G'},
175: {TEXT("gamma"), 103, 'G'},
176: {TEXT("ge"), 179, 'G'},
1.52 cvs 177: {TEXT("geq"), 179, 'G'},
1.44 cvs 178: {TEXT("gt"), 62, 'L'},
179: {TEXT("hearts"), 169, 'G'},
180: {TEXT("horbar"), 190, 'G'},
1.52 cvs 181: {TEXT("iff"), 219, 'G'},
1.44 cvs 182: {TEXT("ifraktur"), 193, 'G'},
1.52 cvs 183: {TEXT("in"), 206, 'G'},
1.44 cvs 184: {TEXT("infin"), 165, 'G'},
185: {TEXT("int"), 242, 'G'},
186: {TEXT("iota"), 105, 'G'},
187: {TEXT("isin"), 206, 'G'},
188: {TEXT("it"), 0, SPACE},
189: {TEXT("kappa"), 107, 'G'},
1.52 cvs 190: {TEXT("lArr"), 220, 'G'},
1.44 cvs 191: {TEXT("lambda"), 108, 'G'},
192: {TEXT("lang"), 225, 'G'},
1.52 cvs 193: {TEXT("langle"), 225, 'G'},
1.44 cvs 194: {TEXT("larr"), 172, 'G'},
1.52 cvs 195: {TEXT("lbrace"), 123, 'L'},
196: {TEXT("lceil"), 233, 'G'},
197: {TEXT("lcub"), 123, 'L'},
1.44 cvs 198: {TEXT("le"), 163, 'G'},
1.52 cvs 199: {TEXT("leq"), 163, 'G'},
200: {TEXT("lfloor"), 235, 'G'},
1.44 cvs 201: {TEXT("lowbar"), 95, 'G'},
202: {TEXT("loz"), 224, 'G'},
1.52 cvs 203: {TEXT("lrArr"), 219, 'G'},
1.44 cvs 204: {TEXT("lrarr"), 171, 'G'},
205: {TEXT("lsqb"), 91, 'G'},
206: {TEXT("lt"), 60, 'L'},
207: {TEXT("middot"), 215, 'G'},
208: {TEXT("mldr"), 188, 'G'},
209: {TEXT("mu"), 109, 'G'},
1.52 cvs 210: {TEXT("nabla"), 209, 'G'},
1.62 cvs 211: {TEXT("nbsp"), 160, 'L'},
1.44 cvs 212: {TEXT("ne"), 185, 'G'},
1.52 cvs 213: {TEXT("neq"), 185, 'G'},
1.44 cvs 214: {TEXT("not"), 216, 'G'},
215: {TEXT("notin"), 207, 'G'},
216: {TEXT("nu"), 110, 'G'},
217: {TEXT("ogr"), 111, 'G'},
218: {TEXT("omega"), 119, 'G'},
219: {TEXT("oplus"), 197, 'G'},
220: {TEXT("or"), 218, 'G'},
221: {TEXT("otimes"), 196, 'G'},
222: {TEXT("part"), 182, 'G'},
1.52 cvs 223: {TEXT("perp"), 94, 'G'},
1.44 cvs 224: {TEXT("phi"), 102, 'G'},
225: {TEXT("phiv"), 106, 'G'},
226: {TEXT("pi"), 112, 'G'},
227: {TEXT("piv"), 118, 'G'},
1.57 cvs 228: {TEXT("prime"), 162, 'G'},
1.44 cvs 229: {TEXT("prop"), 181, 'G'},
230: {TEXT("psi"), 121, 'G'},
1.52 cvs 231: {TEXT("rArr"), 222, 'G'},
1.44 cvs 232: {TEXT("radic"), 214, 'G'},
1.52 cvs 233: {TEXT("rang"), 241, 'G'},
234: {TEXT("rangle"), 241, 'G'},
1.44 cvs 235: {TEXT("rarr"), 174, 'G'},
1.52 cvs 236: {TEXT("rbrace"), 125, 'L'},
237: {TEXT("rceil"), 249, 'G'},
238: {TEXT("rcub"), 125, 'L'},
1.44 cvs 239: {TEXT("rdquo"), 178, 'G'},
240: {TEXT("regsf"), 210, 'G'},
241: {TEXT("regssf"), 226, 'G'},
1.52 cvs 242: {TEXT("rfloor"), 251, 'G'},
1.44 cvs 243: {TEXT("rfraktur"), 194, 'G'},
244: {TEXT("rho"), 114, 'G'},
245: {TEXT("rsqb"), 93, 'G'},
246: {TEXT("sigma"), 115, 'G'},
247: {TEXT("sigmav"), 86, 'G'},
248: {TEXT("spades"), 170, 'G'},
249: {TEXT("sub"), 204, 'G'},
250: {TEXT("sube"), 205, 'G'},
251: {TEXT("subne"), 203, 'G'},
1.52 cvs 252: {TEXT("subset"), 204, 'G'},
1.44 cvs 253: {TEXT("sum"), 229, 'G'},
254: {TEXT("sup"), 201, 'G'},
255: {TEXT("supe"), 202, 'G'},
1.52 cvs 256: {TEXT("supset"), 201, 'G'},
257: {TEXT("supseteq"), 202, 'G'},
258: {TEXT("supseteqq"), 202, 'G'},
1.44 cvs 259: {TEXT("tau"), 116, 'G'},
260: {TEXT("there4"), 92, 'G'},
1.52 cvs 261: {TEXT("therefore"), 92, 'G'},
1.44 cvs 262: {TEXT("theta"), 113, 'G'},
263: {TEXT("thetav"), 74, 'G'},
264: {TEXT("thickspace"), 32, 'L'},
265: {TEXT("times"), 180, 'G'},
266: {TEXT("trade"), 212, 'G'},
267: {TEXT("tradesf"), 212, 'G'},
268: {TEXT("tradessf"), 228, 'G'},
1.52 cvs 269: {TEXT("uArr"), 221, 'G'},
1.44 cvs 270: {TEXT("uarr"), 173, 'G'},
271: {TEXT("upsi"), 117, 'G'},
272: {TEXT("vee"), 218, 'G'},
273: {TEXT("weierp"), 195, 'G'},
274: {TEXT("xi"), 120, 'G'},
275: {TEXT("zeta"), 122, 'G'},
276: {TEXT("zzzz"), -1, SPACE} /* this last entry is required */
1.26 cvs 277:
1.1 cvs 278: };
279:
280: /* mapping table of attribute values */
281:
282: static AttrValueMapping MathMLAttrValueMappingTable[] =
283: {
1.47 cvs 284: {MathML_ATTR_accent, TEXT("true"), MathML_ATTR_accent_VAL_true},
285: {MathML_ATTR_accent, TEXT("false"), MathML_ATTR_accent_VAL_false},
1.46 cvs 286:
1.47 cvs 287: {MathML_ATTR_accentunder, TEXT("true"), MathML_ATTR_accentunder_VAL_true},
288: {MathML_ATTR_accentunder, TEXT("false"), MathML_ATTR_accentunder_VAL_false},
1.46 cvs 289:
1.54 cvs 290: {MathML_ATTR_bevelled, TEXT("true"), MathML_ATTR_bevelled_VAL_true},
291: {MathML_ATTR_bevelled, TEXT("false"), MathML_ATTR_bevelled_VAL_false},
1.46 cvs 292:
1.47 cvs 293: {MathML_ATTR_denomalign, TEXT("center"), MathML_ATTR_denomalign_VAL_center_},
294: {MathML_ATTR_denomalign, TEXT("left"), MathML_ATTR_denomalign_VAL_left_},
295: {MathML_ATTR_denomalign, TEXT("right"), MathML_ATTR_denomalign_VAL_right_},
1.46 cvs 296:
1.47 cvs 297: {MathML_ATTR_displaystyle, TEXT("true"), MathML_ATTR_displaystyle_VAL_true},
298: {MathML_ATTR_displaystyle, TEXT("false"), MathML_ATTR_displaystyle_VAL_false},
1.46 cvs 299:
1.47 cvs 300: {MathML_ATTR_edge, TEXT("left"), MathML_ATTR_edge_VAL_left_},
301: {MathML_ATTR_edge, TEXT("right"), MathML_ATTR_edge_VAL_right_},
1.46 cvs 302:
1.47 cvs 303: {MathML_ATTR_fence, TEXT("true"), MathML_ATTR_fence_VAL_true},
304: {MathML_ATTR_fence, TEXT("false"), MathML_ATTR_fence_VAL_false},
1.46 cvs 305:
1.47 cvs 306: {MathML_ATTR_fontstyle, TEXT("italic"), MathML_ATTR_fontstyle_VAL_italic},
307: {MathML_ATTR_fontstyle, TEXT("normal"), MathML_ATTR_fontstyle_VAL_normal_},
1.46 cvs 308:
1.47 cvs 309: {MathML_ATTR_fontweight, TEXT("normal"), MathML_ATTR_fontweight_VAL_normal_},
310: {MathML_ATTR_fontweight, TEXT("bold"), MathML_ATTR_fontweight_VAL_bold_},
1.46 cvs 311:
1.47 cvs 312: {MathML_ATTR_form, TEXT("prefix"), MathML_ATTR_form_VAL_prefix},
313: {MathML_ATTR_form, TEXT("infix"), MathML_ATTR_form_VAL_infix},
314: {MathML_ATTR_form, TEXT("postfix"), MathML_ATTR_form_VAL_postfix},
1.46 cvs 315:
1.47 cvs 316: {MathML_ATTR_frame, TEXT("none"), MathML_ATTR_frame_VAL_none_},
317: {MathML_ATTR_frame, TEXT("solid"), MathML_ATTR_frame_VAL_solid_},
318: {MathML_ATTR_frame, TEXT("dashed"), MathML_ATTR_frame_VAL_dashed_},
1.46 cvs 319:
1.47 cvs 320: {MathML_ATTR_largeop, TEXT("true"), MathML_ATTR_largeop_VAL_true},
321: {MathML_ATTR_largeop, TEXT("false"), MathML_ATTR_largeop_VAL_false},
1.46 cvs 322:
1.47 cvs 323: {MathML_ATTR_movablelimits, TEXT("true"), MathML_ATTR_movablelimits_VAL_true},
324: {MathML_ATTR_movablelimits, TEXT("false"), MathML_ATTR_movablelimits_VAL_false},
1.46 cvs 325:
1.47 cvs 326: {MathML_ATTR_notation, TEXT("longdiv"), MathML_ATTR_notation_VAL_longdiv},
327: {MathML_ATTR_notation, TEXT("actuarial"), MathML_ATTR_notation_VAL_actuarial},
328: {MathML_ATTR_notation, TEXT("radical"), MathML_ATTR_notation_VAL_radical},
1.46 cvs 329:
1.47 cvs 330: {MathML_ATTR_numalign, TEXT("center"), MathML_ATTR_numalign_VAL_center_},
331: {MathML_ATTR_numalign, TEXT("left"), MathML_ATTR_numalign_VAL_left_},
332: {MathML_ATTR_numalign, TEXT("right"), MathML_ATTR_numalign_VAL_right_},
1.46 cvs 333:
1.47 cvs 334: {MathML_ATTR_separator, TEXT("true"), MathML_ATTR_separator_VAL_true},
335: {MathML_ATTR_separator, TEXT("false"), MathML_ATTR_separator_VAL_false},
1.46 cvs 336:
1.47 cvs 337: {MathML_ATTR_side, TEXT("left"), MathML_ATTR_side_VAL_left_},
338: {MathML_ATTR_side, TEXT("leftoverlap"), MathML_ATTR_side_VAL_leftoverlap},
339: {MathML_ATTR_side, TEXT("right"), MathML_ATTR_side_VAL_right_},
340: {MathML_ATTR_side, TEXT("rightoverlap"), MathML_ATTR_side_VAL_rightoverlap},
1.46 cvs 341:
1.47 cvs 342: {MathML_ATTR_stretchy, TEXT("true"), MathML_ATTR_stretchy_VAL_true},
343: {MathML_ATTR_stretchy, TEXT("false"), MathML_ATTR_stretchy_VAL_false},
1.46 cvs 344:
1.47 cvs 345: {MathML_ATTR_symmetric, TEXT("true"), MathML_ATTR_symmetric_VAL_true},
346: {MathML_ATTR_symmetric, TEXT("false"), MathML_ATTR_symmetric_VAL_false},
1.21 cvs 347:
1.47 cvs 348: {0, TEXT(""), 0} /* Last entry. Mandatory */
1.1 cvs 349: };
350:
351: #define MaxMsgLength 200
352:
1.12 cvs 353: #include "HTMLtable_f.h"
1.29 cvs 354: #include "Mathedit_f.h"
355: #include "XMLparser_f.h"
356: #include "styleparser_f.h"
357: #include "fetchXMLname_f.h"
1.1 cvs 358:
359: /*----------------------------------------------------------------------
360: MapMathMLAttribute
361: Search in the Attribute Mapping Table the entry for the
362: attribute of name Attr and returns the corresponding Thot attribute type.
363: ----------------------------------------------------------------------*/
364: #ifdef __STDC__
1.70 ! cvs 365: void MapMathMLAttribute (CHAR_T *attrName, AttributeType *attrType, STRING elementName, Document doc)
1.1 cvs 366: #else
1.69 cvs 367: void MapMathMLAttribute (attrName, attrType, elementName, doc)
368: STRING attrName;
1.1 cvs 369: AttributeType *attrType;
1.14 cvs 370: STRING elementName;
1.2 cvs 371: Document doc;
1.1 cvs 372: #endif
373: {
1.68 cvs 374: attrType->AttrSSchema = GetMathMLSSchema (doc);
1.69 cvs 375: MapXMLAttribute (MATH_TYPE, attrName, elementName, doc, &(attrType->AttrTypeNum));
1.1 cvs 376: }
377:
378: /*----------------------------------------------------------------------
379: MapMathMLAttributeValue
380: Search in the Attribute Value Mapping Table the entry for the attribute
381: ThotAtt and its value AttrVal. Returns the corresponding Thot value.
382: ----------------------------------------------------------------------*/
383: #ifdef __STDC__
1.14 cvs 384: void MapMathMLAttributeValue (STRING AttrVal, AttributeType attrType, int *value)
1.1 cvs 385: #else
386: void MapMathMLAttributeValue (AttrVal, attrType, value)
1.14 cvs 387: STRING AttrVal;
1.1 cvs 388: AttributeType attrType;
389: int *value;
390: #endif
391: {
392: int i;
393:
394: *value = 0;
395: i = 0;
396: while (MathMLAttrValueMappingTable[i].ThotAttr != attrType.AttrTypeNum &&
397: MathMLAttrValueMappingTable[i].ThotAttr != 0)
398: i++;
399: if (MathMLAttrValueMappingTable[i].ThotAttr == attrType.AttrTypeNum)
400: do
1.14 cvs 401: if (!ustrcasecmp (MathMLAttrValueMappingTable[i].XMLattrValue, AttrVal))
1.1 cvs 402: *value = MathMLAttrValueMappingTable[i].ThotAttrValue;
403: else
404: i++;
405: while (*value <= 0 && MathMLAttrValueMappingTable[i].ThotAttr != 0);
406: }
407:
408: /*----------------------------------------------------------------------
409: MapMathMLEntity
410: Search that entity in the entity table and return the corresponding value.
411: ----------------------------------------------------------------------*/
412: #ifdef __STDC__
1.67 cvs 413: void MapMathMLEntity (STRING entityName, STRING entityValue, STRING alphabet)
1.1 cvs 414: #else
1.67 cvs 415: void MapMathMLEntity (entityName, entityValue, alphabet)
1.66 cvs 416: STRING entityName;
417: STRING entityValue;
418: STRING alphabet;
1.1 cvs 419: #endif
420: {
421: int i;
1.67 cvs 422: ThotBool found;
1.1 cvs 423:
1.67 cvs 424: found = FALSE;
425: for (i = 0; MathEntityTable[i].charCode >= 0 && !found; i++)
426: found = !ustrcmp (MathEntityTable[i].MentityName, entityName);
427:
428: if (found)
429: /* entity found */
430: {
431: i--;
1.15 cvs 432: entityValue[0] = (UCHAR_T) MathEntityTable[i].charCode;
1.1 cvs 433: entityValue[1] = EOS;
434: *alphabet = MathEntityTable[i].alphabet;
1.67 cvs 435: }
436: else
437: {
1.1 cvs 438: entityValue[0] = EOS;
439: *alphabet = EOS;
1.67 cvs 440: }
1.1 cvs 441: }
442:
443: /*----------------------------------------------------------------------
444: MathMLEntityCreated
445: A MathML entity has been created by the XML parser.
1.36 cvs 446: Create an attribute EntityName containing the entity name.
1.1 cvs 447: ----------------------------------------------------------------------*/
448: #ifdef __STDC__
1.34 cvs 449: void MathMLEntityCreated (USTRING entityValue, Language lang, STRING entityName, Document doc)
1.1 cvs 450: #else
1.34 cvs 451: void MathMLEntityCreated (entityValue, lang, entityName, doc)
1.66 cvs 452: USTRING entityValue;
453: Language lang;
454: STRING entityName;
455: Document doc;
1.1 cvs 456: #endif
457: {
458: ElementType elType;
459: Element elText;
460: AttributeType attrType;
461: Attribute attr;
1.45 cvs 462: int len, code;
1.1 cvs 463: #define MAX_ENTITY_LENGTH 80
1.34 cvs 464: CHAR_T buffer[MAX_ENTITY_LENGTH];
1.1 cvs 465:
1.34 cvs 466: if (lang < 0)
467: /* unknown entity */
468: {
1.45 cvs 469: /* by default display a question mark */
1.34 cvs 470: entityValue[0] = '?';
471: entityValue[1] = EOS;
472: lang = TtaGetLanguageIdFromAlphabet('L');
1.45 cvs 473: /* let's see if we can do more */
474: if (entityName[0] == '#')
475: /* it's a number */
476: {
477: if (entityName[1] == 'x')
478: /* it's a hexadecimal number */
479: usscanf (&entityName[2], TEXT("%x"), &code);
480: else
481: /* it's a decimal number */
482: usscanf (&entityName[1], TEXT("%d"), &code);
483: GetFallbackCharacter (code, entityValue, &lang);
484: }
1.34 cvs 485: }
486: XMLTextToDocument ();
1.49 cvs 487: elType.ElTypeNum = MathML_EL_TEXT_UNIT;
1.34 cvs 488: elType.ElSSchema = GetMathMLSSchema (doc);
489: elText = TtaNewElement (doc, elType);
490: SetElemLineNumber (elText);
491: XMLInsertElement (elText);
492: TtaSetTextContent (elText, entityValue, lang, doc);
1.36 cvs 493: TtaSetAccessRight (elText, ReadOnly, doc);
1.34 cvs 494: attrType.AttrSSchema = GetMathMLSSchema (doc);
495: attrType.AttrTypeNum = MathML_ATTR_EntityName;
496: attr = TtaNewAttribute (attrType);
497: TtaAttachAttribute (elText, attr, doc);
498: len = ustrlen (entityName);
499: if (len > MAX_ENTITY_LENGTH -3)
500: len = MAX_ENTITY_LENGTH -3;
501: buffer[0] = '&';
502: ustrncpy (&buffer[1], entityName, len);
503: buffer[len+1] = ';';
504: buffer[len+2] = EOS;
505: TtaSetAttributeText (attr, buffer, elText, doc);
1.1 cvs 506: }
507:
508: /*----------------------------------------------------------------------
509: CheckTextElement Put the content of input buffer into the document.
510: ----------------------------------------------------------------------*/
511: #ifdef __STDC__
512: static void CheckTextElement (Element *el, Document doc)
513: #else
514: static void CheckTextElement (el, doc)
515: Element *el;
516: Document doc;
517:
518: #endif
519: {
1.44 cvs 520: ElementType parentType, elType;
521: Element parent, new;
522: int len;
523: Language lang;
524: CHAR_T alphabet;
1.48 cvs 525: CHAR_T text[4];
1.1 cvs 526:
527: len = TtaGetTextLength (*el);
528: if (len == 1)
1.55 cvs 529: /* the element contains a single character */
1.1 cvs 530: {
1.55 cvs 531: /* get that character */
1.1 cvs 532: len = 2;
533: TtaGiveTextContent (*el, text, &len, &lang);
534: alphabet = TtaGetAlphabet (lang);
1.48 cvs 535: if (text[0] != WC_EOS)
1.55 cvs 536: /* it's not a NULL character */
537: {
538: /* what's the parent of that character? */
539: parent = TtaGetParent (*el);
540: parentType = TtaGetElementType (parent);
541: elType = parentType;
542: if (parentType.ElTypeNum == MathML_EL_MF &&
543: (text[0] == TEXT('(') ||
544: text[0] == TEXT(')') ||
545: text[0] == TEXT('[') ||
546: text[0] == TEXT(']') ||
547: text[0] == TEXT('{') ||
548: text[0] == TEXT('}')))
549: /* It's a stretchable character in a mf element */
550: /* Transform the text element into a Thot SYMBOL */
551: elType.ElTypeNum = MathML_EL_SYMBOL_UNIT;
552: else if (parentType.ElTypeNum == MathML_EL_MF &&
553: text[0] == TEXT('|'))
554: /* It's a vertical bar in a mf element */
555: /* Transform the text element into a Thot GRAPHIC */
556: {
557: elType.ElTypeNum = MathML_EL_GRAPHICS_UNIT;
558: text[0] = TEXT('v');
559: }
560: else
561: /* a TEXT element is OK */
562: elType.ElTypeNum = MathML_EL_TEXT_UNIT;
563: if (elType.ElTypeNum != MathML_EL_TEXT_UNIT)
564: {
565: new = TtaNewElement (doc, elType);
566: TtaInsertSibling (new, *el, FALSE, doc);
567: TtaDeleteTree (*el, doc);
568: *el = new;
569: TtaSetGraphicsShape (new, (char)text[0], doc);
570: }
571: }
1.1 cvs 572: }
573: }
574:
575: /*----------------------------------------------------------------------
576: ElementNeedsPlaceholder
577: returns TRUE if element el needs a sibling placeholder.
578: ----------------------------------------------------------------------*/
579: #ifdef __STDC__
1.18 cvs 580: ThotBool ElementNeedsPlaceholder (Element el)
1.1 cvs 581: #else
1.18 cvs 582: ThotBool ElementNeedsPlaceholder (el)
1.1 cvs 583: Element el;
584:
585: #endif
586: {
587: ElementType elType;
588: Element child, parent;
1.18 cvs 589: ThotBool ret;
1.1 cvs 590:
591: ret = FALSE;
592: elType = TtaGetElementType (el);
1.43 cvs 593: if (elType.ElTypeNum == MathML_EL_MS ||
594: elType.ElTypeNum == MathML_EL_MSPACE ||
1.39 cvs 595: elType.ElTypeNum == MathML_EL_MROW ||
596: elType.ElTypeNum == MathML_EL_MFRAC ||
1.54 cvs 597: elType.ElTypeNum == MathML_EL_BevelledMFRAC ||
1.39 cvs 598: elType.ElTypeNum == MathML_EL_MSQRT ||
599: elType.ElTypeNum == MathML_EL_MROOT ||
600: elType.ElTypeNum == MathML_EL_MSTYLE ||
601: elType.ElTypeNum == MathML_EL_MERROR ||
602: elType.ElTypeNum == MathML_EL_MPADDED ||
603: elType.ElTypeNum == MathML_EL_MPHANTOM ||
604: elType.ElTypeNum == MathML_EL_MFENCED ||
1.1 cvs 605: elType.ElTypeNum == MathML_EL_MF ||
606: elType.ElTypeNum == MathML_EL_MSUB ||
607: elType.ElTypeNum == MathML_EL_MSUP ||
1.39 cvs 608: elType.ElTypeNum == MathML_EL_MSUBSUP ||
1.1 cvs 609: elType.ElTypeNum == MathML_EL_MUNDER ||
610: elType.ElTypeNum == MathML_EL_MOVER ||
611: elType.ElTypeNum == MathML_EL_MUNDEROVER ||
1.28 cvs 612: elType.ElTypeNum == MathML_EL_MMULTISCRIPTS ||
1.39 cvs 613: elType.ElTypeNum == MathML_EL_MTABLE ||
614: elType.ElTypeNum == MathML_EL_MACTION)
1.1 cvs 615: ret = TRUE;
616: else
617: if (elType.ElTypeNum == MathML_EL_MO)
618: /* an operator that contains a single Symbol needs a placeholder,
619: except when it is in a Base or UnderOverBase */
620: {
621: child = TtaGetFirstChild (el);
622: if (child != NULL)
623: {
624: elType = TtaGetElementType (child);
625: if (elType.ElTypeNum == MathML_EL_SYMBOL_UNIT)
626: {
627: ret = TRUE;
628: parent = TtaGetParent (el);
629: if (parent != NULL)
630: {
631: elType = TtaGetElementType (parent);
632: if (elType.ElTypeNum == MathML_EL_Base ||
633: elType.ElTypeNum == MathML_EL_UnderOverBase)
634: ret = FALSE;
635: }
636: }
637: }
638: }
639: return ret;
640: }
641:
642: /*----------------------------------------------------------------------
643: CreatePlaceholders
644: ----------------------------------------------------------------------*/
645: #ifdef __STDC__
646: static void CreatePlaceholders (Element el, Document doc)
647: #else
648: static void CreatePlaceholders (el, doc)
649: Element el;
650: Document doc;
651: #endif
652: {
653: Element sibling, prev, constr, child;
654: Attribute attr;
655: ElementType elType;
656: AttributeType attrType;
1.18 cvs 657: ThotBool create;
1.1 cvs 658:
1.55 cvs 659: if (!el)
660: return;
1.2 cvs 661: elType.ElSSchema = GetMathMLSSchema (doc);
1.1 cvs 662: prev = NULL;
663: create = TRUE;
664: sibling = el;
665: while (sibling != NULL)
666: {
667: if (!ElementNeedsPlaceholder (sibling))
668: create = FALSE;
669: else
670: {
671: if (sibling == el)
672: /* first element */
673: {
674: elType = TtaGetElementType (sibling);
675: if (elType.ElTypeNum == MathML_EL_MF)
676: /* the first element is a MF. Don't create a placeholder
677: before */
678: create = FALSE;
679: else if (elType.ElTypeNum == MathML_EL_MROW)
680: /* the first element is a MROW */
681: {
682: child = TtaGetFirstChild (sibling);
683: if (child != NULL)
684: {
685: elType = TtaGetElementType (child);
686: if (elType.ElTypeNum != MathML_EL_MF)
687: /* the first child of the MROW element is not a MF */
688: /* Don't create a placeholder before */
689: create = FALSE;
690: }
691: }
692: }
693: if (create)
694: {
695: elType.ElTypeNum = MathML_EL_Construct;
696: constr = TtaNewElement (doc, elType);
697: TtaInsertSibling (constr, sibling, TRUE, doc);
698: attrType.AttrSSchema = elType.ElSSchema;
1.22 cvs 699: attrType.AttrTypeNum = MathML_ATTR_IntPlaceholder;
1.1 cvs 700: attr = TtaNewAttribute (attrType);
701: TtaAttachAttribute (constr, attr, doc);
1.55 cvs 702: TtaSetAttributeValue (attr, MathML_ATTR_IntPlaceholder_VAL_yes_,
703: constr, doc);
1.1 cvs 704: }
705: create = TRUE;
706: }
707: prev = sibling;
708: TtaNextSibling (&sibling);
709: }
710: if (prev != NULL && create)
711: {
712: elType = TtaGetElementType (prev);
713: /* don't insert a placeholder after the last element if it's a MF
714: or a SEP */
715: if (elType.ElTypeNum == MathML_EL_MF ||
716: elType.ElTypeNum == MathML_EL_SEP)
717: create = FALSE;
718: else if (elType.ElTypeNum == MathML_EL_MROW)
719: /* the last element is a MROW */
720: {
721: child = TtaGetLastChild (prev);
722: if (child != NULL)
723: {
724: elType = TtaGetElementType (child);
725: if (elType.ElTypeNum != MathML_EL_MF)
726: /* the last child of the MROW element is not a MF */
727: /* Don't create a placeholder before */
728: create = FALSE;
729: }
730: }
731: if (create)
732: {
733: elType.ElTypeNum = MathML_EL_Construct;
734: constr = TtaNewElement (doc, elType);
735: TtaInsertSibling (constr, prev, FALSE, doc);
736: attrType.AttrSSchema = elType.ElSSchema;
1.22 cvs 737: attrType.AttrTypeNum = MathML_ATTR_IntPlaceholder;
1.1 cvs 738: attr = TtaNewAttribute (attrType);
739: TtaAttachAttribute (constr, attr, doc);
1.55 cvs 740: TtaSetAttributeValue (attr, MathML_ATTR_IntPlaceholder_VAL_yes_,
741: constr, doc);
1.1 cvs 742: }
743: }
744: }
745:
746: /*----------------------------------------------------------------------
1.28 cvs 747: NextNotSepOrComment
1.1 cvs 748: Return the next sibling of element el that is not a SEP element
1.28 cvs 749: nor an XMLcomment element.
750: Return el itself if it's not a SEP or a comment.
1.1 cvs 751: ----------------------------------------------------------------------*/
752: #ifdef __STDC__
1.28 cvs 753: static void NextNotSepOrComment (Element* el, Element* prev)
1.1 cvs 754: #else
1.28 cvs 755: static void NextNotSepOrComment (el, prev)
1.1 cvs 756: Element *el;
757: #endif
758: {
759: ElementType elType;
760:
761: if (*el == NULL)
762: return;
763: elType = TtaGetElementType (*el);
1.28 cvs 764: while (*el != NULL && (elType.ElTypeNum == MathML_EL_SEP ||
765: elType.ElTypeNum == MathML_EL_XMLcomment))
1.1 cvs 766: {
767: *prev = *el;
768: TtaNextSibling (el);
769: if (*el != NULL)
770: elType = TtaGetElementType (*el);
771: }
772: }
773:
774: /*----------------------------------------------------------------------
775: CheckMathSubExpressions
776: Children of element el should be of type type1, type2, and type3.
1.56 cvs 777: If they are not, wrap them in elements of these types.
778: If element el have too many or not enough children, return FALSE.
1.1 cvs 779: ----------------------------------------------------------------------*/
780: #ifdef __STDC__
1.56 cvs 781: static ThotBool CheckMathSubExpressions (Element el, int type1, int type2, int type3, Document doc)
1.1 cvs 782: #else
1.56 cvs 783: static ThotBool CheckMathSubExpressions (el, type1, type2, type3, doc)
1.1 cvs 784: Element el;
785: int type1;
786: int type2;
787: int type3;
788: Document doc;
789: #endif
790: {
791: Element child, new, prev;
792: ElementType elType, childType;
1.56 cvs 793: ThotBool result;
1.1 cvs 794:
1.56 cvs 795: result = TRUE;
1.2 cvs 796: elType.ElSSchema = GetMathMLSSchema (doc);
1.1 cvs 797: child = TtaGetFirstChild (el);
798: prev = NULL;
1.28 cvs 799: NextNotSepOrComment (&child, &prev);
1.56 cvs 800: if (type1 == 0)
1.1 cvs 801: {
1.56 cvs 802: if (child)
803: /* no child expected and there is one, error */
804: result = FALSE;
805: }
806: else
807: if (!child)
808: /* a first child is expected and it's missing */
809: result = FALSE;
810: else
811: {
1.1 cvs 812: elType.ElTypeNum = type1;
813: childType = TtaGetElementType (child);
814: if (TtaSameTypes (childType, elType) == 0)
815: {
816: TtaRemoveTree (child, doc);
817: new = TtaNewElement (doc, elType);
818: if (prev == NULL)
819: TtaInsertFirstChild (&new, el, doc);
820: else
821: TtaInsertSibling (new, prev, FALSE, doc);
822: TtaInsertFirstChild (&child, new, doc);
823: CreatePlaceholders (child, doc);
824: child = new;
825: }
1.56 cvs 826: prev = child;
827: TtaNextSibling (&child);
828: NextNotSepOrComment (&child, &prev);
829: if (type2 == 0)
830: {
831: if (child)
832: /* this second child is not expected, error */
833: result = FALSE;
834: }
835: else
1.1 cvs 836: {
1.56 cvs 837: if (!child)
838: /* a second child is expected and it's missing */
839: result = FALSE;
840: else
1.1 cvs 841: {
842: elType.ElTypeNum = type2;
843: childType = TtaGetElementType (child);
844: if (TtaSameTypes (childType, elType) == 0)
845: {
846: TtaRemoveTree (child, doc);
847: new = TtaNewElement (doc, elType);
848: TtaInsertSibling (new, prev, FALSE, doc);
849: TtaInsertFirstChild (&child, new, doc);
850: CreatePlaceholders (child, doc);
851: child = new;
852: }
1.56 cvs 853: prev = child;
854: TtaNextSibling (&child);
855: NextNotSepOrComment (&child, &prev);
856: if (type3 == 0)
1.1 cvs 857: {
1.56 cvs 858: if (child)
859: /* this third child is not expected, error */
860: result = FALSE;
861: }
862: else
863: {
864: if (!child)
865: /* a third child is expected and it's missing */
866: result = FALSE;
867: else
1.1 cvs 868: {
869: elType.ElTypeNum = type3;
870: childType = TtaGetElementType (child);
871: if (TtaSameTypes (childType, elType) == 0)
872: {
873: TtaRemoveTree (child, doc);
874: new = TtaNewElement (doc, elType);
875: TtaInsertSibling (new, prev, FALSE, doc);
876: TtaInsertFirstChild (&child, new, doc);
877: CreatePlaceholders (child, doc);
1.56 cvs 878: child = new;
1.1 cvs 879: }
880: }
1.56 cvs 881: prev = child;
882: TtaNextSibling (&child);
883: NextNotSepOrComment (&child, &prev);
884: if (child)
885: /* this fourth child is unexpected */
886: result = FALSE;
1.1 cvs 887: }
888: }
889: }
1.56 cvs 890: }
891: return result;
1.1 cvs 892: }
893:
894:
895: /*----------------------------------------------------------------------
1.22 cvs 896: SetSingleIntHorizStretchAttr
1.1 cvs 897:
1.22 cvs 898: Put a IntHorizStretch attribute on element el if it contains only
1.1 cvs 899: a MO element that is a stretchable symbol.
900: -----------------------------------------------------------------------*/
901: #ifdef __STDC__
1.22 cvs 902: void SetSingleIntHorizStretchAttr (Element el, Document doc, Element* selEl)
1.1 cvs 903: #else /* __STDC__*/
1.22 cvs 904: void SetSingleIntHorizStretchAttr (el, doc, selEl)
1.1 cvs 905: Element el;
906: Document doc;
907: Element* selEl;
908: #endif /* __STDC__*/
909: {
910: Element child, sibling, textEl, symbolEl;
911: ElementType elType;
912: Attribute attr;
913: AttributeType attrType;
1.55 cvs 914: int len;
915: Language lang;
916: CHAR_T alphabet;
1.49 cvs 917: UCHAR_T text[2];
918: unsigned char c;
1.1 cvs 919:
920: if (el == NULL)
921: return;
922: child = TtaGetFirstChild (el);
1.55 cvs 923: if (child)
1.1 cvs 924: {
925: elType = TtaGetElementType (child);
926: if (elType.ElTypeNum == MathML_EL_MO)
927: /* the first child is a MO */
928: {
929: sibling = child;
930: TtaNextSibling (&sibling);
931: if (sibling == NULL)
932: /* there is no other child */
933: {
934: textEl = TtaGetFirstChild (child);
935: elType = TtaGetElementType (textEl);
936: if (elType.ElTypeNum == MathML_EL_TEXT_UNIT)
1.55 cvs 937: /* the MO child contains a TEXT element */
1.1 cvs 938: {
939: len = TtaGetTextLength (textEl);
940: if (len == 1)
1.55 cvs 941: /* the TEXT element contains a single character */
1.1 cvs 942: {
1.55 cvs 943: /* get that character */
1.1 cvs 944: len = 2;
945: TtaGiveTextContent (textEl, text, &len, &lang);
946: alphabet = TtaGetAlphabet (lang);
1.55 cvs 947: if (alphabet == 'G')
948: /* a single Symbol character */
949: if ((int)text[0] == 172 || (int)text[0] == 174 ||
950: (int)text[0] == 45)
951: /* horizontal arrow or horizontal bar */
952: {
953: c = EOS;
954: /* attach a IntHorizStretch attribute */
955: attrType.AttrSSchema = elType.ElSSchema;
956: attrType.AttrTypeNum = MathML_ATTR_IntHorizStretch;
957: attr = TtaNewAttribute (attrType);
958: TtaAttachAttribute (el, attr, doc);
959: TtaSetAttributeValue (attr, MathML_ATTR_IntHorizStretch_VAL_yes_, el, doc);
960: /* replace the TEXT element by a Thot SYMBOL element */
961: elType.ElTypeNum = MathML_EL_SYMBOL_UNIT;
962: symbolEl = TtaNewElement (doc, elType);
963: TtaInsertSibling (symbolEl, textEl, FALSE, doc);
964: if (selEl != NULL)
965: if (*selEl == textEl)
966: *selEl = symbolEl;
967: TtaDeleteTree (textEl, doc);
968: if ((int)text[0] == 172)
969: c = '<'; /* arrow left */
970: if ((int)text[0] == 174)
971: c = '>'; /* arrow right */
972: if ((int)text[0] == 45) /* - (minus) */
973: /* a horizontal line in the middle of the box */
974: c = 'h';
975: if (c != EOS)
976: TtaSetGraphicsShape (symbolEl, c, doc);
977: }
1.1 cvs 978: }
979: }
980: }
981: }
982: }
983: }
984:
985: /*----------------------------------------------------------------------
1.22 cvs 986: SetIntHorizStretchAttr
1.1 cvs 987:
1.22 cvs 988: Put a IntHorizStretch attribute on all children of element el which
1.1 cvs 989: contain only a MO element that is a stretchable symbol.
990: -----------------------------------------------------------------------*/
991: #ifdef __STDC__
1.22 cvs 992: static void SetIntHorizStretchAttr (Element el, Document doc)
1.1 cvs 993: #else /* __STDC__*/
1.22 cvs 994: static void SetIntHorizStretchAttr (el, doc)
1.1 cvs 995: Element el;
996: Document doc;
997: #endif /* __STDC__*/
998: {
999: Element child;
1000:
1001: if (el == NULL)
1002: return;
1003: child = TtaGetFirstChild (el);
1004: while (child != NULL)
1005: {
1.22 cvs 1006: SetSingleIntHorizStretchAttr (child, doc, NULL);
1.1 cvs 1007: TtaNextSibling (&child);
1008: }
1009: }
1010:
1011: /*----------------------------------------------------------------------
1.22 cvs 1012: SetIntVertStretchAttr
1.1 cvs 1013:
1.22 cvs 1014: Put a IntVertStretch attribute on element el if its base element
1.1 cvs 1015: (Base for a MSUBSUP, MSUP or MSUB; UnderOverBase for a MUNDEROVER,
1016: a MUNDER of a MOVER) contains only a MO element that is a vertically
1017: stretchable symbol.
1018: -----------------------------------------------------------------------*/
1019: #ifdef __STDC__
1.22 cvs 1020: void SetIntVertStretchAttr (Element el, Document doc, int base, Element* selEl)
1.1 cvs 1021: #else /* __STDC__*/
1.22 cvs 1022: void SetIntVertStretchAttr (el, doc, base, selEl)
1.1 cvs 1023: Element el;
1024: Document doc;
1025: int base;
1026: Element* selEl;
1027: #endif /* __STDC__*/
1028: {
1029: Element child, sibling, textEl, symbolEl, parent, operator;
1030: ElementType elType;
1031: Attribute attr;
1032: AttributeType attrType;
1.47 cvs 1033: int len;
1034: Language lang;
1.15 cvs 1035: CHAR_T alphabet;
1.49 cvs 1036: UCHAR_T text[2];
1037: unsigned char c;
1.1 cvs 1038:
1039: if (el == NULL)
1040: return;
1041: operator = NULL;
1042: if (base == 0)
1043: /* it's a MO */
1044: {
1045: parent = TtaGetParent (el);
1046: if (parent != NULL)
1047: {
1048: elType = TtaGetElementType (parent);
1049: if (elType.ElTypeNum != MathML_EL_Base &&
1050: elType.ElTypeNum != MathML_EL_UnderOverBase &&
1051: elType.ElTypeNum != MathML_EL_MSUBSUP &&
1052: elType.ElTypeNum != MathML_EL_MSUB &&
1053: elType.ElTypeNum != MathML_EL_MSUP &&
1054: elType.ElTypeNum != MathML_EL_MUNDEROVER &&
1055: elType.ElTypeNum != MathML_EL_MUNDER &&
1056: elType.ElTypeNum != MathML_EL_MUNDEROVER)
1057: operator = el;
1058: }
1059: }
1060: else
1061: /* it's not a MO */
1062: {
1063: /* search the Base or UnderOverBase child */
1064: child = TtaGetFirstChild (el);
1065: if (child != NULL)
1066: {
1067: elType = TtaGetElementType (child);
1068: if (elType.ElTypeNum == base)
1069: /* the first child is a Base or UnderOverBase */
1070: {
1071: child = TtaGetFirstChild (child);
1072: if (child != NULL)
1073: {
1074: elType = TtaGetElementType (child);
1075: if (elType.ElTypeNum == MathML_EL_MO)
1076: /* its first child is a MO */
1077: {
1078: sibling = child;
1079: TtaNextSibling (&sibling);
1080: if (sibling == NULL)
1081: /* there is no other child */
1082: operator = child;
1083: }
1084: }
1085: }
1086: }
1087: }
1088: if (operator != NULL)
1089: {
1090: textEl = TtaGetFirstChild (operator);
1091: if (textEl != NULL)
1092: {
1093: elType = TtaGetElementType (textEl);
1094: if (elType.ElTypeNum == MathML_EL_TEXT_UNIT)
1095: {
1096: len = TtaGetTextLength (textEl);
1097: if (len == 1)
1.55 cvs 1098: {
1099: len = 2;
1100: TtaGiveTextContent (textEl, text, &len, &lang);
1101: alphabet = TtaGetAlphabet (lang);
1102: if (alphabet == 'G')
1.1 cvs 1103: /* a single Symbol character */
1104: if ((int)text[0] == 242)
1105: /* Integral */
1106: {
1.22 cvs 1107: /* attach a IntVertStretch attribute */
1.1 cvs 1108: attrType.AttrSSchema = elType.ElSSchema;
1.22 cvs 1109: attrType.AttrTypeNum = MathML_ATTR_IntVertStretch;
1.1 cvs 1110: attr = TtaNewAttribute (attrType);
1111: TtaAttachAttribute (el, attr, doc);
1.22 cvs 1112: TtaSetAttributeValue (attr, MathML_ATTR_IntVertStretch_VAL_yes_, el, doc);
1.1 cvs 1113: /* replace the TEXT element by a Thot SYMBOL element*/
1114: elType.ElTypeNum = MathML_EL_SYMBOL_UNIT;
1115: symbolEl = TtaNewElement (doc, elType);
1116: TtaInsertSibling (symbolEl, textEl, FALSE, doc);
1117: if (selEl != NULL)
1118: if (*selEl == textEl)
1119: *selEl = symbolEl;
1120: TtaDeleteTree (textEl, doc);
1121: c = 'i';
1122: TtaSetGraphicsShape (symbolEl, c, doc);
1123: }
1.55 cvs 1124: }
1.1 cvs 1125: }
1126: }
1127: }
1128: }
1129:
1130: /*----------------------------------------------------------------------
1.22 cvs 1131: SetIntPlaceholderAttr
1.1 cvs 1132:
1.22 cvs 1133: Put a IntPlaceholder attribute on all Construct elements in the
1.1 cvs 1134: subtree of root el.
1135: -----------------------------------------------------------------------*/
1136: #ifdef __STDC__
1.22 cvs 1137: static void SetIntPlaceholderAttr (Element el, Document doc)
1.1 cvs 1138: #else /* __STDC__*/
1.22 cvs 1139: static void SetIntPlaceholderAttr (el, doc)
1.1 cvs 1140: Element el;
1141: Document doc;
1142: #endif /* __STDC__*/
1143: {
1144: Element child;
1145: ElementType elType;
1146: Attribute attr;
1147: AttributeType attrType;
1148:
1149: if (el == NULL)
1150: return;
1151: elType = TtaGetElementType (el);
1152: if (elType.ElTypeNum == MathML_EL_Construct &&
1.2 cvs 1153: elType.ElSSchema == GetMathMLSSchema (doc))
1.1 cvs 1154: {
1155: attrType.AttrSSchema = elType.ElSSchema;
1.22 cvs 1156: attrType.AttrTypeNum = MathML_ATTR_IntPlaceholder;
1.1 cvs 1157: attr = TtaNewAttribute (attrType);
1158: TtaAttachAttribute (el, attr, doc);
1.22 cvs 1159: TtaSetAttributeValue (attr, MathML_ATTR_IntPlaceholder_VAL_yes_, el, doc);
1.1 cvs 1160: }
1161: else
1162: {
1163: child = TtaGetFirstChild (el);
1164: while (child != NULL)
1165: {
1.22 cvs 1166: SetIntPlaceholderAttr (child, doc);
1.1 cvs 1167: TtaNextSibling (&child);
1168: }
1169: }
1170: }
1171:
1172: /*----------------------------------------------------------------------
1173: BuildMultiscript
1174:
1175: The content of a MMULTISCRIPT element has been created following
1176: the original MathML structure. Create all Thot elements defined
1177: in the MathML S schema.
1178: -----------------------------------------------------------------------*/
1179: #ifdef __STDC__
1180: static void BuildMultiscript (Element elMMULTISCRIPT, Document doc)
1181: #else /* __STDC__*/
1182: static void BuildMultiscript (elMMULTISCRIPT, doc)
1183: Element elMMULTISCRIPT;
1184: Document doc;
1185: #endif /* __STDC__*/
1186: {
1187: Element elem, base, next, group, pair, script, prevPair, prevScript;
1188: ElementType elType, elTypeGroup, elTypePair, elTypeScript;
1.2 cvs 1189: SSchema MathMLSSchema;
1.1 cvs 1190: base = NULL;
1191: group = NULL;
1192: prevPair = NULL;
1193: prevScript = NULL;
1194:
1.2 cvs 1195: MathMLSSchema = GetMathMLSSchema (doc);
1.1 cvs 1196: elTypeGroup.ElSSchema = MathMLSSchema;
1197: elTypePair.ElSSchema = MathMLSSchema;
1198: elTypeScript.ElSSchema = MathMLSSchema;
1199:
1200: /* process all children of the MMULTISCRIPT element */
1201: elem = TtaGetFirstChild (elMMULTISCRIPT);
1202: while (elem != NULL)
1203: {
1204: /* remember the element to be processed after the current one */
1205: next = elem;
1206: TtaNextSibling (&next);
1207:
1208: /* remove the current element from the tree */
1209: TtaRemoveTree (elem, doc);
1210:
1211: if (base == NULL)
1212: /* the current element is the first child of the MMULTISCRIPT
1213: element */
1214: {
1215: /* Create a MultiscriptBase element as the first child of
1216: MMULTISCRIPT and move the current element as the first child
1217: of the MultiscriptBase element */
1218: elTypeGroup.ElTypeNum = MathML_EL_MultiscriptBase;
1219: base = TtaNewElement (doc, elTypeGroup);
1220: TtaInsertFirstChild (&base, elMMULTISCRIPT, doc);
1221: TtaInsertFirstChild (&elem, base, doc);
1222: }
1223: else
1224: /* the current element is a subscript or a superscript */
1225: {
1226: if (group == NULL)
1227: /* there is no PostscriptPairs element. Create one */
1228: {
1229: elTypeGroup.ElTypeNum = MathML_EL_PostscriptPairs;
1230: group = TtaNewElement (doc, elTypeGroup);
1231: TtaInsertSibling (group, base, FALSE, doc);
1232: elTypePair.ElTypeNum = MathML_EL_PostscriptPair;
1233: /* create a first and a last PostscriptPair as placeholders */
1.47 cvs 1234: pair = TtaNewTree (doc, elTypePair, "");
1.1 cvs 1235: TtaInsertFirstChild (&pair, group, doc);
1.22 cvs 1236: SetIntPlaceholderAttr (pair, doc);
1.1 cvs 1237: prevPair = pair;
1.47 cvs 1238: pair = TtaNewTree (doc, elTypePair, "");
1.1 cvs 1239: TtaInsertSibling (pair, prevPair, FALSE, doc);
1.22 cvs 1240: SetIntPlaceholderAttr (pair, doc);
1.1 cvs 1241: prevScript = NULL;
1242: }
1243: if (prevScript == NULL)
1244: /* the current element is the first subscript or superscript
1245: in a pair */
1246: {
1247: /* create a PostscriptPair or PrescriptPair element */
1248: pair = TtaNewElement (doc, elTypePair);
1249: if (prevPair == NULL)
1250: TtaInsertFirstChild (&pair, group, doc);
1251: else
1252: TtaInsertSibling (pair, prevPair, FALSE, doc);
1253: prevPair = pair;
1254: /* create a MSubscript element */
1255: elTypeScript.ElTypeNum = MathML_EL_MSubscript;
1256: script = TtaNewElement (doc, elTypeScript);
1257: TtaInsertFirstChild (&script, pair, doc);
1258: prevScript = script;
1259: }
1260: else
1261: /* the current element is a superscript in a pair */
1262: {
1263: /* create a MSuperscript element */
1264: elTypeScript.ElTypeNum = MathML_EL_MSuperscript;
1265: script = TtaNewElement (doc, elTypeScript);
1266: /* insert it as a sibling of the previous MSubscript element */
1267: TtaInsertSibling (script, prevScript, FALSE, doc);
1268: prevScript = NULL;
1269: }
1270: /* insert the current element as a child of the new MSuperscript or
1271: MSubscript element */
1272: TtaInsertFirstChild (&elem, script, doc);
1.22 cvs 1273: SetIntPlaceholderAttr (elem, doc);
1.1 cvs 1274: }
1275:
1276: CreatePlaceholders (elem, doc);
1277:
1278: /* get next child of the MMULTISCRIPT element */
1279: elem = next;
1280: if (elem != NULL)
1281: {
1282: elType = TtaGetElementType (elem);
1283: if (elType.ElSSchema == MathMLSSchema &&
1284: elType.ElTypeNum == MathML_EL_PrescriptPairs)
1285: /* the next element is a PrescriptPairs */
1286: {
1287: /* if there there is no PostscriptPairs element, create one as a
1288: placeholder */
1289: if (elTypeGroup.ElTypeNum != MathML_EL_PostscriptPairs)
1290: {
1291: elTypeGroup.ElTypeNum = MathML_EL_PostscriptPairs;
1.47 cvs 1292: group = TtaNewTree (doc, elTypeGroup, "");
1.1 cvs 1293: TtaInsertSibling (group, elem, TRUE, doc);
1.22 cvs 1294: SetIntPlaceholderAttr (group, doc);
1.1 cvs 1295: }
1296: /* the following elements will be interpreted as sub- superscripts
1297: in PrescriptPair elements, wich will be children of this
1298: PrescriptPairs element */
1299: elTypeGroup.ElTypeNum = MathML_EL_PrescriptPairs;
1300: elTypePair.ElTypeNum = MathML_EL_PrescriptPair;
1301: group = elem;
1302: /* create a first and a last PostscriptPair as placeholders */
1.47 cvs 1303: pair = TtaNewTree (doc, elTypePair, "");
1.1 cvs 1304: TtaInsertFirstChild (&pair, group, doc);
1.22 cvs 1305: SetIntPlaceholderAttr (pair, doc);
1.1 cvs 1306: prevPair = pair;
1.47 cvs 1307: pair = TtaNewTree (doc, elTypePair, "");
1.1 cvs 1308: TtaInsertSibling (pair, prevPair, FALSE, doc);
1.22 cvs 1309: SetIntPlaceholderAttr (pair, doc);
1.1 cvs 1310: prevScript = NULL;
1311: TtaNextSibling (&elem);
1312: }
1313: }
1314: }
1315: /* all children of element MMULTISCRIPTS have been processed */
1316: /* if the last group processed is not a PrescriptPairs element,
1317: create one as a placeholder */
1318: if (elTypeGroup.ElTypeNum != MathML_EL_PrescriptPairs && base != NULL)
1319: {
1320: elTypeGroup.ElTypeNum = MathML_EL_PrescriptPairs;
1.47 cvs 1321: elem = TtaNewTree (doc, elTypeGroup, "");
1.1 cvs 1322: if (group == NULL)
1323: group = base;
1324: TtaInsertSibling (elem, group, TRUE, doc);
1.22 cvs 1325: SetIntPlaceholderAttr (elem, doc);
1.1 cvs 1326: }
1327: }
1328:
1.39 cvs 1329: /*----------------------------------------------------------------------
1330: CreateWrapper
1331:
1332: Create an element of type wrapperType as a child of element el and
1333: move all chidren of element el within the new element.
1334: -----------------------------------------------------------------------*/
1335: #ifdef __STDC__
1336: static void CreateWrapper (Element el, int wrapperType, Document doc)
1337: #else /* __STDC__*/
1338: static void CreateWrapper (el, wrapperType, doc)
1339: Element el;
1340: int wrapperType;
1341: Document doc;
1342: #endif /* __STDC__*/
1343: {
1344: Element wrapper, child, prevChild, nextChild;
1345: ElementType elType;
1346:
1347: child = TtaGetFirstChild (el);
1348: elType.ElSSchema = GetMathMLSSchema (doc);
1349: elType.ElTypeNum = wrapperType;
1350: wrapper = TtaNewElement (doc, elType);
1351: TtaInsertFirstChild (&wrapper, el, doc);
1352: prevChild = NULL;
1353: while (child)
1354: {
1355: nextChild = child;
1356: TtaNextSibling (&nextChild);
1357: TtaRemoveTree (child, doc);
1358: if (prevChild == NULL)
1359: TtaInsertFirstChild (&child, wrapper, doc);
1360: else
1361: TtaInsertSibling (child, prevChild, FALSE, doc);
1362: prevChild = child;
1363: child = nextChild;
1364: }
1365: }
1.5 cvs 1366:
1367: /*----------------------------------------------------------------------
1368: CheckMTable
1369:
1370: The content of a MTABLE element has been created following
1371: the original MathML structure. Create all Thot elements defined
1372: in the MathML S schema.
1.64 cvs 1373: If placeholder, associate an attribute IntPlaceholder with all
1374: cells generated in a MathML table.
1.5 cvs 1375: -----------------------------------------------------------------------*/
1376: #ifdef __STDC__
1.64 cvs 1377: void CheckMTable (Element elMTABLE, Document doc, ThotBool placeholder)
1.5 cvs 1378: #else /* __STDC__*/
1.64 cvs 1379: void CheckMTable (elMTABLE, doc, placeholder)
1.5 cvs 1380: Element elMTABLE;
1381: Document doc;
1.64 cvs 1382: ThotBool placeholder;
1.5 cvs 1383: #endif /* __STDC__*/
1384: {
1385: ElementType elType;
1386: Element MTableHead, MTableBody, row, nextRow, el, prevRow, cell,
1.40 cvs 1387: nextCell, newMTD, firstColHead;
1.5 cvs 1388: SSchema MathMLSSchema;
1389:
1390: MathMLSSchema = GetMathMLSSchema (doc);
1391: row = TtaGetFirstChild (elMTABLE);
1392:
1393: /* create a MTable_head as the first child of element MTABLE */
1394: elType.ElSSchema = MathMLSSchema;
1395: elType.ElTypeNum = MathML_EL_MTable_head;
1396: MTableHead = TtaNewElement (doc, elType);
1397: TtaInsertFirstChild (&MTableHead, elMTABLE, doc);
1398: elType.ElTypeNum = MathML_EL_MColumn_head;
1.47 cvs 1399: firstColHead = TtaNewTree (doc, elType, "");
1.5 cvs 1400: TtaInsertFirstChild (&firstColHead, MTableHead, doc);
1401:
1402: /* create a MTable_body */
1403: elType.ElSSchema = MathMLSSchema;
1404: elType.ElTypeNum = MathML_EL_MTable_body;
1405: MTableBody = TtaNewElement (doc, elType);
1406: TtaInsertSibling (MTableBody, MTableHead, FALSE, doc);
1407:
1408: /* move all children of element MTABLE into the new MTable_body element
1409: and wrap each non-MTR element with a MTR */
1410: prevRow = NULL;
1411: while (row)
1412: {
1413: nextRow = row;
1414: TtaNextSibling (&nextRow);
1415: elType = TtaGetElementType (row);
1416: TtaRemoveTree (row, doc);
1417: if (TtaSameSSchemas (elType.ElSSchema, MathMLSSchema) &&
1418: (elType.ElTypeNum == MathML_EL_XMLcomment ||
1419: elType.ElTypeNum == MathML_EL_MTR))
1420: {
1421: if (prevRow == NULL)
1422: TtaInsertFirstChild (&row, MTableBody, doc);
1423: else
1424: TtaInsertSibling (row, prevRow, FALSE, doc);
1425: prevRow = row;
1426: if (elType.ElTypeNum == MathML_EL_MTR)
1427: cell = TtaGetFirstChild (row);
1428: else
1429: cell = NULL;
1430: }
1431: else
1432: /* this child is not a MTR nor a comment, create a MTR element */
1433: {
1434: elType.ElSSchema = MathMLSSchema;
1435: elType.ElTypeNum = MathML_EL_MTR;
1436: el = TtaNewElement (doc, elType);
1437: if (prevRow == NULL)
1438: TtaInsertFirstChild (&el, MTableBody, doc);
1439: else
1440: TtaInsertSibling (el, prevRow, FALSE, doc);
1441: TtaInsertFirstChild (&row, el, doc);
1442: cell = row;
1443: prevRow = el;
1444: }
1445: while (cell)
1446: /* check all children of the current MTR element */
1447: {
1448: nextCell = cell;
1449: TtaNextSibling (&nextCell);
1450: elType = TtaGetElementType (cell);
1451: if (!TtaSameSSchemas (elType.ElSSchema, MathMLSSchema) ||
1452: (elType.ElTypeNum != MathML_EL_XMLcomment &&
1453: elType.ElTypeNum != MathML_EL_MTD))
1454: /* this is not a MTD nor a comment, create a wrapping MTD */
1455: {
1456: elType.ElSSchema = MathMLSSchema;
1457: elType.ElTypeNum = MathML_EL_MTD;
1458: newMTD = TtaNewElement (doc, elType);
1459: TtaInsertSibling (newMTD, cell, TRUE, doc);
1460: TtaRemoveTree (cell, doc);
1461: TtaInsertFirstChild (&cell, newMTD, doc);
1462: cell = newMTD;
1463: }
1464: if (elType.ElTypeNum == MathML_EL_MTD)
1465: /* This is a MTD element. Wrap its contents with a CellWrapper */
1.39 cvs 1466: CreateWrapper (cell, MathML_EL_CellWrapper, doc);
1.5 cvs 1467: cell = nextCell;
1468: }
1469: row = nextRow;
1470: }
1.64 cvs 1471: CheckAllRows (elMTABLE, doc, placeholder);
1.5 cvs 1472: }
1.12 cvs 1473:
1.46 cvs 1474: /*----------------------------------------------------------------------
1475: SetMcharContent
1476: Set the content of the mchar element according to the value of
1477: its name attribute
1478: -----------------------------------------------------------------------*/
1479: #ifdef __STDC__
1480: void SetMcharContent (Element el, Document doc)
1481: #else /* __STDC__*/
1482: void SetMcharContent (el, doc)
1483: Element el;
1484: Document doc;
1485: #endif /* __STDC__*/
1486: {
1487: ElementType elType;
1488: AttributeType attrType;
1489: Attribute attr;
1490: Element leaf;
1491: int length;
1492: CHAR_T name[MAX_ENTITY_LENGTH];
1493: UCHAR_T value[MAX_ENTITY_LENGTH];
1494: CHAR_T alphabet;
1495: Language lang;
1496:
1497: if (el)
1498: {
1499: /* get the name attribute */
1500: elType = TtaGetElementType (el);
1501: attrType.AttrSSchema = elType.ElSSchema;
1502: attrType.AttrTypeNum = MathML_ATTR_name;
1503: attr = TtaGetAttribute (el, attrType);
1504: if (attr)
1505: {
1506: leaf = TtaGetFirstChild (el);
1507: if (!leaf)
1508: /* there is no text leaf. Create one */
1509: {
1510: elType.ElTypeNum = MathML_EL_TEXT_UNIT;
1511: leaf = TtaNewElement (doc, elType);
1512: TtaInsertFirstChild (&leaf, el, doc);
1513: }
1514: length = MAX_ENTITY_LENGTH - 1;
1515: TtaGiveTextAttributeValue (attr, name, &length);
1.67 cvs 1516: MapMathMLEntity (name, value, &alphabet);
1.46 cvs 1517: if (alphabet == EOS)
1518: /* unknown name */
1519: {
1520: /* by default display a question mark */
1521: value[0] = '?';
1522: value[1] = EOS;
1523: lang = TtaGetLanguageIdFromAlphabet('L');
1524: }
1525: else
1526: {
1527: lang = TtaGetLanguageIdFromAlphabet(alphabet);
1528: }
1529: SetElemLineNumber (leaf);
1530: TtaSetTextContent (leaf, value, lang, doc);
1531: TtaSetAccessRight (leaf, ReadOnly, doc);
1532: }
1533: }
1534: }
1.1 cvs 1535:
1536: /*----------------------------------------------------------------------
1537: SetFontstyleAttr
1538: The content of a MI element has been created or modified.
1539: Create or change attribute IntFontstyle for that element accordingly.
1540: -----------------------------------------------------------------------*/
1541: #ifdef __STDC__
1542: void SetFontstyleAttr (Element el, Document doc)
1543: #else /* __STDC__*/
1544: void SetFontstyleAttr (el, doc)
1545: Element el;
1546: Document doc;
1547: #endif /* __STDC__*/
1548: {
1549: ElementType elType;
1550: AttributeType attrType;
1551: Attribute attr, IntAttr;
1.54 cvs 1552: Element textEl;
1.1 cvs 1553: int len;
1.54 cvs 1554: STRING value;
1555: ThotBool italic;
1.1 cvs 1556:
1557: if (el != NULL)
1558: {
1559: /* search the fontstyle attribute */
1560: elType = TtaGetElementType (el);
1561: attrType.AttrSSchema = elType.ElSSchema;
1562: attrType.AttrTypeNum = MathML_ATTR_fontstyle;
1563: attr = TtaGetAttribute (el, attrType);
1564: attrType.AttrTypeNum = MathML_ATTR_IntFontstyle;
1565: IntAttr = TtaGetAttribute (el, attrType);
1566: if (attr != NULL)
1567: /* there is a fontstyle attribute. Remove the corresponding
1568: internal attribute that is not needed */
1569: {
1570: if (IntAttr != NULL)
1.54 cvs 1571: TtaRemoveAttribute (el, IntAttr, doc);
1.1 cvs 1572: }
1573: else
1574: /* there is no fontstyle attribute. Create an internal attribute
1575: IntFontstyle with a value that depends on the content of the MI */
1576: {
1577: /* get content length */
1578: len = TtaGetElementVolume (el);
1579: if (len > 1)
1580: /* put an attribute IntFontstyle = IntNormal */
1581: {
1582: if (IntAttr == NULL)
1583: {
1584: IntAttr = TtaNewAttribute (attrType);
1585: TtaAttachAttribute (el, IntAttr, doc);
1586: }
1587: TtaSetAttributeValue (IntAttr, MathML_ATTR_IntFontstyle_VAL_IntNormal,
1588: el, doc);
1589: }
1590: else
1591: /* MI contains a single character. Remove attribute IntFontstyle
1.54 cvs 1592: if it exists, except if it's ImaginaryI, ExponentialE or
1593: DifferentialD. */
1.1 cvs 1594: {
1.54 cvs 1595: italic = TRUE;
1596: textEl = TtaGetFirstChild (el);
1597: if (textEl != NULL)
1598: {
1599: /* is there an attribute EntityName on that character? */
1600: attrType.AttrTypeNum = MathML_ATTR_EntityName;
1601: attr = TtaGetAttribute (textEl, attrType);
1602: if (attr)
1603: {
1604: len = TtaGetTextAttributeLength (attr);
1605: if (len > 0)
1606: {
1607: value = TtaAllocString (len+1);
1608: TtaGiveTextAttributeValue (attr, value, &len);
1609: if (ustrcmp (value, TEXT("ⅈ")) == 0 ||
1610: ustrcmp (value, TEXT("ⅇ")) == 0 ||
1611: ustrcmp (value, TEXT("ⅆ")) == 0)
1612: italic = FALSE;
1613: TtaFreeMemory (value);
1614: }
1615: }
1616: if (italic)
1617: {
1618: if (IntAttr != NULL)
1619: TtaRemoveAttribute (el, IntAttr, doc);
1620: }
1621: else
1622: {
1623: /* put an attribute IntFontstyle = IntNormal */
1624: if (IntAttr == NULL)
1625: {
1626: attrType.AttrTypeNum = MathML_ATTR_IntFontstyle;
1627: IntAttr = TtaNewAttribute (attrType);
1628: TtaAttachAttribute (el, IntAttr, doc);
1629: }
1630: TtaSetAttributeValue (IntAttr, MathML_ATTR_IntFontstyle_VAL_IntNormal,
1631: el, doc);
1632: }
1633: }
1.1 cvs 1634: }
1635: }
1636: }
1637: }
1638:
1639: /*----------------------------------------------------------------------
1.22 cvs 1640: SetIntAddSpaceAttr
1.1 cvs 1641: The content of a MO element has been created or modified.
1.22 cvs 1642: Create or change attribute IntAddSpace for that element accordingly.
1.1 cvs 1643: -----------------------------------------------------------------------*/
1644: #ifdef __STDC__
1.22 cvs 1645: void SetIntAddSpaceAttr (Element el, Document doc)
1.1 cvs 1646: #else /* __STDC__*/
1.22 cvs 1647: void SetIntAddSpaceAttr (el, doc)
1.1 cvs 1648: Element el;
1649: Document doc;
1650: #endif /* __STDC__*/
1651: {
1652: Element textEl, previous;
1653: ElementType elType;
1654: AttributeType attrType;
1.60 cvs 1655: Attribute attr, formAttr;
1656: int len, val, form;
1.1 cvs 1657: #define BUFLEN 10
1.15 cvs 1658: UCHAR_T text[BUFLEN];
1.1 cvs 1659: Language lang;
1.15 cvs 1660: CHAR_T alphabet;
1.1 cvs 1661:
1.60 cvs 1662: /* get the content of the mo element */
1.1 cvs 1663: textEl = TtaGetFirstChild (el);
1664: if (textEl != NULL)
1.60 cvs 1665: /* the mo element is not empty */
1.1 cvs 1666: {
1.60 cvs 1667: /* does the mo element have an IntAddSpace attribute? */
1.1 cvs 1668: elType = TtaGetElementType (el);
1669: attrType.AttrSSchema = elType.ElSSchema;
1.22 cvs 1670: attrType.AttrTypeNum = MathML_ATTR_IntAddSpace;
1.1 cvs 1671: attr = TtaGetAttribute (el, attrType);
1672: if (attr == NULL)
1.60 cvs 1673: /* no IntAddSpace Attr, create one */
1.1 cvs 1674: {
1675: attr = TtaNewAttribute (attrType);
1676: TtaAttachAttribute (el, attr, doc);
1677: }
1.60 cvs 1678: /* nospace by default */
1.22 cvs 1679: val = MathML_ATTR_IntAddSpace_VAL_nospace;
1.60 cvs 1680: /* does the mo element have a form attribute? */
1681: attrType.AttrTypeNum = MathML_ATTR_form;
1682: formAttr = TtaGetAttribute (el, attrType);
1683: if (formAttr)
1684: /* there is a form attribute */
1685: {
1686: form = TtaGetAttributeValue (formAttr);
1687: switch (form)
1688: {
1689: case MathML_ATTR_form_VAL_prefix:
1690: val = MathML_ATTR_IntAddSpace_VAL_nospace;
1691: break;
1692: case MathML_ATTR_form_VAL_infix:
1693: val = MathML_ATTR_IntAddSpace_VAL_both;
1694: break;
1695: case MathML_ATTR_form_VAL_postfix:
1696: val = MathML_ATTR_IntAddSpace_VAL_spaceafter;
1697: break;
1698: }
1699: }
1700: else
1701: /* no form attribute. Analyze the content */
1702: {
1703: len = TtaGetTextLength (textEl);
1704: if (len > 0 && len < BUFLEN)
1705: {
1706: len = BUFLEN;
1707: TtaGiveTextContent (textEl, text, &len, &lang);
1708: alphabet = TtaGetAlphabet (lang);
1709: if (len == 1)
1710: /* the mo element contains a single character */
1711: if (alphabet == 'L')
1712: /* ISO-Latin 1 character */
1713: {
1714: if (text[0] == '-')
1715: /* prefix or infix operator? */
1716: {
1717: previous = el;
1718: TtaPreviousSibling (&previous);
1719: if (previous == NULL)
1720: /* no previous sibling => prefix operator */
1721: val = MathML_ATTR_IntAddSpace_VAL_nospace;
1722: else
1723: {
1724: elType = TtaGetElementType (previous);
1725: if (elType.ElTypeNum == MathML_EL_MO)
1726: /* after an operator => prefix operator */
1727: val = MathML_ATTR_IntAddSpace_VAL_nospace;
1728: else
1729: /* infix operator */
1730: val = MathML_ATTR_IntAddSpace_VAL_both;
1731: }
1732: }
1733: else if (text[0] == '+' ||
1734: text[0] == '&' ||
1735: text[0] == '*' ||
1736: text[0] == '<' ||
1737: text[0] == '=' ||
1738: text[0] == '>' ||
1739: text[0] == '^')
1740: /* infix operator */
1741: val = MathML_ATTR_IntAddSpace_VAL_both;
1742: else if (text[0] == ',' ||
1743: text[0] == ';')
1744: /* separator */
1745: val = MathML_ATTR_IntAddSpace_VAL_spaceafter;
1746: }
1747: else if (alphabet == 'G')
1748: /* Symbol character set */
1749: if ((int)text[0] == 163 || /* less or equal */
1750: (int)text[0] == 177 || /* plus or minus */
1751: (int)text[0] == 179 || /* greater or equal */
1752: (int)text[0] == 180 || /* times */
1753: (int)text[0] == 184 || /* divide */
1754: (int)text[0] == 185 || /* not equal */
1755: (int)text[0] == 186 || /* identical */
1756: (int)text[0] == 187 || /* equivalent */
1757: (int)text[0] == 196 || /* circle times */
1758: (int)text[0] == 197 || /* circle plus */
1759: ((int)text[0] >= 199 && (int)text[0] <= 209) || /* */
1760: (int)text[0] == 217 || /* and */
1761: (int)text[0] == 218 ) /* or */
1762: /* infix operator */
1763: val = MathML_ATTR_IntAddSpace_VAL_both;
1764: }
1765: }
1.1 cvs 1766: TtaSetAttributeValue (attr, val, el, doc);
1767: }
1768: }
1769:
1770:
1771: /*----------------------------------------------------------------------
1772: ChangeTypeOfElement
1773: Change the type of element elem into newTypeNum
1774: -----------------------------------------------------------------------*/
1775: #ifdef __STDC__
1776: void ChangeTypeOfElement (Element elem, Document doc, int newTypeNum)
1777: #else /* __STDC__*/
1778: void ChangeTypeOfElement (elem, doc, newTypeNum)
1779: Element elem;
1780: Document doc;
1781: int newTypeNum;
1782: #endif /* __STDC__*/
1783:
1784: {
1785: Element prev, next, parent;
1.10 cvs 1786:
1787: parent = NULL;
1.1 cvs 1788: prev = elem;
1789: TtaPreviousSibling (&prev);
1790: if (prev == NULL)
1791: {
1792: next = elem;
1793: TtaNextSibling (&next);
1794: if (next == NULL)
1795: parent = TtaGetParent (elem);
1796: }
1797: TtaRemoveTree (elem, doc);
1798: ChangeElementType (elem, newTypeNum);
1799: if (prev != NULL)
1800: TtaInsertSibling (elem, prev, FALSE, doc);
1801: else if (next != NULL)
1802: TtaInsertSibling (elem, next, TRUE, doc);
1803: else
1804: TtaInsertFirstChild (&elem, parent, doc);
1805: }
1806:
1807:
1808: /*----------------------------------------------------------------------
1.58 cvs 1809: ChildOfMRowOrInferred
1810: Return TRUE if element el is a child of a MROW element or an
1811: inferred MROW element
1812: ----------------------------------------------------------------------*/
1813: #ifdef __STDC__
1814: ThotBool ChildOfMRowOrInferred (Element el)
1815: #else
1816: ThotBool ChildOfMRowOrInferred (el)
1817: Element el;
1818: #endif
1819: {
1820: ElementType elType;
1821: Element parent;
1822: ThotBool result;
1823:
1824: result = FALSE;
1825: parent = TtaGetParent (el);
1826: if (parent)
1827: {
1828: elType = TtaGetElementType (parent);
1829: result = (elType.ElTypeNum == MathML_EL_MROW ||
1830: elType.ElTypeNum == MathML_EL_SqrtBase ||
1831: elType.ElTypeNum == MathML_EL_MSTYLE ||
1832: elType.ElTypeNum == MathML_EL_MERROR ||
1833: elType.ElTypeNum == MathML_EL_MPADDED ||
1834: elType.ElTypeNum == MathML_EL_MPHANTOM ||
1835: elType.ElTypeNum == MathML_EL_MENCLOSE ||
1836: elType.ElTypeNum == MathML_EL_CellWrapper ||
1837: elType.ElTypeNum == MathML_EL_FencedExpression);
1838: }
1839: return result;
1840: }
1841:
1842: /*----------------------------------------------------------------------
1.1 cvs 1843: CheckFence
1.58 cvs 1844: If el is a MO element, if it's a child of a MROW (or equivalent)
1845: element and if it contains a single fence character, transform the MO
1846: into a MF and the fence character into a Thot symbol.
1.1 cvs 1847: ----------------------------------------------------------------------*/
1848: #ifdef __STDC__
1.56 cvs 1849: static void CheckFence (Element el, Document doc)
1.1 cvs 1850: #else
1.56 cvs 1851: static void CheckFence (el, doc)
1.1 cvs 1852: Element el;
1853: Document doc;
1854:
1855: #endif
1856: {
1.46 cvs 1857: ElementType elType;
1.58 cvs 1858: Element content;
1.1 cvs 1859: AttributeType attrType;
1.46 cvs 1860: Attribute attr, attrStretchy;
1.47 cvs 1861: int len, val;
1.58 cvs 1862: Language lang;
1863: CHAR_T alphabet;
1.49 cvs 1864: UCHAR_T text[2];
1865: unsigned char c;
1.1 cvs 1866:
1867: elType = TtaGetElementType (el);
1868: if (elType.ElTypeNum == MathML_EL_MO)
1.58 cvs 1869: /* the element is a MO */
1870: {
1871: if (ChildOfMRowOrInferred (el))
1872: {
1873: content = TtaGetFirstChild (el);
1874: if (content != NULL)
1875: {
1876: elType = TtaGetElementType (content);
1877: if (elType.ElTypeNum == MathML_EL_TEXT_UNIT)
1878: {
1879: len = TtaGetTextLength (content);
1880: if (len == 1)
1.1 cvs 1881: {
1882: len = 2;
1883: TtaGiveTextContent (content, text, &len, &lang);
1884: alphabet = TtaGetAlphabet (lang);
1.55 cvs 1885: if (alphabet == 'L')
1886: /* it contains a single character */
1887: if (text[0] == TEXT('(') || text[0] == TEXT(')') ||
1888: text[0] == TEXT('[') || text[0] == TEXT(']') ||
1889: text[0] == TEXT('{') || text[0] == TEXT('}') ||
1890: text[0] == TEXT('|'))
1891: {
1892: /* remove the content of the MO element */
1893: TtaDeleteTree (content, doc);
1894: /* change the MO element into a MF element */
1895: ChangeTypeOfElement (el, doc, MathML_EL_MF);
1896:
1897: /* is there an attribute stretchy on this mo element? */
1898: attrType.AttrSSchema = elType.ElSSchema;
1899: attrType.AttrTypeNum = MathML_ATTR_stretchy;
1900: attrStretchy = TtaGetAttribute (el, attrType);
1901: if (attrStretchy)
1902: val = TtaGetAttributeValue (attrStretchy);
1903: else
1904: val = MathML_ATTR_stretchy_VAL_true;
1905: if (val == MathML_ATTR_stretchy_VAL_true)
1906: {
1907: /* attach a IntVertStretch attribute to the MF element*/
1908: attrType.AttrTypeNum = MathML_ATTR_IntVertStretch;
1909: attr = TtaNewAttribute (attrType);
1910: TtaAttachAttribute (el, attr, doc);
1911: TtaSetAttributeValue (attr,
1912: MathML_ATTR_IntVertStretch_VAL_yes_, el, doc);
1913: }
1914: /* create a new content for the MF element */
1915: if (text[0] == TEXT('|'))
1916: {
1.1 cvs 1917: elType.ElTypeNum = MathML_EL_GRAPHICS_UNIT;
1918: c = 'v';
1919: }
1920: else
1921: {
1922: elType.ElTypeNum = MathML_EL_SYMBOL_UNIT;
1.49 cvs 1923: c = (char) text[0];
1.1 cvs 1924: }
1925: content = TtaNewElement (doc, elType);
1926: TtaInsertFirstChild (&content, el, doc);
1927: TtaSetGraphicsShape (content, c, doc);
1928: }
1929: }
1.58 cvs 1930: }
1931: }
1932: }
1933: }
1.1 cvs 1934: }
1935:
1936: /*----------------------------------------------------------------------
1937: CreateFencedSeparators
1938: Create FencedSeparator elements within the fencedExpression
1939: according to attribute separators of the MFENCED element.
1940: ----------------------------------------------------------------------*/
1941: #ifdef __STDC__
1.18 cvs 1942: void CreateFencedSeparators (Element fencedExpression, Document doc, ThotBool record)
1.1 cvs 1943: #else
1.17 cvs 1944: void CreateFencedSeparators (fencedExpression, doc, record)
1.1 cvs 1945: Element fencedExpression;
1946: Document doc;
1.18 cvs 1947: ThotBool record;
1.1 cvs 1948:
1949: #endif
1950: {
1951: ElementType elType;
1952: Element child, separator, leaf, next, prev, mfenced;
1953: AttributeType attrType;
1954: Attribute attr;
1955: int length, sep, i;
1956: Language lang;
1.46 cvs 1957: CHAR_T text[32], sepValue[4];
1.1 cvs 1958:
1959: /* get the separators attribute */
1960: mfenced = TtaGetParent (fencedExpression);
1961: elType = TtaGetElementType (fencedExpression);
1962: attrType.AttrSSchema = elType.ElSSchema;
1963: attrType.AttrTypeNum = MathML_ATTR_separators;
1964: text[0] = ','; /* default value is sparators="," */
1965: text[1] = EOS;
1966: length = 1;
1967: attr = TtaGetAttribute (mfenced, attrType);
1968: if (attr != NULL)
1969: {
1970: length = 31;
1971: TtaGiveTextAttributeValue (attr, text, &length);
1972: }
1973:
1974: /* create FencedSeparator elements in the FencedExpression */
1975: prev = NULL;
1976: sep = 0;
1977: /* skip leading spaces in attribute separators */
1978: while (text[sep] <= SPACE && text[sep] != EOS)
1979: sep++;
1980: /* if attribute separators is empty or contains only spaces, do not
1981: insert any separator element */
1982: if (text[sep] != EOS)
1983: {
1984: child = TtaGetFirstChild (fencedExpression);
1985: while (child != NULL)
1986: {
1987: next = child;
1988: TtaNextSibling (&next);
1989: elType = TtaGetElementType (child);
1990: if (elType.ElTypeNum != MathML_EL_Construct)
1991: {
1992: if (prev != NULL)
1993: {
1994: elType.ElTypeNum = MathML_EL_FencedSeparator;
1995: separator = TtaNewElement (doc, elType);
1996: TtaInsertSibling (separator, prev, FALSE, doc);
1997: elType.ElTypeNum = MathML_EL_TEXT_UNIT;
1998: leaf = TtaNewElement (doc, elType);
1999: TtaInsertFirstChild (&leaf, separator, doc);
2000: sepValue[0] = text[sep];
2001: sepValue[1] = SPACE;
2002: sepValue[2] = EOS;
2003: lang = TtaGetLanguageIdFromAlphabet('L');
2004: TtaSetTextContent (leaf, sepValue, lang, doc);
2005: /* is there a following non-space character in separators? */
2006: i = sep + 1;
2007: while (text[i] <= SPACE && text[i] != EOS)
2008: i++;
2009: if (text[i] > SPACE && text[i] != EOS)
2010: sep = i;
1.17 cvs 2011: if (record)
2012: TtaRegisterElementCreate (separator, doc);
1.1 cvs 2013: }
2014: prev = child;
2015: }
2016: child = next;
2017: }
2018: }
2019: }
2020:
2021:
2022: /*----------------------------------------------------------------------
2023: TransformMFENCED
2024: Transform the content of a MFENCED element: create elements
2025: OpeningFence, FencedExpression, ClosingFence and FencedSeparator.
2026: ----------------------------------------------------------------------*/
2027: #ifdef __STDC__
1.46 cvs 2028: static void TransformMFENCED (Element el, Document doc)
1.1 cvs 2029: #else
1.46 cvs 2030: static void TransformMFENCED (el, doc)
1.1 cvs 2031: Element el;
2032: Document doc;
2033:
2034: #endif
2035: {
2036: ElementType elType;
2037: Element child, fencedExpression, leaf, fence, next, prev,
2038: firstChild;
2039: AttributeType attrType;
2040: Attribute attr;
1.47 cvs 2041: int length;
1.49 cvs 2042: CHAR_T text[32];
2043: char c;
1.1 cvs 2044:
2045: child = TtaGetFirstChild (el);
2046: if (child != NULL)
2047: elType = TtaGetElementType (child);
2048: if (child != NULL && elType.ElTypeNum == MathML_EL_OpeningFence)
2049: /* The first child of this MFENCED element is an OpeningFence.
2050: This MFENCED expression has already been transformed, possibly
2051: by the Transform command */
2052: {
2053: TtaNextSibling (&child);
2054: fencedExpression = child;
2055: if (fencedExpression != NULL)
2056: elType = TtaGetElementType (fencedExpression);
2057: if (elType.ElTypeNum == MathML_EL_FencedExpression)
2058: /* the second child is a FencedExpression. OK.
2059: Remove all existing FencedSeparator elements */
2060: {
2061: child = TtaGetFirstChild (fencedExpression);
2062: prev = NULL;
2063: while (child != NULL)
2064: {
2065: elType = TtaGetElementType (child);
2066: next = child;
2067: TtaNextSibling (&next);
2068: if (elType.ElTypeNum == MathML_EL_FencedSeparator)
2069: /* Remove this separator */
2070: TtaDeleteTree (child, doc);
2071: child = next;
2072: }
2073: /* create FencedSeparator elements in the FencedExpression */
1.17 cvs 2074: CreateFencedSeparators (fencedExpression, doc, FALSE);
1.1 cvs 2075: }
2076: }
2077: else
2078: /* this MFENCED element must be transformed */
2079: {
2080: /* create a FencedExpression element as a child of the MFENCED elem. */
2081: elType = TtaGetElementType (el);
2082: elType.ElTypeNum = MathML_EL_FencedExpression;
2083: fencedExpression = TtaNewElement (doc, elType);
2084: TtaInsertFirstChild (&fencedExpression, el, doc);
2085: if (child == NULL)
2086: /* empty MFENCED element */
2087: {
2088: elType.ElTypeNum = MathML_EL_Construct;
2089: child = TtaNewElement (doc, elType);
2090: TtaInsertFirstChild (&child, fencedExpression, doc);
1.22 cvs 2091: SetIntPlaceholderAttr (child, doc);
1.1 cvs 2092: }
2093: else
2094: {
2095: /* move the content of the MFENCED element within the new
2096: FencedExpression element */
2097: prev = NULL;
2098: firstChild = NULL;
2099: while (child != NULL)
2100: {
2101: next = child;
2102: TtaNextSibling (&next);
2103: TtaRemoveTree (child, doc);
2104: if (prev == NULL)
2105: {
2106: TtaInsertFirstChild (&child, fencedExpression, doc);
2107: firstChild = child;
2108: }
2109: else
2110: TtaInsertSibling (child, prev, FALSE, doc);
2111: prev = child;
2112: child = next;
2113: }
2114:
2115: /* create FencedSeparator elements in the FencedExpression */
1.17 cvs 2116: CreateFencedSeparators (fencedExpression, doc, FALSE);
1.1 cvs 2117:
2118: /* Create placeholders within the FencedExpression element */
2119: CreatePlaceholders (firstChild, doc);
2120: }
2121:
2122: /* create the OpeningFence element according to the open attribute */
2123: c = '(';
2124: attrType.AttrSSchema = elType.ElSSchema;
2125: attrType.AttrTypeNum = MathML_ATTR_open;
2126: attr = TtaGetAttribute (el, attrType);
2127: if (attr != NULL)
2128: {
2129: length = 7;
2130: TtaGiveTextAttributeValue (attr, text, &length);
1.49 cvs 2131: c = (char)text[0];
1.1 cvs 2132: }
2133: elType.ElTypeNum = MathML_EL_OpeningFence;
2134: fence = TtaNewElement (doc, elType);
2135: TtaInsertSibling (fence, fencedExpression, TRUE, doc);
2136: elType.ElTypeNum = MathML_EL_SYMBOL_UNIT;
2137: leaf = TtaNewElement (doc, elType);
2138: TtaInsertFirstChild (&leaf, fence, doc);
2139: TtaSetGraphicsShape (leaf, c, doc);
2140:
2141: /* create the ClosingFence element according to close attribute */
2142: c = ')';
2143: attrType.AttrTypeNum = MathML_ATTR_close;
2144: attr = TtaGetAttribute (el, attrType);
2145: if (attr != NULL)
2146: {
2147: length = 7;
2148: TtaGiveTextAttributeValue (attr, text, &length);
1.49 cvs 2149: c = (char) text[0];
1.1 cvs 2150: }
2151: elType.ElTypeNum = MathML_EL_ClosingFence;
2152: fence = TtaNewElement (doc, elType);
2153: TtaInsertSibling (fence, fencedExpression, FALSE, doc);
2154: elType.ElTypeNum = MathML_EL_SYMBOL_UNIT;
2155: leaf = TtaNewElement (doc, elType);
2156: TtaInsertFirstChild (&leaf, fence, doc);
2157: TtaSetGraphicsShape (leaf, c, doc);
2158: }
2159: }
2160:
2161: /*----------------------------------------------------------------------
1.59 cvs 2162: MathMLScriptShift
2163: The MathML attribute attr (superscriptshift or subscriptshift) is associated
2164: with element el (a msub, msup or msubsup).
2165: If value is not NULL, generate the corresponding Thot VertPos rule for the
2166: Subscript or Superscript child of el.
2167: If value is NULL, remove the Thot VertPos rule.
2168: -----------------------------------------------------------------------*/
2169: #ifdef __STDC__
2170: void MathMLScriptShift (Document doc, Element el, STRING value, int attr)
2171: #else /* __STDC__*/
2172: void MathMLScriptShift (doc, el, value, attr)
2173: Document doc;
2174: Element el;
2175: STRING value;
2176: int attr;
2177: #endif /* __STDC__*/
2178: {
2179: ElementType elType;
2180: Element script, child;
2181: int scrType;
2182: PresentationValue pval;
2183: PresentationContext ctxt;
2184:
2185: /* get the Superscript or Subscript child of el */
2186: if (attr == MathML_ATTR_superscriptshift)
2187: scrType = MathML_EL_Superscript;
2188: else if (attr == MathML_ATTR_subscriptshift)
2189: scrType = MathML_EL_Subscript;
2190: else
2191: return;
2192: script = NULL;
2193: child = TtaGetFirstChild (el);
2194: while (!script && child)
2195: {
2196: elType = TtaGetElementType (child);
2197: if (elType.ElTypeNum == scrType)
2198: script = child;
2199: else
2200: TtaNextSibling (&child);
2201: }
2202: if (script)
2203: /* Superscript or Subscript element found */
2204: {
2205: ctxt = TtaGetSpecificStyleContext (doc);
2206: if (!value)
2207: /* remove the presentation rule */
2208: {
2209: ctxt->destroy = TRUE;
2210: TtaSetStylePresentation (PRVertPos, script, NULL, ctxt, pval);
2211: }
2212: else
2213: {
2214: ctxt->destroy = FALSE;
2215: /* parse the attribute value (a number followed by a unit) */
2216: value = TtaSkipWCBlanks (value);
2217: value = ParseCSSUnit (value, &pval);
2218: if (pval.typed_data.unit != STYLE_UNIT_INVALID)
2219: {
2220: if (attr == MathML_ATTR_superscriptshift)
2221: pval.typed_data.value = - pval.typed_data.value;
2222: TtaSetStylePresentation (PRVertPos, script, NULL, ctxt, pval);
2223: }
2224: }
2225: TtaFreeMemory (ctxt);
2226: }
2227: }
2228:
2229: /*----------------------------------------------------------------------
2230: SetScriptShift
2231: If element el (which is a msup, msub or msubsup) has an attribute
2232: att (which is subscriptshift or superscriptshift), generate the
2233: corresponding Thot presentation rule.
2234: ----------------------------------------------------------------------*/
2235: #ifdef __STDC__
2236: static void SetScriptShift (Element el, Document doc, int att)
2237: #else
2238: static void SetScriptShift (el, doc, att)
2239: Element el;
2240: Document doc;
2241: int att;
2242:
2243: #endif
2244: {
2245: AttributeType attrType;
2246: ElementType elType;
2247: Attribute attr;
2248: STRING value;
2249: int length;
2250:
2251: elType = TtaGetElementType (el);
2252: attrType.AttrSSchema = elType.ElSSchema;
2253: attrType.AttrTypeNum = att;
2254: attr = TtaGetAttribute (el, attrType);
2255: if (attr)
2256: {
2257: length = TtaGetTextAttributeLength (attr);
2258: if (length > 0)
2259: {
2260: value = TtaAllocString (length+1);
2261: value[0] = EOS;
2262: TtaGiveTextAttributeValue (attr, value, &length);
2263: MathMLScriptShift (doc, el, value, att);
2264: TtaFreeMemory (value);
2265: }
2266: }
2267: }
2268:
2269: /*----------------------------------------------------------------------
1.1 cvs 2270: MathMLElementComplete
2271: Check the Thot structure of the MathML element el.
2272: ----------------------------------------------------------------------*/
2273: #ifdef __STDC__
1.56 cvs 2274: void MathMLElementComplete (Element el, Document doc, int *error)
1.1 cvs 2275: #else
1.56 cvs 2276: void MathMLElementComplete (el, doc, error)
1.1 cvs 2277: Element el;
2278: Document doc;
1.56 cvs 2279: int *error;
1.1 cvs 2280:
2281: #endif
2282: {
1.60 cvs 2283: ElementType elType, parentType, childType;
1.1 cvs 2284: Element child, parent, new, prev, next;
2285: AttributeType attrType;
2286: Attribute attr;
1.56 cvs 2287: SSchema MathMLSSchema;
2288: ThotBool ok;
1.1 cvs 2289:
1.56 cvs 2290: ok = TRUE;
2291: *error = 0;
1.1 cvs 2292: elType = TtaGetElementType (el);
1.2 cvs 2293: MathMLSSchema = GetMathMLSSchema (doc);
1.1 cvs 2294:
2295: if (elType.ElSSchema != MathMLSSchema)
2296: /* this is not a MathML element. It's the HTML element <math>, or
2297: any other element containing a MathML expression */
2298: {
2299: if (TtaGetFirstChild (el) == NULL && !TtaIsLeaf (elType))
2300: /* this element is empty. Create a MathML element as it's child */
2301: {
2302: elType.ElSSchema = MathMLSSchema;
2303: elType.ElTypeNum = MathML_EL_MathML;
2304: new = TtaNewElement (doc, elType);
2305: TtaInsertFirstChild (&new, el, doc);
2306: /* Create a placeholder within the MathML element */
2307: elType.ElTypeNum = MathML_EL_Construct;
2308: child = TtaNewElement (doc, elType);
2309: TtaInsertFirstChild (&child, new, doc);
2310: attrType.AttrSSchema = elType.ElSSchema;
1.22 cvs 2311: attrType.AttrTypeNum = MathML_ATTR_IntPlaceholder;
1.1 cvs 2312: attr = TtaNewAttribute (attrType);
2313: TtaAttachAttribute (child, attr, doc);
1.28 cvs 2314: TtaSetAttributeValue (attr, MathML_ATTR_IntPlaceholder_VAL_yes_,
2315: child, doc);
1.1 cvs 2316: }
2317: }
2318: else
2319: {
2320: switch (elType.ElTypeNum)
2321: {
2322: case MathML_EL_TEXT_UNIT:
2323: CheckTextElement (&el, doc);
2324: break;
2325: case MathML_EL_MI:
2326: SetFontstyleAttr (el, doc);
2327: break;
2328: case MathML_EL_MO:
1.22 cvs 2329: SetIntAddSpaceAttr (el, doc);
2330: SetIntVertStretchAttr (el, doc, 0, NULL);
1.58 cvs 2331: /* if the MO element is a child of a MROW (or equivalent) and if it
2332: contains a fence character, transform this MO into MF and
2333: transform the fence character into a Thot SYMBOL */
2334: CheckFence (el, doc);
1.1 cvs 2335: break;
1.60 cvs 2336: case MathML_EL_MSPACE:
2337: break;
1.39 cvs 2338: case MathML_EL_MROW:
1.55 cvs 2339: /* Create placeholders within the MROW */
2340: CreatePlaceholders (TtaGetFirstChild (el), doc);
1.39 cvs 2341: break;
2342: case MathML_EL_MFRAC:
1.54 cvs 2343: case MathML_EL_BevelledMFRAC:
1.39 cvs 2344: /* end of a fraction. Create a Numerator and a Denominator */
1.56 cvs 2345: ok = CheckMathSubExpressions (el, MathML_EL_Numerator,
2346: MathML_EL_Denominator, 0, doc);
1.39 cvs 2347: break;
2348: case MathML_EL_MSQRT:
1.50 cvs 2349: /* end of a Square Root */
2350: /* Create placeholders within the element */
2351: CreatePlaceholders (TtaGetFirstChild (el), doc);
2352: /* Create a SqrtBase that contains all children of the MSQRT */
1.39 cvs 2353: CreateWrapper (el, MathML_EL_SqrtBase, doc);
2354: break;
1.1 cvs 2355: case MathML_EL_MROOT:
2356: /* end of a Root. Create a RootBase and an Index */
1.56 cvs 2357: ok = CheckMathSubExpressions (el, MathML_EL_RootBase,
2358: MathML_EL_Index, 0, doc);
1.1 cvs 2359: break;
1.50 cvs 2360: case MathML_EL_MENCLOSE:
2361: /* Create placeholders within the element */
2362: CreatePlaceholders (TtaGetFirstChild (el), doc);
2363: break;
1.39 cvs 2364: case MathML_EL_MSTYLE:
2365: case MathML_EL_MERROR:
2366: case MathML_EL_MPADDED:
2367: case MathML_EL_MPHANTOM:
2368: /* Create placeholders within the element */
2369: CreatePlaceholders (TtaGetFirstChild (el), doc);
1.1 cvs 2370: break;
2371: case MathML_EL_MFENCED:
2372: TransformMFENCED (el, doc);
2373: break;
2374: case MathML_EL_MSUB:
2375: /* end of a MSUB. Create Base and Subscript */
1.56 cvs 2376: ok = CheckMathSubExpressions (el, MathML_EL_Base,
2377: MathML_EL_Subscript, 0, doc);
1.59 cvs 2378: SetScriptShift (el, doc, MathML_ATTR_subscriptshift);
1.22 cvs 2379: SetIntVertStretchAttr (el, doc, MathML_EL_Base, NULL);
1.1 cvs 2380: break;
2381: case MathML_EL_MSUP:
2382: /* end of a MSUP. Create Base and Superscript */
1.56 cvs 2383: ok = CheckMathSubExpressions (el, MathML_EL_Base,
2384: MathML_EL_Superscript, 0, doc);
1.59 cvs 2385: SetScriptShift (el, doc, MathML_ATTR_superscriptshift);
1.22 cvs 2386: SetIntVertStretchAttr (el, doc, MathML_EL_Base, NULL);
1.1 cvs 2387: break;
1.39 cvs 2388: case MathML_EL_MSUBSUP:
2389: /* end of a MSUBSUP. Create Base, Subscript, and Superscript */
1.56 cvs 2390: ok = CheckMathSubExpressions (el, MathML_EL_Base,
2391: MathML_EL_Subscript,
2392: MathML_EL_Superscript, doc);
1.59 cvs 2393: SetScriptShift (el, doc, MathML_ATTR_subscriptshift);
2394: SetScriptShift (el, doc, MathML_ATTR_superscriptshift);
1.39 cvs 2395: SetIntVertStretchAttr (el, doc, MathML_EL_Base, NULL);
1.1 cvs 2396: break;
2397: case MathML_EL_MUNDER:
2398: /* end of a MUNDER. Create UnderOverBase, and Underscript */
1.56 cvs 2399: ok = CheckMathSubExpressions (el, MathML_EL_UnderOverBase,
2400: MathML_EL_Underscript, 0, doc);
1.22 cvs 2401: SetIntHorizStretchAttr (el, doc);
2402: SetIntVertStretchAttr (el, doc, MathML_EL_UnderOverBase, NULL);
1.1 cvs 2403: break;
2404: case MathML_EL_MOVER:
2405: /* end of a MOVER. Create UnderOverBase, and Overscript */
1.56 cvs 2406: ok = CheckMathSubExpressions (el, MathML_EL_UnderOverBase,
2407: MathML_EL_Overscript, 0, doc);
1.22 cvs 2408: SetIntHorizStretchAttr (el, doc);
2409: SetIntVertStretchAttr (el, doc, MathML_EL_UnderOverBase, NULL);
1.1 cvs 2410: break;
1.39 cvs 2411: case MathML_EL_MUNDEROVER:
2412: /* end of a MUNDEROVER. Create UnderOverBase, Underscript, and
2413: Overscript */
1.56 cvs 2414: ok = CheckMathSubExpressions (el, MathML_EL_UnderOverBase,
2415: MathML_EL_Underscript,
2416: MathML_EL_Overscript, doc);
1.39 cvs 2417: SetIntHorizStretchAttr (el, doc);
2418: SetIntVertStretchAttr (el, doc, MathML_EL_UnderOverBase, NULL);
2419: break;
1.1 cvs 2420: case MathML_EL_MMULTISCRIPTS:
2421: /* end of a MMULTISCRIPTS. Create all elements defined in the
2422: MathML S schema */
2423: BuildMultiscript (el, doc);
1.5 cvs 2424: break;
2425: case MathML_EL_MTABLE:
2426: /* end of a MTABLE. Create all elements defined in the MathML S
2427: schema */
1.64 cvs 2428: CheckMTable (el, doc, TRUE);
1.1 cvs 2429: break;
1.39 cvs 2430: case MathML_EL_MTD:
2431: /* Create placeholders within the table cell */
2432: CreatePlaceholders (TtaGetFirstChild (el), doc);
1.46 cvs 2433: break;
2434: case MathML_EL_MCHAR:
2435: /* set the content of the mchar element according to the value of
2436: its name attribute */
2437: SetMcharContent (el, doc);
1.39 cvs 2438: break;
2439: case MathML_EL_MACTION:
2440: /* Create placeholders within the MACTION element */
2441: CreatePlaceholders (TtaGetFirstChild (el), doc);
1.1 cvs 2442: break;
2443: default:
2444: break;
2445: }
2446: parent = TtaGetParent (el);
2447: parentType = TtaGetElementType (parent);
2448: if (parentType.ElSSchema != elType.ElSSchema)
2449: /* root of a MathML tree, Create a MathML element if there is no */
2450: if (elType.ElTypeNum != MathML_EL_MathML)
2451: {
2452: elType.ElSSchema = MathMLSSchema;
2453: elType.ElTypeNum = MathML_EL_MathML;
2454: new = TtaNewElement (doc, elType);
2455: TtaInsertSibling (new, el, TRUE, doc);
2456: next = el;
2457: TtaNextSibling (&next);
2458: TtaRemoveTree (el, doc);
2459: TtaInsertFirstChild (&el, new, doc);
2460: prev = el;
2461: while (next != NULL)
2462: {
2463: child = next;
2464: TtaNextSibling (&next);
2465: TtaRemoveTree (child, doc);
2466: TtaInsertSibling (child, prev, FALSE, doc);
2467: prev = child;
2468: }
2469: /* Create placeholders within the MathML element */
2470: CreatePlaceholders (el, doc);
2471: }
2472: }
1.56 cvs 2473: if (!ok)
2474: /* send an error message */
2475: *error = 1;
1.1 cvs 2476: }
2477:
2478: /*----------------------------------------------------------------------
1.24 cvs 2479: SetFontfamily
2480: -----------------------------------------------------------------------*/
2481: #ifdef __STDC__
2482: void SetFontfamily (Document doc, Element el, STRING value)
2483: #else /* __STDC__*/
2484: void SetFontfamily (doc, el, value)
2485: Document doc;
2486: Element el;
2487: STRING value;
2488: #endif /* __STDC__*/
2489: {
2490: #define buflen 50
2491: CHAR_T css_command[buflen+20];
2492:
1.26 cvs 2493: usprintf (css_command, TEXT("font-family: %s"), value);
1.24 cvs 2494: ParseHTMLSpecificStyle (el, css_command, doc, FALSE);
2495: }
2496:
2497: /*----------------------------------------------------------------------
1.58 cvs 2498: MathMLAttrToStyleProperty
2499: The MathML attribute attr is associated with element el. Generate
2500: the corresponding style property for this element.
1.24 cvs 2501: -----------------------------------------------------------------------*/
2502: #ifdef __STDC__
1.58 cvs 2503: void MathMLAttrToStyleProperty (Document doc, Element el, STRING value, int attr)
1.24 cvs 2504: #else /* __STDC__*/
1.58 cvs 2505: void MathMLAttrToStyleProperty (doc, el, value, attr)
1.24 cvs 2506: Document doc;
2507: Element el;
2508: STRING value;
1.58 cvs 2509: int attr;
1.24 cvs 2510: #endif /* __STDC__*/
2511: {
2512: #define buflen 50
2513: CHAR_T css_command[buflen+20];
1.58 cvs 2514:
2515: switch (attr)
2516: {
2517: case MathML_ATTR_fontsize:
2518: usprintf (css_command, TEXT("font-size: %s"), value);
2519: break;
2520: case MathML_ATTR_lspace:
2521: usprintf (css_command, TEXT("padding-left: %s"), value);
2522: break;
2523: case MathML_ATTR_rspace:
2524: usprintf (css_command, TEXT("padding-right: %s"), value);
2525: break;
2526: }
1.24 cvs 2527: ParseHTMLSpecificStyle (el, css_command, doc, FALSE);
2528: }
2529:
2530: /*----------------------------------------------------------------------
1.60 cvs 2531: MathMLSetScriptLevel
2532: A scriptlevel attribute with value value is associated with element el.
2533: Generate the corresponding style property for this element.
2534: -----------------------------------------------------------------------*/
2535: #ifdef __STDC__
2536: void MathMLSetScriptLevel (Document doc, Element el, STRING value)
2537: #else /* __STDC__*/
2538: void MathMLSetScriptLevel (doc, el, value)
2539: Document doc;
2540: Element el;
2541: STRING value;
2542: #endif /* __STDC__*/
2543: {
2544: PresentationValue pval;
2545: PresentationContext ctxt;
2546: ThotBool relative;
2547: int percentage;
2548:
2549: ctxt = TtaGetSpecificStyleContext (doc);
2550: if (!value)
2551: /* remove the presentation rule */
2552: {
2553: ctxt->destroy = TRUE;
2554: TtaSetStylePresentation (PRSize, el, NULL, ctxt, pval);
2555: }
2556: else
2557: {
2558: ctxt->destroy = FALSE;
2559: /* parse the attribute value (an optional sign and an integer) */
2560: value = TtaSkipWCBlanks (value);
2561: relative = (value[0] == '-' || value[0] == '+');
2562: value = ParseCSSUnit (value, &pval);
2563: if (pval.typed_data.unit != STYLE_UNIT_REL &&
2564: pval.typed_data.real)
2565: /* this is an error: it should be an integer without any unit name */
2566: /* error */;
2567: else
2568: {
2569: if (relative)
2570: {
1.63 cvs 2571: percentage = 100;
1.60 cvs 2572: if (pval.typed_data.value == 0)
2573: /* scriptlevel="+0" */
2574: percentage = 100;
2575: else if (pval.typed_data.value == 1)
2576: /* scriptlevel="+1" */
2577: percentage = 71;
2578: else if (pval.typed_data.value == 2)
2579: /* scriptlevel="+2" */
2580: percentage = 50;
2581: else if (pval.typed_data.value >= 3)
2582: /* scriptlevel="+3" or more */
2583: percentage = 35;
2584: else if (pval.typed_data.value == -1)
2585: /* scriptlevel="-1" */
2586: percentage = 141;
2587: else if (pval.typed_data.value == -2)
2588: /* scriptlevel="-2" */
2589: percentage = 200;
2590: else if (pval.typed_data.value <= -3)
2591: /* scriptlevel="-3" or less */
2592: percentage = 282;
2593: pval.typed_data.value = percentage;
2594: pval.typed_data.unit = STYLE_UNIT_PERCENT;
2595: TtaSetStylePresentation (PRSize, el, NULL, ctxt, pval);
2596: }
2597: else
2598: /* absolute value */
2599: {
2600: /**** ****/;
2601: }
2602: }
2603: }
2604: TtaFreeMemory (ctxt);
2605: }
2606:
2607: /*----------------------------------------------------------------------
2608: MathMLSpacingAttr
2609: The MathML attribute attr (height, width or depth) is associated
2610: with element el (a mspace or mpadding).
2611: If value is not NULL, generate the corresponding Thot presentation rule for
2612: the element.
2613: If value is NULL, remove the corresponding Thot presentation rule.
2614: -----------------------------------------------------------------------*/
2615: #ifdef __STDC__
2616: void MathMLSpacingAttr (Document doc, Element el, STRING value, int attr)
2617: #else /* __STDC__*/
2618: void MathMLSpacingAttr (doc, el, value, attr)
2619: Document doc;
2620: Element el;
2621: STRING value;
2622: int attr;
2623: #endif /* __STDC__*/
2624: {
2625: ElementType elType;
2626: PresentationValue pval;
2627: PresentationContext ctxt;
2628: int ruleType;
2629:
2630: /* provisionally, handles only mspace elements */
2631: elType = TtaGetElementType (el);
2632: if (elType.ElTypeNum != MathML_EL_MSPACE)
2633: return;
2634: switch (attr)
2635: {
2636: case MathML_ATTR_width_:
2637: ruleType = PRWidth;
2638: break;
2639: case MathML_ATTR_height_:
2640: ruleType = PRPaddingTop;
2641: break;
2642: case MathML_ATTR_depth_:
2643: ruleType = PRPaddingBottom;
2644: break;
2645: default:
2646: return;
2647: }
2648: ctxt = TtaGetSpecificStyleContext (doc);
2649: if (!value)
2650: /* remove the presentation rule */
2651: {
2652: ctxt->destroy = TRUE;
2653: TtaSetStylePresentation (ruleType, el, NULL, ctxt, pval);
2654: }
2655: else
2656: {
2657: ctxt->destroy = FALSE;
2658: /* parse the attribute value (a number followed by a unit) */
2659: value = TtaSkipWCBlanks (value);
2660: value = ParseCSSUnit (value, &pval);
2661: /***** we should accept namedspace for width *****/
2662: if (pval.typed_data.unit != STYLE_UNIT_INVALID)
2663: TtaSetStylePresentation (ruleType, el, NULL, ctxt, pval);
2664: }
2665: TtaFreeMemory (ctxt);
2666: }
2667:
2668:
2669: /*----------------------------------------------------------------------
1.1 cvs 2670: MathMLAttributeComplete
1.58 cvs 2671: The XML parser has completed parsing attribute attr (as well as its value)
2672: that is associated with element el in document doc.
1.1 cvs 2673: ----------------------------------------------------------------------*/
2674: #ifdef __STDC__
2675: void MathMLAttributeComplete (Attribute attr, Element el, Document doc)
2676: #else
2677: void MathMLAttributeComplete (attr, el, doc)
2678: Attribute attr;
2679: Element el;
2680: Document doc;
2681:
2682: #endif
2683: {
1.23 cvs 2684: AttributeType attrType;
2685: int attrKind;
1.50 cvs 2686: ElementType elType;
1.23 cvs 2687: #define buflen 50
1.33 cvs 2688: STRING value;
1.50 cvs 2689: int val, length;
1.23 cvs 2690:
1.58 cvs 2691: /* first get the type of that attribute */
1.23 cvs 2692: TtaGiveAttributeType (attr, &attrType, &attrKind);
1.54 cvs 2693: if (attrType.AttrTypeNum == MathML_ATTR_bevelled)
1.58 cvs 2694: /* it's a bevelled attribute */
1.50 cvs 2695: {
2696: val = TtaGetAttributeValue (attr);
1.54 cvs 2697: if (val == MathML_ATTR_bevelled_VAL_true)
2698: /* bevelled = true. Transform MFRAC into BevelledMFRAC */
1.50 cvs 2699: {
2700: elType = TtaGetElementType (el);
2701: if (elType.ElTypeNum == MathML_EL_MFRAC)
1.54 cvs 2702: ChangeTypeOfElement (el, doc, MathML_EL_BevelledMFRAC);
1.50 cvs 2703: }
2704: }
2705: else if (attrType.AttrTypeNum == MathML_ATTR_color ||
1.24 cvs 2706: attrType.AttrTypeNum == MathML_ATTR_background_ ||
2707: attrType.AttrTypeNum == MathML_ATTR_fontsize ||
1.58 cvs 2708: attrType.AttrTypeNum == MathML_ATTR_fontfamily ||
2709: attrType.AttrTypeNum == MathML_ATTR_lspace ||
1.60 cvs 2710: attrType.AttrTypeNum == MathML_ATTR_rspace ||
2711: attrType.AttrTypeNum == MathML_ATTR_scriptlevel ||
2712: attrType.AttrTypeNum == MathML_ATTR_width_ ||
2713: attrType.AttrTypeNum == MathML_ATTR_height_ ||
2714: attrType.AttrTypeNum == MathML_ATTR_depth_ )
1.23 cvs 2715: {
2716: length = TtaGetTextAttributeLength (attr);
2717: if (length >= buflen)
2718: length = buflen - 1;
2719: if (length > 0)
2720: {
1.42 cvs 2721: value = TtaAllocString (buflen);
1.33 cvs 2722: value[0] = EOS;
2723: TtaGiveTextAttributeValue (attr, value, &length);
2724: switch (attrType.AttrTypeNum)
2725: {
2726: case MathML_ATTR_color:
1.24 cvs 2727: HTMLSetForegroundColor (doc, el, value);
2728: break;
1.33 cvs 2729: case MathML_ATTR_background_:
1.24 cvs 2730: HTMLSetBackgroundColor (doc, el, value);
2731: break;
1.33 cvs 2732: case MathML_ATTR_fontfamily:
1.24 cvs 2733: SetFontfamily (doc, el, value);
1.58 cvs 2734: break;
2735: case MathML_ATTR_fontsize:
2736: case MathML_ATTR_lspace:
2737: case MathML_ATTR_rspace:
1.60 cvs 2738: MathMLAttrToStyleProperty (doc, el, value,attrType.AttrTypeNum);
2739: break;
2740: case MathML_ATTR_scriptlevel:
2741: MathMLSetScriptLevel (doc, el, value);
2742: break;
2743: case MathML_ATTR_width_:
2744: case MathML_ATTR_height_:
2745: case MathML_ATTR_depth_:
2746: MathMLSpacingAttr (doc, el, value, attrType.AttrTypeNum);
1.59 cvs 2747: break;
2748: default:
1.24 cvs 2749: break;
1.33 cvs 2750: }
2751: TtaFreeMemory (value);
1.23 cvs 2752: }
2753: }
1.1 cvs 2754: }
2755:
2756: /*----------------------------------------------------------------------
2757: MathMLGetDTDName
2758: ----------------------------------------------------------------------*/
2759: #ifdef __STDC__
1.14 cvs 2760: void MathMLGetDTDName (STRING DTDname, STRING elementName)
1.1 cvs 2761: #else
2762: void MathMLGetDTDName (DTDname, elementName)
1.14 cvs 2763: STRING DTDname;
2764: STRING elementName;
1.1 cvs 2765:
2766: #endif
2767: {
2768: /* no other DTD allowed within MathML elements */
1.49 cvs 2769: ustrcpy (DTDname, TEXT(""));
1.1 cvs 2770: }
2771:
2772: /* end of module */
Webmaster