Further minor tweaks to TiledLibreOffice

Change-Id: If1c1bbaadf8866605bf1026c4a71da0a397391a4
This commit is contained in:
Tor Lillqvist 2013-12-19 21:49:25 +02:00
parent 962d4b35bd
commit 7f02e47111
3 changed files with 37 additions and 19 deletions

View File

@ -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

View File

@ -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);
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);
// 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);
// 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

View File

@ -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: