-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPrintView.m
112 lines (92 loc) · 2.94 KB
/
PrintView.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
//
// PrintView.m
// Kineo
//
// Created by Ben Yellin on 3/25/11.
// Copyright 2011 Been Yelling. All rights reserved.
//
#import "PrintView.h"
#import "FlipSeries.h"
const NSRect kPageFrame = {0, 0, 2550, 3300};
@implementation PrintView
@synthesize flipSeries;
- (id)initWithFlipSeries:(FlipSeries *)series {
self = [super initWithFrame:kPageFrame];
if (self) {
flipSeries = [series retain];
}
return self;
}
- (void)dealloc {
self.flipSeries = nil;
[super dealloc];
}
- (void)drawRect:(NSRect)dirtyRect {
[[NSColor whiteColor] set];
NSRectFill(dirtyRect);
if (flipSeries) {
//NSDictionary *labelAttrs = [NSDictionary dictionaryWithObjectsAndKeys:
NSSize imageFrameSize = NSMakeSize(354, 267);
NSSize stapleSize = NSMakeSize(68, 267);
float margin = 5.0;
int numCols = 6;
int numRows = 8;
int imgCount = 0;
int rowIndex = 0;
BOOL showTitleBox = YES;
for (NSImage *img in [flipSeries images]) {
float xPos = ((imgCount * stapleSize.width) + stapleSize.width) +
(imgCount * (imageFrameSize.width + margin));
float yPos = (dirtyRect.size.height - (rowIndex * (imageFrameSize.height+margin))) - imageFrameSize.height;
// Draw Staple Box
NSRect stapleRect = NSMakeRect(xPos-stapleSize.width, yPos,
stapleSize.width, stapleSize.height);
[[NSColor colorWithCalibratedWhite:0.230 alpha:1.000] set];
NSRectFill(stapleRect);
NSRect imgRect = NSMakeRect(xPos, yPos,
imageFrameSize.width, imageFrameSize.height);
// Title Box
if (showTitleBox) {
[[NSColor colorWithCalibratedWhite:0.704 alpha:1.000] set];
NSFrameRect(imgRect);
showTitleBox = NO;
} else {
[img drawInRect:imgRect
fromRect:NSZeroRect
operation:NSCompositeSourceOver
fraction:1.0];
// Frame Count Label
/*[[NSFont fontWithName:@"Helvetica" size:20.0] set];
[[NSString stringWithFormat:@"%i", imgCount] drawAtPoint:stapleRect.origin];*/
}
// Draw Cut Line
NSBezierPath *cutLine = [NSBezierPath bezierPath];
[cutLine setLineWidth:2.0];
CGFloat dashPattern[2] = {6.0, 3.0};
[cutLine setLineDash:dashPattern count:2 phase:0.0];
[cutLine moveToPoint:NSMakePoint(imageFrameSize.width+xPos+2, yPos)];
[cutLine lineToPoint:NSMakePoint(imageFrameSize.width+xPos+2, yPos+imageFrameSize.height)];
[cutLine stroke];
imgCount++;
if (imgCount > numCols) {
rowIndex++;
imgCount = 0;
// Draw Row Line
NSBezierPath *rowLine = [NSBezierPath bezierPath];
[rowLine setLineWidth:2.0];
[rowLine setLineDash:dashPattern count:2 phase:0.0];
[rowLine moveToPoint:NSMakePoint(0.0, yPos-2)];
[rowLine lineToPoint:NSMakePoint(dirtyRect.size.width, yPos-2)];
[rowLine stroke];
}
}
}
}
- (void)setFlipSeries:(FlipSeries *)series {
if (![flipSeries isEqualTo:series]) {
[flipSeries release];
flipSeries = [series retain];
}
[self setNeedsDisplay:YES];
}
@end