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