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

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:  */
1.159     quint       7: 
1.1       cvs         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:     }
1.158     quint     133:   else if (elType.ElTypeNum == MathML_EL_MO ||
                    134:           elType.ElTypeNum == MathML_EL_OpeningFence ||
                    135:           elType.ElTypeNum == MathML_EL_ClosingFence ||
                    136:           elType.ElTypeNum == MathML_EL_FencedSeparator)
1.138     cvs       137:     /* an operator that contains a single Symbol needs a placeholder,
                    138:        except when it is in a Base or UnderOverBase */
                    139:     {
                    140:       child = TtaGetFirstChild (el);
                    141:       if (child != NULL)
1.1       cvs       142:        {
1.138     cvs       143:          elType = TtaGetElementType (child);
                    144:          if (elType.ElTypeNum == MathML_EL_SYMBOL_UNIT)
                    145:            {
1.1       cvs       146:              ret = TRUE;
                    147:              parent = TtaGetParent (el);
                    148:              if (parent != NULL)
                    149:                {
1.138     cvs       150:                  elType = TtaGetElementType (parent);
                    151:                  if (elType.ElTypeNum == MathML_EL_Base ||
                    152:                      elType.ElTypeNum == MathML_EL_UnderOverBase)
1.139     quint     153:                    ret = FALSE;
                    154:                }
                    155:            }
                    156:        }
                    157:     }
                    158:   else if (elType.ElTypeNum == MathML_EL_MSPACE)
                    159:     {
                    160:       /* in principle mspace needs a placeholder sibling */
                    161:       ret = TRUE;
                    162:       /* but if it's the only child of a mstyle element, the placeholders
                    163:         would change the height and width of the mstyle. Consider for
                    164:         instance:
                    165:         <mstyle background="#000099">
                    166:           <mspace depth="2mm" width=".2in"/>
                    167:         </mstyle>  */
                    168:       sibling = el;  TtaNextSibling (&sibling);
                    169:       if (!sibling)
                    170:        {
                    171:          sibling = el;  TtaPreviousSibling (&sibling);
                    172:          if (!sibling)
                    173:            {
                    174:              parent = TtaGetParent (el);
                    175:              if (parent)
                    176:                {
                    177:                  elType = TtaGetElementType (parent);
                    178:                  if (elType.ElTypeNum == MathML_EL_MSTYLE)
1.138     cvs       179:                    ret = FALSE;
1.1       cvs       180:                }
1.138     cvs       181:            }
1.1       cvs       182:        }
1.138     cvs       183:     }
1.1       cvs       184:   return ret;
                    185: }
1.132     cvs       186: 
1.1       cvs       187: /*----------------------------------------------------------------------
                    188:   CreatePlaceholders
                    189:   ----------------------------------------------------------------------*/
                    190: static void    CreatePlaceholders (Element el, Document doc)
                    191: {
1.132     cvs       192:    Element      sibling, prev, constr, child;
                    193:    Attribute    attr;
                    194:    ElementType  elType;
                    195:    AttributeType attrType;
                    196:    ThotBool     create, stretchableSubsup;
1.1       cvs       197: 
1.55      cvs       198:    if (!el)
                    199:       return;
1.2       cvs       200:    elType.ElSSchema = GetMathMLSSchema (doc);
1.1       cvs       201:    prev = NULL;
                    202:    create = TRUE;
                    203:    sibling = el;
                    204:    while (sibling != NULL)
                    205:       {
                    206:       if (!ElementNeedsPlaceholder (sibling))
                    207:         create = FALSE;
                    208:       else
                    209:         {
                    210:         if (sibling == el)
                    211:            /* first element */
                    212:            {
                    213:            elType = TtaGetElementType (sibling);
                    214:            if (elType.ElTypeNum == MathML_EL_MF)
                    215:               /* the first element is a MF. Don't create a placeholder
                    216:                  before */
                    217:               create = FALSE;
                    218:            else if (elType.ElTypeNum == MathML_EL_MROW)
                    219:               /* the first element is a MROW */
                    220:               {
                    221:               child = TtaGetFirstChild (sibling);
                    222:               if (child != NULL)
                    223:                  {
                    224:                  elType = TtaGetElementType (child);
                    225:                  if (elType.ElTypeNum != MathML_EL_MF)
                    226:                     /* the first child of the MROW element is not a MF */
                    227:                     /* Don't create a placeholder before */
                    228:                     create = FALSE;
                    229:                  }
                    230:               }
                    231:            }
                    232:         if (create)
                    233:            {
                    234:             elType.ElTypeNum = MathML_EL_Construct;
                    235:            constr = TtaNewElement (doc, elType);
                    236:            TtaInsertSibling (constr, sibling, TRUE, doc);
                    237:            attrType.AttrSSchema = elType.ElSSchema;
1.22      cvs       238:            attrType.AttrTypeNum = MathML_ATTR_IntPlaceholder;
1.1       cvs       239:            attr = TtaNewAttribute (attrType);
                    240:            TtaAttachAttribute (constr, attr, doc);
1.55      cvs       241:            TtaSetAttributeValue (attr, MathML_ATTR_IntPlaceholder_VAL_yes_,
                    242:                                  constr, doc);
1.1       cvs       243:            }
                    244:         create = TRUE;
                    245:         }
                    246:       prev = sibling;
                    247:       TtaNextSibling (&sibling);
                    248:       }
                    249:    if (prev != NULL && create)
                    250:       {
1.132     cvs       251:        stretchableSubsup = FALSE;
1.1       cvs       252:        elType = TtaGetElementType (prev);
1.95      cvs       253:        /* don't insert a placeholder after the last element if it's a MF */
                    254:        if (elType.ElTypeNum == MathML_EL_MF)
1.1       cvs       255:           create = FALSE;
                    256:        else if (elType.ElTypeNum == MathML_EL_MROW)
                    257:           /* the last element is a MROW */
                    258:           {
                    259:           child = TtaGetLastChild (prev);
                    260:           if (child != NULL)
                    261:              {
                    262:              elType = TtaGetElementType (child);
                    263:              if (elType.ElTypeNum != MathML_EL_MF)
                    264:                 /* the last child of the MROW element is not a MF */
                    265:                 /* Don't create a placeholder before */
                    266:                 create = FALSE;
                    267:              }
                    268:           }
1.132     cvs       269:        else if (elType.ElTypeNum == MathML_EL_MSUBSUP ||
                    270:                 elType.ElTypeNum == MathML_EL_MSUB ||
                    271:                 elType.ElTypeNum == MathML_EL_MSUP ||
                    272:                 elType.ElTypeNum == MathML_EL_MUNDEROVER ||
                    273:                 elType.ElTypeNum == MathML_EL_MUNDER ||
                    274:                 elType.ElTypeNum == MathML_EL_MUNDEROVER)
                    275:          {
                    276:            attrType.AttrSSchema = elType.ElSSchema;
                    277:            attrType.AttrTypeNum = MathML_ATTR_IntVertStretch;
                    278:            if (TtaGetAttribute (prev, attrType))
                    279:              stretchableSubsup = TRUE;
                    280:          }
                    281: 
1.1       cvs       282:        if (create)
                    283:           {
1.132     cvs       284:           if (stretchableSubsup)
                    285:             elType.ElTypeNum = MathML_EL_Construct1;
                    286:           else
                    287:             elType.ElTypeNum = MathML_EL_Construct;
1.1       cvs       288:           constr = TtaNewElement (doc, elType);
                    289:           TtaInsertSibling (constr, prev, FALSE, doc);
                    290:           attrType.AttrSSchema = elType.ElSSchema;
1.22      cvs       291:           attrType.AttrTypeNum = MathML_ATTR_IntPlaceholder;
1.1       cvs       292:           attr = TtaNewAttribute (attrType);
                    293:           TtaAttachAttribute (constr, attr, doc);
1.55      cvs       294:           TtaSetAttributeValue (attr, MathML_ATTR_IntPlaceholder_VAL_yes_,
                    295:                                 constr, doc);
1.132     cvs       296:           }
1.1       cvs       297:       }
                    298: }
                    299: 
                    300: /*----------------------------------------------------------------------
1.95      cvs       301:   NextNotComment
                    302:   Return the next sibling of element el that is not an XMLcomment element.
                    303:   Return el itself if it's not a comment.
1.1       cvs       304:   ----------------------------------------------------------------------*/
1.95      cvs       305: static void    NextNotComment (Element* el, Element* prev)
1.1       cvs       306: {
                    307:    ElementType elType;
                    308: 
                    309:    if (*el == NULL)
                    310:       return;
                    311:    elType = TtaGetElementType (*el);
1.95      cvs       312:    while (*el != NULL && elType.ElTypeNum == MathML_EL_XMLcomment)
1.1       cvs       313:       {
                    314:       *prev = *el;
                    315:       TtaNextSibling (el);
                    316:       if (*el != NULL)
                    317:        elType = TtaGetElementType (*el);
                    318:       }
                    319: }
                    320: 
                    321: /*----------------------------------------------------------------------
                    322:   CheckMathSubExpressions
                    323:   Children of element el should be of type type1, type2, and type3.
1.56      cvs       324:   If they are not, wrap them in elements of these types.
1.124     cvs       325:   If element el has too many or not enough children, return FALSE.
1.1       cvs       326:   ----------------------------------------------------------------------*/
1.56      cvs       327: static ThotBool CheckMathSubExpressions (Element el, int type1, int type2, int type3, Document doc)
1.1       cvs       328: {
                    329:   Element      child, new, prev;
                    330:   ElementType  elType, childType;
1.124     cvs       331:   char          msgBuffer[200];
1.56      cvs       332:   ThotBool      result;
1.1       cvs       333: 
1.56      cvs       334:   result = TRUE;
1.2       cvs       335:   elType.ElSSchema = GetMathMLSSchema (doc);
1.1       cvs       336:   child = TtaGetFirstChild (el);
                    337:   prev = NULL;
1.95      cvs       338:   NextNotComment (&child, &prev);
1.56      cvs       339:   if (type1 == 0)
1.1       cvs       340:     {
1.56      cvs       341:     if (child)
                    342:       /* no child expected and there is one, error */
1.124     cvs       343:       {
                    344:        sprintf (msgBuffer, "No subexpression allowed in %s",
                    345:                 TtaGetElementTypeName (TtaGetElementType (el)));
                    346:        XmlParseError (errorParsing, msgBuffer, 0);
                    347:        result = FALSE;
                    348:       }
1.56      cvs       349:     }
                    350:   else
                    351:     if (!child)
                    352:       /* a first child is expected and it's missing */
1.124     cvs       353:       {
                    354:        sprintf (msgBuffer, "Missing subexpression in %s",
                    355:                 TtaGetElementTypeName (TtaGetElementType (el)));
                    356:        XmlParseError (errorParsing, msgBuffer, 0);
                    357:        result = FALSE;
                    358:       }
1.56      cvs       359:     else
                    360:       {
1.1       cvs       361:       elType.ElTypeNum = type1;
                    362:       childType = TtaGetElementType (child);
                    363:       if (TtaSameTypes (childType, elType) == 0)
                    364:        {
                    365:          TtaRemoveTree (child, doc);   
                    366:          new = TtaNewElement (doc, elType);
                    367:          if (prev == NULL)
                    368:            TtaInsertFirstChild (&new, el, doc);
                    369:          else
                    370:            TtaInsertSibling (new, prev, FALSE, doc);
                    371:          TtaInsertFirstChild (&child, new, doc);
                    372:          CreatePlaceholders (child, doc);
                    373:          child = new;
                    374:        }
1.56      cvs       375:       prev = child;
                    376:       TtaNextSibling (&child);
1.95      cvs       377:       NextNotComment (&child, &prev);
1.56      cvs       378:       if (type2 == 0)
                    379:         {
                    380:         if (child)
                    381:           /* this second child is not expected, error */
1.124     cvs       382:          {
                    383:            sprintf (msgBuffer, "Only 1 subexpression allowed in %s",
                    384:                     TtaGetElementTypeName (TtaGetElementType (el)));
                    385:            XmlParseError (errorParsing, msgBuffer, 0);
                    386:            result = FALSE;
                    387:          }
1.56      cvs       388:         }
                    389:       else
1.1       cvs       390:        {
1.56      cvs       391:          if (!child)
                    392:            /* a second child is expected and it's missing */
1.124     cvs       393:            {
                    394:              sprintf (msgBuffer, "2 subexpressions required in %s",
                    395:                       TtaGetElementTypeName (TtaGetElementType (el)));
                    396:              XmlParseError (errorParsing, msgBuffer, 0);
                    397:              result = FALSE;
                    398:            }
1.56      cvs       399:          else
1.1       cvs       400:            {
                    401:              elType.ElTypeNum = type2;
                    402:              childType = TtaGetElementType (child);
                    403:              if (TtaSameTypes (childType, elType) == 0)
                    404:                {
                    405:                  TtaRemoveTree (child, doc);
                    406:                  new = TtaNewElement (doc, elType);
                    407:                  TtaInsertSibling (new, prev, FALSE, doc);
                    408:                  TtaInsertFirstChild (&child, new, doc);
                    409:                  CreatePlaceholders (child, doc);
                    410:                  child = new;
                    411:                }
1.56      cvs       412:              prev = child;
                    413:              TtaNextSibling (&child);
1.95      cvs       414:              NextNotComment (&child, &prev);
1.56      cvs       415:              if (type3 == 0)
1.1       cvs       416:                {
1.56      cvs       417:                if (child)
                    418:                  /* this third child is not expected, error */
1.124     cvs       419:                  {
                    420:                    sprintf (msgBuffer, "Only 2 subexpressions allowed in %s",
                    421:                             TtaGetElementTypeName (TtaGetElementType (el)));
                    422:                    XmlParseError (errorParsing, msgBuffer, 0);
                    423:                    result = FALSE;
                    424:                  }
1.56      cvs       425:                }
                    426:              else
                    427:                {
                    428:                  if (!child)
                    429:                    /* a third child is expected and it's missing */
1.124     cvs       430:                    {
                    431:                      sprintf (msgBuffer, "3 subexpressions required in %s",
                    432:                               TtaGetElementTypeName (TtaGetElementType (el)));
                    433:                      XmlParseError (errorParsing, msgBuffer, 0);
                    434:                      result = FALSE;
                    435:                    }
1.56      cvs       436:                  else
1.1       cvs       437:                    {
                    438:                      elType.ElTypeNum = type3;
                    439:                      childType = TtaGetElementType (child);
                    440:                      if (TtaSameTypes (childType, elType) == 0)
                    441:                        {
                    442:                          TtaRemoveTree (child, doc);
                    443:                          new = TtaNewElement (doc, elType);
                    444:                          TtaInsertSibling (new, prev, FALSE, doc);
                    445:                          TtaInsertFirstChild (&child, new, doc);
                    446:                          CreatePlaceholders (child, doc);
1.56      cvs       447:                          child = new;
1.1       cvs       448:                        }
                    449:                    }
1.56      cvs       450:                  prev = child;
                    451:                  TtaNextSibling (&child);
1.95      cvs       452:                  NextNotComment (&child, &prev);
1.56      cvs       453:                  if (child)
                    454:                    /* this fourth child is unexpected */
1.124     cvs       455:                    {
                    456:                      sprintf (msgBuffer,"Only 3 subexpressions allowed in %s",
                    457:                               TtaGetElementTypeName (TtaGetElementType (el)));
                    458:                      XmlParseError (errorParsing, msgBuffer, 0);
                    459:                      result = FALSE;
                    460:                    }
1.1       cvs       461:                }
                    462:            }
                    463:         }
1.56      cvs       464:       }
                    465:   return result;
1.1       cvs       466: }
                    467: 
                    468: /*----------------------------------------------------------------------
1.22      cvs       469:    SetSingleIntHorizStretchAttr
1.1       cvs       470: 
1.22      cvs       471:    Put a IntHorizStretch attribute on element el if it contains only
1.1       cvs       472:    a MO element that is a stretchable symbol.
                    473:  -----------------------------------------------------------------------*/
1.22      cvs       474: void SetSingleIntHorizStretchAttr (Element el, Document doc, Element* selEl)
1.1       cvs       475: {
                    476:   Element      child, sibling, textEl, symbolEl;
1.152     quint     477:   ElementType  elType, childType, siblingType;
1.1       cvs       478:   Attribute    attr;
                    479:   AttributeType        attrType;
1.55      cvs       480:   Language     lang;
1.128     vatton    481:   CHAR_T        text[2];
1.143     vatton    482:   char         script;
1.49      cvs       483:   unsigned char c;
1.128     vatton    484:   int          len;
1.152     quint     485:   ThotBool      doit;
1.1       cvs       486: 
                    487:   if (el == NULL)
                    488:      return;
                    489:   child = TtaGetFirstChild (el);
1.154     vatton    490:   textEl = NULL;
1.55      cvs       491:   if (child)
1.1       cvs       492:      {
                    493:      elType = TtaGetElementType (child);
1.162     quint     494:      /* skip empty Constructs (placeholders) and comments */
                    495:      while (child &&
                    496:            (elType.ElTypeNum == MathML_EL_Construct ||
                    497:             elType.ElTypeNum == MathML_EL_XMLcomment) &&
                    498:            !strcmp (TtaGetSSchemaName (elType.ElSSchema), "MathML"))
1.152     quint     499:        {
                    500:         TtaNextSibling (&child);
                    501:         if (child)
                    502:           elType = TtaGetElementType (child);
                    503:        }
1.162     quint     504:      while (child && elType.ElTypeNum == MathML_EL_MROW &&
                    505:            strcmp (TtaGetSSchemaName (elType.ElSSchema), "MathML") == 0)
                    506:         /* the first significant child is a mrow. Check whether it has a
                    507:           single child */
1.98      cvs       508:         {
                    509:         child = TtaGetFirstChild (child);
                    510:        if (child)
                    511:          {
1.152     quint     512:            elType = TtaGetElementType (child);
1.162     quint     513:            /* skip empty Constructs (placeholders) and comments */
                    514:            while (child &&
                    515:                   (elType.ElTypeNum == MathML_EL_Construct ||
                    516:                    elType.ElTypeNum == MathML_EL_XMLcomment) &&
                    517:                   !strcmp (TtaGetSSchemaName (elType.ElSSchema), "MathML"))
1.152     quint     518:              {
1.162     quint     519:                TtaNextSibling (&child);
                    520:                if (child)
                    521:                  elType = TtaGetElementType (child);
1.152     quint     522:              }
1.98      cvs       523:            sibling = child;
                    524:            TtaNextSibling (&sibling);
1.152     quint     525:            if (sibling)
                    526:              /* there are other children */
                    527:              {
                    528:              siblingType = TtaGetElementType (sibling);
1.162     quint     529:              while (sibling &&
                    530:                     (siblingType.ElTypeNum == MathML_EL_Construct ||
                    531:                      siblingType.ElTypeNum == MathML_EL_XMLcomment) &&
                    532:                     !strcmp (TtaGetSSchemaName (siblingType.ElSSchema), "MathML"))
                    533:                /* its an empty construct (placeholder) or a comment, skip it*/
                    534:                {
                    535:                  TtaNextSibling (&sibling);
                    536:                  if (sibling)
                    537:                    siblingType = TtaGetElementType (sibling);
                    538:                }
1.152     quint     539:              if (sibling)
1.162     quint     540:                /* there are significant siblings */
1.152     quint     541:                child = NULL;
                    542:              }
1.98      cvs       543:          }
                    544:        }
1.152     quint     545:      if (child && (elType.ElTypeNum == MathML_EL_MO ||
                    546:                   elType.ElTypeNum == MathML_EL_MOVER ||
                    547:                   elType.ElTypeNum == MathML_EL_MUNDER))
                    548:        /* the first child is a MO, a MUNDER or a MOVER */
1.1       cvs       549:         {
                    550:         sibling = child;
                    551:         TtaNextSibling (&sibling);
1.152     quint     552:        if (sibling)
1.162     quint     553:          siblingType = TtaGetElementType (sibling);
                    554:        /* skip empty Constructs (placeholders) and comments */
                    555:        while (sibling &&
                    556:               (siblingType.ElTypeNum == MathML_EL_Construct ||
                    557:                siblingType.ElTypeNum == MathML_EL_XMLcomment) &&
                    558:               !strcmp (TtaGetSSchemaName (siblingType.ElSSchema), "MathML"))
1.152     quint     559:          {
1.162     quint     560:            TtaNextSibling (&sibling);
                    561:            if (sibling)
                    562:              siblingType = TtaGetElementType (sibling);
1.152     quint     563:          }
1.1       cvs       564:        if (sibling == NULL)
1.162     quint     565:           /* there is no other significant child */
1.1       cvs       566:           {
1.152     quint     567:           c = EOS;
                    568:           doit = FALSE;
                    569:           attrType.AttrSSchema = elType.ElSSchema;
                    570:           attrType.AttrTypeNum = MathML_ATTR_IntHorizStretch;
                    571: 
                    572:           if (elType.ElTypeNum == MathML_EL_MOVER ||
                    573:               elType.ElTypeNum == MathML_EL_MUNDER)
                    574:             /* check if the UnderOverBase has a IntHorizStretch attribute */
                    575:             {
                    576:               childType.ElTypeNum = MathML_EL_UnderOverBase;
                    577:               textEl = TtaSearchTypedElement (childType, SearchInTree, child);
                    578:               if (textEl)
                    579:                 {
                    580:                   if (TtaGetAttribute (textEl, attrType))
                    581:                     doit = TRUE;
                    582:                  }
                    583:             }
                    584:           else if (elType.ElTypeNum == MathML_EL_MO)
                    585:             {
                    586:             textEl = TtaGetFirstChild (child);
                    587:             childType = TtaGetElementType (textEl);
                    588:             if (childType.ElTypeNum == MathML_EL_TEXT_UNIT)
                    589:               /* the MO child contains a TEXT element */
                    590:               {
                    591:               len = TtaGetElementVolume (textEl);
                    592:               if (len == 1)
1.123     cvs       593:                 /* the TEXT element contains a single character */
                    594:                 {
1.152     quint     595:                   /* get that character */
                    596:                   len = 2;
                    597:                   TtaGiveBufferContent (textEl, text, len, &lang);
                    598:                   script = TtaGetScript (lang);
                    599:                   if (
1.146     quint     600: #ifndef _I18N_
1.152     quint     601:                       (script == 'L') &&
1.146     quint     602: #endif
1.152     quint     603:                       (text[0] == '-' || text[0] == '_' ||
                    604:                        text[0] == 175))
1.146     quint     605:                     /* a horizontal line in the middle of the box */
                    606:                     c = 'h'; 
1.152     quint     607:                   else 
                    608: #ifdef _I18N_
                    609:                     if (text[0] == 0x2190)
                    610:                       c = 'L';  /* arrow left */
                    611:                     else if (text[0] == 0x2192)
                    612:                       c = 'R';  /* arrow right */
1.153     quint     613:                     else if (text[0] == 45)        /* - (minus) */
                    614:                       /* a horizontal line in the middle of the box */
                    615:                       c = 'h'; 
                    616:                     else if (text[0] == 0x2212)    /* - (minus) */
1.152     quint     617:                       /* a horizontal line in the middle of the box */
                    618:                       c = 'h'; 
                    619:                     else if (text[0] == 0x0332)    /* UnderBar */
                    620:                       /* a horizontal line */
                    621:                       c = 'h'; 
                    622:                     else if (text[0] == 65079)
                    623:                       c = 'o';  /* Over brace */
                    624:                     else if (text[0] == 65080)
                    625:                       c = 'u';  /* Under brace */
1.146     quint     626: #else
                    627:                   if (script == 'G')
                    628:                     /* a single Symbol character */
                    629:                     {
                    630:                       if (text[0] == 172)
                    631:                         c = 'L';  /* arrow left */
                    632:                       else if (text[0] == 174)
                    633:                         c = 'R';  /* arrow right */
                    634:                       else if (text[0] == 45)    /* - (minus) */
                    635:                         /* a horizontal line in the middle of the box */
                    636:                         c = 'h'; 
                    637:                       else if (text[0] == 132)
                    638:                         c = 'o';  /* Over brace */
                    639:                       else if (text[0] == 133)
                    640:                         c = 'u';  /* Under brace */
                    641:                     }
                    642: #endif
1.152     quint     643:                   if (c != EOS)
                    644:                     doit = TRUE;
1.123     cvs       645:                 }
1.152     quint     646:               }
                    647:             }
                    648:           if (doit)
                    649:             {
                    650:               /* attach a IntHorizStretch attribute to the element
                    651:                  (UnderOverBase, Underscript, or Overscript) */
                    652:               attr = TtaNewAttribute (attrType);
                    653:               TtaAttachAttribute (el, attr, doc);
                    654:               TtaSetAttributeValue (attr, MathML_ATTR_IntHorizStretch_VAL_yes_, el, doc);
                    655:               attr = TtaNewAttribute (attrType);
                    656:               TtaAttachAttribute (child, attr, doc);
                    657:               TtaSetAttributeValue (attr, MathML_ATTR_IntHorizStretch_VAL_yes_, child, doc);
                    658:             }
                    659:           if (c != EOS)
                    660:             {
                    661:               /* replace the TEXT element by a Thot SYMBOL element */
                    662:               childType.ElTypeNum = MathML_EL_SYMBOL_UNIT;
                    663:               symbolEl = TtaNewElement (doc, childType);
                    664:               TtaInsertSibling (symbolEl, textEl, FALSE, doc);
                    665:               if (selEl != NULL)
                    666:                 if (*selEl == textEl)
                    667:                   *selEl = symbolEl;
                    668:               TtaDeleteTree (textEl, doc);
                    669:               if (c != EOS)
                    670:                 TtaSetGraphicsShape (symbolEl, c, doc);
                    671:             }
1.1       cvs       672:           }
                    673:        }
                    674:      }
                    675: }
