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