Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

file 47 lines (37 sloc) 1.261 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
//
// CGUtils.m
// iCatalog
//
// Created by Oliver Drobnik on 7/18/10.
// Copyright 2010 Drobnik.com. All rights reserved.
//

#import "DTUtils.h"

CGSize sizeThatFitsKeepingAspectRatio(CGSize originalSize, CGSize sizeToFit)
{
CGFloat necessaryZoomWidth = sizeToFit.width / originalSize.width;
CGFloat necessaryZoomHeight = sizeToFit.height / originalSize.height;

CGFloat smallerZoom = MIN(necessaryZoomWidth, necessaryZoomHeight);

CGSize scaledSize = CGSizeMake(roundf(originalSize.width*smallerZoom), roundf(originalSize.height*smallerZoom));
return scaledSize;
}

BOOL DTCGSizeMakeWithDictionaryRepresentation(NSDictionary *dict, CGSize *size)
{
NSNumber *widthNumber = [dict objectForKey:@"Width"];
NSNumber *heightNumber = [dict objectForKey:@"Height"];

if (!widthNumber || !heightNumber)
{
return NO;
}

if (size)
{
size->width = [widthNumber floatValue];
size->height = [heightNumber floatValue];
}

return YES;
}

NSDictionary *DTCGSizeCreateDictionaryRepresentation(CGSize size)
{
NSNumber *widthNumber = [NSNumber numberWithFloat:size.width];
NSNumber *heightNumber = [NSNumber numberWithFloat:size.height];

return [NSDictionary dictionaryWithObjectsAndKeys:widthNumber, @"Width", heightNumber, @"Height", nil];
}
Something went wrong with that request. Please try again.