1.162     quint     676: 
1.1       cvs       677: /*----------------------------------------------------------------------
1.22      cvs       678:    SetIntHorizStretchAttr
1.1       cvs       679: 
1.152     quint     680:    Put a IntHorizStretch attribute on all children of element el that
1.1       cvs       681:    contain only a MO element that is a stretchable symbol.
                    682:  -----------------------------------------------------------------------*/
1.22      cvs       683: static void SetIntHorizStretchAttr (Element el, Document doc)
1.1       cvs       684: {
                    685:   Element      child;
                    686: 
                    687:   if (el == NULL)
                    688:      return;
                    689:   child = TtaGetFirstChild (el);
                    690:   while (child != NULL)
                    691:      {
1.22      cvs       692:      SetSingleIntHorizStretchAttr (child, doc, NULL);
1.1       cvs       693:      TtaNextSibling (&child);
                    694:      }
                    695: }
                    696: 
                    697: /*----------------------------------------------------------------------
1.22      cvs       698:    SetIntVertStretchAttr
1.1       cvs       699: 
1.22      cvs       700:    Put a IntVertStretch attribute on element el if its base element
1.1       cvs       701:    (Base for a MSUBSUP, MSUP or MSUB; UnderOverBase for a MUNDEROVER,
                    702:    a MUNDER of a MOVER) contains only a MO element that is a vertically
1.162     quint     703:    stretchable symbol (integral, vertical arrow, etc).
1.1       cvs       704:  -----------------------------------------------------------------------*/
1.22      cvs       705: void SetIntVertStretchAttr (Element el, Document doc, int base, Element* selEl)
1.1       cvs       706: {
1.132     cvs       707:   Element      child, sibling, textEl, symbolEl, parent, operator, next;
1.1       cvs       708:   ElementType  elType;
                    709:   Attribute    attr;
                    710:   AttributeType        attrType;
1.131     cvs       711:   SSchema       MathMLSSchema;
1.128     vatton    712:   Language     lang;
1.143     vatton    713:   char         script;
1.131     cvs       714: #define buflen 50
                    715:   CHAR_T        text[buflen];
1.49      cvs       716:   unsigned char c;
1.131     cvs       717:   int          len, i;
1.162     quint     718:   ThotBool      inbase, stretchable;
1.1       cvs       719: 
                    720:   if (el == NULL)
1.131     cvs       721:     return;
1.1       cvs       722:   operator = NULL;
1.131     cvs       723:   inbase = FALSE;
                    724:   MathMLSSchema = TtaGetElementType(el).ElSSchema;
1.154     vatton    725:   symbolEl = parent = NULL;
1.1       cvs       726:   if (base == 0)
1.131     cvs       727:     /* it's a MO */
                    728:     {
                    729:       parent = TtaGetParent (el);
                    730:       if (parent != NULL)
1.1       cvs       731:        {
1.131     cvs       732:          /* don't process the mo if it is within a base. It will be processed
                    733:             when the enclosing construct is processed (see below) */
                    734:          elType = TtaGetElementType (parent);
                    735:          if (elType.ElSSchema != MathMLSSchema ||
                    736:              (elType.ElTypeNum != MathML_EL_Base &&
                    737:               elType.ElTypeNum != MathML_EL_UnderOverBase &&
                    738:               elType.ElTypeNum != MathML_EL_MSUBSUP &&
                    739:               elType.ElTypeNum != MathML_EL_MSUB &&
                    740:               elType.ElTypeNum != MathML_EL_MSUP &&
                    741:               elType.ElTypeNum != MathML_EL_MUNDEROVER &&
                    742:               elType.ElTypeNum != MathML_EL_MUNDER &&
1.162     quint     743:               elType.ElTypeNum != MathML_EL_MUNDEROVER &&
                    744:               elType.ElTypeNum != MathML_EL_MTD))
1.131     cvs       745:            operator = el;
1.1       cvs       746:         }
1.131     cvs       747:     }
1.1       cvs       748:   else
1.131     cvs       749:     /* it's not a MO */
                    750:     {
                    751:       /* search the Base or UnderOverBase child */
                    752:       child = TtaGetFirstChild (el);
                    753:       if (child != NULL)
1.1       cvs       754:         {
1.131     cvs       755:          elType = TtaGetElementType (child);
1.162     quint     756:          /* skip empty Constructs (placeholders) and comments */
                    757:          while (child &&
                    758:                 (elType.ElTypeNum == MathML_EL_Construct ||
                    759:                  elType.ElTypeNum == MathML_EL_XMLcomment) &&
                    760:                 elType.ElSSchema == MathMLSSchema)
                    761:            {
                    762:              TtaNextSibling (&child);
                    763:              if (child)
                    764:                elType = TtaGetElementType (child);
                    765:            }
                    766: 
1.131     cvs       767:          if (elType.ElTypeNum == base && elType.ElSSchema == MathMLSSchema)
                    768:            /* the first child is a Base or UnderOverBase */
                    769:            {
                    770:              child = TtaGetFirstChild (child);
                    771:              if (child != NULL)
                    772:                {
                    773:                  elType = TtaGetElementType (child);
1.162     quint     774:                  /* skip empty Constructs (placeholders) and comments */
                    775:                  while (child &&
                    776:                         (elType.ElTypeNum == MathML_EL_Construct ||
                    777:                          elType.ElTypeNum == MathML_EL_XMLcomment) &&
                    778:                         elType.ElSSchema == MathMLSSchema)
                    779:                    {
                    780:                      TtaNextSibling (&child);
                    781:                      if (child)
                    782:                        elType = TtaGetElementType (child);
                    783:                    }
                    784: 
1.131     cvs       785:                  if (elType.ElTypeNum == MathML_EL_MO &&
                    786:                      elType.ElSSchema == MathMLSSchema)
1.162     quint     787:                    /* its first significant child is a MO */
1.131     cvs       788:                    {
                    789:                      sibling = child;
                    790:                      TtaNextSibling (&sibling);
1.162     quint     791:                      /* skip empty Constructs (placeholders) and comments */
                    792:                      while (sibling &&
                    793:                             (elType.ElTypeNum == MathML_EL_Construct ||
                    794:                              elType.ElTypeNum == MathML_EL_XMLcomment) &&
                    795:                             elType.ElSSchema == MathMLSSchema)
                    796:                        {
                    797:                          TtaNextSibling (&sibling);
                    798:                          if (sibling)
                    799:                            elType = TtaGetElementType (sibling);
                    800:                        }
                    801: 
1.131     cvs       802:                      if (sibling == NULL)
1.162     quint     803:                        /* there is no other significant child */
1.131     cvs       804:                        {
                    805:                          operator = child;
                    806:                          if (base == MathML_EL_Base ||
                    807:                              base == MathML_EL_UnderOverBase)
                    808:                            {
                    809:                              parent = el;
                    810:                              inbase = TRUE;
                    811:                            }
                    812:                        }
                    813:                    }
                    814:                }
                    815:            }
1.1       cvs       816:        }
1.131     cvs       817:     }
                    818:   if (operator)
                    819:     {
                    820:       textEl = TtaGetFirstChild (operator);
                    821:       if (textEl != NULL)
1.84      cvs       822:         {
1.131     cvs       823:          elType = TtaGetElementType (textEl);
                    824:          if (elType.ElTypeNum == MathML_EL_TEXT_UNIT)
                    825:            {
1.146     quint     826:              len = TtaGetElementVolume (textEl);
1.131     cvs       827:              if (len >= 1)
                    828:                {
                    829:                  if (len >= buflen)
                    830:                    len = buflen-1;
1.146     quint     831:                  TtaGiveBufferContent (textEl, text, len+1, &lang);
1.143     vatton    832:                  script = TtaGetScript (lang);
1.146     quint     833: #ifdef _I18N_
1.162     quint     834:                  stretchable = TRUE;
1.146     quint     835:                  for (i = 0; i < len; i++)
1.162     quint     836:                    if ((text[i] < 0x222B || text[i] > 0x2233) &&
                    837:                        text[i] != 0x2191 && text[i] != 0x2193 &&
                    838:                        text[i] != 0x2195 &&
                    839:                        text[i] != 0x21D1 && text[i] != 0x21D3 &&
                    840:                        text[i] != 0x21D5)
1.146     quint     841:                      /* accept only symbols like simple integral, double or
1.162     quint     842:                         triple integral, contour integral, etc. or vertical
                    843:                         arrows (add more arrows *****) */
                    844:                      stretchable = FALSE;
1.146     quint     845: #else
1.162     quint     846:                  stretchable = FALSE;
1.143     vatton    847:                  if (script == 'G')
1.131     cvs       848:                    /* Adobe Symbol character set */
1.55      cvs       849:                    {
1.162     quint     850:                    stretchable = TRUE;
1.131     cvs       851:                    /* check all characters in this TEXT element */
                    852:                    for (i = 0; i < len; i++)
1.162     quint     853:                      if (text[i] != 242 &&     /* integral */
                    854:                          text[i] != 173 && text[i] != 175 &&  /* arrows */
                    855:                          text[i] != 221 && text[i] != 223) /* double arrows */
1.131     cvs       856:                        /**** accept also other symbols like double or triple
                    857:                              integral, contour integral, etc. ****/
1.162     quint     858:                        stretchable = FALSE;
1.146     quint     859:                    }
                    860: #endif
1.162     quint     861:                  if (stretchable)
                    862:                    /* the operator contains only stretchable symbols */
1.146     quint     863:                    {
                    864:                      /* attach a IntVertStretch attribute */
                    865:                      attrType.AttrSSchema = MathMLSSchema;
                    866:                      attrType.AttrTypeNum = MathML_ATTR_IntVertStretch;
                    867:                      attr = TtaNewAttribute (attrType);
                    868:                      TtaAttachAttribute (el, attr, doc);
                    869:                      TtaSetAttributeValue (attr,
1.131     cvs       870:                                           MathML_ATTR_IntVertStretch_VAL_yes_,
                    871:                                           el, doc);
1.146     quint     872:                      TtaRegisterAttributeCreate (attr, el, doc);
                    873:                      
1.162     quint     874:                      /* replace the stretchable characters by a Thot SYMBOL
1.146     quint     875:                         element. If there are several such characters in
1.162     quint     876:                         the mo (multiple integral for instance), replace
                    877:                         them too. */
1.146     quint     878:                      do
                    879:                        {
                    880:                          /* replace the TEXT element by a Thot SYMBOL */
1.162     quint     881:                          elType.ElSSchema = MathMLSSchema;
1.146     quint     882:                          elType.ElTypeNum = MathML_EL_SYMBOL_UNIT;
                    883:                          for (i = 0; i < len; i++)
1.162     quint     884:                            {
                    885:                              if (selEl != NULL)
                    886:                                if (*selEl == textEl)
                    887:                                  *selEl = symbolEl;
1.146     quint     888: #ifdef _I18N_
1.162     quint     889:                              if (text[i] == 0x222B)
                    890:                                c = 'i';
                    891:                              else if (text[i] == 0x222C)
                    892:                                c = 'd';
                    893:                              else if (text[i] == 0x222D)
                    894:                                c = 't';
                    895:                              else if (text[i] == 0x222E)
                    896:                                c = 'c';
                    897:                              else if (text[i] == 0x2191)
                    898:                                c = '^';
                    899:                              else if (text[i] == 0x2193)
                    900:                                c = 'V';
1.146     quint     901: #else
1.162     quint     902:                              if (text[i] == 242)
                    903:                                c = 'i';
                    904:                              else if (text[i] == 173)
                    905:                                c = '<';
                    906:                              else if (text[i] == 175)
                    907:                                c = '>';
1.146     quint     908: #endif
1.162     quint     909:                              symbolEl = TtaNewElement (doc, elType);
                    910:                              TtaInsertSibling (symbolEl, textEl, TRUE,doc);
                    911:                              TtaSetGraphicsShape (symbolEl, c, doc);
                    912:                              TtaRegisterElementCreate (symbolEl, doc);
                    913:                            }
1.146     quint     914:                          TtaRegisterElementDelete (textEl, doc);
                    915:                          TtaDeleteTree (textEl, doc);
                    916:                          /* is there an other text element after the
1.162     quint     917:                             stretchable symbol? */
1.146     quint     918:                          textEl = symbolEl; TtaNextSibling (&textEl);
                    919:                          if (textEl)
                    920:                            {
                    921:                              elType = TtaGetElementType (textEl);
                    922:                              if (elType.ElTypeNum != MathML_EL_TEXT_UNIT)
                    923:                                textEl = NULL;
                    924:                              else
                    925:                                /* there is another text element.
1.162     quint     926:                                   Is it a single stretchable symbol? */
1.146     quint     927:                                {
                    928:                                  len = TtaGetElementVolume (textEl);
                    929:                                  if (len < 1)
                    930:                                    /* not a single character */
                    931:                                    textEl = NULL;
                    932:                                  else
                    933:                                    {
                    934:                                      if (len >= buflen)
                    935:                                        len = buflen-1;
                    936:                                      TtaGiveBufferContent (textEl, text,
                    937:                                                            len+1, &lang); 
                    938:                                      script = TtaGetScript (lang);
                    939: #ifdef _I18N_
1.164     quint     940:                                      if (text[0] != 0x222B &&
                    941:                                          text[0] != 0x222C &&
                    942:                                          text[0] != 0x222D &&
                    943:                                          text[0] != 0x222E &&
                    944:                                          text[0] != 0x2191 &&
                    945:                                          text[0] != 0x2193)
1.146     quint     946: #else
1.162     quint     947:                                      if (script != 'G' ||
1.164     quint     948:                                          (text[0] != 242 && text[0] != 173 &&
                    949:                                           text[0] != 175))
1.146     quint     950: #endif
1.162     quint     951:                                        /* not a stretchable symbol */
1.146     quint     952:                                        textEl = NULL;
                    953:                                    }
                    954:                                }
                    955:                            }
                    956:                        }
                    957:                      while (textEl);
                    958:                      
                    959:                      if (inbase)
                    960:                        /* it's within a Base or UnderOverBase element */
                    961:                        {
                    962:                          sibling = parent;
                    963:                          TtaNextSibling (&sibling);
                    964:                          if (sibling)
                    965:                            /* the msubsup of munderover element has a next
                    966:                               sibling */
                    967:                            {
                    968:                              elType = TtaGetElementType (sibling);
                    969:                              if (elType.ElTypeNum == MathML_EL_Construct &&
                    970:                                  elType.ElSSchema == MathMLSSchema)
                    971:                                /* the next sibling is a Construct */
                    972:                                {
                    973:                                  next = sibling;
                    974:                                  TtaNextSibling (&next);
                    975:                                  if (!next)
                    976:                                    /* there is no other sibling after the
                    977:                                       Construct. Change it into Construct1*/
                    978:                                    {
                    979:                                      TtaRegisterElementDelete (sibling, doc);
                    980:                                      TtaRemoveTree (sibling, doc);
                    981:                                      ChangeElementType (sibling,
1.132     cvs       982:                                                         MathML_EL_Construct1);
1.146     quint     983:                                      TtaInsertSibling (sibling, parent,
                    984:                                                        FALSE, doc);
                    985:                                      TtaRegisterElementCreate (sibling, doc);
                    986:                                      /* force the msubsup element to be
                    987:                                         reformatted and to take into account
                    988:                                         its new next sibling */
                    989:                                      TtaRemoveTree (parent, doc);
                    990:                                      TtaInsertSibling (parent, sibling, TRUE,
                    991:                                                        doc);
                    992:                                    }
                    993:                                }
                    994:                            }
                    995:                        } 
1.55      cvs       996:                    }
1.131     cvs       997:                }
                    998:            }
1.84      cvs       999:        }
1.131     cvs      1000:     }
1.1       cvs      1001: }
                   1002: 
                   1003: /*----------------------------------------------------------------------
1.22      cvs      1004:    SetIntPlaceholderAttr
1.1       cvs      1005: 
1.22      cvs      1006:    Put a IntPlaceholder attribute on all Construct elements in the
1.1       cvs      1007:    subtree of root el.
                   1008:  -----------------------------------------------------------------------*/
