forked from netshade/Cocoa-Touch-Barcodes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NKDExtendedCode39Barcode.m
139 lines (134 loc) · 6.32 KB
/
NKDExtendedCode39Barcode.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
136
137
138
139
// -----------------------------------------------------------------------------------
// NKDExtendedCode39Barcode.m
// -----------------------------------------------------------------------------------
// Created by Jeff LaMarche on Sat May 04 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 "NKDExtendedCode39Barcode.h"
@implementation NKDExtendedCode39Barcode
// -----------------------------------------------------------------------------------
-(id)initWithContent: (NSString *)inContent
printsCaption: (BOOL)inPrints
// -----------------------------------------------------------------------------------
{
// We have to override super's behavior after calling it.
self = [super initWithContent:inContent
printsCaption:inPrints];
if (self != nil)
[self setContent:inContent];
return self;
}
// -----------------------------------------------------------------------------------
-(NSString *)_encodeChar:(char)inChar
// -----------------------------------------------------------------------------------
{
if (!( (inChar == '$') || (inChar == '%') || (inChar == '+')))
if (![[super _encodeChar:inChar] isEqual:@""])
return [super _encodeChar:inChar];
switch (inChar)
{
// Extended 3 of 9 supports non-printing characters
// like ACK and NUL. We are not going to bother with
// those...
// -------------------------------------------------
case '!':
return [NSString stringWithFormat:@"%@%@",[super _encodeChar:'/'], [super _encodeChar:'A']];
case '"':
return [NSString stringWithFormat:@"%@%@",[super _encodeChar:'/'], [super _encodeChar:'B']];
case '#':
return [NSString stringWithFormat:@"%@%@",[super _encodeChar:'/'], [super _encodeChar:'C']];
case '$':
return [NSString stringWithFormat:@"%@%@",[super _encodeChar:'/'], [super _encodeChar:'D']];
case '%':
return [NSString stringWithFormat:@"%@%@",[super _encodeChar:'/'], [super _encodeChar:'E']];
case '&':
return [NSString stringWithFormat:@"%@%@",[super _encodeChar:'/'], [super _encodeChar:'F']];
case '\'':
return [NSString stringWithFormat:@"%@%@",[super _encodeChar:'/'], [super _encodeChar:'G']];
case '(':
return [NSString stringWithFormat:@"%@%@",[super _encodeChar:'/'], [super _encodeChar:'H']];
case ')':
return [NSString stringWithFormat:@"%@%@",[super _encodeChar:'/'], [super _encodeChar:'I']];
case '*':
return [NSString stringWithFormat:@"%@%@",[super _encodeChar:'/'], [super _encodeChar:'J']];
case '+':
return [NSString stringWithFormat:@"%@%@",[super _encodeChar:'/'], [super _encodeChar:'K']];
case ',':
return [NSString stringWithFormat:@"%@%@",[super _encodeChar:'/'], [super _encodeChar:'L']];
case '/':
return [NSString stringWithFormat:@"%@%@",[super _encodeChar:'/'], [super _encodeChar:'O']];
case ':':
return [NSString stringWithFormat:@"%@%@",[super _encodeChar:'/'], [super _encodeChar:'Z']];
case ';':
return [NSString stringWithFormat:@"%@%@", [super _encodeChar:'%'], [super _encodeChar:'F']];
case '<':
return [NSString stringWithFormat:@"%@%@", [super _encodeChar:'%'], [super _encodeChar:'G']];
case '=':
return [NSString stringWithFormat:@"%@%@", [super _encodeChar:'%'], [super _encodeChar:'H']];
case '>':
return [NSString stringWithFormat:@"%@%@", [super _encodeChar:'%'], [super _encodeChar:'I']];
case '?':
return [NSString stringWithFormat:@"%@%@", [super _encodeChar:'%'], [super _encodeChar:'J']];
case '@':
return [NSString stringWithFormat:@"%@%@", [super _encodeChar:'%'], [super _encodeChar:'V']];
case '[':
return [NSString stringWithFormat:@"%@%@", [super _encodeChar:'%'], [super _encodeChar:'K']];
case '\\':
return [NSString stringWithFormat:@"%@%@", [super _encodeChar:'%'], [super _encodeChar:'L']];
case ']':
return [NSString stringWithFormat:@"%@%@", [super _encodeChar:'%'], [super _encodeChar:'M']];
case '^':
return [NSString stringWithFormat:@"%@%@", [super _encodeChar:'%'], [super _encodeChar:'N']];
case '_':
return [NSString stringWithFormat:@"%@%@", [super _encodeChar:'%'], [super _encodeChar:'0']];
case '`':
return [NSString stringWithFormat:@"%@%@", [super _encodeChar:'%'], [super _encodeChar:'W']];
case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
case 'g':
case 'h':
case 'i':
case 'j':
case 'k':
case 'l':
case 'm':
case 'n':
case 'o':
case 'p':
case 'q':
case 'r':
case 's':
case 't':
case 'u':
case 'v':
case 'w':
case 'x':
case 'y':
case 'z':
return [NSString stringWithFormat:@"%@%@", [super _encodeChar:'+'], [super _encodeChar:toupper(inChar)]];
case '{':
return [NSString stringWithFormat:@"%@%@", [super _encodeChar:'%'], [super _encodeChar:'P']];
case '|':
return [NSString stringWithFormat:@"%@%@", [super _encodeChar:'%'], [super _encodeChar:'Q']];
case '}':
return [NSString stringWithFormat:@"%@%@", [super _encodeChar:'%'], [super _encodeChar:'R']];
case '~':
return [NSString stringWithFormat:@"%@%@", [super _encodeChar:'%'], [super _encodeChar:'S']];
case '\n':
[NSString stringWithFormat:@"%@%@", [super _encodeChar:'$'], [super _encodeChar:'M']];
case '\t':
[NSString stringWithFormat:@"%@%@", [super _encodeChar:'$'], [super _encodeChar:'I']];
default:
break;
}
return @"";
}
@end