Commit f66ec6f5 authored by admin's avatar admin

修复pdf 放大

parent 0fa012c4
This diff is collapsed.
...@@ -2,16 +2,4 @@ ...@@ -2,16 +2,4 @@
<Bucket <Bucket
type = "0" type = "0"
version = "2.0"> version = "2.0">
<Breakpoints>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.ExceptionBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
scope = "0"
stopOnStyle = "0">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket> </Bucket>
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
#define Url_h #define Url_h
// url 测试环境 // url 测试环境
#define kRedStarURL @"http://218.244.151.129:7580/" #define kRedStarURL @"http://218.244.151.129:7580/"
// 正式环境 // 正式环境
// #define kRedStarURL @"http://219.235.234.225:7580/" // #define kRedStarURL @"http://219.235.234.225:7580/"
......
...@@ -11,6 +11,8 @@ ...@@ -11,6 +11,8 @@
#import "AnnoContentTableViewCell.h" #import "AnnoContentTableViewCell.h"
#import "AnnounceDetailFootView.h" #import "AnnounceDetailFootView.h"
#import "AttachmentModel.h" #import "AttachmentModel.h"
#import "ReaderViewController.h"
#import "HttpClient.h" #import "HttpClient.h"
...@@ -22,7 +24,7 @@ ...@@ -22,7 +24,7 @@
#define kAnnounceContentCell @"AnnoContentTableViewCell" #define kAnnounceContentCell @"AnnoContentTableViewCell"
#define kAttachmentTableViewCell @"AttachmentTableViewCell" #define kAttachmentTableViewCell @"AttachmentTableViewCell"
@interface AnnoDetailViewController ()<UITableViewDataSource, UITableViewDelegate, UIDocumentInteractionControllerDelegate, UIAlertViewDelegate> @interface AnnoDetailViewController ()<UITableViewDataSource, UITableViewDelegate, UIAlertViewDelegate, ReaderViewControllerDelegate>
@property (nonatomic, strong) UITableView *tableView; @property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) AnnounceDetailHeadView *headerView; @property (nonatomic, strong) AnnounceDetailHeadView *headerView;
...@@ -117,20 +119,37 @@ ...@@ -117,20 +119,37 @@
NSFileManager *fileManager = [NSFileManager defaultManager]; NSFileManager *fileManager = [NSFileManager defaultManager];
if ([fileManager fileExistsAtPath:url]) { if ([fileManager fileExistsAtPath:url]) {
UIDocumentInteractionController *docController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:url]];//为该对象初始化一个加载路径
docController.delegate = self;//设置代理
[docController presentPreviewAnimated:YES]; NSString *phrase = nil; // Document password (for unlocking most encrypted PDF files)
ReaderDocument *document = [ReaderDocument withDocumentFilePath:url password:phrase];
if (document != nil) // Must have a valid ReaderDocument object in order to proceed with things
{
ReaderViewController *readerViewController = [[ReaderViewController alloc] initWithReaderDocument:document];
readerViewController.delegate = self; // Set the ReaderViewController delegate to self
[self.navigationController pushViewController:readerViewController animated:YES];
}
} else { } else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"文件不存在,请下载后再查看!" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil]; UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"文件不存在,请下载后再查看!" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
[alert show]; [alert show];
} }
} }
- (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller - (void)dismissReaderViewController:(ReaderViewController *)viewController
{ {
return self;
[self.navigationController popViewControllerAnimated:YES];
} }
- (void)downloadFile:(UIButton *)sender - (void)downloadFile:(UIButton *)sender
{ {
NSInteger row = sender.tag - 998473; NSInteger row = sender.tag - 998473;
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
#import "AttachmentTableViewCell.h" #import "AttachmentTableViewCell.h"
#import "AttachmentModel.h" #import "AttachmentModel.h"
#import "ShowPDFWebViewController.h" #import "ReaderViewController.h"
#import <MBProgressHUD.h> #import <MBProgressHUD.h>
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
#define SELECTED_VIEW_CONTROLLER_TAG 39998 #define SELECTED_VIEW_CONTROLLER_TAG 39998
@interface SOPViewController () <UIAlertViewDelegate,GroupTabBarDelegate, SOPTableViewDelegate, UITableViewDelegate, UITableViewDataSource, UIDocumentInteractionControllerDelegate> @interface SOPViewController () <UIAlertViewDelegate,GroupTabBarDelegate, SOPTableViewDelegate, UITableViewDelegate, UITableViewDataSource, UIDocumentInteractionControllerDelegate,ReaderViewControllerDelegate>
@property (nonatomic, strong) GroupTabBar *groupTabBar; @property (nonatomic, strong) GroupTabBar *groupTabBar;
@property (nonatomic, strong) NSArray *titleArray; @property (nonatomic, strong) NSArray *titleArray;
...@@ -246,31 +246,37 @@ ...@@ -246,31 +246,37 @@
NSFileManager *fileManager = [NSFileManager defaultManager]; NSFileManager *fileManager = [NSFileManager defaultManager];
if ([fileManager fileExistsAtPath:url]) { if ([fileManager fileExistsAtPath:url]) {
ShowPDFWebViewController *showVC = [[ShowPDFWebViewController alloc] init];
showVC.url = url;
showVC.fileName = atta.fileName;
[self.navigationController pushViewController:showVC animated:YES];
NSString *phrase = nil; // Document password (for unlocking most encrypted PDF files)
ReaderDocument *document = [ReaderDocument withDocumentFilePath:url password:phrase];
if (document != nil) // Must have a valid ReaderDocument object in order to proceed with things
{
ReaderViewController *readerViewController = [[ReaderViewController alloc] initWithReaderDocument:document];
readerViewController.delegate = self; // Set the ReaderViewController delegate to self
[self.navigationController pushViewController:readerViewController animated:YES];
}
// NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL fileURLWithPath:url]];
// UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
// [webView loadRequest:request];
//
// [self.view addSubview:webView];
// UIDocumentInteractionController *docController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:url]];//为该对象初始化一个加载路径
// docController.delegate = self;//设置代理
// [docController presentPreviewAnimated:YES];
} else { } else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"文件不存在,请先下载在查看!" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil]; UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"文件不存在,请先下载在查看!" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
[alert show]; [alert show];
} }
} }
- (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller - (void)dismissReaderViewController:(ReaderViewController *)viewController
{ {
return self;
[self.navigationController popViewControllerAnimated:YES];
} }
- (void)downloadFile:(UIButton *)sender - (void)downloadFile:(UIButton *)sender
{ {
NSInteger row = sender.tag - 998473; NSInteger row = sender.tag - 998473;
......
//
// ShowPDFWebViewController.h
// redstar
//
// Created by admin on 16/1/14.
// Copyright © 2016年 ZWF. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface ShowPDFWebViewController : UIViewController
@property (nonatomic, strong) NSString *url;
@property (nonatomic, strong) NSString *fileName;
@end
//
// ShowPDFWebViewController.m
// redstar
//
// Created by admin on 16/1/14.
// Copyright © 2016年 ZWF. All rights reserved.
//
#import "ShowPDFWebViewController.h"
#import <MBProgressHUD.h>
@interface ShowPDFWebViewController ()
@property (nonatomic, strong) UIWebView *webView;
@end
@implementation ShowPDFWebViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self setupNav];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL fileURLWithPath:self.url]];
[self.webView loadRequest:request];
}
- (void)setupNav
{
UILabel *customLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 40, 30)];
[customLab setTextColor:[UIColor whiteColor]];
[customLab setText:self.fileName];
customLab.font = [UIFont boldSystemFontOfSize:19];
self.navigationItem.titleView = customLab;
UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
backBtn.frame = CGRectMake(0, 0, 30, 44);
[backBtn setImage:[UIImage imageNamed:@"back_btn"] forState:UIControlStateNormal];
[backBtn addTarget:self action:@selector(doBack:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithCustomView:backBtn];
self.navigationItem.leftBarButtonItem = backItem;
}
- (void)doBack:(UIBarButtonItem *)sender
{
[self.navigationController popViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (UIWebView *)webView
{
if (!_webView) {
_webView = [[UIWebView alloc] initWithFrame:[UIScreen mainScreen].bounds];
_webView.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addSubview:_webView];
NSLayoutConstraint *tableTop = [NSLayoutConstraint constraintWithItem:_webView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeTop multiplier:1.0 constant:0];
[self.view addConstraint:tableTop];
NSLayoutConstraint *tableLeft = [NSLayoutConstraint constraintWithItem:_webView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeLeft multiplier:1.0 constant:0];
[self.view addConstraint:tableLeft];
NSLayoutConstraint *tableRight = [NSLayoutConstraint constraintWithItem:_webView attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeRight multiplier:1.0 constant:0];
[self.view addConstraint:tableRight];
NSLayoutConstraint *tableBottom = [NSLayoutConstraint constraintWithItem:_webView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0];
[self.view addConstraint:tableBottom];
}
return _webView;
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
//
// ReaderConstants.h
// Reader v2.6.0
//
// Created by Julius Oklamcak on 2011-07-01.
// Copyright © 2011-2013 Julius Oklamcak. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
// of the Software, and to permit persons to whom the Software is furnished to
// do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if !__has_feature(objc_arc)
#error ARC (-fobjc-arc) is required to build this code.
#endif
#import <Foundation/Foundation.h>
#define READER_BOOKMARKS TRUE
#define READER_ENABLE_MAIL TRUE
#define READER_ENABLE_PRINT TRUE
#define READER_ENABLE_THUMBS TRUE
#define READER_ENABLE_PREVIEW TRUE
#define READER_DISABLE_RETINA FALSE
#define READER_DISABLE_IDLE FALSE
#define READER_SHOW_SHADOWS TRUE
#define READER_STANDALONE FALSE
extern NSString *const kReaderCopyrightNotice;
//
// ReaderConstants.m
// Reader v2.6.0
//
// Created by Julius Oklamcak on 2011-07-01.
// Copyright © 2011-2013 Julius Oklamcak. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
// of the Software, and to permit persons to whom the Software is furnished to
// do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#import "ReaderConstants.h"
NSString *const kReaderCopyrightNotice = @"Reader v2.x • Copyright © 2011-2013 Julius Oklamcak. All rights reserved.";
//
// ReaderContentPage.h
// Reader v2.6.1
//
// Created by Julius Oklamcak on 2011-07-01.
// Copyright © 2011-2013 Julius Oklamcak. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
// of the Software, and to permit persons to whom the Software is furnished to
// do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#import <UIKit/UIKit.h>
@interface ReaderContentPage : UIView
- (id)initWithURL:(NSURL *)fileURL page:(NSInteger)page password:(NSString *)phrase;
- (id)processSingleTap:(UITapGestureRecognizer *)recognizer;
@end
#pragma mark -
//
// ReaderDocumentLink class interface
//
@interface ReaderDocumentLink : NSObject <NSObject>
@property (nonatomic, assign, readonly) CGRect rect;
@property (nonatomic, assign, readonly) CGPDFDictionaryRef dictionary;
+ (id)newWithRect:(CGRect)linkRect dictionary:(CGPDFDictionaryRef)linkDictionary;
- (id)initWithRect:(CGRect)linkRect dictionary:(CGPDFDictionaryRef)linkDictionary;
@end
//
// ReaderContentTile.h
// Reader v2.6.0
//
// Created by Julius Oklamcak on 2011-07-01.
// Copyright © 2011-2013 Julius Oklamcak. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
// of the Software, and to permit persons to whom the Software is furnished to
// do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
@interface ReaderContentTile : CATiledLayer
@end
//
// ReaderContentTile.m
// Reader v2.7.3
//
// Created by Julius Oklamcak on 2011-07-01.
// Copyright © 2011-2013 Julius Oklamcak. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
// of the Software, and to permit persons to whom the Software is furnished to
// do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#import "ReaderContentTile.h"
@implementation ReaderContentTile
#pragma mark Constants
#define LEVELS_OF_DETAIL 16
#pragma mark ReaderContentTile class methods
+ (CFTimeInterval)fadeDuration
{
return 0.001; // iOS bug (flickering tiles) workaround
}
#pragma mark ReaderContentTile instance methods
- (id)init
{
if ((self = [super init]))
{
self.levelsOfDetail = LEVELS_OF_DETAIL; // Zoom levels
self.levelsOfDetailBias = (LEVELS_OF_DETAIL - 1); // Bias
UIScreen *mainScreen = [UIScreen mainScreen]; // Main screen
CGFloat screenScale = [mainScreen scale]; // Main screen scale
CGRect screenBounds = [mainScreen bounds]; // Main screen bounds
CGFloat w_pixels = (screenBounds.size.width * screenScale);
CGFloat h_pixels = (screenBounds.size.height * screenScale);
CGFloat max = ((w_pixels < h_pixels) ? h_pixels : w_pixels);
CGFloat sizeOfTiles = ((max < 512.0f) ? 512.0f : 1024.0f);
self.tileSize = CGSizeMake(sizeOfTiles, sizeOfTiles);
}
return self;
}
@end
//
// ReaderContentView.h
// Reader v2.7.3
//
// Created by Julius Oklamcak on 2011-07-01.
// Copyright © 2011-2013 Julius Oklamcak. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
// of the Software, and to permit persons to whom the Software is furnished to
// do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#import <UIKit/UIKit.h>
#import "ReaderThumbView.h"
@class ReaderContentView;
@class ReaderContentPage;
@class ReaderContentThumb;
@protocol ReaderContentViewDelegate <NSObject>
@required // Delegate protocols
- (void)contentView:(ReaderContentView *)contentView touchesBegan:(NSSet *)touches;
@end
@interface ReaderContentView : UIScrollView
@property (nonatomic, weak, readwrite) id <ReaderContentViewDelegate> message;
- (id)initWithFrame:(CGRect)frame fileURL:(NSURL *)fileURL page:(NSUInteger)page password:(NSString *)phrase;
- (void)showPageThumb:(NSURL *)fileURL page:(NSInteger)page password:(NSString *)phrase guid:(NSString *)guid;
- (id)processSingleTap:(UITapGestureRecognizer *)recognizer;
- (void)zoomIncrement;
- (void)zoomDecrement;
- (void)zoomReset;
@end
#pragma mark -
//
// ReaderContentThumb class interface
//
@interface ReaderContentThumb : ReaderThumbView
@end
//
// ReaderContentView.m
// Reader v2.7.3
//
// Created by Julius Oklamcak on 2011-07-01.
// Copyright © 2011-2013 Julius Oklamcak. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
// of the Software, and to permit persons to whom the Software is furnished to
// do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#import "ReaderConstants.h"
#import "ReaderContentView.h"
#import "ReaderContentPage.h"
#import "ReaderThumbCache.h"
#import <QuartzCore/QuartzCore.h>
@interface ReaderContentView () <UIScrollViewDelegate>
@end
@implementation ReaderContentView
{
ReaderContentPage *theContentView;
ReaderContentThumb *theThumbView;
UIView *theContainerView;
}
#pragma mark Constants
#define ZOOM_FACTOR 2.0f
#define ZOOM_MAXIMUM 16.0f
#if (READER_SHOW_SHADOWS == TRUE) // Option
#define CONTENT_INSET 4.0f
#else
#define CONTENT_INSET 2.0f
#endif // end of READER_SHOW_SHADOWS Option
#define PAGE_THUMB_LARGE 240
#define PAGE_THUMB_SMALL 144
static void *ReaderContentViewContext = &ReaderContentViewContext;
#pragma mark Properties
@synthesize message;
#pragma mark ReaderContentView functions
static inline CGFloat ZoomScaleThatFits(CGSize target, CGSize source)
{
CGFloat w_scale = (target.width / source.width);
CGFloat h_scale = (target.height / source.height);
return ((w_scale < h_scale) ? w_scale : h_scale);
}
#pragma mark ReaderContentView instance methods
- (void)updateMinimumMaximumZoom
{
CGRect targetRect = CGRectInset(self.bounds, CONTENT_INSET, CONTENT_INSET);
CGFloat zoomScale = ZoomScaleThatFits(targetRect.size, theContentView.bounds.size);
self.minimumZoomScale = zoomScale; // Set the minimum and maximum zoom scales
self.maximumZoomScale = (zoomScale * ZOOM_MAXIMUM); // Max number of zoom levels
}
- (id)initWithFrame:(CGRect)frame fileURL:(NSURL *)fileURL page:(NSUInteger)page password:(NSString *)phrase
{
if ((self = [super initWithFrame:frame]))
{
self.scrollsToTop = NO;
self.delaysContentTouches = NO;
self.showsVerticalScrollIndicator = NO;
self.showsHorizontalScrollIndicator = NO;
self.contentMode = UIViewContentModeRedraw;
self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.backgroundColor = [UIColor clearColor];
self.userInteractionEnabled = YES;
self.autoresizesSubviews = NO;
self.bouncesZoom = YES;
self.delegate = self;
theContentView = [[ReaderContentPage alloc] initWithURL:fileURL page:page password:phrase];
if (theContentView != nil) // Must have a valid and initialized content view
{
theContainerView = [[UIView alloc] initWithFrame:theContentView.bounds];
theContainerView.autoresizesSubviews = NO;
theContainerView.userInteractionEnabled = NO;
theContainerView.contentMode = UIViewContentModeRedraw;
theContainerView.autoresizingMask = UIViewAutoresizingNone;
theContainerView.backgroundColor = [UIColor whiteColor];
#if (READER_SHOW_SHADOWS == TRUE) // Option
theContainerView.layer.shadowOffset = CGSizeMake(0.0f, 0.0f);
theContainerView.layer.shadowRadius = 4.0f; theContainerView.layer.shadowOpacity = 1.0f;
theContainerView.layer.shadowPath = [UIBezierPath bezierPathWithRect:theContainerView.bounds].CGPath;
#endif // end of READER_SHOW_SHADOWS Option
self.contentSize = theContentView.bounds.size; // Content size same as view size
self.contentOffset = CGPointMake((0.0f - CONTENT_INSET), (0.0f - CONTENT_INSET)); // Offset
self.contentInset = UIEdgeInsetsMake(CONTENT_INSET, CONTENT_INSET, CONTENT_INSET, CONTENT_INSET);
#if (READER_ENABLE_PREVIEW == TRUE) // Option
theThumbView = [[ReaderContentThumb alloc] initWithFrame:theContentView.bounds]; // Page thumb view
[theContainerView addSubview:theThumbView]; // Add the thumb view to the container view
#endif // end of READER_ENABLE_PREVIEW Option
[theContainerView addSubview:theContentView]; // Add the content view to the container view
[self addSubview:theContainerView]; // Add the container view to the scroll view
[self updateMinimumMaximumZoom]; // Update the minimum and maximum zoom scales
self.zoomScale = self.minimumZoomScale; // Set zoom to fit page content
}
[self addObserver:self forKeyPath:@"frame" options:0 context:ReaderContentViewContext];
self.tag = page; // Tag the view with the page number
}
return self;
}
- (void)dealloc
{
[self removeObserver:self forKeyPath:@"frame" context:ReaderContentViewContext];
}
- (void)showPageThumb:(NSURL *)fileURL page:(NSInteger)page password:(NSString *)phrase guid:(NSString *)guid
{
#if (READER_ENABLE_PREVIEW == TRUE) // Option
BOOL large = ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad); // Page thumb size
CGSize size = (large ? CGSizeMake(PAGE_THUMB_LARGE, PAGE_THUMB_LARGE) : CGSizeMake(PAGE_THUMB_SMALL, PAGE_THUMB_SMALL));
ReaderThumbRequest *request = [ReaderThumbRequest newForView:theThumbView fileURL:fileURL password:phrase guid:guid page:page size:size];
UIImage *image = [[ReaderThumbCache sharedInstance] thumbRequest:request priority:YES]; // Request the page thumb
if ([image isKindOfClass:[UIImage class]]) [theThumbView showImage:image]; // Show image from cache
#endif // end of READER_ENABLE_PREVIEW Option
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if (context == ReaderContentViewContext) // Our context
{
if ((object == self) && [keyPath isEqualToString:@"frame"])
{
CGFloat oldMinimumZoomScale = self.minimumZoomScale;
[self updateMinimumMaximumZoom]; // Update zoom scale limits
if (self.zoomScale == oldMinimumZoomScale) // Old minimum
{
self.zoomScale = self.minimumZoomScale;
}
else // Check against minimum zoom scale
{
if (self.zoomScale < self.minimumZoomScale)
{
self.zoomScale = self.minimumZoomScale;
}
else // Check against maximum zoom scale
{
if (self.zoomScale > self.maximumZoomScale)
{
self.zoomScale = self.maximumZoomScale;
}
}
}
}
}
}
- (void)layoutSubviews
{
[super layoutSubviews];
CGSize boundsSize = self.bounds.size;
CGRect viewFrame = theContainerView.frame;
if (viewFrame.size.width < boundsSize.width)
viewFrame.origin.x = (((boundsSize.width - viewFrame.size.width) / 2.0f) + self.contentOffset.x);
else
viewFrame.origin.x = 0.0f;
if (viewFrame.size.height < boundsSize.height)
viewFrame.origin.y = (((boundsSize.height - viewFrame.size.height) / 2.0f) + self.contentOffset.y);
else
viewFrame.origin.y = 0.0f;
theContainerView.frame = viewFrame;
}
- (id)processSingleTap:(UITapGestureRecognizer *)recognizer
{
return [theContentView processSingleTap:recognizer];
}
- (void)zoomIncrement
{
CGFloat zoomScale = self.zoomScale;
if (zoomScale < self.maximumZoomScale)
{
zoomScale *= ZOOM_FACTOR; // Zoom in
if (zoomScale > self.maximumZoomScale)
{
zoomScale = self.maximumZoomScale;
}
[self setZoomScale:zoomScale animated:YES];
}
}
- (void)zoomDecrement
{
CGFloat zoomScale = self.zoomScale;
if (zoomScale > self.minimumZoomScale)
{
zoomScale /= ZOOM_FACTOR; // Zoom out
if (zoomScale < self.minimumZoomScale)
{
zoomScale = self.minimumZoomScale;
}
[self setZoomScale:zoomScale animated:YES];
}
}
- (void)zoomReset
{
if (self.zoomScale > self.minimumZoomScale)
{
self.zoomScale = self.minimumZoomScale;
}
}
#pragma mark UIScrollViewDelegate methods
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
return theContainerView;
}
#pragma mark UIResponder instance methods
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[super touchesBegan:touches withEvent:event]; // Message superclass
[message contentView:self touchesBegan:touches]; // Message delegate
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
[super touchesCancelled:touches withEvent:event]; // Message superclass
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
[super touchesEnded:touches withEvent:event]; // Message superclass
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
[super touchesMoved:touches withEvent:event]; // Message superclass
}
@end
#pragma mark -
//
// ReaderContentThumb class implementation
//
@implementation ReaderContentThumb
#pragma mark ReaderContentThumb instance methods
- (id)initWithFrame:(CGRect)frame
{
if ((self = [super initWithFrame:frame])) // Superclass init
{
imageView.contentMode = UIViewContentModeScaleAspectFill;
imageView.clipsToBounds = YES; // Needed for aspect fill
}
return self;
}
@end
//
// ReaderDocument.h
// Reader v2.6.0
//
// Created by Julius Oklamcak on 2011-07-01.
// Copyright © 2011-2013 Julius Oklamcak. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
// of the Software, and to permit persons to whom the Software is furnished to
// do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#import <Foundation/Foundation.h>
@interface ReaderDocument : NSObject <NSObject, NSCoding>
@property (nonatomic, strong, readonly) NSString *guid;
@property (nonatomic, strong, readonly) NSDate *fileDate;
@property (nonatomic, strong, readwrite) NSDate *lastOpen;
@property (nonatomic, strong, readonly) NSNumber *fileSize;
@property (nonatomic, strong, readonly) NSNumber *pageCount;
@property (nonatomic, strong, readwrite) NSNumber *pageNumber;
@property (nonatomic, strong, readonly) NSMutableIndexSet *bookmarks;
@property (nonatomic, strong, readonly) NSString *fileName;
@property (nonatomic, strong, readonly) NSString *filePath;
@property (nonatomic, strong, readonly) NSString *password;
@property (nonatomic, strong, readonly) NSURL *fileURL;
+ (ReaderDocument *)withDocumentFilePath:(NSString *)filename password:(NSString *)phrase;
+ (ReaderDocument *)unarchiveFromFileName:(NSString *)filename password:(NSString *)phrase;
- (id)initWithFilePath:(NSString *)fullFilePath password:(NSString *)phrase;
- (void)saveReaderDocument;
- (void)updateProperties;
@end
This diff is collapsed.
//
// ReaderMainPagebar.h
// Reader v2.7.1
//
// Created by Julius Oklamcak on 2011-09-01.
// Copyright © 2011-2013 Julius Oklamcak. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
// of the Software, and to permit persons to whom the Software is furnished to
// do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#import <UIKit/UIKit.h>
#import "ReaderThumbView.h"
#import "UIXToolbarView.h"
@class ReaderMainPagebar;
@class ReaderTrackControl;
@class ReaderPagebarThumb;
@class ReaderDocument;
@protocol ReaderMainPagebarDelegate <NSObject>
@required // Delegate protocols
- (void)pagebar:(ReaderMainPagebar *)pagebar gotoPage:(NSInteger)page;
@end
@interface ReaderMainPagebar : UIToolbar
@property (nonatomic, weak, readwrite) id <ReaderMainPagebarDelegate> pagebarDelegate;
- (id)initWithFrame:(CGRect)frame document:(ReaderDocument *)object;
- (void)updatePagebar;
- (void)hidePagebar;
- (void)showPagebar;
@end
#pragma mark -
//
// ReaderTrackControl class interface
//
@interface ReaderTrackControl : UIControl
@property (nonatomic, assign, readonly) CGFloat value;
@end
#pragma mark -
//
// ReaderPagebarThumb class interface
//
@interface ReaderPagebarThumb : ReaderThumbView
- (id)initWithFrame:(CGRect)frame small:(BOOL)small;
@end
\ No newline at end of file
//
// ReaderViewController.h
// Reader v2.7.1
//
// Created by Julius Oklamcak on 2011-07-01.
// Copyright © 2011-2013 Julius Oklamcak. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
// of the Software, and to permit persons to whom the Software is furnished to
// do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#import <UIKit/UIKit.h>
#import "ReaderDocument.h"
@class ReaderViewController;
@protocol ReaderViewControllerDelegate <NSObject>
@optional // Delegate protocols
- (void)dismissReaderViewController:(ReaderViewController *)viewController;
@end
@interface ReaderViewController : UIViewController
@property (strong, nonatomic, readwrite) ReaderDocument *document;
@property (assign, nonatomic, readwrite) NSInteger currentPage;
//
// A UINavigationItem property to allow the PDF View Controller to set its nav
// bar elements in a UINavigationItem other than its own default.
//
// This is useful when you're implementing the PDF View Controller as a subview
// of another VC's view in a UINavigationController, so the PDF View Controller will
// automatically add its bar button items to the UINavigationController's nav bar.
//
@property (strong, nonatomic, readwrite) UINavigationItem *remoteNavigationItem;
@property (strong, nonatomic, readwrite) UINavigationController *remoteNavigationController;
@property (nonatomic, weak, readwrite) id <ReaderViewControllerDelegate> delegate;
- (id)initWithReaderDocument:(ReaderDocument *)object;
- (void)showDocumentPage:(NSInteger)page;
@end
//
// CGPDFDocument.h
// Reader v2.6.0
//
// Created by Julius Oklamcak on 2011-07-01.
// Copyright © 2011-2013 Julius Oklamcak. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
// of the Software, and to permit persons to whom the Software is furnished to
// do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#import <Foundation/Foundation.h>
#import <QuartzCore/QuartzCore.h>
//
// Custom CGPDFDocument[...] functions
//
CGPDFDocumentRef CGPDFDocumentCreateX(CFURLRef theURL, NSString *password);
BOOL CGPDFDocumentNeedsPassword(CFURLRef theURL, NSString *password);
//
// CGPDFDocument.m
// Reader v2.6.0
//
// Created by Julius Oklamcak on 2011-07-01.
// Copyright © 2011-2013 Julius Oklamcak. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
// of the Software, and to permit persons to whom the Software is furnished to
// do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#import "CGPDFDocument.h"
//
// CGPDFDocumentRef CGPDFDocumentCreateX(CFURLRef, NSString *) function
//
CGPDFDocumentRef CGPDFDocumentCreateX(CFURLRef theURL, NSString *password)
{
CGPDFDocumentRef thePDFDocRef = NULL;
if (theURL != NULL) // Check for non-NULL CFURLRef
{
thePDFDocRef = CGPDFDocumentCreateWithURL(theURL);
if (thePDFDocRef != NULL) // Check for non-NULL CGPDFDocumentRef
{
if (CGPDFDocumentIsEncrypted(thePDFDocRef) == TRUE) // Encrypted
{
// Try a blank password first, per Apple's Quartz PDF example
if (CGPDFDocumentUnlockWithPassword(thePDFDocRef, "") == FALSE)
{
// Nope, now let's try the provided password to unlock the PDF
if ((password != nil) && ([password length] > 0)) // Not blank?
{
char text[128]; // char array buffer for the string conversion
[password getCString:text maxLength:126 encoding:NSUTF8StringEncoding];
if (CGPDFDocumentUnlockWithPassword(thePDFDocRef, text) == FALSE) // Log failure
{
#ifdef DEBUG
NSLog(@"CGPDFDocumentCreateX: Unable to unlock [%@] with [%@]", theURL, password);
#endif
}
}
}
if (CGPDFDocumentIsUnlocked(thePDFDocRef) == FALSE) // Cleanup unlock failure
{
CGPDFDocumentRelease(thePDFDocRef), thePDFDocRef = NULL;
}
}
}
}
else // Log an error diagnostic
{
#ifdef DEBUG
NSLog(@"CGPDFDocumentCreateX: theURL == NULL");
#endif
}
return thePDFDocRef;
}
//
// BOOL CGPDFDocumentNeedsPassword(CFURLRef, NSString *) function
//
BOOL CGPDFDocumentNeedsPassword(CFURLRef theURL, NSString *password)
{
BOOL needPassword = NO; // Default flag
if (theURL != NULL) // Check for non-NULL CFURLRef
{
CGPDFDocumentRef thePDFDocRef = CGPDFDocumentCreateWithURL(theURL);
if (thePDFDocRef != NULL) // Check for non-NULL CGPDFDocumentRef
{
if (CGPDFDocumentIsEncrypted(thePDFDocRef) == TRUE) // Encrypted
{
// Try a blank password first, per Apple's Quartz PDF example
if (CGPDFDocumentUnlockWithPassword(thePDFDocRef, "") == FALSE)
{
// Nope, now let's try the provided password to unlock the PDF
if ((password != nil) && ([password length] > 0)) // Not blank?
{
char text[128]; // char array buffer for the string conversion
[password getCString:text maxLength:126 encoding:NSUTF8StringEncoding];
if (CGPDFDocumentUnlockWithPassword(thePDFDocRef, text) == FALSE)
{
needPassword = YES;
}
}
else
{
needPassword = YES;
}
}
}
CGPDFDocumentRelease(thePDFDocRef); // Cleanup CGPDFDocumentRef
}
}
else // Log an error diagnostic
{
#ifdef DEBUG
NSLog(@"CGPDFDocumentNeedsPassword: theURL == NULL");
#endif
}
return needPassword;
}
// EOF
//
// ReaderDocumentOutline.m
// Reader v2.6.1
//
// Created by Julius Oklamcak on 2012-09-01.
// Copyright © 2011-2013 Julius Oklamcak. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
// of the Software, and to permit persons to whom the Software is furnished to
// do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#import <Foundation/Foundation.h>
@interface ReaderDocumentOutline : NSObject <NSObject>
+ (NSArray *)outlineFromFileURL:(NSURL *)fileURL password:(NSString *)phrase;
+ (void)logDocumentOutlineArray:(NSArray *)array;
@end
@interface DocumentOutlineEntry : NSObject <NSObject>
+ (id)newWithTitle:(NSString *)title target:(id)target level:(NSInteger)level;
- (id)initWithTitle:(NSString *)title target:(id)target level:(NSInteger)level;
@property (nonatomic, assign, readonly) NSInteger level;
@property (nonatomic, strong, readwrite) NSMutableArray *children;
@property (nonatomic, strong, readonly) NSString *title;
@property (nonatomic, strong, readonly) id target;
@end
//
// ReaderThumbCache.h
// Reader v2.6.0
//
// Created by Julius Oklamcak on 2011-09-01.
// Copyright © 2011-2013 Julius Oklamcak. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
// of the Software, and to permit persons to whom the Software is furnished to
// do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#import <UIKit/UIKit.h>
#import "ReaderThumbRequest.h"
@interface ReaderThumbCache : NSObject <NSObject>
+ (ReaderThumbCache *)sharedInstance;
+ (void)touchThumbCacheWithGUID:(NSString *)guid;
+ (void)createThumbCacheWithGUID:(NSString *)guid;
+ (void)removeThumbCacheWithGUID:(NSString *)guid;
+ (void)purgeThumbCachesOlderThan:(NSTimeInterval)age;
+ (NSString *)thumbCachePathForGUID:(NSString *)guid;
- (id)thumbRequest:(ReaderThumbRequest *)request priority:(BOOL)priority;
- (void)setObject:(UIImage *)image forKey:(NSString *)key;
- (void)removeObjectForKey:(NSString *)key;
- (void)removeNullForKey:(NSString *)key;
- (void)removeAllObjects;
@end
//
// ReaderThumbCache.m
// Reader v2.6.0
//
// Created by Julius Oklamcak on 2011-09-01.
// Copyright © 2011-2013 Julius Oklamcak. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
// of the Software, and to permit persons to whom the Software is furnished to
// do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#import "ReaderThumbCache.h"
#import "ReaderThumbQueue.h"
#import "ReaderThumbFetch.h"
#import "ReaderThumbView.h"
@implementation ReaderThumbCache
{
NSCache *thumbCache;
}
#pragma mark Constants
#define CACHE_SIZE 2097152
#pragma mark ReaderThumbCache class methods
+ (ReaderThumbCache *)sharedInstance
{
static dispatch_once_t predicate = 0;
static ReaderThumbCache *object = nil; // Object
dispatch_once(&predicate, ^{ object = [self new]; });
return object; // ReaderThumbCache singleton
}
+ (NSString *)appCachesPath
{
static dispatch_once_t predicate = 0;
static NSString *theCachesPath = nil; // Application caches path string
dispatch_once(&predicate, // Save a copy of the application caches path the first time it is needed
^{
NSArray *cachesPaths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
theCachesPath = [[cachesPaths objectAtIndex:0] copy]; // Keep a copy for later abusage
});
return theCachesPath;
}
+ (NSString *)thumbCachePathForGUID:(NSString *)guid
{
NSString *cachesPath = [ReaderThumbCache appCachesPath]; // Caches path
return [cachesPath stringByAppendingPathComponent:guid]; // Append GUID
}
+ (void)createThumbCacheWithGUID:(NSString *)guid
{
NSFileManager *fileManager = [NSFileManager new]; // File manager instance
NSString *cachePath = [ReaderThumbCache thumbCachePathForGUID:guid]; // Thumb cache path
[fileManager createDirectoryAtPath:cachePath withIntermediateDirectories:NO attributes:nil error:NULL];
}
+ (void)removeThumbCacheWithGUID:(NSString *)guid
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0),
^{
NSFileManager *fileManager = [NSFileManager new]; // File manager instance
NSString *cachePath = [ReaderThumbCache thumbCachePathForGUID:guid]; // Thumb cache path
[fileManager removeItemAtPath:cachePath error:NULL]; // Remove thumb cache directory
});
}
+ (void)touchThumbCacheWithGUID:(NSString *)guid
{
NSFileManager *fileManager = [NSFileManager new]; // File manager instance
NSString *cachePath = [ReaderThumbCache thumbCachePathForGUID:guid]; // Thumb cache path
NSDictionary *attributes = [NSDictionary dictionaryWithObject:[NSDate date] forKey:NSFileModificationDate];
[fileManager setAttributes:attributes ofItemAtPath:cachePath error:NULL]; // New modification date
}
+ (void)purgeThumbCachesOlderThan:(NSTimeInterval)age
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0),
^{
NSDate *now = [NSDate date]; // Right about now time
NSString *cachesPath = [ReaderThumbCache appCachesPath]; // Caches path
NSFileManager *fileManager = [NSFileManager new]; // File manager instance
NSArray *cachesList = [fileManager contentsOfDirectoryAtPath:cachesPath error:NULL];
if (cachesList != nil) // Process caches directory contents
{
for (NSString *cacheName in cachesList) // Enumerate directory contents
{
if (cacheName.length == 36) // This is a very hacky cache ident kludge
{
NSString *cachePath = [cachesPath stringByAppendingPathComponent:cacheName];
NSDictionary *attributes = [fileManager attributesOfItemAtPath:cachePath error:NULL];
NSDate *cacheDate = [attributes objectForKey:NSFileModificationDate]; // Cache date
NSTimeInterval seconds = [now timeIntervalSinceDate:cacheDate]; // Cache age
if (seconds > age) // Older than so remove the thumb cache
{
[fileManager removeItemAtPath:cachePath error:NULL];
#ifdef DEBUG
NSLog(@"%s purged %@", __FUNCTION__, cacheName);
#endif
}
}
}
}
});
}
#pragma mark ReaderThumbCache instance methods
- (id)init
{
if ((self = [super init])) // Initialize
{
thumbCache = [NSCache new]; // Cache
[thumbCache setName:@"ReaderThumbCache"];
[thumbCache setTotalCostLimit:CACHE_SIZE];
}
return self;
}
- (id)thumbRequest:(ReaderThumbRequest *)request priority:(BOOL)priority
{
@synchronized(thumbCache) // Mutex lock
{
id object = [thumbCache objectForKey:request.cacheKey];
if (object == nil) // Thumb object does not yet exist in the cache
{
object = [NSNull null]; // Return an NSNull thumb placeholder object
[thumbCache setObject:object forKey:request.cacheKey cost:2]; // Cache the placeholder object
ReaderThumbFetch *thumbFetch = [[ReaderThumbFetch alloc] initWithRequest:request]; // Create a thumb fetch operation
[thumbFetch setQueuePriority:(priority ? NSOperationQueuePriorityNormal : NSOperationQueuePriorityLow)]; // Queue priority
request.thumbView.operation = thumbFetch; [thumbFetch setThreadPriority:(priority ? 0.55 : 0.35)]; // Thread priority
[[ReaderThumbQueue sharedInstance] addLoadOperation:thumbFetch]; // Queue the operation
}
return object; // NSNull or UIImage
}
}
- (void)setObject:(UIImage *)image forKey:(NSString *)key
{
@synchronized(thumbCache) // Mutex lock
{
NSUInteger bytes = (image.size.width * image.size.height * 4.0f);
[thumbCache setObject:image forKey:key cost:bytes]; // Cache image
}
}
- (void)removeObjectForKey:(NSString *)key
{
@synchronized(thumbCache) // Mutex lock
{
[thumbCache removeObjectForKey:key];
}
}
- (void)removeNullForKey:(NSString *)key
{
@synchronized(thumbCache) // Mutex lock
{
id object = [thumbCache objectForKey:key];
if ([object isMemberOfClass:[NSNull class]])
{
[thumbCache removeObjectForKey:key];
}
}
}
- (void)removeAllObjects
{
@synchronized(thumbCache) // Mutex lock
{
[thumbCache removeAllObjects];
}
}
@end
//
// ReaderThumbFetch.h
// Reader v2.6.1
//
// Created by Julius Oklamcak on 2011-09-01.
// Copyright © 2011-2013 Julius Oklamcak. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
// of the Software, and to permit persons to whom the Software is furnished to
// do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#import <Foundation/Foundation.h>
#import "ReaderThumbQueue.h"
@class ReaderThumbRequest;
@interface ReaderThumbFetch : ReaderThumbOperation
- (id)initWithRequest:(ReaderThumbRequest *)options;
@end
//
// ReaderThumbQueue.h
// Reader v2.6.0
//
// Created by Julius Oklamcak on 2011-09-01.
// Copyright © 2011-2013 Julius Oklamcak. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
// of the Software, and to permit persons to whom the Software is furnished to
// do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#import <Foundation/Foundation.h>
@interface ReaderThumbQueue : NSObject <NSObject>
+ (ReaderThumbQueue *)sharedInstance;
- (void)addLoadOperation:(NSOperation *)operation;
- (void)addWorkOperation:(NSOperation *)operation;
- (void)cancelOperationsWithGUID:(NSString *)guid;
- (void)cancelAllOperations;
@end
#pragma mark -
//
// ReaderThumbOperation class interface
//
@interface ReaderThumbOperation : NSOperation
@property (nonatomic, strong, readonly) NSString *guid;
- (id)initWithGUID:(NSString *)guid;
@end
//
// ReaderThumbRender.h
// Reader v2.6.1
//
// Created by Julius Oklamcak on 2011-09-01.
// Copyright © 2011-2013 Julius Oklamcak. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
// of the Software, and to permit persons to whom the Software is furnished to
// do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#import <Foundation/Foundation.h>
#import "ReaderThumbQueue.h"
@class ReaderThumbRequest;
@interface ReaderThumbRender : ReaderThumbOperation
- (id)initWithRequest:(ReaderThumbRequest *)options;
@end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment