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

1.1       cvs         1: /*
                      2:  *
1.78      vatton      3:  *  (c) COPYRIGHT INRIA and W3C, 1996-2003
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"
                     34: #include "UIcss_f.h"
1.13      cvs        35: #include "styleparser_f.h"
1.2       cvs        36: #include "XHTMLbuilder_f.h"
1.13      cvs        37: #include "Xml2thot_f.h"
1.1       cvs        38: 
1.30      cvs        39: #define MaxMsgLength 200
                     40: 
1.47      cvs        41: /* Elements that cannot contain text as immediate children.
                     42:    When some text is present in the HTML file it must be 
                     43:    surrounded by a Pseudo_paragraph element */
                     44: static int          NoTextChild[] =
                     45: {
                     46:    HTML_EL_Document, HTML_EL_HTML, HTML_EL_HEAD, HTML_EL_BODY,
                     47:    HTML_EL_Definition_List, HTML_EL_Block_Quote, HTML_EL_Directory,
                     48:    HTML_EL_Form, HTML_EL_Menu, HTML_EL_FIELDSET,
                     49:    HTML_EL_Numbered_List, HTML_EL_Option_Menu,
                     50:    HTML_EL_Unnumbered_List, HTML_EL_Definition, HTML_EL_List_Item,
                     51:    HTML_EL_MAP, HTML_EL_map, HTML_EL_Applet,
                     52:    HTML_EL_Object, HTML_EL_IFRAME, HTML_EL_NOFRAMES,
                     53:    HTML_EL_Division, HTML_EL_Center, HTML_EL_NOSCRIPT,
                     54:    HTML_EL_Data_cell, HTML_EL_Heading_cell,
                     55:    0};
                     56: 
1.28      cvs        57: /* Define a pointer to let parser functions access the HTML entity table */
                     58: extern XmlEntity *pXhtmlEntityTable;
1.6       cvs        59: 
1.30      cvs        60: /* maximum size of error messages */
                     61: #define MaxMsgLength 200
                     62: 
1.6       cvs        63: /*----------------------------------------------------------------------
1.15      cvs        64:   ParseCharset:
1.6       cvs        65:   Parses the element HTTP-EQUIV and looks for the charset value.
                     66:   ----------------------------------------------------------------------*/
1.30      cvs        67: void             ParseCharset (Element el, Document doc) 
                     68: 
1.6       cvs        69: {
1.15      cvs        70:    AttributeType attrType;
                     71:    Attribute     attr;
                     72:    SSchema       docSSchema;
                     73:    CHARSET       charset;
1.39      cvs        74:    char         *text, *text2, *ptrText, *str;
                     75:    char          charsetname[MAX_LENGTH];
1.15      cvs        76:    int           length;
1.6       cvs        77:    int           pos, index = 0;
                     78: 
1.15      cvs        79:    charset = TtaGetDocumentCharset (doc);
                     80:    if (charset != UNDEFINED_CHARSET)
                     81:      /* the charset was already defined by the http header */
                     82:      return;
1.6       cvs        83: 
                     84:    docSSchema = TtaGetDocumentSSchema (doc);
                     85:    attrType.AttrSSchema = docSSchema;
                     86:    attrType.AttrTypeNum = HTML_ATTR_http_equiv;
                     87:    attr = TtaGetAttribute (el, attrType);
                     88:    if (attr != NULL)
                     89:      {
                     90:        /* There is a HTTP-EQUIV attribute */
                     91:        length = TtaGetTextAttributeLength (attr);
                     92:        if (length > 0)
                     93:         {
1.37      cvs        94:           text = TtaGetMemory (length + 1);
1.6       cvs        95:           TtaGiveTextAttributeValue (attr, text, &length);
1.37      cvs        96:           if (!strcasecmp (text, "content-type"))
1.6       cvs        97:             {
                     98:               attrType.AttrTypeNum = HTML_ATTR_meta_content;
                     99:               attr = TtaGetAttribute (el, attrType);
                    100:               if (attr != NULL)
                    101:                 {
                    102:                   length = TtaGetTextAttributeLength (attr);
                    103:                   if (length > 0)
                    104:                     {
1.37      cvs       105:                       text2 = TtaGetMemory (length + 1);
1.6       cvs       106:                       TtaGiveTextAttributeValue (attr, text2, &length);
                    107:                       ptrText = text2;
                    108:                       while (*ptrText)
                    109:                         {
1.53      vatton    110:                           *ptrText = tolower (*ptrText);
1.6       cvs       111:                           ptrText++;
                    112:                         }
                    113:                       
1.37      cvs       114:                       str = strstr (text2, "charset=");
1.6       cvs       115:                       if (str)
                    116:                         {
                    117:                           pos = str - text2 + 8;
1.37      cvs       118:                           while (text2[pos] != SPACE &&
                    119:                                  text2[pos] != TAB && text2[pos] != EOS)
1.6       cvs       120:                             charsetname[index++] = text2[pos++];
1.37      cvs       121:                           charsetname[index] = EOS;
1.15      cvs       122:                           charset = TtaGetCharset (charsetname);
                    123:                           if (charset != UNDEFINED_CHARSET)
1.77      cvs       124:                             TtaSetDocumentCharset (doc, charset, FALSE);
1.6       cvs       125:                         }
                    126:                       TtaFreeMemory (text2);
                    127:                     }       
                    128:                 } 
                    129:             }
                    130:           TtaFreeMemory (text);
                    131:         }
                    132:      }
                    133: }
                    134: 
1.23      cvs       135: /*----------------------------------------------------------------------
1.47      cvs       136:    XhtmlCannotContainText 
                    137:    Return TRUE if element el is a block element.
                    138:   ----------------------------------------------------------------------*/
                    139: ThotBool      XhtmlCannotContainText (ElementType elType)
                    140: 
                    141: {
                    142:    int        i;
                    143:    ThotBool   ret;
                    144: 
                    145:    if (strcmp (TtaGetSSchemaName (elType.ElSSchema), "HTML"))
                    146:       /* not an HTML element */
                    147:       ret = TRUE;
                    148:    else
                    149:      {
                    150:        ret = FALSE;
                    151:        i = 0;
                    152:        while (NoTextChild[i] > 0 && NoTextChild[i] != elType.ElTypeNum)
                    153:            i++;
                    154:        if (NoTextChild[i] == elType.ElTypeNum)
                    155:            ret = TRUE;
                    156:      }
                    157:    return ret;
1.23      cvs       158: }
                    159: 
1.6       cvs       160: /*----------------------------------------------------------------------
                    161:   XhtmlElementComplete
1.20      cvs       162:   Complete Xhtml elements.
1.6       cvs       163:   Check its attributes and its contents.
                    164:   ----------------------------------------------------------------------*/
