templates tested
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using System.Globalization;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Inspectron.Epson.TemplateEngine.Parsing;
|
||||
@@ -92,9 +93,10 @@ public class TemplateParser
|
||||
var col = new ColumnDef
|
||||
{
|
||||
Text = GetTextContent(colElement),
|
||||
Width = GetNullableIntAttr(colElement, "width"),
|
||||
Align = GetAttr(colElement, "align", "left")
|
||||
Align = GetAttr(colElement, "align", "left"),
|
||||
Wrap = GetBoolAttr(colElement, "wrap")
|
||||
};
|
||||
ParseColumnWidth(colElement, col);
|
||||
node.Columns.Add(col);
|
||||
}
|
||||
|
||||
@@ -158,9 +160,10 @@ public class TemplateParser
|
||||
var col = new ColumnDef
|
||||
{
|
||||
Text = GetTextContent(colElement),
|
||||
Width = GetNullableIntAttr(colElement, "width"),
|
||||
Align = GetAttr(colElement, "align", "left")
|
||||
Align = GetAttr(colElement, "align", "left"),
|
||||
Wrap = GetBoolAttr(colElement, "wrap")
|
||||
};
|
||||
ParseColumnWidth(colElement, col);
|
||||
node.Columns.Add(col);
|
||||
}
|
||||
|
||||
@@ -247,4 +250,22 @@ public class TemplateParser
|
||||
if (attr == null) return null;
|
||||
return int.TryParse(attr.Value, out var v) ? v : null;
|
||||
}
|
||||
|
||||
private static void ParseColumnWidth(XElement element, ColumnDef col)
|
||||
{
|
||||
var attr = element.Attribute("width");
|
||||
if (attr == null) return;
|
||||
|
||||
var value = attr.Value.Trim();
|
||||
if (value.EndsWith('%'))
|
||||
{
|
||||
if (double.TryParse(value[..^1], NumberStyles.Float, CultureInfo.InvariantCulture, out var pct))
|
||||
col.WidthPercent = pct;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (int.TryParse(value, out var w))
|
||||
col.Width = w;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user