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

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

Webmaster