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

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

Webmaster