--- psiconv/trunk/lib/psiconv/parse_common.c 2000/12/15 01:16:43 65 +++ psiconv/trunk/lib/psiconv/parse_common.c 2003/11/20 22:14:43 160 @@ -22,8 +22,13 @@ #include #include -#include "data.h" #include "parse_routines.h" +#include "error.h" + +#ifdef DMALLOC +#include +#endif + static int psiconv_parse_layout_section(const psiconv_buffer buf, int lev,psiconv_u32 off, @@ -89,7 +94,10 @@ } else if ((*result)->uid3 == PSICONV_ID_SKETCH) { (*result)->file = psiconv_sketch_file; psiconv_debug(lev+2,off+len,"File is a Sketch file"); - } + } else if ((*result)->uid3 == PSICONV_ID_SHEET) { + (*result)->file = psiconv_sheet_file; + psiconv_debug(lev+2,off+len,"File is a Sheet file"); + } } else if ((*result)->uid2 == PSICONV_ID_MBM_FILE) { (*result)->file = psiconv_mbm_file; if ((*result)->uid3 != 0x00) @@ -708,31 +716,73 @@ psiconv_debug(lev+3,off+len,"Can't read element!"); } else { total ++; + in_line.object = NULL; + in_line.layout = NULL; if (!(in_line.layout = psiconv_clone_character_layout (para->base_character))) goto ERROR4; psiconv_progress(lev+4,off+len,"Going to read the element type"); temp = psiconv_read_u8(buf,lev+4,len+off,&res); if (res) - goto ERROR4; + goto ERROR5; len += 1; - psiconv_debug(lev+4,off,"Type: %02x",temp); - psiconv_progress(lev+4,off, + psiconv_debug(lev+4,off+len,"Type: %02x",temp); + psiconv_progress(lev+4,off+len, "Going to read the number of characters it applies to"); in_line.length = psiconv_read_u32(buf,lev+4,len+off,&res); if (res) - goto ERROR4; + goto ERROR5; psiconv_debug(lev+4,off+len,"Length: %02x",in_line.length); len += 4; psiconv_progress(lev+4,off+len,"Going to read the character layout"); if ((res = psiconv_parse_character_layout_list(buf,lev+4,off+len,&leng, in_line.layout))) - goto ERROR4; + goto ERROR5; len += leng; if (temp == 0x01) { - psiconv_debug(lev+4,off+len,"Skipping object data"); - len += 0x10; + psiconv_debug(lev+4,off+len,"Found an embedded object"); + psiconv_progress(lev+4,off+len,"Going to read the object marker " + "(0x%08x expected)",PSICONV_ID_OBJECT); + temp = psiconv_read_u32(buf,lev+4,off+len,&res); + if (res) + goto ERROR5; + if (temp != PSICONV_ID_OBJECT) { + psiconv_warn(lev+4,off+len,"Unknown id marks embedded object"); + psiconv_debug(lev+4,off+len,"Marker: read %08x, expected %08x", + temp,PSICONV_ID_OBJECT); + } + len += 4; + psiconv_progress(lev+4,off+len, + "Going to read the Embedded Object Section offset"); + temp = psiconv_read_u32(buf,lev+4,off+len,&res); + if (res) + goto ERROR5; + psiconv_debug(lev+4,off+len, "Offset: %08x",temp); + len += 4; + psiconv_progress(lev+4,off+len, + "Going to parse the Embedded Object"); + if ((res = psiconv_parse_embedded_object(buf,lev+4,temp, + NULL,&(in_line.object)))) + goto ERROR5; + psiconv_progress(lev+4,off+len, + "Going to read the object width"); + in_line.object_width = psiconv_read_length(buf,lev+4,off+len, + &leng,&res); + if (res) + goto ERROR5; + psiconv_debug(lev+4,off+len,"Object width: %f cm", + in_line.object_width); + len += leng; + psiconv_progress(lev+4,off+len, + "Going to read the object height"); + in_line.object_height = psiconv_read_length(buf,lev+4,off+len,&leng, + &res); + if (res) + goto ERROR5; + psiconv_debug(lev+4,off+len,"Object height: %f cm", + in_line.object_height); + len += leng; } else if (temp != 0x00) { psiconv_warn(lev+4,off+len,"Layout section unknown inline type"); } @@ -744,7 +794,7 @@ } line_length += in_line.length; if ((res = psiconv_list_add(para->in_lines,&in_line))) - goto ERROR4; + goto ERROR5; } } } @@ -769,7 +819,7 @@ if (length) *length = len; - psiconv_progress(lev+1,off+len-1,"End of layout section (total length: %08x", + psiconv_progress(lev+1,off+len-1,"End of layout section (total length: %08x)", len); return 0; @@ -790,6 +840,11 @@ psiconv_free_paragraph_layout(anon.paragraph); goto ERROR3; +ERROR5: + if (in_line.layout) + psiconv_free_character_layout(in_line.layout); + if (in_line.object) + psiconv_free_object(in_line.object); ERROR4: free(inline_count); ERROR3: @@ -824,11 +879,11 @@ } int psiconv_parse_styleless_layout_section(const psiconv_buffer buf, - int lev,psiconv_u32 off, - int *length, - psiconv_text_and_layout result, - psiconv_character_layout base_char, - psiconv_paragraph_layout base_para) + int lev,psiconv_u32 off, + int *length, + psiconv_text_and_layout result, + const psiconv_character_layout base_char, + const psiconv_paragraph_layout base_para) { int res = 0; psiconv_word_styles_section styles_section; @@ -876,3 +931,63 @@ return res; } +int psiconv_parse_embedded_object(const psiconv_buffer buf, int lev, + psiconv_u32 off, int *length, + psiconv_object *result) +{ + int res=0; + int len=0; + int leng,i; + psiconv_section_table_section table; + psiconv_section_table_entry entry; + psiconv_u32 icon_sec,display_sec,table_sec; + + psiconv_progress(lev+1,off+len,"Going to read an Embedded Object"); + if (!(*result = malloc(sizeof(**result)))) + goto ERROR1; + + psiconv_progress(lev+2,off+len,"Going to read the Embedded Object Section"); + psiconv_parse_section_table_section(buf,lev+2,off+len,&leng,&table); + len += leng; + + for (i = 0; i < psiconv_list_length(table); i++) { + psiconv_progress(lev+2,off+len,"Going to read entry %d",i); + if (!(entry = psiconv_list_get(table,i))) + goto ERROR2; + if (entry->id == PSICONV_ID_OBJECT_DISPLAY_SECTION) { + display_sec = entry->offset; + psiconv_debug(lev+3,off+len,"Found the Object Display Section at %08x", + display_sec); + } else if (entry->id == PSICONV_ID_OBJECT_ICON_SECTION) { + icon_sec = entry->offset; + psiconv_debug(lev+3,off+len,"Found the Object Icon Section at %08x", + icon_sec); + } else if (entry->id == PSICONV_ID_OBJECT_SECTION_TABLE_SECTION) { + table_sec = entry->offset; + psiconv_debug(lev+3,off+len,"Found the Object Section Table Section at %08x", + table_sec); + } else { + psiconv_warn(lev+3,off+len, + "Found unknown section in the Object Display Section " + "(ignoring)"); + psiconv_debug(lev+3,off+len,"Section ID %08x, offset %08x", + entry->id, entry->offset); + } + } + + psiconv_progress(lev+1,off+len-1,"End of Embedded Object Section " + "(total length: %08x)",len); + return res; + + +ERROR2: + psiconv_free_section_table_section(table); +ERROR1: + psiconv_warn(lev+1,off,"Reading Embedded Object failed"); + if (length) + *length = 0; + if (res == 0) + return -PSICONV_E_NOMEM; + else + return res; +}