Annotation of Amaya/amaya/XHTMLbuilder.c, revision 1.94

1.1       cvs         1: /*
                      2:  *
1.78      vatton      3:  *  (c) COPYRIGHT INRIA and W3C, 1996-2003
1.1       cvs         4:  *  Please first read the full copyright statement in file COPYRIGHT.
                      5:  *
                      6:  */
                      7: 
                      8: /*
1.30      cvs         9:  * XHTMLbuilder.c
1.23      cvs        10:  * Builds the corresponding abstract tree for a Thot document of type HTML.
1.1       cvs        11:  *
1.20      cvs        12:  * Authors: L. Carcone
                     13:  *          V. Quint 
1.1       cvs        14:  */
                     15: 
                     16: #define THOT_EXPORT extern
                     17: #include "amaya.h"
                     18: #include "css.h"
1.2       cvs        19: #include "parser.h"
                     20: #include "HTML.h"
1.30      cvs        21: #include "fetchHTMLname.h"
1.2       cvs        22: 
1.13      cvs        23: #include "css_f.h"
1.76      vatton     24: #include "EDITstyle_f.h"
1.13      cvs        25: #include "fetchXMLname_f.h"
1.30      cvs        26: #include "fetchHTMLname_f.h"
1.22      cvs        27: #include "html2thot_f.h"
1.1       cvs        28: #include "HTMLactions_f.h"
                     29: #include "HTMLedit_f.h"
1.22      cvs        30: #include "HTMLform_f.h"
1.1       cvs        31: #include "HTMLimage_f.h"
                     32: #include "HTMLtable_f.h"
                     33: #include "HTMLimage_f.h"
                     34: #include "UIcss_f.h"
1.13      cvs        35: #include "styleparser_f.h"
1.2       cvs        36: #include "XHTMLbuilder_f.h"
1.13      cvs        37: #include "Xml2thot_f.h"
1.1       cvs        38: 
1.30      cvs        39: #define MaxMsgLength 200
                     40: 
1.47      cvs        41: /* Elements that cannot contain text as immediate children.
                     42:    When some text is present in the HTML file it must be 
                     43:    surrounded by a Pseudo_paragraph element */
                     44: static int          NoTextChild[] =
                     45: {
                     46:    HTML_EL_Document, HTML_EL_HTML, HTML_EL_HEAD, HTML_EL_BODY,
                     47:    HTML_EL_Definition_List, HTML_EL_Block_Quote, HTML_EL_Directory,
                     48:    HTML_EL_Form, HTML_EL_Menu, HTML_EL_FIELDSET,
                     49:    HTML_EL_Numbered_List, HTML_EL_Option_Menu,
                     50:    HTML_EL_Unnumbered_List, HTML_EL_Definition, HTML_EL_List_Item,
                     51:    HTML_EL_MAP, HTML_EL_map, HTML_EL_Applet,
                     52:    HTML_EL_Object, HTML_EL_IFRAME, HTML_EL_NOFRAMES,
                     53:    HTML_EL_Division, HTML_EL_Center, HTML_EL_NOSCRIPT,
                     54:    HTML_EL_Data_cell, HTML_EL_Heading_cell,
                     55:    0};
                     56: 
1.28      cvs        57: /* Define a pointer to let parser functions access the HTML entity table */
                     58: extern XmlEntity *pXhtmlEntityTable;
1.6       cvs        59: 
1.30      cvs        60: /* maximum size of error messages */
                     61: #define MaxMsgLength 200
                     62: 
1.6       cvs        63: /*----------------------------------------------------------------------
1.15      cvs        64:   ParseCharset:
1.6       cvs        65:   Parses the element HTTP-EQUIV and looks for the charset value.
                     66:   ----------------------------------------------------------------------*/
1.30      cvs        67: void             ParseCharset (Element el, Document doc) 
                     68: 
1.6       cvs        69: {
1.15      cvs        70:    AttributeType attrType;
                     71:    Attribute     attr;
                     72:    SSchema       docSSchema;
                     73:    CHARSET       charset;
1.39      cvs        74:    char         *text, *text2, *ptrText, *str;
                     75:    char          charsetname[MAX_LENGTH];
1.15      cvs        76:    int           length;
1.6       cvs        77:    int           pos, index = 0;
                     78: 
1.15      cvs        79:    charset = TtaGetDocumentCharset (doc);
                     80:    if (charset != UNDEFINED_CHARSET)
                     81:      /* the charset was already defined by the http header */
                     82:      return;
1.6       cvs        83: 
                     84:    docSSchema = TtaGetDocumentSSchema (doc);
                     85:    attrType.AttrSSchema = docSSchema;
                     86:    attrType.AttrTypeNum = HTML_ATTR_http_equiv;
                     87:    attr = TtaGetAttribute (el, attrType);
                     88:    if (attr != NULL)
                     89:      {
                     90:        /* There is a HTTP-EQUIV attribute */
                     91:        length = TtaGetTextAttributeLength (attr);
                     92:        if (length > 0)
                     93:         {
1.37      cvs        94:           text = TtaGetMemory (length + 1);
1.6       cvs        95:           TtaGiveTextAttributeValue (attr, text, &length);
1.37      cvs        96:           if (!strcasecmp (text, "content-type"))
1.6       cvs        97:             {
                     98:               attrType.AttrTypeNum = HTML_ATTR_meta_content;
                     99:               attr = TtaGetAttribute (el, attrType);
                    100:               if (attr != NULL)
                    101:                 {
                    102:                   length = TtaGetTextAttributeLength (attr);
                    103:                   if (length > 0)
                    104:                     {
1.37      cvs       105:                       text2 = TtaGetMemory (length + 1);
1.6       cvs       106:                       TtaGiveTextAttributeValue (attr, text2, &length);
                    107:                       ptrText = text2;
                    108:                       while (*ptrText)
                    109:                         {
1.53      vatton    110:                           *ptrText = tolower (*ptrText);
1.6       cvs       111:                           ptrText++;
                    112:                         }
                    113:                       
1.37      cvs       114:                       str = strstr (text2, "charset=");
1.6       cvs       115:                       if (str)
                    116:                         {
                    117:                           pos = str - text2 + 8;
1.37      cvs       118:                           while (text2[pos] != SPACE &&
                    119:                                  text2[pos] != TAB && text2[pos] != EOS)
1.6       cvs       120:                             charsetname[index++] = text2[pos++];
1.37      cvs       121:                           charsetname[index] = EOS;
1.15      cvs       122:                           charset = TtaGetCharset (charsetname);
                    123:                           if (charset != UNDEFINED_CHARSET)
1.77      cvs       124:                             TtaSetDocumentCharset (doc, charset, FALSE);
1.6       cvs       125:                         }
                    126:                       TtaFreeMemory (text2);
                    127:                     }       
                    128:                 } 
                    129:             }
                    130:           TtaFreeMemory (text);
                    131:         }
                    132:      }
                    133: }
                    134: 
1.23      cvs       135: /*----------------------------------------------------------------------
1.47      cvs       136:    XhtmlCannotContainText 
                    137:    Return TRUE if element el is a block element.
                    138:   ----------------------------------------------------------------------*/
                    139: ThotBool      XhtmlCannotContainText (ElementType elType)
                    140: 
                    141: {
                    142:    int        i;
                    143:    ThotBool   ret;
                    144: 
                    145:    if (strcmp (TtaGetSSchemaName (elType.ElSSchema), "HTML"))
                    146:       /* not an HTML element */
                    147:       ret = TRUE;
                    148:    else
                    149:      {
                    150:        ret = FALSE;
                    151:        i = 0;
                    152:        while (NoTextChild[i] > 0 && NoTextChild[i] != elType.ElTypeNum)
                    153:            i++;
                    154:        if (NoTextChild[i] == elType.ElTypeNum)
                    155:            ret = TRUE;
                    156:      }
                    157:    return ret;
1.23      cvs       158: }
                    159: 
1.6       cvs       160: /*----------------------------------------------------------------------
                    161:   XhtmlElementComplete
1.20      cvs       162:   Complete Xhtml elements.
1.6       cvs       163:   Check its attributes and its contents.
                    164:   ----------------------------------------------------------------------*/