1.72      cvs       165: void       XhtmlElementComplete (ParserData *context, Element el, int *error)
1.30      cvs       166: 
                    167: {
1.72      cvs       168:    Document       doc;   
1.30      cvs       169:    ElementType    elType, newElType, childType;
                    170:    Element        constElem, child, desc, leaf, prev, next, last,
1.62      quint     171:                  elFrames, lastFrame, lastChild, parent, picture, content;
1.30      cvs       172:    Attribute      attr;
                    173:    AttributeType  attrType;
                    174:    Language       lang;
1.41      cvs       175:    char           *text;
1.39      cvs       176:    char           lastChar[2];
1.79      quint     177:    char           *name1, *data;
1.30      cvs       178:    int            length;
                    179:    SSchema        docSSchema;
1.62      quint     180:    ThotBool       isImage;
                    181:    PresentationValue    pval;
                    182:    PresentationContext  ctxt;
1.6       cvs       183: 
                    184:    *error = 0;
1.72      cvs       185:    doc = context->doc;
1.6       cvs       186:    docSSchema = TtaGetDocumentSSchema (doc);
                    187: 
                    188:    elType = TtaGetElementType (el);
                    189:    /* is this a block-level element in a character-level element? */
1.56      cvs       190:    if (!IsXMLElementInline (elType, doc) &&
1.24      cvs       191:        elType.ElTypeNum != HTML_EL_Comment_ &&
                    192:        elType.ElTypeNum != HTML_EL_XMLPI)
1.6       cvs       193:        BlockInCharLevelElem (el);
                    194: 
                    195:    newElType.ElSSchema = elType.ElSSchema;
                    196:    switch (elType.ElTypeNum)
                    197:      {
1.62      quint     198:      case HTML_EL_Object:      /* it's an object */
1.79      quint     199:        data = NULL;
1.62      quint     200:        isImage = FALSE;
                    201:        /* is there a type attribute on the object element? */
                    202:        attrType.AttrSSchema = elType.ElSSchema;
                    203:        attrType.AttrTypeNum = HTML_ATTR_Object_type;
1.6       cvs       204:        attr = TtaGetAttribute (el, attrType);
1.62      quint     205:        if (attr)
                    206:         /* there is a type attribute. Get its value to see if the object
                    207:            represents an image */
1.6       cvs       208:         {
                    209:           length = TtaGetTextAttributeLength (attr);
                    210:           if (length > 0)
                    211:             {
1.37      cvs       212:               name1 = TtaGetMemory (length + 1);
1.6       cvs       213:               TtaGiveTextAttributeValue (attr, name1, &length);
1.68      kahan     214:               if (!strcmp (name1, AM_MATHML_MIME_TYPE) ||
1.62      quint     215:                   !strcmp (name1, "application/postscript") ||
                    216:                   !strcmp (name1, "image/x-bitmap") ||
                    217:                   !strcmp (name1, "image/x-xpixmap") ||
                    218:                   !strcmp (name1, "image/gif") ||
                    219:                   !strcmp (name1, "image/jpeg") ||
                    220:                   !strcmp (name1, "image/png") ||
1.67      kahan     221:                   !strcmp (name1, "image/svg") ||
1.83      cvs       222:                   !strcmp (name1, AM_SVG_MIME_TYPE) ||
                    223:                   !strcmp (name1, AM_XHTML_MIME_TYPE) ||
                    224:                   !strcmp (name1, "text/html") ||
                    225:                   !strcmp (name1, "text/htm") ||
                    226:                   !strcmp (name1, AM_GENERIC_XML_MIME_TYPE))
1.62      quint     227:                 isImage = TRUE;
                    228:               TtaFreeMemory (name1);
                    229:             }
                    230:         }
1.79      quint     231: 
                    232:        attrType.AttrTypeNum = HTML_ATTR_data;
                    233:        attr = TtaGetAttribute (el, attrType);
                    234:        if (attr)
                    235:         /* the object has a data attribute */
                    236:         {
                    237:           length = TtaGetTextAttributeLength (attr);
                    238:           if (length > 0)
                    239:             {
                    240:               data = TtaGetMemory (length + 1);
                    241:               TtaGiveTextAttributeValue (attr, data, &length);
                    242:               if (!isImage)
                    243:                 if (!strcmp (&data[length-3], "mml") ||
                    244:                     !strcmp (&data[length-3], "gif") ||
                    245:                     !strcmp (&data[length-3], "jpg") ||
                    246:                     !strcmp (&data[length-4], "jpeg") ||
                    247:                     !strcmp (&data[length-3], "png") ||
                    248:                     !strcmp (&data[length-3], "svg") ||
1.80      cvs       249:                     !strcmp (&data[length-4], "svgz") ||
1.83      cvs       250:                     !strcmp (&data[length-3], "htm") ||
                    251:                     !strcmp (&data[length-4], "html") ||
                    252:                     !strcmp (&data[length-3], "xml"))
1.79      quint     253:                   isImage = TRUE;
                    254:             }
                    255:         }
1.62      quint     256:        picture = NULL;     /* no PICTURE element yet */
                    257:        child = TtaGetFirstChild (el);
                    258:        if (isImage)
                    259:         /* the object represents an image. We need a PICTURE element as
                    260:            child of the object to hold the image */
                    261:         {
                    262:           if (child)
                    263:             {
                    264:               elType = TtaGetElementType (child);
                    265:               if (elType.ElTypeNum == HTML_EL_PICTURE_UNIT)
                    266:                 /* there is already a PICTURE element */
                    267:                 picture = child;
                    268:             }
1.79      quint     269:           /* if the object element has no PICTURE element as its first child
1.62      quint     270:              create one */
                    271:           if (!picture)
                    272:             {
                    273:               elType.ElTypeNum = HTML_EL_PICTURE_UNIT;
                    274:               picture = TtaNewTree (doc, elType, "");
                    275:               if (child)
                    276:                 TtaInsertSibling (picture, child, TRUE, doc);
                    277:               else
                    278:                 TtaInsertFirstChild (&picture, el, doc);
                    279:               child = picture;
                    280:             }
                    281:           /* copy attribute data of the object into the SRC attribute of
                    282:              the PICTURE element */
1.79      quint     283:           if (data)
                    284:             /* the object has a data attribute */
                    285:             {
                    286:               attrType.AttrTypeNum = HTML_ATTR_SRC;
                    287:               attr = TtaGetAttribute (picture, attrType);
                    288:               if (attr == NULL)
                    289:                 {
                    290:                   attr = TtaNewAttribute (attrType);
                    291:                   TtaAttachAttribute (picture, attr, doc);
                    292:                 }
                    293:               TtaSetAttributeText (attr, data, picture, doc);
                    294:             }
                    295:           attrType.AttrTypeNum = HTML_ATTR_Height_;
1.62      quint     296:           attr = TtaGetAttribute (el, attrType);
                    297:           if (attr)
1.79      quint     298:             /* the Object has a height attribute. Applies it to the
                    299:                picture element */
                    300:             {
                    301:               length = TtaGetTextAttributeLength (attr);
                    302:               if (length > 0)
                    303:                 {
                    304:                   text = TtaGetMemory (length + 1);
                    305:                   TtaGiveTextAttributeValue (attr, text, &length);
                    306:                   /* create the corresponding attribute IntHeightPercent or */
                    307:                   /* IntHeightPxl */
                    308:                   CreateAttrHeightPercentPxl (text, el, doc, -1);
                    309:                   TtaFreeMemory (text);
                    310:                 }
                    311:             }
                    312:           attrType.AttrTypeNum = HTML_ATTR_Width__;
                    313:           attr = TtaGetAttribute (el, attrType);
                    314:           if (attr)
                    315:             /* the Object has a width attribute. Applies it to the
                    316:                picture element */
1.62      quint     317:             {
                    318:               length = TtaGetTextAttributeLength (attr);
                    319:               if (length > 0)
1.6       cvs       320:                 {
1.79      quint     321:                   text = TtaGetMemory (length + 1);
                    322:                   TtaGiveTextAttributeValue (attr, text, &length);
                    323:                   /* create the corresponding attribute IntWidthPercent or */
                    324:                   /* IntWidthPxl */
                    325:                   CreateAttrWidthPercentPxl (text, el, doc, -1);
                    326:                   TtaFreeMemory (text);
1.6       cvs       327:                 }
                    328:             }
                    329:         }
                    330:        /* is the Object_Content element already created ? */
1.62      quint     331:        if (child)
                    332:         /* the object element has at least 1 child element */
                    333:         {
                    334:           content = NULL;
                    335:           desc = child;
1.6       cvs       336:           elType = TtaGetElementType (desc);
1.62      quint     337:           if (elType.ElTypeNum != HTML_EL_Object_Content)
                    338:             {
                    339:               TtaNextSibling(&desc);
                    340:               if (desc)
                    341:                 elType = TtaGetElementType (desc);
                    342:             }
                    343:           /* is it the Object_Content element ? */
                    344:           if (elType.ElTypeNum == HTML_EL_Object_Content)
                    345:             content = desc;
                    346:           else
1.6       cvs       347:             {
1.62      quint     348:               /* create an Object_Content element */
                    349:               elType.ElTypeNum = HTML_EL_Object_Content;
                    350:               content = TtaNewElement (doc, elType);
                    351:               if (picture)
                    352:                 TtaInsertSibling (content, picture, FALSE, doc);
                    353:               else
                    354:                 TtaInsertSibling (content, child, TRUE, doc);
                    355:               /* move previous existing children into Object_Content */
1.6       cvs       356:               child = TtaGetLastChild(el);
1.62      quint     357:               while (child != content)
                    358:                 {
                    359:                   TtaRemoveTree (child, doc);
                    360:                   TtaInsertFirstChild (&child, content, doc);
                    361:                   child = TtaGetLastChild(el);
                    362:                 }
                    363:             }
                    364:           if (picture && content)
                    365:             /* there is a picture element. The Object_Content must not be
                    366:                displayed in the main view */
                    367:             {
                    368:               ctxt = TtaGetSpecificStyleContext (doc);
                    369:               /* the presentation rule to be set is not a CSS rule */
                    370:               ctxt->cssSpecificity = 0;
                    371:               ctxt->destroy = FALSE;
1.85      vatton    372:               pval.typed_data.unit = UNIT_PX;
1.62      quint     373:               pval.typed_data.value = 0;
                    374:               pval.typed_data.real = FALSE;
                    375:               TtaSetStylePresentation (PRVisibility, content, NULL, ctxt, pval);
1.6       cvs       376:             }
                    377:         }
1.79      quint     378:        if (data)
                    379:         TtaFreeMemory (data);
1.6       cvs       380:        break;
1.62      quint     381: 
1.6       cvs       382:      case HTML_EL_Unnumbered_List:
                    383:      case HTML_EL_Numbered_List:
                    384:      case HTML_EL_Menu:
                    385:      case HTML_EL_Directory:
                    386:        /* It's a List element. It should only have List_Item children.
                    387:          If it has List element chidren, move these List elements
                    388:          within their previous List_Item sibling.  This is to fix
                    389:          a bug in document generated by Mozilla. */
                    390:        prev = NULL;
                    391:        next = NULL;
                    392:        child = TtaGetFirstChild (el);
                    393:        while (child != NULL)
                    394:         {
                    395:           next = child;
                    396:           TtaNextSibling (&next);
                    397:           elType = TtaGetElementType (child);
                    398:           if (elType.ElTypeNum == HTML_EL_Unnumbered_List ||
                    399:               elType.ElTypeNum == HTML_EL_Numbered_List ||
                    400:               elType.ElTypeNum == HTML_EL_Menu ||
                    401:               elType.ElTypeNum == HTML_EL_Directory)
                    402:             /* this list element is a child of another list element */
                    403:             if (prev)
                    404:               {
                    405:                 elType = TtaGetElementType (prev);
                    406:                 if (elType.ElTypeNum == HTML_EL_List_Item)
                    407:                   {
                    408:                     /* get the last child of the previous List_Item */
                    409:                     desc = TtaGetFirstChild (prev);
                    410:                     last = NULL;
                    411:                     while (desc)
                    412:                       {
                    413:                         last = desc;
                    414:                         TtaNextSibling (&desc);
                    415:                       }
                    416:                     /* move the list element after the last child of the
                    417:                        previous List_Item */
                    418:                     TtaRemoveTree (child, doc);
                    419:                     if (last)
                    420:                       TtaInsertSibling (child, last, FALSE, doc);
                    421:                     else
                    422:                       TtaInsertFirstChild (&child, prev, doc);
                    423:                     child = prev;
                    424:                   }
                    425:               }
                    426:           prev = child;
                    427:           child = next;
                    428:         }
                    429:        break;
                    430:        
                    431:      case HTML_EL_FRAMESET:
                    432:        /* The FRAMESET element is now complete.  Gather all its FRAMESET
                    433:          and FRAME children and wrap them up in a Frames element */
                    434:        elFrames = NULL; lastFrame = NULL;
                    435:        lastChild = NULL;
                    436:        child = TtaGetFirstChild (el);
                    437:        while (child != NULL)
                    438:         {
                    439:           next = child;
                    440:           TtaNextSibling (&next);
                    441:           elType = TtaGetElementType (child);
                    442:           if (elType.ElTypeNum == HTML_EL_FRAMESET ||
                    443:               elType.ElTypeNum == HTML_EL_FRAME ||
                    444:               elType.ElTypeNum == HTML_EL_Comment_)
                    445:             {
                    446:               /* create the Frames element if it does not exist */
                    447:               if (elFrames == NULL)
                    448:                 {
                    449:                   newElType.ElSSchema = docSSchema;
                    450:                   newElType.ElTypeNum = HTML_EL_Frames;
                    451:                   elFrames = TtaNewElement (doc, newElType);
1.63      cvs       452:                   if (DocumentMeta[doc]->xmlformat)
                    453:                     XmlSetElemLineNumber (elFrames);
                    454:                   else
                    455:                     SetHtmlElemLineNumber (elFrames);
1.6       cvs       456:                   TtaInsertSibling (elFrames, child, TRUE, doc);
                    457:                 }
                    458:               /* move the element as the last child of the Frames element */
                    459:               TtaRemoveTree (child, doc);
                    460:               if (lastFrame == NULL)
                    461:                 TtaInsertFirstChild (&child, elFrames, doc);
                    462:               else
                    463:                 TtaInsertSibling (child, lastFrame, FALSE, doc);
                    464:               lastFrame = child;
                    465:             }
                    466:           child = next;
                    467:         }
                    468:        break;
                    469:        
                    470:      case HTML_EL_Input:       /* it's an INPUT without any TYPE attribute */
                    471:        /* Create a child of type Text_Input */
                    472:        elType.ElTypeNum = HTML_EL_Text_Input;
                    473:        child = TtaNewTree (doc, elType, "");
1.63      cvs       474:        if (DocumentMeta[doc]->xmlformat)
                    475:         XmlSetElemLineNumber (child);
                    476:        else
                    477:         SetHtmlElemLineNumber (child);
1.6       cvs       478:        TtaInsertFirstChild (&child, el, doc);
                    479:        /* now, process it like a Text_Input element */
                    480: 
                    481:      case HTML_EL_Text_Input:
                    482:      case HTML_EL_Password_Input:
                    483:      case HTML_EL_File_Input:
1.91      quint     484:        /* set default size */
                    485:        attrType.AttrSSchema = elType.ElSSchema;
                    486:        attrType.AttrTypeNum = HTML_ATTR_IntAreaSize;
                    487:        attr = TtaGetAttribute (el, attrType);
                    488:        if (!attr)
                    489:         CreateAttrIntAreaSize (20, el, doc);
1.6       cvs       490:        /* get element Inserted_Text */
                    491:        child = TtaGetFirstChild (el);
                    492:        if (child != NULL)
                    493:         {
                    494:           attrType.AttrTypeNum = HTML_ATTR_Value_;
                    495:           attr = TtaGetAttribute (el, attrType);
                    496:           if (attr != NULL)
                    497:             {
                    498:               /* copy the value of attribute "value" into the first text
                    499:                  leaf of element */
                    500:               length = TtaGetTextAttributeLength (attr);
                    501:               if (length > 0)
                    502:                 {
                    503:                   /* get the text leaf */
                    504:                   leaf = TtaGetFirstChild (child);
                    505:                   if (leaf != NULL)
                    506:                     {
                    507:                       childType = TtaGetElementType (leaf);
                    508:                       if (childType.ElTypeNum == HTML_EL_TEXT_UNIT)
                    509:                         {
                    510:                           /* copy attribute value into the text leaf */
1.37      cvs       511:                           text = TtaGetMemory (length + 1);
1.6       cvs       512:                           TtaGiveTextAttributeValue (attr, text, &length);
                    513:                           TtaSetTextContent (leaf, text, 
                    514:                                              TtaGetDefaultLanguage (), doc);
                    515:                           TtaFreeMemory (text);
                    516:                         }
                    517:                     }
                    518:                 }
                    519:             }
                    520:         }
                    521:        break;
                    522:        
                    523:      case HTML_EL_META:
1.15      cvs       524:        ParseCharset (el, doc);
1.6       cvs       525:        break;
                    526: 
                    527:      case HTML_EL_STYLE_:      /* it's a STYLE element */
1.60      vatton    528:      case HTML_EL_SCRIPT_:     /* it's a SCRIPT element */
1.6       cvs       529:      case HTML_EL_Preformatted:        /* it's a PRE */
                    530:        /* if the last line of the Preformatted is empty, remove it */
                    531:        leaf = XmlLastLeafInElement (el);
                    532:        if (leaf != NULL)
                    533:         {
                    534:           elType = TtaGetElementType (leaf);
                    535:           if (elType.ElTypeNum == HTML_EL_TEXT_UNIT)
                    536:             /* the last leaf is a TEXT element */
                    537:             {
                    538:               length = TtaGetTextLength (leaf);
                    539:               if (length > 0)
                    540:                 {
                    541:                   TtaGiveSubString (leaf, lastChar, length, 1);
                    542:                   if (lastChar[0] == EOL)
                    543:                     /* last character is new line, delete it */
                    544:                     {
                    545:                       if (length == 1)
                    546:                         /* empty TEXT element */
                    547:                         TtaDeleteTree (leaf, doc);
                    548:                       else
                    549:                         /* remove the last character */
                    550:                         TtaDeleteTextContent (leaf, length, 1, doc);
                    551:                     }
                    552:                 }
                    553:             }
                    554:         }
1.75      kahan     555:        if (DocumentMeta[doc] && DocumentMeta[doc]->xmlformat)
1.63      cvs       556:         {
                    557:           if (IsXmlParsingCSS ())
                    558:             {
                    559:               text = GetStyleContents (el);
                    560:               if (text)
                    561:                 {
1.71      vatton    562:                   ReadCSSRules (doc, NULL, text, NULL,
1.82      quint     563:                                 TtaGetElementLineNumber (el), FALSE, el);
1.63      cvs       564:                   TtaFreeMemory (text);
                    565:                 }
                    566:               SetXmlParsingCSS (FALSE);
                    567:             }
                    568:         }
                    569:        else
1.6       cvs       570:         {
1.63      cvs       571:           if (IsHtmlParsingCSS ())
1.6       cvs       572:             {
1.63      cvs       573:               text = GetStyleContents (el);
                    574:               if (text)
                    575:                 {
1.71      vatton    576:                   ReadCSSRules (doc, NULL, text, NULL,
1.82      quint     577:                                 TtaGetElementLineNumber (el), FALSE, el);
1.63      cvs       578:                   TtaFreeMemory (text);
                    579:                 }
                    580:               SetHtmlParsingCSS (FALSE);
1.6       cvs       581:             }
                    582:         }
                    583:        /* and continue as if it were a Preformatted or a Script */
                    584:        break;
                    585:        
                    586:      case HTML_EL_Text_Area:   /* it's a Text_Area */
1.69      cvs       587:        if (DocumentMeta[doc]->xmlformat)
                    588:         SetParsingTextArea (FALSE);
                    589:        else
                    590:         SetHtmlParsingTextArea (FALSE);
1.6       cvs       591:        child = TtaGetFirstChild (el);
                    592:        if (child == NULL)
                    593:         /* it's an empty Text_Area */
                    594:         /* insert a Inserted_Text element in the element */
                    595:         {
                    596:           newElType.ElTypeNum = HTML_EL_Inserted_Text;
                    597:           child = TtaNewTree (doc, newElType, "");
                    598:           TtaInsertFirstChild (&child, el, doc);
                    599:         }
                    600:        else
                    601:         {
                    602:           /* save the text into Default_Value attribute */
                    603:           attrType.AttrSSchema = docSSchema;
                    604:           attrType.AttrTypeNum = HTML_ATTR_Default_Value;
                    605:           if (TtaGetAttribute (el, attrType) == NULL)
                    606:             /* attribute Default_Value is missing */
                    607:             {
                    608:               attr = TtaNewAttribute (attrType);
                    609:               TtaAttachAttribute (el, attr, doc);
                    610:               desc = TtaGetFirstChild (child);
                    611:               length = TtaGetTextLength (desc) + 1;
1.37      cvs       612:               text = TtaGetMemory (length);
1.6       cvs       613:               TtaGiveTextContent (desc, text, &length, &lang);
                    614:               TtaSetAttributeText (attr, text, el, doc);
                    615:               TtaFreeMemory (text);
                    616:             }
                    617:         }
                    618:        /* insert a Frame element */
                    619:        newElType.ElTypeNum = HTML_EL_Frame;
                    620:        constElem = TtaNewTree (doc, newElType, "");
                    621:        TtaInsertSibling (constElem, child, FALSE, doc);
                    622:        break;
                    623:        
                    624:      case HTML_EL_Radio_Input:
                    625:      case HTML_EL_Checkbox_Input:
                    626:        /* put an attribute Checked if it is missing */
                    627:        attrType.AttrSSchema = docSSchema;
                    628:        attrType.AttrTypeNum = HTML_ATTR_Checked;
                    629:        if (TtaGetAttribute (el, attrType) == NULL)
                    630:         /* attribute Checked is missing */
                    631:         {
                    632:           attr = TtaNewAttribute (attrType);
                    633:           TtaAttachAttribute (el, attr, doc);
                    634:           TtaSetAttributeValue (attr, HTML_ATTR_Checked_VAL_No_, el, doc);
                    635:         }
                    636:        break;
                    637:        
                    638:      case HTML_EL_Option_Menu:
                    639:        /* Check that at least one option has a SELECTED attribute */
                    640:        OnlyOneOptionSelected (el, doc, TRUE);
                    641:        break;
                    642: 
                    643:      case HTML_EL_PICTURE_UNIT:
                    644:        break;
                    645:        
                    646:      case HTML_EL_LINK:
                    647:        CheckCSSLink (el, doc, docSSchema);
                    648:        break;
                    649:        
                    650:      case HTML_EL_Data_cell:
                    651:      case HTML_EL_Heading_cell:
                    652:        /* insert a pseudo paragraph into empty cells */
                    653:        child = TtaGetFirstChild (el);
                    654:        if (child == NULL)
                    655:         {
                    656:           elType.ElTypeNum = HTML_EL_Pseudo_paragraph;
                    657:           child = TtaNewTree (doc, elType, "");
                    658:           if (child != NULL)
                    659:               TtaInsertFirstChild (&child, el, doc);
                    660:         }
                    661:        
1.80      cvs       662:        /* detect whether we are parsing a whole table or just a cell */
1.63      cvs       663:        if (DocumentMeta[doc]->xmlformat)
                    664:         {
                    665:           if (IsWithinXmlTable ())
1.92    ! quint     666:             NewCell (el, doc, FALSE, FALSE);
1.63      cvs       667:         }
                    668:        else
                    669:         {
                    670:           if (IsWithinHtmlTable ())
1.92    ! quint     671:             NewCell (el, doc, FALSE, FALSE);
1.63      cvs       672:         }
1.6       cvs       673:        break;
                    674:        
                    675:      case HTML_EL_Table:
                    676:        CheckTable (el, doc);
                    677:        SubWithinTable ();
                    678:        break;
                    679:        
                    680:      case HTML_EL_TITLE:
                    681:        /* show the TITLE in the main window */
                    682:        UpdateTitle (el, doc);
                    683:        break;
1.41      cvs       684: 
                    685:      case HTML_EL_rbc:
                    686:        /* an rbc element has been read. Its parent should be a complex_ruby.
                    687:          Change the type of the parent, as simple_ruby are created by
                    688:          default */
                    689:        parent = TtaGetParent (el);
                    690:        if (parent)
                    691:         {
                    692:           newElType = TtaGetElementType (parent);
                    693:           if (newElType.ElSSchema == elType.ElSSchema &&
                    694:               newElType.ElTypeNum == HTML_EL_simple_ruby)
                    695:              ChangeElementType (parent, HTML_EL_complex_ruby);
                    696:         }
                    697:        break;
                    698: 
                    699:      case HTML_EL_rtc1:
                    700:        /* an rtc element has been parsed. If it has already a rtc1 sibling,
                    701:          change its type to rtc2 */
                    702:        prev = el;
                    703:        do
                    704:         {
                    705:           TtaPreviousSibling(&prev);
                    706:           if (prev)
                    707:             {
                    708:               newElType = TtaGetElementType (prev);
                    709:               if (newElType.ElSSchema == elType.ElSSchema &&
                    710:                   newElType.ElTypeNum == HTML_EL_rtc1)
                    711:                 {
                    712:                   ChangeElementType (el, HTML_EL_rtc2);
                    713:                   prev = NULL;
                    714:                 }
                    715:             }
                    716:         }
                    717:        while (prev);
                    718:        break;
                    719: 
1.6       cvs       720:      default:
                    721:        break;
                    722:      }
                    723: }
