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