1.72      cvs       165: void       XhtmlElementComplete (ParserData *context, Element el, int *error)
1.30      cvs       166: 
                    167: {
1.72      cvs       168:    Document       doc;   
1.30      cvs       169:    ElementType    elType, newElType, childType;
                    170:    Element        constElem, child, desc, leaf, prev, next, last,
1.62      quint     171:                  elFrames, lastFrame, lastChild, parent, picture, content;
1.30      cvs       172:    Attribute      attr;
                    173:    AttributeType  attrType;
                    174:    Language       lang;
1.41      cvs       175:    char           *text;
1.39      cvs       176:    char           lastChar[2];
1.79      quint     177:    char           *name1, *data;
1.30      cvs       178:    int            length;
                    179:    SSchema        docSSchema;
1.62      quint     180:    ThotBool       isImage;
                    181:    PresentationValue    pval;
                    182:    PresentationContext  ctxt;
1.6       cvs       183: 
                    184:    *error = 0;
1.72      cvs       185:    doc = context->doc;
1.6       cvs       186:    docSSchema = TtaGetDocumentSSchema (doc);
                    187: 
                    188:    elType = TtaGetElementType (el);
                    189:    /* is this a block-level element in a character-level element? */
1.56      cvs       190:    if (!IsXMLElementInline (elType, doc) &&
1.24      cvs       191:        elType.ElTypeNum != HTML_EL_Comment_ &&
                    192:        elType.ElTypeNum != HTML_EL_XMLPI)
1.6       cvs       193:        BlockInCharLevelElem (el);
                    194: 
                    195:    newElType.ElSSchema = elType.ElSSchema;
                    196:    switch (elType.ElTypeNum)
                    197:      {
1.62      quint     198:      case HTML_EL_Object:      /* it's an object */
1.79      quint     199:        data = NULL;
1.62      quint     200:        isImage = FALSE;
                    201:        /* is there a type attribute on the object element? */
                    202:        attrType.AttrSSchema = elType.ElSSchema;
                    203:        attrType.AttrTypeNum = HTML_ATTR_Object_type;
1.6       cvs       204:        attr = TtaGetAttribute (el, attrType);
1.62      quint     205:        if (attr)
                    206:         /* there is a type attribute. Get its value to see if the object
                    207:            represents an image */
1.6       cvs       208:         {
                    209:           length = TtaGetTextAttributeLength (attr);
                    210:           if (length > 0)
                    211:             {
1.37      cvs       212:               name1 = TtaGetMemory (length + 1);
1.6       cvs       213:               TtaGiveTextAttributeValue (attr, name1, &length);
1.68      kahan     214:               if (!strcmp (name1, AM_MATHML_MIME_TYPE) ||
1.62      quint     215:                   !strcmp (name1, "application/postscript") ||
                    216:                   !strcmp (name1, "image/x-bitmap") ||
                    217:                   !strcmp (name1, "image/x-xpixmap") ||
                    218:                   !strcmp (name1, "image/gif") ||
                    219:                   !strcmp (name1, "image/jpeg") ||
                    220:                   !strcmp (name1, "image/png") ||
1.67      kahan     221:                   !strcmp (name1, "image/svg") ||
1.83      cvs       222:                   !strcmp (name1, AM_SVG_MIME_TYPE) ||
                    223:                   !strcmp (name1, AM_XHTML_MIME_TYPE) ||
                    224:                   !strcmp (name1, "text/html") ||
                    225:                   !strcmp (name1, "text/htm") ||
                    226:                   !strcmp (name1, AM_GENERIC_XML_MIME_TYPE))
1.62      quint     227:                 isImage = TRUE;
                    228:               TtaFreeMemory (name1);
                    229:             }
                    230:         }
1.79      quint     231: 
                    232:        attrType.AttrTypeNum = HTML_ATTR_data;
                    233:        attr = TtaGetAttribute (el, attrType);
                    234:        if (attr)
                    235:         /* the object has a data attribute */
                    236:         {
                    237:           length = TtaGetTextAttributeLength (attr);
                    238:           if (length > 0)
                    239:             {
                    240:               data = TtaGetMemory (length + 1);
                    241:               TtaGiveTextAttributeValue (attr, data, &length);
                    242:               if (!isImage)
                    243:                 if (!strcmp (&data[length-3], "mml") ||
                    244:                     !strcmp (&data[length-3], "gif") ||
                    245:                     !strcmp (&data[length-3], "jpg") ||
                    246:                     !strcmp (&data[length-4], "jpeg") ||
                    247:                     !strcmp (&data[length-3], "png") ||
                    248:                     !strcmp (&data[length-3], "svg") ||
1.80      cvs       249:                     !strcmp (&data[length-4], "svgz") ||
1.83      cvs       250:                     !strcmp (&data[length-3], "htm") ||
                    251:                     !strcmp (&data[length-4], "html") ||
                    252:                     !strcmp (&data[length-3], "xml"))
1.79      quint     253:                   isImage = TRUE;
                    254:             }
                    255:         }
1.62      quint     256:        picture = NULL;     /* no PICTURE element yet */
                    257:        child = TtaGetFirstChild (el);
                    258:        if (isImage)
                    259:         /* the object represents an image. We need a PICTURE element as
                    260:            child of the object to hold the image */
                    261:         {
                    262:           if (child)
                    263:             {
                    264:               elType = TtaGetElementType (child);
                    265:               if (elType.ElTypeNum == HTML_EL_PICTURE_UNIT)
                    266:                 /* there is already a PICTURE element */
                    267:                 picture = child;
                    268:             }
1.79      quint     269:           /* if the object element has no PICTURE element as its first child
1.62      quint     270:              create one */
                    271:           if (!picture)
                    272:             {
                    273:               elType.ElTypeNum = HTML_EL_PICTURE_UNIT;
                    274:               picture = TtaNewTree (doc, elType, "");
                    275:               if (child)
                    276:                 TtaInsertSibling (picture, child, TRUE, doc);
                    277:               else
                    278:                 TtaInsertFirstChild (&picture, el, doc);
                    279:               child = picture;
                    280:             }
                    281:           /* copy attribute data of the object into the SRC attribute of
                    282:              the PICTURE element */
1.79      quint     283:           if (data)
                    284:             /* the object has a data attribute */
                    285:             {
                    286:               attrType.AttrTypeNum = HTML_ATTR_SRC;
                    287:               attr = TtaGetAttribute (picture, attrType);
                    288:               if (attr == NULL)
                    289:                 {
                    290:                   attr = TtaNewAttribute (attrType);
                    291:                   TtaAttachAttribute (picture, attr, doc);
                    292:                 }
                    293:               TtaSetAttributeText (attr, data, picture, doc);
                    294:             }
                    295:           attrType.AttrTypeNum = HTML_ATTR_Height_;
1.62      quint     296:           attr = TtaGetAttribute (el, attrType);
                    297:           if (attr)
1.79      quint     298:             /* the Object has a height attribute. Applies it to the
                    299:                picture element */
                    300:             {
                    301:               length = TtaGetTextAttributeLength (attr);
                    302:               if (length > 0)
                    303:                 {
                    304:                   text = TtaGetMemory (length + 1);
                    305:                   TtaGiveTextAttributeValue (attr, text, &length);
                    306:                   /* create the corresponding attribute IntHeightPercent or */
                    307:                   /* IntHeightPxl */
                    308:                   CreateAttrHeightPercentPxl (text, el, doc, -1);
                    309:                   TtaFreeMemory (text);
                    310:                 }
                    311:             }
                    312:           attrType.AttrTypeNum = HTML_ATTR_Width__;
                    313:           attr = TtaGetAttribute (el, attrType);
                    314:           if (attr)
                    315:             /* the Object has a width attribute. Applies it to the
                    316:                picture element */
1.62      quint     317:             {
                    318:               length = TtaGetTextAttributeLength (attr);
                    319:               if (length > 0)
1.6       cvs       320:                 {
1.79      quint     321:                   text = TtaGetMemory (length + 1);
                    322:                   TtaGiveTextAttributeValue (attr, text, &length);
                    323:                   /* create the corresponding attribute IntWidthPercent or */
                    324:                   /* IntWidthPxl */
                    325:                   CreateAttrWidthPercentPxl (text, el, doc, -1);
                    326:                   TtaFreeMemory (text);
1.6       cvs       327:                 }
                    328:             }
                    329:         }
                    330:        /* is the Object_Content element already created ? */
1.62      quint     331:        if (child)
                    332:         /* the object element has at least 1 child element */
                    333:         {
                    334:           content = NULL;
                    335:           desc = child;
1.6       cvs       336:           elType = TtaGetElementType (desc);
1.62      quint     337:           if (elType.ElTypeNum != HTML_EL_Object_Content)
                    338:             {
                    339:               TtaNextSibling(&desc);
                    340:               if (desc)
                    341:                 elType = TtaGetElementType (desc);
                    342:             }
                    343:           /* is it the Object_Content element ? */
                    344:           if (elType.ElTypeNum == HTML_EL_Object_Content)
                    345:             content = desc;
                    346:           else
1.6       cvs       347:             {
1.62      quint     348:               /* create an Object_Content element */
                    349:               elType.ElTypeNum = HTML_EL_Object_Content;
                    350:               content = TtaNewElement (doc, elType);
                    351:               if (picture)
                    352:                 TtaInsertSibling (content, picture, FALSE, doc);
                    353:               else
                    354:                 TtaInsertSibling (content, child, TRUE, doc);
                    355:               /* move previous existing children into Object_Content */
1.6       cvs       356:               child = TtaGetLastChild(el);
1.62      quint     357:               while (child != content)
                    358:                 {
                    359:                   TtaRemoveTree (child, doc);
                    360:                   TtaInsertFirstChild (&child, content, doc);
                    361:                   child = TtaGetLastChild(el);
                    362:                 }
                    363:             }
                    364:           if (picture && content)
                    365:             /* there is a picture element. The Object_Content must not be
                    366:                displayed in the main view */
                    367:             {
                    368:               ctxt = TtaGetSpecificStyleContext (doc);
                    369:               /* the presentation rule to be set is not a CSS rule */
                    370:               ctxt->cssSpecificity = 0;
                    371:               ctxt->destroy = FALSE;
1.85      vatton    372:               pval.typed_data.unit = UNIT_PX;
1.62      quint     373:               pval.typed_data.value = 0;
                    374:               pval.typed_data.real = FALSE;
                    375:               TtaSetStylePresentation (PRVisibility, content, NULL, ctxt, pval);
1.6       cvs       376:             }
                    377:         }
1.79      quint     378:        if (data)
                    379:         TtaFreeMemory (data);
1.6       cvs       380:        break;
1.62      quint     381: 
1.6       cvs       382:      case HTML_EL_Unnumbered_List:
                    383:      case HTML_EL_Numbered_List:
                    384:      case HTML_EL_Menu:
                    385:      case HTML_EL_Directory:
                    386:        /* It's a List element. It should only have List_Item children.
                    387:          If it has List element chidren, move these List elements
                    388:          within their previous List_Item sibling.  This is to fix
                    389:          a bug in document generated by Mozilla. */
                    390:        prev = NULL;
                    391:        next = NULL;
                    392:        child = TtaGetFirstChild (el);
                    393:        while (child != NULL)
                    394:         {
                    395:           next = child;
                    396:           TtaNextSibling (&next);
                    397:           elType = TtaGetElementType (child);
                    398:           if (elType.ElTypeNum == HTML_EL_Unnumbered_List ||
                    399:               elType.ElTypeNum == HTML_EL_Numbered_List ||
                    400:               elType.ElTypeNum == HTML_EL_Menu ||
                    401:               elType.ElTypeNum == HTML_EL_Directory)
                    402:             /* this list element is a child of another list element */
                    403:             if (prev)
                    404:               {
                    405:                 elType = TtaGetElementType (prev);
                    406:                 if (elType.ElTypeNum == HTML_EL_List_Item)
                    407:                   {
                    408:                     /* get the last child of the previous List_Item */
                    409:                     desc = TtaGetFirstChild (prev);
                    410:                     last = NULL;
                    411:                     while (desc)
                    412:                       {
                    413:                         last = desc;
                    414:                         TtaNextSibling (&desc);
                    415:                       }
                    416:                     /* move the list element after the last child of the
                    417:                        previous List_Item */
                    418:                     TtaRemoveTree (child, doc);
                    419:                     if (last)
                    420:                       TtaInsertSibling (child, last, FALSE, doc);
                    421:                     else
                    422:                       TtaInsertFirstChild (&child, prev, doc);
                    423:                     child = prev;
                    424:                   }
                    425:               }
                    426:           prev = child;
                    427:           child = next;
                    428:         }
                    429:        break;
                    430:        
                    431:      case HTML_EL_FRAMESET:
                    432:        /* The FRAMESET element is now complete.  Gather all its FRAMESET
                    433:          and FRAME children and wrap them up in a Frames element */
                    434:        elFrames = NULL; lastFrame = NULL;
                    435:        lastChild = NULL;
                    436:        child = TtaGetFirstChild (el);
                    437:        while (child != NULL)
                    438:         {
                    439:           next = child;
                    440:           TtaNextSibling (&next);
                    441:           elType = TtaGetElementType (child);
                    442:           if (elType.ElTypeNum == HTML_EL_FRAMESET ||
                    443:               elType.ElTypeNum == HTML_EL_FRAME ||
                    444:               elType.ElTypeNum == HTML_EL_Comment_)
                    445:             {
                    446:               /* create the Frames element if it does not exist */
                    447:               if (elFrames == NULL)
                    448:                 {
                    449:                   newElType.ElSSchema = docSSchema;
                    450:                   newElType.ElTypeNum = HTML_EL_Frames;
                    451:                   elFrames = TtaNewElement (doc, newElType);
1.63      cvs       452:                   if (DocumentMeta[doc]->xmlformat)
                    453:                     XmlSetElemLineNumber (elFrames);
                    454:                   else
                    455:                     SetHtmlElemLineNumber (elFrames);
1.6       cvs       456:                   TtaInsertSibling (elFrames, child, TRUE, doc);
                    457:                 }
                    458:               /* move the element as the last child of the Frames element */
                    459:               TtaRemoveTree (child, doc);
                    460:               if (lastFrame == NULL)
                    461:                 TtaInsertFirstChild (&child, elFrames, doc);
                    462:               else
                    463:                 TtaInsertSibling (child, lastFrame, FALSE, doc);
                    464:               lastFrame = child;
                    465:             }
                    466:           child = next;
                    467:         }
                    468:        break;
                    469:        
                    470:      case HTML_EL_Input:       /* it's an INPUT without any TYPE attribute */
                    471:        /* Create a child of type Text_Input */
                    472:        elType.ElTypeNum = HTML_EL_Text_Input;
                    473:        child = TtaNewTree (doc, elType, "");
1.63      cvs       474:        if (DocumentMeta[doc]->xmlformat)
                    475:         XmlSetElemLineNumber (child);
                    476:        else
                    477:         SetHtmlElemLineNumber (child);
1.6       cvs       478:        TtaInsertFirstChild (&child, el, doc);
                    479:        /* now, process it like a Text_Input element */
                    480: 
                    481:      case HTML_EL_Text_Input:
                    482:      case HTML_EL_Password_Input:
                    483:      case HTML_EL_File_Input:
1.91      quint     484:        /* set default size */
                    485:        attrType.AttrSSchema = elType.ElSSchema;
                    486:        attrType.AttrTypeNum = HTML_ATTR_IntAreaSize;
                    487:        attr = TtaGetAttribute (el, attrType);
                    488:        if (!attr)
                    489:         CreateAttrIntAreaSize (20, el, doc);
1.6       cvs       490:        /* get element Inserted_Text */
                    491:        child = TtaGetFirstChild (el);
                    492:        if (child != NULL)
                    493:         {
                    494:           attrType.AttrTypeNum = HTML_ATTR_Value_;
                    495:           attr = TtaGetAttribute (el, attrType);
                    496:           if (attr != NULL)
                    497:             {
                    498:               /* copy the value of attribute "value" into the first text
                    499:                  leaf of element */
                    500:               length = TtaGetTextAttributeLength (attr);
                    501:               if (length > 0)
                    502:                 {
                    503:                   /* get the text leaf */
                    504:                   leaf = TtaGetFirstChild (child);
                    505:                   if (leaf != NULL)
                    506:                     {
                    507:                       childType = TtaGetElementType (leaf);
                    508:                       if (childType.ElTypeNum == HTML_EL_TEXT_UNIT)
                    509:                         {
                    510:                           /* copy attribute value into the text leaf */
1.37      cvs       511:                           text = TtaGetMemory (length + 1);
1.6       cvs       512:                           TtaGiveTextAttributeValue (attr, text, &length);
                    513:                           TtaSetTextContent (leaf, text, 
                    514:                                              TtaGetDefaultLanguage (), doc);
                    515:                           TtaFreeMemory (text);
                    516:                         }
                    517:                     }
                    518:                 }
                    519:             }
                    520:         }
                    521:        break;
                    522:        
                    523:      case HTML_EL_META:
1.15      cvs       524:        ParseCharset (el, doc);
1.6       cvs       525:        break;
                    526: 
                    527:      case HTML_EL_STYLE_:      /* it's a STYLE element */
1.60      vatton    528:      case HTML_EL_SCRIPT_:     /* it's a SCRIPT element */
1.6       cvs       529:      case HTML_EL_Preformatted:        /* it's a PRE */
                    530:        /* if the last line of the Preformatted is empty, remove it */
                    531:        leaf = XmlLastLeafInElement (el);
                    532:        if (leaf != NULL)
                    533:         {
                    534:           elType = TtaGetElementType (leaf);
                    535:           if (elType.ElTypeNum == HTML_EL_TEXT_UNIT)
                    536:             /* the last leaf is a TEXT element */
                    537:             {
                    538:               length = TtaGetTextLength (leaf);
                    539:               if (length > 0)
                    540:                 {
                    541:                   TtaGiveSubString (leaf, lastChar, length, 1);
                    542:                   if (lastChar[0] == EOL)
                    543:                     /* last character is new line, delete it */
                    544:                     {
                    545:                       if (length == 1)
                    546:                         /* empty TEXT element */
                    547:                         TtaDeleteTree (leaf, doc);
                    548:                       else
                    549:                         /* remove the last character */
                    550:                         TtaDeleteTextContent (leaf, length, 1, doc);
                    551:                     }
                    552:                 }
                    553:             }
                    554:         }
1.75      kahan     555:        if (DocumentMeta[doc] && DocumentMeta[doc]->xmlformat)
1.63      cvs       556:         {
                    557:           if (IsXmlParsingCSS ())
                    558:             {
                    559:               text = GetStyleContents (el);
                    560:               if (text)
                    561:                 {
1.71      vatton    562:                   ReadCSSRules (doc, NULL, text, NULL,
1.82      quint     563:                                 TtaGetElementLineNumber (el), FALSE, el);
1.63      cvs       564:                   TtaFreeMemory (text);
                    565:                 }
                    566:               SetXmlParsingCSS (FALSE);
                    567:             }
                    568:         }
                    569:        else
1.6       cvs       570:         {
1.63      cvs       571:           if (IsHtmlParsingCSS ())
1.6       cvs       572:             {
1.63      cvs       573:               text = GetStyleContents (el);
                    574:               if (text)
                    575:                 {
1.71      vatton    576:                   ReadCSSRules (doc, NULL, text, NULL,
1.82      quint     577:                                 TtaGetElementLineNumber (el), FALSE, el);
1.63      cvs       578:                   TtaFreeMemory (text);
                    579:                 }
                    580:               SetHtmlParsingCSS (FALSE);
1.6       cvs       581:             }
                    582:         }
                    583:        /* and continue as if it were a Preformatted or a Script */
                    584:        break;
                    585:        
                    586:      case HTML_EL_Text_Area:   /* it's a Text_Area */
1.69      cvs       587:        if (DocumentMeta[doc]->xmlformat)
                    588:         SetParsingTextArea (FALSE);
                    589:        else
                    590:         SetHtmlParsingTextArea (FALSE);
1.6       cvs       591:        child = TtaGetFirstChild (el);
                    592:        if (child == NULL)
                    593:         /* it's an empty Text_Area */
                    594:         /* insert a Inserted_Text element in the element */
                    595:         {
                    596:           newElType.ElTypeNum = HTML_EL_Inserted_Text;
                    597:           child = TtaNewTree (doc, newElType, "");
                    598:           TtaInsertFirstChild (&child, el, doc);
                    599:         }
                    600:        else
                    601:         {
                    602:           /* save the text into Default_Value attribute */
                    603:           attrType.AttrSSchema = docSSchema;
                    604:           attrType.AttrTypeNum = HTML_ATTR_Default_Value;
                    605:           if (TtaGetAttribute (el, attrType) == NULL)
                    606:             /* attribute Default_Value is missing */
                    607:             {
                    608:               attr = TtaNewAttribute (attrType);
                    609:               TtaAttachAttribute (el, attr, doc);
                    610:               desc = TtaGetFirstChild (child);
                    611:               length = TtaGetTextLength (desc) + 1;
1.37      cvs       612:               text = TtaGetMemory (length);
1.6       cvs       613:               TtaGiveTextContent (desc, text, &length, &lang);
                    614:               TtaSetAttributeText (attr, text, el, doc);
                    615:               TtaFreeMemory (text);
                    616:             }
                    617:         }
                    618:        /* insert a Frame element */
                    619:        newElType.ElTypeNum = HTML_EL_Frame;
                    620:        constElem = TtaNewTree (doc, newElType, "");
                    621:        TtaInsertSibling (constElem, child, FALSE, doc);
                    622:        break;
                    623:        
                    624:      case HTML_EL_Radio_Input:
                    625:      case HTML_EL_Checkbox_Input:
                    626:        /* put an attribute Checked if it is missing */
                    627:        attrType.AttrSSchema = docSSchema;
                    628:        attrType.AttrTypeNum = HTML_ATTR_Checked;
                    629:        if (TtaGetAttribute (el, attrType) == NULL)
                    630:         /* attribute Checked is missing */
                    631:         {
                    632:           attr = TtaNewAttribute (attrType);
                    633:           TtaAttachAttribute (el, attr, doc);
                    634:           TtaSetAttributeValue (attr, HTML_ATTR_Checked_VAL_No_, el, doc);
                    635:         }
                    636:        break;
                    637:        
                    638:      case HTML_EL_Option_Menu:
                    639:        /* Check that at least one option has a SELECTED attribute */
                    640:        OnlyOneOptionSelected (el, doc, TRUE);
                    641:        break;
                    642: 
                    643:      case HTML_EL_PICTURE_UNIT:
                    644:        break;
                    645:        
                    646:      case HTML_EL_LINK:
                    647:        CheckCSSLink (el, doc, docSSchema);
                    648:        break;
                    649:        
                    650:      case HTML_EL_Data_cell:
                    651:      case HTML_EL_Heading_cell:
                    652:        /* insert a pseudo paragraph into empty cells */
                    653:        child = TtaGetFirstChild (el);
                    654:        if (child == NULL)
                    655:         {
                    656:           elType.ElTypeNum = HTML_EL_Pseudo_paragraph;
                    657:           child = TtaNewTree (doc, elType, "");
                    658:           if (child != NULL)
                    659:               TtaInsertFirstChild (&child, el, doc);
                    660:         }
                    661:        
1.80      cvs       662:        /* detect whether we are parsing a whole table or just a cell */
1.63      cvs       663:        if (DocumentMeta[doc]->xmlformat)
                    664:         {
                    665:           if (IsWithinXmlTable ())
1.92      quint     666:             NewCell (el, doc, FALSE, FALSE);
1.63      cvs       667:         }
                    668:        else
                    669:         {
                    670:           if (IsWithinHtmlTable ())
1.92      quint     671:             NewCell (el, doc, FALSE, FALSE);
1.63      cvs       672:         }
1.6       cvs       673:        break;
                    674:        
                    675:      case HTML_EL_Table:
                    676:        CheckTable (el, doc);
                    677:        SubWithinTable ();
                    678:        break;
                    679:        
                    680:      case HTML_EL_TITLE:
                    681:        /* show the TITLE in the main window */
                    682:        UpdateTitle (el, doc);
                    683:        break;
1.41      cvs       684: 
                    685:      case HTML_EL_rbc:
                    686:        /* an rbc element has been read. Its parent should be a complex_ruby.
                    687:          Change the type of the parent, as simple_ruby are created by
                    688:          default */
                    689:        parent = TtaGetParent (el);
                    690:        if (parent)
                    691:         {
                    692:           newElType = TtaGetElementType (parent);
                    693:           if (newElType.ElSSchema == elType.ElSSchema &&
                    694:               newElType.ElTypeNum == HTML_EL_simple_ruby)
                    695:              ChangeElementType (parent, HTML_EL_complex_ruby);
                    696:         }
                    697:        break;
                    698: 
                    699:      case HTML_EL_rtc1:
                    700:        /* an rtc element has been parsed. If it has already a rtc1 sibling,
                    701:          change its type to rtc2 */
                    702:        prev = el;
                    703:        do
                    704:         {
                    705:           TtaPreviousSibling(&prev);
                    706:           if (prev)
                    707:             {
                    708:               newElType = TtaGetElementType (prev);
                    709:               if (newElType.ElSSchema == elType.ElSSchema &&
                    710:                   newElType.ElTypeNum == HTML_EL_rtc1)
                    711:                 {
                    712:                   ChangeElementType (el, HTML_EL_rtc2);
                    713:                   prev = NULL;
                    714:                 }
                    715:             }
                    716:         }
                    717:        while (prev);
                    718:        break;
                    719: 
1.6       cvs       720:      default:
                    721:        break;
                    722:      }
                    723: }
