diff options
author | Fumitoshi UKAI <ukai@debian.or.jp> | 2002-01-31 17:54:47 +0000 |
---|---|---|
committer | Fumitoshi UKAI <ukai@debian.or.jp> | 2002-01-31 17:54:47 +0000 |
commit | 9efbc0885687b07cfe35e5933ebcc202aeff6bef (patch) | |
tree | 03909b91dc1b5c7b0074bea51a549b357b8b9694 /file.c | |
parent | version.c.in: 0.2.5+cvs (diff) | |
download | w3m-9efbc0885687b07cfe35e5933ebcc202aeff6bef.tar.gz w3m-9efbc0885687b07cfe35e5933ebcc202aeff6bef.zip |
w3m-img merge (w3m-0.2.4+cvs-1.278-img-2.2.patch.gz)
* NEWS: w3m-img merge
* .cvsignore: add w3mimgdisplay, w3mimgsize
* XMakefile: add image.c to SRCS
add image.o to OBJS
add IMGDISPLAY, IMGSIZE
* config.h.dist: USE_IMAGE, IMGSIZE, IMGDISPLAY
* configure: add find_imlib
ask use_image
(config.h) add $imgtarget to EXT_TARGETS
$def_use_image
IMGSIZE, IMGDISPLAY
* fm.h (MAX_IMAGE): added
* fm.h (DEFAULT_PIXEL_PER_CHAR): fix for USE_IMAGE
* fm.h (DEFAULT_PIXEL_PER_LINE): added
* fm.h (B_REDRAW_IMAGE): added
* fm.h (IMG_FLAG_SKIP): added
* fm.h (IMG_FLAG_AUTO): added
* fm.h (IMG_FLAG_START): added
* fm.h (IMG_FLAG_STOP): added
* fm.h (IMG_FLAG_NEXT): added
* fm.h (IMG_FLAG_UNLOADED): added
* fm.h (IMG_FLAG_LOADED): added
* fm.h (IMG_FLAG_ERROR): added
* fm.h (MapArea): added
* fm.h (MapList): s/urls/alts/, add area
* fm.h (ImageCache): added
* fm.h (Image): added
* fm.h (Anchor): add image
* fm.h (Buffer): add imarklist, image_flag, need_reshape
* fm.h (RG_FRAME_SRC): added
* fm.h (ALIGN_MIDDLE): added
* fm.h (ALIGN_TOP): added
* fm.h (ALIGN_BOTTOM): added
* fm.h (QuietMessage): added
* fm.h (Imgdisplay): added
* fm.h (Imgsize): added
* fm.h (activeImage): added
* fm.h (displayImage): added
* fm.h (autoImage): added
* fm.h (useExtImageViewer): added
* fm.h (image_source): added
* fm.h (view_unseenobject): change default if USE_IMAGE
* fm.h (set_pixel_per_char): added
* fm.h (pixel_per_line): added
* fm.h (set_pixel_per_line): added
* fm.h (image_scale): added
* proto.h (dispI): added
* proto.h (stopI): added
* proto.h (deleteImage): added
* proto.h (getAllImage): added
* proto.h (loadImage): added
* proto.h (getImage): added
* proto.h (getImageSize): added
* proto.h (process_img): add width arg
* proto.h (loadImageBuffer): added
* proto.h (follow_map_menu): add a_img arg
* proto.h (getMapXY): added
* proto.h (newMapArea): added
* proto.h (touch_cursor): added
* proto.h (cURLcode): added
* proto.h (initImage): added
* proto.h (termImage): added
* proto.h (addImage): added
* proto.h (drawImage): added
* proto.h (clearImage): added
* anchor.c (addMultirowsImg): added
* buffer.c (discardBuffer): deleteImage if USE_IMAGE
* buffer.c (reshapeBuffer): buf->need_reshape check
* display.c (fmTerm): if activeImage, stop load image
* display.c (fmInit): if displayImage, initImage
* display.c (image_touch): added
* display.c (draw_image_flag): added
* display.c (redrawLineImage): added
* display.c (displayBuffer): buf->need_reshape = TRUE
mode == B_REDRAW_IMAGE
image flag checks
force redraw image in mode == B_REDRAW_IMAGE
displayBuffer if need reshape
drawImage
* display.c (redrawNLine): redrawLineImage
* display.c (redrawLineImage): added
* display.c (disp_message_nsec): return immediately if QuietMessage
* etc.c (reset_signals): ignore SIGUSR1
* file.c (frame_source): added
* file.c (_MoveFile): added
* file.c (cur_baseURL): added
* file.c (cur_document_code): added
* file.c (cur_iseq): added
* file.c (loadGeneralFile): fix fmInitialized and prevtrap checks
save cur_baseURL
image_source load
loadImageBuffer for "image/*"
frame_source flag
fix b->type when proc is loadImageBuffer
* file.c (process_img): add width arg
parse height and width attr, align
fix for inline-image
* file.c (process_input): fix for form <input type="image">
* file.c (HTMLtagproc1): pass h_env->limit to process_img()
fix <img_alt> for inline-image
save cur_baseURL
* file.c (HTMLlineproc2body): fix <img_alt> for inline-image
* file.c (loadHTMLstream): fix for inline-image
fix fmInitialized and prevtrap checks
save cur_document_code
save image_flag
* file.c (loadGopherDir): save cur_document_code
fix fmInitialized and prevtrap checks
* file.c (loadImageBuffer): added for inline-image
* file.c (save2tmp): fix fmInitialized and prevtrap checks
* frame.c (frame_download_source): set RG_FRAME_SRC flag
image check
* funcname.tab (DISPLAY_IMAGE): added
* funcname.tab (STOP_IMAGE): added
* html.c (ALST_IMG): add align, ismap
* html.c (ALST_AREA): add shape, coords
* html.c (ALST_IMG_ALT): add width, height, usemap, ismap, hseq,
xoffset, yoffset, top_margin, bottom_margin
* html.c (AttrMap): add shape, coords, ismap, xoffset, yoffset
* html.h (ATTR_SHAPE): added
* html.h (ATTR_COORDS): added
* html.h (ATTR_ISMAP): added
* html.h (ATTR_XOFFSET): added
* html.h (ATTR_YOFFSET): added
* html.h (ATTR_TOP_MARGIN): added
* html.h (ATTR_BOTTOM_MARGIN): added
* html.h (SHAPE_UNKNOWN): added
* html.h (SHAPE_DEFAULT): added
* html.h (SHAPE_RECT): added
* html.h (SHAPE_CIRCLE): added
* html.h (SHAPE_POLY): added
* image.c: added
* main.c (fversion): add USE_IMAGE
* main.c (fusage): -ppl option
* main.c (MAIN): set_pixel_per_char if ppc specified
-ppl option
loadImage
* main.c (pushBuffer): deleteImage
* main.c (quitfm): termImage
* main.c (selBuf): deleteImage
* main.c (followA): fix for inline-image and map area
* main.c (query_from_followform): getMapXY()
* main.c (setOpt): displayBuffer B_REDRAW_IMAGE
* main.c (follow_map): fix calculate x, y
* main.c (dispI): added
* main.c (stopI): added
* map.c: include <math.h>
* map.c (inMapArea): added
* map.c (follow_map_menu): add a_img arg to handle inline-image
* map.c (follow_map_panel): use MapArea
* map.c (getMapXY): added
* map.c (newMapArea): added
* menu.c (smChBuf): deleteImage
* parsetagx.c (toAlign): align top, bottom, middle
* rc.c (P_SCALE): added
* rc.c (CMT_PIXEL_PER_LINE): added
* rc.c (CMT_DISP_IMAGE): added
* rc.c (CMT_AUTO_IMAGE): added
* rc.c (CMT_EXT_IMAGE_VIEWER): added
* rc.c (CMT_IMAGE_SCALE): added
* rc.c (CMT_IMGDISPLAY): added
* rc.c (CMT_IMGSIZE): added
* rc.c (show_param): P_PIXELS
* rc.c (set_param): P_PIXELS
* rc.c (sync_with_option): initImage
* rc.c (to_str): P_PIXELS
* table.c (feed_table_tag): fix <img> for inline-image
* tagtable.tab (image): added
* terms.c (wgetch): retry read when EINTR or EAGAIN
* terms.c (touch_cursor): added
* w3mimgdisplay.c: added
* w3mimgsize.c: added
* doc/README.func (DISPLAY_IMAGE): added
* doc/README.func (STOP_IMAGE): added
* doc/README.img: added
* doc-jp/README.func (DISPLAY_IMAGE): added
* doc-jp/README.func (STOP_IMAGE): added
* doc-jp/README.img: added
* scripts/w3mhelp.cgi.in: show dispI, stopI
* scripts/multipart/multipart.cgi.in: inline image support
From: Fumitoshi UKAI <ukai@debian.or.jp>
Diffstat (limited to 'file.c')
-rw-r--r-- | file.c | 641 |
1 files changed, 523 insertions, 118 deletions
@@ -1,4 +1,4 @@ -/* $Id: file.c,v 1.54 2002/01/31 09:43:14 ukai Exp $ */ +/* $Id: file.c,v 1.55 2002/01/31 17:54:50 ukai Exp $ */ #include "fm.h" #include <sys/types.h> #include "myctype.h" @@ -25,6 +25,9 @@ #define min(a,b) ((a) > (b) ? (b) : (a)) #endif /* not min */ +static int frame_source = 0; + +static int _MoveFile(char *path1, char *path2); static void uncompress_stream(URLFile *uf); static FILE *lessopen_stream(char *path); static Buffer *loadcmdout(char *cmd, @@ -47,6 +50,13 @@ static JMP_BUF AbortLoading; static struct table *tables[MAX_TABLE]; static struct table_mode table_mode[MAX_TABLE]; +#ifdef USE_IMAGE +static ParsedURL *cur_baseURL = NULL; +#ifdef JP_CHARSET +static char cur_document_code; +#endif +#endif + static Str cur_select; static Str select_str; static int select_is_multiple; @@ -113,6 +123,9 @@ static int form_sp = 0; static int current_content_length; static int cur_hseq; +#ifdef USE_IMAGE +static int cur_iseq; +#endif #define MAX_UL_LEVEL 9 #ifdef KANJI_SYMBOLS @@ -1423,10 +1436,10 @@ loadGeneralFile(char *path, ParsedURL *volatile current, char *referer, /* openURL failure: it means either (1) the requested URL is a directory name * on an FTP server, or (2) is a local directory name. */ - if (fmInitialized && prevtrap) { + if (fmInitialized) term_raw(); + if (prevtrap) signal(SIGINT, prevtrap); - } switch (f.scheme) { case SCM_FTPDIR: { @@ -1501,10 +1514,9 @@ loadGeneralFile(char *path, ParsedURL *volatile current, char *referer, /* openURL() succeeded */ if (SETJMP(AbortLoading) != 0) { /* transfer interrupted */ - if (fmInitialized) { + if (fmInitialized) term_raw(); - signal(SIGINT, prevtrap); - } + signal(SIGINT, prevtrap); if (b) discardBuffer(b); UFclose(&f); @@ -1519,10 +1531,9 @@ loadGeneralFile(char *path, ParsedURL *volatile current, char *referer, } if (header_string) header_string = NULL; - if (fmInitialized) { - prevtrap = signal(SIGINT, KeyAbort); + prevtrap = signal(SIGINT, KeyAbort); + if (fmInitialized) term_cbreak(); - } if (pu.scheme == SCM_HTTP || #ifdef USE_SSL pu.scheme == SCM_HTTPS || @@ -1755,14 +1766,17 @@ loadGeneralFile(char *path, ParsedURL *volatile current, char *referer, if (real_type == NULL) real_type = t; proc = loadBuffer; +#ifdef USE_IMAGE + cur_baseURL = New(ParsedURL); + copyParsedURL(cur_baseURL, &pu); +#endif if (do_download) { /* download only */ char *file; - if (fmInitialized) { + if (fmInitialized) term_raw(); - signal(SIGINT, prevtrap); - } + signal(SIGINT, prevtrap); if (DecodeCTE && IStype(f.stream) != IST_ENCODED) f.stream = newEncodedStream(f.stream, f.encoding); if (pu.scheme == SCM_LOCAL) @@ -1786,11 +1800,33 @@ loadGeneralFile(char *path, ParsedURL *volatile current, char *referer, f.compression = CMP_NOCOMPRESS; } } +#ifdef USE_IMAGE + if (image_source) { + Buffer *b = NULL; + if (IStype(f.stream) != IST_ENCODED) + f.stream = newEncodedStream(f.stream, f.encoding); + if (save2tmp(f, image_source) == 0) { + b = newBuffer(INIT_BUFFER_WIDTH); + b->sourcefile = image_source; + b->real_type = t; + } + if (fmInitialized) + term_raw(); + signal(SIGINT, prevtrap); + UFclose(&f); + return b; + } +#endif if (!strcasecmp(t, "text/html")) proc = loadHTMLBuffer; else if (is_plain_text_type(t)) proc = loadBuffer; +#ifdef USE_IMAGE + else if (activeImage && displayImage && !useExtImageViewer && + !w3m_dump && !strncasecmp(t, "image/", 6)) + proc = loadImageBuffer; +#endif #ifdef USE_GOPHER else if (!strcasecmp(t, "gopher:directory")) { proc = loadGopherDir; @@ -1808,17 +1844,15 @@ loadGeneralFile(char *path, ParsedURL *volatile current, char *referer, copyParsedURL(&b->currentURL, &pu); } UFclose(&f); - if (fmInitialized) { + if (fmInitialized) term_raw(); - signal(SIGINT, prevtrap); - } + signal(SIGINT, prevtrap); return b; } else { - if (fmInitialized) { + if (fmInitialized) term_raw(); - signal(SIGINT, prevtrap); - } + signal(SIGINT, prevtrap); if (pu.scheme == SCM_LOCAL) { UFclose(&f); doFileCopy(pu.real_file, @@ -1852,7 +1886,9 @@ loadGeneralFile(char *path, ParsedURL *volatile current, char *referer, t_buf->ssl_certificate = s->ptr; } #endif + frame_source = flag & RG_FRAME_SRC; b = loadSomething(&f, pu.real_file ? pu.real_file : pu.file, proc, t_buf); + frame_source = 0; UFclose(&f); if (b) { b->real_scheme = f.scheme; @@ -1866,6 +1902,10 @@ loadGeneralFile(char *path, ParsedURL *volatile current, char *referer, Str s = Strnew_charp(t); b->type = s->ptr; } +#ifdef USE_IMAGE + else if (proc == loadImageBuffer) + b->type = b->real_type; +#endif else b->type = "text/plain"; if (pu.label) { @@ -1900,10 +1940,9 @@ loadGeneralFile(char *path, ParsedURL *volatile current, char *referer, } if (header_string) header_string = NULL; - if (fmInitialized) { + if (fmInitialized) term_raw(); - signal(SIGINT, prevtrap); - } + signal(SIGINT, prevtrap); return b; } @@ -2712,12 +2751,16 @@ restore_fonteffect(struct html_feed_environ *h_env, struct readbuffer *obuf) push_tag(obuf, "<u>", HTML_U); } - Str -process_img(struct parsed_tag *tag) +process_img(struct parsed_tag *tag, int width) { char *p, *q, *r, *r2, *s; - int w, i; +#ifdef USE_IMAGE + int w, i, nw, ni, n, w0, i0, align, xoffset, yoffset, top, bottom, ismap; + int use_image = activeImage && displayImage; +#else + int w, i, nw, n; +#endif Str tmp = Strnew(); if (!parsedtag_get_value(tag, ATTR_SRC, &p)) @@ -2725,69 +2768,231 @@ process_img(struct parsed_tag *tag) q = NULL; parsedtag_get_value(tag, ATTR_ALT, &q); w = -1; - parsedtag_get_value(tag, ATTR_WIDTH, &w); - i = -1; - parsedtag_get_value(tag, ATTR_HEIGHT, &i); + if (parsedtag_get_value(tag, ATTR_WIDTH, &w)) { + if (w < 0) { + if (width > 0) + w = (int)(-width * pixel_per_char * w / 100 + 0.5); + else + w = -1; + } +#ifdef USE_IMAGE + if (use_image) { + if (w > 0) { + w = (int)(w * image_scale / 100 + 0.5); + if (w == 0) + w = 1; + } + } +#endif + } +#ifdef USE_IMAGE + if (use_image) { + i = -1; + if (parsedtag_get_value(tag, ATTR_HEIGHT, &i)) { + if (i > 0) { + i = (int)(i * image_scale / 100 + 0.5); + if (i == 0) + i = 1; + } + else { + i = -1; + } + } + align = -1; + parsedtag_get_value(tag, ATTR_ALIGN, &align); + ismap = 0; + if (parsedtag_exists(tag, ATTR_ISMAP)) + ismap = 1; + } + else +#endif + parsedtag_get_value(tag, ATTR_HEIGHT, &i); r = NULL; parsedtag_get_value(tag, ATTR_USEMAP, &r); tmp = Strnew_size(128); +#ifdef USE_IMAGE + if (use_image) { + switch (align) { + case ALIGN_LEFT: + Strcat_charp(tmp, "<div align=left>"); + break; + case ALIGN_CENTER: + Strcat_charp(tmp, "<div align=center>"); + break; + case ALIGN_RIGHT: + Strcat_charp(tmp, "<div align=right>"); + break; + } + } +#endif if (r) { r2 = strchr(r, '#'); s = "<form_int method=internal action=map>"; process_form(parse_tag(&s, TRUE)); - Strcat(tmp, Sprintf("<pre_int><input_alt fid=\"%d\" " + Strcat(tmp, Sprintf("<input_alt fid=\"%d\" " "type=hidden name=link value=\"", cur_form_id)); Strcat_charp(tmp, html_quote((r2) ? r2 + 1 : r)); Strcat(tmp, Sprintf("\"><input_alt hseq=\"%d\" fid=\"%d\" " "type=submit no_effect=true>", cur_hseq++, cur_form_id)); } - if (q != NULL && *q == '\0' && ignore_null_img_alt) - q = NULL; - if (q != NULL || r != NULL) - Strcat_charp(tmp, "<img_alt src=\""); +#ifdef USE_IMAGE + if (use_image) { + w0 = w; + i0 = i; + if (w < 0 || i < 0) { + char *url, *ext; + Image image; + ParsedURL u; + +#ifdef JP_CHARSET + parseURL2(conv(p, InnerCode, cur_document_code)->ptr, &u, + cur_baseURL); +#else + parseURL2(p, &u, cur_baseURL); +#endif + image.url = parsedURL2Str(&u)->ptr; + image.ext = filename_extension(u.file, TRUE); + image.cache = NULL; + image.width = w; + image.height = i; + + image.cache = getImage(&image, cur_baseURL, IMG_FLAG_SKIP); + if (image.cache && image.cache->width > 0 && + image.cache->height > 0) { + w = w0 = image.cache->width; + i = i0 = image.cache->height; + } + if (w < 0) + w = 8 * pixel_per_char; + if (i < 0) + i = pixel_per_line; + } + nw = (w > 3) ? (int)((w - 3) / pixel_per_char + 1) : 1; + ni = (i > 3) ? (int)((i - 3) / pixel_per_line + 1) : 1; + Strcat(tmp, + Sprintf("<pre_int><img_alt hseq=\"%d\" src=\"", cur_iseq++)); + } else - Strcat_charp(tmp, "<nobr><img_alt src=\""); +#endif + { + if (w < 0) + w = 12 * pixel_per_char; + nw = w ? (int)((w - 1) / pixel_per_char + 1) : 1; + if (r) + Strcat_charp(tmp, "<pre_int>"); + Strcat_charp(tmp, "<img_alt src=\""); + } Strcat_charp(tmp, html_quote(p)); - Strcat_charp(tmp, "\">"); + Strcat_charp(tmp, "\""); +#ifdef USE_IMAGE + if (use_image) { + if (w0 >= 0) + Strcat(tmp, Sprintf(" width=%d", w0)); + if (i0 >= 0) + Strcat(tmp, Sprintf(" height=%d", i0)); + switch (align) { + case ALIGN_TOP: + top = 0; + bottom = ni - 1; + yoffset = 0; + break; + case ALIGN_MIDDLE: + top = ni / 2; + bottom = top; + if (top * 2 == ni) + yoffset = (int)(((ni + 1) * pixel_per_line - i) / 2); + else + yoffset = (int)((ni * pixel_per_line - i) / 2); + break; + case ALIGN_BOTTOM: + top = ni - 1; + bottom = 0; + yoffset = (int)(ni * pixel_per_line - i); + break; + default: + top = ni - 1; + bottom = 0; + if (ni == 1 && ni * pixel_per_line > i) + yoffset = 0; + else { + yoffset = (int)(ni * pixel_per_line - i); + if (yoffset <= -2) + yoffset++; + } + break; + } + xoffset = (int)((nw * pixel_per_char - w) / 2); + if (xoffset) + Strcat(tmp, Sprintf(" xoffset=%d", xoffset)); + if (yoffset) + Strcat(tmp, Sprintf(" yoffset=%d", yoffset)); + if (top) + Strcat(tmp, Sprintf(" top_margin=%d", top)); + if (bottom) + Strcat(tmp, Sprintf(" bottom_margin=%d", bottom)); + if (r) { + Strcat_charp(tmp, " usemap=\""); + Strcat_charp(tmp, html_quote((r2) ? r2 + 1 : r)); + Strcat_charp(tmp, "\""); + } + if (ismap) + Strcat_charp(tmp, " ismap"); + } +#endif + Strcat_charp(tmp, ">"); + if (q != NULL && *q == '\0' && ignore_null_img_alt) + q = NULL; if (q != NULL) { - Strcat_charp(tmp, html_quote(q)); - Strcat_charp(tmp, "</img_alt> "); - goto img_end2; + n = strlen(q); +#ifdef USE_IMAGE + if (use_image) { + if (n > nw) { + n = nw; + Strcat_charp(tmp, html_quote(Strnew_charp_n(q, nw)->ptr)); + } + else + Strcat_charp(tmp, q); + } + else +#endif + Strcat_charp(tmp, q); + goto img_end; } if (w > 0 && i > 0) { /* guess what the image is! */ if (w < 32 && i < 48) { /* must be an icon or space */ + n = 1; if (strcasestr(p, "space") || strcasestr(p, "blank")) - Strcat_charp(tmp, "_</img_alt>"); + Strcat_charp(tmp, "_"); else { if (w * i < 8 * 16) - Strcat_charp(tmp, "*</img_alt>"); + Strcat_charp(tmp, "*"); else { #ifdef KANJI_SYMBOLS - Strcat_charp(tmp, "¡ü</img_alt>"); + Strcat_charp(tmp, "¡ü"); + n = 2; #else /* not KANJI_SYMBOLS */ - Strcat_charp(tmp, "#</img_alt>"); + Strcat_charp(tmp, "#"); #endif /* not KANJI_SYMBOLS */ } } - goto img_end1; + goto img_end; } if (w > 200 && i < 13) { /* must be a horizontal line */ #ifndef KANJI_SYMBOLS Strcat_charp(tmp, "<_RULE TYPE=10>"); #endif /* not KANJI_SYMBOLS */ - w /= pixel_per_char; - for (i = 0; i < w - (HR_RULE_WIDTH - 1); i += HR_RULE_WIDTH) + for (i = 0; i < nw - (HR_RULE_WIDTH - 1); i += HR_RULE_WIDTH) Strcat_charp(tmp, HR_RULE); #ifndef KANJI_SYMBOLS Strcat_charp(tmp, "</_RULE>"); #endif /* not KANJI_SYMBOLS */ - Strcat_charp(tmp, "</img_alt>"); - goto img_end1; + n = i; + goto img_end; } } for (q = p; *q; q++) ; @@ -2796,27 +3001,50 @@ process_img(struct parsed_tag *tag) if (*q == '/') q++; Strcat_char(tmp, '['); + n = 1; p = q; for (; *q; q++) { if (!IS_ALNUM(*q) && *q != '_' && *q != '-') { break; } - else if (w > 0 && !IS_ALNUM(*q) - && q - p + 2 > (int)(w / pixel_per_char)) { - Strcat_charp(tmp, ".."); - break; - } Strcat_char(tmp, *q); + n++; + if (n + 1 >= nw) + break; + } + Strcat_char(tmp, ']'); + n++; + img_end: +#ifdef USE_IMAGE + if (use_image) { + for (; n < nw; n++) + Strcat_char(tmp, ' '); } - Strcat_charp(tmp, "]</img_alt>"); - img_end1: - if (r == NULL) - Strcat_charp(tmp, "</nobr>"); - img_end2: +#endif + Strcat_charp(tmp, "</img_alt>"); +#ifdef USE_IMAGE + if (use_image) { + Strcat_charp(tmp, "</pre_int>"); + } + else +#endif + if (r) + Strcat_charp(tmp, "</pre_int>"); if (r) { - Strcat_charp(tmp, "</input_alt></pre_int>"); + Strcat_charp(tmp, "</input_alt>"); process_n_form(); } +#ifdef USE_IMAGE + if (use_image) { + switch (align) { + case ALIGN_RIGHT: + case ALIGN_CENTER: + case ALIGN_LEFT: + Strcat_charp(tmp, "</div>"); + break; + } + } +#endif return tmp; } @@ -2838,8 +3066,7 @@ Str process_input(struct parsed_tag *tag) { int i, w, v, x, y, z, iw, ih; - char *q, *p, *r, *p2; - char *pi = NULL; + char *q, *p, *r, *p2, *s; Str tmp; char *qq = ""; int qlen = 0; @@ -2928,6 +3155,20 @@ process_input(struct parsed_tag *tag) Strcat_charp(tmp, "<u>"); break; case FORM_INPUT_IMAGE: + s = NULL; + parsedtag_get_value(tag, ATTR_SRC, &s); + if (s) { + Strcat(tmp, Sprintf("<img src=\"%s\"", html_quote(s))); + if (p2) + Strcat(tmp, Sprintf(" alt=\"%s\"", html_quote(p2))); + if (parsedtag_get_value(tag, ATTR_WIDTH, &iw)) + Strcat(tmp, Sprintf(" width=\"%d\"", iw)); + if (parsedtag_get_value(tag, ATTR_HEIGHT, &ih)) + Strcat(tmp, Sprintf(" height=\"%d\"", ih)); + Strcat_charp(tmp, ">"); + Strcat_charp(tmp, "</input_alt></pre_int>"); + return tmp; + } case FORM_INPUT_SUBMIT: case FORM_INPUT_BUTTON: case FORM_INPUT_RESET: @@ -2953,23 +3194,6 @@ process_input(struct parsed_tag *tag) Strcat_char(tmp, ' '); } break; - case FORM_INPUT_IMAGE: - parsedtag_get_value(tag, ATTR_SRC, &pi); - if (pi) { - Strcat(tmp, Sprintf("<img_alt src=\"%s\"", html_quote(pi))); - if (parsedtag_get_value(tag, ATTR_WIDTH, &iw)) - Strcat(tmp, Sprintf(" width=\"%d\"", iw)); - if (parsedtag_get_value(tag, ATTR_HEIGHT, &ih)) - Strcat(tmp, Sprintf(" height=\"%d\"", ih)); - Strcat_charp(tmp, ">"); - if (p2) - Strcat_charp(tmp, html_quote(p2)); - else - Strcat_charp(tmp, qq); - Strcat_charp(tmp, "</img_alt>"); - break; - } - /* FALL THROUGH */ case FORM_INPUT_SUBMIT: case FORM_INPUT_BUTTON: if (p2) @@ -3966,12 +4190,24 @@ HTMLtagproc1(struct parsed_tag *tag, struct html_feed_environ *h_env) close_anchor(h_env, obuf); return 1; case HTML_IMG: - tmp = process_img(tag); + tmp = process_img(tag, h_env->limit); HTMLlineproc1(tmp->ptr, h_env); return 1; case HTML_IMG_ALT: if (parsedtag_get_value(tag, ATTR_SRC, &p)) obuf->img_alt = Strnew_charp(p); +#ifdef USE_IMAGE + i = 0; + if (parsedtag_get_value(tag, ATTR_TOP_MARGIN, &i)) { + if (i > obuf->top_margin) + obuf->top_margin = i; + } + i = 0; + if (parsedtag_get_value(tag, ATTR_BOTTOM_MARGIN, &i)) { + if (i > obuf->bottom_margin) + obuf->bottom_margin = i; + } +#endif return 0; case HTML_N_IMG_ALT: if (obuf->img_alt) { @@ -4203,6 +4439,14 @@ HTMLtagproc1(struct parsed_tag *tag, struct html_feed_environ *h_env) } return 1; case HTML_BASE: +#ifdef USE_IMAGE + p = NULL; + if (parsedtag_get_value(tag, ATTR_HREF, &p)) { + if (!cur_baseURL) + cur_baseURL = New(ParsedURL); + parseURL(p, cur_baseURL, NULL); + } +#endif case HTML_MAP: case HTML_N_MAP: case HTML_AREA: @@ -4294,7 +4538,7 @@ HTMLlineproc2body(Buffer *buf, Str (*feed) (), int llimit) { Anchor *a_href = NULL, *a_img = NULL, *a_form = NULL; char outc[LINELEN]; - char *p, *q, *r, *str; + char *p, *q, *r, *s, *str; Lineprop outp[LINELEN], mode, effect; int pos; int nlines; @@ -4450,9 +4694,67 @@ HTMLlineproc2body(Buffer *buf, Str (*feed) (), int llimit) break; case HTML_IMG_ALT: if (parsedtag_get_value(tag, ATTR_SRC, &p)) { +#ifdef USE_IMAGE + int w = -1, h = -1, iseq = 0, ismap = 0; + int xoffset = 0, yoffset = 0, top = 0, bottom = 0; + parsedtag_get_value(tag, ATTR_HSEQ, &iseq); + parsedtag_get_value(tag, ATTR_WIDTH, &w); + parsedtag_get_value(tag, ATTR_HEIGHT, &h); + parsedtag_get_value(tag, ATTR_XOFFSET, &xoffset); + parsedtag_get_value(tag, ATTR_YOFFSET, &yoffset); + parsedtag_get_value(tag, ATTR_TOP_MARGIN, &top); + parsedtag_get_value(tag, ATTR_BOTTOM_MARGIN, &bottom); + if (parsedtag_exists(tag, ATTR_ISMAP)) + ismap = 1; + q = NULL; + parsedtag_get_value(tag, ATTR_USEMAP, &q); + if (iseq > 0) { + buf->imarklist = putHmarker(buf->imarklist, + currentLn(buf), pos, + iseq - 1); + } +#endif p = remove_space(p); p = url_quote_conv(p, buf->document_code); a_img = registerImg(buf, p, currentLn(buf), pos); +#ifdef USE_IMAGE + a_img->hseq = iseq; + a_img->image = NULL; + if (iseq > 0) { + ParsedURL u; + Image *image; + + parseURL2(a_img->url, &u, cur_baseURL); + a_img->image = image = New(Image); + image->url = parsedURL2Str(&u)->ptr; + image->ext = filename_extension(u.file, TRUE); + image->cache = NULL; + image->width = w; + image->height = h; + image->xoffset = xoffset; + image->yoffset = yoffset; + image->y = currentLn(buf) - top; + if (image->xoffset < 0 && pos == 0) + image->xoffset = 0; + if (image->yoffset < 0 && image->y == 1) + image->yoffset = 0; + image->rows = 1 + top + bottom; + image->map = q; + image->ismap = ismap; + image->touch = 0; + image->cache = getImage(image, cur_baseURL, + IMG_FLAG_SKIP); + } + else if (iseq < 0) { + BufferPoint *po = buf->imarklist->marks - iseq - 1; + Anchor *a = retrieveAnchor(buf->img, + po->line, po->pos); + if (a) { + a_img->url = a->url; + a_img->image = a->image; + } + } +#endif } effect |= PE_IMAGE; break; @@ -4514,9 +4816,8 @@ HTMLlineproc2body(Buffer *buf, Str (*feed) (), int llimit) if (parsedtag_get_value(tag, ATTR_NAME, &p)) { MapList *m = New(MapList); m->name = Strnew_charp(p); + m->area = newGeneralList(); m->next = buf->maplist; - m->urls = newTextList(); - m->alts = newTextList(); buf->maplist = m; } break; @@ -4527,13 +4828,19 @@ HTMLlineproc2body(Buffer *buf, Str (*feed) (), int llimit) if (buf->maplist == NULL) /* outside of <map>..</map> */ break; if (parsedtag_get_value(tag, ATTR_HREF, &p)) { + MapArea *a; p = remove_space(p); p = url_quote_conv(p, buf->document_code); - pushText(buf->maplist->urls, p); - if (parsedtag_get_value(tag, ATTR_ALT, &q)) - pushText(buf->maplist->alts, q); - else - pushText(buf->maplist->alts, ""); + q = ""; + parsedtag_get_value(tag, ATTR_ALT, &q); + r = NULL; + s = NULL; +#ifdef USE_IMAGE + parsedtag_get_value(tag, ATTR_SHAPE, &r); + parsedtag_get_value(tag, ATTR_COORDS, &s); +#endif + a = newMapArea(p, q, r, s); + pushValue(buf->maplist->area, (void *)a); } break; case HTML_FRAMESET: @@ -4634,6 +4941,9 @@ HTMLlineproc2body(Buffer *buf, Str (*feed) (), int llimit) fclose(debug); if (n_textarea) addMultirowsForm(buf, buf->formitem); +#ifdef USE_IMAGE + addMultirowsImg(buf, buf->img); +#endif } void @@ -5415,6 +5725,9 @@ loadHTMLstream(URLFile *f, Buffer *newBuf, FILE * src, int internal) char code; struct html_feed_environ htmlenv1; struct readbuffer obuf; +#ifdef USE_IMAGE + int image_flag; +#endif MySignalHandler(*volatile prevtrap) (SIGNAL_ARG) = NULL; n_textarea = 0; @@ -5432,6 +5745,17 @@ loadHTMLstream(URLFile *f, Buffer *newBuf, FILE * src, int internal) forms_size = 0; forms = NULL; cur_hseq = 1; +#ifdef USE_IMAGE + cur_iseq = 1; + if (newBuf->image_flag) + image_flag = newBuf->image_flag; + else if (activeImage && displayImage && autoImage) + image_flag = IMG_FLAG_AUTO; + else + image_flag = IMG_FLAG_SKIP; + if (newBuf->currentURL.file) + cur_baseURL = baseURL(newBuf); +#endif if (w3m_halfload) { newBuf->buffername = "---"; @@ -5440,10 +5764,9 @@ loadHTMLstream(URLFile *f, Buffer *newBuf, FILE * src, int internal) #endif /* JP_CHARSET */ HTMLlineproc3(newBuf, f->stream); w3m_halfload = FALSE; - if (fmInitialized) { + if (fmInitialized) term_raw(); - signal(SIGINT, prevtrap); - } + signal(SIGINT, prevtrap); return; } @@ -5458,10 +5781,9 @@ loadHTMLstream(URLFile *f, Buffer *newBuf, FILE * src, int internal) HTMLlineproc1("<br>Transfer Interrupted!<br>", &htmlenv1); goto phase2; } - if (fmInitialized) { - prevtrap = signal(SIGINT, KeyAbort); + prevtrap = signal(SIGINT, KeyAbort); + if (fmInitialized) term_cbreak(); - } #ifdef JP_CHARSET if (newBuf != NULL && newBuf->document_code != '\0') @@ -5482,16 +5804,32 @@ loadHTMLstream(URLFile *f, Buffer *newBuf, FILE * src, int internal) if (src) Strfputs(lineBuf2, src); linelen += lineBuf2->length; + if (w3m_dump & DUMP_SOURCE) + continue; showProgress(&linelen, &trbyte); + /* + * if (frame_source) + * continue; + */ #ifdef JP_CHARSET if (meta_charset != '\0') { /* <META> */ - if (content_charset == '\0' && UseContentCharset) + if (content_charset == '\0' && UseContentCharset) { code = meta_charset; +#ifdef USE_IMAGE + cur_document_code = code; +#endif + } meta_charset = '\0'; } #endif - if (!internal) + if (!internal) { lineBuf2 = convertLine(f, lineBuf2, &code, HTML_MODE); +#ifdef JP_CHARSET +#ifdef USE_IMAGE + cur_document_code = code; +#endif +#endif + } #ifdef USE_NNTP if (f->scheme == SCM_NEWS) { if (Str_news_endline(lineBuf2)) { @@ -5510,22 +5848,23 @@ loadHTMLstream(URLFile *f, Buffer *newBuf, FILE * src, int internal) if (htmlenv1.title) newBuf->buffername = htmlenv1.title; if (w3m_halfdump) { - if (fmInitialized) { + if (fmInitialized) term_raw(); - signal(SIGINT, prevtrap); - } + signal(SIGINT, prevtrap); return; } phase2: newBuf->trbyte = trbyte + linelen; - if (fmInitialized) { + if (fmInitialized) term_raw(); - signal(SIGINT, prevtrap); - } + signal(SIGINT, prevtrap); #ifdef JP_CHARSET newBuf->document_code = code; content_charset = '\0'; #endif /* JP_CHARSET */ +#ifdef USE_IMAGE + newBuf->image_flag = image_flag; +#endif if (w3m_backend) backend_halfdump_buf = htmlenv1.buf; HTMLlineproc2(newBuf, htmlenv1.buf); @@ -5545,15 +5884,18 @@ loadHTMLString(Str page) newBuf = newBuffer(INIT_BUFFER_WIDTH); if (SETJMP(AbortLoading) != 0) { + if (fmInitialized) + term_raw(); + signal(SIGINT, prevtrap); discardBuffer(newBuf); return NULL; } + prevtrap = signal(SIGINT, KeyAbort); + if (fmInitialized) + term_cbreak(); + init_stream(&f, SCM_LOCAL, newStrStream(page)); - if (fmInitialized) { - prevtrap = signal(SIGINT, KeyAbort); - term_cbreak(); - } if (w3m_dump & DUMP_FRAME) { tmp = tmpfname(TMPF_SRC, ".html"); pushText(fileToDelete, tmp->ptr); @@ -5564,10 +5906,9 @@ loadHTMLString(Str page) loadHTMLstream(&f, newBuf, src, TRUE); - if (fmInitialized) { + if (fmInitialized) term_raw(); - signal(SIGINT, prevtrap); - } + signal(SIGINT, prevtrap); newBuf->topLine = newBuf->firstLine; newBuf->lastLine = newBuf->currentLine; newBuf->currentLine = newBuf->firstLine; @@ -5611,6 +5952,9 @@ loadGopherDir(URLFile *uf, Buffer *newBuf) code = content_charset; else code = DocumentCode; +#ifdef USE_IMAGE + cur_document_code = code; +#endif content_charset = '\0'; #endif while (1) { @@ -5714,10 +6058,9 @@ loadBuffer(URLFile *uf, Buffer *volatile newBuf) if (SETJMP(AbortLoading) != 0) { goto _end; } - if (fmInitialized) { - prevtrap = signal(SIGINT, KeyAbort); + prevtrap = signal(SIGINT, KeyAbort); + if (fmInitialized) term_cbreak(); - } if (newBuf->sourcefile == NULL && (uf->scheme != SCM_LOCAL || newBuf->mailcap)) { @@ -5743,7 +6086,11 @@ loadBuffer(URLFile *uf, Buffer *volatile newBuf) if (src) Strfputs(lineBuf2, src); linelen += lineBuf2->length; + if (w3m_dump & DUMP_SOURCE) + continue; showProgress(&linelen, &trbyte); + if (frame_source) + continue; lineBuf2 = convertLine(uf, lineBuf2, &code, PAGER_MODE); if (squeezeBlankLine) { if (lineBuf2->ptr[0] == '\n' && pre_lbuf == '\n') { @@ -5774,10 +6121,9 @@ loadBuffer(URLFile *uf, Buffer *volatile newBuf) lineBuf2->length, nlines); } _end: - if (fmInitialized) { - signal(SIGINT, prevtrap); + if (fmInitialized) term_raw(); - } + signal(SIGINT, prevtrap); newBuf->topLine = newBuf->firstLine; newBuf->lastLine = newBuf->currentLine; newBuf->currentLine = newBuf->firstLine; @@ -5791,6 +6137,67 @@ loadBuffer(URLFile *uf, Buffer *volatile newBuf) return newBuf; } +#ifdef USE_IMAGE +Buffer * +loadImageBuffer(URLFile *uf, Buffer *newBuf) +{ + Image *image; + ImageCache *cache; + Str tmp, tmpf; + FILE *src = NULL; + URLFile f; + MySignalHandler(*prevtrap) (); + + loadImage(IMG_FLAG_STOP); + image = New(Image); + image->url = parsedURL2Str(cur_baseURL)->ptr; + image->ext = filename_extension(cur_baseURL->file, 1); + image->width = -1; + image->height = -1; + cache = getImage(image, cur_baseURL, IMG_FLAG_AUTO); + if (!cur_baseURL->is_nocache && cache->loaded == IMG_FLAG_LOADED) + goto image_buffer; + + prevtrap = signal(SIGINT, KeyAbort); + if (fmInitialized) + term_cbreak(); + if (IStype(uf->stream) != IST_ENCODED) + uf->stream = newEncodedStream(uf->stream, uf->encoding); + if (save2tmp(*uf, cache->file) < 0) { + if (fmInitialized) + term_raw(); + signal(SIGINT, prevtrap); + return NULL; + } + if (fmInitialized) + term_raw(); + signal(SIGINT, prevtrap); + + cache->loaded = IMG_FLAG_LOADED; + getImageSize(cache); + + image_buffer: + tmp = Sprintf("<img src=\"%s\"><br><br>", html_quote(image->url)); + if (newBuf == NULL) + newBuf = newBuffer(INIT_BUFFER_WIDTH); + if (frame_source) { + tmpf = tmpfname(TMPF_SRC, ".html"); + src = fopen(tmpf->ptr, "w"); + newBuf->sourcefile = tmpf->ptr; + pushText(fileToDelete, tmpf->ptr); + } + init_stream(&f, SCM_LOCAL, newStrStream(tmp)); + loadHTMLstream(&f, newBuf, src, TRUE); + if (src) + fclose(src); + + newBuf->topLine = newBuf->firstLine; + newBuf->lastLine = newBuf->currentLine; + newBuf->currentLine = newBuf->firstLine; + return newBuf; +} +#endif + /* * saveBuffer: write buffer to file */ @@ -6165,10 +6572,9 @@ save2tmp(URLFile uf, char *tmpf) if (SETJMP(AbortLoading) != 0) { goto _end; } - if (fmInitialized) { - prevtrap = signal(SIGINT, KeyAbort); + prevtrap = signal(SIGINT, KeyAbort); + if (fmInitialized) term_cbreak(); - } check = 0; current_content_length = 0; #ifdef USE_NNTP @@ -6204,10 +6610,9 @@ save2tmp(URLFile uf, char *tmpf) } _end: bcopy(env_bak, AbortLoading, sizeof(JMP_BUF)); - if (fmInitialized) { + if (fmInitialized) term_raw(); - signal(SIGINT, prevtrap); - } + signal(SIGINT, prevtrap); fclose(ff); if (uf.scheme == SCM_FTP) FTPhalfclose(uf.stream); |