--- psiconv/trunk/lib/psiconv/parse_common.c 2003/11/19 21:04:06 159 +++ psiconv/trunk/lib/psiconv/parse_common.c 2003/11/20 22:14:43 160 @@ -717,31 +717,72 @@ } 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+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"); } @@ -753,7 +794,7 @@ } line_length += in_line.length; if ((res = psiconv_list_add(para->in_lines,&in_line))) - goto ERROR4; + goto ERROR5; } } } @@ -799,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: @@ -885,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; +}