Skip to content

Commit cb8b70e

Browse files
authored
Implement ^FW (#240)
1 parent 6b6272b commit cb8b70e

File tree

7 files changed

+67
-9
lines changed

7 files changed

+67
-9
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System.Collections.Generic;
2+
3+
namespace BinaryKits.Zpl.Label.Elements
4+
{
5+
/// <summary>
6+
/// ^FW - Field Orientation
7+
/// </summary>
8+
public class ZplFieldOrientation : ZplElementBase
9+
{
10+
public FieldOrientation FieldOrientation { get; private set; }
11+
12+
public ZplFieldOrientation(FieldOrientation fieldOrientation)
13+
{
14+
this.FieldOrientation = fieldOrientation;
15+
}
16+
17+
///<inheritdoc/>
18+
public override IEnumerable<string> Render(ZplRenderOptions context)
19+
{
20+
return new[] { $"^FW{RenderFieldOrientation(this.FieldOrientation)}" };
21+
}
22+
23+
}
24+
}

src/BinaryKits.Zpl.Viewer.WebApi/Labels/Test/FieldDataText2-102x152.zpl2

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,33 @@
11
^XA
22

33
^LH0,0
4+
^FWI
45

5-
^A0N,50,0
6+
^A0,50,0
67
^FO10,0
78
^FDFont1 Demo Text^FS
89

9-
^A1N,50,0
10+
^A1,50,0
1011
^FO10,100
1112
^FDFont2 Demo Text^FS
1213

13-
^AAN,80,0
14+
^AA,80,0
1415
^FO10,200
1516
^FDFont3 Demo Text^FS
1617

17-
^ABN,50,0
18+
^AB,50,0
1819
^FO10,300
1920
^FDFont4 Demo Text^FS
2021

21-
^ACN,20,0
22+
^AC,20,0
2223
^FO10,400
2324
^FDFont5 Demo Text^FS
2425

25-
^ADN,0,20
26+
^AD,0,20
2627
^FO10,500
2728
^FDFont6 Demo Text^FS
2829

29-
^ADN,20,20
30+
^AD,20,20
3031
^FO10,600
3132
^FDFont7 Demo Text^FS
3233

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,9 @@ private ZplFont GetFontFromVirtualPrinter()
206206
int fontWidth = this.VirtualPrinter.FontWidth;
207207
int fontHeight = this.VirtualPrinter.FontHeight;
208208
string fontName = this.VirtualPrinter.FontName;
209+
var fieldOrientation = this.VirtualPrinter.FieldOrientation;
209210

210-
return new ZplFont(fontWidth, fontHeight, fontName);
211+
return new ZplFont(fontWidth, fontHeight, fontName, fieldOrientation);
211212
}
212213

213214
private ZplFont GetNextFontFromVirtualPrinter()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using BinaryKits.Zpl.Label.Elements;
2+
3+
namespace BinaryKits.Zpl.Viewer.CommandAnalyzers
4+
{
5+
public class FieldOrientationZplCommandAnalyzer : ZplCommandAnalyzerBase
6+
{
7+
public FieldOrientationZplCommandAnalyzer(VirtualPrinter virtualPrinter) : base("^FW", virtualPrinter) { }
8+
9+
///<inheritdoc/>
10+
public override ZplElementBase Analyze(string zplCommand)
11+
{
12+
var zplDataParts = this.SplitCommand(zplCommand);
13+
if (zplDataParts.Length > 0)
14+
{
15+
var fieldOrientation = ConvertFieldOrientation(zplDataParts[0]);
16+
this.VirtualPrinter.SetFieldOrientation(fieldOrientation);
17+
}
18+
19+
return null;
20+
}
21+
}
22+
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ protected FieldOrientation ConvertFieldOrientation(string fieldOrientation)
3737
"R" => FieldOrientation.Rotated90,
3838
"I" => FieldOrientation.Rotated180,
3939
"B" => FieldOrientation.Rotated270,
40-
_ => FieldOrientation.Normal,
40+
_ => this.VirtualPrinter.FieldOrientation,
4141
};
4242
}
4343

src/BinaryKits.Zpl.Viewer/VirtualPrinter.cs

+9
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public class VirtualPrinter
1010
public LabelPosition NextElementPosition { get; private set; }
1111
public FieldDataBase NextElementFieldData { get; private set; }
1212
public FieldBlock NextElementFieldBlock { get; private set; }
13+
public FieldOrientation FieldOrientation { get; private set; } = FieldOrientation.Normal;
1314
public int FontWidth { get; private set; } = 0;
1415
public int FontHeight { get; private set; } = 10;
1516
public string FontName { get; private set; } = "0";
@@ -103,6 +104,14 @@ public void ClearNextElementFieldUseHexadecimalIndicator()
103104
this.NextElementFieldUseHexadecimalIndicator = false;
104105
}
105106

107+
public void SetFieldOrientation(FieldOrientation fieldOrientation) {
108+
this.FieldOrientation = fieldOrientation;
109+
if (this.NextFont != null)
110+
{
111+
this.SetNextFont(this.NextFont.FontName, fieldOrientation, this.NextFont.FontWidth, this.NextFont.FontHeight);
112+
}
113+
}
114+
106115
public void SetFontWidth(int fontWidth)
107116
{
108117
this.FontWidth = fontWidth;

src/BinaryKits.Zpl.Viewer/ZplAnalyzer.cs

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public AnalyzeInfo Analyze(string zplData)
5050
new DownloadObjectsZplCommandAnaylzer(this._virtualPrinter, this._printerStorage),
5151
new FieldBlockZplCommandAnalyzer(this._virtualPrinter),
5252
new FieldHexadecimalZplCommandAnalyzer(this._virtualPrinter),
53+
new FieldOrientationZplCommandAnalyzer(this._virtualPrinter),
5354
new FieldNumberCommandAnalyzer(this._virtualPrinter),
5455
new FieldVariableZplCommandAnalyzer(this._virtualPrinter),
5556
new FieldReversePrintZplCommandAnalyzer(this._virtualPrinter),

0 commit comments

Comments
 (0)