tagging release
[dasher.git] / Src / MacOSX / ZippyString.m
blob4485c8293f356f63d1042839de0741b401b30bfd
1 //
2 //  ZippyString.m
3 //  RectAl
4 //
5 //  Created by Doug Dickinson on Sat May 24 2003.
6 //  Copyright (c) 2003 Doug Dickinson (dasher@DressTheMonkey.plus.com). All rights reserved.
7 //
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]) {
21     NSImage *m;
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]];
28       [m setFlipped:YES];
29       [m lockFocus];
30       [self drawAtPoint:NSMakePoint(0, 0)];
31       [m unlockFocus];
32       [self setImage:[m autorelease]];
33     }
34   }
36   return self;
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];
43     return;
44   }
45   
46   [[self string] drawAtPoint:aPoint withAttributes:[self attributes]];
49 - (NSSize)size {
50   return _size;
53 - (void)setSize:(NSSize)newSize {
54   _size = newSize;
57 - (NSImage *)image {
58   return _image;
61 - (void)setImage:(NSImage *)newImage {
62   if (_image != newImage) {
63     NSImage *oldValue = _image;
64     _image = [newImage retain];
65     [oldValue release];
66   }
69 - (NSString *)string {
70   return _string;
73 - (void)setString:(NSString *)newString {
74   if (_string != newString) {
75     NSString *oldValue = _string;
76     _string = [newString retain];
77     [oldValue release];
78   }
81 - (NSDictionary *)attributes {
82   return _attributes;
85 - (void)setAttributes:(NSDictionary *)newAttributes {
86   if (_attributes != newAttributes) {
87     NSDictionary *oldValue = _attributes;
88     _attributes = [newAttributes retain];
89     [oldValue release];
90   }
94 - (void)dealloc {
95   [_image release];
96   [_string release];
97   [_attributes release];
98   [super dealloc];
101 @end