summaryrefslogtreecommitdiff
path: root/ios
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2012-12-09 00:12:51 +0100
committerRobin Watts <robin.watts@artifex.com>2012-12-08 19:03:34 -0800
commit761b2da827096a8287daa14b4ea0ad304ad1f341 (patch)
tree7ff42ae7cc4cdd5461622fdfda49e9e487351f89 /ios
parent3dbf93f4612d6736f8b8ba43b5eb6e7971632cfa (diff)
downloadmupdf-761b2da827096a8287daa14b4ea0ad304ad1f341.tar.xz
ios: Use fz_document interface directly.
Diffstat (limited to 'ios')
-rw-r--r--ios/Default-568h@2x.pngbin0 -> 18594 bytes
-rw-r--r--ios/MuPDF.xcodeproj/project.pbxproj10
-rw-r--r--ios/document.c306
-rw-r--r--ios/document.h29
-rw-r--r--ios/main.m136
5 files changed, 90 insertions, 391 deletions
diff --git a/ios/Default-568h@2x.png b/ios/Default-568h@2x.png
new file mode 100644
index 00000000..0891b7aa
--- /dev/null
+++ b/ios/Default-568h@2x.png
Binary files differ
diff --git a/ios/MuPDF.xcodeproj/project.pbxproj b/ios/MuPDF.xcodeproj/project.pbxproj
index f7b1f956..5430f38a 100644
--- a/ios/MuPDF.xcodeproj/project.pbxproj
+++ b/ios/MuPDF.xcodeproj/project.pbxproj
@@ -7,7 +7,6 @@
objects = {
/* Begin PBXBuildFile section */
- 9644E9A0146ACEC000E5B70A /* document.c in Sources */ = {isa = PBXBuildFile; fileRef = 9644E99E146ACEC000E5B70A /* document.c */; };
9668C8D91476A30200D7BA52 /* About.xps in Resources */ = {isa = PBXBuildFile; fileRef = 9668C8D81476A30200D7BA52 /* About.xps */; };
968F2E9C14539C880085264E /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 968F2E9B14539C880085264E /* UIKit.framework */; };
968F2E9E14539C880085264E /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 968F2E9D14539C880085264E /* Foundation.framework */; };
@@ -18,6 +17,7 @@
96B6AF8415D16A7E00EAAF7B /* x_alt_blue@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 96B6AF8215D16A7E00EAAF7B /* x_alt_blue@2x.png */; };
96BD2B38145AC485001CEBC3 /* Icon-72.png in Resources */ = {isa = PBXBuildFile; fileRef = 96BD2B35145AC485001CEBC3 /* Icon-72.png */; };
96BD2B39145AC485001CEBC3 /* Icon.png in Resources */ = {isa = PBXBuildFile; fileRef = 96BD2B36145AC485001CEBC3 /* Icon.png */; };
+ 96EC0F931672AAC60007F804 /* Default-568h@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 96EC0F921672AAC60007F804 /* Default-568h@2x.png */; };
96F2341514603FBA004A8A22 /* Icon@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 96F2341414603FBA004A8A22 /* Icon@2x.png */; };
/* End PBXBuildFile section */
@@ -32,8 +32,6 @@
/* End PBXContainerItemProxy section */
/* Begin PBXFileReference section */
- 9644E99E146ACEC000E5B70A /* document.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = document.c; sourceTree = "<group>"; };
- 9644E99F146ACEC000E5B70A /* document.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = document.h; sourceTree = "<group>"; };
9668C8D81476A30200D7BA52 /* About.xps */ = {isa = PBXFileReference; lastKnownFileType = file; path = About.xps; sourceTree = "<group>"; };
968461E214642DB00012AE09 /* libLibraries.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libLibraries.a; sourceTree = BUILT_PRODUCTS_DIR; };
968F2E8E14539BEB0085264E /* build_libs.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = build_libs.sh; sourceTree = "<group>"; };
@@ -47,6 +45,7 @@
96B6AF8215D16A7E00EAAF7B /* x_alt_blue@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "x_alt_blue@2x.png"; sourceTree = "<group>"; };
96BD2B35145AC485001CEBC3 /* Icon-72.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Icon-72.png"; sourceTree = "<group>"; };
96BD2B36145AC485001CEBC3 /* Icon.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Icon.png; sourceTree = "<group>"; };
+ 96EC0F921672AAC60007F804 /* Default-568h@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Default-568h@2x.png"; sourceTree = "<group>"; };
96F2341414603FBA004A8A22 /* Icon@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Icon@2x.png"; sourceTree = "<group>"; };
/* End PBXFileReference section */
@@ -76,8 +75,6 @@
96B6AF8215D16A7E00EAAF7B /* x_alt_blue@2x.png */,
968F2E8F14539BEB0085264E /* Info.plist */,
968F2E8E14539BEB0085264E /* build_libs.sh */,
- 9644E99E146ACEC000E5B70A /* document.c */,
- 9644E99F146ACEC000E5B70A /* document.h */,
968F2E9014539BEB0085264E /* main.m */,
);
name = Sources;
@@ -105,6 +102,7 @@
96A3B27414539BAD00D0A895 = {
isa = PBXGroup;
children = (
+ 96EC0F921672AAC60007F804 /* Default-568h@2x.png */,
968F2E9214539BF10085264E /* Sources */,
968F2E9A14539C880085264E /* Frameworks */,
968F2E9814539C880085264E /* Products */,
@@ -184,6 +182,7 @@
9668C8D91476A30200D7BA52 /* About.xps in Resources */,
96B6AF8315D16A7E00EAAF7B /* x_alt_blue.png in Resources */,
96B6AF8415D16A7E00EAAF7B /* x_alt_blue@2x.png in Resources */,
+ 96EC0F931672AAC60007F804 /* Default-568h@2x.png in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -213,7 +212,6 @@
buildActionMask = 2147483647;
files = (
968F2EB014539CDA0085264E /* main.m in Sources */,
- 9644E9A0146ACEC000E5B70A /* document.c in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
diff --git a/ios/document.c b/ios/document.c
deleted file mode 100644
index 0fb077ad..00000000
--- a/ios/document.c
+++ /dev/null
@@ -1,306 +0,0 @@
-#include "fitz/fitz.h"
-#include "pdf/mupdf.h"
-#include "xps/muxps.h"
-#include "cbz/mucbz.h"
-#include "document.h"
-
-#include <ctype.h> /* for tolower() */
-
-struct document *
-open_document(fz_context *ctx, char *filename)
-{
- struct document *doc;
-
- doc = fz_malloc_struct(ctx, struct document);
- memset(doc, 0, sizeof *doc);
- doc->ctx = ctx;
- doc->number = -1;
-
- fz_try(ctx)
- {
- if (strstr(filename, ".pdf") || strstr(filename, ".PDF"))
- 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") || strstr(filename, ".zip") || strstr(filename, ".ZIP"))
- doc->cbz = cbz_open_document(ctx, filename);
- else
- fz_throw(ctx, "unknown document format");
- }
- fz_catch(ctx)
- {
- close_document(doc);
- return NULL;
- }
-
- return doc;
-}
-
-int
-needs_password(struct document *doc)
-{
- if (doc->pdf)
- return pdf_needs_password(doc->pdf);
- return 0;
-}
-
-int
-authenticate_password(struct document *doc, char *password)
-{
- if (doc->pdf)
- return pdf_authenticate_password(doc->pdf, password);
- return 1;
-}
-
-fz_outline *
-load_outline(struct document *doc)
-{
- fz_outline *outline;
- fz_var(outline);
- fz_try (doc->ctx)
- {
- if (doc->pdf)
- outline = pdf_load_outline(doc->pdf);
- else if (doc->xps)
- outline = xps_load_outline(doc->xps);
- else
- outline = NULL;
- }
- fz_catch (doc->ctx)
- {
- outline = NULL;
- }
- return outline;
-}
-
-int
-count_pages(struct document *doc)
-{
- if (doc->pdf)
- 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;
-}
-
-static void
-load_page(struct document *doc, int number)
-{
- if (doc->number == number)
- return;
- fz_try (doc->ctx)
- {
- doc->number = number;
- if (doc->pdf) {
- if (doc->pdf_page)
- pdf_free_page(doc->pdf, doc->pdf_page);
- doc->pdf_page = NULL;
- doc->pdf_page = pdf_load_page(doc->pdf, number);
- }
- if (doc->xps) {
- if (doc->xps_page)
- xps_free_page(doc->xps, doc->xps_page);
- 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)
- {
- fprintf(stderr, "cannot load page %d", number);
- }
-}
-
-void
-measure_page(struct document *doc, int number, float *w, float *h)
-{
- load_page(doc, number);
- if (doc->pdf_page) {
- fz_rect bounds = pdf_bound_page(doc->pdf, doc->pdf_page);
- *w = bounds.x1 - bounds.x0;
- *h = bounds.y1 - bounds.y0;
- }
- else if (doc->xps_page) {
- fz_rect bounds = xps_bound_page(doc->xps, doc->xps_page);
- *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;
- }
- fz_flush_warnings(doc->ctx);
-}
-
-void
-draw_page(struct document *doc, int number, fz_device *dev, fz_matrix ctm, fz_cookie *cookie)
-{
- load_page(doc, number);
- fz_try (doc->ctx)
- {
- if (doc->pdf_page)
- pdf_run_page(doc->pdf, doc->pdf_page, dev, ctm, cookie);
- 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)
- {
- fprintf(stderr, "cannot draw page %d", number);
- }
- fz_flush_warnings(doc->ctx);
-}
-
-static fz_text_char
-textcharat(fz_text_page *page, int idx)
-{
- static fz_text_char emptychar = { {0,0,0,0}, ' ' };
- fz_text_block *block;
- fz_text_line *line;
- fz_text_span *span;
- int ofs = 0;
- for (block = page->blocks; block < page->blocks + page->len; block++)
- {
- for (line = block->lines; line < block->lines + block->len; line++)
- {
- for (span = line->spans; span < line->spans + line->len; span++)
- {
- if (idx < ofs + span->len)
- return span->text[idx - ofs];
- /* pseudo-newline */
- if (span + 1 == line->spans + line->len)
- {
- if (idx == ofs + span->len)
- return emptychar;
- ofs++;
- }
- ofs += span->len;
- }
- }
- }
- return emptychar;
-}
-
-static int
-charat(fz_text_page *page, int idx)
-{
- return textcharat(page, idx).c;
-}
-
-static fz_bbox
-bboxat(fz_text_page *page, int idx)
-{
- return fz_round_rect(textcharat(page, idx).bbox);
-}
-
-static int
-textlen(fz_text_page *page)
-{
- fz_text_block *block;
- fz_text_line *line;
- fz_text_span *span;
- int len = 0;
- for (block = page->blocks; block < page->blocks + page->len; block++)
- {
- for (line = block->lines; line < block->lines + block->len; line++)
- {
- for (span = line->spans; span < line->spans + line->len; span++)
- len += span->len;
- len++; /* pseudo-newline */
- }
- }
- return len;
-}
-
-static int
-match(fz_text_page *page, const char *s, int n)
-{
- int orig = n;
- int c;
- while (*s) {
- s += fz_chartorune(&c, (char *)s);
- if (c == ' ' && charat(page, n) == ' ') {
- while (charat(page, n) == ' ')
- n++;
- } else {
- if (tolower(c) != tolower(charat(page, n)))
- return 0;
- n++;
- }
- }
- return n - orig;
-}
-
-int
-search_page(struct document *doc, int number, char *needle, fz_cookie *cookie)
-{
- int pos, len, i, n;
-
- if (strlen(needle) == 0)
- return 0;
-
- fz_text_sheet *sheet = fz_new_text_sheet(doc->ctx);
- fz_text_page *text = fz_new_text_page(doc->ctx, fz_empty_rect);
- fz_device *dev = fz_new_text_device(doc->ctx, sheet, text);
- draw_page(doc, number, dev, fz_identity, cookie);
- fz_free_device(dev);
-
- doc->hit_count = 0;
-
- len = textlen(text);
- for (pos = 0; pos < len; pos++) {
- n = match(text, needle, pos);
- if (n) {
- for (i = 0; i < n; i++) {
- fz_bbox r = bboxat(text, pos + i);
- if (!fz_is_empty_bbox(r) && doc->hit_count < nelem(doc->hit_bbox))
- doc->hit_bbox[doc->hit_count++] = r;
- }
- }
- }
-
- fz_free_text_page(doc->ctx, text);
- fz_free_text_sheet(doc->ctx, sheet);
- return doc->hit_count;
-}
-
-fz_bbox
-search_result_bbox(struct document *doc, int i)
-{
- return doc->hit_bbox[i];
-}
-
-void
-close_document(struct document *doc)
-{
- if (doc->pdf) {
- if (doc->pdf_page)
- pdf_free_page(doc->pdf, doc->pdf_page);
- pdf_close_document(doc->pdf);
- }
- if (doc->xps) {
- if (doc->xps_page)
- 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
deleted file mode 100644
index b4555578..00000000
--- a/ios/document.h
+++ /dev/null
@@ -1,29 +0,0 @@
-#ifndef DOCUMENT_H
-#define DOCUMENT_H
-
-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;
-};
-
-struct document *open_document(fz_context *ctx, char *filename);
-int needs_password(struct document *doc);
-int authenticate_password(struct document *doc, char *password);
-fz_outline *load_outline(struct document *doc);
-int count_pages(struct document *doc);
-void measure_page(struct document *doc, int number, float *w, float *h);
-void draw_page(struct document *doc, int number, fz_device *dev, fz_matrix ctm, fz_cookie *cookie);
-int search_page(struct document *doc, int number, char *needle, fz_cookie *cookie);
-fz_bbox search_result_bbox(struct document *doc, int i);
-void close_document(struct document *doc);
-
-#endif
diff --git a/ios/main.m b/ios/main.m
index 9478af49..0bb0321c 100644
--- a/ios/main.m
+++ b/ios/main.m
@@ -5,11 +5,6 @@
#undef MAX
#include "fitz/fitz.h"
-#include "pdf/mupdf.h"
-#include "xps/muxps.h"
-#include "cbz/mucbz.h"
-
-#include "document.h"
#define GAP 20
#define INDICATOR_Y -44-24
@@ -24,7 +19,7 @@ static fz_context *ctx = NULL;
{
NSArray *files;
NSTimer *timer;
- struct document *_doc; // temporaries for juggling password dialog
+ fz_document *_doc; // temporaries for juggling password dialog
NSString *_filename;
}
- (void) openDocument: (NSString*)filename;
@@ -49,24 +44,26 @@ static fz_context *ctx = NULL;
int hitCount;
CGRect hitRects[500];
}
-- (id) initWithSearchResults: (int)n forDocument: (struct document *)doc;
+- (id) initWithSearchResults: (int)n forDocument: (fz_document *)doc;
- (void) setPageSize: (CGSize)s;
@end
@interface MuPageView : UIScrollView <UIScrollViewDelegate>
{
- struct document *doc;
+ fz_document *doc;
+ fz_page *page;
int number;
UIActivityIndicatorView *loadingView;
UIImageView *imageView;
UIImageView *tileView;
MuHitView *hitView;
+ MuHitView *linkView;
CGSize pageSize;
CGRect tileFrame;
float tileScale;
BOOL cancel;
}
-- (id) initWithFrame: (CGRect)frame document: (struct document*)aDoc page: (int)aNumber;
+- (id) initWithFrame: (CGRect)frame document: (fz_document*)aDoc page: (int)aNumber;
- (void) displayImage: (UIImage*)image;
- (void) resizeImage;
- (void) loadPage;
@@ -80,7 +77,7 @@ static fz_context *ctx = NULL;
@interface MuDocumentController : UIViewController <UIScrollViewDelegate, UISearchBarDelegate>
{
- struct document *doc;
+ fz_document *doc;
NSString *key;
MuOutlineController *outline;
UIScrollView *canvas;
@@ -96,7 +93,7 @@ static fz_context *ctx = NULL;
int current; // currently visible page
int scroll_animating; // stop view updates during scrolling animations
}
-- (id) initWithFilename: (NSString*)nsfilename document: (struct document *)aDoc;
+- (id) initWithFilename: (NSString*)nsfilename document: (fz_document *)aDoc;
- (void) createPageView: (int)number;
- (void) gotoPage: (int)number animated: (BOOL)animated;
- (void) onShowOutline: (id)sender;
@@ -120,6 +117,35 @@ static fz_context *ctx = NULL;
#pragma mark -
+static int hit_count = 0;
+static fz_bbox hit_bbox[500];
+
+static int
+search_page(fz_document *doc, int number, char *needle, fz_cookie *cookie)
+{
+ fz_page *page = fz_load_page(doc, number);
+
+ fz_text_sheet *sheet = fz_new_text_sheet(ctx);
+ fz_text_page *text = fz_new_text_page(ctx, fz_empty_rect);
+ fz_device *dev = fz_new_text_device(ctx, sheet, text);
+ fz_run_page(doc, page, dev, fz_identity, cookie);
+ fz_free_device(dev);
+
+ hit_count = fz_search_text_page(ctx, text, needle, hit_bbox, nelem(hit_bbox));;
+
+ fz_free_text_page(ctx, text);
+ fz_free_text_sheet(ctx, sheet);
+ fz_free_page(doc, page);
+
+ return hit_count;
+}
+
+static fz_bbox
+search_result_bbox(fz_document *doc, int i)
+{
+ return hit_bbox[i];
+}
+
static void showAlert(NSString *msg, NSString *filename)
{
UIAlertView *alert = [[UIAlertView alloc]
@@ -156,10 +182,6 @@ static void flattenOutline(NSMutableArray *titles, NSMutableArray *pages, fz_out
}
}
-static void loadOutline(NSMutableArray *titles, NSMutableArray *pages, struct document *doc)
-{
-}
-
static void releasePixmap(void *info, const void *data, size_t size)
{
fz_drop_pixmap(ctx, info);
@@ -195,14 +217,16 @@ static CGSize fitPageToScreen(CGSize page, CGSize screen)
return CGSizeMake(hscale, vscale);
}
-static CGSize measurePage(struct document *doc, int number)
+static CGSize measurePage(fz_document *doc, fz_page *page)
{
CGSize pageSize;
- measure_page(doc, number, &pageSize.width, &pageSize.height);
+ fz_rect bounds = fz_bound_page(doc, page);
+ pageSize.width = bounds.x1 - bounds.x0;
+ pageSize.height = bounds.y1 - bounds.y0;
return pageSize;
}
-static UIImage *renderPage(struct document *doc, int number, CGSize screenSize)
+static UIImage *renderPage(fz_document *doc, fz_page *page, CGSize screenSize)
{
CGSize pageSize;
fz_bbox bbox;
@@ -214,7 +238,7 @@ static UIImage *renderPage(struct document *doc, int number, CGSize screenSize)
screenSize.width *= screenScale;
screenSize.height *= screenScale;
- measure_page(doc, number, &pageSize.width, &pageSize.height);
+ pageSize = measurePage(doc, page);
scale = fitPageToScreen(pageSize, screenSize);
ctm = fz_scale(scale.width, scale.height);
bbox = (fz_bbox){0, 0, pageSize.width * scale.width, pageSize.height * scale.height};
@@ -223,13 +247,13 @@ static UIImage *renderPage(struct document *doc, int number, CGSize screenSize)
fz_clear_pixmap_with_value(ctx, pix, 255);
dev = fz_new_draw_device(ctx, pix);
- draw_page(doc, number, dev, ctm, NULL);
+ fz_run_page(doc, page, dev, ctm, NULL);
fz_free_device(dev);
return newImageWithPixmap(pix);
}
-static UIImage *renderTile(struct document *doc, int number, CGSize screenSize, CGRect tileRect, float zoom)
+static UIImage *renderTile(fz_document *doc, fz_page *page, CGSize screenSize, CGRect tileRect, float zoom)
{
CGSize pageSize;
fz_rect rect;
@@ -246,7 +270,7 @@ static UIImage *renderTile(struct document *doc, int number, CGSize screenSize,
tileRect.size.width *= screenScale;
tileRect.size.height *= screenScale;
- measure_page(doc, number, &pageSize.width, &pageSize.height);
+ pageSize = measurePage(doc, page);
scale = fitPageToScreen(pageSize, screenSize);
ctm = fz_scale(scale.width * zoom, scale.height * zoom);
@@ -260,7 +284,7 @@ static UIImage *renderTile(struct document *doc, int number, CGSize screenSize,
fz_clear_pixmap_with_value(ctx, pix, 255);
dev = fz_new_draw_device(ctx, pix);
- draw_page(doc, number, dev, ctm, NULL);
+ fz_run_page(doc, page, dev, ctm, NULL);
fz_free_device(dev);
return newImageWithPixmap(pix);
@@ -425,13 +449,13 @@ static UIImage *renderTile(struct document *doc, int number, CGSize screenSize,
printf("open document '%s'\n", filename);
_filename = [nsfilename retain];
- _doc = open_document(ctx, filename);
+ _doc = fz_open_document(ctx, filename);
if (!_doc) {
showAlert(@"Cannot open document", nsfilename);
return;
}
- if (needs_password(_doc))
+ if (fz_needs_password(_doc))
[self askForPassword: @"'%@' needs a password:"];
else
[self onPasswordOkay];
@@ -455,7 +479,7 @@ static UIImage *renderTile(struct document *doc, int number, CGSize screenSize,
char *password = (char*) [[[alertView textFieldAtIndex: 0] text] UTF8String];
[alertView dismissWithClickedButtonIndex: buttonIndex animated: TRUE];
if (buttonIndex == 1) {
- if (authenticate_password(_doc, password))
+ if (fz_authenticate_password(_doc, password))
[self onPasswordOkay];
else
[self askForPassword: @"Wrong password for '%@'. Try again:"];
@@ -480,7 +504,7 @@ static UIImage *renderTile(struct document *doc, int number, CGSize screenSize,
{
[_filename release];
printf("close document (password cancel)\n");
- close_document(_doc);
+ fz_close_document(_doc);
_doc = NULL;
}
@@ -560,7 +584,7 @@ static UIImage *renderTile(struct document *doc, int number, CGSize screenSize,
@implementation MuHitView
-- (id) initWithSearchResults: (int)n forDocument: (struct document *)doc
+- (id) initWithSearchResults: (int)n forDocument: (fz_document *)doc
{
self = [super initWithFrame: CGRectMake(0,0,100,100)];
if (self) {
@@ -607,7 +631,7 @@ static UIImage *renderTile(struct document *doc, int number, CGSize screenSize,
@implementation MuPageView
-- (id) initWithFrame: (CGRect)frame document: (struct document*)aDoc page: (int)aNumber
+- (id) initWithFrame: (CGRect)frame document: (fz_document*)aDoc page: (int)aNumber
{
self = [super initWithFrame: frame];
if (self) {
@@ -645,6 +669,13 @@ static UIImage *renderTile(struct document *doc, int number, CGSize screenSize,
__block id block_self = self; // don't auto-retain self!
dispatch_async(dispatch_get_main_queue(), ^{ [block_self dealloc]; });
} else {
+ __block fz_page *block_page = page;
+ __block fz_document *block_doc = doc;
+ dispatch_async(queue, ^{
+ if (block_page)
+ fz_free_page(block_doc, block_page);
+ });
+ [linkView release];
[hitView release];
[tileView release];
[loadingView release];
@@ -706,13 +737,15 @@ static UIImage *renderTile(struct document *doc, int number, CGSize screenSize,
- (void) loadPage
{
- if (number < 0 || number >= count_pages(doc))
+ if (number < 0 || number >= fz_count_pages(doc))
return;
dispatch_async(queue, ^{
if (!cancel) {
printf("render page %d\n", number);
- CGSize size = measurePage(doc, number);
- UIImage *image = renderPage(doc, number, self.bounds.size);
+ if (!page)
+ page = fz_load_page(doc, number);
+ CGSize size = measurePage(doc, page);
+ UIImage *image = renderPage(doc, page, self.bounds.size);
dispatch_async(dispatch_get_main_queue(), ^{
pageSize = size;
[self displayImage: image];
@@ -852,8 +885,11 @@ static UIImage *renderTile(struct document *doc, int number, CGSize screenSize,
return;
}
+ if (!page)
+ page = fz_load_page(doc, number);
+
printf("render tile\n");
- UIImage *image = renderTile(doc, number, screenSize, viewFrame, scale);
+ UIImage *image = renderTile(doc, page, screenSize, viewFrame, scale);
dispatch_async(dispatch_get_main_queue(), ^{
isValid = CGRectEqualToRect(frame, tileFrame) && scale == tileScale;
@@ -917,7 +953,7 @@ static UIImage *renderTile(struct document *doc, int number, CGSize screenSize,
@implementation MuDocumentController
-- (id) initWithFilename: (NSString*)filename document: (struct document *)aDoc
+- (id) initWithFilename: (NSString*)filename document: (fz_document *)aDoc
{
self = [super init];
if (!self)
@@ -928,7 +964,7 @@ static UIImage *renderTile(struct document *doc, int number, CGSize screenSize,
dispatch_sync(queue, ^{});
- fz_outline *root = load_outline(doc);
+ fz_outline *root = fz_load_outline(doc);
if (root) {
NSMutableArray *titles = [[NSMutableArray alloc] init];
NSMutableArray *pages = [[NSMutableArray alloc] init];
@@ -948,7 +984,7 @@ static UIImage *renderTile(struct document *doc, int number, CGSize screenSize,
[[NSUserDefaults standardUserDefaults] setObject: key forKey: @"OpenDocumentKey"];
current = [[NSUserDefaults standardUserDefaults] integerForKey: key];
- if (current < 0 || current >= count_pages(doc))
+ if (current < 0 || current >= fz_count_pages(doc))
current = 0;
UIView *view = [[UIView alloc] initWithFrame: CGRectZero];
@@ -980,7 +1016,7 @@ static UIImage *renderTile(struct document *doc, int number, CGSize screenSize,
slider = [[UISlider alloc] initWithFrame: CGRectZero];
[slider setMinimumValue: 0];
- [slider setMaximumValue: count_pages(doc) - 1];
+ [slider setMaximumValue: fz_count_pages(doc) - 1];
[slider addTarget: self action: @selector(onSlide:) forControlEvents: UIControlEventValueChanged];
sliderWrapper = [[UIBarButtonItem alloc] initWithCustomView: slider];
@@ -1028,10 +1064,10 @@ static UIImage *renderTile(struct document *doc, int number, CGSize screenSize,
- (void) dealloc
{
if (doc) {
- struct document *self_doc = doc; // don't auto-retain self here!
+ fz_document *self_doc = doc; // don't auto-retain self here!
dispatch_async(queue, ^{
printf("close document\n");
- close_document(self_doc);
+ fz_close_document(self_doc);
});
}
@@ -1057,7 +1093,7 @@ static UIImage *renderTile(struct document *doc, int number, CGSize screenSize,
[slider setValue: current];
- [indicator setText: [NSString stringWithFormat: @" %d of %d ", current+1, count_pages(doc)]];
+ [indicator setText: [NSString stringWithFormat: @" %d of %d ", current+1, fz_count_pages(doc)]];
[[self navigationController] setToolbarHidden: NO animated: animated];
}
@@ -1071,7 +1107,7 @@ static UIImage *renderTile(struct document *doc, int number, CGSize screenSize,
height = size.height;
[canvas setContentInset: UIEdgeInsetsZero];
- [canvas setContentSize: CGSizeMake(count_pages(doc) * width, height)];
+ [canvas setContentSize: CGSizeMake(fz_count_pages(doc) * width, height)];
[canvas setContentOffset: CGPointMake(current * width, 0)];
[sliderWrapper setWidth: SLIDER_W];
@@ -1080,7 +1116,7 @@ static UIImage *renderTile(struct document *doc, int number, CGSize screenSize,
[[[self navigationController] toolbar] setNeedsLayout]; // force layout!
// use max_width so we don't clamp the content offset too early during animation
- [canvas setContentSize: CGSizeMake(count_pages(doc) * max_width, height)];
+ [canvas setContentSize: CGSizeMake(fz_count_pages(doc) * max_width, height)];
[canvas setContentOffset: CGPointMake(current * width, 0)];
for (MuPageView *view in [canvas subviews]) {
@@ -1221,7 +1257,7 @@ static UIImage *renderTile(struct document *doc, int number, CGSize screenSize,
cancelSearch = NO;
dispatch_async(queue, ^{
- for (int i = start; i >= 0 && i < count_pages(doc); i += dir) {
+ for (int i = start; i >= 0 && i < fz_count_pages(doc); i += dir) {
int n = search_page(doc, i, needle, NULL);
if (n) {
dispatch_async(dispatch_get_main_queue(), ^{
@@ -1292,7 +1328,7 @@ static UIImage *renderTile(struct document *doc, int number, CGSize screenSize,
{
int number = [slider value];
if ([slider isTracking])
- [indicator setText: [NSString stringWithFormat: @" %d of %d ", number+1, count_pages(doc)]];
+ [indicator setText: [NSString stringWithFormat: @" %d of %d ", number+1, fz_count_pages(doc)]];
else
[self gotoPage: number animated: NO];
}
@@ -1335,7 +1371,7 @@ static UIImage *renderTile(struct document *doc, int number, CGSize screenSize,
[[NSUserDefaults standardUserDefaults] setInteger: current forKey: key];
- [indicator setText: [NSString stringWithFormat: @" %d of %d ", current+1, count_pages(doc)]];
+ [indicator setText: [NSString stringWithFormat: @" %d of %d ", current+1, fz_count_pages(doc)]];
[slider setValue: current];
// swap the distant page views out
@@ -1362,7 +1398,7 @@ static UIImage *renderTile(struct document *doc, int number, CGSize screenSize,
- (void) createPageView: (int)number
{
- if (number < 0 || number >= count_pages(doc))
+ if (number < 0 || number >= fz_count_pages(doc))
return;
int found = 0;
for (MuPageView *view in [canvas subviews])
@@ -1379,8 +1415,8 @@ static UIImage *renderTile(struct document *doc, int number, CGSize screenSize,
{
if (number < 0)
number = 0;
- if (number >= count_pages(doc))
- number = count_pages(doc) - 1;
+ if (number >= fz_count_pages(doc))
+ number = fz_count_pages(doc) - 1;
if (current == number)
return;
if (animated) {
@@ -1403,7 +1439,7 @@ static UIImage *renderTile(struct document *doc, int number, CGSize screenSize,
[canvas setContentOffset: CGPointMake(number * width, 0)];
[slider setValue: number];
- [indicator setText: [NSString stringWithFormat: @" %d of %d ", number+1, count_pages(doc)]];
+ [indicator setText: [NSString stringWithFormat: @" %d of %d ", number+1, fz_count_pages(doc)]];
[UIView commitAnimations];
} else {
@@ -1427,7 +1463,7 @@ static UIImage *renderTile(struct document *doc, int number, CGSize screenSize,
- (void) didRotateFromInterfaceOrientation: (UIInterfaceOrientation)o
{
- [canvas setContentSize: CGSizeMake(count_pages(doc) * width, height)];
+ [canvas setContentSize: CGSizeMake(fz_count_pages(doc) * width, height)];
[canvas setContentOffset: CGPointMake(current * width, 0)];
}