-
-
Notifications
You must be signed in to change notification settings - Fork 127
Expand file tree
/
Copy pathBarcodeUpcExtensionElementDrawer.cs
More file actions
73 lines (60 loc) · 2.82 KB
/
BarcodeUpcExtensionElementDrawer.cs
File metadata and controls
73 lines (60 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using BinaryKits.Zpl.Label;
using BinaryKits.Zpl.Label.Elements;
using BinaryKits.Zpl.Viewer.Helpers;
using BinaryKits.Zpl.Viewer.Symologies;
using SkiaSharp;
using System;
namespace BinaryKits.Zpl.Viewer.ElementDrawers
{
public class BarcodeUpcExtensionElementDrawer : BarcodeDrawerBase
{
///<inheritdoc/>
public override bool CanDraw(ZplElementBase element)
{
return element is ZplBarcodeUpcExtension;
}
///<inheritdoc/>
public override SKPoint Draw(ZplElementBase element, DrawerOptions options, SKPoint currentPosition, InternationalFont internationalFont, int printDensityDpmm)
{
if (element is ZplBarcodeUpcExtension barcode)
{
float x = barcode.PositionX;
float y = barcode.PositionY;
if (barcode.UseDefaultPosition)
{
x = currentPosition.X;
y = currentPosition.Y;
}
string content = barcode.Content;
if (barcode.HexadecimalIndicator is char hexIndicator)
{
content = content.ReplaceHexEscapes(hexIndicator, internationalFont);
}
if (content.Length <= 2)
{
// EAN-2
content = content.PadLeft(2, '0');
}
else
{
// EAN-5
content = content.PadLeft(5, '0').Substring(0, 5);
}
string interpretation = content;
bool[] data= UpcExtensionSymbology.Encode(content);
using SKBitmap resizedImage = BoolArrayToSKBitmap(data, barcode.Height, barcode.ModuleWidth);
byte[] png = resizedImage.Encode(SKEncodedImageFormat.Png, 100).ToArray();
this.DrawBarcode(png, x, y, resizedImage.Width, resizedImage.Height, barcode.FieldOrigin != null, barcode.FieldOrientation);
if (barcode.PrintInterpretationLine)
{
float labelFontSize = FontScale.GetBitmappedFontSize("A", Math.Min(barcode.ModuleWidth, 10), printDensityDpmm).Value;
SKTypeface labelTypeFace = options.FontManager.GetFont("A");
SKFont labelFont = new(labelTypeFace, labelFontSize);
this.DrawInterpretationLine(interpretation, labelFont, x, y, resizedImage.Width, resizedImage.Height, barcode.FieldOrigin != null, barcode.FieldOrientation, barcode.PrintInterpretationLineAboveCode, options);
}
return this.CalculateNextDefaultPosition(x, y, resizedImage.Width, resizedImage.Height, barcode.FieldOrigin != null, barcode.FieldOrientation, currentPosition);
}
return currentPosition;
}
}
}