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