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

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"
1.169     quint      20: #include "HTML.h"
1.25      cvs        21: #include "parser.h"
1.59      cvs        22: #include "styleparser_f.h"
                     23: #include "style.h"
                     24: #include "undo.h"
1.133     cvs        25: #include "Xml2thot_f.h"
1.109     cvs        26: 
1.106     cvs        27: /* Define a pointer to let parser functions access the Math entity table */
                     28: extern XmlEntity *pMathEntityTable;
1.1       cvs        29: 
                     30: #define MaxMsgLength 200
                     31: 
1.12      cvs        32: #include "HTMLtable_f.h"
1.29      cvs        33: #include "Mathedit_f.h"
                     34: #include "styleparser_f.h"
                     35: #include "fetchXMLname_f.h"
1.1       cvs        36: 
                     37: /*----------------------------------------------------------------------
1.170     quint      38:    IsLargeOp
                     39:    Return TRUE if character is listed as a largeop in the MathML 2.0
                     40:    Operator dictionary (appendix F.5)
                     41:   ----------------------------------------------------------------------*/
1.171     carcone    42: static ThotBool IsLargeOp (CHAR_T character, char script)
1.170     quint      43: {
                     44:   /****** to be completed *****/
                     45: #ifdef _I18N_
                     46:   if (character == 8721 || character == 8719) /* large Sigma or Pi */
                     47: #else
                     48:   if ((script == 'G') &&
                     49:       (character == 229 || character == 213))  /* large Sigma or Pi */
                     50: #endif
                     51:     /* it's a large character */
                     52:     return TRUE;
                     53:   else
                     54:     return FALSE;
                     55: }
                     56: 
                     57: /*----------------------------------------------------------------------
                     58:    IsStretchy
                     59:    Return TRUE if character is listed as a stretchy operator in the MathML 2.0
                     60:    Operator dictionary (appendix F.5)
                     61:   ----------------------------------------------------------------------*/
1.171     carcone    62: static ThotBool IsStretchy (CHAR_T character, char script)
1.170     quint      63: {
                     64:   /****** to be completed *****/
                     65:   if ((
                     66: #ifndef _I18N_
                     67:        (script == 'L') &&
                     68: #endif
                     69:         (character == '(' || character == ')' ||
                     70:         character == '[' || character == ']' ||
                     71:         character == '{' || character == '}' ||
                     72:         character == '|'))  ||
                     73:       (
                     74:        /* test left and right angle brackets */
                     75: #ifdef _I18N_
                     76:        (character == 9001 || character == 9002)
                     77: #else
                     78:        (script == 'G') &&
                     79:        (character == 225 || character == 241)
                     80: #endif
                     81:      ))
                     82:     return TRUE;
                     83:   else
                     84:     return FALSE;
                     85: }
                     86: 
                     87: /*----------------------------------------------------------------------
1.1       cvs        88:    MapMathMLAttribute
                     89:    Search in the Attribute Mapping Table the entry for the
                     90:    attribute of name Attr and returns the corresponding Thot attribute type.
                     91:   ----------------------------------------------------------------------*/
1.120     cvs        92: void MapMathMLAttribute (char *attrName, AttributeType *attrType,
                     93:                         char *elementName, ThotBool *level, Document doc)
1.1       cvs        94: {
1.68      cvs        95:   attrType->AttrSSchema = GetMathMLSSchema (doc);
1.170     quint      96:   MapXMLAttribute (MATH_TYPE, attrName, elementName, level, doc,
                     97:                   &(attrType->AttrTypeNum));
1.1       cvs        98: }
                     99: 
                    100: /*----------------------------------------------------------------------
                    101:    MapMathMLAttributeValue
                    102:    Search in the Attribute Value Mapping Table the entry for the attribute
                    103:    ThotAtt and its value AttrVal. Returns the corresponding Thot value.
                    104:   ----------------------------------------------------------------------*/
1.150     vatton    105: void MapMathMLAttributeValue (char *attVal, AttributeType attrType, int *value)
1.1       cvs       106: {
1.150     vatton    107:   MapXMLAttributeValue (MATH_TYPE, attVal, attrType, value);
1.1       cvs       108: }
                    109: 
                    110: /*----------------------------------------------------------------------
1.130     carcone   111:    MathMLEntityCreated
                    112:   ----------------------------------------------------------------------*/
                    113: void MathMLEntityCreated (unsigned char *entityValue, Language lang,
                    114:                         char *entityName, Document doc)
                    115:  {
                    116:  }
                    117: 
                    118: /*----------------------------------------------------------------------
1.1       cvs       119:   ElementNeedsPlaceholder
                    120:   returns TRUE if element el needs a sibling placeholder.
                    121:   ----------------------------------------------------------------------*/
1.18      cvs       122: ThotBool     ElementNeedsPlaceholder (Element el)
1.1       cvs       123: {
                    124:   ElementType   elType;
1.138     cvs       125:   Element      child, parent, sibling;
1.18      cvs       126:   ThotBool     ret;
1.139     quint     127: 
1.1       cvs       128:   ret = FALSE;
                    129:   elType = TtaGetElementType (el);
1.43      cvs       130:   if (elType.ElTypeNum == MathML_EL_MS ||
1.39      cvs       131:       elType.ElTypeNum == MathML_EL_MFRAC ||
1.54      cvs       132:       elType.ElTypeNum == MathML_EL_BevelledMFRAC ||
1.39      cvs       133:       elType.ElTypeNum == MathML_EL_MSQRT ||
                    134:       elType.ElTypeNum == MathML_EL_MROOT ||
                    135:       elType.ElTypeNum == MathML_EL_MSTYLE ||
                    136:       elType.ElTypeNum == MathML_EL_MERROR ||
                    137:       elType.ElTypeNum == MathML_EL_MPADDED ||
                    138:       elType.ElTypeNum == MathML_EL_MPHANTOM ||
                    139:       elType.ElTypeNum == MathML_EL_MFENCED ||
1.1       cvs       140:       elType.ElTypeNum == MathML_EL_MF ||
                    141:       elType.ElTypeNum == MathML_EL_MSUB ||
                    142:       elType.ElTypeNum == MathML_EL_MSUP ||
1.39      cvs       143:       elType.ElTypeNum == MathML_EL_MSUBSUP ||
1.1       cvs       144:       elType.ElTypeNum == MathML_EL_MUNDER ||
                    145:       elType.ElTypeNum == MathML_EL_MOVER ||
                    146:       elType.ElTypeNum == MathML_EL_MUNDEROVER ||
1.28      cvs       147:       elType.ElTypeNum == MathML_EL_MMULTISCRIPTS ||
1.39      cvs       148:       elType.ElTypeNum == MathML_EL_MTABLE ||
                    149:       elType.ElTypeNum == MathML_EL_MACTION)
1.1       cvs       150:      ret = TRUE;
1.138     cvs       151:   else if (elType.ElTypeNum == MathML_EL_MROW)
                    152:     /* a mrow needs a place holder only if it's not the sole child of
                    153:        an element such as Numerator, Denominator, RootBase, Index, etc. */
                    154:     {
                    155:       ret = TRUE;
                    156:       sibling = el;  TtaNextSibling (&sibling);
                    157:       if (!sibling)
                    158:        {
1.139     quint     159:          sibling = el;  TtaPreviousSibling (&sibling);
1.138     cvs       160:          if (!sibling)
                    161:            {
                    162:              parent = TtaGetParent (el);
                    163:              if (parent)
                    164:                {
                    165:                  elType = TtaGetElementType (parent);
                    166:                  if (elType.ElTypeNum == MathML_EL_Numerator ||
                    167:                      elType.ElTypeNum == MathML_EL_Denominator ||
                    168:                      elType.ElTypeNum == MathML_EL_RootBase ||
                    169:                      elType.ElTypeNum == MathML_EL_Index ||
                    170:                      elType.ElTypeNum == MathML_EL_FencedExpression ||
                    171:                      elType.ElTypeNum == MathML_EL_Base ||
                    172:                      elType.ElTypeNum == MathML_EL_Subscript ||
                    173:                      elType.ElTypeNum == MathML_EL_Superscript ||
                    174:                      elType.ElTypeNum == MathML_EL_UnderOverBase ||
                    175:                      elType.ElTypeNum == MathML_EL_Underscript ||
                    176:                      elType.ElTypeNum == MathML_EL_Overscript ||
                    177:                      elType.ElTypeNum == MathML_EL_MultiscriptBase ||
                    178:                      elType.ElTypeNum == MathML_EL_MSubscript ||
                    179:                      elType.ElTypeNum == MathML_EL_MSuperscript)
                    180:                    ret = FALSE;
                    181:                }
                    182:            }
                    183:        }
                    184:     }
1.158     quint     185:   else if (elType.ElTypeNum == MathML_EL_MO ||
                    186:           elType.ElTypeNum == MathML_EL_OpeningFence ||
                    187:           elType.ElTypeNum == MathML_EL_ClosingFence ||
                    188:           elType.ElTypeNum == MathML_EL_FencedSeparator)
1.138     cvs       189:     /* an operator that contains a single Symbol needs a placeholder,
                    190:        except when it is in a Base or UnderOverBase */
                    191:     {
                    192:       child = TtaGetFirstChild (el);
                    193:       if (child != NULL)
1.1       cvs       194:        {
1.138     cvs       195:          elType = TtaGetElementType (child);
                    196:          if (elType.ElTypeNum == MathML_EL_SYMBOL_UNIT)
                    197:            {
1.1       cvs       198:              ret = TRUE;
                    199:              parent = TtaGetParent (el);
                    200:              if (parent != NULL)
                    201:                {
1.138     cvs       202:                  elType = TtaGetElementType (parent);
                    203:                  if (elType.ElTypeNum == MathML_EL_Base ||
                    204:                      elType.ElTypeNum == MathML_EL_UnderOverBase)
1.139     quint     205:                    ret = FALSE;
                    206:                }
                    207:            }
                    208:        }
                    209:     }
                    210:   else if (elType.ElTypeNum == MathML_EL_MSPACE)
                    211:     {
                    212:       /* in principle mspace needs a placeholder sibling */
                    213:       ret = TRUE;
                    214:       /* but if it's the only child of a mstyle element, the placeholders
                    215:         would change the height and width of the mstyle. Consider for
                    216:         instance:
                    217:         <mstyle background="#000099">
                    218:           <mspace depth="2mm" width=".2in"/>
                    219:         </mstyle>  */
                    220:       sibling = el;  TtaNextSibling (&sibling);
                    221:       if (!sibling)
                    222:        {
                    223:          sibling = el;  TtaPreviousSibling (&sibling);
                    224:          if (!sibling)
                    225:            {
                    226:              parent = TtaGetParent (el);
                    227:              if (parent)
                    228:                {
                    229:                  elType = TtaGetElementType (parent);
                    230:                  if (elType.ElTypeNum == MathML_EL_MSTYLE)
1.138     cvs       231:                    ret = FALSE;
1.1       cvs       232:                }
1.138     cvs       233:            }
1.1       cvs       234:        }
1.138     cvs       235:     }
1.1       cvs       236:   return ret;
                    237: }
1.132     cvs       238: 
1.1       cvs       239: /*----------------------------------------------------------------------
                    240:   CreatePlaceholders
                    241:   ----------------------------------------------------------------------*/
                    242: static void    CreatePlaceholders (Element el, Document doc)
                    243: {
1.132     cvs       244:    Element      sibling, prev, constr, child;
                    245:    Attribute    attr;
                    246:    ElementType  elType;
                    247:    AttributeType attrType;
                    248:    ThotBool     create, stretchableSubsup;
1.1       cvs       249: 
1.55      cvs       250:    if (!el)
                    251:       return;
1.2       cvs       252:    elType.ElSSchema = GetMathMLSSchema (doc);
1.1       cvs       253:    prev = NULL;
                    254:    create = TRUE;
                    255:    sibling = el;
                    256:    while (sibling != NULL)
                    257:       {
                    258:       if (!ElementNeedsPlaceholder (sibling))
                    259:         create = FALSE;
                    260:       else
                    261:         {
                    262:         if (sibling == el)
                    263:            /* first element */
                    264:            {
                    265:            elType = TtaGetElementType (sibling);
                    266:            if (elType.ElTypeNum == MathML_EL_MF)
                    267:               /* the first element is a MF. Don't create a placeholder
                    268:                  before */
                    269:               create = FALSE;
                    270:            else if (elType.ElTypeNum == MathML_EL_MROW)
                    271:               /* the first element is a MROW */
                    272:               {
                    273:               child = TtaGetFirstChild (sibling);
                    274:               if (child != NULL)
                    275:                  {
                    276:                  elType = TtaGetElementType (child);
                    277:                  if (elType.ElTypeNum != MathML_EL_MF)
                    278:                     /* the first child of the MROW element is not a MF */
                    279:                     /* Don't create a placeholder before */
                    280:                     create = FALSE;
                    281:                  }
                    282:               }
                    283:            }
                    284:         if (create)
                    285:            {
                    286:             elType.ElTypeNum = MathML_EL_Construct;
                    287:            constr = TtaNewElement (doc, elType);
                    288:            TtaInsertSibling (constr, sibling, TRUE, doc);
                    289:            attrType.AttrSSchema = elType.ElSSchema;
1.22      cvs       290:            attrType.AttrTypeNum = MathML_ATTR_IntPlaceholder;
1.1       cvs       291:            attr = TtaNewAttribute (attrType);
                    292:            TtaAttachAttribute (constr, attr, doc);
1.55      cvs       293:            TtaSetAttributeValue (attr, MathML_ATTR_IntPlaceholder_VAL_yes_,
                    294:                                  constr, doc);
1.1       cvs       295:            }
                    296:         create = TRUE;
                    297:         }
                    298:       prev = sibling;
                    299:       TtaNextSibling (&sibling);
                    300:       }
                    301:    if (prev != NULL && create)
                    302:       {
1.132     cvs       303:        stretchableSubsup = FALSE;
1.1       cvs       304:        elType = TtaGetElementType (prev);
1.95      cvs       305:        /* don't insert a placeholder after the last element if it's a MF */
                    306:        if (elType.ElTypeNum == MathML_EL_MF)
1.1       cvs       307:           create = FALSE;
                    308:        else if (elType.ElTypeNum == MathML_EL_MROW)
                    309:           /* the last element is a MROW */
                    310:           {
                    311:           child = TtaGetLastChild (prev);
                    312:           if (child != NULL)
                    313:              {
                    314:              elType = TtaGetElementType (child);
                    315:              if (elType.ElTypeNum != MathML_EL_MF)
                    316:                 /* the last child of the MROW element is not a MF */
                    317:                 /* Don't create a placeholder before */
                    318:                 create = FALSE;
                    319:              }
                    320:           }
1.132     cvs       321:        else if (elType.ElTypeNum == MathML_EL_MSUBSUP ||
                    322:                 elType.ElTypeNum == MathML_EL_MSUB ||
                    323:                 elType.ElTypeNum == MathML_EL_MSUP ||
                    324:                 elType.ElTypeNum == MathML_EL_MUNDEROVER ||
                    325:                 elType.ElTypeNum == MathML_EL_MUNDER ||
                    326:                 elType.ElTypeNum == MathML_EL_MUNDEROVER)
                    327:          {
                    328:            attrType.AttrSSchema = elType.ElSSchema;
                    329:            attrType.AttrTypeNum = MathML_ATTR_IntVertStretch;
                    330:            if (TtaGetAttribute (prev, attrType))
                    331:              stretchableSubsup = TRUE;
                    332:          }
                    333: 
1.1       cvs       334:        if (create)
                    335:           {
1.132     cvs       336:           if (stretchableSubsup)
                    337:             elType.ElTypeNum = MathML_EL_Construct1;
                    338:           else
                    339:             elType.ElTypeNum = MathML_EL_Construct;
1.1       cvs       340:           constr = TtaNewElement (doc, elType);
                    341:           TtaInsertSibling (constr, prev, FALSE, doc);
                    342:           attrType.AttrSSchema = elType.ElSSchema;
1.22      cvs       343:           attrType.AttrTypeNum = MathML_ATTR_IntPlaceholder;
1.1       cvs       344:           attr = TtaNewAttribute (attrType);
                    345:           TtaAttachAttribute (constr, attr, doc);
1.55      cvs       346:           TtaSetAttributeValue (attr, MathML_ATTR_IntPlaceholder_VAL_yes_,
                    347:                                 constr, doc);
1.132     cvs       348:           }
1.1       cvs       349:       }
                    350: }
                    351: 
                    352: /*----------------------------------------------------------------------
1.95      cvs       353:   NextNotComment
                    354:   Return the next sibling of element el that is not an XMLcomment element.
                    355:   Return el itself if it's not a comment.
1.1       cvs       356:   ----------------------------------------------------------------------*/
1.95      cvs       357: static void    NextNotComment (Element* el, Element* prev)
1.1       cvs       358: {
                    359:    ElementType elType;
                    360: 
                    361:    if (*el == NULL)
                    362:       return;
                    363:    elType = TtaGetElementType (*el);
1.95      cvs       364:    while (*el != NULL && elType.ElTypeNum == MathML_EL_XMLcomment)
1.1       cvs       365:       {
                    366:       *prev = *el;
                    367:       TtaNextSibling (el);
                    368:       if (*el != NULL)
                    369:        elType = TtaGetElementType (*el);
                    370:       }
                    371: }
                    372: 
                    373: /*----------------------------------------------------------------------
                    374:   CheckMathSubExpressions
                    375:   Children of element el should be of type type1, type2, and type3.
1.56      cvs       376:   If they are not, wrap them in elements of these types.
1.124     cvs       377:   If element el has too many or not enough children, return FALSE.
1.1       cvs       378:   ----------------------------------------------------------------------*/
1.56      cvs       379: static ThotBool CheckMathSubExpressions (Element el, int type1, int type2, int type3, Document doc)
1.1       cvs       380: {
                    381:   Element      child, new, prev;
                    382:   ElementType  elType, childType;
1.124     cvs       383:   char          msgBuffer[200];
1.56      cvs       384:   ThotBool      result;
1.1       cvs       385: 
1.56      cvs       386:   result = TRUE;
1.2       cvs       387:   elType.ElSSchema = GetMathMLSSchema (doc);
1.1       cvs       388:   child = TtaGetFirstChild (el);
                    389:   prev = NULL;
1.95      cvs       390:   NextNotComment (&child, &prev);
1.56      cvs       391:   if (type1 == 0)
1.1       cvs       392:     {
1.56      cvs       393:     if (child)
                    394:       /* no child expected and there is one, error */
1.124     cvs       395:       {
                    396:        sprintf (msgBuffer, "No subexpression allowed in %s",
                    397:                 TtaGetElementTypeName (TtaGetElementType (el)));
                    398:        XmlParseError (errorParsing, msgBuffer, 0);
                    399:        result = FALSE;
                    400:       }
1.56      cvs       401:     }
                    402:   else
                    403:     if (!child)
                    404:       /* a first child is expected and it's missing */
1.124     cvs       405:       {
                    406:        sprintf (msgBuffer, "Missing subexpression in %s",
                    407:                 TtaGetElementTypeName (TtaGetElementType (el)));
                    408:        XmlParseError (errorParsing, msgBuffer, 0);
                    409:        result = FALSE;
                    410:       }
1.56      cvs       411:     else
                    412:       {
1.1       cvs       413:       elType.ElTypeNum = type1;
                    414:       childType = TtaGetElementType (child);
                    415:       if (TtaSameTypes (childType, elType) == 0)
                    416:        {
                    417:          TtaRemoveTree (child, doc);   
                    418:          new = TtaNewElement (doc, elType);
                    419:          if (prev == NULL)
                    420:            TtaInsertFirstChild (&new, el, doc);
                    421:          else
                    422:            TtaInsertSibling (new, prev, FALSE, doc);
                    423:          TtaInsertFirstChild (&child, new, doc);
                    424:          CreatePlaceholders (child, doc);
                    425:          child = new;
                    426:        }
1.56      cvs       427:       prev = child;
                    428:       TtaNextSibling (&child);
1.95      cvs       429:       NextNotComment (&child, &prev);
1.56      cvs       430:       if (type2 == 0)
                    431:         {
                    432:         if (child)
                    433:           /* this second child is not expected, error */
1.124     cvs       434:          {
                    435:            sprintf (msgBuffer, "Only 1 subexpression allowed in %s",
                    436:                     TtaGetElementTypeName (TtaGetElementType (el)));
                    437:            XmlParseError (errorParsing, msgBuffer, 0);
                    438:            result = FALSE;
                    439:          }
1.56      cvs       440:         }
                    441:       else
1.1       cvs       442:        {
1.56      cvs       443:          if (!child)
                    444:            /* a second child is expected and it's missing */
1.124     cvs       445:            {
                    446:              sprintf (msgBuffer, "2 subexpressions required in %s",
                    447:                       TtaGetElementTypeName (TtaGetElementType (el)));
                    448:              XmlParseError (errorParsing, msgBuffer, 0);
                    449:              result = FALSE;
                    450:            }
1.56      cvs       451:          else
1.1       cvs       452:            {
                    453:              elType.ElTypeNum = type2;
                    454:              childType = TtaGetElementType (child);
                    455:              if (TtaSameTypes (childType, elType) == 0)
                    456:                {
                    457:                  TtaRemoveTree (child, doc);
                    458:                  new = TtaNewElement (doc, elType);
                    459:                  TtaInsertSibling (new, prev, FALSE, doc);
                    460:                  TtaInsertFirstChild (&child, new, doc);
                    461:                  CreatePlaceholders (child, doc);
                    462:                  child = new;
                    463:                }
1.56      cvs       464:              prev = child;
                    465:              TtaNextSibling (&child);
1.95      cvs       466:              NextNotComment (&child, &prev);
1.56      cvs       467:              if (type3 == 0)
1.1       cvs       468:                {
1.56      cvs       469:                if (child)
                    470:                  /* this third child is not expected, error */
1.124     cvs       471:                  {
                    472:                    sprintf (msgBuffer, "Only 2 subexpressions allowed in %s",
                    473:                             TtaGetElementTypeName (TtaGetElementType (el)));
                    474:                    XmlParseError (errorParsing, msgBuffer, 0);
                    475:                    result = FALSE;
                    476:                  }
1.56      cvs       477:                }
                    478:              else
                    479:                {
                    480:                  if (!child)
                    481:                    /* a third child is expected and it's missing */
1.124     cvs       482:                    {
                    483:                      sprintf (msgBuffer, "3 subexpressions required in %s",
                    484:                               TtaGetElementTypeName (TtaGetElementType (el)));
                    485:                      XmlParseError (errorParsing, msgBuffer, 0);
                    486:                      result = FALSE;
                    487:                    }
1.56      cvs       488:                  else
1.1       cvs       489:                    {
                    490:                      elType.ElTypeNum = type3;
                    491:                      childType = TtaGetElementType (child);
                    492:                      if (TtaSameTypes (childType, elType) == 0)
                    493:                        {
                    494:                          TtaRemoveTree (child, doc);
                    495:                          new = TtaNewElement (doc, elType);
                    496:                          TtaInsertSibling (new, prev, FALSE, doc);
                    497:                          TtaInsertFirstChild (&child, new, doc);
                    498:                          CreatePlaceholders (child, doc);
1.56      cvs       499:                          child = new;
1.1       cvs       500:                        }
                    501:                    }
1.56      cvs       502:                  prev = child;
                    503:                  TtaNextSibling (&child);
1.95      cvs       504:                  NextNotComment (&child, &prev);
1.56      cvs       505:                  if (child)
                    506:                    /* this fourth child is unexpected */
1.124     cvs       507:                    {
                    508:                      sprintf (msgBuffer,"Only 3 subexpressions allowed in %s",
                    509:                               TtaGetElementTypeName (TtaGetElementType (el)));
                    510:                      XmlParseError (errorParsing, msgBuffer, 0);
                    511:                      result = FALSE;
                    512:                    }
1.1       cvs       513:                }
                    514:            }
                    515:         }
1.56      cvs       516:       }
                    517:   return result;
1.1       cvs       518: }
                    519: 
                    520: /*----------------------------------------------------------------------
1.22      cvs       521:    SetSingleIntHorizStretchAttr
1.1       cvs       522: 
1.22      cvs       523:    Put a IntHorizStretch attribute on element el if it contains only
1.1       cvs       524:    a MO element that is a stretchable symbol.
                    525:  -----------------------------------------------------------------------*/
