Skip to content
This repository has been archived by the owner on Sep 9, 2020. It is now read-only.

Collect useful commits from other forks and package it in a pull request. #11

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
735 changes: 468 additions & 267 deletions CocoaTouchBarcodes.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions CocoaTouchBarcodes/CocoaTouchBarcodes-Prefix.pch
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//
// Prefix header for all source files of the 'CocoaTouchBarcodes' target in the 'CocoaTouchBarcodes' project
//

#ifdef __OBJC__
#import <Foundation/Foundation.h>
#endif
4 changes: 2 additions & 2 deletions JapanPostBarcode.h → CocoaTouchBarcodes/JapanPostBarcode.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@

@interface JapanPostBarcode : NKDBarcode {
@private
NSString *japanpostContents;
NSString *_japanpostContents;
}

- (NSString *)japanpostContents;
@property (readonly, strong) NSString *japanpostContents;

@end
22 changes: 8 additions & 14 deletions JapanPostBarcode.m → CocoaTouchBarcodes/JapanPostBarcode.m
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ - (unsigned int)_barDescriptor:(unsigned int)index
unsigned int bar;
unsigned int hexDigit;
unsigned int descriptor;
unsigned int contentLength = [japanpostContents length];
unsigned int contentLength = [_japanpostContents length];

