summaryrefslogtreecommitdiff
path: root/ios
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2012-01-30 15:12:00 +0100
committerTor Andersson <tor.andersson@artifex.com>2012-01-30 15:12:00 +0100
commit1e3461a02021fba4d27c4f7678f0ad21d8954eee (patch)
tree23317b77247c45c204016907e09e3a84e2ddfc25 /ios
parent99401f12b3969404996dbbeb5a6bff58e3451781 (diff)
downloadmupdf-1e3461a02021fba4d27c4f7678f0ad21d8954eee.tar.xz
Add CBZ (comic book zip-file) parser.
Diffstat (limited to 'ios')
-rw-r--r--ios/document.c28
-rw-r--r--ios/document.h6
-rw-r--r--ios/main.m1
3 files changed, 32 insertions, 3 deletions
diff --git a/ios/document.c b/ios/document.c
index 9c209046..d17d1392 100644
--- a/ios/document.c
+++ b/ios/document.c
@@ -1,6 +1,7 @@
#include "fitz/fitz.h"
#include "pdf/mupdf.h"
#include "xps/muxps.h"
+#include "cbz/mucbz.h"
#include "document.h"
#include <ctype.h> /* for tolower() */
@@ -21,6 +22,8 @@ open_document(fz_context *ctx, char *filename)
doc->pdf = pdf_open_document(ctx, filename);
else if (strstr(filename, ".xps") || strstr(filename, ".XPS"))
doc->xps = xps_open_document(ctx, filename);
+ else if (strstr(filename, ".cbz") || strstr(filename, ".CBZ"))
+ doc->cbz = cbz_open_document(ctx, filename);
else
fz_throw(ctx, "unknown document format");
}
@@ -77,6 +80,8 @@ count_pages(struct document *doc)
return pdf_count_pages(doc->pdf);
else if (doc->xps)
return xps_count_pages(doc->xps);
+ else if (doc->cbz)
+ return cbz_count_pages(doc->cbz);
else
return 1;
}
@@ -101,6 +106,12 @@ load_page(struct document *doc, int number)
doc->xps_page = NULL;
doc->xps_page = xps_load_page(doc->xps, number);
}
+ if (doc->cbz) {
+ if (doc->cbz_page)
+ cbz_free_page(doc->cbz, doc->cbz_page);
+ doc->cbz_page = NULL;
+ doc->cbz_page = cbz_load_page(doc->cbz, number);
+ }
}
fz_catch (doc->ctx)
{
@@ -122,6 +133,11 @@ measure_page(struct document *doc, int number, float *w, float *h)
*w = bounds.x1 - bounds.x0;
*h = bounds.y1 - bounds.y0;
}
+ else if (doc->cbz_page) {
+ fz_rect bounds = cbz_bound_page(doc->cbz, doc->cbz_page);
+ *w = bounds.x1 - bounds.x0;
+ *h = bounds.y1 - bounds.y0;
+ }
else {
*w = *h = 72;
}
@@ -134,11 +150,12 @@ draw_page(struct document *doc, int number, fz_device *dev, fz_matrix ctm, fz_co
load_page(doc, number);
fz_try (doc->ctx)
{
- if (doc->pdf_page) {
+ if (doc->pdf_page)
pdf_run_page(doc->pdf, doc->pdf_page, dev, ctm, cookie);
- } else if (doc->xps_page) {
+ else if (doc->xps_page)
xps_run_page(doc->xps, doc->xps_page, dev, ctm, cookie);
- }
+ else if (doc->cbz_page)
+ cbz_run_page(doc->cbz, doc->cbz_page, dev, ctm, cookie);
}
fz_catch (doc->ctx)
{
@@ -264,6 +281,11 @@ close_document(struct document *doc)
xps_free_page(doc->xps, doc->xps_page);
xps_close_document(doc->xps);
}
+ if (doc->cbz) {
+ if (doc->cbz_page)
+ cbz_free_page(doc->cbz, doc->cbz_page);
+ cbz_close_document(doc->cbz);
+ }
fz_flush_warnings(doc->ctx);
fz_free(doc->ctx, doc);
}
diff --git a/ios/document.h b/ios/document.h
index 5e3c740e..0003070e 100644
--- a/ios/document.h
+++ b/ios/document.h
@@ -13,14 +13,20 @@
#error "muxps.h must be included before document.h"
#endif
+#ifndef _MUCBZ_H_
+#error "mucbz.h must be included before document.h"
+#endif
+
struct document
{
fz_context *ctx;
pdf_document *pdf;
xps_document *xps;
+ cbz_document *cbz;
int number;
pdf_page *pdf_page;
xps_page *xps_page;
+ cbz_page *cbz_page;
fz_bbox hit_bbox[500];
int hit_count;
};
diff --git a/ios/main.m b/ios/main.m
index 582d4e88..1ed6246c 100644
--- a/ios/main.m
+++ b/ios/main.m
@@ -7,6 +7,7 @@
#include "fitz/fitz.h"
#include "pdf/mupdf.h"
#include "xps/muxps.h"
+#include "cbz/mucbz.h"
#include "document.h"