1.22      cvs      1009: static void SetIntPlaceholderAttr (Element el, Document doc)
1.1       cvs      1010: {
                   1011:   Element      child;
                   1012:   ElementType  elType;
                   1013:   Attribute    attr;
                   1014:   AttributeType        attrType;
                   1015: 
                   1016:   if (el == NULL)
                   1017:      return;
                   1018:   elType = TtaGetElementType (el);
                   1019:   if (elType.ElTypeNum == MathML_EL_Construct &&
1.2       cvs      1020:       elType.ElSSchema == GetMathMLSSchema (doc))
1.1       cvs      1021:      {
                   1022:      attrType.AttrSSchema = elType.ElSSchema;
1.22      cvs      1023:      attrType.AttrTypeNum = MathML_ATTR_IntPlaceholder;
1.1       cvs      1024:      attr = TtaNewAttribute (attrType);
                   1025:      TtaAttachAttribute (el, attr, doc);
1.22      cvs      1026:      TtaSetAttributeValue (attr, MathML_ATTR_IntPlaceholder_VAL_yes_, el, doc);
1.1       cvs      1027:      }
                   1028:   else
                   1029:      {
                   1030:      child = TtaGetFirstChild (el);
                   1031:      while (child != NULL)
                   1032:         {
1.22      cvs      1033:         SetIntPlaceholderAttr (child, doc);
1.1       cvs      1034:         TtaNextSibling (&child);
                   1035:         }
                   1036:      }
                   1037: }
                   1038: 
                   1039: /*----------------------------------------------------------------------
                   1040:    BuildMultiscript
                   1041: 
                   1042:    The content of a MMULTISCRIPT element has been created following
                   1043:    the original MathML structure.  Create all Thot elements defined
                   1044:    in the MathML S schema.
                   1045:  -----------------------------------------------------------------------*/
                   1046: static void BuildMultiscript (Element elMMULTISCRIPT, Document doc)
                   1047: {
                   1048:   Element      elem, base, next, group, pair, script, prevPair, prevScript;
                   1049:   ElementType  elType, elTypeGroup, elTypePair, elTypeScript;
1.2       cvs      1050:   SSchema       MathMLSSchema;
1.1       cvs      1051:   base = NULL;
                   1052:   group = NULL;
                   1053:   prevPair = NULL;
                   1054:   prevScript = NULL;
                   1055: 
1.2       cvs      1056:   MathMLSSchema = GetMathMLSSchema (doc);
1.1       cvs      1057:   elTypeGroup.ElSSchema = MathMLSSchema;
                   1058:   elTypePair.ElSSchema = MathMLSSchema;
                   1059:   elTypeScript.ElSSchema = MathMLSSchema;
                   1060: 
                   1061:   /* process all children of the MMULTISCRIPT element */
                   1062:   elem = TtaGetFirstChild (elMMULTISCRIPT);
                   1063:   while (elem != NULL)
                   1064:     {
                   1065:       /* remember the element to be processed after the current one */
                   1066:       next = elem;
                   1067:       TtaNextSibling (&next);
                   1068: 
                   1069:       /* remove the current element from the tree */
                   1070:       TtaRemoveTree (elem, doc);
                   1071: 
                   1072:       if (base == NULL)
                   1073:        /* the current element is the first child of the MMULTISCRIPT
                   1074:           element */
                   1075:        {
                   1076:          /* Create a MultiscriptBase element as the first child of
                   1077:             MMULTISCRIPT and move the current element as the first child
                   1078:             of the MultiscriptBase element */
                   1079:          elTypeGroup.ElTypeNum = MathML_EL_MultiscriptBase;
                   1080:          base = TtaNewElement (doc, elTypeGroup);
                   1081:          TtaInsertFirstChild (&base, elMMULTISCRIPT, doc);
                   1082:          TtaInsertFirstChild (&elem, base, doc);
                   1083:        }
                   1084:       else
                   1085:        /* the current element is a subscript or a superscript */
                   1086:        {
                   1087:          if (group == NULL)
                   1088:            /* there is no PostscriptPairs element. Create one */
                   1089:            {
                   1090:              elTypeGroup.ElTypeNum = MathML_EL_PostscriptPairs;
                   1091:              group = TtaNewElement (doc, elTypeGroup);
                   1092:              TtaInsertSibling (group, base, FALSE, doc);
                   1093:              elTypePair.ElTypeNum = MathML_EL_PostscriptPair;
                   1094:              /* create a first and a last PostscriptPair as placeholders */
1.47      cvs      1095:              pair = TtaNewTree (doc, elTypePair, "");
1.1       cvs      1096:              TtaInsertFirstChild (&pair, group, doc);
1.22      cvs      1097:              SetIntPlaceholderAttr (pair, doc);
1.1       cvs      1098:              prevPair = pair;
1.47      cvs      1099:              pair = TtaNewTree (doc, elTypePair, "");
1.1       cvs      1100:              TtaInsertSibling (pair, prevPair, FALSE, doc);
1.22      cvs      1101:              SetIntPlaceholderAttr (pair, doc);
1.1       cvs      1102:              prevScript = NULL;
                   1103:            }
                   1104:          if (prevScript == NULL)
                   1105:            /* the current element is the first subscript or superscript
                   1106:               in a pair */
                   1107:            {
                   1108:              /* create a PostscriptPair or PrescriptPair element */
                   1109:              pair = TtaNewElement (doc, elTypePair);
                   1110:              if (prevPair == NULL)
                   1111:                TtaInsertFirstChild (&pair, group, doc);
                   1112:              else
                   1113:                TtaInsertSibling (pair, prevPair, FALSE, doc);
                   1114:              prevPair = pair;
                   1115:              /* create a MSubscript element */
                   1116:              elTypeScript.ElTypeNum = MathML_EL_MSubscript;
                   1117:              script = TtaNewElement (doc, elTypeScript);
                   1118:              TtaInsertFirstChild (&script, pair, doc);
                   1119:              prevScript = script;        
                   1120:            }
                   1121:          else
                   1122:            /* the current element is a superscript in a pair */
                   1123:            {
                   1124:              /* create a MSuperscript element */
                   1125:              elTypeScript.ElTypeNum = MathML_EL_MSuperscript;
                   1126:              script = TtaNewElement (doc, elTypeScript);
                   1127:              /* insert it as a sibling of the previous MSubscript element */
                   1128:              TtaInsertSibling (script, prevScript, FALSE, doc);
                   1129:              prevScript = NULL;          
                   1130:            }
                   1131:          /* insert the current element as a child of the new MSuperscript or
                   1132:             MSubscript element */
                   1133:          TtaInsertFirstChild (&elem, script, doc);
1.22      cvs      1134:          SetIntPlaceholderAttr (elem, doc);
1.1       cvs      1135:        }
                   1136: 
                   1137:       CreatePlaceholders (elem, doc);
                   1138: 
                   1139:       /* get next child of the MMULTISCRIPT element */
                   1140:       elem = next;
                   1141:       if (elem != NULL)
                   1142:        {
                   1143:          elType = TtaGetElementType (elem);
                   1144:          if (elType.ElSSchema == MathMLSSchema &&
                   1145:              elType.ElTypeNum == MathML_EL_PrescriptPairs)
                   1146:            /* the next element is a PrescriptPairs */
                   1147:            {
                   1148:              /* if there there is no PostscriptPairs element, create one as a
                   1149:                 placeholder */
                   1150:              if (elTypeGroup.ElTypeNum != MathML_EL_PostscriptPairs)
                   1151:                {
                   1152:                  elTypeGroup.ElTypeNum = MathML_EL_PostscriptPairs;
1.47      cvs      1153:                  group = TtaNewTree (doc, elTypeGroup, "");
1.1       cvs      1154:                  TtaInsertSibling (group, elem, TRUE, doc);
1.22      cvs      1155:                  SetIntPlaceholderAttr (group, doc);
1.1       cvs      1156:                }
                   1157:              /* the following elements will be interpreted as sub- superscripts
                   1158:                 in PrescriptPair elements, wich will be children of this
                   1159:                 PrescriptPairs element */
                   1160:              elTypeGroup.ElTypeNum = MathML_EL_PrescriptPairs;
                   1161:              elTypePair.ElTypeNum = MathML_EL_PrescriptPair;
                   1162:              group = elem;
                   1163:              /* create a first and a last PostscriptPair as placeholders */
1.47      cvs      1164:              pair = TtaNewTree (doc, elTypePair, "");
1.1       cvs      1165:              TtaInsertFirstChild (&pair, group, doc);
1.22      cvs      1166:              SetIntPlaceholderAttr (pair, doc);
1.1       cvs      1167:              prevPair = pair;
1.47      cvs      1168:              pair = TtaNewTree (doc, elTypePair, "");
1.1       cvs      1169:              TtaInsertSibling (pair, prevPair, FALSE, doc);
1.22      cvs      1170:              SetIntPlaceholderAttr (pair, doc);
1.1       cvs      1171:              prevScript = NULL;
                   1172:              TtaNextSibling (&elem);
                   1173:            }
                   1174:        }
                   1175:     }
                   1176:   /* all children of element MMULTISCRIPTS have been processed */
                   1177:   /* if the last group processed is not a PrescriptPairs element,
                   1178:      create one as a placeholder */
                   1179:   if (elTypeGroup.ElTypeNum != MathML_EL_PrescriptPairs && base != NULL)
                   1180:     {
                   1181:       elTypeGroup.ElTypeNum = MathML_EL_PrescriptPairs;
1.47      cvs      1182:       elem = TtaNewTree (doc, elTypeGroup, "");
1.1       cvs      1183:       if (group == NULL)
                   1184:        group = base;
                   1185:       TtaInsertSibling (elem, group, TRUE, doc);
1.22      cvs      1186:       SetIntPlaceholderAttr (elem, doc);
1.1       cvs      1187:     }
                   1188: }
                   1189: 
1.39      cvs      1190: /*----------------------------------------------------------------------
                   1191:    CreateWrapper
                   1192: 
                   1193:    Create an element of type wrapperType as a child of element el and
                   1194:    move all chidren of element el within the new element.
                   1195:  -----------------------------------------------------------------------*/
                   1196: static void CreateWrapper (Element el, int wrapperType, Document doc)
                   1197: {
                   1198:    Element       wrapper, child, prevChild, nextChild;
                   1199:    ElementType   elType;
                   1200: 
                   1201:    child = TtaGetFirstChild (el);
                   1202:    elType.ElSSchema = GetMathMLSSchema (doc);
                   1203:    elType.ElTypeNum = wrapperType;
                   1204:    wrapper = TtaNewElement (doc, elType);
                   1205:    TtaInsertFirstChild (&wrapper, el, doc);
                   1206:    prevChild = NULL;
                   1207:    while (child)
                   1208:      {
                   1209:        nextChild = child;
                   1210:        TtaNextSibling (&nextChild);
                   1211:        TtaRemoveTree (child, doc);
                   1212:        if (prevChild == NULL)
                   1213:         TtaInsertFirstChild (&child, wrapper, doc);
                   1214:        else
                   1215:         TtaInsertSibling (child, prevChild, FALSE, doc);
                   1216:        prevChild = child;
                   1217:        child = nextChild;
                   1218:      }
                   1219: }
