summaryrefslogtreecommitdiff
path: root/platform/ios/Classes/MuDocRef.m
blob: 5a61dffa7eced7e17f239517d1277d29d1d22402 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "common.h"
#include "mupdf/pdf.h"
#import "MuDocRef.h"

@implementation MuDocRef

-(instancetype) initWithFilename:(NSString *)aFilename;
{
	self = [super init];
	if (self)
	{
		dispatch_sync(queue, ^{});

		fz_var(self);

		fz_try(ctx)
		{
			doc = fz_open_document(ctx, aFilename.UTF8String);
			if (!doc)
			{
				[self release];
				self = nil;
			}
			else
			{
				pdf_document *idoc = pdf_specifics(ctx, doc);
				if (idoc) pdf_enable_js(ctx, idoc);
				interactive = (idoc != NULL) && (pdf_crypt_version(ctx, idoc) == 0);
			}
		}
		fz_catch(ctx)
		{
			if (self)
			{
				if (doc != NULL)
					fz_drop_document(ctx, doc);
				[self release];
				self = nil;
			}
		}
	}
	return self;
}

-(void) dealloc
{
	__block fz_document *block_doc = doc;
	dispatch_async(queue, ^{
		fz_drop_document(ctx, block_doc);
	});
	[super dealloc];
}

@end