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; }
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) { int argc; LPWSTR *argv = CommandLineToArgvW(GetCommandLineW(), &argc); char argv0[256]; MSG msg; int fd; int code; fz_context *ctx; ctx = fz_new_context(NULL, NULL, FZ_STORE_DEFAULT); if (!ctx) { fprintf(stderr, "cannot initialise context\n"); exit(1); } pdfapp_init(ctx, &gapp); GetModuleFileNameA(NULL, argv0, sizeof argv0); install_app(argv0); winopen(); if (argc == 2) { wcscpy(wbuf, argv[1]); } else { if (!winfilename(wbuf, nelem(wbuf))) exit(0); } fd = _wopen(wbuf, O_BINARY | O_RDONLY, 0666); if (fd < 0) winerror(&gapp, "cannot open file"); code = WideCharToMultiByte(CP_UTF8, 0, wbuf, -1, filename, sizeof filename, NULL, NULL); if (code == 0) winerror(&gapp, "cannot convert filename to utf-8"); pdfapp_open(&gapp, filename, fd, 0); while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } pdfapp_close(&gapp); return 0; }
AS3_Val f_setup (void *data, AS3_Val args) { pdfapp_init(&gapp); gapp.scrw = 300; gapp.scrh = 800; gapp.zoom = 100.0; gapp.pageno = 1; pdfapp_open(&gapp, "pdfBytes"); return AS3_Int(0); }
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) { int argc; LPWSTR *argv = CommandLineToArgvW(GetCommandLineW(), &argc); char argv0[256]; MSG msg; int fd; int code; fz_accelerate(); pdfapp_init(&gapp); GetModuleFileNameA(NULL, argv0, sizeof argv0); install_app(argv0); winopen(); if (argc == 2) { wcscpy(wbuf, argv[1]); } else { if (!winfilename(wbuf, nelem(wbuf))) exit(0); } fd = _wopen(wbuf, O_BINARY | O_RDONLY, 0666); if (fd < 0) winerror(&gapp, fz_throw("cannot open file '%s'", filename)); code = WideCharToMultiByte(CP_UTF8, 0, wbuf, -1, filename, sizeof filename, NULL, NULL); if (code == 0) win32error("cannot convert filename to utf-8"); pdfapp_open(&gapp, filename, fd, 0); while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } pdfapp_close(&gapp); return 0; }
void convertFile(AcString pdfName, int page, BOOL bDwg) { fz_context *ctx; ctx = fz_new_context(NULL, NULL, FZ_STORE_DEFAULT); if (!ctx) { return; } pdfapp_t gapp; pdfapp_init(ctx, &gapp); gapp.strFileName = pdfName; gapp.pageno = page; gapp.bOutputDwg = bDwg; //½øÐÐת»» char utf8Name[PATH_MAX]; pdfapp_AcString2Utf8Char(gapp.strFileName, utf8Name); pdfapp_open(&gapp, utf8Name, 0); pdfapp_close(&gapp); fz_free_context(ctx); }
int main(int argc, char *argv[]) { fz_context *ctx; FILE *script = NULL; int c; while ((c = fz_getopt(argc, argv, "o:p:v")) != -1) { switch(c) { case 'o': output = fz_optarg; break; case 'p': prefix = fz_optarg; break; case 'v': verbosity ^= 1; break; default: usage(); break; } } if (fz_optind == argc) usage(); ctx = fz_new_context(NULL, NULL, FZ_STORE_DEFAULT); if (!ctx) { fprintf(stderr, "cannot initialise context\n"); exit(1); } pdfapp_init(ctx, &gapp); gapp.scrw = 640; gapp.scrh = 480; gapp.colorspace = fz_device_rgb(ctx); fz_try(ctx) { while (fz_optind < argc) { scriptname = argv[fz_optind++]; script = fopen(scriptname, "rb"); if (script == NULL) fz_throw(ctx, FZ_ERROR_GENERIC, "cannot open script: %s", scriptname); do { char *line = my_getline(script); if (line == NULL) continue; if (verbosity) fprintf(stderr, "'%s'\n", line); if (match(&line, "%")) { /* Comment */ } else if (match(&line, "PASSWORD")) { strcpy(pd_password, line); } else if (match(&line, "OPEN")) { char path[1024]; if (file_open) pdfapp_close(&gapp); strcpy(filename, line); if (prefix) { sprintf(path, "%s%s", prefix, line); } else { strcpy(path, line); } pdfapp_open(&gapp, path, 0); file_open = 1; } else if (match(&line, "GOTO")) { pdfapp_gotopage(&gapp, atoi(line)-1); } else if (match(&line, "SCREENSHOT")) { char text[1024]; sprintf(text, output, ++shotcount); if (strstr(text, ".pgm") || strstr(text, ".ppm") || strstr(text, ".pnm")) fz_write_pnm(ctx, gapp.image, text); else fz_write_png(ctx, gapp.image, text, 0); } else if (match(&line, "RESIZE")) { int w, h; sscanf(line, "%d %d", &w, &h); pdfapp_onresize(&gapp, w, h); } else if (match(&line, "CLICK")) { float x, y, b; int n; n = sscanf(line, "%f %f %f", &x, &y, &b); if (n < 1) x = 0.0f; if (n < 2) y = 0.0f; if (n < 3) b = 1; /* state = 1 = transition down */ pdfapp_onmouse(&gapp, (int)x, (int)y, b, 0, 1); /* state = -1 = transition up */ pdfapp_onmouse(&gapp, (int)x, (int)y, b, 0, -1); } else if (match(&line, "TEXT")) { unescape_string(td_textinput, line); } else { fprintf(stderr, "Unmatched: %s\n", line); } } while (!feof(script)); fclose(script); } } fz_catch(ctx) { fprintf(stderr, "error: cannot execute '%s'\n", scriptname); } if (file_open) pdfapp_close(&gapp); fz_free_context(ctx); return 0; }
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) { int argc; LPWSTR *wargv = CommandLineToArgvW(GetCommandLineW(), &argc); char **argv; char argv0[256]; MSG msg; int code; fz_context *ctx; int bps = 0; int displayRes = get_system_dpi(); int c; char *layout_css = NULL; ctx = fz_new_context(NULL, NULL, FZ_STORE_DEFAULT); if (!ctx) { fprintf(stderr, "cannot initialise context\n"); exit(1); } pdfapp_init(ctx, &gapp); argv = fz_argv_from_wargv(argc, wargv); while ((c = fz_getopt(argc, argv, "p:r:A:C:W:H:S:U:b:")) != -1) { switch (c) { case 'C': c = strtol(fz_optarg, NULL, 16); gapp.tint = 1; gapp.tint_r = (c >> 16) & 255; gapp.tint_g = (c >> 8) & 255; gapp.tint_b = (c) & 255; break; case 'p': password = fz_optarg; break; case 'r': displayRes = fz_atoi(fz_optarg); break; case 'A': fz_set_aa_level(ctx, fz_atoi(fz_optarg)); break; case 'W': gapp.layout_w = fz_atoi(fz_optarg); break; case 'H': gapp.layout_h = fz_atoi(fz_optarg); break; case 'S': gapp.layout_em = fz_atoi(fz_optarg); break; case 'b': bps = (fz_optarg && *fz_optarg) ? fz_atoi(fz_optarg) : 4096; break; case 'U': layout_css = fz_optarg; break; default: usage(); } } pdfapp_setresolution(&gapp, displayRes); GetModuleFileNameA(NULL, argv0, sizeof argv0); install_app(argv0); winopen(); if (fz_optind < argc) { strcpy(filename, argv[fz_optind]); } else { if (!winfilename(wbuf, nelem(wbuf))) exit(0); code = WideCharToMultiByte(CP_UTF8, 0, wbuf, -1, filename, sizeof filename, NULL, NULL); if (code == 0) winerror(&gapp, "cannot convert filename to utf-8"); } if (layout_css) { fz_buffer *buf = fz_read_file(ctx, layout_css); fz_set_user_css(ctx, fz_string_from_buffer(ctx, buf)); fz_drop_buffer(ctx, buf); } if (bps) pdfapp_open_progressive(&gapp, filename, 0, bps); else pdfapp_open(&gapp, filename, 0); while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } fz_free_argv(argc, argv); do_close(&gapp); return 0; }
int main(int argc, char **argv) { int c; int len; char buf[128]; KeySym keysym; int oldx = 0; int oldy = 0; int resolution = -1; int pageno = 1; fd_set fds; int width = -1; int height = -1; fz_context *ctx; struct timeval tmo_at; struct timeval now; struct timeval tmo; struct timeval *timeout; struct timeval tmo_advance_delay; ctx = fz_new_context(NULL, NULL, FZ_STORE_DEFAULT); if (!ctx) { fprintf(stderr, "cannot initialise context\n"); exit(1); } while ((c = fz_getopt(argc, argv, "p:r:b:")) != -1) { switch (c) { case 'p': password = fz_optarg; break; case 'r': resolution = atoi(fz_optarg); break; case 'b': fz_set_aa_level(ctx, atoi(fz_optarg)); break; default: usage(); } } if (argc - fz_optind == 0) usage(); filename = argv[fz_optind++]; if (argc - fz_optind == 1) pageno = atoi(argv[fz_optind++]); pdfapp_init(ctx, &gapp); winopen(); if (resolution == -1) resolution = winresolution(); if (resolution < MINRES) resolution = MINRES; if (resolution > MAXRES) resolution = MAXRES; gapp.transitions_enabled = 1; gapp.scrw = DisplayWidth(xdpy, xscr); gapp.scrh = DisplayHeight(xdpy, xscr); gapp.resolution = resolution; gapp.pageno = pageno; pdfapp_open(&gapp, filename, 0); FD_ZERO(&fds); signal(SIGHUP, signal_handler); tmo_at.tv_sec = 0; tmo_at.tv_usec = 0; while (!closing) { while (!closing && XPending(xdpy) && !transition_dirty) { 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; } width = xevt.xconfigure.width; height = xevt.xconfigure.height; break; case KeyPress: len = XLookupString(&xevt.xkey, buf, sizeof buf, &keysym, NULL); if (!gapp.isediting) switch (keysym) { case XK_Escape: len = 1; buf[0] = '\033'; break; case XK_Up: len = 1; buf[0] = 'k'; break; case XK_Down: len = 1; buf[0] = 'j'; break; case XK_Left: len = 1; buf[0] = 'b'; break; case XK_Right: len = 1; buf[0] = ' '; break; case XK_Page_Up: len = 1; buf[0] = ','; break; case XK_Page_Down: len = 1; buf[0] = '.'; break; } if (xevt.xkey.state & ControlMask && keysym == XK_c) docopy(&gapp, XA_CLIPBOARD); else if (len) onkey(buf[0]); onmouse(oldx, oldy, 0, 0, 0); break; case MotionNotify: oldx = xevt.xmotion.x; oldy = xevt.xmotion.y; onmouse(xevt.xmotion.x, xevt.xmotion.y, 0, xevt.xmotion.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; case ClientMessage: if (xevt.xclient.format == 32 && xevt.xclient.data.l[0] == WM_DELETE_WINDOW) closing = 1; break; } } if (closing) continue; if (width != -1 || height != -1) { pdfapp_onresize(&gapp, width, height); width = -1; height = -1; } if (dirty || dirtysearch) { if (dirty) winblit(&gapp); else if (dirtysearch) winblitsearch(&gapp); dirty = 0; transition_dirty = 0; dirtysearch = 0; pdfapp_postblit(&gapp); } if (showingpage && !tmo_at.tv_sec && !tmo_at.tv_usec) { tmo.tv_sec = 2; tmo.tv_usec = 0; gettimeofday(&now, NULL); timeradd(&now, &tmo, &tmo_at); } if (XPending(xdpy) || transition_dirty) continue; timeout = NULL; if (tmo_at.tv_sec || tmo_at.tv_usec) { gettimeofday(&now, NULL); timersub(&tmo_at, &now, &tmo); if (tmo.tv_sec <= 0) { tmo_at.tv_sec = 0; tmo_at.tv_usec = 0; timeout = NULL; showingpage = 0; winrepaint(&gapp); } else timeout = &tmo; } if (advance_scheduled) { gettimeofday(&now, NULL); timersub(&tmo_advance, &now, &tmo_advance_delay); if (tmo_advance_delay.tv_sec <= 0) { /* Too late already */ onkey(' '); onmouse(oldx, oldy, 0, 0, 0); advance_scheduled = 0; } else if (timeout == NULL) { timeout = &tmo_advance_delay; } else { struct timeval tmp; timersub(&tmo_advance_delay, timeout, &tmp); if (tmp.tv_sec < 0) { timeout = &tmo_advance_delay; } } } FD_SET(x11fd, &fds); if (select(x11fd + 1, &fds, NULL, NULL, timeout) < 0) { if (reloading) { winreloadfile(&gapp); reloading = 0; } } if (!FD_ISSET(x11fd, &fds)) { if (timeout == &tmo_advance_delay) { onkey(' '); onmouse(oldx, oldy, 0, 0, 0); advance_scheduled = 0; } else { tmo_at.tv_sec = 0; tmo_at.tv_usec = 0; timeout = NULL; showingpage = 0; winrepaint(&gapp); } } } cleanup(&gapp); return 0; }
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) { int argc; LPWSTR *argv = CommandLineToArgvW(GetCommandLineW(), &argc); char argv0[256]; MSG msg; int code; fz_context *ctx; int arg; int bps = 0; ctx = fz_new_context(NULL, NULL, FZ_STORE_DEFAULT); if (!ctx) { fprintf(stderr, "cannot initialise context\n"); exit(1); } pdfapp_init(ctx, &gapp); GetModuleFileNameA(NULL, argv0, sizeof argv0); install_app(argv0); winopen(); arg = 1; while (arg < argc) { if (!wcscmp(argv[arg], L"-p")) { if (arg+1 < argc) bps = _wtoi(argv[++arg]); else bps = 4096; } else break; arg++; } if (arg < argc) { wcscpy(wbuf, argv[arg]); } else { if (!winfilename(wbuf, nelem(wbuf))) exit(0); } code = WideCharToMultiByte(CP_UTF8, 0, wbuf, -1, filename, sizeof filename, NULL, NULL); if (code == 0) winerror(&gapp, "cannot convert filename to utf-8"); if (bps) pdfapp_open_progressive(&gapp, filename, 0, bps); else pdfapp_open(&gapp, filename, 0); while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } do_close(&gapp); fz_free_context(ctx); return 0; }
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; }
int main(int argc, char **argv) { int c; int len; char buf[128]; KeySym keysym; int oldx = 0; int oldy = 0; int resolution = 72; int pageno = 1; int pagemark = 0; int accelerate = 1; int fd; fd_set fds; int width = -1; int height = -1; while ((c = fz_getopt(argc, argv, "p:r:b:A")) != -1) { switch (c) { case 'p': password = fz_optarg; break; case 'r': resolution = atoi(fz_optarg); break; case 'A': accelerate = 0; break; case 'b': fz_set_aa_level(atoi(fz_optarg)); break; default: usage(); } } if (resolution < MINRES) resolution = MINRES; if (resolution > MAXRES) resolution = MAXRES; if (argc - fz_optind == 0) usage(); if (accelerate) fz_accelerate(); filename = argv[fz_optind++]; winopen(); pdfapp_init(&gapp); gapp.scrw = DisplayWidth(xdpy, xscr); gapp.scrh = DisplayHeight(xdpy, xscr); gapp.resolution = resolution; if (argc - fz_optind > 1) pageno = atoi(argv[fz_optind++]); gapp.pageno = pageno; fd = open(filename, O_BINARY | O_RDONLY, 0666); if (fd < 0) winerror(&gapp, fz_throw("cannot open file '%s'", filename)); pdfapp_open(&gapp, filename, fd, 0); if (pdfapp_calcfilehash(&gapp, fd)) { pdfapp_getmarkfile(&gapp); pagemark = pdfapp_getpgmark(&gapp); if (pagemark > 0) { if (pagemark <= gapp.pagecount) { gapp.pageno = pagemark; pdfapp_showpage(&gapp, 1, 1, 1); } else pdfapp_closemarkfile(&gapp); } } FD_ZERO(&fds); FD_SET(x11fd, &fds); signal(SIGHUP, signal_handler); atexit(exit_cb); while (!closing) { 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; } width = xevt.xconfigure.width; height = xevt.xconfigure.height; break; case KeyPress: len = XLookupString(&xevt.xkey, buf, sizeof buf, &keysym, NULL); if (!gapp.isediting) switch (keysym) { case XK_Escape: len = 1; buf[0] = '\033'; break; case XK_Up: len = 1; buf[0] = 'k'; break; case XK_Down: len = 1; buf[0] = 'j'; break; case XK_Left: len = 1; buf[0] = 'b'; break; case XK_Right: len = 1; buf[0] = ' '; break; case XK_Page_Up: len = 1; buf[0] = ','; break; case XK_Page_Down: len = 1; buf[0] = '.'; break; } if (len) onkey(buf[0]); onmouse(oldx, oldy, 0, 0, 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; case ClientMessage: if (xevt.xclient.format == 32 && xevt.xclient.data.l[0] == WM_DELETE_WINDOW) closing = 1; break; } } while (!closing && XPending(xdpy)); if (closing) continue; if (width != -1 || height != -1) { pdfapp_onresize(&gapp, width, height); width = -1; height = -1; } if (dirty || dirtysearch) { if (dirty) winblit(&gapp); else if (dirtysearch) winblitsearch(&gapp); dirty = 0; dirtysearch = 0; } if (XPending(xdpy)) continue; if (select(x11fd + 1, &fds, NULL, NULL, NULL) < 0) { if (reloading) { winreloadfile(&gapp); reloading = 0; } } } pdfapp_close(&gapp); XDestroyWindow(xdpy, xwin); XFreePixmap(xdpy, xicon); XFreeCursor(xdpy, xcwait); XFreeCursor(xdpy, xchand); XFreeCursor(xdpy, xcarrow); XFreeGC(xdpy, xgc); XCloseDisplay(xdpy); return 0; }
int main(int argc, char** argv) { int result; int fd; fz_context *ctx; char buf[10]; int c; int pagewidth, pageheight; result = SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER); if(result != 0) { printf("Could not init SDL: %s\n", SDL_GetError()); exit(1); } PDL_Init(0); PDL_SetOrientation(PDL_ORIENTATION_0); PDL_RegisterJSHandler("flipPage",flip_page); PDL_RegisterJSHandler("panPage",pan_page); // PDL_RegisterJSHandler("pause", pause); // PDL_RegisterJSHandler("resume", resume); PDL_JSRegistrationComplete(); PDL_CallJS("ready", NULL, 0); memset(&pitch_action, 0, sizeof(PDF_Pitch_t)); //gesture_data = (Gesture_Event *)malloc(sizeof(Gesture_Event)); memset(&gesture_data, 0, sizeof(Gesture_Event)); pitch_action.scale = 1.0; Surface = SDL_SetVideoMode(0, 0, 0, SDL_SWSURFACE); SDL_FillRect(Surface, NULL, 0xF0F0F); SDL_Flip(Surface); ctx = fz_new_context(NULL, FZ_STORE_DEFAULT); pdfapp_init(ctx, &app); app.scrw = 1024; app.scrh = 768; app.pageno = 10; src.x = 20; src.y = 20; src.w = 1024; src.h = 768; dest.x = 0; dest.y = 0; fd = open(argv[1], O_RDONLY, 0666); if (fd < 0) { printf("cannot open file\n"); fz_throw(app.ctx, "cannot open file '%s'", argv[1]); } pdfapp_open(&app,argv[1],fd,0); //app.rotate = 90 * 3; pdfapp_showpage(&app,1,1,1); draw_pdf(); #if 0 content = SDL_CreateRGBSurfaceFrom(app.image->samples, app.image->w, app.image->h, 32, app.image->w * 4, 0x00, 0x00, 0x00, 0x00); SDL_BlitSurface(content,NULL, Surface, NULL); SDL_Flip(Surface); #endif SDL_Event Event; Event.type = SDL_NOEVENT; int temp1, temp2; do { if (Paused) { SDL_WaitEvent(&Event); if (Event.type == SDL_ACTIVEEVENT) { if ((Event.active.state & SDL_APPACTIVE) && (Event.active.gain == 1)) { Paused = SDL_FALSE; } } } else { while(SDL_PollEvent(&Event)) { handle_events(Event); // switch (Event.type) { #if 0 case SDL_MOUSEBUTTONDOWN: fingerNum = Event.button.which + 1; mouse_state = SDL_MOUSEBUTTONDOWN; printf("%2d fingers touch down\n",Event.button.which); break; case SDL_MOUSEBUTTONUP: if(fingerNum == 2) { memset(&pitch_action, 0, sizeof(PDF_Pitch_t)-sizeof(float32)); pinch = SDL_FALSE; //pitch_action.scale = 1.0; } if(fingerNum == 1 && mouse_state == SDL_MOUSEBUTTONDOWN) { if(Event.button.x > (app.image->h / 2)) { buf[0] = '.'; } else { buf[0] = ','; } pdfapp_onkey(&app,buf[0]); printf("Flip page\n"); draw_pdf(); } // printf("%2d fingers touching\n",fingerNum); mouse_state = NULL; printf("%2d fingers touch up\n",Event.button.which); if(fingerNum > 0) fingerNum -= 1; break; case SDL_MOUSEMOTION: if(fingerNum == 2) { if(Event.motion.which == 0) { pitch_action.x0 = Event.motion.x; pitch_action.y0 = Event.motion.y; } if(Event.motion.which == 1) { pitch_action.x1 = Event.motion.x; pitch_action.y1 = Event.motion.y; } pitch_action.cx = (pitch_action.x0 + pitch_action.x1)/2; pitch_action.cy = (pitch_action.y0 + pitch_action.y1)/2; temp1 = pow((pitch_action.x0 - pitch_action.x1),2); temp2 = pow((pitch_action.y0 - pitch_action.y1),2); pitch_action.distance1 = sqrt(temp1 + temp2); pitch_action.offset = pitch_action.distance1 - pitch_action.distance0; pitch_action.distance0 = pitch_action.distance1; pitch_action.offset = (int)pitch_action.offset; // printf("cx:%4d, cy:%4d, offset:%4f \n",pitch_action.cx, // pitch_action.cy, pitch_action.offset); #if 1 if(pitch_action.offset > 0 && pitch_action.offset < 5) { #if 0 app.resolution *= (Uint16)pitch_action.offset; if (app.resolution > MAXRES) app.resolution = MAXRES; pdfapp_showpage(&app, 0, 1, 0); draw_pdf(); #endif pinch = SDL_TRUE; pitch_action.scale += 0.008; if(pitch_action.scale > 2) pitch_action.scale = 2; printf("-------------------------------------pinch out\n"); } else if(pitch_action.offset < 0) { #if 0 app.resolution /=(Uint16)( abs(pitch_action.offset)); if (app.resolution < MINRES) app.resolution = MINRES; pdfapp_showpage(&app, 0, 1, 0); draw_pdf(); #endif pinch = SDL_TRUE; pitch_action.scale -= 0.008; if(pitch_action.scale < 0.9) pitch_action.scale = 0.9; printf("----------------------------------pinch in\n"); } else { pinch = SDL_FALSE; } #endif } //printf("which: %d, x = %4d, y = %4d \n",Event.motion.which, // Event.motion.x, Event.motion.y); mouse_state = SDL_MOUSEMOTION; printf("Finger move \n"); break; #endif /* // handle deactivation by pausing our animation case SDL_ACTIVEEVENT: if ((Event.active.state & SDL_APPACTIVE) && (Event.active.gain == 0)) { Paused = SDL_TRUE; } break; default: break; // } */ } #if 1 if(pinch) { #if 1 if(pitch_action.scale == 1.4) { app.resolution = 72 * 1.4; pdfapp_showpage(&app,0,1,1); draw_pdf(); printf("----increase pdf resolution \n"); } if(pitch_action.scale == 1) { app.resolution = 72; pdfapp_showpage(&app,0,1,1); draw_pdf(); } content = zoomSurface(page_copy,pitch_action.scale,pitch_action.scale,SMOOTHING_OFF); SDL_FillRect(Surface, NULL, SDL_MapRGBA(Surface->format, 45, 45, 45, 0)); SDL_BlitSurface(content,NULL, Surface, NULL); SDL_Flip(Surface); SDL_FreeSurface(content); #else app.resolution *= pitch_action.scale; if(app.resolution > MAXRES) app.resolution = MAXRES; if (app.resolution < MINRES) app.resolution = MINRES; pdfapp_showpage(&app, 0, 1, 1); draw_pdf(); #endif } #endif SDL_Delay(0); } }while(Event.type != SDL_QUIT); //cleanup SDL_FreeSurface(content); SDL_FreeSurface(Surface); pdfapp_close(&app); PDL_Quit(); SDL_Quit(); return 0; }