1.5       cvs      1220: 
                   1221: /*----------------------------------------------------------------------
                   1222:    CheckMTable
                   1223: 
                   1224:    The content of a MTABLE element has been created following
                   1225:    the original MathML structure.  Create all Thot elements defined
                   1226:    in the MathML S schema.
1.64      cvs      1227:    If placeholder, associate an attribute IntPlaceholder with all
1.103     cvs      1228:    cells generated in the MathML table.
1.5       cvs      1229:  -----------------------------------------------------------------------*/
1.64      cvs      1230: void CheckMTable (Element elMTABLE, Document doc, ThotBool placeholder)
1.5       cvs      1231: {
                   1232:   ElementType  elType;
                   1233:   Element      MTableHead, MTableBody, row, nextRow, el, prevRow, cell,
1.103     cvs      1234:                nextCell, newMTD, firstColHead, label;
1.5       cvs      1235:   SSchema      MathMLSSchema;
                   1236: 
                   1237:   MathMLSSchema = GetMathMLSSchema (doc);
                   1238:   row = TtaGetFirstChild (elMTABLE);
                   1239: 
                   1240:   /* create a MTable_head as the first child of element MTABLE */
                   1241:   elType.ElSSchema = MathMLSSchema;
                   1242:   elType.ElTypeNum = MathML_EL_MTable_head;
                   1243:   MTableHead = TtaNewElement (doc, elType);
                   1244:   TtaInsertFirstChild (&MTableHead, elMTABLE, doc);
                   1245:   elType.ElTypeNum = MathML_EL_MColumn_head;
1.47      cvs      1246:   firstColHead = TtaNewTree (doc, elType, "");
1.5       cvs      1247:   TtaInsertFirstChild (&firstColHead, MTableHead, doc);
                   1248: 
                   1249:   /* create a MTable_body */
                   1250:   elType.ElTypeNum = MathML_EL_MTable_body;
                   1251:   MTableBody = TtaNewElement (doc, elType);
                   1252:   TtaInsertSibling (MTableBody, MTableHead, FALSE, doc);
                   1253: 
                   1254:   /* move all children of element MTABLE into the new MTable_body element
1.103     cvs      1255:      and wrap each non-MTR element in a MTR, except comments */
1.5       cvs      1256:   prevRow = NULL;
                   1257:   while (row)
                   1258:     {
                   1259:     nextRow = row;
                   1260:     TtaNextSibling (&nextRow);
                   1261:     elType = TtaGetElementType (row);
                   1262:     TtaRemoveTree (row, doc);
                   1263:     if (TtaSameSSchemas (elType.ElSSchema, MathMLSSchema) &&
                   1264:        (elType.ElTypeNum == MathML_EL_XMLcomment ||
1.101     cvs      1265:         elType.ElTypeNum == MathML_EL_MTR ||
                   1266:          elType.ElTypeNum == MathML_EL_MLABELEDTR))
1.5       cvs      1267:        {
                   1268:        if (prevRow == NULL)
                   1269:          TtaInsertFirstChild (&row, MTableBody, doc);
                   1270:        else
                   1271:          TtaInsertSibling (row, prevRow, FALSE, doc);
                   1272:        prevRow = row;
1.101     cvs      1273:        if (elType.ElTypeNum == MathML_EL_MTR ||
                   1274:           elType.ElTypeNum == MathML_EL_MLABELEDTR)
1.103     cvs      1275:         {
1.5       cvs      1276:           cell = TtaGetFirstChild (row);
1.103     cvs      1277:          if (elType.ElTypeNum == MathML_EL_MLABELEDTR)
                   1278:            /* skip the first significant child of the mlabeledtr element */
                   1279:            {
                   1280:              /* skip comments first */
                   1281:              do
                   1282:                {
                   1283:                  elType = TtaGetElementType (cell);
                   1284:                  if (TtaSameSSchemas (elType.ElSSchema, MathMLSSchema) &&
                   1285:                      elType.ElTypeNum == MathML_EL_XMLcomment)
                   1286:                    TtaNextSibling (&cell);
                   1287:                }
                   1288:              while (cell && elType.ElTypeNum == MathML_EL_XMLcomment);
                   1289:              /* skip the first element after the comments: it's a label */
                   1290:              if (cell)
                   1291:                {
1.105     cvs      1292:                  /* if it's a MTD change its type into LabelCell */
                   1293:                  if (elType.ElTypeNum == MathML_EL_MTD &&
                   1294:                      elType.ElSSchema == MathMLSSchema)
                   1295:                     ChangeElementType (cell, MathML_EL_LabelCell);
1.103     cvs      1296:                  /* wrap this element in a RowLabel element */
1.105     cvs      1297:                  /* This will allow the P schema to specify the horizontal
                   1298:                     position of the label */
1.103     cvs      1299:                  elType.ElSSchema = MathMLSSchema;
                   1300:                  elType.ElTypeNum = MathML_EL_RowLabel;
                   1301:                  label = TtaNewElement (doc, elType);
                   1302:                  TtaInsertSibling (label, cell, TRUE, doc);
                   1303:                  TtaRemoveTree (cell, doc);
                   1304:                  TtaInsertFirstChild (&cell, label, doc);
                   1305:                  cell = label;
                   1306:                  TtaNextSibling (&cell);
                   1307:                }
                   1308:            } 
                   1309:         }
1.5       cvs      1310:        else
                   1311:          cell = NULL;
                   1312:        }
                   1313:     else
1.103     cvs      1314:        /* this child is not a MTR, MLABELEDTR, or a comment.
                   1315:          In MathML 2.0, this in an error, but we try to recover by
                   1316:          creating a MTR element */
1.5       cvs      1317:        {
                   1318:        elType.ElSSchema = MathMLSSchema;
                   1319:        elType.ElTypeNum = MathML_EL_MTR;
                   1320:        el = TtaNewElement (doc, elType);
                   1321:        if (prevRow == NULL)
                   1322:          TtaInsertFirstChild (&el, MTableBody, doc);
                   1323:        else
                   1324:          TtaInsertSibling (el, prevRow, FALSE, doc);
                   1325:        TtaInsertFirstChild (&row, el, doc);
                   1326:        cell = row;
                   1327:        prevRow = el;
                   1328:        }
                   1329:     while (cell)
                   1330:       /* check all children of the current MTR element */
                   1331:       {
                   1332:       nextCell = cell;
                   1333:       TtaNextSibling (&nextCell);
                   1334:       elType = TtaGetElementType (cell);
                   1335:       if (!TtaSameSSchemas (elType.ElSSchema, MathMLSSchema) ||
                   1336:           (elType.ElTypeNum != MathML_EL_XMLcomment &&
                   1337:            elType.ElTypeNum != MathML_EL_MTD))
                   1338:         /* this is not a MTD nor a comment, create a wrapping MTD */
                   1339:          {
                   1340:         elType.ElSSchema = MathMLSSchema;
                   1341:         elType.ElTypeNum = MathML_EL_MTD;
                   1342:         newMTD = TtaNewElement (doc, elType);
                   1343:         TtaInsertSibling (newMTD, cell, TRUE, doc);
                   1344:         TtaRemoveTree (cell, doc);
                   1345:         TtaInsertFirstChild (&cell, newMTD, doc);
                   1346:         cell = newMTD;
                   1347:         }
                   1348:       if (elType.ElTypeNum == MathML_EL_MTD)
                   1349:         /* This is a MTD element. Wrap its contents with a CellWrapper */
1.162     quint    1350:        {
                   1351:          CreateWrapper (cell, MathML_EL_CellWrapper, doc);
                   1352:          SetIntHorizStretchAttr (cell, doc);
                   1353:          SetIntVertStretchAttr (cell, doc, MathML_EL_CellWrapper, NULL);
                   1354:        }
1.5       cvs      1355:       cell = nextCell;
                   1356:       }
                   1357:     row = nextRow;
                   1358:     }
1.107     cvs      1359:   CheckAllRows (elMTABLE, doc, placeholder, FALSE);
1.5       cvs      1360: }
1.12      cvs      1361: 
1.46      cvs      1362: /*----------------------------------------------------------------------
1.1       cvs      1363:    SetFontstyleAttr
                   1364:    The content of a MI element has been created or modified.
                   1365:    Create or change attribute IntFontstyle for that element accordingly.
                   1366:  -----------------------------------------------------------------------*/
                   1367: void SetFontstyleAttr (Element el, Document doc)
                   1368: {
                   1369:   ElementType  elType;
1.157     quint    1370:   AttributeType        attrType, attrType1;
1.1       cvs      1371:   Attribute    attr, IntAttr;
1.157     quint    1372:   Element       ancestor, textEl;
1.1       cvs      1373:   int          len;
1.163     quint    1374:   Language      lang;
                   1375: #ifndef _I18N_
                   1376:   char          script;
                   1377: #endif
                   1378:   char         *value, text[2];
1.54      cvs      1379:   ThotBool      italic;
1.1       cvs      1380: 
                   1381:   if (el != NULL)
1.142     quint    1382:     {
1.157     quint    1383:       /* search the (deprecated) fontstyle attribute or the mathvariant
                   1384:          attribute on the element and its ancestors */
1.142     quint    1385:       elType = TtaGetElementType (el);
                   1386:       attrType.AttrSSchema = elType.ElSSchema;
                   1387:       attrType.AttrTypeNum = MathML_ATTR_fontstyle;
1.157     quint    1388:       attrType1.AttrSSchema = elType.ElSSchema;
                   1389:       attrType1.AttrTypeNum = MathML_ATTR_mathvariant;
                   1390:       ancestor = el;
                   1391:       attr = NULL;
                   1392:       do
                   1393:        {
                   1394:          attr = TtaGetAttribute (ancestor, attrType);
                   1395:          if (!attr)
                   1396:            attr = TtaGetAttribute (ancestor, attrType1);
                   1397:          if (!attr)
                   1398:            {
                   1399:              ancestor = TtaGetParent (ancestor);
                   1400:              if (ancestor)
                   1401:                {
                   1402:                  elType = TtaGetElementType (ancestor);
                   1403:                  if (elType.ElSSchema != attrType.AttrSSchema)
                   1404:                    /* this ancestor is not in the MathML namespace */
                   1405:                    ancestor = NULL;
                   1406:                }
                   1407:            }
                   1408:        }
                   1409:       while (ancestor && !attr);
                   1410: 
1.142     quint    1411:       attrType.AttrTypeNum = MathML_ATTR_IntFontstyle;
                   1412:       IntAttr = TtaGetAttribute (el, attrType);
                   1413:       if (attr != NULL)
1.157     quint    1414:        /* there is a fontstyle or mathvariant attribute. Remove the
                   1415:           IntFontstyle internal attribute that is not needed */
1.1       cvs      1416:        {
1.142     quint    1417:          if (IntAttr != NULL)
                   1418:            TtaRemoveAttribute (el, IntAttr, doc);
1.1       cvs      1419:        }
1.142     quint    1420:       else
1.157     quint    1421:        /* there is no fontstyle or mathvariant attribute. Create an internal
                   1422:           IntFontstyle attribute with a value that depends on the content of
                   1423:           the MI element */
1.1       cvs      1424:        {
1.142     quint    1425:          /* get content length */
                   1426:          len = TtaGetElementVolume (el);
                   1427:          if (len > 1)
                   1428:            /* put an attribute IntFontstyle = IntNormal */
                   1429:            {
                   1430:              if (IntAttr == NULL)
                   1431:                {
                   1432:                  IntAttr = TtaNewAttribute (attrType);
                   1433:                  TtaAttachAttribute (el, IntAttr, doc);
                   1434:                }
                   1435:              TtaSetAttributeValue (IntAttr,
                   1436:                                    MathML_ATTR_IntFontstyle_VAL_IntNormal,
                   1437:                                    el, doc);
                   1438:            }
                   1439:          else
                   1440:            /* MI contains a single character. Remove attribute IntFontstyle
                   1441:               if it exists, except if it's ImaginaryI, ExponentialE or
                   1442:               DifferentialD */
                   1443:            {
                   1444:              italic = TRUE;
                   1445:              textEl = TtaGetFirstChild (el);
                   1446:              if (textEl != NULL)
                   1447:                {
                   1448:                  elType = TtaGetElementType (textEl);
                   1449:                  if (elType.ElTypeNum == MathML_EL_MGLYPH)
                   1450:                    /* the content of the MI element is a MGLYPH element */
                   1451:                    /* check the length if it's alt attribute */
                   1452:                    {
                   1453:                      /* by default, use normal style */
                   1454:                      italic = FALSE;
                   1455:                      attrType.AttrTypeNum = MathML_ATTR_alt;
                   1456:                      attr = TtaGetAttribute (textEl, attrType);
                   1457:                      if (attr)
                   1458:                        /* the MGLYPH element has an alt attribute */
                   1459:                        {
                   1460:                          len = TtaGetTextAttributeLength (attr);
                   1461:                          if (len == 1)
                   1462:                            italic = TRUE;
                   1463:                        }
                   1464:                    }
1.163     quint    1465:                  else if (elType.ElTypeNum == MathML_EL_TEXT_UNIT)
1.142     quint    1466:                    {
1.163     quint    1467:                      /* is there a single digit? */
                   1468:                      len = TtaGetTextLength (textEl);
                   1469:                      if (len == 1)
                   1470:                        {
                   1471:                          len++;
                   1472:                          TtaGiveTextContent (textEl, text, &len, &lang);
                   1473: #ifndef _I18N_
                   1474:                          script = TtaGetScript (lang);
                   1475: #endif
                   1476:                          if (
                   1477: #ifndef _I18N_
                   1478:                              script == 'L' &&
                   1479: #endif
                   1480:                              text[0] >= '0' && text[0] <= '9')
                   1481:                            italic = FALSE;
                   1482:                        }
                   1483: 
1.142     quint    1484:                      /* is there an attribute EntityName on that character? */
                   1485:                      attrType.AttrTypeNum = MathML_ATTR_EntityName;
                   1486:                      attr = TtaGetAttribute (textEl, attrType);
                   1487:                      if (attr)
                   1488:                        {
                   1489:                          len = TtaGetTextAttributeLength (attr);
                   1490:                          if (len > 0)
                   1491:                            {
                   1492:                              value = TtaGetMemory (len+1);
                   1493:                              TtaGiveTextAttributeValue (attr, value, &len);
                   1494:                              if (strcmp (&value[1], "ImaginaryI;") == 0 ||
                   1495:                                  strcmp (&value[1], "ExponentialE;") == 0 ||
                   1496:                                  strcmp (&value[1], "DifferentialD;") == 0)
                   1497:                                italic = FALSE;
                   1498:                              TtaFreeMemory (value);
                   1499:                            }
                   1500:                        }
                   1501:                    }
                   1502:                  if (italic)
                   1503:                    {
                   1504:                      if (IntAttr != NULL)
                   1505:                        TtaRemoveAttribute (el, IntAttr, doc);
                   1506:                    }
                   1507:                  else
                   1508:                    {
                   1509:                      /* put an attribute IntFontstyle = IntNormal */
                   1510:                      if (IntAttr == NULL)
                   1511:                        {
                   1512:                          attrType.AttrTypeNum = MathML_ATTR_IntFontstyle;
                   1513:                          IntAttr = TtaNewAttribute (attrType);
                   1514:                          TtaAttachAttribute (el, IntAttr, doc);
                   1515:                        }
                   1516:                      TtaSetAttributeValue (IntAttr,
                   1517:                                        MathML_ATTR_IntFontstyle_VAL_IntNormal,
                   1518:                                        el, doc);
                   1519:                    }
                   1520:                }
                   1521:            }
1.1       cvs      1522:         }
1.142     quint    1523:     }
1.1       cvs      1524: }
                   1525: 
                   1526: /*----------------------------------------------------------------------
1.22      cvs      1527:    SetIntAddSpaceAttr
1.1       cvs      1528:    The content of a MO element has been created or modified.
1.22      cvs      1529:    Create or change attribute IntAddSpace for that element accordingly.
1.1       cvs      1530:  -----------------------------------------------------------------------*/
1.22      cvs      1531: void SetIntAddSpaceAttr (Element el, Document doc)
1.1       cvs      1532: {
                   1533:   Element      textEl, previous;
                   1534:   ElementType  elType;
                   1535:   AttributeType        attrType;
1.60      cvs      1536:   Attribute    attr, formAttr;
1.155     quint    1537:   SSchema       MathMLSSchema;
1.60      cvs      1538:   int          len, val, form;
1.146     quint    1539:   CHAR_T        text[2];
1.1       cvs      1540:   Language     lang;
1.143     vatton   1541:   char         script;
1.155     quint    1542:   ThotBool      comment;
1.1       cvs      1543: 
1.155     quint    1544:   MathMLSSchema = TtaGetElementType(el).ElSSchema;
1.60      cvs      1545:   /* get the content of the mo element */
1.1       cvs      1546:   textEl = TtaGetFirstChild (el);
1.155     quint    1547: 
                   1548:   /* skip comments if any */
                   1549:   if (textEl)
                   1550:     do
                   1551:       {
                   1552:        elType = TtaGetElementType (textEl);
                   1553:        if (TtaSameSSchemas (elType.ElSSchema, MathMLSSchema) &&
                   1554:            elType.ElTypeNum == MathML_EL_XMLcomment)
                   1555:          /* it's a comment, skip it */
                   1556:          TtaNextSibling (&textEl);
                   1557:       }
                   1558:     while (textEl && elType.ElTypeNum == MathML_EL_XMLcomment);
                   1559: 
                   1560:   if (textEl && elType.ElTypeNum == MathML_EL_TEXT_UNIT)
                   1561:     /* the mo element is not empty */
                   1562:     {
                   1563:       /* does the mo element have an IntAddSpace attribute? */
                   1564:       attrType.AttrSSchema = MathMLSSchema;
                   1565:       attrType.AttrTypeNum = MathML_ATTR_IntAddSpace;
                   1566:       attr = TtaGetAttribute (el, attrType);
                   1567:       if (attr == NULL)
1.60      cvs      1568:         /* no IntAddSpace Attr, create one */
1.1       cvs      1569:        {
1.155     quint    1570:          attr = TtaNewAttribute (attrType);
                   1571:          TtaAttachAttribute (el, attr, doc);
                   1572:        }
                   1573:       /* space on both sides by default */
                   1574:       val = MathML_ATTR_IntAddSpace_VAL_both;
                   1575:       /* does the mo element have a form attribute? */
                   1576:       attrType.AttrTypeNum = MathML_ATTR_form;
                   1577:       formAttr = TtaGetAttribute (el, attrType);
                   1578:       if (formAttr)
                   1579:        /* there is a form attribute */
                   1580:        {
                   1581:          form = TtaGetAttributeValue (formAttr);
                   1582:          switch (form)
                   1583:            {
                   1584:            case MathML_ATTR_form_VAL_prefix:
                   1585:              val = MathML_ATTR_IntAddSpace_VAL_nospace;
                   1586:              break;
                   1587:            case MathML_ATTR_form_VAL_infix:
                   1588:              val = MathML_ATTR_IntAddSpace_VAL_both;
                   1589:              break;
                   1590:            case MathML_ATTR_form_VAL_postfix:
                   1591:              val = MathML_ATTR_IntAddSpace_VAL_spaceafter;
                   1592:              break;
                   1593:            default:
                   1594:              val = MathML_ATTR_IntAddSpace_VAL_both;
                   1595:              break;
                   1596:            } 
1.1       cvs      1597:        }
1.155     quint    1598:       else
                   1599:        /* no form attribute. Analyze the content */
                   1600:        {
                   1601:          len = TtaGetElementVolume (textEl);
                   1602:          if (len == 1)
                   1603:            {
                   1604:              TtaGiveBufferContent (textEl, text, len+1, &lang);
                   1605:              script = TtaGetScript (lang);
                   1606:              /* the mo element contains a single character */
1.146     quint    1607: #ifndef _I18N_
1.155     quint    1608:              if (script == 'L')
                   1609:                /* ISO-Latin 1 character */
                   1610:                {
1.146     quint    1611: #endif
1.155     quint    1612:                  if (text[0] == '-'
1.153     quint    1613: #ifdef _I18N_
1.155     quint    1614:                      || text[0] == 0x2212   /* minus */
1.153     quint    1615: #endif
1.155     quint    1616:                      )
                   1617:                    /* prefix or infix operator? */
                   1618:                    {
                   1619:                      /* skip preceding comments if any */
                   1620:                      previous = el;
                   1621:                      do
                   1622:                        {
                   1623:                          comment = FALSE;
                   1624:                          TtaPreviousSibling (&previous);
                   1625:                          if (previous)
                   1626:                            {
                   1627:                              elType = TtaGetElementType (previous);
                   1628:                              comment = (TtaSameSSchemas (elType.ElSSchema, MathMLSSchema) &&
                   1629:                                         elType.ElTypeNum == MathML_EL_XMLcomment);
                   1630:                            }
                   1631:                        }
                   1632:                      while (previous && comment);
                   1633:                      
                   1634:                      if (previous == NULL)
                   1635:                        /* no previous sibling => prefix operator */
                   1636:                        val = MathML_ATTR_IntAddSpace_VAL_nospace;
                   1637:                      else
                   1638:                        {
                   1639:                          elType = TtaGetElementType (previous);
1.158     quint    1640:                          if (elType.ElTypeNum == MathML_EL_MO ||
                   1641:                              elType.ElTypeNum == MathML_EL_OpeningFence ||
                   1642:                              elType.ElTypeNum == MathML_EL_ClosingFence ||
                   1643:                              elType.ElTypeNum == MathML_EL_FencedSeparator)
1.155     quint    1644:                            /* after an operator => prefix operator */
                   1645:                            val = MathML_ATTR_IntAddSpace_VAL_nospace;
                   1646:                          else
                   1647:                            /* infix operator */
                   1648:                            val = MathML_ATTR_IntAddSpace_VAL_both;
                   1649:                        }
                   1650:                    }
                   1651:                  else if (text[0] == '&' ||
                   1652:                           text[0] == '*' ||
                   1653:                           text[0] == '+' ||
                   1654:                           text[0] == '/' ||
                   1655:                           text[0] == '<' ||
                   1656:                           text[0] == '=' ||
                   1657:                           text[0] == '>' ||
                   1658:                           text[0] == '^' ||
                   1659:                           (int)text[0] == 177 || /* plus or minus */
                   1660:                           (int)text[0] == 215 || /* times */
                   1661:                           (int)text[0] == 247)   /* divide */
                   1662:                    /* infix operator */
                   1663:                    val = MathML_ATTR_IntAddSpace_VAL_both;
                   1664:                  else if (text[0] == ',' ||
                   1665:                           text[0] == '!' ||
                   1666:                           text[0] == '&' ||
                   1667:                           text[0] == ':' ||
                   1668:                           text[0] == ';')
                   1669:                    /* separator */
                   1670:                    val = MathML_ATTR_IntAddSpace_VAL_spaceafter;
                   1671:                  else if (text[0] == '(' ||
                   1672:                           text[0] == ')' ||
                   1673:                           text[0] == '[' ||
                   1674:                           text[0] == ']' ||
                   1675:                           text[0] == '{' ||
                   1676:                           text[0] == '}' ||
                   1677:                           text[0] == '.' ||
                   1678:                           text[0] == '@' ||
1.165   ! quint    1679: #ifndef _I18N_
        !          1680:                           text[0] == 'd' ||       /* probably DifferentialD */
        !          1681: #endif
1.155     quint    1682:                           (int)text[0] == 129 ||  /* thin space */
                   1683:                           (int)text[0] == 130 ||  /* en space */
                   1684:                           (int)text[0] == 160)    /* em space */
                   1685:                    val = MathML_ATTR_IntAddSpace_VAL_nospace;
1.146     quint    1686: #ifndef _I18N_
1.155     quint    1687:                }
                   1688:              else if (script == 'G')
                   1689:                {
                   1690:                  /* Symbol character set */
                   1691:                  if ((int)text[0] == 163 || /* less or equal */
                   1692:                      (int)text[0] == 177 || /* plus or minus */
                   1693:                      (int)text[0] == 179 || /* greater or equal */
                   1694:                      (int)text[0] == 180 || /* times */
                   1695:                      (int)text[0] == 184 || /* divide */
                   1696:                      (int)text[0] == 185 || /* not equal */
                   1697:                      (int)text[0] == 186 || /* identical */
                   1698:                      (int)text[0] == 187 || /* equivalent */
                   1699:                      (int)text[0] == 196 || /* circle times */
                   1700:                      (int)text[0] == 197 || /* circle plus */
                   1701:                      ((int)text[0] >= 199 && (int)text[0] <= 209) || /*  */
                   1702:                      (int)text[0] == 217 || /* and */
                   1703:                      (int)text[0] == 218)   /* or */
1.146     quint    1704: #else
1.155     quint    1705:                    else
                   1706:                      if ((int)text[0] == 0x2264 || /* less or equal */
                   1707:                          (int)text[0] == 0x00B1 || /* plus or minus */
                   1708:                          (int)text[0] == 0x2265 || /* greater or equal */
                   1709:                          (int)text[0] == 0x00D7 || /* times */
                   1710:                          (int)text[0] == 0x00F7 || /* divide */
                   1711:                          (int)text[0] == 0x2260 || /* not equal */
                   1712:                          (int)text[0] == 0x2261 || /* identical */
                   1713:                          (int)text[0] == 0x2248 || /* equivalent */
                   1714:                          (int)text[0] == 0x2297 || /* circle times */
                   1715:                          (int)text[0] == 0x2295 || /* circle plus */
                   1716:                          (int)text[0] == 0x2229 || /* Intersection */
                   1717:                          (int)text[0] == 0x222A || /* Union */
                   1718:                          (int)text[0] == 0x2283 || /* Superset of */
                   1719:                          (int)text[0] == 0x2287 || /* Superset of or equal to */
                   1720:                          (int)text[0] == 0x2284 || /* Not a subset of */
                   1721:                          (int)text[0] == 0x2282 || /* Subset of */
                   1722:                          (int)text[0] == 0x2286 || /* Subset of or equal to */
                   1723:                          (int)text[0] == 0x2208 || /* Element of */
                   1724:                          (int)text[0] == 0x2209 || /* Not an element of */
                   1725:                          (int)text[0] == 0x2220 || /* Angle */
                   1726:                          (int)text[0] == 0x2207 || /* Nabla */
                   1727:                          (int)text[0] == 0x2227 || /* and */
                   1728:                          (int)text[0] == 0x2228 || /* or */
                   1729:                          (int)text[0] == 0x2190 || /* left arrow */
                   1730:                          (int)text[0] == 0x2192 || /* right arrow */
                   1731:                          (int)text[0] == 0x2194)   /* left right arrow */
1.146     quint    1732: #endif
1.155     quint    1733:                        /* infix operator */
                   1734:                        val = MathML_ATTR_IntAddSpace_VAL_both;
                   1735:                      else
                   1736:                        val = MathML_ATTR_IntAddSpace_VAL_nospace;
1.146     quint    1737: #ifndef _I18N_
1.155     quint    1738:                }
1.146     quint    1739: #endif
1.155     quint    1740:            }
                   1741:        }
                   1742:       TtaSetAttributeValue (attr, val, el, doc);
                   1743:     }
1.1       cvs      1744: }
                   1745: 
                   1746: /*----------------------------------------------------------------------
1.58      cvs      1747:    ChildOfMRowOrInferred
                   1748:    Return TRUE if element el is a child of a MROW element or an
                   1749:    inferred MROW element
                   1750:   ----------------------------------------------------------------------*/
                   1751: ThotBool      ChildOfMRowOrInferred (Element el)
                   1752: {
                   1753:    ElementType  elType;
                   1754:    Element       parent;
                   1755:    ThotBool      result;
                   1756: 
                   1757:    result = FALSE;
                   1758:    parent = TtaGetParent (el);
                   1759:    if (parent)
                   1760:       {
                   1761:       elType = TtaGetElementType (parent);
                   1762:       result = (elType.ElTypeNum == MathML_EL_MROW ||
                   1763:                elType.ElTypeNum == MathML_EL_SqrtBase ||
                   1764:                elType.ElTypeNum == MathML_EL_MSTYLE ||
                   1765:                elType.ElTypeNum == MathML_EL_MERROR ||
1.92      cvs      1766:                elType.ElTypeNum == MathML_EL_MENCLOSE ||
1.58      cvs      1767:                elType.ElTypeNum == MathML_EL_MPADDED ||
                   1768:                elType.ElTypeNum == MathML_EL_MPHANTOM ||
1.158     quint    1769:                elType.ElTypeNum == MathML_EL_MFENCED ||
1.58      cvs      1770:                elType.ElTypeNum == MathML_EL_CellWrapper ||
1.92      cvs      1771:                elType.ElTypeNum == MathML_EL_MathML ||
1.58      cvs      1772:                 elType.ElTypeNum == MathML_EL_FencedExpression);
                   1773:       }
                   1774:    return result;   
                   1775: }
                   1776: 
                   1777: /*----------------------------------------------------------------------
1.1       cvs      1778:    CheckFence
1.84      cvs      1779:    If el is a MO element,
                   1780:     - if it's a large operator (&Sum; for instance), put a presentation
                   1781:       rule to enlarge the character.
                   1782:     - if it's a child of a MROW (or equivalent) element and if it contains
                   1783:       a single fence character, transform the MO into a MF and the fence
                   1784:       character into a Thot stretchable symbol.
1.1       cvs      1785:   ----------------------------------------------------------------------*/
1.84      cvs      1786: void      CheckFence (Element el, Document doc)
1.1       cvs      1787: {
1.158     quint    1788:    ElementType        elType, contType;
1.128     vatton   1789:    Element            content;
                   1790:    AttributeType       attrType;
                   1791:    Attribute          attr, attrStretchy;
                   1792:    Language           lang;
1.84      cvs      1793:    PresentationValue   pval;
                   1794:    PresentationContext ctxt;
1.128     vatton   1795:    CHAR_T              text[2];
1.143     vatton   1796:    char                       script;
1.128     vatton   1797:    unsigned char       c;
1.158     quint    1798:    int                 len, val, oldStructureChecking;
1.1       cvs      1799: 
                   1800:    elType = TtaGetElementType (el);
1.158     quint    1801:    if (elType.ElTypeNum == MathML_EL_MO ||
                   1802:        elType.ElTypeNum == MathML_EL_OpeningFence ||
                   1803:        elType.ElTypeNum == MathML_EL_ClosingFence ||
                   1804:        elType.ElTypeNum == MathML_EL_FencedSeparator)
                   1805:      /* the element is a MO or equivalent */
1.58      cvs      1806:      {
1.84      cvs      1807:      content = TtaGetFirstChild (el);
                   1808:      if (content != NULL)
                   1809:        {
1.158     quint    1810:        contType = TtaGetElementType (content);
                   1811:        if (contType.ElTypeNum == MathML_EL_TEXT_UNIT)
1.84      cvs      1812:         {
1.146     quint    1813:         len = TtaGetElementVolume (content);
1.84      cvs      1814:         if (len == 1)
                   1815:           /* the MO element contains a single character */
                   1816:           {
1.146     quint    1817:           TtaGiveBufferContent (content, text, len+1, &lang);
1.143     vatton   1818:           script = TtaGetScript (lang);
1.146     quint    1819: #ifdef _I18N_
                   1820:           if (text[0] == 8721 || text[0] == 8719) /* large Sigma or Pi */
                   1821: #else
1.143     vatton   1822:           if ((script == 'G') &&
1.158     quint    1823:               (text[0] == 229 || text[0] == 213))  /* large Sigma or Pi */
1.146     quint    1824: #endif
1.84      cvs      1825:             /* it's a large operator */
                   1826:             {
                   1827:             ctxt = TtaGetSpecificStyleContext (doc);
                   1828:             ctxt->destroy = FALSE;
                   1829:             /* the specific presentation to be created is not a CSS rule */
1.147     quint    1830:             ctxt->cssSpecificity = 0;
1.84      cvs      1831:             pval.typed_data.unit = STYLE_UNIT_PERCENT;
                   1832:             pval.typed_data.real = FALSE;
                   1833:             pval.typed_data.value = 180;
                   1834:             TtaSetStylePresentation (PRSize, content, NULL, ctxt, pval);
                   1835:             }
                   1836:           else if (ChildOfMRowOrInferred (el))
                   1837:             /* the MO element is a child of a MROW element */
1.1       cvs      1838:              {
1.146     quint    1839:              if ((
                   1840: #ifndef _I18N_
                   1841:                    (script == 'L') &&
                   1842: #endif
1.115     cvs      1843:                   (text[0] == '(' || text[0] == ')' ||
                   1844:                    text[0] == '[' || text[0] == ']' ||
                   1845:                    text[0] == '{' || text[0] == '}' ||
                   1846:                    text[0] == '|'))  ||
1.146     quint    1847:                  (
                   1848:                   /* test left and right angle brackets */
                   1849: #ifdef _I18N_
                   1850:                   (text[0] == 9001 || text[0] == 9002)
                   1851: #else
                   1852:                    (script == 'G') &&
                   1853:                   (text[0] == 225 || text[0] == 241)
                   1854: #endif
                   1855:                 ))
1.84      cvs      1856:                /* it's a stretchable parenthesis or equivalent */
                   1857:                {
                   1858:                /* remove the content of the MO element */
                   1859:                TtaDeleteTree (content, doc);
                   1860:                /* change the MO element into a MF element */
1.158     quint    1861:                if (elType.ElTypeNum == MathML_EL_MO)
                   1862:                   ChangeTypeOfElement (el, doc, MathML_EL_MF);
1.84      cvs      1863:                /* is there an attribute stretchy on this mo element? */
                   1864:                attrType.AttrSSchema = elType.ElSSchema;
                   1865:                attrType.AttrTypeNum = MathML_ATTR_stretchy;
                   1866:                attrStretchy = TtaGetAttribute (el, attrType);
                   1867:                if (attrStretchy)
                   1868:                  val = TtaGetAttributeValue (attrStretchy);
                   1869:                else
                   1870:                  val = MathML_ATTR_stretchy_VAL_true;
                   1871:                if (val == MathML_ATTR_stretchy_VAL_true)
                   1872:                  {
1.158     quint    1873:                  /* attach a IntVertStretch attribute to the MF element */
1.84      cvs      1874:                  attrType.AttrTypeNum = MathML_ATTR_IntVertStretch;
1.158     quint    1875:                  attr = TtaGetAttribute (el, attrType);
                   1876:                  if (!attr)
                   1877:                    {
                   1878:                    attr = TtaNewAttribute (attrType);
                   1879:                    TtaAttachAttribute (el, attr, doc);
                   1880:                    }
1.84      cvs      1881:                  TtaSetAttributeValue (attr,
                   1882:                                        MathML_ATTR_IntVertStretch_VAL_yes_,
                   1883:                                        el, doc);
                   1884:                  }
                   1885:                /* create a new content for the MF element */
1.87      cvs      1886:                elType.ElTypeNum = MathML_EL_SYMBOL_UNIT;
1.146     quint    1887: #ifdef _I18N_
                   1888:                 if (text[0] == 9002)
                   1889: #else
1.143     vatton   1890:                if (script == 'G' && text[0] == 241)
1.146     quint    1891: #endif
1.102     cvs      1892:                  c = '>';    /* RightAngleBracket */
                   1893:                else
1.146     quint    1894: #ifdef _I18N_
                   1895:                   if (text[0] == 9001)
                   1896: #else
                   1897:                  if (script == 'G' && text[0] == 225)
                   1898: #endif
                   1899:                    c = '<';    /* LeftAngleBracket */
                   1900:                  else
                   1901:                    c = (char) text[0];
1.84      cvs      1902:                content = TtaNewElement (doc, elType);
1.158     quint    1903:                /* do not check the Thot abstract tree against the structure
                   1904:                   schema while inserting this child element  */
                   1905:                oldStructureChecking = TtaGetStructureChecking (doc);
                   1906:                TtaSetStructureChecking (0, doc);
1.84      cvs      1907:                TtaInsertFirstChild (&content, el, doc);
                   1908:                TtaSetGraphicsShape (content, c, doc);
1.158     quint    1909:                /* resume structure checking */
                   1910:                TtaSetStructureChecking ((ThotBool)oldStructureChecking, doc);
1.84      cvs      1911:                }
1.1       cvs      1912:              }
1.84      cvs      1913:           }
                   1914:         }
1.58      cvs      1915:        }
                   1916:      }
1.1       cvs      1917: }
                   1918: 
                   1919: /*----------------------------------------------------------------------
                   1920:    CreateFencedSeparators
                   1921:    Create FencedSeparator elements within the fencedExpression
                   1922:    according to attribute separators of the MFENCED element.
                   1923:   ----------------------------------------------------------------------*/
