From 157091c4e76808f335bd2f2efc5619d8fca61d89 Mon Sep 17 00:00:00 2001 From: Werner LEMBERG Date: Sun, 30 Apr 2000 05:09:24 +0000 Subject: [PATCH] * html.cc (calculate_margin): Calculate the left and right margin irrespective of the boolean `margin_on'. Fixes a divide by zero bug and a column bug as reported by Steve Blinkhorn . Improved the behaviour of the -m (margin on) option. * html.cc (make_html_indent): More checking. * html.cc (right_indentation): Fixed substitution slip-up. * ordered_list.h (list_element): Added `' twice to satisfy picky --- src/devices/grohtml/ChangeLog | 13 +++- src/devices/grohtml/html.cc | 143 ++++++++++++++++++++++++------------------ 2 files changed, 93 insertions(+), 63 deletions(-) diff --git a/src/devices/grohtml/ChangeLog b/src/devices/grohtml/ChangeLog index 3a4b8ce6..afbf8727 100755 --- a/src/devices/grohtml/ChangeLog +++ b/src/devices/grohtml/ChangeLog @@ -1,3 +1,14 @@ +2000-04-28 Gaius Mulley + + * html.cc (calculate_margin): Calculate the left and right margin + irrespective of the boolean `margin_on'. Fixes a divide by zero + bug and a column bug as reported by Steve Blinkhorn . + Improved the behaviour of the -m (margin on) option. + + * html.cc (make_html_indent): More checking. + + * html.cc (right_indentation): Fixed substitution slip-up. + 2000-03-30 Werner LEMBERG * grohtml.man: Document use of whitespace between command line @@ -9,7 +20,7 @@ 2000-03-11 Werner LEMBERG - * ordered_list.h (list_element): Added `' twice to satisfy picky + * ordered_list.h (list_element): Added `' twice to satisfy picky compilers. 2000-03-01 Gaius Mulley diff --git a/src/devices/grohtml/html.cc b/src/devices/grohtml/html.cc index b5121534..f63b0af4 100755 --- a/src/devices/grohtml/html.cc +++ b/src/devices/grohtml/html.cc @@ -1155,6 +1155,7 @@ class html_printer : public printer { int get_left (void); void can_loose_column (text_glob *start, struct text_defn *last_guess, int limit); int check_lack_of_hits (struct text_defn *next_guess, struct text_defn *last_guess, text_glob *start, int limit); + int is_in_table (void); // ADD HERE @@ -1917,31 +1918,29 @@ void html_printer::restore_paragraph (void) void html_printer::calculate_margin (void) { - if (! margin_on) { - text_glob *w; - graphic_glob *g; + text_glob *w; + graphic_glob *g; - // remove margin + // remove margin - right_margin_indent = 0; + right_margin_indent = 0; - if (! page_contents->words.is_empty()) { - - // firstly check the words to determine the right margin + if (! page_contents->words.is_empty()) { + + // firstly check the words to determine the right margin - page_contents->words.start_from_head(); - do { - w = page_contents->words.get_data(); - if ((w->maxh >= 0) && (w->maxh > right_margin_indent)) { - right_margin_indent = w->maxh; + page_contents->words.start_from_head(); + do { + w = page_contents->words.get_data(); + if ((w->maxh >= 0) && (w->maxh > right_margin_indent)) { + right_margin_indent = w->maxh; #if 0 - if (right_margin_indent == 758) stop(); + if (right_margin_indent == 758) stop(); #endif - } - page_contents->words.move_right(); - } while (! page_contents->words.is_equal_to_head()); - } - + } + page_contents->words.move_right(); + } while (! page_contents->words.is_equal_to_head()); + /* * only examine graphics if no words present */ @@ -1960,6 +1959,7 @@ void html_printer::calculate_margin (void) } while (! page_contents->lines.is_equal_to_head()); } + /* * now we know the right margin lets do the same to find left margin */ @@ -1968,7 +1968,7 @@ void html_printer::calculate_margin (void) header_indent = right_margin_indent; } left_margin_indent = right_margin_indent; - + if (! page_contents->words.is_empty()) { do { w = page_contents->words.get_data(); @@ -3075,7 +3075,8 @@ int html_printer::is_on_same_line (text_glob *g, int vpos) void html_printer::make_html_indent (int indent) { - if (indent > 0) { + if ((indent > 0) && ((right_margin_indent-get_left()) > 0) && + ((indent*100)/(right_margin_indent-get_left()))) { html.put_string(""); @@ -3142,7 +3143,7 @@ int html_printer::collect_columns (struct text_defn *next_words, if (start != 0) { int graphic_limit = end_region_vpos; - if (is_whole_line_bold(t) && (t->minh <= left_margin_indent)) { + if (is_whole_line_bold(t) && (t->minh <= left_margin_indent) && (guess_on)) { /* * found header therefore terminate indentation table. * Return a negative number so we know a header has @@ -3180,7 +3181,7 @@ int html_printer::collect_columns (struct text_defn *next_words, * if we have found a significant gap then record it */ if (((t->minh - prevh >= mingap) || - ((last_cols != 0) && (last_cols [j].left != 0) && (t->minh == last_cols [j].left))) && + ((last_cols != 0) && (last_cols [j].right != 0) && (t->minh == last_cols [j].left))) && (t->minh != t->maxh)) { next_cols[i].left = t->minh; next_cols[i].right = t->maxh; @@ -3276,11 +3277,11 @@ int html_printer::conflict_with_words (struct text_defn *column_guess, struct te int i=0; int j; - while ((column_guess[i].left != 0) && (i= column_guess[i+1].left)) { + (column_guess[i+1].right != 0) && (words[j].right >= column_guess[i+1].left)) { if (debug_table_on) { fprintf(stderr, "is a conflict with words\n"); fflush(stderr); @@ -3306,7 +3307,7 @@ void html_printer::combine_line (struct text_defn *dest, struct text_defn *src) { int i; - for (i=0; (ileft)) { + while ((ileft)) { i++; } - if (line[i].left == 0) { + if (line[i].right == 0) { // add to the end if (i0) && (line[i-1].left > item->left)) { @@ -3385,7 +3386,7 @@ void html_printer::include_into_list (struct text_defn *line, struct text_defn * int l = line[i].left; int r = line[i].right; - while ((i+1left) { return( TRUE ); } else { @@ -3430,7 +3431,7 @@ void html_printer::calculate_right (struct text_defn *line, int max_words) { int i=0; - while ((i0) { line[i-1].right = line[i].left; } @@ -3447,7 +3448,7 @@ void html_printer::add_right_full_width (struct text_defn *line, int mingap) { int i=0; - while ((i0) { @@ -3503,7 +3504,7 @@ int html_printer::is_column_match (struct text_defn *match, include_into_list(match, &t); } - while ((line1[i].left != 0) && (line2[i].left != 0)) { + while ((line1[i].right != 0) && (line2[i].right != 0)) { if (line1[i].left == line2[j].left) { // same horizontal alignment found include_into_list(match, &line1[i]); @@ -3541,7 +3542,7 @@ int html_printer::check_lack_of_hits (struct text_defn *next_guess, i=0; j=0; while ((i last_guess[j].left) && (last_guess[j].left != 0)) { + if ((next_guess[i-1].right > last_guess[j].left) && (last_guess[j].right != 0)) { removed = TRUE; } } else if (last_guess[j].right < next_line[k].left) { @@ -3605,12 +3606,12 @@ int html_printer::remove_white_using_words (struct text_defn *next_guess, i++; j++; k++; - if ((next_guess[i-1].right > last_guess[j].left) && (last_guess[j].left != 0)) { + if ((next_guess[i-1].right > last_guess[j].left) && (last_guess[j].right != 0)) { removed = TRUE; } } } - while (next_line[k].left != 0) { + while (next_line[k].right != 0) { next_guess[i].left = next_line[k].left; next_guess[i].right = next_line[k].right; i++; @@ -3640,7 +3641,7 @@ int html_printer::count_columns (struct text_defn *line) { int i=0; - while (line[i].left != 0) { + while (line[i].right != 0) { i++; } return( i ); @@ -3699,7 +3700,7 @@ void html_printer::display_columns (const char *word, const char *name, text_def int i=0; fprintf(stderr, "[%s:%s]", name, word); - while (line[i].left != 0) { + while (line[i].right != 0) { fprintf(stderr, " ", line[i].left, line[i].right, line[i].percent); i++; } @@ -3715,7 +3716,7 @@ void html_printer::copy_line (struct text_defn *dest, struct text_defn *src) { int k; - for (k=0; ((src[k].left != 0) && (k= gap) { found = TRUE; } - while ((last_col[i].left != 0) && (last_col[i+1].left != 0)) { + while ((last_col[i].right != 0) && (last_col[i+1].right != 0)) { if (abs(last_col[i+1].left-last_col[i].right) >= gap) { found = TRUE; i++; @@ -3878,13 +3879,13 @@ int html_printer::is_subset_of_columns (text_defn *a, text_defn *b) int j; i=0; - while ((iminh)) { i++; } - if ((col[i].left == g->minh) && (col[i].left != 0)) { + if ((col[i].left == g->minh) && (col[i].right != 0)) { col[i].is_used++; } page_contents->words.move_right(); @@ -4261,7 +4262,11 @@ int html_printer::get_left (void) if ((header_indent < left_margin_indent) && (header_indent != -1)) { return( header_indent ); } else { - return( left_margin_indent ); + if (margin_on) { + return( 0 ); + } else { + return( left_margin_indent ); + } } } @@ -4379,7 +4384,7 @@ int html_printer::large_enough_gap_for_two (struct text_defn *col) if (abs(col[i].left - left_margin_indent) >= gap) { found = TRUE; } - while ((col[i].left != 0) && (col[i+1].left != 0)) { + while ((col[i].right != 0) && (col[i+1].right != 0)) { if (abs(col[i+1].left-col[i].right) >= gap) { found = TRUE; i++; @@ -4566,7 +4571,7 @@ int html_printer::is_new_exact_right (struct text_defn *last_guess, int n=count_columns(last_guess)-1; return( FALSE ); - if ((n>=0) && (last_guess[n].left != 0) && (last_cols[n].left != 0) && (next_cols[n].left != 0)) { + if ((n>=0) && (last_guess[n].right != 0) && (last_cols[n].right != 0) && (next_cols[n].right != 0)) { if ((last_cols[n].right != last_guess[n].right) && ((next_cols[n].right == last_guess[n].right) || (next_cols[n].right == right_margin_indent))) { return( TRUE ); @@ -4624,8 +4629,8 @@ int html_printer::found_use_for_table (text_glob *start) int limit; // vertical limit reached in our table int limit_1; // vertical position after line 1 -#if 1 - if (strcmp(start->text_string, "This") == 0) { +#if 0 + if (strcmp(start->text_string, "
") == 0) { stop(); } #endif @@ -4999,6 +5004,17 @@ void html_printer::end_table (void) supress_sub_sup = TRUE; } + +/* + * is_in_table - returns TRUE if we are inside an html table. + */ + +int html_printer::is_in_table (void) +{ + return( indentation.no_of_columns != 0 ); +} + + /* * column_calculate_right_margin - scan through the column and find the right most margin */ @@ -5091,7 +5107,7 @@ int html_printer::find_column_index_in_line (text_glob *t, text_defn *line) { int i=0; - while ((line != 0) && ((line[i].left != 0) || (line[i].right != 0)) && + while ((line != 0) && ((line[i].right != 0) || (line[i].right != 0)) && (! ((line[i].left<=t->minh) && (line[i].right>t->minh)))) { i++; } @@ -5229,7 +5245,7 @@ void html_printer::assign_used_columns (text_glob *start) if (! page_contents->words.is_empty()) { do { i = find_column_index(t); - if (indentation.columns[i].left != 0) { + if (indentation.columns[i].right != 0) { if (debug_table_on) { fprintf(stderr, "[%s] in column %d at %d..%d limit %d\n", t->text_string, i, t->minv, t->maxv, indentation.vertical_limit); fflush(stderr); @@ -5602,6 +5618,9 @@ char *html_printer::html_position_text (text_glob *g, int left_margin, int right return( postword ); } else { force_begin_paragraph(); + if ((! is_in_table()) && (margin_on)) { + make_html_indent(left_margin); + } if (g->minh-left_margin != 0) { make_html_indent(g->minh-left_margin); } -- 2.11.4.GIT