Skip to content

Commit

Permalink
Apply RecallFieldNumber to current template (#235)
Browse files Browse the repository at this point in the history
  • Loading branch information
primo-ppcg authored May 13, 2024
1 parent d6b7903 commit 3482955
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
11 changes: 11 additions & 0 deletions src/BinaryKits.Zpl.Viewer.WebApi/Labels/Test/Format2-54x86.zpl2
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
^XA
^DFFORMAT^FS
^BY2,3.0^FO40,40^BCN,80,Y,,,A^FR^FN1^FS
^BY2,3.0^FO40,160^BCN,80,Y,,,A^FR^FN2^FS
^FN1^FD12345^FS
^XZ

^XA
^XFFORMAT.ZPL
^FN2^FDABC12345^FS
^XZ
21 changes: 16 additions & 5 deletions src/BinaryKits.Zpl.Viewer/FormatMerger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,27 @@ private static List<ZplElementBase> GetMergedElements(
{
var elements = new List<ZplElementBase>();

foreach (ZplElementBase element in rawLabelInfo.ZplElements)
foreach (ZplElementBase zplElement in rawLabelInfo.ZplElements)
{
if (element is ZplRecallFormat recallFormat)
if (zplElement is ZplRecallFormat recallFormat)
{
LabelInfo formatLabelInfo = GetFormatLabelInfo(recallFormat, templateFormats);
elements.AddRange(GetMergedElements(rawLabelInfo, formatLabelInfo));
}
else if (element is not ZplRecallFieldNumber)
else if (zplElement is ZplRecallFieldNumber recallFieldNumber)
{
elements.Add(element);
for(int i = 0; i < elements.Count; i++)
{
if (elements[i] is ZplFieldNumber fieldNumber && fieldNumber.Number == recallFieldNumber.Number)
{
((IFormatElement)fieldNumber.FormatElement).SetTemplateContent(recallFieldNumber.Text);
elements[i] = fieldNumber.FormatElement;
}
}
}
else
{
elements.Add(zplElement);
}
}

Expand Down Expand Up @@ -103,4 +114,4 @@ private static IEnumerable<ZplElementBase> GetMergedElements(
}
}
}
}
}

0 comments on commit 3482955

Please sign in to comment.