Annotation of Amaya/amaya/MathMLbuilder.c, revision 1.80

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

Webmaster