void handlekey(int c) { if (timer_pending) killtimer(&gapp); if (GetCapture() == hwndview) return; if (justcopied) { justcopied = 0; winrepaint(&gapp); } /* translate VK into ASCII equivalents */ if (c > 256) { switch (c - 256) { case VK_F1: c = '?'; break; case VK_ESCAPE: c = '\033'; break; case VK_DOWN: c = 'j'; break; case VK_UP: c = 'k'; break; case VK_LEFT: c = 'b'; break; case VK_RIGHT: c = ' '; break; case VK_PRIOR: c = ','; break; case VK_NEXT: c = '.'; break; } } pdfapp_onkey(&gapp, c); winrepaint(&gapp); }
static void onkey(int c, int modifiers) { advance_scheduled = 0; if (justcopied) { justcopied = 0; winrepaint(&gapp); } if (!gapp.issearching && c == 'P') { struct timeval now; struct timeval tmo; tmo.tv_sec = 2; tmo.tv_usec = 0; gettimeofday(&now, NULL); timeradd(&now, &tmo, &tmo_at); showingpage = 1; winrepaint(&gapp); return; } pdfapp_onkey(&gapp, c, modifiers); if (gapp.issearching) { showingpage = 0; showingmessage = 0; } }
void handlekey(int c) { if (GetCapture() == hwndview) return; if (justcopied) { justcopied = 0; winrepaint(&gapp); } /* translate VK into ascii equivalents */ switch (c) { case VK_F1: c = '?'; break; case VK_ESCAPE: c = 'q'; break; case VK_DOWN: c = 'd'; break; case VK_UP: c = 'u'; break; case VK_LEFT: c = 'p'; break; case VK_RIGHT: c = 'n'; break; case VK_PRIOR: c = 'b'; break; case VK_NEXT: c = ' '; break; } if (c == 'q') exit(0); else if (c == '?' || c == 'h') help(); else pdfapp_onkey(&gapp, c); }
static void onkey(int c) { if (justcopied) { justcopied = 0; winrepaint(&gapp); } pdfapp_onkey(&gapp, c); }
void onkey(int c) { if (justcopied) { justcopied = 0; winrepaint(&gapp); } if (c == 'q') exit(0); pdfapp_onkey(&gapp, c); }
PDL_bool flip_page(PDL_JSParameters *params) { char *key; if(PDL_GetNumJSParams(params) < 1) { PDL_JSException(params, "Params not ok"); return PDL_TRUE; } key = PDL_GetJSParamString(params,0); pdfapp_onkey(&app,*key); draw_pdf(); return PDL_TRUE; }
static void onkey(int c) { if (justcopied) { justcopied = 0; winrepaint(&gapp); } if (c == 'P') windrawpageno(&gapp); else if (c == 'q') exit(0); else pdfapp_onkey(&gapp, c); }
static void onkey(int c) { advance_scheduled = 0; if (justcopied) { justcopied = 0; winrepaint(&gapp); } if (!gapp.isediting && c == 'P') { showingpage = 1; winrepaint(&gapp); return; } pdfapp_onkey(&gapp, c); }
void pdfapp_onkey(pdfapp_t *app, int c) { int oldpage = app->pageno; enum panning panto = PAN_TO_TOP; int loadpage = 1; if (app->isediting) { int n = strlen(app->search); if (c < ' ') { if (c == '\b' && n > 0) { app->search[n - 1] = 0; winrepaintsearch(app); } if (c == '\n' || c == '\r') { app->isediting = 0; if (n > 0) { winrepaintsearch(app); pdfapp_onkey(app, 'n'); } else winrepaint(app); } if (c == '\033') { app->isediting = 0; winrepaint(app); } } else { if (n + 2 < sizeof app->search) { app->search[n] = c; app->search[n + 1] = 0; winrepaintsearch(app); } } return; } /* * Save numbers typed for later */ if (c >= '0' && c <= '9') { app->number[app->numberlen++] = c; app->number[app->numberlen] = '\0'; } switch (c) { case '?': winhelp(app); break; case 'q': winclose(app); break; /* * Zoom and rotate */ case '+': case '=': app->resolution *= ZOOMSTEP; if (app->resolution > MAXRES) app->resolution = MAXRES; pdfapp_showpage(app, 0, 1, 1); break; case '-': app->resolution /= ZOOMSTEP; if (app->resolution < MINRES) app->resolution = MINRES; pdfapp_showpage(app, 0, 1, 1); break; case 'L': app->rotate -= 90; pdfapp_showpage(app, 0, 1, 1); break; case 'R': app->rotate += 90; pdfapp_showpage(app, 0, 1, 1); break; case 'c': app->grayscale ^= 1; pdfapp_showpage(app, 0, 1, 1); break; #ifndef NDEBUG case 'a': app->rotate -= 15; pdfapp_showpage(app, 0, 1, 1); break; case 's': app->rotate += 15; pdfapp_showpage(app, 0, 1, 1); break; #endif /* * Pan view, but dont need to repaint image */ case 'w': app->shrinkwrap = 1; app->panx = app->pany = 0; pdfapp_showpage(app, 0, 0, 1); break; case 'h': app->panx += app->image->w / 10; pdfapp_showpage(app, 0, 0, 1); break; case 'j': app->pany -= app->image->h / 10; pdfapp_showpage(app, 0, 0, 1); break; case 'k': app->pany += app->image->h / 10; pdfapp_showpage(app, 0, 0, 1); break; case 'l': app->panx -= app->image->w / 10; pdfapp_showpage(app, 0, 0, 1); break; /* * Page navigation */ case 'g': case '\n': case '\r': if (app->numberlen > 0) app->pageno = atoi(app->number); else app->pageno = 1; break; case 'G': app->pageno = app->pagecount; break; case 'm': if (app->numberlen > 0) { int idx = atoi(app->number); if (idx >= 0 && idx < nelem(app->marks)) app->marks[idx] = app->pageno; } else { if (app->histlen + 1 == 256) { memmove(app->hist, app->hist + 1, sizeof(int) * 255); app->histlen --; } app->hist[app->histlen++] = app->pageno; } break; case 't': if (app->numberlen > 0) { int idx = atoi(app->number); if (idx >= 0 && idx < nelem(app->marks)) if (app->marks[idx] > 0) app->pageno = app->marks[idx]; } else if (app->histlen > 0) app->pageno = app->hist[--app->histlen]; break; /* * Back and forth ... */ case ',': panto = PAN_TO_BOTTOM; if (app->numberlen > 0) app->pageno -= atoi(app->number); else app->pageno--; break; case '.': panto = PAN_TO_TOP; if (app->numberlen > 0) app->pageno += atoi(app->number); else app->pageno++; break; case 'b': panto = DONT_PAN; if (app->numberlen > 0) app->pageno -= atoi(app->number); else app->pageno--; break; case ' ': panto = DONT_PAN; if (app->numberlen > 0) app->pageno += atoi(app->number); else app->pageno++; break; case '<': panto = PAN_TO_TOP; app->pageno -= 10; break; case '>': panto = PAN_TO_TOP; app->pageno += 10; break; /* * Reloading the file... */ case 'r': panto = DONT_PAN; oldpage = -1; winreloadfile(app); break; /* * Searching */ case '/': app->isediting = 1; app->search[0] = 0; app->hit = -1; app->hitlen = 0; winrepaintsearch(app); break; case 'n': pdfapp_searchforward(app, &panto); loadpage = 0; break; case 'N': pdfapp_searchbackward(app, &panto); loadpage = 0; break; } if (c < '0' || c > '9') app->numberlen = 0; if (app->pageno < 1) app->pageno = 1; if (app->pageno > app->pagecount) app->pageno = app->pagecount; if (app->pageno != oldpage) { switch (panto) { case PAN_TO_TOP: app->pany = 0; break; case PAN_TO_BOTTOM: app->pany = -2000; break; case DONT_PAN: break; } pdfapp_showpage(app, loadpage, 1, 1); } }
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; }