if ([[self initiator] length] > index) {
bar = index % [[self initiator] length];
Expand All @@ -98,7 +98,7 @@ - (unsigned int)_barDescriptor:(unsigned int)index

bar = (index - [[self initiator] length]) % (2 * numberLength); // 1文字の中の何番目のバーになるか //
if (digit != contentLength) {
hexDigit = japanpost_characterDescriptor( [[self japanpostContents] characterAtIndex:digit] );
hexDigit = japanpost_characterDescriptor( [_japanpostContents characterAtIndex:digit] );
descriptor = japanpost_barDescriptor( hexDigit, bar,numberLength);
}
else { // last digit is checksum
Expand All @@ -110,10 +110,6 @@ - (unsigned int)_barDescriptor:(unsigned int)index
return descriptor;
}

- (NSString *)japanpostContents {
return japanpostContents;
}

// override //

- (id)initWithContent:(NSString *)inContent printsCaption:(BOOL)inPrints andBarWidth:(float)inBarWidth andHeight:(float)inHeight andFontSize:(float)inFontSize andCheckDigit:(char)inDigit
Expand Down Expand Up @@ -165,8 +161,8 @@ - (void)generateChecksum
unichar uChar,character;
unsigned int checkValue = 0;

for (i = 0; i < [japanpostContents length]; i++) {
uChar = [japanpostContents characterAtIndex:i];
for (i = 0; i < _japanpostContents.length; i++) {
uChar = [_japanpostContents characterAtIndex:i];
if ('-' == uChar)
checkValue += 10; // 10 //
else {
Expand Down Expand Up @@ -257,10 +253,8 @@ - (void)setContent:(NSString *)inContent
tempContents = [NSMutableString stringWithString:[tempCStr substringWithRange:NSMakeRange(0,validCount)]];
}
}
[japanpostContents release];
japanpostContents = [[NSString allocWithZone:[self zone]] initWithString:tempStr];
[content release];
content = [[NSString allocWithZone:[self zone]] initWithString:tempContents];
_japanpostContents = [[NSString alloc] initWithString:tempStr];
content = [[NSString alloc] initWithString:tempContents];
[self generateChecksum];
}

Expand All @@ -286,8 +280,8 @@ - (NSString *)barcode
unsigned int i;
NSMutableString *theReturn = [NSMutableString string];

for (i = 0; i < [japanpostContents length]; i++)
[theReturn appendString:[self _encodeChar:[japanpostContents characterAtIndex:i]]];
for (i = 0; i < _japanpostContents.length; i++)
[theReturn appendString:[self _encodeChar:[_japanpostContents characterAtIndex:i]]];
if (checkDigit != -1)
[theReturn appendString:[self _encodeChar:checkDigit]];
return theReturn;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// NKDAbstractUPCEANBarcode.h
// -----------------------------------------------------------------------------------
// Created by Jeff LaMarche on Sat May 11 2002.
// �2002 Naked Software. All rights reserved.
// �2002 Naked Software. All rights reserved.
// -----------------------------------------------------------------------------------
// THIS SOURCE CODE IS PROVIDED AS-IS WITH NO WARRANTY OF ANY KIND
// -----------------------------------------------------------------------------------
Expand Down Expand Up @@ -117,7 +117,7 @@ typedef BOOL Handedness;
@abstract Overridden to specify that guard bars, terminator and initiator should extend down into the caption area
@param index The index of the bar that you want to find the bottom for (assuming origin at lower left) as an index of
completeBarcode
@result Bottom of the bar specified in inches * kScreenResolution
@result Bottom of the bar specified in inches * screenResolution()
*/
-(float)barBottom:(int)index;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ -(float)barBottom:(int)index
{

if ( (index < 7) || (index > ([[self completeBarcode] length] - 7)) || ( (index >= 45) && (index <= 49)))
return 0.05*kScreenResolution;
return 0.05*screenResolution();
else
return [self captionHeight] * kScreenResolution;
return [self captionHeight] * screenResolution();

}
// -----------------------------------------------------------------------------------
Expand Down
6 changes: 2 additions & 4 deletions NKDBarcode.h → CocoaTouchBarcodes/NKDBarcode.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,9 @@
#import <Foundation/Foundation.h>

/*!
@defined kScreenResolution
@discussion This value is used to determine the drawing location of various bars. Though many
devices have different resolution, drawing in Cocoa seems to based on 72 pixels per inch
@discussion This value is used to determine the drawing location of various bars.
*/
#define kScreenResolution 163.00
float screenResolution();

/*!
@class NKDBarcode
Expand Down
49 changes: 34 additions & 15 deletions NKDBarcode.m → CocoaTouchBarcodes/NKDBarcode.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
// -----------------------------------------------------------------------------------
#import "NKDBarcode.h"
#import <UIKit/UIKit.h>
#import <sys/utsname.h>

@implementation NKDBarcode
// -----------------------------------------------------------------------------------
Expand All @@ -26,8 +27,8 @@ -(id)initWithContent: (NSString *)inContent
{
return [self initWithContent:inContent
printsCaption:inPrints
andBarWidth:.013*kScreenResolution
andHeight:.5*kScreenResolution
andBarWidth:.013*screenResolution()
andHeight:.5*screenResolution()
andFontSize:6.0
andCheckDigit:(char)-1];
}
Expand All @@ -44,7 +45,6 @@ -(id)initWithContent: (NSString *)inContent
{
if (!inContent)
{
[self release];
return nil;
}
[self setContent:inContent];
Expand All @@ -55,7 +55,7 @@ -(id)initWithContent: (NSString *)inContent
//if (![self printsCaption])
[self setHeight:inHeight];
//else
[self setHeight:inHeight + (captionHeight*kScreenResolution)];
[self setHeight:inHeight + (captionHeight*screenResolution())];

// Calculate width based on number of bars needed to encode this content
[self calculateWidth];
Expand All @@ -70,11 +70,37 @@ -(id)initWithContent: (NSString *)inContent
return self;
}
// -----------------------------------------------------------------------------------
float screenResolution()
// -----------------------------------------------------------------------------------
{
struct utsname systemInfo;
uname(&systemInfo);
char *name = systemInfo.machine;

float ppi;
if ((strstr(name, "iPod") != NULL) && (strstr(name, "iPod4") == NULL)) {
// older ipod touches
ppi = 163;
} else if ((strstr(name, "iPhone") != NULL) && (strstr(name, "iPhone3") == NULL)) {
// older non-retina iphones
ppi = 163;
} else if ((strstr(name, "iPad") != NULL) && (strstr(name, "iPad3") == NULL)) {
// ipad 1, ipad 2
ppi = 132;
} else if (strstr(name, "iPad3") != NULL) {
// ipad 3
ppi = 264;
} else {
// iphone 4/4s, ipod touch 4g or simulator
ppi = 326;
}
return ppi;
}
// -----------------------------------------------------------------------------------
-(void)setContent:(NSString *)inContent
// -----------------------------------------------------------------------------------
{
[content autorelease];
content = [inContent retain];
content = inContent;
}
// -----------------------------------------------------------------------------------
-(void)setHeight:(float)inHeight
Expand Down Expand Up @@ -288,7 +314,7 @@ -(float)barBottom:(int)index
// -----------------------------------------------------------------------------------
{
if ([self printsCaption])
return captionHeight * kScreenResolution;
return captionHeight * screenResolution();
else
return 0.0;
}
Expand All @@ -314,7 +340,7 @@ -(float)lastBar
-(NSString *)description
// -----------------------------------------------------------------------------------
{
return [NSString stringWithFormat:@"\n\tBarcode Class: %@\n\tContent: %@\n\tCheck Digit:%c\n\tWidth:%f\n\t%Height:%f\n\tBar Width:%f\n\tFont Size:%f\n\tCaption Height:%f",
return [NSString stringWithFormat:@"\n\tBarcode Class: %@\n\tContent: %@\n\tCheck Digit:%c\n\tWidth:%f\n\tHeight:%f\n\tBar Width:%f\n\tFont Size:%f\n\tCaption Height:%f",
[self class],
[self content],
[self checkDigit],
Expand Down Expand Up @@ -385,11 +411,4 @@ - (void) encodeWithCoder: (NSCoder *)coder
[coder encodeValueOfObjCType:@encode(char) at:&checkDigit];

}
// -----------------------------------------------------------------------------------
-(void)dealloc
// -----------------------------------------------------------------------------------
{
[content release];
[super dealloc];
}
@end
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ -(NKDBarcode *)barcode
-(void)setBarcode:(NKDBarcode *)inBarcode
// -----------------------------------------------------------------------------------
{
[barcode autorelease];
barcode = inBarcode;
}
// -----------------------------------------------------------------------------------
Expand Down Expand Up @@ -230,11 +229,11 @@ - (UIImage *)imageInsideRect:(CGRect)rect

- (NSData *)pdfInsideRect:(CGRect)rect {
NSMutableData * data = [NSMutableData data];
CGDataConsumerRef consumer = CGDataConsumerCreateWithCFData((CFMutableDataRef)data);
CGDataConsumerRef consumer = CGDataConsumerCreateWithCFData((__bridge CFMutableDataRef)data);
CGRect media = CGRectMake(0.0, 0.0, rect.size.width, rect.size.height);
CGContextRef context = CGPDFContextCreate(consumer, &media, (CFDictionaryRef)[NSDictionary dictionary]);
CGContextRef context = CGPDFContextCreate(consumer, &media, (__bridge CFDictionaryRef)[NSDictionary dictionary]);
UIGraphicsPushContext(context);
CGPDFContextBeginPage(context, (CFDictionaryRef)[NSDictionary dictionary]);
CGPDFContextBeginPage(context, (__bridge CFDictionaryRef)[NSDictionary dictionary]);
[self drawRect:rect];
UIGraphicsPopContext();
CGPDFContextEndPage(context);
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions NKDEAN8Barcode.h → CocoaTouchBarcodes/NKDEAN8Barcode.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// NKDEAN8Barcode.h
// -----------------------------------------------------------------------------------
// Created by Jeff LaMarche on Wed May 29 2002.
// �2002 Naked Software. All rights reserved.
// �2002 Naked Software. All rights reserved.
// -----------------------------------------------------------------------------------
// THIS SOURCE CODE IS PROVIDED AS-IS WITH NO WARRANTY OF ANY KIND
// -----------------------------------------------------------------------------------
Expand Down Expand Up @@ -66,7 +66,7 @@
@abstract Overridden to specify that guard bars, terminator and initiator should extend down into the caption area
@param index The index of the bar that you want to find the bottom for (assuming origin at lower left) as an index of
completeBarcode
@result Bottom of the bar specified in inches * kScreenResolution
@result Bottom of the bar specified in inches * screenResolution()
*/
-(float)barBottom:(int)index;

Expand Down
4 changes: 2 additions & 2 deletions NKDEAN8Barcode.m → CocoaTouchBarcodes/NKDEAN8Barcode.m
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ -(float)barBottom:(int)index
// -----------------------------------------------------------------------------------
{
if ( (index < 4) || (index > ([[self completeBarcode] length] - 4)) || (index == 33) || (index == 35))
return 0.05*kScreenResolution;
return 0.05*screenResolution();
else
return [self captionHeight] * kScreenResolution;
return [self captionHeight] * screenResolution();
}
// -----------------------------------------------------------------------------------
-(int)digitsToRight
Expand Down
11 changes: 5 additions & 6 deletions NKDPostnetBarcode.m → CocoaTouchBarcodes/NKDPostnetBarcode.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,18 @@ -(id)initWithContent: (NSString *)inContent
{
if (!inContent)
{
[self release];
return nil;
}
[self setContent:inContent];

[self setBarWidth:.015*kScreenResolution];
[self setBarWidth:.015*screenResolution()];
[self setPrintsCaption:inPrints];

// Postnet has a mandatory check digit
[self generateChecksum];

// .125 inch bar height is about the middle of the allowed values
[self setHeight:.125*kScreenResolution];
[self setHeight:.125*screenResolution()];

// Calculate width based on number of bars needed to encode this content
[self calculateWidth];
Expand Down Expand Up @@ -81,15 +80,15 @@ -(float)barTop:(int)index

// Look for and deal with terminator and initiator first
if (index == 0)
return TALL_BAR * kScreenResolution;
return TALL_BAR * screenResolution();

if (index >= ([[self completeBarcode] length] - 1))
return TALL_BAR * kScreenResolution;
return TALL_BAR * screenResolution();

// Now, figure out which digit we're encoding, and which bar of that digit
digit = (int)((index-3) / 15);
bar = (index - (digit * 15)) / 3;
return [self _heightForDigit:digit andBar:bar] * kScreenResolution;
return [self _heightForDigit:digit andBar:bar] * screenResolution();
}
// -----------------------------------------------------------------------------------
-(float)_heightForDigit:(int)index
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,17 +154,16 @@ -(id)initWithContent: (NSString *)inContent
{
if (!inContent)
{
[self release];
return nil;
}
[self setContent:inContent];

[self setBarWidth:CBC_BAR_WIDTH*CBC_INCHES_PER_MILLIMETER*kScreenResolution];
[self setBarWidth:CBC_BAR_WIDTH*CBC_INCHES_PER_MILLIMETER*screenResolution()];
[self setPrintsCaption:NO];

// RM4SCC has a mandatory check digit
[self generateChecksum];
[self setHeight:CBC_ASCENDER_TOP*CBC_INCHES_PER_MILLIMETER*kScreenResolution];
[self setHeight:CBC_ASCENDER_TOP*CBC_INCHES_PER_MILLIMETER*screenResolution()];

// Calculate width based on number of bars needed to encode this content
[self calculateWidth];
Expand Down Expand Up @@ -240,7 +239,7 @@ -(float)barTop:(int)index
{
return royalmail_barTop( [self _barDescriptor:index] ) *
CBC_INCHES_PER_MILLIMETER *
kScreenResolution;
screenResolution();
}

// -----------------------------------------------------------------------------------
Expand All @@ -249,7 +248,7 @@ -(float)barBottom:(int)index
{
return royalmail_barBottom( [self _barDescriptor:index] ) *
CBC_INCHES_PER_MILLIMETER *
kScreenResolution;
screenResolution();
}

// -----------------------------------------------------------------------------------
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions NKDUPCEBarcode.h → CocoaTouchBarcodes/NKDUPCEBarcode.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// NKDUPCEBarcode.h
// -----------------------------------------------------------------------------------
// Created by Jeff LaMarche on Fri May 24 2002.
// �2002 Naked Software. All rights reserved.
// �2002 Naked Software. All rights reserved.
// -----------------------------------------------------------------------------------
// THIS SOURCE CODE IS PROVIDED AS-IS WITH NO WARRANTY OF ANY KIND
// -----------------------------------------------------------------------------------
Expand Down Expand Up @@ -55,7 +55,7 @@
@abstract [TO COME]
@param index The index of the bar that you want to find the bottom for (assuming origin at lower left) as an index of
completeBarcode
@result Bottom of the bar specified in inches * kScreenResolution
@result Bottom of the bar specified in inches * screenResolution()
*/
-(float)barBottom:(int)index;

Expand Down
4 changes: 2 additions & 2 deletions NKDUPCEBarcode.m → CocoaTouchBarcodes/NKDUPCEBarcode.m
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ -(float)barBottom:(int)index
// -----------------------------------------------------------------------------------
{
if ( (index < 7) || (index > ([[self completeBarcode] length] - 4)))
return 0.05*kScreenResolution;
return 0.05*screenResolution();
else
return [self captionHeight] * kScreenResolution;
return [self captionHeight] * screenResolution();
}
// -----------------------------------------------------------------------------------
-(BOOL) isContentValid
Expand Down
File renamed without changes.
File renamed without changes.
Loading