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