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

1.1       cvs         1: /*
                      2:  *
1.123     vatton      3:  *  (c) COPYRIGHT INRIA and W3C, 1996-2005
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"
1.104     vatton     34: #include "init_f.h"
1.1       cvs        35: #include "UIcss_f.h"
1.13      cvs        36: #include "styleparser_f.h"
1.2       cvs        37: #include "XHTMLbuilder_f.h"
1.13      cvs        38: #include "Xml2thot_f.h"
1.1       cvs        39: 
1.47      cvs        40: /* Elements that cannot contain text as immediate children.
                     41:    When some text is present in the HTML file it must be 
                     42:    surrounded by a Pseudo_paragraph element */
                     43: static int          NoTextChild[] =
1.129     vatton     44:   {
                     45:     HTML_EL_Document, HTML_EL_HTML, HTML_EL_HEAD, HTML_EL_BODY,
                     46:     HTML_EL_Definition_List, HTML_EL_Block_Quote, HTML_EL_Directory,
                     47:     HTML_EL_Form, HTML_EL_Menu, HTML_EL_FIELDSET,
                     48:     HTML_EL_Numbered_List, HTML_EL_Option_Menu,
                     49:     HTML_EL_Unnumbered_List, HTML_EL_Definition, HTML_EL_List_Item,
                     50:     HTML_EL_MAP, HTML_EL_map, HTML_EL_Applet,
                     51:     HTML_EL_Object, HTML_EL_IFRAME, HTML_EL_NOFRAMES,
                     52:     HTML_EL_Division, HTML_EL_Center, HTML_EL_NOSCRIPT,
                     53:     HTML_EL_Data_cell, HTML_EL_Heading_cell,
                     54:     0};
1.47      cvs        55: 
1.28      cvs        56: /* Define a pointer to let parser functions access the HTML entity table */
                     57: extern XmlEntity *pXhtmlEntityTable;
1.6       cvs        58: 
1.30      cvs        59: /* maximum size of error messages */
                     60: #define MaxMsgLength 200
                     61: 
1.6       cvs        62: /*----------------------------------------------------------------------
1.104     vatton     63:   ParseCharsetAndContentType:
1.6       cvs        64:   Parses the element HTTP-EQUIV and looks for the charset value.
                     65:   ----------------------------------------------------------------------*/
1.104     vatton     66: void ParseCharsetAndContentType (Element el, Document doc) 
1.30      cvs        67: 
1.6       cvs        68: {
1.129     vatton     69:   AttributeType attrType;
                     70:   Attribute     attr;
                     71:   ElementType   elType;
                     72:   CHARSET       charset;
                     73:   char         *text, *text2, *ptrText, *str;
                     74:   char          charsetname[MAX_LENGTH];
                     75:   int           length;
                     76:   int           pos, index = 0;
                     77: 
                     78:   charset = TtaGetDocumentCharset (doc);
                     79:   if (charset != UNDEFINED_CHARSET &&
                     80:       DocumentMeta[doc] && DocumentMeta[doc]->content_type)
                     81:     return;
                     82: 
                     83:   elType = TtaGetElementType (el);
                     84:   attrType.AttrSSchema = elType.ElSSchema;
                     85:   attrType.AttrTypeNum = HTML_ATTR_http_equiv;
                     86:   attr = TtaGetAttribute (el, attrType);
                     87:   if (attr != NULL)
                     88:     {
                     89:       /* There is a HTTP-EQUIV attribute */
                     90:       length = TtaGetTextAttributeLength (attr);
                     91:       if (length > 0)
                     92:         {
                     93:           text = (char *)TtaGetMemory (length + 1);
                     94:           TtaGiveTextAttributeValue (attr, text, &length);
                     95:           if (!strcasecmp (text, "content-type"))
                     96:             {
                     97:               attrType.AttrTypeNum = HTML_ATTR_meta_content;
                     98:               attr = TtaGetAttribute (el, attrType);
                     99:               if (attr != NULL)
                    100:                 {
                    101:                   length = TtaGetTextAttributeLength (attr);
                    102:                   if (length > 0)
                    103:                     {
                    104:                       text2 = (char *)TtaGetMemory (length + 1);
                    105:                       TtaGiveTextAttributeValue (attr, text2, &length);
                    106:                       ptrText = text2;
                    107:                       while (*ptrText)
                    108:                         {
                    109:                           *ptrText = tolower (*ptrText);
                    110:                           ptrText++;
                    111:                         }
                    112: 
                    113:                       if (!DocumentMeta[doc])
                    114:                         DocumentMeta[doc] = DocumentMetaDataAlloc ();
                    115:                       if (DocumentMeta[doc]->content_type == NULL)
                    116:                         {
1.104     vatton    117:                           
1.129     vatton    118:                           if (!strncmp (text2, "text/html", 9))
                    119:                             DocumentMeta[doc]->content_type = TtaStrdup ("text/html");
                    120:                           else
                    121:                             DocumentMeta[doc]->content_type = TtaStrdup (AM_XHTML_MIME_TYPE);
                    122:                         }
                    123: 
                    124:                       if (charset == UNDEFINED_CHARSET)
                    125:                         {
                    126:                           /* the charset is not already defined by the http header */
                    127:                           str = strstr (text2, "charset=");
                    128:                           if (str)
                    129:                             {
                    130:                               pos = str - text2 + 8;
                    131:                               while (text2[pos] != SPACE &&
                    132:                                      text2[pos] != TAB && text2[pos] != EOS)
                    133:                                 charsetname[index++] = text2[pos++];
                    134:                               charsetname[index] = EOS;
                    135:                               charset = TtaGetCharset (charsetname);
                    136:                               if (charset != UNDEFINED_CHARSET)
                    137:                                 TtaSetDocumentCharset (doc, charset, FALSE);
                    138:                             }
                    139:                         }
                    140:                       TtaFreeMemory (text2);
                    141:                     }       
                    142:                 } 
                    143:             }
                    144:           TtaFreeMemory (text);
                    145:         }
                    146:     }
1.6       cvs       147: }
                    148: 
1.126     tollenae  149: #ifdef TEMPLATES
1.130     vatton    150: /*----------------------------------------------------------------------
                    151:   ----------------------------------------------------------------------*/
1.126     tollenae  152: void ParseTemplateMeta (Element el, Document doc)
                    153: {
                    154:   AttributeType attrType;
                    155:   Attribute     attr;
                    156:   ElementType   elType;
                    157:   char         *text, *text2, *ptrText;
                    158:   int           length;
                    159: 
                    160:   elType = TtaGetElementType (el);
                    161:   attrType.AttrSSchema = elType.ElSSchema;
                    162:   attrType.AttrTypeNum = HTML_ATTR_meta_name;
                    163:   attr = TtaGetAttribute (el, attrType);
                    164: 
                    165:   if (attr != NULL)
                    166:     {
                    167:       /* There is a name attribute */
                    168:       length = TtaGetTextAttributeLength (attr);
                    169:       if (length > 0)
1.129     vatton    170:         {
                    171:           text = (char *)TtaGetMemory (length + 1);
                    172:           TtaGiveTextAttributeValue (attr, text, &length);
                    173:           if (!strcasecmp (text, "template"))
                    174:             {
                    175:               /* We are parsing the 'template' meta */
                    176:               attrType.AttrTypeNum = HTML_ATTR_meta_content;
                    177:               attr = TtaGetAttribute (el, attrType);
                    178:               if (attr != NULL)
                    179:                 {
                    180:                   length = TtaGetTextAttributeLength (attr);
                    181:                   if (length > 0)
                    182:                     {
                    183:                       text2 = (char *)TtaGetMemory (length + 1);
                    184:                       TtaGiveTextAttributeValue (attr, text2, &length);
                    185:                       ptrText = text2;
1.126     tollenae  186:                      
1.129     vatton    187:                       /* Convert all char to lower case */
                    188:                       while (*ptrText)
                    189:                         {
                    190:                           *ptrText = tolower (*ptrText);
                    191:                           ptrText++;
                    192:                         }
                    193: 
                    194:                       if (!DocumentMeta[doc])
                    195:                         DocumentMeta[doc] = DocumentMetaDataAlloc ();
                    196:                       if (DocumentMeta[doc]->template_version == NULL)
                    197:                         {
                    198:                           DocumentMeta[doc]->template_version = TtaStrdup (text2);
                    199:                         }
                    200:                       TtaFreeMemory (text2);
                    201:                     }       
                    202:                 } 
                    203:             }
                    204:           TtaFreeMemory (text);
                    205:         }
1.126     tollenae  206:     }
                    207: }
                    208: #endif /* TEMPLATES */
                    209: 
                    210: 
1.23      cvs       211: /*----------------------------------------------------------------------
1.129     vatton    212:   XhtmlCannotContainText 
                    213:   Return TRUE if element el is a block element.
1.47      cvs       214:   ----------------------------------------------------------------------*/
1.109     vatton    215: ThotBool XhtmlCannotContainText (ElementType elType)
1.47      cvs       216: 
                    217: {
1.129     vatton    218:   int        i;
                    219:   ThotBool   ret;
1.47      cvs       220: 
1.129     vatton    221:   if (strcmp (TtaGetSSchemaName (elType.ElSSchema), "HTML"))
                    222:     /* not an HTML element */
                    223:     ret = TRUE;
                    224:   else
                    225:     {
                    226:       ret = FALSE;
                    227:       i = 0;
                    228:       while (NoTextChild[i] > 0 && NoTextChild[i] != elType.ElTypeNum)
                    229:         i++;
                    230:       if (NoTextChild[i] == elType.ElTypeNum)
                    231:         ret = TRUE;
                    232:     }
                    233:   return ret;
1.23      cvs       234: }
                    235: 
1.6       cvs       236: /*----------------------------------------------------------------------
1.117     quint     237:   CheckMandatoryAttribute
                    238:   If attribute attrNum is not present on element el, generate a
                    239:   parsing error message.
1.111     vatton    240:   ----------------------------------------------------------------------*/
1.128     tollenae  241: void CheckMandatoryAttribute (Element el, Document doc, int attrNum)
1.111     vatton    242: {
                    243:   ElementType    elType;
                    244:   Attribute      attr;
                    245:   AttributeType  attrType;
1.117     quint     246:   int            lineNum;
1.114     vatton    247:   char          *name;
                    248:   char           msgBuffer[MaxMsgLength];
1.111     vatton    249: 
1.129     vatton    250:   elType = TtaGetElementType (el);
                    251:   attrType.AttrSSchema = elType.ElSSchema;
                    252:   attrType.AttrTypeNum = attrNum;
                    253:   attr = TtaGetAttribute (el, attrType);
                    254:   if (attr == NULL)
                    255:     {
                    256:       name = GetXMLAttributeName (attrType, elType, doc);
                    257:       if (name)
                    258:         {
                    259:           sprintf (msgBuffer, "Missing mandatory attribute %s for element %s",
                    260:                    name, TtaGetElementTypeName(TtaGetElementType(el)));
                    261:           lineNum = TtaGetElementLineNumber(el);
                    262:           if (DocumentMeta[doc] && DocumentMeta[doc]->xmlformat)
                    263:             XmlParseError (errorParsing, (unsigned char *)msgBuffer, lineNum);
                    264:           else
                    265:             HTMLParseError (doc, msgBuffer, lineNum);
                    266:         }
                    267:     }
1.111     vatton    268: }
                    269: 
1.118     vatton    270: 
                    271: /*----------------------------------------------------------------------
                    272:   AddRowsColumns
                    273:   Add default rows and columns attributes to a TEXTAREA element.
                    274:   ----------------------------------------------------------------------*/
                    275: void AddRowsColumns (Element el, Document doc)
                    276: {
                    277:   ElementType    elType;
                    278:   Attribute      attr;
                    279:   AttributeType  attrType;
                    280: 
                    281:   /* Add defaults rows and columns to display the textarea */
                    282:   elType = TtaGetElementType (el);
                    283:   attrType.AttrSSchema = elType.ElSSchema;
                    284:   attrType.AttrTypeNum = HTML_ATTR_Rows;
                    285:   attr = TtaGetAttribute (el, attrType);
                    286:   if (attr == NULL)
                    287:     {
                    288:       attr = TtaNewAttribute (attrType);
                    289:       TtaAttachAttribute (el, attr, doc);
                    290:       TtaSetAttributeValue (attr, 4, el, doc);
                    291:     }
                    292:   attrType.AttrTypeNum = HTML_ATTR_Columns;
                    293:   attr = TtaGetAttribute (el, attrType);
                    294:   if (attr == NULL)
                    295:     {
                    296:       attr = TtaNewAttribute (attrType);
                    297:       TtaAttachAttribute (el, attr, doc);
                    298:       TtaSetAttributeValue (attr, 20, el, doc);
                    299:     }
                    300: }
                    301: 