1.1       cvs       724: 
                    725: /*----------------------------------------------------------------------
1.30      cvs       726:    PutInContent    
                    727:    Put the string ChrString in the leaf of current element.
                    728:   ----------------------------------------------------------------------*/
1.39      cvs       729: Element         PutInContent (char *ChrString, ParserData *context)
1.30      cvs       730: 
                    731: {
                    732:    Element      el, child;
                    733:    ElementType  elType;
                    734:    int          length;
                    735: 
                    736:    el = NULL;
                    737:    if (context->lastElement != NULL)
                    738:      {
                    739:        /* search first leaf of current element */
                    740:        el = context->lastElement;
                    741:        do
                    742:          {
                    743:             child = TtaGetFirstChild (el);
                    744:             if (child != NULL)
                    745:                el = child;
                    746:          }
                    747:        while (child != NULL);
                    748:        elType = TtaGetElementType (el);
                    749:        length = 0;
                    750:        if (elType.ElTypeNum == 1)
                    751:           length = TtaGetTextLength (el);
                    752:        if (length == 0)
                    753:           TtaSetTextContent (el, ChrString, context->language, context->doc);
                    754:        else
                    755:           TtaAppendTextContent (el, ChrString, context->doc);
                    756:      }
                    757:    return el;
                    758: }
                    759: 
                    760: /*----------------------------------------------------------------------
1.93      vatton    761:   UnknownXhtmlNameSpace
                    762:   The element doesn't belong to a supported namespace
1.51      cvs       763:   ----------------------------------------------------------------------*/
1.93      vatton    764: void UnknownXhtmlNameSpace (ParserData *context, Element *unknownEl,
                    765:                            char* content)
