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
xps_document *
xps_open_document(fz_context *ctx, const char *filename)
{
	char buf[2048];
	fz_stream *file;
	char *p;
	xps_document *doc;

	if (strstr(filename, "/_rels/.rels") || strstr(filename, "\\_rels\\.rels"))
	{
		fz_strlcpy(buf, filename, sizeof buf);
		p = strstr(buf, "/_rels/.rels");
		if (!p)
			p = strstr(buf, "\\_rels\\.rels");
		*p = 0;
		return xps_open_document_with_directory(ctx, buf);
	}

	file = fz_open_file(ctx, filename);

	fz_try(ctx)
		doc = xps_open_document_with_stream(ctx, file);
	fz_always(ctx)
		fz_drop_stream(ctx, file);
	fz_catch(ctx)
		fz_rethrow_message(ctx, "cannot load document '%s'", filename);

	return doc;
}