Skip to content

Commit

Permalink
Implement ^FW (#240)
Browse files Browse the repository at this point in the history
  • Loading branch information
primo-ppcg authored May 20, 2024
1 parent 6b6272b commit cb8b70e
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 9 deletions.
24 changes: 24 additions & 0 deletions src/BinaryKits.Zpl.Label/Elements/ZplFieldOrientation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System.Collections.Generic;

namespace BinaryKits.Zpl.Label.Elements
{
/// <summary>
/// ^FW - Field Orientation
/// </summary>
public class ZplFieldOrientation : ZplElementBase
{
public FieldOrientation FieldOrientation { get; private set; }

public ZplFieldOrientation(FieldOrientation fieldOrientation)
{
this.FieldOrientation = fieldOrientation;
}

///<inheritdoc/>
public override IEnumerable<string> Render(ZplRenderOptions context)
{
return new[] { $"^FW{RenderFieldOrientation(this.FieldOrientation)}" };
}

}
}
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
^XA

^LH0,0
^FWI

^A0N,50,0
^A0,50,0
^FO10,0
^FDFont1 Demo Text^FS

^A1N,50,0
^A1,50,0
^FO10,100
^FDFont2 Demo Text^FS

^AAN,80,0
^AA,80,0
^FO10,200
^FDFont3 Demo Text^FS

^ABN,50,0
^AB,50,0
^FO10,300
^FDFont4 Demo Text^FS

^ACN,20,0
^AC,20,0
^FO10,400
^FDFont5 Demo Text^FS

^ADN,0,20
^AD,0,20
^FO10,500
^FDFont6 Demo Text^FS

^ADN,20,20
^AD,20,20
^FO10,600
^FDFont7 Demo Text^FS

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,9 @@ private ZplFont GetFontFromVirtualPrinter()
int fontWidth = this.VirtualPrinter.FontWidth;
int fontHeight = this.VirtualPrinter.FontHeight;
string fontName = this.VirtualPrinter.FontName;
var fieldOrientation = this.VirtualPrinter.FieldOrientation;

return new ZplFont(fontWidth, fontHeight, fontName);
return new ZplFont(fontWidth, fontHeight, fontName, fieldOrientation);
}

private ZplFont GetNextFontFromVirtualPrinter()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using BinaryKits.Zpl.Label.Elements;

namespace BinaryKits.Zpl.Viewer.CommandAnalyzers
{
public class FieldOrientationZplCommandAnalyzer : ZplCommandAnalyzerBase
{
public FieldOrientationZplCommandAnalyzer(VirtualPrinter virtualPrinter) : base("^FW", virtualPrinter) { }

///<inheritdoc/>
public override ZplElementBase Analyze(string zplCommand)
{
var zplDataParts = this.SplitCommand(zplCommand);
if (zplDataParts.Length > 0)
{
var fieldOrientation = ConvertFieldOrientation(zplDataParts[0]);
this.VirtualPrinter.SetFieldOrientation(fieldOrientation);
}

return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected FieldOrientation ConvertFieldOrientation(string fieldOrientation)
"R" => FieldOrientation.Rotated90,
"I" => FieldOrientation.Rotated180,
"B" => FieldOrientation.Rotated270,
_ => FieldOrientation.Normal,
_ => this.VirtualPrinter.FieldOrientation,
};
}

Expand Down
9 changes: 9 additions & 0 deletions src/BinaryKits.Zpl.Viewer/VirtualPrinter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class VirtualPrinter
public LabelPosition NextElementPosition { get; private set; }
public FieldDataBase NextElementFieldData { get; private set; }
public FieldBlock NextElementFieldBlock { get; private set; }
public FieldOrientation FieldOrientation { get; private set; } = FieldOrientation.Normal;
public int FontWidth { get; private set; } = 0;
public int FontHeight { get; private set; } = 10;
public string FontName { get; private set; } = "0";
Expand Down Expand Up @@ -103,6 +104,14 @@ public void ClearNextElementFieldUseHexadecimalIndicator()
this.NextElementFieldUseHexadecimalIndicator = false;
}

public void SetFieldOrientation(FieldOrientation fieldOrientation) {
this.FieldOrientation = fieldOrientation;
if (this.NextFont != null)
{
this.SetNextFont(this.NextFont.FontName, fieldOrientation, this.NextFont.FontWidth, this.NextFont.FontHeight);
}
}

public void SetFontWidth(int fontWidth)
{
this.FontWidth = fontWidth;
Expand Down
1 change: 1 addition & 0 deletions src/BinaryKits.Zpl.Viewer/ZplAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public AnalyzeInfo Analyze(string zplData)
new DownloadObjectsZplCommandAnaylzer(this._virtualPrinter, this._printerStorage),
new FieldBlockZplCommandAnalyzer(this._virtualPrinter),
new FieldHexadecimalZplCommandAnalyzer(this._virtualPrinter),
new FieldOrientationZplCommandAnalyzer(this._virtualPrinter),
new FieldNumberCommandAnalyzer(this._virtualPrinter),
new FieldVariableZplCommandAnalyzer(this._virtualPrinter),
new FieldReversePrintZplCommandAnalyzer(this._virtualPrinter),
Expand Down

0 comments on commit cb8b70e

Please sign in to comment.