1.51      cvs       766: {
                    767:    ElementType     elType;
1.65      cvs       768:    Element         elText;
1.51      cvs       769: 
                    770:    /* Create a new Invalid_element */
                    771:    elType.ElSSchema = GetXMLSSchema (XHTML_TYPE, context->doc);
1.94    ! cvs       772:    elType.ElTypeNum = HTML_EL_XHTML_Unknown_namespace;
1.65      cvs       773:    *unknownEl = TtaNewElement (context->doc, elType);
                    774:    if (*unknownEl != NULL)
1.51      cvs       775:      {
1.65      cvs       776:        XmlSetElemLineNumber (*unknownEl);
                    777:        InsertXmlElement (unknownEl);
1.51      cvs       778:        context->lastElementClosed = TRUE;
                    779:        elType.ElTypeNum = HTML_EL_TEXT_UNIT;
                    780:        elText = TtaNewElement (context->doc, elType);
                    781:        XmlSetElemLineNumber (elText);
1.65      cvs       782:        TtaInsertFirstChild (&elText, *unknownEl, context->doc);
1.51      cvs       783:        TtaSetTextContent (elText, content, context->language, context->doc);
                    784:        TtaSetAccessRight (elText, ReadOnly, context->doc);
                    785:      }
                    786: }
                    787: 
                    788: /*----------------------------------------------------------------------
1.30      cvs       789:    CreateHTMLAttribute
                    790:    create an attribute of type attrType for the element el.
                    791:   ----------------------------------------------------------------------*/
1.93      vatton    792: void CreateHTMLAttribute (Element       el,
                    793:                          AttributeType attrType,
                    794:                          char*         text,
                    795:                          ThotBool      isInvalid,
                    796:                          Document      doc,
                    797:                          Attribute    *lastAttribute,
                    798:                          Element      *lastAttrElement)
1.30      cvs       799: {
                    800:    int         attrKind;
                    801:    int         length;
1.39      cvs       802:    char       *buffer;
1.30      cvs       803:    Attribute   attr, oldAttr;
                    804: 
                    805:    if (attrType.AttrTypeNum != 0)
                    806:      {
                    807:        oldAttr = TtaGetAttribute (el, attrType);
                    808:        if (oldAttr != NULL)
                    809:         /* this attribute already exists */
                    810:         attr = oldAttr;
                    811:        else
                    812:         /* create a new attribute and attach it to the element */
                    813:         {
                    814:           attr = TtaNewAttribute (attrType);
                    815:           TtaAttachAttribute (el, attr, doc);
                    816:         }
                    817:        *lastAttribute = attr;
                    818:        *lastAttrElement = el;
                    819: 
                    820:        TtaGiveAttributeType (attr, &attrType, &attrKind);
                    821:        if (attrKind == 0)      /* enumerate */
                    822:         TtaSetAttributeValue (attr, 1, el, doc);
                    823: 
                    824:        /* attribute BORDER without any value (ThotBool attribute) is */
                    825:        /* considered as BORDER=1 */
                    826:        if (attrType.AttrTypeNum == HTML_ATTR_Border)
                    827:         TtaSetAttributeValue (attr, 1, el, doc);
                    828: 
                    829:        if (isInvalid)
                    830:         /* Copy the name of the invalid attribute as the content */
                    831:         /* of the Invalid_attribute attribute. */
                    832:         {
1.37      cvs       833:           length = strlen (text) + 2;
1.30      cvs       834:           length += TtaGetTextAttributeLength (attr);
1.37      cvs       835:           buffer = TtaGetMemory (length + 1);
1.30      cvs       836:           TtaGiveTextAttributeValue (attr, buffer, &length);
1.37      cvs       837:           strcat (buffer, " ");
                    838:           strcat (buffer, text);
1.30      cvs       839:           TtaSetAttributeText (attr, buffer, el, doc);
                    840:           TtaFreeMemory (buffer);
                    841:         }
                    842:      }
                    843: }
                    844: 
                    845: /*----------------------------------------------------------------------
                    846:    HTMLTypeAttrValue
                    847:    Value val has been read for the HTML attribute TYPE.
                    848:    Create a child for the current Thot element INPUT accordingly.
                    849:   ----------------------------------------------------------------------*/