1.111     vatton    302: /*----------------------------------------------------------------------
1.6       cvs       303:   XhtmlElementComplete
1.20      cvs       304:   Complete Xhtml elements.
1.6       cvs       305:   Check its attributes and its contents.
                    306:   ----------------------------------------------------------------------*/
1.99      cvs       307: void XhtmlElementComplete (ParserData *context, Element el, int *error)
1.30      cvs       308: {
1.129     vatton    309:   Document       doc;   
                    310:   ElementType    elType, newElType, childType;
                    311:   Element        child, desc, leaf, prev, next, last,
                    312:     elFrames, lastFrame, lastChild, parent, picture, content;
                    313:   Attribute      attr;
                    314:   AttributeType  attrType;
1.135     vatton    315:   SSchema        htmlSchema;
1.129     vatton    316:   Language       lang;
1.136     cvs       317:   char           *text;
1.129     vatton    318:   char           lastChar[2];
                    319:   char           *name1, *data;
1.135     vatton    320:   char           msgBuffer[MaxMsgLength];
                    321:   int            lineNum, typenum, length;
1.134     vatton    322:   ThotBool       isImage, isInline, clean;
1.129     vatton    323: 
                    324:   *error = 0;
                    325:   doc = context->doc;
                    326: 
                    327:   elType = TtaGetElementType (el);
                    328:   htmlSchema = elType.ElSSchema;
                    329:   isInline = IsXMLElementInline (elType, doc);
                    330:   newElType.ElSSchema = elType.ElSSchema;
                    331: 
                    332:   if (elType.ElTypeNum == HTML_EL_Paragraph ||
                    333:       elType.ElTypeNum == HTML_EL_Address ||
                    334:       elType.ElTypeNum == HTML_EL_H1 ||
                    335:       elType.ElTypeNum == HTML_EL_H2 ||
                    336:       elType.ElTypeNum == HTML_EL_H3 ||
                    337:       elType.ElTypeNum == HTML_EL_H4 ||
                    338:       elType.ElTypeNum == HTML_EL_H5 ||
                    339:       elType.ElTypeNum == HTML_EL_H6 ||
                    340:       elType.ElTypeNum == HTML_EL_Preformatted ||
                    341:       elType.ElTypeNum == HTML_EL_Term ||
                    342:       elType.ElTypeNum == HTML_EL_LEGEND ||
                    343:       elType.ElTypeNum == HTML_EL_CAPTION ||
                    344:       elType.ElTypeNum == HTML_EL_rb ||
                    345:       elType.ElTypeNum == HTML_EL_rt ||
                    346:       (isInline &&  !TtaIsLeaf (elType) &&
                    347:        elType.ElTypeNum != HTML_EL_Text_Area))
                    348:     /* It's an element that is supposed to contain at least a Basic_Elem.
                    349:        If it is empty, insert a Basic_Elem to allow the user to put the
                    350:        selection within this element */
                    351:     /* Don't do it for a Text_Area, as an Inserted_Text element has to be
                    352:        created (see below) */
                    353:     {
                    354:       child = TtaGetFirstChild (el);
                    355:       if (child == NULL)
                    356:         /* it's an empty inline element */
                    357:         /* insert a Basic_Elem element in the element */
                    358:         {
                    359:           newElType.ElTypeNum = HTML_EL_Basic_Elem;
                    360:           child = TtaNewTree (doc, newElType, "");
                    361:           TtaInsertFirstChild (&child, el, doc);
                    362:         }
                    363:     }
                    364:   if (!isInline)
                    365:     /* It's a block-level element. Is it within a character-level element? */
                    366:     if (elType.ElTypeNum != HTML_EL_Comment_ &&
1.138     vatton    367:         elType.ElTypeNum != HTML_EL_ASP_element &&
1.129     vatton    368:         elType.ElTypeNum != HTML_EL_XMLPI)
                    369:       BlockInCharLevelElem (el);
                    370: 
1.135     vatton    371:   typenum = elType.ElTypeNum;
                    372:   switch (typenum)
1.129     vatton    373:     {
1.134     vatton    374:     case HTML_EL_PICTURE_UNIT:
                    375:       /* Check the mandatory SRC attribute */
                    376:       CheckMandatoryAttribute (el, doc, HTML_ATTR_SRC);
                    377:       break;
                    378: 
1.129     vatton    379:     case HTML_EL_Object:       /* it's an object */
                    380:       data = NULL;
                    381:       isImage = FALSE;
                    382:       /* is there a type attribute on the object element? */
                    383:       attrType.AttrSSchema = elType.ElSSchema;
                    384:       attrType.AttrTypeNum = HTML_ATTR_Object_type;
                    385:       attr = TtaGetAttribute (el, attrType);
                    386:       if (attr)
                    387:         /* there is a type attribute. Get its value to see if the object
                    388:            represents an image */
                    389:         {
                    390:           length = TtaGetTextAttributeLength (attr);
                    391:           if (length > 0)
                    392:             {
                    393:               name1 = (char *)TtaGetMemory (length + 1);
                    394:               TtaGiveTextAttributeValue (attr, name1, &length);
                    395:               if (!strcmp (name1, AM_MATHML_MIME_TYPE) ||
                    396:                   !strcmp (name1, "application/postscript") ||
                    397:                   !strcmp (name1, "image/x-bitmap") ||
                    398:                   !strcmp (name1, "image/x-xpixmap") ||
                    399:                   !strcmp (name1, "image/gif") ||
                    400:                   !strcmp (name1, "image/jpeg") ||
                    401:                   !strcmp (name1, "image/png") ||
                    402:                   !strcmp (name1, "image/svg") ||
                    403:                   !strcmp (name1, AM_SVG_MIME_TYPE) ||
                    404:                   !strcmp (name1, AM_XHTML_MIME_TYPE) ||
                    405:                   !strcmp (name1, "text/html") ||
                    406:                   !strcmp (name1, "text/htm") ||
                    407:                   !strcmp (name1, AM_GENERIC_XML_MIME_TYPE))
                    408:                 isImage = TRUE;
                    409:               TtaFreeMemory (name1);
                    410:             }
                    411:         }
                    412: 
                    413:       attrType.AttrTypeNum = HTML_ATTR_data;
                    414:       attr = TtaGetAttribute (el, attrType);
                    415:       if (attr)
                    416:         /* the object has a data attribute */
                    417:         {
                    418:           length = TtaGetTextAttributeLength (attr);
                    419:           if (length > 0)
                    420:             {
                    421:               data = (char *)TtaGetMemory (length + 1);
                    422:               TtaGiveTextAttributeValue (attr, data, &length);
1.139   ! quint     423:               if (!isImage && length >= 5)
        !           424:                 if (!strcmp (&data[length-4], ".mml") ||
        !           425:                     !strcmp (&data[length-4], ".gif") ||
        !           426:                     !strcmp (&data[length-4], ".jpg") ||
        !           427:                     !strcmp (&data[length-5], ".jpeg") ||
        !           428:                     !strcmp (&data[length-4], ".png") ||
        !           429:                     !strcmp (&data[length-4], ".svg") ||
        !           430:                     !strcmp (&data[length-5], ".svgz") ||
        !           431:                     !strcmp (&data[length-4], ".htm") ||
        !           432:                     !strcmp (&data[length-5], ".html") ||
        !           433:                     !strcmp (&data[length-4], ".xml"))
1.129     vatton    434:                   isImage = TRUE;
                    435:             }
                    436:         }
                    437:       picture = NULL;     /* no PICTURE element yet */
                    438:       child = TtaGetFirstChild (el);
                    439:       if (isImage)
                    440:         {
                    441:           /* the object represents an image. We need a PICTURE element as
                    442:              child of the object to hold the image */
                    443:           elType.ElTypeNum = HTML_EL_PICTURE_UNIT;
                    444:           picture = TtaNewTree (doc, elType, "");
                    445:           if (child)
                    446:             TtaInsertSibling (picture, child, TRUE, doc);
                    447:           else
                    448:             TtaInsertFirstChild (&picture, el, doc);
                    449:           /* copy attribute data of the object into the SRC attribute of
                    450:              the PICTURE element */
                    451:           if (data)
                    452:             /* the object has a data attribute */
                    453:             {
1.134     vatton    454:               // remove extra spaces
                    455:               clean = FALSE;
                    456:               while (length > 0 && data[length-1] == SPACE)
                    457:                 {
                    458:                   data[length-1] = EOS;
                    459:                   length--;
                    460:                   clean = TRUE;
                    461:                 }
                    462:               if (clean)
                    463:                 TtaSetAttributeText (attr, data, el, doc);
                    464:               // copy the attribute in the picture element
1.129     vatton    465:               attrType.AttrTypeNum = HTML_ATTR_SRC;
                    466:               attr = TtaGetAttribute (picture, attrType);
                    467:               if (attr == NULL)
                    468:                 {
                    469:                   attr = TtaNewAttribute (attrType);
                    470:                   TtaAttachAttribute (picture, attr, doc);
1.134     vatton    471: 
1.129     vatton    472:                 }
                    473:               TtaSetAttributeText (attr, data, picture, doc);
1.134     vatton    474:               }
1.129     vatton    475:           attrType.AttrTypeNum = HTML_ATTR_Height_;
                    476:           attr = TtaGetAttribute (el, attrType);
                    477:           if (attr)
                    478:             /* the Object has a height attribute. Applies it to the
                    479:                picture element */
                    480:             {
                    481:               length = TtaGetTextAttributeLength (attr);
                    482:               if (length > 0)
                    483:                 {
                    484:                   text = (char *)TtaGetMemory (length + 1);
                    485:                   TtaGiveTextAttributeValue (attr, text, &length);
                    486:                   /* create the corresponding attribute IntHeightPercent or */
                    487:                   /* IntHeightPxl */
                    488:                   CreateAttrHeightPercentPxl (text, el, doc, -1);
                    489:                   TtaFreeMemory (text);
                    490:                 }
                    491:             }
                    492:           attrType.AttrTypeNum = HTML_ATTR_Width__;
                    493:           attr = TtaGetAttribute (el, attrType);
                    494:           if (attr)
                    495:             /* the Object has a width attribute. Applies it to the
                    496:                picture element */
                    497:             {
                    498:               length = TtaGetTextAttributeLength (attr);
                    499:               if (length > 0)
                    500:                 {
                    501:                   text = (char *)TtaGetMemory (length + 1);
                    502:                   TtaGiveTextAttributeValue (attr, text, &length);
                    503:                   /* create the corresponding attribute IntWidthPercent or */
                    504:                   /* IntWidthPxl */
                    505:                   CreateAttrWidthPercentPxl (text, el, doc, -1);
                    506:                   TtaFreeMemory (text);
                    507:                 }
                    508:             }
                    509:         }
                    510: 
                    511:       /* is the Object_Content element already created ? */
                    512:       if (child)
                    513:         /* the object element has at least 1 child element */
                    514:         {
1.139   ! quint     515:           /* put an attribute NoObjects on the Object element: this attribute
        !           516:              will be removed when and if the actual object is loaded (see
        !           517:              module HTMLimage.c */
        !           518:           attrType.AttrTypeNum = HTML_ATTR_NoObjects;
        !           519:           attr = TtaGetAttribute (el, attrType);
        !           520:           if (!attr)
        !           521:             {
        !           522:               attr = TtaNewAttribute (attrType);
        !           523:               TtaSetAttributeValue (attr, 1, el, doc);
        !           524:               TtaAttachAttribute (el, attr, doc);
        !           525:             }
        !           526: 
1.129     vatton    527:           content = NULL;
                    528:           desc = child;
                    529:           elType = TtaGetElementType (desc);
                    530:           if (elType.ElTypeNum != HTML_EL_Object_Content)
                    531:             {
                    532:               TtaNextSibling(&desc);
                    533:               if (desc)
                    534:                 elType = TtaGetElementType (desc);
                    535:             }
                    536:           /* is it the Object_Content element ? */
                    537:           if (elType.ElTypeNum == HTML_EL_Object_Content)
                    538:             content = desc;
                    539:           else
                    540:             {
                    541:               /* create an Object_Content element */
                    542:               elType.ElTypeNum = HTML_EL_Object_Content;
                    543:               content = TtaNewElement (doc, elType);
                    544:               if (picture)
                    545:                 TtaInsertSibling (content, picture, FALSE, doc);
                    546:               else
                    547:                 TtaInsertSibling (content, child, TRUE, doc);
                    548:               /* move previous existing children into Object_Content */
                    549:               child = TtaGetLastChild(el);
                    550:               while (child != content)
                    551:                 {
                    552:                   TtaRemoveTree (child, doc);
                    553:                   TtaInsertFirstChild (&child, content, doc);
                    554:                   child = TtaGetLastChild(el);
                    555:                 }
                    556:             }
                    557:         }
1.134     vatton    558:       TtaFreeMemory (data);
                    559:       break;
                    560: 
1.135     vatton    561:     case HTML_EL_Image_Input:
1.134     vatton    562:     case HTML_EL_IMG:
                    563:       /* Check the mandatory ALT attribute */
                    564:       CheckMandatoryAttribute (el, doc, HTML_ATTR_ALT);
                    565:       /* Check the mandatory SRC attribute */
                    566:       CheckMandatoryAttribute (el, doc, HTML_ATTR_SRC);
                    567:       /* We need a PICTURE element as child to hold the image */
                    568:       picture = NULL;
1.137     quint     569:       for (child = TtaGetFirstChild (el); child && !picture;
                    570:            TtaNextSibling (&child))
1.134     vatton    571:         {
1.137     quint     572:           childType = TtaGetElementType (child);
                    573:           if (childType.ElTypeNum == HTML_EL_PICTURE_UNIT &&
                    574:               childType.ElSSchema == elType.ElSSchema)
1.134     vatton    575:             // the picture is already created
                    576:             picture = child;
                    577:         }
                    578:       if (picture == NULL)
                    579:         {
1.137     quint     580:           childType.ElTypeNum = HTML_EL_PICTURE_UNIT;
                    581:           picture = TtaNewTree (doc, childType, "");
1.134     vatton    582:           if (child)
                    583:             TtaInsertSibling (picture, child, TRUE, doc);
                    584:           else
                    585:             TtaInsertFirstChild (&picture, el, doc);
                    586:         }
                    587:       attrType.AttrSSchema = elType.ElSSchema;
                    588:       attrType.AttrTypeNum = HTML_ATTR_SRC;
                    589:       attr = TtaGetAttribute (el, attrType);
                    590:       if (attr)
                    591:         /* the img has a src attribute */
                    592:         {
                    593:           length = TtaGetTextAttributeLength (attr);
                    594:           data = (char *)TtaGetMemory (length + 1);
                    595:           TtaGiveTextAttributeValue (attr, data, &length);
                    596:           if (data)
                    597:             {
                    598:               // remove extra spaces
                    599:               clean = FALSE;
                    600:               while (length > 0 && data[length-1] == SPACE)
                    601:                 {
                    602:                   data[length-1] = EOS;
                    603:                   length--;
                    604:                   clean = TRUE;
                    605:                 }
                    606:               if (clean)
                    607:                 TtaSetAttributeText (attr, data, el, doc);
                    608:               // copy the attribute in the picture element
                    609:               attr = TtaGetAttribute (picture, attrType);
                    610:               if (attr == NULL)
                    611:                 {
                    612:                   attr = TtaNewAttribute (attrType);
                    613:                   TtaAttachAttribute (picture, attr, doc);
                    614:                 }
                    615:               TtaSetAttributeText (attr, data, picture, doc);
                    616:               TtaFreeMemory (data);
                    617:             }
                    618:         }
1.135     vatton    619:       if (typenum == HTML_EL_IMG)
1.134     vatton    620:         {
1.135     vatton    621:           attrType.AttrTypeNum = HTML_ATTR_Height_;
                    622:           attr = TtaGetAttribute (el, attrType);
                    623:           if (attr)
                    624:             /* the img has a height attribute. Applies it to the
                    625:                picture element */
1.134     vatton    626:             {
1.135     vatton    627:               length = TtaGetTextAttributeLength (attr);
                    628:               if (length > 0)
                    629:                 {
                    630:                   text = (char *)TtaGetMemory (length + 1);
                    631:                   TtaGiveTextAttributeValue (attr, text, &length);
                    632:                   /* create the corresponding attribute IntHeightPercent or */
                    633:                   /* IntHeightPxl */
                    634:                   CreateAttrHeightPercentPxl (text, el, doc, -1);
                    635:                   TtaFreeMemory (text);
                    636:                 }
1.134     vatton    637:             }
1.135     vatton    638:           attrType.AttrTypeNum = HTML_ATTR_Width__;
                    639:           attr = TtaGetAttribute (el, attrType);
                    640:           if (attr)
                    641:             /* the img has a width attribute. Applies it to the
                    642:                picture element */
1.134     vatton    643:             {
1.135     vatton    644:               length = TtaGetTextAttributeLength (attr);
                    645:               if (length > 0)
                    646:                 {
                    647:                   text = (char *)TtaGetMemory (length + 1);
                    648:                   TtaGiveTextAttributeValue (attr, text, &length);
                    649:                   /* create the corresponding attribute IntWidthPercent or */
                    650:                   /* IntWidthPxl */
                    651:                   CreateAttrWidthPercentPxl (text, el, doc, -1);
                    652:                   TtaFreeMemory (text);
                    653:                 }
1.134     vatton    654:             }
1.135     vatton    655:          }
1.129     vatton    656:       break;
                    657: 
                    658:     case HTML_EL_Parameter:
                    659:       /* Check the mandatory name attribute */
                    660:       CheckMandatoryAttribute (el, doc, HTML_ATTR_Param_name);
                    661:       break;
                    662: 
                    663:     case HTML_EL_IFRAME:         /* it's an iframe */
                    664:       child = TtaGetFirstChild (el);
                    665:       /* is the Iframe_Content element already created ? */
                    666:       if (child)
                    667:         /* the iframe element has at least 1 child element */
                    668:         {
                    669:           content = NULL;
                    670:           desc = child;
                    671:           elType = TtaGetElementType (desc);
                    672:           if (elType.ElTypeNum != HTML_EL_Iframe_Content)
                    673:             {
                    674:               TtaNextSibling(&desc);
                    675:               if (desc)
                    676:                 elType = TtaGetElementType (desc);
                    677:             }
                    678:           /* is it the Iframe_Content element ? */
                    679:           if (elType.ElTypeNum == HTML_EL_Iframe_Content)
                    680:             content = desc;
                    681:           else
                    682:             {
                    683:               /* create an Iframe_Content element */
                    684:               elType.ElTypeNum = HTML_EL_Iframe_Content;
                    685:               content = TtaNewElement (doc, elType);
                    686:               TtaInsertSibling (content, child, TRUE, doc);
                    687:               /* move previous existing children into Iframe_Content */
                    688:               child = TtaGetLastChild(el);
                    689:               while (child != content)
                    690:                 {
                    691:                   TtaRemoveTree (child, doc);
                    692:                   TtaInsertFirstChild (&child, content, doc);
                    693:                   child = TtaGetLastChild(el);
                    694:                 }
                    695:             }
                    696:         }
                    697:       break;
                    698: 
                    699:     case HTML_EL_Unnumbered_List:
                    700:     case HTML_EL_Numbered_List:
                    701:     case HTML_EL_Menu:
                    702:     case HTML_EL_Directory:
                    703:       /* It's a List element. It should only have List_Item children.
                    704:          If it has List element chidren, move these List elements
                    705:          within their previous List_Item sibling.  This is to fix
                    706:          a bug in document generated by Mozilla. */
                    707:       prev = NULL;
                    708:       next = NULL;
                    709:       child = TtaGetFirstChild (el);
                    710:       while (child != NULL)
                    711:         {
                    712:           next = child;
                    713:           TtaNextSibling (&next);
                    714:           elType = TtaGetElementType (child);
                    715:           if (elType.ElTypeNum == HTML_EL_Unnumbered_List ||
                    716:               elType.ElTypeNum == HTML_EL_Numbered_List ||
                    717:               elType.ElTypeNum == HTML_EL_Menu ||
                    718:               elType.ElTypeNum == HTML_EL_Directory)
                    719:             /* this list element is a child of another list element */
                    720:             if (prev)
                    721:               {
                    722:                 elType = TtaGetElementType (prev);
                    723:                 if (elType.ElTypeNum == HTML_EL_List_Item)
                    724:                   {
                    725:                     /* get the last child of the previous List_Item */
                    726:                     desc = TtaGetFirstChild (prev);
                    727:                     last = NULL;
                    728:                     while (desc)
                    729:                       {
                    730:                         last = desc;
                    731:                         TtaNextSibling (&desc);
                    732:                       }
                    733:                     /* move the list element after the last child of the
                    734:                        previous List_Item */
                    735:                     TtaRemoveTree (child, doc);
                    736:                     if (last)
                    737:                       TtaInsertSibling (child, last, FALSE, doc);
                    738:                     else
                    739:                       TtaInsertFirstChild (&child, prev, doc);
                    740:                     child = prev;
                    741:                   }
                    742:               }
                    743:           prev = child;
                    744:           child = next;
                    745:         }
                    746:       break;
1.6       cvs       747:        
1.129     vatton    748:     case HTML_EL_FRAMESET:
                    749:       /* The FRAMESET element is now complete.  Gather all its FRAMESET
                    750:          and FRAME children and wrap them up in a Frames element */
                    751:       elFrames = NULL; lastFrame = NULL;
                    752:       lastChild = NULL;
                    753:       child = TtaGetFirstChild (el);
                    754:       while (child != NULL)
                    755:         {
                    756:           next = child;
                    757:           TtaNextSibling (&next);
                    758:           elType = TtaGetElementType (child);
                    759:           if (elType.ElTypeNum == HTML_EL_FRAMESET ||
                    760:               elType.ElTypeNum == HTML_EL_FRAME ||
1.138     vatton    761:               elType.ElTypeNum == HTML_EL_Comment_||
                    762:               elType.ElTypeNum == HTML_EL_ASP_element)
1.129     vatton    763:             {
                    764:               /* create the Frames element if it does not exist */
                    765:               if (elFrames == NULL)
                    766:                 {
                    767:                   newElType.ElSSchema = htmlSchema;
                    768:                   newElType.ElTypeNum = HTML_EL_Frames;
                    769:                   elFrames = TtaNewElement (doc, newElType);
                    770:                   if (DocumentMeta[doc]->xmlformat)
                    771:                     XmlSetElemLineNumber (elFrames);
                    772:                   else
                    773:                     SetHtmlElemLineNumber (elFrames);
                    774:                   TtaInsertSibling (elFrames, child, TRUE, doc);
                    775:                 }
                    776:               /* move the element as the last child of the Frames element */
                    777:               TtaRemoveTree (child, doc);
                    778:               if (lastFrame == NULL)
                    779:                 TtaInsertFirstChild (&child, elFrames, doc);
                    780:               else
                    781:                 TtaInsertSibling (child, lastFrame, FALSE, doc);
                    782:               lastFrame = child;
                    783:             }
                    784:           child = next;
                    785:         }
                    786:       break;
1.6       cvs       787:        
1.129     vatton    788:     case HTML_EL_Form:
                    789:       /* Check the mandatory action attribute */
                    790:       CheckMandatoryAttribute (el, doc, HTML_ATTR_Script_URL);
                    791:       break;
                    792: 
                    793:     case HTML_EL_Input:        /* it's an INPUT without any TYPE attribute */
                    794:       /* Create a child of type Text_Input */
                    795:       elType.ElTypeNum = HTML_EL_Text_Input;
                    796:       child = TtaNewTree (doc, elType, "");
                    797:       if (DocumentMeta[doc]->xmlformat)
                    798:         XmlSetElemLineNumber (child);
                    799:       else
                    800:         SetHtmlElemLineNumber (child);
                    801:       TtaInsertFirstChild (&child, el, doc);
                    802:       /* now, process it like a Text_Input element */
                    803: 
                    804:     case HTML_EL_Text_Input:
                    805:     case HTML_EL_Password_Input:
                    806:     case HTML_EL_File_Input:
                    807:       /* set default size */
                    808:       attrType.AttrSSchema = elType.ElSSchema;
                    809:       attrType.AttrTypeNum = HTML_ATTR_IntAreaSize;
                    810:       attr = TtaGetAttribute (el, attrType);
                    811:       if (!attr)
                    812:         CreateAttrIntAreaSize (20, el, doc);
                    813:       /* get element Inserted_Text */
                    814:       child = TtaGetFirstChild (el);
                    815:       if (child != NULL)
                    816:         {
                    817:           attrType.AttrTypeNum = HTML_ATTR_Value_;
                    818:           attr = TtaGetAttribute (el, attrType);
                    819:           if (attr != NULL)
                    820:             {
                    821:               /* copy the value of attribute "value" into the first text
                    822:                  leaf of element */
                    823:               length = TtaGetTextAttributeLength (attr);
                    824:               if (length > 0)
                    825:                 {
                    826:                   /* get the text leaf */
                    827:                   leaf = TtaGetFirstChild (child);
                    828:                   if (leaf != NULL)
                    829:                     {
                    830:                       childType = TtaGetElementType (leaf);
                    831:                       if (childType.ElTypeNum == HTML_EL_TEXT_UNIT)
                    832:                         {
                    833:                           /* copy attribute value into the text leaf */
                    834:                           text = (char *)TtaGetMemory (length + 1);
                    835:                           TtaGiveTextAttributeValue (attr, text, &length);
                    836:                           TtaSetTextContent (leaf, (unsigned char *)text, 
                    837:                                              TtaGetDefaultLanguage (), doc);
                    838:                           TtaFreeMemory (text);
                    839:                         }
                    840:                     }
                    841:                 }
                    842:             }
                    843:         }
                    844:       break;
1.6       cvs       845:        
1.129     vatton    846:     case HTML_EL_META:
                    847:       ParseCharsetAndContentType (el, doc);
                    848:       /* Check the mandatory CONTENT attribute */
                    849:       CheckMandatoryAttribute (el, doc, HTML_ATTR_meta_content);
1.126     tollenae  850: #ifdef TEMPLATES
1.129     vatton    851:       ParseTemplateMeta (el, doc);
1.126     tollenae  852: #endif /* TEMPLATES */
1.129     vatton    853:       break;
                    854: 
                    855:     case HTML_EL_BASE:
                    856:       /* Check the mandatory HREF attribute */
                    857:       CheckMandatoryAttribute (el, doc, HTML_ATTR_HREF_);
                    858:       break;
                    859: 
                    860:     case HTML_EL_BaseFont:
                    861:       /* Check the mandatory size attribute */
                    862:       CheckMandatoryAttribute (el, doc, HTML_ATTR_BaseFontSize);
                    863:       break;
                    864: 
                    865:     case HTML_EL_BDO:
                    866:       /* Check the mandatory DIR attribute */
                    867:       CheckMandatoryAttribute (el, doc, HTML_ATTR_dir);
                    868:       break;
1.114     vatton    869: 
1.129     vatton    870:     case HTML_EL_STYLE_:       /* it's a STYLE element */
                    871:     case HTML_EL_SCRIPT_:      /* it's a SCRIPT element */
                    872:     case HTML_EL_Preformatted: /* it's a PRE */
1.131     quint     873:       if (elType.ElTypeNum == HTML_EL_SCRIPT_)
                    874:         if (DocumentMeta[doc]->xmlformat)
                    875:           SetParsingScript (FALSE);
                    876:         else
                    877:           SetHtmlParsingScript (FALSE);
                    878: 
1.129     vatton    879:       /* if the last line of the Preformatted is empty, remove it */
                    880:       leaf = XmlLastLeafInElement (el);
                    881:       if (leaf != NULL)
                    882:         {
                    883:           elType = TtaGetElementType (leaf);
                    884:           if (elType.ElTypeNum == HTML_EL_TEXT_UNIT)
                    885:             /* the last leaf is a TEXT element */
                    886:             {
                    887:               length = TtaGetTextLength (leaf);
                    888:               if (length > 0)
                    889:                 {
                    890:                   TtaGiveSubString (leaf, (unsigned char *)lastChar, length, 1);
                    891:                   if (lastChar[0] == EOL)
                    892:                     /* last character is new line, delete it */
                    893:                     {
                    894:                       if (length == 1)
                    895:                         /* empty TEXT element */
                    896:                         TtaDeleteTree (leaf, doc);
                    897:                       else
                    898:                         /* remove the last character */
                    899:                         TtaDeleteTextContent (leaf, length, 1, doc);
                    900:                     }
                    901:                 }
                    902:             }
                    903:         }
                    904: 
                    905:       if (elType.ElTypeNum == HTML_EL_STYLE_)
                    906:         /* Check the mandatory TYPE attribute */
                    907:         CheckMandatoryAttribute (el, doc, HTML_ATTR_Notation);
                    908:       else if (elType.ElTypeNum == HTML_EL_SCRIPT_)
                    909:         /* Check the mandatory TYPE attribute */
                    910:         CheckMandatoryAttribute (el, doc, HTML_ATTR_content_type);
                    911: 
                    912:       if (DocumentMeta[doc] && DocumentMeta[doc]->xmlformat)
                    913:         {
                    914:           if (IsXmlParsingCSS ())
                    915:             {
                    916:               text = GetStyleContents (el);
                    917:               if (text)
                    918:                 {
                    919:                   ReadCSSRules (doc, NULL, text, NULL,
                    920:                                 TtaGetElementLineNumber (el), FALSE, el);
                    921:                   TtaFreeMemory (text);
                    922:                 }
                    923:               SetXmlParsingCSS (FALSE);
                    924:             }
                    925:         }
                    926:       else
                    927:         {
                    928:           if (IsHtmlParsingCSS ())
                    929:             {
                    930:               text = GetStyleContents (el);
                    931:               if (text)
                    932:                 {
                    933:                   ReadCSSRules (doc, NULL, text, NULL,
                    934:                                 TtaGetElementLineNumber (el), FALSE, el);
                    935:                   TtaFreeMemory (text);
                    936:                 }
                    937:               SetHtmlParsingCSS (FALSE);
                    938:             }
                    939:         }
                    940:       /* and continue as if it were a Preformatted or a Script */
                    941:       break;
1.6       cvs       942:        
1.129     vatton    943:     case HTML_EL_Text_Area:    /* it's a Text_Area */
                    944:       if (DocumentMeta[doc]->xmlformat)
                    945:         SetParsingTextArea (FALSE);
                    946:       else
                    947:         SetHtmlParsingTextArea (FALSE);
                    948:       child = TtaGetFirstChild (el);
                    949:       if (child == NULL)
                    950:         /* it's an empty Text_Area */
                    951:         /* insert a Inserted_Text element and a child Basic_Elem in the
                    952:            Text_Area element */
                    953:         {
                    954:           newElType.ElTypeNum = HTML_EL_Inserted_Text;
                    955:           child = TtaNewTree (doc, newElType, "");
                    956:           TtaInsertFirstChild (&child, el, doc);
                    957:         }
                    958:       else
                    959:         {
                    960:           /* save the text into Default_Value attribute */
                    961:           attrType.AttrSSchema = htmlSchema;
                    962:           attrType.AttrTypeNum = HTML_ATTR_Default_Value;
                    963:           if (TtaGetAttribute (el, attrType) == NULL)
                    964:             /* attribute Default_Value is missing */
                    965:             {
                    966:               desc = TtaGetFirstChild (child);
                    967:               if (desc)
                    968:                 {
                    969:                   length = TtaGetTextLength (desc);
                    970:                   if (length > 0)
                    971:                     {
                    972:                       length++;
                    973:                       attr = TtaNewAttribute (attrType);
                    974:                       TtaAttachAttribute (el, attr, doc);
                    975:                       text = (char *)TtaGetMemory (length);
                    976:                       TtaGiveTextContent (desc, (unsigned char *)text, &length, &lang);
                    977:                       TtaSetAttributeText (attr, text, el, doc);
                    978:                       TtaFreeMemory (text);
                    979:                     }
                    980:                 }
                    981:             }
                    982:         }
                    983:       /* Check the mandatory rows attribute */
                    984:       CheckMandatoryAttribute (el, doc, HTML_ATTR_Rows);
                    985:       /* Check the mandatory columns attribute */
                    986:       CheckMandatoryAttribute (el, doc, HTML_ATTR_Columns);
                    987:       /* Add default rows and columns attributes */
                    988:       AddRowsColumns (el, doc);
                    989:       break;
                    990: 
                    991:     case HTML_EL_Radio_Input:
                    992:     case HTML_EL_Checkbox_Input:
                    993:       /* put an attribute Checked if it is missing */
                    994:       attrType.AttrSSchema = htmlSchema;
                    995:       attrType.AttrTypeNum = HTML_ATTR_Checked;
                    996:       if (TtaGetAttribute (el, attrType) == NULL)
                    997:         /* attribute Checked is missing */
                    998:         {
                    999:           attr = TtaNewAttribute (attrType);
                   1000:           TtaAttachAttribute (el, attr, doc);
                   1001:           TtaSetAttributeValue (attr, HTML_ATTR_Checked_VAL_No_, el, doc);
                   1002:         }
                   1003:       break;
1.6       cvs      1004:        
1.129     vatton   1005:     case HTML_EL_Option_Menu:
                   1006:       /* Check that at least one option has a SELECTED attribute */
                   1007:       OnlyOneOptionSelected (el, doc, TRUE);
                   1008:       break;
                   1009: 
                   1010:     case HTML_EL_OptGroup:
                   1011:       /* Check the mandatory label attribute */
                   1012:       CheckMandatoryAttribute (el, doc, HTML_ATTR_label);
                   1013:       break;
                   1014: 
                   1015:     case HTML_EL_MAP:
                   1016:     case HTML_EL_map:
                   1017:       /* Check the mandatory attributes */
                   1018:       if (DocumentMeta[doc] && DocumentMeta[doc]->xmlformat)
                   1019:         /* it's XHTML. Check attribute id */
                   1020:         CheckMandatoryAttribute (el, doc, HTML_ATTR_ID);
                   1021:       else
                   1022:         /* it's a HTML document. Check attribute name */
                   1023:         CheckMandatoryAttribute (el, doc, HTML_ATTR_NAME);
                   1024:       break;
                   1025: 
                   1026:     case HTML_EL_AREA:
                   1027:       /* Check the mandatory alt attribute */
                   1028:       CheckMandatoryAttribute (el, doc, HTML_ATTR_ALT);
                   1029:       break;
1.6       cvs      1030:        
1.129     vatton   1031:     case HTML_EL_LINK:
                   1032:       CheckCSSLink (el, doc, htmlSchema);
                   1033:       break;
1.6       cvs      1034:        
1.129     vatton   1035:     case HTML_EL_Data_cell:
                   1036:     case HTML_EL_Heading_cell:
                   1037:     case HTML_EL_List_Item:
                   1038:     case HTML_EL_Definition:
                   1039:       /* insert a pseudo paragraph into empty cells or list items */
                   1040:       child = TtaGetFirstChild (el);
                   1041:       if (child == NULL)
                   1042:         {
                   1043:           elType.ElTypeNum = HTML_EL_Pseudo_paragraph;
                   1044:           child = TtaNewTree (doc, elType, "");
                   1045:           if (child != NULL)
                   1046:             TtaInsertFirstChild (&child, el, doc);
                   1047:         }
                   1048:       if (elType.ElTypeNum == HTML_EL_Data_cell ||
                   1049:           elType.ElTypeNum == HTML_EL_Heading_cell)
                   1050:         /* detect whether we are parsing a whole table or just a cell */
                   1051:         {
                   1052:           if (DocumentMeta[doc]->xmlformat)
                   1053:             {
                   1054:               if (IsWithinXmlTable ())
                   1055:                 NewCell (el, doc, FALSE, FALSE, FALSE);
                   1056:             }
                   1057:           else
                   1058:             {
                   1059:               if (IsWithinHtmlTable ())
                   1060:                 NewCell (el, doc, FALSE, FALSE, FALSE);
                   1061:             }
                   1062:         }
                   1063:       break;
1.6       cvs      1064:        
1.129     vatton   1065:     case HTML_EL_Table_:
                   1066:       CheckTable (el, doc);
                   1067:       SubWithinTable ();
                   1068:       break;
1.6       cvs      1069:        
1.129     vatton   1070:     case HTML_EL_TITLE:
                   1071:       /* show the TITLE in the main window */
                   1072:       UpdateTitle (el, doc);
                   1073:       break;
                   1074: 
                   1075:     case HTML_EL_rbc:
                   1076:       /* an rbc element has been read. Its parent should be a complex_ruby.
                   1077:          Change the type of the parent, as simple_ruby are created by
                   1078:          default */
                   1079:       parent = TtaGetParent (el);
                   1080:       if (parent)
                   1081:         {
                   1082:           newElType = TtaGetElementType (parent);
                   1083:           if (newElType.ElSSchema == elType.ElSSchema &&
                   1084:               newElType.ElTypeNum == HTML_EL_simple_ruby)
                   1085:             TtaChangeElementType (parent, HTML_EL_complex_ruby);
                   1086:         }
                   1087:       break;
1.41      cvs      1088: 
1.129     vatton   1089:     case HTML_EL_rtc1:
                   1090:       /* an rtc element has been parsed. If it has already a rtc1 sibling,
                   1091:          change its type to rtc2 */
                   1092:       prev = el;
                   1093:       do
                   1094:         {
                   1095:           TtaPreviousSibling(&prev);
                   1096:           if (prev)
                   1097:             {
                   1098:               newElType = TtaGetElementType (prev);
                   1099:               if (newElType.ElSSchema == elType.ElSSchema &&
                   1100:                   newElType.ElTypeNum == HTML_EL_rtc1)
                   1101:                 {
                   1102:                   TtaChangeElementType (el, HTML_EL_rtc2);
                   1103:                   prev = NULL;
                   1104:                 }
                   1105:             }
                   1106:         }
                   1107:       while (prev);
                   1108:       break;
                   1109: 
                   1110:     case HTML_EL_FIELDSET:
1.124     cvs      1111:        
1.129     vatton   1112:       childType.ElTypeNum = 0;
                   1113:       child = TtaGetFirstChild (el);
                   1114:       if (child != NULL)
                   1115:         childType = TtaGetElementType (child);
                   1116:       if (childType.ElTypeNum != HTML_EL_LEGEND)
                   1117:         {
                   1118:           sprintf (msgBuffer, "The <fieldset> element requires <legend> as first child element");
                   1119:           lineNum = TtaGetElementLineNumber(el);
                   1120:           if (DocumentMeta[doc] && DocumentMeta[doc]->xmlformat)
                   1121:             XmlParseError (errorParsing, (unsigned char *)msgBuffer, lineNum);
                   1122:           else
                   1123:             HTMLParseError (doc, msgBuffer, lineNum);
                   1124: 
                   1125:         }
                   1126:       break;
                   1127: 
                   1128:     default:
                   1129:       break;
                   1130:     }
1.6       cvs      1131: }
1.1       cvs      1132: 
                   1133: /*----------------------------------------------------------------------
1.129     vatton   1134:   PutInContent    
                   1135:   Put the string ChrString in the leaf of current element.
1.30      cvs      1136:   ----------------------------------------------------------------------*/
1.39      cvs      1137: Element         PutInContent (char *ChrString, ParserData *context)
1.30      cvs      1138: 
                   1139: {
1.129     vatton   1140:   Element      el, child;
                   1141:   ElementType  elType;
                   1142:   int          length;
                   1143: 
                   1144:   el = NULL;
                   1145:   if (context->lastElement != NULL)
                   1146:     {
                   1147:       /* search first leaf of current element */
                   1148:       el = context->lastElement;
                   1149:       do
                   1150:         {
                   1151:           child = TtaGetFirstChild (el);
                   1152:           if (child != NULL)
                   1153:             el = child;
                   1154:         }
                   1155:       while (child != NULL);
                   1156:       elType = TtaGetElementType (el);
                   1157:       length = 0;
                   1158:       if (elType.ElTypeNum == 1)
                   1159:         length = TtaGetTextLength (el);
                   1160:       if (length == 0)
                   1161:         TtaSetTextContent (el, (unsigned char *)ChrString,
                   1162:                            context->language, context->doc);
                   1163:       else
                   1164:         TtaAppendTextContent (el, (unsigned char *)ChrString, context->doc);
                   1165:     }
                   1166:   return el;
1.30      cvs      1167: }
                   1168: 
                   1169: /*----------------------------------------------------------------------
1.93      vatton   1170:   UnknownXhtmlNameSpace
                   1171:   The element doesn't belong to a supported namespace
1.51      cvs      1172:   ----------------------------------------------------------------------*/
1.93      vatton   1173: void UnknownXhtmlNameSpace (ParserData *context, Element *unknownEl,
1.129     vatton   1174:                             char* content)
1.51      cvs      1175: {
1.129     vatton   1176:   ElementType     elType;
                   1177:   Element         elText;
1.51      cvs      1178: 
1.129     vatton   1179:   /* Create a new Invalid_element */
                   1180:   elType.ElSSchema = GetXMLSSchema (XHTML_TYPE, context->doc);
                   1181:   elType.ElTypeNum = HTML_EL_XHTML_Unknown_namespace;
                   1182:   *unknownEl = TtaNewElement (context->doc, elType);
                   1183:   if (*unknownEl != NULL)
                   1184:     {
                   1185:       XmlSetElemLineNumber (*unknownEl);
                   1186:       InsertXmlElement (unknownEl);
                   1187:       context->lastElementClosed = TRUE;
                   1188:       elType.ElTypeNum = HTML_EL_TEXT_UNIT;
                   1189:       elText = TtaNewElement (context->doc, elType);
                   1190:       XmlSetElemLineNumber (elText);
                   1191:       TtaInsertFirstChild (&elText, *unknownEl, context->doc);
                   1192:       TtaSetTextContent (elText, (unsigned char *)content, context->language, context->doc);
                   1193:       TtaSetAccessRight (elText, ReadOnly, context->doc);
                   1194:     }
1.51      cvs      1195: }
                   1196: 
                   1197: /*----------------------------------------------------------------------
1.129     vatton   1198:   CreateHTMLAttribute
                   1199:   create an attribute of type attrType for the element el.
1.30      cvs      1200:   ----------------------------------------------------------------------*/
1.93      vatton   1201: void CreateHTMLAttribute (Element       el,
1.129     vatton   1202:                           AttributeType attrType,
                   1203:                           char*         text,
                   1204:                           ThotBool      isInvalid,
                   1205:                           Document      doc,
                   1206:                           Attribute    *lastAttribute,
                   1207:                           Element      *lastAttrElement)
