This repository has been archived by the owner on Sep 9, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 62
/
NKDAbstractUPCEANBarcode.m
executable file
·135 lines (128 loc) · 4.69 KB
/
NKDAbstractUPCEANBarcode.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
// -----------------------------------------------------------------------------------
// NKDAbstractUPCEANBarcode.m
// -----------------------------------------------------------------------------------
// Created by Jeff LaMarche on Sat May 11 2002.
// �2002 Naked Software. All rights reserved.
// -----------------------------------------------------------------------------------
// THIS SOURCE CODE IS PROVIDED AS-IS WITH NO WARRANTY OF ANY KIND
// -----------------------------------------------------------------------------------
// You may use and redistribute this source code without limitation
// -----------------------------------------------------------------------------------
#import "NKDAbstractUPCEANBarcode.h"
@implementation NKDAbstractUPCEANBarcode
// -----------------------------------------------------------------------------------
-(void)calculateWidth
// -----------------------------------------------------------------------------------
{
// We need to add additional width for the characters to the left and right
if ([[self content] length] != 0)
[self setWidth:([[self completeBarcode] length] * [self barWidth]) * 1.2];
else
[self setWidth:0.0];
}
// -----------------------------------------------------------------------------------
-(float)firstBar
// -----------------------------------------------------------------------------------
{
return [self width] * .1;
}
// -----------------------------------------------------------------------------------
-(float)lastBar
// -----------------------------------------------------------------------------------
{
return ([self width] * .9) - [self barWidth];
}
// -----------------------------------------------------------------------------------
-(NSString *)_encodeChar:(char)inChar
// -----------------------------------------------------------------------------------
{
switch (inChar)
{
case '0':
return @"0001101";
case '1':
return @"0011001";
case '2':
return @"0010011";
case '3':
return @"0111101";
case '4':
return @"0100011";
case '5':
return @"0110001";
case '6':
return @"0101111";
case '7':
return @"0111011";
case '8':
return @"0110111";
case '9':
return @"0001011";
default:
return @"";
break;
}
}
// -----------------------------------------------------------------------------------
-(NSString *)initiator
// -----------------------------------------------------------------------------------
{
return @"101";
}
// -----------------------------------------------------------------------------------
-(NSString *)terminator
// -----------------------------------------------------------------------------------
{
return @"101";
}
// -----------------------------------------------------------------------------------
-(int)digitsToRight
// -----------------------------------------------------------------------------------
{
return 1;
}
// -----------------------------------------------------------------------------------
-(float)barBottom:(int)index
// -----------------------------------------------------------------------------------
{
if ( (index < 7) || (index > ([[self completeBarcode] length] - 7)) || ( (index >= 45) && (index <= 49)))
return 0.05*kScreenResolution;
else
return [self captionHeight] * kScreenResolution;
}
// -----------------------------------------------------------------------------------
-(void)generateChecksum
// -----------------------------------------------------------------------------------
{
int oddSum = 0;
int evenSum = 0;
int i, checkInt;
int even = 1;
//char * code = (char *) [content cStringUsingEncoding:NSStringEncodingConversionAllowLossy];
char * code = (char *) [content cStringUsingEncoding:NSStringEncodingConversionAllowLossy];
if (strlen(code) == 11)
{
i = strlen(code);
while (i-- > 0) {
if (even) evenSum += code[i]-'0';
else oddSum += code[i]-'0';
even = !even;
}
i = (3*evenSum + oddSum) % 10;
checkInt = (10-i) % 10; // complement to 10
checkDigit = checkInt + '0';
}
}
// -----------------------------------------------------------------------------------
-(int)digitsToLeft
// -----------------------------------------------------------------------------------
{
return 1;
}
// -----------------------------------------------------------------------------------
-(NSString *)rightCaption
// -----------------------------------------------------------------------------------
{
return [NSString stringWithFormat:@"%c", checkDigit];
}
@end