1.22      cvs       526: void SetSingleIntHorizStretchAttr (Element el, Document doc, Element* selEl)
1.1       cvs       527: {
                    528:   Element      child, sibling, textEl, symbolEl;
1.152     quint     529:   ElementType  elType, childType, siblingType;
1.1       cvs       530:   Attribute    attr;
                    531:   AttributeType        attrType;
1.55      cvs       532:   Language     lang;
1.128     vatton    533:   CHAR_T        text[2];
1.143     vatton    534:   char         script;
1.49      cvs       535:   unsigned char c;
1.128     vatton    536:   int          len;
1.152     quint     537:   ThotBool      doit;
1.1       cvs       538: 
                    539:   if (el == NULL)
                    540:      return;
                    541:   child = TtaGetFirstChild (el);
1.154     vatton    542:   textEl = NULL;
1.55      cvs       543:   if (child)
1.1       cvs       544:      {
                    545:      elType = TtaGetElementType (child);
1.162     quint     546:      /* skip empty Constructs (placeholders) and comments */
                    547:      while (child &&
                    548:            (elType.ElTypeNum == MathML_EL_Construct ||
                    549:             elType.ElTypeNum == MathML_EL_XMLcomment) &&
                    550:            !strcmp (TtaGetSSchemaName (elType.ElSSchema), "MathML"))
1.152     quint     551:        {
                    552:         TtaNextSibling (&child);
                    553:         if (child)
                    554:           elType = TtaGetElementType (child);
                    555:        }
1.162     quint     556:      while (child && elType.ElTypeNum == MathML_EL_MROW &&
                    557:            strcmp (TtaGetSSchemaName (elType.ElSSchema), "MathML") == 0)
                    558:         /* the first significant child is a mrow. Check whether it has a
                    559:           single child */
1.98      cvs       560:         {
                    561:         child = TtaGetFirstChild (child);
                    562:        if (child)
                    563:          {
1.152     quint     564:            elType = TtaGetElementType (child);
1.162     quint     565:            /* skip empty Constructs (placeholders) and comments */
                    566:            while (child &&
                    567:                   (elType.ElTypeNum == MathML_EL_Construct ||
                    568:                    elType.ElTypeNum == MathML_EL_XMLcomment) &&
                    569:                   !strcmp (TtaGetSSchemaName (elType.ElSSchema), "MathML"))
1.152     quint     570:              {
1.162     quint     571:                TtaNextSibling (&child);
                    572:                if (child)
                    573:                  elType = TtaGetElementType (child);
1.152     quint     574:              }
1.98      cvs       575:            sibling = child;
                    576:            TtaNextSibling (&sibling);
1.152     quint     577:            if (sibling)
                    578:              /* there are other children */
                    579:              {
                    580:              siblingType = TtaGetElementType (sibling);
1.162     quint     581:              while (sibling &&
                    582:                     (siblingType.ElTypeNum == MathML_EL_Construct ||
                    583:                      siblingType.ElTypeNum == MathML_EL_XMLcomment) &&
                    584:                     !strcmp (TtaGetSSchemaName (siblingType.ElSSchema), "MathML"))
                    585:                /* its an empty construct (placeholder) or a comment, skip it*/
                    586:                {
                    587:                  TtaNextSibling (&sibling);
                    588:                  if (sibling)
                    589:                    siblingType = TtaGetElementType (sibling);
                    590:                }
1.152     quint     591:              if (sibling)
1.162     quint     592:                /* there are significant siblings */
1.152     quint     593:                child = NULL;
                    594:              }
1.98      cvs       595:          }
                    596:        }
1.152     quint     597:      if (child && (elType.ElTypeNum == MathML_EL_MO ||
                    598:                   elType.ElTypeNum == MathML_EL_MOVER ||
                    599:                   elType.ElTypeNum == MathML_EL_MUNDER))
                    600:        /* the first child is a MO, a MUNDER or a MOVER */
1.1       cvs       601:         {
                    602:         sibling = child;
                    603:         TtaNextSibling (&sibling);
1.152     quint     604:        if (sibling)
1.162     quint     605:          siblingType = TtaGetElementType (sibling);
                    606:        /* skip empty Constructs (placeholders) and comments */
                    607:        while (sibling &&
                    608:               (siblingType.ElTypeNum == MathML_EL_Construct ||
                    609:                siblingType.ElTypeNum == MathML_EL_XMLcomment) &&
                    610:               !strcmp (TtaGetSSchemaName (siblingType.ElSSchema), "MathML"))
1.152     quint     611:          {
1.162     quint     612:            TtaNextSibling (&sibling);
                    613:            if (sibling)
                    614:              siblingType = TtaGetElementType (sibling);
1.152     quint     615:          }
1.1       cvs       616:        if (sibling == NULL)
1.162     quint     617:           /* there is no other significant child */
1.1       cvs       618:           {
1.152     quint     619:           c = EOS;
                    620:           doit = FALSE;
                    621:           attrType.AttrSSchema = elType.ElSSchema;
                    622:           attrType.AttrTypeNum = MathML_ATTR_IntHorizStretch;
                    623: 
                    624:           if (elType.ElTypeNum == MathML_EL_MOVER ||
                    625:               elType.ElTypeNum == MathML_EL_MUNDER)
                    626:             /* check if the UnderOverBase has a IntHorizStretch attribute */
                    627:             {
                    628:               childType.ElTypeNum = MathML_EL_UnderOverBase;
1.172     cheyroul  629:                   childType.ElSSchema = elType.ElSSchema;
1.152     quint     630:               textEl = TtaSearchTypedElement (childType, SearchInTree, child);
                    631:               if (textEl)
                    632:                 {
                    633:                   if (TtaGetAttribute (textEl, attrType))
                    634:                     doit = TRUE;
                    635:                  }
                    636:             }
                    637:           else if (elType.ElTypeNum == MathML_EL_MO)
                    638:             {
                    639:             textEl = TtaGetFirstChild (child);
                    640:             childType = TtaGetElementType (textEl);
                    641:             if (childType.ElTypeNum == MathML_EL_TEXT_UNIT)
                    642:               /* the MO child contains a TEXT element */
                    643:               {
                    644:               len = TtaGetElementVolume (textEl);
                    645:               if (len == 1)
1.123     cvs       646:                 /* the TEXT element contains a single character */
                    647:                 {
1.152     quint     648:                   /* get that character */
                    649:                   len = 2;
                    650:                   TtaGiveBufferContent (textEl, text, len, &lang);
                    651:                   script = TtaGetScript (lang);
                    652:                   if (
1.146     quint     653: #ifndef _I18N_
1.152     quint     654:                       (script == 'L') &&
1.146     quint     655: #endif
1.152     quint     656:                       (text[0] == '-' || text[0] == '_' ||
                    657:                        text[0] == 175))
1.146     quint     658:                     /* a horizontal line in the middle of the box */
                    659:                     c = 'h'; 
1.152     quint     660:                   else 
                    661: #ifdef _I18N_
                    662:                     if (text[0] == 0x2190)
                    663:                       c = 'L';  /* arrow left */
                    664:                     else if (text[0] == 0x2192)
                    665:                       c = 'R';  /* arrow right */
1.153     quint     666:                     else if (text[0] == 45)        /* - (minus) */
                    667:                       /* a horizontal line in the middle of the box */
                    668:                       c = 'h'; 
                    669:                     else if (text[0] == 0x2212)    /* - (minus) */
1.152     quint     670:                       /* a horizontal line in the middle of the box */
                    671:                       c = 'h'; 
                    672:                     else if (text[0] == 0x0332)    /* UnderBar */
                    673:                       /* a horizontal line */
                    674:                       c = 'h'; 
                    675:                     else if (text[0] == 65079)
                    676:                       c = 'o';  /* Over brace */
                    677:                     else if (text[0] == 65080)
                    678:                       c = 'u';  /* Under brace */
1.146     quint     679: #else
                    680:                   if (script == 'G')
                    681:                     /* a single Symbol character */
                    682:                     {
                    683:                       if (text[0] == 172)
                    684:                         c = 'L';  /* arrow left */
                    685:                       else if (text[0] == 174)
                    686:                         c = 'R';  /* arrow right */
                    687:                       else if (text[0] == 45)    /* - (minus) */
                    688:                         /* a horizontal line in the middle of the box */
                    689:                         c = 'h'; 
                    690:                       else if (text[0] == 132)
                    691:                         c = 'o';  /* Over brace */
                    692:                       else if (text[0] == 133)
                    693:                         c = 'u';  /* Under brace */
                    694:                     }
                    695: #endif
1.152     quint     696:                   if (c != EOS)
                    697:                     doit = TRUE;
1.123     cvs       698:                 }
1.152     quint     699:               }
                    700:             }
                    701:           if (doit)
                    702:             {
                    703:               /* attach a IntHorizStretch attribute to the element
                    704:                  (UnderOverBase, Underscript, or Overscript) */
                    705:               attr = TtaNewAttribute (attrType);
                    706:               TtaAttachAttribute (el, attr, doc);
                    707:               TtaSetAttributeValue (attr, MathML_ATTR_IntHorizStretch_VAL_yes_, el, doc);
                    708:               attr = TtaNewAttribute (attrType);
                    709:               TtaAttachAttribute (child, attr, doc);
                    710:               TtaSetAttributeValue (attr, MathML_ATTR_IntHorizStretch_VAL_yes_, child, doc);
                    711:             }
                    712:           if (c != EOS)
                    713:             {
                    714:               /* replace the TEXT element by a Thot SYMBOL element */
                    715:               childType.ElTypeNum = MathML_EL_SYMBOL_UNIT;
                    716:               symbolEl = TtaNewElement (doc, childType);
                    717:               TtaInsertSibling (symbolEl, textEl, FALSE, doc);
                    718:               if (selEl != NULL)
                    719:                 if (*selEl == textEl)
                    720:                   *selEl = symbolEl;
                    721:               TtaDeleteTree (textEl, doc);
                    722:               if (c != EOS)
                    723:                 TtaSetGraphicsShape (symbolEl, c, doc);
                    724:             }
1.1       cvs       725:           }
                    726:        }
                    727:      }
                    728: }
1.162     quint     729: 
1.1       cvs       730: /*----------------------------------------------------------------------
1.22      cvs       731:    SetIntHorizStretchAttr
1.1       cvs       732: 
1.152     quint     733:    Put a IntHorizStretch attribute on all children of element el that
1.1       cvs       734:    contain only a MO element that is a stretchable symbol.
                    735:  -----------------------------------------------------------------------*/
1.22      cvs       736: static void SetIntHorizStretchAttr (Element el, Document doc)
1.1       cvs       737: {
                    738:   Element      child;
                    739: 
                    740:   if (el == NULL)
                    741:      return;
                    742:   child = TtaGetFirstChild (el);
                    743:   while (child != NULL)
                    744:      {
1.22      cvs       745:      SetSingleIntHorizStretchAttr (child, doc, NULL);
1.1       cvs       746:      TtaNextSibling (&child);
                    747:      }
                    748: }
                    749: 
                    750: /*----------------------------------------------------------------------
1.22      cvs       751:    SetIntVertStretchAttr
1.1       cvs       752: 
1.22      cvs       753:    Put a IntVertStretch attribute on element el if its base element
1.1       cvs       754:    (Base for a MSUBSUP, MSUP or MSUB; UnderOverBase for a MUNDEROVER,
                    755:    a MUNDER of a MOVER) contains only a MO element that is a vertically
1.162     quint     756:    stretchable symbol (integral, vertical arrow, etc).
1.1       cvs       757:  -----------------------------------------------------------------------*/
1.22      cvs       758: void SetIntVertStretchAttr (Element el, Document doc, int base, Element* selEl)
1.1       cvs       759: {
1.132     cvs       760:   Element      child, sibling, textEl, symbolEl, parent, operator, next;
1.1       cvs       761:   ElementType  elType;
                    762:   Attribute    attr;
                    763:   AttributeType        attrType;
1.131     cvs       764:   SSchema       MathMLSSchema;
1.128     vatton    765:   Language     lang;
1.143     vatton    766:   char         script;
1.131     cvs       767: #define buflen 50
                    768:   CHAR_T        text[buflen];
1.49      cvs       769:   unsigned char c;
1.131     cvs       770:   int          len, i;
1.162     quint     771:   ThotBool      inbase, stretchable;
1.1       cvs       772: 
                    773:   if (el == NULL)
1.131     cvs       774:     return;
1.1       cvs       775:   operator = NULL;
1.131     cvs       776:   inbase = FALSE;
                    777:   MathMLSSchema = TtaGetElementType(el).ElSSchema;
1.154     vatton    778:   symbolEl = parent = NULL;
1.1       cvs       779:   if (base == 0)
1.131     cvs       780:     /* it's a MO */
                    781:     {
                    782:       parent = TtaGetParent (el);
                    783:       if (parent != NULL)
1.1       cvs       784:        {
1.131     cvs       785:          /* don't process the mo if it is within a base. It will be processed
                    786:             when the enclosing construct is processed (see below) */
                    787:          elType = TtaGetElementType (parent);
                    788:          if (elType.ElSSchema != MathMLSSchema ||
                    789:              (elType.ElTypeNum != MathML_EL_Base &&
                    790:               elType.ElTypeNum != MathML_EL_UnderOverBase &&
                    791:               elType.ElTypeNum != MathML_EL_MSUBSUP &&
                    792:               elType.ElTypeNum != MathML_EL_MSUB &&
                    793:               elType.ElTypeNum != MathML_EL_MSUP &&
                    794:               elType.ElTypeNum != MathML_EL_MUNDEROVER &&
                    795:               elType.ElTypeNum != MathML_EL_MUNDER &&
1.162     quint     796:               elType.ElTypeNum != MathML_EL_MUNDEROVER &&
                    797:               elType.ElTypeNum != MathML_EL_MTD))
1.131     cvs       798:            operator = el;
1.1       cvs       799:         }
1.131     cvs       800:     }
1.1       cvs       801:   else
1.131     cvs       802:     /* it's not a MO */
                    803:     {
                    804:       /* search the Base or UnderOverBase child */
                    805:       child = TtaGetFirstChild (el);
                    806:       if (child != NULL)
1.1       cvs       807:         {
1.131     cvs       808:          elType = TtaGetElementType (child);
1.162     quint     809:          /* skip empty Constructs (placeholders) and comments */
                    810:          while (child &&
                    811:                 (elType.ElTypeNum == MathML_EL_Construct ||
                    812:                  elType.ElTypeNum == MathML_EL_XMLcomment) &&
                    813:                 elType.ElSSchema == MathMLSSchema)
                    814:            {
                    815:              TtaNextSibling (&child);
                    816:              if (child)
                    817:                elType = TtaGetElementType (child);
                    818:            }
                    819: 
1.131     cvs       820:          if (elType.ElTypeNum == base && elType.ElSSchema == MathMLSSchema)
                    821:            /* the first child is a Base or UnderOverBase */
                    822:            {
                    823:              child = TtaGetFirstChild (child);
                    824:              if (child != NULL)
                    825:                {
                    826:                  elType = TtaGetElementType (child);
1.162     quint     827:                  /* skip empty Constructs (placeholders) and comments */
                    828:                  while (child &&
                    829:                         (elType.ElTypeNum == MathML_EL_Construct ||
                    830:                          elType.ElTypeNum == MathML_EL_XMLcomment) &&
                    831:                         elType.ElSSchema == MathMLSSchema)
                    832:                    {
                    833:                      TtaNextSibling (&child);
                    834:                      if (child)
                    835:                        elType = TtaGetElementType (child);
                    836:                    }
                    837: 
1.131     cvs       838:                  if (elType.ElTypeNum == MathML_EL_MO &&
                    839:                      elType.ElSSchema == MathMLSSchema)
1.162     quint     840:                    /* its first significant child is a MO */
1.131     cvs       841:                    {
                    842:                      sibling = child;
                    843:                      TtaNextSibling (&sibling);
1.162     quint     844:                      /* skip empty Constructs (placeholders) and comments */
                    845:                      while (sibling &&
                    846:                             (elType.ElTypeNum == MathML_EL_Construct ||
                    847:                              elType.ElTypeNum == MathML_EL_XMLcomment) &&
                    848:                             elType.ElSSchema == MathMLSSchema)
                    849:                        {
                    850:                          TtaNextSibling (&sibling);
                    851:                          if (sibling)
                    852:                            elType = TtaGetElementType (sibling);
                    853:                        }
                    854: 
1.131     cvs       855:                      if (sibling == NULL)
1.162     quint     856:                        /* there is no other significant child */
1.131     cvs       857:                        {
                    858:                          operator = child;
                    859:                          if (base == MathML_EL_Base ||
                    860:                              base == MathML_EL_UnderOverBase)
                    861:                            {
                    862:                              parent = el;
                    863:                              inbase = TRUE;
                    864:                            }
                    865:                        }
                    866:                    }
                    867:                }
                    868:            }
1.1       cvs       869:        }
1.131     cvs       870:     }
                    871:   if (operator)
                    872:     {
                    873:       textEl = TtaGetFirstChild (operator);
                    874:       if (textEl != NULL)
1.84      cvs       875:         {
1.131     cvs       876:          elType = TtaGetElementType (textEl);
                    877:          if (elType.ElTypeNum == MathML_EL_TEXT_UNIT)
                    878:            {
1.146     quint     879:              len = TtaGetElementVolume (textEl);
1.131     cvs       880:              if (len >= 1)
                    881:                {
                    882:                  if (len >= buflen)
                    883:                    len = buflen-1;
1.146     quint     884:                  TtaGiveBufferContent (textEl, text, len+1, &lang);
1.143     vatton    885:                  script = TtaGetScript (lang);
1.146     quint     886: #ifdef _I18N_
1.162     quint     887:                  stretchable = TRUE;
1.146     quint     888:                  for (i = 0; i < len; i++)
1.162     quint     889:                    if ((text[i] < 0x222B || text[i] > 0x2233) &&
                    890:                        text[i] != 0x2191 && text[i] != 0x2193 &&
                    891:                        text[i] != 0x2195 &&
                    892:                        text[i] != 0x21D1 && text[i] != 0x21D3 &&
                    893:                        text[i] != 0x21D5)
1.146     quint     894:                      /* accept only symbols like simple integral, double or
1.162     quint     895:                         triple integral, contour integral, etc. or vertical
                    896:                         arrows (add more arrows *****) */
                    897:                      stretchable = FALSE;
1.146     quint     898: #else
1.162     quint     899:                  stretchable = FALSE;
1.143     vatton    900:                  if (script == 'G')
1.131     cvs       901:                    /* Adobe Symbol character set */
1.55      cvs       902:                    {
1.162     quint     903:                    stretchable = TRUE;
1.131     cvs       904:                    /* check all characters in this TEXT element */
                    905:                    for (i = 0; i < len; i++)
1.162     quint     906:                      if (text[i] != 242 &&     /* integral */
                    907:                          text[i] != 173 && text[i] != 175 &&  /* arrows */
                    908:                          text[i] != 221 && text[i] != 223) /* double arrows */
1.131     cvs       909:                        /**** accept also other symbols like double or triple
                    910:                              integral, contour integral, etc. ****/
1.162     quint     911:                        stretchable = FALSE;
1.146     quint     912:                    }
                    913: #endif
1.162     quint     914:                  if (stretchable)
                    915:                    /* the operator contains only stretchable symbols */
1.146     quint     916:                    {
                    917:                      /* attach a IntVertStretch attribute */
                    918:                      attrType.AttrSSchema = MathMLSSchema;
                    919:                      attrType.AttrTypeNum = MathML_ATTR_IntVertStretch;
                    920:                      attr = TtaNewAttribute (attrType);
                    921:                      TtaAttachAttribute (el, attr, doc);
                    922:                      TtaSetAttributeValue (attr,
1.131     cvs       923:                                           MathML_ATTR_IntVertStretch_VAL_yes_,
                    924:                                           el, doc);
1.146     quint     925:                      TtaRegisterAttributeCreate (attr, el, doc);
                    926:                      
1.162     quint     927:                      /* replace the stretchable characters by a Thot SYMBOL
1.146     quint     928:                         element. If there are several such characters in
1.162     quint     929:                         the mo (multiple integral for instance), replace
                    930:                         them too. */
1.146     quint     931:                      do
                    932:                        {
                    933:                          /* replace the TEXT element by a Thot SYMBOL */
1.162     quint     934:                          elType.ElSSchema = MathMLSSchema;
1.146     quint     935:                          elType.ElTypeNum = MathML_EL_SYMBOL_UNIT;
                    936:                          for (i = 0; i < len; i++)
1.162     quint     937:                            {
                    938:                              if (selEl != NULL)
                    939:                                if (*selEl == textEl)
                    940:                                  *selEl = symbolEl;
1.173   ! vatton    941:                              c = text[i];
1.146     quint     942: #ifdef _I18N_
1.162     quint     943:                              if (text[i] == 0x222B)
                    944:                                c = 'i';
                    945:                              else if (text[i] == 0x222C)
                    946:                                c = 'd';
                    947:                              else if (text[i] == 0x222D)
                    948:                                c = 't';
                    949:                              else if (text[i] == 0x222E)
                    950:                                c = 'c';
                    951:                              else if (text[i] == 0x2191)
                    952:                                c = '^';
                    953:                              else if (text[i] == 0x2193)
                    954:                                c = 'V';
1.173   ! vatton    955: #else /*_I18N_ */
1.162     quint     956:                              if (text[i] == 242)
                    957:                                c = 'i';
                    958:                              else if (text[i] == 173)
                    959:                                c = '<';
                    960:                              else if (text[i] == 175)
                    961:                                c = '>';
1.173   ! vatton    962: #endif /*_I18N_ */
1.162     quint     963:                              symbolEl = TtaNewElement (doc, elType);
                    964:                              TtaInsertSibling (symbolEl, textEl, TRUE,doc);
                    965:                              TtaSetGraphicsShape (symbolEl, c, doc);
                    966:                              TtaRegisterElementCreate (symbolEl, doc);
                    967:                            }
1.146     quint     968:                          TtaRegisterElementDelete (textEl, doc);
                    969:                          TtaDeleteTree (textEl, doc);
                    970:                          /* is there an other text element after the
1.162     quint     971:                             stretchable symbol? */
1.146     quint     972:                          textEl = symbolEl; TtaNextSibling (&textEl);
                    973:                          if (textEl)
                    974:                            {
                    975:                              elType = TtaGetElementType (textEl);
                    976:                              if (elType.ElTypeNum != MathML_EL_TEXT_UNIT)
                    977:                                textEl = NULL;
                    978:                              else
                    979:                                /* there is another text element.
1.162     quint     980:                                   Is it a single stretchable symbol? */
1.146     quint     981:                                {
                    982:                                  len = TtaGetElementVolume (textEl);
                    983:                                  if (len < 1)
                    984:                                    /* not a single character */
                    985:                                    textEl = NULL;
                    986:                                  else
                    987:                                    {
                    988:                                      if (len >= buflen)
                    989:                                        len = buflen-1;
                    990:                                      TtaGiveBufferContent (textEl, text,
                    991:                                                            len+1, &lang); 
                    992:                                      script = TtaGetScript (lang);
                    993: #ifdef _I18N_
1.164     quint     994:                                      if (text[0] != 0x222B &&
                    995:                                          text[0] != 0x222C &&
                    996:                                          text[0] != 0x222D &&
                    997:                                          text[0] != 0x222E &&
                    998:                                          text[0] != 0x2191 &&
                    999:                                          text[0] != 0x2193)
1.173   ! vatton   1000: #else /*_I18N_ */
1.162     quint    1001:                                      if (script != 'G' ||
1.164     quint    1002:                                          (text[0] != 242 && text[0] != 173 &&
                   1003:                                           text[0] != 175))
1.173   ! vatton   1004: #endif /*_I18N_ */
1.162     quint    1005:                                        /* not a stretchable symbol */
1.146     quint    1006:                                        textEl = NULL;
                   1007:                                    }
                   1008:                                }
                   1009:                            }
                   1010:                        }
                   1011:                      while (textEl);
                   1012:                      
                   1013:                      if (inbase)
                   1014:                        /* it's within a Base or UnderOverBase element */
                   1015:                        {
                   1016:                          sibling = parent;
                   1017:                          TtaNextSibling (&sibling);
                   1018:                          if (sibling)
                   1019:                            /* the msubsup of munderover element has a next
                   1020:                               sibling */
                   1021:                            {
                   1022:                              elType = TtaGetElementType (sibling);
                   1023:                              if (elType.ElTypeNum == MathML_EL_Construct &&
                   1024:                                  elType.ElSSchema == MathMLSSchema)
                   1025:                                /* the next sibling is a Construct */
                   1026:                                {
                   1027:                                  next = sibling;
                   1028:                                  TtaNextSibling (&next);
                   1029:                                  if (!next)
                   1030:                                    /* there is no other sibling after the
                   1031:                                       Construct. Change it into Construct1*/
                   1032:                                    {
                   1033:                                      TtaRegisterElementDelete (sibling, doc);
                   1034:                                      TtaRemoveTree (sibling, doc);
                   1035:                                      ChangeElementType (sibling,
1.132     cvs      1036:                                                         MathML_EL_Construct1);
1.146     quint    1037:                                      TtaInsertSibling (sibling, parent,
                   1038:                                                        FALSE, doc);
                   1039:                                      TtaRegisterElementCreate (sibling, doc);
                   1040:                                      /* force the msubsup element to be
                   1041:                                         reformatted and to take into account
                   1042:                                         its new next sibling */
                   1043:                                      TtaRemoveTree (parent, doc);
                   1044:                                      TtaInsertSibling (parent, sibling, TRUE,
                   1045:                                                        doc);
                   1046:                                    }
                   1047:                                }
                   1048:                            }
                   1049:                        } 
1.55      cvs      1050:                    }
1.131     cvs      1051:                }
                   1052:            }
1.84      cvs      1053:        }
1.131     cvs      1054:     }
1.1       cvs      1055: }
                   1056: 
                   1057: /*----------------------------------------------------------------------
1.169     quint    1058:    SetIntMovelimitsAttr
                   1059:    Put a IntMovelimits attribute on element el (which is a munder, mover
                   1060:    or munderover) if the current value of IntDisplaystyle is false and
                   1061:    if el contains a MO element that allows limits to be moved.
                   1062:  -----------------------------------------------------------------------*/
                   1063: void SetIntMovelimitsAttr (Element el, Document doc)
                   1064: {
                   1065:   Element      ancestor, child, base, operator, textEl;
                   1066:   int           value, len;
                   1067:   ElementType   elType;
                   1068:   AttributeType attrType;
                   1069:   Attribute     attr;
                   1070:   Language      lang;
                   1071:   CHAR_T        text[10];
                   1072:   char          buffer[20];
                   1073:   ThotBool      movable;
                   1074: #ifndef _I18N_
                   1075:   char          script;
                   1076: #endif
                   1077: 
                   1078:   if (el == NULL || doc == 0)
                   1079:      return;
                   1080:   movable = FALSE;
                   1081: 
                   1082:   /* first look for an IntDisplaystyle attribute on an ancestor */
                   1083:   elType = TtaGetElementType (el);
                   1084:   attrType.AttrSSchema = elType.ElSSchema;
                   1085:   attrType.AttrTypeNum = MathML_ATTR_IntDisplaystyle;
                   1086:   ancestor = el;
                   1087:   do
                   1088:     {
                   1089:       attr = TtaGetAttribute (ancestor, attrType);
                   1090:       if (!attr)
                   1091:         ancestor = TtaGetParent(ancestor);
                   1092:     }
                   1093:   while (!attr && ancestor);
                   1094:   if (attr)
                   1095:     /* there is an ancestor with an attribute IntDisplaystyle */
                   1096:     {
                   1097:       value = TtaGetAttributeValue (attr);
                   1098:       if (value == MathML_ATTR_IntDisplaystyle_VAL_false)
                   1099:        /* an ancestor has an attribute IntDisplaystyle = false */
                   1100:        {
                   1101:          /* Check the operator within the base */
                   1102:          child = TtaGetFirstChild (el);
                   1103:          base = NULL;
                   1104:          do
                   1105:            {
                   1106:              elType = TtaGetElementType (child);
                   1107:              if (elType.ElTypeNum == MathML_EL_UnderOverBase)
                   1108:                base = child;
                   1109:              else
                   1110:                TtaNextSibling (&child);
                   1111:            }
                   1112:          while (child && !base);
                   1113:          if (base)
                   1114:            {
                   1115:              child = TtaGetFirstChild (base);
                   1116:              operator = NULL;
                   1117:              do
                   1118:                {
                   1119:                  elType = TtaGetElementType (child);
                   1120:                  if (elType.ElTypeNum == MathML_EL_MO)
                   1121:                    operator = child;
                   1122:                  else
                   1123:                    TtaNextSibling (&child);
                   1124:                }
                   1125:              while (child && !operator);
                   1126:              if (operator)
                   1127:                {
                   1128:                  attrType.AttrTypeNum = MathML_ATTR_movablelimits;
                   1129:                  attr = TtaGetAttribute (operator, attrType);
                   1130:                  if (attr)
                   1131:                    /* the operator has an attribute movablelimits */
                   1132:                    {
                   1133:                      value = TtaGetAttributeValue (attr);
                   1134:                      if (value == MathML_ATTR_movablelimits_VAL_true)
                   1135:                        movable = TRUE;
                   1136:                    }
                   1137:                  else
                   1138:                    /* no attribute movablelimits. Look at the content of the
                   1139:                       operator element */
                   1140:                    {
                   1141:                      textEl = TtaGetFirstChild (operator);
                   1142:                      if (textEl)
                   1143:                        {
                   1144:                          elType = TtaGetElementType (textEl);
                   1145:                          if (elType.ElTypeNum == MathML_EL_TEXT_UNIT)
                   1146:                            {
                   1147:                              len = TtaGetElementVolume (textEl);
                   1148:                              if (len == 3)
                   1149:                                {
                   1150:                                  TtaGiveTextContent (textEl, buffer, &len, &lang);
                   1151: #ifndef _I18N_
                   1152:                                  script = TtaGetScript (lang);
                   1153:                                  if (script == 'L')
                   1154: #endif
                   1155:                                    {
                   1156:                                      if (!strcmp (buffer, "lim") ||
                   1157:                                          !strcmp (buffer, "max") ||
                   1158:                                          !strcmp (buffer, "min"))
                   1159:                                        movable = TRUE;
                   1160:                                    }
                   1161:                                }
                   1162:                              else if (len == 1)
                   1163:                                {
                   1164:                                  TtaGiveBufferContent (textEl, text, len+1, &lang);
                   1165: #ifdef _I18N_
                   1166:                                  if (text[0] == 0x22C1 /* Vee */ ||
                   1167:                                      text[0] == 0x2296 /* CircleMinus */ ||
                   1168:                                      text[0] == 0x2295 /* CirclePlus */ ||
                   1169:                                      text[0] == 0x2211 /* Sum */ ||
                   1170:                                      text[0] == 0x22C3 /* Union */ ||
                   1171:                                      text[0] == 0x228E /* UnionPlus */ ||
                   1172:                                      text[0] == 0x22C0 /* Wedge */ ||
                   1173:                                      text[0] == 0x2297 /* CircleTimes */ ||
                   1174:                                      text[0] == 0x2210 /* Coproduct */ ||
                   1175:                                      text[0] == 0x220F /* Product */ ||
                   1176:                                      text[0] == 0x22C2 /* Intersection */ ||
                   1177:                                      text[0] == 0x2299 /* CircleDot */ )
                   1178:                                    movable = TRUE;
                   1179: #else
                   1180:                                  script = TtaGetScript (lang);
                   1181:                                  if (script == 'G')
                   1182:                                    /* Adobe Symbol character set */
                   1183:                                    if (text[0] == 197 || text[0] == 229 ||
                   1184:                                        text[0] == 200 || text[0] == 196 ||
                   1185:                                        text[0] == 213 || text[0] == 199)
                   1186:                                      movable = TRUE;
                   1187: #endif
                   1188:                                }
                   1189:                            }
                   1190:                        }
                   1191:                    }
                   1192:                }
                   1193:            }
                   1194:        }
                   1195:     }
                   1196: 
                   1197:   attrType.AttrTypeNum = MathML_ATTR_IntMovelimits;
                   1198:   attr = TtaGetAttribute (el, attrType);
                   1199:   if (movable)
                   1200:     {
                   1201:       if (!attr)
                   1202:        {
                   1203:          attr = TtaNewAttribute (attrType);
                   1204:          TtaAttachAttribute (el, attr, doc);
                   1205:        }
                   1206:       TtaSetAttributeValue (attr, MathML_ATTR_IntMovelimits_VAL_yes_, el, doc);
                   1207:     }
                   1208:   else if (attr)
                   1209:     TtaRemoveAttribute (el, attr, doc);
                   1210: }
                   1211: 
                   1212: /*----------------------------------------------------------------------
1.22      cvs      1213:    SetIntPlaceholderAttr
1.1       cvs      1214: 
1.22      cvs      1215:    Put a IntPlaceholder attribute on all Construct elements in the
1.1       cvs      1216:    subtree of root el.
                   1217:  -----------------------------------------------------------------------*/
