aboutsummaryrefslogtreecommitdiffstats
path: root/w3mimgdisplay.c
diff options
context:
space:
mode:
authorFumitoshi UKAI <ukai@debian.or.jp>2002-01-31 17:54:47 +0000
committerFumitoshi UKAI <ukai@debian.or.jp>2002-01-31 17:54:47 +0000
commit9efbc0885687b07cfe35e5933ebcc202aeff6bef (patch)
tree03909b91dc1b5c7b0074bea51a549b357b8b9694 /w3mimgdisplay.c
parentversion.c.in: 0.2.5+cvs (diff)
downloadw3m-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 'w3mimgdisplay.c')
-rw-r--r--w3mimgdisplay.c369
1 files changed, 369 insertions, 0 deletions
diff --git a/w3mimgdisplay.c b/w3mimgdisplay.c
new file mode 100644
index 0000000..872068a
--- /dev/null
+++ b/w3mimgdisplay.c
@@ -0,0 +1,369 @@
+/* $Id: w3mimgdisplay.c,v 1.1 2002/01/31 17:54:57 ukai Exp $ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <Imlib.h>
+
+static Display *display;
+static Window window, parent;
+static unsigned long background_pixel;
+static char *background = NULL;
+static int offset_x = 2, offset_y = 2;
+static int defined_bg = 0, defined_x = 0, defined_y = 0, defined_test = 0;
+static int defined_debug = 0;
+
+#define MAX_IMAGE 1000
+typedef struct {
+ Pixmap pixmap;
+ int width;
+ int height;
+} Image;
+static Image *imageBuf = NULL;
+static int maxImage = 0;
+static GC imageGC = NULL;
+
+static void GetOption(int argc, char **argv);
+static void DrawImage(char *buf, int redraw);
+static void ClearImage(void);
+
+/* *INDENT-OFF* */
+/*
+ xterm/kterm/hanterm/cxterm
+ top window (WINDOWID)
+ +- text window
+ +- scrollbar
+ rxvt/aterm/Eterm/wterm
+ top window (WINDOWID)
+ +- text window
+ +- scrollbar
+ +- menubar (etc.)
+ gnome-terminal
+ top window
+ +- text window (WINDOWID)
+ +- scrollbar
+ +- menubar
+ mlterm (-s)
+ top window
+ +- text window (WINDOWID)
+ +- scrollbar
+ mlterm
+ top window = text window (WINDOWID)
+
+ powershell
+ top window
+ +- window
+ | +- text window
+ | +- scrollbar
+ +- menubar (etc.)
+ dtterm
+ top window
+ +- window
+ +- window
+ | +- window
+ | +- text window
+ | +- scrollbar
+ +- menubar
+ hpterm
+ top window
+ +- window
+ +- text window
+ +- scrollbar
+ +- (etc.)
+*/
+/* *INDENT-ON* */
+
+int
+main(int argc, char **argv)
+{
+ Window root, *children;
+ XWindowAttributes attr;
+ XColor screen_def, exact_def;
+ int revert, nchildren, len, width, height, i;
+ char buf[1024 + 128];
+ char *id;
+
+ GetOption(argc, argv);
+ if (!defined_debug)
+ fclose(stderr);
+
+ display = XOpenDisplay(NULL);
+ if (!display)
+ exit(1);
+ if ((id = getenv("WINDOWID")) != NULL)
+ window = (Window) atoi(id);
+ else
+ XGetInputFocus(display, &window, &revert);
+ if (!window)
+ exit(1);
+
+ XGetWindowAttributes(display, window, &attr);
+ width = attr.width;
+ height = attr.height;
+ while (1) {
+ Window p_window;
+
+ XQueryTree(display, window, &root, &parent, &children, &nchildren);
+ if (defined_debug)
+ fprintf(stderr,
+ "window=%x root=%x parent=%x nchildren=%d width=%d height=%d\n",
+ window, root, parent, nchildren, width, height);
+ p_window = window;
+ for (i = 0; i < nchildren; i++) {
+ XGetWindowAttributes(display, children[i], &attr);
+ if (defined_debug)
+ fprintf(stderr,
+ "children[%d]=%x x=%d y=%d width=%d height=%d\n", i,
+ children[i], attr.x, attr.y, attr.width, attr.height);
+ if (attr.width > width * 0.7 && attr.height > height * 0.7) {
+ /* maybe text window */
+ width = attr.width;
+ height = attr.height;
+ window = children[i];
+ }
+ }
+ if (p_window == window)
+ break;
+ }
+ if (!defined_x) {
+ for (i = 0; i < nchildren; i++) {
+ XGetWindowAttributes(display, children[i], &attr);
+ if (attr.x <= 0 && attr.width < 30 && attr.height > height * 0.7) {
+ if (defined_debug)
+ fprintf(stderr,
+ "children[%d]=%x x=%d y=%d width=%d height=%d\n",
+ i, children[i], attr.x, attr.y, attr.width,
+ attr.height);
+ /* scrollbar of xterm/kterm ? */
+ offset_x += attr.x + attr.width + attr.border_width * 2;
+ break;
+ }
+ }
+ }
+
+ if (defined_test) {
+ printf("%d %d\n", width - offset_x, height - offset_y);
+ exit(0);
+ }
+
+ if (defined_bg && XAllocNamedColor(display, DefaultColormap(display, 0),
+ background, &screen_def, &exact_def))
+ background_pixel = screen_def.pixel;
+ else {
+ Pixmap p;
+ GC gc;
+ XImage *i;
+
+ p = XCreatePixmap(display, window, 1, 1, DefaultDepth(display, 0));
+ gc = XCreateGC(display, window, 0, NULL);
+ if (!p || !gc)
+ exit(1);
+ XCopyArea(display, window, p, gc, (offset_x >= 1) ? (offset_x - 1) : 0,
+ (offset_y >= 1) ? (offset_y - 1) : 0, 1, 1, 0, 0);
+ i = XGetImage(display, p, 0, 0, 1, 1, -1, ZPixmap);
+ if (!i)
+ exit(1);
+ background_pixel = XGetPixel(i, 0, 0);
+ XDestroyImage(i);
+ XFreeGC(display, gc);
+ XFreePixmap(display, p);
+/*
+ background_pixel = WhitePixel(display, 0);
+*/
+ }
+
+ while (fgets(buf, sizeof(buf), stdin) != NULL) {
+ if (!(isdigit(buf[0]) && buf[1] == ';')) {
+ fputc('\n', stdout);
+ fflush(stdout);
+ continue;
+ }
+ len = strlen(buf);
+ if (buf[len - 1] == '\n') {
+ buf[--len] = '\0';
+ if (buf[len - 1] == '\r')
+ buf[--len] = '\0';
+ }
+ switch (buf[0]) {
+ case '0':
+ DrawImage(&buf[2], 0);
+ break;
+ case '1':
+ DrawImage(&buf[2], 1);
+ break;
+ case '2':
+ ClearImage();
+ break;
+ case '3':
+ XSync(display, False);
+ break;
+ case '4':
+ fputs("\n", stdout);
+ fflush(stdout);
+ break;
+ }
+ }
+ ClearImage();
+ /*
+ * XCloseDisplay(display);
+ */
+ exit(0);
+}
+
+static void
+GetOption(int argc, char **argv)
+{
+ int i;
+
+ for (i = 1; i < argc; i++) {
+ if (!strcmp("-bg", argv[i])) {
+ if (++i >= argc)
+ exit(1);
+ background = argv[i];
+ defined_bg = 1;
+ }
+ else if (!strcmp("-x", argv[i])) {
+ if (++i >= argc)
+ exit(1);
+ offset_x = atoi(argv[i]);
+ defined_x = 1;
+ }
+ else if (!strcmp("-y", argv[i])) {
+ if (++i >= argc)
+ exit(1);
+ offset_y = atoi(argv[i]);
+ defined_y = 1;
+ }
+ else if (!strcmp("-test", argv[i])) {
+ defined_test = 1;
+ }
+ else if (!strcmp("-debug", argv[i])) {
+ defined_debug = 1;
+ }
+ else {
+ exit(1);
+ }
+ }
+}
+
+void
+DrawImage(char *buf, int redraw)
+{
+ static ImlibData *id = NULL;
+ ImlibImage *im;
+ char *p = buf;
+ int n = 0, x = 0, y = 0, w = 0, h = 0, sx = 0, sy = 0, sw = 0, sh = 0;
+
+ if (!p)
+ return;
+ for (; isdigit(*p); p++)
+ n = 10 * n + (*p - '0');
+ if (*(p++) != ';')
+ return;
+ for (; isdigit(*p); p++)
+ x = 10 * x + (*p - '0');
+ if (*(p++) != ';')
+ return;
+ for (; isdigit(*p); p++)
+ y = 10 * y + (*p - '0');
+ if (*(p++) != ';')
+ return;
+ for (; isdigit(*p); p++)
+ w = 10 * w + (*p - '0');
+ if (*(p++) != ';')
+ return;
+ for (; isdigit(*p); p++)
+ h = 10 * h + (*p - '0');
+ if (*(p++) != ';')
+ return;
+ for (; isdigit(*p); p++)
+ sx = 10 * sx + (*p - '0');
+ if (*(p++) != ';')
+ return;
+ for (; isdigit(*p); p++)
+ sy = 10 * sy + (*p - '0');
+ if (*(p++) != ';')
+ return;
+ for (; isdigit(*p); p++)
+ sw = 10 * sw + (*p - '0');
+ if (*(p++) != ';')
+ return;
+ for (; isdigit(*p); p++)
+ sh = 10 * sh + (*p - '0');
+ if (*(p++) != ';')
+ return;
+
+ n--;
+ if (n < 0 || n >= MAX_IMAGE)
+ return;
+ if (redraw) {
+ if (!imageGC || n >= maxImage || !imageBuf[n].pixmap)
+ return;
+ goto draw_image;
+ }
+ if (!id) {
+ id = Imlib_init(display);
+ if (!id)
+ return;
+ }
+ if (!imageGC) {
+ imageGC = XCreateGC(display, parent, 0, NULL);
+ if (!imageGC)
+ return;
+ }
+ if (n >= maxImage) {
+ int i = maxImage;
+ maxImage = i ? (i * 2) : 2;
+ if (maxImage > MAX_IMAGE)
+ maxImage = MAX_IMAGE;
+ else if (n >= maxImage)
+ maxImage = n + 1;
+ imageBuf = (Image *) realloc((void *)imageBuf,
+ sizeof(Image) * maxImage);
+ for (; i < maxImage; i++)
+ imageBuf[i].pixmap = NULL;
+ }
+ if (imageBuf[n].pixmap) {
+ XFreePixmap(display, imageBuf[n].pixmap);
+ imageBuf[n].pixmap = NULL;
+ }
+
+ im = Imlib_load_image(id, p);
+ if (!im)
+ return;
+ if (!w)
+ w = im->rgb_width;
+ if (!h)
+ h = im->rgb_height;
+ imageBuf[n].pixmap = XCreatePixmap(display, parent, w, h,
+ DefaultDepth(display, 0));
+ if (!imageBuf[n].pixmap)
+ return;
+ XSetForeground(display, imageGC, background_pixel);
+ XFillRectangle(display, imageBuf[n].pixmap, imageGC, 0, 0, w, h);
+ Imlib_paste_image(id, im, imageBuf[n].pixmap, 0, 0, w, h);
+ Imlib_kill_image(id, im);
+ imageBuf[n].width = w;
+ imageBuf[n].height = h;
+ draw_image:
+ XCopyArea(display, imageBuf[n].pixmap, window, imageGC,
+ sx, sy, (sw ? sw : imageBuf[n].width),
+ (sh ? sh : imageBuf[n].height), x + offset_x, y + offset_y);
+}
+
+void
+ClearImage(void)
+{
+ if (imageGC) {
+ XFreeGC(display, imageGC);
+ imageGC = NULL;
+ }
+ if (imageBuf) {
+ int i;
+ for (i = 0; i < maxImage; i++) {
+ if (imageBuf[i].pixmap)
+ XFreePixmap(display, imageBuf[i].pixmap);
+ }
+ free(imageBuf);
+ imageBuf = NULL;
+ }
+ maxImage = 0;
+}