templates tested
This commit is contained in:
@@ -145,15 +145,36 @@ public class TemplateRenderer
|
||||
var evaluator = new ExpressionEvaluator(context);
|
||||
int effectiveWidth = row.Big ? _bigFontLineWidth : _lineWidth;
|
||||
|
||||
var columnData = row.Columns.Select(c => (
|
||||
text: evaluator.Evaluate(c.Text ?? ""),
|
||||
width: c.Width ?? 0,
|
||||
align: c.Align
|
||||
)).ToList();
|
||||
bool anyWrap = row.Columns.Any(c => c.Wrap);
|
||||
|
||||
string text = _layout.FormatMultiColumn(columnData, effectiveWidth);
|
||||
var cmd = CreateCommand(text, row.Bold, row.Big, row.Tall, row.Red, row.LineSpacing);
|
||||
commands.Add(cmd);
|
||||
if (anyWrap)
|
||||
{
|
||||
var columnData = row.Columns.Select(c => (
|
||||
text: evaluator.Evaluate(c.Text ?? ""),
|
||||
width: ResolveColumnWidth(c, effectiveWidth),
|
||||
align: c.Align,
|
||||
wrap: c.Wrap
|
||||
)).ToList();
|
||||
|
||||
var lines = _layout.FormatMultiColumnWithWrap(columnData, effectiveWidth);
|
||||
foreach (var line in lines)
|
||||
{
|
||||
var cmd = CreateCommand(line, row.Bold, row.Big, row.Tall, row.Red, row.LineSpacing);
|
||||
commands.Add(cmd);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var columnData = row.Columns.Select(c => (
|
||||
text: evaluator.Evaluate(c.Text ?? ""),
|
||||
width: ResolveColumnWidth(c, effectiveWidth),
|
||||
align: c.Align
|
||||
)).ToList();
|
||||
|
||||
string text = _layout.FormatMultiColumn(columnData, effectiveWidth);
|
||||
var cmd = CreateCommand(text, row.Bold, row.Big, row.Tall, row.Red, row.LineSpacing);
|
||||
commands.Add(cmd);
|
||||
}
|
||||
}
|
||||
|
||||
private void RenderSeparator(SeparatorNode separator, List<PrintCommand> commands)
|
||||
@@ -199,9 +220,10 @@ public class TemplateRenderer
|
||||
{
|
||||
var evaluator = new ExpressionEvaluator(context);
|
||||
|
||||
int tableContentWidth = _lineWidth - table.Columns.Count - 1;
|
||||
var columnDefs = table.Columns.Select(c => (
|
||||
text: evaluator.Evaluate(c.Text ?? ""),
|
||||
width: c.Width ?? 0,
|
||||
width: ResolveColumnWidth(c, tableContentWidth),
|
||||
align: c.Align
|
||||
)).ToList();
|
||||
|
||||
@@ -267,13 +289,21 @@ public class TemplateRenderer
|
||||
}
|
||||
}
|
||||
|
||||
var lines = _layout.FormatTable(columnDefs, headerRows, dataRows, _lineWidth);
|
||||
var wrapFlags = table.Columns.Select(c => c.Wrap).ToList();
|
||||
var lines = _layout.FormatTable(columnDefs, headerRows, dataRows, _lineWidth, wrapFlags);
|
||||
foreach (var line in lines)
|
||||
{
|
||||
commands.Add(new PrintCommand(line));
|
||||
}
|
||||
}
|
||||
|
||||
private static int ResolveColumnWidth(ColumnDef col, int availableWidth)
|
||||
{
|
||||
if (col.Width.HasValue) return col.Width.Value;
|
||||
if (col.WidthPercent.HasValue) return (int)(availableWidth * col.WidthPercent.Value / 100.0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
private static PrintCommand CreateCommand(string text, bool bold, bool big, bool tall, bool red, int? lineSpacing)
|
||||
{
|
||||
return new PrintCommand(text, isBig: big, isBold: bold)
|
||||
|
||||
Reference in New Issue
Block a user