1.22      cvs      1218: static void SetIntPlaceholderAttr (Element el, Document doc)
1.1       cvs      1219: {
                   1220:   Element      child;
                   1221:   ElementType  elType;
                   1222:   Attribute    attr;
                   1223:   AttributeType        attrType;
                   1224: 
                   1225:   if (el == NULL)
                   1226:      return;
                   1227:   elType = TtaGetElementType (el);
                   1228:   if (elType.ElTypeNum == MathML_EL_Construct &&
1.2       cvs      1229:       elType.ElSSchema == GetMathMLSSchema (doc))
1.1       cvs      1230:      {
                   1231:      attrType.AttrSSchema = elType.ElSSchema;
1.22      cvs      1232:      attrType.AttrTypeNum = MathML_ATTR_IntPlaceholder;
1.1       cvs      1233:      attr = TtaNewAttribute (attrType);
                   1234:      TtaAttachAttribute (el, attr, doc);
1.22      cvs      1235:      TtaSetAttributeValue (attr, MathML_ATTR_IntPlaceholder_VAL_yes_, el, doc);
1.1       cvs      1236:      }
                   1237:   else
                   1238:      {
                   1239:      child = TtaGetFirstChild (el);
                   1240:      while (child != NULL)
                   1241:         {
1.22      cvs      1242:         SetIntPlaceholderAttr (child, doc);
1.1       cvs      1243:         TtaNextSibling (&child);
                   1244:         }
                   1245:      }
                   1246: }
                   1247: 
                   1248: /*----------------------------------------------------------------------
                   1249:    BuildMultiscript
                   1250: 
                   1251:    The content of a MMULTISCRIPT element has been created following
                   1252:    the original MathML structure.  Create all Thot elements defined
                   1253:    in the MathML S schema.
                   1254:  -----------------------------------------------------------------------*/
                   1255: static void BuildMultiscript (Element elMMULTISCRIPT, Document doc)
                   1256: {
                   1257:   Element      elem, base, next, group, pair, script, prevPair, prevScript;
                   1258:   ElementType  elType, elTypeGroup, elTypePair, elTypeScript;
1.2       cvs      1259:   SSchema       MathMLSSchema;
1.1       cvs      1260:   base = NULL;
                   1261:   group = NULL;
                   1262:   prevPair = NULL;
                   1263:   prevScript = NULL;
                   1264: 
1.2       cvs      1265:   MathMLSSchema = GetMathMLSSchema (doc);
1.1       cvs      1266:   elTypeGroup.ElSSchema = MathMLSSchema;
                   1267:   elTypePair.ElSSchema = MathMLSSchema;
                   1268:   elTypeScript.ElSSchema = MathMLSSchema;
                   1269: 
                   1270:   /* process all children of the MMULTISCRIPT element */
                   1271:   elem = TtaGetFirstChild (elMMULTISCRIPT);
                   1272:   while (elem != NULL)
                   1273:     {
                   1274:       /* remember the element to be processed after the current one */
                   1275:       next = elem;
                   1276:       TtaNextSibling (&next);
                   1277: 
                   1278:       /* remove the current element from the tree */
                   1279:       TtaRemoveTree (elem, doc);
                   1280: 
                   1281:       if (base == NULL)
                   1282:        /* the current element is the first child of the MMULTISCRIPT
                   1283:           element */
                   1284:        {
                   1285:          /* Create a MultiscriptBase element as the first child of
                   1286:             MMULTISCRIPT and move the current element as the first child
                   1287:             of the MultiscriptBase element */
                   1288:          elTypeGroup.ElTypeNum = MathML_EL_MultiscriptBase;
                   1289:          base = TtaNewElement (doc, elTypeGroup);
                   1290:          TtaInsertFirstChild (&base, elMMULTISCRIPT, doc);
                   1291:          TtaInsertFirstChild (&elem, base, doc);
                   1292:        }
                   1293:       else
                   1294:        /* the current element is a subscript or a superscript */
                   1295:        {
                   1296:          if (group == NULL)
                   1297:            /* there is no PostscriptPairs element. Create one */
                   1298:            {
                   1299:              elTypeGroup.ElTypeNum = MathML_EL_PostscriptPairs;
                   1300:              group = TtaNewElement (doc, elTypeGroup);
                   1301:              TtaInsertSibling (group, base, FALSE, doc);
                   1302:              elTypePair.ElTypeNum = MathML_EL_PostscriptPair;
                   1303:              /* create a first and a last PostscriptPair as placeholders */
1.47      cvs      1304:              pair = TtaNewTree (doc, elTypePair, "");
1.1       cvs      1305:              TtaInsertFirstChild (&pair, group, doc);
1.22      cvs      1306:              SetIntPlaceholderAttr (pair, doc);
1.1       cvs      1307:              prevPair = pair;
1.47      cvs      1308:              pair = TtaNewTree (doc, elTypePair, "");
1.1       cvs      1309:              TtaInsertSibling (pair, prevPair, FALSE, doc);
1.22      cvs      1310:              SetIntPlaceholderAttr (pair, doc);
1.1       cvs      1311:              prevScript = NULL;
                   1312:            }
                   1313:          if (prevScript == NULL)
                   1314:            /* the current element is the first subscript or superscript
                   1315:               in a pair */
                   1316:            {
                   1317:              /* create a PostscriptPair or PrescriptPair element */
                   1318:              pair = TtaNewElement (doc, elTypePair);
                   1319:              if (prevPair == NULL)
                   1320:                TtaInsertFirstChild (&pair, group, doc);
                   1321:              else
                   1322:                TtaInsertSibling (pair, prevPair, FALSE, doc);
                   1323:              prevPair = pair;
                   1324:              /* create a MSubscript element */
                   1325:              elTypeScript.ElTypeNum = MathML_EL_MSubscript;
                   1326:              script = TtaNewElement (doc, elTypeScript);
                   1327:              TtaInsertFirstChild (&script, pair, doc);
                   1328:              prevScript = script;        
                   1329:            }
                   1330:          else
                   1331:            /* the current element is a superscript in a pair */
                   1332:            {
                   1333:              /* create a MSuperscript element */
                   1334:              elTypeScript.ElTypeNum = MathML_EL_MSuperscript;
                   1335:              script = TtaNewElement (doc, elTypeScript);
                   1336:              /* insert it as a sibling of the previous MSubscript element */
                   1337:              TtaInsertSibling (script, prevScript, FALSE, doc);
                   1338:              prevScript = NULL;          
                   1339:            }
                   1340:          /* insert the current element as a child of the new MSuperscript or
                   1341:             MSubscript element */
                   1342:          TtaInsertFirstChild (&elem, script, doc);
1.22      cvs      1343:          SetIntPlaceholderAttr (elem, doc);
1.1       cvs      1344:        }
                   1345: 
                   1346:       CreatePlaceholders (elem, doc);
                   1347: 
                   1348:       /* get next child of the MMULTISCRIPT element */
                   1349:       elem = next;
                   1350:       if (elem != NULL)
                   1351:        {
                   1352:          elType = TtaGetElementType (elem);
                   1353:          if (elType.ElSSchema == MathMLSSchema &&
                   1354:              elType.ElTypeNum == MathML_EL_PrescriptPairs)
                   1355:            /* the next element is a PrescriptPairs */
                   1356:            {
                   1357:              /* if there there is no PostscriptPairs element, create one as a
                   1358:                 placeholder */
                   1359:              if (elTypeGroup.ElTypeNum != MathML_EL_PostscriptPairs)
                   1360:                {
                   1361:                  elTypeGroup.ElTypeNum = MathML_EL_PostscriptPairs;
1.47      cvs      1362:                  group = TtaNewTree (doc, elTypeGroup, "");
1.1       cvs      1363:                  TtaInsertSibling (group, elem, TRUE, doc);
1.22      cvs      1364:                  SetIntPlaceholderAttr (group, doc);
1.1       cvs      1365:                }
                   1366:              /* the following elements will be interpreted as sub- superscripts
                   1367:                 in PrescriptPair elements, wich will be children of this
                   1368:                 PrescriptPairs element */
                   1369:              elTypeGroup.ElTypeNum = MathML_EL_PrescriptPairs;
                   1370:              elTypePair.ElTypeNum = MathML_EL_PrescriptPair;
                   1371:              group = elem;
                   1372:              /* create a first and a last PostscriptPair as placeholders */
1.47      cvs      1373:              pair = TtaNewTree (doc, elTypePair, "");
1.1       cvs      1374:              TtaInsertFirstChild (&pair, group, doc);
1.22      cvs      1375:              SetIntPlaceholderAttr (pair, doc);
1.1       cvs      1376:              prevPair = pair;
1.47      cvs      1377:              pair = TtaNewTree (doc, elTypePair, "");
1.1       cvs      1378:              TtaInsertSibling (pair, prevPair, FALSE, doc);
1.22      cvs      1379:              SetIntPlaceholderAttr (pair, doc);
1.1       cvs      1380:              prevScript = NULL;
                   1381:              TtaNextSibling (&elem);
                   1382:            }
                   1383:        }
                   1384:     }
                   1385:   /* all children of element MMULTISCRIPTS have been processed */
                   1386:   /* if the last group processed is not a PrescriptPairs element,
                   1387:      create one as a placeholder */
                   1388:   if (elTypeGroup.ElTypeNum != MathML_EL_PrescriptPairs && base != NULL)
                   1389:     {
                   1390:       elTypeGroup.ElTypeNum = MathML_EL_PrescriptPairs;
1.47      cvs      1391:       elem = TtaNewTree (doc, elTypeGroup, "");
1.1       cvs      1392:       if (group == NULL)
                   1393:        group = base;
                   1394:       TtaInsertSibling (elem, group, TRUE, doc);
1.22      cvs      1395:       SetIntPlaceholderAttr (elem, doc);
1.1       cvs      1396:     }
                   1397: }
                   1398: 
1.39      cvs      1399: /*----------------------------------------------------------------------
                   1400:    CreateWrapper
                   1401: 
                   1402:    Create an element of type wrapperType as a child of element el and
                   1403:    move all chidren of element el within the new element.
                   1404:  -----------------------------------------------------------------------*/
                   1405: static void CreateWrapper (Element el, int wrapperType, Document doc)
                   1406: {
                   1407:    Element       wrapper, child, prevChild, nextChild;
                   1408:    ElementType   elType;
                   1409: 
                   1410:    child = TtaGetFirstChild (el);
                   1411:    elType.ElSSchema = GetMathMLSSchema (doc);
                   1412:    elType.ElTypeNum = wrapperType;
                   1413:    wrapper = TtaNewElement (doc, elType);
                   1414:    TtaInsertFirstChild (&wrapper, el, doc);
                   1415:    prevChild = NULL;
                   1416:    while (child)
                   1417:      {
                   1418:        nextChild = child;
                   1419:        TtaNextSibling (&nextChild);
                   1420:        TtaRemoveTree (child, doc);
                   1421:        if (prevChild == NULL)
                   1422:         TtaInsertFirstChild (&child, wrapper, doc);
                   1423:        else
                   1424:         TtaInsertSibling (child, prevChild, FALSE, doc);
                   1425:        prevChild = child;
                   1426:        child = nextChild;
                   1427:      }
                   1428: }
