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

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

Webmaster