--- psiconv/trunk/program/psiconv/gen_html4.c 2004/02/02 21:57:34 194 +++ psiconv/trunk/program/psiconv/gen_html4.c 2004/02/04 11:35:35 195 @@ -96,7 +96,37 @@ output_simple_chars(config,list,"\n",enc); } +int character_layout_equal(const psiconv_character_layout l1, + const psiconv_character_layout l2) +{ + int font_size1,font_size2; + font_size1 = l1->font_size < 8 ?1: + l1->font_size < 10 ?2: + l1->font_size < 13 ?3: + l1->font_size < 17 ?4: + l1->font_size < 24 ?5: + l1->font_size < 36 ?6:7; + font_size2 = l2->font_size < 8 ?1: + l2->font_size < 10 ?2: + l2->font_size < 13 ?3: + l2->font_size < 17 ?4: + l2->font_size < 24 ?5: + l2->font_size < 36 ?6:7; + + return (l1 && l2 && + (l1->color->red == l2->color->red) && + (l1->color->green == l2->color->green) && + (l1->color->blue == l2->color->blue) && + (font_size1 == font_size2) && + (l1->italic == l2->italic) && + (l1->bold == l2->bold) && + (l1->super_sub == l2->super_sub) && + (l1->underline == l2->underline) && + (l1->strikethrough == l2->strikethrough) && + (l1->font->screenfont == l2->font->screenfont)); +} + void characters(const psiconv_config config, psiconv_list list, const psiconv_string_t textstr, const psiconv_character_layout layout,const encoding enc) @@ -167,9 +197,9 @@ void paragraph(const psiconv_config config, psiconv_list list, psiconv_paragraph para, const encoding enc) { - int i,charnr; + int i,charnr,start,len; psiconv_string_t text; - psiconv_in_line_layout layout; + psiconv_in_line_layout layout,next_layout; output_simple_chars(config,list, @@ -185,23 +215,44 @@ output_simple_chars(config,list,">",enc); if (psiconv_list_length(para->in_lines) == 0) { - characters(config,list,para->text,para->base_character,enc); + if (psiconv_unicode_strlen(para->text)) + characters(config,list,para->text,para->base_character,enc); } else { charnr = 0; + start = -1; for (i = 0; i < psiconv_list_length(para->in_lines); i++) { + if (start < 0) + start = charnr; if (!(layout = psiconv_list_get(para->in_lines,i))) { fputs("Internal data structures corruption\n",stderr); exit(1); } - if (!(text = malloc(sizeof (*text) * (layout->length + 1)))) { - fputs("Out of memory error\n",stderr); - exit(1); + if (i+1 < psiconv_list_length(para->in_lines)) { + if (!(next_layout = psiconv_list_get(para->in_lines,i+1))) { + fputs("Internal data structures corruption\n",stderr); + exit(1); + } + } else { + next_layout = NULL; + } + if (next_layout && + character_layout_equal(layout->layout,next_layout->layout)) { + charnr += layout->length; + continue; + } + len = charnr - start + layout->length; + if (len) { + if (!(text = malloc(sizeof (*text) * (len + 1)))) { + fputs("Out of memory error\n",stderr); + exit(1); + } + memcpy(text,para->text+charnr,len * sizeof(*text)); + text[len] = 0; + characters(config,list,text,layout->layout,enc); + free(text); } - memcpy(text,para->text+charnr,layout->length * sizeof(*text)); - text[layout->length] = 0; - characters(config,list,text,layout->layout,enc); - free(text); charnr += layout->length; + start = -1; } } output_simple_chars(config, list,