* 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>
417 lines
10 KiB
C
417 lines
10 KiB
C
/* $Id: map.c,v 1.5 2002/01/31 17:54:52 ukai Exp $ */
|
|
/*
|
|
* client-side image maps
|
|
*/
|
|
#include "fm.h"
|
|
#include <math.h>
|
|
|
|
#ifdef MENU_MAP
|
|
#ifdef USE_IMAGE
|
|
static int
|
|
inMapArea(MapArea * a, int x, int y)
|
|
{
|
|
int i;
|
|
double r1, r2, s, c, t;
|
|
|
|
if (!a)
|
|
return FALSE;
|
|
switch (a->shape) {
|
|
case SHAPE_RECT:
|
|
if (x >= a->coords[0] && y >= a->coords[1] &&
|
|
x <= a->coords[2] && y <= a->coords[3])
|
|
return TRUE;
|
|
break;
|
|
case SHAPE_CIRCLE:
|
|
if ((x - a->coords[0]) * (x - a->coords[0])
|
|
+ (y - a->coords[1]) * (y - a->coords[1])
|
|
<= a->coords[2] * a->coords[2])
|
|
return TRUE;
|
|
break;
|
|
case SHAPE_POLY:
|
|
for (t = 0, i = 0; i < a->ncoords; i += 2) {
|
|
r1 = sqrt((double)(x - a->coords[i]) * (x - a->coords[i])
|
|
+ (double)(y - a->coords[i + 1]) * (y -
|
|
a->coords[i + 1]));
|
|
r2 = sqrt((double)(x - a->coords[i + 2]) * (x - a->coords[i + 2])
|
|
+ (double)(y - a->coords[i + 3]) * (y -
|
|
a->coords[i + 3]));
|
|
if (r1 == 0 || r2 == 0)
|
|
return TRUE;
|
|
s = ((double)(x - a->coords[i]) * (y - a->coords[i + 3])
|
|
- (double)(x - a->coords[i + 2]) * (y -
|
|
a->coords[i +
|
|
1])) / r1 / r2;
|
|
c = ((double)(x - a->coords[i]) * (x - a->coords[i + 2])
|
|
+ (double)(y - a->coords[i + 1]) * (y -
|
|
a->coords[i +
|
|
3])) / r1 / r2;
|
|
t += atan2(s, c);
|
|
}
|
|
if (fabs(t) > 2 * 3.14)
|
|
return TRUE;
|
|
break;
|
|
case SHAPE_DEFAULT:
|
|
return TRUE;
|
|
default:
|
|
break;
|
|
}
|
|
return FALSE;
|
|
}
|
|
#endif
|
|
|
|
char *
|
|
follow_map_menu(Buffer *buf, struct parsed_tagarg *arg, Anchor *a_img, int x,
|
|
int y)
|
|
{
|
|
MapList *ml;
|
|
ListItem *al;
|
|
MapArea *a;
|
|
char *name;
|
|
int i, n, selected = -1, initial;
|
|
char **label;
|
|
int px, py, map = 0;
|
|
|
|
name = tag_get_value(arg, "link");
|
|
if (name == NULL)
|
|
return NULL;
|
|
|
|
for (ml = buf->maplist; ml != NULL; ml = ml->next) {
|
|
if (!Strcmp_charp(ml->name, name))
|
|
break;
|
|
}
|
|
if (ml == NULL || ml->area == NULL)
|
|
return NULL;
|
|
|
|
n = ml->area->nitem;
|
|
if (n == 0)
|
|
return NULL;
|
|
label = New_N(char *, n + 1);
|
|
#ifdef USE_IMAGE
|
|
if (getMapXY(buf, a_img, &px, &py))
|
|
map = 1;
|
|
#endif
|
|
initial = -n;
|
|
for (i = 0, al = ml->area->first; al != NULL; i++, al = al->next) {
|
|
a = (MapArea *) al->ptr;
|
|
if (a) {
|
|
label[i] = *a->alt ? a->alt : a->url;
|
|
#ifdef USE_IMAGE
|
|
if (initial < 0 && map && inMapArea(a, px, py)) {
|
|
if (a->shape == SHAPE_DEFAULT) {
|
|
if (initial == -n)
|
|
initial = -i;
|
|
}
|
|
else
|
|
initial = i;
|
|
}
|
|
#endif
|
|
}
|
|
else
|
|
label[i] = "";
|
|
}
|
|
label[n] = NULL;
|
|
if (initial == -n)
|
|
initial = 0;
|
|
else if (initial < 0)
|
|
initial *= -1;
|
|
|
|
optionMenu(x, y, label, &selected, initial, NULL);
|
|
|
|
if (selected >= 0) {
|
|
for (i = 0, al = ml->area->first; al != NULL; i++, al = al->next) {
|
|
if (al->ptr && i == selected)
|
|
return ((MapArea *) al->ptr)->url;
|
|
}
|
|
}
|
|
return NULL;
|
|
}
|
|
|
|
#else
|
|
char *map1 = "<HTML><HEAD><TITLE>Image map links</TITLE></HEAD>\
|
|
<BODY><H1>Image map links</H1>";
|
|
|
|
Buffer *
|
|
follow_map_panel(Buffer *buf, struct parsed_tagarg *arg)
|
|
{
|
|
Str mappage;
|
|
MapList *ml;
|
|
ListItem *al;
|
|
MapArea *a;
|
|
char *name;
|
|
ParsedURL pu;
|
|
|
|
name = tag_get_value(arg, "link");
|
|
if (name == NULL)
|
|
return NULL;
|
|
|
|
for (ml = buf->maplist; ml != NULL; ml = ml->next) {
|
|
if (!Strcmp_charp(ml->name, name))
|
|
break;
|
|
}
|
|
if (ml == NULL)
|
|
return NULL;
|
|
|
|
mappage = Strnew_charp(map1);
|
|
for (al = ml->area->first; al != NULL; al = al->next) {
|
|
a = (MapArea *) al->ptr;
|
|
if (!a)
|
|
continue;
|
|
parseURL2(a->url, &pu, baseURL(buf));
|
|
Strcat_charp(mappage, "<a href=\"");
|
|
Strcat_charp(mappage, html_quote(parsedURL2Str(&pu)->ptr));
|
|
Strcat_charp(mappage, "\">");
|
|
Strcat_charp(mappage, html_quote(a->alt));
|
|
Strcat_charp(mappage, " ");
|
|
Strcat_charp(mappage, html_quote(a->url));
|
|
Strcat_charp(mappage, "</a><br>\n");
|
|
}
|
|
Strcat_charp(mappage, "</body></html>");
|
|
|
|
return loadHTMLString(mappage);
|
|
}
|
|
#endif
|
|
|
|
#ifdef USE_IMAGE
|
|
int
|
|
getMapXY(Buffer *buf, Anchor *a, int *x, int *y)
|
|
{
|
|
if (!buf || !a || !a->image || !x || !y)
|
|
return 0;
|
|
*x = (int)((buf->currentColumn + buf->cursorX
|
|
- COLPOS(buf->currentLine, a->start.pos) + 0.5)
|
|
* pixel_per_char) - a->image->xoffset;
|
|
*y = (int)((buf->currentLine->linenumber - a->image->y + 0.5)
|
|
* pixel_per_line) - a->image->yoffset;
|
|
if (*x <= 0)
|
|
*x = 1;
|
|
if (*y <= 0)
|
|
*y = 1;
|
|
return 1;
|
|
}
|
|
#endif
|
|
|
|
MapArea *
|
|
newMapArea(char *url, char *alt, char *shape, char *coords)
|
|
{
|
|
MapArea *a = New(MapArea);
|
|
#ifdef MENU_MAP
|
|
char *p;
|
|
int i, max;
|
|
#endif
|
|
|
|
a->url = url;
|
|
a->alt = alt ? alt : "";
|
|
#ifdef MENU_MAP
|
|
#ifdef USE_IMAGE
|
|
a->shape = SHAPE_RECT;
|
|
if (shape) {
|
|
if (!strcasecmp(shape, "default"))
|
|
a->shape = SHAPE_DEFAULT;
|
|
else if (!strncasecmp(shape, "rect", 4))
|
|
a->shape = SHAPE_RECT;
|
|
else if (!strncasecmp(shape, "circ", 4))
|
|
a->shape = SHAPE_CIRCLE;
|
|
else if (!strncasecmp(shape, "poly", 4))
|
|
a->shape = SHAPE_POLY;
|
|
else
|
|
a->shape = SHAPE_UNKNOWN;
|
|
}
|
|
a->coords = NULL;
|
|
a->ncoords = 0;
|
|
if (a->shape == SHAPE_UNKNOWN || a->shape == SHAPE_DEFAULT)
|
|
return a;
|
|
if (!coords) {
|
|
a->shape = SHAPE_UNKNOWN;
|
|
return a;
|
|
}
|
|
if (a->shape == SHAPE_RECT) {
|
|
a->coords = New_N(short, 4);
|
|
a->ncoords = 4;
|
|
}
|
|
else if (a->shape == SHAPE_CIRCLE) {
|
|
a->coords = New_N(short, 3);
|
|
a->ncoords = 3;
|
|
}
|
|
max = a->ncoords;
|
|
for (i = 0, p = coords; (a->shape == SHAPE_POLY || i < a->ncoords) && *p;) {
|
|
while (IS_SPACE(*p))
|
|
p++;
|
|
if (!IS_DIGIT(*p))
|
|
break;
|
|
if (a->shape == SHAPE_POLY) {
|
|
if (max <= i) {
|
|
max = i ? i * 2 : 6;
|
|
a->coords = New_Reuse(short, a->coords, max + 2);
|
|
}
|
|
a->ncoords++;
|
|
}
|
|
a->coords[i] = (short)atoi(p);
|
|
i++;
|
|
while (IS_DIGIT(*p))
|
|
p++;
|
|
if (*p != ',' && !IS_SPACE(*p))
|
|
break;
|
|
while (IS_SPACE(*p))
|
|
p++;
|
|
if (*p == ',')
|
|
p++;
|
|
}
|
|
if (i != a->ncoords || (a->shape == SHAPE_POLY && a->ncoords < 6)) {
|
|
a->shape = SHAPE_UNKNOWN;
|
|
a->coords = NULL;
|
|
a->ncoords = 0;
|
|
}
|
|
if (a->shape == SHAPE_POLY) {
|
|
a->ncoords = a->ncoords / 2 * 2;
|
|
a->coords[a->ncoords] = a->coords[0];
|
|
a->coords[a->ncoords + 1] = a->coords[1];
|
|
}
|
|
#endif
|
|
#endif
|
|
return a;
|
|
}
|
|
|
|
/* append frame URL */
|
|
static void
|
|
append_frame_info(Buffer *buf, Str html, struct frameset *set, int level)
|
|
{
|
|
char *p, *q;
|
|
int i, j;
|
|
|
|
if (!set)
|
|
return;
|
|
|
|
for (i = 0; i < set->col * set->row; i++) {
|
|
union frameset_element frame = set->frame[i];
|
|
if (frame.element != NULL) {
|
|
switch (frame.element->attr) {
|
|
case F_UNLOADED:
|
|
case F_BODY:
|
|
if (frame.body->url == NULL)
|
|
break;
|
|
for (j = 0; j < level; j++)
|
|
Strcat_charp(html, " ");
|
|
q = html_quote(frame.body->url);
|
|
Strcat_charp(html, "<a href=\"");
|
|
Strcat_charp(html, q);
|
|
Strcat_charp(html, "\">");
|
|
if (frame.body->name) {
|
|
p = file_unquote(frame.body->name);
|
|
#ifdef JP_CHARSET
|
|
p = conv(p, buf->document_code, InnerCode)->ptr;
|
|
#endif
|
|
p = html_quote(p);
|
|
Strcat_charp(html, p);
|
|
}
|
|
Strcat_charp(html, " ");
|
|
Strcat_charp(html, q);
|
|
Strcat_charp(html, "</a>\n");
|
|
break;
|
|
case F_FRAMESET:
|
|
append_frame_info(buf, html, frame.set, level + 1);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/*
|
|
* information of current page and link
|
|
*/
|
|
Buffer *
|
|
page_info_panel(Buffer *buf)
|
|
{
|
|
Str tmp = Strnew_size(1024);
|
|
Anchor *a;
|
|
Str s;
|
|
ParsedURL pu;
|
|
TextListItem *ti;
|
|
struct frameset *f_set = NULL;
|
|
int all;
|
|
|
|
Strcat_charp(tmp,
|
|
"<html><head><title>Information about current page</title></head><body>");
|
|
Strcat_charp(tmp,
|
|
"<h1>Information about current page</h1><table cellpadding=0>");
|
|
if (buf == NULL)
|
|
goto end;
|
|
Strcat_charp(tmp, "<tr><td nowrap>Title<td>");
|
|
Strcat_charp(tmp, html_quote(buf->buffername));
|
|
Strcat_charp(tmp, "<tr><td nowrap>Current URL<td>");
|
|
Strcat_charp(tmp, html_quote(parsedURL2Str(&buf->currentURL)->ptr));
|
|
Strcat_charp(tmp, "<tr><td nowrap>Document Type<td>");
|
|
if (buf->real_type)
|
|
Strcat_charp(tmp, buf->real_type);
|
|
else
|
|
Strcat_charp(tmp, "unknown");
|
|
Strcat_charp(tmp, "<tr><td nowrap>Last Modified<td>");
|
|
Strcat_charp(tmp, html_quote(last_modified(buf)));
|
|
#ifdef JP_CHARSET
|
|
Strcat_charp(tmp, "<tr><td nowrap>Document Code<td>");
|
|
Strcat_charp(tmp, code_to_str(buf->document_code));
|
|
#endif /* JP_CHARSET */
|
|
Strcat_charp(tmp, "<tr><td nowrap>Number of line<td>");
|
|
all = buf->allLine;
|
|
if (all == 0 && buf->lastLine)
|
|
all = buf->lastLine->linenumber;
|
|
Strcat(tmp, Sprintf("%d", all));
|
|
Strcat_charp(tmp, "<tr><td nowrap>Transferred byte<td>");
|
|
Strcat(tmp, Sprintf("%d", buf->trbyte));
|
|
|
|
a = retrieveCurrentAnchor(buf);
|
|
if (a != NULL) {
|
|
parseURL2(a->url, &pu, baseURL(buf));
|
|
s = parsedURL2Str(&pu);
|
|
Strcat_charp(tmp, "<tr><td nowrap>URL of current anchor<td>");
|
|
Strcat_charp(tmp, html_quote(s->ptr));
|
|
}
|
|
a = retrieveCurrentImg(buf);
|
|
if (a != NULL) {
|
|
parseURL2(a->url, &pu, baseURL(buf));
|
|
s = parsedURL2Str(&pu);
|
|
Strcat_charp(tmp, "<tr><td nowrap>URL of current image<td>");
|
|
Strcat_charp(tmp, "<a href=\"");
|
|
Strcat_charp(tmp, html_quote(s->ptr));
|
|
Strcat_charp(tmp, "\">");
|
|
Strcat_charp(tmp, html_quote(s->ptr));
|
|
Strcat_charp(tmp, "</a>");
|
|
}
|
|
a = retrieveCurrentForm(buf);
|
|
if (a != NULL) {
|
|
s = Strnew_charp(form2str((FormItemList *)a->url));
|
|
Strcat_charp(tmp, "<tr><td nowrap>Method/type of current form<td>");
|
|
Strcat_charp(tmp, html_quote(s->ptr));
|
|
}
|
|
Strcat_charp(tmp, "</table>\n");
|
|
if (buf->document_header != NULL) {
|
|
Strcat_charp(tmp, "<hr width=50%>\n");
|
|
Strcat_charp(tmp, "<h1>Header information</h1>\n");
|
|
for (ti = buf->document_header->first; ti != NULL; ti = ti->next) {
|
|
Strcat_charp(tmp, html_quote(ti->ptr));
|
|
Strcat_charp(tmp, "<br>");
|
|
}
|
|
}
|
|
if (buf->frameset != NULL)
|
|
f_set = buf->frameset;
|
|
else if (buf->bufferprop & BP_FRAME &&
|
|
buf->nextBuffer != NULL && buf->nextBuffer->frameset != NULL)
|
|
f_set = buf->nextBuffer->frameset;
|
|
|
|
if (f_set) {
|
|
Strcat_charp(tmp, "<hr width=50%><h1>Frame information</h1><pre>");
|
|
append_frame_info(buf, tmp, f_set, 0);
|
|
Strcat_charp(tmp, "</pre>");
|
|
}
|
|
#ifdef USE_SSL
|
|
if (buf->ssl_certificate == NULL)
|
|
goto end;
|
|
Strcat_charp(tmp, "<h1>SSL certificate</h1>\n");
|
|
Strcat_charp(tmp, "<pre>\n");
|
|
Strcat_charp(tmp, buf->ssl_certificate);
|
|
Strcat_charp(tmp, "</pre>\n");
|
|
#endif
|
|
end:
|
|
Strcat_charp(tmp, "</body></html>");
|
|
return loadHTMLString(tmp);
|
|
}
|