summaryrefslogtreecommitdiff
path: root/fitz
diff options
context:
space:
mode:
Diffstat (limited to 'fitz')
-rw-r--r--fitz/doc_document.c58
-rw-r--r--fitz/fitz.h10
2 files changed, 53 insertions, 15 deletions
diff --git a/fitz/doc_document.c b/fitz/doc_document.c
index 1233aeb9..eb50285b 100644
--- a/fitz/doc_document.c
+++ b/fitz/doc_document.c
@@ -5,6 +5,11 @@ extern struct pdf_document *pdf_open_document(fz_context *ctx, char *filename);
extern struct xps_document *xps_open_document(fz_context *ctx, char *filename);
extern struct cbz_document *cbz_open_document(fz_context *ctx, char *filename);
+extern struct pdf_document *pdf_open_document_with_stream(fz_context *ctx, fz_stream *file);
+extern struct xps_document *xps_open_document_with_stream(fz_context *ctx, fz_stream *file);
+extern struct cbz_document *cbz_open_document_with_stream(fz_context *ctx, fz_stream *file);
+
+
static inline int fz_tolower(int c)
{
if (c >= 'A' && c <= 'Z')
@@ -24,25 +29,48 @@ static inline int fz_strcasecmp(char *a, char *b)
}
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);
+}
+
+fz_document *
fz_open_document(fz_context *ctx, char *filename)
{
char *ext = strrchr(filename, '.');
- if (ext && (!fz_strcasecmp(ext, ".xps") || !fz_strcasecmp(ext, ".rels")))
- return (fz_document*) xps_open_document(ctx, filename);
- if (ext && !fz_strcasecmp(ext, ".cbz"))
- return (fz_document*) cbz_open_document(ctx, filename);
-#if 0
- /* We used to only open pdf files if they ended in .pdf. For now,
- * until we move to detecting filetypes by their content, we disable
- * this code, and assume that any file that hasn't matched an
- * extension already, is a PDF. */
- if (ext && !fz_strcasecmp(ext, ".pdf"))
- return (fz_document*) pdf_open_document(ctx, filename);
- fz_throw(ctx, "unknown document type: '%s'", filename);
- return NULL;
-#else
+
+ if (ext)
+ {
+ if (!fz_strcasecmp(ext, ".xps") || !fz_strcasecmp(ext, ".rels"))
+ return (fz_document*) xps_open_document(ctx, filename);
+ if (!fz_strcasecmp(ext, ".cbz") || !fz_strcasecmp(ext, ".zip"))
+ return (fz_document*) cbz_open_document(ctx, filename);
+ if (!fz_strcasecmp(ext, ".pdf"))
+ return (fz_document*) pdf_open_document(ctx, filename);
+ }
+
+ /* last guess: pdf */
return (fz_document*) pdf_open_document(ctx, filename);
-#endif
}
void
diff --git a/fitz/fitz.h b/fitz/fitz.h
index b4e7cee4..96cd69a8 100644
--- a/fitz/fitz.h
+++ b/fitz/fitz.h
@@ -2143,6 +2143,16 @@ typedef struct fz_page_s fz_page;
fz_document *fz_open_document(fz_context *ctx, char *filename);
/*
+ fz_open_document_with_stream: Open a PDF, XPS or CBZ document.
+
+ Open a document using the specified stream object rather than
+ opening a file on disk.
+
+ magic: a string used to detect document type; either a file name or mime-type.
+*/
+fz_document *fz_open_document_with_stream(fz_context *ctx, char *magic, fz_stream *stream);
+
+/*
fz_close_document: Close and free an open document.
The resource store in the context associated with fz_document