1.30      cvs      1208: {
1.129     vatton   1209:   int         attrKind;
                   1210:   int         length;
                   1211:   char       *buffer;
                   1212:   Attribute   attr, oldAttr;
                   1213: 
                   1214:   if (attrType.AttrTypeNum != 0)
                   1215:     {
                   1216:       oldAttr = TtaGetAttribute (el, attrType);
                   1217:       if (oldAttr != NULL)
                   1218:         /* this attribute already exists */
                   1219:         attr = oldAttr;
                   1220:       else
                   1221:         /* create a new attribute and attach it to the element */
                   1222:         {
                   1223:           attr = TtaNewAttribute (attrType);
                   1224:           TtaAttachAttribute (el, attr, doc);
                   1225:         }
                   1226:       *lastAttribute = attr;
                   1227:       *lastAttrElement = el;
                   1228: 
                   1229:       TtaGiveAttributeType (attr, &attrType, &attrKind);
                   1230:       if (attrKind == 0)       /* enumerate */
                   1231:         TtaSetAttributeValue (attr, 1, el, doc);
                   1232: 
                   1233:       /* attribute BORDER without any value (ThotBool attribute) is */
                   1234:       /* considered as BORDER=1 */
                   1235:       if (attrType.AttrTypeNum == HTML_ATTR_Border)
                   1236:         TtaSetAttributeValue (attr, 1, el, doc);
                   1237: 
                   1238:       if (isInvalid)
                   1239:         /* Copy the name of the invalid attribute as the content */
                   1240:         /* of the Invalid_attribute attribute. */
                   1241:         {
                   1242:           length = strlen (text) + 2;
                   1243:           length += TtaGetTextAttributeLength (attr);
                   1244:           buffer = (char *)TtaGetMemory (length + 1);
                   1245:           TtaGiveTextAttributeValue (attr, buffer, &length);
                   1246:           strcat (buffer, " ");
                   1247:           strcat (buffer, text);
                   1248:           TtaSetAttributeText (attr, buffer, el, doc);
                   1249:           TtaFreeMemory (buffer);
                   1250:         }
                   1251:     }
1.30      cvs      1252: }
                   1253: 
                   1254: 
                   1255: /*----------------------------------------------------------------------
1.129     vatton   1256:   XhtmlTypeAttrValue 
                   1257:   Value val has been read for the HTML attribute TYPE.
                   1258:   Create a child for the current Thot element INPUT accordingly.
1.30      cvs      1259:   ----------------------------------------------------------------------*/
1.135     vatton   1260: static void XhtmlTypeAttrValue (char *val,
                   1261:                                 Attribute currentAttribute,
                   1262:                                 Element lastAttrElement,
                   1263:                                 ParserData *context, ThotBool isXML)
