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

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

Webmaster