int main(int argc, char **argv) { MSG msg; char buf[1024]; char *filename; fz_cpudetect(); fz_accelerate(); pdfapp_init(&gapp); associate(argv[0]); winopen(); if (argc == 2) filename = fz_strdup(argv[1]); else { if (!winfilename(buf, sizeof buf)) exit(0); filename = buf; } pdfapp_open(&gapp, filename); while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } pdfapp_close(&gapp); return 0; }
BKPDF* BKPDF::create(string& file) { if (singleton != 0) { printf("cannot open more than 1 pdf at the same time\n"); return singleton; } reset_allocs(); BKPDF* b = new BKPDF(file); singleton = b; fz_setmemorycontext(&bkmem); fz_cpudetect(); fz_accelerate(); pdfInit(); PDFContext* ctx = pdfOpen((char*)file.c_str()); if (ctx == 0) { delete b; return 0; } b->ctx = ctx; int lastSlash = 0; int n = file.size(); for (int i = 0; i < n; ++i) { if (file[i] == '\\') lastSlash == i++; else if (file[i] == '/') lastSlash == i++; } b->title.assign(file, lastSlash, n - lastSlash); if (ctx->xref->info) { fz_error *error; fz_obj *obj; obj = fz_dictgets(ctx->xref->info, "Title"); if (obj) { char *p = NULL; error = pdf_toutf8(&p, obj); if (error == NULL) { b->title = p; } } } // Add bookmark support //int position = BKBookmark::getLastView(b->filePath); //b->setPage(position); b->pageError = pdfLoadPage(ctx) != 0; FZScreen::resetReps(); b->redrawBuffer(); print_allocs(); lastScrollFlag = BKUser::options.pdfFastScroll; return b; }
int main(int argc, char **argv) { char *filename; int c; int len; char buf[128]; KeySym keysym; int oldx = 0; int oldy = 0; int zoom = 100; int pageno = 1; int wasshowingpage; struct timeval tmo, tmo_at; while ((c = fz_getopt(argc, argv, "d:z:p:")) != -1) { switch (c) { case 'd': password = fz_optarg; break; case 'z': zoom = atoi(fz_optarg); break; case 'p': pageno = atoi(fz_optarg); break; default: usage(); } } if (zoom < 100) zoom = 100; if (zoom > 300) zoom = 300; if (argc - fz_optind == 0) usage(); filename = argv[fz_optind++]; fz_cpudetect(); fz_accelerate(); winopen(); pdfapp_init(&gapp); gapp.scrw = DisplayWidth(xdpy, xscr); gapp.scrh = DisplayHeight(xdpy, xscr); gapp.zoom = zoom / 100.0; gapp.pageno = pageno; pdfapp_open(&gapp, filename); winresettmo(&tmo, &tmo_at); while (1) { do { winawaitevent(&tmo, &tmo_at); if (tmo_at.tv_sec != 0 && tmo_at.tv_usec != 0 && tmo.tv_sec == 0 && tmo.tv_usec == 0) { /* redraw page */ winblit(&gapp); isshowingpage = 0; winresettmo(&tmo, &tmo_at); continue; } switch (xevt.type) { case Expose: dirty = 1; break; case ConfigureNotify: if (gapp.image) { if (xevt.xconfigure.width != reqw || xevt.xconfigure.height != reqh) gapp.shrinkwrap = 0; } pdfapp_onresize(&gapp, xevt.xconfigure.width, xevt.xconfigure.height); break; case KeyPress: wasshowingpage = isshowingpage; len = XLookupString(&xevt.xkey, buf, sizeof buf, &keysym, nil); if (len) onkey(buf[0]); onmouse(oldx, oldy, 0, 0, 0); if (dirty) { winblit(&gapp); dirty = 0; if (isshowingpage) { isshowingpage = 0; winresettmo(&tmo, &tmo_at); } } if (!wasshowingpage && isshowingpage) winsettmo(&tmo, &tmo_at); break; case MotionNotify: oldx = xevt.xbutton.x; oldy = xevt.xbutton.y; onmouse(xevt.xbutton.x, xevt.xbutton.y, xevt.xbutton.button, xevt.xbutton.state, 0); break; case ButtonPress: onmouse(xevt.xbutton.x, xevt.xbutton.y, xevt.xbutton.button, xevt.xbutton.state, 1); break; case ButtonRelease: copytime = xevt.xbutton.time; onmouse(xevt.xbutton.x, xevt.xbutton.y, xevt.xbutton.button, xevt.xbutton.state, -1); break; case SelectionRequest: onselreq(xevt.xselectionrequest.requestor, xevt.xselectionrequest.selection, xevt.xselectionrequest.target, xevt.xselectionrequest.property, xevt.xselectionrequest.time); break; } } while (XPending(xdpy)); if (dirty) { winblit(&gapp); dirty = 0; if (isshowingpage) { isshowingpage = 0; winresettmo(&tmo, &tmo_at); } } } pdfapp_close(&gapp); return 0; }
int main(int argc, char **argv) { char *filename; int c; int len; unsigned char buf[128]; KeySym keysym; int oldx = 0; int oldy = 0; double zoom = 1.0; int pageno = 1; while ((c = getopt(argc, argv, "d:z:p:")) != -1) { switch (c) { case 'd': password = optarg; break; case 'z': zoom = atof(optarg); break; case 'p': pageno = atoi(optarg); break; default: usage(); } } if (argc - optind == 0) usage(); filename = argv[optind++]; fz_cpudetect(); fz_accelerate(); winopen(); pdfapp_init(&gapp); gapp.scrw = DisplayWidth(xdpy, xscr); gapp.scrh = DisplayHeight(xdpy, xscr); gapp.zoom = zoom; gapp.pageno = pageno; pdfapp_open(&gapp, filename); while (1) { do { XNextEvent(xdpy, &xevt); switch (xevt.type) { case Expose: dirty = 1; break; case ConfigureNotify: if (gapp.image) { if (xevt.xconfigure.width != reqw || xevt.xconfigure.height != reqh) gapp.shrinkwrap = 0; } pdfapp_onresize(&gapp, xevt.xconfigure.width, xevt.xconfigure.height); break; case KeyPress: len = XLookupString(&xevt.xkey, buf, sizeof buf, &keysym, 0); if (len) onkey(buf[0]); onmouse(oldx, oldy, 0, 0, 0); if (dirty) { winblit(&gapp); dirty = 0; } break; case MotionNotify: oldx = xevt.xbutton.x; oldy = xevt.xbutton.y; onmouse(xevt.xbutton.x, xevt.xbutton.y, xevt.xbutton.button, xevt.xbutton.state, 0); break; case ButtonPress: onmouse(xevt.xbutton.x, xevt.xbutton.y, xevt.xbutton.button, xevt.xbutton.state, 1); break; case ButtonRelease: copytime = xevt.xbutton.time; onmouse(xevt.xbutton.x, xevt.xbutton.y, xevt.xbutton.button, xevt.xbutton.state, -1); break; case SelectionRequest: onselreq(xevt.xselectionrequest.requestor, xevt.xselectionrequest.selection, xevt.xselectionrequest.target, xevt.xselectionrequest.property, xevt.xselectionrequest.time); break; } } while (XPending(xdpy)); if (dirty) { winblit(&gapp); dirty = 0; } } pdfapp_close(&gapp); return 0; }