1.110     cvs      1924: void CreateFencedSeparators (Element fencedExpression, Document doc, ThotBool record)
1.1       cvs      1925: {
                   1926:    ElementType  elType;
                   1927:    Element      child, separator, leaf, next, prev, mfenced;
                   1928:    AttributeType attrType;
                   1929:    Attribute     attr;
                   1930:    int          length, sep, i;
                   1931:    Language     lang;
1.116     cvs      1932:    char         text[32], sepValue[4];
1.1       cvs      1933: 
                   1934:    /* get the separators attribute */
                   1935:    mfenced = TtaGetParent (fencedExpression);
                   1936:    elType = TtaGetElementType (fencedExpression);
                   1937:    attrType.AttrSSchema = elType.ElSSchema;
                   1938:    attrType.AttrTypeNum = MathML_ATTR_separators;
                   1939:    text[0] = ',';      /* default value is  sparators=","  */
                   1940:    text[1] = EOS;
                   1941:    length = 1;
                   1942:    attr = TtaGetAttribute (mfenced, attrType);
                   1943:    if (attr != NULL)
                   1944:       {
                   1945:       length = 31;
                   1946:       TtaGiveTextAttributeValue (attr, text, &length);
                   1947:       }
                   1948: 
                   1949:    /* create FencedSeparator elements in the FencedExpression */
                   1950:    prev = NULL;
                   1951:    sep = 0;
                   1952:    /* skip leading spaces in attribute separators */
                   1953:    while (text[sep] <= SPACE && text[sep] != EOS)
                   1954:       sep++;
                   1955:    /* if attribute separators is empty or contains only spaces, do not
                   1956:       insert any separator element */
                   1957:    if (text[sep] != EOS)
                   1958:      {
                   1959:      child = TtaGetFirstChild (fencedExpression);
                   1960:      while (child != NULL)
                   1961:        {
                   1962:        next = child;
                   1963:        TtaNextSibling (&next);
                   1964:        elType = TtaGetElementType (child);
                   1965:        if (elType.ElTypeNum != MathML_EL_Construct)
                   1966:          {
                   1967:          if (prev != NULL)
                   1968:            {
                   1969:            elType.ElTypeNum = MathML_EL_FencedSeparator;
                   1970:            separator = TtaNewElement (doc, elType);
                   1971:            TtaInsertSibling (separator, prev, FALSE, doc);
                   1972:            elType.ElTypeNum = MathML_EL_TEXT_UNIT;
                   1973:            leaf = TtaNewElement (doc, elType);
                   1974:            TtaInsertFirstChild (&leaf, separator, doc);
                   1975:            sepValue[0] = text[sep];
1.158     quint    1976:            sepValue[1] = EOS;
1.143     vatton   1977:           lang = TtaGetLanguageIdFromScript('L');
1.1       cvs      1978:            TtaSetTextContent (leaf, sepValue, lang, doc);
1.158     quint    1979:           SetIntAddSpaceAttr (separator, doc);
                   1980:           SetIntVertStretchAttr (separator, doc, 0, NULL);
                   1981:           CheckFence (separator, doc);
                   1982: 
1.1       cvs      1983:           /* is there a following non-space character in separators? */
                   1984:           i = sep + 1;
                   1985:           while (text[i] <= SPACE && text[i] != EOS)
                   1986:              i++;
                   1987:            if (text[i] > SPACE && text[i] != EOS)
                   1988:               sep = i;
1.17      cvs      1989:           if (record)
                   1990:             TtaRegisterElementCreate (separator, doc);
1.1       cvs      1991:            }
                   1992:          prev = child;
                   1993:          }
                   1994:        child = next;
                   1995:        }
                   1996:      }
                   1997: }
                   1998: 
1.124     cvs      1999: /*----------------------------------------------------------------------
                   2000:    CreateOpeningOrClosingFence
                   2001:    Create the OpeningFence or ClosingFence element (depending on parameter
                   2002:    open) for the MFENCED element el which contain the fencedExpression
                   2003:    element.
                   2004:   ----------------------------------------------------------------------*/
                   2005: static void  CreateOpeningOrClosingFence (Element fencedExpression,
                   2006:                                          Element el, Document doc,
                   2007:                                          ThotBool open)
                   2008: {
                   2009:   ElementType  elType;
                   2010:   Element       leaf, fence;
                   2011:   AttributeType attrType;
                   2012:   Attribute     attr;
                   2013:   int           length;
                   2014:   char          text[32];
                   2015: 
                   2016:   elType = TtaGetElementType (el);
                   2017:   attrType.AttrSSchema = elType.ElSSchema;
                   2018:   if (open)
                   2019:     {
1.158     quint    2020:       text[0] = '(';    /* default value of attribute 'open' */
1.124     cvs      2021:       attrType.AttrTypeNum = MathML_ATTR_open;
                   2022:       elType.ElTypeNum = MathML_EL_OpeningFence;
                   2023:     }
                   2024:   else
                   2025:     {
1.158     quint    2026:       text[0] = ')';    /* default value of attribute 'close' */
1.124     cvs      2027:       attrType.AttrTypeNum = MathML_ATTR_close;
                   2028:       elType.ElTypeNum = MathML_EL_ClosingFence;
                   2029:     }
                   2030:   attr = TtaGetAttribute (el, attrType);
                   2031:   if (attr != NULL)
                   2032:     {
                   2033:       length = 31;
                   2034:       TtaGiveTextAttributeValue (attr, text, &length);
                   2035:       if (length != 1)
                   2036:        /* content of attribute open or close should be a single character */
1.158     quint    2037:        text[0] = '?';
1.124     cvs      2038:     }
1.158     quint    2039:   text[1] = EOS;
1.124     cvs      2040:   fence = TtaNewElement (doc, elType);
                   2041:   TtaInsertSibling (fence, fencedExpression, open, doc);
1.158     quint    2042:   elType.ElTypeNum = MathML_EL_TEXT_UNIT;
1.124     cvs      2043:   leaf = TtaNewElement (doc, elType);
                   2044:   TtaInsertFirstChild (&leaf, fence, doc);
1.158     quint    2045:   TtaSetTextContent (leaf, text, TtaGetLanguageIdFromScript('L'), doc);
                   2046:   SetIntAddSpaceAttr (fence, doc);
                   2047:   SetIntVertStretchAttr (fence, doc, 0, NULL);
                   2048:   CheckFence (fence, doc);
1.124     cvs      2049: }
1.1       cvs      2050: 
                   2051: /*----------------------------------------------------------------------
                   2052:    TransformMFENCED
                   2053:    Transform the content of a MFENCED element: create elements
                   2054:    OpeningFence, FencedExpression, ClosingFence and FencedSeparator.
                   2055:   ----------------------------------------------------------------------*/
1.46      cvs      2056: static void      TransformMFENCED (Element el, Document doc)
1.1       cvs      2057: {
                   2058:    ElementType  elType;
1.124     cvs      2059:    Element      child, fencedExpression, next, prev, firstChild;
1.1       cvs      2060: 
                   2061:    child = TtaGetFirstChild (el);
                   2062:    if (child != NULL)
                   2063:         elType = TtaGetElementType (child);
                   2064:    if (child != NULL && elType.ElTypeNum == MathML_EL_OpeningFence)
                   2065:       /* The first child of this MFENCED element is an OpeningFence.
                   2066:         This MFENCED expression has already been transformed, possibly
                   2067:         by the Transform command */
                   2068:       {
                   2069:       TtaNextSibling (&child);
                   2070:       fencedExpression = child;
                   2071:       if (fencedExpression != NULL)
                   2072:         elType = TtaGetElementType (fencedExpression);
                   2073:       if (elType.ElTypeNum == MathML_EL_FencedExpression)
                   2074:         /* the second child is a FencedExpression. OK.
                   2075:            Remove all existing FencedSeparator elements */
                   2076:         {
                   2077:         child = TtaGetFirstChild (fencedExpression);
                   2078:         prev = NULL;
                   2079:         while (child != NULL)
                   2080:            {
                   2081:            elType = TtaGetElementType (child);
                   2082:            next = child;
                   2083:            TtaNextSibling (&next);
                   2084:            if (elType.ElTypeNum == MathML_EL_FencedSeparator)
                   2085:                /* Remove this separator */
                   2086:                TtaDeleteTree (child, doc);
                   2087:            child = next;
                   2088:            }
                   2089:         /* create FencedSeparator elements in the FencedExpression */
1.17      cvs      2090:         CreateFencedSeparators (fencedExpression, doc, FALSE);
1.1       cvs      2091:         }
                   2092:       }
                   2093:    else
                   2094:       /* this MFENCED element must be transformed */
                   2095:       {
                   2096:       /* create a FencedExpression element as a child of the MFENCED elem. */
                   2097:       elType = TtaGetElementType (el);
                   2098:       elType.ElTypeNum = MathML_EL_FencedExpression;
                   2099:       fencedExpression = TtaNewElement (doc, elType);
                   2100:       TtaInsertFirstChild (&fencedExpression, el, doc);
                   2101:       if (child == NULL)
                   2102:        /* empty MFENCED element */
                   2103:        {
                   2104:         elType.ElTypeNum = MathML_EL_Construct;
                   2105:        child = TtaNewElement (doc, elType);
                   2106:        TtaInsertFirstChild (&child, fencedExpression, doc);
1.22      cvs      2107:        SetIntPlaceholderAttr (child, doc);
1.1       cvs      2108:        }
                   2109:       else
                   2110:        {
                   2111:         /* move the content of the MFENCED element within the new
                   2112:           FencedExpression element */
                   2113:         prev = NULL;
                   2114:        firstChild = NULL;
                   2115:         while (child != NULL)
                   2116:          {
                   2117:          next = child;
                   2118:          TtaNextSibling (&next);
                   2119:          TtaRemoveTree (child, doc);
                   2120:          if (prev == NULL)
                   2121:            {
                   2122:            TtaInsertFirstChild (&child, fencedExpression, doc);
                   2123:            firstChild = child;
                   2124:            }
                   2125:          else
                   2126:            TtaInsertSibling (child, prev, FALSE, doc);
                   2127:          prev = child;
                   2128:          child = next;
                   2129:          }
                   2130: 
                   2131:        /* create FencedSeparator elements in the FencedExpression */
1.17      cvs      2132:        CreateFencedSeparators (fencedExpression, doc, FALSE);
1.1       cvs      2133: 
                   2134:         /* Create placeholders within the FencedExpression element */
                   2135:         CreatePlaceholders (firstChild, doc);
                   2136:        }
                   2137: 
                   2138:       /* create the OpeningFence element according to the open attribute */
1.124     cvs      2139:       CreateOpeningOrClosingFence (fencedExpression, el, doc, TRUE);
1.1       cvs      2140: 
                   2141:       /* create the ClosingFence element according to close attribute */
1.124     cvs      2142:       CreateOpeningOrClosingFence (fencedExpression, el, doc, FALSE);
1.1       cvs      2143:       }
                   2144: }
                   2145: 
                   2146: /*----------------------------------------------------------------------
1.59      cvs      2147:  MathMLScriptShift
                   2148:  The MathML attribute attr (superscriptshift or subscriptshift) is associated
                   2149:  with element el (a msub, msup or msubsup).
                   2150:  If value is not NULL, generate the corresponding Thot VertPos rule for the
                   2151:  Subscript or  Superscript child of el.
                   2152:  If value is NULL, remove the Thot VertPos rule.
                   2153:  -----------------------------------------------------------------------*/
1.120     cvs      2154: void MathMLScriptShift (Document doc, Element el, char *value, int attr)
1.59      cvs      2155: {
                   2156:   ElementType         elType;
                   2157:   Element             script, child;
                   2158:   int                 scrType;
                   2159:   PresentationValue   pval;
                   2160:   PresentationContext ctxt;
                   2161: 
                   2162:   /* get the Superscript or Subscript child of el */
                   2163:   if (attr == MathML_ATTR_superscriptshift)
                   2164:      scrType = MathML_EL_Superscript;
                   2165:   else if (attr == MathML_ATTR_subscriptshift)
                   2166:      scrType = MathML_EL_Subscript;
                   2167:   else
                   2168:      return;
                   2169:   script = NULL;
                   2170:   child = TtaGetFirstChild (el);
                   2171:   while (!script && child)
                   2172:     {
                   2173:     elType = TtaGetElementType (child);
                   2174:     if (elType.ElTypeNum == scrType)
                   2175:        script = child;
                   2176:     else
                   2177:        TtaNextSibling (&child);
                   2178:     }
                   2179:   if (script)
                   2180:     /* Superscript or Subscript element found */
                   2181:     {
                   2182:     ctxt = TtaGetSpecificStyleContext (doc);
                   2183:     if (!value)
                   2184:        /* remove the presentation rule */
                   2185:        {
                   2186:        ctxt->destroy = TRUE;
1.75      cvs      2187:        pval.typed_data.value = 0;
1.59      cvs      2188:        TtaSetStylePresentation (PRVertPos, script, NULL, ctxt, pval);
                   2189:        }
                   2190:     else
                   2191:        {
                   2192:        ctxt->destroy = FALSE;
                   2193:        /* parse the attribute value (a number followed by a unit) */
1.119     cvs      2194:        value = TtaSkipBlanks (value);
1.59      cvs      2195:        value = ParseCSSUnit (value, &pval);
                   2196:        if (pval.typed_data.unit != STYLE_UNIT_INVALID)
                   2197:          {
1.78      cvs      2198:          /* the specific presentation to be created is not a CSS rule */
1.147     quint    2199:          ctxt->cssSpecificity = 0;
1.59      cvs      2200:           if (attr == MathML_ATTR_superscriptshift)
                   2201:            pval.typed_data.value = - pval.typed_data.value;
                   2202:          TtaSetStylePresentation (PRVertPos, script, NULL, ctxt, pval);
                   2203:          }
                   2204:        }
                   2205:     TtaFreeMemory (ctxt);
                   2206:     }
                   2207: }
                   2208: 
                   2209: /*----------------------------------------------------------------------
                   2210:    SetScriptShift
                   2211:    If element el (which is a msup, msub or msubsup) has an attribute
                   2212:    att (which is subscriptshift or superscriptshift), generate the
                   2213:    corresponding Thot presentation rule.
                   2214:   ----------------------------------------------------------------------*/
