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