1.1       cvs       724: 
                    725: /*----------------------------------------------------------------------
1.30      cvs       726:    PutInContent    
                    727:    Put the string ChrString in the leaf of current element.
                    728:   ----------------------------------------------------------------------*/
1.39      cvs       729: Element         PutInContent (char *ChrString, ParserData *context)
1.30      cvs       730: 
                    731: {
                    732:    Element      el, child;
                    733:    ElementType  elType;
                    734:    int          length;
                    735: 
                    736:    el = NULL;
                    737:    if (context->lastElement != NULL)
                    738:      {
                    739:        /* search first leaf of current element */
                    740:        el = context->lastElement;
                    741:        do
                    742:          {
                    743:             child = TtaGetFirstChild (el);
                    744:             if (child != NULL)
                    745:                el = child;
                    746:          }
                    747:        while (child != NULL);
                    748:        elType = TtaGetElementType (el);
                    749:        length = 0;
                    750:        if (elType.ElTypeNum == 1)
                    751:           length = TtaGetTextLength (el);
                    752:        if (length == 0)
                    753:           TtaSetTextContent (el, ChrString, context->language, context->doc);
                    754:        else
                    755:           TtaAppendTextContent (el, ChrString, context->doc);
                    756:      }
                    757:    return el;
                    758: }
                    759: 
                    760: /*----------------------------------------------------------------------
1.51      cvs       761:    UnknownXhtmlNameSpace
1.65      cvs       762:    The element doesn't belong to a supported namespace
1.51      cvs       763:   ----------------------------------------------------------------------*/
1.65      cvs       764: void               UnknownXhtmlNameSpace (ParserData *context,
                    765:                                          Element *unknownEl,
                    766:                                          char* content)
