5 // Created by Doug Dickinson on Mon May 26 2003.
6 // Copyright (c) 2003 Doug Dickinson (dasher AT DressTheMonkey DOT plus DOT com). All rights reserved.
9 #import <Foundation/Foundation.h>
11 #import "ZippyCache.h"
12 #import "ZippyStringImage.h"
13 #import "ZippyStringGlyph.h"
15 #if defined(ZIPPY_STRING_GLYPH)
17 // ZippyStringGlyph is not yet ready for primetime
18 #define ZIPPY_STRING_CLASS ZippyStringGlyph
20 // not terribly sophisticated way of choosing which Zippy string type to use
21 #define ZIPPY_STRING_CLASS ZippyStringImage
24 @implementation ZippyCache
26 - (ZippyString *)zippyStringWithString:(NSString *)aString size:(int)aSize attributes:(NSDictionary *)someAttributes {
27 ZippyString *result = nil;
28 NSMutableDictionary *sizeCache;
30 sizeCache = [[self cache] objectForKey:[self sizeKeyForSize:aSize]];
31 if (sizeCache == nil) {
32 sizeCache = [NSMutableDictionary dictionary];
33 [[self cache] setObject:sizeCache forKey:[self sizeKeyForSize:aSize]];
36 result = [sizeCache objectForKey:aString];
38 result = [ZIPPY_STRING_CLASS zippyStringWithString:aString attributes:someAttributes];
39 if ([aString length] == 1) {
40 [sizeCache setObject:result forKey:aString];
47 - (NSNumber *)sizeKeyForSize:(int)aSize {
48 //#if defined(ZIPPY_STRING_GLYPH)
49 // return [NSNumber numberWithInt:42]; // just testing
51 return [NSNumber numberWithInt:aSize];
56 return [[[self alloc] init] autorelease];
60 if (self = [super init]) {
69 [self setCache:[NSMutableDictionary dictionary]];
72 - (NSMutableDictionary *)cache {
76 - (void)setCache:(NSMutableDictionary *)newCache {
77 if (_cache != newCache) {
78 NSMutableDictionary *oldValue = _cache;
79 _cache = [newCache retain];