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

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

Webmaster