Return to MathMLbuilder.c CVS log | Up to [Public] / Amaya / amaya |
1.1 cvs 1: /* 2: * 3: * (c) COPYRIGHT MIT and INRIA, 1996. 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: 15: 16: #define THOT_EXPORT extern 1.4 cvs 17: #include "amaya.h" 1.25 cvs 18: #include "css.h" 1.17 cvs 19: #include "undo.h" 1.25 cvs 20: #include "MathML.h" 21: #include "parser.h" 1.35 cvs 22: #include "html2thot_f.h" 1.1 cvs 23: 1.41 ! cvs 24: typedef unsigned char MathEntityName[30]; 1.1 cvs 25: typedef struct _MathEntity 26: { /* a Math entity representing an operator char */ 27: MathEntityName MentityName; /* entity name */ 28: int charCode; /* decimal code of char */ 1.15 cvs 29: CHAR_T alphabet; /* 'L' = ISO-Latin-1, 'G' = Symbol */ 1.1 cvs 30: } 31: MathEntity; 32: 33: static MathEntity MathEntityTable[] = 34: { 35: /* This table MUST be in alphabetical order */ 36: /* This table contains characters from the Symbol font plus some 37: specific MathML entities */ 38: {"Agr", 65, 'G'}, 1.9 cvs 39: {"And", 217, 'G'}, 1.1 cvs 40: {"ApplyFunction", 32, 'L'}, /* render as white space */ 1.9 cvs 41: {"Backslash", 92, 'L'}, 1.1 cvs 42: {"Bgr", 66, 'G'}, 43: {"Cap", 199, 'G'}, 1.9 cvs 44: {"CenterDot", 215, 'G'}, 45: {"CirclePlus", 197, 'G'}, 46: {"CircleTimes", 196, 'G'}, 47: {"Colon", 58, 'G'}, 48: {"Congruent", 64, 'G'}, 1.1 cvs 49: {"Cup", 200, 'G'}, 50: {"Delta", 68, 'G'}, 1.9 cvs 51: {"Diamond", 168, 'G'}, 52: {"DoubleDownArrow", 223, 'G'}, 53: {"DoubleLeftArrow", 220, 'G'}, 54: {"DoubleLeftRightArrow", 219, 'G'}, 55: {"DoubleRightArrow", 222, 'G'}, 56: {"DoubleUpArrow", 221, 'G'}, 57: {"DownArrow", 175, 'G'}, 58: {"DownTee", 94, 'G'}, 1.1 cvs 59: {"EEgr", 72, 'G'}, 60: {"Egr", 69, 'G'}, 1.9 cvs 61: {"Element", 206, 'G'}, 62: {"Equal", 61, 'L'}, 63: {"EqualTilde", 64, 'G'}, 64: {"Exists", 36, 'G'}, 65: {"ForAll", 34, 'G'}, 1.1 cvs 66: {"Gamma", 71, 'G'}, 1.9 cvs 67: {"GreaterEqual", 179, 'G'}, 1.1 cvs 68: {"Igr", 73, 'G'}, 69: {"Integral", 242, 'G'}, 1.9 cvs 70: {"Intersection", 199, 'G'}, 1.1 cvs 71: {"InvisibleTimes", 0, SPACE}, 72: {"Kgr", 75, 'G'}, 73: {"KHgr", 67, 'G'}, 74: {"Lambda", 76, 'G'}, 75: {"LeftArrow", 172, 'G'}, 1.9 cvs 76: {"LeftRightArrow", 171, 'G'}, 1.1 cvs 77: {"Mgr", 77, 'G'}, 78: {"Ngr", 78, 'G'}, 1.11 cvs 79: {"NonBreakingSpace", 160, 'L'}, 1.9 cvs 80: {"Not", 216, 'G'}, 81: {"NotElement", 207, 'G'}, 82: {"NotEqual", 185, 'G'}, 83: {"NotSubset", 203, 'G'}, 1.1 cvs 84: {"Ogr", 79, 'G'}, 85: {"Omega", 87, 'G'}, 1.9 cvs 86: {"Or", 218, 'G'}, 1.1 cvs 87: {"PI", 213, 'G'}, 1.9 cvs 88: {"PartialD", 182, 'G'}, 1.1 cvs 89: {"Phi", 70, 'G'}, 90: {"Pi", 80, 'G'}, 91: {"PlusMinus", 177, 'G'}, 1.9 cvs 92: {"Product", 213, 'G'}, 93: {"Proportional", 181, 'G'}, 1.1 cvs 94: {"Psi", 89, 'G'}, 95: {"Rgr", 82, 'G'}, 96: {"RightArrow", 174, 'G'}, 97: {"Sigma", 83, 'G'}, 98: {"Sol", 164, 'G'}, 1.9 cvs 99: {"Star", 42, 'L'}, 100: {"Subset", 204, 'G'}, 101: {"SubsetEqual", 205, 'G'}, 102: {"SuchThat", 39, 'G'}, 1.1 cvs 103: {"Sum", 229, 'G'}, 1.9 cvs 104: {"Superset", 201, 'G'}, 105: {"SupersetEqual", 202, 'G'}, 1.1 cvs 106: {"Tgr", 84, 'G'}, 1.9 cvs 107: {"Therefore", 92, 'G'}, 1.1 cvs 108: {"Theta", 81, 'G'}, 1.9 cvs 109: {"Tilde", 126, 'L'}, 110: {"TripleDot", 188, 'G'}, 111: {"Union", 200, 'G'}, 112: {"UpArrow", 173, 'G'}, 1.1 cvs 113: {"Upsi", 85, 'G'}, 114: {"Upsi1", 161, 'G'}, 1.13 cvs 115: {"Vee", 218, 'G'}, 1.1 cvs 116: {"Verbar", 189, 'G'}, 1.9 cvs 117: {"VerticalBar", 124, 'L'}, 1.1 cvs 118: {"Xi", 88, 'G'}, 119: {"Zgr", 90, 'G'}, 120: {"af", 32, 'L'}, /* render as white space */ 121: {"aleph", 192, 'G'}, 122: {"alpha", 97, 'G'}, 123: {"and", 217, 'G'}, 124: {"angle", 208, 'G'}, 125: {"ap", 187, 'G'}, 126: {"beta", 98, 'G'}, 127: {"bottom", 94, 'G'}, 128: {"bull", 183, 'G'}, 129: {"cap", 199, 'G'}, 130: {"chi", 99, 'G'}, 131: {"clubs", 167, 'G'}, 132: {"cong", 64, 'G'}, 133: {"copysf", 211, 'G'}, 134: {"copyssf", 227, 'G'}, 135: {"cr", 191, 'G'}, 136: {"cup", 200, 'G'}, 137: {"darr", 175, 'G'}, 138: {"dArr", 223, 'G'}, 139: {"dd", 100, 'L'}, 140: {"deg", 176, 'G'}, 141: {"delta", 100, 'G'}, 142: {"diams", 168, 'G'}, 143: {"divide", 184, 'G'}, 144: {"dtri", 209, 'G'}, 145: {"ee", 101, 'L'}, 146: {"empty", 198, 'G'}, 147: {"emsp", 32, 'G'}, 148: {"epsiv", 101, 'G'}, 149: {"equiv", 186, 'G'}, 150: {"eta", 104, 'G'}, 151: {"exist", 36, 'G'}, 152: {"florin", 166, 'G'}, 153: {"forall", 34, 'G'}, 154: {"gamma", 103, 'G'}, 155: {"ge", 179, 'G'}, 156: {"gt", 62, 'L'}, 157: {"hearts", 169, 'G'}, 158: {"horbar", 190, 'G'}, 1.8 cvs 159: {"ifraktur", 193, 'G'}, 1.1 cvs 160: {"infin", 165, 'G'}, 161: {"int", 242, 'G'}, 162: {"iota", 105, 'G'}, 163: {"isin", 206, 'G'}, 1.31 cvs 164: {"it", 0, SPACE}, 1.1 cvs 165: {"kappa", 107, 'G'}, 166: {"lambda", 108, 'G'}, 167: {"lang", 225, 'G'}, 168: {"larr", 172, 'G'}, 169: {"lArr", 220, 'G'}, 170: {"le", 163, 'G'}, 171: {"lowbar", 95, 'G'}, 172: {"loz", 224, 'G'}, 173: {"lrarr", 171, 'G'}, 174: {"lrArr", 219, 'G'}, 175: {"lsqb", 91, 'G'}, 1.6 cvs 176: {"lt", 60, 'L'}, 1.1 cvs 177: {"middot", 215, 'G'}, 178: {"mldr", 188, 'G'}, 179: {"mu", 109, 'G'}, 180: {"ne", 185, 'G'}, 181: {"not", 216, 'G'}, 182: {"notin", 207, 'G'}, 1.8 cvs 183: {"nu", 110, 'G'}, 1.1 cvs 184: {"ogr", 111, 'G'}, 185: {"omega", 119, 'G'}, 186: {"oplus", 197, 'G'}, 187: {"or", 218, 'G'}, 188: {"otimes", 196, 'G'}, 189: {"part", 182, 'G'}, 190: {"phi", 102, 'G'}, 191: {"phiv", 106, 'G'}, 192: {"pi", 112, 'G'}, 193: {"piv", 118, 'G'}, 194: {"prop", 181, 'G'}, 195: {"psi", 121, 'G'}, 196: {"radic", 214, 'G'}, 197: {"rarr", 174, 'G'}, 198: {"rArr", 222, 'G'}, 199: {"rdquo", 178, 'G'}, 200: {"regsf", 210, 'G'}, 201: {"regssf", 226, 'G'}, 202: {"rfraktur", 194, 'G'}, 203: {"rho", 114, 'G'}, 204: {"rsqb", 93, 'G'}, 205: {"sigma", 115, 'G'}, 206: {"sigmav", 86, 'G'}, 207: {"spades", 170, 'G'}, 208: {"sub", 204, 'G'}, 209: {"sube", 205, 'G'}, 210: {"subne", 203, 'G'}, 211: {"sum", 229, 'G'}, 212: {"sup", 201, 'G'}, 213: {"supe", 202, 'G'}, 214: {"tau", 116, 'G'}, 215: {"there4", 92, 'G'}, 216: {"theta", 113, 'G'}, 217: {"thetav", 74, 'G'}, 218: {"thickspace", 32, 'L'}, 219: {"times", 180, 'G'}, 220: {"trade", 212, 'G'}, 221: {"tradesf", 212, 'G'}, 222: {"tradessf", 228, 'G'}, 223: {"uarr", 173, 'G'}, 224: {"uArr", 221, 'G'}, 225: {"upsi", 117, 'G'}, 1.13 cvs 226: {"vee", 218, 'G'}, 1.1 cvs 227: {"weierp", 195, 'G'}, 228: {"xi", 120, 'G'}, 229: {"zeta", 122, 'G'}, 230: {"zzzz", -1, SPACE} /* this last entry is required */ 1.26 cvs 231: 1.1 cvs 232: }; 233: 234: static AttributeMapping MathMLAttributeMappingTable[] = 235: { 236: /* The first entry MUST be unknown_attr */ 237: /* The rest of this table MUST be in alphabetical order */ 1.41 ! cvs 238: {"unknown_attr", "", 'A', MathML_ATTR_Invalid_attribute}, ! 239: {"accent", "", 'A', MathML_ATTR_accent}, ! 240: {"accentunder", "", 'A', MathML_ATTR_accentunder}, ! 241: {"actiontype", "", 'A', MathML_ATTR_actiontype}, ! 242: {"align", "", 'A', MathML_ATTR_align}, ! 243: {"alignmentscope", "", 'A', MathML_ATTR_alignmentscope}, ! 244: {"background", "", 'A', MathML_ATTR_background_}, ! 245: {"class", "", 'A', MathML_ATTR_class}, ! 246: {"close", "", 'A', MathML_ATTR_close}, ! 247: {"columnalign", "", 'A', MathML_ATTR_columnalign}, ! 248: {"columnlines", "", 'A', MathML_ATTR_columnlines}, ! 249: {"columnspacing", "", 'A', MathML_ATTR_columnspacing}, ! 250: {"columnspan", "", 'A', MathML_ATTR_columnspan}, ! 251: {"color", "", 'A', MathML_ATTR_color}, ! 252: {"depth", "", 'A', MathML_ATTR_depth_}, ! 253: {"displaystyle", "", 'A', MathML_ATTR_displaystyle}, ! 254: {"edge", "", 'A', MathML_ATTR_edge}, ! 255: {"equalcolumns", "", 'A', MathML_ATTR_equalcolumns}, ! 256: {"equalrows", "", 'A', MathML_ATTR_equalrows}, ! 257: {"fence", "", 'A', MathML_ATTR_fence}, ! 258: {"fontfamily", "", 'A', MathML_ATTR_fontfamily}, ! 259: {"fontstyle", "", 'A', MathML_ATTR_fontstyle}, ! 260: {"fontsize", "", 'A', MathML_ATTR_fontsize}, ! 261: {"fontweight", "", 'A', MathML_ATTR_fontweight}, ! 262: {"form", "", 'A', MathML_ATTR_form}, ! 263: {"frame", "", 'A', MathML_ATTR_frame}, ! 264: {"framespacing", "", 'A', MathML_ATTR_framespacing}, ! 265: {"groupalign", "", 'A', MathML_ATTR_groupalign}, ! 266: {"height", "", 'A', MathML_ATTR_height_}, ! 267: {"id", "", 'A', MathML_ATTR_id}, ! 268: {"largeop", "", 'A', MathML_ATTR_largeop}, ! 269: {"linethickness", "", 'A', MathML_ATTR_linethickness}, ! 270: {"link", "", 'A', MathML_ATTR_link}, ! 271: {"lquote", "", 'A', MathML_ATTR_lquote}, ! 272: {"lspace", "", 'A', MathML_ATTR_lspace}, ! 273: {"maxsize", "", 'A', MathML_ATTR_maxsize}, ! 274: {"minsize", "", 'A', MathML_ATTR_minsize}, ! 275: {"movablelimits", "", 'A', MathML_ATTR_movablelimits}, ! 276: {"open", "", 'A', MathML_ATTR_open}, ! 277: {"other", "", 'A', MathML_ATTR_other}, ! 278: {"rowalign", "", 'A', MathML_ATTR_rowalign}, ! 279: {"rowlines", "", 'A', MathML_ATTR_rowlines}, ! 280: {"rowspacing", "", 'A', MathML_ATTR_rowspacing}, ! 281: {"rowspan", "", 'A', MathML_ATTR_rowspan_}, ! 282: {"rquote", "", 'A', MathML_ATTR_rquote}, ! 283: {"rspace", "", 'A', MathML_ATTR_rspace}, ! 284: {"scriptlevel", "", 'A', MathML_ATTR_scriptlevel}, ! 285: {"scriptminsize", "", 'A', MathML_ATTR_scriptminsize}, ! 286: {"scriptsizemultiplier", "", 'A', MathML_ATTR_scriptsizemultiplier}, ! 287: {"selection", "", 'A', MathML_ATTR_selection}, ! 288: {"separator", "", 'A', MathML_ATTR_separator}, ! 289: {"separators", "", 'A', MathML_ATTR_separators}, ! 290: {"stretchy", "", 'A', MathML_ATTR_stretchy}, ! 291: {"style", "", 'A', MathML_ATTR_style_}, ! 292: {"subscriptshift", "", 'A', MathML_ATTR_subscriptshift}, ! 293: {"superscriptshift", "", 'A', MathML_ATTR_superscriptshift}, ! 294: {"symmetric", "", 'A', MathML_ATTR_symmetric}, ! 295: {"width", "", 'A', MathML_ATTR_width_}, ! 296: {"zzghost", "", 'A', MathML_ATTR_Ghost_restruct}, 1.1 cvs 297: 1.41 ! cvs 298: {"", "", EOS, 0} /* Last entry. Mandatory */ 1.1 cvs 299: }; 300: 301: /* mapping table of attribute values */ 302: 303: static AttrValueMapping MathMLAttrValueMappingTable[] = 304: { 1.41 ! cvs 305: {MathML_ATTR_accent, "true", MathML_ATTR_accent_VAL_true}, ! 306: {MathML_ATTR_accent, "false", MathML_ATTR_accent_VAL_false}, ! 307: {MathML_ATTR_accentunder, "true", MathML_ATTR_accentunder_VAL_true}, ! 308: {MathML_ATTR_accentunder, "false", MathML_ATTR_accentunder_VAL_false}, ! 309: {MathML_ATTR_displaystyle, "true", MathML_ATTR_displaystyle_VAL_true}, ! 310: {MathML_ATTR_displaystyle, "false", MathML_ATTR_displaystyle_VAL_false}, ! 311: {MathML_ATTR_edge, "left", MathML_ATTR_edge_VAL_left_}, ! 312: {MathML_ATTR_edge, "right", MathML_ATTR_edge_VAL_right_}, ! 313: {MathML_ATTR_fence, "true", MathML_ATTR_fence_VAL_true}, ! 314: {MathML_ATTR_fence, "false", MathML_ATTR_fence_VAL_false}, ! 315: {MathML_ATTR_fontstyle, "italic", MathML_ATTR_fontstyle_VAL_italic}, ! 316: {MathML_ATTR_fontstyle, "normal", MathML_ATTR_fontstyle_VAL_normal_}, ! 317: {MathML_ATTR_fontweight, "normal", MathML_ATTR_fontweight_VAL_normal_}, ! 318: {MathML_ATTR_fontweight, "bold", MathML_ATTR_fontweight_VAL_bold_}, ! 319: {MathML_ATTR_form, "prefix", MathML_ATTR_form_VAL_prefix}, ! 320: {MathML_ATTR_form, "infix", MathML_ATTR_form_VAL_infix}, ! 321: {MathML_ATTR_form, "postfix", MathML_ATTR_form_VAL_postfix}, ! 322: {MathML_ATTR_frame, "none", MathML_ATTR_frame_VAL_none_}, ! 323: {MathML_ATTR_frame, "solid", MathML_ATTR_frame_VAL_solid_}, ! 324: {MathML_ATTR_frame, "dashed", MathML_ATTR_frame_VAL_dashed_}, ! 325: {MathML_ATTR_largeop, "true", MathML_ATTR_largeop_VAL_true}, ! 326: {MathML_ATTR_largeop, "false", MathML_ATTR_largeop_VAL_false}, ! 327: {MathML_ATTR_link, "document", MathML_ATTR_link_VAL_document}, ! 328: {MathML_ATTR_link, "extended", MathML_ATTR_link_VAL_extended}, ! 329: {MathML_ATTR_link, "group", MathML_ATTR_link_VAL_group}, ! 330: {MathML_ATTR_link, "locator", MathML_ATTR_link_VAL_locator}, ! 331: {MathML_ATTR_link, "simple", MathML_ATTR_link_VAL_simple}, ! 332: {MathML_ATTR_movablelimits, "true", MathML_ATTR_movablelimits_VAL_true}, ! 333: {MathML_ATTR_movablelimits, "false", MathML_ATTR_movablelimits_VAL_false}, ! 334: {MathML_ATTR_separator, "true", MathML_ATTR_separator_VAL_true}, ! 335: {MathML_ATTR_separator, "false", MathML_ATTR_separator_VAL_false}, ! 336: {MathML_ATTR_stretchy, "true", MathML_ATTR_stretchy_VAL_true}, ! 337: {MathML_ATTR_stretchy, "false", MathML_ATTR_stretchy_VAL_false}, ! 338: {MathML_ATTR_symmetric, "true", MathML_ATTR_symmetric_VAL_true}, ! 339: {MathML_ATTR_symmetric, "false", MathML_ATTR_symmetric_VAL_false}, 1.21 cvs 340: 1.41 ! cvs 341: {0, "", 0} /* Last entry. Mandatory */ 1.1 cvs 342: }; 343: 344: #define MaxMsgLength 200 345: 1.29 cvs 346: 1.12 cvs 347: #include "HTMLtable_f.h" 1.29 cvs 348: #include "Mathedit_f.h" 349: #include "XMLparser_f.h" 350: #include "styleparser_f.h" 351: #include "fetchXMLname_f.h" 1.1 cvs 352: 353: /*---------------------------------------------------------------------- 354: MapMathMLAttribute 355: Search in the Attribute Mapping Table the entry for the 356: attribute of name Attr and returns the corresponding Thot attribute type. 357: ----------------------------------------------------------------------*/ 358: #ifdef __STDC__ 1.14 cvs 359: void MapMathMLAttribute (STRING Attr, AttributeType *attrType, STRING elementName, Document doc) 1.1 cvs 360: #else 1.2 cvs 361: void MapMathMLAttribute (Attr, attrType, elementName, doc) 1.14 cvs 362: STRING Attr; 1.1 cvs 363: AttributeType *attrType; 1.14 cvs 364: STRING elementName; 1.2 cvs 365: Document doc; 1.1 cvs 366: #endif 367: { 368: int i; 369: 370: attrType->AttrTypeNum = 0; 371: attrType->AttrSSchema = NULL; 372: i = 0; 373: do 1.14 cvs 374: if (ustrcasecmp (MathMLAttributeMappingTable[i].XMLattribute, Attr)) 1.1 cvs 375: i++; 376: else 377: if (MathMLAttributeMappingTable[i].XMLelement[0] == EOS) 378: { 379: attrType->AttrTypeNum = MathMLAttributeMappingTable[i].ThotAttribute; 1.2 cvs 380: attrType->AttrSSchema = GetMathMLSSchema (doc); 1.1 cvs 381: } 1.14 cvs 382: else if (!ustrcasecmp (MathMLAttributeMappingTable[i].XMLelement, 1.1 cvs 383: elementName)) 384: { 385: attrType->AttrTypeNum = MathMLAttributeMappingTable[i].ThotAttribute; 1.2 cvs 386: attrType->AttrSSchema = GetMathMLSSchema (doc); 1.1 cvs 387: } 388: else 389: i++; 390: while (attrType->AttrTypeNum <= 0 && MathMLAttributeMappingTable[i].AttrOrContent != EOS); 391: } 392: 393: /*---------------------------------------------------------------------- 394: MapMathMLAttributeValue 395: Search in the Attribute Value Mapping Table the entry for the attribute 396: ThotAtt and its value AttrVal. Returns the corresponding Thot value. 397: ----------------------------------------------------------------------*/ 398: #ifdef __STDC__ 1.14 cvs 399: void MapMathMLAttributeValue (STRING AttrVal, AttributeType attrType, int *value) 1.1 cvs 400: #else 401: void MapMathMLAttributeValue (AttrVal, attrType, value) 1.14 cvs 402: STRING AttrVal; 1.1 cvs 403: AttributeType attrType; 404: int *value; 405: #endif 406: { 407: int i; 408: 409: *value = 0; 410: i = 0; 411: while (MathMLAttrValueMappingTable[i].ThotAttr != attrType.AttrTypeNum && 412: MathMLAttrValueMappingTable[i].ThotAttr != 0) 413: i++; 414: if (MathMLAttrValueMappingTable[i].ThotAttr == attrType.AttrTypeNum) 415: do 1.14 cvs 416: if (!ustrcasecmp (MathMLAttrValueMappingTable[i].XMLattrValue, AttrVal)) 1.1 cvs 417: *value = MathMLAttrValueMappingTable[i].ThotAttrValue; 418: else 419: i++; 420: while (*value <= 0 && MathMLAttrValueMappingTable[i].ThotAttr != 0); 421: } 422: 423: /*---------------------------------------------------------------------- 424: MapMathMLEntity 425: Search that entity in the entity table and return the corresponding value. 426: ----------------------------------------------------------------------*/ 427: #ifdef __STDC__ 1.14 cvs 428: void MapMathMLEntity (STRING entityName, STRING entityValue, int valueLength, STRING alphabet) 1.1 cvs 429: #else 430: void MapMathMLEntity (entityName, entityValue, valueLength, alphabet) 1.14 cvs 431: STRING entityName; 432: STRING entityValue; 1.1 cvs 433: int valueLength; 1.14 cvs 434: STRING alphabet; 1.1 cvs 435: 436: #endif 437: 438: { 439: int i; 440: 441: for (i = 0; MathEntityTable[i].charCode >= 0 && 1.14 cvs 442: ustrcmp (MathEntityTable[i].MentityName, entityName); 1.1 cvs 443: i++); 1.14 cvs 444: if (!ustrcmp (MathEntityTable[i].MentityName, entityName)) 1.1 cvs 445: /* entity found */ 446: { 1.15 cvs 447: entityValue[0] = (UCHAR_T) MathEntityTable[i].charCode; 1.1 cvs 448: entityValue[1] = EOS; 449: *alphabet = MathEntityTable[i].alphabet; 450: } 451: else 452: { 453: entityValue[0] = EOS; 454: *alphabet = EOS; 455: } 456: } 457: 458: /*---------------------------------------------------------------------- 459: MathMLEntityCreated 460: A MathML entity has been created by the XML parser. 1.36 cvs 461: Create an attribute EntityName containing the entity name. 1.1 cvs 462: ----------------------------------------------------------------------*/ 463: #ifdef __STDC__ 1.34 cvs 464: void MathMLEntityCreated (USTRING entityValue, Language lang, STRING entityName, Document doc) 1.1 cvs 465: #else 1.34 cvs 466: void MathMLEntityCreated (entityValue, lang, entityName, doc) 1.14 cvs 467: USTRING entityValue; 1.34 cvs 468: Language lang; 1.14 cvs 469: STRING entityName; 1.1 cvs 470: Document doc; 471: 472: #endif 473: { 474: ElementType elType; 475: Element elText; 476: AttributeType attrType; 477: Attribute attr; 478: int len; 479: #define MAX_ENTITY_LENGTH 80 1.34 cvs 480: CHAR_T buffer[MAX_ENTITY_LENGTH]; 1.1 cvs 481: 1.34 cvs 482: if (lang < 0) 483: /* unknown entity */ 484: { 485: entityValue[0] = '?'; 486: entityValue[1] = EOS; 487: lang = TtaGetLanguageIdFromAlphabet('L'); 488: } 489: XMLTextToDocument (); 490: elType.ElTypeNum = MathML_EL_TEXT_UNIT; 491: elType.ElSSchema = GetMathMLSSchema (doc); 492: elText = TtaNewElement (doc, elType); 493: SetElemLineNumber (elText); 494: XMLInsertElement (elText); 495: TtaSetTextContent (elText, entityValue, lang, doc); 1.36 cvs 496: TtaSetAccessRight (elText, ReadOnly, doc); 1.34 cvs 497: attrType.AttrSSchema = GetMathMLSSchema (doc); 498: attrType.AttrTypeNum = MathML_ATTR_EntityName; 499: attr = TtaNewAttribute (attrType); 500: TtaAttachAttribute (elText, attr, doc); 501: len = ustrlen (entityName); 502: if (len > MAX_ENTITY_LENGTH -3) 503: len = MAX_ENTITY_LENGTH -3; 504: buffer[0] = '&'; 505: ustrncpy (&buffer[1], entityName, len); 506: buffer[len+1] = ';'; 507: buffer[len+2] = EOS; 508: TtaSetAttributeText (attr, buffer, elText, doc); 1.1 cvs 509: } 1.34 cvs 510: 1.1 cvs 511: 512: /*---------------------------------------------------------------------- 513: CheckTextElement Put the content of input buffer into the document. 514: ----------------------------------------------------------------------*/ 515: #ifdef __STDC__ 516: static void CheckTextElement (Element *el, Document doc) 517: #else 518: static void CheckTextElement (el, doc) 519: Element *el; 520: Document doc; 521: 522: #endif 523: { 524: ElementType parentType, elType; 525: Element parent, new; 526: int len; 527: Language lang; 1.15 cvs 528: CHAR_T alphabet; 529: CHAR_T text[4]; 1.1 cvs 530: 531: len = TtaGetTextLength (*el); 532: if (len == 1) 533: { 534: len = 2; 535: TtaGiveTextContent (*el, text, &len, &lang); 536: alphabet = TtaGetAlphabet (lang); 537: parent = TtaGetParent (*el); 538: if (text[0] != EOS) 539: { 540: parentType = TtaGetElementType (parent); 541: elType = parentType; 542: if (parentType.ElTypeNum == MathML_EL_MF && 543: (text[0] == '(' || 544: text[0] == ')' || 545: text[0] == '[' || 546: text[0] == ']' || 547: text[0] == '{' || 548: text[0] == '}')) 549: /* Transform the text element into a Thot SYMBOL */ 550: elType.ElTypeNum = MathML_EL_SYMBOL_UNIT; 551: else if (parentType.ElTypeNum == MathML_EL_MF && 552: text[0] == '|') 553: /* Transform the text element into a Thot GRAPHIC */ 554: { 555: elType.ElTypeNum = MathML_EL_GRAPHICS_UNIT; 556: text[0] = 'v'; 557: } 558: else 559: /* a TEXT element is OK */ 560: elType.ElTypeNum = MathML_EL_TEXT_UNIT; 561: if (elType.ElTypeNum != MathML_EL_TEXT_UNIT) 562: { 563: new = TtaNewElement (doc, elType); 564: TtaInsertSibling (new, *el, FALSE, doc); 565: TtaDeleteTree (*el, doc); 566: *el = new; 567: TtaSetGraphicsShape (new, text[0], doc); 568: } 569: } 570: } 571: } 572: 573: /*---------------------------------------------------------------------- 574: ElementNeedsPlaceholder 575: returns TRUE if element el needs a sibling placeholder. 576: ----------------------------------------------------------------------*/ 577: #ifdef __STDC__ 1.18 cvs 578: ThotBool ElementNeedsPlaceholder (Element el) 1.1 cvs 579: #else 1.18 cvs 580: ThotBool ElementNeedsPlaceholder (el) 1.1 cvs 581: Element el; 582: 583: #endif 584: { 585: ElementType elType; 586: Element child, parent; 1.18 cvs 587: ThotBool ret; 1.1 cvs 588: 589: ret = FALSE; 590: elType = TtaGetElementType (el); 1.39 cvs 591: if (elType.ElTypeNum == MathML_EL_MSPACE || 592: elType.ElTypeNum == MathML_EL_MROW || 593: elType.ElTypeNum == MathML_EL_MFRAC || 594: elType.ElTypeNum == MathML_EL_MSQRT || 595: elType.ElTypeNum == MathML_EL_MROOT || 596: elType.ElTypeNum == MathML_EL_MSTYLE || 597: elType.ElTypeNum == MathML_EL_MERROR || 598: elType.ElTypeNum == MathML_EL_MPADDED || 599: elType.ElTypeNum == MathML_EL_MPHANTOM || 600: elType.ElTypeNum == MathML_EL_MFENCED || 1.1 cvs 601: elType.ElTypeNum == MathML_EL_MF || 602: elType.ElTypeNum == MathML_EL_MSUB || 603: elType.ElTypeNum == MathML_EL_MSUP || 1.39 cvs 604: elType.ElTypeNum == MathML_EL_MSUBSUP || 1.1 cvs 605: elType.ElTypeNum == MathML_EL_MUNDER || 606: elType.ElTypeNum == MathML_EL_MOVER || 607: elType.ElTypeNum == MathML_EL_MUNDEROVER || 1.28 cvs 608: elType.ElTypeNum == MathML_EL_MMULTISCRIPTS || 1.39 cvs 609: elType.ElTypeNum == MathML_EL_MTABLE || 610: elType.ElTypeNum == MathML_EL_MACTION) 1.1 cvs 611: ret = TRUE; 612: else 613: if (elType.ElTypeNum == MathML_EL_MO) 614: /* an operator that contains a single Symbol needs a placeholder, 615: except when it is in a Base or UnderOverBase */ 616: { 617: child = TtaGetFirstChild (el); 618: if (child != NULL) 619: { 620: elType = TtaGetElementType (child); 621: if (elType.ElTypeNum == MathML_EL_SYMBOL_UNIT) 622: { 623: ret = TRUE; 624: parent = TtaGetParent (el); 625: if (parent != NULL) 626: { 627: elType = TtaGetElementType (parent); 628: if (elType.ElTypeNum == MathML_EL_Base || 629: elType.ElTypeNum == MathML_EL_UnderOverBase) 630: ret = FALSE; 631: } 632: } 633: } 634: } 635: return ret; 636: } 637: 638: /*---------------------------------------------------------------------- 639: CreatePlaceholders 640: ----------------------------------------------------------------------*/ 641: #ifdef __STDC__ 642: static void CreatePlaceholders (Element el, Document doc) 643: #else 644: static void CreatePlaceholders (el, doc) 645: Element el; 646: Document doc; 647: #endif 648: { 649: Element sibling, prev, constr, child; 650: Attribute attr; 651: ElementType elType; 652: AttributeType attrType; 1.18 cvs 653: ThotBool create; 1.1 cvs 654: 1.2 cvs 655: elType.ElSSchema = GetMathMLSSchema (doc); 1.1 cvs 656: prev = NULL; 657: create = TRUE; 658: sibling = el; 659: while (sibling != NULL) 660: { 661: if (!ElementNeedsPlaceholder (sibling)) 662: create = FALSE; 663: else 664: { 665: if (sibling == el) 666: /* first element */ 667: { 668: elType = TtaGetElementType (sibling); 669: if (elType.ElTypeNum == MathML_EL_MF) 670: /* the first element is a MF. Don't create a placeholder 671: before */ 672: create = FALSE; 673: else if (elType.ElTypeNum == MathML_EL_MROW) 674: /* the first element is a MROW */ 675: { 676: child = TtaGetFirstChild (sibling); 677: if (child != NULL) 678: { 679: elType = TtaGetElementType (child); 680: if (elType.ElTypeNum != MathML_EL_MF) 681: /* the first child of the MROW element is not a MF */ 682: /* Don't create a placeholder before */ 683: create = FALSE; 684: } 685: } 686: } 687: if (create) 688: { 689: elType.ElTypeNum = MathML_EL_Construct; 690: constr = TtaNewElement (doc, elType); 691: TtaInsertSibling (constr, sibling, TRUE, doc); 692: attrType.AttrSSchema = elType.ElSSchema; 1.22 cvs 693: attrType.AttrTypeNum = MathML_ATTR_IntPlaceholder; 1.1 cvs 694: attr = TtaNewAttribute (attrType); 695: TtaAttachAttribute (constr, attr, doc); 1.22 cvs 696: TtaSetAttributeValue (attr, MathML_ATTR_IntPlaceholder_VAL_yes_, constr, doc); 1.1 cvs 697: } 698: create = TRUE; 699: } 700: prev = sibling; 701: TtaNextSibling (&sibling); 702: } 703: if (prev != NULL && create) 704: { 705: elType = TtaGetElementType (prev); 706: /* don't insert a placeholder after the last element if it's a MF 707: or a SEP */ 708: if (elType.ElTypeNum == MathML_EL_MF || 709: elType.ElTypeNum == MathML_EL_SEP) 710: create = FALSE; 711: else if (elType.ElTypeNum == MathML_EL_MROW) 712: /* the last element is a MROW */ 713: { 714: child = TtaGetLastChild (prev); 715: if (child != NULL) 716: { 717: elType = TtaGetElementType (child); 718: if (elType.ElTypeNum != MathML_EL_MF) 719: /* the last child of the MROW element is not a MF */ 720: /* Don't create a placeholder before */ 721: create = FALSE; 722: } 723: } 724: if (create) 725: { 726: elType.ElTypeNum = MathML_EL_Construct; 727: constr = TtaNewElement (doc, elType); 728: TtaInsertSibling (constr, prev, FALSE, doc); 729: attrType.AttrSSchema = elType.ElSSchema; 1.22 cvs 730: attrType.AttrTypeNum = MathML_ATTR_IntPlaceholder; 1.1 cvs 731: attr = TtaNewAttribute (attrType); 732: TtaAttachAttribute (constr, attr, doc); 1.22 cvs 733: TtaSetAttributeValue (attr, MathML_ATTR_IntPlaceholder_VAL_yes_, constr, doc); 1.1 cvs 734: } 735: } 736: } 737: 738: /*---------------------------------------------------------------------- 1.28 cvs 739: NextNotSepOrComment 1.1 cvs 740: Return the next sibling of element el that is not a SEP element 1.28 cvs 741: nor an XMLcomment element. 742: Return el itself if it's not a SEP or a comment. 1.1 cvs 743: ----------------------------------------------------------------------*/ 744: #ifdef __STDC__ 1.28 cvs 745: static void NextNotSepOrComment (Element* el, Element* prev) 1.1 cvs 746: #else 1.28 cvs 747: static void NextNotSepOrComment (el, prev) 1.1 cvs 748: Element *el; 749: #endif 750: { 751: ElementType elType; 752: 753: if (*el == NULL) 754: return; 755: elType = TtaGetElementType (*el); 1.28 cvs 756: while (*el != NULL && (elType.ElTypeNum == MathML_EL_SEP || 757: elType.ElTypeNum == MathML_EL_XMLcomment)) 1.1 cvs 758: { 759: *prev = *el; 760: TtaNextSibling (el); 761: if (*el != NULL) 762: elType = TtaGetElementType (*el); 763: } 764: } 765: 766: /*---------------------------------------------------------------------- 767: CheckMathSubExpressions 768: Children of element el should be of type type1, type2, and type3. 769: Create an element of that type. 770: ----------------------------------------------------------------------*/ 771: #ifdef __STDC__ 772: static void CheckMathSubExpressions (Element el, int type1, int type2, int type3, Document doc) 773: #else 774: static void CheckMathSubExpressions (el, type1, type2, type3, doc) 775: Element el; 776: int type1; 777: int type2; 778: int type3; 779: Document doc; 780: #endif 781: { 782: Element child, new, prev; 783: ElementType elType, childType; 784: 1.2 cvs 785: elType.ElSSchema = GetMathMLSSchema (doc); 1.1 cvs 786: child = TtaGetFirstChild (el); 787: prev = NULL; 1.28 cvs 788: NextNotSepOrComment (&child, &prev); 1.1 cvs 789: if (child != NULL && type1 != 0) 790: { 791: elType.ElTypeNum = type1; 792: childType = TtaGetElementType (child); 793: if (TtaSameTypes (childType, elType) == 0) 794: { 795: TtaRemoveTree (child, doc); 796: new = TtaNewElement (doc, elType); 797: if (prev == NULL) 798: TtaInsertFirstChild (&new, el, doc); 799: else 800: TtaInsertSibling (new, prev, FALSE, doc); 801: TtaInsertFirstChild (&child, new, doc); 802: CreatePlaceholders (child, doc); 803: child = new; 804: } 805: if (type2 != 0) 806: { 807: prev = child; 808: TtaNextSibling (&child); 1.28 cvs 809: NextNotSepOrComment (&child, &prev); 1.1 cvs 810: if (child != NULL) 811: { 812: elType.ElTypeNum = type2; 813: childType = TtaGetElementType (child); 814: if (TtaSameTypes (childType, elType) == 0) 815: { 816: TtaRemoveTree (child, doc); 817: new = TtaNewElement (doc, elType); 818: TtaInsertSibling (new, prev, FALSE, doc); 819: TtaInsertFirstChild (&child, new, doc); 820: CreatePlaceholders (child, doc); 821: child = new; 822: } 823: if (type3 != 0) 824: { 825: prev = child; 826: TtaNextSibling (&child); 1.28 cvs 827: NextNotSepOrComment (&child, &prev); 1.1 cvs 828: if (child != NULL) 829: { 830: elType.ElTypeNum = type3; 831: childType = TtaGetElementType (child); 832: if (TtaSameTypes (childType, elType) == 0) 833: { 834: TtaRemoveTree (child, doc); 835: new = TtaNewElement (doc, elType); 836: TtaInsertSibling (new, prev, FALSE, doc); 837: TtaInsertFirstChild (&child, new, doc); 838: CreatePlaceholders (child, doc); 839: } 840: } 841: } 842: } 843: } 844: } 845: } 846: 847: 848: /*---------------------------------------------------------------------- 1.22 cvs 849: SetSingleIntHorizStretchAttr 1.1 cvs 850: 1.22 cvs 851: Put a IntHorizStretch attribute on element el if it contains only 1.1 cvs 852: a MO element that is a stretchable symbol. 853: -----------------------------------------------------------------------*/ 854: #ifdef __STDC__ 1.22 cvs 855: void SetSingleIntHorizStretchAttr (Element el, Document doc, Element* selEl) 1.1 cvs 856: #else /* __STDC__*/ 1.22 cvs 857: void SetSingleIntHorizStretchAttr (el, doc, selEl) 1.1 cvs 858: Element el; 859: Document doc; 860: Element* selEl; 861: #endif /* __STDC__*/ 862: { 863: Element child, sibling, textEl, symbolEl; 864: ElementType elType; 865: Attribute attr; 866: AttributeType attrType; 867: int len; 868: Language lang; 1.15 cvs 869: CHAR_T alphabet; 870: UCHAR_T text[2], c; 1.1 cvs 871: 872: if (el == NULL) 873: return; 874: child = TtaGetFirstChild (el); 875: if (child != NULL) 876: { 877: elType = TtaGetElementType (child); 878: if (elType.ElTypeNum == MathML_EL_MO) 879: /* the first child is a MO */ 880: { 881: sibling = child; 882: TtaNextSibling (&sibling); 883: if (sibling == NULL) 884: /* there is no other child */ 885: { 886: textEl = TtaGetFirstChild (child); 887: elType = TtaGetElementType (textEl); 888: if (elType.ElTypeNum == MathML_EL_TEXT_UNIT) 889: { 890: len = TtaGetTextLength (textEl); 891: if (len == 1) 892: { 893: len = 2; 894: TtaGiveTextContent (textEl, text, &len, &lang); 895: alphabet = TtaGetAlphabet (lang); 896: if (len == 1) 897: if (alphabet == 'G') 898: /* a single Symbol character */ 899: if ((int)text[0] == 172 || (int)text[0] == 174) 900: /* horizontal arrow */ 901: { 1.10 cvs 902: c = EOS; 1.22 cvs 903: /* attach a IntHorizStretch attribute */ 1.1 cvs 904: attrType.AttrSSchema = elType.ElSSchema; 1.22 cvs 905: attrType.AttrTypeNum = MathML_ATTR_IntHorizStretch; 1.1 cvs 906: attr = TtaNewAttribute (attrType); 907: TtaAttachAttribute (el, attr, doc); 1.22 cvs 908: TtaSetAttributeValue (attr, MathML_ATTR_IntHorizStretch_VAL_yes_, el, doc); 1.1 cvs 909: /* replace the TEXT element by a Thot SYMBOL element */ 910: elType.ElTypeNum = MathML_EL_SYMBOL_UNIT; 911: symbolEl = TtaNewElement (doc, elType); 912: TtaInsertSibling (symbolEl, textEl, FALSE, doc); 913: if (selEl != NULL) 914: if (*selEl == textEl) 915: *selEl = symbolEl; 916: TtaDeleteTree (textEl, doc); 917: if ((int)text[0] == 172) 918: c = '<'; 919: if ((int)text[0] == 174) 920: c = '>'; 1.10 cvs 921: if (c != EOS) 922: TtaSetGraphicsShape (symbolEl, c, doc); 1.1 cvs 923: } 924: } 925: } 926: } 927: } 928: } 929: } 930: 931: /*---------------------------------------------------------------------- 1.22 cvs 932: SetIntHorizStretchAttr 1.1 cvs 933: 1.22 cvs 934: Put a IntHorizStretch attribute on all children of element el which 1.1 cvs 935: contain only a MO element that is a stretchable symbol. 936: -----------------------------------------------------------------------*/ 937: #ifdef __STDC__ 1.22 cvs 938: static void SetIntHorizStretchAttr (Element el, Document doc) 1.1 cvs 939: #else /* __STDC__*/ 1.22 cvs 940: static void SetIntHorizStretchAttr (el, doc) 1.1 cvs 941: Element el; 942: Document doc; 943: #endif /* __STDC__*/ 944: { 945: Element child; 946: 947: if (el == NULL) 948: return; 949: child = TtaGetFirstChild (el); 950: while (child != NULL) 951: { 1.22 cvs 952: SetSingleIntHorizStretchAttr (child, doc, NULL); 1.1 cvs 953: TtaNextSibling (&child); 954: } 955: } 956: 957: /*---------------------------------------------------------------------- 1.22 cvs 958: SetIntVertStretchAttr 1.1 cvs 959: 1.22 cvs 960: Put a IntVertStretch attribute on element el if its base element 1.1 cvs 961: (Base for a MSUBSUP, MSUP or MSUB; UnderOverBase for a MUNDEROVER, 962: a MUNDER of a MOVER) contains only a MO element that is a vertically 963: stretchable symbol. 964: -----------------------------------------------------------------------*/ 965: #ifdef __STDC__ 1.22 cvs 966: void SetIntVertStretchAttr (Element el, Document doc, int base, Element* selEl) 1.1 cvs 967: #else /* __STDC__*/ 1.22 cvs 968: void SetIntVertStretchAttr (el, doc, base, selEl) 1.1 cvs 969: Element el; 970: Document doc; 971: int base; 972: Element* selEl; 973: #endif /* __STDC__*/ 974: { 975: Element child, sibling, textEl, symbolEl, parent, operator; 976: ElementType elType; 977: Attribute attr; 978: AttributeType attrType; 979: int len; 980: Language lang; 1.15 cvs 981: CHAR_T alphabet; 982: UCHAR_T text[2], c; 1.1 cvs 983: 984: if (el == NULL) 985: return; 986: operator = NULL; 987: if (base == 0) 988: /* it's a MO */ 989: { 990: parent = TtaGetParent (el); 991: if (parent != NULL) 992: { 993: elType = TtaGetElementType (parent); 994: if (elType.ElTypeNum != MathML_EL_Base && 995: elType.ElTypeNum != MathML_EL_UnderOverBase && 996: elType.ElTypeNum != MathML_EL_MSUBSUP && 997: elType.ElTypeNum != MathML_EL_MSUB && 998: elType.ElTypeNum != MathML_EL_MSUP && 999: elType.ElTypeNum != MathML_EL_MUNDEROVER && 1000: elType.ElTypeNum != MathML_EL_MUNDER && 1001: elType.ElTypeNum != MathML_EL_MUNDEROVER) 1002: operator = el; 1003: } 1004: } 1005: else 1006: /* it's not a MO */ 1007: { 1008: /* search the Base or UnderOverBase child */ 1009: child = TtaGetFirstChild (el); 1010: if (child != NULL) 1011: { 1012: elType = TtaGetElementType (child); 1013: if (elType.ElTypeNum == base) 1014: /* the first child is a Base or UnderOverBase */ 1015: { 1016: child = TtaGetFirstChild (child); 1017: if (child != NULL) 1018: { 1019: elType = TtaGetElementType (child); 1020: if (elType.ElTypeNum == MathML_EL_MO) 1021: /* its first child is a MO */ 1022: { 1023: sibling = child; 1024: TtaNextSibling (&sibling); 1025: if (sibling == NULL) 1026: /* there is no other child */ 1027: operator = child; 1028: } 1029: } 1030: } 1031: } 1032: } 1033: if (operator != NULL) 1034: { 1035: textEl = TtaGetFirstChild (operator); 1036: if (textEl != NULL) 1037: { 1038: elType = TtaGetElementType (textEl); 1039: if (elType.ElTypeNum == MathML_EL_TEXT_UNIT) 1040: { 1041: len = TtaGetTextLength (textEl); 1042: if (len == 1) 1043: { 1044: len = 2; 1045: TtaGiveTextContent (textEl, text, &len, &lang); 1046: alphabet = TtaGetAlphabet (lang); 1047: if (len == 1) 1048: if (alphabet == 'G') 1049: /* a single Symbol character */ 1050: if ((int)text[0] == 242) 1051: /* Integral */ 1052: { 1.22 cvs 1053: /* attach a IntVertStretch attribute */ 1.1 cvs 1054: attrType.AttrSSchema = elType.ElSSchema; 1.22 cvs 1055: attrType.AttrTypeNum = MathML_ATTR_IntVertStretch; 1.1 cvs 1056: attr = TtaNewAttribute (attrType); 1057: TtaAttachAttribute (el, attr, doc); 1.22 cvs 1058: TtaSetAttributeValue (attr, MathML_ATTR_IntVertStretch_VAL_yes_, el, doc); 1.1 cvs 1059: /* replace the TEXT element by a Thot SYMBOL element*/ 1060: elType.ElTypeNum = MathML_EL_SYMBOL_UNIT; 1061: symbolEl = TtaNewElement (doc, elType); 1062: TtaInsertSibling (symbolEl, textEl, FALSE, doc); 1063: if (selEl != NULL) 1064: if (*selEl == textEl) 1065: *selEl = symbolEl; 1066: TtaDeleteTree (textEl, doc); 1067: c = 'i'; 1068: TtaSetGraphicsShape (symbolEl, c, doc); 1069: } 1070: } 1071: } 1072: } 1073: } 1074: } 1075: 1076: /*---------------------------------------------------------------------- 1.22 cvs 1077: SetIntPlaceholderAttr 1.1 cvs 1078: 1.22 cvs 1079: Put a IntPlaceholder attribute on all Construct elements in the 1.1 cvs 1080: subtree of root el. 1081: -----------------------------------------------------------------------*/ 1082: #ifdef __STDC__ 1.22 cvs 1083: static void SetIntPlaceholderAttr (Element el, Document doc) 1.1 cvs 1084: #else /* __STDC__*/ 1.22 cvs 1085: static void SetIntPlaceholderAttr (el, doc) 1.1 cvs 1086: Element el; 1087: Document doc; 1088: #endif /* __STDC__*/ 1089: { 1090: Element child; 1091: ElementType elType; 1092: Attribute attr; 1093: AttributeType attrType; 1094: 1095: if (el == NULL) 1096: return; 1097: elType = TtaGetElementType (el); 1098: if (elType.ElTypeNum == MathML_EL_Construct && 1.2 cvs 1099: elType.ElSSchema == GetMathMLSSchema (doc)) 1.1 cvs 1100: { 1101: attrType.AttrSSchema = elType.ElSSchema; 1.22 cvs 1102: attrType.AttrTypeNum = MathML_ATTR_IntPlaceholder; 1.1 cvs 1103: attr = TtaNewAttribute (attrType); 1104: TtaAttachAttribute (el, attr, doc); 1.22 cvs 1105: TtaSetAttributeValue (attr, MathML_ATTR_IntPlaceholder_VAL_yes_, el, doc); 1.1 cvs 1106: } 1107: else 1108: { 1109: child = TtaGetFirstChild (el); 1110: while (child != NULL) 1111: { 1.22 cvs 1112: SetIntPlaceholderAttr (child, doc); 1.1 cvs 1113: TtaNextSibling (&child); 1114: } 1115: } 1116: } 1117: 1118: /*---------------------------------------------------------------------- 1119: BuildMultiscript 1120: 1121: The content of a MMULTISCRIPT element has been created following 1122: the original MathML structure. Create all Thot elements defined 1123: in the MathML S schema. 1124: -----------------------------------------------------------------------*/ 1125: #ifdef __STDC__ 1126: static void BuildMultiscript (Element elMMULTISCRIPT, Document doc) 1127: #else /* __STDC__*/ 1128: static void BuildMultiscript (elMMULTISCRIPT, doc) 1129: Element elMMULTISCRIPT; 1130: Document doc; 1131: #endif /* __STDC__*/ 1132: { 1133: Element elem, base, next, group, pair, script, prevPair, prevScript; 1134: ElementType elType, elTypeGroup, elTypePair, elTypeScript; 1.2 cvs 1135: SSchema MathMLSSchema; 1.1 cvs 1136: base = NULL; 1137: group = NULL; 1138: prevPair = NULL; 1139: prevScript = NULL; 1140: 1.2 cvs 1141: MathMLSSchema = GetMathMLSSchema (doc); 1.1 cvs 1142: elTypeGroup.ElSSchema = MathMLSSchema; 1143: elTypePair.ElSSchema = MathMLSSchema; 1144: elTypeScript.ElSSchema = MathMLSSchema; 1145: 1146: /* process all children of the MMULTISCRIPT element */ 1147: elem = TtaGetFirstChild (elMMULTISCRIPT); 1148: while (elem != NULL) 1149: { 1150: /* remember the element to be processed after the current one */ 1151: next = elem; 1152: TtaNextSibling (&next); 1153: 1154: /* remove the current element from the tree */ 1155: TtaRemoveTree (elem, doc); 1156: 1157: if (base == NULL) 1158: /* the current element is the first child of the MMULTISCRIPT 1159: element */ 1160: { 1161: /* Create a MultiscriptBase element as the first child of 1162: MMULTISCRIPT and move the current element as the first child 1163: of the MultiscriptBase element */ 1164: elTypeGroup.ElTypeNum = MathML_EL_MultiscriptBase; 1165: base = TtaNewElement (doc, elTypeGroup); 1166: TtaInsertFirstChild (&base, elMMULTISCRIPT, doc); 1167: TtaInsertFirstChild (&elem, base, doc); 1168: } 1169: else 1170: /* the current element is a subscript or a superscript */ 1171: { 1172: if (group == NULL) 1173: /* there is no PostscriptPairs element. Create one */ 1174: { 1175: elTypeGroup.ElTypeNum = MathML_EL_PostscriptPairs; 1176: group = TtaNewElement (doc, elTypeGroup); 1177: TtaInsertSibling (group, base, FALSE, doc); 1178: elTypePair.ElTypeNum = MathML_EL_PostscriptPair; 1179: /* create a first and a last PostscriptPair as placeholders */ 1.26 cvs 1180: pair = TtaNewTree (doc, elTypePair, _EMPTYSTR_); 1.1 cvs 1181: TtaInsertFirstChild (&pair, group, doc); 1.22 cvs 1182: SetIntPlaceholderAttr (pair, doc); 1.1 cvs 1183: prevPair = pair; 1.26 cvs 1184: pair = TtaNewTree (doc, elTypePair, _EMPTYSTR_); 1.1 cvs 1185: TtaInsertSibling (pair, prevPair, FALSE, doc); 1.22 cvs 1186: SetIntPlaceholderAttr (pair, doc); 1.1 cvs 1187: prevScript = NULL; 1188: } 1189: if (prevScript == NULL) 1190: /* the current element is the first subscript or superscript 1191: in a pair */ 1192: { 1193: /* create a PostscriptPair or PrescriptPair element */ 1194: pair = TtaNewElement (doc, elTypePair); 1195: if (prevPair == NULL) 1196: TtaInsertFirstChild (&pair, group, doc); 1197: else 1198: TtaInsertSibling (pair, prevPair, FALSE, doc); 1199: prevPair = pair; 1200: /* create a MSubscript element */ 1201: elTypeScript.ElTypeNum = MathML_EL_MSubscript; 1202: script = TtaNewElement (doc, elTypeScript); 1203: TtaInsertFirstChild (&script, pair, doc); 1204: prevScript = script; 1205: } 1206: else 1207: /* the current element is a superscript in a pair */ 1208: { 1209: /* create a MSuperscript element */ 1210: elTypeScript.ElTypeNum = MathML_EL_MSuperscript; 1211: script = TtaNewElement (doc, elTypeScript); 1212: /* insert it as a sibling of the previous MSubscript element */ 1213: TtaInsertSibling (script, prevScript, FALSE, doc); 1214: prevScript = NULL; 1215: } 1216: /* insert the current element as a child of the new MSuperscript or 1217: MSubscript element */ 1218: TtaInsertFirstChild (&elem, script, doc); 1.22 cvs 1219: SetIntPlaceholderAttr (elem, doc); 1.1 cvs 1220: } 1221: 1222: CreatePlaceholders (elem, doc); 1223: 1224: /* get next child of the MMULTISCRIPT element */ 1225: elem = next; 1226: if (elem != NULL) 1227: { 1228: elType = TtaGetElementType (elem); 1229: if (elType.ElSSchema == MathMLSSchema && 1230: elType.ElTypeNum == MathML_EL_PrescriptPairs) 1231: /* the next element is a PrescriptPairs */ 1232: { 1233: /* if there there is no PostscriptPairs element, create one as a 1234: placeholder */ 1235: if (elTypeGroup.ElTypeNum != MathML_EL_PostscriptPairs) 1236: { 1237: elTypeGroup.ElTypeNum = MathML_EL_PostscriptPairs; 1.26 cvs 1238: group = TtaNewTree (doc, elTypeGroup, _EMPTYSTR_); 1.1 cvs 1239: TtaInsertSibling (group, elem, TRUE, doc); 1.22 cvs 1240: SetIntPlaceholderAttr (group, doc); 1.1 cvs 1241: } 1242: /* the following elements will be interpreted as sub- superscripts 1243: in PrescriptPair elements, wich will be children of this 1244: PrescriptPairs element */ 1245: elTypeGroup.ElTypeNum = MathML_EL_PrescriptPairs; 1246: elTypePair.ElTypeNum = MathML_EL_PrescriptPair; 1247: group = elem; 1248: /* create a first and a last PostscriptPair as placeholders */ 1.26 cvs 1249: pair = TtaNewTree (doc, elTypePair, _EMPTYSTR_); 1.1 cvs 1250: TtaInsertFirstChild (&pair, group, doc); 1.22 cvs 1251: SetIntPlaceholderAttr (pair, doc); 1.1 cvs 1252: prevPair = pair; 1.26 cvs 1253: pair = TtaNewTree (doc, elTypePair, _EMPTYSTR_); 1.1 cvs 1254: TtaInsertSibling (pair, prevPair, FALSE, doc); 1.22 cvs 1255: SetIntPlaceholderAttr (pair, doc); 1.1 cvs 1256: prevScript = NULL; 1257: TtaNextSibling (&elem); 1258: } 1259: } 1260: } 1261: /* all children of element MMULTISCRIPTS have been processed */ 1262: /* if the last group processed is not a PrescriptPairs element, 1263: create one as a placeholder */ 1264: if (elTypeGroup.ElTypeNum != MathML_EL_PrescriptPairs && base != NULL) 1265: { 1266: elTypeGroup.ElTypeNum = MathML_EL_PrescriptPairs; 1.26 cvs 1267: elem = TtaNewTree (doc, elTypeGroup, _EMPTYSTR_); 1.1 cvs 1268: if (group == NULL) 1269: group = base; 1270: TtaInsertSibling (elem, group, TRUE, doc); 1.22 cvs 1271: SetIntPlaceholderAttr (elem, doc); 1.1 cvs 1272: } 1273: } 1274: 1.39 cvs 1275: /*---------------------------------------------------------------------- 1276: CreateWrapper 1277: 1278: Create an element of type wrapperType as a child of element el and 1279: move all chidren of element el within the new element. 1280: -----------------------------------------------------------------------*/ 1281: #ifdef __STDC__ 1282: static void CreateWrapper (Element el, int wrapperType, Document doc) 1283: #else /* __STDC__*/ 1284: static void CreateWrapper (el, wrapperType, doc) 1285: Element el; 1286: int wrapperType; 1287: Document doc; 1288: #endif /* __STDC__*/ 1289: { 1290: Element wrapper, child, prevChild, nextChild; 1291: ElementType elType; 1292: 1293: child = TtaGetFirstChild (el); 1294: elType.ElSSchema = GetMathMLSSchema (doc); 1295: elType.ElTypeNum = wrapperType; 1296: wrapper = TtaNewElement (doc, elType); 1297: TtaInsertFirstChild (&wrapper, el, doc); 1298: prevChild = NULL; 1299: while (child) 1300: { 1301: nextChild = child; 1302: TtaNextSibling (&nextChild); 1303: TtaRemoveTree (child, doc); 1304: if (prevChild == NULL) 1305: TtaInsertFirstChild (&child, wrapper, doc); 1306: else 1307: TtaInsertSibling (child, prevChild, FALSE, doc); 1308: prevChild = child; 1309: child = nextChild; 1310: } 1311: } 1.5 cvs 1312: 1313: /*---------------------------------------------------------------------- 1314: CheckMTable 1315: 1316: The content of a MTABLE element has been created following 1317: the original MathML structure. Create all Thot elements defined 1318: in the MathML S schema. 1319: -----------------------------------------------------------------------*/ 1320: #ifdef __STDC__ 1.12 cvs 1321: void CheckMTable (Element elMTABLE, Document doc) 1.5 cvs 1322: #else /* __STDC__*/ 1.12 cvs 1323: void CheckMTable (elMTABLE, doc) 1.5 cvs 1324: Element elMTABLE; 1325: Document doc; 1326: #endif /* __STDC__*/ 1327: { 1328: ElementType elType; 1329: Element MTableHead, MTableBody, row, nextRow, el, prevRow, cell, 1.40 cvs 1330: nextCell, newMTD, firstColHead; 1.5 cvs 1331: SSchema MathMLSSchema; 1332: 1333: MathMLSSchema = GetMathMLSSchema (doc); 1334: row = TtaGetFirstChild (elMTABLE); 1335: 1336: /* create a MTable_head as the first child of element MTABLE */ 1337: elType.ElSSchema = MathMLSSchema; 1338: elType.ElTypeNum = MathML_EL_MTable_head; 1339: MTableHead = TtaNewElement (doc, elType); 1340: TtaInsertFirstChild (&MTableHead, elMTABLE, doc); 1341: elType.ElTypeNum = MathML_EL_MColumn_head; 1.26 cvs 1342: firstColHead = TtaNewTree (doc, elType, _EMPTYSTR_); 1.5 cvs 1343: TtaInsertFirstChild (&firstColHead, MTableHead, doc); 1344: 1345: /* create a MTable_body */ 1346: elType.ElSSchema = MathMLSSchema; 1347: elType.ElTypeNum = MathML_EL_MTable_body; 1348: MTableBody = TtaNewElement (doc, elType); 1349: TtaInsertSibling (MTableBody, MTableHead, FALSE, doc); 1350: 1351: /* move all children of element MTABLE into the new MTable_body element 1352: and wrap each non-MTR element with a MTR */ 1353: prevRow = NULL; 1354: while (row) 1355: { 1356: nextRow = row; 1357: TtaNextSibling (&nextRow); 1358: elType = TtaGetElementType (row); 1359: TtaRemoveTree (row, doc); 1360: if (TtaSameSSchemas (elType.ElSSchema, MathMLSSchema) && 1361: (elType.ElTypeNum == MathML_EL_XMLcomment || 1362: elType.ElTypeNum == MathML_EL_MTR)) 1363: { 1364: if (prevRow == NULL) 1365: TtaInsertFirstChild (&row, MTableBody, doc); 1366: else 1367: TtaInsertSibling (row, prevRow, FALSE, doc); 1368: prevRow = row; 1369: if (elType.ElTypeNum == MathML_EL_MTR) 1370: cell = TtaGetFirstChild (row); 1371: else 1372: cell = NULL; 1373: } 1374: else 1375: /* this child is not a MTR nor a comment, create a MTR element */ 1376: { 1377: elType.ElSSchema = MathMLSSchema; 1378: elType.ElTypeNum = MathML_EL_MTR; 1379: el = TtaNewElement (doc, elType); 1380: if (prevRow == NULL) 1381: TtaInsertFirstChild (&el, MTableBody, doc); 1382: else 1383: TtaInsertSibling (el, prevRow, FALSE, doc); 1384: TtaInsertFirstChild (&row, el, doc); 1385: cell = row; 1386: prevRow = el; 1387: } 1388: while (cell) 1389: /* check all children of the current MTR element */ 1390: { 1391: nextCell = cell; 1392: TtaNextSibling (&nextCell); 1393: elType = TtaGetElementType (cell); 1394: if (!TtaSameSSchemas (elType.ElSSchema, MathMLSSchema) || 1395: (elType.ElTypeNum != MathML_EL_XMLcomment && 1396: elType.ElTypeNum != MathML_EL_MTD)) 1397: /* this is not a MTD nor a comment, create a wrapping MTD */ 1398: { 1399: elType.ElSSchema = MathMLSSchema; 1400: elType.ElTypeNum = MathML_EL_MTD; 1401: newMTD = TtaNewElement (doc, elType); 1402: TtaInsertSibling (newMTD, cell, TRUE, doc); 1403: TtaRemoveTree (cell, doc); 1404: TtaInsertFirstChild (&cell, newMTD, doc); 1405: cell = newMTD; 1406: } 1407: if (elType.ElTypeNum == MathML_EL_MTD) 1408: /* This is a MTD element. Wrap its contents with a CellWrapper */ 1.39 cvs 1409: CreateWrapper (cell, MathML_EL_CellWrapper, doc); 1.5 cvs 1410: cell = nextCell; 1411: } 1412: row = nextRow; 1413: } 1.12 cvs 1414: CheckAllRows (elMTABLE, doc); 1.5 cvs 1415: } 1.12 cvs 1416: 1.1 cvs 1417: 1418: /*---------------------------------------------------------------------- 1419: SetFontstyleAttr 1420: The content of a MI element has been created or modified. 1421: Create or change attribute IntFontstyle for that element accordingly. 1422: -----------------------------------------------------------------------*/ 1423: #ifdef __STDC__ 1424: void SetFontstyleAttr (Element el, Document doc) 1425: #else /* __STDC__*/ 1426: void SetFontstyleAttr (el, doc) 1427: Element el; 1428: Document doc; 1429: #endif /* __STDC__*/ 1430: { 1431: ElementType elType; 1432: AttributeType attrType; 1433: Attribute attr, IntAttr; 1434: int len; 1435: 1436: if (el != NULL) 1437: { 1438: /* search the fontstyle attribute */ 1439: elType = TtaGetElementType (el); 1440: attrType.AttrSSchema = elType.ElSSchema; 1441: attrType.AttrTypeNum = MathML_ATTR_fontstyle; 1442: attr = TtaGetAttribute (el, attrType); 1443: attrType.AttrTypeNum = MathML_ATTR_IntFontstyle; 1444: IntAttr = TtaGetAttribute (el, attrType); 1445: if (attr != NULL) 1446: /* there is a fontstyle attribute. Remove the corresponding 1447: internal attribute that is not needed */ 1448: { 1449: if (IntAttr != NULL) 1450: TtaRemoveAttribute (el, IntAttr, doc); 1451: } 1452: else 1453: /* there is no fontstyle attribute. Create an internal attribute 1454: IntFontstyle with a value that depends on the content of the MI */ 1455: { 1456: /* get content length */ 1457: len = TtaGetElementVolume (el); 1458: if (len > 1) 1459: /* put an attribute IntFontstyle = IntNormal */ 1460: { 1461: if (IntAttr == NULL) 1462: { 1463: IntAttr = TtaNewAttribute (attrType); 1464: TtaAttachAttribute (el, IntAttr, doc); 1465: } 1466: TtaSetAttributeValue (IntAttr, MathML_ATTR_IntFontstyle_VAL_IntNormal, 1467: el, doc); 1468: } 1469: else 1470: /* MI contains a single character. Remove attribute IntFontstyle 1471: if it exists */ 1472: { 1473: if (IntAttr != NULL) 1474: TtaRemoveAttribute (el, IntAttr, doc); 1475: } 1476: } 1477: } 1478: } 1479: 1480: /*---------------------------------------------------------------------- 1.22 cvs 1481: SetIntAddSpaceAttr 1.1 cvs 1482: The content of a MO element has been created or modified. 1.22 cvs 1483: Create or change attribute IntAddSpace for that element accordingly. 1.1 cvs 1484: -----------------------------------------------------------------------*/ 1485: #ifdef __STDC__ 1.22 cvs 1486: void SetIntAddSpaceAttr (Element el, Document doc) 1.1 cvs 1487: #else /* __STDC__*/ 1.22 cvs 1488: void SetIntAddSpaceAttr (el, doc) 1.1 cvs 1489: Element el; 1490: Document doc; 1491: #endif /* __STDC__*/ 1492: { 1493: Element textEl, previous; 1494: ElementType elType; 1495: AttributeType attrType; 1496: Attribute attr; 1497: int len, val; 1498: #define BUFLEN 10 1.15 cvs 1499: UCHAR_T text[BUFLEN]; 1.1 cvs 1500: Language lang; 1.15 cvs 1501: CHAR_T alphabet; 1.1 cvs 1502: 1503: textEl = TtaGetFirstChild (el); 1504: if (textEl != NULL) 1505: { 1.22 cvs 1506: /* search the IntAddSpace attribute */ 1.1 cvs 1507: elType = TtaGetElementType (el); 1508: attrType.AttrSSchema = elType.ElSSchema; 1.22 cvs 1509: attrType.AttrTypeNum = MathML_ATTR_IntAddSpace; 1.1 cvs 1510: attr = TtaGetAttribute (el, attrType); 1511: if (attr == NULL) 1512: { 1513: attr = TtaNewAttribute (attrType); 1514: TtaAttachAttribute (el, attr, doc); 1515: } 1.22 cvs 1516: val = MathML_ATTR_IntAddSpace_VAL_nospace; 1.1 cvs 1517: len = TtaGetTextLength (textEl); 1518: if (len > 0 && len < BUFLEN) 1519: { 1520: len = BUFLEN; 1521: TtaGiveTextContent (textEl, text, &len, &lang); 1522: alphabet = TtaGetAlphabet (lang); 1523: if (len == 1) 1524: if (alphabet == 'L') 1525: /* ISO-Latin 1 character */ 1526: { 1527: if (text[0] == '-') 1528: /* unary or binary operator? */ 1529: { 1530: previous = el; 1531: TtaPreviousSibling (&previous); 1532: if (previous == NULL) 1533: /* no previous sibling => unary operator */ 1.22 cvs 1534: val = MathML_ATTR_IntAddSpace_VAL_nospace; 1.1 cvs 1535: else 1536: { 1537: elType = TtaGetElementType (previous); 1538: if (elType.ElTypeNum == MathML_EL_MO) 1539: /* after an operator => unary operator */ 1.22 cvs 1540: val = MathML_ATTR_IntAddSpace_VAL_nospace; 1.1 cvs 1541: else 1542: /* binary operator */ 1.22 cvs 1543: val = MathML_ATTR_IntAddSpace_VAL_both; 1.1 cvs 1544: } 1545: } 1546: else if (text[0] == '+' || 1547: text[0] == '&' || 1548: text[0] == '*' || 1549: text[0] == '<' || 1550: text[0] == '=' || 1551: text[0] == '>' || 1552: text[0] == '^') 1553: /* binary operator */ 1.22 cvs 1554: val = MathML_ATTR_IntAddSpace_VAL_both; 1.1 cvs 1555: else if (text[0] == ',' || 1556: text[0] == ';') 1.22 cvs 1557: val = MathML_ATTR_IntAddSpace_VAL_spaceafter; 1.1 cvs 1558: } 1559: else if (alphabet == 'G') 1560: /* Symbol character set */ 1561: if ((int)text[0] == 163 || /* less or equal */ 1562: (int)text[0] == 177 || /* plus or minus */ 1563: (int)text[0] == 179 || /* greater or equal */ 1564: (int)text[0] == 180 || /* times */ 1565: (int)text[0] == 184 || /* divide */ 1566: (int)text[0] == 185 || /* not equal */ 1567: (int)text[0] == 186 || /* identical */ 1568: (int)text[0] == 187 || /* equivalent */ 1569: (int)text[0] == 196 || /* circle times */ 1570: (int)text[0] == 197 || /* circle plus */ 1571: ((int)text[0] >= 199 && (int)text[0] <= 209) || /* */ 1572: (int)text[0] == 217 || /* and */ 1573: (int)text[0] == 218 ) /* or */ 1.22 cvs 1574: val = MathML_ATTR_IntAddSpace_VAL_both; 1.1 cvs 1575: } 1576: TtaSetAttributeValue (attr, val, el, doc); 1577: } 1578: } 1579: 1580: 1581: /*---------------------------------------------------------------------- 1582: ChangeTypeOfElement 1583: Change the type of element elem into newTypeNum 1584: -----------------------------------------------------------------------*/ 1585: #ifdef __STDC__ 1586: void ChangeTypeOfElement (Element elem, Document doc, int newTypeNum) 1587: #else /* __STDC__*/ 1588: void ChangeTypeOfElement (elem, doc, newTypeNum) 1589: Element elem; 1590: Document doc; 1591: int newTypeNum; 1592: #endif /* __STDC__*/ 1593: 1594: { 1595: Element prev, next, parent; 1.10 cvs 1596: 1597: parent = NULL; 1.1 cvs 1598: prev = elem; 1599: TtaPreviousSibling (&prev); 1600: if (prev == NULL) 1601: { 1602: next = elem; 1603: TtaNextSibling (&next); 1604: if (next == NULL) 1605: parent = TtaGetParent (elem); 1606: } 1607: TtaRemoveTree (elem, doc); 1608: ChangeElementType (elem, newTypeNum); 1609: if (prev != NULL) 1610: TtaInsertSibling (elem, prev, FALSE, doc); 1611: else if (next != NULL) 1612: TtaInsertSibling (elem, next, TRUE, doc); 1613: else 1614: TtaInsertFirstChild (&elem, parent, doc); 1615: } 1616: 1617: 1618: /*---------------------------------------------------------------------- 1619: CheckFence 1620: If el is a MO element that contains a single fence character, 1621: transform the MO into a MF and the character into a Thot symbol. 1622: ----------------------------------------------------------------------*/ 1623: #ifdef __STDC__ 1624: void CheckFence (Element el, Document doc) 1625: #else 1626: void CheckFence (el, doc) 1627: Element el; 1628: Document doc; 1629: 1630: #endif 1631: { 1632: ElementType elType; 1633: Element content; 1634: AttributeType attrType; 1635: Attribute attr; 1636: int len; 1637: Language lang; 1.15 cvs 1638: CHAR_T alphabet; 1639: UCHAR_T text[2], c; 1.1 cvs 1640: 1641: elType = TtaGetElementType (el); 1642: if (elType.ElTypeNum == MathML_EL_MO) 1643: { 1644: content = TtaGetFirstChild (el); 1645: if (content != NULL) 1646: { 1647: elType = TtaGetElementType (content); 1648: if (elType.ElTypeNum == MathML_EL_TEXT_UNIT) 1649: { 1650: len = TtaGetTextLength (content); 1651: if (len == 1) 1652: { 1653: len = 2; 1654: TtaGiveTextContent (content, text, &len, &lang); 1655: alphabet = TtaGetAlphabet (lang); 1656: if (len == 1) 1657: if (alphabet == 'L') 1658: /* a single character */ 1659: if (text[0] == '(' || text[0] == ')' || 1660: text[0] == '[' || text[0] == ']' || 1661: text[0] == '{' || text[0] == '}' || 1662: text[0] == '|' ) 1663: { 1664: /* remove the content of the MO element */ 1665: TtaDeleteTree (content, doc); 1666: /* change the MO element into a MF element */ 1667: ChangeTypeOfElement (el, doc, MathML_EL_MF); 1.22 cvs 1668: /* attach a IntVertStretch attribute to the MF element */ 1.1 cvs 1669: attrType.AttrSSchema = elType.ElSSchema; 1.22 cvs 1670: attrType.AttrTypeNum = MathML_ATTR_IntVertStretch; 1.1 cvs 1671: attr = TtaNewAttribute (attrType); 1672: TtaAttachAttribute (el, attr, doc); 1.22 cvs 1673: TtaSetAttributeValue (attr, MathML_ATTR_IntVertStretch_VAL_yes_, el, doc); 1.1 cvs 1674: /* create a new content for the MF element */ 1675: if (text[0] == '|') 1676: { 1677: elType.ElTypeNum = MathML_EL_GRAPHICS_UNIT; 1678: c = 'v'; 1679: } 1680: else 1681: { 1682: elType.ElTypeNum = MathML_EL_SYMBOL_UNIT; 1683: c = text[0]; 1684: } 1685: content = TtaNewElement (doc, elType); 1686: TtaInsertFirstChild (&content, el, doc); 1687: TtaSetGraphicsShape (content, c, doc); 1688: } 1689: } 1690: } 1691: } 1692: } 1693: } 1694: 1695: /*---------------------------------------------------------------------- 1696: CreateFencedSeparators 1697: Create FencedSeparator elements within the fencedExpression 1698: according to attribute separators of the MFENCED element. 1699: ----------------------------------------------------------------------*/ 1700: #ifdef __STDC__ 1.18 cvs 1701: void CreateFencedSeparators (Element fencedExpression, Document doc, ThotBool record) 1.1 cvs 1702: #else 1.17 cvs 1703: void CreateFencedSeparators (fencedExpression, doc, record) 1.1 cvs 1704: Element fencedExpression; 1705: Document doc; 1.18 cvs 1706: ThotBool record; 1.1 cvs 1707: 1708: #endif 1709: { 1710: ElementType elType; 1711: Element child, separator, leaf, next, prev, mfenced; 1712: AttributeType attrType; 1713: Attribute attr; 1714: int length, sep, i; 1715: Language lang; 1.15 cvs 1716: CHAR_T text[32], sepValue[4]; 1.1 cvs 1717: 1718: /* get the separators attribute */ 1719: mfenced = TtaGetParent (fencedExpression); 1720: elType = TtaGetElementType (fencedExpression); 1721: attrType.AttrSSchema = elType.ElSSchema; 1722: attrType.AttrTypeNum = MathML_ATTR_separators; 1723: text[0] = ','; /* default value is sparators="," */ 1724: text[1] = EOS; 1725: length = 1; 1726: attr = TtaGetAttribute (mfenced, attrType); 1727: if (attr != NULL) 1728: { 1729: length = 31; 1730: TtaGiveTextAttributeValue (attr, text, &length); 1731: } 1732: 1733: /* create FencedSeparator elements in the FencedExpression */ 1734: prev = NULL; 1735: sep = 0; 1736: /* skip leading spaces in attribute separators */ 1737: while (text[sep] <= SPACE && text[sep] != EOS) 1738: sep++; 1739: /* if attribute separators is empty or contains only spaces, do not 1740: insert any separator element */ 1741: if (text[sep] != EOS) 1742: { 1743: child = TtaGetFirstChild (fencedExpression); 1744: while (child != NULL) 1745: { 1746: next = child; 1747: TtaNextSibling (&next); 1748: elType = TtaGetElementType (child); 1749: if (elType.ElTypeNum != MathML_EL_Construct) 1750: { 1751: if (prev != NULL) 1752: { 1753: elType.ElTypeNum = MathML_EL_FencedSeparator; 1754: separator = TtaNewElement (doc, elType); 1755: TtaInsertSibling (separator, prev, FALSE, doc); 1756: elType.ElTypeNum = MathML_EL_TEXT_UNIT; 1757: leaf = TtaNewElement (doc, elType); 1758: TtaInsertFirstChild (&leaf, separator, doc); 1759: sepValue[0] = text[sep]; 1760: sepValue[1] = SPACE; 1761: sepValue[2] = EOS; 1762: lang = TtaGetLanguageIdFromAlphabet('L'); 1763: TtaSetTextContent (leaf, sepValue, lang, doc); 1764: /* is there a following non-space character in separators? */ 1765: i = sep + 1; 1766: while (text[i] <= SPACE && text[i] != EOS) 1767: i++; 1768: if (text[i] > SPACE && text[i] != EOS) 1769: sep = i; 1.17 cvs 1770: if (record) 1771: TtaRegisterElementCreate (separator, doc); 1.1 cvs 1772: } 1773: prev = child; 1774: } 1775: child = next; 1776: } 1777: } 1778: } 1779: 1780: 1781: /*---------------------------------------------------------------------- 1782: TransformMFENCED 1783: Transform the content of a MFENCED element: create elements 1784: OpeningFence, FencedExpression, ClosingFence and FencedSeparator. 1785: ----------------------------------------------------------------------*/ 1786: #ifdef __STDC__ 1787: void TransformMFENCED (Element el, Document doc) 1788: #else 1789: void TransformMFENCED (el, doc) 1790: Element el; 1791: Document doc; 1792: 1793: #endif 1794: { 1795: ElementType elType; 1796: Element child, fencedExpression, leaf, fence, next, prev, 1797: firstChild; 1798: AttributeType attrType; 1799: Attribute attr; 1800: int length; 1.15 cvs 1801: CHAR_T text[32], c; 1.1 cvs 1802: 1803: child = TtaGetFirstChild (el); 1804: if (child != NULL) 1805: elType = TtaGetElementType (child); 1806: if (child != NULL && elType.ElTypeNum == MathML_EL_OpeningFence) 1807: /* The first child of this MFENCED element is an OpeningFence. 1808: This MFENCED expression has already been transformed, possibly 1809: by the Transform command */ 1810: { 1811: TtaNextSibling (&child); 1812: fencedExpression = child; 1813: if (fencedExpression != NULL) 1814: elType = TtaGetElementType (fencedExpression); 1815: if (elType.ElTypeNum == MathML_EL_FencedExpression) 1816: /* the second child is a FencedExpression. OK. 1817: Remove all existing FencedSeparator elements */ 1818: { 1819: child = TtaGetFirstChild (fencedExpression); 1820: prev = NULL; 1821: while (child != NULL) 1822: { 1823: elType = TtaGetElementType (child); 1824: next = child; 1825: TtaNextSibling (&next); 1826: if (elType.ElTypeNum == MathML_EL_FencedSeparator) 1827: /* Remove this separator */ 1828: TtaDeleteTree (child, doc); 1829: child = next; 1830: } 1831: /* create FencedSeparator elements in the FencedExpression */ 1.17 cvs 1832: CreateFencedSeparators (fencedExpression, doc, FALSE); 1.1 cvs 1833: } 1834: } 1835: else 1836: /* this MFENCED element must be transformed */ 1837: { 1838: /* create a FencedExpression element as a child of the MFENCED elem. */ 1839: elType = TtaGetElementType (el); 1840: elType.ElTypeNum = MathML_EL_FencedExpression; 1841: fencedExpression = TtaNewElement (doc, elType); 1842: TtaInsertFirstChild (&fencedExpression, el, doc); 1843: if (child == NULL) 1844: /* empty MFENCED element */ 1845: { 1846: elType.ElTypeNum = MathML_EL_Construct; 1847: child = TtaNewElement (doc, elType); 1848: TtaInsertFirstChild (&child, fencedExpression, doc); 1.22 cvs 1849: SetIntPlaceholderAttr (child, doc); 1.1 cvs 1850: } 1851: else 1852: { 1853: /* move the content of the MFENCED element within the new 1854: FencedExpression element */ 1855: prev = NULL; 1856: firstChild = NULL; 1857: while (child != NULL) 1858: { 1859: next = child; 1860: TtaNextSibling (&next); 1861: TtaRemoveTree (child, doc); 1862: if (prev == NULL) 1863: { 1864: TtaInsertFirstChild (&child, fencedExpression, doc); 1865: firstChild = child; 1866: } 1867: else 1868: TtaInsertSibling (child, prev, FALSE, doc); 1869: prev = child; 1870: child = next; 1871: } 1872: 1873: /* create FencedSeparator elements in the FencedExpression */ 1.17 cvs 1874: CreateFencedSeparators (fencedExpression, doc, FALSE); 1.1 cvs 1875: 1876: /* Create placeholders within the FencedExpression element */ 1877: CreatePlaceholders (firstChild, doc); 1878: } 1879: 1880: /* create the OpeningFence element according to the open attribute */ 1881: c = '('; 1882: attrType.AttrSSchema = elType.ElSSchema; 1883: attrType.AttrTypeNum = MathML_ATTR_open; 1884: attr = TtaGetAttribute (el, attrType); 1885: if (attr != NULL) 1886: { 1887: length = 7; 1888: TtaGiveTextAttributeValue (attr, text, &length); 1889: c = text[0]; 1890: } 1891: elType.ElTypeNum = MathML_EL_OpeningFence; 1892: fence = TtaNewElement (doc, elType); 1893: TtaInsertSibling (fence, fencedExpression, TRUE, doc); 1894: elType.ElTypeNum = MathML_EL_SYMBOL_UNIT; 1895: leaf = TtaNewElement (doc, elType); 1896: TtaInsertFirstChild (&leaf, fence, doc); 1897: TtaSetGraphicsShape (leaf, c, doc); 1898: 1899: /* create the ClosingFence element according to close attribute */ 1900: c = ')'; 1901: attrType.AttrTypeNum = MathML_ATTR_close; 1902: attr = TtaGetAttribute (el, attrType); 1903: if (attr != NULL) 1904: { 1905: length = 7; 1906: TtaGiveTextAttributeValue (attr, text, &length); 1907: c = text[0]; 1908: } 1909: elType.ElTypeNum = MathML_EL_ClosingFence; 1910: fence = TtaNewElement (doc, elType); 1911: TtaInsertSibling (fence, fencedExpression, FALSE, doc); 1912: elType.ElTypeNum = MathML_EL_SYMBOL_UNIT; 1913: leaf = TtaNewElement (doc, elType); 1914: TtaInsertFirstChild (&leaf, fence, doc); 1915: TtaSetGraphicsShape (leaf, c, doc); 1916: } 1917: } 1918: 1919: /*---------------------------------------------------------------------- 1920: MathMLElementComplete 1921: Check the Thot structure of the MathML element el. 1922: ----------------------------------------------------------------------*/ 1923: #ifdef __STDC__ 1924: void MathMLElementComplete (Element el, Document doc) 1925: #else 1926: void MathMLElementComplete (el, doc) 1927: Element el; 1928: Document doc; 1929: 1930: #endif 1931: { 1932: ElementType elType, parentType; 1933: Element child, parent, new, prev, next; 1934: AttributeType attrType; 1935: Attribute attr; 1.2 cvs 1936: SSchema MathMLSSchema; 1.1 cvs 1937: 1938: elType = TtaGetElementType (el); 1.2 cvs 1939: MathMLSSchema = GetMathMLSSchema (doc); 1.1 cvs 1940: 1941: if (elType.ElSSchema != MathMLSSchema) 1942: /* this is not a MathML element. It's the HTML element <math>, or 1943: any other element containing a MathML expression */ 1944: { 1945: if (TtaGetFirstChild (el) == NULL && !TtaIsLeaf (elType)) 1946: /* this element is empty. Create a MathML element as it's child */ 1947: { 1948: elType.ElSSchema = MathMLSSchema; 1949: elType.ElTypeNum = MathML_EL_MathML; 1950: new = TtaNewElement (doc, elType); 1951: TtaInsertFirstChild (&new, el, doc); 1952: /* Create a placeholder within the MathML element */ 1953: elType.ElTypeNum = MathML_EL_Construct; 1954: child = TtaNewElement (doc, elType); 1955: TtaInsertFirstChild (&child, new, doc); 1956: attrType.AttrSSchema = elType.ElSSchema; 1.22 cvs 1957: attrType.AttrTypeNum = MathML_ATTR_IntPlaceholder; 1.1 cvs 1958: attr = TtaNewAttribute (attrType); 1959: TtaAttachAttribute (child, attr, doc); 1.28 cvs 1960: TtaSetAttributeValue (attr, MathML_ATTR_IntPlaceholder_VAL_yes_, 1961: child, doc); 1.1 cvs 1962: } 1963: } 1964: else 1965: { 1966: switch (elType.ElTypeNum) 1967: { 1968: case MathML_EL_TEXT_UNIT: 1969: CheckTextElement (&el, doc); 1970: break; 1971: case MathML_EL_MI: 1972: SetFontstyleAttr (el, doc); 1973: break; 1974: case MathML_EL_MO: 1.22 cvs 1975: SetIntAddSpaceAttr (el, doc); 1976: SetIntVertStretchAttr (el, doc, 0, NULL); 1.1 cvs 1977: break; 1.39 cvs 1978: case MathML_EL_MROW: 1979: /* end of MROW */ 1980: /*if the first and the last child are MO containing a fence character 1981: transform the MO into a MF and the character into a Thot SYMBOL */ 1982: child = TtaGetFirstChild (el); 1983: if (child != NULL) 1984: { 1985: CheckFence (child, doc); 1986: child = TtaGetLastChild (el); 1987: if (child != NULL) 1988: CheckFence (child, doc); 1989: /* Create placeholders within the MROW */ 1990: CreatePlaceholders (TtaGetFirstChild (el), doc); 1991: } 1992: break; 1993: case MathML_EL_MFRAC: 1994: /* end of a fraction. Create a Numerator and a Denominator */ 1995: CheckMathSubExpressions (el, MathML_EL_Numerator, 1996: MathML_EL_Denominator, 0, doc); 1997: break; 1998: case MathML_EL_MSQRT: 1999: /* end od a Square Root. Create a SqrtBase that contains all 2000: children of the MSQRT element */ 2001: CreateWrapper (el, MathML_EL_SqrtBase, doc); 2002: break; 1.1 cvs 2003: case MathML_EL_MROOT: 2004: /* end of a Root. Create a RootBase and an Index */ 2005: CheckMathSubExpressions (el, MathML_EL_RootBase, MathML_EL_Index, 2006: 0, doc); 2007: break; 1.39 cvs 2008: case MathML_EL_MSTYLE: 2009: case MathML_EL_MERROR: 2010: case MathML_EL_MPADDED: 2011: case MathML_EL_MPHANTOM: 2012: /* Create placeholders within the element */ 2013: CreatePlaceholders (TtaGetFirstChild (el), doc); 1.1 cvs 2014: break; 2015: case MathML_EL_MFENCED: 2016: TransformMFENCED (el, doc); 2017: break; 2018: case MathML_EL_MSUB: 2019: /* end of a MSUB. Create Base and Subscript */ 2020: CheckMathSubExpressions (el, MathML_EL_Base, MathML_EL_Subscript, 2021: 0, doc); 1.22 cvs 2022: SetIntVertStretchAttr (el, doc, MathML_EL_Base, NULL); 1.1 cvs 2023: break; 2024: case MathML_EL_MSUP: 2025: /* end of a MSUP. Create Base and Superscript */ 2026: CheckMathSubExpressions (el, MathML_EL_Base, MathML_EL_Superscript, 2027: 0, doc); 1.22 cvs 2028: SetIntVertStretchAttr (el, doc, MathML_EL_Base, NULL); 1.1 cvs 2029: break; 1.39 cvs 2030: case MathML_EL_MSUBSUP: 2031: /* end of a MSUBSUP. Create Base, Subscript, and Superscript */ 2032: CheckMathSubExpressions (el, MathML_EL_Base, MathML_EL_Subscript, 2033: MathML_EL_Superscript, doc); 2034: SetIntVertStretchAttr (el, doc, MathML_EL_Base, NULL); 1.1 cvs 2035: break; 2036: case MathML_EL_MUNDER: 2037: /* end of a MUNDER. Create UnderOverBase, and Underscript */ 2038: CheckMathSubExpressions (el, MathML_EL_UnderOverBase, 2039: MathML_EL_Underscript, 0, doc); 1.22 cvs 2040: SetIntHorizStretchAttr (el, doc); 2041: SetIntVertStretchAttr (el, doc, MathML_EL_UnderOverBase, NULL); 1.1 cvs 2042: break; 2043: case MathML_EL_MOVER: 2044: /* end of a MOVER. Create UnderOverBase, and Overscript */ 2045: CheckMathSubExpressions (el, MathML_EL_UnderOverBase, 2046: MathML_EL_Overscript, 0, doc); 1.22 cvs 2047: SetIntHorizStretchAttr (el, doc); 2048: SetIntVertStretchAttr (el, doc, MathML_EL_UnderOverBase, NULL); 1.1 cvs 2049: break; 1.39 cvs 2050: case MathML_EL_MUNDEROVER: 2051: /* end of a MUNDEROVER. Create UnderOverBase, Underscript, and 2052: Overscript */ 2053: CheckMathSubExpressions (el, MathML_EL_UnderOverBase, 2054: MathML_EL_Underscript, MathML_EL_Overscript, doc); 2055: SetIntHorizStretchAttr (el, doc); 2056: SetIntVertStretchAttr (el, doc, MathML_EL_UnderOverBase, NULL); 2057: break; 1.1 cvs 2058: case MathML_EL_MMULTISCRIPTS: 2059: /* end of a MMULTISCRIPTS. Create all elements defined in the 2060: MathML S schema */ 2061: BuildMultiscript (el, doc); 1.5 cvs 2062: break; 2063: case MathML_EL_MTABLE: 2064: /* end of a MTABLE. Create all elements defined in the MathML S 2065: schema */ 2066: CheckMTable (el, doc); 1.1 cvs 2067: break; 1.39 cvs 2068: case MathML_EL_MTD: 2069: /* Create placeholders within the table cell */ 2070: CreatePlaceholders (TtaGetFirstChild (el), doc); 2071: break; 2072: case MathML_EL_MACTION: 2073: /* Create placeholders within the MACTION element */ 2074: CreatePlaceholders (TtaGetFirstChild (el), doc); 1.1 cvs 2075: break; 2076: default: 2077: break; 2078: } 2079: parent = TtaGetParent (el); 2080: parentType = TtaGetElementType (parent); 2081: if (parentType.ElSSchema != elType.ElSSchema) 2082: /* root of a MathML tree, Create a MathML element if there is no */ 2083: if (elType.ElTypeNum != MathML_EL_MathML) 2084: { 2085: elType.ElSSchema = MathMLSSchema; 2086: elType.ElTypeNum = MathML_EL_MathML; 2087: new = TtaNewElement (doc, elType); 2088: TtaInsertSibling (new, el, TRUE, doc); 2089: next = el; 2090: TtaNextSibling (&next); 2091: TtaRemoveTree (el, doc); 2092: TtaInsertFirstChild (&el, new, doc); 2093: prev = el; 2094: while (next != NULL) 2095: { 2096: child = next; 2097: TtaNextSibling (&next); 2098: TtaRemoveTree (child, doc); 2099: TtaInsertSibling (child, prev, FALSE, doc); 2100: prev = child; 2101: } 2102: /* Create placeholders within the MathML element */ 2103: CreatePlaceholders (el, doc); 2104: } 2105: } 2106: } 2107: 2108: /*---------------------------------------------------------------------- 1.24 cvs 2109: SetFontfamily 2110: -----------------------------------------------------------------------*/ 2111: #ifdef __STDC__ 2112: void SetFontfamily (Document doc, Element el, STRING value) 2113: #else /* __STDC__*/ 2114: void SetFontfamily (doc, el, value) 2115: Document doc; 2116: Element el; 2117: STRING value; 2118: #endif /* __STDC__*/ 2119: { 2120: #define buflen 50 2121: CHAR_T css_command[buflen+20]; 2122: 1.26 cvs 2123: usprintf (css_command, TEXT("font-family: %s"), value); 1.24 cvs 2124: ParseHTMLSpecificStyle (el, css_command, doc, FALSE); 2125: } 2126: 2127: /*---------------------------------------------------------------------- 2128: SetFontsize 2129: -----------------------------------------------------------------------*/ 2130: #ifdef __STDC__ 2131: void SetFontsize (Document doc, Element el, STRING value) 2132: #else /* __STDC__*/ 2133: void SetFontsize (doc, el, value) 2134: Document doc; 2135: Element el; 2136: STRING value; 2137: #endif /* __STDC__*/ 2138: { 2139: #define buflen 50 2140: CHAR_T css_command[buflen+20]; 2141: 1.26 cvs 2142: usprintf (css_command, TEXT("font-size: %s"), value); 1.24 cvs 2143: ParseHTMLSpecificStyle (el, css_command, doc, FALSE); 2144: } 2145: 2146: /*---------------------------------------------------------------------- 1.1 cvs 2147: MathMLAttributeComplete 2148: ----------------------------------------------------------------------*/ 2149: #ifdef __STDC__ 2150: void MathMLAttributeComplete (Attribute attr, Element el, Document doc) 2151: #else 2152: void MathMLAttributeComplete (attr, el, doc) 2153: Attribute attr; 2154: Element el; 2155: Document doc; 2156: 2157: #endif 2158: { 1.23 cvs 2159: AttributeType attrType; 2160: int attrKind; 2161: #define buflen 50 1.33 cvs 2162: STRING value; 1.23 cvs 2163: int length; 2164: 2165: TtaGiveAttributeType (attr, &attrType, &attrKind); 1.24 cvs 2166: if (attrType.AttrTypeNum == MathML_ATTR_color || 2167: attrType.AttrTypeNum == MathML_ATTR_background_ || 2168: attrType.AttrTypeNum == MathML_ATTR_fontsize || 2169: attrType.AttrTypeNum == MathML_ATTR_fontfamily) 1.23 cvs 2170: { 2171: length = TtaGetTextAttributeLength (attr); 2172: if (length >= buflen) 2173: length = buflen - 1; 2174: if (length > 0) 2175: { 1.33 cvs 2176: value = (STRING) TtaGetMemory (sizeof (CHAR_T) * buflen); 2177: value[0] = EOS; 2178: TtaGiveTextAttributeValue (attr, value, &length); 2179: switch (attrType.AttrTypeNum) 2180: { 2181: case MathML_ATTR_color: 1.24 cvs 2182: HTMLSetForegroundColor (doc, el, value); 2183: break; 1.33 cvs 2184: case MathML_ATTR_background_: 1.24 cvs 2185: HTMLSetBackgroundColor (doc, el, value); 2186: break; 1.33 cvs 2187: case MathML_ATTR_fontsize: 1.24 cvs 2188: SetFontsize (doc, el, value); 2189: break; 1.33 cvs 2190: case MathML_ATTR_fontfamily: 1.24 cvs 2191: SetFontfamily (doc, el, value); 2192: break; 1.33 cvs 2193: } 2194: TtaFreeMemory (value); 1.23 cvs 2195: } 2196: } 1.1 cvs 2197: } 2198: 2199: /*---------------------------------------------------------------------- 2200: MathMLGetDTDName 2201: ----------------------------------------------------------------------*/ 2202: #ifdef __STDC__ 1.14 cvs 2203: void MathMLGetDTDName (STRING DTDname, STRING elementName) 1.1 cvs 2204: #else 2205: void MathMLGetDTDName (DTDname, elementName) 1.14 cvs 2206: STRING DTDname; 2207: STRING elementName; 1.1 cvs 2208: 2209: #endif 2210: { 2211: /* no other DTD allowed within MathML elements */ 1.26 cvs 2212: ustrcpy (DTDname, _EMPTYSTR_); 1.1 cvs 2213: } 2214: 2215: /* end of module */