1.120     cvs      2215: static void SetScriptShift (Element el, Document doc, int att)
1.59      cvs      2216: {
                   2217:    AttributeType     attrType;
                   2218:    ElementType       elType;
                   2219:    Attribute         attr;
1.120     cvs      2220:    char             *value;
1.59      cvs      2221:    int               length;
                   2222: 
                   2223:    elType = TtaGetElementType (el);
                   2224:    attrType.AttrSSchema = elType.ElSSchema;
                   2225:    attrType.AttrTypeNum = att;
                   2226:    attr = TtaGetAttribute (el, attrType);
                   2227:    if (attr)
                   2228:       {
                   2229:       length = TtaGetTextAttributeLength (attr);
                   2230:       if (length > 0)
                   2231:         {
1.116     cvs      2232:         value = TtaGetMemory (length+1);
1.59      cvs      2233:         value[0] = EOS;
                   2234:         TtaGiveTextAttributeValue (attr, value, &length);
                   2235:         MathMLScriptShift (doc, el, value, att);
                   2236:         TtaFreeMemory (value);
                   2237:         }
                   2238:       }
                   2239: }
                   2240: 
                   2241: /*----------------------------------------------------------------------
1.159     quint    2242:  DeleteIntRowAlign
                   2243:  Remove attribute IntRowAlign from element row if there is no rowalign_mtr
                   2244:  attribut on this element.
                   2245:  -----------------------------------------------------------------------*/
                   2246: static void DeleteIntRowAlign (Element row, Document doc)
                   2247: {
                   2248:   ElementType   elType;
                   2249:   AttributeType attrType;
                   2250:   Attribute     attr;
                   2251: 
                   2252:   elType = TtaGetElementType (row);
                   2253:   attrType.AttrSSchema = elType.ElSSchema;
                   2254:   attrType.AttrTypeNum = MathML_ATTR_rowalign_mtr;
                   2255:   attr = TtaGetAttribute (row, attrType);
                   2256:   if (!attr)
                   2257:     {
                   2258:       attrType.AttrTypeNum = MathML_ATTR_IntRowAlign;
                   2259:       attr = TtaGetAttribute (row, attrType);
                   2260:       if (attr)
                   2261:        TtaRemoveAttribute (row, attr, doc);
                   2262:     }
                   2263: }
                   2264: 
                   2265: /*----------------------------------------------------------------------
                   2266:  SetIntRowAlign
                   2267:  Set attribute IntRowAlign for element row unless this element already has
                   2268:  a rowalign_mtr attribute
                   2269:  -----------------------------------------------------------------------*/
                   2270: static void SetIntRowAlign (Element row, int val, Document doc)
                   2271: {
                   2272:   ElementType   elType;
                   2273:   AttributeType attrType;
                   2274:   Attribute     attr;
                   2275: 
                   2276:   elType = TtaGetElementType (row);
                   2277:   attrType.AttrSSchema = elType.ElSSchema;
                   2278:   attrType.AttrTypeNum = MathML_ATTR_rowalign_mtr;
                   2279:   attr = TtaGetAttribute (row, attrType);
                   2280:   if (!attr)
                   2281:     {
                   2282:       attrType.AttrTypeNum = MathML_ATTR_IntRowAlign;
                   2283:       attr = TtaGetAttribute (row, attrType);
                   2284:       if (!attr)
                   2285:        {
                   2286:          attr = TtaNewAttribute (attrType);
                   2287:          TtaAttachAttribute (row, attr, doc);
                   2288:        }
                   2289:       TtaSetAttributeValue (attr, val, row, doc);
                   2290:     }
                   2291: }
                   2292: 
                   2293: /*----------------------------------------------------------------------
                   2294:    HandleRowalignAttribute
                   2295:    An attribute rowalign has been created, updated (if !delete) or deleted
                   2296:    (if delete) for element el in document doc. Update the IntRowAlign
                   2297:    attributes of all enclosed mrow elements accordingly.
                   2298:   ----------------------------------------------------------------------*/
                   2299: void HandleRowalignAttribute (Attribute attr, Element el, Document doc,
                   2300:                              ThotBool delete)
                   2301: {
                   2302:   char            *value;
                   2303:   char            *ptr;
                   2304:   int              length, val;
                   2305:   ElementType      elType;
                   2306:   Element          row;
                   2307: 
                   2308:   elType = TtaGetElementType (el);
                   2309:   if (elType.ElTypeNum != MathML_EL_MTABLE ||
                   2310:       strcmp (TtaGetSSchemaName (elType.ElSSchema), "MathML"))
                   2311:     /* ignore rowalign attribute on mstyle elements */
                   2312:     /* process it only on mtable elements */
                   2313:     return;
                   2314: 
                   2315:   value = NULL;
                   2316:   if (!delete)
                   2317:     {
                   2318:       length = TtaGetTextAttributeLength (attr);
                   2319:       if (length > 0)
                   2320:        {
                   2321:          value = TtaGetMemory (length+1);
                   2322:          value[0] = EOS;
                   2323:          TtaGiveTextAttributeValue (attr, value, &length);
                   2324:        }
                   2325:     }
                   2326:   /* if attribute rowalign is created or updated but has no value, don't
                   2327:      do anything */
                   2328:   if (!delete && !value)
                   2329:     return;
                   2330: 
                   2331:   ptr = value;
                   2332:   val = 0;
                   2333:   elType.ElTypeNum = MathML_EL_TableRow;
                   2334:   row = TtaSearchTypedElement (elType, SearchInTree, el);
                   2335:   while (row)
                   2336:     {
                   2337:     elType = TtaGetElementType (row);
                   2338:     /* skip comments and other non row elements */
                   2339:     if ((elType.ElTypeNum == MathML_EL_MTR ||
                   2340:         elType.ElTypeNum == MathML_EL_MLABELEDTR) &&
                   2341:        strcmp (TtaGetSSchemaName (elType.ElSSchema), "MathML") == 0)
                   2342:       {
                   2343:       if (delete)
                   2344:        DeleteIntRowAlign (row, doc);
                   2345:       else
                   2346:        {
                   2347:          if (*ptr != EOS)
                   2348:            {
                   2349:              /* get next word in the attribute value */
                   2350:              ptr = TtaSkipBlanks (ptr);
                   2351:              /* process that word */
                   2352:              if (*ptr != EOS && *ptr != ' ')
                   2353:                {
                   2354:                  if (!strncasecmp (ptr, "top", 3))
                   2355:                    val = MathML_ATTR_IntRowAlign_VAL_IntTop;
                   2356:                  else if (!strncasecmp (ptr, "bottom", 6))
                   2357:                    val = MathML_ATTR_IntRowAlign_VAL_IntBottom;
                   2358:                  else if (!strncasecmp (ptr, "center", 6))
                   2359:                    val = MathML_ATTR_IntRowAlign_VAL_IntCenter;
                   2360:                  else if (!strncasecmp (ptr, "baseline", 8))
                   2361:                    val = MathML_ATTR_IntRowAlign_VAL_IntBaseline;
                   2362:                  else if (!strncasecmp (ptr, "axis", 4))
                   2363:                    val = MathML_ATTR_IntRowAlign_VAL_IntAxis;
                   2364:                  else
                   2365:                    val = 0;
                   2366:                  /* skip the word that has been processed */
                   2367:                  while (*ptr != EOS && *ptr != ' ')
                   2368:                    ptr++;
                   2369:                }
                   2370:            }
                   2371:          if (val > 0)
                   2372:            SetIntRowAlign (row, val, doc);
                   2373:        }
                   2374:       }
                   2375:     TtaNextSibling (&row);
                   2376:     }
                   2377:   if (value)
                   2378:     TtaFreeMemory (value);
                   2379: }
                   2380: 
                   2381: /*----------------------------------------------------------------------
                   2382:  DeleteIntColAlign
                   2383:  Remove attribute IntColAlign from element cell if there is no columnalign_mtd
                   2384:  attribut on this element.
                   2385:  -----------------------------------------------------------------------*/
                   2386: static void DeleteIntColAlign (Element cell, Document doc)
                   2387: {
                   2388:   ElementType   elType;
                   2389:   AttributeType attrType;
                   2390:   Attribute     attr;
                   2391: 
                   2392:   elType = TtaGetElementType (cell);
                   2393:   attrType.AttrSSchema = elType.ElSSchema;
                   2394:   attrType.AttrTypeNum = MathML_ATTR_columnalign_mtd;
                   2395:   attr = TtaGetAttribute (cell, attrType);
                   2396:   if (!attr)
                   2397:     {
                   2398:       attrType.AttrTypeNum = MathML_ATTR_IntColAlign;
                   2399:       attr = TtaGetAttribute (cell, attrType);
                   2400:       if (attr)
                   2401:        TtaRemoveAttribute (cell, attr, doc);
                   2402:     }
                   2403: }
                   2404: 
                   2405: /*----------------------------------------------------------------------
                   2406:  SetIntColAlign
                   2407:  Set attribute IntColAlign for element cell unless this element already has
                   2408:  a columnalign_mtd attribute
                   2409:  -----------------------------------------------------------------------*/
                   2410: static void SetIntColAlign (Element cell, int val, Document doc)
                   2411: {
                   2412:   ElementType   elType;
                   2413:   AttributeType attrType;
                   2414:   Attribute     attr;
                   2415: 
                   2416:   elType = TtaGetElementType (cell);
                   2417:   attrType.AttrSSchema = elType.ElSSchema;
                   2418:   attrType.AttrTypeNum = MathML_ATTR_columnalign_mtd;
                   2419:   attr = TtaGetAttribute (cell, attrType);
                   2420:   if (!attr)
                   2421:     {
                   2422:       attrType.AttrTypeNum = MathML_ATTR_IntColAlign;
                   2423:       attr = TtaGetAttribute (cell, attrType);
                   2424:       if (!attr)
                   2425:        {
                   2426:          attr = TtaNewAttribute (attrType);
                   2427:          TtaAttachAttribute (cell, attr, doc);
                   2428:        }
                   2429:       TtaSetAttributeValue (attr, val, cell, doc);
                   2430:     }
                   2431: }
                   2432: 
                   2433: /*----------------------------------------------------------------------
                   2434:  RowWithoutColalignAttr
                   2435:  if skip: if element row has a columnalign attribute, get the next sibling row
                   2436:  element without a columnalign attribute and return its first cell
                   2437:  if not skip: always return the first cell in the row, and the columnalign
                   2438:  attribute of that row if there is one.
                   2439:  -----------------------------------------------------------------------*/
                   2440: static void RowWithoutColalignAttr (Element *row, Element *cell,
                   2441:                                    Attribute *attr, ThotBool skip)
                   2442: {
                   2443:   ElementType      elType;
                   2444:   AttributeType    attrType;
                   2445: 
                   2446:   elType = TtaGetElementType (*row);
                   2447:   attrType.AttrSSchema = elType.ElSSchema;
                   2448:   attrType.AttrTypeNum = MathML_ATTR_columnalign;
                   2449:   *cell = NULL;
                   2450:   *attr = NULL;
                   2451:   while (*row != NULL && *cell == NULL)
                   2452:     {
                   2453:       elType = TtaGetElementType (*row);
                   2454:       if ((elType.ElTypeNum != MathML_EL_MTR &&
                   2455:           elType.ElTypeNum != MathML_EL_MLABELEDTR) ||
                   2456:          strcmp (TtaGetSSchemaName (elType.ElSSchema), "MathML"))
                   2457:        /* not a row. Skip it */
                   2458:        TtaNextSibling (row);
                   2459:       else
                   2460:        {
                   2461:          /* skip that row if it has a columnalign attribute */
                   2462:          *attr = TtaGetAttribute (*row, attrType);
                   2463:          if (skip && *attr != NULL)
                   2464:            {
                   2465:            TtaNextSibling (row);
                   2466:            *attr = NULL;
                   2467:            }
                   2468:          else
                   2469:            /* it's a row without a columnalign attribute */
                   2470:            *cell = TtaGetFirstChild (*row);
                   2471:        }
                   2472:     }
                   2473: }
                   2474: 
                   2475: /*----------------------------------------------------------------------
                   2476:    HandleColalignAttribute
                   2477:    An attribute columnalign has been created, updated (if !delete) or deleted
                   2478:    (if delete) for element el in document doc. Update the IntColAlign
                   2479:    attributes of all concerned cells accordingly.
                   2480:    If allRows is TRUE, process also rows that have their own columnalign
                   2481:    attribute, according to that attribute, otherwise skip those rows.
                   2482:   ----------------------------------------------------------------------*/
                   2483: void HandleColalignAttribute (Attribute attr, Element el, Document doc,
                   2484:                              ThotBool delete, ThotBool allRows)
                   2485: {
                   2486:   char            *value, *localValue;
                   2487:   char            *ptr;
                   2488:   int              length, val;
                   2489:   ElementType      elType;
                   2490:   Element          cell, row;
                   2491:   Attribute        localAttr;
                   2492:   ThotBool         fullTable;
                   2493: 
                   2494:   elType = TtaGetElementType (el);
                   2495:   if ((elType.ElTypeNum != MathML_EL_MTABLE &&
                   2496:        elType.ElTypeNum != MathML_EL_MTR &&
                   2497:        elType.ElTypeNum != MathML_EL_MLABELEDTR) ||
                   2498:       strcmp (TtaGetSSchemaName (elType.ElSSchema), "MathML"))
                   2499:     /* ignore columnalign attribute on mstyle elements */
                   2500:     /* process it only on mtable elements */
                   2501:     return;
                   2502: 
                   2503:   fullTable = (elType.ElTypeNum == MathML_EL_MTABLE);
                   2504:   value = NULL;
                   2505:   localValue = NULL;
                   2506:   if (!delete)
                   2507:     {
                   2508:       length = TtaGetTextAttributeLength (attr);
                   2509:       if (length > 0)
                   2510:        {
                   2511:          value = TtaGetMemory (length+1);
                   2512:          value[0] = EOS;
                   2513:          TtaGiveTextAttributeValue (attr, value, &length);
                   2514:        }
                   2515:     }
                   2516:   /* if attribute columnalign is created or updated but has no value, don't
                   2517:      do anything */
                   2518:   if (!delete && !value)
                   2519:     return;
                   2520: 
                   2521:   ptr = value;
                   2522:   val = 0;
                   2523:   /* get the first cell within the element */
                   2524:   elType.ElTypeNum = MathML_EL_MTD;
                   2525:   cell = TtaSearchTypedElement (elType, SearchInTree, el);
                   2526:   if (cell && fullTable)
                   2527:     {
                   2528:     elType.ElTypeNum = MathML_EL_TableRow;
                   2529:     row = TtaGetTypedAncestor (cell, elType);
                   2530:     RowWithoutColalignAttr (&row, &cell, &localAttr, !allRows);
                   2531:     if (localAttr)
                   2532:       {
                   2533:        length = TtaGetTextAttributeLength (localAttr);
                   2534:        if (length > 0)
                   2535:          {
                   2536:            if (localValue)
                   2537:              TtaFreeMemory (localValue);
                   2538:            localValue = TtaGetMemory (length+1);
                   2539:            localValue[0] = EOS;
                   2540:            TtaGiveTextAttributeValue (localAttr, localValue, &length);
                   2541:            ptr = localValue;
                   2542:          }
                   2543:       }
                   2544:     }
                   2545:   while (cell)
                   2546:     {
                   2547:     elType = TtaGetElementType (cell);
                   2548:     /* skip comments and other non cell elements */
                   2549:     if (elType.ElTypeNum == MathML_EL_MTD &&
                   2550:        strcmp (TtaGetSSchemaName (elType.ElSSchema), "MathML") == 0)
                   2551:       {
                   2552:         if (delete)
                   2553:          DeleteIntColAlign (cell, doc);
                   2554:         else
                   2555:          {
                   2556:          if (*ptr != EOS)
                   2557:            {
                   2558:              /* get next word in the attribute value */
                   2559:              ptr = TtaSkipBlanks (ptr);
                   2560:              /* process that word */
                   2561:              if (*ptr != EOS && *ptr != ' ')
                   2562:                {
                   2563:                  if (!strncasecmp (ptr, "left", 4))
                   2564:                    val = MathML_ATTR_IntColAlign_VAL_IntLeft;
                   2565:                  else if (!strncasecmp (ptr, "center", 6))
                   2566:                    val = MathML_ATTR_IntColAlign_VAL_IntCenter;
                   2567:                  else if (!strncasecmp (ptr, "right", 5))
                   2568:                    val = MathML_ATTR_IntColAlign_VAL_IntRight;
                   2569:                  else
                   2570:                    val = 0;
                   2571:                  /* skip the word that has been processed */
                   2572:                  while (*ptr != EOS && *ptr != ' ')
                   2573:                    ptr++;
                   2574:                }
                   2575:            }
                   2576:          if (val > 0)
                   2577:            SetIntColAlign (cell, val, doc);
                   2578:          }
                   2579:       }
                   2580:     TtaNextSibling (&cell);
                   2581:     if (!cell && fullTable && row)
                   2582:       /* no more sibling cell. If the columnalign attribute is for the
                   2583:          full table, get the first cell in the next row */
                   2584:       {
                   2585:       TtaNextSibling (&row);
                   2586:       if (row)
                   2587:        {
                   2588:          /* parse value of columnalign attribute again from the beginning */
                   2589:          ptr = value;
                   2590:          RowWithoutColalignAttr (&row, &cell, &localAttr, !allRows);
                   2591:          if (localAttr)
                   2592:            {
                   2593:              length = TtaGetTextAttributeLength (localAttr);
                   2594:              if (length > 0)
                   2595:                {
                   2596:                  if (localValue)
                   2597:                    TtaFreeMemory (localValue);
                   2598:                  localValue = TtaGetMemory (length+1);
                   2599:                  localValue[0] = EOS;
                   2600:                  TtaGiveTextAttributeValue (localAttr, localValue, &length);
                   2601:                  ptr = localValue;
                   2602:                }
                   2603:            }
                   2604:        }
                   2605:       }
                   2606:     }
                   2607:   if (value)
                   2608:     TtaFreeMemory (value);
                   2609:   if (localValue)
                   2610:     TtaFreeMemory (localValue);
                   2611: }
                   2612: 
                   2613: /*----------------------------------------------------------------------
                   2614:    HandleRowlinesAttribute
                   2615:    An attribute rowlines has been created, updated or deleted (if delete
                   2616:    is TRUE) for element el in document doc. Update attribute MLineBelow
                   2617:    of all cells accordingly.
                   2618:   ----------------------------------------------------------------------*/
                   2619: void HandleRowlinesAttribute (Attribute attr, Element el, Document doc,
                   2620:                              ThotBool delete)
                   2621: {
                   2622:   char            *value;
1.160     quint    2623:   char            *ptr, *spanPtr;
                   2624:   int              length, val, rowspan, i, cellVal;
1.159     quint    2625:   ElementType      elType, rowType, cellType;
                   2626:   Element          row, nextRow, cell;
                   2627:   ThotBool         stop;
1.160     quint    2628:   AttributeType    attrType, rowspanType;
                   2629:   Attribute        intAttr, rowspanAttr;
1.159     quint    2630: 
                   2631:   elType = TtaGetElementType (el);
                   2632:   if (elType.ElTypeNum != MathML_EL_MTABLE ||
                   2633:       strcmp (TtaGetSSchemaName (elType.ElSSchema), "MathML"))
                   2634:     /* ignore rowlines attribute on mstyle elements */
                   2635:     /* process it only on mtable elements */
                   2636:     return;
                   2637: 
                   2638:   value = NULL;
                   2639:   if (!delete)
                   2640:     {
                   2641:       length = TtaGetTextAttributeLength (attr);
                   2642:       if (length > 0)
                   2643:        {
                   2644:          value = TtaGetMemory (length+1);
                   2645:          value[0] = EOS;
                   2646:          TtaGiveTextAttributeValue (attr, value, &length);
                   2647:        }
                   2648:     }
                   2649:   /* if attribute rowlines is created or updated but has no value, don't
                   2650:      do anything */
                   2651:   if (!delete && !value)
                   2652:     return;
                   2653: 
                   2654:   ptr = value;
                   2655:   val = 0;
                   2656:   attrType.AttrSSchema = elType.ElSSchema;
1.160     quint    2657:   rowspanType.AttrSSchema = elType.ElSSchema;
                   2658:   rowspanType.AttrTypeNum = MathML_ATTR_rowspan_;
1.159     quint    2659: 
                   2660:   /* check all rows within the table */
                   2661:   elType.ElTypeNum = MathML_EL_TableRow;
                   2662:   row = TtaSearchTypedElement (elType, SearchInTree, el);
                   2663:   while (row)
                   2664:     {
                   2665:       /* get the next row to check if the current row is the last one */
                   2666:       nextRow = row;
                   2667:       stop = FALSE;
                   2668:       do
                   2669:        {
                   2670:          TtaNextSibling (&nextRow);
                   2671:          if (!nextRow)
                   2672:            stop = TRUE;
                   2673:          else
                   2674:            {
                   2675:              rowType = TtaGetElementType (nextRow);
                   2676:              /* skip comments and other non mrow elements */
                   2677:              if ((rowType.ElTypeNum == MathML_EL_MTR ||
                   2678:                   rowType.ElTypeNum == MathML_EL_MLABELEDTR) &&
                   2679:                  !strcmp (TtaGetSSchemaName (rowType.ElSSchema), "MathML"))
                   2680:                /* it's the next mrow */
                   2681:                stop = TRUE;
                   2682:            }
                   2683:        }
                   2684:       while (!stop);
                   2685: 
                   2686:       if (!nextRow)
                   2687:        /* row is the last in the table. It must not have a line
                   2688:           at the bottom. Delete it if there is one */
                   2689:        val = 0;
                   2690:       else
                   2691:        {
                   2692:          if (delete)
                   2693:            val = 0;
                   2694:          else
                   2695:            if (*ptr != EOS)
                   2696:              {
                   2697:                /* get next word in the attribute value */
                   2698:                ptr = TtaSkipBlanks (ptr);
                   2699:                /* process that word */
                   2700:                if (*ptr != EOS && *ptr != ' ')
                   2701:                  {
                   2702:                    if (!strncasecmp (ptr, "none", 4))
                   2703:                      val = 0;
                   2704:                    else if (!strncasecmp (ptr, "solid", 5))
                   2705:                      val = MathML_ATTR_MLineBelow_VAL_solid_;
                   2706:                    else if (!strncasecmp (ptr, "dashed", 6))
                   2707:                      val = MathML_ATTR_MLineBelow_VAL_dashed_;
                   2708:                    else
                   2709:                      val = 0;
                   2710:                    /* skip the word that has been processed */
                   2711:                    while (*ptr != EOS && *ptr != ' ')
                   2712:                      ptr++;
                   2713:                  }
                   2714:              }
                   2715:        }
                   2716:       /* get the first cell of that row (ignoring Label cells) */
                   2717:       elType.ElTypeNum = MathML_EL_MTD;
                   2718:       cell = TtaSearchTypedElement (elType, SearchInTree, row);
                   2719:       /* update attribute MLineBelow for all cells in that row */
                   2720:       while (cell)
                   2721:        {
                   2722:          cellType = TtaGetElementType (cell);
                   2723:          /* skip comments and other non mtd elements */
                   2724:          if (cellType.ElTypeNum == MathML_EL_MTD &&
                   2725:              !strcmp (TtaGetSSchemaName (cellType.ElSSchema), "MathML"))
                   2726:            /* that's a mtd element. Process it */
                   2727:            {
1.160     quint    2728:              /* is there a rowspan attribute on that cell? */
                   2729:              rowspanAttr = TtaGetAttribute (cell, rowspanType);
                   2730:              if (!rowspanAttr)
                   2731:                rowspan = 1;
                   2732:              else
                   2733:                rowspan = TtaGetAttributeValue (rowspanAttr);
1.161     quint    2734:              /* by default, use the value for the current row */
                   2735:              cellVal = val;
                   2736:              if (!delete)
1.160     quint    2737:                {
1.161     quint    2738:                  /* skip rowspan-1 words in the value of attribute rowlines */
                   2739:                  if (rowspan > 1)
1.160     quint    2740:                    {
1.161     quint    2741:                      spanPtr = ptr;
                   2742:                      for (i = 1; i < rowspan && *spanPtr != EOS; i++)
1.160     quint    2743:                        {
1.161     quint    2744:                          spanPtr = TtaSkipBlanks (spanPtr);
                   2745:                          if (*spanPtr != EOS && *spanPtr != ' ')
                   2746:                            {
                   2747:                              if (!strncasecmp (spanPtr, "none", 4))
                   2748:                                cellVal = 0;
                   2749:                              else if (!strncasecmp (spanPtr, "solid", 5))
                   2750:                                cellVal = MathML_ATTR_MLineBelow_VAL_solid_;
                   2751:                              else if (!strncasecmp (spanPtr, "dashed", 6))
                   2752:                                cellVal = MathML_ATTR_MLineBelow_VAL_dashed_;
                   2753:                              else
                   2754:                                cellVal = 0;
                   2755:                            }
                   2756:                          /* skip the word that has been processed */
                   2757:                          while (*spanPtr != EOS && *spanPtr != ' ')
                   2758:                            spanPtr++;
1.160     quint    2759:                        }
                   2760:                    }
                   2761:                }
1.161     quint    2762:              if (rowspan == 1)
                   2763:                attrType.AttrTypeNum = MathML_ATTR_MLineBelow;
                   2764:              else
                   2765:                attrType.AttrTypeNum = MathML_ATTR_MLineBelowExt;
1.159     quint    2766:              intAttr = TtaGetAttribute (cell, attrType);
1.160     quint    2767:              if (cellVal == 0)
1.159     quint    2768:                {
                   2769:                  if (intAttr)
                   2770:                    /* remove attribute MLineBelow */
                   2771:                    TtaRemoveAttribute (cell, intAttr, doc);
                   2772:                }
                   2773:              else
                   2774:                /* set attribute MLineBelow */
                   2775:                {
                   2776:                  if (!intAttr)
                   2777:                    {
                   2778:                      intAttr = TtaNewAttribute (attrType);
                   2779:                      TtaAttachAttribute (cell, intAttr, doc);
                   2780:                    }
1.160     quint    2781:                  TtaSetAttributeValue (intAttr, cellVal, cell, doc);
1.159     quint    2782:                }
                   2783:            }
                   2784:          TtaNextSibling (&cell);
                   2785:        }
                   2786:       row = nextRow;
                   2787:     }
                   2788:   if (value)
                   2789:     TtaFreeMemory (value);
                   2790: }
                   2791: 
                   2792: /*----------------------------------------------------------------------
                   2793:    HandleColumnlinesAttribute
                   2794:    An attribute columnlines has been created, updated or deleted (if delete
                   2795:    is TRUE) for element el in document doc. Update attribute MLineOnTheRight
                   2796:    of all cells accordingly.
                   2797:   ----------------------------------------------------------------------*/
                   2798: void HandleColumnlinesAttribute (Attribute attr, Element el, Document doc,
                   2799:                                 ThotBool delete)
                   2800: {
                   2801:   char            *value;
                   2802:   char            *ptr;
1.161     quint    2803:   int              length, val, colspan, rowspan, i;
1.159     quint    2804:   ElementType      elType;
                   2805:   Element          row, cell, nextCell;
                   2806:   ThotBool         stop;
1.161     quint    2807:   AttributeType    attrType, colspanType, rowspanType;
                   2808:   Attribute        intAttr, spanAttr;
1.159     quint    2809: 
                   2810:   elType = TtaGetElementType (el);
                   2811:   if (elType.ElTypeNum != MathML_EL_MTABLE ||
                   2812:       strcmp (TtaGetSSchemaName (elType.ElSSchema), "MathML"))
                   2813:     /* ignore rowlines attribute on mstyle elements */
                   2814:     /* process it only on mtable elements */
                   2815:     return;
                   2816: 
                   2817:   value = NULL;
                   2818:   if (!delete)
                   2819:     {
                   2820:       length = TtaGetTextAttributeLength (attr);
                   2821:       if (length > 0)
                   2822:        {
                   2823:          value = TtaGetMemory (length+1);
                   2824:          value[0] = EOS;
                   2825:          TtaGiveTextAttributeValue (attr, value, &length);
                   2826:        }
                   2827:     }
                   2828:   /* if attribute columnlines is created or updated but has no value, don't
                   2829:      do anything */
                   2830:   if (!delete && !value)
                   2831:     return;
                   2832: 
                   2833:   val = 0;
                   2834:   attrType.AttrSSchema = elType.ElSSchema;
1.160     quint    2835:   colspanType.AttrSSchema = elType.ElSSchema;
                   2836:   colspanType.AttrTypeNum = MathML_ATTR_columnspan;
1.161     quint    2837:   rowspanType.AttrSSchema = elType.ElSSchema;
                   2838:   rowspanType.AttrTypeNum = MathML_ATTR_rowspan_;
1.159     quint    2839: 
                   2840:   /* check all cells in all rows in the table */
                   2841:   elType.ElTypeNum = MathML_EL_TableRow;
                   2842:   row = TtaSearchTypedElement (elType, SearchInTree, el);
                   2843:   while (row)
                   2844:     {
                   2845:       elType = TtaGetElementType (row);
                   2846:       if ((elType.ElTypeNum == MathML_EL_MTR ||
                   2847:           elType.ElTypeNum == MathML_EL_MLABELEDTR) &&
                   2848:          strcmp (TtaGetSSchemaName (elType.ElSSchema), "MathML") == 0)
                   2849:        /* that's a table row. check all its cells */
                   2850:        {
                   2851:          /* start from the beginning of the columnlines attribute */
                   2852:          ptr = value;
                   2853:          val = 0;
                   2854:          /* get the first cell of that row (ignoring Label cells) */
                   2855:          elType.ElTypeNum = MathML_EL_MTD;
                   2856:          cell = TtaSearchTypedElement (elType, SearchInTree, row);
                   2857:          while (cell)
                   2858:            {
                   2859:              /* get the next cell in the current row to check if the current
                   2860:                 cell is the last one in the row */
                   2861:              nextCell = cell;
                   2862:              stop = FALSE;
                   2863:              do
                   2864:                {
                   2865:                  TtaNextSibling (&nextCell);
                   2866:                  if (!nextCell)
                   2867:                    stop = TRUE;
                   2868:                  else
                   2869:                    {
                   2870:                      elType = TtaGetElementType (nextCell);
                   2871:                      /* skip comments and other non mtd elements */
                   2872:                      if (elType.ElTypeNum == MathML_EL_MTD &&
                   2873:                          strcmp (TtaGetSSchemaName (elType.ElSSchema), "MathML") == 0)
                   2874:                        /* it's the next cell */
                   2875:                        stop = TRUE;
                   2876:                    }
                   2877:                }
                   2878:              while (!stop);
                   2879: 
1.161     quint    2880:              /* is there a rowspan attribute on that cell? */
                   2881:              spanAttr = TtaGetAttribute (cell, rowspanType);
                   2882:              if (!spanAttr)
                   2883:                rowspan = 1;
                   2884:              else
                   2885:                rowspan = TtaGetAttributeValue (spanAttr);
                   2886: 
1.159     quint    2887:              if (!nextCell)
                   2888:                /* it's the last cell in the row. It must not have a line
                   2889:                   on its right edge. Delete it if there is noe. */
                   2890:                val = 0;
                   2891:              else
                   2892:                /* set the attribute MLineOnTheRight for this cell */
                   2893:                {
                   2894:                  if (delete)
                   2895:                    val = 0;
                   2896:                  else
                   2897:                    if (*ptr != EOS)
                   2898:                      {
1.161     quint    2899:                        /* is there a columnspan attribute on that cell? */
                   2900:                        spanAttr = TtaGetAttribute (cell, colspanType);
                   2901:                        if (!spanAttr)
1.160     quint    2902:                          colspan = 1;
                   2903:                        else
1.161     quint    2904:                          colspan = TtaGetAttributeValue (spanAttr);
1.160     quint    2905:                        /* skip (colspan - 1) words in the attribute */
                   2906:                        for (i = 1; i <= colspan && *ptr != EOS; i++)
1.159     quint    2907:                          {
1.160     quint    2908:                            /* get next word in the attribute value */
                   2909:                            ptr = TtaSkipBlanks (ptr);
                   2910:                            /* process that word */
                   2911:                            if (*ptr != EOS && *ptr != ' ')
                   2912:                              {
                   2913:                                if (!strncasecmp (ptr, "none", 4))
                   2914:                                  val = 0;
                   2915:                                else if (!strncasecmp (ptr, "solid", 5))
                   2916:                                  val = MathML_ATTR_MLineOnTheRight_VAL_solid_;
                   2917:                                else if (!strncasecmp (ptr, "dashed", 6))
                   2918:                                  val = MathML_ATTR_MLineOnTheRight_VAL_dashed_;
                   2919:                                else
                   2920:                                  val = 0;
                   2921:                                /* skip the word that has been processed */
                   2922:                                while (*ptr != EOS && *ptr != ' ')
                   2923:                                  ptr++;
                   2924:                              }
1.159     quint    2925:                          }
                   2926:                      }
                   2927:                }
1.161     quint    2928:              if (rowspan == 1)
                   2929:                attrType.AttrTypeNum = MathML_ATTR_MLineOnTheRight;
                   2930:              else
                   2931:                attrType.AttrTypeNum = MathML_ATTR_MLineOnTheRightExt;
1.159     quint    2932:              intAttr = TtaGetAttribute (cell, attrType);
                   2933:              if (val == 0)
                   2934:                {
                   2935:                  if (intAttr)
                   2936:                    /* remove attribute MLineOnTheRight */
                   2937:                    TtaRemoveAttribute (cell, intAttr, doc);
                   2938:                }
                   2939:              else
                   2940:                /* set attribute MLineOnTheRight */
                   2941:                {
                   2942:                  if (!intAttr)
                   2943:                    {
                   2944:                      intAttr = TtaNewAttribute (attrType);
                   2945:                      TtaAttachAttribute (cell, intAttr, doc);
                   2946:                    }
                   2947:                  TtaSetAttributeValue (intAttr, val, cell, doc);
                   2948:                }
                   2949:              cell = nextCell;
                   2950:            }
                   2951:        }
                   2952:       TtaNextSibling (&row);
                   2953:     }
                   2954:   if (value)
                   2955:     TtaFreeMemory (value);
                   2956: }
                   2957: 
                   2958: /*----------------------------------------------------------------------
1.1       cvs      2959:    MathMLElementComplete
                   2960:    Check the Thot structure of the MathML element el.
                   2961:   ----------------------------------------------------------------------*/