1.51      cvs       767: {
                    768:    ElementType     elType;
1.65      cvs       769:    Element         elText;
1.51      cvs       770: 
                    771:    /* Create a new Invalid_element */
                    772:    elType.ElSSchema = GetXMLSSchema (XHTML_TYPE, context->doc);
                    773:    elType.ElTypeNum = HTML_EL_Unknown_namespace;
1.65      cvs       774:    *unknownEl = TtaNewElement (context->doc, elType);
                    775:    if (*unknownEl != NULL)
1.51      cvs       776:      {
1.65      cvs       777:        XmlSetElemLineNumber (*unknownEl);
                    778:        InsertXmlElement (unknownEl);
1.51      cvs       779:        context->lastElementClosed = TRUE;
                    780:        elType.ElTypeNum = HTML_EL_TEXT_UNIT;
                    781:        elText = TtaNewElement (context->doc, elType);
                    782:        XmlSetElemLineNumber (elText);
1.65      cvs       783:        TtaInsertFirstChild (&elText, *unknownEl, context->doc);
1.51      cvs       784:        TtaSetTextContent (elText, content, context->language, context->doc);
                    785:        TtaSetAccessRight (elText, ReadOnly, context->doc);
                    786:      }
                    787: }
                    788: 
                    789: /*----------------------------------------------------------------------
1.30      cvs       790:    CreateHTMLAttribute
                    791:    create an attribute of type attrType for the element el.
                    792:   ----------------------------------------------------------------------*/
                    793: void           CreateHTMLAttribute (Element       el,
                    794:                                    AttributeType attrType,
1.46      cvs       795:                                    char*         text,
1.30      cvs       796:                                    ThotBool      isInvalid,
                    797:                                    Document      doc,
                    798:                                    Attribute    *lastAttribute,
                    799:                                    Element      *lastAttrElement)
                    800:      
                    801: {
                    802:    int         attrKind;
                    803:    int         length;
1.39      cvs       804:    char       *buffer;
1.30      cvs       805:    Attribute   attr, oldAttr;
                    806: 
                    807:    if (attrType.AttrTypeNum != 0)
                    808:      {
                    809:        oldAttr = TtaGetAttribute (el, attrType);
                    810:        if (oldAttr != NULL)
                    811:         /* this attribute already exists */
                    812:         attr = oldAttr;
                    813:        else
                    814:         /* create a new attribute and attach it to the element */
                    815:         {
                    816:           attr = TtaNewAttribute (attrType);
                    817:           TtaAttachAttribute (el, attr, doc);
                    818:         }
                    819:        *lastAttribute = attr;
                    820:        *lastAttrElement = el;
                    821: 
                    822:        TtaGiveAttributeType (attr, &attrType, &attrKind);
                    823:        if (attrKind == 0)      /* enumerate */
                    824:         TtaSetAttributeValue (attr, 1, el, doc);
                    825: 
                    826:        /* attribute BORDER without any value (ThotBool attribute) is */
                    827:        /* considered as BORDER=1 */
                    828:        if (attrType.AttrTypeNum == HTML_ATTR_Border)
                    829:         TtaSetAttributeValue (attr, 1, el, doc);
                    830: 
                    831:        if (isInvalid)
                    832:         /* Copy the name of the invalid attribute as the content */
                    833:         /* of the Invalid_attribute attribute. */
                    834:         {
1.37      cvs       835:           length = strlen (text) + 2;
1.30      cvs       836:           length += TtaGetTextAttributeLength (attr);
1.37      cvs       837:           buffer = TtaGetMemory (length + 1);
1.30      cvs       838:           TtaGiveTextAttributeValue (attr, buffer, &length);
1.37      cvs       839:           strcat (buffer, " ");
                    840:           strcat (buffer, text);
1.30      cvs       841:           TtaSetAttributeText (attr, buffer, el, doc);
                    842:           TtaFreeMemory (buffer);
                    843:         }
                    844:      }
                    845: }
                    846: 
                    847: /*----------------------------------------------------------------------
                    848:    HTMLTypeAttrValue
                    849:    Value val has been read for the HTML attribute TYPE.
                    850:    Create a child for the current Thot element INPUT accordingly.
                    851:   ----------------------------------------------------------------------*/
