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

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

Webmaster