Permalink
Browse files

First commit

  • Loading branch information...
0 parents commit 4ef75490031fb1d38a9ce9fed992711d44017900 Adrian Kosmaczewski committed Jul 8, 2010
@@ -0,0 +1,5 @@
+build
+*.mode2v3
+*.mode1v3
+*.pbxuser
+
@@ -0,0 +1,24 @@
+//
+// CoreTextWrapperAppDelegate.h
+// CoreTextWrapper
+//
+// Created by Adrian on 7/8/10.
+// Copyright akosma software 2010. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+
+@class PageController;
+
+@interface CoreTextWrapperAppDelegate : NSObject <UIApplicationDelegate>
+{
+@private
+ UIWindow *_window;
+ PageController *_pageController;
+}
+
+@property (nonatomic, retain) IBOutlet UIWindow *window;
+@property (nonatomic, retain) IBOutlet PageController *pageController;
+
+@end
+
@@ -0,0 +1,39 @@
+//
+// CoreTextWrapperAppDelegate.m
+// CoreTextWrapper
+//
+// Created by Adrian on 7/8/10.
+// Copyright akosma software 2010. All rights reserved.
+//
+
+#import "CoreTextWrapperAppDelegate.h"
+#import "PageController.h"
+
+@implementation CoreTextWrapperAppDelegate
+
+@synthesize window = _window;
+@synthesize pageController = _pageController;
+
+
+#pragma mark -
+#pragma mark Application lifecycle
+
+- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
+{
+ [self.window addSubview:self.pageController.view];
+ [self.window makeKeyAndVisible];
+
+ return YES;
+}
+
+#pragma mark -
+#pragma mark Memory management
+
+- (void)dealloc
+{
+ [self.window release];
+ [super dealloc];
+}
+
+
+@end
@@ -0,0 +1,26 @@
+//
+// PageController.h
+// CoreTextWrapper
+//
+// Created by Adrian on 7/8/10.
+// Copyright 2010 akosma software. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+
+@class AKOMultiPageTextView;
+@class AKOCustomFontLabel;
+
+@interface PageController : UIViewController
+{
+@private
+ AKOMultiPageTextView *_multiPageView;
+ AKOCustomFontLabel *_label;
+ CGFloat _previousScale;
+ CGFloat _fontSize;
+}
+
+@property (nonatomic, retain) IBOutlet AKOCustomFontLabel *label;
+@property (nonatomic, retain) IBOutlet AKOMultiPageTextView *multiPageView;
+
+@end
@@ -0,0 +1,113 @@
+//
+// PageController.m
+// CoreTextWrapper
+//
+// Created by Adrian on 7/8/10.
+// Copyright 2010 akosma software. All rights reserved.
+//
+
+#import "PageController.h"
+#import "AKOMultiPageTextView.h"
+#import "AKOCustomFontLabel.h"
+#import "NSString+BundleExtensions.h"
+#import "UIFont+CoreTextExtensions.h"
+
+@interface PageController ()
+
+@property (nonatomic) CGFloat previousScale;
+@property (nonatomic) CGFloat fontSize;
+
+@end
+
+
+@implementation PageController
+
+@synthesize multiPageView = _multiPageView;
+@synthesize label = _label;
+@synthesize previousScale = _previousScale;
+@synthesize fontSize = _fontSize;
+
+- (void)dealloc
+{
+ self.label = nil;
+ self.multiPageView = nil;
+ [super dealloc];
+}
+
+#pragma mark -
+#pragma mark UIViewController methods
+
+- (void)viewDidLoad
+{
+ [super viewDidLoad];
+ self.label.text = @"News of the Day";
+ self.label.font = [UIFont bundledFontNamed:@"Polsku" size:34.0];
+
+ self.fontSize = 24.0;
+ self.multiPageView.text = [NSString stringFromFileNamed:@"lorem_ipsum.txt"];
+ self.multiPageView.font = [UIFont fontWithName:@"Georgia" size:self.fontSize];
+ self.multiPageView.columnCount = UIInterfaceOrientationIsPortrait(self.interfaceOrientation) ? 3 : 4;
+
+ UIPinchGestureRecognizer *pinchRecognizer = [[[UIPinchGestureRecognizer alloc] initWithTarget:self
+ action:@selector(changeTextSize:)] autorelease];
+ [self.multiPageView addGestureRecognizer:pinchRecognizer];
+}
+
+- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
+{
+ return YES;
+}
+
+- (void)didReceiveMemoryWarning
+{
+ [super didReceiveMemoryWarning];
+}
+
+- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
+ duration:(NSTimeInterval)duration
+{
+ if (UIInterfaceOrientationIsPortrait(interfaceOrientation))
+ {
+ self.multiPageView.columnCount = 3;
+ }
+ else
+ {
+ self.multiPageView.columnCount = 4;
+ }
+ [self.multiPageView setNeedsDisplay];
+ [self.label setNeedsDisplay];
+}
+
+#pragma mark -
+#pragma mark Gesture recognizer methods
+
+- (void)changeTextSize:(UIPinchGestureRecognizer *)recognizer
+{
+ if (recognizer.state == UIGestureRecognizerStateBegan)
+ {
+ self.previousScale = recognizer.scale;
+ }
+ else if (recognizer.state == UIGestureRecognizerStateChanged)
+ {
+ if (recognizer.scale > self.previousScale)
+ {
+ if (self.fontSize < 48.0)
+ {
+ self.fontSize += 0.25;
+ }
+ }
+ else
+ {
+ if (self.fontSize > 12.0)
+ {
+ self.fontSize -= 0.25;
+ }
+ }
+
+ self.multiPageView.font = [UIFont fontWithName:@"Georgia" size:self.fontSize];
+ self.previousScale = recognizer.scale;
+ }
+}
+
+@end
+
@@ -0,0 +1,15 @@
+//
+// NSString+BundleExtensions.h
+// CoreTextWrapper
+//
+// Created by Adrian on 4/28/10.
+// Copyright 2010 akosma software. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+@interface NSString (BundleExtensions)
+
++ (NSString *)stringFromFileNamed:(NSString *)bundleFileName;
+
+@end
@@ -0,0 +1,20 @@
+//
+// NSString+BundleExtensions.m
+// CoreTextWrapper
+//
+// Created by Adrian on 4/28/10.
+// Copyright 2010 akosma software. All rights reserved.
+//
+
+#import "NSString+BundleExtensions.h"
+
+@implementation NSString (BundleExtensions)
+
++ (NSString *)stringFromFileNamed:(NSString *)bundleFileName
+{
+ NSString *path = [[NSBundle mainBundle] pathForResource:bundleFileName ofType:nil];
+ NSString *text = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
+ return text;
+}
+
+@end
@@ -0,0 +1,18 @@
+//
+// UIFont+CoreTextExtensions.h
+// CoreTextWrapper
+//
+// Created by Adrian on 4/24/10.
+// Copyright 2010 akosma software. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+#import <CoreText/CoreText.h>
+
+@interface UIFont (CoreTextExtensions)
+
+@property (nonatomic, readonly) CTFontRef CTFont;
+
++ (CTFontRef)bundledFontNamed:(NSString *)name size:(CGFloat)size;
+
+@end
@@ -0,0 +1,33 @@
+//
+// UIFont+CoreTextExtensions.m
+// CoreTextWrapper
+//
+// Created by Adrian on 4/24/10.
+// Copyright 2010 akosma software. All rights reserved.
+//
+
+#import "UIFont+CoreTextExtensions.h"
+
+@implementation UIFont (CoreTextExtensions)
+
+- (CTFontRef)CTFont
+{
+ CTFontRef font = CTFontCreateWithName((CFStringRef)self.fontName, self.pointSize, NULL);
+ return font;
+}
+
++ (CTFontRef)bundledFontNamed:(NSString *)name size:(CGFloat)size
+{
+ // Adapted from http://stackoverflow.com/questions/2703085/how-can-you-load-a-font-ttf-from-a-file-using-core-text
+ NSString *path = [[NSBundle mainBundle] pathForResource:name ofType:@"ttf"];
+ CFURLRef url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, (CFStringRef)path, kCFURLPOSIXPathStyle, false);
+ CGDataProviderRef dataProvider = CGDataProviderCreateWithURL(url);
+ CGFontRef theCGFont = CGFontCreateWithDataProvider(dataProvider);
+ CTFontRef result = CTFontCreateWithGraphicsFont(theCGFont, size, NULL, NULL);
+ CFRelease(theCGFont);
+ CFRelease(dataProvider);
+ CFRelease(url);
+ return result;
+}
+
+@end
@@ -0,0 +1,26 @@
+//
+// AKOCustomFontView.h
+// CoreTextWrapper
+//
+// Created by Adrian on 6/19/10.
+// Copyright 2010 akosma software. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+#import <CoreText/CoreText.h>
+
+@interface AKOCustomFontLabel : UIView
+{
+@private
+ CTFontRef _font;
+ NSString *_text;
+ UIColor *_textColor;
+}
+
+@property (nonatomic, copy) NSString *text;
+@property (nonatomic, retain) UIColor *textColor;
+
+- (CTFontRef)font;
+- (void)setFont:(CTFontRef)customFont;
+
+@end
Oops, something went wrong.

0 comments on commit 4ef7549

Please sign in to comment.