1.46      cvs       852: void               HTMLTypeAttrValue (char       *val,
1.30      cvs       853:                                      Attribute   lastAttribute,
                    854:                                      Element     lastAttrElement,
                    855:                                      ParserData *context)
                    856: 
                    857: {
                    858:   ElementType      elType;
                    859:   Element          newChild;
                    860:   AttributeType    attrType;
                    861:   Attribute        attr;
1.39      cvs       862:   char             msgBuffer[MaxMsgLength];
1.30      cvs       863:   int              value;
                    864:   int              numberOfLinesRead;
                    865: 
                    866:   value = MapAttrValue (DummyAttribute, val);
1.91      quint     867:   if (value <= 0)
1.30      cvs       868:     {
1.37      cvs       869:       if (strlen (val) > MaxMsgLength - 40)
                    870:          val[MaxMsgLength - 40] = EOS;
                    871:       sprintf (msgBuffer, "Unknown attribute value \"type = %s\"", val);
1.42      cvs       872:       HTMLParseError (context->doc, msgBuffer);
1.30      cvs       873:       attrType.AttrSSchema = TtaGetDocumentSSchema (context->doc);
                    874:       attrType.AttrTypeNum = pHTMLAttributeMapping[0].ThotAttribute;
1.37      cvs       875:       sprintf (msgBuffer, "type=%s", val);
1.30      cvs       876:       CreateHTMLAttribute (context->lastElement, attrType, msgBuffer, TRUE,
                    877:                           context->doc, &lastAttribute, &lastAttrElement);
                    878:     }
                    879:   else
                    880:     {
                    881:       elType = TtaGetElementType (context->lastElement);
                    882:       if (elType.ElTypeNum != HTML_EL_Input)
                    883:        {
1.37      cvs       884:          if (strlen (val) > MaxMsgLength - 40)
                    885:            val[MaxMsgLength - 40] = EOS;
                    886:          sprintf (msgBuffer, "Duplicate attribute \"type = %s\"", val);
1.30      cvs       887:        }
                    888:       else
                    889:        {
                    890:          elType.ElSSchema = TtaGetDocumentSSchema (context->doc);
                    891:          elType.ElTypeNum = value;
                    892:          newChild = TtaNewTree (context->doc, elType, "");
                    893:          numberOfLinesRead = 0;
                    894:          TtaSetElementLineNumber (newChild, numberOfLinesRead);
                    895:          TtaInsertFirstChild (&newChild, context->lastElement, context->doc);
                    896:          if (value == HTML_EL_PICTURE_UNIT)
                    897:            {
                    898:              /* add the attribute IsInput to input pictures */
                    899:              attrType.AttrSSchema = elType.ElSSchema;
                    900:              attrType.AttrTypeNum = HTML_ATTR_IsInput;
                    901:              attr = TtaNewAttribute (attrType);
                    902:              TtaAttachAttribute (newChild, attr, context->doc);
                    903:            }
                    904:        }
                    905:     }
                    906: }
                    907: 
                    908: /*----------------------------------------------------------------------
                    909:    XhtmlTypeAttrValue 
                    910:    Value val has been read for the HTML attribute TYPE.
                    911:    Create a child for the current Thot element INPUT accordingly.
                    912:   ----------------------------------------------------------------------*/
1.46      cvs       913: void              XhtmlTypeAttrValue (char       *val,
1.30      cvs       914:                                      Attribute   currentAttribute,
                    915:                                      Element     lastAttrElement,
                    916:                                      ParserData *context)
                    917: 
                    918: {
                    919:   ElementType     elType;
                    920:   Element         newChild;
                    921:   AttributeType   attrType;
                    922:   Attribute       attr;
1.39      cvs       923:   char            msgBuffer[MaxMsgLength];
1.30      cvs       924:   int             value;
                    925:   ThotBool        level;
                    926: 
1.91      quint     927:   /* Look in the dummy section of the attribute value table */
1.30      cvs       928:   attrType.AttrTypeNum = DummyAttribute;
                    929:   MapHTMLAttributeValue (val, attrType, &value);
1.91      quint     930:   if (value <= 0)
                    931:     /* invalid value for the type attribute of an input element */
1.30      cvs       932:     {
1.37      cvs       933:       sprintf (msgBuffer, "Unknown attribute value \"type=%s\"", val);
1.30      cvs       934:       XmlParseError (errorParsing, msgBuffer, 0);
1.36      cvs       935:       MapHTMLAttribute ("unknown_attr", &attrType, NULL,
1.30      cvs       936:                        &level, context->doc);
1.37      cvs       937:       sprintf (msgBuffer, "type=%s", val);
1.30      cvs       938:       CreateHTMLAttribute (context->lastElement, attrType, msgBuffer, TRUE,
                    939:                           context->doc, &currentAttribute, &lastAttrElement);
                    940:     }
                    941:   else
1.91      quint     942:     /* value is the Thot type of the element to be created for this value of
                    943:        the TYPE attribute */
1.30      cvs       944:     {
                    945:       elType = TtaGetElementType (context->lastElement);
                    946:       if (elType.ElTypeNum != HTML_EL_Input)
                    947:        {
1.37      cvs       948:          sprintf (msgBuffer, "Duplicate attribute \"type = %s\"", val);
1.30      cvs       949:          XmlParseError (errorParsing, msgBuffer, 0);
                    950:        }
                    951:       else
                    952:        {
                    953:          elType.ElTypeNum = value;
                    954:          newChild = TtaNewTree (context->doc, elType, "");
                    955:          XmlSetElemLineNumber (newChild);
                    956:          TtaInsertFirstChild (&newChild, context->lastElement, context->doc);
                    957:          if (value == HTML_EL_PICTURE_UNIT)
                    958:            {
                    959:              /* add the attribute IsInput to input pictures */
                    960:              attrType.AttrSSchema = elType.ElSSchema;
                    961:              attrType.AttrTypeNum = HTML_ATTR_IsInput;
                    962:              attr = TtaNewAttribute (attrType);
                    963:              TtaAttachAttribute (newChild, attr, context->doc);
                    964:            }
                    965:        }
                    966:     }
                    967: }
                    968: 
                    969: /*----------------------------------------------------------------------
                    970:    CreateAttrWidthPercentPxl
1.79      quint     971:    an HTML attribute "width" has been created for a Table, an image,
                    972:    an Object of a HR.
1.30      cvs       973:    Create the corresponding attribute IntWidthPercent or IntWidthPxl.
                    974:    oldWidth is -1 or the old image width.
                    975:   ----------------------------------------------------------------------*/
1.58      vatton    976: void CreateAttrWidthPercentPxl (char *buffer, Element el,
                    977:                                Document doc, int oldWidth)