1.156     cvs      2962: void      MathMLElementComplete (ParserData *context, Element el, int *error)
1.1       cvs      2963: {
1.156     cvs      2964:    Document             doc;   
1.74      cvs      2965:    ElementType         elType, parentType;
1.1       cvs      2966:    Element             child, parent, new, prev, next;
1.101     cvs      2967:    AttributeType        attrType;
                   2968:    Attribute            attr;
1.56      cvs      2969:    SSchema              MathMLSSchema;
                   2970:    ThotBool             ok;
1.1       cvs      2971: 
1.56      cvs      2972:    ok = TRUE;
                   2973:    *error = 0;
1.156     cvs      2974:    doc = context->doc;
1.1       cvs      2975:    elType = TtaGetElementType (el);
1.2       cvs      2976:    MathMLSSchema = GetMathMLSSchema (doc);
1.1       cvs      2977: 
1.76      cvs      2978:    if (elType.ElSSchema == MathMLSSchema)
1.1       cvs      2979:      {
                   2980:      switch (elType.ElTypeNum)
                   2981:        {
1.76      cvs      2982:        case MathML_EL_MathML:
                   2983:          /* Create placeholders within the MathML element */
                   2984:          CreatePlaceholders (TtaGetFirstChild (el), doc);
1.132     cvs      2985:          break;
1.1       cvs      2986:        case MathML_EL_MI:
                   2987:          SetFontstyleAttr (el, doc);
                   2988:          break;
                   2989:        case MathML_EL_MO:
1.22      cvs      2990:          SetIntAddSpaceAttr (el, doc);
                   2991:          SetIntVertStretchAttr (el, doc, 0, NULL);
1.58      cvs      2992:          /* if the MO element is a child of a MROW (or equivalent) and if it
                   2993:             contains a fence character, transform this MO into MF and
                   2994:             transform the fence character into a Thot SYMBOL */
                   2995:          CheckFence (el, doc);
1.1       cvs      2996:          break;
1.60      cvs      2997:        case MathML_EL_MSPACE:
                   2998:          break;
1.39      cvs      2999:        case MathML_EL_MROW:
1.55      cvs      3000:          /* Create placeholders within the MROW */
                   3001:           CreatePlaceholders (TtaGetFirstChild (el), doc);
1.39      cvs      3002:          break;
                   3003:        case MathML_EL_MFRAC:
1.54      cvs      3004:        case MathML_EL_BevelledMFRAC:
1.39      cvs      3005:          /* end of a fraction. Create a Numerator and a Denominator */
1.56      cvs      3006:          ok = CheckMathSubExpressions (el, MathML_EL_Numerator,
                   3007:                                        MathML_EL_Denominator, 0, doc);
1.39      cvs      3008:          break;
                   3009:        case MathML_EL_MSQRT:
1.50      cvs      3010:          /* end of a Square Root */
                   3011:          /* Create placeholders within the element */
                   3012:           CreatePlaceholders (TtaGetFirstChild (el), doc);
                   3013:          /* Create a SqrtBase that contains all children of the MSQRT */
1.39      cvs      3014:          CreateWrapper (el, MathML_EL_SqrtBase, doc);
                   3015:          break;
1.1       cvs      3016:        case MathML_EL_MROOT:
                   3017:          /* end of a Root. Create a RootBase and an Index */
1.56      cvs      3018:          ok = CheckMathSubExpressions (el, MathML_EL_RootBase,
                   3019:                                        MathML_EL_Index, 0, doc);
1.1       cvs      3020:          break;
1.50      cvs      3021:        case MathML_EL_MENCLOSE:
                   3022:          /* Create placeholders within the element */
                   3023:           CreatePlaceholders (TtaGetFirstChild (el), doc);
                   3024:          break;
1.39      cvs      3025:        case MathML_EL_MSTYLE:
                   3026:        case MathML_EL_MERROR:
                   3027:        case MathML_EL_MPADDED:
                   3028:        case MathML_EL_MPHANTOM:
                   3029:          /* Create placeholders within the element */
                   3030:           CreatePlaceholders (TtaGetFirstChild (el), doc);
1.1       cvs      3031:          break;
                   3032:        case MathML_EL_MFENCED:
                   3033:          TransformMFENCED (el, doc);
                   3034:          break;
                   3035:        case MathML_EL_MSUB:
                   3036:          /* end of a MSUB. Create Base and Subscript */
1.56      cvs      3037:          ok = CheckMathSubExpressions (el, MathML_EL_Base,
                   3038:                                        MathML_EL_Subscript, 0, doc);
1.59      cvs      3039:          SetScriptShift (el, doc, MathML_ATTR_subscriptshift);
1.22      cvs      3040:          SetIntVertStretchAttr (el, doc, MathML_EL_Base, NULL);
1.1       cvs      3041:          break;
                   3042:        case MathML_EL_MSUP:
                   3043:          /* end of a MSUP. Create Base and Superscript */
1.56      cvs      3044:          ok = CheckMathSubExpressions (el, MathML_EL_Base,
                   3045:                                        MathML_EL_Superscript, 0, doc);
1.59      cvs      3046:          SetScriptShift (el, doc, MathML_ATTR_superscriptshift);
1.22      cvs      3047:          SetIntVertStretchAttr (el, doc, MathML_EL_Base, NULL);
1.1       cvs      3048:          break;
1.39      cvs      3049:        case MathML_EL_MSUBSUP:
                   3050:          /* end of a MSUBSUP. Create Base, Subscript, and Superscript */
1.56      cvs      3051:          ok = CheckMathSubExpressions (el, MathML_EL_Base,
                   3052:                                        MathML_EL_Subscript,
                   3053:                                        MathML_EL_Superscript, doc);
1.59      cvs      3054:          SetScriptShift (el, doc, MathML_ATTR_subscriptshift);
                   3055:          SetScriptShift (el, doc, MathML_ATTR_superscriptshift);
1.39      cvs      3056:          SetIntVertStretchAttr (el, doc, MathML_EL_Base, NULL);
1.1       cvs      3057:          break;
                   3058:        case MathML_EL_MUNDER:
                   3059:          /* end of a MUNDER. Create UnderOverBase, and Underscript */
1.56      cvs      3060:          ok = CheckMathSubExpressions (el, MathML_EL_UnderOverBase,
                   3061:                                        MathML_EL_Underscript, 0, doc);
1.22      cvs      3062:          SetIntHorizStretchAttr (el, doc);
                   3063:          SetIntVertStretchAttr (el, doc, MathML_EL_UnderOverBase, NULL);
1.1       cvs      3064:          break;
                   3065:        case MathML_EL_MOVER:
                   3066:          /* end of a MOVER. Create UnderOverBase, and Overscript */
1.56      cvs      3067:          ok = CheckMathSubExpressions (el, MathML_EL_UnderOverBase,
                   3068:                                        MathML_EL_Overscript, 0, doc);
1.22      cvs      3069:          SetIntHorizStretchAttr (el, doc);
                   3070:          SetIntVertStretchAttr (el, doc, MathML_EL_UnderOverBase, NULL);
1.1       cvs      3071:          break;
1.39      cvs      3072:        case MathML_EL_MUNDEROVER:
                   3073:          /* end of a MUNDEROVER. Create UnderOverBase, Underscript, and
                   3074:             Overscript */
1.56      cvs      3075:          ok = CheckMathSubExpressions (el, MathML_EL_UnderOverBase,
                   3076:                                        MathML_EL_Underscript,
                   3077:                                        MathML_EL_Overscript, doc);
1.39      cvs      3078:          SetIntHorizStretchAttr (el, doc);
                   3079:          SetIntVertStretchAttr (el, doc, MathML_EL_UnderOverBase, NULL);
                   3080:          break;
1.1       cvs      3081:        case MathML_EL_MMULTISCRIPTS:
                   3082:          /* end of a MMULTISCRIPTS. Create all elements defined in the
                   3083:             MathML S schema */
                   3084:          BuildMultiscript (el, doc);
1.5       cvs      3085:          break;
                   3086:        case MathML_EL_MTABLE:
                   3087:          /* end of a MTABLE. Create all elements defined in the MathML S
                   3088:              schema */
1.64      cvs      3089:          CheckMTable (el, doc, TRUE);
1.101     cvs      3090:          /* if the table has a rowalign attribute, process it */
                   3091:           attrType.AttrSSchema = MathMLSSchema;
                   3092:           attrType.AttrTypeNum = MathML_ATTR_rowalign;
                   3093:          attr = TtaGetAttribute (el, attrType);
                   3094:          if (attr)
                   3095:             HandleRowalignAttribute (attr, el, doc, FALSE);
                   3096:          /* if the table has a columnalign attribute, process it */
                   3097:           attrType.AttrTypeNum = MathML_ATTR_columnalign;
                   3098:          attr = TtaGetAttribute (el, attrType);
                   3099:          if (attr)
1.108     cvs      3100:             HandleColalignAttribute (attr, el, doc, FALSE, FALSE);
1.159     quint    3101:          /* if the table has a rowlines attribute, process it */
                   3102:           attrType.AttrSSchema = MathMLSSchema;
                   3103:           attrType.AttrTypeNum = MathML_ATTR_rowlines;
                   3104:          attr = TtaGetAttribute (el, attrType);
                   3105:          if (attr)
                   3106:             HandleRowlinesAttribute (attr, el, doc, FALSE);
                   3107:          /* if the table has a columnlines attribute, process it */
                   3108:           attrType.AttrTypeNum = MathML_ATTR_columnlines;
                   3109:          attr = TtaGetAttribute (el, attrType);
                   3110:          if (attr)
                   3111:             HandleColumnlinesAttribute (attr, el, doc, FALSE);
1.101     cvs      3112:          break;
                   3113:        case MathML_EL_MTR:
                   3114:          /* if the row has a columnalign attribute, process it */
                   3115:           attrType.AttrSSchema = MathMLSSchema;
                   3116:           attrType.AttrTypeNum = MathML_ATTR_columnalign;
                   3117:          attr = TtaGetAttribute (el, attrType);
                   3118:          if (attr)
1.108     cvs      3119:             HandleColalignAttribute (attr, el, doc, FALSE, TRUE);
1.101     cvs      3120:          break;
                   3121:        case MathML_EL_MLABELEDTR:
                   3122:          /* if the row has a columnalign attribute, process it */
                   3123:           attrType.AttrSSchema = MathMLSSchema;
                   3124:           attrType.AttrTypeNum = MathML_ATTR_columnalign;
                   3125:          attr = TtaGetAttribute (el, attrType);
                   3126:          if (attr)
1.108     cvs      3127:             HandleColalignAttribute (attr, el, doc, FALSE, TRUE);
1.1       cvs      3128:          break;
1.39      cvs      3129:        case MathML_EL_MTD:
                   3130:          /* Create placeholders within the table cell */
                   3131:           CreatePlaceholders (TtaGetFirstChild (el), doc);
1.46      cvs      3132:          break;
1.39      cvs      3133:        case MathML_EL_MACTION:
                   3134:          /* Create placeholders within the MACTION element */
                   3135:           CreatePlaceholders (TtaGetFirstChild (el), doc);
1.1       cvs      3136:          break;
                   3137:        default:
                   3138:          break;
                   3139:        }
                   3140:      parent = TtaGetParent (el);
1.118     cvs      3141:      if (parent)
                   3142:        {
                   3143:         parentType = TtaGetElementType (parent);
                   3144:         if (parentType.ElSSchema != elType.ElSSchema)
                   3145:           /* root of a MathML tree, Create a MathML element if there is no */
                   3146:           if (elType.ElTypeNum != MathML_EL_MathML)
                   3147:             {
                   3148:               elType.ElSSchema = MathMLSSchema;
                   3149:               elType.ElTypeNum = MathML_EL_MathML;
                   3150:               new = TtaNewElement (doc, elType);
                   3151:               TtaInsertSibling (new, el, TRUE, doc);
                   3152:               next = el;
                   3153:               TtaNextSibling (&next);
                   3154:               TtaRemoveTree (el, doc);
                   3155:               TtaInsertFirstChild (&el, new, doc);
                   3156:               prev = el;
                   3157:               while (next != NULL)
                   3158:                 {
                   3159:                   child = next;
                   3160:                   TtaNextSibling (&next);
                   3161:                   TtaRemoveTree (child, doc);
                   3162:                   TtaInsertSibling (child, prev, FALSE, doc);
                   3163:                   prev = child;
                   3164:                 }
                   3165:               /* Create placeholders within the MathML element */
                   3166:               CreatePlaceholders (el, doc);
                   3167:             }
                   3168:        }
1.1       cvs      3169:      }
1.56      cvs      3170:    if (!ok)
                   3171:      /* send an error message */
                   3172:      *error = 1;
1.1       cvs      3173: }
                   3174: 
                   3175: /*----------------------------------------------------------------------
1.126     cvs      3176:    UnknownMathMLNameSpace
1.149     cvs      3177:    The element doesn't belong to a supported namespace
1.126     cvs      3178:   ----------------------------------------------------------------------*/
1.149     cvs      3179: void               UnknownMathMLNameSpace (ParserData *context,
                   3180:                                           Element *unknownEl,
                   3181:                                           char* content)
1.126     cvs      3182: {
                   3183:    ElementType     elType;
1.149     cvs      3184:    Element         elText;
1.126     cvs      3185: 
                   3186:    /* Create a new Invalid_element */
                   3187:    elType.ElSSchema = GetXMLSSchema (MATH_TYPE, context->doc);
                   3188:    elType.ElTypeNum = MathML_EL_Unknown_namespace;
1.149     cvs      3189:    *unknownEl = TtaNewElement (context->doc, elType);
                   3190:    if (*unknownEl != NULL)
1.126     cvs      3191:      {
1.149     cvs      3192:        XmlSetElemLineNumber (*unknownEl);
                   3193:        InsertXmlElement (unknownEl);
1.126     cvs      3194:        context->lastElementClosed = TRUE;
                   3195:        elType.ElTypeNum = MathML_EL_TEXT_UNIT;
                   3196:        elText = TtaNewElement (context->doc, elType);
                   3197:        XmlSetElemLineNumber (elText);
1.149     cvs      3198:        TtaInsertFirstChild (&elText, *unknownEl, context->doc);
1.126     cvs      3199:        TtaSetTextContent (elText, content, context->language, context->doc);
                   3200:        TtaSetAccessRight (elText, ReadOnly, context->doc);
                   3201:    }
                   3202: }
                   3203: 
                   3204: /*----------------------------------------------------------------------
1.24      cvs      3205:  SetFontfamily
                   3206:  -----------------------------------------------------------------------*/
1.120     cvs      3207: void SetFontfamily (Document doc, Element el, char *value)
1.24      cvs      3208: {
                   3209: #define buflen 50
1.116     cvs      3210:   char           css_command[buflen+20];
1.24      cvs      3211:  
1.116     cvs      3212:   sprintf (css_command, "font-family: %s", value);
1.72      cvs      3213:   ParseHTMLSpecificStyle (el, css_command, doc, 0, FALSE);
1.24      cvs      3214: }
                   3215: 
                   3216: /*----------------------------------------------------------------------
1.83      cvs      3217:  MathMLlinethickness
                   3218:  The MathML attribute linthickness is associated with element el. Generate
                   3219:  the corresponding style property for this element. 
                   3220:  -----------------------------------------------------------------------*/