1.5       cvs      1429: 
                   1430: /*----------------------------------------------------------------------
                   1431:    CheckMTable
                   1432: 
                   1433:    The content of a MTABLE element has been created following
                   1434:    the original MathML structure.  Create all Thot elements defined
                   1435:    in the MathML S schema.
1.64      cvs      1436:    If placeholder, associate an attribute IntPlaceholder with all
1.103     cvs      1437:    cells generated in the MathML table.
1.5       cvs      1438:  -----------------------------------------------------------------------*/
1.64      cvs      1439: void CheckMTable (Element elMTABLE, Document doc, ThotBool placeholder)
1.5       cvs      1440: {
                   1441:   ElementType  elType;
                   1442:   Element      MTableHead, MTableBody, row, nextRow, el, prevRow, cell,
1.103     cvs      1443:                nextCell, newMTD, firstColHead, label;
1.5       cvs      1444:   SSchema      MathMLSSchema;
                   1445: 
                   1446:   MathMLSSchema = GetMathMLSSchema (doc);
                   1447:   row = TtaGetFirstChild (elMTABLE);
                   1448: 
                   1449:   /* create a MTable_head as the first child of element MTABLE */
                   1450:   elType.ElSSchema = MathMLSSchema;
                   1451:   elType.ElTypeNum = MathML_EL_MTable_head;
                   1452:   MTableHead = TtaNewElement (doc, elType);
                   1453:   TtaInsertFirstChild (&MTableHead, elMTABLE, doc);
                   1454:   elType.ElTypeNum = MathML_EL_MColumn_head;
1.47      cvs      1455:   firstColHead = TtaNewTree (doc, elType, "");
1.5       cvs      1456:   TtaInsertFirstChild (&firstColHead, MTableHead, doc);
                   1457: 
                   1458:   /* create a MTable_body */
                   1459:   elType.ElTypeNum = MathML_EL_MTable_body;
                   1460:   MTableBody = TtaNewElement (doc, elType);
                   1461:   TtaInsertSibling (MTableBody, MTableHead, FALSE, doc);
                   1462: 
                   1463:   /* move all children of element MTABLE into the new MTable_body element
1.103     cvs      1464:      and wrap each non-MTR element in a MTR, except comments */
1.5       cvs      1465:   prevRow = NULL;
                   1466:   while (row)
                   1467:     {
                   1468:     nextRow = row;
                   1469:     TtaNextSibling (&nextRow);
                   1470:     elType = TtaGetElementType (row);
                   1471:     TtaRemoveTree (row, doc);
                   1472:     if (TtaSameSSchemas (elType.ElSSchema, MathMLSSchema) &&
                   1473:        (elType.ElTypeNum == MathML_EL_XMLcomment ||
1.101     cvs      1474:         elType.ElTypeNum == MathML_EL_MTR ||
                   1475:          elType.ElTypeNum == MathML_EL_MLABELEDTR))
1.5       cvs      1476:        {
                   1477:        if (prevRow == NULL)
                   1478:          TtaInsertFirstChild (&row, MTableBody, doc);
                   1479:        else
                   1480:          TtaInsertSibling (row, prevRow, FALSE, doc);
                   1481:        prevRow = row;
1.101     cvs      1482:        if (elType.ElTypeNum == MathML_EL_MTR ||
                   1483:           elType.ElTypeNum == MathML_EL_MLABELEDTR)
1.103     cvs      1484:         {
1.5       cvs      1485:           cell = TtaGetFirstChild (row);
1.103     cvs      1486:          if (elType.ElTypeNum == MathML_EL_MLABELEDTR)
                   1487:            /* skip the first significant child of the mlabeledtr element */
                   1488:            {
                   1489:              /* skip comments first */
                   1490:              do
                   1491:                {
                   1492:                  elType = TtaGetElementType (cell);
                   1493:                  if (TtaSameSSchemas (elType.ElSSchema, MathMLSSchema) &&
                   1494:                      elType.ElTypeNum == MathML_EL_XMLcomment)
                   1495:                    TtaNextSibling (&cell);
                   1496:                }
                   1497:              while (cell && elType.ElTypeNum == MathML_EL_XMLcomment);
                   1498:              /* skip the first element after the comments: it's a label */
                   1499:              if (cell)
                   1500:                {
1.105     cvs      1501:                  /* if it's a MTD change its type into LabelCell */
                   1502:                  if (elType.ElTypeNum == MathML_EL_MTD &&
                   1503:                      elType.ElSSchema == MathMLSSchema)
                   1504:                     ChangeElementType (cell, MathML_EL_LabelCell);
1.103     cvs      1505:                  /* wrap this element in a RowLabel element */
1.105     cvs      1506:                  /* This will allow the P schema to specify the horizontal
                   1507:                     position of the label */
1.103     cvs      1508:                  elType.ElSSchema = MathMLSSchema;
                   1509:                  elType.ElTypeNum = MathML_EL_RowLabel;
                   1510:                  label = TtaNewElement (doc, elType);
                   1511:                  TtaInsertSibling (label, cell, TRUE, doc);
                   1512:                  TtaRemoveTree (cell, doc);
                   1513:                  TtaInsertFirstChild (&cell, label, doc);
                   1514:                  cell = label;
                   1515:                  TtaNextSibling (&cell);
                   1516:                }
                   1517:            } 
                   1518:         }
1.5       cvs      1519:        else
                   1520:          cell = NULL;
                   1521:        }
                   1522:     else
1.103     cvs      1523:        /* this child is not a MTR, MLABELEDTR, or a comment.
                   1524:          In MathML 2.0, this in an error, but we try to recover by
                   1525:          creating a MTR element */
1.5       cvs      1526:        {
                   1527:        elType.ElSSchema = MathMLSSchema;
                   1528:        elType.ElTypeNum = MathML_EL_MTR;
                   1529:        el = TtaNewElement (doc, elType);
                   1530:        if (prevRow == NULL)
                   1531:          TtaInsertFirstChild (&el, MTableBody, doc);
                   1532:        else
                   1533:          TtaInsertSibling (el, prevRow, FALSE, doc);
                   1534:        TtaInsertFirstChild (&row, el, doc);
                   1535:        cell = row;
                   1536:        prevRow = el;
                   1537:        }
                   1538:     while (cell)
                   1539:       /* check all children of the current MTR element */
                   1540:       {
                   1541:       nextCell = cell;
                   1542:       TtaNextSibling (&nextCell);
                   1543:       elType = TtaGetElementType (cell);
                   1544:       if (!TtaSameSSchemas (elType.ElSSchema, MathMLSSchema) ||
                   1545:           (elType.ElTypeNum != MathML_EL_XMLcomment &&
                   1546:            elType.ElTypeNum != MathML_EL_MTD))
                   1547:         /* this is not a MTD nor a comment, create a wrapping MTD */
                   1548:          {
                   1549:         elType.ElSSchema = MathMLSSchema;
                   1550:         elType.ElTypeNum = MathML_EL_MTD;
                   1551:         newMTD = TtaNewElement (doc, elType);
                   1552:         TtaInsertSibling (newMTD, cell, TRUE, doc);
                   1553:         TtaRemoveTree (cell, doc);
                   1554:         TtaInsertFirstChild (&cell, newMTD, doc);
                   1555:         cell = newMTD;
                   1556:         }
                   1557:       if (elType.ElTypeNum == MathML_EL_MTD)
                   1558:         /* This is a MTD element. Wrap its contents with a CellWrapper */
1.162     quint    1559:        {
                   1560:          CreateWrapper (cell, MathML_EL_CellWrapper, doc);
                   1561:          SetIntHorizStretchAttr (cell, doc);
                   1562:          SetIntVertStretchAttr (cell, doc, MathML_EL_CellWrapper, NULL);
                   1563:        }
1.5       cvs      1564:       cell = nextCell;
                   1565:       }
                   1566:     row = nextRow;
                   1567:     }
1.107     cvs      1568:   CheckAllRows (elMTABLE, doc, placeholder, FALSE);
1.5       cvs      1569: }
1.12      cvs      1570: 
1.46      cvs      1571: /*----------------------------------------------------------------------
1.1       cvs      1572:    SetFontstyleAttr
                   1573:    The content of a MI element has been created or modified.
                   1574:    Create or change attribute IntFontstyle for that element accordingly.
                   1575:  -----------------------------------------------------------------------*/
                   1576: void SetFontstyleAttr (Element el, Document doc)
                   1577: {
                   1578:   ElementType  elType;
1.157     quint    1579:   AttributeType        attrType, attrType1;
1.1       cvs      1580:   Attribute    attr, IntAttr;
1.157     quint    1581:   Element       ancestor, textEl;
1.1       cvs      1582:   int          len;
1.163     quint    1583:   Language      lang;
                   1584: #ifndef _I18N_
                   1585:   char          script;
1.166     quint    1586:   char         *value;
1.163     quint    1587: #endif
1.166     quint    1588:   CHAR_T        text[2];
1.54      cvs      1589:   ThotBool      italic;
1.1       cvs      1590: 
                   1591:   if (el != NULL)
1.142     quint    1592:     {
1.157     quint    1593:       /* search the (deprecated) fontstyle attribute or the mathvariant
                   1594:          attribute on the element and its ancestors */
1.142     quint    1595:       elType = TtaGetElementType (el);
                   1596:       attrType.AttrSSchema = elType.ElSSchema;
                   1597:       attrType.AttrTypeNum = MathML_ATTR_fontstyle;
1.157     quint    1598:       attrType1.AttrSSchema = elType.ElSSchema;
                   1599:       attrType1.AttrTypeNum = MathML_ATTR_mathvariant;
                   1600:       ancestor = el;
                   1601:       attr = NULL;
                   1602:       do
                   1603:        {
                   1604:          attr = TtaGetAttribute (ancestor, attrType);
                   1605:          if (!attr)
                   1606:            attr = TtaGetAttribute (ancestor, attrType1);
                   1607:          if (!attr)
                   1608:            {
                   1609:              ancestor = TtaGetParent (ancestor);
                   1610:              if (ancestor)
                   1611:                {
                   1612:                  elType = TtaGetElementType (ancestor);
                   1613:                  if (elType.ElSSchema != attrType.AttrSSchema)
                   1614:                    /* this ancestor is not in the MathML namespace */
                   1615:                    ancestor = NULL;
                   1616:                }
                   1617:            }
                   1618:        }
                   1619:       while (ancestor && !attr);
                   1620: 
1.142     quint    1621:       attrType.AttrTypeNum = MathML_ATTR_IntFontstyle;
                   1622:       IntAttr = TtaGetAttribute (el, attrType);
                   1623:       if (attr != NULL)
1.157     quint    1624:        /* there is a fontstyle or mathvariant attribute. Remove the
                   1625:           IntFontstyle internal attribute that is not needed */
1.1       cvs      1626:        {
1.142     quint    1627:          if (IntAttr != NULL)
                   1628:            TtaRemoveAttribute (el, IntAttr, doc);
1.1       cvs      1629:        }
1.142     quint    1630:       else
1.157     quint    1631:        /* there is no fontstyle or mathvariant attribute. Create an internal
                   1632:           IntFontstyle attribute with a value that depends on the content of
                   1633:           the MI element */
1.1       cvs      1634:        {
1.142     quint    1635:          /* get content length */
                   1636:          len = TtaGetElementVolume (el);
                   1637:          if (len > 1)
                   1638:            /* put an attribute IntFontstyle = IntNormal */
                   1639:            {
                   1640:              if (IntAttr == NULL)
                   1641:                {
                   1642:                  IntAttr = TtaNewAttribute (attrType);
                   1643:                  TtaAttachAttribute (el, IntAttr, doc);
                   1644:                }
                   1645:              TtaSetAttributeValue (IntAttr,
                   1646:                                    MathML_ATTR_IntFontstyle_VAL_IntNormal,
                   1647:                                    el, doc);
                   1648:            }
                   1649:          else
                   1650:            /* MI contains a single character. Remove attribute IntFontstyle
                   1651:               if it exists, except if it's ImaginaryI, ExponentialE or
                   1652:               DifferentialD */
                   1653:            {
                   1654:              italic = TRUE;
                   1655:              textEl = TtaGetFirstChild (el);
                   1656:              if (textEl != NULL)
                   1657:                {
                   1658:                  elType = TtaGetElementType (textEl);
                   1659:                  if (elType.ElTypeNum == MathML_EL_MGLYPH)
                   1660:                    /* the content of the MI element is a MGLYPH element */
                   1661:                    /* check the length if it's alt attribute */
                   1662:                    {
                   1663:                      /* by default, use normal style */
                   1664:                      italic = FALSE;
                   1665:                      attrType.AttrTypeNum = MathML_ATTR_alt;
                   1666:                      attr = TtaGetAttribute (textEl, attrType);
                   1667:                      if (attr)
                   1668:                        /* the MGLYPH element has an alt attribute */
                   1669:                        {
                   1670:                          len = TtaGetTextAttributeLength (attr);
                   1671:                          if (len == 1)
                   1672:                            italic = TRUE;
                   1673:                        }
                   1674:                    }
1.163     quint    1675:                  else if (elType.ElTypeNum == MathML_EL_TEXT_UNIT)
1.142     quint    1676:                    {
1.166     quint    1677:                      len = TtaGetElementVolume (textEl);
1.163     quint    1678:                      if (len == 1)
1.166     quint    1679:                        /* the TEXT element contains a single character */
1.163     quint    1680:                        {
1.166     quint    1681:                          /* get that character */
                   1682:                          len = 2;
                   1683:                          TtaGiveBufferContent (textEl, text, len, &lang);
1.163     quint    1684: #ifndef _I18N_
                   1685:                          script = TtaGetScript (lang);
                   1686: #endif
                   1687:                          if (
                   1688: #ifndef _I18N_
                   1689:                              script == 'L' &&
                   1690: #endif
                   1691:                              text[0] >= '0' && text[0] <= '9')
1.166     quint    1692:                            /* that's a single digit */
1.163     quint    1693:                            italic = FALSE;
1.166     quint    1694:                          else
                   1695: #ifdef _I18N_
                   1696:                            /* is this the Unicode character for DifferentialD,
                   1697:                               ExponentialE or ImaginaryI? */
                   1698:                            if (text[0] == 0x2146 || text[0] == 0x2147 ||
                   1699:                                text[0] == 0x2148)
                   1700:                              italic = FALSE;
                   1701: #else
1.142     quint    1702:                            {
1.166     quint    1703:                            /* is there an attribute EntityName on that
                   1704:                               character? */
                   1705:                            attrType.AttrTypeNum = MathML_ATTR_EntityName;
                   1706:                            attr = TtaGetAttribute (textEl, attrType);
                   1707:                            if (attr)
                   1708:                              {
                   1709:                                len = TtaGetTextAttributeLength (attr);
                   1710:                                if (len > 0)
                   1711:                                  {
                   1712:                                    value = TtaGetMemory (len+1);
                   1713:                                    TtaGiveTextAttributeValue (attr, value, &len);
                   1714:                                    if (strcmp (&value[1], "ImaginaryI;") == 0 ||
                   1715:                                        strcmp (&value[1], "ExponentialE;") == 0 ||
                   1716:                                        strcmp (&value[1], "DifferentialD;") == 0)
                   1717:                                      italic = FALSE;
                   1718:                                    TtaFreeMemory (value);
                   1719:                                  }
                   1720:                              }
1.142     quint    1721:                            }
1.166     quint    1722: #endif
1.142     quint    1723:                        }
                   1724:                    }
                   1725:                  if (italic)
                   1726:                    {
                   1727:                      if (IntAttr != NULL)
                   1728:                        TtaRemoveAttribute (el, IntAttr, doc);
                   1729:                    }
                   1730:                  else
                   1731:                    {
                   1732:                      /* put an attribute IntFontstyle = IntNormal */
                   1733:                      if (IntAttr == NULL)
                   1734:                        {
                   1735:                          attrType.AttrTypeNum = MathML_ATTR_IntFontstyle;
                   1736:                          IntAttr = TtaNewAttribute (attrType);
                   1737:                          TtaAttachAttribute (el, IntAttr, doc);
                   1738:                        }
                   1739:                      TtaSetAttributeValue (IntAttr,
                   1740:                                        MathML_ATTR_IntFontstyle_VAL_IntNormal,
                   1741:                                        el, doc);
                   1742:                    }
                   1743:                }
                   1744:            }
1.1       cvs      1745:         }
1.142     quint    1746:     }
1.1       cvs      1747: }
                   1748: 
                   1749: /*----------------------------------------------------------------------
1.22      cvs      1750:    SetIntAddSpaceAttr
1.1       cvs      1751:    The content of a MO element has been created or modified.
1.22      cvs      1752:    Create or change attribute IntAddSpace for that element accordingly.
1.1       cvs      1753:  -----------------------------------------------------------------------*/
1.22      cvs      1754: void SetIntAddSpaceAttr (Element el, Document doc)
1.1       cvs      1755: {
                   1756:   Element      textEl, previous;
                   1757:   ElementType  elType;
                   1758:   AttributeType        attrType;
1.60      cvs      1759:   Attribute    attr, formAttr;
1.155     quint    1760:   SSchema       MathMLSSchema;
1.60      cvs      1761:   int          len, val, form;
1.146     quint    1762:   CHAR_T        text[2];
1.1       cvs      1763:   Language     lang;
1.143     vatton   1764:   char         script;
1.155     quint    1765:   ThotBool      comment;
1.1       cvs      1766: 
1.155     quint    1767:   MathMLSSchema = TtaGetElementType(el).ElSSchema;
1.60      cvs      1768:   /* get the content of the mo element */
1.1       cvs      1769:   textEl = TtaGetFirstChild (el);
1.155     quint    1770: 
                   1771:   /* skip comments if any */
                   1772:   if (textEl)
                   1773:     do
                   1774:       {
                   1775:        elType = TtaGetElementType (textEl);
                   1776:        if (TtaSameSSchemas (elType.ElSSchema, MathMLSSchema) &&
                   1777:            elType.ElTypeNum == MathML_EL_XMLcomment)
                   1778:          /* it's a comment, skip it */
                   1779:          TtaNextSibling (&textEl);
                   1780:       }
                   1781:     while (textEl && elType.ElTypeNum == MathML_EL_XMLcomment);
                   1782: 
                   1783:   if (textEl && elType.ElTypeNum == MathML_EL_TEXT_UNIT)
                   1784:     /* the mo element is not empty */
                   1785:     {
                   1786:       /* does the mo element have an IntAddSpace attribute? */
                   1787:       attrType.AttrSSchema = MathMLSSchema;
                   1788:       attrType.AttrTypeNum = MathML_ATTR_IntAddSpace;
                   1789:       attr = TtaGetAttribute (el, attrType);
                   1790:       if (attr == NULL)
1.60      cvs      1791:         /* no IntAddSpace Attr, create one */
1.1       cvs      1792:        {
1.155     quint    1793:          attr = TtaNewAttribute (attrType);
                   1794:          TtaAttachAttribute (el, attr, doc);
                   1795:        }
                   1796:       /* space on both sides by default */
                   1797:       val = MathML_ATTR_IntAddSpace_VAL_both;
                   1798:       /* does the mo element have a form attribute? */
                   1799:       attrType.AttrTypeNum = MathML_ATTR_form;
                   1800:       formAttr = TtaGetAttribute (el, attrType);
                   1801:       if (formAttr)
                   1802:        /* there is a form attribute */
                   1803:        {
                   1804:          form = TtaGetAttributeValue (formAttr);
                   1805:          switch (form)
                   1806:            {
                   1807:            case MathML_ATTR_form_VAL_prefix:
                   1808:              val = MathML_ATTR_IntAddSpace_VAL_nospace;
                   1809:              break;
                   1810:            case MathML_ATTR_form_VAL_infix:
                   1811:              val = MathML_ATTR_IntAddSpace_VAL_both;
                   1812:              break;
                   1813:            case MathML_ATTR_form_VAL_postfix:
                   1814:              val = MathML_ATTR_IntAddSpace_VAL_spaceafter;
                   1815:              break;
                   1816:            default:
                   1817:              val = MathML_ATTR_IntAddSpace_VAL_both;
                   1818:              break;
                   1819:            } 
1.1       cvs      1820:        }
1.155     quint    1821:       else
                   1822:        /* no form attribute. Analyze the content */
                   1823:        {
                   1824:          len = TtaGetElementVolume (textEl);
                   1825:          if (len == 1)
                   1826:            {
                   1827:              TtaGiveBufferContent (textEl, text, len+1, &lang);
                   1828:              script = TtaGetScript (lang);
                   1829:              /* the mo element contains a single character */
1.146     quint    1830: #ifndef _I18N_
1.155     quint    1831:              if (script == 'L')
                   1832:                /* ISO-Latin 1 character */
                   1833:                {
1.146     quint    1834: #endif
1.155     quint    1835:                  if (text[0] == '-'
1.153     quint    1836: #ifdef _I18N_
1.155     quint    1837:                      || text[0] == 0x2212   /* minus */
1.153     quint    1838: #endif
1.155     quint    1839:                      )
                   1840:                    /* prefix or infix operator? */
                   1841:                    {
                   1842:                      /* skip preceding comments if any */
                   1843:                      previous = el;
                   1844:                      do
                   1845:                        {
                   1846:                          comment = FALSE;
                   1847:                          TtaPreviousSibling (&previous);
                   1848:                          if (previous)
                   1849:                            {
                   1850:                              elType = TtaGetElementType (previous);
                   1851:                              comment = (TtaSameSSchemas (elType.ElSSchema, MathMLSSchema) &&
                   1852:                                         elType.ElTypeNum == MathML_EL_XMLcomment);
                   1853:                            }
                   1854:                        }
                   1855:                      while (previous && comment);
                   1856:                      
                   1857:                      if (previous == NULL)
                   1858:                        /* no previous sibling => prefix operator */
                   1859:                        val = MathML_ATTR_IntAddSpace_VAL_nospace;
                   1860:                      else
                   1861:                        {
                   1862:                          elType = TtaGetElementType (previous);
1.158     quint    1863:                          if (elType.ElTypeNum == MathML_EL_MO ||
                   1864:                              elType.ElTypeNum == MathML_EL_OpeningFence ||
                   1865:                              elType.ElTypeNum == MathML_EL_ClosingFence ||
                   1866:                              elType.ElTypeNum == MathML_EL_FencedSeparator)
1.155     quint    1867:                            /* after an operator => prefix operator */
                   1868:                            val = MathML_ATTR_IntAddSpace_VAL_nospace;
                   1869:                          else
                   1870:                            /* infix operator */
                   1871:                            val = MathML_ATTR_IntAddSpace_VAL_both;
                   1872:                        }
                   1873:                    }
                   1874:                  else if (text[0] == '&' ||
                   1875:                           text[0] == '*' ||
                   1876:                           text[0] == '+' ||
                   1877:                           text[0] == '/' ||
                   1878:                           text[0] == '<' ||
                   1879:                           text[0] == '=' ||
                   1880:                           text[0] == '>' ||
                   1881:                           text[0] == '^' ||
                   1882:                           (int)text[0] == 177 || /* plus or minus */
                   1883:                           (int)text[0] == 215 || /* times */
                   1884:                           (int)text[0] == 247)   /* divide */
                   1885:                    /* infix operator */
                   1886:                    val = MathML_ATTR_IntAddSpace_VAL_both;
                   1887:                  else if (text[0] == ',' ||
                   1888:                           text[0] == '!' ||
                   1889:                           text[0] == '&' ||
                   1890:                           text[0] == ':' ||
                   1891:                           text[0] == ';')
                   1892:                    /* separator */
                   1893:                    val = MathML_ATTR_IntAddSpace_VAL_spaceafter;
                   1894:                  else if (text[0] == '(' ||
                   1895:                           text[0] == ')' ||
                   1896:                           text[0] == '[' ||
                   1897:                           text[0] == ']' ||
                   1898:                           text[0] == '{' ||
                   1899:                           text[0] == '}' ||
                   1900:                           text[0] == '.' ||
                   1901:                           text[0] == '@' ||
1.165     quint    1902: #ifndef _I18N_
                   1903:                           text[0] == 'd' ||       /* probably DifferentialD */
                   1904: #endif
1.155     quint    1905:                           (int)text[0] == 129 ||  /* thin space */
                   1906:                           (int)text[0] == 130 ||  /* en space */
                   1907:                           (int)text[0] == 160)    /* em space */
                   1908:                    val = MathML_ATTR_IntAddSpace_VAL_nospace;
1.146     quint    1909: #ifndef _I18N_
1.155     quint    1910:                }
                   1911:              else if (script == 'G')
                   1912:                {
                   1913:                  /* Symbol character set */
                   1914:                  if ((int)text[0] == 163 || /* less or equal */
                   1915:                      (int)text[0] == 177 || /* plus or minus */
                   1916:                      (int)text[0] == 179 || /* greater or equal */
                   1917:                      (int)text[0] == 180 || /* times */
                   1918:                      (int)text[0] == 184 || /* divide */
                   1919:                      (int)text[0] == 185 || /* not equal */
                   1920:                      (int)text[0] == 186 || /* identical */
                   1921:                      (int)text[0] == 187 || /* equivalent */
                   1922:                      (int)text[0] == 196 || /* circle times */
                   1923:                      (int)text[0] == 197 || /* circle plus */
                   1924:                      ((int)text[0] >= 199 && (int)text[0] <= 209) || /*  */
                   1925:                      (int)text[0] == 217 || /* and */
                   1926:                      (int)text[0] == 218)   /* or */
1.146     quint    1927: #else
1.155     quint    1928:                    else
                   1929:                      if ((int)text[0] == 0x2264 || /* less or equal */
                   1930:                          (int)text[0] == 0x00B1 || /* plus or minus */
                   1931:                          (int)text[0] == 0x2265 || /* greater or equal */
                   1932:                          (int)text[0] == 0x00D7 || /* times */
                   1933:                          (int)text[0] == 0x00F7 || /* divide */
                   1934:                          (int)text[0] == 0x2260 || /* not equal */
                   1935:                          (int)text[0] == 0x2261 || /* identical */
                   1936:                          (int)text[0] == 0x2248 || /* equivalent */
                   1937:                          (int)text[0] == 0x2297 || /* circle times */
                   1938:                          (int)text[0] == 0x2295 || /* circle plus */
                   1939:                          (int)text[0] == 0x2229 || /* Intersection */
                   1940:                          (int)text[0] == 0x222A || /* Union */
                   1941:                          (int)text[0] == 0x2283 || /* Superset of */
                   1942:                          (int)text[0] == 0x2287 || /* Superset of or equal to */
                   1943:                          (int)text[0] == 0x2284 || /* Not a subset of */
                   1944:                          (int)text[0] == 0x2282 || /* Subset of */
                   1945:                          (int)text[0] == 0x2286 || /* Subset of or equal to */
                   1946:                          (int)text[0] == 0x2208 || /* Element of */
                   1947:                          (int)text[0] == 0x2209 || /* Not an element of */
                   1948:                          (int)text[0] == 0x2220 || /* Angle */
                   1949:                          (int)text[0] == 0x2207 || /* Nabla */
                   1950:                          (int)text[0] == 0x2227 || /* and */
                   1951:                          (int)text[0] == 0x2228 || /* or */
                   1952:                          (int)text[0] == 0x2190 || /* left arrow */
                   1953:                          (int)text[0] == 0x2192 || /* right arrow */
                   1954:                          (int)text[0] == 0x2194)   /* left right arrow */
1.146     quint    1955: #endif
1.155     quint    1956:                        /* infix operator */
                   1957:                        val = MathML_ATTR_IntAddSpace_VAL_both;
                   1958:                      else
                   1959:                        val = MathML_ATTR_IntAddSpace_VAL_nospace;
1.146     quint    1960: #ifndef _I18N_
1.155     quint    1961:                }
1.146     quint    1962: #endif
1.155     quint    1963:            }
                   1964:        }
                   1965:       TtaSetAttributeValue (attr, val, el, doc);
                   1966:     }
1.1       cvs      1967: }
                   1968: 
                   1969: /*----------------------------------------------------------------------
1.58      cvs      1970:    ChildOfMRowOrInferred
                   1971:    Return TRUE if element el is a child of a MROW element or an
                   1972:    inferred MROW element
                   1973:   ----------------------------------------------------------------------*/
                   1974: ThotBool      ChildOfMRowOrInferred (Element el)
                   1975: {
                   1976:    ElementType  elType;
                   1977:    Element       parent;
                   1978:    ThotBool      result;
                   1979: 
                   1980:    result = FALSE;
                   1981:    parent = TtaGetParent (el);
                   1982:    if (parent)
                   1983:       {
                   1984:       elType = TtaGetElementType (parent);
                   1985:       result = (elType.ElTypeNum == MathML_EL_MROW ||
                   1986:                elType.ElTypeNum == MathML_EL_SqrtBase ||
                   1987:                elType.ElTypeNum == MathML_EL_MSTYLE ||
                   1988:                elType.ElTypeNum == MathML_EL_MERROR ||
1.92      cvs      1989:                elType.ElTypeNum == MathML_EL_MENCLOSE ||
1.58      cvs      1990:                elType.ElTypeNum == MathML_EL_MPADDED ||
                   1991:                elType.ElTypeNum == MathML_EL_MPHANTOM ||
1.158     quint    1992:                elType.ElTypeNum == MathML_EL_MFENCED ||
1.58      cvs      1993:                elType.ElTypeNum == MathML_EL_CellWrapper ||
1.92      cvs      1994:                elType.ElTypeNum == MathML_EL_MathML ||
1.58      cvs      1995:                 elType.ElTypeNum == MathML_EL_FencedExpression);
                   1996:       }
                   1997:    return result;   
                   1998: }
                   1999: 
                   2000: /*----------------------------------------------------------------------
1.170     quint    2001:    CheckFenceLargeOp
1.84      cvs      2002:    If el is a MO element,
                   2003:     - if it's a large operator (&Sum; for instance), put a presentation
                   2004:       rule to enlarge the character.
                   2005:     - if it's a child of a MROW (or equivalent) element and if it contains
                   2006:       a single fence character, transform the MO into a MF and the fence
                   2007:       character into a Thot stretchable symbol.
1.1       cvs      2008:   ----------------------------------------------------------------------*/
1.170     quint    2009: void      CheckFenceLargeOp (Element el, Document doc)
1.1       cvs      2010: {
1.158     quint    2011:    ElementType        elType, contType;
1.170     quint    2012:    Element            content, ancestor;
1.128     vatton   2013:    AttributeType       attrType;
1.170     quint    2014:    Attribute          attrLargeop, attr, attrStretchy;
1.128     vatton   2015:    Language           lang;
1.84      cvs      2016:    PresentationValue   pval;
                   2017:    PresentationContext ctxt;
1.128     vatton   2018:    CHAR_T              text[2];
1.143     vatton   2019:    char                       script;
1.128     vatton   2020:    unsigned char       c;
1.158     quint    2021:    int                 len, val, oldStructureChecking;
1.170     quint    2022:    ThotBool            largeop;
1.1       cvs      2023: 
                   2024:    elType = TtaGetElementType (el);
1.158     quint    2025:    if (elType.ElTypeNum == MathML_EL_MO ||
                   2026:        elType.ElTypeNum == MathML_EL_OpeningFence ||
                   2027:        elType.ElTypeNum == MathML_EL_ClosingFence ||
                   2028:        elType.ElTypeNum == MathML_EL_FencedSeparator)
                   2029:      /* the element is a MO or equivalent */
1.58      cvs      2030:      {
1.84      cvs      2031:      content = TtaGetFirstChild (el);
                   2032:      if (content != NULL)
                   2033:        {
1.158     quint    2034:        contType = TtaGetElementType (content);
                   2035:        if (contType.ElTypeNum == MathML_EL_TEXT_UNIT)
1.84      cvs      2036:         {
1.146     quint    2037:         len = TtaGetElementVolume (content);
1.84      cvs      2038:         if (len == 1)
                   2039:           /* the MO element contains a single character */
                   2040:           {
1.146     quint    2041:           TtaGiveBufferContent (content, text, len+1, &lang);
1.143     vatton   2042:           script = TtaGetScript (lang);
1.170     quint    2043:           largeop = FALSE;
                   2044:           /* is there an attribute largeop on this mo element? */
                   2045:           attrType.AttrSSchema = elType.ElSSchema;
                   2046:           attrType.AttrTypeNum = MathML_ATTR_largeop;
                   2047:           attrLargeop = TtaGetAttribute (el, attrType);
                   2048:           if (attrLargeop)
                   2049:             /* there is an attribute largeop. Just take its value */
                   2050:             largeop = (TtaGetAttributeValue (attrLargeop) == MathML_ATTR_largeop_VAL_true);
                   2051:           else
                   2052:             /* no attribute largeop */
                   2053:             {
                   2054:               /* first look for an IntDisplaystyle attribute on an ancestor */
                   2055:               attrType.AttrSSchema = elType.ElSSchema;
                   2056:               attrType.AttrTypeNum = MathML_ATTR_IntDisplaystyle;
                   2057:               ancestor = el;
                   2058:               do
                   2059:                 {
                   2060:                   attr = TtaGetAttribute (ancestor, attrType);
                   2061:                   if (!attr)
                   2062:                     ancestor = TtaGetParent(ancestor);
                   2063:                 }
                   2064:               while (!attr && ancestor);
                   2065:               if (attr)
                   2066:                 /* there is an ancestor with an attribute IntDisplaystyle */
                   2067:                 {
                   2068:                   val = TtaGetAttributeValue (attr);
                   2069:                   if (val == MathML_ATTR_IntDisplaystyle_VAL_true)
                   2070:                     /* an ancestor has an attribute IntDisplaystyle = true */
                   2071:                     /* Look at the symbol */
1.171     carcone  2072:                     largeop = IsLargeOp (text[0], script);
1.170     quint    2073:                 }
                   2074:             }
                   2075:           ctxt = TtaGetSpecificStyleContext (doc);
                   2076:           if (largeop)
                   2077:             /* it's a large operator. Make it larger */
1.84      cvs      2078:             {
                   2079:             ctxt->destroy = FALSE;
                   2080:             /* the specific presentation to be created is not a CSS rule */
1.147     quint    2081:             ctxt->cssSpecificity = 0;
1.84      cvs      2082:             pval.typed_data.unit = STYLE_UNIT_PERCENT;
                   2083:             pval.typed_data.real = FALSE;
                   2084:             pval.typed_data.value = 180;
                   2085:             }
1.170     quint    2086:           else
                   2087:             /* it's not a large operator, remove the Size presentation rule
                   2088:                if it's present */
                   2089:             {
                   2090:             ctxt->destroy = TRUE;
                   2091:              pval.typed_data.value = 0;
                   2092:             }
                   2093:           TtaSetStylePresentation (PRSize, content, NULL, ctxt, pval);
                   2094: 
                   2095:           if (!largeop && ChildOfMRowOrInferred (el))
1.84      cvs      2096:             /* the MO element is a child of a MROW element */
1.170     quint    2097:             /* Is it a stretchable symbol? */
1.1       cvs      2098:              {
1.171     carcone  2099:                if (IsStretchy (text[0], script))
1.84      cvs      2100:                /* it's a stretchable parenthesis or equivalent */
                   2101:                {
                   2102:                /* remove the content of the MO element */
                   2103:                TtaDeleteTree (content, doc);
                   2104:                /* change the MO element into a MF element */
1.158     quint    2105:                if (elType.ElTypeNum == MathML_EL_MO)
                   2106:                   ChangeTypeOfElement (el, doc, MathML_EL_MF);
1.84      cvs      2107:                /* is there an attribute stretchy on this mo element? */
                   2108:                attrType.AttrSSchema = elType.ElSSchema;
                   2109:                attrType.AttrTypeNum = MathML_ATTR_stretchy;
                   2110:                attrStretchy = TtaGetAttribute (el, attrType);
                   2111:                if (attrStretchy)
                   2112:                  val = TtaGetAttributeValue (attrStretchy);
                   2113:                else
                   2114:                  val = MathML_ATTR_stretchy_VAL_true;
                   2115:                if (val == MathML_ATTR_stretchy_VAL_true)
                   2116:                  {
1.158     quint    2117:                  /* attach a IntVertStretch attribute to the MF element */
1.84      cvs      2118:                  attrType.AttrTypeNum = MathML_ATTR_IntVertStretch;
1.158     quint    2119:                  attr = TtaGetAttribute (el, attrType);
                   2120:                  if (!attr)
                   2121:                    {
                   2122:                    attr = TtaNewAttribute (attrType);
                   2123:                    TtaAttachAttribute (el, attr, doc);
                   2124:                    }
1.84      cvs      2125:                  TtaSetAttributeValue (attr,
                   2126:                                        MathML_ATTR_IntVertStretch_VAL_yes_,
                   2127:                                        el, doc);
                   2128:                  }
                   2129:                /* create a new content for the MF element */
1.87      cvs      2130:                elType.ElTypeNum = MathML_EL_SYMBOL_UNIT;
1.146     quint    2131: #ifdef _I18N_
                   2132:                 if (text[0] == 9002)
                   2133: #else
1.143     vatton   2134:                if (script == 'G' && text[0] == 241)
1.146     quint    2135: #endif
1.102     cvs      2136:                  c = '>';    /* RightAngleBracket */
                   2137:                else
1.146     quint    2138: #ifdef _I18N_
                   2139:                   if (text[0] == 9001)
                   2140: #else
                   2141:                  if (script == 'G' && text[0] == 225)
                   2142: #endif
                   2143:                    c = '<';    /* LeftAngleBracket */
                   2144:                  else
                   2145:                    c = (char) text[0];
1.84      cvs      2146:                content = TtaNewElement (doc, elType);
1.158     quint    2147:                /* do not check the Thot abstract tree against the structure
                   2148:                   schema while inserting this child element  */
                   2149:                oldStructureChecking = TtaGetStructureChecking (doc);
                   2150:                TtaSetStructureChecking (0, doc);
1.84      cvs      2151:                TtaInsertFirstChild (&content, el, doc);
                   2152:                TtaSetGraphicsShape (content, c, doc);
1.158     quint    2153:                /* resume structure checking */
                   2154:                TtaSetStructureChecking ((ThotBool)oldStructureChecking, doc);
1.84      cvs      2155:                }
1.1       cvs      2156:              }
1.84      cvs      2157:           }
                   2158:         }
1.58      cvs      2159:        }
                   2160:      }
1.1       cvs      2161: }
                   2162: 
                   2163: /*----------------------------------------------------------------------
                   2164:    CreateFencedSeparators
                   2165:    Create FencedSeparator elements within the fencedExpression
                   2166:    according to attribute separators of the MFENCED element.
                   2167:   ----------------------------------------------------------------------*/
1.110     cvs      2168: void CreateFencedSeparators (Element fencedExpression, Document doc, ThotBool record)
1.1       cvs      2169: {
                   2170:    ElementType  elType;
                   2171:    Element      child, separator, leaf, next, prev, mfenced;
                   2172:    AttributeType attrType;
                   2173:    Attribute     attr;
                   2174:    int          length, sep, i;
                   2175:    Language     lang;
1.116     cvs      2176:    char         text[32], sepValue[4];
1.1       cvs      2177: 
                   2178:    /* get the separators attribute */
                   2179:    mfenced = TtaGetParent (fencedExpression);
                   2180:    elType = TtaGetElementType (fencedExpression);
                   2181:    attrType.AttrSSchema = elType.ElSSchema;
                   2182:    attrType.AttrTypeNum = MathML_ATTR_separators;
                   2183:    text[0] = ',';      /* default value is  sparators=","  */
                   2184:    text[1] = EOS;
                   2185:    length = 1;
                   2186:    attr = TtaGetAttribute (mfenced, attrType);
                   2187:    if (attr != NULL)
                   2188:       {
                   2189:       length = 31;
                   2190:       TtaGiveTextAttributeValue (attr, text, &length);
                   2191:       }
                   2192: 
                   2193:    /* create FencedSeparator elements in the FencedExpression */
                   2194:    prev = NULL;
                   2195:    sep = 0;
                   2196:    /* skip leading spaces in attribute separators */
                   2197:    while (text[sep] <= SPACE && text[sep] != EOS)
                   2198:       sep++;
                   2199:    /* if attribute separators is empty or contains only spaces, do not
                   2200:       insert any separator element */
                   2201:    if (text[sep] != EOS)
                   2202:      {
                   2203:      child = TtaGetFirstChild (fencedExpression);
                   2204:      while (child != NULL)
                   2205:        {
                   2206:        next = child;
                   2207:        TtaNextSibling (&next);
                   2208:        elType = TtaGetElementType (child);
                   2209:        if (elType.ElTypeNum != MathML_EL_Construct)
                   2210:          {
                   2211:          if (prev != NULL)
                   2212:            {
                   2213:            elType.ElTypeNum = MathML_EL_FencedSeparator;
                   2214:            separator = TtaNewElement (doc, elType);
                   2215:            TtaInsertSibling (separator, prev, FALSE, doc);
                   2216:            elType.ElTypeNum = MathML_EL_TEXT_UNIT;
                   2217:            leaf = TtaNewElement (doc, elType);
                   2218:            TtaInsertFirstChild (&leaf, separator, doc);
                   2219:            sepValue[0] = text[sep];
1.158     quint    2220:            sepValue[1] = EOS;
1.143     vatton   2221:           lang = TtaGetLanguageIdFromScript('L');
1.1       cvs      2222:            TtaSetTextContent (leaf, sepValue, lang, doc);
1.158     quint    2223:           SetIntAddSpaceAttr (separator, doc);
                   2224:           SetIntVertStretchAttr (separator, doc, 0, NULL);
1.170     quint    2225:           CheckFenceLargeOp (separator, doc);
1.158     quint    2226: 
1.1       cvs      2227:           /* is there a following non-space character in separators? */
                   2228:           i = sep + 1;
                   2229:           while (text[i] <= SPACE && text[i] != EOS)
                   2230:              i++;
                   2231:            if (text[i] > SPACE && text[i] != EOS)
                   2232:               sep = i;
1.17      cvs      2233:           if (record)
                   2234:             TtaRegisterElementCreate (separator, doc);
1.1       cvs      2235:            }
                   2236:          prev = child;
                   2237:          }
                   2238:        child = next;
                   2239:        }
                   2240:      }
                   2241: }
                   2242: 
1.124     cvs      2243: /*----------------------------------------------------------------------
                   2244:    CreateOpeningOrClosingFence
                   2245:    Create the OpeningFence or ClosingFence element (depending on parameter
                   2246:    open) for the MFENCED element el which contain the fencedExpression
                   2247:    element.
                   2248:   ----------------------------------------------------------------------*/
                   2249: static void  CreateOpeningOrClosingFence (Element fencedExpression,
                   2250:                                          Element el, Document doc,
                   2251:                                          ThotBool open)
                   2252: {
                   2253:   ElementType  elType;
                   2254:   Element       leaf, fence;
                   2255:   AttributeType attrType;
                   2256:   Attribute     attr;
                   2257:   int           length;
                   2258:   char          text[32];
                   2259: 
                   2260:   elType = TtaGetElementType (el);
                   2261:   attrType.AttrSSchema = elType.ElSSchema;
                   2262:   if (open)
                   2263:     {
1.158     quint    2264:       text[0] = '(';    /* default value of attribute 'open' */
1.124     cvs      2265:       attrType.AttrTypeNum = MathML_ATTR_open;
                   2266:       elType.ElTypeNum = MathML_EL_OpeningFence;
                   2267:     }
                   2268:   else
                   2269:     {
1.158     quint    2270:       text[0] = ')';    /* default value of attribute 'close' */
1.124     cvs      2271:       attrType.AttrTypeNum = MathML_ATTR_close;
                   2272:       elType.ElTypeNum = MathML_EL_ClosingFence;
                   2273:     }
                   2274:   attr = TtaGetAttribute (el, attrType);
                   2275:   if (attr != NULL)
                   2276:     {
                   2277:       length = 31;
                   2278:       TtaGiveTextAttributeValue (attr, text, &length);
                   2279:       if (length != 1)
                   2280:        /* content of attribute open or close should be a single character */
1.158     quint    2281:        text[0] = '?';
1.124     cvs      2282:     }
1.158     quint    2283:   text[1] = EOS;
1.124     cvs      2284:   fence = TtaNewElement (doc, elType);
                   2285:   TtaInsertSibling (fence, fencedExpression, open, doc);
1.158     quint    2286:   elType.ElTypeNum = MathML_EL_TEXT_UNIT;
1.124     cvs      2287:   leaf = TtaNewElement (doc, elType);
                   2288:   TtaInsertFirstChild (&leaf, fence, doc);
1.158     quint    2289:   TtaSetTextContent (leaf, text, TtaGetLanguageIdFromScript('L'), doc);
                   2290:   SetIntAddSpaceAttr (fence, doc);
                   2291:   SetIntVertStretchAttr (fence, doc, 0, NULL);
1.170     quint    2292:   CheckFenceLargeOp (fence, doc);
1.124     cvs      2293: }
1.1       cvs      2294: 
                   2295: /*----------------------------------------------------------------------
                   2296:    TransformMFENCED
                   2297:    Transform the content of a MFENCED element: create elements
                   2298:    OpeningFence, FencedExpression, ClosingFence and FencedSeparator.
                   2299:   ----------------------------------------------------------------------*/