1.30      cvs       978: {
                    979:   AttributeType   attrTypePxl, attrTypePercent;
                    980:   Attribute       attrOld, attrNew;
                    981:   int             length, val;
1.39      cvs       982:   char            msgBuffer[MaxMsgLength];
1.79      quint     983:   ElementType    elType, childType;
                    984:   Element         origEl, child;
1.30      cvs       985:   int             w, h;
                    986:   ThotBool        isImage;
                    987: 
1.79      quint     988:   origEl = el;
1.30      cvs       989:   elType = TtaGetElementType (el);
                    990:   isImage = (elType.ElTypeNum == HTML_EL_PICTURE_UNIT ||
                    991:             elType.ElTypeNum == HTML_EL_Data_cell ||
1.79      quint     992:             elType.ElTypeNum == HTML_EL_Heading_cell ||
                    993:             elType.ElTypeNum == HTML_EL_Object);
                    994:   if (elType.ElTypeNum == HTML_EL_Object)
                    995:     /* the width attribute is attached to an Object element */
                    996:     {
                    997:       child = TtaGetFirstChild (el);
                    998:       if (child)
                    999:        {
                   1000:          childType = TtaGetElementType (child);
                   1001:          if (childType.ElTypeNum == HTML_EL_PICTURE_UNIT)
                   1002:            /* the Object element is of type image. apply the width
                   1003:               attribute to the actual image element */
                   1004:            el = child;
                   1005:        }
                   1006:     }
1.30      cvs      1007:   /* remove trailing spaces */
1.37      cvs      1008:   length = strlen (buffer) - 1;
1.30      cvs      1009:   while (length > 0 && buffer[length] <= SPACE)
                   1010:     length--;
                   1011:   attrTypePxl.AttrSSchema = TtaGetDocumentSSchema (doc);
                   1012:   attrTypePercent.AttrSSchema = TtaGetDocumentSSchema (doc);
                   1013:   attrTypePxl.AttrTypeNum = HTML_ATTR_IntWidthPxl;
                   1014:   attrTypePercent.AttrTypeNum = HTML_ATTR_IntWidthPercent;
                   1015:   /* is the last character a '%' ? */
                   1016:   if (buffer[length] == '%')
                   1017:     {
                   1018:       /* remove IntWidthPxl */
                   1019:       attrOld = TtaGetAttribute (el, attrTypePxl);
                   1020:       /* update IntWidthPercent */
                   1021:       attrNew = TtaGetAttribute (el, attrTypePercent);
                   1022:       if (attrNew == NULL)
                   1023:        {
                   1024:          attrNew = TtaNewAttribute (attrTypePercent);
                   1025:          TtaAttachAttribute (el, attrNew, doc);
                   1026:        }
                   1027:       else if (isImage && oldWidth == -1)
                   1028:        {
                   1029:          if (attrOld == NULL)
                   1030:            oldWidth = TtaGetAttributeValue (attrNew);
                   1031:          else
                   1032:            oldWidth = TtaGetAttributeValue (attrOld);
                   1033:        }
                   1034:     }
                   1035:   else
                   1036:     {
                   1037:       /* remove IntWidthPercent */
                   1038:       attrOld = TtaGetAttribute (el, attrTypePercent);
                   1039:       /* update IntWidthPxl */
                   1040:       attrNew = TtaGetAttribute (el, attrTypePxl);
                   1041:       if (attrNew == NULL)
                   1042:        {
                   1043:          attrNew = TtaNewAttribute (attrTypePxl);
                   1044:          TtaAttachAttribute (el, attrNew, doc);
                   1045:        }
                   1046:       else if (isImage && oldWidth == -1)
                   1047:        {
                   1048:          TtaGiveBoxSize (el, doc, 1, UnPixel, &w, &h);
                   1049:          if (attrOld == NULL)
                   1050:            oldWidth = w * TtaGetAttributeValue (attrNew) / 100;
                   1051:          else
                   1052:            oldWidth = w * TtaGetAttributeValue (attrOld) / 100;          
                   1053:        }
                   1054:     }
                   1055: 
                   1056:   if (attrOld != NULL)
                   1057:     TtaRemoveAttribute (el, attrOld, doc);
1.43      cvs      1058:   if (sscanf (buffer, "%d", &val))
1.30      cvs      1059:     TtaSetAttributeValue (attrNew, val, el, doc);
                   1060:   else
                   1061:     /* its not a number. Delete attribute and send an error message */
                   1062:     {
                   1063:     TtaRemoveAttribute (el, attrNew, doc);
1.37      cvs      1064:     if (strlen (buffer) > MaxMsgLength - 30)
1.30      cvs      1065:         buffer[MaxMsgLength - 30] = EOS;
1.37      cvs      1066:     sprintf (msgBuffer, "Invalid attribute value \"%s\"", buffer);
1.42      cvs      1067:     HTMLParseError (doc, msgBuffer);
1.30      cvs      1068:     }
                   1069:   if (isImage)
1.79      quint    1070:     UpdateImageMap (origEl, doc, oldWidth, -1);
1.30      cvs      1071: }
                   1072: 
                   1073: /*----------------------------------------------------------------------
1.58      vatton   1074:    CreateAttrHeightPercentPxl
1.79      quint    1075:    an HTML attribute "width" has been created for a Table, an image,
                   1076:    an Object or a HR.
1.58      vatton   1077:    Create the corresponding attribute IntHeightPercent or IntHeightPxl.
                   1078:    oldHeight is -1 or the old image width.
                   1079:   ----------------------------------------------------------------------*/
                   1080: void CreateAttrHeightPercentPxl (char *buffer, Element el,
                   1081:                                Document doc, int oldHeight)
                   1082: {
                   1083:   AttributeType   attrTypePxl, attrTypePercent;
                   1084:   Attribute       attrOld, attrNew;
                   1085:   int             length, val;
                   1086:   char            msgBuffer[MaxMsgLength];
1.79      quint    1087:   ElementType    elType, childType;
                   1088:   Element         origEl, child;
1.58      vatton   1089:   int             w, h;
                   1090:   ThotBool        isImage;
                   1091: 
1.79      quint    1092:   origEl = el;
1.58      vatton   1093:   elType = TtaGetElementType (el);
                   1094:   isImage = (elType.ElTypeNum == HTML_EL_PICTURE_UNIT ||
                   1095:             elType.ElTypeNum == HTML_EL_Data_cell ||
1.79      quint    1096:             elType.ElTypeNum == HTML_EL_Heading_cell ||
                   1097:             elType.ElTypeNum == HTML_EL_Object);
                   1098:   if (elType.ElTypeNum == HTML_EL_Object)
                   1099:     /* the height attribute is attached to an Object element */
                   1100:     {
                   1101:       child = TtaGetFirstChild (el);
1.81      cvs      1102:       if (!child)
                   1103:        return;
                   1104:       else
1.79      quint    1105:        {
                   1106:          childType = TtaGetElementType (child);
                   1107:          if (childType.ElTypeNum == HTML_EL_PICTURE_UNIT)
                   1108:            /* the Object element is of type image. apply the width
                   1109:               attribute to the actual image element */
                   1110:            el = child;
1.81      cvs      1111:          else
                   1112:            return;
1.79      quint    1113:        }
                   1114:     }
1.58      vatton   1115:   /* remove trailing spaces */
                   1116:   length = strlen (buffer) - 1;
                   1117:   while (length > 0 && buffer[length] <= SPACE)
                   1118:     length--;
                   1119:   attrTypePxl.AttrSSchema = TtaGetDocumentSSchema (doc);
                   1120:   attrTypePercent.AttrSSchema = TtaGetDocumentSSchema (doc);
                   1121:   attrTypePxl.AttrTypeNum = HTML_ATTR_IntHeightPxl;
                   1122:   attrTypePercent.AttrTypeNum = HTML_ATTR_IntHeightPercent;
                   1123:   /* is the last character a '%' ? */
                   1124:   if (buffer[length] == '%')
                   1125:     {
                   1126:       /* remove IntHeightPxl */
                   1127:       attrOld = TtaGetAttribute (el, attrTypePxl);
                   1128:       /* update IntHeightPercent */
                   1129:       attrNew = TtaGetAttribute (el, attrTypePercent);
                   1130:       if (attrNew == NULL)
                   1131:        {
                   1132:          attrNew = TtaNewAttribute (attrTypePercent);
                   1133:          TtaAttachAttribute (el, attrNew, doc);
                   1134:        }
                   1135:       else if (isImage && oldHeight == -1)
                   1136:        {
                   1137:          if (attrOld == NULL)
                   1138:            oldHeight = TtaGetAttributeValue (attrNew);
                   1139:          else
                   1140:            oldHeight = TtaGetAttributeValue (attrOld);
                   1141:        }
                   1142:     }
                   1143:   else
                   1144:     {
                   1145:       /* remove IntHeightPercent */
                   1146:       attrOld = TtaGetAttribute (el, attrTypePercent);
                   1147:       /* update IntHeightPxl */
                   1148:       attrNew = TtaGetAttribute (el, attrTypePxl);
                   1149:       if (attrNew == NULL)
                   1150:        {
                   1151:          attrNew = TtaNewAttribute (attrTypePxl);
                   1152:          TtaAttachAttribute (el, attrNew, doc);
                   1153:        }
                   1154:       else if (isImage && oldHeight == -1)
                   1155:        {
                   1156:          TtaGiveBoxSize (el, doc, 1, UnPixel, &w, &h);
                   1157:          if (attrOld == NULL)
                   1158:            oldHeight = w * TtaGetAttributeValue (attrNew) / 100;
                   1159:          else
                   1160:            oldHeight = w * TtaGetAttributeValue (attrOld) / 100;         
                   1161:        }
                   1162:     }
                   1163: 
                   1164:   if (attrOld != NULL)
                   1165:     TtaRemoveAttribute (el, attrOld, doc);
                   1166:   if (sscanf (buffer, "%d", &val))
                   1167:     TtaSetAttributeValue (attrNew, val, el, doc);
                   1168:   else
                   1169:     /* its not a number. Delete attribute and send an error message */
                   1170:     {
                   1171:     TtaRemoveAttribute (el, attrNew, doc);
                   1172:     if (strlen (buffer) > MaxMsgLength - 30)
                   1173:         buffer[MaxMsgLength - 30] = EOS;
                   1174:     sprintf (msgBuffer, "Invalid attribute value \"%s\"", buffer);
                   1175:     HTMLParseError (doc, msgBuffer);
                   1176:     }
                   1177:   if (isImage)
1.79      quint    1178:     UpdateImageMap (origEl, doc, oldHeight, -1);
1.58      vatton   1179: }
                   1180: 
                   1181: /*----------------------------------------------------------------------
1.91      quint    1182:    CreateAttrIntAreaSize
                   1183:    an HTML attribute "size" has been created or modified for a input element.
                   1184:    Create or update the corresponding attribute IntAreaSize.
                   1185:   ----------------------------------------------------------------------*/
                   1186: void CreateAttrIntAreaSize (int value, Element el, Document doc)
                   1187: {
                   1188:   AttributeType   attrType;
                   1189:   Attribute       attr;
                   1190:   ElementType    elType;
                   1191: 
                   1192:   elType = TtaGetElementType (el);
                   1193:   attrType.AttrSSchema = elType.ElSSchema;
                   1194:   attrType.AttrTypeNum = HTML_ATTR_IntAreaSize;
                   1195:   attr = TtaGetAttribute (el, attrType);
                   1196:   if (!attr)
                   1197:     {
                   1198:       attr = TtaNewAttribute (attrType);
                   1199:       TtaAttachAttribute (el, attr, doc);
                   1200:     }
                   1201:   /* the presentation rule associated with attribute IntAreaSize expresses
                   1202:      the element width in "em". Convert the value into em */
                   1203:   TtaSetAttributeValue (attr, (int) (value * 0.55), el, doc);
                   1204: }
                   1205: 
                   1206: /*----------------------------------------------------------------------
1.30      cvs      1207:    CreateAttrIntSize
                   1208:    an HTML attribute "size" has been created for a Font element.
                   1209:    Create the corresponding internal attribute.
                   1210:   ----------------------------------------------------------------------*/
