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