1.46      cvs       850: void               HTMLTypeAttrValue (char       *val,
1.30      cvs       851:                                      Attribute   lastAttribute,
                    852:                                      Element     lastAttrElement,
                    853:                                      ParserData *context)
                    854: 
                    855: {
                    856:   ElementType      elType;
                    857:   Element          newChild;
                    858:   AttributeType    attrType;
                    859:   Attribute        attr;
1.39      cvs       860:   char             msgBuffer[MaxMsgLength];
1.30      cvs       861:   int              value;
                    862:   int              numberOfLinesRead;
                    863: 
                    864:   value = MapAttrValue (DummyAttribute, val);
1.91      quint     865:   if (value <= 0)
1.30      cvs       866:     {
1.37      cvs       867:       if (strlen (val) > MaxMsgLength - 40)
                    868:          val[MaxMsgLength - 40] = EOS;
                    869:       sprintf (msgBuffer, "Unknown attribute value \"type = %s\"", val);
1.42      cvs       870:       HTMLParseError (context->doc, msgBuffer);
1.30      cvs       871:       attrType.AttrSSchema = TtaGetDocumentSSchema (context->doc);
                    872:       attrType.AttrTypeNum = pHTMLAttributeMapping[0].ThotAttribute;
1.37      cvs       873:       sprintf (msgBuffer, "type=%s", val);
1.30      cvs       874:       CreateHTMLAttribute (context->lastElement, attrType, msgBuffer, TRUE,
                    875:                           context->doc, &lastAttribute, &lastAttrElement);
                    876:     }
                    877:   else
                    878:     {
                    879:       elType = TtaGetElementType (context->lastElement);
                    880:       if (elType.ElTypeNum != HTML_EL_Input)
                    881:        {
1.37      cvs       882:          if (strlen (val) > MaxMsgLength - 40)
                    883:            val[MaxMsgLength - 40] = EOS;
                    884:          sprintf (msgBuffer, "Duplicate attribute \"type = %s\"", val);
1.30      cvs       885:        }
                    886:       else
                    887:        {
                    888:          elType.ElSSchema = TtaGetDocumentSSchema (context->doc);
                    889:          elType.ElTypeNum = value;
                    890:          newChild = TtaNewTree (context->doc, elType, "");
                    891:          numberOfLinesRead = 0;
                    892:          TtaSetElementLineNumber (newChild, numberOfLinesRead);
                    893:          TtaInsertFirstChild (&newChild, context->lastElement, context->doc);
                    894:          if (value == HTML_EL_PICTURE_UNIT)
                    895:            {
                    896:              /* add the attribute IsInput to input pictures */
                    897:              attrType.AttrSSchema = elType.ElSSchema;
                    898:              attrType.AttrTypeNum = HTML_ATTR_IsInput;
                    899:              attr = TtaNewAttribute (attrType);
                    900:              TtaAttachAttribute (newChild, attr, context->doc);
                    901:            }
                    902:        }
                    903:     }
                    904: }
                    905: 
                    906: /*----------------------------------------------------------------------
                    907:    XhtmlTypeAttrValue 
                    908:    Value val has been read for the HTML attribute TYPE.
                    909:    Create a child for the current Thot element INPUT accordingly.
                    910:   ----------------------------------------------------------------------*/
1.46      cvs       911: void              XhtmlTypeAttrValue (char       *val,
1.30      cvs       912:                                      Attribute   currentAttribute,
                    913:                                      Element     lastAttrElement,
                    914:                                      ParserData *context)
                    915: 
                    916: {
                    917:   ElementType     elType;
                    918:   Element         newChild;
                    919:   AttributeType   attrType;
                    920:   Attribute       attr;
1.39      cvs       921:   char            msgBuffer[MaxMsgLength];
1.30      cvs       922:   int             value;
                    923:   ThotBool        level;
                    924: 
1.91      quint     925:   /* Look in the dummy section of the attribute value table */
1.30      cvs       926:   attrType.AttrTypeNum = DummyAttribute;
                    927:   MapHTMLAttributeValue (val, attrType, &value);
1.91      quint     928:   if (value <= 0)
                    929:     /* invalid value for the type attribute of an input element */
1.30      cvs       930:     {
1.37      cvs       931:       sprintf (msgBuffer, "Unknown attribute value \"type=%s\"", val);
1.30      cvs       932:       XmlParseError (errorParsing, msgBuffer, 0);
1.36      cvs       933:       MapHTMLAttribute ("unknown_attr", &attrType, NULL,
1.30      cvs       934:                        &level, context->doc);
1.37      cvs       935:       sprintf (msgBuffer, "type=%s", val);
1.30      cvs       936:       CreateHTMLAttribute (context->lastElement, attrType, msgBuffer, TRUE,
                    937:                           context->doc, &currentAttribute, &lastAttrElement);
                    938:     }
                    939:   else
1.91      quint     940:     /* value is the Thot type of the element to be created for this value of
                    941:        the TYPE attribute */
1.30      cvs       942:     {
                    943:       elType = TtaGetElementType (context->lastElement);
                    944:       if (elType.ElTypeNum != HTML_EL_Input)
                    945:        {
1.37      cvs       946:          sprintf (msgBuffer, "Duplicate attribute \"type = %s\"", val);
1.30      cvs       947:          XmlParseError (errorParsing, msgBuffer, 0);
                    948:        }
                    949:       else
                    950:        {
                    951:          elType.ElTypeNum = value;
                    952:          newChild = TtaNewTree (context->doc, elType, "");
                    953:          XmlSetElemLineNumber (newChild);
                    954:          TtaInsertFirstChild (&newChild, context->lastElement, context->doc);
                    955:          if (value == HTML_EL_PICTURE_UNIT)
                    956:            {
                    957:              /* add the attribute IsInput to input pictures */
                    958:              attrType.AttrSSchema = elType.ElSSchema;
                    959:              attrType.AttrTypeNum = HTML_ATTR_IsInput;
                    960:              attr = TtaNewAttribute (attrType);
                    961:              TtaAttachAttribute (newChild, attr, context->doc);
                    962:            }
                    963:        }
                    964:     }
                    965: }
                    966: 
                    967: /*----------------------------------------------------------------------
                    968:    CreateAttrWidthPercentPxl
1.79      quint     969:    an HTML attribute "width" has been created for a Table, an image,
                    970:    an Object of a HR.
1.30      cvs       971:    Create the corresponding attribute IntWidthPercent or IntWidthPxl.
                    972:    oldWidth is -1 or the old image width.
                    973:   ----------------------------------------------------------------------*/
1.58      vatton    974: void CreateAttrWidthPercentPxl (char *buffer, Element el,
                    975:                                Document doc, int oldWidth)
