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
3 changes: 2 additions & 1 deletion Leaves/LeavesCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@

@property (nonatomic, assign) CGSize pageSize;
@property (assign) id<LeavesViewDataSource> dataSource;
@property (readonly) CGFloat scaleFactor;

- (id)initWithPageSize:(CGSize)aPageSize;
- (id)initWithPageSize:(CGSize)aPageSize andScaleFactor:(CGFloat)scaleFactor;
- (CGImageRef)cachedImageForPageIndex:(NSUInteger)pageIndex;
- (void)precacheImageForPageIndex:(NSUInteger)pageIndex;
- (void)minimizeToPageIndex:(NSUInteger)pageIndex;
Expand Down
12 changes: 8 additions & 4 deletions Leaves/LeavesCache.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ @interface LeavesCache ()

@implementation LeavesCache

- (id)initWithPageSize:(CGSize)aPageSize
- (id)initWithPageSize:(CGSize)aPageSize andScaleFactor:(CGFloat)fScaleFactor
{
if (self = [super init]) {
_pageSize = aPageSize;
_pageCache = [[NSMutableDictionary alloc] init];
_scaleFactor = fScaleFactor;
}
return self;
}
Expand All @@ -38,12 +39,15 @@ - (CGImageRef)imageForPageIndex:(NSUInteger)pageIndex {

CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate(NULL,
self.pageSize.width,
self.pageSize.height,
self.pageSize.width * self.scaleFactor,
self.pageSize.height * self.scaleFactor,
8, /* bits per component*/
self.pageSize.width * 4, /* bytes per row */
self.pageSize.width * 4 * self.scaleFactor, /* bytes per row */
colorSpace,
kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);

CGContextScaleCTM(context, self.scaleFactor, self.scaleFactor);

CGColorSpaceRelease(colorSpace);
CGContextClipToRect(context, CGRectMake(0, 0, self.pageSize.width, self.pageSize.height));

Expand Down
15 changes: 13 additions & 2 deletions Leaves/LeavesView.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ @interface LeavesView ()
@property (nonatomic, assign) CGRect nextPageRect, prevPageRect;
@property (nonatomic, assign) BOOL touchIsActive, interactionLocked;
@property (readonly) LeavesCache *pageCache;
@property (readonly) CGFloat scaleFactor;

@end

Expand Down Expand Up @@ -78,6 +79,16 @@ - (void)initCommon {
nil];
_bottomPageShadow.startPoint = CGPointMake(0,0.5);
_bottomPageShadow.endPoint = CGPointMake(1,0.5);

_scaleFactor = 1.0;

// Check if iOS > 4
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]){
_topPage.contentsScale = \
_topPageReverseImage.contentsScale = \
_bottomPage.contentsScale = \
_scaleFactor = [[UIScreen mainScreen] scale];
}

[_topPage addSublayer:_topPageShadow];
[_topPage addSublayer:_topPageOverlay];
Expand All @@ -89,9 +100,9 @@ - (void)initCommon {
[self.layer addSublayer:_topPage];
[self.layer addSublayer:_topPageReverse];

_leafEdge = 1.0;
_leafEdge = 1.0;
_backgroundRendering = NO;
_pageCache = [[LeavesCache alloc] initWithPageSize:self.bounds.size];
_pageCache = [[LeavesCache alloc] initWithPageSize:self.bounds.size andScaleFactor: self.scaleFactor];
}

- (id)initWithFrame:(CGRect)frame {
Expand Down