5 // Created by Doug Dickinson on Sat May 24 2003.
6 // Copyright (c) 2003 Doug Dickinson (dasher@DressTheMonkey.plus.com). All rights reserved.
9 #import <AppKit/AppKit.h>
10 #import "ZippyString.h"
13 @implementation ZippyString
15 + (id)zippyStringWithString:(NSString *)aString attributes:(NSDictionary *)someAttributes {
16 return [[[self alloc] initWithString:aString attributes:someAttributes] autorelease];
19 - (id)initWithString:(NSString *)aString attributes:(NSDictionary *)someAttributes {
20 if (self = [super init]) {
22 NSSize s = [aString sizeWithAttributes:someAttributes];
23 [self setString:aString];
24 [self setAttributes:someAttributes];
25 [self setSize:[aString sizeWithAttributes:someAttributes]];
26 if ([aString length] == 1 && s.width != 0 && s.height != 0) {
27 m = [[NSImage alloc] initWithSize:[self size]];
30 [self drawAtPoint:NSMakePoint(0, 0)];
32 [self setImage:[m autorelease]];
39 - (void)drawAtPoint:(NSPoint)aPoint {
40 if ([self image] != nil) {
41 NSPoint at = NSMakePoint(aPoint.x, aPoint.y + [self size].height);
42 [[self image] compositeToPoint:at operation:NSCompositeSourceAtop];
46 [[self string] drawAtPoint:aPoint withAttributes:[self attributes]];
53 - (void)setSize:(NSSize)newSize {
61 - (void)setImage:(NSImage *)newImage {
62 if (_image != newImage) {
63 NSImage *oldValue = _image;
64 _image = [newImage retain];
69 - (NSString *)string {
73 - (void)setString:(NSString *)newString {
74 if (_string != newString) {
75 NSString *oldValue = _string;
76 _string = [newString retain];
81 - (NSDictionary *)attributes {
85 - (void)setAttributes:(NSDictionary *)newAttributes {
86 if (_attributes != newAttributes) {
87 NSDictionary *oldValue = _attributes;
88 _attributes = [newAttributes retain];
97 [_attributes release];