1.46      cvs      1211: void              CreateAttrIntSize (char *buffer, Element el, Document doc)
1.30      cvs      1212: 
                   1213: {
                   1214:    AttributeType  attrType;
                   1215:    int            val, ind, factor, delta;
                   1216:    Attribute      attr;
1.37      cvs      1217:    char         msgBuffer[MaxMsgLength];
1.30      cvs      1218: 
                   1219:    /* is the first character a '+' or a '-' ? */
                   1220:    ind = 0;
                   1221:    factor = 1;
                   1222:    delta = 0;
                   1223:    if (buffer[0] == '+')
                   1224:      {
                   1225:        attrType.AttrTypeNum = HTML_ATTR_IntSizeIncr;
                   1226:        ind++;
1.90      vatton   1227:        factor = 1;
1.30      cvs      1228:      }
                   1229:    else if (buffer[0] == '-')
                   1230:      {
                   1231:        attrType.AttrTypeNum = HTML_ATTR_IntSizeDecr;
                   1232:        ind++;
1.90      vatton   1233:        factor = 1;
1.30      cvs      1234:      }
                   1235:    else
                   1236:      {
                   1237:        attrType.AttrTypeNum = HTML_ATTR_IntSizeRel;
                   1238:        delta = 1;
                   1239:      }
                   1240:    attrType.AttrSSchema = TtaGetDocumentSSchema (doc);
                   1241:    attr = TtaGetAttribute (el, attrType);
1.43      cvs      1242:    if (sscanf (&buffer[ind], "%d", &val))
1.30      cvs      1243:      {
                   1244:        val = val * factor + delta;
                   1245:        if (attr == NULL)
                   1246:         {
                   1247:           /* this attribute doesn't exist, create it */
                   1248:           attr = TtaNewAttribute (attrType);
                   1249:           TtaAttachAttribute (el, attr, doc);
                   1250:         }
                   1251:        TtaSetAttributeValue (attr, val, el, doc);
                   1252:      }
                   1253:    else
                   1254:      /* its not a number. Delete attribute and send an error message */
                   1255:      {
                   1256:        if (attr)
                   1257:          TtaRemoveAttribute (el, attr, doc);
1.37      cvs      1258:        if (strlen (buffer) > MaxMsgLength - 30)
1.30      cvs      1259:          buffer[MaxMsgLength - 30] = EOS;
1.37      cvs      1260:        sprintf (msgBuffer, "Invalid attribute value \"%s\"", buffer);
1.42      cvs      1261:        HTMLParseError (doc, msgBuffer);
1.30      cvs      1262:      }
                   1263: }
                   1264: /*----------------------------------------------------------------------
                   1265:    EndOfHTMLAttributeValue
                   1266:    Filling of an HTML attribute value
                   1267:   ----------------------------------------------------------------------*/
1.48      vatton   1268: void EndOfHTMLAttributeValue (char *attrValue,
                   1269:                              AttributeMapping *lastMappedAttr,
                   1270:                              Attribute currentAttribute,
                   1271:                              Element lastAttrElement,
                   1272:                              ThotBool UnknownAttr,
                   1273:                              ParserData *context,
                   1274:                              ThotBool isXML)
