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