Annotation of Amaya/amaya/XHTMLbuilder.c, revision 1.103
1.1 cvs 1: /*
2: *
1.101 vatton 3: * (c) COPYRIGHT INRIA and W3C, 1996-2004
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"
34: #include "UIcss_f.h"
1.13 cvs 35: #include "styleparser_f.h"
1.2 cvs 36: #include "XHTMLbuilder_f.h"
1.13 cvs 37: #include "Xml2thot_f.h"
1.1 cvs 38:
1.30 cvs 39: #define MaxMsgLength 200
40:
1.47 cvs 41: /* Elements that cannot contain text as immediate children.
42: When some text is present in the HTML file it must be
43: surrounded by a Pseudo_paragraph element */
44: static int NoTextChild[] =
45: {
46: HTML_EL_Document, HTML_EL_HTML, HTML_EL_HEAD, HTML_EL_BODY,
47: HTML_EL_Definition_List, HTML_EL_Block_Quote, HTML_EL_Directory,
48: HTML_EL_Form, HTML_EL_Menu, HTML_EL_FIELDSET,
49: HTML_EL_Numbered_List, HTML_EL_Option_Menu,
50: HTML_EL_Unnumbered_List, HTML_EL_Definition, HTML_EL_List_Item,
51: HTML_EL_MAP, HTML_EL_map, HTML_EL_Applet,
52: HTML_EL_Object, HTML_EL_IFRAME, HTML_EL_NOFRAMES,
53: HTML_EL_Division, HTML_EL_Center, HTML_EL_NOSCRIPT,
54: HTML_EL_Data_cell, HTML_EL_Heading_cell,
55: 0};
56:
1.28 cvs 57: /* Define a pointer to let parser functions access the HTML entity table */
58: extern XmlEntity *pXhtmlEntityTable;
1.6 cvs 59:
1.30 cvs 60: /* maximum size of error messages */
61: #define MaxMsgLength 200
62:
1.6 cvs 63: /*----------------------------------------------------------------------
1.15 cvs 64: ParseCharset:
1.6 cvs 65: Parses the element HTTP-EQUIV and looks for the charset value.
66: ----------------------------------------------------------------------*/
1.30 cvs 67: void ParseCharset (Element el, Document doc)
68:
1.6 cvs 69: {
1.15 cvs 70: AttributeType attrType;
71: Attribute attr;
72: SSchema docSSchema;
73: CHARSET charset;
1.39 cvs 74: char *text, *text2, *ptrText, *str;
75: char charsetname[MAX_LENGTH];
1.15 cvs 76: int length;
1.6 cvs 77: int pos, index = 0;
78:
1.15 cvs 79: charset = TtaGetDocumentCharset (doc);
80: if (charset != UNDEFINED_CHARSET)
81: /* the charset was already defined by the http header */
82: return;
1.6 cvs 83:
84: docSSchema = TtaGetDocumentSSchema (doc);
85: attrType.AttrSSchema = docSSchema;
86: attrType.AttrTypeNum = HTML_ATTR_http_equiv;
87: attr = TtaGetAttribute (el, attrType);
88: if (attr != NULL)
89: {
90: /* There is a HTTP-EQUIV attribute */
91: length = TtaGetTextAttributeLength (attr);
92: if (length > 0)
93: {
1.100 gully 94: text = (char *)TtaGetMemory (length + 1);
1.6 cvs 95: TtaGiveTextAttributeValue (attr, text, &length);
1.37 cvs 96: if (!strcasecmp (text, "content-type"))
1.6 cvs 97: {
98: attrType.AttrTypeNum = HTML_ATTR_meta_content;
99: attr = TtaGetAttribute (el, attrType);
100: if (attr != NULL)
101: {
102: length = TtaGetTextAttributeLength (attr);
103: if (length > 0)
104: {
1.100 gully 105: text2 = (char *)TtaGetMemory (length + 1);
1.6 cvs 106: TtaGiveTextAttributeValue (attr, text2, &length);
107: ptrText = text2;
108: while (*ptrText)
109: {
1.53 vatton 110: *ptrText = tolower (*ptrText);
1.6 cvs 111: ptrText++;
112: }
113:
1.37 cvs 114: str = strstr (text2, "charset=");
1.6 cvs 115: if (str)
116: {
117: pos = str - text2 + 8;
1.37 cvs 118: while (text2[pos] != SPACE &&
119: text2[pos] != TAB && text2[pos] != EOS)
1.6 cvs 120: charsetname[index++] = text2[pos++];
1.37 cvs 121: charsetname[index] = EOS;
1.15 cvs 122: charset = TtaGetCharset (charsetname);
123: if (charset != UNDEFINED_CHARSET)
1.77 cvs 124: TtaSetDocumentCharset (doc, charset, FALSE);
1.6 cvs 125: }
126: TtaFreeMemory (text2);
127: }
128: }
129: }
130: TtaFreeMemory (text);
131: }
132: }
133: }
134:
1.23 cvs 135: /*----------------------------------------------------------------------
1.47 cvs 136: XhtmlCannotContainText
137: Return TRUE if element el is a block element.
138: ----------------------------------------------------------------------*/
139: ThotBool XhtmlCannotContainText (ElementType elType)
140:
141: {
142: int i;
143: ThotBool ret;
144:
145: if (strcmp (TtaGetSSchemaName (elType.ElSSchema), "HTML"))
146: /* not an HTML element */
147: ret = TRUE;
148: else
149: {
150: ret = FALSE;
151: i = 0;
152: while (NoTextChild[i] > 0 && NoTextChild[i] != elType.ElTypeNum)
153: i++;
154: if (NoTextChild[i] == elType.ElTypeNum)
155: ret = TRUE;
156: }
157: return ret;
1.23 cvs 158: }
159:
1.6 cvs 160: /*----------------------------------------------------------------------
161: XhtmlElementComplete
1.20 cvs 162: Complete Xhtml elements.
1.6 cvs 163: Check its attributes and its contents.
164: ----------------------------------------------------------------------*/
1.99 cvs 165: void XhtmlElementComplete (ParserData *context, Element el, int *error)
1.30 cvs 166:
167: {
1.72 cvs 168: Document doc;
1.30 cvs 169: ElementType elType, newElType, childType;
170: Element constElem, child, desc, leaf, prev, next, last,
1.62 quint 171: elFrames, lastFrame, lastChild, parent, picture, content;
1.30 cvs 172: Attribute attr;
173: AttributeType attrType;
174: Language lang;
1.41 cvs 175: char *text;
1.39 cvs 176: char lastChar[2];
1.79 quint 177: char *name1, *data;
1.30 cvs 178: int length;
179: SSchema docSSchema;
1.62 quint 180: ThotBool isImage;
1.6 cvs 181:
182: *error = 0;
1.72 cvs 183: doc = context->doc;
1.6 cvs 184: docSSchema = TtaGetDocumentSSchema (doc);
185:
186: elType = TtaGetElementType (el);
1.96 quint 187: newElType.ElSSchema = elType.ElSSchema;
188:
1.97 quint 189: if (elType.ElTypeNum != HTML_EL_Text_Area &&
190: IsXMLElementInline (elType, doc))
1.96 quint 191: /* It's an inline element. If it is empty, insert a Basic_Elem to allow
192: the user to put the selection within this element */
1.97 quint 193: /* Don't do it for a Text_Area, as a Inserted_Text element has to be
194: created (see below) */
1.96 quint 195: {
196: child = TtaGetFirstChild (el);
197: if (child == NULL)
198: /* it's an empty inline element */
199: /* insert a Basic_Elem element in the element */
200: {
201: newElType.ElTypeNum = HTML_EL_Basic_Elem;
202: child = TtaNewTree (doc, newElType, "");
203: TtaInsertFirstChild (&child, el, doc);
204: }
205: }
206: else
207: /* It's a block-level element. Is it within a character-level element? */
208: if (elType.ElTypeNum != HTML_EL_Comment_ &&
209: elType.ElTypeNum != HTML_EL_XMLPI)
1.6 cvs 210: BlockInCharLevelElem (el);
211:
212: switch (elType.ElTypeNum)
213: {
1.62 quint 214: case HTML_EL_Object: /* it's an object */
1.79 quint 215: data = NULL;
1.62 quint 216: isImage = FALSE;
217: /* is there a type attribute on the object element? */
218: attrType.AttrSSchema = elType.ElSSchema;
219: attrType.AttrTypeNum = HTML_ATTR_Object_type;
1.6 cvs 220: attr = TtaGetAttribute (el, attrType);
1.62 quint 221: if (attr)
222: /* there is a type attribute. Get its value to see if the object
223: represents an image */
1.6 cvs 224: {
225: length = TtaGetTextAttributeLength (attr);
226: if (length > 0)
227: {
1.100 gully 228: name1 = (char *)TtaGetMemory (length + 1);
1.6 cvs 229: TtaGiveTextAttributeValue (attr, name1, &length);
1.68 kahan 230: if (!strcmp (name1, AM_MATHML_MIME_TYPE) ||
1.62 quint 231: !strcmp (name1, "application/postscript") ||
232: !strcmp (name1, "image/x-bitmap") ||
233: !strcmp (name1, "image/x-xpixmap") ||
234: !strcmp (name1, "image/gif") ||
235: !strcmp (name1, "image/jpeg") ||
236: !strcmp (name1, "image/png") ||
1.67 kahan 237: !strcmp (name1, "image/svg") ||
1.83 cvs 238: !strcmp (name1, AM_SVG_MIME_TYPE) ||
239: !strcmp (name1, AM_XHTML_MIME_TYPE) ||
240: !strcmp (name1, "text/html") ||
241: !strcmp (name1, "text/htm") ||
242: !strcmp (name1, AM_GENERIC_XML_MIME_TYPE))
1.62 quint 243: isImage = TRUE;
244: TtaFreeMemory (name1);
245: }
246: }
1.79 quint 247:
248: attrType.AttrTypeNum = HTML_ATTR_data;
249: attr = TtaGetAttribute (el, attrType);
250: if (attr)
251: /* the object has a data attribute */
252: {
253: length = TtaGetTextAttributeLength (attr);
254: if (length > 0)
255: {
1.100 gully 256: data = (char *)TtaGetMemory (length + 1);
1.79 quint 257: TtaGiveTextAttributeValue (attr, data, &length);
258: if (!isImage)
259: if (!strcmp (&data[length-3], "mml") ||
260: !strcmp (&data[length-3], "gif") ||
261: !strcmp (&data[length-3], "jpg") ||
262: !strcmp (&data[length-4], "jpeg") ||
263: !strcmp (&data[length-3], "png") ||
264: !strcmp (&data[length-3], "svg") ||
1.80 cvs 265: !strcmp (&data[length-4], "svgz") ||
1.83 cvs 266: !strcmp (&data[length-3], "htm") ||
267: !strcmp (&data[length-4], "html") ||
268: !strcmp (&data[length-3], "xml"))
1.79 quint 269: isImage = TRUE;
270: }
271: }
1.62 quint 272: picture = NULL; /* no PICTURE element yet */
273: child = TtaGetFirstChild (el);
274: if (isImage)
275: /* the object represents an image. We need a PICTURE element as
276: child of the object to hold the image */
277: {
278: if (child)
279: {
280: elType = TtaGetElementType (child);
281: if (elType.ElTypeNum == HTML_EL_PICTURE_UNIT)
282: /* there is already a PICTURE element */
283: picture = child;
284: }
1.79 quint 285: /* if the object element has no PICTURE element as its first child
1.62 quint 286: create one */
287: if (!picture)
288: {
289: elType.ElTypeNum = HTML_EL_PICTURE_UNIT;
290: picture = TtaNewTree (doc, elType, "");
291: if (child)
292: TtaInsertSibling (picture, child, TRUE, doc);
293: else
294: TtaInsertFirstChild (&picture, el, doc);
295: child = picture;
296: }
297: /* copy attribute data of the object into the SRC attribute of
298: the PICTURE element */
1.79 quint 299: if (data)
300: /* the object has a data attribute */
301: {
302: attrType.AttrTypeNum = HTML_ATTR_SRC;
303: attr = TtaGetAttribute (picture, attrType);
304: if (attr == NULL)
305: {
306: attr = TtaNewAttribute (attrType);
307: TtaAttachAttribute (picture, attr, doc);
308: }
309: TtaSetAttributeText (attr, data, picture, doc);
310: }
311: attrType.AttrTypeNum = HTML_ATTR_Height_;
1.62 quint 312: attr = TtaGetAttribute (el, attrType);
313: if (attr)
1.79 quint 314: /* the Object has a height attribute. Applies it to the
315: picture element */
316: {
317: length = TtaGetTextAttributeLength (attr);
318: if (length > 0)
319: {
1.100 gully 320: text = (char *)TtaGetMemory (length + 1);
1.79 quint 321: TtaGiveTextAttributeValue (attr, text, &length);
322: /* create the corresponding attribute IntHeightPercent or */
323: /* IntHeightPxl */
324: CreateAttrHeightPercentPxl (text, el, doc, -1);
325: TtaFreeMemory (text);
326: }
327: }
328: attrType.AttrTypeNum = HTML_ATTR_Width__;
329: attr = TtaGetAttribute (el, attrType);
330: if (attr)
331: /* the Object has a width attribute. Applies it to the
332: picture element */
1.62 quint 333: {
334: length = TtaGetTextAttributeLength (attr);
335: if (length > 0)
1.6 cvs 336: {
1.100 gully 337: text = (char *)TtaGetMemory (length + 1);
1.79 quint 338: TtaGiveTextAttributeValue (attr, text, &length);
339: /* create the corresponding attribute IntWidthPercent or */
340: /* IntWidthPxl */
341: CreateAttrWidthPercentPxl (text, el, doc, -1);
342: TtaFreeMemory (text);
1.6 cvs 343: }
344: }
345: }
346: /* is the Object_Content element already created ? */
1.62 quint 347: if (child)
348: /* the object element has at least 1 child element */
349: {
350: content = NULL;
351: desc = child;
1.6 cvs 352: elType = TtaGetElementType (desc);
1.62 quint 353: if (elType.ElTypeNum != HTML_EL_Object_Content)
354: {
355: TtaNextSibling(&desc);
356: if (desc)
357: elType = TtaGetElementType (desc);
358: }
359: /* is it the Object_Content element ? */
360: if (elType.ElTypeNum == HTML_EL_Object_Content)
361: content = desc;
362: else
1.6 cvs 363: {
1.62 quint 364: /* create an Object_Content element */
365: elType.ElTypeNum = HTML_EL_Object_Content;
366: content = TtaNewElement (doc, elType);
367: if (picture)
368: TtaInsertSibling (content, picture, FALSE, doc);
369: else
370: TtaInsertSibling (content, child, TRUE, doc);
371: /* move previous existing children into Object_Content */
1.6 cvs 372: child = TtaGetLastChild(el);
1.62 quint 373: while (child != content)
374: {
375: TtaRemoveTree (child, doc);
376: TtaInsertFirstChild (&child, content, doc);
377: child = TtaGetLastChild(el);
378: }
379: }
1.6 cvs 380: }
1.79 quint 381: if (data)
382: TtaFreeMemory (data);
1.6 cvs 383: break;
1.62 quint 384:
1.6 cvs 385: case HTML_EL_Unnumbered_List:
386: case HTML_EL_Numbered_List:
387: case HTML_EL_Menu:
388: case HTML_EL_Directory:
389: /* It's a List element. It should only have List_Item children.
390: If it has List element chidren, move these List elements
391: within their previous List_Item sibling. This is to fix
392: a bug in document generated by Mozilla. */
393: prev = NULL;
394: next = NULL;
395: child = TtaGetFirstChild (el);
396: while (child != NULL)
397: {
398: next = child;
399: TtaNextSibling (&next);
400: elType = TtaGetElementType (child);
401: if (elType.ElTypeNum == HTML_EL_Unnumbered_List ||
402: elType.ElTypeNum == HTML_EL_Numbered_List ||
403: elType.ElTypeNum == HTML_EL_Menu ||
404: elType.ElTypeNum == HTML_EL_Directory)
405: /* this list element is a child of another list element */
406: if (prev)
407: {
408: elType = TtaGetElementType (prev);
409: if (elType.ElTypeNum == HTML_EL_List_Item)
410: {
411: /* get the last child of the previous List_Item */
412: desc = TtaGetFirstChild (prev);
413: last = NULL;
414: while (desc)
415: {
416: last = desc;
417: TtaNextSibling (&desc);
418: }
419: /* move the list element after the last child of the
420: previous List_Item */
421: TtaRemoveTree (child, doc);
422: if (last)
423: TtaInsertSibling (child, last, FALSE, doc);
424: else
425: TtaInsertFirstChild (&child, prev, doc);
426: child = prev;
427: }
428: }
429: prev = child;
430: child = next;
431: }
432: break;
433:
434: case HTML_EL_FRAMESET:
435: /* The FRAMESET element is now complete. Gather all its FRAMESET
436: and FRAME children and wrap them up in a Frames element */
437: elFrames = NULL; lastFrame = NULL;
438: lastChild = NULL;
439: child = TtaGetFirstChild (el);
440: while (child != NULL)
441: {
442: next = child;
443: TtaNextSibling (&next);
444: elType = TtaGetElementType (child);
445: if (elType.ElTypeNum == HTML_EL_FRAMESET ||
446: elType.ElTypeNum == HTML_EL_FRAME ||
447: elType.ElTypeNum == HTML_EL_Comment_)
448: {
449: /* create the Frames element if it does not exist */
450: if (elFrames == NULL)
451: {
452: newElType.ElSSchema = docSSchema;
453: newElType.ElTypeNum = HTML_EL_Frames;
454: elFrames = TtaNewElement (doc, newElType);
1.63 cvs 455: if (DocumentMeta[doc]->xmlformat)
456: XmlSetElemLineNumber (elFrames);
457: else
458: SetHtmlElemLineNumber (elFrames);
1.6 cvs 459: TtaInsertSibling (elFrames, child, TRUE, doc);
460: }
461: /* move the element as the last child of the Frames element */
462: TtaRemoveTree (child, doc);
463: if (lastFrame == NULL)
464: TtaInsertFirstChild (&child, elFrames, doc);
465: else
466: TtaInsertSibling (child, lastFrame, FALSE, doc);
467: lastFrame = child;
468: }
469: child = next;
470: }
471: break;
472:
473: case HTML_EL_Input: /* it's an INPUT without any TYPE attribute */
474: /* Create a child of type Text_Input */
475: elType.ElTypeNum = HTML_EL_Text_Input;
476: child = TtaNewTree (doc, elType, "");
1.63 cvs 477: if (DocumentMeta[doc]->xmlformat)
478: XmlSetElemLineNumber (child);
479: else
480: SetHtmlElemLineNumber (child);
1.6 cvs 481: TtaInsertFirstChild (&child, el, doc);
482: /* now, process it like a Text_Input element */
483:
484: case HTML_EL_Text_Input:
485: case HTML_EL_Password_Input:
486: case HTML_EL_File_Input:
1.91 quint 487: /* set default size */
488: attrType.AttrSSchema = elType.ElSSchema;
489: attrType.AttrTypeNum = HTML_ATTR_IntAreaSize;
490: attr = TtaGetAttribute (el, attrType);
491: if (!attr)
492: CreateAttrIntAreaSize (20, el, doc);
1.6 cvs 493: /* get element Inserted_Text */
494: child = TtaGetFirstChild (el);
495: if (child != NULL)
496: {
497: attrType.AttrTypeNum = HTML_ATTR_Value_;
498: attr = TtaGetAttribute (el, attrType);
499: if (attr != NULL)
500: {
501: /* copy the value of attribute "value" into the first text
502: leaf of element */
503: length = TtaGetTextAttributeLength (attr);
504: if (length > 0)
505: {
506: /* get the text leaf */
507: leaf = TtaGetFirstChild (child);
508: if (leaf != NULL)
509: {
510: childType = TtaGetElementType (leaf);
511: if (childType.ElTypeNum == HTML_EL_TEXT_UNIT)
512: {
513: /* copy attribute value into the text leaf */
1.100 gully 514: text = (char *)TtaGetMemory (length + 1);
1.6 cvs 515: TtaGiveTextAttributeValue (attr, text, &length);
1.100 gully 516: TtaSetTextContent (leaf, (unsigned char *)text,
1.6 cvs 517: TtaGetDefaultLanguage (), doc);
518: TtaFreeMemory (text);
519: }
520: }
521: }
522: }
523: }
524: break;
525:
526: case HTML_EL_META:
1.15 cvs 527: ParseCharset (el, doc);
1.6 cvs 528: break;
529:
530: case HTML_EL_STYLE_: /* it's a STYLE element */
1.60 vatton 531: case HTML_EL_SCRIPT_: /* it's a SCRIPT element */
1.6 cvs 532: case HTML_EL_Preformatted: /* it's a PRE */
533: /* if the last line of the Preformatted is empty, remove it */
534: leaf = XmlLastLeafInElement (el);
535: if (leaf != NULL)
536: {
537: elType = TtaGetElementType (leaf);
538: if (elType.ElTypeNum == HTML_EL_TEXT_UNIT)
539: /* the last leaf is a TEXT element */
540: {
541: length = TtaGetTextLength (leaf);
542: if (length > 0)
543: {
1.100 gully 544: TtaGiveSubString (leaf, (unsigned char *)lastChar, length, 1);
1.6 cvs 545: if (lastChar[0] == EOL)
546: /* last character is new line, delete it */
547: {
548: if (length == 1)
549: /* empty TEXT element */
550: TtaDeleteTree (leaf, doc);
551: else
552: /* remove the last character */
553: TtaDeleteTextContent (leaf, length, 1, doc);
554: }
555: }
556: }
557: }
1.75 kahan 558: if (DocumentMeta[doc] && DocumentMeta[doc]->xmlformat)
1.63 cvs 559: {
560: if (IsXmlParsingCSS ())
561: {
562: text = GetStyleContents (el);
563: if (text)
564: {
1.71 vatton 565: ReadCSSRules (doc, NULL, text, NULL,
1.82 quint 566: TtaGetElementLineNumber (el), FALSE, el);
1.63 cvs 567: TtaFreeMemory (text);
568: }
569: SetXmlParsingCSS (FALSE);
570: }
571: }
572: else
1.6 cvs 573: {
1.63 cvs 574: if (IsHtmlParsingCSS ())
1.6 cvs 575: {
1.63 cvs 576: text = GetStyleContents (el);
577: if (text)
578: {
1.71 vatton 579: ReadCSSRules (doc, NULL, text, NULL,
1.82 quint 580: TtaGetElementLineNumber (el), FALSE, el);
1.63 cvs 581: TtaFreeMemory (text);
582: }
583: SetHtmlParsingCSS (FALSE);
1.6 cvs 584: }
585: }
586: /* and continue as if it were a Preformatted or a Script */
587: break;
588:
589: case HTML_EL_Text_Area: /* it's a Text_Area */
1.69 cvs 590: if (DocumentMeta[doc]->xmlformat)
591: SetParsingTextArea (FALSE);
592: else
593: SetHtmlParsingTextArea (FALSE);
1.6 cvs 594: child = TtaGetFirstChild (el);
595: if (child == NULL)
596: /* it's an empty Text_Area */
1.97 quint 597: /* insert a Inserted_Text element and a child Basic_Elem in the
598: Text_Area element */
1.6 cvs 599: {
600: newElType.ElTypeNum = HTML_EL_Inserted_Text;
601: child = TtaNewTree (doc, newElType, "");
602: TtaInsertFirstChild (&child, el, doc);
603: }
604: else
605: {
606: /* save the text into Default_Value attribute */
607: attrType.AttrSSchema = docSSchema;
608: attrType.AttrTypeNum = HTML_ATTR_Default_Value;
609: if (TtaGetAttribute (el, attrType) == NULL)
610: /* attribute Default_Value is missing */
611: {
612: desc = TtaGetFirstChild (child);
1.97 quint 613: if (desc)
614: {
615: length = TtaGetTextLength (desc);
616: if (length > 0)
617: {
618: length++;
619: attr = TtaNewAttribute (attrType);
620: TtaAttachAttribute (el, attr, doc);
1.100 gully 621: text = (char *)TtaGetMemory (length);
622: TtaGiveTextContent (desc, (unsigned char *)text, &length, &lang);
1.97 quint 623: TtaSetAttributeText (attr, text, el, doc);
624: TtaFreeMemory (text);
625: }
626: }
1.6 cvs 627: }
628: }
629: break;
1.103 ! quint 630:
1.6 cvs 631: case HTML_EL_Radio_Input:
632: case HTML_EL_Checkbox_Input:
633: /* put an attribute Checked if it is missing */
634: attrType.AttrSSchema = docSSchema;
635: attrType.AttrTypeNum = HTML_ATTR_Checked;
636: if (TtaGetAttribute (el, attrType) == NULL)
637: /* attribute Checked is missing */
638: {
639: attr = TtaNewAttribute (attrType);
640: TtaAttachAttribute (el, attr, doc);
641: TtaSetAttributeValue (attr, HTML_ATTR_Checked_VAL_No_, el, doc);
642: }
643: break;
644:
645: case HTML_EL_Option_Menu:
646: /* Check that at least one option has a SELECTED attribute */
647: OnlyOneOptionSelected (el, doc, TRUE);
648: break;
649:
650: case HTML_EL_PICTURE_UNIT:
651: break;
652:
653: case HTML_EL_LINK:
654: CheckCSSLink (el, doc, docSSchema);
655: break;
656:
657: case HTML_EL_Data_cell:
658: case HTML_EL_Heading_cell:
659: /* insert a pseudo paragraph into empty cells */
660: child = TtaGetFirstChild (el);
661: if (child == NULL)
662: {
663: elType.ElTypeNum = HTML_EL_Pseudo_paragraph;
664: child = TtaNewTree (doc, elType, "");
665: if (child != NULL)
666: TtaInsertFirstChild (&child, el, doc);
667: }
668:
1.80 cvs 669: /* detect whether we are parsing a whole table or just a cell */
1.63 cvs 670: if (DocumentMeta[doc]->xmlformat)
671: {
672: if (IsWithinXmlTable ())
1.102 quint 673: NewCell (el, doc, FALSE, FALSE, FALSE);
1.63 cvs 674: }
675: else
676: {
677: if (IsWithinHtmlTable ())
1.102 quint 678: NewCell (el, doc, FALSE, FALSE, FALSE);
1.63 cvs 679: }
1.6 cvs 680: break;
681:
682: case HTML_EL_Table:
683: CheckTable (el, doc);
684: SubWithinTable ();
685: break;
686:
687: case HTML_EL_TITLE:
688: /* show the TITLE in the main window */
689: UpdateTitle (el, doc);
690: break;
1.41 cvs 691:
692: case HTML_EL_rbc:
693: /* an rbc element has been read. Its parent should be a complex_ruby.
694: Change the type of the parent, as simple_ruby are created by
695: default */
696: parent = TtaGetParent (el);
697: if (parent)
698: {
699: newElType = TtaGetElementType (parent);
700: if (newElType.ElSSchema == elType.ElSSchema &&
701: newElType.ElTypeNum == HTML_EL_simple_ruby)
1.95 vatton 702: TtaChangeElementType (parent, HTML_EL_complex_ruby);
1.41 cvs 703: }
704: break;
705:
706: case HTML_EL_rtc1:
707: /* an rtc element has been parsed. If it has already a rtc1 sibling,
708: change its type to rtc2 */
709: prev = el;
710: do
711: {
712: TtaPreviousSibling(&prev);
713: if (prev)
714: {
715: newElType = TtaGetElementType (prev);
716: if (newElType.ElSSchema == elType.ElSSchema &&
717: newElType.ElTypeNum == HTML_EL_rtc1)
718: {
1.95 vatton 719: TtaChangeElementType (el, HTML_EL_rtc2);
1.41 cvs 720: prev = NULL;
721: }
722: }
723: }
724: while (prev);
725: break;
726:
1.6 cvs 727: default:
728: break;
729: }
730: }
1.1 cvs 731:
732: /*----------------------------------------------------------------------
1.30 cvs 733: PutInContent
734: Put the string ChrString in the leaf of current element.
735: ----------------------------------------------------------------------*/
1.39 cvs 736: Element PutInContent (char *ChrString, ParserData *context)
1.30 cvs 737:
738: {
739: Element el, child;
740: ElementType elType;
741: int length;
742:
743: el = NULL;
744: if (context->lastElement != NULL)
745: {
746: /* search first leaf of current element */
747: el = context->lastElement;
748: do
749: {
750: child = TtaGetFirstChild (el);
751: if (child != NULL)
752: el = child;
753: }
754: while (child != NULL);
755: elType = TtaGetElementType (el);
756: length = 0;
757: if (elType.ElTypeNum == 1)
758: length = TtaGetTextLength (el);
759: if (length == 0)
1.100 gully 760: TtaSetTextContent (el, (unsigned char *)ChrString, context->language, context->doc);
1.30 cvs 761: else
1.100 gully 762: TtaAppendTextContent (el, (unsigned char *)ChrString, context->doc);
1.30 cvs 763: }
764: return el;
765: }
766:
767: /*----------------------------------------------------------------------
1.93 vatton 768: UnknownXhtmlNameSpace
769: The element doesn't belong to a supported namespace
1.51 cvs 770: ----------------------------------------------------------------------*/
1.93 vatton 771: void UnknownXhtmlNameSpace (ParserData *context, Element *unknownEl,
772: char* content)
1.51 cvs 773: {
774: ElementType elType;
1.65 cvs 775: Element elText;
1.51 cvs 776:
777: /* Create a new Invalid_element */
778: elType.ElSSchema = GetXMLSSchema (XHTML_TYPE, context->doc);
1.94 cvs 779: elType.ElTypeNum = HTML_EL_XHTML_Unknown_namespace;
1.65 cvs 780: *unknownEl = TtaNewElement (context->doc, elType);
781: if (*unknownEl != NULL)
1.51 cvs 782: {
1.65 cvs 783: XmlSetElemLineNumber (*unknownEl);
784: InsertXmlElement (unknownEl);
1.51 cvs 785: context->lastElementClosed = TRUE;
786: elType.ElTypeNum = HTML_EL_TEXT_UNIT;
787: elText = TtaNewElement (context->doc, elType);
788: XmlSetElemLineNumber (elText);
1.65 cvs 789: TtaInsertFirstChild (&elText, *unknownEl, context->doc);
1.100 gully 790: TtaSetTextContent (elText, (unsigned char *)content, context->language, context->doc);
1.51 cvs 791: TtaSetAccessRight (elText, ReadOnly, context->doc);
792: }
793: }
794:
795: /*----------------------------------------------------------------------
1.30 cvs 796: CreateHTMLAttribute
797: create an attribute of type attrType for the element el.
798: ----------------------------------------------------------------------*/
1.93 vatton 799: void CreateHTMLAttribute (Element el,
800: AttributeType attrType,
801: char* text,
802: ThotBool isInvalid,
803: Document doc,
804: Attribute *lastAttribute,
805: Element *lastAttrElement)
1.30 cvs 806: {
807: int attrKind;
808: int length;
1.39 cvs 809: char *buffer;
1.30 cvs 810: Attribute attr, oldAttr;
811:
812: if (attrType.AttrTypeNum != 0)
813: {
814: oldAttr = TtaGetAttribute (el, attrType);
815: if (oldAttr != NULL)
816: /* this attribute already exists */
817: attr = oldAttr;
818: else
819: /* create a new attribute and attach it to the element */
820: {
821: attr = TtaNewAttribute (attrType);
822: TtaAttachAttribute (el, attr, doc);
823: }
824: *lastAttribute = attr;
825: *lastAttrElement = el;
826:
827: TtaGiveAttributeType (attr, &attrType, &attrKind);
828: if (attrKind == 0) /* enumerate */
829: TtaSetAttributeValue (attr, 1, el, doc);
830:
831: /* attribute BORDER without any value (ThotBool attribute) is */
832: /* considered as BORDER=1 */
833: if (attrType.AttrTypeNum == HTML_ATTR_Border)
834: TtaSetAttributeValue (attr, 1, el, doc);
835:
836: if (isInvalid)
837: /* Copy the name of the invalid attribute as the content */
838: /* of the Invalid_attribute attribute. */
839: {
1.37 cvs 840: length = strlen (text) + 2;
1.30 cvs 841: length += TtaGetTextAttributeLength (attr);
1.100 gully 842: buffer = (char *)TtaGetMemory (length + 1);
1.30 cvs 843: TtaGiveTextAttributeValue (attr, buffer, &length);
1.37 cvs 844: strcat (buffer, " ");
845: strcat (buffer, text);
1.30 cvs 846: TtaSetAttributeText (attr, buffer, el, doc);
847: TtaFreeMemory (buffer);
848: }
849: }
850: }
851:
852: /*----------------------------------------------------------------------
853: HTMLTypeAttrValue
854: Value val has been read for the HTML attribute TYPE.
855: Create a child for the current Thot element INPUT accordingly.
856: ----------------------------------------------------------------------*/
1.46 cvs 857: void HTMLTypeAttrValue (char *val,
1.30 cvs 858: Attribute lastAttribute,
859: Element lastAttrElement,
860: ParserData *context)
861:
862: {
863: ElementType elType;
864: Element newChild;
865: AttributeType attrType;
866: Attribute attr;
1.39 cvs 867: char msgBuffer[MaxMsgLength];
1.30 cvs 868: int value;
869: int numberOfLinesRead;
870:
871: value = MapAttrValue (DummyAttribute, val);
1.91 quint 872: if (value <= 0)
1.30 cvs 873: {
1.37 cvs 874: if (strlen (val) > MaxMsgLength - 40)
875: val[MaxMsgLength - 40] = EOS;
876: sprintf (msgBuffer, "Unknown attribute value \"type = %s\"", val);
1.42 cvs 877: HTMLParseError (context->doc, msgBuffer);
1.30 cvs 878: attrType.AttrSSchema = TtaGetDocumentSSchema (context->doc);
879: attrType.AttrTypeNum = pHTMLAttributeMapping[0].ThotAttribute;
1.37 cvs 880: sprintf (msgBuffer, "type=%s", val);
1.30 cvs 881: CreateHTMLAttribute (context->lastElement, attrType, msgBuffer, TRUE,
882: context->doc, &lastAttribute, &lastAttrElement);
883: }
884: else
885: {
886: elType = TtaGetElementType (context->lastElement);
887: if (elType.ElTypeNum != HTML_EL_Input)
888: {
1.37 cvs 889: if (strlen (val) > MaxMsgLength - 40)
890: val[MaxMsgLength - 40] = EOS;
891: sprintf (msgBuffer, "Duplicate attribute \"type = %s\"", val);
1.30 cvs 892: }
893: else
894: {
895: elType.ElSSchema = TtaGetDocumentSSchema (context->doc);
896: elType.ElTypeNum = value;
897: newChild = TtaNewTree (context->doc, elType, "");
898: numberOfLinesRead = 0;
899: TtaSetElementLineNumber (newChild, numberOfLinesRead);
900: TtaInsertFirstChild (&newChild, context->lastElement, context->doc);
901: if (value == HTML_EL_PICTURE_UNIT)
902: {
903: /* add the attribute IsInput to input pictures */
904: attrType.AttrSSchema = elType.ElSSchema;
905: attrType.AttrTypeNum = HTML_ATTR_IsInput;
906: attr = TtaNewAttribute (attrType);
907: TtaAttachAttribute (newChild, attr, context->doc);
908: }
909: }
910: }
911: }
912:
913: /*----------------------------------------------------------------------
914: XhtmlTypeAttrValue
915: Value val has been read for the HTML attribute TYPE.
916: Create a child for the current Thot element INPUT accordingly.
917: ----------------------------------------------------------------------*/
1.46 cvs 918: void XhtmlTypeAttrValue (char *val,
1.30 cvs 919: Attribute currentAttribute,
920: Element lastAttrElement,
921: ParserData *context)
922:
923: {
924: ElementType elType;
925: Element newChild;
926: AttributeType attrType;
927: Attribute attr;
1.39 cvs 928: char msgBuffer[MaxMsgLength];
1.30 cvs 929: int value;
930: ThotBool level;
931:
1.91 quint 932: /* Look in the dummy section of the attribute value table */
1.30 cvs 933: attrType.AttrTypeNum = DummyAttribute;
1.100 gully 934: MapHTMLAttributeValue (val, &attrType, &value);
1.91 quint 935: if (value <= 0)
936: /* invalid value for the type attribute of an input element */
1.30 cvs 937: {
1.37 cvs 938: sprintf (msgBuffer, "Unknown attribute value \"type=%s\"", val);
1.100 gully 939: XmlParseError (errorParsing, (unsigned char *)msgBuffer, 0);
1.36 cvs 940: MapHTMLAttribute ("unknown_attr", &attrType, NULL,
1.30 cvs 941: &level, context->doc);
1.37 cvs 942: sprintf (msgBuffer, "type=%s", val);
1.30 cvs 943: CreateHTMLAttribute (context->lastElement, attrType, msgBuffer, TRUE,
944: context->doc, ¤tAttribute, &lastAttrElement);
945: }
946: else
1.91 quint 947: /* value is the Thot type of the element to be created for this value of
948: the TYPE attribute */
1.30 cvs 949: {
950: elType = TtaGetElementType (context->lastElement);
951: if (elType.ElTypeNum != HTML_EL_Input)
952: {
1.37 cvs 953: sprintf (msgBuffer, "Duplicate attribute \"type = %s\"", val);
1.100 gully 954: XmlParseError (errorParsing, (unsigned char *)msgBuffer, 0);
1.30 cvs 955: }
956: else
957: {
958: elType.ElTypeNum = value;
959: newChild = TtaNewTree (context->doc, elType, "");
960: XmlSetElemLineNumber (newChild);
961: TtaInsertFirstChild (&newChild, context->lastElement, context->doc);
962: if (value == HTML_EL_PICTURE_UNIT)
963: {
964: /* add the attribute IsInput to input pictures */
965: attrType.AttrSSchema = elType.ElSSchema;
966: attrType.AttrTypeNum = HTML_ATTR_IsInput;
967: attr = TtaNewAttribute (attrType);
968: TtaAttachAttribute (newChild, attr, context->doc);
969: }
970: }
971: }
972: }
973:
974: /*----------------------------------------------------------------------
975: CreateAttrWidthPercentPxl
1.79 quint 976: an HTML attribute "width" has been created for a Table, an image,
977: an Object of a HR.
1.30 cvs 978: Create the corresponding attribute IntWidthPercent or IntWidthPxl.
979: oldWidth is -1 or the old image width.
980: ----------------------------------------------------------------------*/
1.58 vatton 981: void CreateAttrWidthPercentPxl (char *buffer, Element el,
982: Document doc, int oldWidth)
1.30 cvs 983: {
984: AttributeType attrTypePxl, attrTypePercent;
985: Attribute attrOld, attrNew;
986: int length, val;
1.39 cvs 987: char msgBuffer[MaxMsgLength];
1.79 quint 988: ElementType elType, childType;
989: Element origEl, child;
1.30 cvs 990: int w, h;
991: ThotBool isImage;
992:
1.79 quint 993: origEl = el;
1.30 cvs 994: elType = TtaGetElementType (el);
995: isImage = (elType.ElTypeNum == HTML_EL_PICTURE_UNIT ||
996: elType.ElTypeNum == HTML_EL_Data_cell ||
1.79 quint 997: elType.ElTypeNum == HTML_EL_Heading_cell ||
998: elType.ElTypeNum == HTML_EL_Object);
999: if (elType.ElTypeNum == HTML_EL_Object)
1000: /* the width attribute is attached to an Object element */
1001: {
1002: child = TtaGetFirstChild (el);
1003: if (child)
1004: {
1005: childType = TtaGetElementType (child);
1006: if (childType.ElTypeNum == HTML_EL_PICTURE_UNIT)
1007: /* the Object element is of type image. apply the width
1008: attribute to the actual image element */
1009: el = child;
1010: }
1011: }
1.30 cvs 1012: /* remove trailing spaces */
1.37 cvs 1013: length = strlen (buffer) - 1;
1.30 cvs 1014: while (length > 0 && buffer[length] <= SPACE)
1015: length--;
1016: attrTypePxl.AttrSSchema = TtaGetDocumentSSchema (doc);
1017: attrTypePercent.AttrSSchema = TtaGetDocumentSSchema (doc);
1018: attrTypePxl.AttrTypeNum = HTML_ATTR_IntWidthPxl;
1019: attrTypePercent.AttrTypeNum = HTML_ATTR_IntWidthPercent;
1020: /* is the last character a '%' ? */
1021: if (buffer[length] == '%')
1022: {
1023: /* remove IntWidthPxl */
1024: attrOld = TtaGetAttribute (el, attrTypePxl);
1025: /* update IntWidthPercent */
1026: attrNew = TtaGetAttribute (el, attrTypePercent);
1027: if (attrNew == NULL)
1028: {
1029: attrNew = TtaNewAttribute (attrTypePercent);
1030: TtaAttachAttribute (el, attrNew, doc);
1031: }
1032: else if (isImage && oldWidth == -1)
1033: {
1034: if (attrOld == NULL)
1035: oldWidth = TtaGetAttributeValue (attrNew);
1036: else
1037: oldWidth = TtaGetAttributeValue (attrOld);
1038: }
1039: }
1040: else
1041: {
1042: /* remove IntWidthPercent */
1043: attrOld = TtaGetAttribute (el, attrTypePercent);
1044: /* update IntWidthPxl */
1045: attrNew = TtaGetAttribute (el, attrTypePxl);
1046: if (attrNew == NULL)
1047: {
1048: attrNew = TtaNewAttribute (attrTypePxl);
1049: TtaAttachAttribute (el, attrNew, doc);
1050: }
1051: else if (isImage && oldWidth == -1)
1052: {
1053: TtaGiveBoxSize (el, doc, 1, UnPixel, &w, &h);
1054: if (attrOld == NULL)
1055: oldWidth = w * TtaGetAttributeValue (attrNew) / 100;
1056: else
1057: oldWidth = w * TtaGetAttributeValue (attrOld) / 100;
1058: }
1059: }
1060:
1061: if (attrOld != NULL)
1062: TtaRemoveAttribute (el, attrOld, doc);
1.43 cvs 1063: if (sscanf (buffer, "%d", &val))
1.30 cvs 1064: TtaSetAttributeValue (attrNew, val, el, doc);
1065: else
1066: /* its not a number. Delete attribute and send an error message */
1067: {
1068: TtaRemoveAttribute (el, attrNew, doc);
1.37 cvs 1069: if (strlen (buffer) > MaxMsgLength - 30)
1.30 cvs 1070: buffer[MaxMsgLength - 30] = EOS;
1.37 cvs 1071: sprintf (msgBuffer, "Invalid attribute value \"%s\"", buffer);
1.42 cvs 1072: HTMLParseError (doc, msgBuffer);
1.30 cvs 1073: }
1074: if (isImage)
1.79 quint 1075: UpdateImageMap (origEl, doc, oldWidth, -1);
1.30 cvs 1076: }
1077:
1078: /*----------------------------------------------------------------------
1.58 vatton 1079: CreateAttrHeightPercentPxl
1.79 quint 1080: an HTML attribute "width" has been created for a Table, an image,
1081: an Object or a HR.
1.58 vatton 1082: Create the corresponding attribute IntHeightPercent or IntHeightPxl.
1083: oldHeight is -1 or the old image width.
1084: ----------------------------------------------------------------------*/
1085: void CreateAttrHeightPercentPxl (char *buffer, Element el,
1086: Document doc, int oldHeight)
1087: {
1088: AttributeType attrTypePxl, attrTypePercent;
1089: Attribute attrOld, attrNew;
1090: int length, val;
1091: char msgBuffer[MaxMsgLength];
1.79 quint 1092: ElementType elType, childType;
1093: Element origEl, child;
1.58 vatton 1094: int w, h;
1095: ThotBool isImage;
1096:
1.79 quint 1097: origEl = el;
1.58 vatton 1098: elType = TtaGetElementType (el);
1099: isImage = (elType.ElTypeNum == HTML_EL_PICTURE_UNIT ||
1100: elType.ElTypeNum == HTML_EL_Data_cell ||
1.79 quint 1101: elType.ElTypeNum == HTML_EL_Heading_cell ||
1102: elType.ElTypeNum == HTML_EL_Object);
1103: if (elType.ElTypeNum == HTML_EL_Object)
1104: /* the height attribute is attached to an Object element */
1105: {
1106: child = TtaGetFirstChild (el);
1.81 cvs 1107: if (!child)
1108: return;
1109: else
1.79 quint 1110: {
1111: childType = TtaGetElementType (child);
1112: if (childType.ElTypeNum == HTML_EL_PICTURE_UNIT)
1113: /* the Object element is of type image. apply the width
1114: attribute to the actual image element */
1115: el = child;
1.81 cvs 1116: else
1117: return;
1.79 quint 1118: }
1119: }
1.58 vatton 1120: /* remove trailing spaces */
1121: length = strlen (buffer) - 1;
1122: while (length > 0 && buffer[length] <= SPACE)
1123: length--;
1124: attrTypePxl.AttrSSchema = TtaGetDocumentSSchema (doc);
1125: attrTypePercent.AttrSSchema = TtaGetDocumentSSchema (doc);
1126: attrTypePxl.AttrTypeNum = HTML_ATTR_IntHeightPxl;
1127: attrTypePercent.AttrTypeNum = HTML_ATTR_IntHeightPercent;
1128: /* is the last character a '%' ? */
1129: if (buffer[length] == '%')
1130: {
1131: /* remove IntHeightPxl */
1132: attrOld = TtaGetAttribute (el, attrTypePxl);
1133: /* update IntHeightPercent */
1134: attrNew = TtaGetAttribute (el, attrTypePercent);
1135: if (attrNew == NULL)
1136: {
1137: attrNew = TtaNewAttribute (attrTypePercent);
1138: TtaAttachAttribute (el, attrNew, doc);
1139: }
1140: else if (isImage && oldHeight == -1)
1141: {
1142: if (attrOld == NULL)
1143: oldHeight = TtaGetAttributeValue (attrNew);
1144: else
1145: oldHeight = TtaGetAttributeValue (attrOld);
1146: }
1147: }
1148: else
1149: {
1150: /* remove IntHeightPercent */
1151: attrOld = TtaGetAttribute (el, attrTypePercent);
1152: /* update IntHeightPxl */
1153: attrNew = TtaGetAttribute (el, attrTypePxl);
1154: if (attrNew == NULL)
1155: {
1156: attrNew = TtaNewAttribute (attrTypePxl);
1157: TtaAttachAttribute (el, attrNew, doc);
1158: }
1159: else if (isImage && oldHeight == -1)
1160: {
1161: TtaGiveBoxSize (el, doc, 1, UnPixel, &w, &h);
1162: if (attrOld == NULL)
1163: oldHeight = w * TtaGetAttributeValue (attrNew) / 100;
1164: else
1165: oldHeight = w * TtaGetAttributeValue (attrOld) / 100;
1166: }
1167: }
1168:
1169: if (attrOld != NULL)
1170: TtaRemoveAttribute (el, attrOld, doc);
1171: if (sscanf (buffer, "%d", &val))
1172: TtaSetAttributeValue (attrNew, val, el, doc);
1173: else
1174: /* its not a number. Delete attribute and send an error message */
1175: {
1176: TtaRemoveAttribute (el, attrNew, doc);
1177: if (strlen (buffer) > MaxMsgLength - 30)
1178: buffer[MaxMsgLength - 30] = EOS;
1179: sprintf (msgBuffer, "Invalid attribute value \"%s\"", buffer);
1180: HTMLParseError (doc, msgBuffer);
1181: }
1182: if (isImage)
1.79 quint 1183: UpdateImageMap (origEl, doc, oldHeight, -1);
1.58 vatton 1184: }
1185:
1186: /*----------------------------------------------------------------------
1.91 quint 1187: CreateAttrIntAreaSize
1188: an HTML attribute "size" has been created or modified for a input element.
1189: Create or update the corresponding attribute IntAreaSize.
1190: ----------------------------------------------------------------------*/
1191: void CreateAttrIntAreaSize (int value, Element el, Document doc)
1192: {
1193: AttributeType attrType;
1194: Attribute attr;
1195: ElementType elType;
1196:
1197: elType = TtaGetElementType (el);
1198: attrType.AttrSSchema = elType.ElSSchema;
1199: attrType.AttrTypeNum = HTML_ATTR_IntAreaSize;
1200: attr = TtaGetAttribute (el, attrType);
1201: if (!attr)
1202: {
1203: attr = TtaNewAttribute (attrType);
1204: TtaAttachAttribute (el, attr, doc);
1205: }
1206: /* the presentation rule associated with attribute IntAreaSize expresses
1207: the element width in "em". Convert the value into em */
1208: TtaSetAttributeValue (attr, (int) (value * 0.55), el, doc);
1209: }
1210:
1211: /*----------------------------------------------------------------------
1.30 cvs 1212: CreateAttrIntSize
1213: an HTML attribute "size" has been created for a Font element.
1214: Create the corresponding internal attribute.
1215: ----------------------------------------------------------------------*/
1.46 cvs 1216: void CreateAttrIntSize (char *buffer, Element el, Document doc)
1.30 cvs 1217:
1218: {
1219: AttributeType attrType;
1220: int val, ind, factor, delta;
1221: Attribute attr;
1.37 cvs 1222: char msgBuffer[MaxMsgLength];
1.30 cvs 1223:
1224: /* is the first character a '+' or a '-' ? */
1225: ind = 0;
1226: factor = 1;
1227: delta = 0;
1228: if (buffer[0] == '+')
1229: {
1230: attrType.AttrTypeNum = HTML_ATTR_IntSizeIncr;
1231: ind++;
1.90 vatton 1232: factor = 1;
1.30 cvs 1233: }
1234: else if (buffer[0] == '-')
1235: {
1236: attrType.AttrTypeNum = HTML_ATTR_IntSizeDecr;
1237: ind++;
1.90 vatton 1238: factor = 1;
1.30 cvs 1239: }
1240: else
1241: {
1242: attrType.AttrTypeNum = HTML_ATTR_IntSizeRel;
1243: delta = 1;
1244: }
1245: attrType.AttrSSchema = TtaGetDocumentSSchema (doc);
1246: attr = TtaGetAttribute (el, attrType);
1.43 cvs 1247: if (sscanf (&buffer[ind], "%d", &val))
1.30 cvs 1248: {
1249: val = val * factor + delta;
1250: if (attr == NULL)
1251: {
1252: /* this attribute doesn't exist, create it */
1253: attr = TtaNewAttribute (attrType);
1254: TtaAttachAttribute (el, attr, doc);
1255: }
1256: TtaSetAttributeValue (attr, val, el, doc);
1257: }
1258: else
1259: /* its not a number. Delete attribute and send an error message */
1260: {
1261: if (attr)
1262: TtaRemoveAttribute (el, attr, doc);
1.37 cvs 1263: if (strlen (buffer) > MaxMsgLength - 30)
1.30 cvs 1264: buffer[MaxMsgLength - 30] = EOS;
1.37 cvs 1265: sprintf (msgBuffer, "Invalid attribute value \"%s\"", buffer);
1.42 cvs 1266: HTMLParseError (doc, msgBuffer);
1.30 cvs 1267: }
1268: }
1269: /*----------------------------------------------------------------------
1270: EndOfHTMLAttributeValue
1271: Filling of an HTML attribute value
1272: ----------------------------------------------------------------------*/
1.48 vatton 1273: void EndOfHTMLAttributeValue (char *attrValue,
1274: AttributeMapping *lastMappedAttr,
1275: Attribute currentAttribute,
1276: Element lastAttrElement,
1277: ThotBool UnknownAttr,
1278: ParserData *context,
1279: ThotBool isXML)
1.30 cvs 1280: {
1.48 vatton 1281: AttributeType attrType, attrType1;
1282: Attribute attr;
1.79 quint 1283: ElementType elType;
1.48 vatton 1284: Element child, root;
1285: Language lang;
1286: char translation;
1287: char shape;
1288: char *buffer;
1289: char *attrName;
1290: char msgBuffer[MaxMsgLength];
1291: int val;
1292: int length;
1293: int attrKind;
1294: ThotBool done = FALSE;
1.88 vatton 1295: ThotBool loadcss;
1.30 cvs 1296:
1.48 vatton 1297: /* treatments of some particular HTML attributes */
1298: if (!strcmp (lastMappedAttr->XMLattribute, "style"))
1299: {
1300: TtaSetAttributeText (currentAttribute, attrValue,
1301: lastAttrElement, context->doc);
1.88 vatton 1302: /* check if we have to load CSS */
1303: TtaGetEnvBoolean ("LOAD_CSS", &loadcss);
1304: if (loadcss)
1305: ParseHTMLSpecificStyle (context->lastElement, attrValue,
1306: context->doc, 100, FALSE);
1.48 vatton 1307: done = TRUE;
1308: }
1309: else
1310: {
1311: if (!strcmp (lastMappedAttr->XMLattribute, "link"))
1.89 vatton 1312: HTMLSetAlinkColor (context->doc, context->lastElement, attrValue);
1.48 vatton 1313: else if (!strcmp (lastMappedAttr->XMLattribute, "alink"))
1.89 vatton 1314: HTMLSetAactiveColor (context->doc, context->lastElement, attrValue);
1.48 vatton 1315: else if (!strcmp (lastMappedAttr->XMLattribute, "vlink"))
1.89 vatton 1316: HTMLSetAvisitedColor (context->doc, context->lastElement, attrValue);
1.48 vatton 1317: }
1.30 cvs 1318:
1.48 vatton 1319: if (!done)
1320: {
1321: val = 0;
1322: translation = lastMappedAttr->AttrOrContent;
1323: switch (translation)
1324: {
1325: case 'C': /* Content */
1326: child = PutInContent (attrValue, context);
1327: if (child != NULL)
1.100 gully 1328: TtaAppendTextContent (child, (unsigned char *)"\" ", context->doc);
1.48 vatton 1329: break;
1330:
1331: case 'A':
1332: if (currentAttribute != NULL)
1333: {
1334: TtaGiveAttributeType (currentAttribute, &attrType, &attrKind);
1335: switch (attrKind)
1336: {
1337: case 0: /* enumerate */
1338: if (isXML)
1.100 gully 1339: MapHTMLAttributeValue (attrValue, &attrType, &val);
1.48 vatton 1340: else
1341: val = MapAttrValue (lastMappedAttr->ThotAttribute,
1.40 cvs 1342: attrValue);
1.48 vatton 1343: if (val < 0)
1344: {
1345: TtaGiveAttributeType (currentAttribute,
1346: &attrType, &attrKind);
1347: attrName = TtaGetAttributeName (attrType);
1348: sprintf (msgBuffer,
1.51 cvs 1349: "Invalid attribute value \"%s = %s\"",
1.48 vatton 1350: attrName, attrValue);
1351: if (isXML)
1.100 gully 1352: XmlParseError (errorParsing, (unsigned char *)msgBuffer, 0);
1.48 vatton 1353: else
1.84 quint 1354: /* we are parsing an HTML file, not an XHTML file */
1.51 cvs 1355: {
1.84 quint 1356: /* generate an error message in the log */
1.51 cvs 1357: HTMLParseError (context->doc, msgBuffer);
1.84 quint 1358: /* special case for value POLYGON of attribute
1359: shape (AREA element) */
1360: if (attrType.AttrTypeNum == HTML_ATTR_shape &&
1361: strcasecmp (attrValue, "POLYGON") == 0)
1362: {
1363: val = HTML_ATTR_shape_VAL_polygon;
1364: /* interpret it as if it were "poly" */
1365: TtaSetAttributeValue (currentAttribute, val,
1366: lastAttrElement, context->doc);
1367: }
1368: else
1369: /* remove the attribute and replace it by an */
1370: /* Invalid_attribute (not for XHTML) */
1371: {
1372: TtaRemoveAttribute (lastAttrElement,
1.51 cvs 1373: currentAttribute, context->doc);
1.84 quint 1374: attrType.AttrSSchema =
1375: TtaGetDocumentSSchema (context->doc);
1376: attrType.AttrTypeNum =
1377: pHTMLAttributeMapping[0].ThotAttribute;
1378: sprintf (msgBuffer, "%s=%s", attrName,attrValue);
1379: CreateHTMLAttribute (lastAttrElement, attrType,
1380: msgBuffer, TRUE, context->doc,
1381: ¤tAttribute, &lastAttrElement);
1382: }
1.48 vatton 1383: }
1384: }
1385: else
1386: TtaSetAttributeValue (currentAttribute, val,
1387: lastAttrElement, context->doc);
1388: break;
1389: case 1: /* integer */
1390: if (attrType.AttrTypeNum == HTML_ATTR_Border &&
1391: !strcasecmp (attrValue, "border"))
1392: {
1393: /* border="border" for a table */
1394: val = 1;
1395: TtaSetAttributeValue (currentAttribute, val,
1.30 cvs 1396: lastAttrElement, context->doc);
1.48 vatton 1397: }
1398: else if (sscanf (attrValue, "%d", &val))
1399: TtaSetAttributeValue (currentAttribute, val,
1400: lastAttrElement, context->doc);
1401: else
1402: {
1403: TtaRemoveAttribute (lastAttrElement, currentAttribute,
1404: context->doc);
1405: sprintf (msgBuffer,
1406: "Unknown attribute value \"%s\"",
1407: attrValue);
1408: if (isXML)
1.100 gully 1409: XmlParseError (errorParsing, (unsigned char *)msgBuffer, 0);
1.48 vatton 1410: else
1411: HTMLParseError (context->doc, msgBuffer);
1412: }
1413: break;
1414: case 2: /* text */
1415: if (!UnknownAttr)
1416: {
1417: TtaSetAttributeText (currentAttribute, attrValue,
1418: lastAttrElement, context->doc);
1.55 cvs 1419: if (attrType.AttrTypeNum == HTML_ATTR_Language)
1.48 vatton 1420: {
1421: /* it's a LANG attribute value */
1422: lang = TtaGetLanguageIdFromName (attrValue);
1.70 vatton 1423: if (lang < 0)
1.48 vatton 1424: {
1425: sprintf (msgBuffer,
1426: "warning - unsupported language: %s",
1427: attrValue);
1428: if (isXML)
1.100 gully 1429: XmlParseError (warningMessage, (unsigned char *)msgBuffer, 0);
1.48 vatton 1430: else
1431: HTMLParseError (context->doc, msgBuffer);
1432: }
1433: else
1434: {
1435: /* change current language */
1436: context->language = lang;
1437: if (isXML)
1438: SetLanguagInXmlStack (lang);
1439: else
1440: SetLanguagInHTMLStack (lang);
1441: }
1442: root = TtaGetRootElement (context->doc);
1443: if (lastAttrElement == root)
1444: /* it's a LANG attribute on the root element */
1445: /* set the RealLang attribute */
1446: {
1447: attrType1.AttrSSchema = TtaGetDocumentSSchema (context->doc);
1448: attrType1.AttrTypeNum = HTML_ATTR_RealLang;
1449: /* this attribute could be already present,
1450: (lang and xml:lang attributes) */
1451: if (!TtaGetAttribute (lastAttrElement,
1452: attrType1))
1453: /* it's not present. Add it */
1454: {
1455: attr = TtaNewAttribute (attrType1);
1456: TtaAttachAttribute (lastAttrElement,
1457: attr, context->doc);
1458: TtaSetAttributeValue (attr,
1459: HTML_ATTR_RealLang_VAL_Yes_,
1460: lastAttrElement,
1461: context->doc);
1462: }
1463: }
1464: }
1465: else if (attrType.AttrTypeNum == HTML_ATTR_accesskey)
1466: TtaAddAccessKey (context->doc, (unsigned int)attrValue[0],
1467: lastAttrElement);
1468: }
1469: else
1470: {
1.51 cvs 1471: /* this is the content of an invalid attribute */
1472: /* append it to the current Invalid_attribute */
1473: if (!isXML)
1474: {
1475: length = strlen (attrValue) + 2;
1476: length += TtaGetTextAttributeLength (currentAttribute);
1.100 gully 1477: buffer = (char *)TtaGetMemory (length + 1);
1.51 cvs 1478: TtaGiveTextAttributeValue (currentAttribute,
1479: buffer, &length);
1480: strcat (buffer, "=");
1481: strcat (buffer, attrValue);
1482: TtaSetAttributeText (currentAttribute, buffer,
1483: lastAttrElement, context->doc);
1484: TtaFreeMemory (buffer);
1485: }
1.48 vatton 1486: }
1487: break;
1488: case 3: /* reference */
1489: break;
1490: }
1491: }
1492: break;
1493:
1494: case SPACE:
1495: if (isXML)
1496: XhtmlTypeAttrValue (attrValue, currentAttribute,
1.30 cvs 1497: lastAttrElement, context);
1.48 vatton 1498: else
1499: HTMLTypeAttrValue (attrValue, currentAttribute,
1500: lastAttrElement, context);
1501: break;
1502:
1.30 cvs 1503: default:
1504: break;
1.48 vatton 1505: }
1.30 cvs 1506:
1507: if (lastMappedAttr->ThotAttribute == HTML_ATTR_Width__)
1.79 quint 1508: /* HTML attribute "width" */
1509: {
1510: /* if it's an Object element, wait until all attributes are handled,
1511: especially the data attribute that may generate the image to
1512: which the width has to be applied */
1513: elType = TtaGetElementType (lastAttrElement);
1514: if (elType.ElTypeNum != HTML_EL_Object)
1515: /* create the corresponding attribute IntWidthPercent or */
1516: /* IntWidthPxl */
1517: CreateAttrWidthPercentPxl (attrValue, lastAttrElement,
1518: context->doc, -1);
1519: }
1.58 vatton 1520: else if (lastMappedAttr->ThotAttribute == HTML_ATTR_Height_)
1.79 quint 1521: /* HTML attribute "height" */
1522: {
1523: /* if it's an Object element, wait until all attributes are handled,
1524: especially the data attribute that may generate the image to
1525: which the height has to be applied */
1526: elType = TtaGetElementType (lastAttrElement);
1527: if (elType.ElTypeNum != HTML_EL_Object)
1528: /* create the corresponding attribute IntHeightPercent or */
1529: /* IntHeightPxl */
1530: CreateAttrHeightPercentPxl (attrValue, lastAttrElement,
1531: context->doc, -1);
1532: }
1.91 quint 1533: else if (lastMappedAttr->ThotAttribute == HTML_ATTR_Area_Size)
1534: /* HTML attribute "size" for an element "input" */
1535: CreateAttrIntAreaSize (val, lastAttrElement, context->doc);
1.48 vatton 1536: else if (!strcmp (lastMappedAttr->XMLattribute, "size"))
1537: {
1538: TtaGiveAttributeType (currentAttribute, &attrType, &attrKind);
1539: if (attrType.AttrTypeNum == HTML_ATTR_Font_size)
1540: CreateAttrIntSize (attrValue, lastAttrElement, context->doc);
1541: }
1542: else if (!strcmp (lastMappedAttr->XMLattribute, "shape"))
1543: {
1544: child = TtaGetFirstChild (lastAttrElement);
1545: if (child != NULL)
1546: {
1547: switch (val)
1548: {
1549: case HTML_ATTR_shape_VAL_rectangle:
1550: shape = 'R';
1551: break;
1552: case HTML_ATTR_shape_VAL_circle:
1553: shape = 'a';
1554: break;
1555: case HTML_ATTR_shape_VAL_polygon:
1556: shape = 'p';
1557: break;
1558: default:
1559: shape = SPACE;
1560: break;
1561: }
1562: TtaSetGraphicsShape (child, shape, context->doc);
1563: }
1564: }
1565: else if (!strcmp (lastMappedAttr->XMLattribute, "value"))
1566: {
1567: elType = TtaGetElementType (lastAttrElement);
1568: if (elType.ElTypeNum == HTML_EL_Text_Input ||
1569: elType.ElTypeNum == HTML_EL_Password_Input ||
1570: elType.ElTypeNum == HTML_EL_File_Input ||
1571: elType.ElTypeNum == HTML_EL_Input)
1572: /* create a Default_Value attribute with the same content */
1573: {
1574: attrType1.AttrSSchema = attrType.AttrSSchema;
1575: attrType1.AttrTypeNum = HTML_ATTR_Default_Value;
1576: attr = TtaNewAttribute (attrType1);
1577: TtaAttachAttribute (lastAttrElement, attr, context->doc);
1578: TtaSetAttributeText (attr, attrValue,
1579: lastAttrElement, context->doc);
1580: }
1581: }
1.30 cvs 1582: else
1.48 vatton 1583: {
1584: /* Some HTML attributes are equivalent to a CSS property: */
1585: /* background -> background */
1586: /* bgcolor -> background */
1587: /* text -> color */
1588: /* color -> color */
1589: if (!strcmp (lastMappedAttr->XMLattribute, "background"))
1590: {
1591: if (strlen (attrValue) > MaxMsgLength - 30)
1592: attrValue[MaxMsgLength - 30] = EOS;
1.76 vatton 1593: HTMLSetBackgroundImage (context->doc, context->lastElement,
1.85 vatton 1594: REPEAT, attrValue, FALSE);
1.48 vatton 1595: }
1596: else if (!strcmp (lastMappedAttr->XMLattribute, "bgcolor"))
1.76 vatton 1597: HTMLSetBackgroundColor (context->doc, context->lastElement,
1598: attrValue);
1.48 vatton 1599: else if (!strcmp (lastMappedAttr->XMLattribute, "text") ||
1600: !strcmp (lastMappedAttr->XMLattribute, "color"))
1601: HTMLSetForegroundColor (context->doc,
1602: context->lastElement, attrValue);
1603: }
1604: }
1.30 cvs 1605: }
1606:
1607: /*----------------------------------------------------------------------
1.16 cvs 1608: MapHTMLAttributeValue
1.2 cvs 1609: Search in the Attribute Value Mapping Table the entry for the attribute
1.66 vatton 1610: ThotAtt and its value attVal. Returns the corresponding Thot value.
1.1 cvs 1611: ----------------------------------------------------------------------*/
1.100 gully 1612: void MapHTMLAttributeValue (char *attVal, const AttributeType * attrType, int *value)
1.1 cvs 1613: {
1.66 vatton 1614: MapXMLAttributeValue (XHTML_TYPE, attVal, attrType, value);
1.1 cvs 1615: }
Webmaster