1.30      cvs       976: {
                    977:   AttributeType   attrTypePxl, attrTypePercent;
                    978:   Attribute       attrOld, attrNew;
                    979:   int             length, val;
1.39      cvs       980:   char            msgBuffer[MaxMsgLength];
1.79      quint     981:   ElementType    elType, childType;
                    982:   Element         origEl, child;
1.30      cvs       983:   int             w, h;
                    984:   ThotBool        isImage;
                    985: 
1.79      quint     986:   origEl = el;
1.30      cvs       987:   elType = TtaGetElementType (el);
                    988:   isImage = (elType.ElTypeNum == HTML_EL_PICTURE_UNIT ||
                    989:             elType.ElTypeNum == HTML_EL_Data_cell ||
1.79      quint     990:             elType.ElTypeNum == HTML_EL_Heading_cell ||
                    991:             elType.ElTypeNum == HTML_EL_Object);
                    992:   if (elType.ElTypeNum == HTML_EL_Object)
                    993:     /* the width attribute is attached to an Object element */
                    994:     {
                    995:       child = TtaGetFirstChild (el);
                    996:       if (child)
                    997:        {
                    998:          childType = TtaGetElementType (child);
                    999:          if (childType.ElTypeNum == HTML_EL_PICTURE_UNIT)
                   1000:            /* the Object element is of type image. apply the width
                   1001:               attribute to the actual image element */
                   1002:            el = child;
                   1003:        }
                   1004:     }
1.30      cvs      1005:   /* remove trailing spaces */
1.37      cvs      1006:   length = strlen (buffer) - 1;
1.30      cvs      1007:   while (length > 0 && buffer[length] <= SPACE)
                   1008:     length--;
                   1009:   attrTypePxl.AttrSSchema = TtaGetDocumentSSchema (doc);
                   1010:   attrTypePercent.AttrSSchema = TtaGetDocumentSSchema (doc);
                   1011:   attrTypePxl.AttrTypeNum = HTML_ATTR_IntWidthPxl;
                   1012:   attrTypePercent.AttrTypeNum = HTML_ATTR_IntWidthPercent;
                   1013:   /* is the last character a '%' ? */
                   1014:   if (buffer[length] == '%')
                   1015:     {
                   1016:       /* remove IntWidthPxl */
                   1017:       attrOld = TtaGetAttribute (el, attrTypePxl);
                   1018:       /* update IntWidthPercent */
                   1019:       attrNew = TtaGetAttribute (el, attrTypePercent);
                   1020:       if (attrNew == NULL)
                   1021:        {
                   1022:          attrNew = TtaNewAttribute (attrTypePercent);
                   1023:          TtaAttachAttribute (el, attrNew, doc);
                   1024:        }
                   1025:       else if (isImage && oldWidth == -1)
                   1026:        {
                   1027:          if (attrOld == NULL)
                   1028:            oldWidth = TtaGetAttributeValue (attrNew);
                   1029:          else
                   1030:            oldWidth = TtaGetAttributeValue (attrOld);
                   1031:        }
                   1032:     }
                   1033:   else
                   1034:     {
                   1035:       /* remove IntWidthPercent */
                   1036:       attrOld = TtaGetAttribute (el, attrTypePercent);
                   1037:       /* update IntWidthPxl */
                   1038:       attrNew = TtaGetAttribute (el, attrTypePxl);
                   1039:       if (attrNew == NULL)
                   1040:        {
                   1041:          attrNew = TtaNewAttribute (attrTypePxl);
                   1042:          TtaAttachAttribute (el, attrNew, doc);
                   1043:        }
                   1044:       else if (isImage && oldWidth == -1)
                   1045:        {
                   1046:          TtaGiveBoxSize (el, doc, 1, UnPixel, &w, &h);
                   1047:          if (attrOld == NULL)
                   1048:            oldWidth = w * TtaGetAttributeValue (attrNew) / 100;
                   1049:          else
                   1050:            oldWidth = w * TtaGetAttributeValue (attrOld) / 100;          
                   1051:        }
                   1052:     }
                   1053: 
                   1054:   if (attrOld != NULL)
                   1055:     TtaRemoveAttribute (el, attrOld, doc);
1.43      cvs      1056:   if (sscanf (buffer, "%d", &val))
1.30      cvs      1057:     TtaSetAttributeValue (attrNew, val, el, doc);
                   1058:   else
                   1059:     /* its not a number. Delete attribute and send an error message */
                   1060:     {
                   1061:     TtaRemoveAttribute (el, attrNew, doc);
1.37      cvs      1062:     if (strlen (buffer) > MaxMsgLength - 30)
1.30      cvs      1063:         buffer[MaxMsgLength - 30] = EOS;
1.37      cvs      1064:     sprintf (msgBuffer, "Invalid attribute value \"%s\"", buffer);
1.42      cvs      1065:     HTMLParseError (doc, msgBuffer);
1.30      cvs      1066:     }
                   1067:   if (isImage)
1.79      quint    1068:     UpdateImageMap (origEl, doc, oldWidth, -1);
1.30      cvs      1069: }
                   1070: 
                   1071: /*----------------------------------------------------------------------
1.58      vatton   1072:    CreateAttrHeightPercentPxl
1.79      quint    1073:    an HTML attribute "width" has been created for a Table, an image,
                   1074:    an Object or a HR.
1.58      vatton   1075:    Create the corresponding attribute IntHeightPercent or IntHeightPxl.
                   1076:    oldHeight is -1 or the old image width.
                   1077:   ----------------------------------------------------------------------*/
                   1078: void CreateAttrHeightPercentPxl (char *buffer, Element el,
                   1079:                                Document doc, int oldHeight)
                   1080: {
                   1081:   AttributeType   attrTypePxl, attrTypePercent;
                   1082:   Attribute       attrOld, attrNew;
                   1083:   int             length, val;
                   1084:   char            msgBuffer[MaxMsgLength];
1.79      quint    1085:   ElementType    elType, childType;
                   1086:   Element         origEl, child;
1.58      vatton   1087:   int             w, h;
                   1088:   ThotBool        isImage;
                   1089: 
1.79      quint    1090:   origEl = el;
1.58      vatton   1091:   elType = TtaGetElementType (el);
                   1092:   isImage = (elType.ElTypeNum == HTML_EL_PICTURE_UNIT ||
                   1093:             elType.ElTypeNum == HTML_EL_Data_cell ||
1.79      quint    1094:             elType.ElTypeNum == HTML_EL_Heading_cell ||
                   1095:             elType.ElTypeNum == HTML_EL_Object);
                   1096:   if (elType.ElTypeNum == HTML_EL_Object)
                   1097:     /* the height attribute is attached to an Object element */
                   1098:     {
                   1099:       child = TtaGetFirstChild (el);
1.81      cvs      1100:       if (!child)
                   1101:        return;
                   1102:       else
1.79      quint    1103:        {
                   1104:          childType = TtaGetElementType (child);
                   1105:          if (childType.ElTypeNum == HTML_EL_PICTURE_UNIT)
                   1106:            /* the Object element is of type image. apply the width
                   1107:               attribute to the actual image element */
                   1108:            el = child;
1.81      cvs      1109:          else
                   1110:            return;
1.79      quint    1111:        }
                   1112:     }
1.58      vatton   1113:   /* remove trailing spaces */
                   1114:   length = strlen (buffer) - 1;
                   1115:   while (length > 0 && buffer[length] <= SPACE)
                   1116:     length--;
                   1117:   attrTypePxl.AttrSSchema = TtaGetDocumentSSchema (doc);
                   1118:   attrTypePercent.AttrSSchema = TtaGetDocumentSSchema (doc);
                   1119:   attrTypePxl.AttrTypeNum = HTML_ATTR_IntHeightPxl;
                   1120:   attrTypePercent.AttrTypeNum = HTML_ATTR_IntHeightPercent;
                   1121:   /* is the last character a '%' ? */
                   1122:   if (buffer[length] == '%')
                   1123:     {
                   1124:       /* remove IntHeightPxl */
                   1125:       attrOld = TtaGetAttribute (el, attrTypePxl);
                   1126:       /* update IntHeightPercent */
                   1127:       attrNew = TtaGetAttribute (el, attrTypePercent);
                   1128:       if (attrNew == NULL)
                   1129:        {
                   1130:          attrNew = TtaNewAttribute (attrTypePercent);
                   1131:          TtaAttachAttribute (el, attrNew, doc);
                   1132:        }
                   1133:       else if (isImage && oldHeight == -1)
                   1134:        {
                   1135:          if (attrOld == NULL)
                   1136:            oldHeight = TtaGetAttributeValue (attrNew);
                   1137:          else
                   1138:            oldHeight = TtaGetAttributeValue (attrOld);
                   1139:        }
                   1140:     }
                   1141:   else
                   1142:     {
                   1143:       /* remove IntHeightPercent */
                   1144:       attrOld = TtaGetAttribute (el, attrTypePercent);
                   1145:       /* update IntHeightPxl */
                   1146:       attrNew = TtaGetAttribute (el, attrTypePxl);
                   1147:       if (attrNew == NULL)
                   1148:        {
                   1149:          attrNew = TtaNewAttribute (attrTypePxl);
                   1150:          TtaAttachAttribute (el, attrNew, doc);
                   1151:        }
                   1152:       else if (isImage && oldHeight == -1)
                   1153:        {
                   1154:          TtaGiveBoxSize (el, doc, 1, UnPixel, &w, &h);
                   1155:          if (attrOld == NULL)
                   1156:            oldHeight = w * TtaGetAttributeValue (attrNew) / 100;
                   1157:          else
                   1158:            oldHeight = w * TtaGetAttributeValue (attrOld) / 100;         
                   1159:        }
                   1160:     }
                   1161: 
                   1162:   if (attrOld != NULL)
                   1163:     TtaRemoveAttribute (el, attrOld, doc);
                   1164:   if (sscanf (buffer, "%d", &val))
                   1165:     TtaSetAttributeValue (attrNew, val, el, doc);
                   1166:   else
                   1167:     /* its not a number. Delete attribute and send an error message */
                   1168:     {
                   1169:     TtaRemoveAttribute (el, attrNew, doc);
                   1170:     if (strlen (buffer) > MaxMsgLength - 30)
                   1171:         buffer[MaxMsgLength - 30] = EOS;
                   1172:     sprintf (msgBuffer, "Invalid attribute value \"%s\"", buffer);
                   1173:     HTMLParseError (doc, msgBuffer);
                   1174:     }
                   1175:   if (isImage)
1.79      quint    1176:     UpdateImageMap (origEl, doc, oldHeight, -1);
1.58      vatton   1177: }
                   1178: 
                   1179: /*----------------------------------------------------------------------
1.91      quint    1180:    CreateAttrIntAreaSize
                   1181:    an HTML attribute "size" has been created or modified for a input element.
                   1182:    Create or update the corresponding attribute IntAreaSize.
                   1183:   ----------------------------------------------------------------------*/
                   1184: void CreateAttrIntAreaSize (int value, Element el, Document doc)
                   1185: {
                   1186:   AttributeType   attrType;
                   1187:   Attribute       attr;
                   1188:   ElementType    elType;
                   1189: 
                   1190:   elType = TtaGetElementType (el);
                   1191:   attrType.AttrSSchema = elType.ElSSchema;
                   1192:   attrType.AttrTypeNum = HTML_ATTR_IntAreaSize;
                   1193:   attr = TtaGetAttribute (el, attrType);
                   1194:   if (!attr)
                   1195:     {
                   1196:       attr = TtaNewAttribute (attrType);
                   1197:       TtaAttachAttribute (el, attr, doc);
                   1198:     }
                   1199:   /* the presentation rule associated with attribute IntAreaSize expresses
                   1200:      the element width in "em". Convert the value into em */
                   1201:   TtaSetAttributeValue (attr, (int) (value * 0.55), el, doc);
                   1202: }
                   1203: 
                   1204: /*----------------------------------------------------------------------
1.30      cvs      1205:    CreateAttrIntSize
                   1206:    an HTML attribute "size" has been created for a Font element.
                   1207:    Create the corresponding internal attribute.
                   1208:   ----------------------------------------------------------------------*/
