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

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

Webmaster