1 |
// -*- C++ -*- |
// -*- C++ -*- |
2 |
/* Copyright (C) 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc. |
/* Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005 |
3 |
|
* Free Software Foundation, Inc. |
4 |
* |
* |
5 |
* Gaius Mulley (gaius@glam.ac.uk) wrote post-html.cpp |
* Gaius Mulley (gaius@glam.ac.uk) wrote post-html.cpp |
6 |
* but it owes a huge amount of ideas and raw code from |
* but it owes a huge amount of ideas and raw code from |
1994 |
int next_center; |
int next_center; |
1995 |
int seen_space; |
int seen_space; |
1996 |
int seen_break; |
int seen_break; |
1997 |
|
int current_column; |
1998 |
|
int row_space; |
1999 |
assert_state as; |
assert_state as; |
2000 |
|
|
2001 |
void flush_sbuf (); |
void flush_sbuf (); |
2022 |
void start_font (const char *name); |
void start_font (const char *name); |
2023 |
void end_font (const char *name); |
void end_font (const char *name); |
2024 |
int is_font_courier (font *f); |
int is_font_courier (font *f); |
2025 |
|
int is_line_start (int nf); |
2026 |
int is_courier_until_eol (void); |
int is_courier_until_eol (void); |
2027 |
void start_size (int from, int to); |
void start_size (int from, int to); |
2028 |
void do_font (text_glob *g); |
void do_font (text_glob *g); |
2094 |
void do_end_para (text_glob *g); |
void do_end_para (text_glob *g); |
2095 |
int round_width (int x); |
int round_width (int x); |
2096 |
void handle_tag_within_title (text_glob *g); |
void handle_tag_within_title (text_glob *g); |
2097 |
|
void writeHeadMetaStyle (void); |
2098 |
// ADD HERE |
// ADD HERE |
2099 |
|
|
2100 |
public: |
public: |
2203 |
determine_space(g); |
determine_space(g); |
2204 |
current_paragraph->do_emittext(g->text_string, g->text_length); |
current_paragraph->do_emittext(g->text_string, g->text_length); |
2205 |
} else { |
} else { |
2206 |
|
int space = current_paragraph->retrieve_para_space() || seen_space; |
2207 |
|
|
2208 |
current_paragraph->done_para(); |
current_paragraph->done_para(); |
2209 |
shutdown_table(); |
shutdown_table(); |
2210 |
switch (next_tag) { |
switch (next_tag) { |
2211 |
|
|
2212 |
case CENTERED: |
case CENTERED: |
2213 |
current_paragraph->do_para("align=center"); |
current_paragraph->do_para("align=center", space); |
2214 |
break; |
break; |
2215 |
case LEFT: |
case LEFT: |
2216 |
current_paragraph->do_para(&html, "align=left", get_troff_indent(), pageoffset, linelength); |
current_paragraph->do_para(&html, "align=left", get_troff_indent(), pageoffset, linelength, space); |
2217 |
break; |
break; |
2218 |
case RIGHT: |
case RIGHT: |
2219 |
current_paragraph->do_para(&html, "align=right", get_troff_indent(), pageoffset, linelength); |
current_paragraph->do_para(&html, "align=right", get_troff_indent(), pageoffset, linelength, space); |
2220 |
break; |
break; |
2221 |
default: |
default: |
2222 |
fatal("unknown enumeration"); |
fatal("unknown enumeration"); |
2415 |
void html_printer::write_header (void) |
void html_printer::write_header (void) |
2416 |
{ |
{ |
2417 |
if (! header.header_buffer.empty()) { |
if (! header.header_buffer.empty()) { |
2418 |
|
int space = current_paragraph->retrieve_para_space() || seen_space; |
2419 |
|
|
2420 |
if (header.header_level > 7) { |
if (header.header_level > 7) { |
2421 |
header.header_level = 7; |
header.header_level = 7; |
2422 |
} |
} |
2500 |
header.no_of_headings, header.no_of_headings, |
header.no_of_headings, header.no_of_headings, |
2501 |
header.no_of_headings, header.no_of_headings); |
header.no_of_headings, header.no_of_headings); |
2502 |
|
|
2503 |
current_paragraph->do_para(&html, "", get_troff_indent(), pageoffset, linelength); |
current_paragraph->do_para(&html, "", get_troff_indent(), pageoffset, linelength, space); |
2504 |
} |
} |
2505 |
} |
} |
2506 |
|
|
2696 |
{ |
{ |
2697 |
if ((device_indent != -1) && |
if ((device_indent != -1) && |
2698 |
(pageoffset+device_indent != in+pageoff)) { |
(pageoffset+device_indent != in+pageoff)) { |
2699 |
|
|
2700 |
|
int space = current_paragraph->retrieve_para_space() || seen_space; |
2701 |
current_paragraph->done_para(); |
current_paragraph->done_para(); |
2702 |
|
|
2703 |
device_indent = in; |
device_indent = in; |
2706 |
linelength = linelen; |
linelength = linelen; |
2707 |
|
|
2708 |
current_paragraph->do_para(&html, "", device_indent, |
current_paragraph->do_para(&html, "", device_indent, |
2709 |
pageoffset, max_linelength); |
pageoffset, max_linelength, space); |
2710 |
} |
} |
2711 |
} |
} |
2712 |
|
|
2774 |
|
|
2775 |
if (fill_on != on) { |
if (fill_on != on) { |
2776 |
if (on) |
if (on) |
2777 |
current_paragraph->do_para(""); |
current_paragraph->do_para("", seen_space); |
2778 |
fill_on = on; |
fill_on = on; |
2779 |
} |
} |
2780 |
} |
} |
2805 |
seen_center = FALSE; |
seen_center = FALSE; |
2806 |
if (next_center > 0) { |
if (next_center > 0) { |
2807 |
if (end_center == 0) { |
if (end_center == 0) { |
2808 |
|
int space = current_paragraph->retrieve_para_space() || seen_space; |
2809 |
current_paragraph->done_para(); |
current_paragraph->done_para(); |
2810 |
supress_sub_sup = TRUE; |
supress_sub_sup = TRUE; |
2811 |
current_paragraph->do_para("align=center"); |
current_paragraph->do_para("align=center", space); |
2812 |
} else |
} else |
2813 |
if (strcmp("align=center", |
if (strcmp("align=center", |
2814 |
current_paragraph->get_alignment()) != 0) { |
current_paragraph->get_alignment()) != 0) { |
2816 |
* different alignment, so shutdown paragraph and open |
* different alignment, so shutdown paragraph and open |
2817 |
* a new one. |
* a new one. |
2818 |
*/ |
*/ |
2819 |
|
int space = current_paragraph->retrieve_para_space() || seen_space; |
2820 |
current_paragraph->done_para(); |
current_paragraph->done_para(); |
2821 |
supress_sub_sup = TRUE; |
supress_sub_sup = TRUE; |
2822 |
current_paragraph->do_para("align=center"); |
current_paragraph->do_para("align=center", space); |
2823 |
} else |
} else |
2824 |
/* |
/* |
2825 |
* same alignment, if we have emitted text then issue a break. |
* same alignment, if we have emitted text then issue a break. |
2831 |
* next_center == 0 |
* next_center == 0 |
2832 |
*/ |
*/ |
2833 |
if (end_center > 0) { |
if (end_center > 0) { |
2834 |
|
seen_space = seen_space || current_paragraph->retrieve_para_space(); |
2835 |
current_paragraph->done_para(); |
current_paragraph->done_para(); |
2836 |
supress_sub_sup = TRUE; |
supress_sub_sup = TRUE; |
2837 |
} |
} |
2968 |
|
|
2969 |
seen_space = atoi(arg); |
seen_space = atoi(arg); |
2970 |
as.check_sp(seen_space); |
as.check_sp(seen_space); |
2971 |
|
#if 0 |
2972 |
|
if (n>0 && table) |
2973 |
|
table->set_space(TRUE); |
2974 |
|
#endif |
2975 |
|
|
2976 |
while (n>0) { |
while (n>0) { |
2977 |
current_paragraph->do_space(); |
current_paragraph->do_space(); |
2978 |
n--; |
n--; |
2989 |
html_table *t = g->get_table(); |
html_table *t = g->get_table(); |
2990 |
|
|
2991 |
if (t != NULL) { |
if (t != NULL) { |
2992 |
|
current_column = 0; |
2993 |
current_paragraph->done_pre(); |
current_paragraph->done_pre(); |
2994 |
current_paragraph->done_para(); |
current_paragraph->done_para(); |
2995 |
current_paragraph->remove_para_space(); |
current_paragraph->remove_para_space(); |
3000 |
|
|
3001 |
t->set_linelength(max_linelength); |
t->set_linelength(max_linelength); |
3002 |
t->add_indent(pageoffset); |
t->add_indent(pageoffset); |
3003 |
|
#if 0 |
3004 |
|
t->emit_table_header(seen_space); |
3005 |
|
#else |
3006 |
t->emit_table_header(FALSE); |
t->emit_table_header(FALSE); |
3007 |
|
row_space = current_paragraph->retrieve_para_space() || seen_space; |
3008 |
|
seen_space = FALSE; |
3009 |
|
#endif |
3010 |
} |
} |
3011 |
|
|
3012 |
table = t; |
table = t; |
3020 |
{ |
{ |
3021 |
if (table) { |
if (table) { |
3022 |
current_paragraph->done_para(); |
current_paragraph->done_para(); |
3023 |
|
current_paragraph->remove_para_space(); |
3024 |
table->emit_finish_table(); |
table->emit_finish_table(); |
3025 |
} |
} |
3026 |
|
|
3068 |
void html_printer::do_col (char *s) |
void html_printer::do_col (char *s) |
3069 |
{ |
{ |
3070 |
if (table) { |
if (table) { |
3071 |
|
if (atoi(s) < current_column) |
3072 |
|
row_space = seen_space; |
3073 |
|
|
3074 |
|
current_column = atoi(s); |
3075 |
current_paragraph->done_para(); |
current_paragraph->done_para(); |
3076 |
table->emit_col(atoi(s)); |
table->emit_col(current_column); |
3077 |
|
current_paragraph->do_para("", row_space); |
3078 |
} |
} |
3079 |
} |
} |
3080 |
|
|
3195 |
page_contents->glyphs.start_from_head(); |
page_contents->glyphs.start_from_head(); |
3196 |
do { |
do { |
3197 |
g = page_contents->glyphs.get_data(); |
g = page_contents->glyphs.get_data(); |
|
if (strcmp(g->text_string, "Here") == 0) |
|
|
stop(); |
|
|
|
|
3198 |
#if 0 |
#if 0 |
3199 |
fprintf(stderr, "[%s:%d:%d:%d:%d]", |
fprintf(stderr, "[%s:%d:%d:%d:%d]", |
3200 |
g->text_string, g->minv, g->minh, g->maxv, g->maxh) ; |
g->text_string, g->minv, g->minh, g->maxv, g->maxh) ; |
3758 |
} |
} |
3759 |
|
|
3760 |
/* |
/* |
3761 |
|
* is_line_start - returns TRUE if we are at the start of a line. |
3762 |
|
*/ |
3763 |
|
|
3764 |
|
int html_printer::is_line_start (int nf) |
3765 |
|
{ |
3766 |
|
int line_start = FALSE; |
3767 |
|
int result = TRUE; |
3768 |
|
text_glob *orig = page_contents->glyphs.get_data(); |
3769 |
|
text_glob *g; |
3770 |
|
|
3771 |
|
if (! page_contents->glyphs.is_equal_to_head()) { |
3772 |
|
do { |
3773 |
|
page_contents->glyphs.move_left(); |
3774 |
|
g = page_contents->glyphs.get_data(); |
3775 |
|
result = !g->is_a_tag(); |
3776 |
|
if (g->is_fi()) |
3777 |
|
nf = FALSE; |
3778 |
|
else if (g->is_nf()) |
3779 |
|
nf = TRUE; |
3780 |
|
line_start = g->is_col() || g->is_br() || (nf && g->is_eol()); |
3781 |
|
} while ((!line_start) && (result)); |
3782 |
|
/* |
3783 |
|
* now restore our previous position. |
3784 |
|
*/ |
3785 |
|
while (page_contents->glyphs.get_data() != orig) |
3786 |
|
page_contents->glyphs.move_right(); |
3787 |
|
} |
3788 |
|
return result; |
3789 |
|
} |
3790 |
|
|
3791 |
|
/* |
3792 |
* is_font_courier - returns TRUE if the font, f, is courier. |
* is_font_courier - returns TRUE if the font, f, is courier. |
3793 |
*/ |
*/ |
3794 |
|
|
3848 |
current_paragraph->do_bold(); |
current_paragraph->do_bold(); |
3849 |
current_paragraph->do_italic(); |
current_paragraph->do_italic(); |
3850 |
} else if (strcmp(fontname, "CR") == 0) { |
} else if (strcmp(fontname, "CR") == 0) { |
3851 |
if ((! fill_on) && (is_courier_until_eol())) { |
if ((! fill_on) && (is_courier_until_eol()) && |
3852 |
|
is_line_start(fill_on)) { |
3853 |
current_paragraph->do_pre(); |
current_paragraph->do_pre(); |
3854 |
} |
} |
3855 |
current_paragraph->do_tt(); |
current_paragraph->do_tt(); |
3856 |
} else if (strcmp(fontname, "CI") == 0) { |
} else if (strcmp(fontname, "CI") == 0) { |
3857 |
if ((! fill_on) && (is_courier_until_eol())) { |
if ((! fill_on) && (is_courier_until_eol()) && |
3858 |
|
is_line_start(fill_on)) { |
3859 |
current_paragraph->do_pre(); |
current_paragraph->do_pre(); |
3860 |
} |
} |
3861 |
current_paragraph->do_tt(); |
current_paragraph->do_tt(); |
3862 |
current_paragraph->do_italic(); |
current_paragraph->do_italic(); |
3863 |
} else if (strcmp(fontname, "CB") == 0) { |
} else if (strcmp(fontname, "CB") == 0) { |
3864 |
if ((! fill_on) && (is_courier_until_eol())) { |
if ((! fill_on) && (is_courier_until_eol()) && |
3865 |
|
is_line_start(fill_on)) { |
3866 |
current_paragraph->do_pre(); |
current_paragraph->do_pre(); |
3867 |
} |
} |
3868 |
current_paragraph->do_tt(); |
current_paragraph->do_tt(); |
3869 |
current_paragraph->do_bold(); |
current_paragraph->do_bold(); |
3870 |
} else if (strcmp(fontname, "CBI") == 0) { |
} else if (strcmp(fontname, "CBI") == 0) { |
3871 |
if ((! fill_on) && (is_courier_until_eol())) { |
if ((! fill_on) && (is_courier_until_eol()) && |
3872 |
|
is_line_start(fill_on)) { |
3873 |
current_paragraph->do_pre(); |
current_paragraph->do_pre(); |
3874 |
} |
} |
3875 |
current_paragraph->do_tt(); |
current_paragraph->do_tt(); |
4030 |
{ |
{ |
4031 |
do_font(g); |
do_font(g); |
4032 |
current_paragraph->done_para(); |
current_paragraph->done_para(); |
4033 |
|
current_paragraph->remove_para_space(); |
4034 |
html.put_string(g->text_string+9); |
html.put_string(g->text_string+9); |
4035 |
output_vpos = g->minv; |
output_vpos = g->minv; |
4036 |
output_hpos = g->maxh; |
output_hpos = g->maxh; |
4188 |
seen_center(FALSE), |
seen_center(FALSE), |
4189 |
next_center(0), |
next_center(0), |
4190 |
seen_space(0), |
seen_space(0), |
4191 |
seen_break(0) |
seen_break(0), |
4192 |
|
current_column(0), |
4193 |
|
row_space(FALSE) |
4194 |
{ |
{ |
4195 |
file_list.add_new_file(xtmpfile()); |
file_list.add_new_file(xtmpfile()); |
4196 |
html.set_file(file_list.get_file()); |
html.set_file(file_list.get_file()); |
4500 |
output_vpos_max = -1; |
output_vpos_max = -1; |
4501 |
current_paragraph = new html_text(&html); |
current_paragraph = new html_text(&html); |
4502 |
do_indent(get_troff_indent(), pageoffset, linelength); |
do_indent(get_troff_indent(), pageoffset, linelength); |
4503 |
current_paragraph->do_para(""); |
current_paragraph->do_para("", FALSE); |
4504 |
} |
} |
4505 |
|
|
4506 |
void html_printer::end_page(int) |
void html_printer::end_page(int) |
4622 |
fflush(stdout); |
fflush(stdout); |
4623 |
freopen(split_file.contents(), "w", stdout); |
freopen(split_file.contents(), "w", stdout); |
4624 |
fragment_no++; |
fragment_no++; |
4625 |
|
writeHeadMetaStyle(); |
4626 |
write_navigation(top, prev, next, current); |
write_navigation(top, prev, next, current); |
4627 |
} |
} |
4628 |
if (file_list.are_links_required()) |
if (file_list.are_links_required()) |
4634 |
write_rule(); |
write_rule(); |
4635 |
} |
} |
4636 |
|
|
4637 |
|
/* |
4638 |
|
* writeHeadMetaStyle - emits the <head> <meta> and <style> tags and |
4639 |
|
* related information. |
4640 |
|
*/ |
4641 |
|
|
4642 |
|
void html_printer::writeHeadMetaStyle (void) |
4643 |
|
{ |
4644 |
|
fputs("<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n", stdout); |
4645 |
|
fputs("\"http://www.w3.org/TR/html4/loose.dtd\">\n", stdout); |
4646 |
|
|
4647 |
|
fputs("<html>\n", stdout); |
4648 |
|
fputs("<head>\n", stdout); |
4649 |
|
fputs("<meta name=\"generator\" " |
4650 |
|
"content=\"groff -Thtml, see www.gnu.org\">\n", stdout); |
4651 |
|
fputs("<meta http-equiv=\"Content-Type\" " |
4652 |
|
"content=\"text/html; charset=US-ASCII\">\n", stdout); |
4653 |
|
fputs("<meta name=\"Content-Style\" content=\"text/css\">\n", stdout); |
4654 |
|
|
4655 |
|
fputs("<style type=\"text/css\">\n", stdout); |
4656 |
|
fputs(" p { margin-top: 0; margin-bottom: 0; }\n", stdout); |
4657 |
|
fputs(" pre { margin-top: 0; margin-bottom: 0; }\n", stdout); |
4658 |
|
fputs(" table { margin-top: 0; margin-bottom: 0; }\n", stdout); |
4659 |
|
fputs("</style>\n", stdout); |
4660 |
|
} |
4661 |
|
|
4662 |
html_printer::~html_printer() |
html_printer::~html_printer() |
4663 |
{ |
{ |
4664 |
#ifdef LONG_FOR_TIME_T |
#ifdef LONG_FOR_TIME_T |
4681 |
.put_string(ctime(&t), strlen(ctime(&t))-1) |
.put_string(ctime(&t), strlen(ctime(&t))-1) |
4682 |
.end_comment(); |
.end_comment(); |
4683 |
|
|
4684 |
fputs("<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n", stdout); |
writeHeadMetaStyle(); |
|
fputs("\"http://www.w3.org/TR/html4/loose.dtd\">\n", stdout); |
|
4685 |
|
|
|
fputs("<html>\n", stdout); |
|
|
fputs("<head>\n", stdout); |
|
|
fputs("<meta name=\"generator\" " |
|
|
"content=\"groff -Thtml, see www.gnu.org\">\n", stdout); |
|
|
fputs("<meta http-equiv=\"Content-Type\" " |
|
|
"content=\"text/html; charset=US-ASCII\">\n", stdout); |
|
|
fputs("<meta name=\"Content-Style\" content=\"text/css\">\n", stdout); |
|
4686 |
write_title(TRUE); |
write_title(TRUE); |
4687 |
head_info += '\0'; |
head_info += '\0'; |
4688 |
fputs(head_info.contents(), stdout); |
fputs(head_info.contents(), stdout); |