-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPrinterView.m
More file actions
99 lines (87 loc) · 2.5 KB
/
Copy pathPrinterView.m
File metadata and controls
99 lines (87 loc) · 2.5 KB
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
//
// PrinterView.m
// Atari800MacX
//
// Created by Mark Grebe on Sun Mar 13 2005.
// Copyright (c) 2005 __MyCompanyName__. All rights reserved.
//
#import "PrintableString.h"
#import "PrinterView.h"
@implementation PrinterView
- (id)initWithFrame:(NSRect)frame:(PrintOutputController *)owner:(float)pageLen:(float)vert {
self = [super initWithFrame:frame];
if (self) {
controller = owner;
pageLength = pageLen;
vertPosition = vert;
}
return self;
}
- (void)updateVerticlePosition:(float)vert
{
vertPosition = vert;
}
- (void)drawRect:(NSRect)rect {
int i;
NSArray *array = [controller getPrintArray];
int count = [array count];
PrintableString *element;
NSBezierPath *path;
NSColor *purple = [NSColor purpleColor];
NSColor *black = [NSColor blackColor];
NSColor *grey = [NSColor grayColor];
float offset = [controller getPrintOffset];
// Draw each of the elements in the print array
[black set];
for (i=0;i<count;i++)
{
element = [array objectAtIndex:i];
[element print:rect:offset];
}
// If this is only the preview, then print the current line position
// and page break markers.
if ([controller isPreview])
{
float width = [self frame].size.width;
NSPoint point1 = NSMakePoint(0.0,vertPosition+offset-5.0);
NSPoint point2 = NSMakePoint(10.0,vertPosition+offset);
NSPoint point3 = NSMakePoint(0.0,vertPosition+offset+5.0);
NSPoint point4 = NSMakePoint(width,vertPosition+offset-5.0);
NSPoint point5 = NSMakePoint(width - 10.0,vertPosition+offset);
NSPoint point6 = NSMakePoint(width,vertPosition+5.0+offset);
float pageBreak;
float array[2] = {5.0,2.0};
// Print the current line position markers
path = [NSBezierPath bezierPath];
[path moveToPoint:point1];
[path lineToPoint:point2];
[path lineToPoint:point3];
[path lineToPoint:point1];
[purple set];
[path fill];
path = [NSBezierPath bezierPath];
[path moveToPoint:point4];
[path lineToPoint:point5];
[path lineToPoint:point6];
[path lineToPoint:point4];
[path fill];
// Print the page break markers.
[grey set];
pageBreak = pageLength;
do {
NSPoint start = NSMakePoint(0.0, pageBreak);
NSPoint end = NSMakePoint([self frame].size.width, pageBreak);
path = [NSBezierPath bezierPath];
[path setLineDash: array count: 2 phase: 0.0];
[path moveToPoint:start];
[path lineToPoint:end];
[path stroke];
pageBreak += pageLength;
} while (pageBreak <= ([self frame].origin.y + [self frame].size.height));
}
}
- (BOOL)isFlipped
{
return YES;
}
@end