Ejemplo n.º 1
0
fz_document *
fz_open_document_with_stream(fz_context *ctx, char *magic, fz_stream *stream)
{
	char *ext = strrchr(magic, '.');

	if (ext)
	{
		if (!fz_strcasecmp(ext, ".xps") || !fz_strcasecmp(ext, ".rels"))
			return (fz_document*) xps_open_document_with_stream(ctx, stream);
		if (!fz_strcasecmp(ext, ".cbz") || !fz_strcasecmp(ext, ".zip"))
			return (fz_document*) cbz_open_document_with_stream(ctx, stream);
		if (!fz_strcasecmp(ext, ".pdf"))
			return (fz_document*) pdf_open_document_with_stream(ctx, stream);
	}

	if (!strcmp(magic, "cbz") || !strcmp(magic, "application/x-cbz"))
		return (fz_document*) cbz_open_document_with_stream(ctx, stream);
	if (!strcmp(magic, "xps") || !strcmp(magic, "application/vnd.ms-xpsdocument"))
		return (fz_document*) xps_open_document_with_stream(ctx, stream);
	if (!strcmp(magic, "pdf") || !strcmp(magic, "application/pdf"))
		return (fz_document*) pdf_open_document_with_stream(ctx, stream);

	/* last guess: pdf */
	return (fz_document*) pdf_open_document_with_stream(ctx, stream);
}
Ejemplo n.º 2
0
int open_pdf(fz_context *context, char *filename) {
    fz_stream *file;
    int faulty;
    unsigned int i;
    /* char * s; */

    faulty = 0;

    /* Resolution */

    printf("Opening: %s\n", filename);

    fz_try(context) {
        file = fz_open_file(context, filename);

        doc = (fz_document *) pdf_open_document_with_stream(file);

        /* TODO Password */

        fz_close(file);
    } fz_catch (context) {
        fprintf(stderr, "Cannot open: %s\n", filename);
        faulty = 1;
    }

    if (faulty)
        return faulty;

    /* XXX need error handling */
    pagec = fz_count_pages(doc);
    pages = malloc(sizeof(struct least_page_info) * pagec);

    #if 0
    return 0;
    #endif

    for(i = 0; i < pagec; i++) {
        pages[i].rendering = 0;
        pages[i].texture = 0;
        /* page_to_texture(context, doc, i); */
    }
    page_to_texture(context, doc, 0);

    printf("Done opening\n");
    return 0;
}