1.46      cvs      1209: void              CreateAttrIntSize (char *buffer, Element el, Document doc)
1.30      cvs      1210: 
                   1211: {
                   1212:    AttributeType  attrType;
                   1213:    int            val, ind, factor, delta;
                   1214:    Attribute      attr;
1.37      cvs      1215:    char         msgBuffer[MaxMsgLength];
1.30      cvs      1216: 
                   1217:    /* is the first character a '+' or a '-' ? */
                   1218:    ind = 0;
                   1219:    factor = 1;
                   1220:    delta = 0;
                   1221:    if (buffer[0] == '+')
                   1222:      {
                   1223:        attrType.AttrTypeNum = HTML_ATTR_IntSizeIncr;
                   1224:        ind++;
1.90      vatton   1225:        factor = 1;
1.30      cvs      1226:      }
                   1227:    else if (buffer[0] == '-')
                   1228:      {
                   1229:        attrType.AttrTypeNum = HTML_ATTR_IntSizeDecr;
                   1230:        ind++;
1.90      vatton   1231:        factor = 1;
1.30      cvs      1232:      }
                   1233:    else
                   1234:      {
                   1235:        attrType.AttrTypeNum = HTML_ATTR_IntSizeRel;
                   1236:        delta = 1;
                   1237:      }
                   1238:    attrType.AttrSSchema = TtaGetDocumentSSchema (doc);
                   1239:    attr = TtaGetAttribute (el, attrType);
1.43      cvs      1240:    if (sscanf (&buffer[ind], "%d", &val))
1.30      cvs      1241:      {
                   1242:        val = val * factor + delta;
                   1243:        if (attr == NULL)
                   1244:         {
                   1245:           /* this attribute doesn't exist, create it */
                   1246:           attr = TtaNewAttribute (attrType);
                   1247:           TtaAttachAttribute (el, attr, doc);
                   1248:         }
                   1249:        TtaSetAttributeValue (attr, val, el, doc);
                   1250:      }
                   1251:    else
                   1252:      /* its not a number. Delete attribute and send an error message */
                   1253:      {
                   1254:        if (attr)
                   1255:          TtaRemoveAttribute (el, attr, doc);
1.37      cvs      1256:        if (strlen (buffer) > MaxMsgLength - 30)
1.30      cvs      1257:          buffer[MaxMsgLength - 30] = EOS;
1.37      cvs      1258:        sprintf (msgBuffer, "Invalid attribute value \"%s\"", buffer);
1.42      cvs      1259:        HTMLParseError (doc, msgBuffer);
1.30      cvs      1260:      }
                   1261: }
                   1262: /*----------------------------------------------------------------------
                   1263:    EndOfHTMLAttributeValue
                   1264:    Filling of an HTML attribute value
                   1265:   ----------------------------------------------------------------------*/
1.48      vatton   1266: void EndOfHTMLAttributeValue (char *attrValue,
                   1267:                              AttributeMapping *lastMappedAttr,
                   1268:                              Attribute currentAttribute,
                   1269:                              Element lastAttrElement,
                   1270:                              ThotBool UnknownAttr,
                   1271:                              ParserData *context,
                   1272:                              ThotBool isXML)
