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