UniPRT SDK v1.0.0.0
 
载入中...
搜索中...
未找到
LabelMaker

Classes and methods related to LabelMaker. 更多...

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.
 

详细描述

Classes and methods related to LabelMaker.

For the Objective-C example, see here.

For the Swift example, see here.

Example

Objective-C:

#import <Foundation/Foundation.h>
//Please remark the define or not to test PGL or TSPL .
#define TSPL_Case
@import UniPRT ;
#ifdef TSPL_Case
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 valueWithSize:NSMakeSize(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;
}
int main(int argc, const char * argv[]) {
@autoreleasepool {
Label *label = BcdPdf417();
NSLog(@"Label: \r\n%@", label);
Label *simpleLabel = SimpleTextLabel(@"Mr. Milky Cheese", @"123 No Way Road");
NSLog(@"SimpleTextLabel: \r\n%@", simpleLabel);
Label *rfidLabel = RfidEncode();
NSLog(@"RfidLabel: \r\n%@", rfidLabel);
Label *maxicodesLabel = BcdMaxicodes();
NSLog(@"MaxicodesLabel: \r\n%@", maxicodesLabel);
Label *dataMatrixLabel = BcdDataMatrix();
NSLog(@"DataMatrixLabel: \r\n%@", dataMatrixLabel);
Label *aztecLabel = BcdAztec();
NSLog(@"AztecLabel: \r\n%@", aztecLabel);
Label *qrCodeLabel = BcdQRCode();
NSLog(@"QRCodeLabel: \r\n%@", qrCodeLabel);
}
return 0;
}
//PGL
#else
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 *RfidEncode(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 *BcdPdf417(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 *BcdAztec(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 *BcdQRCode(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 *BcdDataMatrix(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 valueWithSize:NSMakeSize(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 *BcdMaxicodes(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 *SimpleLabel(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;
}
int main(int argc, const char * argv[]) {
@autoreleasepool {
NSLog(@"%@", RfidEncode());
NSLog(@"%@", BcdPdf417());
NSLog(@"%@", BcdAztec());
NSLog(@"%@", BcdQRCode());
NSLog(@"%@", BcdDataMatrix());
NSLog(@"%@", BcdMaxicodes());
NSLog(@"%@", SimpleLabel(@"Mr. Einstein", @"123 Relativity Road"));
NSLog(@"%@", RuleredLabel(4.0f, 6.0f, YES, 1.0f/8.0f));
NSLog(@"%@", RuleredLabel(4.0f * 25.4f, 6.0f * 25.4f, NO, 1.0f/8.0f));
}
return 0;
}
#endif
表示 TSPL 中的方形对象的类。
Definition _Box.h:44
id< IRuler > ruler
用于测量方形对象的标尺。
Definition _Box.h:56
表示 TSPL 线对象的类。
Definition _Line.h:45
表示一个盒子形状的类。
Definition _PglBox.h:45
id< IRuler > ruler
用于测量盒子的尺子。
Definition _PglBox.h:57
表示一条线形状的类。
Definition _PglLine.h:46
表示文本对象的类。
Definition _PglText.h:47
AztecCodeTypeEnum type
Aztec 条形码的类型。
Definition AAztecBarcode.h:57
int layers
AztecCodeTypeEnum.Compact 或 AztecCodeTypeEnum.Full 条形码类型使用的层数。
Definition AAztecBarcode.h:87
id< ICellSquare > cellSize
条形码的单元格大小。
Definition AAztecBarcode.h:45
int fixedErrCorrection
此百分比错误更正值仅适用于 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)
获取表示 0-31 范围内不可打印控制字符的字符串。
NSValue * rowsCols
如果希望手动设置条码矩阵的尺寸,请指定条码的行和列的单元格数量。
Definition ADataMatrix.h:90
BOOL rectangle
设置条码的形状为矩形,否则使用默认的正方形。
Definition ADataMatrix.h:48
id< IRuler > ruler
用于放置的标尺。如果未设置,则使用默认的标尺设置。
Definition ALine.h:46
id< IRuler > ruler
Definition AMaxicodeBarcode.h:37
int rows
行数可以用来限制条形码的高度。
Definition APdf417.h:110
Pdf417ErrCorrectionEnum errorCorrection
PDF417条形码的错误校正级别。
Definition APdf417.h:86
int columns
列数可以用来限制条形码的宽度。
Definition APdf417.h:140
id< ICellRect > cellSize
单元格大小可以看作是PDF417行中最窄条元素的宽度和高度。
Definition APdf417.h:74
QRCodeMaskEnum mask
用于生成二维码的掩码。
Definition AQRBarcode.h:106
id< ICellSquare > cellSize
构成二维码的单元格的大小。
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
表示用于 TSPL 的 Aztec 条码的类。
Definition AztecBarcode.h:45
表示用于 TSPL 条码中条宽的类。
Definition BarWidths.h:44
表示用于 TSPL 的一维条码的类。
Definition Barcode_1D.h:45
BarcodeItem 类,继承自 ABarcodeItem 类。
Definition BarcodeItem.h:33
遵循 ICellRect 协议的 CellRect 类。
Definition CellRect.h:31
CellSquare 类,继承自 ACellSquare 类。
Definition CellSquare.h:31
表示用于 TSPL 的 Data Matrix 条码的类。
Definition DataMatrixBarcode.h:47
如果在对象创建期间或设置/更改时未指定的默认设置。
Definition Defaults.h:38
void SetRuler:(id< IRuler > ruler)
void SetPrinterResolution:(id< IPrintResolution > printerResolution)
字体在 X 和 Y 方向的大小,允许在需要非默认字体大小时进行拉伸/调整大小。
Definition FontSize.h:38
表示 TSPL 标签的类。
Definition Label.h:42
void addObject:(id addObject)
向标签添加一个可以转换为印表机语言语法的对象。
表示用于 TSPL 的 Maxicode 条码的类。
Definition MaxicodeBarcode.h:45
表示用于 TSPL 的 Maxicode 讯息的类。
Definition MaxicodeMsg.h:40
表示用于 TSPL 的结构化 Maxicode 讯息的类。
Definition MaxicodeMsgStructured.h:41
表示 TSPL 中 PDF417 条形码的类。
Definition Pdf417Barcode.h:41
表示Aztec条形码的类。
Definition PglAztecBarcode.h:47
表示条形码条宽的类。
Definition PglBarWidths.h:44
表示一维条形码的类。
Definition PglBarcode_1D.h:42
表示数据矩阵条形码的类。
Definition PglDataMatrixBarcode.h:46
表示一个可以转换为印表机语言语法的标签类。
Definition PglLabel.h:41
void addObject:(id addObject)
向标签添加可以转换为印表机语言语法的对象。
表示Maxicode条形码的类。
Definition PglMaxicodeBarcode.h:43
表示Maxicode讯息的类。
Definition PglMaxicodeMsg.h:41
表示结构化Maxicode讯息的类。
Definition PglMaxicodeMsgStructured.h:41
表示按照开放系统标准结构化的Maxicode讯息的类。
Definition PglMaxicodeMsgStructuredOpenSystemStandard.h:41
表示 PDF417 条码的类。
Definition PglPdf417Barcode.h:42
表示一个 QR 码条形码的类。
Definition PglQRBarcode.h:42
表示 RFID 写操作的类。
Definition PglRfid_Write.h:42
继承自 IPoint 的 Points 类。
Definition Point.h:38
继承自 IPrintResolution 的 PrintResolution 类。
Definition PrintResolution.h:37
表示 TSPL 中 QR 码条形码的类。
Definition QRBarcode.h:48
表示 TSPL 中 RFID 写入操作的类。
Definition Rfid_Write.h:45
支持将非字节数据转换为RFID标签中存储的顺序的方法。
Definition RfidConvert.h:41
NSString * toHexFromUShort:(uint16_t ushortData)
将2字节无符号整数转换为可写入RFID标签的十六进制字符串。
NSString * toHexFromUInt:(uint32_t uintData)
将4字节无符号整数转换为可写入RFID标签的十六进制字符串。
NSString * toHexFromBytes:(NSData *bytes)
便利方法,将字节数组转换为可写入RFID标签的十六进制字符串。
NSString * toHexFromASCIIString:(NSString *asciiString)
便利方法,将ASCII字符串转换为十六进制。
继承自 IRuler 的 Ruler 类。
Definition Ruler.h:36
TextItem 类,继承自 ITextItem。
Definition TextItem.h:34

Swift:

import Foundation
import UniPRT
func BcdPdf417() -> Label {
let lbl = Label(name: "Pdf417Bcodes")
Defaults.setPrinterResolution(PrintResolution(dotsPerUnit: 300, unit: .inch))
Defaults.setRuler(Ruler(scale: ScaleEnum.inch))
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) -> 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 = BarcodeTypeEnum1D.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 = BarcodeTypeEnum1D.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() -> 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: RfidMemBlockEnum.EPC, data: epcHexData)
lbl!.add(epc)
var userHexData = RfidConvert.toHex(fromASCIIString: "MyUserData")
userHexData! += "0ABCDE0F"
let userMem = Rfid_Write(memBlock: RfidMemBlockEnum.user, data: userHexData)
userMem!.offsetFromStart = 2
lbl!.add(userMem)
return lbl!
}
func BcdMaxicodes() -> 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() -> Label {
let lbl = Label(name: "DMatrixBcds")
Defaults.setPrinterResolution(PrintResolution(dotsPerUnit: 600, unit: .inch))
Defaults.setRuler(Ruler(scale: .inch))
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)
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 = NSValue(size: CGSize(width: 16, height: 36))
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() -> Label {
let lbl = Label(name: "AztecBcodes")
Defaults.setPrinterResolution(PrintResolution(dotsPerUnit: 300, unit: .inch))
Defaults.setRuler(Ruler(scale: .inch))
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(bcdFull)
lbl!.add(bcdCompact)
lbl!.add(bcdRuneA)
lbl!.add(bcdRuneB)
lbl!.add(bcdRuneC)
return lbl!
}
func BcdQRCode() -> Label {
let lbl = Label(name: "QRCodes")
Defaults.setPrinterResolution(PrintResolution(dotsPerUnit: 300, unit: .inch))
Defaults.setRuler(Ruler(scale: ScaleEnum.inch))
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!
}
//let label = BcdPdf417()
//print("Label: \n\‍(label)")
//
//let simpleLabel = SimpleTextLabel(name: "Mr. Milky Cheese", address: "123 No Way Road")
//print("SimpleTextLabel: \n\‍(simpleLabel)")
//
//let rfidLabel = RfidEncode()
//print("RfidLabel: \n\‍(rfidLabel)")
//
//let maxicodesLabel = BcdMaxicodes()
//print("MaxicodesLabel: \n\‍(maxicodesLabel)")
//
//let dataMatrixLabel = BcdDataMatrix()
//print("DataMatrixLabel: \n\‍(dataMatrixLabel)")
//
//let aztecLabel = BcdAztec()
//print("AztecLabel: \n\‍(aztecLabel)")
//
//let qrCodeLabel = BcdQRCode()
//print("QRCodeLabel: \n\‍(qrCodeLabel)")
//PGL part
func fileReplace(pathAndName: String, dataToWrite: String) {
do {
try dataToWrite.write(toFile: pathAndName, atomically: true, encoding: .utf8)
} catch {
print("Error writing file: \‍(error.localizedDescription)")
}
}
func stringToHex(_ input: String) -> String {
let utf8String = input.utf8
var hexString = ""
for byte in utf8String {
hexString.append(String(format: "%02X", byte))
}
return hexString
}
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: RfidMemBlockEnum.EPC, data: epcHexData)!
lbl.add(epc)
var userDataHex = stringToHex("MyUserData")
userDataHex += "0ABCDE0F"
let userMem = PglRfid_Write(memBlock: RfidMemBlockEnum.user, data: userDataHex)!
userMem.offsetFromStart = 2
lbl.add(userMem)
return lbl
}
func PglBcdPdf417() -> PglLabel {
let lbl = PglLabel(name: "Pdf417Bcodes")!
Defaults.setPrinterResolution(PrintResolution(dotsPerUnit: 600, unit: ScaleEnum.inch)!)
Defaults.setRuler(Ruler(scale: ScaleEnum.inch)!)
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: ScaleEnum.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: ScaleEnum.inch)!)
bcdErrCorrectionLvl0.errorCorrection = Pdf417ErrCorrectionEnum.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: ScaleEnum.inch)!)
bcdErrCorrectionLvl5.errorCorrection = Pdf417ErrCorrectionEnum.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: ScaleEnum.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: ScaleEnum.inch)!)
bcdColsLimited.columns = 5
lbl.add(bcdDefault)
lbl.add(bcdErrCorrectionLvl0)
lbl.add(bcdErrCorrectionLvl5)
lbl.add(bcdRowsLimited)
lbl.add(bcdColsLimited)
return lbl
}
func PglBcdAztec() -> PglLabel {
let lbl = PglLabel(name: "AztecBcodes")!
Defaults.setPrinterResolution(PrintResolution(dotsPerUnit: 300, unit: ScaleEnum.inch)!)
Defaults.setRuler(Ruler(scale: ScaleEnum.inch)!)
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: ScaleEnum.inch)!)
let bcdFixedErrCorr = PglAztecBarcode(start: Points(x: 1.5, y: 1.0)!, data: someText)!
bcdFixedErrCorr.cellSize = CellSquare(xDim: 0.025, ruler: Ruler(scale: ScaleEnum.inch)!)
bcdFixedErrCorr.type = AztecCodeTypeEnum.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: ScaleEnum.inch)!)
bcdCompact.type = AztecCodeTypeEnum.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: ScaleEnum.inch)!)
bcdFull.type = AztecCodeTypeEnum.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: ScaleEnum.inch)!)
bcdRuneA.type = AztecCodeTypeEnum.rune
let bcdRuneB = PglAztecBarcode(start: Points(x: 0.75, y: 4.00)!, data: "255")!
bcdRuneB.cellSize = CellSquare(xDim: 0.025, ruler: Ruler(scale: ScaleEnum.inch)!)
bcdRuneB.type = AztecCodeTypeEnum.rune
let bcdRuneC = PglAztecBarcode(start: Points(x: 1.25, y: 4.00)!, data: "123")!
bcdRuneC.cellSize = CellSquare(xDim: 0.025, ruler: Ruler(scale: ScaleEnum.inch)!)
bcdRuneC.type = AztecCodeTypeEnum.rune
lbl.add(bcdDefault)
lbl.add(bcdFixedErrCorr)
lbl.add(bcdCompact)
lbl.add(bcdRuneB)
return lbl
}
func PglBcdQRCode() -> PglLabel {
let lbl = PglLabel(name: "QRCodes")!
Defaults.setPrinterResolution(PrintResolution(dotsPerUnit: 300, unit: ScaleEnum.inch)!)
Defaults.setRuler(Ruler(scale: ScaleEnum.inch)!)
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: ScaleEnum.inch)!)
let englishMasked = PglQRBarcode(start: Points(x: 1.5, y: 1.0)!, data: enText)!
englishMasked.cellSize = CellSquare(xDim: 0.025, ruler: Ruler(scale: ScaleEnum.inch)!)
englishMasked.mask = QRCodeMaskEnum.mask4
let japanese = PglQRBarcode(start: Points(x: 0.25, y: 2.25)!, data: jaText)!
japanese.cellSize = CellSquare(xDim: 0.025, ruler: Ruler(scale: ScaleEnum.inch)!)
japanese.mask = QRCodeMaskEnum.mask1
let japaneseMasked = PglQRBarcode(start: Points(x: 1.5, y: 2.25)!, data: jaText)!
japaneseMasked.cellSize = CellSquare(xDim: 0.025, ruler: Ruler(scale: ScaleEnum.inch)!)
japaneseMasked.mask = QRCodeMaskEnum.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: ScaleEnum.inch)!)
autoEncData.mask = QRCodeMaskEnum.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: ScaleEnum.inch)!)
manualEncData.mask = QRCodeMaskEnum.mask4
lbl.add(english)
lbl.add(englishMasked)
lbl.add(japanese)
lbl.add(japaneseMasked)
lbl.add(autoEncData)
lbl.add(manualEncData)
return lbl
}
func PglBcdDataMatrix() -> PglLabel {
let lbl = PglLabel(name: "DMatrixBcds")!
Defaults.setPrinterResolution(PrintResolution(dotsPerUnit: 300, unit: ScaleEnum.inch)!)
Defaults.setRuler(Ruler(scale: ScaleEnum.inch)!)
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 = RotateEnum.counterClockwise
rectMatrix.rectangle = true
rectMatrix.cellSize = CellSquare(xDim: 0.025, ruler: Ruler(scale: ScaleEnum.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 = 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 = NSValue(size: CGSize(width: 16, height: 36))
rectMatrixUserDefinedDimensions.cellSize = CellSquare(xDim: 0.030, ruler: Ruler(scale: ScaleEnum.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: MaxicodeModeEnum.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: ScaleEnum.inch)!
let maxiDataOss = PglMaxicodeMsgStructuredOpenSystemStandard(mode: MaxicodeModeEnum.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: ScaleEnum.inch)!
let maxiData = PglMaxicodeMsg(mode: MaxicodeModeEnum.mode4, primaryMsg: "123456789", remainingMsg: "Maxicode unstructured")!
let maxicodeBarcode = PglMaxicodeBarcode(start: Points(x: 0.5, y: 3.5)!, data: maxiData)!
maxicodeBarcode.ruler = Ruler(scale: ScaleEnum.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
}
let pgllabel = PglRfidEncode()
print("RfidEncode: \n\‍(pgllabel)")
let pglpdf417Label = PglBcdPdf417()
print("BcdPdf417: \n\‍(pglpdf417Label)")
let pglaztecLabel = PglBcdAztec()
print("BcdAztec: \n\‍(pglaztecLabel)")
let pglqrCodeLabel = PglBcdQRCode()
print("BcdQRCode: \n\‍(pglqrCodeLabel)")
let pgldataMatrixLabel = PglBcdDataMatrix()
print("BcdDataMatrix: \n\‍(pgldataMatrixLabel)")
let pglmaxicodesLabel = PglBcdMaxicodes()
print("BcdMaxicodes: \n\‍(pglmaxicodesLabel)")
let pglsimpleLabel = PglSimpleLabel(name: "Mr. Einstein", address: "123 Relativity Road")
print("SimpleLabel: \n\‍(pglsimpleLabel)")
let RuleredLabel1 = RuleredLabel(width: 4.0, length: 6.0, inchUnits: true, rulerMargin: 1.0 / 8.0)
print("RuleredLabel (Inches): \n\‍(RuleredLabel1)")
let RuleredLabel2 = RuleredLabel(width: 4.0 * 25.4, length: 6.0 * 25.4, inchUnits: false, rulerMargin: 1.0 / 8.0)
print("RuleredLabel (MM): \n\‍(RuleredLabel2)")