Skip to content
Browse files

Changed the pdf placment calculations a little, fits better when usin…

…g other pdfs
  • Loading branch information...
1 parent b170170 commit a679ce1a72ccc274a02f55c0f48f8f0f9048a631 @epatel committed Feb 4, 2011
Showing with 7 additions and 5 deletions.
  1. +7 −5 FlipReader-iPad/Classes/MyPDFView.m
View
12 FlipReader-iPad/Classes/MyPDFView.m
@@ -36,7 +36,7 @@ - (void)gotoPage:(int)nextPage
- (void)drawRect:(CGRect)rect {
CGPDFPageRef page1;
CGPDFPageRef page2;
-
+
if (pageNumber) {
page1 = CGPDFDocumentGetPage(book, pageNumber-2);
page2 = CGPDFDocumentGetPage(book, pageNumber-1);
@@ -48,22 +48,24 @@ - (void)drawRect:(CGRect)rect {
CGRect frameRect = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
CGFloat scaleFactorWidth = 0.5*frameRect.size.width/pageRect.size.width;
+ CGFloat nudge = ((frameRect.size.height/scaleFactorWidth) - pageRect.size.height) / 2.0;
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetRGBFillColor(context, 1.0, 1.0, 1.0, 1.0);
CGContextFillRect(context, frameRect);
CGContextSaveGState(context);
- CGContextTranslateCTM(context, 0, rect.size.height);
+ CGContextTranslateCTM(context, frameRect.size.width/2.0, frameRect.size.height-nudge);
CGContextScaleCTM(context, 1.0, -1.0);
CGContextScaleCTM(context, scaleFactorWidth, scaleFactorWidth);
+ CGContextTranslateCTM(context, -0.5*frameRect.size.width/scaleFactorWidth, 0);
if (page1)
CGContextDrawPDFPage(context, page1);
- CGContextTranslateCTM(context, 0.5*rect.size.height*scaleFactorWidth, 0);
+ CGContextTranslateCTM(context, 0.5*frameRect.size.width/scaleFactorWidth, 0);
if (page2)
CGContextDrawPDFPage(context, page2);
- CGContextMoveToPoint(context, 0.5*scaleFactorWidth, 0);
- CGContextAddLineToPoint(context, 0.5*scaleFactorWidth, rect.size.width*scaleFactorWidth);
+ CGContextMoveToPoint(context, -0.5/scaleFactorWidth, -nudge/scaleFactorWidth);
+ CGContextAddLineToPoint(context, -0.5/scaleFactorWidth, frameRect.size.height/scaleFactorWidth);
CGContextStrokePath(context);
} else {
page1 = CGPDFDocumentGetPage(cover, 1);

0 comments on commit a679ce1

Please sign in to comment.
Something went wrong with that request. Please try again.