1.46      cvs      2300: static void      TransformMFENCED (Element el, Document doc)
1.1       cvs      2301: {
                   2302:    ElementType  elType;
1.124     cvs      2303:    Element      child, fencedExpression, next, prev, firstChild;
1.1       cvs      2304: 
                   2305:    child = TtaGetFirstChild (el);
                   2306:    if (child != NULL)
                   2307:         elType = TtaGetElementType (child);
                   2308:    if (child != NULL && elType.ElTypeNum == MathML_EL_OpeningFence)
                   2309:       /* The first child of this MFENCED element is an OpeningFence.
                   2310:         This MFENCED expression has already been transformed, possibly
                   2311:         by the Transform command */
                   2312:       {
                   2313:       TtaNextSibling (&child);
                   2314:       fencedExpression = child;
                   2315:       if (fencedExpression != NULL)
                   2316:         elType = TtaGetElementType (fencedExpression);
                   2317:       if (elType.ElTypeNum == MathML_EL_FencedExpression)
                   2318:         /* the second child is a FencedExpression. OK.
                   2319:            Remove all existing FencedSeparator elements */
                   2320:         {
                   2321:         child = TtaGetFirstChild (fencedExpression);
                   2322:         prev = NULL;
                   2323:         while (child != NULL)
                   2324:            {
                   2325:            elType = TtaGetElementType (child);
                   2326:            next = child;
                   2327:            TtaNextSibling (&next);
                   2328:            if (elType.ElTypeNum == MathML_EL_FencedSeparator)
                   2329:                /* Remove this separator */
                   2330:                TtaDeleteTree (child, doc);
                   2331:            child = next;
                   2332:            }
                   2333:         /* create FencedSeparator elements in the FencedExpression */
1.17      cvs      2334:         CreateFencedSeparators (fencedExpression, doc, FALSE);
1.1       cvs      2335:         }
                   2336:       }
                   2337:    else
                   2338:       /* this MFENCED element must be transformed */
                   2339:       {
                   2340:       /* create a FencedExpression element as a child of the MFENCED elem. */
                   2341:       elType = TtaGetElementType (el);
                   2342:       elType.ElTypeNum = MathML_EL_FencedExpression;
                   2343:       fencedExpression = TtaNewElement (doc, elType);
                   2344:       TtaInsertFirstChild (&fencedExpression, el, doc);
                   2345:       if (child == NULL)
                   2346:        /* empty MFENCED element */
                   2347:        {
                   2348:         elType.ElTypeNum = MathML_EL_Construct;
                   2349:        child = TtaNewElement (doc, elType);
                   2350:        TtaInsertFirstChild (&child, fencedExpression, doc);
1.22      cvs      2351:        SetIntPlaceholderAttr (child, doc);
1.1       cvs      2352:        }
                   2353:       else
                   2354:        {
                   2355:         /* move the content of the MFENCED element within the new
                   2356:           FencedExpression element */
                   2357:         prev = NULL;
                   2358:        firstChild = NULL;
                   2359:         while (child != NULL)
                   2360:          {
                   2361:          next = child;
                   2362:          TtaNextSibling (&next);
                   2363:          TtaRemoveTree (child, doc);
                   2364:          if (prev == NULL)
                   2365:            {
                   2366:            TtaInsertFirstChild (&child, fencedExpression, doc);
                   2367:            firstChild = child;
                   2368:            }
                   2369:          else
                   2370:            TtaInsertSibling (child, prev, FALSE, doc);
                   2371:          prev = child;
                   2372:          child = next;
                   2373:          }
                   2374: 
                   2375:        /* create FencedSeparator elements in the FencedExpression */
1.17      cvs      2376:        CreateFencedSeparators (fencedExpression, doc, FALSE);
1.1       cvs      2377: 
                   2378:         /* Create placeholders within the FencedExpression element */
                   2379:         CreatePlaceholders (firstChild, doc);
                   2380:        }
                   2381: 
                   2382:       /* create the OpeningFence element according to the open attribute */
1.124     cvs      2383:       CreateOpeningOrClosingFence (fencedExpression, el, doc, TRUE);
1.1       cvs      2384: 
                   2385:       /* create the ClosingFence element according to close attribute */
1.124     cvs      2386:       CreateOpeningOrClosingFence (fencedExpression, el, doc, FALSE);
1.1       cvs      2387:       }
                   2388: }
                   2389: 
                   2390: /*----------------------------------------------------------------------
1.59      cvs      2391:  MathMLScriptShift
                   2392:  The MathML attribute attr (superscriptshift or subscriptshift) is associated
                   2393:  with element el (a msub, msup or msubsup).
                   2394:  If value is not NULL, generate the corresponding Thot VertPos rule for the
                   2395:  Subscript or  Superscript child of el.
                   2396:  If value is NULL, remove the Thot VertPos rule.
                   2397:  -----------------------------------------------------------------------*/
1.120     cvs      2398: void MathMLScriptShift (Document doc, Element el, char *value, int attr)
1.59      cvs      2399: {
                   2400:   ElementType         elType;
                   2401:   Element             script, child;
                   2402:   int                 scrType;
                   2403:   PresentationValue   pval;
                   2404:   PresentationContext ctxt;
                   2405: 
                   2406:   /* get the Superscript or Subscript child of el */
                   2407:   if (attr == MathML_ATTR_superscriptshift)
                   2408:      scrType = MathML_EL_Superscript;
                   2409:   else if (attr == MathML_ATTR_subscriptshift)
                   2410:      scrType = MathML_EL_Subscript;
                   2411:   else
                   2412:      return;
                   2413:   script = NULL;
                   2414:   child = TtaGetFirstChild (el);
                   2415:   while (!script && child)
                   2416:     {
                   2417:     elType = TtaGetElementType (child);
                   2418:     if (elType.ElTypeNum == scrType)
                   2419:        script = child;
                   2420:     else
                   2421:        TtaNextSibling (&child);
                   2422:     }
                   2423:   if (script)
                   2424:     /* Superscript or Subscript element found */
                   2425:     {
                   2426:     ctxt = TtaGetSpecificStyleContext (doc);
                   2427:     if (!value)
                   2428:        /* remove the presentation rule */
                   2429:        {
                   2430:        ctxt->destroy = TRUE;
1.75      cvs      2431:        pval.typed_data.value = 0;
1.59      cvs      2432:        TtaSetStylePresentation (PRVertPos, script, NULL, ctxt, pval);
                   2433:        }
                   2434:     else
                   2435:        {
                   2436:        ctxt->destroy = FALSE;
                   2437:        /* parse the attribute value (a number followed by a unit) */
1.119     cvs      2438:        value = TtaSkipBlanks (value);
1.59      cvs      2439:        value = ParseCSSUnit (value, &pval);
                   2440:        if (pval.typed_data.unit != STYLE_UNIT_INVALID)
                   2441:          {
1.78      cvs      2442:          /* the specific presentation to be created is not a CSS rule */
1.147     quint    2443:          ctxt->cssSpecificity = 0;
1.59      cvs      2444:           if (attr == MathML_ATTR_superscriptshift)
                   2445:            pval.typed_data.value = - pval.typed_data.value;
                   2446:          TtaSetStylePresentation (PRVertPos, script, NULL, ctxt, pval);
                   2447:          }
                   2448:        }
                   2449:     TtaFreeMemory (ctxt);
                   2450:     }
                   2451: }
                   2452: 
                   2453: /*----------------------------------------------------------------------
                   2454:    SetScriptShift
                   2455:    If element el (which is a msup, msub or msubsup) has an attribute
                   2456:    att (which is subscriptshift or superscriptshift), generate the
                   2457:    corresponding Thot presentation rule.
                   2458:   ----------------------------------------------------------------------*/
