UniPRT SDK v1.0.0.0
 
Loading...
Searching...
No Matches
LabelMaker

Classes and methods related to LabelMaker. More...

Topics

 Interface
 Interface for different barcode types and formats.
 
 PGL
 Interface for different barcode types and formats.
 
 TSPL
 Interface for different barcode types and formats.
 

Detailed Description

Classes and methods related to LabelMaker.

For the Objective-C example, see here.

For the Swift example, see here.

Example

Objective-C:

#import "ViewController.h"
@import UniPRT;
@interface ViewController ()
@property (nonatomic, strong) UITextView *resultTextView;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
[self setupButtons];
[self setupResultTextView];
}
- (void)setupButtons {
NSArray *buttonTitles = @[@"Pdf417", @"SimpleLabel", @"RfidEncode", @"Maxicodes", @"DataMatrix", @"Aztec", @"QRCode",@"PglPdf417", @"PglSimpleLabel", @"PglRfidEncode", @"PglMaxicodes", @"PglDataMatrix", @"PglAztec", @"PglQRCode", @"PglRulerLabel"];
CGFloat buttonWidth = (self.view.frame.size.width - 40) / 3 - 10;
CGFloat buttonHeight = 50;
CGFloat yOffset = 100;
int buttonsPerRow = 3;
for (NSInteger i = 0; i < buttonTitles.count; i++) {
UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
CGFloat xPosition = 20 + (buttonWidth + 10) * (i % buttonsPerRow);
CGFloat yPosition = yOffset + (buttonHeight + 10) * (i / buttonsPerRow);
button.frame = CGRectMake(xPosition, yPosition, buttonWidth, buttonHeight);
[button setTitle:buttonTitles[i] forState:UIControlStateNormal];
button.backgroundColor = [UIColor lightGrayColor];
button.layer.cornerRadius = 5;
button.tag = i;
[button addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
}
}
- (void)setupResultTextView {
self.resultTextView = [[UITextView alloc] initWithFrame:CGRectMake(20, 400, self.view.frame.size.width - 40, 450)];
self.resultTextView.editable = NO;
self.resultTextView.backgroundColor = [UIColor lightGrayColor];
[self.view addSubview:self.resultTextView];
}
- (void)buttonTapped:(UIButton *)sender {
Label *result;
PglLabel *pglresult;
NSString *resultString;
switch (sender.tag) {
case 0:
result = BcdPdf417();
break;
case 1:
result = SimpleTextLabel(@"Mr. Milky Cheese",@"123 No Way Road");
break;
case 2:
result = RfidEncode();
break;
case 3:
result = BcdMaxicodes();
break;
case 4:
result = BcdDataMatrix();
break;
case 5:
result = BcdAztec();
break;
case 6:
result = BcdQRCode();
break;
case 7:
pglresult = PglBcdPdf417();
break;
case 8:
pglresult = PglSimpleLabel(@"Mr. Milky Cheese",@"123 No Way Road");
break;
case 9:
pglresult = PglRfidEncode();
break;
case 10:
pglresult = PglBcdMaxicodes();
break;
case 11:
pglresult = PglBcdDataMatrix();
break;
case 12:
pglresult = PglBcdAztec();
break;
case 13:
pglresult = PglBcdQRCode();
break;
case 14:
pglresult = RuleredLabel(4.0f, 6.0f, YES, 1.0f/8.0f);
default:
break;
}
if (result) {
resultString = [result description];
}else if(pglresult){
resultString = [pglresult description];
}else {
resultString = @"";
}
self.resultTextView.text = resultString;
}
Label* BcdPdf417(void) {
Label *lbl = [[Label alloc] initWithName:@"Pdf417Bcodes"];
[Defaults SetPrinterResolution:[[PrintResolution alloc] initWithDotsPerUnit:300 unit:ScaleEnumInch]];
[Defaults SetRuler:[[Ruler alloc] initWithScale:ScaleEnumInch]];
NSString *someText = @"The happiness in your life depends on the quality of your thoughts. --Marcus Aurelius";
NSString *someShortText = @"PI = 3.1415";
Pdf417Barcode *bcdDefault = [[Pdf417Barcode alloc] initWithStart:[[Points alloc] initWithX:0.25 y:0.50] data:someText];
bcdDefault.cellSize = [[CellRect alloc] initWithXDim:0.015 yDim:0.050 ruler:[[Ruler alloc] initWithScale:ScaleEnumInch]];
Pdf417Barcode *bcdErrCorrectionLvl0 = [[Pdf417Barcode alloc] initWithStart:[[Points alloc] initWithX:0.25 y:1.50] data:someShortText];
bcdErrCorrectionLvl0.cellSize = [[CellRect alloc] initWithXDim:0.015 yDim:0.050 ruler:[[Ruler alloc] initWithScale:ScaleEnumInch]];
bcdErrCorrectionLvl0.errorCorrection = Pdf417ErrCorrectionLevel0;
Pdf417Barcode *bcdErrCorrectionLvl5 = [[Pdf417Barcode alloc] initWithStart:[[Points alloc] initWithX:0.25 y:2.00] data:someShortText];
bcdErrCorrectionLvl5.cellSize = [[CellRect alloc] initWithXDim:0.015 yDim:0.050 ruler:[[Ruler alloc] initWithScale:ScaleEnumInch]];
bcdErrCorrectionLvl5.errorCorrection = Pdf417ErrCorrectionLevel5;
Pdf417Barcode *bcdRowsLimited = [[Pdf417Barcode alloc] initWithStart:[[Points alloc] initWithX:0.25 y:3.00] data:someShortText];
bcdRowsLimited.cellSize = [[CellRect alloc] initWithXDim:0.015 yDim:0.050 ruler:[[Ruler alloc] initWithScale:ScaleEnumInch]];
bcdRowsLimited.rows = 15;
Pdf417Barcode *bcdColsLimited = [[Pdf417Barcode alloc] initWithStart:[[Points alloc] initWithX:0.25 y:4.00] data:someShortText];
bcdColsLimited.cellSize = [[CellRect alloc] initWithXDim:0.015 yDim:0.050 ruler:[[Ruler alloc] initWithScale:ScaleEnumInch]];
bcdColsLimited.columns = 5;
[lbl addObject:bcdDefault];
[lbl addObject:bcdErrCorrectionLvl0];
[lbl addObject:bcdErrCorrectionLvl5];
[lbl addObject:bcdRowsLimited];
[lbl addObject:bcdColsLimited];
return lbl;
}
Label* SimpleTextLabel(NSString *name, NSString *address) {
[Defaults SetPrinterResolution:[[PrintResolution alloc] initWithDotsPerUnit:600 unit:ScaleEnumInch]];
Label *lbl = [[Label alloc] initWithName:@"SimpleLabel"];
Ruler *inchRuler = [[Ruler alloc] initWithScale:ScaleEnumInch];
// Ruler *mmRuler = [[Ruler alloc] initWithScale:ScaleEnumMM];
_Line *line1 = [[_Line alloc] initWithStart:[[Points alloc] initWithX:2.5f y:1.0f/16.0f]
end:[[Points alloc] initWithX:2.5f y:1.0f]
lineThickness:1.0f/32.0f];
line1.ruler = inchRuler;
[lbl addObject:line1];
_Line *line2 = [[_Line alloc] initWithStart:[[Points alloc] initWithX:0.12 y:1.0]
end:[[Points alloc] initWithX:3.88 y:1.0]
lineThickness:1.0/32.0];
line2.ruler = inchRuler;
[lbl addObject:line2];
_Line *line3 = [[_Line alloc] initWithStart:[[Points alloc] initWithX:0.12 y:3.5]
end:[[Points alloc] initWithX:3.88 y:3.5]
lineThickness:1.0/32.0];
line3.ruler = inchRuler;
[lbl addObject:line3];
_Box *line4 = [[_Box alloc] initWithStart:[[Points alloc] initWithX:0.5 y:1.25]
end:[[Points alloc] initWithX:3.5 y:2.25]
lineThickness:1.0/16.0];
line4.ruler = inchRuler;
[lbl addObject:line4];
BarcodeItem *barcodeItem128 = [[BarcodeItem alloc] initWithStart:[[Points alloc] initWithX:0.5 y:(1.0 + 1.5 + 1.0 / 4.0 + 1.2)]
height:1.2
data:@"Code 128"];
Barcode_1D *bcd128 = [[Barcode_1D alloc] initWithBarcodeItem:barcodeItem128];
bcd128.barcodeType = BarcodeTypeEnum1DCode128;
bcd128.printHumanReadable = YES;
bcd128.rotation = RotateEnumNone;
bcd128.ruler = inchRuler;
bcd128.barWidths = [[BarWidths alloc] initWithNarrowBar:0.015f wideBar:0.015f];
bcd128.barWidths.ruler = [[Ruler alloc] initWithScale:ScaleEnumInch];
[lbl addObject:bcd128];
BarcodeItem *barcodeItem93 = [[BarcodeItem alloc] initWithStart:[[Points alloc] initWithX:0.5f y:3.5f - 1.0f / 8.0f - 0.6f]
height:0.6f
data:@"CODE 93"];
Barcode_1D *bcd93 = [[Barcode_1D alloc] initWithBarcodeItem:barcodeItem93];
bcd93.barcodeType = BarcodeTypeEnum1DCode93;
bcd93.printHumanReadable = YES;
bcd93.rotation = RotateEnumNone;
bcd93.ruler = inchRuler;
bcd93.barWidths = [[BarWidths alloc] initWithNarrowBar:0.025f wideBar:0.025f * 3];
bcd93.barWidths.ruler = [[Ruler alloc] initWithScale:ScaleEnumInch];
[lbl addObject:bcd93];
return lbl;
}
Label* RfidEncode(void) {
Label *lbl = [[Label alloc] initWithName:@"RfidLbl"];
uint32_t a32BitField = 0x11223344;
uint16_t a16BitField = 0xBEEF;
NSString *a6CharAsciiString = @"MyData";
NSString *epcHexData = [RfidConvert toHexFromUInt:a32BitField];
epcHexData = [epcHexData stringByAppendingString:[RfidConvert toHexFromBytes:[a6CharAsciiString dataUsingEncoding:NSASCIIStringEncoding]]];
epcHexData = [epcHexData stringByAppendingString:[RfidConvert toHexFromUShort:a16BitField]];
Rfid_Write *epc = [[Rfid_Write alloc] initWithMemBlock:RfidMemBlockEnumEPC data:epcHexData];
[lbl addObject:epc];
NSString *userHexData = [RfidConvert toHexFromASCIIString:@"MyUserData"];
userHexData = [userHexData stringByAppendingString:@"0ABCDE0F"];
Rfid_Write *userMem = [[Rfid_Write alloc] initWithMemBlock:RfidMemBlockEnumUser data:userHexData];
userMem.offsetFromStart = 2;
[lbl addObject:userMem];
return lbl;
}
Label* BcdMaxicodes(void) {
[Defaults SetPrinterResolution:[[PrintResolution alloc] initWithDotsPerUnit:203.0f unit:ScaleEnumInch]];
Label *lbl = [[Label alloc] initWithName:@"MaxiBcds"];
MaxicodeMsgStructured *maxiDataStructCarrier = [[MaxicodeMsgStructured alloc] initWithMode:MaxicodeModeEnumMode2 postalCode:@"902557317" countryCode:@"800" serviceClass:@"200" remainingMsg:@"Maxicode Carrier Standard"];
MaxicodeBarcode *maxicodeBarcodeSc = [[MaxicodeBarcode alloc] initWithStart:[[Points alloc] initWithX:0.5f y:0.5f] data:maxiDataStructCarrier];
maxicodeBarcodeSc.ruler = [[Ruler alloc] initWithScale:ScaleEnumInch];
MaxicodeMsg *maxiData = [[MaxicodeMsg alloc] initWithMode:MaxicodeModeEnumMode4 primaryMsg:@"123456789" remainingMsg:@"Maxicode unstructured"];
MaxicodeBarcode *maxicodeBarcode = [[MaxicodeBarcode alloc] initWithStart:[[Points alloc] initWithX:0.5f y:3.5f] data:maxiData];
maxicodeBarcode.ruler = [[Ruler alloc] initWithScale:ScaleEnumInch];
[lbl addObject:maxicodeBarcodeSc];
[lbl addObject:maxicodeBarcode];
return lbl;
}
Label* BcdDataMatrix(void) {
Label *lbl = [[Label alloc] initWithName:@"DMatrixBcds"];
[Defaults SetPrinterResolution:[[PrintResolution alloc] initWithDotsPerUnit:600.0f unit:ScaleEnumInch]];
[Defaults SetRuler:[[Ruler alloc] initWithScale:ScaleEnumInch]];
DataMatrixBarcode *dfltMatrix = [[DataMatrixBarcode alloc] initWithStart:[[Points alloc] initWithX:0.25f y:0.25f] data:@"Default DataMatrix"];
DataMatrixBarcode *rectMatrix = [[DataMatrixBarcode alloc] initWithStart:[[Points alloc] initWithX:1.25f y:0.25f] data:@"Rectangular DataMatrix"];
rectMatrix.rotation = RotateEnumCounterClockwise;
rectMatrix.rectangle = YES;
rectMatrix.cellSize = [[CellSquare alloc] initWithXDim:0.025f ruler:[[Ruler alloc] initWithScale:ScaleEnumInch]];
DataMatrixBarcode *dfltMatrixMultiLine = [[DataMatrixBarcode alloc] initWithStart:[[Points alloc] initWithX:2.25f y:0.25f] data:@"Line 1 DataMatrix"];
NSString *Eol = [[dfltMatrixMultiLine ctrlChar:0x0D] stringByAppendingString:[dfltMatrixMultiLine ctrlChar:0x0A]]; // CR + LF
dfltMatrixMultiLine.data = [dfltMatrixMultiLine.data stringByAppendingString:Eol];
dfltMatrixMultiLine.data = [dfltMatrixMultiLine.data stringByAppendingString:@"Line 2 content"];
dfltMatrixMultiLine.data = [dfltMatrixMultiLine.data stringByAppendingString:Eol];
dfltMatrixMultiLine.data = [dfltMatrixMultiLine.data stringByAppendingString:@"Line 3 content"];
DataMatrixBarcode *rectMatrixUserDefinedDimensions = [[DataMatrixBarcode alloc] initWithStart:[[Points alloc] initWithX:1.25f y:1.75f] data:@"DataMatrix with user defined dimensions"];
rectMatrixUserDefinedDimensions.rectangle = YES;
rectMatrixUserDefinedDimensions.rowsCols = [NSValue valueWithCGSize:CGSizeMake(16, 36)];
rectMatrixUserDefinedDimensions.cellSize = [[CellSquare alloc] initWithXDim:0.030f ruler:[[Ruler alloc] initWithScale:ScaleEnumInch]];
[lbl addObject:dfltMatrix];
[lbl addObject:rectMatrix];
[lbl addObject:dfltMatrixMultiLine];
[lbl addObject:rectMatrixUserDefinedDimensions];
return lbl;
}
Label* BcdAztec(void) {
Label *lbl = [[Label alloc] initWithName:@"AztecBcodes"];
[Defaults SetPrinterResolution:[[PrintResolution alloc] initWithDotsPerUnit:300.0f unit:ScaleEnumInch]];
[Defaults SetRuler:[[Ruler alloc] initWithScale:ScaleEnumInch]];
NSString *someText = @"Mr. AirTraveler, seat A, flight 200";
AztecBarcode *bcdDefault = [[AztecBarcode alloc] initWithStart:[[Points alloc] initWithX:0.25f y:1.0f] data:someText];
bcdDefault.cellSize = [[CellSquare alloc] initWithXDim:0.025f ruler:[[Ruler alloc] initWithScale:ScaleEnumInch]];
AztecBarcode *bcdFixedErrCorr = [[AztecBarcode alloc] initWithStart:[[Points alloc] initWithX:1.5f y:1.0f] data:someText];
bcdFixedErrCorr.cellSize = [[CellSquare alloc] initWithXDim:0.025f ruler:[[Ruler alloc] initWithScale:ScaleEnumInch]];
bcdFixedErrCorr.type = AztecCodeTypeFixedErrCorrection;
bcdFixedErrCorr.fixedErrCorrection = 30;
AztecBarcode *bcdCompact = [[AztecBarcode alloc] initWithStart:[[Points alloc] initWithX:0.25f y:2.25f] data:someText];
bcdCompact.cellSize = [[CellSquare alloc] initWithXDim:0.025f ruler:[[Ruler alloc] initWithScale:ScaleEnumInch]];
bcdCompact.type = AztecCodeTypeCompact;
bcdCompact.layers = 4;
AztecBarcode *bcdFull = [[AztecBarcode alloc] initWithStart:[[Points alloc] initWithX:1.5f y:2.25f] data:someText];
bcdFull.cellSize = [[CellSquare alloc] initWithXDim:0.025f ruler:[[Ruler alloc] initWithScale:ScaleEnumInch]];
bcdFull.type = AztecCodeTypeFull;
bcdFull.layers = 5;
AztecBarcode *bcdRuneA = [[AztecBarcode alloc] initWithStart:[[Points alloc] initWithX:0.25f y:4.00f] data:@"0"];
bcdRuneA.cellSize = [[CellSquare alloc] initWithXDim:0.025f ruler:[[Ruler alloc] initWithScale:ScaleEnumInch]];
bcdRuneA.type = AztecCodeTypeRune;
AztecBarcode *bcdRuneB = [[AztecBarcode alloc] initWithStart:[[Points alloc] initWithX:0.75f y:4.00f] data:@"255"];
bcdRuneB.cellSize = [[CellSquare alloc] initWithXDim:0.025f ruler:[[Ruler alloc] initWithScale:ScaleEnumInch]];
bcdRuneB.type = AztecCodeTypeRune;
AztecBarcode *bcdRuneC = [[AztecBarcode alloc] initWithStart:[[Points alloc] initWithX:1.25f y:4.00f] data:@"123"];
bcdRuneC.cellSize = [[CellSquare alloc] initWithXDim:0.025f ruler:[[Ruler alloc] initWithScale:ScaleEnumInch]];
bcdRuneC.type = AztecCodeTypeRune;
[lbl addObject:bcdDefault];
[lbl addObject:bcdFixedErrCorr];
[lbl addObject:bcdFull];
[lbl addObject:bcdCompact];
[lbl addObject:bcdRuneA];
[lbl addObject:bcdRuneB];
[lbl addObject:bcdRuneC];
return lbl;
}
Label* BcdQRCode(void) {
Label *lbl = [[Label alloc] initWithName:@"QRCodes"];
[Defaults SetPrinterResolution:[[PrintResolution alloc] initWithDotsPerUnit:300.0f unit:ScaleEnumInch]];
[Defaults SetRuler:[[Ruler alloc] initWithScale:ScaleEnumInch]];
NSString *enText = @"Tree in the forest";
NSString *jaText = @"森の中の木";
QRBarcode *english = [[QRBarcode alloc] initWithStart:[[Points alloc] initWithX:0.25f y:1.0f] data:enText];
english.cellSize = [[CellSquare alloc] initWithXDim:0.025f ruler:[[Ruler alloc] initWithScale:ScaleEnumInch]];
QRBarcode *englishMasked = [[QRBarcode alloc] initWithStart:[[Points alloc] initWithX:1.5f y:1.0f] data:enText];
englishMasked.cellSize = [[CellSquare alloc] initWithXDim:0.025f ruler:[[Ruler alloc] initWithScale:ScaleEnumInch]];
englishMasked.mask = QRCodeMask4;
QRBarcode *japanese = [[QRBarcode alloc] initWithStart:[[Points alloc] initWithX:0.25f y:2.25f] data:jaText];
japanese.cellSize = [[CellSquare alloc] initWithXDim:0.025f ruler:[[Ruler alloc] initWithScale:ScaleEnumInch]];
japanese.mask = QRCodeMask1;
QRBarcode *japaneseMasked = [[QRBarcode alloc] initWithStart:[[Points alloc] initWithX:1.5f y:2.25f] data:jaText];
japaneseMasked.cellSize = [[CellSquare alloc] initWithXDim:0.025f ruler:[[Ruler alloc] initWithScale:ScaleEnumInch]];
japaneseMasked.mask = QRCodeMask4;
QRBarcode *autoEncData = [[QRBarcode alloc] initWithStart:[[Points alloc] initWithX:0.25f y:3.75f] data:@"12345678 TREE IN THE FOREST 森の中の木"];
autoEncData.cellSize = [[CellSquare alloc] initWithXDim:0.025f ruler:[[Ruler alloc] initWithScale:ScaleEnumInch]];
autoEncData.mask = QRCodeMask4;
NSArray *manualModeData = @[
@[@(QRCodeManualEncodingNumeric), @"12345678"],
@[@(QRCodeManualEncodingAlphaNumeric), @" TREE IN THE FOREST "],
@[@(QRCodeManualEncodingBinary), @"森の中の木"]
];
QRBarcode *manualEncData = [[QRBarcode alloc] initWithStart:[[Points alloc] initWithX:1.75f y:3.75f] manuallyEncodedData:manualModeData];
manualEncData.cellSize = [[CellSquare alloc] initWithXDim:0.025f ruler:[[Ruler alloc] initWithScale:ScaleEnumInch]];
manualEncData.mask = QRCodeMask4;
[lbl addObject:english];
[lbl addObject:englishMasked];
[lbl addObject:japanese];
[lbl addObject:japaneseMasked];
[lbl addObject:autoEncData];
[lbl addObject:manualEncData];
return lbl;
}
//PGL
void FileReplace(NSString *pathAndName, NSString *dataToWrite) {
NSError *error;
[dataToWrite writeToFile:pathAndName atomically:YES encoding:NSUTF8StringEncoding error:&error];
if (error) {
NSLog(@"Error writing file: %@", error.localizedDescription);
}
}
NSString *stringToHex(NSString *input) {
const char *utf8String = [input UTF8String];
NSMutableString *hexString = [NSMutableString string];
while (*utf8String) {
[hexString appendFormat:@"%02X", *utf8String++];
}
return hexString;
}
PglLabel *PglRfidEncode(void) {
PglLabel *lbl = [[PglLabel alloc] initWithName:@"RfidLbl"];
uint32_t a32BitField = 0x11223344;
uint16_t a16BitField = 0xBEEF;
NSString *a6CharAsciiString = @"MyData";
NSString *epcHexData = [NSString stringWithFormat:@"%08X%@", a32BitField, stringToHex(a6CharAsciiString)];
epcHexData = [epcHexData stringByAppendingFormat:@"%04X", a16BitField];
PglRfid_Write *epc = [[PglRfid_Write alloc] initWithMemBlock:RfidMemBlockEnumEPC data:epcHexData];
[lbl addObject:epc];
NSString *userDataHex = stringToHex(@"MyUserData");
userDataHex = [userDataHex stringByAppendingString:@"0ABCDE0F"];
PglRfid_Write *userMem = [[PglRfid_Write alloc] initWithMemBlock:RfidMemBlockEnumUser data:userDataHex];
userMem.offsetFromStart = 2;
[lbl addObject:userMem];
return lbl;
}
PglLabel *PglBcdPdf417(void) {
PglLabel *lbl = [[PglLabel alloc] initWithName:@"Pdf417Bcodes"];
// [Defaults SetPrinterResolution:[[PrintResolution alloc] initWithDotsPerUnit:300.0f unit:ScaleEnumInch]];
[Defaults SetPrinterResolution:[[PrintResolution alloc] initWithDotsPerUnit:600.0f unit:ScaleEnumInch]];
[Defaults SetRuler:[[Ruler alloc] initWithScale:ScaleEnumInch]];
NSString *someText = @"The happiness in your life depends on the quality of your thoughts. --Marcus Aurelius";
NSString *someShortText = @"PI = 3.1415";
PglPdf417Barcode *bcdDefault = [[PglPdf417Barcode alloc] initWithStart:[[Points alloc] initWithX:0.25f y:0.50f] data:someText];
bcdDefault.cellSize = [[CellRect alloc] initWithXDim:0.015f yDim:0.050f ruler:[[Ruler alloc] initWithScale:ScaleEnumInch]];
PglPdf417Barcode *bcdErrCorrectionLvl0 = [[PglPdf417Barcode alloc] initWithStart:[[Points alloc] initWithX:0.25f y:1.50f] data:someShortText];
bcdErrCorrectionLvl0.cellSize = [[CellRect alloc] initWithXDim:0.015f yDim:0.050f ruler:[[Ruler alloc] initWithScale:ScaleEnumInch]];
bcdErrCorrectionLvl0.errorCorrection = Pdf417ErrCorrectionLevel0;
PglPdf417Barcode *bcdErrCorrectionLvl5 = [[PglPdf417Barcode alloc] initWithStart:[[Points alloc] initWithX:0.25f y:2.00f] data:someShortText];
bcdErrCorrectionLvl5.cellSize = [[CellRect alloc] initWithXDim:0.015f yDim:0.050f ruler:[[Ruler alloc] initWithScale:ScaleEnumInch]];
bcdErrCorrectionLvl5.errorCorrection = Pdf417ErrCorrectionLevel5;
PglPdf417Barcode *bcdRowsLimited = [[PglPdf417Barcode alloc] initWithStart:[[Points alloc] initWithX:0.25f y:3.00f] data:someShortText];
bcdRowsLimited.cellSize = [[CellRect alloc] initWithXDim:0.015f yDim:0.050f ruler:[[Ruler alloc] initWithScale:ScaleEnumInch]];
bcdRowsLimited.rows = 15;
PglPdf417Barcode *bcdColsLimited = [[PglPdf417Barcode alloc] initWithStart:[[Points alloc] initWithX:0.25f y:4.00f] data:someShortText];
bcdColsLimited.cellSize = [[CellRect alloc] initWithXDim:0.015f yDim:0.050f ruler:[[Ruler alloc] initWithScale:ScaleEnumInch]];
bcdColsLimited.columns = 5;
[lbl addObject:bcdDefault];
[lbl addObject:bcdErrCorrectionLvl0];
[lbl addObject:bcdErrCorrectionLvl5];
[lbl addObject:bcdRowsLimited];
[lbl addObject:bcdColsLimited];
return lbl;
}
PglLabel *PglBcdAztec(void) {
PglLabel *lbl = [[PglLabel alloc] initWithName:@"AztecBcodes"];
[Defaults SetPrinterResolution:[[PrintResolution alloc] initWithDotsPerUnit:300.0f unit:ScaleEnumInch]];
[Defaults SetRuler:[[Ruler alloc] initWithScale:ScaleEnumInch]];
NSString *someText = @"Mr. AirTraveler, seat A, flight 200";
PglAztecBarcode *bcdDefault = [[PglAztecBarcode alloc] initWithStart:[[Points alloc] initWithX:0.25f y:1.0f] data:someText];
bcdDefault.cellSize = [[CellSquare alloc] initWithXDim:0.025f ruler:[[Ruler alloc] initWithScale:ScaleEnumInch]];
PglAztecBarcode *bcdFixedErrCorr = [[PglAztecBarcode alloc] initWithStart:[[Points alloc] initWithX:1.5f y:1.0f] data:someText];
bcdFixedErrCorr.cellSize = [[CellSquare alloc] initWithXDim:0.025f ruler:[[Ruler alloc] initWithScale:ScaleEnumInch]];
bcdFixedErrCorr.type = AztecCodeTypeFixedErrCorrection;
bcdFixedErrCorr.fixedErrCorrection = 30;
PglAztecBarcode *bcdCompact = [[PglAztecBarcode alloc] initWithStart:[[Points alloc] initWithX:0.25f y:2.25f] data:someText];
bcdCompact.cellSize = [[CellSquare alloc] initWithXDim:0.025f ruler:[[Ruler alloc] initWithScale:ScaleEnumInch]];
bcdCompact.type = AztecCodeTypeCompact;
bcdCompact.layers = 4;
PglAztecBarcode *bcdFull = [[PglAztecBarcode alloc] initWithStart:[[Points alloc] initWithX:1.5f y:2.25f] data:someText];
bcdFull.cellSize = [[CellSquare alloc] initWithXDim:0.025f ruler:[[Ruler alloc] initWithScale:ScaleEnumInch]];
bcdFull.type = AztecCodeTypeFull;
bcdFull.layers = 5;
PglAztecBarcode *bcdRuneA = [[PglAztecBarcode alloc] initWithStart:[[Points alloc] initWithX:0.25f y:4.00f] data:@"0"];
bcdRuneA.cellSize = [[CellSquare alloc] initWithXDim:0.025f ruler:[[Ruler alloc] initWithScale:ScaleEnumInch]];
bcdRuneA.type = AztecCodeTypeRune;
PglAztecBarcode *bcdRuneB = [[PglAztecBarcode alloc] initWithStart:[[Points alloc] initWithX:0.75f y:4.00f] data:@"255"];
bcdRuneB.cellSize = [[CellSquare alloc] initWithXDim:0.025f ruler:[[Ruler alloc] initWithScale:ScaleEnumInch]];
bcdRuneB.type = AztecCodeTypeRune;
PglAztecBarcode *bcdRuneC = [[PglAztecBarcode alloc] initWithStart:[[Points alloc] initWithX:1.25f y:4.00f] data:@"123"];
bcdRuneC.cellSize = [[CellSquare alloc] initWithXDim:0.025f ruler:[[Ruler alloc] initWithScale:ScaleEnumInch]];
bcdRuneC.type = AztecCodeTypeRune;
[lbl addObject:bcdDefault];
[lbl addObject:bcdFixedErrCorr];
[lbl addObject:bcdCompact];
[lbl addObject:bcdRuneB];
return lbl;
}
PglLabel *PglBcdQRCode(void) {
PglLabel *lbl = [[PglLabel alloc] initWithName:@"QRCodes"];
[Defaults SetPrinterResolution:[[PrintResolution alloc] initWithDotsPerUnit:300.0f unit:ScaleEnumInch]];
[Defaults SetRuler:[[Ruler alloc] initWithScale:ScaleEnumInch]];
NSString *enText = @"Tree in the forest";
NSString *jaText = @"森の中の木";
PglQRBarcode *english = [[PglQRBarcode alloc] initWithStart:[[Points alloc] initWithX:0.25f y:1.0f] data:enText];
english.cellSize = [[CellSquare alloc] initWithXDim:0.025f ruler:[[Ruler alloc] initWithScale:ScaleEnumInch]];
PglQRBarcode *englishMasked = [[PglQRBarcode alloc] initWithStart:[[Points alloc] initWithX:1.5f y:1.0f] data:enText];
englishMasked.cellSize = [[CellSquare alloc] initWithXDim:0.025f ruler:[[Ruler alloc] initWithScale:ScaleEnumInch]];
englishMasked.mask = QRCodeMask4;
PglQRBarcode *japanese = [[PglQRBarcode alloc] initWithStart:[[Points alloc] initWithX:0.25f y:2.25f] data:jaText];
japanese.cellSize = [[CellSquare alloc] initWithXDim:0.025f ruler:[[Ruler alloc] initWithScale:ScaleEnumInch]];
PglQRBarcode *japaneseMasked = [[PglQRBarcode alloc] initWithStart:[[Points alloc] initWithX:1.5f y:2.25f] data:jaText];
japaneseMasked.cellSize = [[CellSquare alloc] initWithXDim:0.025f ruler:[[Ruler alloc] initWithScale:ScaleEnumInch]];
japaneseMasked.mask = QRCodeMask4;
PglQRBarcode *autoEncData = [[PglQRBarcode alloc] initWithStart:[[Points alloc] initWithX:0.25f y:3.75f] data:@"12345678 TREE IN THE FOREST 森の中の木"];
autoEncData.cellSize = [[CellSquare alloc] initWithXDim:0.025f ruler:[[Ruler alloc] initWithScale:ScaleEnumInch]];
autoEncData.mask = QRCodeMask4;
NSArray *manualModeData = @[@[@(QRCodeManualEncodingNumeric), @"12345678"],
@[@(QRCodeManualEncodingAlphaNumeric), @" TREE IN THE FOREST "],
@[@(QRCodeManualEncodingBinary), @"森の中の木"]];
PglQRBarcode *manualEncData = [[PglQRBarcode alloc] initWithStart:[[Points alloc] initWithX:1.75f y:3.75f] manuallyEncodedData:manualModeData];
manualEncData.cellSize = [[CellSquare alloc] initWithXDim:0.025f ruler:[[Ruler alloc] initWithScale:ScaleEnumInch]];
manualEncData.mask = QRCodeMask4;
[lbl addObject:english];
[lbl addObject:englishMasked];
[lbl addObject:japanese];
[lbl addObject:japaneseMasked];
[lbl addObject:autoEncData];
[lbl addObject:manualEncData];
return lbl;
}
PglLabel *PglBcdDataMatrix(void) {
PglLabel *lbl = [[PglLabel alloc] initWithName:@"DMatrixBcds"];
[Defaults SetPrinterResolution:[[PrintResolution alloc] initWithDotsPerUnit:300.0f unit:ScaleEnumInch]];
[Defaults SetRuler:[[Ruler alloc] initWithScale:ScaleEnumInch]];
PglDataMatrixBarcode *dfltMatrix = [[PglDataMatrixBarcode alloc] initWithStart:[[Points alloc] initWithX:0.25f y:0.25f] data:@"Default DataMatrix"];
PglDataMatrixBarcode *rectMatrix = [[PglDataMatrixBarcode alloc] initWithStart:[[Points alloc] initWithX:1.25f y:0.25f] data:@"Rectangular DataMatrix"];
rectMatrix.rotation = RotateEnumCounterClockwise;
rectMatrix.rectangle = YES;
rectMatrix.cellSize = [[CellSquare alloc] initWithXDim:0.025f ruler:[[Ruler alloc] initWithScale:ScaleEnumInch]];
PglDataMatrixBarcode *dfltMatrixMultiLine = [[PglDataMatrixBarcode alloc] initWithStart:[[Points alloc] initWithX:2.25f y:0.25f] data:@"Line 1 DataMatrix"];
NSString *Eol = [[dfltMatrixMultiLine ctrlChar:0x0D] stringByAppendingString:[dfltMatrixMultiLine ctrlChar:0x0A]]; // CR + LF
dfltMatrixMultiLine.data = [dfltMatrixMultiLine.data stringByAppendingString:Eol];
dfltMatrixMultiLine.data = [dfltMatrixMultiLine.data stringByAppendingFormat:@"Line 2 content"];
dfltMatrixMultiLine.data = [dfltMatrixMultiLine.data stringByAppendingString:Eol];
dfltMatrixMultiLine.data = [dfltMatrixMultiLine.data stringByAppendingFormat:@"Line 3 content"];
PglDataMatrixBarcode *rectMatrixUserDefinedDimensions = [[PglDataMatrixBarcode alloc] initWithStart:[[Points alloc] initWithX:1.25f y:1.75f] data:@"DataMatrix with user defined dimensions"];
rectMatrixUserDefinedDimensions.rectangle = YES;
rectMatrixUserDefinedDimensions.rowsCols = [NSValue valueWithCGSize:CGSizeMake(16, 36)];
rectMatrixUserDefinedDimensions.cellSize = [[CellSquare alloc] initWithXDim:0.030f ruler:[[Ruler alloc] initWithScale:ScaleEnumInch]];
[lbl addObject:dfltMatrix];
[lbl addObject:rectMatrix];
[lbl addObject:dfltMatrixMultiLine];
[lbl addObject:rectMatrixUserDefinedDimensions];
return lbl;
}
PglLabel *PglBcdMaxicodes(void) {
PglLabel *lbl = [[PglLabel alloc] initWithName:@"MaxiBcds"];
PglMaxicodeMsgStructured *maxiDataStructCarrier = [[PglMaxicodeMsgStructured alloc] initWithMode:MaxicodeModeEnumMode2 postalCode:@"90255" countryCode:@"800" serviceClass:@"200" remainingMsg:@"Maxicode Carrier Standard"];
PglMaxicodeBarcode *maxicodeBarcodeSc = [[PglMaxicodeBarcode alloc] initWithStart:[[Points alloc] initWithX:0.5f y:0.5f] data:maxiDataStructCarrier];
maxicodeBarcodeSc.ruler = [[Ruler alloc] initWithScale:ScaleEnumInch];
PglMaxicodeMsgStructuredOpenSystemStandard *maxiDataOss = [[PglMaxicodeMsgStructuredOpenSystemStandard alloc] initWithMode:MaxicodeModeEnumMode3 year:@"24" postalCode:@"OHA123" countryCode:@"123" serviceClass:@"400" remainingMsg:@"Maxicode Open Standard Format"];
PglMaxicodeBarcode *maxicodeBarcodeOss = [[PglMaxicodeBarcode alloc] initWithStart:[[Points alloc] initWithX:0.5f y:2.0f] data:maxiDataOss];
maxicodeBarcodeOss.ruler = [[Ruler alloc] initWithScale:ScaleEnumInch];
PglMaxicodeMsg *maxiData = [[PglMaxicodeMsg alloc] initWithMode:MaxicodeModeEnumMode4 primaryMsg:@"123456789" remainingMsg:@"Maxicode unstructured"];
PglMaxicodeBarcode *maxicodeBarcode = [[PglMaxicodeBarcode alloc] initWithStart:[[Points alloc] initWithX:0.5f y:3.5f] data:maxiData];
maxicodeBarcode.ruler = [[Ruler alloc] initWithScale:ScaleEnumInch];
[lbl addObject:maxicodeBarcodeSc];
[lbl addObject:maxicodeBarcodeOss];
[lbl addObject:maxicodeBarcode];
return lbl;
}
PglLabel *PglSimpleLabel(NSString *name, NSString *address) {
PglLabel *lbl = [[PglLabel alloc] initWithName:@"SimpleLabel"];
Ruler *inchRuler = [[Ruler alloc] initWithScale:ScaleEnumInch];
Ruler *mmRuler = [[Ruler alloc] initWithScale:ScaleEnumMM];
_PglLine *line1 =[[_PglLine alloc] initWithStart:[[Points alloc] initWithX:2.5f y:1.0f/16.0f]
end:[[Points alloc] initWithX:2.5f y:1.0f]
lineThickness:1.0f/32.0f];
line1.ruler = inchRuler;
[lbl addObject:line1];
_PglLine *line2 = [[_PglLine alloc] initWithStart:[[Points alloc] initWithX:0.12f y:1.0f]
end:[[Points alloc] initWithX:3.88f y:1.0f]
lineThickness:1.0f/32.0f];
line2.ruler = inchRuler;
[lbl addObject:line2];
_PglLine *line3 = [[_PglLine alloc] initWithStart:[[Points alloc] initWithX:0.12f y:3.5f]
end:[[Points alloc] initWithX:3.88f y:3.5f]
lineThickness:1.0f/32.0f];
line3.ruler = inchRuler;
[lbl addObject:line3];
_PglBox *box1 = [[_PglBox alloc] initWithStart:[[Points alloc] initWithX:0.5f y:1.25f]
end:[[Points alloc] initWithX:3.5f y:2.25f]
lineThickness:1.0f/16.0f];
box1.ruler = inchRuler;
[lbl addObject:box1];
_PglText *productText = [[_PglText alloc] init];
productText.fontSizeUnits = FontSizeUnitsRuler;
productText.ruler = inchRuler;
productText.alignment = AlignEnumCenter;
productText.fontName = @"93952.sf";
TextItem *textItem1 = [[TextItem alloc] initWithStart:[[Points alloc] initWithX:2.0f y:1.25f + 7.0 / 16.0f] data:@"MY MAGIC"];
textItem1.fontSize = [[FontSize alloc] initWithX:3.0 / 16.0f y:7.0 / 16.0f];
[productText.text addObject:textItem1];
TextItem *textItem2 = [[TextItem alloc] initWithStart:[[Points alloc] initWithX:2.0f y:1.25f + 1.0f - 3.0 / 16.0f] data:@"PRODUCT"];
textItem2.fontSize = [[FontSize alloc] initWithX:3.0 / 16.0f y:7.0 / 16.0f];
[productText.text addObject:textItem2];
[lbl addObject:productText];
_PglText *boldToFrom = [[_PglText alloc] init];
boldToFrom.fontSizeUnits = FontSizeUnitsRuler;
boldToFrom.ruler = mmRuler;
boldToFrom.fontStyle = FontStyleBold;
boldToFrom.fontName = @"92248.sf";
TextItem *bold_textItem1 = [[TextItem alloc] initWithStart:[[Points alloc] initWithX:5.0f y:5.0f] data:@"TO:"];
bold_textItem1.fontSize = [[FontSize alloc] initWithX:2.5f y:5.0f];
[boldToFrom.text addObject:bold_textItem1];
TextItem *bold_textItem2 = [[TextItem alloc] initWithStart:[[Points alloc] initWithX:(2.5f + 1 / 16.0f) * 25.4f y:5.0f] data:@"FROM:"];
[boldToFrom.text addObject:bold_textItem2];
[lbl addObject:boldToFrom];
_PglText *companyName = [[_PglText alloc] init];
companyName.fontSizeUnits = FontSizeUnitsPercent;
companyName.ruler = mmRuler;
companyName.fontStyle = FontStyleItalic;
companyName.fontName = @"92500.sf";
TextItem *companyName_textItem = [[TextItem alloc] initWithStart:[[Points alloc] initWithX:(2.5f + 1 / 16.0f + 1 / 8.0f) * 25.4f y:17.0f] data:@"Happy Inc."];
companyName_textItem.fontSize = [[FontSize alloc] initWithX:2.0f y:3.0f];
[companyName.text addObject:companyName_textItem];
[lbl addObject:companyName];
_PglText *nameTxt = [[_PglText alloc] init];
nameTxt.fontSizeUnits = FontSizeUnitsRuler;
nameTxt.ruler = mmRuler;
nameTxt.fontStyle = FontStyleItalic;
TextItem *nameTextItem = [[TextItem alloc] initWithStart:[[Points alloc] initWithX:8.0f y:10.0f] data:name];
nameTextItem.fontSize = [[FontSize alloc] initWithX:2.5f y:5.0f];
[nameTxt.text addObject:nameTextItem];
[lbl addObject:nameTxt];
// Add address in normal text
_PglText *addressTxt = [[_PglText alloc] init];
addressTxt.ruler = mmRuler;
TextItem *addressTextItem = [[TextItem alloc] initWithStart:[[Points alloc] initWithX:8.0f y:17.0f] data:address];
[addressTxt.text addObject:addressTextItem];
[lbl addObject:addressTxt];
// ======= Add some barcodes to bottom
// Code 128: 15 mil X-Dim
PglBarcode_1D *bcd128 = [[PglBarcode_1D alloc] initWithBarcodeItem:[[BarcodeItem alloc] initWithStart:[[Points alloc] initWithX:0.5f y:1.5f + 1 / 4.0f + 1.2f] height:1.2f data:@"Code 128"]];
bcd128.barcodeType = BarcodeTypeEnum1DCode128;
bcd128.printHumanReadable = YES;
bcd128.rotation = RotateEnumNone;
bcd128.ruler = inchRuler;
bcd128.barWidths = [[PglBarWidths alloc] initWithNarrowBar:0.015f wideBar:0.015f * 4.1f ];
bcd128.barWidths.ruler = inchRuler;
[lbl addObject:bcd128];
// Code 93: 25 mil X-Dim
PglBarcode_1D *bcd93 = [[PglBarcode_1D alloc] initWithBarcodeItem:[[BarcodeItem alloc] initWithStart:[[Points alloc] initWithX:0.5f y:3.5f - 1 / 8.0f - 0.6f] height:0.6f data:@"CODE 93"]];
bcd93.barcodeType = BarcodeTypeEnum1DCode93;
bcd93.printHumanReadable = YES;
bcd93.rotation = RotateEnumNone;
bcd93.ruler = inchRuler;
bcd93.barWidths = [[PglBarWidths alloc] initWithNarrowBar:0.025f wideBar:0.025f * 4.1f ];
bcd93.barWidths.ruler = inchRuler;
[lbl addObject:bcd93];
// Datamatrix 40 mil barcode with customer name/address
PglDataMatrixBarcode *dmCustomer = [[PglDataMatrixBarcode alloc] initWithStart:[[Points alloc] initWithX:2.7f y:4.0f] data:name];
dmCustomer.cellSize = [[CellSquare alloc] initWithXDim:0.040f ruler:inchRuler];
dmCustomer.ruler = inchRuler;
NSString *Eol = [[dmCustomer ctrlChar:0x0D] stringByAppendingString:[dmCustomer ctrlChar:0x0A]]; // CR + LF
dmCustomer.data = [dmCustomer.data stringByAppendingFormat:@"%@%@", Eol, address];
[lbl addObject:dmCustomer];
return lbl;
}
NSArray<_PglLine *> *RulerLines(float length, BOOL vertical, BOOL inchUnits, float margin) {
NSMutableArray<_PglLine *> *rulerLines = [NSMutableArray array];
Ruler *tickRuler = inchUnits ? [[Ruler alloc] initWithScale:ScaleEnumInch] : [[Ruler alloc] initWithScale:ScaleEnumMM];
float rulerLength = length;
float tickThickness = 0.010f;
float tickLength = 1 / 16.0f;
float ticksPerUnit = inchUnits ? 16.0f : 1.0f;
if (!inchUnits) {
tickThickness *= MM_PER_INCH;
tickLength *= MM_PER_INCH;
margin *= MM_PER_INCH;
}
rulerLength -= tickThickness;
for (float i = 1; i <= (rulerLength * ticksPerUnit); i++) {
float tick = tickLength;
if (inchUnits) {
if ((int)i % 16 == 0) {
tick *= 3.5f;
} else if ((int)i % 8 == 0) {
tick *= 2.5f;
} else if ((int)i % 4 == 0) {
tick *= 2.0f;
} else if ((int)i % 2 == 0) {
tick *= 1.5f;
}
} else {
if ((int)i % 10 == 0) {
tick *= 3.0f;
} else if ((int)i % 5 == 0) {
tick *= 1.5f;
}
}
_PglLine *tickLine;
if (vertical) {
tickLine = [[_PglLine alloc] initWithXStart:margin
yStart:i / ticksPerUnit
xEnd:margin + tick
yEnd:i / ticksPerUnit
lineThickness:tickThickness];
} else {
tickLine = [[_PglLine alloc] initWithXStart:i / ticksPerUnit
yStart:margin
xEnd:i / ticksPerUnit
yEnd:margin + tick
lineThickness:tickThickness];
}
tickLine.ruler = tickRuler;
[rulerLines addObject:tickLine];
}
return rulerLines;
}
PglLabel *RuleredLabel(float width, float length, BOOL inchUnits, float rulerMargin) {
NSArray<_PglLine *> *verRulerTicks = RulerLines(length, YES, inchUnits, rulerMargin);
NSArray<_PglLine *> *horRulerTicks = RulerLines(width, NO, inchUnits, rulerMargin);
[Defaults SetPrinterResolution:[[PrintResolution alloc] initWithDotsPerUnit:300.0f unit:ScaleEnumInch]];
PglLabel *rulerLbl = [[PglLabel alloc] initWithName:@"Ruler"];
for (_PglLine *tickLine in verRulerTicks) {
[rulerLbl addObject:tickLine];
}
for (_PglLine *tickLine in horRulerTicks) {
[rulerLbl addObject:tickLine];
}
return rulerLbl;
}
@end
A class representing a box shape for TSPL.
Definition _Box.h:44
id< IRuler > ruler
The ruler used to measure the box.
Definition _Box.h:56
A class representing a line object for TSPL.
Definition _Line.h:45
A class representing a box shape.
Definition _PglBox.h:45
id< IRuler > ruler
The ruler used to measure the box.
Definition _PglBox.h:57
A class representing a line shape.
Definition _PglLine.h:46
A class representing a text object.
Definition _PglText.h:47
AztecCodeTypeEnum type
The type of the Aztec barcode.
Definition AAztecBarcode.h:57
int layers
The number of layers to use for AztecCodeTypeEnum.Compact or AztecCodeTypeEnum.Full barcode types.
Definition AAztecBarcode.h:87
id< ICellSquare > cellSize
The cell size for the barcode.
Definition AAztecBarcode.h:45
int fixedErrCorrection
This percent error correction value only applies to AztecCodeTypeEnum.FixedErrCorrection.
Definition AAztecBarcode.h:105
id< IBarWidths > barWidths
Definition ABarcode1D.h:36
RotateEnum rotation
Definition ABarcode1D.h:38
BOOL printHumanReadable
Definition ABarcode1D.h:37
BarcodeTypeEnum1D barcodeType
Definition ABarcode1D.h:34
id< IRuler > ruler
Definition ABarcode1D.h:35
RotateEnum rotation
Definition ABarcode2D.h:36
id< IRuler > ruler
Definition ABarcode2D.h:33
id< ICellSquare > cellSize
Definition ADataMatrix.h:36
NSString * data
Definition ADataMatrix.h:34
NSString * ctrlChar:(int decimalCharValue)
Gets a string that represents non-printable control character in 0-31 range.
NSValue * rowsCols
Specify the number of cells in terms of rows and columns of the barcode if want to manually set the b...
Definition ADataMatrix.h:90
BOOL rectangle
Sets the shape for barcode to be rectangular shape, otherwise default square shape is used.
Definition ADataMatrix.h:48
id< IRuler > ruler
The ruler used for placement. If not set, the default ruler setting is used.
Definition ALine.h:46
id< IRuler > ruler
Definition AMaxicodeBarcode.h:37
int rows
The number of rows can be used to limit the height of the barcode.
Definition APdf417.h:110
Pdf417ErrCorrectionEnum errorCorrection
Error correction level for the PDF417 barcode.
Definition APdf417.h:86
int columns
The number of columns can be used to limit the width of the barcode.
Definition APdf417.h:140
id< ICellRect > cellSize
The cell size can be thought of as the width and height of the narrowest bar element within a PDF417 ...
Definition APdf417.h:74
QRCodeMaskEnum mask
Mask used in the QR code generation.
Definition AQRBarcode.h:106
id< ICellSquare > cellSize
Size of the cells that make up the QR code.
Definition AQRBarcode.h:142
int offsetFromStart
Definition ARfidWrite.h:39
AlignEnum alignment
Definition AText.h:36
FontStyleEnum fontStyle
Definition AText.h:34
NSString * fontName
Definition AText.h:33
id< IRuler > ruler
Definition AText.h:32
FontSizeUnitsEnum fontSizeUnits
Definition AText.h:35
id< IFontSize > fontSize
Definition ATextItem.h:31
A class representing an Aztec barcode for TSPL.
Definition AztecBarcode.h:45
A class representing the widths of bars in barcodes for TSPL.
Definition BarWidths.h:44
A class representing a 1D barcode for TSPL.
Definition Barcode_1D.h:45
A class for BarcodeItem, inheriting from ABarcodeItem class.
Definition BarcodeItem.h:33
A class for CellRect, conforming to the ICellRect protocol.
Definition CellRect.h:31
A class for CellSquare, inheriting from ACellSquare class.
Definition CellSquare.h:31
A class representing a Data Matrix barcode for TSPL.
Definition DataMatrixBarcode.h:47
The defaults used for settings if not specified during object creation or set/changed.
Definition Defaults.h:38
void SetRuler:(id< IRuler > ruler)
void SetPrinterResolution:(id< IPrintResolution > printerResolution)
Font size in the X and Y direction allows for stretching/resizing when non-default font size is desir...
Definition FontSize.h:38
A class representing a label for TSPL.
Definition Label.h:42
NSString * description()
Returns a string that can be sent to the printer.
void addObject:(id addObject)
Adds an object that can be converted to printer language syntax to the label.
A class representing a Maxicode barcode for TSPL.
Definition MaxicodeBarcode.h:45
A class representing a Maxicode message for TSPL.
Definition MaxicodeMsg.h:40
A class representing a structured Maxicode message for TSPL.
Definition MaxicodeMsgStructured.h:41
A class representing a PDF417 barcode for TSPL.
Definition Pdf417Barcode.h:41
A class representing an Aztec barcode.
Definition PglAztecBarcode.h:47
A class representing the widths of bars in barcodes.
Definition PglBarWidths.h:44
A class representing a 1D barcode.
Definition PglBarcode_1D.h:42
A class representing a Data Matrix barcode.
Definition PglDataMatrixBarcode.h:46
A class representing a label that can be converted to printer language syntax.
Definition PglLabel.h:41
NSString * description()
Returns a string that can be sent to the printer.
void addObject:(id addObject)
Adds an object that can be converted to printer language syntax to the label.
A class representing a Maxicode barcode.
Definition PglMaxicodeBarcode.h:43
A class representing a Maxicode message.
Definition PglMaxicodeMsg.h:41
A class representing a structured Maxicode message.
Definition PglMaxicodeMsgStructured.h:41
A class representing a Maxicode message structured according to the Open System Standard.
Definition PglMaxicodeMsgStructuredOpenSystemStandard.h:41
A class representing a PDF417 barcode.
Definition PglPdf417Barcode.h:42
A class representing a QR code barcode.
Definition PglQRBarcode.h:42
A class representing an RFID write operation.
Definition PglRfid_Write.h:42
A class for Points, inheriting from IPoint.
Definition Point.h:38
A class for PrintResolution, inheriting from IPrintResolution.
Definition PrintResolution.h:37
A class representing a QR code barcode for TSPL.
Definition QRBarcode.h:48
A class representing an RFID write operation for TSPL.
Definition Rfid_Write.h:45
Support methods to help convert non-byte data to order stored in RFID tags.
Definition RfidConvert.h:41
NSString * toHexFromUShort:(uint16_t ushortData)
Convert a 2 byte unsigned integer into hex string that can be written on RFID tag.
NSString * toHexFromUInt:(uint32_t uintData)
Convert a 4 byte unsigned integer into hex string that can be written on RFID tag.
NSString * toHexFromBytes:(NSData *bytes)
Convenience routine that takes and array of bytes and converts to hex string that can be written to R...
NSString * toHexFromASCIIString:(NSString *asciiString)
Convenience routine that takes an ASCII string and converts to hex.
A class for Ruler, inheriting from IRuler.
Definition Ruler.h:36
A class for TextItem, inheriting from ITextItem.
Definition TextItem.h:34

Swift:

import SwiftUI
import UniPRT
struct ContentView: View {
@State private var resultText: String = ""
let buttonTitles = ["Pdf417", "SimpleLabel", "RfidEncode", "Maxicodes", "DataMatrix", "Aztec", "QRCode", "PglPdf417", "PglSimpleLabel", "PglRfidEncode", "PglMaxicodes", "PglDataMatrix", "PglAztec", "PglQRCode", "PglRulerLabel"]
var body: some View {
VStack {
ScrollView {
LazyVGrid(columns: [GridItem(.flexible()), GridItem(.flexible()), GridItem(.flexible())], spacing: 10) {
ForEach(buttonTitles.indices, id: \.self) { index in
Button(action: {
buttonTapped(index)
}) {
Text(buttonTitles[index])
.frame(width: UIScreen.main.bounds.width / 3 - 20, height: 50)
.background(Color.gray)
.foregroundColor(.white)
.cornerRadius(5)
}
}
}
}
.padding(.top, 100)
TextEditor(text: $resultText)
.frame(height: 450)
.background(Color.accentColor)
.cornerRadius(5)
.padding(.horizontal, 20)
}
.background(Color.white)
.edgesIgnoringSafeArea(.all)
}
func buttonTapped(_ index: Int) {
var result: UniPRT.Label?
var pglResult: PglLabel?
switch index {
case 0:
result = BcdPdf417()
case 1:
result = SimpleTextLabel(name: "Mr. Milky Cheese", address: "123 No Way Road")
case 2:
result = RfidEncode()
case 3:
result = BcdMaxicodes()
case 4:
result = BcdDataMatrix()
case 5:
result = BcdAztec()
case 6:
result = BcdQRCode()
case 7:
pglResult = PglBcdPdf417()
case 8:
pglResult = PglSimpleLabel(name: "Mr. Milky Cheese", address: "123 No Way Road")
case 9:
pglResult = PglRfidEncode()
case 10:
pglResult = PglBcdMaxicodes()
case 11:
pglResult = PglBcdDataMatrix()
case 12:
pglResult = PglBcdAztec()
case 13:
pglResult = PglBcdQRCode()
case 14:
pglResult = RuleredLabel(width: 4.0, length: 6.0, inchUnits: true, rulerMargin: 1.0 / 8.0)
default:
break
}
if let result = result {
resultText = result.description
} else if let pglResult = pglResult {
resultText = pglResult.description
} else {
resultText = ""
}
}
// Add your label generating functions here, translated from Objective-C to Swift
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
func BcdPdf417() -> UniPRT.Label? {
Defaults.setPrinterResolution(PrintResolution(dotsPerUnit: 300, unit: .inch))
Defaults.setRuler(Ruler(scale: .inch))
let lbl = Label(name: "Pdf417Bcodes")
let someText = "The happiness in your life depends on the quality of your thoughts. --Marcus Aurelius"
let someShortText = "PI = 3.1415"
let bcdDefault = Pdf417Barcode(start: Points(x: 0.25, y: 0.50), data: someText)
bcdDefault?.cellSize = CellRect(xDim: 0.015, yDim: 0.050, ruler: Ruler(scale: .inch))
let bcdErrCorrectionLvl0 = Pdf417Barcode(start: Points(x: 0.25, y: 1.50), data: someShortText)
bcdErrCorrectionLvl0?.cellSize = CellRect(xDim: 0.015, yDim: 0.050, ruler: Ruler(scale: .inch))
bcdErrCorrectionLvl0?.errorCorrection = .level0
let bcdErrCorrectionLvl5 = Pdf417Barcode(start: Points(x: 0.25, y: 2.00), data: someShortText)
bcdErrCorrectionLvl5?.cellSize = CellRect(xDim: 0.015, yDim: 0.050, ruler: Ruler(scale: .inch))
bcdErrCorrectionLvl5?.errorCorrection = .level5
let bcdRowsLimited = Pdf417Barcode(start: Points(x: 0.25, y: 3.00), data: someShortText)
bcdRowsLimited?.cellSize = CellRect(xDim: 0.015, yDim: 0.050, ruler: Ruler(scale: .inch))
bcdRowsLimited?.rows = 15
let bcdColsLimited = Pdf417Barcode(start: Points(x: 0.25, y: 4.00), data: someShortText)
bcdColsLimited?.cellSize = CellRect(xDim: 0.015, yDim: 0.050, ruler: Ruler(scale: .inch))
bcdColsLimited?.columns = 5
lbl!.add(bcdDefault)
lbl!.add(bcdErrCorrectionLvl0)
lbl!.add(bcdErrCorrectionLvl5)
lbl!.add(bcdRowsLimited)
lbl!.add(bcdColsLimited)
return lbl!
}
func SimpleTextLabel(name: String, address: String) -> UniPRT.Label? {
Defaults.setPrinterResolution(PrintResolution(dotsPerUnit: 600, unit: .inch))
let lbl = Label(name: "SimpleLabel")
let inchRuler = Ruler(scale: .inch)
let line1 = _Line(start: Points(x: 2.5, y: 1.0 / 16.0), end: Points(x: 2.5, y: 1.0), lineThickness: 1.0 / 32.0)
line1!.ruler = inchRuler
lbl!.add(line1)
let line2 = _Line(start: Points(x: 0.12, y: 1.0), end: Points(x: 3.88, y: 1.0), lineThickness: 1.0 / 32.0)
line2!.ruler = inchRuler
lbl!.add(line2)
let line3 = _Line(start: Points(x: 0.12, y: 3.5), end: Points(x: 3.88, y: 3.5), lineThickness: 1.0 / 32.0)
line3!.ruler = inchRuler
lbl!.add(line3)
let line4 = _Box(start: Points(x: 0.5, y: 1.25), end: Points(x: 3.5, y: 2.25), lineThickness: 1.0 / 16.0)
line4!.ruler = inchRuler
lbl!.add(line4)
let barcodeItem128 = BarcodeItem(start: Points(x: 0.5, y: 1.0 + 1.5 + 1.0 / 4.0 + 1.2), height: 1.2, data: "Code 128")
let bcd128 = Barcode_1D(barcodeItem: barcodeItem128)
bcd128!.barcodeType = .dCode128
bcd128!.printHumanReadable = true
bcd128!.rotation = .none
bcd128!.ruler = inchRuler
bcd128!.barWidths = BarWidths(narrowBar: 0.015, wideBar: 0.015)
bcd128!.barWidths?.ruler = Ruler(scale: .inch)
lbl!.add(bcd128)
let barcodeItem93 = BarcodeItem(start: Points(x: 0.5, y: 3.5 - 1.0 / 8.0 - 0.6), height: 0.6, data: "CODE 93")
let bcd93 = Barcode_1D(barcodeItem: barcodeItem93)
bcd93!.barcodeType = .dCode93
bcd93!.printHumanReadable = true
bcd93!.rotation = .none
bcd93!.ruler = inchRuler
bcd93!.barWidths = BarWidths(narrowBar: 0.025, wideBar: 0.025 * 3)
bcd93!.barWidths?.ruler = Ruler(scale: .inch)
lbl!.add(bcd93)
return lbl!
}
func RfidEncode() -> UniPRT.Label? {
let lbl = Label(name: "Rfidlbl!")
let a32BitField: UInt32 = 0x11223344
let a16BitField: UInt16 = 0xBEEF
let a6CharAsciiString = "MyData"
var epcHexData = RfidConvert.toHex(from: a32BitField)
epcHexData! += RfidConvert.toHex(fromBytes: a6CharAsciiString.data(using: .ascii)!)
epcHexData! += RfidConvert.toHex(fromUShort: a16BitField)
let epc = Rfid_Write(memBlock: .EPC, data: epcHexData)
lbl!.add(epc)
var userHexData = RfidConvert.toHex(fromASCIIString: "MyUserData")
userHexData! += "0ABCDE0F"
let userMem = Rfid_Write(memBlock: .user, data: userHexData)
userMem!.offsetFromStart = 2
lbl!.add(userMem)
return lbl!
}
func BcdMaxicodes() -> UniPRT.Label? {
Defaults.setPrinterResolution(PrintResolution(dotsPerUnit: 203, unit: .inch))
let lbl = Label(name: "MaxiBcds")
let maxiDataStructCarrier = MaxicodeMsgStructured(mode: .mode2, postalCode: "902557317", countryCode: "800", serviceClass: "200", remainingMsg: "Maxicode Carrier Standard")
let maxicodeBarcodeSc = MaxicodeBarcode(start: Points(x: 0.5, y: 0.5), data: maxiDataStructCarrier)
maxicodeBarcodeSc!.ruler = Ruler(scale: .inch)
let maxiData = MaxicodeMsg(mode: .mode4, primaryMsg: "123456789", remainingMsg: "Maxicode unstructured")
let maxicodeBarcode = MaxicodeBarcode(start: Points(x: 0.5, y: 3.5), data: maxiData)
maxicodeBarcode!.ruler = Ruler(scale: .inch)
lbl!.add(maxicodeBarcodeSc)
lbl!.add(maxicodeBarcode)
return lbl!
}
func BcdDataMatrix() -> UniPRT.Label? {
Defaults.setPrinterResolution(PrintResolution(dotsPerUnit: 600, unit: .inch))
Defaults.setRuler(Ruler(scale: .inch))
let lbl = Label(name: "DMatrixBcds")
let dfltMatrix = DataMatrixBarcode(start: Points(x: 0.25, y: 0.25), data: "Default DataMatrix")
let rectMatrix = DataMatrixBarcode(start: Points(x: 1.25, y: 0.25), data: "Rectangular DataMatrix")
rectMatrix!.rotation = .counterClockwise
rectMatrix!.rectangle = true
rectMatrix!.cellSize = CellSquare(xDim: 0.025, ruler: Ruler(scale: .inch))
let dfltMatrixMultiLine = DataMatrixBarcode(start: Points(x: 2.25, y: 0.25), data: "Line 1 DataMatrix")
let Eol = dfltMatrixMultiLine!.ctrlChar(0x0D) + dfltMatrixMultiLine!.ctrlChar(0x0A) // CR + LF
dfltMatrixMultiLine!.data += Eol + "Line 2 content" + Eol + "Line 3 content"
let rectMatrixUserDefinedDimensions = DataMatrixBarcode(start: Points(x: 1.25, y: 1.75), data: "DataMatrix with user defined dimensions")
rectMatrixUserDefinedDimensions!.rectangle = true
rectMatrixUserDefinedDimensions!.rowsCols = CGSize(width: 16, height: 36) as NSValue
rectMatrixUserDefinedDimensions!.cellSize = CellSquare(xDim: 0.030, ruler: Ruler(scale: .inch))
lbl!.add(dfltMatrix)
lbl!.add(rectMatrix)
lbl!.add(dfltMatrixMultiLine)
lbl!.add(rectMatrixUserDefinedDimensions)
return lbl!
}
func BcdAztec() -> UniPRT.Label? {
Defaults.setPrinterResolution(PrintResolution(dotsPerUnit: 300, unit: .inch))
Defaults.setRuler(Ruler(scale: .inch))
let lbl = Label(name: "AztecBcodes")
let someText = "Mr. AirTraveler, seat A, flight 200"
let bcdDefault = AztecBarcode(start: Points(x: 0.25, y: 1.0), data: someText)
bcdDefault!.cellSize = CellSquare(xDim: 0.025, ruler: Ruler(scale: .inch))
let bcdFixedErrCorr = AztecBarcode(start: Points(x: 1.5, y: 1.0), data: someText)
bcdFixedErrCorr!.cellSize = CellSquare(xDim: 0.025, ruler: Ruler(scale: .inch))
bcdFixedErrCorr!.type = .fixedErrCorrection
bcdFixedErrCorr!.fixedErrCorrection = 30
let bcdCompact = AztecBarcode(start: Points(x: 0.25, y: 2.25), data: someText)
bcdCompact!.cellSize = CellSquare(xDim: 0.025, ruler: Ruler(scale: .inch))
bcdCompact!.type = .compact
bcdCompact!.layers = 4
let bcdFull = AztecBarcode(start: Points(x: 1.5, y: 2.25), data: someText)
bcdFull!.cellSize = CellSquare(xDim: 0.025, ruler: Ruler(scale: .inch))
bcdFull!.type = .full
bcdFull!.layers = 5
let bcdRuneA = AztecBarcode(start: Points(x: 0.25, y: 4.00), data: "0")
bcdRuneA!.cellSize = CellSquare(xDim: 0.025, ruler: Ruler(scale: .inch))
bcdRuneA!.type = .rune
let bcdRuneB = AztecBarcode(start: Points(x: 0.75, y: 4.00), data: "255")
bcdRuneB!.cellSize = CellSquare(xDim: 0.025, ruler: Ruler(scale: .inch))
bcdRuneB!.type = .rune
let bcdRuneC = AztecBarcode(start: Points(x: 1.25, y: 4.00), data: "123")
bcdRuneC!.cellSize = CellSquare(xDim: 0.025, ruler: Ruler(scale: .inch))
bcdRuneC!.type = .rune
lbl!.add(bcdDefault)
lbl!.add(bcdFixedErrCorr)
lbl!.add(bcdCompact)
lbl!.add(bcdFull)
lbl!.add(bcdRuneA)
lbl!.add(bcdRuneB)
lbl!.add(bcdRuneC)
return lbl!
}
func BcdQRCode() -> UniPRT.Label? {
Defaults.setPrinterResolution(PrintResolution(dotsPerUnit: 300, unit: .inch))
Defaults.setRuler(Ruler(scale: .inch))
let lbl = Label(name: "QRCodes")
let enText = "Tree in the forest"
let jaText = "森の中の木"
let english = QRBarcode(start: Points(x: 0.25, y: 1.0), data: enText)
english!.cellSize = CellSquare(xDim: 0.025, ruler: Ruler(scale: .inch))
let englishMasked = QRBarcode(start: Points(x: 1.5, y: 1.0), data: enText)
englishMasked!.cellSize = CellSquare(xDim: 0.025, ruler: Ruler(scale: .inch))
englishMasked!.mask = .mask4
let japanese = QRBarcode(start: Points(x: 0.25, y: 2.25), data: jaText)
japanese!.cellSize = CellSquare(xDim: 0.025, ruler: Ruler(scale: .inch))
japanese!.mask = .mask1
let japaneseMasked = QRBarcode(start: Points(x: 1.5, y: 2.25), data: jaText)
japaneseMasked!.cellSize = CellSquare(xDim: 0.025, ruler: Ruler(scale: .inch))
japaneseMasked!.mask = .mask4
let autoEncData = QRBarcode(start: Points(x: 0.25, y: 3.75), data: "12345678 TREE IN THE FOREST 森の中の木")
autoEncData!.cellSize = CellSquare(xDim: 0.025, ruler: Ruler(scale: .inch))
autoEncData!.mask = .mask4
let manualModeData: [[Any]] = [
[NSNumber(value: QRCodeManualEncodingEnum.numeric.rawValue), "12345678"],
[NSNumber(value: QRCodeManualEncodingEnum.alphaNumeric.rawValue), " TREE IN THE FOREST "],
[NSNumber(value: QRCodeManualEncodingEnum.binary.rawValue), "森の中の木"]
]
let manualEncData = QRBarcode(start: Points(x: 1.75, y: 3.75), manuallyEncodedData: manualModeData)
manualEncData!.cellSize = CellSquare(xDim: 0.025, ruler: Ruler(scale: .inch))
manualEncData!.mask = .mask4
lbl!.add(english)
lbl!.add(englishMasked)
lbl!.add(japanese)
lbl!.add(japaneseMasked)
lbl!.add(autoEncData)
lbl!.add(manualEncData)
return lbl!
}
//PGL Functions
func PglRfidEncode() -> PglLabel {
let lbl = PglLabel(name: "Rfidlbl!")
let a32BitField: UInt32 = 0x11223344
let a16BitField: UInt16 = 0xBEEF
let a6CharAsciiString = "MyData"
var epcHexData = String(format: "%08X", a32BitField) + stringToHex(a6CharAsciiString)
epcHexData += String(format: "%04X", a16BitField)
let epc = PglRfid_Write(memBlock: .EPC, data: epcHexData)
lbl!.add(epc)
var userDataHex = stringToHex("MyUserData")
userDataHex += "0ABCDE0F"
let userMem = PglRfid_Write(memBlock: .user, data: userDataHex)
userMem!.offsetFromStart = 2
lbl!.add(userMem)
return lbl!
}
func PglBcdPdf417() -> PglLabel {
Defaults.setPrinterResolution(PrintResolution(dotsPerUnit: 600, unit: .inch))
Defaults.setRuler(Ruler(scale: .inch))
let lbl = PglLabel(name: "Pdf417Bcodes")
let someText = "The happiness in your life depends on the quality of your thoughts. --Marcus Aurelius"
let someShortText = "PI = 3.1415"
let bcdDefault = PglPdf417Barcode(start: Points(x: 0.25, y: 0.50), data: someText)
bcdDefault!.cellSize = CellRect(xDim: 0.015, yDim: 0.050, ruler: Ruler(scale: .inch))
let bcdErrCorrectionLvl0 = PglPdf417Barcode(start: Points(x: 0.25, y: 1.50), data: someShortText)
bcdErrCorrectionLvl0!.cellSize = CellRect(xDim: 0.015, yDim: 0.050, ruler: Ruler(scale: .inch))
bcdErrCorrectionLvl0!.errorCorrection = .level0
let bcdErrCorrectionLvl5 = PglPdf417Barcode(start: Points(x: 0.25, y: 2.00), data: someShortText)
bcdErrCorrectionLvl5!.cellSize = CellRect(xDim: 0.015, yDim: 0.050, ruler: Ruler(scale: .inch))
bcdErrCorrectionLvl5!.errorCorrection = .level5
let bcdRowsLimited = PglPdf417Barcode(start: Points(x: 0.25, y: 3.00), data: someShortText)
bcdRowsLimited!.cellSize = CellRect(xDim: 0.015, yDim: 0.050, ruler: Ruler(scale: .inch))
bcdRowsLimited!.rows = 15
let bcdColsLimited = PglPdf417Barcode(start: Points(x: 0.25, y: 4.00), data: someShortText)
bcdColsLimited!.cellSize = CellRect(xDim: 0.015, yDim: 0.050, ruler: Ruler(scale: .inch))
bcdColsLimited!.columns = 5
lbl!.add(bcdDefault)
lbl!.add(bcdErrCorrectionLvl0)
lbl!.add(bcdErrCorrectionLvl5)
lbl!.add(bcdRowsLimited)
lbl!.add(bcdColsLimited)
return lbl!
}
func PglBcdAztec() -> PglLabel {
Defaults.setPrinterResolution(PrintResolution(dotsPerUnit: 300, unit: .inch))
Defaults.setRuler(Ruler(scale: .inch))
let lbl = PglLabel(name: "AztecBcodes")
let someText = "Mr. AirTraveler, seat A, flight 200"
let bcdDefault = PglAztecBarcode(start: Points(x: 0.25, y: 1.0), data: someText)
bcdDefault!.cellSize = CellSquare(xDim: 0.025, ruler: Ruler(scale: .inch))
let bcdFixedErrCorr = PglAztecBarcode(start: Points(x: 1.5, y: 1.0), data: someText)
bcdFixedErrCorr!.cellSize = CellSquare(xDim: 0.025, ruler: Ruler(scale: .inch))
bcdFixedErrCorr!.type = .fixedErrCorrection
bcdFixedErrCorr!.fixedErrCorrection = 30
let bcdCompact = PglAztecBarcode(start: Points(x: 0.25, y: 2.25), data: someText)
bcdCompact!.cellSize = CellSquare(xDim: 0.025, ruler: Ruler(scale: .inch))
bcdCompact!.type = .compact
bcdCompact!.layers = 4
let bcdFull = PglAztecBarcode(start: Points(x: 1.5, y: 2.25), data: someText)
bcdFull!.cellSize = CellSquare(xDim: 0.025, ruler: Ruler(scale: .inch))
bcdFull!.type = .full
bcdFull!.layers = 5
let bcdRuneA = PglAztecBarcode(start: Points(x: 0.25, y: 4.00), data: "0")
bcdRuneA!.cellSize = CellSquare(xDim: 0.025, ruler: Ruler(scale: .inch))
bcdRuneA!.type = .rune
let bcdRuneB = PglAztecBarcode(start: Points(x: 0.75, y: 4.00), data: "255")
bcdRuneB!.cellSize = CellSquare(xDim: 0.025, ruler: Ruler(scale: .inch))
bcdRuneB!.type = .rune
let bcdRuneC = PglAztecBarcode(start: Points(x: 1.25, y: 4.00), data: "123")
bcdRuneC!.cellSize = CellSquare(xDim: 0.025, ruler: Ruler(scale: .inch))
bcdRuneC!.type = .rune
lbl!.add(bcdDefault)
lbl!.add(bcdFixedErrCorr)
lbl!.add(bcdCompact)
lbl!.add(bcdFull)
lbl!.add(bcdRuneA)
lbl!.add(bcdRuneB)
lbl!.add(bcdRuneC)
return lbl!
}
func PglBcdQRCode() -> PglLabel {
Defaults.setPrinterResolution(PrintResolution(dotsPerUnit: 300, unit: .inch))
Defaults.setRuler(Ruler(scale: .inch))
let lbl = PglLabel(name: "QRCodes")
let enText = "Tree in the forest"
let jaText = "森の中の木"
let english = PglQRBarcode(start: Points(x: 0.25, y: 1.0), data: enText)
english!.cellSize = CellSquare(xDim: 0.025, ruler: Ruler(scale: .inch))
let englishMasked = PglQRBarcode(start: Points(x: 1.5, y: 1.0), data: enText)
englishMasked!.cellSize = CellSquare(xDim: 0.025, ruler: Ruler(scale: .inch))
englishMasked!.mask = .mask4
let japanese = PglQRBarcode(start: Points(x: 0.25, y: 2.25), data: jaText)
japanese!.cellSize = CellSquare(xDim: 0.025, ruler: Ruler(scale: .inch))
let japaneseMasked = PglQRBarcode(start: Points(x: 1.5, y: 2.25), data: jaText)
japaneseMasked!.cellSize = CellSquare(xDim: 0.025, ruler: Ruler(scale: .inch))
japaneseMasked!.mask = .mask4
let autoEncData = PglQRBarcode(start: Points(x: 0.25, y: 3.75), data: "12345678 TREE IN THE FOREST 森の中の木")
autoEncData!.cellSize = CellSquare(xDim: 0.025, ruler: Ruler(scale: .inch))
autoEncData!.mask = .mask4
let manualModeData: [[Any]] = [
[NSNumber(value: QRCodeManualEncodingEnum.numeric.rawValue), "12345678"],
[NSNumber(value: QRCodeManualEncodingEnum.alphaNumeric.rawValue), " TREE IN THE FOREST "],
[NSNumber(value: QRCodeManualEncodingEnum.binary.rawValue), "森の中の木"]
]
let manualEncData = PglQRBarcode(start: Points(x: 1.75, y: 3.75), manuallyEncodedData: manualModeData)
manualEncData!.cellSize = CellSquare(xDim: 0.025, ruler: Ruler(scale: .inch))
manualEncData!.mask = .mask4
lbl!.add(english)
lbl!.add(englishMasked)
lbl!.add(japanese)
lbl!.add(japaneseMasked)
lbl!.add(autoEncData)
lbl!.add(manualEncData)
return lbl!
}
func PglBcdDataMatrix() -> PglLabel {
Defaults.setPrinterResolution(PrintResolution(dotsPerUnit: 300, unit: .inch))
Defaults.setRuler(Ruler(scale: .inch))
let lbl = PglLabel(name: "DMatrixBcds")
let dfltMatrix = PglDataMatrixBarcode(start: Points(x: 0.25, y: 0.25), data: "Default DataMatrix")
let rectMatrix = PglDataMatrixBarcode(start: Points(x: 1.25, y: 0.25), data: "Rectangular DataMatrix")
rectMatrix!.rotation = .counterClockwise
rectMatrix!.rectangle = true
rectMatrix!.cellSize = CellSquare(xDim: 0.025, ruler: Ruler(scale: .inch))
let dfltMatrixMultiLine = PglDataMatrixBarcode(start: Points(x: 2.25, y: 0.25), data: "Line 1 DataMatrix")
let Eol = dfltMatrixMultiLine!.ctrlChar(0x0D) + dfltMatrixMultiLine!.ctrlChar(0x0A) // CR + LF
dfltMatrixMultiLine!.data += Eol + "Line 2 content" + Eol + "Line 3 content"
let rectMatrixUserDefinedDimensions = PglDataMatrixBarcode(start: Points(x: 1.25, y: 1.75), data: "DataMatrix with user defined dimensions")
rectMatrixUserDefinedDimensions!.rectangle = true
rectMatrixUserDefinedDimensions!.rowsCols = CGSize(width: 16, height: 36) as NSValue
rectMatrixUserDefinedDimensions!.cellSize = CellSquare(xDim: 0.030, ruler: Ruler(scale: .inch))
lbl!.add(dfltMatrix)
lbl!.add(rectMatrix)
lbl!.add(dfltMatrixMultiLine)
lbl!.add(rectMatrixUserDefinedDimensions)
return lbl!
}
func PglBcdMaxicodes() -> PglLabel {
let lbl = PglLabel(name: "MaxiBcds")
let maxiDataStructCarrier = PglMaxicodeMsgStructured(mode: .mode2, postalCode: "90255", countryCode: "800", serviceClass: "200", remainingMsg: "Maxicode Carrier Standard")
let maxicodeBarcodeSc = PglMaxicodeBarcode(start: Points(x: 0.5, y: 0.5), data: maxiDataStructCarrier)
maxicodeBarcodeSc!.ruler = Ruler(scale: .inch)
let maxiDataOss = PglMaxicodeMsgStructuredOpenSystemStandard(mode: .mode3, year: "24", postalCode: "OHA123", countryCode: "123", serviceClass: "400", remainingMsg: "Maxicode Open Standard Format")
let maxicodeBarcodeOss = PglMaxicodeBarcode(start: Points(x: 0.5, y: 2.0), data: maxiDataOss)
maxicodeBarcodeOss!.ruler = Ruler(scale: .inch)
let maxiData = PglMaxicodeMsg(mode: .mode4, primaryMsg: "123456789", remainingMsg: "Maxicode unstructured")
let maxicodeBarcode = PglMaxicodeBarcode(start: Points(x: 0.5, y: 3.5), data: maxiData)
maxicodeBarcode!.ruler = Ruler(scale: .inch)
lbl!.add(maxicodeBarcodeSc)
lbl!.add(maxicodeBarcodeOss)
lbl!.add(maxicodeBarcode)
return lbl!
}
func PglSimpleLabel(name: String, address: String) -> PglLabel {
let lbl = PglLabel(name: "SimpleLabel")!
let inchRuler = Ruler(scale: ScaleEnum.inch)!
let mmRuler = Ruler(scale: ScaleEnum.MM)!
let line1 = _PglLine(start: Points(x: 2.5, y: 1.0 / 16.0)!, end: Points(x: 2.5, y: 1.0)!, lineThickness: 1.0 / 32.0)!
line1.ruler = inchRuler
lbl.add(line1)
let line2 = _PglLine(start: Points(x: 0.12, y: 1.0)!, end: Points(x: 3.88, y: 1.0)!, lineThickness: 1.0 / 32.0)!
line2.ruler = inchRuler
lbl.add(line2)
let line3 = _PglLine(start: Points(x: 0.12, y: 3.5)!, end: Points(x: 3.88, y: 3.5)!, lineThickness: 1.0 / 32.0)!
line3.ruler = inchRuler
lbl.add(line3)
let box1 = _PglBox(start: Points(x: 0.5, y: 1.25)!, end: Points(x: 3.5, y: 2.25)!, lineThickness: 1.0 / 16.0)!
box1.ruler = inchRuler
lbl.add(box1)
let productText = _PglText()!
productText.fontSizeUnits = FontSizeUnitsEnum.ruler
productText.ruler = inchRuler
productText.alignment = AlignEnum.center
productText.fontName = "93952.sf"
let textItem1 = TextItem(start: Points(x: 2.0, y: 1.25 + 7.0 / 16.0)!, data: "MY MAGIC")!
textItem1.fontSize = FontSize(x: 3.0 / 16.0, y: 7.0 / 16.0)
productText.text.add(textItem1)
let textItem2 = TextItem(start: Points(x: 2.0, y: 1.25 + 1.0 - 3.0 / 16.0)!, data: "PRODUCT")!
textItem2.fontSize = FontSize(x: 3.0 / 16.0, y: 7.0 / 16.0)
productText.text.add(textItem2)
lbl.add(productText)
let boldToFrom = _PglText()!
boldToFrom.fontSizeUnits = FontSizeUnitsEnum.ruler
boldToFrom.ruler = mmRuler
boldToFrom.fontStyle = FontStyleEnum.bold
boldToFrom.fontName = "92248.sf"
let bold_textItem1 = TextItem(start: Points(x: 5.0, y: 5.0)!, data: "TO:")!
bold_textItem1.fontSize = FontSize(x: 2.5, y: 5.0)
boldToFrom.text.add(bold_textItem1)
let bold_textItem2 = TextItem(start: Points(x: (2.5 + 1 / 16.0) * 25.4, y: 5.0)!, data: "FROM:")!
boldToFrom.text.add(bold_textItem2)
lbl.add(boldToFrom)
let companyName = _PglText()!
companyName.fontSizeUnits = FontSizeUnitsEnum.percent
companyName.ruler = mmRuler
companyName.fontStyle = FontStyleEnum.italic
companyName.fontName = "92500.sf"
let companyNameTextItem = TextItem(start: Points(x: (2.5 + 1 / 16.0 + 1 / 8.0) * 25.4, y: 17.0)!, data: "Happy Inc.")!
companyNameTextItem.fontSize = FontSize(x: 2.0, y: 3.0)
companyName.text.add(companyNameTextItem)
lbl.add(companyName)
let nameTxt = _PglText()!
nameTxt.fontSizeUnits = FontSizeUnitsEnum.ruler
nameTxt.ruler = mmRuler
nameTxt.fontStyle = FontStyleEnum.italic
let nameTextItem = TextItem(start: Points(x: 8.0, y: 10.0)!, data: name)!
nameTextItem.fontSize = FontSize(x: 2.5, y: 5.0)
nameTxt.text.add(nameTextItem)
lbl.add(nameTxt)
let addressTxt = _PglText()!
addressTxt.ruler = mmRuler
let addressTextItem = TextItem(start: Points(x: 8.0, y: 17.0)!, data: address)!
addressTxt.text.add(addressTextItem)
lbl.add(addressTxt)
let bcd128 = PglBarcode_1D(barcodeItem: BarcodeItem(start: Points(x: 0.5, y: (1.5 + 1 / 4.0 + 1.2))!, height: 1.2, data: "Code 128")!)!
bcd128.barcodeType = BarcodeTypeEnum1D.dCode128
bcd128.printHumanReadable = true
bcd128.rotation = RotateEnum.none
bcd128.ruler = inchRuler
bcd128.barWidths = PglBarWidths(narrowBar: 0.015, wideBar: 0.015 * 4.1)!
bcd128.barWidths!.ruler = inchRuler
lbl.add(bcd128)
let bcd93 = PglBarcode_1D(barcodeItem: BarcodeItem(start: Points(x: 0.5, y: 3.5 - 1 / 8.0 - 0.6)!, height: 0.6, data: "CODE 93")!)!
bcd93.barcodeType = BarcodeTypeEnum1D.dCode93
bcd93.printHumanReadable = true
bcd93.rotation = RotateEnum.none
bcd93.ruler = inchRuler
bcd93.barWidths = PglBarWidths(narrowBar: 0.025, wideBar: 0.025 * 4.1)!
bcd93.barWidths!.ruler = inchRuler
lbl.add(bcd93)
let dmCustomer = PglDataMatrixBarcode(start: Points(x: 2.7, y: 4.0)!, data: name)!
dmCustomer.cellSize = CellSquare(xDim: 0.040, ruler: inchRuler)
dmCustomer.ruler = inchRuler
let Eol = dmCustomer.ctrlChar(0x0D)! + dmCustomer.ctrlChar(0x0A)!
dmCustomer.data = "\‍(dmCustomer.data!)\‍(Eol)\‍(address)"
lbl.add(dmCustomer)
return lbl
}
func RulerLines(length: Float, vertical: Bool, inchUnits: Bool, margin: Float) -> [_PglLine] {
var rulerLines: [_PglLine] = []
let tickRuler = inchUnits ? Ruler(scale: .inch)! : Ruler(scale: .MM)!
var rulerLength = length
var tickThickness: Float = 0.010
var tickLength: Float = 1 / 16.0
let ticksPerUnit: Float = inchUnits ? 16.0 : 1.0
var margin = margin
if !inchUnits {
tickThickness *= MM_PER_INCH
tickLength *= MM_PER_INCH
margin *= MM_PER_INCH
}
rulerLength -= tickThickness
for i in stride(from: 1, through: (rulerLength * ticksPerUnit), by: 1) {
var tick = tickLength
if inchUnits {
if Int(i) % 16 == 0 {
tick *= 3.5
} else if Int(i) % 8 == 0 {
tick *= 2.5
} else if Int(i) % 4 == 0 {
tick *= 2.0
} else if Int(i) % 2 == 0 {
tick *= 1.5
}
} else {
if Int(i) % 10 == 0 {
tick *= 3.0
} else if Int(i) % 5 == 0 {
tick *= 1.5
}
}
let tickLine: _PglLine
if vertical {
tickLine = _PglLine(xStart: margin, yStart: i / ticksPerUnit, xEnd: margin + tick, yEnd: i / ticksPerUnit, lineThickness: tickThickness)!
} else {
tickLine = _PglLine(xStart: i / ticksPerUnit, yStart: margin, xEnd: i / ticksPerUnit, yEnd: margin + tick, lineThickness: tickThickness)!
}
tickLine.ruler = tickRuler
rulerLines.append(tickLine)
}
return rulerLines
}
func RuleredLabel(width: Float, length: Float, inchUnits: Bool, rulerMargin: Float) -> PglLabel {
let verRulerTicks = RulerLines(length: length, vertical: true, inchUnits: inchUnits, margin: rulerMargin)
let horRulerTicks = RulerLines(length: width, vertical: false, inchUnits: inchUnits, margin: rulerMargin)
Defaults.setPrinterResolution(PrintResolution(dotsPerUnit: 300, unit: ScaleEnum.inch)!)
let rulerLbl = PglLabel(name: "Ruler")!
for tickLine in verRulerTicks {
rulerLbl.add(tickLine)
}
for tickLine in horRulerTicks {
rulerLbl.add(tickLine)
}
return rulerLbl
}
func stringToHex(_ input: String) -> String {
let utf8String = input.utf8
var hexString = ""
for byte in utf8String {
hexString += String(format: "%02X", byte)
}
return hexString
}