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