1.120     cvs      2459: static void SetScriptShift (Element el, Document doc, int att)
1.59      cvs      2460: {
                   2461:    AttributeType     attrType;
                   2462:    ElementType       elType;
                   2463:    Attribute         attr;
1.120     cvs      2464:    char             *value;
1.59      cvs      2465:    int               length;
                   2466: 
                   2467:    elType = TtaGetElementType (el);
                   2468:    attrType.AttrSSchema = elType.ElSSchema;
                   2469:    attrType.AttrTypeNum = att;
                   2470:    attr = TtaGetAttribute (el, attrType);
                   2471:    if (attr)
                   2472:       {
                   2473:       length = TtaGetTextAttributeLength (attr);
                   2474:       if (length > 0)
                   2475:         {
1.116     cvs      2476:         value = TtaGetMemory (length+1);
1.59      cvs      2477:         value[0] = EOS;
                   2478:         TtaGiveTextAttributeValue (attr, value, &length);
                   2479:         MathMLScriptShift (doc, el, value, att);
                   2480:         TtaFreeMemory (value);
                   2481:         }
                   2482:       }
                   2483: }
                   2484: 
                   2485: /*----------------------------------------------------------------------
1.159     quint    2486:  DeleteIntRowAlign
                   2487:  Remove attribute IntRowAlign from element row if there is no rowalign_mtr
                   2488:  attribut on this element.
                   2489:  -----------------------------------------------------------------------*/
                   2490: static void DeleteIntRowAlign (Element row, Document doc)
                   2491: {
                   2492:   ElementType   elType;
                   2493:   AttributeType attrType;
                   2494:   Attribute     attr;
                   2495: 
                   2496:   elType = TtaGetElementType (row);
                   2497:   attrType.AttrSSchema = elType.ElSSchema;
                   2498:   attrType.AttrTypeNum = MathML_ATTR_rowalign_mtr;
                   2499:   attr = TtaGetAttribute (row, attrType);
                   2500:   if (!attr)
                   2501:     {
                   2502:       attrType.AttrTypeNum = MathML_ATTR_IntRowAlign;
                   2503:       attr = TtaGetAttribute (row, attrType);
                   2504:       if (attr)
                   2505:        TtaRemoveAttribute (row, attr, doc);
                   2506:     }
                   2507: }
                   2508: 
                   2509: /*----------------------------------------------------------------------
                   2510:  SetIntRowAlign
                   2511:  Set attribute IntRowAlign for element row unless this element already has
                   2512:  a rowalign_mtr attribute
                   2513:  -----------------------------------------------------------------------*/
                   2514: static void SetIntRowAlign (Element row, int val, Document doc)
                   2515: {
                   2516:   ElementType   elType;
                   2517:   AttributeType attrType;
                   2518:   Attribute     attr;
                   2519: 
                   2520:   elType = TtaGetElementType (row);
                   2521:   attrType.AttrSSchema = elType.ElSSchema;
                   2522:   attrType.AttrTypeNum = MathML_ATTR_rowalign_mtr;
                   2523:   attr = TtaGetAttribute (row, attrType);
                   2524:   if (!attr)
                   2525:     {
                   2526:       attrType.AttrTypeNum = MathML_ATTR_IntRowAlign;
                   2527:       attr = TtaGetAttribute (row, attrType);
                   2528:       if (!attr)
                   2529:        {
                   2530:          attr = TtaNewAttribute (attrType);
                   2531:          TtaAttachAttribute (row, attr, doc);
                   2532:        }
                   2533:       TtaSetAttributeValue (attr, val, row, doc);
                   2534:     }
                   2535: }
                   2536: 
                   2537: /*----------------------------------------------------------------------
                   2538:    HandleRowalignAttribute
                   2539:    An attribute rowalign has been created, updated (if !delete) or deleted
                   2540:    (if delete) for element el in document doc. Update the IntRowAlign
                   2541:    attributes of all enclosed mrow elements accordingly.
                   2542:   ----------------------------------------------------------------------*/
                   2543: void HandleRowalignAttribute (Attribute attr, Element el, Document doc,
                   2544:                              ThotBool delete)
                   2545: {
                   2546:   char            *value;
                   2547:   char            *ptr;
                   2548:   int              length, val;
                   2549:   ElementType      elType;
                   2550:   Element          row;
                   2551: 
                   2552:   elType = TtaGetElementType (el);
                   2553:   if (elType.ElTypeNum != MathML_EL_MTABLE ||
                   2554:       strcmp (TtaGetSSchemaName (elType.ElSSchema), "MathML"))
                   2555:     /* ignore rowalign attribute on mstyle elements */
                   2556:     /* process it only on mtable elements */
                   2557:     return;
                   2558: 
                   2559:   value = NULL;
                   2560:   if (!delete)
                   2561:     {
                   2562:       length = TtaGetTextAttributeLength (attr);
                   2563:       if (length > 0)
                   2564:        {
                   2565:          value = TtaGetMemory (length+1);
                   2566:          value[0] = EOS;
                   2567:          TtaGiveTextAttributeValue (attr, value, &length);
                   2568:        }
                   2569:     }
                   2570:   /* if attribute rowalign is created or updated but has no value, don't
                   2571:      do anything */
                   2572:   if (!delete && !value)
                   2573:     return;
                   2574: 
                   2575:   ptr = value;
                   2576:   val = 0;
                   2577:   elType.ElTypeNum = MathML_EL_TableRow;
                   2578:   row = TtaSearchTypedElement (elType, SearchInTree, el);
                   2579:   while (row)
                   2580:     {
                   2581:     elType = TtaGetElementType (row);
                   2582:     /* skip comments and other non row elements */
                   2583:     if ((elType.ElTypeNum == MathML_EL_MTR ||
                   2584:         elType.ElTypeNum == MathML_EL_MLABELEDTR) &&
                   2585:        strcmp (TtaGetSSchemaName (elType.ElSSchema), "MathML") == 0)
                   2586:       {
                   2587:       if (delete)
                   2588:        DeleteIntRowAlign (row, doc);
                   2589:       else
                   2590:        {
                   2591:          if (*ptr != EOS)
                   2592:            {
                   2593:              /* get next word in the attribute value */
                   2594:              ptr = TtaSkipBlanks (ptr);
                   2595:              /* process that word */
                   2596:              if (*ptr != EOS && *ptr != ' ')
                   2597:                {
                   2598:                  if (!strncasecmp (ptr, "top", 3))
                   2599:                    val = MathML_ATTR_IntRowAlign_VAL_IntTop;
                   2600:                  else if (!strncasecmp (ptr, "bottom", 6))
                   2601:                    val = MathML_ATTR_IntRowAlign_VAL_IntBottom;
                   2602:                  else if (!strncasecmp (ptr, "center", 6))
                   2603:                    val = MathML_ATTR_IntRowAlign_VAL_IntCenter;
                   2604:                  else if (!strncasecmp (ptr, "baseline", 8))
                   2605:                    val = MathML_ATTR_IntRowAlign_VAL_IntBaseline;
                   2606:                  else if (!strncasecmp (ptr, "axis", 4))
                   2607:                    val = MathML_ATTR_IntRowAlign_VAL_IntAxis;
                   2608:                  else
                   2609:                    val = 0;
                   2610:                  /* skip the word that has been processed */
                   2611:                  while (*ptr != EOS && *ptr != ' ')
                   2612:                    ptr++;
                   2613:                }
                   2614:            }
                   2615:          if (val > 0)
                   2616:            SetIntRowAlign (row, val, doc);
                   2617:        }
                   2618:       }
                   2619:     TtaNextSibling (&row);
                   2620:     }
                   2621:   if (value)
                   2622:     TtaFreeMemory (value);
                   2623: }
                   2624: 
                   2625: /*----------------------------------------------------------------------
                   2626:  DeleteIntColAlign
                   2627:  Remove attribute IntColAlign from element cell if there is no columnalign_mtd
                   2628:  attribut on this element.
                   2629:  -----------------------------------------------------------------------*/
                   2630: static void DeleteIntColAlign (Element cell, Document doc)
                   2631: {
                   2632:   ElementType   elType;
                   2633:   AttributeType attrType;
                   2634:   Attribute     attr;
                   2635: 
                   2636:   elType = TtaGetElementType (cell);
                   2637:   attrType.AttrSSchema = elType.ElSSchema;
                   2638:   attrType.AttrTypeNum = MathML_ATTR_columnalign_mtd;
                   2639:   attr = TtaGetAttribute (cell, attrType);
                   2640:   if (!attr)
                   2641:     {
                   2642:       attrType.AttrTypeNum = MathML_ATTR_IntColAlign;
                   2643:       attr = TtaGetAttribute (cell, attrType);
                   2644:       if (attr)
                   2645:        TtaRemoveAttribute (cell, attr, doc);
                   2646:     }
                   2647: }
                   2648: 
                   2649: /*----------------------------------------------------------------------
                   2650:  SetIntColAlign
                   2651:  Set attribute IntColAlign for element cell unless this element already has
                   2652:  a columnalign_mtd attribute
                   2653:  -----------------------------------------------------------------------*/
                   2654: static void SetIntColAlign (Element cell, int val, Document doc)
                   2655: {
                   2656:   ElementType   elType;
                   2657:   AttributeType attrType;
                   2658:   Attribute     attr;
                   2659: 
                   2660:   elType = TtaGetElementType (cell);
                   2661:   attrType.AttrSSchema = elType.ElSSchema;
                   2662:   attrType.AttrTypeNum = MathML_ATTR_columnalign_mtd;
                   2663:   attr = TtaGetAttribute (cell, attrType);
                   2664:   if (!attr)
                   2665:     {
                   2666:       attrType.AttrTypeNum = MathML_ATTR_IntColAlign;
                   2667:       attr = TtaGetAttribute (cell, attrType);
                   2668:       if (!attr)
                   2669:        {
                   2670:          attr = TtaNewAttribute (attrType);
                   2671:          TtaAttachAttribute (cell, attr, doc);
                   2672:        }
                   2673:       TtaSetAttributeValue (attr, val, cell, doc);
                   2674:     }
                   2675: }
                   2676: 
                   2677: /*----------------------------------------------------------------------
                   2678:  RowWithoutColalignAttr
                   2679:  if skip: if element row has a columnalign attribute, get the next sibling row
                   2680:  element without a columnalign attribute and return its first cell
                   2681:  if not skip: always return the first cell in the row, and the columnalign
                   2682:  attribute of that row if there is one.
                   2683:  -----------------------------------------------------------------------*/
                   2684: static void RowWithoutColalignAttr (Element *row, Element *cell,
                   2685:                                    Attribute *attr, ThotBool skip)
                   2686: {
                   2687:   ElementType      elType;
                   2688:   AttributeType    attrType;
                   2689: 
                   2690:   elType = TtaGetElementType (*row);
                   2691:   attrType.AttrSSchema = elType.ElSSchema;
                   2692:   attrType.AttrTypeNum = MathML_ATTR_columnalign;
                   2693:   *cell = NULL;
                   2694:   *attr = NULL;
                   2695:   while (*row != NULL && *cell == NULL)
                   2696:     {
                   2697:       elType = TtaGetElementType (*row);
                   2698:       if ((elType.ElTypeNum != MathML_EL_MTR &&
                   2699:           elType.ElTypeNum != MathML_EL_MLABELEDTR) ||
                   2700:          strcmp (TtaGetSSchemaName (elType.ElSSchema), "MathML"))
                   2701:        /* not a row. Skip it */
                   2702:        TtaNextSibling (row);
                   2703:       else
                   2704:        {
                   2705:          /* skip that row if it has a columnalign attribute */
                   2706:          *attr = TtaGetAttribute (*row, attrType);
                   2707:          if (skip && *attr != NULL)
                   2708:            {
                   2709:            TtaNextSibling (row);
                   2710:            *attr = NULL;
                   2711:            }
                   2712:          else
                   2713:            /* it's a row without a columnalign attribute */
                   2714:            *cell = TtaGetFirstChild (*row);
                   2715:        }
                   2716:     }
                   2717: }
                   2718: 
                   2719: /*----------------------------------------------------------------------
                   2720:    HandleColalignAttribute
                   2721:    An attribute columnalign has been created, updated (if !delete) or deleted
                   2722:    (if delete) for element el in document doc. Update the IntColAlign
                   2723:    attributes of all concerned cells accordingly.
                   2724:    If allRows is TRUE, process also rows that have their own columnalign
                   2725:    attribute, according to that attribute, otherwise skip those rows.
                   2726:   ----------------------------------------------------------------------*/
                   2727: void HandleColalignAttribute (Attribute attr, Element el, Document doc,
                   2728:                              ThotBool delete, ThotBool allRows)
                   2729: {
                   2730:   char            *value, *localValue;
                   2731:   char            *ptr;
                   2732:   int              length, val;
                   2733:   ElementType      elType;
                   2734:   Element          cell, row;
                   2735:   Attribute        localAttr;
                   2736:   ThotBool         fullTable;
                   2737: 
                   2738:   elType = TtaGetElementType (el);
                   2739:   if ((elType.ElTypeNum != MathML_EL_MTABLE &&
                   2740:        elType.ElTypeNum != MathML_EL_MTR &&
                   2741:        elType.ElTypeNum != MathML_EL_MLABELEDTR) ||
                   2742:       strcmp (TtaGetSSchemaName (elType.ElSSchema), "MathML"))
                   2743:     /* ignore columnalign attribute on mstyle elements */
                   2744:     /* process it only on mtable elements */
                   2745:     return;
                   2746: 
                   2747:   fullTable = (elType.ElTypeNum == MathML_EL_MTABLE);
                   2748:   value = NULL;
                   2749:   localValue = NULL;
                   2750:   if (!delete)
                   2751:     {
                   2752:       length = TtaGetTextAttributeLength (attr);
                   2753:       if (length > 0)
                   2754:        {
                   2755:          value = TtaGetMemory (length+1);
                   2756:          value[0] = EOS;
                   2757:          TtaGiveTextAttributeValue (attr, value, &length);
                   2758:        }
                   2759:     }
                   2760:   /* if attribute columnalign is created or updated but has no value, don't
                   2761:      do anything */
                   2762:   if (!delete && !value)
                   2763:     return;
                   2764: 
                   2765:   ptr = value;
                   2766:   val = 0;
                   2767:   /* get the first cell within the element */
                   2768:   elType.ElTypeNum = MathML_EL_MTD;
                   2769:   cell = TtaSearchTypedElement (elType, SearchInTree, el);
                   2770:   if (cell && fullTable)
                   2771:     {
                   2772:     elType.ElTypeNum = MathML_EL_TableRow;
                   2773:     row = TtaGetTypedAncestor (cell, elType);
                   2774:     RowWithoutColalignAttr (&row, &cell, &localAttr, !allRows);
                   2775:     if (localAttr)
                   2776:       {
                   2777:        length = TtaGetTextAttributeLength (localAttr);
                   2778:        if (length > 0)
                   2779:          {
                   2780:            if (localValue)
                   2781:              TtaFreeMemory (localValue);
                   2782:            localValue = TtaGetMemory (length+1);
                   2783:            localValue[0] = EOS;
                   2784:            TtaGiveTextAttributeValue (localAttr, localValue, &length);
                   2785:            ptr = localValue;
                   2786:          }
                   2787:       }
                   2788:     }
                   2789:   while (cell)
                   2790:     {
                   2791:     elType = TtaGetElementType (cell);
                   2792:     /* skip comments and other non cell elements */
                   2793:     if (elType.ElTypeNum == MathML_EL_MTD &&
                   2794:        strcmp (TtaGetSSchemaName (elType.ElSSchema), "MathML") == 0)
                   2795:       {
                   2796:         if (delete)
                   2797:          DeleteIntColAlign (cell, doc);
                   2798:         else
                   2799:          {
                   2800:          if (*ptr != EOS)
                   2801:            {
                   2802:              /* get next word in the attribute value */
                   2803:              ptr = TtaSkipBlanks (ptr);
                   2804:              /* process that word */
                   2805:              if (*ptr != EOS && *ptr != ' ')
                   2806:                {
                   2807:                  if (!strncasecmp (ptr, "left", 4))
                   2808:                    val = MathML_ATTR_IntColAlign_VAL_IntLeft;
                   2809:                  else if (!strncasecmp (ptr, "center", 6))
                   2810:                    val = MathML_ATTR_IntColAlign_VAL_IntCenter;
                   2811:                  else if (!strncasecmp (ptr, "right", 5))
                   2812:                    val = MathML_ATTR_IntColAlign_VAL_IntRight;
                   2813:                  else
                   2814:                    val = 0;
                   2815:                  /* skip the word that has been processed */
                   2816:                  while (*ptr != EOS && *ptr != ' ')
                   2817:                    ptr++;
                   2818:                }
                   2819:            }
                   2820:          if (val > 0)
                   2821:            SetIntColAlign (cell, val, doc);
                   2822:          }
                   2823:       }
                   2824:     TtaNextSibling (&cell);
                   2825:     if (!cell && fullTable && row)
                   2826:       /* no more sibling cell. If the columnalign attribute is for the
                   2827:          full table, get the first cell in the next row */
                   2828:       {
                   2829:       TtaNextSibling (&row);
                   2830:       if (row)
                   2831:        {
                   2832:          /* parse value of columnalign attribute again from the beginning */
                   2833:          ptr = value;
                   2834:          RowWithoutColalignAttr (&row, &cell, &localAttr, !allRows);
                   2835:          if (localAttr)
                   2836:            {
                   2837:              length = TtaGetTextAttributeLength (localAttr);
                   2838:              if (length > 0)
                   2839:                {
                   2840:                  if (localValue)
                   2841:                    TtaFreeMemory (localValue);
                   2842:                  localValue = TtaGetMemory (length+1);
                   2843:                  localValue[0] = EOS;
                   2844:                  TtaGiveTextAttributeValue (localAttr, localValue, &length);
                   2845:                  ptr = localValue;
                   2846:                }
                   2847:            }
                   2848:        }
                   2849:       }
                   2850:     }
                   2851:   if (value)
                   2852:     TtaFreeMemory (value);
                   2853:   if (localValue)
                   2854:     TtaFreeMemory (localValue);
                   2855: }
                   2856: 
                   2857: /*----------------------------------------------------------------------
1.167     quint    2858:    HandleRowspacingAttribute
                   2859:    An attribute rowspacing has been created, updated or deleted (if delete
                   2860:    is TRUE) for element el in document doc. Update the top and bottom padding
                   2861:    of all cells accordingly.
                   2862:   ----------------------------------------------------------------------*/
                   2863: void HandleRowspacingAttribute (Attribute attr, Element el, Document doc,
                   2864:                                 ThotBool delete)
                   2865: {
                   2866:   ElementType         elType, rowType, cellType;
                   2867:   int                 length, val, topVal, topValUnit, bottomVal,
                   2868:                       bottomValUnit, rowspan, cellBottomVal, i;
                   2869:   char               *value, *ptr, *spanPtr;
                   2870:   PresentationValue   pval;
                   2871:   PresentationContext ctxt;
                   2872:   Element             row, nextRow, cell;
                   2873:   ThotBool            stop, firstRow;
                   2874:   AttributeType       rowspanType;
                   2875:   Attribute           rowspanAttr;
                   2876: 
                   2877:   elType = TtaGetElementType (el);
                   2878:   if (elType.ElTypeNum != MathML_EL_MTABLE ||
                   2879:       strcmp (TtaGetSSchemaName (elType.ElSSchema), "MathML"))
                   2880:     /* ignore rowspacing attribute on mstyle elements */
                   2881:     /* process it only on mtable elements */
                   2882:     return;
                   2883: 
                   2884:   value = NULL;
                   2885:   if (!delete && attr)
                   2886:     {
                   2887:       length = TtaGetTextAttributeLength (attr);
                   2888:       if (length > 0)
                   2889:        {
                   2890:          value = TtaGetMemory (length+1);
                   2891:          value[0] = EOS;
                   2892:          TtaGiveTextAttributeValue (attr, value, &length);
                   2893:        }
                   2894:     }
                   2895: 
                   2896:   ctxt = TtaGetSpecificStyleContext (doc);
                   2897:   /* the specific presentation to be created is not a CSS rule */
                   2898:   ctxt->cssSpecificity = 0;
                   2899:   ptr = value;
                   2900:   rowspanType.AttrSSchema = elType.ElSSchema;
                   2901:   rowspanType.AttrTypeNum = MathML_ATTR_rowspan_;
                   2902: 
                   2903:   /* check all rows within the table */
                   2904:   firstRow = TRUE;
                   2905:   bottomVal = 0;
                   2906:   elType.ElTypeNum = MathML_EL_TableRow;
                   2907:   row = TtaSearchTypedElement (elType, SearchInTree, el);
                   2908:   while (row)
                   2909:     {
                   2910:       /* get the next row to check if the current row is the last one */
                   2911:       nextRow = row;
                   2912:       stop = FALSE;
                   2913:       do
                   2914:        {
                   2915:          TtaNextSibling (&nextRow);
                   2916:          if (!nextRow)
                   2917:            stop = TRUE;
                   2918:          else
                   2919:            {
                   2920:              rowType = TtaGetElementType (nextRow);
                   2921:              /* skip comments and other non mrow elements */
                   2922:              if ((rowType.ElTypeNum == MathML_EL_MTR ||
                   2923:                   rowType.ElTypeNum == MathML_EL_MLABELEDTR) &&
                   2924:                  !strcmp (TtaGetSSchemaName (rowType.ElSSchema), "MathML"))
                   2925:                /* it's the next mrow */
                   2926:                stop = TRUE;
                   2927:            }
                   2928:        }
                   2929:       while (!stop);
                   2930: 
                   2931:       /* prepare the value of the padding to be associated with the cells
                   2932:         of that row */
                   2933:       if (delete)
                   2934:        /* remove the presentation rules */
                   2935:        {
                   2936:          pval.typed_data.value = 0;
                   2937:          val = 0;
                   2938:        }
                   2939:       else
                   2940:        {
                   2941:          if (!value)
                   2942:            {
                   2943:              pval.typed_data.unit = STYLE_UNIT_PT;
                   2944:              pval.typed_data.value = 0;
                   2945:              pval.typed_data.real = FALSE;
                   2946:              val = 0;
                   2947:            }
                   2948:          else
                   2949:            {
                   2950:              /* get the next field in the attribute value (a number followed
                   2951:                 by a unit) */
                   2952:              ptr = TtaSkipBlanks (ptr);
                   2953:              if (*ptr != EOS)
                   2954:                {
                   2955:                  ptr = ParseCSSUnit (ptr, &pval);
                   2956:                  if (pval.typed_data.unit != STYLE_UNIT_INVALID)
                   2957:                    {
                   2958:                      /* if the value is an integer, make it a real to avoid
                   2959:                         errors in dividing small integers, such as "1cm" */
                   2960:                      if (!pval.typed_data.real)
                   2961:                        {
                   2962:                          pval.typed_data.value *= 1000;
                   2963:                          pval.typed_data.real = TRUE;
                   2964:                        }
                   2965:                      val = pval.typed_data.value / 2;
                   2966:                    }
1.173   ! vatton   2967:                  else
        !          2968:                    val = pval.typed_data.value;
1.167     quint    2969:                }
                   2970:            }
                   2971:        }
                   2972: 
                   2973:       /* initialize the padding to be set at the top and at the bottom
                   2974:         of each cell */
                   2975:       /* the top padding of a row is the same as the bottom padding of the
                   2976:         previous row */
                   2977:       topVal = bottomVal;
                   2978:       topValUnit = bottomValUnit;
                   2979:       if (!nextRow)
                   2980:        /* row is the last in the table. It must not have any padding
                   2981:           at the bottom */
                   2982:        bottomVal = 0;
                   2983:       else
                   2984:        {
                   2985:          bottomVal = val;
                   2986:          bottomValUnit = pval.typed_data.unit;
                   2987:        }
                   2988: 
                   2989:       /* get the first cell of that row (ignoring Label cells) */
                   2990:       elType.ElTypeNum = MathML_EL_MTD;
                   2991:       cell = TtaSearchTypedElement (elType, SearchInTree, row);
                   2992:       /* update attribute MLineBelowtop padding and bottom padding for all
                   2993:         cells in that row */
                   2994:       while (cell)
                   2995:        {
                   2996:          cellType = TtaGetElementType (cell);
                   2997:          /* skip comments and other non mtd elements */
                   2998:          if (cellType.ElTypeNum == MathML_EL_MTD &&
                   2999:              !strcmp (TtaGetSSchemaName (cellType.ElSSchema), "MathML"))
                   3000:            /* that's a mtd element. Process it */
                   3001:            {
                   3002:              /* by default, use the value for the current row */
                   3003:              cellBottomVal = bottomVal;
                   3004:              if (!delete && value)
                   3005:                /* take row spanning into account */
                   3006:                {
                   3007:                  /* is there a rowspan attribute on that cell? */
                   3008:                  rowspanAttr = TtaGetAttribute (cell, rowspanType);
                   3009:                  if (!rowspanAttr)
                   3010:                    rowspan = 1;
                   3011:                  else
                   3012:                    rowspan = TtaGetAttributeValue (rowspanAttr);
                   3013:                  if (!delete)
                   3014:                    {
                   3015:                      /* skip rowspan-1 words in the value of attribute
                   3016:                         rowlines */
                   3017:                      if (rowspan > 1)
                   3018:                        {
                   3019:                          spanPtr = ptr;
                   3020:                          for (i = 1; i < rowspan && *spanPtr != EOS; i++)
                   3021:                            {
                   3022:                              spanPtr = TtaSkipBlanks (spanPtr);
                   3023:                              spanPtr = ParseCSSUnit (spanPtr, &pval);
                   3024:                            }
                   3025:                          if (pval.typed_data.unit == STYLE_UNIT_INVALID)
                   3026:                            {
                   3027:                              val = 0;
                   3028:                              cellBottomVal = 0;
                   3029:                              bottomValUnit = STYLE_UNIT_PT;
                   3030:                            }
                   3031:                          else
                   3032:                            {
                   3033:                              /* if the value is an integer, make it a real to
                   3034:                                 avoid errors in dividing small integers,
                   3035:                                 such as "1cm" */
                   3036:                              if (!pval.typed_data.real)
                   3037:                                {
                   3038:                                  pval.typed_data.value *= 1000;
                   3039:                                  pval.typed_data.real = TRUE;
                   3040:                                }
                   3041:                              val = pval.typed_data.value / 2;
                   3042:                              cellBottomVal = val;
                   3043:                              bottomValUnit = pval.typed_data.unit;
                   3044:                            }
                   3045:                        }
                   3046:                    }
                   3047:                }
                   3048: 
                   3049:              if ((delete || !value) && !firstRow)
                   3050:                ctxt->destroy = TRUE;
                   3051:              else
                   3052:                {
                   3053:                  pval.typed_data.value = topVal;
                   3054:                  pval.typed_data.unit = topValUnit;
                   3055:                  ctxt->destroy = FALSE;
                   3056:                }
                   3057:              TtaSetStylePresentation (PRPaddingTop, cell, NULL, ctxt, pval);
                   3058:              if ((delete || !value) && nextRow)
                   3059:                ctxt->destroy = TRUE;
                   3060:              else
                   3061:                {
                   3062:                  pval.typed_data.value = cellBottomVal;
                   3063:                  pval.typed_data.unit = bottomValUnit;
                   3064:                  ctxt->destroy = FALSE;
                   3065:                }
                   3066:              TtaSetStylePresentation (PRPaddingBottom, cell, NULL, ctxt,pval);
                   3067:            }
                   3068:          TtaNextSibling (&cell);
                   3069:        }
                   3070:       row = nextRow;
                   3071:       firstRow = FALSE;
                   3072:     }
                   3073: 
                   3074:   TtaFreeMemory (ctxt);
                   3075:   if (value)
                   3076:     TtaFreeMemory (value);
                   3077: }
                   3078: 
                   3079: /*----------------------------------------------------------------------
                   3080:   ConvertNamedSpace
                   3081:   if name is the name of a space, return the value of this space
                   3082:   in value, otherwise return an empty string in value.
                   3083:  -----------------------------------------------------------------------*/
                   3084: static char* ConvertNamedSpace (char *name, char *value)
                   3085:   {
                   3086:        if (strcmp (name, "veryverythinmathspace") == 0)
                   3087:         {
                   3088:           strcpy (value, "0.0555556em");
                   3089:           return (name + strlen("veryverythinmathspace"));
                   3090:         }
                   3091:        else if (strcmp (name, "verythinmathspace") == 0)
                   3092:         {
                   3093:           strcpy (value, "0.111111em");
                   3094:           return (name + strlen("verythinmathspace"));
                   3095:         }
                   3096:        else if (strcmp (name, "thinmathspace") == 0)
                   3097:         {
                   3098:           strcpy (value, "0.166667em");
                   3099:           return (name + strlen("thinmathspace"));
                   3100:         }
                   3101:        else if (strcmp (name, "mediummathspace") == 0)
                   3102:         {
                   3103:           strcpy (value, "0.222222em");
                   3104:           return (name + strlen("mediummathspace"));
                   3105:         }
                   3106:        else if (strcmp (name, "thickmathspace") == 0)
                   3107:         {
                   3108:           strcpy (value, "0.277778em");
                   3109:           return (name + strlen("thickmathspace"));
                   3110:         }
                   3111:        else if (strcmp (name, "verythickmathspace") == 0)
                   3112:         {
                   3113:           strcpy (value, "0.333333em");
                   3114:           return (name + strlen("verythickmathspace"));
                   3115:         }
                   3116:        else if (strcmp (name, "veryverythickmathspace") == 0)
                   3117:         {
                   3118:           strcpy (value, "0.388889em");
                   3119:           return (name + strlen("veryverythickmathspace"));
                   3120:         }
                   3121:        else
                   3122:         {
                   3123:           value[0] = EOS;
                   3124:           return name;
                   3125:         }
                   3126:   }
                   3127:          
                   3128: /*----------------------------------------------------------------------
                   3129:    HandleColumnspacingAttribute
                   3130:    An attribute columnspacing has been created, updated or deleted (if delete
                   3131:    is TRUE) for element el in document doc. Update the left and right padding
                   3132:    of all cells accordingly.
                   3133:   ----------------------------------------------------------------------*/
                   3134: void HandleColumnspacingAttribute (Attribute attr, Element el, Document doc,
                   3135:                                 ThotBool delete)
                   3136: {
                   3137:   ElementType         elType;
                   3138:   int                 length, val, valUnit, leftVal, leftValUnit,
                   3139:                       rightVal, rightValUnit, colspan, i;
                   3140:   char               *value, *ptr, valueOfNamedSpace[20];
                   3141:   PresentationValue   pval;
                   3142:   PresentationContext ctxt;
                   3143:   Element             row, cell, nextCell;
                   3144:   ThotBool            stop, firstCell;
1.168     quint    3145:   Attribute           spanAttr;
1.167     quint    3146:   AttributeType       colspanType;
                   3147: 
                   3148:   elType = TtaGetElementType (el);
                   3149:   if (elType.ElTypeNum != MathML_EL_MTABLE ||
                   3150:       strcmp (TtaGetSSchemaName (elType.ElSSchema), "MathML"))
                   3151:     /* ignore columnspacing attribute on mstyle elements */
                   3152:     /* process it only on mtable elements */
                   3153:     return;
                   3154: 
                   3155:   value = NULL;
                   3156:   if (!delete && attr)
                   3157:     {
                   3158:       length = TtaGetTextAttributeLength (attr);
                   3159:       if (length > 0)
                   3160:        {
                   3161:          value = TtaGetMemory (length+1);
                   3162:          value[0] = EOS;
                   3163:          TtaGiveTextAttributeValue (attr, value, &length);
                   3164:        }
                   3165:     }
                   3166: 
                   3167:   ctxt = TtaGetSpecificStyleContext (doc);
                   3168:   /* the specific presentation to be created is not a CSS rule */
                   3169:   ctxt->cssSpecificity = 0;
                   3170:   val = 0;
                   3171:   colspanType.AttrSSchema = elType.ElSSchema;
                   3172:   colspanType.AttrTypeNum = MathML_ATTR_columnspan;
                   3173:   
                   3174:   /* check all cells in all rows within the table */
                   3175:   elType.ElTypeNum = MathML_EL_TableRow;
                   3176:   row = TtaSearchTypedElement (elType, SearchInTree, el);
                   3177:   while (row)
                   3178:     {
                   3179:       elType = TtaGetElementType (row);
                   3180:       if ((elType.ElTypeNum == MathML_EL_MTR ||
                   3181:           elType.ElTypeNum == MathML_EL_MLABELEDTR) &&
                   3182:          strcmp (TtaGetSSchemaName (elType.ElSSchema), "MathML") == 0)
                   3183:        /* that's a table row. check all its cells */
                   3184:        {
                   3185:          firstCell = TRUE;
                   3186:          rightVal = 0;
                   3187:           val = 0;
                   3188:          valUnit = STYLE_UNIT_PT;
                   3189:          ptr = value;
                   3190:          /* get the first cell of that row (ignoring Label cells) */
                   3191:          elType.ElTypeNum = MathML_EL_MTD;
                   3192:          cell = TtaSearchTypedElement (elType, SearchInTree, row);
                   3193:          while (cell)
                   3194:            {
                   3195:              /* prepare the value of the padding to be associated with the 
                   3196:                 cells */
                   3197:              if (delete)
                   3198:                /* remove the presentation rules */
                   3199:                {
                   3200:                  pval.typed_data.value = 0;
                   3201:                  val = 0;
                   3202:                  valUnit = STYLE_UNIT_PT;
                   3203:                }
                   3204:              else
                   3205:                {
                   3206:                  if (!value)
                   3207:                    {
                   3208:                      pval.typed_data.unit = STYLE_UNIT_PT;
                   3209:                      pval.typed_data.value = 0;
                   3210:                      pval.typed_data.real = FALSE;
                   3211:                      val = 0;
                   3212:                      valUnit = STYLE_UNIT_PT;
                   3213:                    }
                   3214:                  else
                   3215:                    {
                   3216:                      /* parse the next field in the attribute value (a number
                   3217:                         followed by a unit or a named space) */
                   3218:                      ptr = TtaSkipBlanks (ptr);
                   3219:                      if (*ptr != EOS)
                   3220:                        {
                   3221:                          /* is there a columnspan attribute on that cell? */
                   3222:                          spanAttr = TtaGetAttribute (cell, colspanType);
                   3223:                          if (!spanAttr)
                   3224:                            colspan = 1;
                   3225:                          else
                   3226:                            colspan = TtaGetAttributeValue (spanAttr);
                   3227:                          /* skip (colspan - 1) words in the attribute */
                   3228:                          for (i = 1; i <= colspan && *ptr != EOS; i++)
                   3229:                            {
                   3230:                              ptr = TtaSkipBlanks (ptr);
                   3231:                              ptr = ConvertNamedSpace (ptr, valueOfNamedSpace);
                   3232:                              if (valueOfNamedSpace[0] != EOS)
                   3233:                                /* it's a named space */
                   3234:                                ptr = ParseCSSUnit (valueOfNamedSpace, &pval);
                   3235:                              else
                   3236:                                ptr = ParseCSSUnit (ptr, &pval);
                   3237:                              if (pval.typed_data.unit == STYLE_UNIT_INVALID)
                   3238:                                {
                   3239:                                  val = 0;
                   3240:                                  valUnit = STYLE_UNIT_PT;
                   3241:                                }
                   3242:                              else
                   3243:                                {
                   3244:                                  /* if the value is an integer, make it a real
                   3245:                                     to avoid errors in dividing small
                   3246:                                     integers, such as "1cm" */
                   3247:                                  if (!pval.typed_data.real)
                   3248:                                    {
                   3249:                                      pval.typed_data.value *= 1000;
                   3250:                                      pval.typed_data.real = TRUE;
                   3251:                                    }
                   3252:                                  val = pval.typed_data.value / 2;
                   3253:                                  valUnit = pval.typed_data.unit;
                   3254:                                }
                   3255:                            }
                   3256:                        }
                   3257:                    }
                   3258:                }
                   3259: 
                   3260:              /* get the next cell in the current row to check if the current
                   3261:                 cell is the last one in the row */
                   3262:              nextCell = cell;
                   3263:              stop = FALSE;
                   3264:              do
                   3265:                {
                   3266:                  TtaNextSibling (&nextCell);
                   3267:                  if (!nextCell)
                   3268:                    stop = TRUE;
                   3269:                  else
                   3270:                    {
                   3271:                      elType = TtaGetElementType (nextCell);
                   3272:                      /* skip comments and other non mtd elements */
                   3273:                      if (elType.ElTypeNum == MathML_EL_MTD &&
                   3274:                          strcmp (TtaGetSSchemaName (elType.ElSSchema), "MathML") == 0)
                   3275:                        /* it's the next cell */
                   3276:                        stop = TRUE;
                   3277:                    }
                   3278:                }
                   3279:              while (!stop);
                   3280: 
                   3281:              /* initialize the padding to be set at the right and at the left
                   3282:                 of each cell */
                   3283:              /* the leftPadding of a cell is the same as the right padding
                   3284:                 of the previous cell */
                   3285:              leftVal = rightVal;
                   3286:              leftValUnit = rightValUnit;
                   3287:              if (!nextCell)
                   3288:                /* it's the last cell in the row. It must not have any
                   3289:                   padding on the right */
                   3290:                {
                   3291:                  rightVal = 0;
                   3292:                  rightValUnit = STYLE_UNIT_PT;
                   3293:                }
                   3294:              else
                   3295:                {
                   3296:                  rightVal = val;
                   3297:                  rightValUnit = valUnit;
                   3298:                }
                   3299: 
                   3300:              /* set the left and right padding for this cell */
                   3301:              if ((delete || !value) && !firstCell)
                   3302:                ctxt->destroy = TRUE;
                   3303:              else
                   3304:                {
                   3305:                  pval.typed_data.value = leftVal;
                   3306:                  pval.typed_data.unit = leftValUnit;
                   3307:                  ctxt->destroy = FALSE;
                   3308:                }
                   3309:              TtaSetStylePresentation (PRPaddingLeft, cell, NULL, ctxt, pval);
                   3310:              if ((delete || !value) && nextCell)
                   3311:                ctxt->destroy = TRUE;
                   3312:              else
                   3313:                {
                   3314:                  pval.typed_data.value = rightVal;
                   3315:                  pval.typed_data.unit = rightValUnit;
                   3316:                  ctxt->destroy = FALSE;
                   3317:                }
                   3318:              TtaSetStylePresentation (PRPaddingRight, cell, NULL, ctxt, pval);
                   3319:              cell = nextCell;
                   3320:              firstCell = FALSE;
                   3321:            }
                   3322:        }
                   3323:       TtaNextSibling (&row);
                   3324:     }
                   3325: 
                   3326:   if (value)
                   3327:     TtaFreeMemory (value);
                   3328: }
                   3329: 
                   3330: /*----------------------------------------------------------------------
1.159     quint    3331:    HandleRowlinesAttribute
                   3332:    An attribute rowlines has been created, updated or deleted (if delete
                   3333:    is TRUE) for element el in document doc. Update attribute MLineBelow
                   3334:    of all cells accordingly.
                   3335:   ----------------------------------------------------------------------*/
                   3336: void HandleRowlinesAttribute (Attribute attr, Element el, Document doc,
                   3337:                              ThotBool delete)
                   3338: {
                   3339:   char            *value;
1.160     quint    3340:   char            *ptr, *spanPtr;
                   3341:   int              length, val, rowspan, i, cellVal;
1.159     quint    3342:   ElementType      elType, rowType, cellType;
                   3343:   Element          row, nextRow, cell;
                   3344:   ThotBool         stop;
1.160     quint    3345:   AttributeType    attrType, rowspanType;
                   3346:   Attribute        intAttr, rowspanAttr;
1.159     quint    3347: 
                   3348:   elType = TtaGetElementType (el);
                   3349:   if (elType.ElTypeNum != MathML_EL_MTABLE ||
                   3350:       strcmp (TtaGetSSchemaName (elType.ElSSchema), "MathML"))
                   3351:     /* ignore rowlines attribute on mstyle elements */
                   3352:     /* process it only on mtable elements */
                   3353:     return;
                   3354: 
                   3355:   value = NULL;
                   3356:   if (!delete)
                   3357:     {
                   3358:       length = TtaGetTextAttributeLength (attr);
                   3359:       if (length > 0)
                   3360:        {
                   3361:          value = TtaGetMemory (length+1);
                   3362:          value[0] = EOS;
                   3363:          TtaGiveTextAttributeValue (attr, value, &length);
                   3364:        }
                   3365:     }
                   3366:   /* if attribute rowlines is created or updated but has no value, don't
                   3367:      do anything */
                   3368:   if (!delete && !value)
                   3369:     return;
                   3370: 
                   3371:   ptr = value;
                   3372:   val = 0;
                   3373:   attrType.AttrSSchema = elType.ElSSchema;
1.160     quint    3374:   rowspanType.AttrSSchema = elType.ElSSchema;
                   3375:   rowspanType.AttrTypeNum = MathML_ATTR_rowspan_;
1.159     quint    3376: 
                   3377:   /* check all rows within the table */
                   3378:   elType.ElTypeNum = MathML_EL_TableRow;
                   3379:   row = TtaSearchTypedElement (elType, SearchInTree, el);
                   3380:   while (row)
                   3381:     {
                   3382:       /* get the next row to check if the current row is the last one */
                   3383:       nextRow = row;
                   3384:       stop = FALSE;
                   3385:       do
                   3386:        {
                   3387:          TtaNextSibling (&nextRow);
                   3388:          if (!nextRow)
                   3389:            stop = TRUE;
                   3390:          else
                   3391:            {
                   3392:              rowType = TtaGetElementType (nextRow);
                   3393:              /* skip comments and other non mrow elements */
                   3394:              if ((rowType.ElTypeNum == MathML_EL_MTR ||
                   3395:                   rowType.ElTypeNum == MathML_EL_MLABELEDTR) &&
                   3396:                  !strcmp (TtaGetSSchemaName (rowType.ElSSchema), "MathML"))
                   3397:                /* it's the next mrow */
                   3398:                stop = TRUE;
                   3399:            }
                   3400:        }
                   3401:       while (!stop);
                   3402: 
                   3403:       if (!nextRow)
                   3404:        /* row is the last in the table. It must not have a line
                   3405:           at the bottom. Delete it if there is one */
                   3406:        val = 0;
                   3407:       else
                   3408:        {
                   3409:          if (delete)
                   3410:            val = 0;
                   3411:          else
                   3412:            if (*ptr != EOS)
                   3413:              {
                   3414:                /* get next word in the attribute value */
                   3415:                ptr = TtaSkipBlanks (ptr);
                   3416:                /* process that word */
                   3417:                if (*ptr != EOS && *ptr != ' ')
                   3418:                  {
                   3419:                    if (!strncasecmp (ptr, "none", 4))
                   3420:                      val = 0;
                   3421:                    else if (!strncasecmp (ptr, "solid", 5))
                   3422:                      val = MathML_ATTR_MLineBelow_VAL_solid_;
                   3423:                    else if (!strncasecmp (ptr, "dashed", 6))
                   3424:                      val = MathML_ATTR_MLineBelow_VAL_dashed_;
                   3425:                    else
                   3426:                      val = 0;
                   3427:                    /* skip the word that has been processed */
                   3428:                    while (*ptr != EOS && *ptr != ' ')
                   3429:                      ptr++;
                   3430:                  }
                   3431:              }
                   3432:        }
                   3433:       /* get the first cell of that row (ignoring Label cells) */
                   3434:       elType.ElTypeNum = MathML_EL_MTD;
                   3435:       cell = TtaSearchTypedElement (elType, SearchInTree, row);
                   3436:       /* update attribute MLineBelow for all cells in that row */
                   3437:       while (cell)
                   3438:        {
                   3439:          cellType = TtaGetElementType (cell);
                   3440:          /* skip comments and other non mtd elements */
                   3441:          if (cellType.ElTypeNum == MathML_EL_MTD &&
                   3442:              !strcmp (TtaGetSSchemaName (cellType.ElSSchema), "MathML"))
                   3443:            /* that's a mtd element. Process it */
                   3444:            {
1.160     quint    3445:              /* is there a rowspan attribute on that cell? */
                   3446:              rowspanAttr = TtaGetAttribute (cell, rowspanType);
                   3447:              if (!rowspanAttr)
                   3448:                rowspan = 1;
                   3449:              else
                   3450:                rowspan = TtaGetAttributeValue (rowspanAttr);
1.161     quint    3451:              /* by default, use the value for the current row */
                   3452:              cellVal = val;
                   3453:              if (!delete)
1.160     quint    3454:                {
1.161     quint    3455:                  /* skip rowspan-1 words in the value of attribute rowlines */
                   3456:                  if (rowspan > 1)
1.160     quint    3457:                    {
1.161     quint    3458:                      spanPtr = ptr;
                   3459:                      for (i = 1; i < rowspan && *spanPtr != EOS; i++)
1.160     quint    3460:                        {
1.161     quint    3461:                          spanPtr = TtaSkipBlanks (spanPtr);
                   3462:                          if (*spanPtr != EOS && *spanPtr != ' ')
                   3463:                            {
                   3464:                              if (!strncasecmp (spanPtr, "none", 4))
                   3465:                                cellVal = 0;
                   3466:                              else if (!strncasecmp (spanPtr, "solid", 5))
                   3467:                                cellVal = MathML_ATTR_MLineBelow_VAL_solid_;
                   3468:                              else if (!strncasecmp (spanPtr, "dashed", 6))
                   3469:                                cellVal = MathML_ATTR_MLineBelow_VAL_dashed_;
                   3470:                              else
                   3471:                                cellVal = 0;
                   3472:                            }
                   3473:                          /* skip the word that has been processed */
                   3474:                          while (*spanPtr != EOS && *spanPtr != ' ')
                   3475:                            spanPtr++;
1.160     quint    3476:                        }
                   3477:                    }
                   3478:                }
1.161     quint    3479:              if (rowspan == 1)
                   3480:                attrType.AttrTypeNum = MathML_ATTR_MLineBelow;
                   3481:              else
                   3482:                attrType.AttrTypeNum = MathML_ATTR_MLineBelowExt;
1.159     quint    3483:              intAttr = TtaGetAttribute (cell, attrType);
1.160     quint    3484:              if (cellVal == 0)
1.159     quint    3485:                {
                   3486:                  if (intAttr)
                   3487:                    /* remove attribute MLineBelow */
                   3488:                    TtaRemoveAttribute (cell, intAttr, doc);
                   3489:                }
                   3490:              else
                   3491:                /* set attribute MLineBelow */
                   3492:                {
                   3493:                  if (!intAttr)
                   3494:                    {
                   3495:                      intAttr = TtaNewAttribute (attrType);
                   3496:                      TtaAttachAttribute (cell, intAttr, doc);
                   3497:                    }
1.160     quint    3498:                  TtaSetAttributeValue (intAttr, cellVal, cell, doc);
1.159     quint    3499:                }
                   3500:            }
                   3501:          TtaNextSibling (&cell);
                   3502:        }
                   3503:       row = nextRow;
                   3504:     }
                   3505:   if (value)
                   3506:     TtaFreeMemory (value);
                   3507: }
                   3508: 
                   3509: /*----------------------------------------------------------------------
                   3510:    HandleColumnlinesAttribute
                   3511:    An attribute columnlines has been created, updated or deleted (if delete
                   3512:    is TRUE) for element el in document doc. Update attribute MLineOnTheRight
                   3513:    of all cells accordingly.
                   3514:   ----------------------------------------------------------------------*/
                   3515: void HandleColumnlinesAttribute (Attribute attr, Element el, Document doc,
                   3516:                                 ThotBool delete)
                   3517: {
                   3518:   char            *value;
                   3519:   char            *ptr;
1.161     quint    3520:   int              length, val, colspan, rowspan, i;
1.159     quint    3521:   ElementType      elType;
                   3522:   Element          row, cell, nextCell;
                   3523:   ThotBool         stop;
1.161     quint    3524:   AttributeType    attrType, colspanType, rowspanType;
                   3525:   Attribute        intAttr, spanAttr;
1.159     quint    3526: 
                   3527:   elType = TtaGetElementType (el);
                   3528:   if (elType.ElTypeNum != MathML_EL_MTABLE ||
                   3529:       strcmp (TtaGetSSchemaName (elType.ElSSchema), "MathML"))
                   3530:     /* ignore rowlines attribute on mstyle elements */
                   3531:     /* process it only on mtable elements */
                   3532:     return;
                   3533: 
                   3534:   value = NULL;
                   3535:   if (!delete)
                   3536:     {
                   3537:       length = TtaGetTextAttributeLength (attr);
                   3538:       if (length > 0)
                   3539:        {
                   3540:          value = TtaGetMemory (length+1);
                   3541:          value[0] = EOS;
                   3542:          TtaGiveTextAttributeValue (attr, value, &length);
                   3543:        }
                   3544:     }
                   3545:   /* if attribute columnlines is created or updated but has no value, don't
                   3546:      do anything */
                   3547:   if (!delete && !value)
                   3548:     return;
                   3549: 
                   3550:   val = 0;
                   3551:   attrType.AttrSSchema = elType.ElSSchema;
1.160     quint    3552:   colspanType.AttrSSchema = elType.ElSSchema;
                   3553:   colspanType.AttrTypeNum = MathML_ATTR_columnspan;
1.161     quint    3554:   rowspanType.AttrSSchema = elType.ElSSchema;
                   3555:   rowspanType.AttrTypeNum = MathML_ATTR_rowspan_;
1.159     quint    3556: 
                   3557:   /* check all cells in all rows in the table */
                   3558:   elType.ElTypeNum = MathML_EL_TableRow;
                   3559:   row = TtaSearchTypedElement (elType, SearchInTree, el);
                   3560:   while (row)
                   3561:     {
                   3562:       elType = TtaGetElementType (row);
                   3563:       if ((elType.ElTypeNum == MathML_EL_MTR ||
                   3564:           elType.ElTypeNum == MathML_EL_MLABELEDTR) &&
                   3565:          strcmp (TtaGetSSchemaName (elType.ElSSchema), "MathML") == 0)
                   3566:        /* that's a table row. check all its cells */
                   3567:        {
                   3568:          /* start from the beginning of the columnlines attribute */
                   3569:          ptr = value;
                   3570:          val = 0;
                   3571:          /* get the first cell of that row (ignoring Label cells) */
                   3572:          elType.ElTypeNum = MathML_EL_MTD;
                   3573:          cell = TtaSearchTypedElement (elType, SearchInTree, row);
                   3574:          while (cell)
                   3575:            {
                   3576:              /* get the next cell in the current row to check if the current
                   3577:                 cell is the last one in the row */
                   3578:              nextCell = cell;
                   3579:              stop = FALSE;
                   3580:              do
                   3581:                {
                   3582:                  TtaNextSibling (&nextCell);
                   3583:                  if (!nextCell)
                   3584:                    stop = TRUE;
                   3585:                  else
                   3586:                    {
                   3587:                      elType = TtaGetElementType (nextCell);
                   3588:                      /* skip comments and other non mtd elements */
                   3589:                      if (elType.ElTypeNum == MathML_EL_MTD &&
                   3590:                          strcmp (TtaGetSSchemaName (elType.ElSSchema), "MathML") == 0)
                   3591:                        /* it's the next cell */
                   3592:                        stop = TRUE;
                   3593:                    }
                   3594:                }
                   3595:              while (!stop);
                   3596: 
1.161     quint    3597:              /* is there a rowspan attribute on that cell? */
                   3598:              spanAttr = TtaGetAttribute (cell, rowspanType);
                   3599:              if (!spanAttr)
                   3600:                rowspan = 1;
                   3601:              else
                   3602:                rowspan = TtaGetAttributeValue (spanAttr);
                   3603: 
1.159     quint    3604:              if (!nextCell)
                   3605:                /* it's the last cell in the row. It must not have a line
                   3606:                   on its right edge. Delete it if there is noe. */
                   3607:                val = 0;
                   3608:              else
                   3609:                /* set the attribute MLineOnTheRight for this cell */
                   3610:                {
                   3611:                  if (delete)
                   3612:                    val = 0;
                   3613:                  else
                   3614:                    if (*ptr != EOS)
                   3615:                      {
1.161     quint    3616:                        /* is there a columnspan attribute on that cell? */
                   3617:                        spanAttr = TtaGetAttribute (cell, colspanType);
                   3618:                        if (!spanAttr)
1.160     quint    3619:                          colspan = 1;
                   3620:                        else
1.161     quint    3621:                          colspan = TtaGetAttributeValue (spanAttr);
1.160     quint    3622:                        /* skip (colspan - 1) words in the attribute */
                   3623:                        for (i = 1; i <= colspan && *ptr != EOS; i++)
1.159     quint    3624:                          {
1.160     quint    3625:                            /* get next word in the attribute value */
                   3626:                            ptr = TtaSkipBlanks (ptr);
                   3627:                            /* process that word */
                   3628:                            if (*ptr != EOS && *ptr != ' ')
                   3629:                              {
                   3630:                                if (!strncasecmp (ptr, "none", 4))
                   3631:                                  val = 0;
                   3632:                                else if (!strncasecmp (ptr, "solid", 5))
                   3633:                                  val = MathML_ATTR_MLineOnTheRight_VAL_solid_;
                   3634:                                else if (!strncasecmp (ptr, "dashed", 6))
                   3635:                                  val = MathML_ATTR_MLineOnTheRight_VAL_dashed_;
                   3636:                                else
                   3637:                                  val = 0;
                   3638:                                /* skip the word that has been processed */
                   3639:                                while (*ptr != EOS && *ptr != ' ')
                   3640:                                  ptr++;
                   3641:                              }
1.159     quint    3642:                          }
                   3643:                      }
                   3644:                }
1.161     quint    3645:              if (rowspan == 1)
                   3646:                attrType.AttrTypeNum = MathML_ATTR_MLineOnTheRight;
                   3647:              else
                   3648:                attrType.AttrTypeNum = MathML_ATTR_MLineOnTheRightExt;
1.159     quint    3649:              intAttr = TtaGetAttribute (cell, attrType);
                   3650:              if (val == 0)
                   3651:                {
                   3652:                  if (intAttr)
                   3653:                    /* remove attribute MLineOnTheRight */
                   3654:                    TtaRemoveAttribute (cell, intAttr, doc);
                   3655:                }
                   3656:              else
                   3657:                /* set attribute MLineOnTheRight */
                   3658:                {
                   3659:                  if (!intAttr)
                   3660:                    {
                   3661:                      intAttr = TtaNewAttribute (attrType);
                   3662:                      TtaAttachAttribute (cell, intAttr, doc);
                   3663:                    }
                   3664:                  TtaSetAttributeValue (intAttr, val, cell, doc);
                   3665:                }
                   3666:              cell = nextCell;
                   3667:            }
                   3668:        }
                   3669:       TtaNextSibling (&row);
                   3670:     }
                   3671:   if (value)
                   3672:     TtaFreeMemory (value);
                   3673: }
                   3674: 
                   3675: /*----------------------------------------------------------------------
1.168     quint    3676:    HandleFramespacingAttribute
                   3677:    An attribute framespacing has been created, updated or deleted (if delete
                   3678:    is TRUE) for element el in document doc. Update attribute the padding
                   3679:    properties of the concerned table(s).
                   3680:   ----------------------------------------------------------------------*/
                   3681: void HandleFramespacingAttribute (Attribute attr, Element el, Document doc,
                   3682:                                  ThotBool delete)
                   3683: {
                   3684:   ElementType         elType;
                   3685:   char                *value, *ptr, valueOfNamedSpace[20];
                   3686:   int                 length, vertPadding, horizPadding, vertPaddingUnit,
                   3687:                       horizPaddingUnit;
                   3688:   Attribute           attrFrame;
                   3689:   AttributeType       attrType;
                   3690:   PresentationValue   pval;
                   3691:   PresentationContext ctxt;
                   3692:   ThotBool            vertPaddingReal, horizPaddingReal;
                   3693: 
                   3694:   if ((!delete && !attr) || !el)
                   3695:     return;
                   3696:   elType = TtaGetElementType (el);
                   3697:   if (elType.ElTypeNum != MathML_EL_MTABLE ||
                   3698:       strcmp (TtaGetSSchemaName (elType.ElSSchema), "MathML"))
                   3699:     /* ignore framespacing attribute on mstyle elements */
                   3700:     /* process it only on mtable elements */
                   3701:     return;
                   3702: 
                   3703:   value = NULL;
                   3704:   if (!delete)
                   3705:     {
                   3706:       length = TtaGetTextAttributeLength (attr);
                   3707:       if (length > 0)
                   3708:        {
                   3709:          value = TtaGetMemory (length+1);
                   3710:          value[0] = EOS;
                   3711:          TtaGiveTextAttributeValue (attr, value, &length);
                   3712:        }
                   3713:     }
                   3714:   ctxt = TtaGetSpecificStyleContext (doc);
                   3715:   /* the specific presentation to be created is not a CSS rule */
                   3716:   ctxt->cssSpecificity = 0;
                   3717:   vertPadding = 0;
                   3718:   horizPadding = 0;
                   3719:   vertPaddingUnit = STYLE_UNIT_PT;
                   3720:   horizPaddingUnit = STYLE_UNIT_PT;
                   3721:   vertPaddingReal = FALSE;
                   3722:   horizPaddingReal = FALSE;
                   3723:   /* is there a frame attribute? */
                   3724:   attrType.AttrSSchema = elType.ElSSchema;
                   3725:   attrType.AttrTypeNum = MathML_ATTR_frame;
                   3726:   attrFrame = TtaGetAttribute (el, attrType);
                   3727:   if (!delete && value && attrFrame)
                   3728:     {
                   3729:       ptr = value;
                   3730:       /* parse the first part: horizontal spacing */
                   3731:       ptr = TtaSkipBlanks (ptr);
                   3732:       if (*ptr != EOS)
                   3733:        {
                   3734:          ptr = ConvertNamedSpace (ptr, valueOfNamedSpace);
                   3735:          if (valueOfNamedSpace[0] != EOS)
                   3736:            /* it's a named space */
                   3737:            ptr = ParseCSSUnit (valueOfNamedSpace, &pval);
                   3738:          else
                   3739:            ptr = ParseCSSUnit (ptr, &pval);
                   3740:          if (pval.typed_data.unit != STYLE_UNIT_INVALID)
                   3741:            {
                   3742:              horizPadding = pval.typed_data.value;
                   3743:              horizPaddingUnit = pval.typed_data.unit;
                   3744:              horizPaddingReal = pval.typed_data.real;
                   3745:              /* if there is no second part, the vertical spacing is the same
                   3746:                 as the horizontal spacing */
                   3747:              vertPadding = horizPadding;
                   3748:              vertPaddingUnit = horizPaddingUnit;
                   3749:              vertPaddingReal = horizPaddingReal;
                   3750:              /* parse the second part, if any */
                   3751:              ptr = TtaSkipBlanks (ptr);
                   3752:              if (*ptr != EOS)
                   3753:                {
                   3754:                  ptr = ConvertNamedSpace (ptr, valueOfNamedSpace);
                   3755:                  if (valueOfNamedSpace[0] != EOS)
                   3756:                    /* it's a named space */
                   3757:                    ptr = ParseCSSUnit (valueOfNamedSpace, &pval);
                   3758:                  else
                   3759:                    ptr = ParseCSSUnit (ptr, &pval);
                   3760:                  if (pval.typed_data.unit != STYLE_UNIT_INVALID)
                   3761:                    {
                   3762:                      vertPadding = pval.typed_data.value;
                   3763:                      vertPaddingUnit = pval.typed_data.unit;
                   3764:                      vertPaddingReal = pval.typed_data.real;
                   3765:                    }
                   3766:                }
                   3767:            }
                   3768:        }
                   3769:     }
                   3770:   if (delete)
                   3771:     ctxt->destroy = TRUE;
                   3772:   else
                   3773:     {
                   3774:       ctxt->destroy = FALSE;
                   3775:       pval.typed_data.value = horizPadding;
                   3776:       pval.typed_data.unit = horizPaddingUnit;
                   3777:       pval.typed_data.real = horizPaddingReal;
                   3778:     }
                   3779:   TtaSetStylePresentation (PRPaddingLeft, el, NULL, ctxt, pval);
                   3780:   TtaSetStylePresentation (PRPaddingRight, el, NULL, ctxt, pval);
                   3781:   if (!delete)
                   3782:     {
                   3783:       pval.typed_data.value = vertPadding;
                   3784:       pval.typed_data.unit = vertPaddingUnit;
                   3785:       pval.typed_data.real = vertPaddingReal;
                   3786:     }
                   3787:   TtaSetStylePresentation (PRPaddingTop, el, NULL, ctxt, pval);
                   3788:   TtaSetStylePresentation (PRPaddingBottom, el, NULL, ctxt, pval);
                   3789: 
                   3790:   if (value)
                   3791:     TtaFreeMemory (value);
                   3792: }
                   3793: 
                   3794: /*----------------------------------------------------------------------
1.169     quint    3795:    SetDisplaystyleMathElement
                   3796:    Associate a IntDisplaystyle attribute with element el (which is a
                   3797:    <math> element), and set its value depending on the surrounding context.
                   3798:   ----------------------------------------------------------------------*/
                   3799: void   SetDisplaystyleMathElement (Element el, Document doc)
                   3800: {
                   3801:   Element               parent, sibling;
                   3802:   ElementType          elType, parentType;
                   3803:   Attribute             attr;
                   3804:   AttributeType         attrType;
                   3805:   int                   display, val;
                   3806: 
                   3807:   display = MathML_ATTR_IntDisplaystyle_VAL_true;
                   3808:   /* is there an attribute display? */
                   3809:   elType = TtaGetElementType (el);
                   3810:   attrType.AttrSSchema = elType.ElSSchema;
                   3811:   attrType.AttrTypeNum = MathML_ATTR_display;
                   3812:   attr = TtaGetAttribute (el, attrType);
                   3813:   if (attr)
                   3814:     /* there is an attribute display. Take its value */
                   3815:     {
                   3816:       val = TtaGetAttributeValue (attr);
                   3817:       if (val == MathML_ATTR_display_VAL_block)
                   3818:        display = MathML_ATTR_IntDisplaystyle_VAL_true;
                   3819:       else
                   3820:        display = MathML_ATTR_IntDisplaystyle_VAL_false;
                   3821:     }
                   3822:   else
                   3823:     /* no attribute display. Look at the context */
                   3824:     {
                   3825:       parent = TtaGetParent (el);
                   3826:       parentType = TtaGetElementType (parent);
                   3827:       if (elType.ElSSchema == parentType.ElSSchema)
                   3828:        /* it's the only <math> element in a MathML document */
                   3829:        display = MathML_ATTR_IntDisplaystyle_VAL_true;
                   3830:       else
                   3831:        /* it's a MathML expression within another vocabulary */
                   3832:        {
                   3833:          if (!strcmp (TtaGetSSchemaName (parentType.ElSSchema), "SVG"))
                   3834:            /* a <math> element in a SVG element */
                   3835:            display = MathML_ATTR_IntDisplaystyle_VAL_true;
                   3836:          else if (!strcmp (TtaGetSSchemaName (parentType.ElSSchema), "HTML"))
                   3837:            /* a <math> element in a HTML element */
                   3838:            {
                   3839:              display = MathML_ATTR_IntDisplaystyle_VAL_false;
                   3840:              if (parentType.ElTypeNum == HTML_EL_BODY ||
                   3841:                  parentType.ElTypeNum == HTML_EL_Division)
                   3842:                display = MathML_ATTR_IntDisplaystyle_VAL_true;
                   3843:              else if (parentType.ElTypeNum == HTML_EL_Pseudo_paragraph ||
                   3844:                       parentType.ElTypeNum == HTML_EL_Paragraph)
                   3845:                {
                   3846:                  sibling = el;
                   3847:                  TtaPreviousSibling (&sibling);
                   3848:                  if (!sibling)
                   3849:                    {
                   3850:                      sibling = el;
                   3851:                      TtaNextSibling (&sibling);
                   3852:                      if (!sibling)
                   3853:                        display = MathML_ATTR_IntDisplaystyle_VAL_true;
                   3854:                    }
                   3855:                }
                   3856:            }
                   3857:        }
                   3858:     }
                   3859:   /* create the IntDisplastyle attribute and set its value */
                   3860:   attrType.AttrTypeNum = MathML_ATTR_IntDisplaystyle;
                   3861:   attr = TtaGetAttribute (el, attrType);
                   3862:   if (!attr)
                   3863:     {
                   3864:       attr = TtaNewAttribute (attrType);
                   3865:       TtaAttachAttribute (el, attr, doc);
                   3866:     }
                   3867:   TtaSetAttributeValue (attr, display, el, doc);
                   3868: }
                   3869: 
                   3870: /*----------------------------------------------------------------------
                   3871:    MathMLElementCreated
                   3872:    The XML parser has just inserted a new element in the abstract tree.
                   3873:   ----------------------------------------------------------------------*/
                   3874: void      MathMLElementCreated (Element el, Document doc)
                   3875: {
                   3876:   ElementType          elType;
                   3877: 
                   3878:   elType = TtaGetElementType (el);
                   3879:   if (elType.ElTypeNum == MathML_EL_MathML)
                   3880:     /* associate a IntDisplaystyle attribute with the element depending
                   3881:        on its context */
                   3882:     SetDisplaystyleMathElement (el, doc);    
                   3883: }
                   3884: 
                   3885: /*----------------------------------------------------------------------
1.1       cvs      3886:    MathMLElementComplete
1.169     quint    3887:    Element el has just been completed by the XML parser.
1.1       cvs      3888:    Check the Thot structure of the MathML element el.
                   3889:   ----------------------------------------------------------------------*/
