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