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

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

Webmaster