diff options
author | Tor Lillqvist <tml@collabora.com> | 2013-12-19 21:49:25 +0200 |
---|---|---|
committer | Tor Lillqvist <tml@collabora.com> | 2013-12-19 21:58:59 +0200 |
commit | 7f02e47111eba4ec45ca02f78729b35d56839c1b (patch) | |
tree | bf416ecd698287aafe591c86fb5cae7d72f15294 /ios | |
parent | 962d4b35bd53e3d37849acd325dc57861c930972 (diff) |
Further minor tweaks to TiledLibreOffice
Change-Id: If1c1bbaadf8866605bf1026c4a71da0a397391a4
Diffstat (limited to 'ios')
3 files changed, 37 insertions, 19 deletions
diff --git a/ios/experimental/TiledLibreOffice/TiledLibreOffice/TiledView.h b/ios/experimental/TiledLibreOffice/TiledLibreOffice/TiledView.h index fb42358941ad..2b228e6e1c30 100644 --- a/ios/experimental/TiledLibreOffice/TiledLibreOffice/TiledView.h +++ b/ios/experimental/TiledLibreOffice/TiledLibreOffice/TiledView.h @@ -10,7 +10,7 @@ @interface TiledView : UIView -- (id)initWithFrame:(CGRect)frame andScale:(CGFloat)scale; +- (id)initWithFrame:(CGRect)frame scale:(CGFloat)scale maxZoom:(int)maxZoom; @end diff --git a/ios/experimental/TiledLibreOffice/TiledLibreOffice/TiledView.m b/ios/experimental/TiledLibreOffice/TiledLibreOffice/TiledView.m index 0fe9c9450b1c..57a13fb2c723 100644 --- a/ios/experimental/TiledLibreOffice/TiledLibreOffice/TiledView.m +++ b/ios/experimental/TiledLibreOffice/TiledLibreOffice/TiledView.m @@ -19,15 +19,15 @@ @implementation TiledView -- (id)initWithFrame:(CGRect)frame andScale:(CGFloat)scale +- (id)initWithFrame:(CGRect)frame scale:(CGFloat)scale maxZoom:(int)maxZoom { self = [super initWithFrame:frame]; if (self) { self.scale = scale; CATiledLayer *catl = (CATiledLayer*) [self layer]; catl.tileSize = CGSizeMake(512, 512); - catl.levelsOfDetail = 4; - catl.levelsOfDetailBias = 4; + catl.levelsOfDetail = log2(maxZoom) + 1; + catl.levelsOfDetailBias = catl.levelsOfDetail - 1; } return self; } @@ -39,22 +39,46 @@ - (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx { - CGContextSaveGState(ctx); + // Even if I set the CATL's tileSize to 512x512 above, this is + // called initially with a clip bbox of 128x128. Odd, I would have + // expected it to be called with a bbox of 256x256. CGRect bb = CGContextGetClipBoundingBox(ctx); + double zoomScale = [(View *) [self superview] zoomScale]; + CATiledLayer *catl = (CATiledLayer*) [self layer]; - // NSLog(@"%.0fx%.0f@(%.0f,%.0f) %f", bb.size.width, bb.size.height, bb.origin.x, bb.origin.y, 1/[(View *) [self superview] zoomScale]); + CGContextSaveGState(ctx); CGContextTranslateCTM(ctx, bb.origin.x, bb.origin.y); + // CGContextScaleCTM(ctx, 1/zoomScale, 1/zoomScale); + + // CGSize tileSize = [catl tileSize]; + CGSize tileSize = bb.size; + + // NSLog(@"bb:%.0fx%.0f@(%.0f,%.0f) zoomScale:%.0f tile:%.0fx%.0f at:(%.0f,%.0f) size:%.0fx%.0f", bb.size.width, bb.size.height, bb.origin.x, bb.origin.y, zoomScale, tileSize.width, tileSize.height, bb.origin.x/self.scale, bb.origin.y/self.scale, bb.size.width/self.scale, bb.size.height/self.scale); - NSLog(@"tile:%.0fx%.0f at:(%.0f,%.0f) size:%.0fx%.0f", bb.size.width, bb.size.height, bb.origin.x/self.scale, bb.origin.y/self.scale, bb.size.width/self.scale, bb.size.height/self.scale); + // I don't really claim to fully understand all this. It does seem + // a bit weird to be passing in a "context width x height" (in the + // terminology of touch_lo_draw_tile) of 64x64, for instance, even + // if that tile is actually going to be rendered to 128x128 actual + // pixels. But this seems to work. Other combinations, applying + // scaling to the CTM, etc, don't. But maybe I haven't tried hard + // enough. touch_lo_draw_tile(ctx, - bb.size.width, bb.size.height, + tileSize.width, tileSize.height, CGPointMake(bb.origin.x/self.scale, bb.origin.y/self.scale), CGSizeMake(bb.size.width/self.scale, bb.size.height/self.scale)); CGContextRestoreGState(ctx); + + // I am a bit confused about what tiles exactly I am drawing, so + // make it perfectly obvious by drawing borders around the tiles + CGContextSaveGState(ctx); + CGContextSetStrokeColorWithColor(ctx, [[UIColor colorWithRed:1 green:0 blue:0 alpha:0.5] CGColor]); + CGContextSetLineWidth(ctx, 1); + CGContextStrokeRect(ctx, bb); + CGContextRestoreGState(ctx); } @end diff --git a/ios/experimental/TiledLibreOffice/TiledLibreOffice/View.m b/ios/experimental/TiledLibreOffice/TiledLibreOffice/View.m index be27c0903e68..9291b4561369 100644 --- a/ios/experimental/TiledLibreOffice/TiledLibreOffice/View.m +++ b/ios/experimental/TiledLibreOffice/TiledLibreOffice/View.m @@ -23,7 +23,9 @@ { self = [super initWithFrame:frame]; if (self) { - [self setMaximumZoomScale:4]; + const int MAXZOOM = 4; + + [self setMaximumZoomScale:MAXZOOM]; [self setDelegate:self]; MLODpxSize docSize = touch_lo_get_content_size(); @@ -31,9 +33,9 @@ double widthScale = frame.size.width / docSize.width; double docAspectRatio = docSize.height / docSize.width; - NSLog(@"View frame=%.0fx%.0f docSize=%.0fx%.0f scale=%.3f aspectRatio=%.3f", frame.size.width, frame.size.height, docSize.width, docSize.height, widthScale, docAspectRatio); + // NSLog(@"View frame=%.0fx%.0f docSize=%.0fx%.0f scale=%.3f aspectRatio=%.3f", frame.size.width, frame.size.height, docSize.width, docSize.height, widthScale, docAspectRatio); - self.subView = [[TiledView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.width*docAspectRatio) andScale:widthScale]; + self.subView = [[TiledView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.width*docAspectRatio) scale:widthScale maxZoom:MAXZOOM]; [self addSubview:self.subView]; } return self; @@ -44,14 +46,6 @@ return self.subView; } -- (void)scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:(UIView *)view -{ -} - -- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(CGFloat)scale -{ -} - @end // vim:set shiftwidth=4 softtabstop=4 expandtab: |