Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions Classes/PDFContainer.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,29 +36,29 @@ - (void)dealloc {
CGPDFDocumentRelease(_PDFDocRef);
[_fileURL release];
[_password release];

[super dealloc];
}

- (BOOL)changeFileURL:(NSURL *)fileURL password:(NSString *)password
{
BOOL status = NO;

if (fileURL != nil) // Check for non-nil file URL
{
{
if (_fileURL)
[_fileURL release];
[_fileURL release];

if (_password)
[_password release];
[_password release];

_fileURL = [fileURL copy]; // Keep a copy
_password = [password copy]; // Ditto

CGPDFDocumentRelease(_PDFDocRef);

_PDFDocRef = CGPDFDocumentCreateX((CFURLRef)fileURL, password);

if (_PDFDocRef != NULL) // Check for non-NULL CGPDFDocRef
{
pages = CGPDFDocumentGetNumberOfPages(_PDFDocRef); // Set the total page count
Expand All @@ -72,7 +72,7 @@ - (BOOL)changeFileURL:(NSURL *)fileURL password:(NSString *)password
{
NSAssert(NO, @"fileURL == nil");
}

return status;
}

Expand All @@ -81,7 +81,7 @@ - (CGPDFPageRef)getPage:(NSInteger)pageNumber {
if (pageNumber > pages) pageNumber = pages; // Check the upper page bounds

CGPDFPageRef newPDFPageRef = CGPDFDocumentGetPage(_PDFDocRef, pageNumber);

if (newPDFPageRef == NULL) // Check for non-NULL CGPDFPageRef
{
NSAssert(NO, @"CGPDFPageRef == NULL");
Expand Down
10 changes: 5 additions & 5 deletions Classes/PDFViewTiled.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ + (Class)layerClass

- (id)initWithPage:(NSInteger)onPage frame:(CGRect)frame {
if (self = [self initWithFrame:frame])
{
{
page = onPage;
_PDFPageRef = [[PDFContainer sharedPDF] getPage:onPage];

Expand All @@ -56,11 +56,11 @@ - (id)initWithPage:(NSInteger)onPage frame:(CGRect)frame {
{
NSAssert(NO, @"CGPDFPageRef == NULL");
}

}

self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

return self;
}

Expand All @@ -72,7 +72,7 @@ - (void)willRotate
}

- (void)didRotate
{
{
[self.layer setNeedsDisplay];

self.layer.hidden = NO;
Expand Down
6 changes: 3 additions & 3 deletions Classes/ReaderViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ - (void)viewDidLoad
[[PDFContainer sharedPDF] changeFileURL:fileURL password:nil];

[self initPDFScroll];

theToolbar = [UIToolbar new]; // Create the application toolbar

theToolbar.autoresizingMask = UIViewAutoresizingFlexibleWidth;
Expand Down Expand Up @@ -252,7 +252,7 @@ - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrie
NSLog(@"ReaderViewController.m -willRotateToInterfaceOrientation: [%d]", toInterfaceOrientation);
NSLog(@" -> self.view.bounds = %@", NSStringFromCGRect(self.view.bounds));
#endif

[super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
}

Expand All @@ -274,7 +274,7 @@ - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceO
#endif

//if (fromInterfaceOrientation == self.interfaceOrientation) return; // You get this when presented modally

[super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
}

Expand Down
12 changes: 6 additions & 6 deletions PDFScrollView.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
File: PDFScrollView.h
Abstract: Centers image within the scroll view and configures image sizing and display.
Version: 1.1

Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
Inc. ("Apple") in consideration of your agreement to the following
terms, and your use, installation, modification or redistribution of
this Apple software constitutes acceptance of these terms. If you do
not agree with these terms, please do not use, install, modify or
redistribute this Apple software.

In consideration of your agreement to abide by the following terms, and
subject to these terms, Apple grants you a personal, non-exclusive
license, under Apple's copyrights in this original Apple software (the
Expand All @@ -25,13 +25,13 @@
implied, are granted by Apple herein, including but not limited to any
patent rights that may be infringed by your derivative works or by other
works in which the Apple Software may be incorporated.

The Apple Software is provided by Apple on an "AS IS" basis. APPLE
MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.

IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
Expand All @@ -40,9 +40,9 @@
AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.

Copyright (C) 2010 Apple Inc. All Rights Reserved.

*/

#import <UIKit/UIKit.h>
Expand Down
58 changes: 29 additions & 29 deletions PDFScrollView.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
File: PDFScrollView.m
Abstract: Centers image within the scroll view and configures image sizing and display.
Version: 1.1

Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
Inc. ("Apple") in consideration of your agreement to the following
terms, and your use, installation, modification or redistribution of
this Apple software constitutes acceptance of these terms. If you do
not agree with these terms, please do not use, install, modify or
redistribute this Apple software.

In consideration of your agreement to abide by the following terms, and
subject to these terms, Apple grants you a personal, non-exclusive
license, under Apple's copyrights in this original Apple software (the
Expand All @@ -25,13 +25,13 @@
implied, are granted by Apple herein, including but not limited to any
patent rights that may be infringed by your derivative works or by other
works in which the Apple Software may be incorporated.

The Apple Software is provided by Apple on an "AS IS" basis. APPLE
MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.

IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
Expand All @@ -40,9 +40,9 @@ OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.

Copyright (C) 2010 Apple Inc. All Rights Reserved.

*/

#import "PDFScrollView.h"
Expand All @@ -67,7 +67,7 @@ - (id)initWithFrame:(CGRect)frame
self.showsHorizontalScrollIndicator = NO;
self.bouncesZoom = YES;
self.decelerationRate = UIScrollViewDecelerationRateFast;
self.delegate = self;
self.delegate = self;
[self setMaxMinZoomScalesForCurrentBounds];
self.contentSize = CGSizeMake(pdfView.bounds.size.width * 5, pdfView.bounds.size.height * 5);
self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
Expand All @@ -89,29 +89,29 @@ - (void)dealloc
#pragma mark -
#pragma mark Override layoutSubviews to center content

- (void)layoutSubviews
- (void)layoutSubviews
{
[super layoutSubviews];

// center the image as it becomes smaller than the size of the screen

CGSize boundsSize = self.bounds.size;
CGRect frameToCenter = pdfView.frame;

// center horizontally
if (frameToCenter.size.width < boundsSize.width)
frameToCenter.origin.x = (boundsSize.width - frameToCenter.size.width) / 2;
else
frameToCenter.origin.x = 0;

// center vertically
if (frameToCenter.size.height < boundsSize.height)
frameToCenter.origin.y = (boundsSize.height - frameToCenter.size.height) / 2;
else
frameToCenter.origin.y = 0;

pdfView.frame = frameToCenter;

// if ([pdfView isKindOfClass:[PDFViewTiled class]]) {
// // to handle the interaction between CATiledLayer and high resolution screens, we need to manually set the
// // tiling view's contentScaleFactor to 1.0. (If we omitted this, it would be 2.0 on high resolution screens,
Expand Down Expand Up @@ -147,48 +147,48 @@ - (void)setMaxMinZoomScalesForCurrentBounds
{
CGSize boundsSize = self.bounds.size;
CGSize imageSize = CGSizeMake(pdfView.bounds.size.width * 5, pdfView.bounds.size.height * 5);

// calculate min/max zoomscale
CGFloat xScale = boundsSize.width / imageSize.width; // the scale needed to perfectly fit the image width-wise
CGFloat yScale = boundsSize.height / imageSize.height; // the scale needed to perfectly fit the image height-wise
CGFloat minScale = MIN(xScale, yScale); // use minimum of these to allow the image to become fully visible

// on high resolution screens we have double the pixel density, so we will be seeing every pixel if we limit the
// maximum zoom scale to 0.5.
CGFloat maxScale = 5.0 / [[UIScreen mainScreen] scale];
// don't let minScale exceed maxScale. (If the image is smaller than the screen, we don't want to force it to be zoomed.)

// don't let minScale exceed maxScale. (If the image is smaller than the screen, we don't want to force it to be zoomed.)
if (minScale > maxScale) {
minScale = maxScale;
}

// if (minScale < -5)
// minScale = -5;

self.maximumZoomScale = 5.0; //maxScale;
self.minimumZoomScale = 1.0; //minScale;
}

#pragma mark -
#pragma mark Methods called during rotation to preserve the zoomScale and the visible portion of the image

// returns the center point, in image coordinate space, to try to restore after rotation.
// returns the center point, in image coordinate space, to try to restore after rotation.
- (CGPoint)pointToCenterAfterRotation
{
CGPoint boundsCenter = CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds));
return [self convertPoint:boundsCenter toView:pdfView];
}

// returns the zoom scale to attempt to restore after rotation.
// returns the zoom scale to attempt to restore after rotation.
- (CGFloat)scaleToRestoreAfterRotation
{
CGFloat contentScale = self.zoomScale;

// If we're at the minimum zoom scale, preserve that by returning 0, which will be converted to the minimum
// allowable scale when the scale is restored.
if (contentScale <= self.minimumZoomScale + FLT_EPSILON)
contentScale = 0;

return contentScale;
}

Expand All @@ -206,17 +206,17 @@ - (CGPoint)minimumContentOffset

// Adjusts content offset and scale to try to preserve the old zoomscale and center.
- (void)restoreCenterPoint:(CGPoint)oldCenter scale:(CGFloat)oldScale
{
{
// Step 1: restore zoom scale, first making sure it is within the allowable range.
self.zoomScale = MIN(self.maximumZoomScale, MAX(self.minimumZoomScale, oldScale));


// Step 2: restore center point, first making sure it is within the allowable range.

// 2a: convert our desired center point back to our own coordinate space
CGPoint boundsCenter = [self convertPoint:oldCenter fromView:pdfView];
// 2b: calculate the content offset that would yield that center point
CGPoint offset = CGPointMake(boundsCenter.x - self.bounds.size.width / 2.0,
CGPoint offset = CGPointMake(boundsCenter.x - self.bounds.size.width / 2.0,
boundsCenter.y - self.bounds.size.height / 2.0);
// 2c: restore offset, adjusted to be within the allowable range
CGPoint maxOffset = [self maximumContentOffset];
Expand Down
2 changes: 1 addition & 1 deletion PDFViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

NSMutableSet *recycledPages;
NSMutableSet *visiblePages;

// these values are stored off before we start rotation so we adjust our content offset appropriately during rotation
int firstVisiblePageIndexBeforeRotation;
CGFloat percentScrolledIntoFirstVisiblePage;
Expand Down
Loading