1.120     cvs      3221: void MathMLlinethickness (Document doc, Element el, char *value)
1.83      cvs      3222: {
                   3223: #define buflen 50
1.116     cvs      3224:   char           css_command[buflen+20];
1.83      cvs      3225: 
1.116     cvs      3226:   if (strcmp (value, "thin") == 0)
                   3227:      strcpy (value, "1pt");
                   3228:   else if (strcmp (value, "medium") == 0)
                   3229:      strcpy (value, "1pt");
                   3230:   else if (strcmp (value, "thick") == 0)
                   3231:      strcpy (value, "2pt");
                   3232:   sprintf (css_command, "stroke-width: %s", value);
1.83      cvs      3233:   ParseHTMLSpecificStyle (el, css_command, doc, 0, FALSE);
                   3234: }
                   3235: 
                   3236: /*----------------------------------------------------------------------
1.58      cvs      3237:  MathMLAttrToStyleProperty
                   3238:  The MathML attribute attr is associated with element el. Generate
                   3239:  the corresponding style property for this element.
1.24      cvs      3240:  -----------------------------------------------------------------------*/
1.138     cvs      3241: void MathMLAttrToStyleProperty (Document doc, Element el, char *value,
                   3242:                                int attr)
1.24      cvs      3243: {
1.116     cvs      3244:   char           css_command[buflen+20];
1.141     quint    3245:   int            i;
1.58      cvs      3246: 
                   3247:   switch (attr)
                   3248:     {
                   3249:     case MathML_ATTR_fontsize:
1.116     cvs      3250:        sprintf (css_command, "font-size: %s", value);
1.58      cvs      3251:        break;
1.93      cvs      3252:     case MathML_ATTR_mathsize:
1.116     cvs      3253:        if (strcmp (value, "small") == 0)
                   3254:         strcpy (value, "80%");
                   3255:        else if (strcmp (value, "normal") == 0)
                   3256:         strcpy (value, "100%");
                   3257:        else if (strcmp (value, "big") == 0)
                   3258:         strcpy (value, "125%");
                   3259:        sprintf (css_command, "font-size: %s", value);
1.93      cvs      3260:        break;
1.58      cvs      3261:     case MathML_ATTR_lspace:
                   3262:     case MathML_ATTR_rspace:
1.141     quint    3263:        if (attr == MathML_ATTR_lspace)
                   3264:         strcpy (css_command, "padding-left: ");
                   3265:        else
                   3266:         strcpy (css_command, "padding-right: ");
                   3267:        /* is the value a named space? */
                   3268:        if (strcmp (value, "veryverythinmathspace") == 0)
                   3269:         strcat (css_command, "0.0555556em");
                   3270:        else if (strcmp (value, "verythinmathspace") == 0)
                   3271:         strcat (css_command, "0.111111em");
                   3272:        else if (strcmp (value, "thinmathspace") == 0)
                   3273:         strcat (css_command, "0.166667em");
                   3274:        else if (strcmp (value, "mediummathspace") == 0)
                   3275:         strcat (css_command, "0.222222em");
                   3276:        else if (strcmp (value, "thickmathspace") == 0)
                   3277:         strcat (css_command, "0.277778em");
                   3278:        else if (strcmp (value, "verythickmathspace") == 0)
                   3279:         strcat (css_command, "0.333333em");
                   3280:        else if (strcmp (value, "veryverythickmathspace") == 0)
                   3281:         strcat (css_command, "0.388889em");
                   3282:        else
                   3283:         {
                   3284:           strcat (css_command, value);
                   3285:           /* does the value contain an unit at the end? */
                   3286:           i = strlen (value) - 1;
                   3287:           if ((value[i] <= '9' && value[i] >= '0') ||
                   3288:               value[i] == '.')
                   3289:             /* it's just a number. Add the (implicit) unit: em */
                   3290:             strcat (css_command, "em");
                   3291:         }
1.58      cvs      3292:        break;
                   3293:     }
1.72      cvs      3294:   ParseHTMLSpecificStyle (el, css_command, doc, 0, FALSE);
1.24      cvs      3295: }
                   3296: 
                   3297: /*----------------------------------------------------------------------
1.60      cvs      3298:  MathMLSetScriptLevel
                   3299:  A scriptlevel attribute with value value is associated with element el.
                   3300:  Generate the corresponding style property for this element.
                   3301:  -----------------------------------------------------------------------*/
1.120     cvs      3302: void MathMLSetScriptLevel (Document doc, Element el, char *value)
1.60      cvs      3303: {
                   3304:   PresentationValue   pval;
                   3305:   PresentationContext ctxt;
                   3306:   ThotBool            relative;
                   3307:   int                 percentage;
                   3308: 
                   3309:   ctxt = TtaGetSpecificStyleContext (doc);
                   3310:   if (!value)
                   3311:      /* remove the presentation rule */
                   3312:      {
                   3313:      ctxt->destroy = TRUE;
1.75      cvs      3314:      pval.typed_data.value = 0;
1.60      cvs      3315:      TtaSetStylePresentation (PRSize, el, NULL, ctxt, pval);
                   3316:      }
                   3317:   else
                   3318:      {
                   3319:      ctxt->destroy = FALSE;
                   3320:      /* parse the attribute value (an optional sign and an integer) */
1.119     cvs      3321:      value = TtaSkipBlanks (value);
1.60      cvs      3322:      relative = (value[0] == '-' || value[0] == '+');
                   3323:      value = ParseCSSUnit (value, &pval);
                   3324:      if (pval.typed_data.unit != STYLE_UNIT_REL &&
                   3325:         pval.typed_data.real)
                   3326:        /* this is an error: it should be an integer without any unit name */
                   3327:        /* error */;
                   3328:      else
                   3329:        {
                   3330:        if (relative)
                   3331:         {
1.63      cvs      3332:         percentage = 100;
1.60      cvs      3333:          if (pval.typed_data.value == 0)
                   3334:           /* scriptlevel="+0" */
                   3335:           percentage = 100;
                   3336:          else if (pval.typed_data.value == 1)
                   3337:           /* scriptlevel="+1" */
                   3338:           percentage = 71;
                   3339:         else if (pval.typed_data.value == 2)
                   3340:           /* scriptlevel="+2" */
                   3341:           percentage = 50;
                   3342:         else if (pval.typed_data.value >= 3)
                   3343:           /* scriptlevel="+3" or more */
                   3344:           percentage = 35;
                   3345:         else if (pval.typed_data.value == -1)
                   3346:           /* scriptlevel="-1" */
                   3347:           percentage = 141;
                   3348:         else if (pval.typed_data.value == -2)
                   3349:           /* scriptlevel="-2" */
                   3350:           percentage = 200;
                   3351:         else if (pval.typed_data.value <= -3)
                   3352:           /* scriptlevel="-3" or less */
                   3353:           percentage = 282;
                   3354:         pval.typed_data.value = percentage;
                   3355:         pval.typed_data.unit = STYLE_UNIT_PERCENT;
1.78      cvs      3356:         /* the specific presentation to be created is not a CSS rule */
1.147     quint    3357:         ctxt->cssSpecificity = 0;
1.60      cvs      3358:         TtaSetStylePresentation (PRSize, el, NULL, ctxt, pval);       
                   3359:         }
                   3360:        else
                   3361:         /* absolute value */
                   3362:         {
                   3363:           /****  ****/;
                   3364:         }
                   3365:        }
                   3366:      }
                   3367:   TtaFreeMemory (ctxt);
                   3368: }
                   3369: 
                   3370: /*----------------------------------------------------------------------
                   3371:  MathMLSpacingAttr
                   3372:  The MathML attribute attr (height, width or depth) is associated
                   3373:  with element el (a mspace or mpadding).
                   3374:  If value is not NULL, generate the corresponding Thot presentation rule for
                   3375:  the element.
                   3376:  If value is NULL, remove the corresponding Thot presentation rule.
                   3377:  -----------------------------------------------------------------------*/
1.120     cvs      3378: void MathMLSpacingAttr (Document doc, Element el, char *value, int attr)
1.60      cvs      3379: {
                   3380:   ElementType         elType;
                   3381:   PresentationValue   pval;
                   3382:   PresentationContext ctxt;
                   3383:   int                 ruleType;
                   3384: 
                   3385:   /* provisionally, handles only mspace elements */
                   3386:   elType = TtaGetElementType (el);
1.96      cvs      3387:   if (elType.ElTypeNum != MathML_EL_MSPACE &&
1.97      cvs      3388:       elType.ElTypeNum != MathML_EL_MPADDED &&
                   3389:       elType.ElTypeNum != MathML_EL_MTABLE)
1.60      cvs      3390:      return;
                   3391:   switch (attr)
                   3392:     {
                   3393:     case MathML_ATTR_width_:
                   3394:       ruleType = PRWidth;
                   3395:       break;
                   3396:     case MathML_ATTR_height_:
                   3397:       ruleType = PRPaddingTop;
                   3398:       break;
                   3399:     case MathML_ATTR_depth_:
                   3400:       ruleType = PRPaddingBottom;
                   3401:       break;
                   3402:     default:
                   3403:       return;
                   3404:     }
                   3405:   ctxt = TtaGetSpecificStyleContext (doc);
1.116     cvs      3406:   if (!value || (strcmp (value, "auto") == 0))
1.60      cvs      3407:     /* remove the presentation rule */
                   3408:     {
                   3409:       ctxt->destroy = TRUE;
1.75      cvs      3410:       pval.typed_data.value = 0;
1.60      cvs      3411:       TtaSetStylePresentation (ruleType, el, NULL, ctxt, pval);
                   3412:     }
                   3413:   else
                   3414:     {
                   3415:       ctxt->destroy = FALSE;
                   3416:       /* parse the attribute value (a number followed by a unit) */
1.119     cvs      3417:       value = TtaSkipBlanks (value);
1.60      cvs      3418:       value = ParseCSSUnit (value, &pval);
                   3419:       /***** we should accept namedspace for width *****/
                   3420:       if (pval.typed_data.unit != STYLE_UNIT_INVALID)
1.78      cvs      3421:        {
                   3422:          /* the specific presentation to be created is not a CSS rule */
1.147     quint    3423:          ctxt->cssSpecificity = 0;
1.78      cvs      3424:          TtaSetStylePresentation (ruleType, el, NULL, ctxt, pval);
                   3425:        }
1.60      cvs      3426:     }
                   3427:   TtaFreeMemory (ctxt);
                   3428: }
                   3429: 
                   3430: /*----------------------------------------------------------------------
1.153     quint    3431:    MathMLSetDisplayAttr
                   3432:    The MathML attribute display is associated  with element el.
                   3433:    Generate the corresponding Thot presentation rule for
                   3434:    the element.
                   3435:   ----------------------------------------------------------------------*/
                   3436: void MathMLSetDisplayAttr (Element el, Attribute attr, Document doc,
                   3437:                           ThotBool delete)
                   3438: {
                   3439:   int val;
                   3440: 
                   3441:   val = TtaGetAttributeValue (attr);
                   3442:   if (val == MathML_ATTR_display_VAL_block)
                   3443:     ParseHTMLSpecificStyle (el, "display: block", doc, 0, delete);
                   3444:   else if (val == MathML_ATTR_display_VAL_inline_)
                   3445:     ParseHTMLSpecificStyle (el, "display: inline", doc, 0, delete);
                   3446: }
                   3447: 
                   3448: /*----------------------------------------------------------------------
1.1       cvs      3449:    MathMLAttributeComplete
1.58      cvs      3450:    The XML parser has completed parsing attribute attr (as well as its value)
                   3451:    that is associated with element el in document doc.
1.1       cvs      3452:   ----------------------------------------------------------------------*/
1.120     cvs      3453: void MathMLAttributeComplete (Attribute attr, Element el, Document doc)
1.1       cvs      3454: {
1.134     cvs      3455:    AttributeType     attrType, depAttrType;
1.23      cvs      3456:    int              attrKind;
1.50      cvs      3457:    ElementType       elType;
1.120     cvs      3458:    char             *value;
1.50      cvs      3459:    int               val, length;
1.101     cvs      3460:    Attribute         intAttr;
1.23      cvs      3461:  
1.58      cvs      3462:    /* first get the type of that attribute */
1.23      cvs      3463:    TtaGiveAttributeType (attr, &attrType, &attrKind);
1.153     quint    3464: 
1.54      cvs      3465:    if (attrType.AttrTypeNum == MathML_ATTR_bevelled)
1.58      cvs      3466:      /* it's a bevelled attribute */
1.50      cvs      3467:      {
                   3468:        val = TtaGetAttributeValue (attr);
1.54      cvs      3469:        if (val == MathML_ATTR_bevelled_VAL_true)
                   3470:         /* bevelled = true.  Transform MFRAC into BevelledMFRAC */
1.50      cvs      3471:         {
                   3472:         elType = TtaGetElementType (el);
                   3473:         if (elType.ElTypeNum == MathML_EL_MFRAC)
1.54      cvs      3474:            ChangeTypeOfElement (el, doc, MathML_EL_BevelledMFRAC);
1.50      cvs      3475:         }
                   3476:      }
1.101     cvs      3477: 
                   3478:    else if (attrType.AttrTypeNum == MathML_ATTR_rowalign_mtr)
                   3479:      {
                   3480:        /* create an equivalent IntRowAlign attribute on the same element */
                   3481:        attrType.AttrTypeNum = MathML_ATTR_IntRowAlign;
                   3482:        intAttr = TtaGetAttribute (el, attrType);
                   3483:        if (!intAttr)
                   3484:         /* no IntRowAlign attribute, create one */
                   3485:         {
                   3486:           intAttr = TtaNewAttribute (attrType);
                   3487:           TtaAttachAttribute (el, intAttr, doc);
                   3488:         }
                   3489:        val = TtaGetAttributeValue (attr);
                   3490:        TtaSetAttributeValue (intAttr, val, el, doc);
                   3491:      }
                   3492: 
                   3493:    else if (attrType.AttrTypeNum == MathML_ATTR_columnalign_mtd)
                   3494:      {
                   3495:        /* create an equivalent IntColAlign attribute on the same element */
                   3496:        attrType.AttrTypeNum = MathML_ATTR_IntColAlign;
                   3497:        intAttr = TtaGetAttribute (el, attrType);
                   3498:        if (!intAttr)
                   3499:         /* no IntColAlign attribute, create one */
                   3500:         {
                   3501:           intAttr = TtaNewAttribute (attrType);
                   3502:           TtaAttachAttribute (el, intAttr, doc);
                   3503:         }
                   3504:        val = TtaGetAttributeValue (attr);
                   3505:        TtaSetAttributeValue (intAttr, val, el, doc);
                   3506:      }
                   3507: 
1.159     quint    3508:    /* don't handle attributes columnalign, rowalign, columnlines and rowlines
                   3509:       now: the table or the row is not complete yet. Handle them when the
                   3510:       element is complete.
1.104     cvs      3511:    */
1.153     quint    3512: 
                   3513:    else if (attrType.AttrTypeNum == MathML_ATTR_display)
                   3514:      /* it's a display attribute */
                   3515:      MathMLSetDisplayAttr (el, attr, doc, FALSE);
1.138     cvs      3516: 
                   3517:    else if (attrType.AttrTypeNum == MathML_ATTR_Language)
                   3518:      {
                   3519:        if (el == TtaGetRootElement (doc))
                   3520:         /* it's the lang attribute on the root element */
                   3521:         /* set the RealLang attribute */
                   3522:         {
                   3523:           depAttrType.AttrSSchema = attrType.AttrSSchema ;
                   3524:           depAttrType.AttrTypeNum = MathML_ATTR_RealLang;
                   3525:           if (!TtaGetAttribute (el, depAttrType))
                   3526:             /* it's not present. Add it */
                   3527:             {
                   3528:               intAttr = TtaNewAttribute (depAttrType);
                   3529:               TtaAttachAttribute (el, intAttr, doc);
                   3530:               TtaSetAttributeValue (intAttr, MathML_ATTR_RealLang_VAL_Yes_,
                   3531:                                     el, doc);
                   3532:             }
                   3533:         }
                   3534:      }
1.101     cvs      3535: 
1.50      cvs      3536:    else if (attrType.AttrTypeNum == MathML_ATTR_color ||
1.93      cvs      3537:            attrType.AttrTypeNum == MathML_ATTR_mathcolor ||
                   3538:            attrType.AttrTypeNum == MathML_ATTR_background_ ||
                   3539:            attrType.AttrTypeNum == MathML_ATTR_mathbackground ||
                   3540:            attrType.AttrTypeNum == MathML_ATTR_fontsize ||
                   3541:            attrType.AttrTypeNum == MathML_ATTR_mathsize ||
                   3542:            attrType.AttrTypeNum == MathML_ATTR_fontfamily ||
                   3543:            attrType.AttrTypeNum == MathML_ATTR_linethickness ||
                   3544:            attrType.AttrTypeNum == MathML_ATTR_lspace ||
                   3545:            attrType.AttrTypeNum == MathML_ATTR_rspace ||
                   3546:            attrType.AttrTypeNum == MathML_ATTR_scriptlevel ||
                   3547:            attrType.AttrTypeNum == MathML_ATTR_width_ ||
                   3548:            attrType.AttrTypeNum == MathML_ATTR_height_ ||
                   3549:            attrType.AttrTypeNum == MathML_ATTR_depth_ )
                   3550:      {
1.23      cvs      3551:       length = TtaGetTextAttributeLength (attr);
                   3552:       if (length >= buflen)
                   3553:          length = buflen - 1;
                   3554:       if (length > 0)
                   3555:         {
1.116     cvs      3556:           value = TtaGetMemory (buflen);
1.33      cvs      3557:           value[0] = EOS;
                   3558:           TtaGiveTextAttributeValue (attr, value, &length);
                   3559:           switch (attrType.AttrTypeNum)
                   3560:             {
                   3561:             case MathML_ATTR_color:
1.134     cvs      3562:               /* deprecated attribute */
                   3563:               /* if the same element has a mathcolor attribute, ignore
                   3564:                  the color attribute */
                   3565:               depAttrType.AttrSSchema = attrType.AttrSSchema ;
                   3566:               depAttrType.AttrTypeNum = MathML_ATTR_mathcolor;
                   3567:               if (!TtaGetAttribute (el, depAttrType))
                   3568:                   HTMLSetForegroundColor (doc, el, value);
                   3569:               break;
1.93      cvs      3570:             case MathML_ATTR_mathcolor:
1.24      cvs      3571:                HTMLSetForegroundColor (doc, el, value);
                   3572:               break;
1.33      cvs      3573:             case MathML_ATTR_background_:
1.134     cvs      3574:               /* deprecated attribute */
                   3575:               /* if the same element has a mathbackground attribute, ignore
                   3576:                  the background attribute */
                   3577:               depAttrType.AttrSSchema = attrType.AttrSSchema;
                   3578:               depAttrType.AttrTypeNum = MathML_ATTR_mathbackground;
                   3579:               if (!TtaGetAttribute (el, depAttrType))
                   3580:                   HTMLSetBackgroundColor (doc, el, value);
                   3581:               break;
1.93      cvs      3582:             case MathML_ATTR_mathbackground:
1.24      cvs      3583:                HTMLSetBackgroundColor (doc, el, value);
                   3584:               break;
1.33      cvs      3585:             case MathML_ATTR_fontfamily:
1.24      cvs      3586:               SetFontfamily (doc, el, value);
1.83      cvs      3587:               break;
                   3588:             case MathML_ATTR_linethickness:
                   3589:               MathMLlinethickness (doc, el, value);
1.58      cvs      3590:               break;
                   3591:             case MathML_ATTR_fontsize:
1.134     cvs      3592:               /* deprecated attribute */
                   3593:               /* if the same element has a mathsize attribute, ignore
                   3594:                  the fontsize attribute */
                   3595:               depAttrType.AttrSSchema = attrType.AttrSSchema;
                   3596:               depAttrType.AttrTypeNum = MathML_ATTR_mathsize;
                   3597:               if (!TtaGetAttribute (el, depAttrType))
                   3598:                 MathMLAttrToStyleProperty (doc, el, value,
                   3599:                                            attrType.AttrTypeNum);
                   3600:               break;
1.93      cvs      3601:             case MathML_ATTR_mathsize:
1.58      cvs      3602:             case MathML_ATTR_lspace:
                   3603:             case MathML_ATTR_rspace:
1.60      cvs      3604:               MathMLAttrToStyleProperty (doc, el, value,attrType.AttrTypeNum);
                   3605:               break;
                   3606:             case MathML_ATTR_scriptlevel:
                   3607:               MathMLSetScriptLevel (doc, el, value);
                   3608:               break;
                   3609:              case MathML_ATTR_width_:
                   3610:             case MathML_ATTR_height_:
                   3611:             case MathML_ATTR_depth_:
                   3612:               MathMLSpacingAttr (doc, el, value, attrType.AttrTypeNum);
1.59      cvs      3613:               break;
                   3614:             default:
1.24      cvs      3615:               break;
1.33      cvs      3616:             }
                   3617:           TtaFreeMemory (value);
1.23      cvs      3618:         }
                   3619:       }
1.1       cvs      3620: }
                   3621: 
                   3622: /*----------------------------------------------------------------------
                   3623:    MathMLGetDTDName
                   3624:   ----------------------------------------------------------------------*/
1.120     cvs      3625: void MathMLGetDTDName (char *DTDname, char *elementName)
1.1       cvs      3626: {
                   3627:    /* no other DTD allowed within MathML elements */
1.116     cvs      3628:    strcpy (DTDname, "");
1.1       cvs      3629: }
                   3630: 
                   3631: /* end of module */

Webmaster