Skip to content

Commit 52fc140

Browse files
author
Matteo Dell'Acqua
committed
Fix QR code positioning with barcode height set
1 parent a555a1d commit 52fc140

4 files changed

Lines changed: 38 additions & 5 deletions

File tree

src/BinaryKits.Zpl.Viewer/CommandAnalyzers/FieldDataZplCommandAnalyzer.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using BinaryKits.Zpl.Label;
22
using BinaryKits.Zpl.Label.Elements;
3+
using BinaryKits.Zpl.Viewer.Elements;
34
using BinaryKits.Zpl.Viewer.Models;
45

56
using System;
@@ -87,7 +88,7 @@ public override ZplElementBase Analyze(string zplCommand, VirtualPrinter virtual
8788
{
8889
(ErrorCorrectionLevel errorCorrection, string parsedText) = this.ParseQrCodeFieldData(qrCode, text);
8990
// N.B.: always pass Field Orientation Normal to QR codes; the ZPL II standard does not allow rotation
90-
return new ZplQrCode(parsedText, x, y, qrCode.Model, qrCode.MagnificationFactor, errorCorrection, qrCode.MaskValue, FieldOrientation.Normal, hexadecimalIndicator, bottomToTop, useDefaultPosition);
91+
return new ZplQrCodeViewer(parsedText, x, y, qrCode.Model, qrCode.MagnificationFactor, errorCorrection, qrCode.MaskValue, FieldOrientation.Normal, hexadecimalIndicator, bottomToTop, useDefaultPosition, virtualPrinter.BarcodeInfo.Height);
9192
}
9293
else if (virtualPrinter.NextElementFieldData is UpcABarcodeFieldData upcA)
9394
{

src/BinaryKits.Zpl.Viewer/CommandAnalyzers/QrCodeBarcodeZplCommandAnalyzer.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ public override ZplElementBase Analyze(string zplCommand, VirtualPrinter virtual
3030
{
3131
magnificationFactor = tmpint;
3232

33-
if (magnificationFactor > 10)
33+
if (magnificationFactor > 100)
3434
{
35-
//TODO: Add validation message max value is 10
36-
magnificationFactor = 10;
35+
// TODO: Add validation message max value is 100
36+
magnificationFactor = 100;
3737
}
3838
}
3939

src/BinaryKits.Zpl.Viewer/ElementDrawers/QrCodeElementDrawer.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using BinaryKits.Zpl.Label;
22
using BinaryKits.Zpl.Label.Elements;
3+
using BinaryKits.Zpl.Viewer.Elements;
34
using BinaryKits.Zpl.Viewer.Helpers;
45

56
using SkiaSharp;
@@ -55,6 +56,10 @@ public override SKPoint Draw(ZplElementBase element, DrawerOptions options, SKPo
5556
}
5657

5758
int verticalQuietZone = 10;
59+
if (qrcode is ZplQrCodeViewer qrCodeDrawing)
60+
{
61+
verticalQuietZone = qrCodeDrawing.VerticalQuietZone;
62+
}
5863

5964
QRCodeWriter writer = new();
6065
QrCodeEncodingOptions encodingOptions = new()
@@ -88,6 +93,5 @@ private static ZXing.QrCode.Internal.ErrorCorrectionLevel ConvertErrorCorrection
8893
_ => ZXing.QrCode.Internal.ErrorCorrectionLevel.M
8994
};
9095
}
91-
9296
}
9397
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using BinaryKits.Zpl.Label;
2+
using BinaryKits.Zpl.Label.Elements;
3+
4+
namespace BinaryKits.Zpl.Viewer.Elements
5+
{
6+
internal class ZplQrCodeViewer : ZplQrCode
7+
{
8+
internal int VerticalQuietZone { get; private set; }
9+
10+
public ZplQrCodeViewer(
11+
string content,
12+
int positionX,
13+
int positionY,
14+
int model,
15+
int magnificationFactor,
16+
ErrorCorrectionLevel errorCorrectionLevel,
17+
int maskValue,
18+
FieldOrientation fieldOrientation,
19+
char? hexadecimalIndicator,
20+
bool bottomToTop,
21+
bool useDefaultPosition,
22+
int verticalQuietZone)
23+
: base(content, positionX, positionY, model, magnificationFactor, errorCorrectionLevel, maskValue, fieldOrientation, hexadecimalIndicator, bottomToTop, useDefaultPosition)
24+
{
25+
this.VerticalQuietZone = verticalQuietZone;
26+
}
27+
}
28+
}

0 commit comments

Comments
 (0)