1.30      cvs      1264: {
                   1265:   ElementType     elType;
                   1266:   Element         newChild;
                   1267:   AttributeType   attrType;
                   1268:   Attribute       attr;
1.39      cvs      1269:   char            msgBuffer[MaxMsgLength];
1.135     vatton   1270:   int             value, nb;
1.30      cvs      1271:   ThotBool        level;
                   1272: 
1.91      quint    1273:   /* Look in the dummy section of the attribute value table */
1.30      cvs      1274:   attrType.AttrTypeNum = DummyAttribute;
1.100     gully    1275:   MapHTMLAttributeValue (val, &attrType, &value);
1.135     vatton   1276:   elType = TtaGetElementType (context->lastElement);
1.91      quint    1277:   if (value <= 0)
                   1278:     /* invalid value for the type attribute of an input element */
1.30      cvs      1279:     {
1.37      cvs      1280:       sprintf (msgBuffer, "Unknown attribute value \"type=%s\"", val);
1.135     vatton   1281:       if (isXML)
                   1282:         XmlParseError (errorParsing, (unsigned char *)msgBuffer, 0);
                   1283:       else
                   1284:         HTMLParseError (context->doc, msgBuffer, 0);
1.36      cvs      1285:       MapHTMLAttribute ("unknown_attr", &attrType, NULL,
1.129     vatton   1286:                         &level, context->doc);
1.37      cvs      1287:       sprintf (msgBuffer, "type=%s", val);
1.30      cvs      1288:       CreateHTMLAttribute (context->lastElement, attrType, msgBuffer, TRUE,
1.129     vatton   1289:                            context->doc, &currentAttribute, &lastAttrElement);
1.30      cvs      1290:     }
                   1291:   else
1.91      quint    1292:     /* value is the Thot type of the element to be created for this value of
                   1293:        the TYPE attribute */
1.30      cvs      1294:     {
                   1295:       if (elType.ElTypeNum != HTML_EL_Input)
1.129     vatton   1296:         {
                   1297:           sprintf (msgBuffer, "Duplicate attribute \"type = %s\"", val);
1.135     vatton   1298:           if (isXML)
                   1299:             XmlParseError (errorParsing, (unsigned char *)msgBuffer, 0);
                   1300:           else
                   1301:             HTMLParseError (context->doc, msgBuffer, 0);
1.129     vatton   1302:         }
1.30      cvs      1303:       else
1.129     vatton   1304:         {
                   1305:           elType.ElTypeNum = value;
                   1306:           newChild = TtaNewTree (context->doc, elType, "");
1.135     vatton   1307:           
                   1308:           nb = TtaGetElementLineNumber (context->lastElement);
                   1309:           TtaSetElementLineNumber (newChild, nb);
1.129     vatton   1310:           TtaInsertFirstChild (&newChild, context->lastElement, context->doc);
1.135     vatton   1311:           /* add the attribute type */
                   1312:           attrType.AttrSSchema = elType.ElSSchema;
                   1313:           attrType.AttrTypeNum = HTML_ATTR_type;
                   1314:           attr = TtaGetAttribute (newChild, attrType);
                   1315:           if (attr == NULL)
1.129     vatton   1316:             {
                   1317:               attr = TtaNewAttribute (attrType);
                   1318:               TtaAttachAttribute (newChild, attr, context->doc);
                   1319:             }
                   1320:         }
1.30      cvs      1321:     }
                   1322: }
                   1323: 
                   1324: /*----------------------------------------------------------------------
1.129     vatton   1325:   CreateAttrWidthPercentPxl
                   1326:   an HTML attribute "width" has been created for a Table, an image,
                   1327:   an Object of a HR.
                   1328:   Create the corresponding attribute IntWidthPercent or IntWidthPxl.
                   1329:   oldWidth is -1 or the old image width.
1.30      cvs      1330:   ----------------------------------------------------------------------*/
1.58      vatton   1331: void CreateAttrWidthPercentPxl (char *buffer, Element el,
1.129     vatton   1332:                                 Document doc, int oldWidth)
1.30      cvs      1333: {
                   1334:   AttributeType   attrTypePxl, attrTypePercent;
                   1335:   Attribute       attrOld, attrNew;
                   1336:   int             length, val;
1.39      cvs      1337:   char            msgBuffer[MaxMsgLength];
1.133     vatton   1338:   ElementType      elType, childType;
1.79      quint    1339:   Element         origEl, child;
1.30      cvs      1340:   int             w, h;
1.133     vatton   1341:   ThotBool        isImage, isSVG = FALSE;
1.30      cvs      1342: 
1.132     vatton   1343:   if (buffer == NULL || buffer[0] == EOS)
                   1344:     return;
1.79      quint    1345:   origEl = el;
1.30      cvs      1346:   elType = TtaGetElementType (el);
                   1347:   isImage = (elType.ElTypeNum == HTML_EL_PICTURE_UNIT ||
1.129     vatton   1348:              elType.ElTypeNum == HTML_EL_Data_cell ||
                   1349:              elType.ElTypeNum == HTML_EL_Heading_cell ||
1.134     vatton   1350:              elType.ElTypeNum == HTML_EL_Object ||
1.135     vatton   1351:              elType.ElTypeNum == HTML_EL_IMG ||
                   1352:              elType.ElTypeNum == HTML_EL_Image_Input);
1.133     vatton   1353: 
1.79      quint    1354:   if (elType.ElTypeNum == HTML_EL_Object)
                   1355:     /* the width attribute is attached to an Object element */
                   1356:     {
                   1357:       child = TtaGetFirstChild (el);
                   1358:       if (child)
1.129     vatton   1359:         {
                   1360:           childType = TtaGetElementType (child);
                   1361:           if (childType.ElTypeNum == HTML_EL_PICTURE_UNIT)
                   1362:             /* the Object element is of type image. apply the width
                   1363:                attribute to the actual image element */
                   1364:             el = child;
1.133     vatton   1365: #ifdef _SVG
                   1366:           else
                   1367:             {
                   1368:               el = child;
                   1369:               child = TtaGetFirstChild (el);
                   1370:               if (child)
                   1371:                 {
                   1372:                   childType = TtaGetElementType (child);
                   1373:                   isSVG = (!strcmp (TtaGetSSchemaName (childType.ElSSchema), "SVG") &&
                   1374:                       childType.ElTypeNum == SVG_EL_SVG);
                   1375:                 }
                   1376:             }
                   1377: #endif /* _SVG */
1.129     vatton   1378:         }
1.79      quint    1379:     }
1.133     vatton   1380: 
1.30      cvs      1381:   /* remove trailing spaces */
1.37      cvs      1382:   length = strlen (buffer) - 1;
1.30      cvs      1383:   while (length > 0 && buffer[length] <= SPACE)
                   1384:     length--;
1.109     vatton   1385:   attrTypePxl.AttrSSchema = elType.ElSSchema;
                   1386:   attrTypePercent.AttrSSchema = elType.ElSSchema;
1.30      cvs      1387:   attrTypePxl.AttrTypeNum = HTML_ATTR_IntWidthPxl;
                   1388:   attrTypePercent.AttrTypeNum = HTML_ATTR_IntWidthPercent;
                   1389:   /* is the last character a '%' ? */
                   1390:   if (buffer[length] == '%')
                   1391:     {
                   1392:       /* remove IntWidthPxl */
                   1393:       attrOld = TtaGetAttribute (el, attrTypePxl);
                   1394:       /* update IntWidthPercent */
                   1395:       attrNew = TtaGetAttribute (el, attrTypePercent);
                   1396:       if (attrNew == NULL)
1.129     vatton   1397:         {
                   1398:           attrNew = TtaNewAttribute (attrTypePercent);
                   1399:           TtaAttachAttribute (el, attrNew, doc);
                   1400:         }
1.30      cvs      1401:       else if (isImage && oldWidth == -1)
1.129     vatton   1402:         {
                   1403:           if (attrOld == NULL)
                   1404:             oldWidth = TtaGetAttributeValue (attrNew);
                   1405:           else
                   1406:             oldWidth = TtaGetAttributeValue (attrOld);
                   1407:         }
1.30      cvs      1408:     }
                   1409:   else
                   1410:     {
                   1411:       /* remove IntWidthPercent */
                   1412:       attrOld = TtaGetAttribute (el, attrTypePercent);
                   1413:       /* update IntWidthPxl */
                   1414:       attrNew = TtaGetAttribute (el, attrTypePxl);
                   1415:       if (attrNew == NULL)
1.129     vatton   1416:         {
                   1417:           attrNew = TtaNewAttribute (attrTypePxl);
                   1418:           TtaAttachAttribute (el, attrNew, doc);
                   1419:         }
1.30      cvs      1420:       else if (isImage && oldWidth == -1)
1.129     vatton   1421:         {
                   1422:           TtaGiveBoxSize (el, doc, 1, UnPixel, &w, &h);
                   1423:           if (attrOld == NULL)
                   1424:             oldWidth = w * TtaGetAttributeValue (attrNew) / 100;
                   1425:           else
                   1426:             oldWidth = w * TtaGetAttributeValue (attrOld) / 100;         
                   1427:         }
1.30      cvs      1428:     }
                   1429: 
                   1430:   if (attrOld != NULL)
                   1431:     TtaRemoveAttribute (el, attrOld, doc);
1.43      cvs      1432:   if (sscanf (buffer, "%d", &val))
1.30      cvs      1433:     TtaSetAttributeValue (attrNew, val, el, doc);
                   1434:   else
                   1435:     /* its not a number. Delete attribute and send an error message */
                   1436:     {
1.129     vatton   1437:       TtaRemoveAttribute (el, attrNew, doc);
                   1438:       if (strlen (buffer) > MaxMsgLength - 30)
1.30      cvs      1439:         buffer[MaxMsgLength - 30] = EOS;
1.129     vatton   1440:       sprintf (msgBuffer, "Invalid attribute value \"%s\"", buffer);
                   1441:       HTMLParseError (doc, msgBuffer, 0);
1.30      cvs      1442:     }
                   1443:   if (isImage)
1.79      quint    1444:     UpdateImageMap (origEl, doc, oldWidth, -1);
1.133     vatton   1445:   else if (isSVG && oldWidth != -1)
                   1446:     {
                   1447:       // force the redisplay of the SVG element
                   1448:       el = TtaGetParent (child);
                   1449:       if (el)
                   1450:         {
                   1451:           TtaRemoveTree (child, doc);
                   1452:           TtaInsertFirstChild (&child, el, doc);
                   1453:         }
                   1454:     }
1.30      cvs      1455: }
                   1456: 
                   1457: /*----------------------------------------------------------------------
1.129     vatton   1458:   CreateAttrHeightPercentPxl
                   1459:   an HTML attribute "width" has been created for a Table, an image,
                   1460:   an Object or a HR.
                   1461:   Create the corresponding attribute IntHeightPercent or IntHeightPxl.
                   1462:   oldHeight is -1 or the old image width.
1.58      vatton   1463:   ----------------------------------------------------------------------*/
                   1464: void CreateAttrHeightPercentPxl (char *buffer, Element el,
1.129     vatton   1465:                                  Document doc, int oldHeight)
1.58      vatton   1466: {
                   1467:   AttributeType   attrTypePxl, attrTypePercent;
                   1468:   Attribute       attrOld, attrNew;
                   1469:   int             length, val;
                   1470:   char            msgBuffer[MaxMsgLength];
1.133     vatton   1471:   ElementType      elType, childType;
1.79      quint    1472:   Element         origEl, child;
1.58      vatton   1473:   int             w, h;
1.133     vatton   1474:   ThotBool        isImage, isSVG = FALSE;
1.58      vatton   1475: 
1.79      quint    1476:   origEl = el;
1.58      vatton   1477:   elType = TtaGetElementType (el);
                   1478:   isImage = (elType.ElTypeNum == HTML_EL_PICTURE_UNIT ||
1.129     vatton   1479:              elType.ElTypeNum == HTML_EL_Data_cell ||
                   1480:              elType.ElTypeNum == HTML_EL_Heading_cell ||
1.134     vatton   1481:              elType.ElTypeNum == HTML_EL_Object ||
                   1482:              elType.ElTypeNum == HTML_EL_IMG);
1.133     vatton   1483: 
1.79      quint    1484:   if (elType.ElTypeNum == HTML_EL_Object)
                   1485:     /* the height attribute is attached to an Object element */
                   1486:     {
                   1487:       child = TtaGetFirstChild (el);
1.81      cvs      1488:       if (!child)
1.129     vatton   1489:         return;
1.81      cvs      1490:       else
1.129     vatton   1491:         {
                   1492:           childType = TtaGetElementType (child);
                   1493:           if (childType.ElTypeNum == HTML_EL_PICTURE_UNIT)
                   1494:             /* the Object element is of type image. apply the width
                   1495:                attribute to the actual image element */
                   1496:             el = child;
1.133     vatton   1497: #ifdef _SVG
1.129     vatton   1498:           else
1.133     vatton   1499:             {
                   1500:               el = child;
                   1501:               child = TtaGetFirstChild (el);
                   1502:               if (child)
                   1503:                 {
                   1504:                   childType = TtaGetElementType (child);
                   1505:                   isSVG = (!strcmp (TtaGetSSchemaName (childType.ElSSchema), "SVG") &&
                   1506:                       childType.ElTypeNum == SVG_EL_SVG);
                   1507:                 }
                   1508:             }
                   1509: #endif /* _SVG */
1.129     vatton   1510:         }
1.79      quint    1511:     }
1.133     vatton   1512: 
1.58      vatton   1513:   /* remove trailing spaces */
                   1514:   length = strlen (buffer) - 1;
                   1515:   while (length > 0 && buffer[length] <= SPACE)
                   1516:     length--;
1.109     vatton   1517:   attrTypePxl.AttrSSchema = elType.ElSSchema;
                   1518:   attrTypePercent.AttrSSchema = elType.ElSSchema;
1.58      vatton   1519:   attrTypePxl.AttrTypeNum = HTML_ATTR_IntHeightPxl;
                   1520:   attrTypePercent.AttrTypeNum = HTML_ATTR_IntHeightPercent;
                   1521:   /* is the last character a '%' ? */
                   1522:   if (buffer[length] == '%')
                   1523:     {
                   1524:       /* remove IntHeightPxl */
                   1525:       attrOld = TtaGetAttribute (el, attrTypePxl);
                   1526:       /* update IntHeightPercent */
                   1527:       attrNew = TtaGetAttribute (el, attrTypePercent);
                   1528:       if (attrNew == NULL)
1.129     vatton   1529:         {
                   1530:           attrNew = TtaNewAttribute (attrTypePercent);
                   1531:           TtaAttachAttribute (el, attrNew, doc);
                   1532:         }
1.58      vatton   1533:       else if (isImage && oldHeight == -1)
1.129     vatton   1534:         {
                   1535:           if (attrOld == NULL)
                   1536:             oldHeight = TtaGetAttributeValue (attrNew);
                   1537:           else
                   1538:             oldHeight = TtaGetAttributeValue (attrOld);
                   1539:         }
1.58      vatton   1540:     }
                   1541:   else
                   1542:     {
                   1543:       /* remove IntHeightPercent */
                   1544:       attrOld = TtaGetAttribute (el, attrTypePercent);
                   1545:       /* update IntHeightPxl */
                   1546:       attrNew = TtaGetAttribute (el, attrTypePxl);
                   1547:       if (attrNew == NULL)
1.129     vatton   1548:         {
                   1549:           attrNew = TtaNewAttribute (attrTypePxl);
                   1550:           TtaAttachAttribute (el, attrNew, doc);
                   1551:         }
1.58      vatton   1552:       else if (isImage && oldHeight == -1)
1.129     vatton   1553:         {
                   1554:           TtaGiveBoxSize (el, doc, 1, UnPixel, &w, &h);
                   1555:           if (attrOld == NULL)
                   1556:             oldHeight = w * TtaGetAttributeValue (attrNew) / 100;
                   1557:           else
                   1558:             oldHeight = w * TtaGetAttributeValue (attrOld) / 100;        
                   1559:         }
1.58      vatton   1560:     }
                   1561: 
                   1562:   if (attrOld != NULL)
                   1563:     TtaRemoveAttribute (el, attrOld, doc);
                   1564:   if (sscanf (buffer, "%d", &val))
                   1565:     TtaSetAttributeValue (attrNew, val, el, doc);
                   1566:   else
                   1567:     /* its not a number. Delete attribute and send an error message */
                   1568:     {
1.129     vatton   1569:       TtaRemoveAttribute (el, attrNew, doc);
                   1570:       if (strlen (buffer) > MaxMsgLength - 30)
1.58      vatton   1571:         buffer[MaxMsgLength - 30] = EOS;
1.129     vatton   1572:       sprintf (msgBuffer, "Invalid attribute value \"%s\"", buffer);
                   1573:       HTMLParseError (doc, msgBuffer, 0);
1.58      vatton   1574:     }
                   1575:   if (isImage)
1.79      quint    1576:     UpdateImageMap (origEl, doc, oldHeight, -1);
1.133     vatton   1577:   else if (isSVG && oldHeight != -1)
                   1578:     {
                   1579:       // force the redisplay of the SVG element
                   1580:       el = TtaGetParent (child);
                   1581:       if (el)
                   1582:         {
                   1583:           TtaRemoveTree (child, doc);
                   1584:           TtaInsertFirstChild (&child, el, doc);
                   1585:         }
                   1586:     }
1.58      vatton   1587: }
                   1588: 
                   1589: /*----------------------------------------------------------------------
1.129     vatton   1590:   CreateAttrIntAreaSize
                   1591:   an HTML attribute "size" has been created or modified for a input element.
                   1592:   Create or update the corresponding attribute IntAreaSize.
1.91      quint    1593:   ----------------------------------------------------------------------*/
                   1594: void CreateAttrIntAreaSize (int value, Element el, Document doc)
                   1595: {
                   1596:   AttributeType   attrType;
                   1597:   Attribute       attr;
                   1598:   ElementType    elType;
                   1599: 
                   1600:   elType = TtaGetElementType (el);
                   1601:   attrType.AttrSSchema = elType.ElSSchema;
1.135     vatton   1602:   if (elType.ElTypeNum == HTML_EL_Image_Input)
                   1603:     {
                   1604:       attrType.AttrTypeNum = HTML_ATTR_IntWidthPxl;
                   1605:       attr = TtaGetAttribute (el, attrType);
                   1606:       if (!attr)
                   1607:         {
                   1608:           attr = TtaNewAttribute (attrType);
                   1609:           TtaAttachAttribute (el, attr, doc);
                   1610:         }
                   1611:       /* the presentation rule associated with attribute IntWidthPxl */
                   1612:       TtaSetAttributeValue (attr, value, el, doc);
                   1613:     }
                   1614:   else
1.91      quint    1615:     {
1.135     vatton   1616:       attrType.AttrTypeNum = HTML_ATTR_IntAreaSize;
                   1617:       attr = TtaGetAttribute (el, attrType);
                   1618:       if (!attr)
                   1619:         {
                   1620:           attr = TtaNewAttribute (attrType);
                   1621:           TtaAttachAttribute (el, attr, doc);
                   1622:         }
                   1623:       /* the presentation rule associated with attribute IntAreaSize expresses
                   1624:          the element width in "em". Convert the value into em */
                   1625:       TtaSetAttributeValue (attr, (int) (value * 0.40), el, doc);
1.91      quint    1626:     }
                   1627: }
                   1628: 
                   1629: /*----------------------------------------------------------------------
1.129     vatton   1630:   CreateAttrIntSize
                   1631:   an HTML attribute "size" has been created for a Font element.
                   1632:   Create the corresponding internal attribute.
1.30      cvs      1633:   ----------------------------------------------------------------------*/
1.109     vatton   1634: void CreateAttrIntSize (char *buffer, Element el, Document doc)
1.30      cvs      1635: 
                   1636: {
1.129     vatton   1637:   ElementType    elType;
                   1638:   AttributeType  attrType;
                   1639:   int            val, ind, factor, delta;
                   1640:   Attribute      attr;
                   1641:   char         msgBuffer[MaxMsgLength];
                   1642: 
                   1643:   /* is the first character a '+' or a '-' ? */
                   1644:   elType = TtaGetElementType (el);
                   1645:   ind = 0;
                   1646:   factor = 1;
                   1647:   delta = 0;
                   1648:   if (buffer[0] == '+')
                   1649:     {
                   1650:       attrType.AttrTypeNum = HTML_ATTR_IntSizeIncr;
                   1651:       ind++;
                   1652:       factor = 1;
                   1653:     }
                   1654:   else if (buffer[0] == '-')
                   1655:     {
                   1656:       attrType.AttrTypeNum = HTML_ATTR_IntSizeDecr;
                   1657:       ind++;
                   1658:       factor = 1;
                   1659:     }
                   1660:   else
                   1661:     {
                   1662:       attrType.AttrTypeNum = HTML_ATTR_IntSizeRel;
                   1663:       delta = 1;
                   1664:     }
                   1665:   attrType.AttrSSchema = elType.ElSSchema;
                   1666:   attr = TtaGetAttribute (el, attrType);
                   1667:   if (sscanf (&buffer[ind], "%d", &val))
                   1668:     {
                   1669:       val = val * factor + delta;
                   1670:       if (attr == NULL)
                   1671:         {
                   1672:           /* this attribute doesn't exist, create it */
                   1673:           attr = TtaNewAttribute (attrType);
                   1674:           TtaAttachAttribute (el, attr, doc);
                   1675:         }
                   1676:       TtaSetAttributeValue (attr, val, el, doc);
                   1677:     }
                   1678:   else
                   1679:     /* its not a number. Delete attribute and send an error message */
                   1680:     {
                   1681:       if (attr)
                   1682:         TtaRemoveAttribute (el, attr, doc);
                   1683:       if (strlen (buffer) > MaxMsgLength - 30)
                   1684:         buffer[MaxMsgLength - 30] = EOS;
                   1685:       sprintf (msgBuffer, "Invalid attribute value \"%s\"", buffer);
                   1686:       HTMLParseError (doc, msgBuffer, 0);
                   1687:     }
1.30      cvs      1688: }
                   1689: /*----------------------------------------------------------------------
1.129     vatton   1690:   EndOfHTMLAttributeValue
                   1691:   Filling of an HTML attribute value
1.30      cvs      1692:   ----------------------------------------------------------------------*/
1.109     vatton   1693: void EndOfHTMLAttributeValue (char *attrValue, AttributeMapping *lastMappedAttr,
1.129     vatton   1694:                               Attribute currentAttribute, Element lastAttrElement,
                   1695:                               ThotBool UnknownAttr, ParserData *context,
                   1696:                               ThotBool isXML)