1.156     cvs      3890: void      MathMLElementComplete (ParserData *context, Element el, int *error)
1.1       cvs      3891: {
1.156     cvs      3892:    Document             doc;   
1.74      cvs      3893:    ElementType         elType, parentType;
1.1       cvs      3894:    Element             child, parent, new, prev, next;
1.101     cvs      3895:    AttributeType        attrType;
                   3896:    Attribute            attr;
1.56      cvs      3897:    SSchema              MathMLSSchema;
                   3898:    ThotBool             ok;
1.1       cvs      3899: 
1.56      cvs      3900:    ok = TRUE;
                   3901:    *error = 0;
1.156     cvs      3902:    doc = context->doc;
1.1       cvs      3903:    elType = TtaGetElementType (el);
1.2       cvs      3904:    MathMLSSchema = GetMathMLSSchema (doc);
1.1       cvs      3905: 
1.76      cvs      3906:    if (elType.ElSSchema == MathMLSSchema)
1.1       cvs      3907:      {
                   3908:      switch (elType.ElTypeNum)
                   3909:        {
1.76      cvs      3910:        case MathML_EL_MathML:
                   3911:          /* Create placeholders within the MathML element */
                   3912:          CreatePlaceholders (TtaGetFirstChild (el), doc);
1.132     cvs      3913:          break;
1.1       cvs      3914:        case MathML_EL_MI:
                   3915:          SetFontstyleAttr (el, doc);
                   3916:          break;
                   3917:        case MathML_EL_MO:
1.22      cvs      3918:          SetIntAddSpaceAttr (el, doc);
                   3919:          SetIntVertStretchAttr (el, doc, 0, NULL);
1.58      cvs      3920:          /* if the MO element is a child of a MROW (or equivalent) and if it
                   3921:             contains a fence character, transform this MO into MF and
                   3922:             transform the fence character into a Thot SYMBOL */
1.170     quint    3923:          CheckFenceLargeOp (el, doc);
1.1       cvs      3924:          break;
1.60      cvs      3925:        case MathML_EL_MSPACE:
                   3926:          break;
1.39      cvs      3927:        case MathML_EL_MROW:
1.55      cvs      3928:          /* Create placeholders within the MROW */
                   3929:           CreatePlaceholders (TtaGetFirstChild (el), doc);
1.39      cvs      3930:          break;
                   3931:        case MathML_EL_MFRAC:
1.54      cvs      3932:        case MathML_EL_BevelledMFRAC:
1.39      cvs      3933:          /* end of a fraction. Create a Numerator and a Denominator */
1.56      cvs      3934:          ok = CheckMathSubExpressions (el, MathML_EL_Numerator,
                   3935:                                        MathML_EL_Denominator, 0, doc);
1.39      cvs      3936:          break;
                   3937:        case MathML_EL_MSQRT:
1.50      cvs      3938:          /* end of a Square Root */
                   3939:          /* Create placeholders within the element */
                   3940:           CreatePlaceholders (TtaGetFirstChild (el), doc);
                   3941:          /* Create a SqrtBase that contains all children of the MSQRT */
1.39      cvs      3942:          CreateWrapper (el, MathML_EL_SqrtBase, doc);
                   3943:          break;
1.1       cvs      3944:        case MathML_EL_MROOT:
                   3945:          /* end of a Root. Create a RootBase and an Index */
1.56      cvs      3946:          ok = CheckMathSubExpressions (el, MathML_EL_RootBase,
                   3947:                                        MathML_EL_Index, 0, doc);
1.1       cvs      3948:          break;
1.50      cvs      3949:        case MathML_EL_MENCLOSE:
                   3950:          /* Create placeholders within the element */
                   3951:           CreatePlaceholders (TtaGetFirstChild (el), doc);
                   3952:          break;
1.39      cvs      3953:        case MathML_EL_MSTYLE:
                   3954:        case MathML_EL_MERROR:
                   3955:        case MathML_EL_MPADDED:
                   3956:        case MathML_EL_MPHANTOM:
                   3957:          /* Create placeholders within the element */
                   3958:           CreatePlaceholders (TtaGetFirstChild (el), doc);
1.1       cvs      3959:          break;
                   3960:        case MathML_EL_MFENCED:
                   3961:          TransformMFENCED (el, doc);
                   3962:          break;
                   3963:        case MathML_EL_MSUB:
                   3964:          /* end of a MSUB. Create Base and Subscript */
1.56      cvs      3965:          ok = CheckMathSubExpressions (el, MathML_EL_Base,
                   3966:                                        MathML_EL_Subscript, 0, doc);
1.59      cvs      3967:          SetScriptShift (el, doc, MathML_ATTR_subscriptshift);
1.22      cvs      3968:          SetIntVertStretchAttr (el, doc, MathML_EL_Base, NULL);
1.1       cvs      3969:          break;
                   3970:        case MathML_EL_MSUP:
                   3971:          /* end of a MSUP. Create Base and Superscript */
1.56      cvs      3972:          ok = CheckMathSubExpressions (el, MathML_EL_Base,
                   3973:                                        MathML_EL_Superscript, 0, doc);
1.59      cvs      3974:          SetScriptShift (el, doc, MathML_ATTR_superscriptshift);
1.22      cvs      3975:          SetIntVertStretchAttr (el, doc, MathML_EL_Base, NULL);
1.1       cvs      3976:          break;
1.39      cvs      3977:        case MathML_EL_MSUBSUP:
                   3978:          /* end of a MSUBSUP. Create Base, Subscript, and Superscript */
1.56      cvs      3979:          ok = CheckMathSubExpressions (el, MathML_EL_Base,
                   3980:                                        MathML_EL_Subscript,
                   3981:                                        MathML_EL_Superscript, doc);
1.59      cvs      3982:          SetScriptShift (el, doc, MathML_ATTR_subscriptshift);
                   3983:          SetScriptShift (el, doc, MathML_ATTR_superscriptshift);
1.39      cvs      3984:          SetIntVertStretchAttr (el, doc, MathML_EL_Base, NULL);
1.1       cvs      3985:          break;
                   3986:        case MathML_EL_MUNDER:
                   3987:          /* end of a MUNDER. Create UnderOverBase, and Underscript */
1.56      cvs      3988:          ok = CheckMathSubExpressions (el, MathML_EL_UnderOverBase,
                   3989:                                        MathML_EL_Underscript, 0, doc);
1.22      cvs      3990:          SetIntHorizStretchAttr (el, doc);
                   3991:          SetIntVertStretchAttr (el, doc, MathML_EL_UnderOverBase, NULL);
1.169     quint    3992:          SetIntMovelimitsAttr (el, doc);
1.1       cvs      3993:          break;
                   3994:        case MathML_EL_MOVER:
                   3995:          /* end of a MOVER. Create UnderOverBase, and Overscript */
1.56      cvs      3996:          ok = CheckMathSubExpressions (el, MathML_EL_UnderOverBase,
                   3997:                                        MathML_EL_Overscript, 0, doc);
1.22      cvs      3998:          SetIntHorizStretchAttr (el, doc);
                   3999:          SetIntVertStretchAttr (el, doc, MathML_EL_UnderOverBase, NULL);
1.169     quint    4000:          SetIntMovelimitsAttr (el, doc);
1.1       cvs      4001:          break;
1.39      cvs      4002:        case MathML_EL_MUNDEROVER:
                   4003:          /* end of a MUNDEROVER. Create UnderOverBase, Underscript, and
                   4004:             Overscript */
1.56      cvs      4005:          ok = CheckMathSubExpressions (el, MathML_EL_UnderOverBase,
                   4006:                                        MathML_EL_Underscript,
                   4007:                                        MathML_EL_Overscript, doc);
1.39      cvs      4008:          SetIntHorizStretchAttr (el, doc);
                   4009:          SetIntVertStretchAttr (el, doc, MathML_EL_UnderOverBase, NULL);
1.169     quint    4010:          SetIntMovelimitsAttr (el, doc);
1.39      cvs      4011:          break;
1.1       cvs      4012:        case MathML_EL_MMULTISCRIPTS:
                   4013:          /* end of a MMULTISCRIPTS. Create all elements defined in the
                   4014:             MathML S schema */
                   4015:          BuildMultiscript (el, doc);
1.5       cvs      4016:          break;
                   4017:        case MathML_EL_MTABLE:
                   4018:          /* end of a MTABLE. Create all elements defined in the MathML S
                   4019:              schema */
1.64      cvs      4020:          CheckMTable (el, doc, TRUE);
1.101     cvs      4021:          /* if the table has a rowalign attribute, process it */
                   4022:           attrType.AttrSSchema = MathMLSSchema;
                   4023:           attrType.AttrTypeNum = MathML_ATTR_rowalign;
                   4024:          attr = TtaGetAttribute (el, attrType);
                   4025:          if (attr)
                   4026:             HandleRowalignAttribute (attr, el, doc, FALSE);
                   4027:          /* if the table has a columnalign attribute, process it */
                   4028:           attrType.AttrTypeNum = MathML_ATTR_columnalign;
                   4029:          attr = TtaGetAttribute (el, attrType);
                   4030:          if (attr)
1.108     cvs      4031:             HandleColalignAttribute (attr, el, doc, FALSE, FALSE);
1.167     quint    4032:          /* process the rowspacing attribute, or set the top padding of the
                   4033:             first row and the bottom padding of the last row to 0. */
                   4034:           attrType.AttrSSchema = MathMLSSchema;
                   4035:           attrType.AttrTypeNum = MathML_ATTR_rowspacing;
                   4036:          attr = TtaGetAttribute (el, attrType);
                   4037:          HandleRowspacingAttribute (attr, el, doc, FALSE);
                   4038:          /* process the columnspacing attribute, or set the left padding of
                   4039:             the first column and the right padding of the last column to 0 */
                   4040:           attrType.AttrSSchema = MathMLSSchema;
                   4041:           attrType.AttrTypeNum = MathML_ATTR_columnspacing;
                   4042:          attr = TtaGetAttribute (el, attrType);
                   4043:          HandleColumnspacingAttribute (attr, el, doc, FALSE);
1.159     quint    4044:          /* if the table has a rowlines attribute, process it */
                   4045:           attrType.AttrSSchema = MathMLSSchema;
                   4046:           attrType.AttrTypeNum = MathML_ATTR_rowlines;
                   4047:          attr = TtaGetAttribute (el, attrType);
                   4048:          if (attr)
1.167     quint    4049:            HandleRowlinesAttribute (attr, el, doc, FALSE);
1.159     quint    4050:          /* if the table has a columnlines attribute, process it */
                   4051:           attrType.AttrTypeNum = MathML_ATTR_columnlines;
                   4052:          attr = TtaGetAttribute (el, attrType);
                   4053:          if (attr)
                   4054:             HandleColumnlinesAttribute (attr, el, doc, FALSE);
1.101     cvs      4055:          break;
                   4056:        case MathML_EL_MTR:
                   4057:          /* if the row has a columnalign attribute, process it */
                   4058:           attrType.AttrSSchema = MathMLSSchema;
                   4059:           attrType.AttrTypeNum = MathML_ATTR_columnalign;
                   4060:          attr = TtaGetAttribute (el, attrType);
                   4061:          if (attr)
1.108     cvs      4062:             HandleColalignAttribute (attr, el, doc, FALSE, TRUE);
1.101     cvs      4063:          break;
                   4064:        case MathML_EL_MLABELEDTR:
                   4065:          /* if the row has a columnalign attribute, process it */
                   4066:           attrType.AttrSSchema = MathMLSSchema;
                   4067:           attrType.AttrTypeNum = MathML_ATTR_columnalign;
                   4068:          attr = TtaGetAttribute (el, attrType);
                   4069:          if (attr)
1.108     cvs      4070:             HandleColalignAttribute (attr, el, doc, FALSE, TRUE);
1.1       cvs      4071:          break;
1.39      cvs      4072:        case MathML_EL_MTD:
                   4073:          /* Create placeholders within the table cell */
                   4074:           CreatePlaceholders (TtaGetFirstChild (el), doc);
1.46      cvs      4075:          break;
1.39      cvs      4076:        case MathML_EL_MACTION:
                   4077:          /* Create placeholders within the MACTION element */
                   4078:           CreatePlaceholders (TtaGetFirstChild (el), doc);
1.1       cvs      4079:          break;
                   4080:        default:
                   4081:          break;
                   4082:        }
                   4083:      parent = TtaGetParent (el);
1.118     cvs      4084:      if (parent)
                   4085:        {
                   4086:         parentType = TtaGetElementType (parent);
                   4087:         if (parentType.ElSSchema != elType.ElSSchema)
                   4088:           /* root of a MathML tree, Create a MathML element if there is no */
                   4089:           if (elType.ElTypeNum != MathML_EL_MathML)
                   4090:             {
                   4091:               elType.ElSSchema = MathMLSSchema;
                   4092:               elType.ElTypeNum = MathML_EL_MathML;
                   4093:               new = TtaNewElement (doc, elType);
                   4094:               TtaInsertSibling (new, el, TRUE, doc);
                   4095:               next = el;
                   4096:               TtaNextSibling (&next);
                   4097:               TtaRemoveTree (el, doc);
                   4098:               TtaInsertFirstChild (&el, new, doc);
                   4099:               prev = el;
                   4100:               while (next != NULL)
                   4101:                 {
                   4102:                   child = next;
                   4103:                   TtaNextSibling (&next);
                   4104:                   TtaRemoveTree (child, doc);
                   4105:                   TtaInsertSibling (child, prev, FALSE, doc);
                   4106:                   prev = child;
                   4107:                 }
1.169     quint    4108:               /* associate a IntDisplaystyle attribute with the element
                   4109:                  depending on its context */
                   4110:               SetDisplaystyleMathElement (new, doc);
1.118     cvs      4111:               /* Create placeholders within the MathML element */
1.169     quint    4112:               CreatePlaceholders (new, doc);
1.118     cvs      4113:             }
                   4114:        }
1.1       cvs      4115:      }
1.56      cvs      4116:    if (!ok)
                   4117:      /* send an error message */
                   4118:      *error = 1;
1.1       cvs      4119: }
                   4120: 
                   4121: /*----------------------------------------------------------------------
1.126     cvs      4122:    UnknownMathMLNameSpace
1.149     cvs      4123:    The element doesn't belong to a supported namespace
1.126     cvs      4124:   ----------------------------------------------------------------------*/
1.149     cvs      4125: void               UnknownMathMLNameSpace (ParserData *context,
                   4126:                                           Element *unknownEl,
                   4127:                                           char* content)
