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

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

Webmaster