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

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

Webmaster