-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPrintableGraphics.m
More file actions
86 lines (73 loc) · 1.61 KB
/
Copy pathPrintableGraphics.m
File metadata and controls
86 lines (73 loc) · 1.61 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
//
// PrintableGraphics.m
// Atari800MacX
//
// Created by Mark Grebe on Sat Mar 26 2005.
// Copyright (c) 2005 __MyCompanyName__. All rights reserved.
//
#import "PrintableGraphics.h"
@implementation PrintableGraphics
- (id)initWithBytes:(const void *)bytes length:(unsigned)length width:(float)width height:(float) height bits:(unsigned)bits
{
graphLength = length;
graphBytes = (unsigned char *) NSZoneMalloc(NSDefaultMallocZone(), length);
bcopy(bytes, graphBytes, length);
pixelWidth = width;
pixelHeight = height;
columnBits = bits;
return(self);
}
- (void)dealloc
{
NSZoneFree(NSDefaultMallocZone(), graphBytes);
[super dealloc];
}
-(void) setLocation:(NSPoint)location
{
printLocation = location;
}
-(void)print:(NSRect)rect:(float)offset
{
NSRect r;
unsigned length = graphLength;
unsigned i,j;
unsigned char *bytes = (unsigned char *) graphBytes;
static unsigned char mask[8] = {128,64,32,16,8,4,2,1};
if ((printLocation.y < rect.origin.y-12.0) ||
(printLocation.y > (rect.origin.y + rect.size.height +12.0)))
return;
r.origin.x = printLocation.x;
r.size.width = pixelWidth;
r.size.height = pixelHeight;
NSColor *color = [NSColor blackColor];
[color set];
if (columnBits>8)
length /= 2;
for (i=0;i<length;i++)
{
r.origin.y = printLocation.y;
for (j=0;j<8;j++)
{
if (*bytes & mask[j])
NSRectFill(r);
r.origin.y += pixelHeight;
}
if (columnBits > 8)
{
bytes++;
if (*bytes & 128)
NSRectFill(r);
}
r.origin.x += pixelWidth;
bytes++;
}
}
-(float)getYLocation
{
return printLocation.y;
}
-(float)getMinYLocation
{
return printLocation.y;
}
@end