[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Groff] HTML output in Mozilla
From: |
Gaius Mulley |
Subject: |
Re: [Groff] HTML output in Mozilla |
Date: |
Wed, 11 Apr 2001 02:17:25 +0100 |
Hi Werner,
here are some patches which fix some of the outstanding bugs.
I've held back on some of the image bugfixing I'm currently
doing (Lesters paper in particular), so that you can include
these into the Easter gift :-)
The inline image fixing is coming along, I hope to post these
fixes soon ish (probably after Easter?), it is quite fun
tracking down the image extent bugs..
Anyway for the moment it might be worth including these
patches,
Gaius
These fixes include:
2001-04-11 Gaius Mulley <address@hidden>
* src/preproc/html/pre-html.cc (createImage): fixed right hand cropping
of images.
* src/preproc/html/pre-html.cc (removeTempFiles): new function to tidy
up
temporary files.
* src/preproc/html/pre-html.cc (main): calls removeTempFiles.
* src/devices/grohtml/post-html.cc: new method is_auto_img.
* src/devices/grohtml/post-html.cc (generate_img_src): new function.
* src/devices/grohtml/post-html.cc (html_printer::do_auto_image):
utilizes it.
* src/devices/grohtml/post-html.cc (do_heading) (do_title):
include inline images within their contents.
* src/devices/grohtml/post-html.cc (html_printer::begin_page):
tidied up comments that are issued to the html output file.
* src/devices/grohtml/post-html.cc (html_printer::do_fill):
fixed so that .nf works with fonts other than courier.
* tmac/s.tmac: if -Thtml then emit $1 in .IP rather than its
equivalent diversion.
2001-04-08 Bruno Haible <address@hidden>
* src/devices/grohtml/post-html.cc (html_printer::add_to_sbuf): Escape
the html_glyph in the buffer.
(str_translate_to_html): Output the unescaped escaped_char.
* src/devices/grohtml/html-text.cc (issue_table_begin): Set
frame=void, not frame=none. Add border=0.
--- groff-cvs/src/preproc/html/pre-html.cc Sun Mar 4 22:22:56 2001
+++ groff-html/src/preproc/html/pre-html.cc Wed Apr 11 00:16:45 2001
@@ -55,8 +55,10 @@
#define POSTSCRIPTRES 72000 // maybe there is a better way to find
this? --fixme--
#define DEFAULT_IMAGE_RES 80 // 80 pixels per inch resolution
-#define DEFAULT_VERTICAL_OFFSET 40 // 40/72 of an inch
-#define IMAGE_BOARDER_PIXELS 10
+#define DEFAULT_VERTICAL_OFFSET 45 // DEFAULT_VERTICAL_OFFSET/72 of an inch
+#define IMAGE_BOARDER_PIXELS 10
+#define MAX_WIDTH 8 // inches
+#define INLINE_LEADER_CHAR '\\'
#define TRANSPARENT "-background \"#FFF\" -transparent \"#FFF\""
@@ -640,9 +657,10 @@
if (i->X1 != -1) {
char buffer[4096];
int x1 = max(min(i->X1,
i->X2)*image_res/POSTSCRIPTRES-1*IMAGE_BOARDER_PIXELS, 0);
- int y1 = max((image_res*vertical_offset/72)+min(i->Y1,
i->Y2)*image_res/POSTSCRIPTRES, 0);
- int x2 = min(max(i->X1,
i->X2)*image_res/POSTSCRIPTRES+1*IMAGE_BOARDER_PIXELS,
i->maxx*image_res/POSTSCRIPTRES);
- int y2 = (image_res*vertical_offset/72)+max(i->Y1,
i->Y2)*image_res/POSTSCRIPTRES+2*IMAGE_BOARDER_PIXELS;
+ int y1 = max((image_res*vertical_offset/72)+min(i->Y1,
i->Y2)*image_res/POSTSCRIPTRES-IMAGE_BOARDER_PIXELS, 0);
+ int x2 = max(i->X1, i->X2)*image_res/POSTSCRIPTRES+1*IMAGE_BOARDER_PIXELS;
+ // int x2 = min(max(i->X1,
i->X2)*image_res/POSTSCRIPTRES+1*IMAGE_BOARDER_PIXELS,
i->maxx*image_res/POSTSCRIPTRES);
+ int y2 = (image_res*vertical_offset/72)+max(i->Y1,
i->Y2)*image_res/POSTSCRIPTRES+1*IMAGE_BOARDER_PIXELS;
sprintf(buffer,
"pnmcut %d %d %d %d < %s%d | pnmtopng %s > %s \n",
@@ -753,7 +767,7 @@
int y1 = f->readInt();
int x2 = f->readInt();
int y2 = f->readInt();
- int maxx = f->readInt();
+ int maxx = max(f->readInt(), MAX_WIDTH*image_res);
char *name = f->readString();
int res = POSTSCRIPTRES; // --fixme-- prefer (f->readInt())
providing that troff can discover the value
listOfImages.add(x1, y1, x2, y2, page, res, maxx, name);
@@ -1050,6 +1064,22 @@
}
/*
+ * removeTempFiles - remove the temporary files
+ */
+
+static void removeTempFiles (void)
+{
+#if !defined(DEBUGGING)
+ char buffer[8192];
+
+ sprintf(buffer,
+ "/bin/rm -f %s* %s* \n",
+ psFileName, regionFileName);
+ system(buffer);
+#endif
+}
+
+/*
* findPrefix - finds the optional prefix to the groff utilities.
* It also builds the 'troff' executable name.
*/
@@ -1100,6 +1130,7 @@
ok = inputFile.do_html(argc, argv);
removeAllPages();
}
+ removeTempFiles();
return ok;
}
--- groff-cvs/src/devices/grohtml/post-html.cc Mon Mar 19 15:33:03 2001
+++ groff-html/src/devices/grohtml/post-html.cc Tue Apr 10 21:42:04 2001
@@ -340,16 +340,18 @@
class text_glob {
public:
text_glob (style *s, char *string, unsigned int length,
- int min_vertical, int min_horizontal,
- int max_vertical, int max_horizontal,
- int is_html , int is_troff_command,
- int is_a_line , int thickness);
+ int min_vertical , int min_horizontal,
+ int max_vertical , int max_horizontal,
+ int is_html , int is_troff_command,
+ int is_auto_image,
+ int is_a_line , int thickness);
text_glob (void);
~text_glob (void);
- int is_a_line (void);
- int is_a_tag (void);
- int is_raw (void);
- int is_eol (void);
+ int is_a_line (void);
+ int is_a_tag (void);
+ int is_raw (void);
+ int is_eol (void);
+ int is_auto_img (void);
style text_style;
char *text_string;
@@ -358,6 +360,7 @@
int is_raw_command; // should the text be sent directly to
the device?
int is_tag; // is this a .br, .sp, .tl etc
int is_line; // is the command a <line>?
+ int is_img_auto; // image created by eqn delim
int thickness; // the thickness of a line
};
@@ -365,11 +368,12 @@
int min_vertical, int min_horizontal,
int max_vertical, int max_horizontal,
int is_html, int is_troff_command,
+ int is_auto_image,
int is_a_line, int line_thickness)
: text_style(*s), text_string(string), text_length(length),
minv(min_vertical), minh(min_horizontal), maxv(max_vertical),
maxh(max_horizontal),
- is_raw_command(is_html), is_tag(is_troff_command), is_line(is_a_line),
- thickness(line_thickness)
+ is_raw_command(is_html), is_tag(is_troff_command),
is_img_auto(is_auto_image),
+ is_line(is_a_line), thickness(line_thickness)
{
}
@@ -420,6 +424,16 @@
}
/*
+ * is_auto_img - returns TRUE if the glob contains an automatically
+ * generated image.
+ */
+
+int text_glob::is_auto_img (void)
+{
+ return( is_img_auto );
+}
+
+/*
* the class and methods used to construct ordered double linked lists.
* In a previous implementation we used templates via #include
"ordered-list.h",
* but this does assume that all C++ compilers can handle this feature.
Pragmatically
@@ -748,7 +762,7 @@
if (length > 0) {
text_glob *g=new text_glob(s, buffer.add_string(string, length), length,
min_vertical, min_horizontal, max_vertical,
max_horizontal,
- FALSE, FALSE, FALSE, 0);
+ FALSE, FALSE, FALSE, FALSE, 0);
glyphs.add(g, line_number, min_vertical, min_horizontal, max_vertical,
max_horizontal);
}
}
@@ -765,7 +779,7 @@
if (length > 0) {
text_glob *g=new text_glob(s, buffer.add_string(string, length), length,
min_vertical, min_horizontal, max_vertical,
max_horizontal,
- TRUE, FALSE, FALSE, 0);
+ TRUE, FALSE, FALSE, FALSE, 0);
glyphs.add(g, line_number, min_vertical, min_horizontal, max_vertical,
max_horizontal);
}
}
@@ -782,7 +796,9 @@
if (length > 0) {
text_glob *g=new text_glob(s, buffer.add_string(string, length), length,
min_vertical, min_horizontal, max_vertical,
max_horizontal,
- FALSE, TRUE, FALSE, 0);
+ FALSE, TRUE,
+ (strncmp(string, "html-tag:.auto-image", 20) ==
0),
+ FALSE, 0);
glyphs.add(g, line_number, min_vertical, min_horizontal, max_vertical,
max_horizontal);
}
}
@@ -799,7 +815,7 @@
if (y1 == y2) {
text_glob *g = new text_glob(s, "", 0,
min(y1, y2), min(x1, y2), max(y1, y2), max(x1,
x2),
- FALSE, TRUE, FALSE, thickness);
+ FALSE, TRUE, FALSE, FALSE, thickness);
glyphs.add(g, line_number, min(y1, y2), min(x1, y2), max(y1, y2), max(x1,
x2));
}
}
@@ -1196,6 +1212,30 @@
}
/*
+ * generate_img_src - returns a html image tag for the filename
+ * providing that the image exists.
+ */
+
+static char *generate_img_src (const char *filename)
+{
+ static char buffer[MAX_STRING_LENGTH];
+
+ while (filename && (filename[0] == ' ')) {
+ filename++;
+ }
+ if (exists(filename)) {
+ strcpy(buffer, "<img src=\"");
+ strncat(buffer, filename, MAX_STRING_LENGTH-strlen("<img src=\"")-1);
+ if (strlen(buffer) < MAX_STRING_LENGTH-3) {
+ strncat(buffer, "\">", 3);
+ }
+ return( (char *)&buffer );
+ } else {
+ return( 0 );
+ }
+}
+
+/*
* do_auto_image - tests whether the image, indicated by filename,
* is present, if so then it emits an html image tag.
* An image tag may be passed through from pic, eqn
@@ -1205,24 +1245,17 @@
void html_printer::do_auto_image (text_glob *g, const char *filename)
{
- while (filename && (filename[0] == ' ')) {
- filename++;
- }
- if (exists(filename)) {
+ char *buffer = generate_img_src(filename);
+
+ if (buffer) {
/*
* utilize emit_raw by creating a new text_glob.
*/
text_glob h = *g;
- char buffer[MAX_STRING_LENGTH];
- strcpy(buffer, "<img src=\"");
- strncat(buffer, filename, MAX_STRING_LENGTH-strlen("<img src=\"")-1);
- if (strlen(buffer) < MAX_STRING_LENGTH-3) {
- strncat(buffer, "\">", 3);
- h.text_string = (char *)&buffer;
- h.text_length = strlen(buffer);
- emit_raw(&h);
- }
+ h.text_string = buffer;
+ h.text_length = strlen(buffer);
+ emit_raw(&h);
} else {
next_tag = INLINE;
}
@@ -1245,7 +1278,21 @@
do {
t = page_contents->glyphs.get_data();
removed_from_head = FALSE;
- if (t->is_raw_command) {
+ if (t->is_auto_img()) {
+ char *img=generate_img_src((char *)(t->text_string + 20));
+
+ if (img) {
+ if (found_title_start) {
+ strcat(title.text, " ");
+ }
+ found_title_start = TRUE;
+ title.has_been_found = TRUE;
+ strcat(title.text, img);
+ }
+ page_contents->glyphs.sub_move_right(); /* move onto next
word */
+ removed_from_head = ((!page_contents->glyphs.is_empty()) &&
+ (page_contents->glyphs.is_equal_to_head()));
+ } else if (t->is_raw_command) {
/* skip raw commands
*/
page_contents->glyphs.sub_move_right(); /* move onto next
word */
@@ -1304,7 +1351,7 @@
strlen(header.header_buffer),
header.no_of_headings, header.header_level,
header.no_of_headings, header.header_level,
- FALSE, FALSE, FALSE, FALSE);
+ FALSE, FALSE, FALSE, FALSE, FALSE);
header.headers.add(h,
header.no_of_headings,
header.no_of_headings, header.no_of_headings,
@@ -1368,7 +1415,18 @@
if (! page_contents->glyphs.is_equal_to_head()) {
g = page_contents->glyphs.get_data();
do {
- if (! (g->is_a_line() || g->is_a_tag() || g->is_raw())) {
+ if (g->is_auto_img()) {
+ char *img=generate_img_src((char *)(g->text_string + 20));
+
+ if (img) {
+ simple_anchors = TRUE; // we cannot use full heading anchors with
images
+ if (l != 0) {
+ strcat(header.header_buffer, " ");
+ }
+ l = g;
+ strcat(header.header_buffer, img);
+ }
+ } else if (! (g->is_a_line() || g->is_a_tag() || g->is_raw())) {
/*
* we ignore raw commands when constructing a heading
*/
@@ -1382,7 +1440,7 @@
page_contents->glyphs.move_right();
g = page_contents->glyphs.get_data();
} while ((! page_contents->glyphs.is_equal_to_head()) &&
- (! g->is_a_tag()));
+ ((! g->is_a_tag()) || (g->is_auto_img())));
}
determine_header_level(level);
@@ -1505,7 +1563,18 @@
do {
t = page_contents->glyphs.get_data();
removed_from_head = FALSE;
- if (t->is_raw_command) {
+ if (t->is_auto_img()) {
+ char *img=generate_img_src((char *)(t->text_string + 20));
+
+ if (img) {
+ if (found_indent_start) {
+ strcat(indent.text, " ");
+ }
+ found_indent_start = TRUE;
+ strcat(indent.text, img);
+ }
+ page_contents->glyphs.sub_move_right(); /* move onto next
word */
+ } else if (t->is_raw_command) {
/* skip raw commands
*/
page_contents->glyphs.sub_move_right(); /* move onto next
word */
@@ -1568,6 +1637,7 @@
supress_sub_sup = TRUE;
if (fill_on != on) {
+#if defined(OLD)
if (is_font_courier(output_style.f) && (is_courier_until_eol())) {
if (on) {
current_paragraph->do_pre();
@@ -1575,6 +1645,13 @@
current_paragraph->done_pre();
}
}
+#else
+ if (on) {
+ current_paragraph->done_pre();
+ } else {
+ current_paragraph->do_pre();
+ }
+#endif
}
fill_on = on;
}
@@ -2276,9 +2353,14 @@
int l = strlen(html_glyph);
int i;
+ // Escape the name, so that "&" doesn't get expanded to "&"
+ // later during translate_to_html.
+ add_char_to_sbuf('\\'); add_char_to_sbuf('(');
+
for (i=0; i<l; i++) {
add_char_to_sbuf(html_glyph[i]);
}
+ add_char_to_sbuf('\\'); add_char_to_sbuf(')');
}
}
}
@@ -2632,7 +2714,9 @@
void html_printer::begin_page(int n)
{
page_number = n;
+#if defined(DEBUGGING)
html.begin_comment("Page: ").put_string(i_to_a(page_number)).end_comment();;
+#endif
no_of_printed_pages++;
output_style.f = 0;
@@ -2700,10 +2784,13 @@
#endif
t = time(0);
html.begin_comment("CreationDate: ")
- .put_string(ctime(&t))
+ .put_string(ctime(&t), strlen(ctime(&t))-1)
.end_comment();
}
+#if defined(DEBUGGING)
html.begin_comment("Total number of pages:
").put_string(i_to_a(no_of_printed_pages)).end_comment();
+#endif
+ html.end_line();
html.end_line();
/*
* now run through the file list copying each temporary file in turn and
emitting the links.
--- groff-cvs/src/devices/grohtml/html-text.cc Mon Mar 19 15:33:03 2001
+++ groff-html/src/devices/grohtml/html-text.cc Tue Apr 10 10:55:29 2001
@@ -140,7 +140,7 @@
int width=current_indentation*100/linelength;
if (width > 0) {
- out->put_string("<table width=\"100%\" rules=\"none\" frame=\"none\"\n
cols=\"2\" cellspacing=\"0\" cellpadding=\"0\">").nl();
+ out->put_string("<table width=\"100%\" border=0 rules=\"none\"
frame=\"void\"\n cols=\"2\" cellspacing=\"0\" cellpadding=\"0\">").nl();
out->put_string("<tr valign=\"top\" align=\"left\">").nl();
if ((t->arg1 == 0) || (strcmp(t->arg1, "") == 0))
out->put_string("<td
width=\"").put_number(width).put_string("%\"></td>");
@@ -612,7 +612,11 @@
void html_text::do_space (void)
{
- do_para(done_para());
+ if (is_in_pre()) {
+ do_emittext("", 0);
+ } else {
+ do_para(done_para());
+ }
space_emitted = TRUE;
}
--- groff-cvs/tmac/s.tmac Mon Mar 19 15:33:04 2001
+++ groff-html/tmac/s.tmac Wed Apr 11 01:30:31 2001
@@ -1156,7 +1156,7 @@
. ie '\*(.T'html' \{\
. if \\n[dl]+1n<=\\n[\\n[.ev]:ai] .HTML-TAG ".ip"
. ti 0
-\\*[par*label]
+\&\\$1
. br
. \}
. el \{\
- [Groff] HTML output in Mozilla, Bruno Haible, 2001/04/09
- Re: [Groff] HTML output in Mozilla,
Gaius Mulley <=
- Re: [Groff] HTML output in Mozilla, Werner LEMBERG, 2001/04/11
- Re: [Groff] HTML output in Mozilla, Werner LEMBERG, 2001/04/13
- Re: [Groff] HTML output in Mozilla, Gaius Mulley, 2001/04/13
- Re: [Groff] HTML output in Mozilla, Werner LEMBERG, 2001/04/14
- Re: [Groff] HTML output in Mozilla, Werner LEMBERG, 2001/04/14