--- psiconv/trunk/lib/psiconv/generate_common.c 2002/01/29 18:38:38 142 +++ psiconv/trunk/lib/psiconv/generate_common.c 2003/11/23 21:47:24 167 @@ -134,12 +134,13 @@ psiconv_u8 style; psiconv_u8 nr; } *psiconv_paragraph_type_list; + psiconv_u32 obj_id; psiconv_list paragraph_type_list; /* Of psiconv_paragraph_type_list_s */ psiconv_paragraph_type_list paragraph_type; struct psiconv_paragraph_type_list_s new_type; - psiconv_buffer buf_types,buf_elements,buf_inlines; + psiconv_buffer buf_types,buf_elements,buf_inlines,buf_objects; psiconv_paragraph paragraph; - psiconv_in_line_layout in_line; + psiconv_in_line_layout in_line = NULL; psiconv_word_style style; psiconv_character_layout para_charlayout; int i,j,para_type,nr_of_inlines=0,res,ptl_length,pel_length,thislen,paralen; @@ -169,35 +170,47 @@ goto ERROR4; } + if (!(buf_objects = psiconv_buffer_new())) { + res = -PSICONV_E_NOMEM; + goto ERROR5; + } + for (i = 0; i < psiconv_list_length(value); i++) { if (!(paragraph = psiconv_list_get(value,i))) { psiconv_warn(0,psiconv_buffer_length(buf),"Massive memory corruption"); res = -PSICONV_E_OTHER; - goto ERROR5; + goto ERROR6; } if ((res = psiconv_write_u32(buf_elements,strlen(paragraph->text)+1))) - goto ERROR5; + goto ERROR6; - if (psiconv_list_length(paragraph->in_lines) > 1) { - /* Inline layouts, so we generate a paragraph element and inline - elements */ + /* We need it for the next if-statement */ + if (psiconv_list_length(paragraph->in_lines) == 1) + if (!(in_line = psiconv_list_get(paragraph->in_lines,1))) + goto ERROR6; + + if ((psiconv_list_length(paragraph->in_lines) > 1) || + ((psiconv_list_length(paragraph->in_lines) == 1) && + (in_line->object != NULL))) { + /* Inline layouts, or an object, so we generate a paragraph element + and inline elements */ if ((res = psiconv_write_u8(buf_elements,0x00))) - goto ERROR5; + goto ERROR6; if (!(style = psiconv_get_style(styles,paragraph->base_style))) { psiconv_warn(0,psiconv_buffer_length(buf),"Unknown style"); res = -PSICONV_E_GENERATE; - goto ERROR5; + goto ERROR6; } if ((res = psiconv_write_paragraph_layout_list(buf_elements, paragraph->base_paragraph, style->paragraph))) - goto ERROR5; + goto ERROR6; if (with_styles) if ((res = psiconv_write_u8(buf_elements,paragraph->base_style))) - goto ERROR5; + goto ERROR6; if ((res = psiconv_write_u32(buf_elements, psiconv_list_length(paragraph->in_lines)))) - goto ERROR5; + goto ERROR6; /* Generate the inlines. NB: Against what are all settings relative?!? */ paralen = 0; @@ -207,10 +220,10 @@ psiconv_warn(0,psiconv_buffer_length(buf), "Massive memory corruption"); res = -PSICONV_E_OTHER; - goto ERROR5; + goto ERROR6; } - if ((res = psiconv_write_u8(buf_inlines,0x00))) - goto ERROR5; + if ((res = psiconv_write_u8(buf_inlines,in_line->object?0x01:0x00))) + goto ERROR6; thislen = in_line->length; paralen += thislen; /* If this is the last in_line, we need to make sure that the @@ -218,16 +231,32 @@ if (j == psiconv_list_length(paragraph->in_lines)-1) { if (paralen > strlen(paragraph->text)+1) { res = -PSICONV_E_GENERATE; - goto ERROR5; + goto ERROR6; } thislen += strlen(paragraph->text)+1-paralen; } if ((res = psiconv_write_u32(buf_inlines,thislen))) - goto ERROR5; + goto ERROR6; if ((res = psiconv_write_character_layout_list(buf_inlines, in_line->layout, style->character))) - goto ERROR5; + goto ERROR6; + if (in_line->object) { + if ((res = psiconv_write_u32(buf_inlines,PSICONV_ID_OBJECT))) + goto ERROR6; + obj_id = psiconv_buffer_unique_id(); + if ((res = psiconv_buffer_add_reference(buf_inlines,obj_id))) + goto ERROR6; + if ((res = psiconv_buffer_add_target(buf_objects,obj_id))) + goto ERROR6; + if ((res = psiconv_write_embedded_object_section(buf_objects, + in_line->object))) + goto ERROR6; + if ((res = psiconv_write_length(buf_inlines,in_line->object_width))) + goto ERROR6; + if ((res = psiconv_write_length(buf_inlines,in_line->object_height))) + goto ERROR6; + } } } else { /* No inline layouts (or only 1), so we generate a paragraph type list */ @@ -240,7 +269,7 @@ psiconv_warn(0,psiconv_buffer_length(buf), "Massive memory corruption"); res = -PSICONV_E_OTHER; - goto ERROR5; + goto ERROR6; } para_charlayout = in_line->layout; } @@ -249,7 +278,7 @@ psiconv_warn(0,psiconv_buffer_length(buf), "Massive memory corruption"); res = -PSICONV_E_OTHER; - goto ERROR5; + goto ERROR6; } if ((paragraph->base_style == paragraph_type->style) && !psiconv_compare_character_layout(para_charlayout, @@ -269,45 +298,45 @@ new_type.style = paragraph->base_style; paragraph_type = &new_type; if ((res = psiconv_list_add(paragraph_type_list,paragraph_type))) - goto ERROR5; + goto ERROR6; if ((res = psiconv_write_u32(buf_types,paragraph_type->nr))) - goto ERROR5; + goto ERROR6; if (!(style = psiconv_get_style(styles,paragraph_type->style))) { psiconv_warn(0,psiconv_buffer_length(buf),"Unknown style"); res = -PSICONV_E_GENERATE; - goto ERROR5; + goto ERROR6; } if ((res = psiconv_write_paragraph_layout_list(buf_types, paragraph_type->paragraph,style->paragraph))) - goto ERROR5; + goto ERROR6; if (with_styles) if ((res = psiconv_write_u8(buf_types,paragraph_type->style))) - goto ERROR5; + goto ERROR6; if ((res = psiconv_write_character_layout_list(buf_types, paragraph_type->character,style->character))) - goto ERROR5; + goto ERROR6; } if ((res = psiconv_write_u8(buf_elements,para_type))) - goto ERROR5; + goto ERROR6; } } /* HACK: special case: no paragraphs at all. We need to improvize. */ if (!psiconv_list_length(value)) { if ((res = psiconv_write_u32(buf_types,1))) - goto ERROR5; + goto ERROR6; if ((res = psiconv_write_u32(buf_types,0))) - goto ERROR5; + goto ERROR6; if (with_styles) if ((res = psiconv_write_u8(buf_types,0))) - goto ERROR5; + goto ERROR6; if ((res = psiconv_write_u32(buf_types,0))) - goto ERROR5; + goto ERROR6; if ((res = psiconv_write_u32(buf_elements,1))) - goto ERROR5; + goto ERROR6; if ((res = psiconv_write_u8(buf_elements,1))) - goto ERROR5; + goto ERROR6; pel_length = 1; ptl_length = 1; } else { @@ -317,19 +346,24 @@ /* Now append everything */ if ((res = psiconv_write_u16(buf,with_styles?0x0001:0x0000))) - goto ERROR5; + goto ERROR6; if ((res = psiconv_write_u8(buf, ptl_length))) - goto ERROR5; + goto ERROR6; if ((res = psiconv_buffer_concat(buf,buf_types))) - goto ERROR5; + goto ERROR6; if ((res = psiconv_write_u32(buf,pel_length))) - goto ERROR5; + goto ERROR6; if ((res = psiconv_buffer_concat(buf,buf_elements))) - goto ERROR5; + goto ERROR6; if ((res = psiconv_write_u32(buf,nr_of_inlines))) - goto ERROR5; - res = psiconv_buffer_concat(buf,buf_inlines); + goto ERROR6; + if ((res = psiconv_buffer_concat(buf,buf_inlines))) + goto ERROR6; + if ((res = psiconv_buffer_concat(buf,buf_objects))) + goto ERROR6; +ERROR6: + psiconv_buffer_free(buf_objects); ERROR5: psiconv_buffer_free(buf_inlines); ERROR4: @@ -394,3 +428,139 @@ else return res; } + + +int psiconv_write_embedded_object_section(psiconv_buffer buf, + const psiconv_embedded_object_section value) +{ + int res; + psiconv_u32 display_id,icon_id,table_id; + psiconv_buffer extra_buf; + + if (!value) { + psiconv_warn(0,psiconv_buffer_length(buf),"Null Object"); + res = -PSICONV_E_GENERATE; + goto ERROR1; + } + + if (!(extra_buf = psiconv_buffer_new())) { + res = -PSICONV_E_NOMEM; + goto ERROR1; + } + + display_id = psiconv_buffer_unique_id(); + icon_id = psiconv_buffer_unique_id(); + table_id = psiconv_buffer_unique_id(); + if ((res = psiconv_write_u8(buf,0x06))) + goto ERROR2; + if ((res = psiconv_write_u32(buf,PSICONV_ID_OBJECT_DISPLAY_SECTION))) + goto ERROR2; + if ((res = psiconv_buffer_add_reference(buf,display_id))) + goto ERROR2; + if ((res = psiconv_write_u32(buf,PSICONV_ID_OBJECT_ICON_SECTION))) + goto ERROR2; + if ((res = psiconv_buffer_add_reference(buf,icon_id))) + goto ERROR2; + if ((res = psiconv_write_u32(buf,PSICONV_ID_OBJECT_SECTION_TABLE_SECTION))) + goto ERROR2; + if ((res = psiconv_buffer_add_reference(buf,table_id))) + goto ERROR2; + + if ((res = psiconv_buffer_add_target(buf,display_id))) + goto ERROR2; + if ((res = psiconv_write_object_display_section(buf,value->display))) + goto ERROR2; + if ((res = psiconv_buffer_add_target(buf,icon_id))) + goto ERROR2; + if ((res = psiconv_write_object_icon_section(buf,value->icon))) + goto ERROR2; + if ((res = psiconv_buffer_add_target(buf,table_id))) + goto ERROR2; + switch(value->object->type) { + case psiconv_word_file: + if ((res = psiconv_write_word_file(extra_buf, + (psiconv_word_f) value->object->file))) + goto ERROR2; + break; +/* + case psiconv_sketch_file: + if ((res = psiconv_write_sketch_file(extra_buf, + (psiconv_sketch_f) value->object->file))) + goto ERROR2; + break; + case psiconv_sheet_file: + if ((res = psiconv_write_sheet_file(extra_buf, + (psiconv_sheet_f) value->object->file))) + goto ERROR2; + break; +*/ + default: + psiconv_warn(0,psiconv_buffer_length(buf), + "Unknown or unsupported object type"); + res = -PSICONV_E_GENERATE; + goto ERROR2; + } + + if ((res = psiconv_buffer_resolve(extra_buf))) + goto ERROR2; + if ((res = psiconv_buffer_concat(buf,extra_buf))) + goto ERROR2; + + return 0; + +ERROR2: + psiconv_buffer_free(extra_buf); +ERROR1: + return res; +} + + +int psiconv_write_object_display_section(psiconv_buffer buf, + const psiconv_object_display_section value) +{ + int res; + + if (!value) { + psiconv_warn(0,psiconv_buffer_length(buf),"Null Object Display Section"); + res = -PSICONV_E_GENERATE; + goto ERROR1; + } + + if ((res = psiconv_write_u8(buf,value->show_icon?0x00:0x01))) + goto ERROR1; + if ((res = psiconv_write_length(buf,value->width))) + goto ERROR1; + if ((res = psiconv_write_length(buf,value->height))) + goto ERROR1; + if ((res = psiconv_write_u32(buf,0x00000000))) + goto ERROR1; + + return 0; + +ERROR1: + return res; +} + +int psiconv_write_object_icon_section(psiconv_buffer buf, + const psiconv_object_icon_section value) +{ + int res; + + if (!value) { + psiconv_warn(0,psiconv_buffer_length(buf),"Null Object Icon Section"); + res = -PSICONV_E_GENERATE; + goto ERROR1; + } + + if ((res = psiconv_write_string(buf,value->icon_name))) + goto ERROR1; + if ((res = psiconv_write_length(buf,value->icon_width))) + goto ERROR1; + if ((res = psiconv_write_length(buf,value->icon_height))) + goto ERROR1; + + return 0; + +ERROR1: + return res; +}