1.30      cvs      1697: {
1.48      vatton   1698:   AttributeType   attrType, attrType1;
                   1699:   Attribute       attr;
1.79      quint    1700:   ElementType    elType;
1.48      vatton   1701:   Element         child, root;
                   1702:   Language        lang;
                   1703:   char            translation;
                   1704:   char            shape;
                   1705:   char           *buffer;
                   1706:   char           *attrName;
                   1707:   char            msgBuffer[MaxMsgLength];
                   1708:   int             val;
                   1709:   int             length;
                   1710:   int             attrKind;
                   1711:   ThotBool        done = FALSE;
1.88      vatton   1712:   ThotBool            loadcss;
1.30      cvs      1713: 
1.48      vatton   1714:   /* treatments of some particular HTML attributes */
                   1715:   if (!strcmp (lastMappedAttr->XMLattribute, "style"))
                   1716:     {
                   1717:       TtaSetAttributeText (currentAttribute, attrValue,
1.129     vatton   1718:                            lastAttrElement, context->doc);
1.88      vatton   1719:       /* check if we have to load CSS */
                   1720:       TtaGetEnvBoolean ("LOAD_CSS", &loadcss);
                   1721:       if (loadcss)
1.129     vatton   1722:         ParseHTMLSpecificStyle (context->lastElement, attrValue,
                   1723:                                 context->doc, 200, FALSE);
1.48      vatton   1724:       done = TRUE;
                   1725:     }
                   1726:   else
                   1727:     {
                   1728:       if (!strcmp (lastMappedAttr->XMLattribute, "link"))
1.129     vatton   1729:         HTMLSetAlinkColor (context->doc, context->lastElement, attrValue);
1.48      vatton   1730:       else if (!strcmp (lastMappedAttr->XMLattribute, "alink"))
1.129     vatton   1731:         HTMLSetAactiveColor (context->doc, context->lastElement, attrValue);
1.48      vatton   1732:       else if (!strcmp (lastMappedAttr->XMLattribute, "vlink"))
1.129     vatton   1733:         HTMLSetAvisitedColor (context->doc, context->lastElement, attrValue);
1.48      vatton   1734:     }
1.30      cvs      1735: 
1.48      vatton   1736:   if (!done)
                   1737:     {
1.109     vatton   1738:       elType = TtaGetElementType (lastAttrElement);
1.48      vatton   1739:       val = 0;
                   1740:       translation = lastMappedAttr->AttrOrContent;
                   1741:       switch (translation)
1.129     vatton   1742:         {
                   1743:         case 'C':      /* Content */
                   1744:           child = PutInContent (attrValue, context);
                   1745:           if (child != NULL)
                   1746:             TtaAppendTextContent (child, (unsigned char *)"\" ", context->doc);
                   1747:           break;
                   1748:         case 'A':
                   1749:           if (currentAttribute != NULL)
                   1750:             {
                   1751:               TtaGiveAttributeType (currentAttribute, &attrType, &attrKind);
                   1752:               switch (attrKind)
                   1753:                 {
                   1754:                 case 0:        /* enumerate */
                   1755:                   if (isXML)
                   1756:                     MapHTMLAttributeValue (attrValue, &attrType, &val);
                   1757:                   else
                   1758:                     val = MapAttrValue (lastMappedAttr->ThotAttribute,
                   1759:                                         attrValue);
                   1760:                   if (val < 0)
                   1761:                     {
                   1762:                       TtaGiveAttributeType (currentAttribute,
                   1763:                                             &attrType, &attrKind);
                   1764:                       attrName = TtaGetAttributeName (attrType);
                   1765:                       sprintf (msgBuffer,
                   1766:                                "Invalid attribute value \"%s = %s\"",
                   1767:                                attrName, attrValue);
                   1768:                       if (isXML)
                   1769:                         XmlParseError (errorParsing, (unsigned char *)msgBuffer, 0);
                   1770:                       else
                   1771:                         /* we are parsing an HTML file, not an XHTML file */
                   1772:                         {
                   1773:                           /* generate an error message in the log */
                   1774:                           HTMLParseError (context->doc, msgBuffer, 0);
                   1775:                           /* special case for value POLYGON of attribute 
                   1776:                              shape (AREA element) */
                   1777:                           if (attrType.AttrTypeNum == HTML_ATTR_shape &&
                   1778:                               strcasecmp (attrValue, "POLYGON") == 0)
                   1779:                             {
                   1780:                               val = HTML_ATTR_shape_VAL_polygon;
                   1781:                               /* interpret it as if it were "poly" */
                   1782:                               TtaSetAttributeValue (currentAttribute, val,
                   1783:                                                     lastAttrElement, context->doc);
                   1784:                             }
                   1785:                           else
                   1786:                             /* remove the attribute and replace it by an */
                   1787:                             /* Invalid_attribute (not for XHTML) */
                   1788:                             {
                   1789:                               TtaRemoveAttribute (lastAttrElement,
                   1790:                                                   currentAttribute, context->doc);
                   1791:                               attrType.AttrSSchema = elType.ElSSchema;
                   1792:                               attrType.AttrTypeNum =
                   1793:                                 pHTMLAttributeMapping[0].ThotAttribute;
                   1794:                               sprintf (msgBuffer, "%s=%s", attrName,attrValue);
                   1795:                               CreateHTMLAttribute (lastAttrElement, attrType,
                   1796:                                                    msgBuffer, TRUE, context->doc,
                   1797:                                                    &currentAttribute, &lastAttrElement);
                   1798:                             }
                   1799:                         }
                   1800:                     }
                   1801:                   else
                   1802:                     TtaSetAttributeValue (currentAttribute, val,
                   1803:                                           lastAttrElement, context->doc);
                   1804:                   break;
                   1805:                 case 1:        /* integer */
                   1806:                   if (attrType.AttrTypeNum == HTML_ATTR_Border &&
                   1807:                       !strcasecmp (attrValue, "border"))
                   1808:                     {
                   1809:                       /* border="border" for a table */
                   1810:                       val = 1;
                   1811:                       TtaSetAttributeValue (currentAttribute, val,
                   1812:                                             lastAttrElement, context->doc);
                   1813:                     }
                   1814:                   else if (sscanf (attrValue, "%d", &val))
                   1815:                     TtaSetAttributeValue (currentAttribute, val,
                   1816:                                           lastAttrElement, context->doc);
                   1817:                   else
                   1818:                     {
                   1819:                       TtaRemoveAttribute (lastAttrElement, currentAttribute,
                   1820:                                           context->doc);
                   1821:                       sprintf (msgBuffer,
                   1822:                                "Unknown attribute value \"%s\"",
                   1823:                                attrValue);
                   1824:                       if (isXML)
                   1825:                         XmlParseError (errorParsing, (unsigned char *)msgBuffer, 0);
                   1826:                       else
                   1827:                         HTMLParseError (context->doc, msgBuffer, 0);
                   1828:                     }
                   1829:                   break;
                   1830:                 case 2:        /* text */
                   1831:                   if (!UnknownAttr)
                   1832:                     {
                   1833:                       TtaSetAttributeText (currentAttribute, attrValue,
                   1834:                                            lastAttrElement, context->doc);
                   1835:                       if (attrType.AttrTypeNum == HTML_ATTR_Language)
                   1836:                         {
                   1837:                           /* it's a LANG attribute value */
                   1838:                           lang = TtaGetLanguageIdFromName (attrValue);
                   1839:                           if (lang < 0)
                   1840:                             {
                   1841:                               sprintf (msgBuffer,
                   1842:                                        "warning - unsupported language: %s",
                   1843:                                        attrValue);
                   1844:                               if (isXML)
                   1845:                                 XmlParseError (warningMessage, (unsigned char *)msgBuffer, 0);
                   1846:                               else
                   1847:                                 HTMLParseError (context->doc, msgBuffer, 0);
                   1848:                             }
                   1849:                           else
                   1850:                             {
                   1851:                               /* change current language */
                   1852:                               context->language = lang;
                   1853:                               if (isXML)
                   1854:                                 SetLanguagInXmlStack (lang);
                   1855:                               else
                   1856:                                 SetLanguagInHTMLStack (lang);
                   1857:                             }
                   1858:                           root = TtaGetRootElement (context->doc);
                   1859:                           if (lastAttrElement == root)
                   1860:                             /* it's a LANG attribute on the root element */
                   1861:                             /* set the RealLang attribute */
                   1862:                             {
                   1863:                               attrType1.AttrSSchema = elType.ElSSchema;
                   1864:                               attrType1.AttrTypeNum = HTML_ATTR_RealLang;
                   1865:                               /* this attribute could be already present,
                   1866:                                  (lang and xml:lang attributes) */
                   1867:                               if (!TtaGetAttribute (lastAttrElement,
                   1868:                                                     attrType1))
                   1869:                                 /* it's not present. Add it */
                   1870:                                 {
                   1871:                                   attr = TtaNewAttribute (attrType1);
                   1872:                                   TtaAttachAttribute (lastAttrElement,
                   1873:                                                       attr, context->doc);
                   1874:                                   TtaSetAttributeValue (attr,
                   1875:                                                         HTML_ATTR_RealLang_VAL_Yes_,
                   1876:                                                         lastAttrElement,
                   1877:                                                         context->doc);
                   1878:                                 }
                   1879:                             }
                   1880:                         }
                   1881:                       else if (attrType.AttrTypeNum == HTML_ATTR_ID ||
                   1882:                                attrType.AttrTypeNum == HTML_ATTR_NAME)
                   1883:                         CheckUniqueName (lastAttrElement, context->doc,
                   1884:                                          currentAttribute, attrType);
                   1885:                       else if (attrType.AttrTypeNum == HTML_ATTR_accesskey)
                   1886:                         TtaAddAccessKey (context->doc, (unsigned int)attrValue[0],
                   1887:                                          lastAttrElement);
                   1888:                     }
                   1889:                   else
                   1890:                     {
                   1891:                       /* this is the content of an invalid attribute */
                   1892:                       /* append it to the current Invalid_attribute */
                   1893:                       if (!isXML)
                   1894:                         {
                   1895:                           length = strlen (attrValue) + 2;
                   1896:                           length += TtaGetTextAttributeLength (currentAttribute);
                   1897:                           buffer = (char *)TtaGetMemory (length + 1);
                   1898:                           TtaGiveTextAttributeValue (currentAttribute,
                   1899:                                                      buffer, &length);
                   1900:                           strcat (buffer, "=");
                   1901:                           strcat (buffer, attrValue);
                   1902:                           TtaSetAttributeText (currentAttribute, buffer,
                   1903:                                                lastAttrElement, context->doc);
                   1904:                           TtaFreeMemory (buffer);
                   1905:                         }
                   1906:                     }
                   1907:                   break;
                   1908:                 case 3:        /* reference */
                   1909:                   break;
                   1910:                 }
                   1911:             }
                   1912:           break;
                   1913:         case SPACE:
1.135     vatton   1914:           XhtmlTypeAttrValue (attrValue, currentAttribute,
                   1915:                               lastAttrElement, context,isXML );
1.129     vatton   1916:           break;  
                   1917:         default:
                   1918:           break;
                   1919:         }
1.30      cvs      1920: 
                   1921:       if (lastMappedAttr->ThotAttribute == HTML_ATTR_Width__)
1.129     vatton   1922:         /* HTML attribute "width" */
                   1923:         {
                   1924:           /* if it's an Object element, wait until all attributes are handled,
                   1925:              especially the data attribute that may generate the image to
                   1926:              which the width has to be applied */
                   1927:           if (elType.ElTypeNum != HTML_EL_Object)
                   1928:             /* create the corresponding attribute IntWidthPercent or */
                   1929:             /* IntWidthPxl */
                   1930:             CreateAttrWidthPercentPxl (attrValue, lastAttrElement,
                   1931:                                        context->doc, -1);
                   1932:         }
1.58      vatton   1933:       else if (lastMappedAttr->ThotAttribute == HTML_ATTR_Height_)
1.129     vatton   1934:         /* HTML attribute "height" */
                   1935:         {
                   1936:           /* if it's an Object element, wait until all attributes are handled,
                   1937:              especially the data attribute that may generate the image to
                   1938:              which the height has to be applied */
                   1939:           if (elType.ElTypeNum != HTML_EL_Object)
                   1940:             /* create the corresponding attribute IntHeightPercent or */
                   1941:             /* IntHeightPxl */
                   1942:             CreateAttrHeightPercentPxl (attrValue, lastAttrElement,
                   1943:                                         context->doc, -1);
                   1944:         }
1.91      quint    1945:       else if (lastMappedAttr->ThotAttribute == HTML_ATTR_Area_Size)
1.129     vatton   1946:         /* HTML attribute "size" for an element "input" */
                   1947:         CreateAttrIntAreaSize (val, lastAttrElement, context->doc);
1.48      vatton   1948:       else if (!strcmp (lastMappedAttr->XMLattribute, "size"))
1.129     vatton   1949:         {
                   1950:           TtaGiveAttributeType (currentAttribute, &attrType, &attrKind);
                   1951:           if (attrType.AttrTypeNum == HTML_ATTR_Font_size)
                   1952:             CreateAttrIntSize (attrValue, lastAttrElement, context->doc);
                   1953:         }
1.48      vatton   1954:       else if (!strcmp (lastMappedAttr->XMLattribute, "shape"))
1.129     vatton   1955:         {
                   1956:           child = TtaGetFirstChild (lastAttrElement);
                   1957:           if (child != NULL)
                   1958:             {
                   1959:               switch (val)
                   1960:                 {
                   1961:                 case HTML_ATTR_shape_VAL_rectangle:
                   1962:                   shape = 'R';
                   1963:                   break;
                   1964:                 case HTML_ATTR_shape_VAL_circle:
                   1965:                   shape = 'a';
                   1966:                   break;
                   1967:                 case HTML_ATTR_shape_VAL_polygon:
                   1968:                   shape = 'p';
                   1969:                   break;
                   1970:                 default:
                   1971:                   shape = SPACE;
                   1972:                   break;
                   1973:                 }
                   1974:               TtaSetGraphicsShape (child, shape, context->doc);
                   1975:             }
                   1976:         }
1.48      vatton   1977:       else if (!strcmp (lastMappedAttr->XMLattribute, "value"))
1.129     vatton   1978:         {
                   1979:           if (elType.ElTypeNum == HTML_EL_Text_Input ||
                   1980:               elType.ElTypeNum == HTML_EL_Password_Input ||
                   1981:               elType.ElTypeNum == HTML_EL_File_Input ||
                   1982:               elType.ElTypeNum == HTML_EL_Input)
                   1983:             /* create a Default_Value attribute with the same content */
                   1984:             {
                   1985:               attrType1.AttrSSchema = attrType.AttrSSchema;
                   1986:               attrType1.AttrTypeNum = HTML_ATTR_Default_Value;
                   1987:               attr = TtaNewAttribute (attrType1);
                   1988:               TtaAttachAttribute (lastAttrElement, attr, context->doc);
                   1989:               TtaSetAttributeText (attr, attrValue,
                   1990:                                    lastAttrElement, context->doc);
                   1991:             }
                   1992:         }
1.30      cvs      1993:       else
1.129     vatton   1994:         {
                   1995:           /* Some HTML attributes are equivalent to a CSS property:      */
                   1996:           /*      background     ->                   background         */
                   1997:           /*      bgcolor        ->                   background         */
                   1998:           /*      text           ->                   color              */
                   1999:           /*      color          ->                   color              */
                   2000:           if (!strcmp (lastMappedAttr->XMLattribute, "background"))
                   2001:             {
                   2002:               if (strlen (attrValue) > MaxMsgLength - 30)
                   2003:                 attrValue[MaxMsgLength - 30] = EOS;
                   2004:               HTMLSetBackgroundImage (context->doc, context->lastElement,
                   2005:                                       REPEAT, 0, attrValue, FALSE);
                   2006:             }
                   2007:           else if (!strcmp (lastMappedAttr->XMLattribute, "bgcolor"))
                   2008:             HTMLSetBackgroundColor (context->doc, context->lastElement,
                   2009:                                     0, attrValue);
                   2010:           else if (!strcmp (lastMappedAttr->XMLattribute, "text") ||
                   2011:                    !strcmp (lastMappedAttr->XMLattribute, "color"))
                   2012:             HTMLSetForegroundColor (context->doc, context->lastElement,
                   2013:                                     0, attrValue);
                   2014:         }
1.48      vatton   2015:     }
1.30      cvs      2016: }
                   2017: 
                   2018: /*----------------------------------------------------------------------
1.129     vatton   2019:   MapHTMLAttributeValue
                   2020:   Search in the Attribute Value Mapping Table the entry for the attribute
                   2021:   ThotAtt and its value attVal. Returns the corresponding Thot value.
1.1       cvs      2022:   ----------------------------------------------------------------------*/
1.118     vatton   2023: void MapHTMLAttributeValue (char *attVal, const AttributeType *attrType,
1.129     vatton   2024:                             int *value)
1.1       cvs      2025: {
1.66      vatton   2026:   MapXMLAttributeValue (XHTML_TYPE, attVal, attrType, value);
1.1       cvs      2027: }

Webmaster