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

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

Webmaster