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