fz_rect fz_boundpath(fz_path *path, fz_strokestate *stroke, fz_matrix ctm) { fz_point p; fz_rect r = fz_emptyrect; int i = 0; if (path->len) { p.x = path->els[1].v; p.y = path->els[2].v; p = fz_transformpoint(ctm, p); r.x0 = r.x1 = p.x; r.y0 = r.y1 = p.y; } while (i < path->len) { switch (path->els[i++].k) { case FZ_CURVETO: p.x = path->els[i++].v; p.y = path->els[i++].v; r = boundexpand(r, fz_transformpoint(ctm, p)); p.x = path->els[i++].v; p.y = path->els[i++].v; r = boundexpand(r, fz_transformpoint(ctm, p)); p.x = path->els[i++].v; p.y = path->els[i++].v; r = boundexpand(r, fz_transformpoint(ctm, p)); break; case FZ_MOVETO: case FZ_LINETO: p.x = path->els[i++].v; p.y = path->els[i++].v; r = boundexpand(r, fz_transformpoint(ctm, p)); break; case FZ_CLOSEPATH: break; } } if (stroke) { float miterlength = sinf(stroke->miterlimit * 0.5f); float linewidth = stroke->linewidth; float expand = MAX(miterlength, linewidth) * 0.5f; r.x0 -= expand; r.y0 -= expand; r.x1 += expand; r.y1 += expand; } return r; }
fz_rect fz_boundpathnode(fz_pathnode *path, fz_matrix ctm) { fz_point p; fz_rect r = fz_emptyrect; int i = 0; if (path->len) { p.x = path->els[1].v; p.y = path->els[2].v; p = fz_transformpoint(ctm, p); r.x0 = r.x1 = p.x; r.y0 = r.y1 = p.y; } while (i < path->len) { switch (path->els[i++].k) { case FZ_CURVETO: p.x = path->els[i++].v; p.y = path->els[i++].v; r = boundexpand(r, fz_transformpoint(ctm, p)); p.x = path->els[i++].v; p.y = path->els[i++].v; r = boundexpand(r, fz_transformpoint(ctm, p)); case FZ_MOVETO: case FZ_LINETO: p.x = path->els[i++].v; p.y = path->els[i++].v; r = boundexpand(r, fz_transformpoint(ctm, p)); break; case FZ_CLOSEPATH: break; } } if (path->paint == FZ_STROKE) { float miterlength = sin(path->miterlimit / 2.0); float linewidth = path->linewidth; float expand = MAX(miterlength, linewidth) / 2.0; r.x0 -= expand; r.y0 -= expand; r.x1 += expand; r.y1 += expand; } return r; }
void pdfmoz_onmouse(pdfmoz_t *moz, int x, int y, int click) { char buf[512]; pdf_link *link; fz_matrix ctm; fz_point p; int pi; int py; if (!moz->pages) return; pi = moz->scrollpage; py = -moz->scrollyofs; while (pi < moz->pagecount) { if (!moz->pages[pi].image) return; if (y > py && y < moz->pages[pi].px) break; py += moz->pages[pi].px; pi ++; } if (pi == moz->pagecount) return; p.x = x + moz->pages[pi].image->x; p.y = y + moz->pages[pi].image->y - py; ctm = pdfmoz_pagectm(moz, pi); ctm = fz_invertmatrix(ctm); p = fz_transformpoint(ctm, p); for (link = moz->pages[pi].page->links; link; link = link->next) { if (p.x >= link->rect.x0 && p.x <= link->rect.x1) if (p.y >= link->rect.y0 && p.y <= link->rect.y1) break; } if (link) { SetCursor(moz->hand); if (click) { if (link->kind == PDF_LURI) pdfmoz_gotouri(moz, link->dest); else if (link->kind == PDF_LGOTO) pdfmoz_gotopage(moz, link->dest); return; } else { if (fz_isstring(link->dest)) { memcpy(buf, fz_tostrbuf(link->dest), fz_tostrlen(link->dest)); buf[fz_tostrlen(link->dest)] = 0; NPN_Status(moz->inst, buf); } else if (fz_isindirect(link->dest)) { sprintf(buf, "Go to page %d", pdfmoz_getpagenum(moz, link->dest) + 1); NPN_Status(moz->inst, buf); } else NPN_Status(moz->inst, "Say what?"); } } else { sprintf(buf, "Page %d of %d", moz->scrollpage + 1, moz->pagecount); NPN_Status(moz->inst, buf); SetCursor(moz->arrow); } }
void pdfapp_onmouse(pdfapp_t *app, int x, int y, int btn, int modifiers, int state) { pdf_link *link; fz_matrix ctm; fz_point p; p.x = x - app->panx + app->image->x; p.y = y - app->pany + app->image->y; ctm = pdfapp_viewctm(app); ctm = fz_invertmatrix(ctm); p = fz_transformpoint(ctm, p); for (link = app->page->links; link; link = link->next) { if (p.x >= link->rect.x0 && p.x <= link->rect.x1) if (p.y >= link->rect.y0 && p.y <= link->rect.y1) break; } if (link) { wincursor(app, HAND); if (btn == 1 && state == 1) { if (fz_isstring(link->dest)) pdfapp_gotouri(app, link->dest); if (fz_isindirect(link->dest)) pdfapp_gotopage(app, link->dest); return; } } else { wincursor(app, ARROW); } if (state == 1) { if (btn == 1 && !app->iscopying) { app->ispanning = 1; app->selx = x; app->sely = y; } if (btn == 3 && !app->ispanning) { app->iscopying = 1; app->selx = x; app->sely = y; app->selr.x0 = x; app->selr.x1 = x; app->selr.y0 = y; app->selr.y1 = y; } if (btn == 4 || btn == 5) /* scroll wheel */ { int dir = btn == 4 ? 1 : -1; app->ispanning = app->iscopying = 0; if (modifiers & (1<<2)) { /* zoom in/out if ctrl is pressed */ app->zoom += 0.1 * dir; if (app->zoom > 3.0) app->zoom = 3.0; if (app->zoom < 0.1) app->zoom = 0.1; pdfapp_showpage(app, 0, 1); } else { /* scroll up/down, or left/right if shift is pressed */ int isx = (modifiers & (1<<0)); int xstep = isx ? 20 * dir : 0; int ystep = !isx ? 20 * dir : 0; pdfapp_panview(app, app->panx + xstep, app->pany + ystep); } } } else if (state == -1) { if (app->iscopying) { app->iscopying = 0; app->selr.x0 = MIN(app->selx, x); app->selr.x1 = MAX(app->selx, x); app->selr.y0 = MIN(app->sely, y); app->selr.y1 = MAX(app->sely, y); winrepaint(app); if (app->selr.x0 < app->selr.x1 && app->selr.y0 < app->selr.y1) windocopy(app); } if (app->ispanning) app->ispanning = 0; } else if (app->ispanning) { int newx = app->panx + x - app->selx; int newy = app->pany + y - app->sely; pdfapp_panview(app, newx, newy); app->selx = x; app->sely = y; } else if (app->iscopying) { app->selr.x0 = MIN(app->selx, x); app->selr.x1 = MAX(app->selx, x); app->selr.y0 = MIN(app->sely, y); app->selr.y1 = MAX(app->sely, y); winrepaint(app); } }
fz_error fz_rendershade(fz_shade *shade, fz_matrix ctm, fz_colorspace *destcs, fz_pixmap *dest) { unsigned char clut[256][3]; unsigned char *s, *d; fz_error error; fz_pixmap *temp; float rgb[3]; float tri[3][MAXN]; fz_point p; int i, j, k, n; assert(dest->n == 4); ctm = fz_concat(shade->matrix, ctm); if (shade->usefunction) { n = 3; error = fz_newpixmap(&temp, dest->x, dest->y, dest->w, dest->h, 2); if (error) return error; } else if (shade->cs != destcs) { n = 2 + shade->cs->n; error = fz_newpixmap(&temp, dest->x, dest->y, dest->w, dest->h, shade->cs->n + 1); if (error) return error; } else { n = 2 + shade->cs->n; temp = dest; } fz_clearpixmap(temp); for (i = 0; i < shade->meshlen; i++) { for (k = 0; k < 3; k++) { p.x = shade->mesh[(i * 3 + k) * n + 0]; p.y = shade->mesh[(i * 3 + k) * n + 1]; p = fz_transformpoint(ctm, p); if (isnan(p.y) || isnan(p.x)) // How is this happening? goto baddata; tri[k][0] = p.x; tri[k][1] = p.y; for (j = 2; j < n; j++) tri[k][j] = shade->mesh[( i * 3 + k) * n + j] * 255; } fz_drawtriangle(temp, tri[0], tri[1], tri[2], n); baddata: ; } if (shade->usefunction) { for (i = 0; i < 256; i++) { fz_convertcolor(shade->cs, shade->function[i], destcs, rgb); clut[i][0] = rgb[0] * 255; clut[i][1] = rgb[1] * 255; clut[i][2] = rgb[2] * 255; } n = temp->w * temp->h; s = temp->samples; d = dest->samples; while (n--) { d[0] = s[0]; d[1] = fz_mul255(s[0], clut[s[1]][0]); d[2] = fz_mul255(s[0], clut[s[1]][1]); d[3] = fz_mul255(s[0], clut[s[1]][2]); s += 2; d += 4; } fz_droppixmap(temp); } else if (shade->cs != destcs) { fz_convertpixmap(shade->cs, temp, destcs, dest); fz_droppixmap(temp); } return fz_okay; }
void pdfapp_onmouse(pdfapp_t *app, int x, int y, int btn, int modifiers, int state) { pdf_link *link; fz_matrix ctm; fz_point p; p.x = x - app->panx + app->image->x; p.y = y - app->pany + app->image->y; ctm = pdfapp_viewctm(app); ctm = fz_invertmatrix(ctm); p = fz_transformpoint(ctm, p); for (link = app->page->links; link; link = link->next) { if (p.x >= link->rect.x0 && p.x <= link->rect.x1) if (p.y >= link->rect.y0 && p.y <= link->rect.y1) break; } if (link) { wincursor(app, HAND); if (btn == 1 && state == 1) { if (link->kind == PDF_LURI) pdfapp_gotouri(app, link->dest); else if (link->kind == PDF_LGOTO) pdfapp_gotopage(app, link->dest); return; } } else { wincursor(app, ARROW); } if (state == 1) { if (btn == 1 && !app->iscopying) { app->ispanning = 1; app->selx = x; app->sely = y; } if (btn == 3 && !app->ispanning) { kno_clearselect(app); //code change by kakai app->iscopying = 1; app->selx = x; app->sely = y; app->selr.x0 = x; app->selr.x1 = x; app->selr.y0 = y; app->selr.y1 = y; } if (btn == 4 || btn == 5) /* scroll wheel */ { int dir = btn == 4 ? 1 : -1; app->ispanning = app->iscopying = 0; if (modifiers & (1<<2)) { /* zoom in/out if ctrl is pressed */ app->zoom += 0.1 * dir; if (app->zoom > 3.0) app->zoom = 3.0; if (app->zoom < 0.1) app->zoom = 0.1; pdfapp_showpage(app, 0, 1); } else { /* scroll up/down, or left/right if shift is pressed */ int isx = (modifiers & (1<<0)); int xstep = isx ? 20 * dir : 0; int ystep = !isx ? 20 * dir : 0; pdfapp_panview(app, app->panx + xstep, app->pany + ystep); } } } else if (state == -1) { //Code change by Kakai //Hit testing kno_hitdata *hitdata = kno_gethitdata(app, x, y); printf("hit test char is: %c\n", hitdata->ucs); //Code change by Kakai if (app->iscopying) { app->iscopying = 0; app->selr.x0 = MIN(app->selx, x); app->selr.x1 = MAX(app->selx, x); app->selr.y0 = MIN(app->sely, y); app->selr.y1 = MAX(app->sely, y); winrepaint(app); if (app->selr.x0 < app->selr.x1 && app->selr.y0 < app->selr.y1) windocopy(app); } if (app->ispanning) app->ispanning = 0; } else if (app->ispanning) { int newx = app->panx + x - app->selx; int newy = app->pany + y - app->sely; pdfapp_panview(app, newx, newy); app->selx = x; app->sely = y; } else if (app->iscopying) { app->selr.x0 = MIN(app->selx, x); app->selr.x1 = MAX(app->selx, x); app->selr.y0 = MIN(app->sely, y); app->selr.y1 = MAX(app->sely, y); //code change by kakai //IsHighlightable and selection testing int closestx, closesty; closestx = closesty = 0; if (kno_ishighlightable(app, x, y, &closestx, &closesty) == 1) kno_onselect(app); //code change by kakai else { printf("x is %d\n", closestx); printf("y is %d\n", closesty); } //code change by kakai winrepaint(app); } }