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

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

Webmaster