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