--- psiconv/trunk/lib/psiconv/generate_common.c 2000/12/31 01:36:30 88 +++ psiconv/trunk/lib/psiconv/generate_common.c 2001/01/07 20:30:13 89 @@ -137,7 +137,8 @@ psiconv_paragraph paragraph; psiconv_in_line_layout in_line; psiconv_word_style style; - int i,j,para_type,nr_of_inlines=0,res,ptl_length,pel_length; + psiconv_character_layout para_charlayout; + int i,j,para_type,nr_of_inlines=0,res,ptl_length,pel_length,thislen,paralen; if (!value) { psiconv_warn(0,psiconv_buffer_length(buf),"Null text section"); @@ -173,7 +174,7 @@ if ((res = psiconv_write_u32(buf_elements,strlen(paragraph->text)+1))) goto ERROR5; - if (psiconv_list_length(paragraph->in_lines)) { + if (psiconv_list_length(paragraph->in_lines) > 1) { /* Inline layouts, so we generate a paragraph element and inline elements */ if ((res = psiconv_write_u8(buf_elements,0x00))) @@ -195,16 +196,29 @@ goto ERROR5; /* Generate the inlines. NB: Against what are all settings relative?!? */ + paralen = 0; for (j = 0; j < psiconv_list_length(paragraph->in_lines); j++) { nr_of_inlines ++; if (!(in_line = psiconv_list_get(paragraph->in_lines,j))) { - psiconv_warn(0,psiconv_buffer_length(buf),"Massive memory corruption"); + psiconv_warn(0,psiconv_buffer_length(buf), + "Massive memory corruption"); res = -PSICONV_E_OTHER; goto ERROR5; } if ((res = psiconv_write_u8(buf_inlines,0x00))) goto ERROR5; - if ((res = psiconv_write_u32(buf_inlines,in_line->length))) + thislen = in_line->length; + paralen += thislen; + /* If this is the last in_line, we need to make sure that the + complete length of all inlines equals the text length */ + if (j == psiconv_list_length(paragraph->in_lines)-1) { + if (paralen > strlen(paragraph->text)+1) { + res = -PSICONV_E_GENERATE; + goto ERROR5; + } + thislen += strlen(paragraph->text)+1-paralen; + } + if ((res = psiconv_write_u32(buf_inlines,thislen))) goto ERROR5; if ((res = psiconv_write_character_layout_list(buf_inlines, in_line->layout, @@ -212,16 +226,29 @@ goto ERROR5; } } else { - /* No inline layouts, so we generate a paragraph type list */ + /* No inline layouts (or only 1), so we generate a paragraph type list */ para_type = 0; + /* Set para_charlayout to the correct character-level layout */ + if (psiconv_list_length(paragraph->in_lines) == 0) + para_charlayout = paragraph->base_character; + else { + if (!(in_line = psiconv_list_get(paragraph->in_lines,0))) { + psiconv_warn(0,psiconv_buffer_length(buf), + "Massive memory corruption"); + res = -PSICONV_E_OTHER; + goto ERROR5; + } + para_charlayout = in_line->layout; + } for (j = 0; j < psiconv_list_length(paragraph_type_list); j++) { if (!(paragraph_type = psiconv_list_get(paragraph_type_list,j))) { - psiconv_warn(0,psiconv_buffer_length(buf),"Massive memory corruption"); + psiconv_warn(0,psiconv_buffer_length(buf), + "Massive memory corruption"); res = -PSICONV_E_OTHER; goto ERROR5; } if ((paragraph->base_style == paragraph_type->style) && - !psiconv_compare_character_layout(paragraph->base_character, + !psiconv_compare_character_layout(para_charlayout, paragraph_type->character) && !psiconv_compare_paragraph_layout(paragraph->base_paragraph, paragraph_type->paragraph)) { @@ -234,7 +261,7 @@ para_type = new_type.nr = j+1; /* No need to copy them, we won't change them anyway */ new_type.paragraph = paragraph->base_paragraph; - new_type.character = paragraph->base_character; + new_type.character = para_charlayout; new_type.style = paragraph->base_style; paragraph_type = &new_type; if ((res = psiconv_list_add(paragraph_type_list,paragraph_type)))