static void pdfapp_loadpage_pdf(pdfapp_t *app) { pdf_page *page; fz_error error; fz_device *mdev; error = pdf_load_page(&page, app->xref, app->pageno - 1); if (error) pdfapp_error(app, error); app->page_bbox = page->mediabox; app->page_rotate = page->rotate; app->page_links = page->links; page->links = NULL; /* Create display list */ app->page_list = fz_new_display_list(); mdev = fz_new_list_device(app->page_list); error = pdf_run_page(app->xref, page, mdev, fz_identity); if (error) { error = fz_rethrow(error, "cannot draw page %d in '%s'", app->pageno, app->doctitle); pdfapp_error(app, error); } fz_free_device(mdev); pdf_free_page(page); pdf_age_store(app->xref->store, 3); }
static void pdfapp_loadpage_xps(pdfapp_t *app) { xps_page *page; fz_device *mdev; fz_error error; error = xps_load_page(&page, app->xps, app->pageno - 1); if (error) pdfapp_error(app, fz_rethrow(error, "cannot load page %d in file '%s'", app->pageno, app->doctitle)); app->page_bbox.x0 = 0; app->page_bbox.y0 = 0; app->page_bbox.x1 = page->width; app->page_bbox.y1 = page->height; app->page_rotate = 0; app->page_links = NULL; /* Create display list */ app->page_list = fz_new_display_list(); mdev = fz_new_list_device(app->page_list); app->xps->dev = mdev; xps_parse_fixed_page(app->xps, fz_identity, page); app->xps->dev = NULL; fz_free_device(mdev); xps_free_page(app->xps, page); }
void pdfapp_init(pdfapp_t *app) { #if 0 fz_error error; memset(app, 0, sizeof(pdfapp_t)); error = fz_newrenderer(&app->rast, pdf_devicergb, 0, 1024 * 512); if (error) pdfapp_error(app, error); #else memset(app, 0, sizeof(pdfapp_t)); #endif }
void pdfapp_init(pdfapp_t *app) { fz_error *error; memset(app, 0, sizeof(pdfapp_t)); error = fz_newrenderer(&app->rast, pdf_devicergb, 0, 1024 * 512); if (error) pdfapp_error(app, error); app->scrw = 640; app->scrh = 480; }
void pdfapp_oncopy(pdfapp_t *app, unsigned short *ucsbuf, int ucslen) { fz_error *error; pdf_textline *line, *ln; int y, c; int i, p; int bx0, bx1, by0, by1; int x0 = app->image->x + app->selr.x0 - app->panx; int x1 = app->image->x + app->selr.x1 - app->panx; int y0 = app->image->y + app->selr.y0 - app->pany; int y1 = app->image->y + app->selr.y1 - app->pany; error = pdf_loadtextfromtree(&line, app->page->tree, pdfapp_viewctm(app)); if (error) pdfapp_error(app, error); p = 0; for (ln = line; ln; ln = ln->next) { y = y0 - 1; for (i = 0; i < ln->len; i++) { bx0 = ln->text[i].bbox.x0; bx1 = ln->text[i].bbox.x1; by0 = ln->text[i].bbox.y0; by1 = ln->text[i].bbox.y1; c = ln->text[i].c; if (c < 32) c = '?'; if (bx1 >= x0 && bx0 <= x1 && by1 >= y0 && by0 <= y1) if (p < ucslen - 1) ucsbuf[p++] = c; } if (by1 >= y0 && by0 <= y1) { #ifdef WIN32 if (p < ucslen - 1) ucsbuf[p++] = '\r'; #endif if (p < ucslen - 1) ucsbuf[p++] = '\n'; } } ucsbuf[p] = 0; pdf_droptextline(line); }
static void pdfapp_open_xps(pdfapp_t *app, char *filename, int fd) { fz_error error; fz_stream *file; file = fz_open_fd(fd); error = xps_open_stream(&app->xps, file); if (error) pdfapp_error(app, fz_rethrow(error, "cannot open document '%s'", filename)); fz_close(file); app->doctitle = filename; app->pagecount = xps_count_pages(app->xps); }
static void pdfapp_open_pdf(pdfapp_t *app, char *filename, int fd) { fz_error error; fz_stream *file; char *password = ""; fz_obj *obj; fz_obj *info; /* * Open PDF and load xref table */ file = fz_open_fd(fd); error = pdf_open_xref_with_stream(&app->xref, file, NULL); if (error) pdfapp_error(app, fz_rethrow(error, "cannot open document '%s'", filename)); fz_close(file); /* * Handle encrypted PDF files */ if (pdf_needs_password(app->xref)) { int okay = pdf_authenticate_password(app->xref, password); while (!okay) { password = winpassword(app, filename); if (!password) exit(1); okay = pdf_authenticate_password(app->xref, password); if (!okay) pdfapp_warn(app, "Invalid password."); } } /* * Load meta information */ app->outline = pdf_load_outline(app->xref); app->doctitle = filename; if (strrchr(app->doctitle, '\\')) app->doctitle = strrchr(app->doctitle, '\\') + 1; if (strrchr(app->doctitle, '/')) app->doctitle = strrchr(app->doctitle, '/') + 1; info = fz_dict_gets(app->xref->trailer, "Info"); if (info) { obj = fz_dict_gets(info, "Title"); if (obj) app->doctitle = pdf_to_utf8(obj); } /* * Start at first page */ error = pdf_load_page_tree(app->xref); if (error) pdfapp_error(app, fz_rethrow(error, "cannot load page tree")); app->pagecount = pdf_count_pages(app->xref); }
void pdfapp_open(pdfapp_t *app, char *filename) { fz_error *error; fz_obj *obj; char *password = ""; /* * Open PDF and load xref table */ app->filename = filename; error = pdf_newxref(&app->xref); if (error) pdfapp_error(app, error); error = pdf_loadxref(app->xref, filename); if (error) { if (!strncmp(error->msg, "ioerror", 7)) pdfapp_error(app, error); pdfapp_warn(app, "There was a problem with file \"%s\".\n" "It may be corrupted, or generated by broken software.\n\n" "%s\n\nTrying to continue anyway...", filename, error->msg); error = pdf_repairxref(app->xref, filename); if (error) pdfapp_error(app, error); } /* * Handle encrypted PDF files */ error = pdf_decryptxref(app->xref); if (error) pdfapp_error(app, error); if (app->xref->crypt) { error = pdf_setpassword(app->xref->crypt, password); while (error) { fz_droperror(error); password = winpassword(app, filename); if (!password) exit(1); error = pdf_setpassword(app->xref->crypt, password); if (error) pdfapp_warn(app, "Invalid password."); } } /* * Load page tree */ error = pdf_loadpagetree(&app->pages, app->xref); if (error) pdfapp_error(app, error); /* * Load meta information * TODO: move this into mupdf library */ obj = fz_dictgets(app->xref->trailer, "Root"); if (!obj) pdfapp_error(app, fz_throw("syntaxerror: missing Root object")); error = pdf_loadindirect(&app->xref->root, app->xref, obj); if (error) pdfapp_error(app, error); obj = fz_dictgets(app->xref->trailer, "Info"); if (obj) { error = pdf_loadindirect(&app->xref->info, app->xref, obj); if (error) pdfapp_error(app, error); } error = pdf_loadnametrees(app->xref); if (error) pdfapp_error(app, error); error = pdf_loadoutline(&app->outline, app->xref); if (error) pdfapp_error(app, error); app->doctitle = filename; if (strrchr(app->doctitle, '\\')) app->doctitle = strrchr(app->doctitle, '\\') + 1; if (strrchr(app->doctitle, '/')) app->doctitle = strrchr(app->doctitle, '/') + 1; if (app->xref->info) { obj = fz_dictgets(app->xref->info, "Title"); if (obj) { error = pdf_toutf8(&app->doctitle, obj); if (error) pdfapp_error(app, error); } } /* * Start at first page */ app->shrinkwrap = 1; if (app->pageno < 1) app->pageno = 1; if (app->zoom <= 0.0) app->zoom = 1.0; app->rotate = 0; app->panx = 0; app->pany = 0; pdfapp_showpage(app, 1, 1); }
void pdfapp_showpage(pdfapp_t *app, int loadpage, int drawpage) { char buf[256]; fz_error *error; fz_matrix ctm; fz_rect bbox; fz_obj *obj; if (loadpage) { wincursor(app, WAIT); if (app->page) pdf_droppage(app->page); app->page = nil; obj = pdf_getpageobject(app->pages, app->pageno - 1); error = pdf_loadpage(&app->page, app->xref, obj); if (error) pdfapp_error(app, error); sprintf(buf, "%s - %d/%d", app->doctitle, app->pageno, pdf_getpagecount(app->pages)); wintitle(app, buf); } if (drawpage) { wincursor(app, WAIT); if (app->image) fz_droppixmap(app->image); app->image = nil; ctm = pdfapp_viewctm(app); bbox = fz_transformaabb(ctm, app->page->mediabox); error = fz_rendertree(&app->image, app->rast, app->page->tree, ctm, fz_roundrect(bbox), 1); if (error) pdfapp_error(app, error); winconvert(app, app->image); } pdfapp_panview(app, app->panx, app->pany); if (app->shrinkwrap) { int w = app->image->w; int h = app->image->h; if (app->winw == w) app->panx = 0; if (app->winh == h) app->pany = 0; if (w > app->scrw * 90 / 100) w = app->scrw * 90 / 100; if (h > app->scrh * 90 / 100) h = app->scrh * 90 / 100; if (w != app->winw || h != app->winh) winresize(app, w, h); } winrepaint(app); wincursor(app, ARROW); }
void pdfapp_open(pdfapp_t *app, char *filename) { #if 0 fz_error error; fz_obj *obj; char *password = ""; #else fz_error error; fz_stream *file; char *password = ""; fz_obj *obj; fz_obj *info; int fd; fd = open(filename, O_BINARY | O_RDONLY, 0666); if (fd < 0) fprintf(stderr, "error, file %s does not exist\n", filename); #endif /* * Open PDF and load xref table */ app->filename = filename; #if 0 app->xref = pdf_newxref(); error = pdf_loadxref(app->xref, filename); if (error) { fz_catch(error, "trying to air"); error = pdf_repairxref(app->xref, filename); if (error) pdfapp_error(app, error); } error = pdf_decryptxref(app->xref); if (error) pdfapp_error(app, error); #else file = fz_open_fd(fd); error = pdf_open_xref_with_stream(&app->xref, file, NULL); if (error) pdfapp_error(app, fz_rethrow(error, "cannot open document '%s'", filename)); fz_close(file); #endif /* * Handle encrypted PDF files */ if (pdf_needs_password(app->xref)) { int okay = pdf_authenticate_password(app->xref, password); while (!okay) { //password = winpassword(app, filename); if (!password) exit(1); okay = pdf_authenticate_password(app->xref, password); if (!okay) pdfapp_warn(app, "Invalid password."); } } /* * Load meta information * TODO: move this into mupdf library */ #if 0 obj = fz_dictgets(app->xref->trailer, "Root"); app->xref->root = fz_resolveindirect(obj); if (!app->xref->root) pdfapp_error(app, fz_throw("syntaxerror: missing Root object")); fz_keepobj(app->xref->root); obj = fz_dictgets(app->xref->trailer, "Info"); app->xref->info = fz_resolveindirect(obj); if (!app->xref->info) pdfapp_warn(app, "Could not load PDF meta information."); if (app->xref->info) fz_keepobj(app->xref->info); /*app->outline = pdf_loadoutline(app->xref);*/ app->doctitle = filename; if (strrchr(app->doctitle, '\\')) app->doctitle = strrchr(app->doctitle, '\\') + 1; if (strrchr(app->doctitle, '/')) app->doctitle = strrchr(app->doctitle, '/') + 1; if (app->xref->info) { obj = fz_dictgets(app->xref->info, "Title"); if (obj) { app->doctitle = pdf_toutf8(obj); } } #else app->outline = pdf_load_outline(app->xref); app->doctitle = filename; if (strrchr(app->doctitle, '\\')) app->doctitle = strrchr(app->doctitle, '\\') + 1; if (strrchr(app->doctitle, '/')) app->doctitle = strrchr(app->doctitle, '/') + 1; info = fz_dict_gets(app->xref->trailer, "Info"); if (info) { obj = fz_dict_gets(info, "Title"); if (obj) app->doctitle = pdf_to_utf8(obj); } #endif /* * Start at first page */ #if 0 app->pagecount = pdf_getpagecount(app->xref); #else error = pdf_load_page_tree(app->xref); if (error) pdfapp_error(app, fz_rethrow(error, "cannot load page tree")); app->pagecount = pdf_count_pages(app->xref); #endif app->rotate = 0; }
void pdfapp_open(pdfapp_t *app, char *filename) { fz_obj *obj; fz_obj *info; char *password = ""; /* * Open PDF and load xref table */ app->filename = filename; app->xref = pdf_openxref(filename); if (!app->xref) pdfapp_error(app, -1); /* * Handle encrypted PDF files */ if (pdf_needspassword(app->xref)) { int okay = pdf_authenticatepassword(app->xref, password); while (!okay) { password = winpassword(app, filename); if (!password) exit(1); okay = pdf_authenticatepassword(app->xref, password); if (!okay) pdfapp_warn(app, "Invalid password."); } } /* * Load meta information */ app->outline = pdf_loadoutline(app->xref); app->doctitle = filename; if (strrchr(app->doctitle, '\\')) app->doctitle = strrchr(app->doctitle, '\\') + 1; if (strrchr(app->doctitle, '/')) app->doctitle = strrchr(app->doctitle, '/') + 1; info = fz_dictgets(app->xref->trailer, "Info"); if (info) { obj = fz_dictgets(info, "Title"); if (obj) app->doctitle = pdf_toutf8(obj); } /* * Start at first page */ app->pagecount = pdf_getpagecount(app->xref); app->shrinkwrap = 1; if (app->pageno < 1) app->pageno = 1; if (app->zoom < 0.1) app->zoom = 0.1; if (app->zoom > 3.0) app->zoom = 3.0; app->rotate = 0; app->panx = 0; app->pany = 0; //code change by kakai //highlight color settings kno_setHighlightColor(app, 0x00ffff00); //code change by kakai pdfapp_showpage(app, 1, 1); }
static void pdfapp_showpage(pdfapp_t *app, int loadpage, int drawpage) { char buf[256]; fz_error error; fz_device *idev, *tdev, *mdev; fz_displaylist *list; fz_matrix ctm; fz_bbox bbox; fz_obj *obj; if (loadpage) { wincursor(app, WAIT); if (app->page) pdf_droppage(app->page); app->page = nil; //code change by kakai kno_clearselect(app); //code change by kakai pdf_flushxref(app->xref, 0); obj = pdf_getpageobject(app->xref, app->pageno); error = pdf_loadpage(&app->page, app->xref, obj); if (error) pdfapp_error(app, error); sprintf(buf, "%s - %d/%d", app->doctitle, app->pageno, app->pagecount); wintitle(app, buf); } if (drawpage) { wincursor(app, WAIT); ctm = pdfapp_viewctm(app); bbox = fz_roundrect(fz_transformrect(ctm, app->page->mediabox)); list = fz_newdisplaylist(); mdev = fz_newlistdevice(list); error = pdf_runcontentstream(mdev, fz_identity(), app->xref, app->page->resources, app->page->contents); if (error) pdfapp_error(app, error); fz_freedevice(mdev); if (app->image) fz_droppixmap(app->image); app->image = fz_newpixmapwithrect(pdf_devicergb, bbox); fz_clearpixmap(app->image, 0xFF); idev = fz_newdrawdevice(app->cache, app->image); fz_executedisplaylist(list, idev, ctm); fz_freedevice(idev); if (app->text) fz_freetextspan(app->text); app->text = fz_newtextspan(); tdev = fz_newtextdevice(app->text); fz_executedisplaylist(list, tdev, ctm); fz_freedevice(tdev); fz_freedisplaylist(list); //code change by kakai kno_allocselection(app); kno_applyselect(app); //code change by kakai winconvert(app, app->image); } pdfapp_panview(app, app->panx, app->pany); if (app->shrinkwrap) { int w = app->image->w; int h = app->image->h; if (app->winw == w) app->panx = 0; if (app->winh == h) app->pany = 0; if (w > app->scrw * 90 / 100) w = app->scrw * 90 / 100; if (h > app->scrh * 90 / 100) h = app->scrh * 90 / 100; if (w != app->winw || h != app->winh) winresize(app, w, h); } winrepaint(app); wincursor(app, ARROW); }