1.30      cvs      1275: {
1.48      vatton   1276:   AttributeType   attrType, attrType1;
                   1277:   Attribute       attr;
1.79      quint    1278:   ElementType    elType;
1.48      vatton   1279:   Element         child, root;
                   1280:   Language        lang;
                   1281:   char            translation;
                   1282:   char            shape;
                   1283:   char           *buffer;
                   1284:   char           *attrName;
                   1285:   char            msgBuffer[MaxMsgLength];
                   1286:   int             val;
                   1287:   int             length;
                   1288:   int             attrKind;
                   1289:   ThotBool        done = FALSE;
1.88      vatton   1290:   ThotBool            loadcss;
1.30      cvs      1291: 
1.48      vatton   1292:   /* treatments of some particular HTML attributes */
                   1293:   if (!strcmp (lastMappedAttr->XMLattribute, "style"))
                   1294:     {
                   1295:       TtaSetAttributeText (currentAttribute, attrValue,
                   1296:                           lastAttrElement, context->doc);
1.88      vatton   1297:       /* check if we have to load CSS */
                   1298:       TtaGetEnvBoolean ("LOAD_CSS", &loadcss);
                   1299:       if (loadcss)
                   1300:        ParseHTMLSpecificStyle (context->lastElement, attrValue,
                   1301:                                context->doc, 100, FALSE);
1.48      vatton   1302:       done = TRUE;
                   1303:     }
                   1304:   else
                   1305:     {
                   1306:       if (!strcmp (lastMappedAttr->XMLattribute, "link"))
1.89      vatton   1307:        HTMLSetAlinkColor (context->doc, context->lastElement, attrValue);
1.48      vatton   1308:       else if (!strcmp (lastMappedAttr->XMLattribute, "alink"))
1.89      vatton   1309:        HTMLSetAactiveColor (context->doc, context->lastElement, attrValue);
1.48      vatton   1310:       else if (!strcmp (lastMappedAttr->XMLattribute, "vlink"))
1.89      vatton   1311:        HTMLSetAvisitedColor (context->doc, context->lastElement, attrValue);
1.48      vatton   1312:     }
1.30      cvs      1313: 
1.48      vatton   1314:   if (!done)
                   1315:     {
                   1316:       val = 0;
                   1317:       translation = lastMappedAttr->AttrOrContent;
                   1318:       switch (translation)
                   1319:        {
                   1320:        case 'C':       /* Content */
                   1321:          child = PutInContent (attrValue, context);
                   1322:          if (child != NULL)
                   1323:            TtaAppendTextContent (child, "\" ", context->doc);
                   1324:          break;
                   1325:          
                   1326:        case 'A':
                   1327:          if (currentAttribute != NULL)
                   1328:            {
                   1329:              TtaGiveAttributeType (currentAttribute, &attrType, &attrKind);
                   1330:              switch (attrKind)
                   1331:                {
                   1332:                case 0: /* enumerate */
                   1333:                  if (isXML)
                   1334:                    MapHTMLAttributeValue (attrValue, attrType, &val);
                   1335:                  else
                   1336:                    val = MapAttrValue (lastMappedAttr->ThotAttribute,
1.40      cvs      1337:                                        attrValue);
1.48      vatton   1338:                  if (val < 0)
                   1339:                    {
                   1340:                      TtaGiveAttributeType (currentAttribute,
                   1341:                                            &attrType, &attrKind);
                   1342:                      attrName = TtaGetAttributeName (attrType);
                   1343:                      sprintf (msgBuffer,
1.51      cvs      1344:                               "Invalid attribute value \"%s = %s\"",
1.48      vatton   1345:                               attrName, attrValue);
                   1346:                      if (isXML)
                   1347:                        XmlParseError (errorParsing, msgBuffer, 0);
                   1348:                      else
1.84      quint    1349:                        /* we are parsing an HTML file, not an XHTML file */
1.51      cvs      1350:                        {
1.84      quint    1351:                          /* generate an error message in the log */
1.51      cvs      1352:                          HTMLParseError (context->doc, msgBuffer);
1.84      quint    1353:                          /* special case for value POLYGON of attribute 
                   1354:                             shape (AREA element) */
                   1355:                          if (attrType.AttrTypeNum == HTML_ATTR_shape &&
                   1356:                              strcasecmp (attrValue, "POLYGON") == 0)
                   1357:                            {
                   1358:                              val = HTML_ATTR_shape_VAL_polygon;
                   1359:                              /* interpret it as if it were "poly" */
                   1360:                              TtaSetAttributeValue (currentAttribute, val,
                   1361:                                          lastAttrElement, context->doc);
                   1362:                            }
                   1363:                          else
                   1364:                            /* remove the attribute and replace it by an */
                   1365:                            /* Invalid_attribute (not for XHTML) */
                   1366:                            {
                   1367:                              TtaRemoveAttribute (lastAttrElement,
1.51      cvs      1368:                                              currentAttribute, context->doc);
1.84      quint    1369:                              attrType.AttrSSchema = 
                   1370:                                         TtaGetDocumentSSchema (context->doc);
                   1371:                              attrType.AttrTypeNum =
                   1372:                                       pHTMLAttributeMapping[0].ThotAttribute;
                   1373:                              sprintf (msgBuffer, "%s=%s", attrName,attrValue);
                   1374:                              CreateHTMLAttribute (lastAttrElement, attrType,
                   1375:                                         msgBuffer, TRUE, context->doc,
                   1376:                                         &currentAttribute, &lastAttrElement);
                   1377:                            }
1.48      vatton   1378:                        }
                   1379:                    }
                   1380:                  else
                   1381:                    TtaSetAttributeValue (currentAttribute, val,
                   1382:                                          lastAttrElement, context->doc);
                   1383:                  break;
                   1384:                case 1: /* integer */
                   1385:                  if (attrType.AttrTypeNum == HTML_ATTR_Border &&
                   1386:                      !strcasecmp (attrValue, "border"))
                   1387:                    {
                   1388:                      /* border="border" for a table */
                   1389:                      val = 1;
                   1390:                      TtaSetAttributeValue (currentAttribute, val,
1.30      cvs      1391:                                            lastAttrElement, context->doc);
1.48      vatton   1392:                    }
                   1393:                  else if (sscanf (attrValue, "%d", &val))
                   1394:                    TtaSetAttributeValue (currentAttribute, val,
                   1395:                                          lastAttrElement, context->doc);
                   1396:                  else
                   1397:                    {
                   1398:                      TtaRemoveAttribute (lastAttrElement, currentAttribute,
                   1399:                                          context->doc);
                   1400:                      sprintf (msgBuffer,
                   1401:                               "Unknown attribute value \"%s\"",
                   1402:                               attrValue);
                   1403:                      if (isXML)
                   1404:                        XmlParseError (errorParsing, msgBuffer, 0);
                   1405:                      else
                   1406:                        HTMLParseError (context->doc, msgBuffer);
                   1407:                    }
                   1408:                  break;
                   1409:                case 2: /* text */
                   1410:                  if (!UnknownAttr)
                   1411:                    {
                   1412:                      TtaSetAttributeText (currentAttribute, attrValue,
                   1413:                                           lastAttrElement, context->doc);
1.55      cvs      1414:                      if (attrType.AttrTypeNum == HTML_ATTR_Language)
1.48      vatton   1415:                        {
                   1416:                          /* it's a LANG attribute value */
                   1417:                          lang = TtaGetLanguageIdFromName (attrValue);
1.70      vatton   1418:                          if (lang < 0)
1.48      vatton   1419:                            {
                   1420:                              sprintf (msgBuffer,
                   1421:                                       "warning - unsupported language: %s",
                   1422:                                       attrValue);
                   1423:                              if (isXML)
1.87      vatton   1424:                                XmlParseError (warningMessage, msgBuffer, 0);
1.48      vatton   1425:                              else
                   1426:                                HTMLParseError (context->doc, msgBuffer);
                   1427:                            }
                   1428:                          else
                   1429:                            {
                   1430:                              /* change current language */
                   1431:                              context->language = lang;
                   1432:                              if (isXML)
                   1433:                                SetLanguagInXmlStack (lang);
                   1434:                              else
                   1435:                                SetLanguagInHTMLStack (lang);
                   1436:                            }
                   1437:                          root = TtaGetRootElement (context->doc);
                   1438:                          if (lastAttrElement == root)
                   1439:                            /* it's a LANG attribute on the root element */
                   1440:                            /* set the RealLang attribute */
                   1441:                            {
                   1442:                              attrType1.AttrSSchema = TtaGetDocumentSSchema (context->doc);
                   1443:                              attrType1.AttrTypeNum = HTML_ATTR_RealLang;
                   1444:                              /* this attribute could be already present,
                   1445:                                 (lang and xml:lang attributes) */
                   1446:                              if (!TtaGetAttribute (lastAttrElement,
                   1447:                                                    attrType1))
                   1448:                                /* it's not present. Add it */
                   1449:                                {
                   1450:                                  attr = TtaNewAttribute (attrType1);
                   1451:                                  TtaAttachAttribute (lastAttrElement,
                   1452:                                                      attr, context->doc);
                   1453:                                  TtaSetAttributeValue (attr,
                   1454:                                                        HTML_ATTR_RealLang_VAL_Yes_,
                   1455:                                                        lastAttrElement,
                   1456:                                                        context->doc);
                   1457:                                }
                   1458:                            }
                   1459:                        }
                   1460:                      else if (attrType.AttrTypeNum == HTML_ATTR_accesskey)
                   1461:                        TtaAddAccessKey (context->doc, (unsigned int)attrValue[0],
                   1462:                                         lastAttrElement);
                   1463:                    }
                   1464:                  else
                   1465:                    {
1.51      cvs      1466:                      /* this is the content of an invalid attribute */
                   1467:                      /* append it to the current Invalid_attribute */
                   1468:                      if (!isXML)
                   1469:                        {
                   1470:                          length = strlen (attrValue) + 2;
                   1471:                          length += TtaGetTextAttributeLength (currentAttribute);
                   1472:                          buffer = TtaGetMemory (length + 1);
                   1473:                          TtaGiveTextAttributeValue (currentAttribute,
                   1474:                                                     buffer, &length);
                   1475:                          strcat (buffer, "=");
                   1476:                          strcat (buffer, attrValue);
                   1477:                          TtaSetAttributeText (currentAttribute, buffer,
                   1478:                                               lastAttrElement, context->doc);
                   1479:                          TtaFreeMemory (buffer);
                   1480:                        }
1.48      vatton   1481:                    }
                   1482:                  break;
                   1483:                case 3: /* reference */
                   1484:                  break;
                   1485:                }
                   1486:            }
                   1487:          break;
                   1488:          
                   1489:        case SPACE:
                   1490:          if (isXML)
                   1491:            XhtmlTypeAttrValue (attrValue, currentAttribute,
1.30      cvs      1492:                                lastAttrElement, context);
1.48      vatton   1493:          else
                   1494:            HTMLTypeAttrValue (attrValue, currentAttribute,
                   1495:                               lastAttrElement, context);
                   1496:          break;
                   1497:          
1.30      cvs      1498:         default:
                   1499:           break;
1.48      vatton   1500:        }
1.30      cvs      1501: 
                   1502:       if (lastMappedAttr->ThotAttribute == HTML_ATTR_Width__)
1.79      quint    1503:        /* HTML attribute "width" */
                   1504:        {
                   1505:          /* if it's an Object element, wait until all attributes are handled,
                   1506:             especially the data attribute that may generate the image to
                   1507:             which the width has to be applied */
                   1508:          elType = TtaGetElementType (lastAttrElement);
                   1509:          if (elType.ElTypeNum != HTML_EL_Object)
                   1510:            /* create the corresponding attribute IntWidthPercent or */
                   1511:            /* IntWidthPxl */
                   1512:            CreateAttrWidthPercentPxl (attrValue, lastAttrElement,
                   1513:                                       context->doc, -1);
                   1514:        }
1.58      vatton   1515:       else if (lastMappedAttr->ThotAttribute == HTML_ATTR_Height_)
1.79      quint    1516:        /* HTML attribute "height" */
                   1517:        {
                   1518:          /* if it's an Object element, wait until all attributes are handled,
                   1519:             especially the data attribute that may generate the image to
                   1520:             which the height has to be applied */
                   1521:          elType = TtaGetElementType (lastAttrElement);
                   1522:          if (elType.ElTypeNum != HTML_EL_Object)
                   1523:            /* create the corresponding attribute IntHeightPercent or */
                   1524:            /* IntHeightPxl */
                   1525:            CreateAttrHeightPercentPxl (attrValue, lastAttrElement,
                   1526:                                        context->doc, -1);
                   1527:        }
1.91      quint    1528:       else if (lastMappedAttr->ThotAttribute == HTML_ATTR_Area_Size)
                   1529:        /* HTML attribute "size" for an element "input" */
                   1530:        CreateAttrIntAreaSize (val, lastAttrElement, context->doc);
1.48      vatton   1531:       else if (!strcmp (lastMappedAttr->XMLattribute, "size"))
                   1532:        {
                   1533:          TtaGiveAttributeType (currentAttribute, &attrType, &attrKind);
                   1534:          if (attrType.AttrTypeNum == HTML_ATTR_Font_size)
                   1535:            CreateAttrIntSize (attrValue, lastAttrElement, context->doc);
                   1536:        }
                   1537:       else if (!strcmp (lastMappedAttr->XMLattribute, "shape"))
                   1538:        {
                   1539:          child = TtaGetFirstChild (lastAttrElement);
                   1540:          if (child != NULL)
                   1541:            {
                   1542:              switch (val)
                   1543:                {
                   1544:                case HTML_ATTR_shape_VAL_rectangle:
                   1545:                  shape = 'R';
                   1546:                  break;
                   1547:                case HTML_ATTR_shape_VAL_circle:
                   1548:                  shape = 'a';
                   1549:                  break;
                   1550:                case HTML_ATTR_shape_VAL_polygon:
                   1551:                  shape = 'p';
                   1552:                  break;
                   1553:                default:
                   1554:                  shape = SPACE;
                   1555:                  break;
                   1556:                }
                   1557:              TtaSetGraphicsShape (child, shape, context->doc);
                   1558:            }
                   1559:        }
                   1560:       else if (!strcmp (lastMappedAttr->XMLattribute, "value"))
                   1561:        {
                   1562:          elType = TtaGetElementType (lastAttrElement);
                   1563:          if (elType.ElTypeNum == HTML_EL_Text_Input ||
                   1564:              elType.ElTypeNum == HTML_EL_Password_Input ||
                   1565:              elType.ElTypeNum == HTML_EL_File_Input ||
                   1566:              elType.ElTypeNum == HTML_EL_Input)
                   1567:            /* create a Default_Value attribute with the same content */
                   1568:            {
                   1569:              attrType1.AttrSSchema = attrType.AttrSSchema;
                   1570:              attrType1.AttrTypeNum = HTML_ATTR_Default_Value;
                   1571:              attr = TtaNewAttribute (attrType1);
                   1572:              TtaAttachAttribute (lastAttrElement, attr, context->doc);
                   1573:              TtaSetAttributeText (attr, attrValue,
                   1574:                                   lastAttrElement, context->doc);
                   1575:            }
                   1576:        }
1.30      cvs      1577:       else
1.48      vatton   1578:        {
                   1579:          /* Some HTML attributes are equivalent to a CSS property:      */
                   1580:          /*      background     ->                   background         */
                   1581:          /*      bgcolor        ->                   background         */
                   1582:          /*      text           ->                   color              */
                   1583:          /*      color          ->                   color              */
                   1584:          if (!strcmp (lastMappedAttr->XMLattribute, "background"))
                   1585:            {
                   1586:              if (strlen (attrValue) > MaxMsgLength - 30)
                   1587:                attrValue[MaxMsgLength - 30] = EOS;
1.76      vatton   1588:              HTMLSetBackgroundImage (context->doc, context->lastElement,
1.85      vatton   1589:                                      REPEAT, attrValue, FALSE);
1.48      vatton   1590:            }
                   1591:          else if (!strcmp (lastMappedAttr->XMLattribute, "bgcolor"))
1.76      vatton   1592:            HTMLSetBackgroundColor (context->doc, context->lastElement,
                   1593:                                    attrValue);
1.48      vatton   1594:          else if (!strcmp (lastMappedAttr->XMLattribute, "text") ||
                   1595:                   !strcmp (lastMappedAttr->XMLattribute, "color"))
                   1596:            HTMLSetForegroundColor (context->doc,
                   1597:                                    context->lastElement, attrValue);
                   1598:        }
                   1599:     }
1.30      cvs      1600: }
                   1601: 
                   1602: /*----------------------------------------------------------------------
1.16      cvs      1603:    MapHTMLAttributeValue
1.2       cvs      1604:    Search in the Attribute Value Mapping Table the entry for the attribute
1.66      vatton   1605:    ThotAtt and its value attVal. Returns the corresponding Thot value.
1.1       cvs      1606:   ----------------------------------------------------------------------*/
1.66      vatton   1607: void MapHTMLAttributeValue (char *attVal, AttributeType attrType, int *value)
1.1       cvs      1608: {
1.66      vatton   1609:   MapXMLAttributeValue (XHTML_TYPE, attVal, attrType, value);
1.1       cvs      1610: }

Webmaster