forked from adlr/formulatepro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FPImage.m
89 lines (74 loc) · 2.08 KB
/
FPImage.m
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
//
// FPImage.m
// FormulatePro
//
// Created by Andrew de los Reyes on 12/27/06.
// Copyright 2006 Andrew de los Reyes. All rights reserved.
//
#import "FPImage.h"
#import "NSMutableDictionaryAdditions.h"
@implementation FPImage
- (id)initWithGraphic:(FPGraphic *)graphic
{
self = [super initWithGraphic:graphic];
assert([graphic class] == [FPImage class]);
FPImage *gr = (FPImage *)graphic;
if (self) {
self->_image = [gr->_image copy];
}
return self;
}
+ (NSString *)archivalClassName;
{
return @"Image";
}
static NSString *imageArchiveKey = @"image";
- (id)initWithArchivalDictionary:(NSDictionary *)dict
inDocumentView:(FPDocumentView *)docView
{
self = [super initWithArchivalDictionary:dict
inDocumentView:docView];
if (self) {
_image = [[NSUnarchiver unarchiveObjectWithData:
[dict objectForKey:imageArchiveKey]] retain];
}
return self;
}
- (NSDictionary *)archivalDictionary
{
NSMutableDictionary *ret =
[NSMutableDictionary
dictionaryWithDictionary:[super archivalDictionary]];
[ret setObject:[NSArchiver archivedDataWithRootObject:_image]
forNonexistentKey:imageArchiveKey];
return ret;
}
- (id)initInDocumentView:(FPDocumentView *)docView
withImage:(NSImage *)image;
{
self = [super initInDocumentView:docView];
if (self) {
_image = [image retain];
[_image setCacheMode:NSImageCacheNever];
NSPoint center;
[_docView getViewingMidpointToPage:&_page pagePoint:¢er];
_bounds.size = [_image size];
_bounds.origin = NSMakePoint(center.x - NSWidth(_bounds)/2,
center.y - NSHeight(_bounds)/2);
_naturalBounds = _bounds;
}
return self;
}
- (void)dealloc
{
[_image release];
[super dealloc];
}
- (void)draw:(BOOL)selected
{
[_image drawInRect:[self bounds]
fromRect:NSZeroRect
operation:NSCompositeSourceOver
fraction:1.0]; // 1.0 means fully opaque
}
@end