-
-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added: Barcode93 support * Update Code93 Update interpretation line Add test to WebApi
- Loading branch information
1 parent
d1f5ae1
commit 35118fe
Showing
10 changed files
with
256 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace BinaryKits.Zpl.Label.Elements | ||
{ | ||
/// <summary> | ||
/// Code 93 Barcode | ||
/// </summary> | ||
public class ZplBarcode93 : ZplBarcode | ||
{ | ||
public bool CheckDigit { get; private set; } | ||
|
||
/// <summary> | ||
/// Code 93 Barcode | ||
/// </summary> | ||
/// <param name="content"></param> | ||
/// <param name="positionX"></param> | ||
/// <param name="positionY"></param> | ||
/// <param name="height"></param> | ||
/// <param name="moduleWidth"></param> | ||
/// <param name="wideBarToNarrowBarWidthRatio"></param> | ||
/// <param name="fieldOrientation"></param> | ||
/// <param name="printInterpretationLine"></param> | ||
/// <param name="printInterpretationLineAboveCode"></param> | ||
/// <param name="bottomToTop"></param> | ||
/// <param name="checkDigit"></param> | ||
/// <param name="mode"></param> | ||
Check warning on line 26 in src/BinaryKits.Zpl.Label/Elements/ZplBarcode93.cs GitHub Actions / build-windows
Check warning on line 26 in src/BinaryKits.Zpl.Label/Elements/ZplBarcode93.cs GitHub Actions / build-windows
Check warning on line 26 in src/BinaryKits.Zpl.Label/Elements/ZplBarcode93.cs GitHub Actions / build-windows
Check warning on line 26 in src/BinaryKits.Zpl.Label/Elements/ZplBarcode93.cs GitHub Actions / build-linux
Check warning on line 26 in src/BinaryKits.Zpl.Label/Elements/ZplBarcode93.cs GitHub Actions / build-linux
|
||
public ZplBarcode93( | ||
string content, | ||
int positionX, | ||
int positionY, | ||
int height = 100, | ||
int moduleWidth = 2, | ||
double wideBarToNarrowBarWidthRatio = 3, | ||
FieldOrientation fieldOrientation = FieldOrientation.Normal, | ||
bool printInterpretationLine = true, | ||
bool printInterpretationLineAboveCode = false, | ||
bool checkDigit = false, | ||
bool bottomToTop = false) | ||
: base(content, | ||
positionX, | ||
positionY, | ||
height, | ||
moduleWidth, | ||
wideBarToNarrowBarWidthRatio, | ||
fieldOrientation, | ||
printInterpretationLine, | ||
printInterpretationLineAboveCode, | ||
bottomToTop) | ||
{ | ||
this.CheckDigit = checkDigit; | ||
} | ||
|
||
///<inheritdoc/> | ||
public override IEnumerable<string> Render(ZplRenderOptions context) | ||
{ | ||
//TODO:Add 'mode' | ||
|
||
//^FO100,100 ^ BY3 | ||
//^BAN,100,Y,N,N | ||
//^FD123456 ^ FS | ||
var result = new List<string>(); | ||
result.AddRange(RenderPosition(context)); | ||
result.Add(RenderModuleWidth()); | ||
result.Add($"^BA{RenderFieldOrientation()},{context.Scale(Height)},{RenderPrintInterpretationLine()},{RenderPrintInterpretationLineAboveCode()},{(CheckDigit ? "Y" : "N")}"); | ||
result.Add($"^FD{Content}^FS"); | ||
|
||
return result; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/BinaryKits.Zpl.Viewer.WebApi/Labels/Test/Barcode93-102x152.zpl2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
^XA | ||
|
||
^FO10,10 | ||
^BY3,2 | ||
^BAN,100,Y,N | ||
^FD123ABC^FS | ||
|
||
^FO10,160 | ||
^BY4,2 | ||
^BAN,100,Y,N | ||
^FD123ABC^FS | ||
|
||
^FO10,320 | ||
^BY5,2 | ||
^BAN,100,Y,N | ||
^FD123ABC^FS | ||
|
||
^XZ |
55 changes: 55 additions & 0 deletions
55
src/BinaryKits.Zpl.Viewer/CommandAnalyzers/Code93BarcodeZplCommandAnalyzer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using BinaryKits.Zpl.Label.Elements; | ||
using BinaryKits.Zpl.Viewer.Models; | ||
|
||
namespace BinaryKits.Zpl.Viewer.CommandAnalyzers | ||
{ | ||
public class Code93BarcodeZplCommandAnalyzer : ZplCommandAnalyzerBase | ||
{ | ||
public Code93BarcodeZplCommandAnalyzer(VirtualPrinter virtualPrinter) : base("^BA", virtualPrinter) { } | ||
|
||
///<inheritdoc/> | ||
public override ZplElementBase Analyze(string zplCommand) | ||
{ | ||
var zplDataParts = this.SplitCommand(zplCommand); | ||
|
||
int tmpint; | ||
bool printCheckDigit = false; | ||
int height = this.VirtualPrinter.BarcodeInfo.Height; | ||
bool printInterpretationLine = true; | ||
bool printInterpretationLineAboveCode = false; | ||
|
||
var fieldOrientation = this.ConvertFieldOrientation(zplDataParts[0]); | ||
if (zplDataParts.Length > 1 && int.TryParse(zplDataParts[1], out tmpint)) | ||
{ | ||
height = tmpint; | ||
} | ||
|
||
if (zplDataParts.Length > 2) | ||
{ | ||
printInterpretationLine = this.ConvertBoolean(zplDataParts[2], "Y"); | ||
} | ||
|
||
if (zplDataParts.Length > 3) | ||
{ | ||
printInterpretationLineAboveCode = this.ConvertBoolean(zplDataParts[3]); | ||
} | ||
|
||
if (zplDataParts.Length > 4) | ||
{ | ||
printCheckDigit = this.ConvertBoolean(zplDataParts[4]); | ||
} | ||
|
||
//The field data are processing in the FieldDataZplCommandAnalyzer | ||
this.VirtualPrinter.SetNextElementFieldData(new Code93BarcodeFieldData | ||
{ | ||
FieldOrientation = fieldOrientation, | ||
Height = height, | ||
PrintInterpretationLine = printInterpretationLine, | ||
PrintInterpretationLineAboveCode = printInterpretationLineAboveCode, | ||
PrintCheckDigit = printCheckDigit | ||
}); | ||
|
||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/BinaryKits.Zpl.Viewer/ElementDrawers/Barcode93ElementDrawer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using BarcodeLib; | ||
using BinaryKits.Zpl.Label.Elements; | ||
using BinaryKits.Zpl.Viewer.Helpers; | ||
using SkiaSharp; | ||
using System; | ||
using System.Drawing; | ||
|
||
namespace BinaryKits.Zpl.Viewer.ElementDrawers | ||
{ | ||
public class Barcode93ElementDrawer : BarcodeDrawerBase | ||
{ | ||
///<inheritdoc/> | ||
public override bool CanDraw(ZplElementBase element) | ||
{ | ||
return element is ZplBarcode93; | ||
} | ||
|
||
///<inheritdoc/> | ||
public override void Draw(ZplElementBase element) | ||
{ | ||
Draw(element, new DrawerOptions()); | ||
} | ||
|
||
///<inheritdoc/> | ||
public override void Draw(ZplElementBase element, DrawerOptions options) | ||
{ | ||
if (element is ZplBarcode93 barcode) | ||
{ | ||
float x = barcode.PositionX; | ||
float y = barcode.PositionY; | ||
|
||
var content = barcode.Content; | ||
|
||
float labelFontSize = Math.Min(barcode.ModuleWidth * 7.2f, 72f); | ||
var labelTypeFace = options.FontLoader("A"); | ||
var labelFont = new SKFont(labelTypeFace, labelFontSize).ToSystemDrawingFont(); | ||
int labelHeight = barcode.PrintInterpretationLine ? labelFont.Height : 0; | ||
int labelHeightOffset = barcode.PrintInterpretationLineAboveCode ? labelHeight : 0; | ||
|
||
var barcodeElement = new Barcode | ||
{ | ||
BarWidth = barcode.ModuleWidth, | ||
BackColor = Color.Transparent, | ||
Height = barcode.Height + labelHeight, | ||
IncludeLabel = barcode.PrintInterpretationLine, | ||
LabelPosition = barcode.PrintInterpretationLineAboveCode ? LabelPositions.TOPCENTER : LabelPositions.BOTTOMCENTER, | ||
LabelFont = labelFont, | ||
AlternateLabel = content | ||
}; | ||
|
||
using var image = barcodeElement.Encode(TYPE.CODE93, content); | ||
this.DrawBarcode(this.GetImageData(image), barcode.Height, image.Width, barcode.FieldOrigin != null, x, y, labelHeightOffset, barcode.FieldOrientation); | ||
} | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/BinaryKits.Zpl.Viewer/Models/Code93BarcodeFieldData.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using BinaryKits.Zpl.Label; | ||
|
||
namespace BinaryKits.Zpl.Viewer.Models | ||
{ | ||
internal class Code93BarcodeFieldData : FieldDataBase | ||
{ | ||
public FieldOrientation FieldOrientation { get; set; } | ||
public int Height { get; set; } | ||
public bool PrintInterpretationLine { get; set; } | ||
public bool PrintInterpretationLineAboveCode { get; set; } | ||
public bool PrintCheckDigit { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.