Classes and methods related to LabelMaker.
#import <Foundation/Foundation.h>
#define TSPL_Case
@import UniPRT ;
#ifdef TSPL_Case
Label *lbl = [[
Label alloc] initWithName:@"Pdf417Bcodes"];
NSString *someText = @"The happiness in your life depends on the quality of your thoughts. --Marcus Aurelius";
NSString *someShortText = @"PI = 3.1415";
bcdDefault.
cellSize = [[
CellRect alloc] initWithXDim:0.015 yDim:0.050 ruler:[[
Ruler alloc] initWithScale:ScaleEnumInch]];
bcdErrCorrectionLvl0.
cellSize = [[
CellRect alloc] initWithXDim:0.015 yDim:0.050 ruler:[[
Ruler alloc] initWithScale:ScaleEnumInch]];
bcdErrCorrectionLvl5.
cellSize = [[
CellRect alloc] initWithXDim:0.015 yDim:0.050 ruler:[[
Ruler alloc] initWithScale:ScaleEnumInch]];
bcdRowsLimited.
cellSize = [[
CellRect alloc] initWithXDim:0.015 yDim:0.050 ruler:[[
Ruler alloc] initWithScale:ScaleEnumInch]];
bcdRowsLimited.
rows = 15;
bcdColsLimited.
cellSize = [[
CellRect alloc] initWithXDim:0.015 yDim:0.050 ruler:[[
Ruler alloc] initWithScale:ScaleEnumInch]];
return lbl;
}
Label* SimpleTextLabel(NSString *name, NSString *address) {
Label *lbl = [[
Label alloc] initWithName:@"SimpleLabel"];
Ruler *inchRuler = [[
Ruler alloc] initWithScale:ScaleEnumInch];
_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];
_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];
_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];
_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];
height:1.2
data:@"Code 128"];
bcd128.
ruler = inchRuler;
height:0.6f
data:@"CODE 93"];
return lbl;
}
Label* RfidEncode(
void) {
Label *lbl = [[
Label alloc] initWithName:@"RfidLbl"];
uint32_t a32BitField = 0x11223344;
uint16_t a16BitField = 0xBEEF;
NSString *a6CharAsciiString = @"MyData";
epcHexData = [epcHexData stringByAppendingString:[
RfidConvert toHexFromBytes:[a6CharAsciiString dataUsingEncoding:NSASCIIStringEncoding]]];
userHexData = [userHexData stringByAppendingString:@"0ABCDE0F"];
return lbl;
}
Label* BcdMaxicodes(
void) {
Label *lbl = [[
Label alloc] initWithName:@"MaxiBcds"];
MaxicodeMsgStructured *maxiDataStructCarrier = [[
MaxicodeMsgStructured alloc] initWithMode:MaxicodeModeEnumMode2 postalCode:@"902557317" countryCode:@"800" serviceClass:@"200" remainingMsg:@"Maxicode Carrier Standard"];
maxicodeBarcodeSc.
ruler = [[
Ruler alloc] initWithScale:ScaleEnumInch];
MaxicodeMsg *maxiData = [[
MaxicodeMsg alloc] initWithMode:MaxicodeModeEnumMode4 primaryMsg:@"123456789" remainingMsg:@"Maxicode unstructured"];
maxicodeBarcode.
ruler = [[
Ruler alloc] initWithScale:ScaleEnumInch];
return lbl;
}
Label* BcdDataMatrix(
void) {
Label *lbl = [[
Label alloc] initWithName:@"DMatrixBcds"];
rectMatrix.
rotation = RotateEnumCounterClockwise;
NSString *Eol = [[dfltMatrixMultiLine
ctrlChar:0x0D] stringByAppendingString:[dfltMatrixMultiLine
ctrlChar:0x0A]];
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"];
rectMatrixUserDefinedDimensions.
rectangle = YES;
rectMatrixUserDefinedDimensions.
rowsCols = [NSValue valueWithSize:NSMakeSize(16, 36)];
rectMatrixUserDefinedDimensions.
cellSize = [[
CellSquare alloc] initWithXDim:0.030f ruler:[[
Ruler alloc] initWithScale:ScaleEnumInch]];
[lbl
addObject:rectMatrixUserDefinedDimensions];
return lbl;
}
Label *lbl = [[
Label alloc] initWithName:@"AztecBcodes"];
NSString *someText = @"Mr. AirTraveler, seat A, flight 200";
bcdFixedErrCorr.
cellSize = [[
CellSquare alloc] initWithXDim:0.025f ruler:[[
Ruler alloc] initWithScale:ScaleEnumInch]];
bcdFixedErrCorr.
type = AztecCodeTypeFixedErrCorrection;
bcdCompact.
type = AztecCodeTypeCompact;
bcdFull.
type = AztecCodeTypeFull;
bcdRuneA.
type = AztecCodeTypeRune;
bcdRuneB.
type = AztecCodeTypeRune;
bcdRuneC.
type = AztecCodeTypeRune;
return lbl;
}
Label *lbl = [[
Label alloc] initWithName:@"QRCodes"];
NSString *enText = @"Tree in the forest";
NSString *jaText = @"森の中の木";
englishMasked.
cellSize = [[
CellSquare alloc] initWithXDim:0.025f ruler:[[
Ruler alloc] initWithScale:ScaleEnumInch]];
englishMasked.
mask = QRCodeMask4;
japanese.
mask = QRCodeMask1;
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.
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;
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;
}
#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;
}
uint32_t a32BitField = 0x11223344;
uint16_t a16BitField = 0xBEEF;
NSString *a6CharAsciiString = @"MyData";
NSString *epcHexData = [NSString stringWithFormat:@"%08X%@", a32BitField, stringToHex(a6CharAsciiString)];
epcHexData = [epcHexData stringByAppendingFormat:@"%04X", a16BitField];
NSString *userDataHex = stringToHex(@"MyUserData");
userDataHex = [userDataHex stringByAppendingString:@"0ABCDE0F"];
return lbl;
}
NSString *someText = @"The happiness in your life depends on the quality of your thoughts. --Marcus Aurelius";
NSString *someShortText = @"PI = 3.1415";
bcdDefault.
cellSize = [[
CellRect alloc] initWithXDim:0.015f yDim:0.050f ruler:[[
Ruler alloc] initWithScale:ScaleEnumInch]];
bcdErrCorrectionLvl0.
cellSize = [[
CellRect alloc] initWithXDim:0.015f yDim:0.050f ruler:[[
Ruler alloc] initWithScale:ScaleEnumInch]];
bcdErrCorrectionLvl5.
cellSize = [[
CellRect alloc] initWithXDim:0.015f yDim:0.050f ruler:[[
Ruler alloc] initWithScale:ScaleEnumInch]];
bcdRowsLimited.
cellSize = [[
CellRect alloc] initWithXDim:0.015f yDim:0.050f ruler:[[
Ruler alloc] initWithScale:ScaleEnumInch]];
bcdRowsLimited.
rows = 15;
bcdColsLimited.
cellSize = [[
CellRect alloc] initWithXDim:0.015f yDim:0.050f ruler:[[
Ruler alloc] initWithScale:ScaleEnumInch]];
return lbl;
}
NSString *someText = @"Mr. AirTraveler, seat A, flight 200";
bcdFixedErrCorr.
cellSize = [[
CellSquare alloc] initWithXDim:0.025f ruler:[[
Ruler alloc] initWithScale:ScaleEnumInch]];
bcdFixedErrCorr.
type = AztecCodeTypeFixedErrCorrection;
bcdCompact.
type = AztecCodeTypeCompact;
bcdFull.
type = AztecCodeTypeFull;
bcdRuneA.
type = AztecCodeTypeRune;
bcdRuneB.
type = AztecCodeTypeRune;
bcdRuneC.
type = AztecCodeTypeRune;
return lbl;
}
NSString *enText = @"Tree in the forest";
NSString *jaText = @"森の中の木";
englishMasked.
cellSize = [[
CellSquare alloc] initWithXDim:0.025f ruler:[[
Ruler alloc] initWithScale:ScaleEnumInch]];
englishMasked.
mask = QRCodeMask4;
japaneseMasked.
cellSize = [[
CellSquare alloc] initWithXDim:0.025f ruler:[[
Ruler alloc] initWithScale:ScaleEnumInch]];
japaneseMasked.
mask = QRCodeMask4;
autoEncData.
mask = QRCodeMask4;
NSArray *manualModeData = @[@[@(QRCodeManualEncodingNumeric), @"12345678"],
@[@(QRCodeManualEncodingAlphaNumeric), @" TREE IN THE FOREST "],
@[@(QRCodeManualEncodingBinary), @"森の中の木"]];
manualEncData.
cellSize = [[
CellSquare alloc] initWithXDim:0.025f ruler:[[
Ruler alloc] initWithScale:ScaleEnumInch]];
manualEncData.
mask = QRCodeMask4;
return lbl;
}
rectMatrix.
rotation = RotateEnumCounterClockwise;
NSString *Eol = [[dfltMatrixMultiLine
ctrlChar:0x0D] stringByAppendingString:[dfltMatrixMultiLine
ctrlChar:0x0A]];
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"];
rectMatrixUserDefinedDimensions.
rectangle = YES;
rectMatrixUserDefinedDimensions.
rowsCols = [NSValue valueWithSize:NSMakeSize(16, 36)];
rectMatrixUserDefinedDimensions.
cellSize = [[
CellSquare alloc] initWithXDim:0.030f ruler:[[
Ruler alloc] initWithScale:ScaleEnumInch]];
[lbl
addObject:rectMatrixUserDefinedDimensions];
return lbl;
}
maxicodeBarcodeSc.
ruler = [[
Ruler alloc] initWithScale:ScaleEnumInch];
maxicodeBarcodeOss.
ruler = [[
Ruler alloc] initWithScale:ScaleEnumInch];
PglMaxicodeMsg *maxiData = [[
PglMaxicodeMsg alloc] initWithMode:MaxicodeModeEnumMode4 primaryMsg:@"123456789" remainingMsg:@"Maxicode unstructured"];
maxicodeBarcode.
ruler = [[
Ruler alloc] initWithScale:ScaleEnumInch];
return lbl;
}
PglLabel *SimpleLabel(NSString *name, NSString *address) {
Ruler *inchRuler = [[
Ruler alloc] initWithScale:ScaleEnumInch];
Ruler *mmRuler = [[
Ruler alloc] initWithScale:ScaleEnumMM];
end:[[
Points alloc] initWithX:2.5f y:1.0f]
lineThickness:1.0f/32.0f];
end:[[
Points alloc] initWithX:3.88f y:1.0f]
lineThickness:1.0f/32.0f];
end:[[
Points alloc] initWithX:3.88f y:3.5f]
lineThickness:1.0f/32.0f];
end:[[
Points alloc] initWithX:3.5f y:2.25f]
lineThickness:1.0f/16.0f];
productText.
ruler = inchRuler;
TextItem *textItem1 = [[
TextItem alloc] initWithStart:[[
Points alloc] initWithX:2.0f y:1.25f + 7.0 / 16.0f] data:@"MY MAGIC"];
[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"];
[productText.text addObject:textItem2];
boldToFrom.
ruler = mmRuler;
TextItem *bold_textItem1 = [[
TextItem alloc] initWithStart:[[
Points alloc] initWithX:5.0f y:5.0f] data:@"TO:"];
[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];
companyName.
ruler = mmRuler;
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.text addObject:companyName_textItem];
[nameTxt.text addObject:nameTextItem];
addressTxt.
ruler = mmRuler;
TextItem *addressTextItem = [[
TextItem alloc] initWithStart:[[
Points alloc] initWithX:8.0f y:17.0f] data:address];
[addressTxt.text addObject:addressTextItem];
bcd128.
ruler = inchRuler;
dmCustomer.
ruler = inchRuler;
NSString *Eol = [[dmCustomer
ctrlChar:0x0D] stringByAppendingString:[dmCustomer
ctrlChar:0x0A]];
dmCustomer.
data = [dmCustomer.data stringByAppendingFormat:@"%@%@", Eol, address];
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;
}
}
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);
for (
_PglLine *tickLine in verRulerTicks) {
}
for (
_PglLine *tickLine in horRulerTicks) {
}
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
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)")