1.30      cvs      1273: {
1.48      vatton   1274:   AttributeType   attrType, attrType1;
                   1275:   Attribute       attr;
1.79      quint    1276:   ElementType    elType;
1.48      vatton   1277:   Element         child, root;
                   1278:   Language        lang;
                   1279:   char            translation;
                   1280:   char            shape;
                   1281:   char           *buffer;
                   1282:   char           *attrName;
                   1283:   char            msgBuffer[MaxMsgLength];
                   1284:   int             val;
                   1285:   int             length;
                   1286:   int             attrKind;
                   1287:   ThotBool        done = FALSE;
1.88      vatton   1288:   ThotBool            loadcss;
1.30      cvs      1289: 
1.48      vatton   1290:   /* treatments of some particular HTML attributes */
                   1291:   if (!strcmp (lastMappedAttr->XMLattribute, "style"))
                   1292:     {
                   1293:       TtaSetAttributeText (currentAttribute, attrValue,
                   1294:                           lastAttrElement, context->doc);
1.88      vatton   1295:       /* check if we have to load CSS */
                   1296:       TtaGetEnvBoolean ("LOAD_CSS", &loadcss);
                   1297:       if (loadcss)
                   1298:        ParseHTMLSpecificStyle (context->lastElement, attrValue,
                   1299:                                context->doc, 100, FALSE);
1.48      vatton   1300:       done = TRUE;
                   1301:     }
                   1302:   else
                   1303:     {
                   1304:       if (!strcmp (lastMappedAttr->XMLattribute, "link"))
1.89      vatton   1305:        HTMLSetAlinkColor (context->doc, context->lastElement, attrValue);
1.48      vatton   1306:       else if (!strcmp (lastMappedAttr->XMLattribute, "alink"))
1.89      vatton   1307:        HTMLSetAactiveColor (context->doc, context->lastElement, attrValue);
1.48      vatton   1308:       else if (!strcmp (lastMappedAttr->XMLattribute, "vlink"))
1.89      vatton   1309:        HTMLSetAvisitedColor (context->doc, context->lastElement, attrValue);
1.48      vatton   1310:     }
1.30      cvs      1311: 
1.48      vatton   1312:   if (!done)
                   1313:     {
                   1314:       val = 0;
                   1315:       translation = lastMappedAttr->AttrOrContent;
                   1316:       switch (translation)
                   1317:        {
                   1318:        case 'C':       /* Content */
                   1319:          child = PutInContent (attrValue, context);
                   1320:          if (child != NULL)
                   1321:            TtaAppendTextContent (child, "\" ", context->doc);
                   1322:          break;
                   1323:          
                   1324:        case 'A':
                   1325:          if (currentAttribute != NULL)
                   1326:            {
                   1327:              TtaGiveAttributeType (currentAttribute, &attrType, &attrKind);
                   1328:              switch (attrKind)
                   1329:                {
                   1330:                case 0: /* enumerate */
                   1331:                  if (isXML)
                   1332:                    MapHTMLAttributeValue (attrValue, attrType, &val);
                   1333:                  else
                   1334:                    val = MapAttrValue (lastMappedAttr->ThotAttribute,
1.40      cvs      1335:                                        attrValue);
1.48      vatton   1336:                  if (val < 0)
                   1337:                    {
                   1338:                      TtaGiveAttributeType (currentAttribute,
                   1339:                                            &attrType, &attrKind);
                   1340:                      attrName = TtaGetAttributeName (attrType);
                   1341:                      sprintf (msgBuffer,
1.51      cvs      1342:                               "Invalid attribute value \"%s = %s\"",
1.48      vatton   1343:                               attrName, attrValue);
                   1344:                      if (isXML)
                   1345:                        XmlParseError (errorParsing, msgBuffer, 0);
                   1346:                      else
1.84      quint    1347:                        /* we are parsing an HTML file, not an XHTML file */
1.51      cvs      1348:                        {
1.84      quint    1349:                          /* generate an error message in the log */
1.51      cvs      1350:                          HTMLParseError (context->doc, msgBuffer);
1.84      quint    1351:                          /* special case for value POLYGON of attribute 
                   1352:                             shape (AREA element) */
                   1353:                          if (attrType.AttrTypeNum == HTML_ATTR_shape &&
                   1354:                              strcasecmp (attrValue, "POLYGON") == 0)
                   1355:                            {
                   1356:                              val = HTML_ATTR_shape_VAL_polygon;
                   1357:                              /* interpret it as if it were "poly" */
                   1358:                              TtaSetAttributeValue (currentAttribute, val,
                   1359:                                          lastAttrElement, context->doc);
                   1360:                            }
                   1361:                          else
                   1362:                            /* remove the attribute and replace it by an */
                   1363:                            /* Invalid_attribute (not for XHTML) */
                   1364:                            {
                   1365:                              TtaRemoveAttribute (lastAttrElement,
1.51      cvs      1366:                                              currentAttribute, context->doc);
1.84      quint    1367:                              attrType.AttrSSchema = 
                   1368:                                         TtaGetDocumentSSchema (context->doc);
                   1369:                              attrType.AttrTypeNum =
                   1370:                                       pHTMLAttributeMapping[0].ThotAttribute;
                   1371:                              sprintf (msgBuffer, "%s=%s", attrName,attrValue);
                   1372:                              CreateHTMLAttribute (lastAttrElement, attrType,
                   1373:                                         msgBuffer, TRUE, context->doc,
                   1374:                                         &currentAttribute, &lastAttrElement);
                   1375:                            }
1.48      vatton   1376:                        }
                   1377:                    }
                   1378:                  else
                   1379:                    TtaSetAttributeValue (currentAttribute, val,
                   1380:                                          lastAttrElement, context->doc);
                   1381:                  break;
                   1382:                case 1: /* integer */
                   1383:                  if (attrType.AttrTypeNum == HTML_ATTR_Border &&
                   1384:                      !strcasecmp (attrValue, "border"))
                   1385:                    {
                   1386:                      /* border="border" for a table */
                   1387:                      val = 1;
                   1388:                      TtaSetAttributeValue (currentAttribute, val,
1.30      cvs      1389:                                            lastAttrElement, context->doc);
1.48      vatton   1390:                    }
                   1391:                  else if (sscanf (attrValue, "%d", &val))
                   1392:                    TtaSetAttributeValue (currentAttribute, val,
                   1393:                                          lastAttrElement, context->doc);
                   1394:                  else
                   1395:                    {
                   1396:                      TtaRemoveAttribute (lastAttrElement, currentAttribute,
                   1397:                                          context->doc);
                   1398:                      sprintf (msgBuffer,
                   1399:                               "Unknown attribute value \"%s\"",
                   1400:                               attrValue);
                   1401:                      if (isXML)
                   1402:                        XmlParseError (errorParsing, msgBuffer, 0);
                   1403:                      else
                   1404:                        HTMLParseError (context->doc, msgBuffer);
                   1405:                    }
                   1406:                  break;
                   1407:                case 2: /* text */
                   1408:                  if (!UnknownAttr)
                   1409:                    {
                   1410:                      TtaSetAttributeText (currentAttribute, attrValue,
                   1411:                                           lastAttrElement, context->doc);
1.55      cvs      1412:                      if (attrType.AttrTypeNum == HTML_ATTR_Language)
1.48      vatton   1413:                        {
                   1414:                          /* it's a LANG attribute value */
                   1415:                          lang = TtaGetLanguageIdFromName (attrValue);
1.70      vatton   1416:                          if (lang < 0)
1.48      vatton   1417:                            {
                   1418:                              sprintf (msgBuffer,
                   1419:                                       "warning - unsupported language: %s",
                   1420:                                       attrValue);
                   1421:                              if (isXML)
1.87      vatton   1422:                                XmlParseError (warningMessage, msgBuffer, 0);
1.48      vatton   1423:                              else
                   1424:                                HTMLParseError (context->doc, msgBuffer);
                   1425:                            }
                   1426:                          else
                   1427:                            {
                   1428:                              /* change current language */
                   1429:                              context->language = lang;
                   1430:                              if (isXML)
                   1431:                                SetLanguagInXmlStack (lang);
                   1432:                              else
                   1433:                                SetLanguagInHTMLStack (lang);
                   1434:                            }
                   1435:                          root = TtaGetRootElement (context->doc);
                   1436:                          if (lastAttrElement == root)
                   1437:                            /* it's a LANG attribute on the root element */
                   1438:                            /* set the RealLang attribute */
                   1439:                            {
                   1440:                              attrType1.AttrSSchema = TtaGetDocumentSSchema (context->doc);
                   1441:                              attrType1.AttrTypeNum = HTML_ATTR_RealLang;
                   1442:                              /* this attribute could be already present,
                   1443:                                 (lang and xml:lang attributes) */
                   1444:                              if (!TtaGetAttribute (lastAttrElement,
                   1445:                                                    attrType1))
                   1446:                                /* it's not present. Add it */
                   1447:                                {
                   1448:                                  attr = TtaNewAttribute (attrType1);
                   1449:                                  TtaAttachAttribute (lastAttrElement,
                   1450:                                                      attr, context->doc);
                   1451:                                  TtaSetAttributeValue (attr,
                   1452:                                                        HTML_ATTR_RealLang_VAL_Yes_,
                   1453:                                                        lastAttrElement,
                   1454:                                                        context->doc);
                   1455:                                }
                   1456:                            }
                   1457:                        }
                   1458:                      else if (attrType.AttrTypeNum == HTML_ATTR_accesskey)
                   1459:                        TtaAddAccessKey (context->doc, (unsigned int)attrValue[0],
                   1460:                                         lastAttrElement);
                   1461:                    }
                   1462:                  else
                   1463:                    {
1.51      cvs      1464:                      /* this is the content of an invalid attribute */
                   1465:                      /* append it to the current Invalid_attribute */
                   1466:                      if (!isXML)
                   1467:                        {
                   1468:                          length = strlen (attrValue) + 2;
                   1469:                          length += TtaGetTextAttributeLength (currentAttribute);
                   1470:                          buffer = TtaGetMemory (length + 1);
                   1471:                          TtaGiveTextAttributeValue (currentAttribute,
                   1472:                                                     buffer, &length);
                   1473:                          strcat (buffer, "=");
                   1474:                          strcat (buffer, attrValue);
                   1475:                          TtaSetAttributeText (currentAttribute, buffer,
                   1476:                                               lastAttrElement, context->doc);
                   1477:                          TtaFreeMemory (buffer);
                   1478:                        }
1.48      vatton   1479:                    }
                   1480:                  break;
                   1481:                case 3: /* reference */
                   1482:                  break;
                   1483:                }
                   1484:            }
                   1485:          break;
                   1486:          
                   1487:        case SPACE:
                   1488:          if (isXML)
                   1489:            XhtmlTypeAttrValue (attrValue, currentAttribute,
1.30      cvs      1490:                                lastAttrElement, context);
1.48      vatton   1491:          else
                   1492:            HTMLTypeAttrValue (attrValue, currentAttribute,
                   1493:                               lastAttrElement, context);
                   1494:          break;
                   1495:          
1.30      cvs      1496:         default:
                   1497:           break;
1.48      vatton   1498:        }
1.30      cvs      1499: 
                   1500:       if (lastMappedAttr->ThotAttribute == HTML_ATTR_Width__)
1.79      quint    1501:        /* HTML attribute "width" */
                   1502:        {
                   1503:          /* if it's an Object element, wait until all attributes are handled,
                   1504:             especially the data attribute that may generate the image to
                   1505:             which the width has to be applied */
                   1506:          elType = TtaGetElementType (lastAttrElement);
                   1507:          if (elType.ElTypeNum != HTML_EL_Object)
                   1508:            /* create the corresponding attribute IntWidthPercent or */
                   1509:            /* IntWidthPxl */
                   1510:            CreateAttrWidthPercentPxl (attrValue, lastAttrElement,
                   1511:                                       context->doc, -1);
                   1512:        }
1.58      vatton   1513:       else if (lastMappedAttr->ThotAttribute == HTML_ATTR_Height_)
1.79      quint    1514:        /* HTML attribute "height" */
                   1515:        {
                   1516:          /* if it's an Object element, wait until all attributes are handled,
                   1517:             especially the data attribute that may generate the image to
                   1518:             which the height has to be applied */
                   1519:          elType = TtaGetElementType (lastAttrElement);
                   1520:          if (elType.ElTypeNum != HTML_EL_Object)
                   1521:            /* create the corresponding attribute IntHeightPercent or */
                   1522:            /* IntHeightPxl */
                   1523:            CreateAttrHeightPercentPxl (attrValue, lastAttrElement,
                   1524:                                        context->doc, -1);
                   1525:        }
1.91      quint    1526:       else if (lastMappedAttr->ThotAttribute == HTML_ATTR_Area_Size)
                   1527:        /* HTML attribute "size" for an element "input" */
                   1528:        CreateAttrIntAreaSize (val, lastAttrElement, context->doc);
1.48      vatton   1529:       else if (!strcmp (lastMappedAttr->XMLattribute, "size"))
                   1530:        {
                   1531:          TtaGiveAttributeType (currentAttribute, &attrType, &attrKind);
                   1532:          if (attrType.AttrTypeNum == HTML_ATTR_Font_size)
                   1533:            CreateAttrIntSize (attrValue, lastAttrElement, context->doc);
                   1534:        }
                   1535:       else if (!strcmp (lastMappedAttr->XMLattribute, "shape"))
                   1536:        {
                   1537:          child = TtaGetFirstChild (lastAttrElement);
                   1538:          if (child != NULL)
                   1539:            {
                   1540:              switch (val)
                   1541:                {
                   1542:                case HTML_ATTR_shape_VAL_rectangle:
                   1543:                  shape = 'R';
                   1544:                  break;
                   1545:                case HTML_ATTR_shape_VAL_circle:
                   1546:                  shape = 'a';
                   1547:                  break;
                   1548:                case HTML_ATTR_shape_VAL_polygon:
                   1549:                  shape = 'p';
                   1550:                  break;
                   1551:                default:
                   1552:                  shape = SPACE;
                   1553:                  break;
                   1554:                }
                   1555:              TtaSetGraphicsShape (child, shape, context->doc);
                   1556:            }
                   1557:        }
                   1558:       else if (!strcmp (lastMappedAttr->XMLattribute, "value"))
                   1559:        {
                   1560:          elType = TtaGetElementType (lastAttrElement);
                   1561:          if (elType.ElTypeNum == HTML_EL_Text_Input ||
                   1562:              elType.ElTypeNum == HTML_EL_Password_Input ||
                   1563:              elType.ElTypeNum == HTML_EL_File_Input ||
                   1564:              elType.ElTypeNum == HTML_EL_Input)
                   1565:            /* create a Default_Value attribute with the same content */
                   1566:            {
                   1567:              attrType1.AttrSSchema = attrType.AttrSSchema;
                   1568:              attrType1.AttrTypeNum = HTML_ATTR_Default_Value;
                   1569:              attr = TtaNewAttribute (attrType1);
                   1570:              TtaAttachAttribute (lastAttrElement, attr, context->doc);
                   1571:              TtaSetAttributeText (attr, attrValue,
                   1572:                                   lastAttrElement, context->doc);
                   1573:            }
                   1574:        }
1.30      cvs      1575:       else
1.48      vatton   1576:        {
                   1577:          /* Some HTML attributes are equivalent to a CSS property:      */
                   1578:          /*      background     ->                   background         */
                   1579:          /*      bgcolor        ->                   background         */
                   1580:          /*      text           ->                   color              */
                   1581:          /*      color          ->                   color              */
                   1582:          if (!strcmp (lastMappedAttr->XMLattribute, "background"))
                   1583:            {
                   1584:              if (strlen (attrValue) > MaxMsgLength - 30)
                   1585:                attrValue[MaxMsgLength - 30] = EOS;
1.76      vatton   1586:              HTMLSetBackgroundImage (context->doc, context->lastElement,
1.85      vatton   1587:                                      REPEAT, attrValue, FALSE);
1.48      vatton   1588:            }
                   1589:          else if (!strcmp (lastMappedAttr->XMLattribute, "bgcolor"))
1.76      vatton   1590:            HTMLSetBackgroundColor (context->doc, context->lastElement,
                   1591:                                    attrValue);
1.48      vatton   1592:          else if (!strcmp (lastMappedAttr->XMLattribute, "text") ||
                   1593:                   !strcmp (lastMappedAttr->XMLattribute, "color"))
                   1594:            HTMLSetForegroundColor (context->doc,
                   1595:                                    context->lastElement, attrValue);
                   1596:        }
                   1597:     }
1.30      cvs      1598: }
                   1599: 
                   1600: /*----------------------------------------------------------------------
1.16      cvs      1601:    MapHTMLAttributeValue
1.2       cvs      1602:    Search in the Attribute Value Mapping Table the entry for the attribute
1.66      vatton   1603:    ThotAtt and its value attVal. Returns the corresponding Thot value.
1.1       cvs      1604:   ----------------------------------------------------------------------*/
1.66      vatton   1605: void MapHTMLAttributeValue (char *attVal, AttributeType attrType, int *value)
1.1       cvs      1606: {
1.66      vatton   1607:   MapXMLAttributeValue (XHTML_TYPE, attVal, attrType, value);
1.1       cvs      1608: }

Webmaster