Annotation of Amaya/amaya/XHTMLbuilder.c, revision 1.99
1.1 cvs 1: /*
2: *
1.78 vatton 3: * (c) COPYRIGHT INRIA and W3C, 1996-2003
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.37 cvs 94: text = 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.37 cvs 105: text2 = 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.37 cvs 228: name1 = 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: {
256: data = TtaGetMemory (length + 1);
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: {
320: text = TtaGetMemory (length + 1);
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.79 quint 337: text = TtaGetMemory (length + 1);
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.37 cvs 514: text = TtaGetMemory (length + 1);
1.6 cvs 515: TtaGiveTextAttributeValue (attr, text, &length);
516: TtaSetTextContent (leaf, text,
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: {
544: TtaGiveSubString (leaf, lastChar, length, 1);
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);
621: text = TtaGetMemory (length);
622: TtaGiveTextContent (desc, text, &length, &lang);
623: TtaSetAttributeText (attr, text, el, doc);
624: TtaFreeMemory (text);
625: }
626: }
1.6 cvs 627: }
628: }
629: /* insert a Frame element */
630: newElType.ElTypeNum = HTML_EL_Frame;
631: constElem = TtaNewTree (doc, newElType, "");
632: TtaInsertSibling (constElem, child, FALSE, doc);
633: break;
634:
635: case HTML_EL_Radio_Input:
636: case HTML_EL_Checkbox_Input:
637: /* put an attribute Checked if it is missing */
638: attrType.AttrSSchema = docSSchema;
639: attrType.AttrTypeNum = HTML_ATTR_Checked;
640: if (TtaGetAttribute (el, attrType) == NULL)
641: /* attribute Checked is missing */
642: {
643: attr = TtaNewAttribute (attrType);
644: TtaAttachAttribute (el, attr, doc);
645: TtaSetAttributeValue (attr, HTML_ATTR_Checked_VAL_No_, el, doc);
646: }
647: break;
648:
649: case HTML_EL_Option_Menu:
650: /* Check that at least one option has a SELECTED attribute */
651: OnlyOneOptionSelected (el, doc, TRUE);
652: break;
653:
654: case HTML_EL_PICTURE_UNIT:
655: break;
656:
657: case HTML_EL_LINK:
658: CheckCSSLink (el, doc, docSSchema);
659: break;
660:
661: case HTML_EL_Data_cell:
662: case HTML_EL_Heading_cell:
663: /* insert a pseudo paragraph into empty cells */
664: child = TtaGetFirstChild (el);
665: if (child == NULL)
666: {
667: elType.ElTypeNum = HTML_EL_Pseudo_paragraph;
668: child = TtaNewTree (doc, elType, "");
669: if (child != NULL)
670: TtaInsertFirstChild (&child, el, doc);
671: }
672:
1.80 cvs 673: /* detect whether we are parsing a whole table or just a cell */
1.63 cvs 674: if (DocumentMeta[doc]->xmlformat)
675: {
676: if (IsWithinXmlTable ())
1.92 quint 677: NewCell (el, doc, FALSE, FALSE);
1.63 cvs 678: }
679: else
680: {
681: if (IsWithinHtmlTable ())
1.92 quint 682: NewCell (el, doc, FALSE, FALSE);
1.63 cvs 683: }
1.6 cvs 684: break;
685:
686: case HTML_EL_Table:
687: CheckTable (el, doc);
688: SubWithinTable ();
689: break;
690:
691: case HTML_EL_TITLE:
692: /* show the TITLE in the main window */
693: UpdateTitle (el, doc);
694: break;
1.41 cvs 695:
696: case HTML_EL_rbc:
697: /* an rbc element has been read. Its parent should be a complex_ruby.
698: Change the type of the parent, as simple_ruby are created by
699: default */
700: parent = TtaGetParent (el);
701: if (parent)
702: {
703: newElType = TtaGetElementType (parent);
704: if (newElType.ElSSchema == elType.ElSSchema &&
705: newElType.ElTypeNum == HTML_EL_simple_ruby)
1.95 vatton 706: TtaChangeElementType (parent, HTML_EL_complex_ruby);
1.41 cvs 707: }
708: break;
709:
710: case HTML_EL_rtc1:
711: /* an rtc element has been parsed. If it has already a rtc1 sibling,
712: change its type to rtc2 */
713: prev = el;
714: do
715: {
716: TtaPreviousSibling(&prev);
717: if (prev)
718: {
719: newElType = TtaGetElementType (prev);
720: if (newElType.ElSSchema == elType.ElSSchema &&
721: newElType.ElTypeNum == HTML_EL_rtc1)
722: {
1.95 vatton 723: TtaChangeElementType (el, HTML_EL_rtc2);
1.41 cvs 724: prev = NULL;
725: }
726: }
727: }
728: while (prev);
729: break;
730:
1.6 cvs 731: default:
732: break;
733: }
734: }
1.1 cvs 735:
736: /*----------------------------------------------------------------------
1.30 cvs 737: PutInContent
738: Put the string ChrString in the leaf of current element.
739: ----------------------------------------------------------------------*/
1.39 cvs 740: Element PutInContent (char *ChrString, ParserData *context)
1.30 cvs 741:
742: {
743: Element el, child;
744: ElementType elType;
745: int length;
746:
747: el = NULL;
748: if (context->lastElement != NULL)
749: {
750: /* search first leaf of current element */
751: el = context->lastElement;
752: do
753: {
754: child = TtaGetFirstChild (el);
755: if (child != NULL)
756: el = child;
757: }
758: while (child != NULL);
759: elType = TtaGetElementType (el);
760: length = 0;
761: if (elType.ElTypeNum == 1)
762: length = TtaGetTextLength (el);
763: if (length == 0)
764: TtaSetTextContent (el, ChrString, context->language, context->doc);
765: else
766: TtaAppendTextContent (el, ChrString, context->doc);
767: }
768: return el;
769: }
770:
771: /*----------------------------------------------------------------------
1.93 vatton 772: UnknownXhtmlNameSpace
773: The element doesn't belong to a supported namespace
1.51 cvs 774: ----------------------------------------------------------------------*/
1.93 vatton 775: void UnknownXhtmlNameSpace (ParserData *context, Element *unknownEl,
776: char* content)
1.51 cvs 777: {
778: ElementType elType;
1.65 cvs 779: Element elText;
1.51 cvs 780:
781: /* Create a new Invalid_element */
782: elType.ElSSchema = GetXMLSSchema (XHTML_TYPE, context->doc);
1.94 cvs 783: elType.ElTypeNum = HTML_EL_XHTML_Unknown_namespace;
1.65 cvs 784: *unknownEl = TtaNewElement (context->doc, elType);
785: if (*unknownEl != NULL)
1.51 cvs 786: {
1.65 cvs 787: XmlSetElemLineNumber (*unknownEl);
788: InsertXmlElement (unknownEl);
1.51 cvs 789: context->lastElementClosed = TRUE;
790: elType.ElTypeNum = HTML_EL_TEXT_UNIT;
791: elText = TtaNewElement (context->doc, elType);
792: XmlSetElemLineNumber (elText);
1.65 cvs 793: TtaInsertFirstChild (&elText, *unknownEl, context->doc);
1.51 cvs 794: TtaSetTextContent (elText, content, context->language, context->doc);
795: TtaSetAccessRight (elText, ReadOnly, context->doc);
796: }
797: }
798:
799: /*----------------------------------------------------------------------
1.30 cvs 800: CreateHTMLAttribute
801: create an attribute of type attrType for the element el.
802: ----------------------------------------------------------------------*/
1.93 vatton 803: void CreateHTMLAttribute (Element el,
804: AttributeType attrType,
805: char* text,
806: ThotBool isInvalid,
807: Document doc,
808: Attribute *lastAttribute,
809: Element *lastAttrElement)
1.30 cvs 810: {
811: int attrKind;
812: int length;
1.39 cvs 813: char *buffer;
1.30 cvs 814: Attribute attr, oldAttr;
815:
816: if (attrType.AttrTypeNum != 0)
817: {
818: oldAttr = TtaGetAttribute (el, attrType);
819: if (oldAttr != NULL)
820: /* this attribute already exists */
821: attr = oldAttr;
822: else
823: /* create a new attribute and attach it to the element */
824: {
825: attr = TtaNewAttribute (attrType);
826: TtaAttachAttribute (el, attr, doc);
827: }
828: *lastAttribute = attr;
829: *lastAttrElement = el;
830:
831: TtaGiveAttributeType (attr, &attrType, &attrKind);
832: if (attrKind == 0) /* enumerate */
833: TtaSetAttributeValue (attr, 1, el, doc);
834:
835: /* attribute BORDER without any value (ThotBool attribute) is */
836: /* considered as BORDER=1 */
837: if (attrType.AttrTypeNum == HTML_ATTR_Border)
838: TtaSetAttributeValue (attr, 1, el, doc);
839:
840: if (isInvalid)
841: /* Copy the name of the invalid attribute as the content */
842: /* of the Invalid_attribute attribute. */
843: {
1.37 cvs 844: length = strlen (text) + 2;
1.30 cvs 845: length += TtaGetTextAttributeLength (attr);
1.37 cvs 846: buffer = TtaGetMemory (length + 1);
1.30 cvs 847: TtaGiveTextAttributeValue (attr, buffer, &length);
1.37 cvs 848: strcat (buffer, " ");
849: strcat (buffer, text);
1.30 cvs 850: TtaSetAttributeText (attr, buffer, el, doc);
851: TtaFreeMemory (buffer);
852: }
853: }
854: }
855:
856: /*----------------------------------------------------------------------
857: HTMLTypeAttrValue
858: Value val has been read for the HTML attribute TYPE.
859: Create a child for the current Thot element INPUT accordingly.
860: ----------------------------------------------------------------------*/
1.46 cvs 861: void HTMLTypeAttrValue (char *val,
1.30 cvs 862: Attribute lastAttribute,
863: Element lastAttrElement,
864: ParserData *context)
865:
866: {
867: ElementType elType;
868: Element newChild;
869: AttributeType attrType;
870: Attribute attr;
1.39 cvs 871: char msgBuffer[MaxMsgLength];
1.30 cvs 872: int value;
873: int numberOfLinesRead;
874:
875: value = MapAttrValue (DummyAttribute, val);
1.91 quint 876: if (value <= 0)
1.30 cvs 877: {
1.37 cvs 878: if (strlen (val) > MaxMsgLength - 40)
879: val[MaxMsgLength - 40] = EOS;
880: sprintf (msgBuffer, "Unknown attribute value \"type = %s\"", val);
1.42 cvs 881: HTMLParseError (context->doc, msgBuffer);
1.30 cvs 882: attrType.AttrSSchema = TtaGetDocumentSSchema (context->doc);
883: attrType.AttrTypeNum = pHTMLAttributeMapping[0].ThotAttribute;
1.37 cvs 884: sprintf (msgBuffer, "type=%s", val);
1.30 cvs 885: CreateHTMLAttribute (context->lastElement, attrType, msgBuffer, TRUE,
886: context->doc, &lastAttribute, &lastAttrElement);
887: }
888: else
889: {
890: elType = TtaGetElementType (context->lastElement);
891: if (elType.ElTypeNum != HTML_EL_Input)
892: {
1.37 cvs 893: if (strlen (val) > MaxMsgLength - 40)
894: val[MaxMsgLength - 40] = EOS;
895: sprintf (msgBuffer, "Duplicate attribute \"type = %s\"", val);
1.30 cvs 896: }
897: else
898: {
899: elType.ElSSchema = TtaGetDocumentSSchema (context->doc);
900: elType.ElTypeNum = value;
901: newChild = TtaNewTree (context->doc, elType, "");
902: numberOfLinesRead = 0;
903: TtaSetElementLineNumber (newChild, numberOfLinesRead);
904: TtaInsertFirstChild (&newChild, context->lastElement, context->doc);
905: if (value == HTML_EL_PICTURE_UNIT)
906: {
907: /* add the attribute IsInput to input pictures */
908: attrType.AttrSSchema = elType.ElSSchema;
909: attrType.AttrTypeNum = HTML_ATTR_IsInput;
910: attr = TtaNewAttribute (attrType);
911: TtaAttachAttribute (newChild, attr, context->doc);
912: }
913: }
914: }
915: }
916:
917: /*----------------------------------------------------------------------
918: XhtmlTypeAttrValue
919: Value val has been read for the HTML attribute TYPE.
920: Create a child for the current Thot element INPUT accordingly.
921: ----------------------------------------------------------------------*/
1.46 cvs 922: void XhtmlTypeAttrValue (char *val,
1.30 cvs 923: Attribute currentAttribute,
924: Element lastAttrElement,
925: ParserData *context)
926:
927: {
928: ElementType elType;
929: Element newChild;
930: AttributeType attrType;
931: Attribute attr;
1.39 cvs 932: char msgBuffer[MaxMsgLength];
1.30 cvs 933: int value;
934: ThotBool level;
935:
1.91 quint 936: /* Look in the dummy section of the attribute value table */
1.30 cvs 937: attrType.AttrTypeNum = DummyAttribute;
938: MapHTMLAttributeValue (val, attrType, &value);
1.91 quint 939: if (value <= 0)
940: /* invalid value for the type attribute of an input element */
1.30 cvs 941: {
1.37 cvs 942: sprintf (msgBuffer, "Unknown attribute value \"type=%s\"", val);
1.30 cvs 943: XmlParseError (errorParsing, msgBuffer, 0);
1.36 cvs 944: MapHTMLAttribute ("unknown_attr", &attrType, NULL,
1.30 cvs 945: &level, context->doc);
1.37 cvs 946: sprintf (msgBuffer, "type=%s", val);
1.30 cvs 947: CreateHTMLAttribute (context->lastElement, attrType, msgBuffer, TRUE,
948: context->doc, ¤tAttribute, &lastAttrElement);
949: }
950: else
1.91 quint 951: /* value is the Thot type of the element to be created for this value of
952: the TYPE attribute */
1.30 cvs 953: {
954: elType = TtaGetElementType (context->lastElement);
955: if (elType.ElTypeNum != HTML_EL_Input)
956: {
1.37 cvs 957: sprintf (msgBuffer, "Duplicate attribute \"type = %s\"", val);
1.30 cvs 958: XmlParseError (errorParsing, msgBuffer, 0);
959: }
960: else
961: {
962: elType.ElTypeNum = value;
963: newChild = TtaNewTree (context->doc, elType, "");
964: XmlSetElemLineNumber (newChild);
965: TtaInsertFirstChild (&newChild, context->lastElement, context->doc);
966: if (value == HTML_EL_PICTURE_UNIT)
967: {
968: /* add the attribute IsInput to input pictures */
969: attrType.AttrSSchema = elType.ElSSchema;
970: attrType.AttrTypeNum = HTML_ATTR_IsInput;
971: attr = TtaNewAttribute (attrType);
972: TtaAttachAttribute (newChild, attr, context->doc);
973: }
974: }
975: }
976: }
977:
978: /*----------------------------------------------------------------------
979: CreateAttrWidthPercentPxl
1.79 quint 980: an HTML attribute "width" has been created for a Table, an image,
981: an Object of a HR.
1.30 cvs 982: Create the corresponding attribute IntWidthPercent or IntWidthPxl.
983: oldWidth is -1 or the old image width.
984: ----------------------------------------------------------------------*/
1.58 vatton 985: void CreateAttrWidthPercentPxl (char *buffer, Element el,
986: Document doc, int oldWidth)
1.30 cvs 987: {
988: AttributeType attrTypePxl, attrTypePercent;
989: Attribute attrOld, attrNew;
990: int length, val;
1.39 cvs 991: char msgBuffer[MaxMsgLength];
1.79 quint 992: ElementType elType, childType;
993: Element origEl, child;
1.30 cvs 994: int w, h;
995: ThotBool isImage;
996:
1.79 quint 997: origEl = el;
1.30 cvs 998: elType = TtaGetElementType (el);
999: isImage = (elType.ElTypeNum == HTML_EL_PICTURE_UNIT ||
1000: elType.ElTypeNum == HTML_EL_Data_cell ||
1.79 quint 1001: elType.ElTypeNum == HTML_EL_Heading_cell ||
1002: elType.ElTypeNum == HTML_EL_Object);
1003: if (elType.ElTypeNum == HTML_EL_Object)
1004: /* the width attribute is attached to an Object element */
1005: {
1006: child = TtaGetFirstChild (el);
1007: if (child)
1008: {
1009: childType = TtaGetElementType (child);
1010: if (childType.ElTypeNum == HTML_EL_PICTURE_UNIT)
1011: /* the Object element is of type image. apply the width
1012: attribute to the actual image element */
1013: el = child;
1014: }
1015: }
1.30 cvs 1016: /* remove trailing spaces */
1.37 cvs 1017: length = strlen (buffer) - 1;
1.30 cvs 1018: while (length > 0 && buffer[length] <= SPACE)
1019: length--;
1020: attrTypePxl.AttrSSchema = TtaGetDocumentSSchema (doc);
1021: attrTypePercent.AttrSSchema = TtaGetDocumentSSchema (doc);
1022: attrTypePxl.AttrTypeNum = HTML_ATTR_IntWidthPxl;
1023: attrTypePercent.AttrTypeNum = HTML_ATTR_IntWidthPercent;
1024: /* is the last character a '%' ? */
1025: if (buffer[length] == '%')
1026: {
1027: /* remove IntWidthPxl */
1028: attrOld = TtaGetAttribute (el, attrTypePxl);
1029: /* update IntWidthPercent */
1030: attrNew = TtaGetAttribute (el, attrTypePercent);
1031: if (attrNew == NULL)
1032: {
1033: attrNew = TtaNewAttribute (attrTypePercent);
1034: TtaAttachAttribute (el, attrNew, doc);
1035: }
1036: else if (isImage && oldWidth == -1)
1037: {
1038: if (attrOld == NULL)
1039: oldWidth = TtaGetAttributeValue (attrNew);
1040: else
1041: oldWidth = TtaGetAttributeValue (attrOld);
1042: }
1043: }
1044: else
1045: {
1046: /* remove IntWidthPercent */
1047: attrOld = TtaGetAttribute (el, attrTypePercent);
1048: /* update IntWidthPxl */
1049: attrNew = TtaGetAttribute (el, attrTypePxl);
1050: if (attrNew == NULL)
1051: {
1052: attrNew = TtaNewAttribute (attrTypePxl);
1053: TtaAttachAttribute (el, attrNew, doc);
1054: }
1055: else if (isImage && oldWidth == -1)
1056: {
1057: TtaGiveBoxSize (el, doc, 1, UnPixel, &w, &h);
1058: if (attrOld == NULL)
1059: oldWidth = w * TtaGetAttributeValue (attrNew) / 100;
1060: else
1061: oldWidth = w * TtaGetAttributeValue (attrOld) / 100;
1062: }
1063: }
1064:
1065: if (attrOld != NULL)
1066: TtaRemoveAttribute (el, attrOld, doc);
1.43 cvs 1067: if (sscanf (buffer, "%d", &val))
1.30 cvs 1068: TtaSetAttributeValue (attrNew, val, el, doc);
1069: else
1070: /* its not a number. Delete attribute and send an error message */
1071: {
1072: TtaRemoveAttribute (el, attrNew, doc);
1.37 cvs 1073: if (strlen (buffer) > MaxMsgLength - 30)
1.30 cvs 1074: buffer[MaxMsgLength - 30] = EOS;
1.37 cvs 1075: sprintf (msgBuffer, "Invalid attribute value \"%s\"", buffer);
1.42 cvs 1076: HTMLParseError (doc, msgBuffer);
1.30 cvs 1077: }
1078: if (isImage)
1.79 quint 1079: UpdateImageMap (origEl, doc, oldWidth, -1);
1.30 cvs 1080: }
1081:
1082: /*----------------------------------------------------------------------
1.58 vatton 1083: CreateAttrHeightPercentPxl
1.79 quint 1084: an HTML attribute "width" has been created for a Table, an image,
1085: an Object or a HR.
1.58 vatton 1086: Create the corresponding attribute IntHeightPercent or IntHeightPxl.
1087: oldHeight is -1 or the old image width.
1088: ----------------------------------------------------------------------*/
1089: void CreateAttrHeightPercentPxl (char *buffer, Element el,
1090: Document doc, int oldHeight)
1091: {
1092: AttributeType attrTypePxl, attrTypePercent;
1093: Attribute attrOld, attrNew;
1094: int length, val;
1095: char msgBuffer[MaxMsgLength];
1.79 quint 1096: ElementType elType, childType;
1097: Element origEl, child;
1.58 vatton 1098: int w, h;
1099: ThotBool isImage;
1100:
1.79 quint 1101: origEl = el;
1.58 vatton 1102: elType = TtaGetElementType (el);
1103: isImage = (elType.ElTypeNum == HTML_EL_PICTURE_UNIT ||
1104: elType.ElTypeNum == HTML_EL_Data_cell ||
1.79 quint 1105: elType.ElTypeNum == HTML_EL_Heading_cell ||
1106: elType.ElTypeNum == HTML_EL_Object);
1107: if (elType.ElTypeNum == HTML_EL_Object)
1108: /* the height attribute is attached to an Object element */
1109: {
1110: child = TtaGetFirstChild (el);
1.81 cvs 1111: if (!child)
1112: return;
1113: else
1.79 quint 1114: {
1115: childType = TtaGetElementType (child);
1116: if (childType.ElTypeNum == HTML_EL_PICTURE_UNIT)
1117: /* the Object element is of type image. apply the width
1118: attribute to the actual image element */
1119: el = child;
1.81 cvs 1120: else
1121: return;
1.79 quint 1122: }
1123: }
1.58 vatton 1124: /* remove trailing spaces */
1125: length = strlen (buffer) - 1;
1126: while (length > 0 && buffer[length] <= SPACE)
1127: length--;
1128: attrTypePxl.AttrSSchema = TtaGetDocumentSSchema (doc);
1129: attrTypePercent.AttrSSchema = TtaGetDocumentSSchema (doc);
1130: attrTypePxl.AttrTypeNum = HTML_ATTR_IntHeightPxl;
1131: attrTypePercent.AttrTypeNum = HTML_ATTR_IntHeightPercent;
1132: /* is the last character a '%' ? */
1133: if (buffer[length] == '%')
1134: {
1135: /* remove IntHeightPxl */
1136: attrOld = TtaGetAttribute (el, attrTypePxl);
1137: /* update IntHeightPercent */
1138: attrNew = TtaGetAttribute (el, attrTypePercent);
1139: if (attrNew == NULL)
1140: {
1141: attrNew = TtaNewAttribute (attrTypePercent);
1142: TtaAttachAttribute (el, attrNew, doc);
1143: }
1144: else if (isImage && oldHeight == -1)
1145: {
1146: if (attrOld == NULL)
1147: oldHeight = TtaGetAttributeValue (attrNew);
1148: else
1149: oldHeight = TtaGetAttributeValue (attrOld);
1150: }
1151: }
1152: else
1153: {
1154: /* remove IntHeightPercent */
1155: attrOld = TtaGetAttribute (el, attrTypePercent);
1156: /* update IntHeightPxl */
1157: attrNew = TtaGetAttribute (el, attrTypePxl);
1158: if (attrNew == NULL)
1159: {
1160: attrNew = TtaNewAttribute (attrTypePxl);
1161: TtaAttachAttribute (el, attrNew, doc);
1162: }
1163: else if (isImage && oldHeight == -1)
1164: {
1165: TtaGiveBoxSize (el, doc, 1, UnPixel, &w, &h);
1166: if (attrOld == NULL)
1167: oldHeight = w * TtaGetAttributeValue (attrNew) / 100;
1168: else
1169: oldHeight = w * TtaGetAttributeValue (attrOld) / 100;
1170: }
1171: }
1172:
1173: if (attrOld != NULL)
1174: TtaRemoveAttribute (el, attrOld, doc);
1175: if (sscanf (buffer, "%d", &val))
1176: TtaSetAttributeValue (attrNew, val, el, doc);
1177: else
1178: /* its not a number. Delete attribute and send an error message */
1179: {
1180: TtaRemoveAttribute (el, attrNew, doc);
1181: if (strlen (buffer) > MaxMsgLength - 30)
1182: buffer[MaxMsgLength - 30] = EOS;
1183: sprintf (msgBuffer, "Invalid attribute value \"%s\"", buffer);
1184: HTMLParseError (doc, msgBuffer);
1185: }
1186: if (isImage)
1.79 quint 1187: UpdateImageMap (origEl, doc, oldHeight, -1);
1.58 vatton 1188: }
1189:
1190: /*----------------------------------------------------------------------
1.91 quint 1191: CreateAttrIntAreaSize
1192: an HTML attribute "size" has been created or modified for a input element.
1193: Create or update the corresponding attribute IntAreaSize.
1194: ----------------------------------------------------------------------*/
1195: void CreateAttrIntAreaSize (int value, Element el, Document doc)
1196: {
1197: AttributeType attrType;
1198: Attribute attr;
1199: ElementType elType;
1200:
1201: elType = TtaGetElementType (el);
1202: attrType.AttrSSchema = elType.ElSSchema;
1203: attrType.AttrTypeNum = HTML_ATTR_IntAreaSize;
1204: attr = TtaGetAttribute (el, attrType);
1205: if (!attr)
1206: {
1207: attr = TtaNewAttribute (attrType);
1208: TtaAttachAttribute (el, attr, doc);
1209: }
1210: /* the presentation rule associated with attribute IntAreaSize expresses
1211: the element width in "em". Convert the value into em */
1212: TtaSetAttributeValue (attr, (int) (value * 0.55), el, doc);
1213: }
1214:
1215: /*----------------------------------------------------------------------
1.30 cvs 1216: CreateAttrIntSize
1217: an HTML attribute "size" has been created for a Font element.
1218: Create the corresponding internal attribute.
1219: ----------------------------------------------------------------------*/
1.46 cvs 1220: void CreateAttrIntSize (char *buffer, Element el, Document doc)
1.30 cvs 1221:
1222: {
1223: AttributeType attrType;
1224: int val, ind, factor, delta;
1225: Attribute attr;
1.37 cvs 1226: char msgBuffer[MaxMsgLength];
1.30 cvs 1227:
1228: /* is the first character a '+' or a '-' ? */
1229: ind = 0;
1230: factor = 1;
1231: delta = 0;
1232: if (buffer[0] == '+')
1233: {
1234: attrType.AttrTypeNum = HTML_ATTR_IntSizeIncr;
1235: ind++;
1.90 vatton 1236: factor = 1;
1.30 cvs 1237: }
1238: else if (buffer[0] == '-')
1239: {
1240: attrType.AttrTypeNum = HTML_ATTR_IntSizeDecr;
1241: ind++;
1.90 vatton 1242: factor = 1;
1.30 cvs 1243: }
1244: else
1245: {
1246: attrType.AttrTypeNum = HTML_ATTR_IntSizeRel;
1247: delta = 1;
1248: }
1249: attrType.AttrSSchema = TtaGetDocumentSSchema (doc);
1250: attr = TtaGetAttribute (el, attrType);
1.43 cvs 1251: if (sscanf (&buffer[ind], "%d", &val))
1.30 cvs 1252: {
1253: val = val * factor + delta;
1254: if (attr == NULL)
1255: {
1256: /* this attribute doesn't exist, create it */
1257: attr = TtaNewAttribute (attrType);
1258: TtaAttachAttribute (el, attr, doc);
1259: }
1260: TtaSetAttributeValue (attr, val, el, doc);
1261: }
1262: else
1263: /* its not a number. Delete attribute and send an error message */
1264: {
1265: if (attr)
1266: TtaRemoveAttribute (el, attr, doc);
1.37 cvs 1267: if (strlen (buffer) > MaxMsgLength - 30)
1.30 cvs 1268: buffer[MaxMsgLength - 30] = EOS;
1.37 cvs 1269: sprintf (msgBuffer, "Invalid attribute value \"%s\"", buffer);
1.42 cvs 1270: HTMLParseError (doc, msgBuffer);
1.30 cvs 1271: }
1272: }
1273: /*----------------------------------------------------------------------
1274: EndOfHTMLAttributeValue
1275: Filling of an HTML attribute value
1276: ----------------------------------------------------------------------*/
1.48 vatton 1277: void EndOfHTMLAttributeValue (char *attrValue,
1278: AttributeMapping *lastMappedAttr,
1279: Attribute currentAttribute,
1280: Element lastAttrElement,
1281: ThotBool UnknownAttr,
1282: ParserData *context,
1283: ThotBool isXML)
1.30 cvs 1284: {
1.48 vatton 1285: AttributeType attrType, attrType1;
1286: Attribute attr;
1.79 quint 1287: ElementType elType;
1.48 vatton 1288: Element child, root;
1289: Language lang;
1290: char translation;
1291: char shape;
1292: char *buffer;
1293: char *attrName;
1294: char msgBuffer[MaxMsgLength];
1295: int val;
1296: int length;
1297: int attrKind;
1298: ThotBool done = FALSE;
1.88 vatton 1299: ThotBool loadcss;
1.30 cvs 1300:
1.48 vatton 1301: /* treatments of some particular HTML attributes */
1302: if (!strcmp (lastMappedAttr->XMLattribute, "style"))
1303: {
1304: TtaSetAttributeText (currentAttribute, attrValue,
1305: lastAttrElement, context->doc);
1.88 vatton 1306: /* check if we have to load CSS */
1307: TtaGetEnvBoolean ("LOAD_CSS", &loadcss);
1308: if (loadcss)
1309: ParseHTMLSpecificStyle (context->lastElement, attrValue,
1310: context->doc, 100, FALSE);
1.48 vatton 1311: done = TRUE;
1312: }
1313: else
1314: {
1315: if (!strcmp (lastMappedAttr->XMLattribute, "link"))
1.89 vatton 1316: HTMLSetAlinkColor (context->doc, context->lastElement, attrValue);
1.48 vatton 1317: else if (!strcmp (lastMappedAttr->XMLattribute, "alink"))
1.89 vatton 1318: HTMLSetAactiveColor (context->doc, context->lastElement, attrValue);
1.48 vatton 1319: else if (!strcmp (lastMappedAttr->XMLattribute, "vlink"))
1.89 vatton 1320: HTMLSetAvisitedColor (context->doc, context->lastElement, attrValue);
1.48 vatton 1321: }
1.30 cvs 1322:
1.48 vatton 1323: if (!done)
1324: {
1325: val = 0;
1326: translation = lastMappedAttr->AttrOrContent;
1327: switch (translation)
1328: {
1329: case 'C': /* Content */
1330: child = PutInContent (attrValue, context);
1331: if (child != NULL)
1332: TtaAppendTextContent (child, "\" ", context->doc);
1333: break;
1334:
1335: case 'A':
1336: if (currentAttribute != NULL)
1337: {
1338: TtaGiveAttributeType (currentAttribute, &attrType, &attrKind);
1339: switch (attrKind)
1340: {
1341: case 0: /* enumerate */
1342: if (isXML)
1343: MapHTMLAttributeValue (attrValue, attrType, &val);
1344: else
1345: val = MapAttrValue (lastMappedAttr->ThotAttribute,
1.40 cvs 1346: attrValue);
1.48 vatton 1347: if (val < 0)
1348: {
1349: TtaGiveAttributeType (currentAttribute,
1350: &attrType, &attrKind);
1351: attrName = TtaGetAttributeName (attrType);
1352: sprintf (msgBuffer,
1.51 cvs 1353: "Invalid attribute value \"%s = %s\"",
1.48 vatton 1354: attrName, attrValue);
1355: if (isXML)
1356: XmlParseError (errorParsing, msgBuffer, 0);
1357: else
1.84 quint 1358: /* we are parsing an HTML file, not an XHTML file */
1.51 cvs 1359: {
1.84 quint 1360: /* generate an error message in the log */
1.51 cvs 1361: HTMLParseError (context->doc, msgBuffer);
1.84 quint 1362: /* special case for value POLYGON of attribute
1363: shape (AREA element) */
1364: if (attrType.AttrTypeNum == HTML_ATTR_shape &&
1365: strcasecmp (attrValue, "POLYGON") == 0)
1366: {
1367: val = HTML_ATTR_shape_VAL_polygon;
1368: /* interpret it as if it were "poly" */
1369: TtaSetAttributeValue (currentAttribute, val,
1370: lastAttrElement, context->doc);
1371: }
1372: else
1373: /* remove the attribute and replace it by an */
1374: /* Invalid_attribute (not for XHTML) */
1375: {
1376: TtaRemoveAttribute (lastAttrElement,
1.51 cvs 1377: currentAttribute, context->doc);
1.84 quint 1378: attrType.AttrSSchema =
1379: TtaGetDocumentSSchema (context->doc);
1380: attrType.AttrTypeNum =
1381: pHTMLAttributeMapping[0].ThotAttribute;
1382: sprintf (msgBuffer, "%s=%s", attrName,attrValue);
1383: CreateHTMLAttribute (lastAttrElement, attrType,
1384: msgBuffer, TRUE, context->doc,
1385: ¤tAttribute, &lastAttrElement);
1386: }
1.48 vatton 1387: }
1388: }
1389: else
1390: TtaSetAttributeValue (currentAttribute, val,
1391: lastAttrElement, context->doc);
1392: break;
1393: case 1: /* integer */
1394: if (attrType.AttrTypeNum == HTML_ATTR_Border &&
1395: !strcasecmp (attrValue, "border"))
1396: {
1397: /* border="border" for a table */
1398: val = 1;
1399: TtaSetAttributeValue (currentAttribute, val,
1.30 cvs 1400: lastAttrElement, context->doc);
1.48 vatton 1401: }
1402: else if (sscanf (attrValue, "%d", &val))
1403: TtaSetAttributeValue (currentAttribute, val,
1404: lastAttrElement, context->doc);
1405: else
1406: {
1407: TtaRemoveAttribute (lastAttrElement, currentAttribute,
1408: context->doc);
1409: sprintf (msgBuffer,
1410: "Unknown attribute value \"%s\"",
1411: attrValue);
1412: if (isXML)
1413: XmlParseError (errorParsing, msgBuffer, 0);
1414: else
1415: HTMLParseError (context->doc, msgBuffer);
1416: }
1417: break;
1418: case 2: /* text */
1419: if (!UnknownAttr)
1420: {
1421: TtaSetAttributeText (currentAttribute, attrValue,
1422: lastAttrElement, context->doc);
1.55 cvs 1423: if (attrType.AttrTypeNum == HTML_ATTR_Language)
1.48 vatton 1424: {
1425: /* it's a LANG attribute value */
1426: lang = TtaGetLanguageIdFromName (attrValue);
1.70 vatton 1427: if (lang < 0)
1.48 vatton 1428: {
1429: sprintf (msgBuffer,
1430: "warning - unsupported language: %s",
1431: attrValue);
1432: if (isXML)
1.87 vatton 1433: XmlParseError (warningMessage, msgBuffer, 0);
1.48 vatton 1434: else
1435: HTMLParseError (context->doc, msgBuffer);
1436: }
1437: else
1438: {
1439: /* change current language */
1440: context->language = lang;
1441: if (isXML)
1442: SetLanguagInXmlStack (lang);
1443: else
1444: SetLanguagInHTMLStack (lang);
1445: }
1446: root = TtaGetRootElement (context->doc);
1447: if (lastAttrElement == root)
1448: /* it's a LANG attribute on the root element */
1449: /* set the RealLang attribute */
1450: {
1451: attrType1.AttrSSchema = TtaGetDocumentSSchema (context->doc);
1452: attrType1.AttrTypeNum = HTML_ATTR_RealLang;
1453: /* this attribute could be already present,
1454: (lang and xml:lang attributes) */
1455: if (!TtaGetAttribute (lastAttrElement,
1456: attrType1))
1457: /* it's not present. Add it */
1458: {
1459: attr = TtaNewAttribute (attrType1);
1460: TtaAttachAttribute (lastAttrElement,
1461: attr, context->doc);
1462: TtaSetAttributeValue (attr,
1463: HTML_ATTR_RealLang_VAL_Yes_,
1464: lastAttrElement,
1465: context->doc);
1466: }
1467: }
1468: }
1469: else if (attrType.AttrTypeNum == HTML_ATTR_accesskey)
1470: TtaAddAccessKey (context->doc, (unsigned int)attrValue[0],
1471: lastAttrElement);
1472: }
1473: else
1474: {
1.51 cvs 1475: /* this is the content of an invalid attribute */
1476: /* append it to the current Invalid_attribute */
1477: if (!isXML)
1478: {
1479: length = strlen (attrValue) + 2;
1480: length += TtaGetTextAttributeLength (currentAttribute);
1481: buffer = TtaGetMemory (length + 1);
1482: TtaGiveTextAttributeValue (currentAttribute,
1483: buffer, &length);
1484: strcat (buffer, "=");
1485: strcat (buffer, attrValue);
1486: TtaSetAttributeText (currentAttribute, buffer,
1487: lastAttrElement, context->doc);
1488: TtaFreeMemory (buffer);
1489: }
1.48 vatton 1490: }
1491: break;
1492: case 3: /* reference */
1493: break;
1494: }
1495: }
1496: break;
1497:
1498: case SPACE:
1499: if (isXML)
1500: XhtmlTypeAttrValue (attrValue, currentAttribute,
1.30 cvs 1501: lastAttrElement, context);
1.48 vatton 1502: else
1503: HTMLTypeAttrValue (attrValue, currentAttribute,
1504: lastAttrElement, context);
1505: break;
1506:
1.30 cvs 1507: default:
1508: break;
1.48 vatton 1509: }
1.30 cvs 1510:
1511: if (lastMappedAttr->ThotAttribute == HTML_ATTR_Width__)
1.79 quint 1512: /* HTML attribute "width" */
1513: {
1514: /* if it's an Object element, wait until all attributes are handled,
1515: especially the data attribute that may generate the image to
1516: which the width has to be applied */
1517: elType = TtaGetElementType (lastAttrElement);
1518: if (elType.ElTypeNum != HTML_EL_Object)
1519: /* create the corresponding attribute IntWidthPercent or */
1520: /* IntWidthPxl */
1521: CreateAttrWidthPercentPxl (attrValue, lastAttrElement,
1522: context->doc, -1);
1523: }
1.58 vatton 1524: else if (lastMappedAttr->ThotAttribute == HTML_ATTR_Height_)
1.79 quint 1525: /* HTML attribute "height" */
1526: {
1527: /* if it's an Object element, wait until all attributes are handled,
1528: especially the data attribute that may generate the image to
1529: which the height has to be applied */
1530: elType = TtaGetElementType (lastAttrElement);
1531: if (elType.ElTypeNum != HTML_EL_Object)
1532: /* create the corresponding attribute IntHeightPercent or */
1533: /* IntHeightPxl */
1534: CreateAttrHeightPercentPxl (attrValue, lastAttrElement,
1535: context->doc, -1);
1536: }
1.91 quint 1537: else if (lastMappedAttr->ThotAttribute == HTML_ATTR_Area_Size)
1538: /* HTML attribute "size" for an element "input" */
1539: CreateAttrIntAreaSize (val, lastAttrElement, context->doc);
1.48 vatton 1540: else if (!strcmp (lastMappedAttr->XMLattribute, "size"))
1541: {
1542: TtaGiveAttributeType (currentAttribute, &attrType, &attrKind);
1543: if (attrType.AttrTypeNum == HTML_ATTR_Font_size)
1544: CreateAttrIntSize (attrValue, lastAttrElement, context->doc);
1545: }
1546: else if (!strcmp (lastMappedAttr->XMLattribute, "shape"))
1547: {
1548: child = TtaGetFirstChild (lastAttrElement);
1549: if (child != NULL)
1550: {
1551: switch (val)
1552: {
1553: case HTML_ATTR_shape_VAL_rectangle:
1554: shape = 'R';
1555: break;
1556: case HTML_ATTR_shape_VAL_circle:
1557: shape = 'a';
1558: break;
1559: case HTML_ATTR_shape_VAL_polygon:
1560: shape = 'p';
1561: break;
1562: default:
1563: shape = SPACE;
1564: break;
1565: }
1566: TtaSetGraphicsShape (child, shape, context->doc);
1567: }
1568: }
1569: else if (!strcmp (lastMappedAttr->XMLattribute, "value"))
1570: {
1571: elType = TtaGetElementType (lastAttrElement);
1572: if (elType.ElTypeNum == HTML_EL_Text_Input ||
1573: elType.ElTypeNum == HTML_EL_Password_Input ||
1574: elType.ElTypeNum == HTML_EL_File_Input ||
1575: elType.ElTypeNum == HTML_EL_Input)
1576: /* create a Default_Value attribute with the same content */
1577: {
1578: attrType1.AttrSSchema = attrType.AttrSSchema;
1579: attrType1.AttrTypeNum = HTML_ATTR_Default_Value;
1580: attr = TtaNewAttribute (attrType1);
1581: TtaAttachAttribute (lastAttrElement, attr, context->doc);
1582: TtaSetAttributeText (attr, attrValue,
1583: lastAttrElement, context->doc);
1584: }
1585: }
1.30 cvs 1586: else
1.48 vatton 1587: {
1588: /* Some HTML attributes are equivalent to a CSS property: */
1589: /* background -> background */
1590: /* bgcolor -> background */
1591: /* text -> color */
1592: /* color -> color */
1593: if (!strcmp (lastMappedAttr->XMLattribute, "background"))
1594: {
1595: if (strlen (attrValue) > MaxMsgLength - 30)
1596: attrValue[MaxMsgLength - 30] = EOS;
1.76 vatton 1597: HTMLSetBackgroundImage (context->doc, context->lastElement,
1.85 vatton 1598: REPEAT, attrValue, FALSE);
1.48 vatton 1599: }
1600: else if (!strcmp (lastMappedAttr->XMLattribute, "bgcolor"))
1.76 vatton 1601: HTMLSetBackgroundColor (context->doc, context->lastElement,
1602: attrValue);
1.48 vatton 1603: else if (!strcmp (lastMappedAttr->XMLattribute, "text") ||
1604: !strcmp (lastMappedAttr->XMLattribute, "color"))
1605: HTMLSetForegroundColor (context->doc,
1606: context->lastElement, attrValue);
1607: }
1608: }
1.30 cvs 1609: }
1610:
1611: /*----------------------------------------------------------------------
1.16 cvs 1612: MapHTMLAttributeValue
1.2 cvs 1613: Search in the Attribute Value Mapping Table the entry for the attribute
1.66 vatton 1614: ThotAtt and its value attVal. Returns the corresponding Thot value.
1.1 cvs 1615: ----------------------------------------------------------------------*/
1.66 vatton 1616: void MapHTMLAttributeValue (char *attVal, AttributeType attrType, int *value)
1.1 cvs 1617: {
1.66 vatton 1618: MapXMLAttributeValue (XHTML_TYPE, attVal, attrType, value);
1.1 cvs 1619: }
Webmaster