Return to XHTMLbuilder.c CVS log | Up to [Public] / Amaya / amaya |
1.1 cvs 1: /* 2: * 1.59 quint 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 845: Create an element that belongs to a non-supported namespace 846: ----------------------------------------------------------------------*/ 847: void UnknownXhtmlNameSpace (ParserData *context, char* content) 848: { 849: ElementType elType; 850: Element elInv, elText; 851: 852: /* Create a new Invalid_element */ 853: elType.ElSSchema = GetXMLSSchema (XHTML_TYPE, context->doc); 854: elType.ElTypeNum = HTML_EL_Unknown_namespace; 855: elInv = TtaNewElement (context->doc, elType); 856: if (elInv != NULL) 857: { 858: XmlSetElemLineNumber (elInv); 859: InsertXmlElement (&elInv); 860: context->lastElementClosed = TRUE; 861: elType.ElTypeNum = HTML_EL_TEXT_UNIT; 862: elText = TtaNewElement (context->doc, elType); 863: XmlSetElemLineNumber (elText); 864: TtaInsertFirstChild (&elText, elInv, context->doc); 865: TtaSetTextContent (elText, content, context->language, context->doc); 866: TtaSetAccessRight (elText, ReadOnly, context->doc); 867: } 868: } 869: 870: /*---------------------------------------------------------------------- 1.30 cvs 871: CreateHTMLAttribute 872: create an attribute of type attrType for the element el. 873: ----------------------------------------------------------------------*/ 874: void CreateHTMLAttribute (Element el, 875: AttributeType attrType, 1.46 cvs 876: char* text, 1.30 cvs 877: ThotBool isInvalid, 878: Document doc, 879: Attribute *lastAttribute, 880: Element *lastAttrElement) 881: 882: { 883: int attrKind; 884: int length; 1.39 cvs 885: char *buffer; 1.30 cvs 886: Attribute attr, oldAttr; 887: 888: if (attrType.AttrTypeNum != 0) 889: { 890: oldAttr = TtaGetAttribute (el, attrType); 891: if (oldAttr != NULL) 892: /* this attribute already exists */ 893: attr = oldAttr; 894: else 895: /* create a new attribute and attach it to the element */ 896: { 897: attr = TtaNewAttribute (attrType); 898: TtaAttachAttribute (el, attr, doc); 899: } 900: *lastAttribute = attr; 901: *lastAttrElement = el; 902: 903: TtaGiveAttributeType (attr, &attrType, &attrKind); 904: if (attrKind == 0) /* enumerate */ 905: TtaSetAttributeValue (attr, 1, el, doc); 906: 907: /* attribute BORDER without any value (ThotBool attribute) is */ 908: /* considered as BORDER=1 */ 909: if (attrType.AttrTypeNum == HTML_ATTR_Border) 910: TtaSetAttributeValue (attr, 1, el, doc); 911: 912: if (isInvalid) 913: /* Copy the name of the invalid attribute as the content */ 914: /* of the Invalid_attribute attribute. */ 915: { 1.37 cvs 916: length = strlen (text) + 2; 1.30 cvs 917: length += TtaGetTextAttributeLength (attr); 1.37 cvs 918: buffer = TtaGetMemory (length + 1); 1.30 cvs 919: TtaGiveTextAttributeValue (attr, buffer, &length); 1.37 cvs 920: strcat (buffer, " "); 921: strcat (buffer, text); 1.30 cvs 922: TtaSetAttributeText (attr, buffer, el, doc); 923: TtaFreeMemory (buffer); 924: } 925: } 926: } 927: 928: /*---------------------------------------------------------------------- 929: HTMLTypeAttrValue 930: Value val has been read for the HTML attribute TYPE. 931: Create a child for the current Thot element INPUT accordingly. 932: ----------------------------------------------------------------------*/ 1.46 cvs 933: void HTMLTypeAttrValue (char *val, 1.30 cvs 934: Attribute lastAttribute, 935: Element lastAttrElement, 936: ParserData *context) 937: 938: { 939: ElementType elType; 940: Element newChild; 941: AttributeType attrType; 942: Attribute attr; 1.39 cvs 943: char msgBuffer[MaxMsgLength]; 1.30 cvs 944: int value; 945: int numberOfLinesRead; 946: 947: value = MapAttrValue (DummyAttribute, val); 948: if (value < 0) 949: { 1.37 cvs 950: if (strlen (val) > MaxMsgLength - 40) 951: val[MaxMsgLength - 40] = EOS; 952: sprintf (msgBuffer, "Unknown attribute value \"type = %s\"", val); 1.42 cvs 953: HTMLParseError (context->doc, msgBuffer); 1.30 cvs 954: attrType.AttrSSchema = TtaGetDocumentSSchema (context->doc); 955: attrType.AttrTypeNum = pHTMLAttributeMapping[0].ThotAttribute; 1.37 cvs 956: sprintf (msgBuffer, "type=%s", val); 1.30 cvs 957: CreateHTMLAttribute (context->lastElement, attrType, msgBuffer, TRUE, 958: context->doc, &lastAttribute, &lastAttrElement); 959: } 960: else 961: { 962: elType = TtaGetElementType (context->lastElement); 963: if (elType.ElTypeNum != HTML_EL_Input) 964: { 1.37 cvs 965: if (strlen (val) > MaxMsgLength - 40) 966: val[MaxMsgLength - 40] = EOS; 967: sprintf (msgBuffer, "Duplicate attribute \"type = %s\"", val); 1.30 cvs 968: } 969: else 970: { 971: elType.ElSSchema = TtaGetDocumentSSchema (context->doc); 972: elType.ElTypeNum = value; 973: newChild = TtaNewTree (context->doc, elType, ""); 974: numberOfLinesRead = 0; 975: TtaSetElementLineNumber (newChild, numberOfLinesRead); 976: TtaInsertFirstChild (&newChild, context->lastElement, context->doc); 977: if (value == HTML_EL_PICTURE_UNIT) 978: { 979: /* add the attribute IsInput to input pictures */ 980: attrType.AttrSSchema = elType.ElSSchema; 981: attrType.AttrTypeNum = HTML_ATTR_IsInput; 982: attr = TtaNewAttribute (attrType); 983: TtaAttachAttribute (newChild, attr, context->doc); 984: } 985: } 986: } 987: } 988: 989: /*---------------------------------------------------------------------- 990: XhtmlTypeAttrValue 991: Value val has been read for the HTML attribute TYPE. 992: Create a child for the current Thot element INPUT accordingly. 993: ----------------------------------------------------------------------*/ 1.46 cvs 994: void XhtmlTypeAttrValue (char *val, 1.30 cvs 995: Attribute currentAttribute, 996: Element lastAttrElement, 997: ParserData *context) 998: 999: { 1000: ElementType elType; 1001: Element newChild; 1002: AttributeType attrType; 1003: Attribute attr; 1.39 cvs 1004: char msgBuffer[MaxMsgLength]; 1.30 cvs 1005: int value; 1006: ThotBool level; 1007: 1008: attrType.AttrTypeNum = DummyAttribute; 1009: MapHTMLAttributeValue (val, attrType, &value); 1010: if (value < 0) 1011: { 1.37 cvs 1012: sprintf (msgBuffer, "Unknown attribute value \"type=%s\"", val); 1.30 cvs 1013: XmlParseError (errorParsing, msgBuffer, 0); 1.36 cvs 1014: MapHTMLAttribute ("unknown_attr", &attrType, NULL, 1.30 cvs 1015: &level, context->doc); 1.37 cvs 1016: sprintf (msgBuffer, "type=%s", val); 1.30 cvs 1017: CreateHTMLAttribute (context->lastElement, attrType, msgBuffer, TRUE, 1018: context->doc, ¤tAttribute, &lastAttrElement); 1019: } 1020: else 1021: { 1022: elType = TtaGetElementType (context->lastElement); 1023: if (elType.ElTypeNum != HTML_EL_Input) 1024: { 1.37 cvs 1025: sprintf (msgBuffer, "Duplicate attribute \"type = %s\"", val); 1.30 cvs 1026: XmlParseError (errorParsing, msgBuffer, 0); 1027: } 1028: else 1029: { 1030: elType.ElTypeNum = value; 1031: newChild = TtaNewTree (context->doc, elType, ""); 1032: XmlSetElemLineNumber (newChild); 1033: TtaInsertFirstChild (&newChild, context->lastElement, context->doc); 1034: if (value == HTML_EL_PICTURE_UNIT) 1035: { 1036: /* add the attribute IsInput to input pictures */ 1037: attrType.AttrSSchema = elType.ElSSchema; 1038: attrType.AttrTypeNum = HTML_ATTR_IsInput; 1039: attr = TtaNewAttribute (attrType); 1040: TtaAttachAttribute (newChild, attr, context->doc); 1041: } 1042: } 1043: } 1044: } 1045: 1046: /*---------------------------------------------------------------------- 1047: CreateAttrWidthPercentPxl 1048: an HTML attribute "width" has been created for a Table of a HR. 1049: Create the corresponding attribute IntWidthPercent or IntWidthPxl. 1050: oldWidth is -1 or the old image width. 1051: ----------------------------------------------------------------------*/ 1.58 vatton 1052: void CreateAttrWidthPercentPxl (char *buffer, Element el, 1053: Document doc, int oldWidth) 1.30 cvs 1054: { 1055: AttributeType attrTypePxl, attrTypePercent; 1056: Attribute attrOld, attrNew; 1057: int length, val; 1.39 cvs 1058: char msgBuffer[MaxMsgLength]; 1.30 cvs 1059: ElementType elType; 1060: int w, h; 1061: ThotBool isImage; 1062: 1063: elType = TtaGetElementType (el); 1064: isImage = (elType.ElTypeNum == HTML_EL_PICTURE_UNIT || 1065: elType.ElTypeNum == HTML_EL_Data_cell || 1066: elType.ElTypeNum == HTML_EL_Heading_cell); 1067: 1068: /* remove trailing spaces */ 1.37 cvs 1069: length = strlen (buffer) - 1; 1.30 cvs 1070: while (length > 0 && buffer[length] <= SPACE) 1071: length--; 1072: attrTypePxl.AttrSSchema = TtaGetDocumentSSchema (doc); 1073: attrTypePercent.AttrSSchema = TtaGetDocumentSSchema (doc); 1074: attrTypePxl.AttrTypeNum = HTML_ATTR_IntWidthPxl; 1075: attrTypePercent.AttrTypeNum = HTML_ATTR_IntWidthPercent; 1076: /* is the last character a '%' ? */ 1077: if (buffer[length] == '%') 1078: { 1079: /* remove IntWidthPxl */ 1080: attrOld = TtaGetAttribute (el, attrTypePxl); 1081: /* update IntWidthPercent */ 1082: attrNew = TtaGetAttribute (el, attrTypePercent); 1083: if (attrNew == NULL) 1084: { 1085: attrNew = TtaNewAttribute (attrTypePercent); 1086: TtaAttachAttribute (el, attrNew, doc); 1087: } 1088: else if (isImage && oldWidth == -1) 1089: { 1090: if (attrOld == NULL) 1091: oldWidth = TtaGetAttributeValue (attrNew); 1092: else 1093: oldWidth = TtaGetAttributeValue (attrOld); 1094: } 1095: } 1096: else 1097: { 1098: /* remove IntWidthPercent */ 1099: attrOld = TtaGetAttribute (el, attrTypePercent); 1100: /* update IntWidthPxl */ 1101: attrNew = TtaGetAttribute (el, attrTypePxl); 1102: if (attrNew == NULL) 1103: { 1104: attrNew = TtaNewAttribute (attrTypePxl); 1105: TtaAttachAttribute (el, attrNew, doc); 1106: } 1107: else if (isImage && oldWidth == -1) 1108: { 1109: TtaGiveBoxSize (el, doc, 1, UnPixel, &w, &h); 1110: if (attrOld == NULL) 1111: oldWidth = w * TtaGetAttributeValue (attrNew) / 100; 1112: else 1113: oldWidth = w * TtaGetAttributeValue (attrOld) / 100; 1114: } 1115: } 1116: 1117: if (attrOld != NULL) 1118: TtaRemoveAttribute (el, attrOld, doc); 1.43 cvs 1119: if (sscanf (buffer, "%d", &val)) 1.30 cvs 1120: TtaSetAttributeValue (attrNew, val, el, doc); 1121: else 1122: /* its not a number. Delete attribute and send an error message */ 1123: { 1124: TtaRemoveAttribute (el, attrNew, doc); 1.37 cvs 1125: if (strlen (buffer) > MaxMsgLength - 30) 1.30 cvs 1126: buffer[MaxMsgLength - 30] = EOS; 1.37 cvs 1127: sprintf (msgBuffer, "Invalid attribute value \"%s\"", buffer); 1.42 cvs 1128: HTMLParseError (doc, msgBuffer); 1.30 cvs 1129: } 1130: if (isImage) 1131: UpdateImageMap (el, doc, oldWidth, -1); 1132: } 1133: 1134: /*---------------------------------------------------------------------- 1.58 vatton 1135: CreateAttrHeightPercentPxl 1136: an HTML attribute "width" has been created for a Table of a HR. 1137: Create the corresponding attribute IntHeightPercent or IntHeightPxl. 1138: oldHeight is -1 or the old image width. 1139: ----------------------------------------------------------------------*/ 1140: void CreateAttrHeightPercentPxl (char *buffer, Element el, 1141: Document doc, int oldHeight) 1142: { 1143: AttributeType attrTypePxl, attrTypePercent; 1144: Attribute attrOld, attrNew; 1145: int length, val; 1146: char msgBuffer[MaxMsgLength]; 1147: ElementType elType; 1148: int w, h; 1149: ThotBool isImage; 1150: 1151: elType = TtaGetElementType (el); 1152: isImage = (elType.ElTypeNum == HTML_EL_PICTURE_UNIT || 1153: elType.ElTypeNum == HTML_EL_Data_cell || 1154: elType.ElTypeNum == HTML_EL_Heading_cell); 1155: 1156: /* remove trailing spaces */ 1157: length = strlen (buffer) - 1; 1158: while (length > 0 && buffer[length] <= SPACE) 1159: length--; 1160: attrTypePxl.AttrSSchema = TtaGetDocumentSSchema (doc); 1161: attrTypePercent.AttrSSchema = TtaGetDocumentSSchema (doc); 1162: attrTypePxl.AttrTypeNum = HTML_ATTR_IntHeightPxl; 1163: attrTypePercent.AttrTypeNum = HTML_ATTR_IntHeightPercent; 1164: /* is the last character a '%' ? */ 1165: if (buffer[length] == '%') 1166: { 1167: /* remove IntHeightPxl */ 1168: attrOld = TtaGetAttribute (el, attrTypePxl); 1169: /* update IntHeightPercent */ 1170: attrNew = TtaGetAttribute (el, attrTypePercent); 1171: if (attrNew == NULL) 1172: { 1173: attrNew = TtaNewAttribute (attrTypePercent); 1174: TtaAttachAttribute (el, attrNew, doc); 1175: } 1176: else if (isImage && oldHeight == -1) 1177: { 1178: if (attrOld == NULL) 1179: oldHeight = TtaGetAttributeValue (attrNew); 1180: else 1181: oldHeight = TtaGetAttributeValue (attrOld); 1182: } 1183: } 1184: else 1185: { 1186: /* remove IntHeightPercent */ 1187: attrOld = TtaGetAttribute (el, attrTypePercent); 1188: /* update IntHeightPxl */ 1189: attrNew = TtaGetAttribute (el, attrTypePxl); 1190: if (attrNew == NULL) 1191: { 1192: attrNew = TtaNewAttribute (attrTypePxl); 1193: TtaAttachAttribute (el, attrNew, doc); 1194: } 1195: else if (isImage && oldHeight == -1) 1196: { 1197: TtaGiveBoxSize (el, doc, 1, UnPixel, &w, &h); 1198: if (attrOld == NULL) 1199: oldHeight = w * TtaGetAttributeValue (attrNew) / 100; 1200: else 1201: oldHeight = w * TtaGetAttributeValue (attrOld) / 100; 1202: } 1203: } 1204: 1205: if (attrOld != NULL) 1206: TtaRemoveAttribute (el, attrOld, doc); 1207: if (sscanf (buffer, "%d", &val)) 1208: TtaSetAttributeValue (attrNew, val, el, doc); 1209: else 1210: /* its not a number. Delete attribute and send an error message */ 1211: { 1212: TtaRemoveAttribute (el, attrNew, doc); 1213: if (strlen (buffer) > MaxMsgLength - 30) 1214: buffer[MaxMsgLength - 30] = EOS; 1215: sprintf (msgBuffer, "Invalid attribute value \"%s\"", buffer); 1216: HTMLParseError (doc, msgBuffer); 1217: } 1218: if (isImage) 1219: UpdateImageMap (el, doc, oldHeight, -1); 1220: } 1221: 1222: /*---------------------------------------------------------------------- 1.30 cvs 1223: CreateAttrIntSize 1224: an HTML attribute "size" has been created for a Font element. 1225: Create the corresponding internal attribute. 1226: ----------------------------------------------------------------------*/ 1.46 cvs 1227: void CreateAttrIntSize (char *buffer, Element el, Document doc) 1.30 cvs 1228: 1229: { 1230: AttributeType attrType; 1231: int val, ind, factor, delta; 1232: Attribute attr; 1.37 cvs 1233: char msgBuffer[MaxMsgLength]; 1.30 cvs 1234: 1235: /* is the first character a '+' or a '-' ? */ 1236: ind = 0; 1237: factor = 1; 1238: delta = 0; 1239: if (buffer[0] == '+') 1240: { 1241: attrType.AttrTypeNum = HTML_ATTR_IntSizeIncr; 1242: ind++; 1243: factor = 2; 1244: } 1245: else if (buffer[0] == '-') 1246: { 1247: attrType.AttrTypeNum = HTML_ATTR_IntSizeDecr; 1248: ind++; 1249: factor = 2; 1250: } 1251: else 1252: { 1253: attrType.AttrTypeNum = HTML_ATTR_IntSizeRel; 1254: delta = 1; 1255: } 1256: attrType.AttrSSchema = TtaGetDocumentSSchema (doc); 1257: attr = TtaGetAttribute (el, attrType); 1.43 cvs 1258: if (sscanf (&buffer[ind], "%d", &val)) 1.30 cvs 1259: { 1260: val = val * factor + delta; 1261: if (attr == NULL) 1262: { 1263: /* this attribute doesn't exist, create it */ 1264: attr = TtaNewAttribute (attrType); 1265: TtaAttachAttribute (el, attr, doc); 1266: } 1267: TtaSetAttributeValue (attr, val, el, doc); 1268: } 1269: else 1270: /* its not a number. Delete attribute and send an error message */ 1271: { 1272: if (attr) 1273: TtaRemoveAttribute (el, attr, doc); 1.37 cvs 1274: if (strlen (buffer) > MaxMsgLength - 30) 1.30 cvs 1275: buffer[MaxMsgLength - 30] = EOS; 1.37 cvs 1276: sprintf (msgBuffer, "Invalid attribute value \"%s\"", buffer); 1.42 cvs 1277: HTMLParseError (doc, msgBuffer); 1.30 cvs 1278: } 1279: } 1280: /*---------------------------------------------------------------------- 1281: EndOfHTMLAttributeValue 1282: Filling of an HTML attribute value 1283: ----------------------------------------------------------------------*/ 1.48 vatton 1284: void EndOfHTMLAttributeValue (char *attrValue, 1285: AttributeMapping *lastMappedAttr, 1286: Attribute currentAttribute, 1287: Element lastAttrElement, 1288: ThotBool UnknownAttr, 1289: ParserData *context, 1290: ThotBool isXML) 1.30 cvs 1291: { 1.48 vatton 1292: AttributeType attrType, attrType1; 1293: Attribute attr; 1294: ElementType elType; 1295: Element child, root; 1296: Language lang; 1297: char translation; 1298: char shape; 1299: char *buffer; 1300: char *attrName; 1301: char msgBuffer[MaxMsgLength]; 1302: int val; 1303: int length; 1304: int attrKind; 1305: ThotBool done = FALSE; 1.30 cvs 1306: 1.48 vatton 1307: /* treatments of some particular HTML attributes */ 1308: if (!strcmp (lastMappedAttr->XMLattribute, "style")) 1309: { 1310: TtaSetAttributeText (currentAttribute, attrValue, 1311: lastAttrElement, context->doc); 1312: ParseHTMLSpecificStyle (context->lastElement, attrValue, 1.61 quint 1313: context->doc, 100, FALSE); 1.48 vatton 1314: done = TRUE; 1315: } 1316: else 1317: { 1318: if (!strcmp (lastMappedAttr->XMLattribute, "link")) 1319: HTMLSetAlinkColor (context->doc, attrValue); 1320: else if (!strcmp (lastMappedAttr->XMLattribute, "alink")) 1321: HTMLSetAactiveColor (context->doc, attrValue); 1322: else if (!strcmp (lastMappedAttr->XMLattribute, "vlink")) 1323: HTMLSetAvisitedColor (context->doc, attrValue); 1324: } 1.30 cvs 1325: 1.48 vatton 1326: if (!done) 1327: { 1328: val = 0; 1329: translation = lastMappedAttr->AttrOrContent; 1330: switch (translation) 1331: { 1332: case 'C': /* Content */ 1333: child = PutInContent (attrValue, context); 1334: if (child != NULL) 1335: TtaAppendTextContent (child, "\" ", context->doc); 1336: break; 1337: 1338: case 'A': 1339: if (currentAttribute != NULL) 1340: { 1341: TtaGiveAttributeType (currentAttribute, &attrType, &attrKind); 1342: switch (attrKind) 1343: { 1344: case 0: /* enumerate */ 1345: if (isXML) 1346: MapHTMLAttributeValue (attrValue, attrType, &val); 1347: else 1348: val = MapAttrValue (lastMappedAttr->ThotAttribute, 1.40 cvs 1349: attrValue); 1.48 vatton 1350: if (val < 0) 1351: { 1352: TtaGiveAttributeType (currentAttribute, 1353: &attrType, &attrKind); 1354: attrName = TtaGetAttributeName (attrType); 1355: sprintf (msgBuffer, 1.51 cvs 1356: "Invalid attribute value \"%s = %s\"", 1.48 vatton 1357: attrName, attrValue); 1358: if (isXML) 1359: XmlParseError (errorParsing, msgBuffer, 0); 1360: else 1.51 cvs 1361: { 1362: HTMLParseError (context->doc, msgBuffer); 1.48 vatton 1363: /* remove the attribute and replace it by an */ 1.51 cvs 1364: /* Invalid_attribute (not for XHTML) */ 1365: TtaRemoveAttribute (lastAttrElement, 1366: currentAttribute, context->doc); 1.48 vatton 1367: attrType.AttrSSchema = 1368: TtaGetDocumentSSchema (context->doc); 1369: attrType.AttrTypeNum = 1370: pHTMLAttributeMapping[0].ThotAttribute; 1.51 cvs 1371: sprintf (msgBuffer, "%s=%s", attrName, attrValue); 1372: CreateHTMLAttribute (lastAttrElement, attrType, 1373: msgBuffer, TRUE, context->doc, 1374: ¤tAttribute, 1375: &lastAttrElement); 1.48 vatton 1376: } 1377: } 1378: else 1379: TtaSetAttributeValue (currentAttribute, val, 1380: lastAttrElement, context->doc); 1381: break; 1382: case 1: /* integer */ 1383: if (attrType.AttrTypeNum == HTML_ATTR_Border && 1384: !strcasecmp (attrValue, "border")) 1385: { 1386: /* border="border" for a table */ 1387: val = 1; 1388: TtaSetAttributeValue (currentAttribute, val, 1.30 cvs 1389: lastAttrElement, context->doc); 1.48 vatton 1390: } 1391: else if (sscanf (attrValue, "%d", &val)) 1392: TtaSetAttributeValue (currentAttribute, val, 1393: lastAttrElement, context->doc); 1394: else 1395: { 1396: TtaRemoveAttribute (lastAttrElement, currentAttribute, 1397: context->doc); 1398: sprintf (msgBuffer, 1399: "Unknown attribute value \"%s\"", 1400: attrValue); 1401: if (isXML) 1402: XmlParseError (errorParsing, msgBuffer, 0); 1403: else 1404: HTMLParseError (context->doc, msgBuffer); 1405: } 1406: break; 1407: case 2: /* text */ 1408: if (!UnknownAttr) 1409: { 1410: TtaSetAttributeText (currentAttribute, attrValue, 1411: lastAttrElement, context->doc); 1.55 cvs 1412: if (attrType.AttrTypeNum == HTML_ATTR_Language) 1.48 vatton 1413: { 1414: /* it's a LANG attribute value */ 1415: lang = TtaGetLanguageIdFromName (attrValue); 1416: if (lang == 0) 1417: { 1418: sprintf (msgBuffer, 1419: "warning - unsupported language: %s", 1420: attrValue); 1421: if (isXML) 1422: XmlParseError (errorParsing, msgBuffer, 0); 1423: else 1424: HTMLParseError (context->doc, msgBuffer); 1425: } 1426: else 1427: { 1428: /* change current language */ 1429: context->language = lang; 1430: if (isXML) 1431: SetLanguagInXmlStack (lang); 1432: else 1433: SetLanguagInHTMLStack (lang); 1434: } 1435: root = TtaGetRootElement (context->doc); 1436: if (lastAttrElement == root) 1437: /* it's a LANG attribute on the root element */ 1438: /* set the RealLang attribute */ 1439: { 1440: attrType1.AttrSSchema = TtaGetDocumentSSchema (context->doc); 1441: attrType1.AttrTypeNum = HTML_ATTR_RealLang; 1442: /* this attribute could be already present, 1443: (lang and xml:lang attributes) */ 1444: if (!TtaGetAttribute (lastAttrElement, 1445: attrType1)) 1446: /* it's not present. Add it */ 1447: { 1448: attr = TtaNewAttribute (attrType1); 1449: TtaAttachAttribute (lastAttrElement, 1450: attr, context->doc); 1451: TtaSetAttributeValue (attr, 1452: HTML_ATTR_RealLang_VAL_Yes_, 1453: lastAttrElement, 1454: context->doc); 1455: } 1456: } 1457: } 1458: else if (attrType.AttrTypeNum == HTML_ATTR_accesskey) 1459: TtaAddAccessKey (context->doc, (unsigned int)attrValue[0], 1460: lastAttrElement); 1461: } 1462: else 1463: { 1.51 cvs 1464: /* this is the content of an invalid attribute */ 1465: /* append it to the current Invalid_attribute */ 1466: if (!isXML) 1467: { 1468: length = strlen (attrValue) + 2; 1469: length += TtaGetTextAttributeLength (currentAttribute); 1470: buffer = TtaGetMemory (length + 1); 1471: TtaGiveTextAttributeValue (currentAttribute, 1472: buffer, &length); 1473: strcat (buffer, "="); 1474: strcat (buffer, attrValue); 1475: TtaSetAttributeText (currentAttribute, buffer, 1476: lastAttrElement, context->doc); 1477: TtaFreeMemory (buffer); 1478: } 1.48 vatton 1479: } 1480: break; 1481: case 3: /* reference */ 1482: break; 1483: } 1484: } 1485: break; 1486: 1487: case SPACE: 1488: if (isXML) 1489: XhtmlTypeAttrValue (attrValue, currentAttribute, 1.30 cvs 1490: lastAttrElement, context); 1.48 vatton 1491: else 1492: HTMLTypeAttrValue (attrValue, currentAttribute, 1493: lastAttrElement, context); 1494: break; 1495: 1.30 cvs 1496: default: 1497: break; 1.48 vatton 1498: } 1.30 cvs 1499: 1500: if (lastMappedAttr->ThotAttribute == HTML_ATTR_Width__) 1.48 vatton 1501: /* HTML attribute "width" for a table or a hr */ 1502: /* create the corresponding attribute IntWidthPercent or */ 1503: /* IntWidthPxl */ 1504: CreateAttrWidthPercentPxl (attrValue, lastAttrElement, context->doc, -1); 1.58 vatton 1505: else if (lastMappedAttr->ThotAttribute == HTML_ATTR_Height_) 1506: /* HTML attribute "width" for a table or a hr */ 1507: /* create the corresponding attribute IntHeightPercent or */ 1508: /* IntHeightPxl */ 1509: CreateAttrHeightPercentPxl (attrValue, lastAttrElement, context->doc, -1); 1.48 vatton 1510: else if (!strcmp (lastMappedAttr->XMLattribute, "size")) 1511: { 1512: TtaGiveAttributeType (currentAttribute, &attrType, &attrKind); 1513: if (attrType.AttrTypeNum == HTML_ATTR_Font_size) 1514: CreateAttrIntSize (attrValue, lastAttrElement, context->doc); 1515: } 1516: else if (!strcmp (lastMappedAttr->XMLattribute, "shape")) 1517: { 1518: child = TtaGetFirstChild (lastAttrElement); 1519: if (child != NULL) 1520: { 1521: switch (val) 1522: { 1523: case HTML_ATTR_shape_VAL_rectangle: 1524: shape = 'R'; 1525: break; 1526: case HTML_ATTR_shape_VAL_circle: 1527: shape = 'a'; 1528: break; 1529: case HTML_ATTR_shape_VAL_polygon: 1530: shape = 'p'; 1531: break; 1532: default: 1533: shape = SPACE; 1534: break; 1535: } 1536: TtaSetGraphicsShape (child, shape, context->doc); 1537: } 1538: } 1539: else if (!strcmp (lastMappedAttr->XMLattribute, "value")) 1540: { 1541: elType = TtaGetElementType (lastAttrElement); 1542: if (elType.ElTypeNum == HTML_EL_Text_Input || 1543: elType.ElTypeNum == HTML_EL_Password_Input || 1544: elType.ElTypeNum == HTML_EL_File_Input || 1545: elType.ElTypeNum == HTML_EL_Input) 1546: /* create a Default_Value attribute with the same content */ 1547: { 1548: attrType1.AttrSSchema = attrType.AttrSSchema; 1549: attrType1.AttrTypeNum = HTML_ATTR_Default_Value; 1550: attr = TtaNewAttribute (attrType1); 1551: TtaAttachAttribute (lastAttrElement, attr, context->doc); 1552: TtaSetAttributeText (attr, attrValue, 1553: lastAttrElement, context->doc); 1554: } 1555: } 1.30 cvs 1556: else 1.48 vatton 1557: { 1558: /* Some HTML attributes are equivalent to a CSS property: */ 1559: /* background -> background */ 1560: /* bgcolor -> background */ 1561: /* text -> color */ 1562: /* color -> color */ 1563: if (!strcmp (lastMappedAttr->XMLattribute, "background")) 1564: { 1565: if (strlen (attrValue) > MaxMsgLength - 30) 1566: attrValue[MaxMsgLength - 30] = EOS; 1567: HTMLSetBackgroundImage (context->doc, 1568: context->lastElement, STYLE_REPEAT, attrValue); 1569: } 1570: else if (!strcmp (lastMappedAttr->XMLattribute, "bgcolor")) 1571: HTMLSetBackgroundColor (context->doc, 1572: context->lastElement, attrValue); 1573: else if (!strcmp (lastMappedAttr->XMLattribute, "text") || 1574: !strcmp (lastMappedAttr->XMLattribute, "color")) 1575: HTMLSetForegroundColor (context->doc, 1576: context->lastElement, attrValue); 1577: } 1578: } 1.30 cvs 1579: } 1580: 1581: /*---------------------------------------------------------------------- 1.16 cvs 1582: MapHTMLAttributeValue 1.2 cvs 1583: Search in the Attribute Value Mapping Table the entry for the attribute 1584: ThotAtt and its value AttrVal. Returns the corresponding Thot value. 1.1 cvs 1585: ----------------------------------------------------------------------*/ 1.39 cvs 1586: void MapHTMLAttributeValue (char *AttrVal, 1.30 cvs 1587: AttributeType attrType, 1588: int *value) 1.1 cvs 1589: { 1.45 cvs 1590: int i; 1.2 cvs 1591: 1.45 cvs 1592: *value = 0; 1593: i = 0; 1594: while (XhtmlAttrValueMappingTable[i].ThotAttr != attrType.AttrTypeNum && 1595: XhtmlAttrValueMappingTable[i].ThotAttr != 0) 1596: i++; 1597: if (XhtmlAttrValueMappingTable[i].ThotAttr == attrType.AttrTypeNum) 1598: do 1599: if (!strcmp (XhtmlAttrValueMappingTable[i].XMLattrValue, AttrVal)) 1600: *value = XhtmlAttrValueMappingTable[i].ThotAttrValue; 1601: else 1602: i++; 1603: while (*value <= 0 && 1604: XhtmlAttrValueMappingTable[i].ThotAttr == attrType.AttrTypeNum); 1.1 cvs 1605: }