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

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

Webmaster