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