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