int pdf_resolve_link(fz_context *ctx, pdf_document *doc, const char *uri, float *xp, float *yp) { if (uri && uri[0] == '#') { int page = fz_atoi(uri + 1) - 1; if (xp || yp) { const char *x = strchr(uri, ','); const char *y = strrchr(uri, ','); if (x && y) { pdf_obj *obj; fz_matrix ctm; fz_point p; p.x = x ? fz_atoi(x + 1) : 0; p.y = y ? fz_atoi(y + 1) : 0; obj = pdf_lookup_page_obj(ctx, doc, page); pdf_page_obj_transform(ctx, obj, NULL, &ctm); fz_transform_point(&p, &ctm); if (xp) *xp = p.x; if (yp) *yp = p.y; } } return page; } fz_warn(ctx, "unknown link uri '%s'", uri); return -1; }
static void pdfportfolio_extract(int argc, char **argv) { int entry; const char *filename; fz_buffer *buf; unsigned char *data; int len; FILE *file; if (fz_optind > argc-2) usage(); entry = fz_atoi(argv[fz_optind++]); filename = argv[fz_optind++]; buf = pdf_portfolio_entry(ctx, doc, entry); len = fz_buffer_storage(ctx, buf, &data); file = fopen(filename, "wb"); if (file == NULL) { fprintf(stderr, "Failed to open '%s' for writing\n", filename); exit(1); } fwrite(data, 1, len, file); fclose(file); fz_drop_buffer(ctx, buf); }
/* * compute decimal integer m, exp such that: * f = m*10^exp * m is as short as possible with losing exactness * assumes special cases (NaN, +Inf, -Inf) have been handled. */ void fz_ftoa(float f, char *s, int *exp, int *neg, int *ns) { char buf[40], *p = buf; int i; for (i = 0; i < 10; ++i) { sprintf(buf, "%.*e", i, f); if (fz_atof(buf) == f) break; } if (*p == '-') { *neg = 1; ++p; } else *neg = 0; *ns = 0; while (*p && *p != 'e') { if (*p >= '0' && *p <= '9') { *ns += 1; *s++ = *p; } ++p; } *exp = fz_atoi(p+1) - (*ns) + 1; }
int pdf_resolve_link(fz_context *ctx, pdf_document *doc, const char *uri, float *xp, float *yp) { if (uri && uri[0] == '#') { int page = fz_atoi(uri + 1) - 1; if (xp || yp) { const char *x = strchr(uri, ','); const char *y = strrchr(uri, ','); if (x && y) { if (xp) *xp = x ? fz_atoi(x + 1) : 0; if (yp) *yp = y ? fz_atoi(y + 1) : 0; } } return page; } fz_warn(ctx, "unknown link uri '%s'", uri); return -1; }
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; }