1.126     cvs      4128: {
                   4129:    ElementType     elType;
1.149     cvs      4130:    Element         elText;
1.126     cvs      4131: 
                   4132:    /* Create a new Invalid_element */
                   4133:    elType.ElSSchema = GetXMLSSchema (MATH_TYPE, context->doc);
                   4134:    elType.ElTypeNum = MathML_EL_Unknown_namespace;
1.149     cvs      4135:    *unknownEl = TtaNewElement (context->doc, elType);
                   4136:    if (*unknownEl != NULL)
1.126     cvs      4137:      {
1.149     cvs      4138:        XmlSetElemLineNumber (*unknownEl);
                   4139:        InsertXmlElement (unknownEl);
1.126     cvs      4140:        context->lastElementClosed = TRUE;
                   4141:        elType.ElTypeNum = MathML_EL_TEXT_UNIT;
                   4142:        elText = TtaNewElement (context->doc, elType);
                   4143:        XmlSetElemLineNumber (elText);
1.149     cvs      4144:        TtaInsertFirstChild (&elText, *unknownEl, context->doc);
1.126     cvs      4145:        TtaSetTextContent (elText, content, context->language, context->doc);
                   4146:        TtaSetAccessRight (elText, ReadOnly, context->doc);
                   4147:    }
                   4148: }
                   4149: 
                   4150: /*----------------------------------------------------------------------
1.24      cvs      4151:  SetFontfamily
                   4152:  -----------------------------------------------------------------------*/
1.120     cvs      4153: void SetFontfamily (Document doc, Element el, char *value)
1.24      cvs      4154: {
                   4155: #define buflen 50
1.116     cvs      4156:   char           css_command[buflen+20];
1.24      cvs      4157:  
1.116     cvs      4158:   sprintf (css_command, "font-family: %s", value);
1.72      cvs      4159:   ParseHTMLSpecificStyle (el, css_command, doc, 0, FALSE);
1.24      cvs      4160: }
                   4161: 
                   4162: /*----------------------------------------------------------------------
1.83      cvs      4163:  MathMLlinethickness
                   4164:  The MathML attribute linthickness is associated with element el. Generate
                   4165:  the corresponding style property for this element. 
                   4166:  -----------------------------------------------------------------------*/
1.120     cvs      4167: void MathMLlinethickness (Document doc, Element el, char *value)
1.83      cvs      4168: {
                   4169: #define buflen 50
1.116     cvs      4170:   char           css_command[buflen+20];
1.83      cvs      4171: 
1.116     cvs      4172:   if (strcmp (value, "thin") == 0)
                   4173:      strcpy (value, "1pt");
                   4174:   else if (strcmp (value, "medium") == 0)
                   4175:      strcpy (value, "1pt");
                   4176:   else if (strcmp (value, "thick") == 0)
                   4177:      strcpy (value, "2pt");
                   4178:   sprintf (css_command, "stroke-width: %s", value);
1.83      cvs      4179:   ParseHTMLSpecificStyle (el, css_command, doc, 0, FALSE);
                   4180: }
                   4181: 
                   4182: /*----------------------------------------------------------------------
1.58      cvs      4183:  MathMLAttrToStyleProperty
                   4184:  The MathML attribute attr is associated with element el. Generate
                   4185:  the corresponding style property for this element.
1.24      cvs      4186:  -----------------------------------------------------------------------*/
1.138     cvs      4187: void MathMLAttrToStyleProperty (Document doc, Element el, char *value,
                   4188:                                int attr)
1.24      cvs      4189: {
1.167     quint    4190:   char           css_command[buflen+20], namedSpaceVal[20];
1.141     quint    4191:   int            i;
1.58      cvs      4192: 
                   4193:   switch (attr)
                   4194:     {
                   4195:     case MathML_ATTR_fontsize:
1.116     cvs      4196:        sprintf (css_command, "font-size: %s", value);
1.58      cvs      4197:        break;
1.93      cvs      4198:     case MathML_ATTR_mathsize:
1.116     cvs      4199:        if (strcmp (value, "small") == 0)
                   4200:         strcpy (value, "80%");
                   4201:        else if (strcmp (value, "normal") == 0)
                   4202:         strcpy (value, "100%");
                   4203:        else if (strcmp (value, "big") == 0)
                   4204:         strcpy (value, "125%");
                   4205:        sprintf (css_command, "font-size: %s", value);
1.93      cvs      4206:        break;
1.58      cvs      4207:     case MathML_ATTR_lspace:
                   4208:     case MathML_ATTR_rspace:
1.141     quint    4209:        if (attr == MathML_ATTR_lspace)
                   4210:         strcpy (css_command, "padding-left: ");
                   4211:        else
                   4212:         strcpy (css_command, "padding-right: ");
1.167     quint    4213:        ConvertNamedSpace (value, namedSpaceVal);
                   4214:        if (namedSpaceVal[0] != EOS)
                   4215:         /* it's a named space */
                   4216:         strcat (css_command, namedSpaceVal);
1.141     quint    4217:        else
                   4218:         {
                   4219:           strcat (css_command, value);
                   4220:           /* does the value contain an unit at the end? */
                   4221:           i = strlen (value) - 1;
                   4222:           if ((value[i] <= '9' && value[i] >= '0') ||
                   4223:               value[i] == '.')
                   4224:             /* it's just a number. Add the (implicit) unit: em */
                   4225:             strcat (css_command, "em");
                   4226:         }
1.58      cvs      4227:        break;
                   4228:     }
1.72      cvs      4229:   ParseHTMLSpecificStyle (el, css_command, doc, 0, FALSE);
1.24      cvs      4230: }
                   4231: 
                   4232: /*----------------------------------------------------------------------
1.60      cvs      4233:  MathMLSetScriptLevel
                   4234:  A scriptlevel attribute with value value is associated with element el.
                   4235:  Generate the corresponding style property for this element.
                   4236:  -----------------------------------------------------------------------*/
1.120     cvs      4237: void MathMLSetScriptLevel (Document doc, Element el, char *value)
1.60      cvs      4238: {
                   4239:   PresentationValue   pval;
                   4240:   PresentationContext ctxt;
                   4241:   ThotBool            relative;
                   4242:   int                 percentage;
                   4243: 
                   4244:   ctxt = TtaGetSpecificStyleContext (doc);
                   4245:   if (!value)
                   4246:      /* remove the presentation rule */
                   4247:      {
                   4248:      ctxt->destroy = TRUE;
1.75      cvs      4249:      pval.typed_data.value = 0;
1.60      cvs      4250:      TtaSetStylePresentation (PRSize, el, NULL, ctxt, pval);
                   4251:      }
                   4252:   else
                   4253:      {
                   4254:      ctxt->destroy = FALSE;
                   4255:      /* parse the attribute value (an optional sign and an integer) */
1.119     cvs      4256:      value = TtaSkipBlanks (value);
1.60      cvs      4257:      relative = (value[0] == '-' || value[0] == '+');
                   4258:      value = ParseCSSUnit (value, &pval);
                   4259:      if (pval.typed_data.unit != STYLE_UNIT_REL &&
                   4260:         pval.typed_data.real)
                   4261:        /* this is an error: it should be an integer without any unit name */
                   4262:        /* error */;
                   4263:      else
                   4264:        {
                   4265:        if (relative)
                   4266:         {
1.63      cvs      4267:         percentage = 100;
1.60      cvs      4268:          if (pval.typed_data.value == 0)
                   4269:           /* scriptlevel="+0" */
                   4270:           percentage = 100;
                   4271:          else if (pval.typed_data.value == 1)
                   4272:           /* scriptlevel="+1" */
                   4273:           percentage = 71;
                   4274:         else if (pval.typed_data.value == 2)
                   4275:           /* scriptlevel="+2" */
                   4276:           percentage = 50;
                   4277:         else if (pval.typed_data.value >= 3)
                   4278:           /* scriptlevel="+3" or more */
                   4279:           percentage = 35;
                   4280:         else if (pval.typed_data.value == -1)
                   4281:           /* scriptlevel="-1" */
                   4282:           percentage = 141;
                   4283:         else if (pval.typed_data.value == -2)
                   4284:           /* scriptlevel="-2" */
                   4285:           percentage = 200;
                   4286:         else if (pval.typed_data.value <= -3)
                   4287:           /* scriptlevel="-3" or less */
                   4288:           percentage = 282;
                   4289:         pval.typed_data.value = percentage;
                   4290:         pval.typed_data.unit = STYLE_UNIT_PERCENT;
1.78      cvs      4291:         /* the specific presentation to be created is not a CSS rule */
1.147     quint    4292:         ctxt->cssSpecificity = 0;
1.60      cvs      4293:         TtaSetStylePresentation (PRSize, el, NULL, ctxt, pval);       
                   4294:         }
                   4295:        else
                   4296:         /* absolute value */
                   4297:         {
                   4298:           /****  ****/;
                   4299:         }
                   4300:        }
                   4301:      }
                   4302:   TtaFreeMemory (ctxt);
                   4303: }
                   4304: 
                   4305: /*----------------------------------------------------------------------
                   4306:  MathMLSpacingAttr
                   4307:  The MathML attribute attr (height, width or depth) is associated
                   4308:  with element el (a mspace or mpadding).
                   4309:  If value is not NULL, generate the corresponding Thot presentation rule for
                   4310:  the element.
                   4311:  If value is NULL, remove the corresponding Thot presentation rule.
                   4312:  -----------------------------------------------------------------------*/
1.120     cvs      4313: void MathMLSpacingAttr (Document doc, Element el, char *value, int attr)
1.60      cvs      4314: {
                   4315:   ElementType         elType;
                   4316:   PresentationValue   pval;
                   4317:   PresentationContext ctxt;
                   4318:   int                 ruleType;
                   4319: 
                   4320:   /* provisionally, handles only mspace elements */
                   4321:   elType = TtaGetElementType (el);
1.96      cvs      4322:   if (elType.ElTypeNum != MathML_EL_MSPACE &&
1.97      cvs      4323:       elType.ElTypeNum != MathML_EL_MPADDED &&
                   4324:       elType.ElTypeNum != MathML_EL_MTABLE)
1.60      cvs      4325:      return;
                   4326:   switch (attr)
                   4327:     {
                   4328:     case MathML_ATTR_width_:
                   4329:       ruleType = PRWidth;
                   4330:       break;
                   4331:     case MathML_ATTR_height_:
                   4332:       ruleType = PRPaddingTop;
                   4333:       break;
                   4334:     case MathML_ATTR_depth_:
                   4335:       ruleType = PRPaddingBottom;
                   4336:       break;
                   4337:     default:
                   4338:       return;
                   4339:     }
                   4340:   ctxt = TtaGetSpecificStyleContext (doc);
1.116     cvs      4341:   if (!value || (strcmp (value, "auto") == 0))
1.60      cvs      4342:     /* remove the presentation rule */
                   4343:     {
                   4344:       ctxt->destroy = TRUE;
1.75      cvs      4345:       pval.typed_data.value = 0;
1.60      cvs      4346:       TtaSetStylePresentation (ruleType, el, NULL, ctxt, pval);
                   4347:     }
                   4348:   else
                   4349:     {
                   4350:       ctxt->destroy = FALSE;
                   4351:       /* parse the attribute value (a number followed by a unit) */
1.119     cvs      4352:       value = TtaSkipBlanks (value);
1.60      cvs      4353:       value = ParseCSSUnit (value, &pval);
                   4354:       /***** we should accept namedspace for width *****/
                   4355:       if (pval.typed_data.unit != STYLE_UNIT_INVALID)
1.78      cvs      4356:        {
                   4357:          /* the specific presentation to be created is not a CSS rule */
1.147     quint    4358:          ctxt->cssSpecificity = 0;
1.78      cvs      4359:          TtaSetStylePresentation (ruleType, el, NULL, ctxt, pval);
                   4360:        }
1.60      cvs      4361:     }
                   4362:   TtaFreeMemory (ctxt);
                   4363: }
                   4364: 
                   4365: /*----------------------------------------------------------------------
1.153     quint    4366:    MathMLSetDisplayAttr
1.169     quint    4367:    The MathML attribute display is associated  with element el (which
                   4368:    should be a <math> element).
                   4369:    Generate the corresponding internal attribute.
1.153     quint    4370:   ----------------------------------------------------------------------*/
                   4371: void MathMLSetDisplayAttr (Element el, Attribute attr, Document doc,
                   4372:                           ThotBool delete)
                   4373: {
1.169     quint    4374:   int            val, intVal, attrKind;
                   4375:   AttributeType  attrType;
                   4376:   Attribute      intAttr;
                   4377: 
                   4378:   if (delete)
                   4379:     SetDisplaystyleMathElement (el, doc);
                   4380:   else
                   4381:     {
                   4382:       val = TtaGetAttributeValue (attr);
                   4383:       if (val == MathML_ATTR_display_VAL_block)
                   4384:        intVal = MathML_ATTR_IntDisplaystyle_VAL_true;
                   4385:       else
                   4386:        intVal = MathML_ATTR_IntDisplaystyle_VAL_false;
                   4387:       TtaGiveAttributeType (attr, &attrType, &attrKind);
                   4388:       attrType.AttrTypeNum = MathML_ATTR_IntDisplaystyle;
                   4389:       intAttr = TtaGetAttribute (el, attrType);
                   4390:       /* create the IntDisplaystyle attribute and set its value */
                   4391:       if (!intAttr)
                   4392:        {
                   4393:          intAttr = TtaNewAttribute (attrType);
                   4394:          TtaAttachAttribute (el, intAttr, doc);
                   4395:        }
                   4396:       TtaSetAttributeValue (intAttr, intVal, el, doc);
                   4397:     }
                   4398: }
                   4399: 
                   4400: /*----------------------------------------------------------------------
                   4401:    MathMLSetDisplaystyleAttr
                   4402:    The attribute displaystyle is associated  with element el (which
                   4403:    should be a <mstyle> or a <mtable> element).
                   4404:    GenerateSet the corresponding internal attribute accordingly.
                   4405:   ----------------------------------------------------------------------*/
                   4406: void MathMLSetDisplaystyleAttr (Element el, Attribute attr, Document doc,
                   4407:                                ThotBool delete)
                   4408: {
                   4409:   int            val, intVal;
                   4410:   ElementType    elType;
                   4411:   AttributeType  attrType;
                   4412:   Attribute      intAttr;
1.153     quint    4413: 
1.169     quint    4414:   /* get the internal attribute */
                   4415:   elType = TtaGetElementType (el);
                   4416:   attrType.AttrSSchema = elType.ElSSchema;
                   4417:   attrType.AttrTypeNum = MathML_ATTR_IntDisplaystyle;
                   4418:   intAttr = TtaGetAttribute (el, attrType);
                   4419:   if (delete)
                   4420:     /* attribute displaystyle has been deleted */
                   4421:     {
                   4422:       if (elType.ElTypeNum == MathML_EL_MSTYLE)
                   4423:        /* it's a mstyle element. Just remove the internal attribute */
                   4424:        {
                   4425:          if (intAttr)
                   4426:            TtaRemoveAttribute (el, intAttr, doc);
                   4427:           return;
                   4428:        }
                   4429:       else if (elType.ElTypeNum == MathML_EL_MTABLE)
                   4430:        /* it's a matable element, set the default value (false) */
                   4431:        intVal = MathML_ATTR_IntDisplaystyle_VAL_false;
                   4432:       else
                   4433:        return;
                   4434:     }
                   4435:   else
                   4436:     {
                   4437:       val = TtaGetAttributeValue (attr);
                   4438:       if (val == MathML_ATTR_displaystyle_VAL_true)
                   4439:        intVal = MathML_ATTR_IntDisplaystyle_VAL_true;
                   4440:       else
                   4441:        intVal = MathML_ATTR_IntDisplaystyle_VAL_false;
                   4442:     }
                   4443:   /* create the IntDisplaystyle attribute if needed and set its value */
                   4444:   if (!intAttr)
                   4445:     {
                   4446:       intAttr = TtaNewAttribute (attrType);
                   4447:       TtaAttachAttribute (el, intAttr, doc);
                   4448:     }
                   4449:   TtaSetAttributeValue (intAttr, intVal, el, doc);
1.153     quint    4450: }
                   4451: 
                   4452: /*----------------------------------------------------------------------
1.1       cvs      4453:    MathMLAttributeComplete
1.58      cvs      4454:    The XML parser has completed parsing attribute attr (as well as its value)
                   4455:    that is associated with element el in document doc.
1.1       cvs      4456:   ----------------------------------------------------------------------*/
1.120     cvs      4457: void MathMLAttributeComplete (Attribute attr, Element el, Document doc)
1.1       cvs      4458: {
1.134     cvs      4459:    AttributeType     attrType, depAttrType;
1.23      cvs      4460:    int              attrKind;
1.50      cvs      4461:    ElementType       elType;
1.120     cvs      4462:    char             *value;
1.50      cvs      4463:    int               val, length;
1.101     cvs      4464:    Attribute         intAttr;
1.169     quint    4465: 
1.58      cvs      4466:    /* first get the type of that attribute */
1.23      cvs      4467:    TtaGiveAttributeType (attr, &attrType, &attrKind);
1.153     quint    4468: 
1.54      cvs      4469:    if (attrType.AttrTypeNum == MathML_ATTR_bevelled)
1.58      cvs      4470:      /* it's a bevelled attribute */
1.50      cvs      4471:      {
                   4472:        val = TtaGetAttributeValue (attr);
1.54      cvs      4473:        if (val == MathML_ATTR_bevelled_VAL_true)
                   4474:         /* bevelled = true.  Transform MFRAC into BevelledMFRAC */
1.50      cvs      4475:         {
                   4476:         elType = TtaGetElementType (el);
                   4477:         if (elType.ElTypeNum == MathML_EL_MFRAC)
1.54      cvs      4478:            ChangeTypeOfElement (el, doc, MathML_EL_BevelledMFRAC);
1.50      cvs      4479:         }
                   4480:      }
1.101     cvs      4481: 
                   4482:    else if (attrType.AttrTypeNum == MathML_ATTR_rowalign_mtr)
                   4483:      {
                   4484:        /* create an equivalent IntRowAlign attribute on the same element */
                   4485:        attrType.AttrTypeNum = MathML_ATTR_IntRowAlign;
                   4486:        intAttr = TtaGetAttribute (el, attrType);
                   4487:        if (!intAttr)
                   4488:         /* no IntRowAlign attribute, create one */
                   4489:         {
                   4490:           intAttr = TtaNewAttribute (attrType);
                   4491:           TtaAttachAttribute (el, intAttr, doc);
                   4492:         }
                   4493:        val = TtaGetAttributeValue (attr);
                   4494:        TtaSetAttributeValue (intAttr, val, el, doc);
                   4495:      }
                   4496: 
                   4497:    else if (attrType.AttrTypeNum == MathML_ATTR_columnalign_mtd)
                   4498:      {
                   4499:        /* create an equivalent IntColAlign attribute on the same element */
                   4500:        attrType.AttrTypeNum = MathML_ATTR_IntColAlign;
                   4501:        intAttr = TtaGetAttribute (el, attrType);
                   4502:        if (!intAttr)
                   4503:         /* no IntColAlign attribute, create one */
                   4504:         {
                   4505:           intAttr = TtaNewAttribute (attrType);
                   4506:           TtaAttachAttribute (el, intAttr, doc);
                   4507:         }
                   4508:        val = TtaGetAttributeValue (attr);
                   4509:        TtaSetAttributeValue (intAttr, val, el, doc);
                   4510:      }
                   4511: 
1.159     quint    4512:    /* don't handle attributes columnalign, rowalign, columnlines and rowlines
                   4513:       now: the table or the row is not complete yet. Handle them when the
                   4514:       element is complete.
1.104     cvs      4515:    */
1.153     quint    4516: 
                   4517:    else if (attrType.AttrTypeNum == MathML_ATTR_display)
1.169     quint    4518:      /* it's a display attribute on element <math> */
1.153     quint    4519:      MathMLSetDisplayAttr (el, attr, doc, FALSE);
1.169     quint    4520: 
                   4521:    else if (attrType.AttrTypeNum == MathML_ATTR_displaystyle)
                   4522:      /* it's a displaystyle attribute */
                   4523:      MathMLSetDisplaystyleAttr (el, attr, doc, FALSE);
1.138     cvs      4524: 
1.168     quint    4525:    else if (attrType.AttrTypeNum == MathML_ATTR_framespacing)
                   4526:      /* it's a framespacing attribute */
                   4527:      HandleFramespacingAttribute (attr, el, doc, FALSE);
                   4528: 
1.138     cvs      4529:    else if (attrType.AttrTypeNum == MathML_ATTR_Language)
                   4530:      {
                   4531:        if (el == TtaGetRootElement (doc))
                   4532:         /* it's the lang attribute on the root element */
                   4533:         /* set the RealLang attribute */
                   4534:         {
                   4535:           depAttrType.AttrSSchema = attrType.AttrSSchema ;
                   4536:           depAttrType.AttrTypeNum = MathML_ATTR_RealLang;
                   4537:           if (!TtaGetAttribute (el, depAttrType))
                   4538:             /* it's not present. Add it */
                   4539:             {
                   4540:               intAttr = TtaNewAttribute (depAttrType);
                   4541:               TtaAttachAttribute (el, intAttr, doc);
                   4542:               TtaSetAttributeValue (intAttr, MathML_ATTR_RealLang_VAL_Yes_,
                   4543:                                     el, doc);
                   4544:             }
                   4545:         }
                   4546:      }
1.101     cvs      4547: 
1.50      cvs      4548:    else if (attrType.AttrTypeNum == MathML_ATTR_color ||
1.93      cvs      4549:            attrType.AttrTypeNum == MathML_ATTR_mathcolor ||
                   4550:            attrType.AttrTypeNum == MathML_ATTR_background_ ||
                   4551:            attrType.AttrTypeNum == MathML_ATTR_mathbackground ||
                   4552:            attrType.AttrTypeNum == MathML_ATTR_fontsize ||
                   4553:            attrType.AttrTypeNum == MathML_ATTR_mathsize ||
                   4554:            attrType.AttrTypeNum == MathML_ATTR_fontfamily ||
                   4555:            attrType.AttrTypeNum == MathML_ATTR_linethickness ||
                   4556:            attrType.AttrTypeNum == MathML_ATTR_lspace ||
                   4557:            attrType.AttrTypeNum == MathML_ATTR_rspace ||
                   4558:            attrType.AttrTypeNum == MathML_ATTR_scriptlevel ||
                   4559:            attrType.AttrTypeNum == MathML_ATTR_width_ ||
                   4560:            attrType.AttrTypeNum == MathML_ATTR_height_ ||
1.168     quint    4561:            attrType.AttrTypeNum == MathML_ATTR_depth_)
1.93      cvs      4562:      {
1.23      cvs      4563:       length = TtaGetTextAttributeLength (attr);
                   4564:       if (length >= buflen)
                   4565:          length = buflen - 1;
                   4566:       if (length > 0)
                   4567:         {
1.116     cvs      4568:           value = TtaGetMemory (buflen);
1.33      cvs      4569:           value[0] = EOS;
                   4570:           TtaGiveTextAttributeValue (attr, value, &length);
                   4571:           switch (attrType.AttrTypeNum)
                   4572:             {
                   4573:             case MathML_ATTR_color:
1.134     cvs      4574:               /* deprecated attribute */
                   4575:               /* if the same element has a mathcolor attribute, ignore
                   4576:                  the color attribute */
                   4577:               depAttrType.AttrSSchema = attrType.AttrSSchema ;
                   4578:               depAttrType.AttrTypeNum = MathML_ATTR_mathcolor;
                   4579:               if (!TtaGetAttribute (el, depAttrType))
                   4580:                   HTMLSetForegroundColor (doc, el, value);
                   4581:               break;
1.93      cvs      4582:             case MathML_ATTR_mathcolor:
1.24      cvs      4583:                HTMLSetForegroundColor (doc, el, value);
                   4584:               break;
1.33      cvs      4585:             case MathML_ATTR_background_:
1.134     cvs      4586:               /* deprecated attribute */
                   4587:               /* if the same element has a mathbackground attribute, ignore
                   4588:                  the background attribute */
                   4589:               depAttrType.AttrSSchema = attrType.AttrSSchema;
                   4590:               depAttrType.AttrTypeNum = MathML_ATTR_mathbackground;
                   4591:               if (!TtaGetAttribute (el, depAttrType))
                   4592:                   HTMLSetBackgroundColor (doc, el, value);
                   4593:               break;
1.93      cvs      4594:             case MathML_ATTR_mathbackground:
1.24      cvs      4595:                HTMLSetBackgroundColor (doc, el, value);
                   4596:               break;
1.33      cvs      4597:             case MathML_ATTR_fontfamily:
1.24      cvs      4598:               SetFontfamily (doc, el, value);
1.83      cvs      4599:               break;
                   4600:             case MathML_ATTR_linethickness:
                   4601:               MathMLlinethickness (doc, el, value);
1.58      cvs      4602:               break;
                   4603:             case MathML_ATTR_fontsize:
1.134     cvs      4604:               /* deprecated attribute */
                   4605:               /* if the same element has a mathsize attribute, ignore
                   4606:                  the fontsize attribute */
                   4607:               depAttrType.AttrSSchema = attrType.AttrSSchema;
                   4608:               depAttrType.AttrTypeNum = MathML_ATTR_mathsize;
                   4609:               if (!TtaGetAttribute (el, depAttrType))
                   4610:                 MathMLAttrToStyleProperty (doc, el, value,
                   4611:                                            attrType.AttrTypeNum);
                   4612:               break;
1.93      cvs      4613:             case MathML_ATTR_mathsize:
1.58      cvs      4614:             case MathML_ATTR_lspace:
                   4615:             case MathML_ATTR_rspace:
1.60      cvs      4616:               MathMLAttrToStyleProperty (doc, el, value,attrType.AttrTypeNum);
                   4617:               break;
                   4618:             case MathML_ATTR_scriptlevel:
                   4619:               MathMLSetScriptLevel (doc, el, value);
                   4620:               break;
                   4621:              case MathML_ATTR_width_:
                   4622:             case MathML_ATTR_height_:
                   4623:             case MathML_ATTR_depth_:
                   4624:               MathMLSpacingAttr (doc, el, value, attrType.AttrTypeNum);
1.59      cvs      4625:               break;
                   4626:             default:
1.24      cvs      4627:               break;
1.33      cvs      4628:             }
                   4629:           TtaFreeMemory (value);
1.23      cvs      4630:         }
                   4631:       }
1.1       cvs      4632: }
                   4633: 
                   4634: /*----------------------------------------------------------------------
                   4635:    MathMLGetDTDName
                   4636:   ----------------------------------------------------------------------*/
1.120     cvs      4637: void MathMLGetDTDName (char *DTDname, char *elementName)
1.1       cvs      4638: {
                   4639:    /* no other DTD allowed within MathML elements */
1.116     cvs      4640:    strcpy (DTDname, "");
1.1       cvs      4641: }
                   4642: 
                   4643: /* end of module */

Webmaster