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