#include #include #include "block.h" #include "obj.h" #include "parse.h" #include "animate.h" HTMLObj* htmlobj_new(void) { HTMLObj *p; if ((p = malloc(sizeof(*p))) == NULL) { perror("htmlobj_new"); exit(1); } p->next = p->prev = p; p->type = HTMLOBJ_NONE; p->data = NULL; p->link = NULL; p->width = 0; p->lbearing = p->rbearing = 0; p->ascent = p->descent = 0; p->pixel = 0; return p; } void htmlobj_delete(HTMLObj *p) { if (p) { switch (p->type) { case HTMLOBJ_BLOCK: blockobj_delete(p->data); break; case HTMLOBJ_TEXT_MEM: { HTMLTextObj *o = p->data; free(o->str); } case HTMLOBJ_TEXT: htmltextobj_delete(p->data); break; case HTMLOBJ_IMAGE: htmlimageobj_delete(p->data); break; default: break; } free(p); } } void htmlobjlist_delete(HTMLObjList l) { HTMLObj *p, *q; if (l) { p = l->next; while (p != l) { q = p; p = p->next; htmlobj_delete(q); } htmlobj_delete(l); } } HTMLTextObj* htmltextobj_new(void) { HTMLTextObj *p; if ((p = malloc(sizeof(*p))) == NULL) { perror("htmltextobj_new"); exit(1); } p->str = NULL; p->len = 0; p->oc = NULL; return p; } void htmltextobj_delete(HTMLTextObj *p) { if (p) free(p); } HTMLImageObj * htmlimageobj_new(void) { HTMLImageObj *p; if ((p = malloc(sizeof(*p))) == NULL) { perror("htmlimageobj_new"); exit(1); } p->anim = NULL; return p; } void htmlimageobj_delete(HTMLImageObj *p) { if (p) { free(p); } } void htmlobj_draw(Display *dpy, Drawable draw, GC gc, int x, int y, HTMLObj *o, int x1,int y1,int w, int h) { HTMLTextObj *to; HTMLImageObj *io; switch (o->type) { case HTMLOBJ_BLOCK: blockobj_draw(dpy, draw, gc, x, y, o, x1, y1, w, h); break; case HTMLOBJ_TEXT: case HTMLOBJ_TEXT_MEM: to = (HTMLTextObj*)o->data; XSetForeground(dpy, gc, o->pixel); WcDrawString(dpy, draw, to->oc, gc, x + o->x, y + o->y, to->str, to->len); break; case HTMLOBJ_IMAGE: io = (HTMLImageObj*)o->data; if (io->anim) { XSetClipMask(dpy, gc, io->anim->mask); XSetClipOrigin(dpy, gc, x + o->x, y + o->y - o->ascent); XCopyArea(dpy, io->anim->pixmap, draw, gc, x1, y1, w, h, x + o->x + x1, y + o->y - o->ascent + y1); XSetClipMask(dpy, gc, None); } break; case HTMLOBJ_HR: XSetForeground(dpy, gc, o->pixel); XFillRectangle(dpy, draw, gc, x + o->x, y + o->y - o->ascent, o->width, o->height); break; case HTMLOBJ_BULLET: XSetForeground(dpy, gc, o->pixel); { int type = (int)o->data; switch (type) { case 1: XFillArc(dpy, draw, gc, x + o->x + o->lbearing, y + o->y - o->ascent, o->width, o->height, 0, 360*64); break; case 2: XDrawArc(dpy, draw, gc, x + o->x + o->lbearing, y + o->y - o->ascent, o->width, o->height, 0, 360*64); break; default: XDrawRectangle(dpy, draw, gc, x + o->x + o->lbearing, y + o->y - o->ascent, o->width, o->height); break; } } break; default: break; } #if 0 XDrawRectangle(dpy, draw, gc, x + o->x + o->lbearing, y + o->y - o->ascent, - o->lbearing + o->rbearing, o->ascent + o->descent); XDrawLine(dpy, draw, gc, x + o->x + o->lbearing, y + o->y, x + o->x + o->rbearing , y + o->y); #endif #if 0 XDrawRectangle(dpy, draw, gc, x + o->x + x1, y + o->y - o->ascent + y1, w, h); #endif }