diff options
-rw-r--r-- | platform/ios/Classes/MuDocRef.h | 18 | ||||
-rw-r--r-- | platform/ios/Classes/MuDocRef.m | 35 | ||||
-rw-r--r-- | platform/ios/Classes/MuDocumentController.h | 4 | ||||
-rw-r--r-- | platform/ios/Classes/MuDocumentController.m | 16 | ||||
-rw-r--r-- | platform/ios/Classes/MuLibraryController.h | 4 | ||||
-rw-r--r-- | platform/ios/Classes/MuLibraryController.m | 15 | ||||
-rw-r--r-- | platform/ios/Classes/MuPageView.h | 4 | ||||
-rw-r--r-- | platform/ios/Classes/MuPageView.m | 8 | ||||
-rw-r--r-- | platform/ios/MuPDF.xcodeproj/project.pbxproj | 6 |
9 files changed, 85 insertions, 25 deletions
diff --git a/platform/ios/Classes/MuDocRef.h b/platform/ios/Classes/MuDocRef.h new file mode 100644 index 00000000..ceefcc59 --- /dev/null +++ b/platform/ios/Classes/MuDocRef.h @@ -0,0 +1,18 @@ +// +// MuDocRef.h +// MuPDF +// +// Copyright (c) 2013 Artifex Software, Inc. All rights reserved. +// + +#import <Foundation/Foundation.h> + +#include "mupdf/fitz.h" + +@interface MuDocRef : NSObject +{ +@public + fz_document *doc; +} +-(id) initWithFilename:(char *)aFilename; +@end diff --git a/platform/ios/Classes/MuDocRef.m b/platform/ios/Classes/MuDocRef.m new file mode 100644 index 00000000..60cfa99d --- /dev/null +++ b/platform/ios/Classes/MuDocRef.m @@ -0,0 +1,35 @@ +// +// MuDocRef.m +// MuPDF +// +// Copyright (c) 2013 Artifex Software, Inc. All rights reserved. +// + +#include "common.h" +#import "MuDocRef.h" + +@implementation MuDocRef + +-(id) initWithFilename:(char *)aFilename; +{ + self = [super init]; + if (self) + { + dispatch_sync(queue, ^{}); + doc = fz_open_document(ctx, aFilename); + if (!doc) + self = nil; + } + return self; +} + +-(void) dealloc +{ + __block fz_document *block_doc = doc; + dispatch_async(queue, ^{ + fz_close_document(block_doc); + }); + [super dealloc]; +} + +@end diff --git a/platform/ios/Classes/MuDocumentController.h b/platform/ios/Classes/MuDocumentController.h index f5d6115a..b15d629a 100644 --- a/platform/ios/Classes/MuDocumentController.h +++ b/platform/ios/Classes/MuDocumentController.h @@ -14,10 +14,12 @@ #include "mupdf/fitz.h" #import "MuOutlineController.h" +#import "MuDocRef.h" @interface MuDocumentController : UIViewController <UIScrollViewDelegate, UISearchBarDelegate> { fz_document *doc; + MuDocRef *docRef; NSString *key; MuOutlineController *outline; UIScrollView *canvas; @@ -34,7 +36,7 @@ int current; // currently visible page int scroll_animating; // stop view updates during scrolling animations } -- (id) initWithFilename: (NSString*)nsfilename document: (fz_document *)aDoc; +- (id) initWithFilename: (NSString*)nsfilename document: (MuDocRef *)aDoc; - (void) createPageView: (int)number; - (void) gotoPage: (int)number animated: (BOOL)animated; - (void) onShowOutline: (id)sender; diff --git a/platform/ios/Classes/MuDocumentController.m b/platform/ios/Classes/MuDocumentController.m index 89ee0da8..0b4f7d2e 100644 --- a/platform/ios/Classes/MuDocumentController.m +++ b/platform/ios/Classes/MuDocumentController.m @@ -41,14 +41,15 @@ static void flattenOutline(NSMutableArray *titles, NSMutableArray *pages, fz_out @implementation MuDocumentController -- (id) initWithFilename: (NSString*)filename document: (fz_document *)aDoc +- (id) initWithFilename: (NSString*)filename document: (MuDocRef *)aDoc { self = [super init]; if (!self) return nil; key = [filename retain]; - doc = aDoc; + docRef = [aDoc retain]; + doc = docRef->doc; dispatch_sync(queue, ^{}); @@ -154,14 +155,7 @@ static void flattenOutline(NSMutableArray *titles, NSMutableArray *pages, fz_out - (void) dealloc { - if (doc) { - fz_document *self_doc = doc; // don't auto-retain self here! - dispatch_async(queue, ^{ - printf("close document\n"); - fz_close_document(self_doc); - }); - } - + [docRef release]; docRef = nil; doc = NULL; [indicator release]; indicator = nil; [slider release]; slider = nil; [sliderWrapper release]; sliderWrapper = nil; @@ -508,7 +502,7 @@ static void flattenOutline(NSMutableArray *titles, NSMutableArray *pages, fz_out if ([view number] == number) found = 1; if (!found) { - MuPageView *view = [[MuPageView alloc] initWithFrame: CGRectMake(number * width, 0, width-GAP, height) document: doc page: number]; + MuPageView *view = [[MuPageView alloc] initWithFrame: CGRectMake(number * width, 0, width-GAP, height) document: docRef page: number]; [canvas addSubview: view]; if (showLinks) [view showLinks]; diff --git a/platform/ios/Classes/MuLibraryController.h b/platform/ios/Classes/MuLibraryController.h index 2bb7ff71..0f823d5d 100644 --- a/platform/ios/Classes/MuLibraryController.h +++ b/platform/ios/Classes/MuLibraryController.h @@ -13,11 +13,13 @@ #include "mupdf/fitz.h" +#import "MuDocRef.h" + @interface MuLibraryController : UITableViewController <UIActionSheetDelegate> { NSArray *files; NSTimer *timer; - fz_document *_doc; // temporaries for juggling password dialog + MuDocRef *doc; NSString *_filename; } - (void) openDocument: (NSString*)filename; diff --git a/platform/ios/Classes/MuLibraryController.m b/platform/ios/Classes/MuLibraryController.m index cc5a1ddd..7f21b303 100644 --- a/platform/ios/Classes/MuLibraryController.m +++ b/platform/ios/Classes/MuLibraryController.m @@ -69,6 +69,7 @@ static void showAlert(NSString *msg, NSString *filename) - (void) dealloc { + [doc release]; [files release]; [super dealloc]; } @@ -163,13 +164,14 @@ static void showAlert(NSString *msg, NSString *filename) printf("open document '%s'\n", filename); _filename = [nsfilename retain]; - _doc = fz_open_document(ctx, filename); - if (!_doc) { + [doc release]; + doc = [[MuDocRef alloc] initWithFilename:filename]; + if (!doc) { showAlert(@"Cannot open document", nsfilename); return; } - if (fz_needs_password(_doc)) + if (fz_needs_password(doc->doc)) [self askForPassword: @"'%@' needs a password:"]; else [self onPasswordOkay]; @@ -193,7 +195,7 @@ static void showAlert(NSString *msg, NSString *filename) char *password = (char*) [[[alertView textFieldAtIndex: 0] text] UTF8String]; [alertView dismissWithClickedButtonIndex: buttonIndex animated: TRUE]; if (buttonIndex == 1) { - if (fz_authenticate_password(_doc, password)) + if (fz_authenticate_password(doc->doc, password)) [self onPasswordOkay]; else [self askForPassword: @"Wrong password for '%@'. Try again:"]; @@ -204,22 +206,19 @@ static void showAlert(NSString *msg, NSString *filename) - (void) onPasswordOkay { - MuDocumentController *document = [[MuDocumentController alloc] initWithFilename: _filename document: _doc]; + MuDocumentController *document = [[MuDocumentController alloc] initWithFilename: _filename document: doc]; if (document) { [self setTitle: @"Library"]; [[self navigationController] pushViewController: document animated: YES]; [document release]; } [_filename release]; - _doc = NULL; } - (void) onPasswordCancel { [_filename release]; printf("close document (password cancel)\n"); - fz_close_document(_doc); - _doc = NULL; } @end diff --git a/platform/ios/Classes/MuPageView.h b/platform/ios/Classes/MuPageView.h index ab141ea8..58d1c8a7 100644 --- a/platform/ios/Classes/MuPageView.h +++ b/platform/ios/Classes/MuPageView.h @@ -13,10 +13,12 @@ #include "mupdf/fitz.h" +#import "MuDocRef.h" #include "MuHitView.h" @interface MuPageView : UIScrollView <UIScrollViewDelegate> { + MuDocRef *docRef; fz_document *doc; fz_page *page; int number; @@ -30,7 +32,7 @@ float tileScale; BOOL cancel; } -- (id) initWithFrame: (CGRect)frame document: (fz_document*)aDoc page: (int)aNumber; +- (id) initWithFrame: (CGRect)frame document: (MuDocRef*)aDoc page: (int)aNumber; - (void) displayImage: (UIImage*)image; - (void) resizeImage; - (void) loadPage; diff --git a/platform/ios/Classes/MuPageView.m b/platform/ios/Classes/MuPageView.m index 53fe79b9..6fa17f54 100644 --- a/platform/ios/Classes/MuPageView.m +++ b/platform/ios/Classes/MuPageView.m @@ -113,11 +113,12 @@ static UIImage *renderTile(fz_document *doc, fz_page *page, CGSize screenSize, C @implementation MuPageView -- (id) initWithFrame: (CGRect)frame document: (fz_document*)aDoc page: (int)aNumber +- (id) initWithFrame: (CGRect)frame document: (MuDocRef *)aDoc page: (int)aNumber { self = [super initWithFrame: frame]; if (self) { - doc = aDoc; + docRef = [aDoc retain]; + doc = docRef->doc; number = aNumber; cancel = NO; @@ -152,12 +153,13 @@ static UIImage *renderTile(fz_document *doc, fz_page *page, CGSize screenSize, C dispatch_async(dispatch_get_main_queue(), ^{ [block_self dealloc]; }); } else { __block fz_page *block_page = page; - __block fz_document *block_doc = doc; + __block fz_document *block_doc = docRef->doc; dispatch_async(queue, ^{ if (block_page) fz_free_page(block_doc, block_page); block_page = nil; }); + [docRef release]; [linkView release]; [hitView release]; [tileView release]; diff --git a/platform/ios/MuPDF.xcodeproj/project.pbxproj b/platform/ios/MuPDF.xcodeproj/project.pbxproj index 40e1211b..d905e32d 100644 --- a/platform/ios/MuPDF.xcodeproj/project.pbxproj +++ b/platform/ios/MuPDF.xcodeproj/project.pbxproj @@ -35,6 +35,7 @@ DA1C68B317E86A500061F586 /* MuDocumentController.m in Sources */ = {isa = PBXBuildFile; fileRef = DA1C68A717E864180061F586 /* MuDocumentController.m */; }; DA1C68B517E86A500061F586 /* MuAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = DA1C68A917E864CB0061F586 /* MuAppDelegate.m */; }; DA1C68C417E8969C0061F586 /* common.m in Sources */ = {isa = PBXBuildFile; fileRef = DA1C68C317E8969C0061F586 /* common.m */; }; + DABDEF5A17EC484A00AC35F1 /* MuDocRef.m in Sources */ = {isa = PBXBuildFile; fileRef = DABDEF5917EC484A00AC35F1 /* MuDocRef.m */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -85,6 +86,8 @@ DA1C68A917E864CB0061F586 /* MuAppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = MuAppDelegate.m; path = Classes/MuAppDelegate.m; sourceTree = "<group>"; }; DA1C68C217E8968C0061F586 /* common.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = common.h; sourceTree = "<group>"; }; DA1C68C317E8969C0061F586 /* common.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = common.m; sourceTree = "<group>"; }; + DABDEF5817EC484A00AC35F1 /* MuDocRef.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MuDocRef.h; path = Classes/MuDocRef.h; sourceTree = "<group>"; }; + DABDEF5917EC484A00AC35F1 /* MuDocRef.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = MuDocRef.m; path = Classes/MuDocRef.m; sourceTree = "<group>"; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -179,6 +182,8 @@ DA1C68A717E864180061F586 /* MuDocumentController.m */, DA1C68A817E864CB0061F586 /* MuAppDelegate.h */, DA1C68A917E864CB0061F586 /* MuAppDelegate.m */, + DABDEF5817EC484A00AC35F1 /* MuDocRef.h */, + DABDEF5917EC484A00AC35F1 /* MuDocRef.m */, ); name = Classes; sourceTree = "<group>"; @@ -306,6 +311,7 @@ DA1C68B517E86A500061F586 /* MuAppDelegate.m in Sources */, 96C8ED011779A88E00A30AF4 /* main.m in Sources */, DA1C68C417E8969C0061F586 /* common.m in Sources */, + DABDEF5A17EC484A00AC35F1 /* MuDocRef.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; |