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