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