OnePerMeterPrintDocument changes.
This commit is contained in:
parent
7465f23809
commit
615b3409be
@ -374,6 +374,13 @@ namespace Config.Entities
|
|||||||
Count
|
Count
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum VertAlignment
|
||||||
|
{
|
||||||
|
[Description("Top")] Top,
|
||||||
|
[Description("Middle")] Middle,
|
||||||
|
[Description("Bottom")] Bottom,
|
||||||
|
}
|
||||||
|
|
||||||
public enum ImageRotation
|
public enum ImageRotation
|
||||||
{
|
{
|
||||||
[Description("0 deg")] None,
|
[Description("0 deg")] None,
|
||||||
|
|||||||
@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
|
|||||||
// You can specify all the values or you can default the Build and Revision Numbers
|
// You can specify all the values or you can default the Build and Revision Numbers
|
||||||
// by using the '*' as shown below:
|
// by using the '*' as shown below:
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
[assembly: AssemblyVersion("2.18.797.0")]
|
[assembly: AssemblyVersion("2.18.827.0")]
|
||||||
[assembly: AssemblyFileVersion("2.18.797.0")]
|
[assembly: AssemblyFileVersion("2.18.827.0")]
|
||||||
|
|||||||
@ -11,7 +11,7 @@ using Results.Resources;
|
|||||||
|
|
||||||
namespace Results.Output.Printers.OnePerMeter
|
namespace Results.Output.Printers.OnePerMeter
|
||||||
{
|
{
|
||||||
public class OnePerMeterPrintDocument : PrintDocument
|
public class OnePerMeterPrintDocument : PrintersCommon
|
||||||
{
|
{
|
||||||
const float GapBetweenTableColumns = 10;
|
const float GapBetweenTableColumns = 10;
|
||||||
const float GapBetweenCommonColumns = 10;
|
const float GapBetweenCommonColumns = 10;
|
||||||
@ -198,53 +198,92 @@ namespace Results.Output.Printers.OnePerMeter
|
|||||||
/// Write aligned columns
|
/// Write aligned columns
|
||||||
for (int i = 0; i < Math.Min(leftColumn.Length, rightColumn.Length); i++)
|
for (int i = 0; i < Math.Min(leftColumn.Length, rightColumn.Length); i++)
|
||||||
{
|
{
|
||||||
PrintAt(e, leftMargin, commonTop + spacingOne * i, maxWidth, leftColumn[i], font, Alignment.Left);
|
PrintAt(e, leftColumn[i], font, leftMargin, commonTop + spacingOne * i, maxWidth, 0, Alignment.Left, VertAlignment.Top);
|
||||||
PrintAt(e, leftMargin + maxWidth + GapBetweenCommonColumns, commonTop + spacingOne * i, 0, rightColumn[i], font, Alignment.Left);
|
PrintAt(e, rightColumn[i], font, leftMargin + maxWidth + GapBetweenCommonColumns, commonTop + spacingOne * i, 0, 0, Alignment.Left, VertAlignment.Top);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Body
|
/// Body
|
||||||
///
|
///
|
||||||
|
IList<string[]> tableRows;
|
||||||
|
IList<Alignment[]> horizAlignment;
|
||||||
|
IList<VertAlignment[]> vertAlignment;
|
||||||
if (pageNr == 1)
|
if (pageNr == 1)
|
||||||
{
|
{
|
||||||
string[] tableHeader;
|
|
||||||
IList<string[]> tableRows;
|
|
||||||
Alignment[] itemAlignment;
|
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Prepare table content: tableHeader + tableRows + itemAlignment
|
/// Prepare table content: tableHeader + tableRows + itemAlignment
|
||||||
///
|
///
|
||||||
if (cfg.TestsAreRows)
|
if (cfg.TestsAreRows)
|
||||||
{
|
{
|
||||||
GetContentTestsAreRows(wm, testItems, out tableHeader, out tableRows, out itemAlignment);
|
GetContentTestsAreRows(wm, testItems, out tableRows, out horizAlignment, out vertAlignment);
|
||||||
|
DrawTable(e, (float)leftMargin, bodyTop, tableRows, horizAlignment, vertAlignment,
|
||||||
|
new TableStyle
|
||||||
|
{
|
||||||
|
Font = font,
|
||||||
|
HeaderFont = headerFont,
|
||||||
|
MarginX = 5,
|
||||||
|
MarginY = 3,
|
||||||
|
LineWidth = 1,
|
||||||
|
TopHeadersCount = 1,
|
||||||
|
HorizLines = TableLines.All,
|
||||||
|
VertLines = TableLines.All
|
||||||
|
});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
GetContentTestsAreColumns(wm, testItems, out tableHeader, out tableRows, out itemAlignment);
|
GetContentTestsAreColumns(wm, testItems, out tableRows, out horizAlignment, out vertAlignment);
|
||||||
|
DrawTable(e, (float)leftMargin, bodyTop, tableRows, horizAlignment, vertAlignment,
|
||||||
|
new TableStyle
|
||||||
|
{
|
||||||
|
Font = font,
|
||||||
|
HeaderFont = headerFont,
|
||||||
|
MarginX = 5,
|
||||||
|
MarginY = 3,
|
||||||
|
LineWidth = 1,
|
||||||
|
LeftHeadersCount = 1,
|
||||||
|
HorizLines = TableLines.All,
|
||||||
|
VertLines = TableLines.All
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
DrawTable(e, (float)leftMargin, bodyTop, tableHeader, tableRows, itemAlignment);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
string[] tableHeader;
|
|
||||||
IList<string[]> tableRows;
|
|
||||||
Alignment[] itemAlignment;
|
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Prepare table content: tableHeader + tableRows + itemAlignment
|
/// Prepare table content: tableHeader + tableRows + itemAlignment
|
||||||
///
|
///
|
||||||
if (cfg.TestsAreRows2)
|
if (cfg.TestsAreRows2)
|
||||||
{
|
{
|
||||||
GetContentTestsAreRows(wm, testItems2, out tableHeader, out tableRows, out itemAlignment);
|
GetContentTestsAreRows(wm, testItems2, out tableRows, out horizAlignment, out vertAlignment);
|
||||||
|
DrawTable(e, (float)leftMargin, bodyTop, tableRows, horizAlignment, vertAlignment,
|
||||||
|
new TableStyle
|
||||||
|
{
|
||||||
|
Font = font,
|
||||||
|
HeaderFont = headerFont,
|
||||||
|
MarginX = 5,
|
||||||
|
MarginY = 3,
|
||||||
|
LineWidth = 1,
|
||||||
|
TopHeadersCount = 1,
|
||||||
|
HorizLines = TableLines.All,
|
||||||
|
VertLines = TableLines.All
|
||||||
|
});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
GetContentTestsAreColumns(wm, testItems2, out tableHeader, out tableRows, out itemAlignment);
|
GetContentTestsAreColumns(wm, testItems2, out tableRows, out horizAlignment, out vertAlignment);
|
||||||
|
DrawTable(e, (float)leftMargin, bodyTop, tableRows, horizAlignment, vertAlignment,
|
||||||
|
new TableStyle
|
||||||
|
{
|
||||||
|
Font = font,
|
||||||
|
HeaderFont = headerFont,
|
||||||
|
MarginX = 5,
|
||||||
|
MarginY = 3,
|
||||||
|
LineWidth = 1,
|
||||||
|
LeftHeadersCount = 1,
|
||||||
|
HorizLines = TableLines.All,
|
||||||
|
VertLines = TableLines.All
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
DrawTable(e, (float)leftMargin, (float)topMargin, tableHeader, tableRows, itemAlignment);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pageNr == nrPages)
|
if (pageNr == nrPages)
|
||||||
@ -253,7 +292,7 @@ namespace Results.Output.Printers.OnePerMeter
|
|||||||
/// Footer on the last page
|
/// Footer on the last page
|
||||||
///
|
///
|
||||||
float footerWidth = e.Graphics.MeasureString(footer, footerFont).Width;
|
float footerWidth = e.Graphics.MeasureString(footer, footerFont).Width;
|
||||||
PrintAt(e, leftMargin, topMargin + printHeight - 2 * spacingOne, 0, footer, footerFont, Alignment.Left);
|
PrintAt(e, footer, footerFont, leftMargin, topMargin + printHeight - 2 * spacingOne, 0, 0, Alignment.Left, VertAlignment.Top);
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
@ -261,7 +300,7 @@ namespace Results.Output.Printers.OnePerMeter
|
|||||||
///
|
///
|
||||||
string pageNrText = string.Format("{0} {1}/{2}", Strings.Page, pageNr, nrPages);
|
string pageNrText = string.Format("{0} {1}/{2}", Strings.Page, pageNr, nrPages);
|
||||||
float pageNrWidth = e.Graphics.MeasureString(pageNrText, font).Width;
|
float pageNrWidth = e.Graphics.MeasureString(pageNrText, font).Width;
|
||||||
PrintAt(e, leftMargin + (printWidth - pageNrWidth) / 2, topMargin + printHeight - spacingOne, 0, pageNrText, font, Alignment.Left);
|
PrintAt(e, pageNrText, font, leftMargin + (printWidth - pageNrWidth) / 2, topMargin + printHeight - spacingOne, 0, 0, Alignment.Left, VertAlignment.Top);
|
||||||
|
|
||||||
e.HasMorePages = !(pageNr == nrPages);
|
e.HasMorePages = !(pageNr == nrPages);
|
||||||
|
|
||||||
@ -269,75 +308,104 @@ namespace Results.Output.Printers.OnePerMeter
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void GetContentTestsAreRows(Results.Entities.WaterMeter wm, IList<WMeterRsltItemSpec> items, out string[] tableHeader, out IList<string[]> tableRows, out Alignment[] itemAlignment)
|
void GetContentTestsAreRows(Results.Entities.WaterMeter wm, IList<WMeterRsltItemSpec> items,
|
||||||
|
out IList<string[]> tableRows, out IList<Alignment[]> horizAlignments, out IList<VertAlignment[]> vertAlignments)
|
||||||
{
|
{
|
||||||
|
/// Top row contains column captions
|
||||||
|
|
||||||
int tableColumnsCount = items.Count;
|
int tableColumnsCount = items.Count;
|
||||||
|
|
||||||
tableRows = new List<string[]>();
|
tableRows = new List<string[]>();
|
||||||
tableHeader = new string[tableColumnsCount];
|
horizAlignments = new List<Alignment[]>();
|
||||||
itemAlignment = new Alignment[tableColumnsCount];
|
vertAlignments = new List<VertAlignment[]>();
|
||||||
|
|
||||||
|
|
||||||
|
string[] tableHeader = new string[tableColumnsCount];
|
||||||
|
Alignment[] horizAlignment = new Alignment[tableColumnsCount];
|
||||||
|
VertAlignment[] vertAlignment = new VertAlignment[tableColumnsCount];
|
||||||
for (int i = 0; i < tableColumnsCount; i++)
|
for (int i = 0; i < tableColumnsCount; i++)
|
||||||
{
|
{
|
||||||
tableHeader[i] = items[i].Caption;
|
tableHeader[i] = items[i].Caption;
|
||||||
itemAlignment[i] = items[i].Alignment;
|
horizAlignment[i] = Alignment.Center;
|
||||||
|
vertAlignment[i] = VertAlignment.Middle;
|
||||||
}
|
}
|
||||||
|
tableRows.Add(tableHeader);
|
||||||
|
horizAlignments.Add(horizAlignment);
|
||||||
|
vertAlignments.Add(vertAlignment);
|
||||||
|
|
||||||
WMeterRsltItemSpec.TableRowNr = 0;
|
WMeterRsltItemSpec.TableRowNr = 1;
|
||||||
foreach (var mtr in wm.MeterTestRslts)
|
foreach (var mtr in wm.MeterTestRslts)
|
||||||
{
|
{
|
||||||
if (mtr != null && mtr.IsPilotRslt() && mtr.Publish() == Config.Entities.Publish.Always)
|
if (mtr != null && mtr.IsPilotRslt() && mtr.Publish() == Config.Entities.Publish.Always)
|
||||||
{
|
{
|
||||||
string[] oneTableRow = new string[tableColumnsCount];
|
string[] oneTableRow = new string[tableColumnsCount];
|
||||||
WMeterRsltItemSpec.TableRowNr++;
|
horizAlignment = new Alignment[tableColumnsCount];
|
||||||
|
vertAlignment = new VertAlignment[tableColumnsCount];
|
||||||
|
|
||||||
for (int i = 0; i < tableColumnsCount; i++)
|
for (int i = 0; i < tableColumnsCount; i++)
|
||||||
{
|
{
|
||||||
WMeterRsltItemSpec.TableColumnNr = i + 1;
|
WMeterRsltItemSpec.TableColumnNr = i + 1;
|
||||||
oneTableRow[i] = items[i].Print(wm, mtr.Name()).Split(new char[] { '|' })[0];
|
oneTableRow[i] = items[i].Print(wm, mtr.Name()).Split(new char[] { '|' })[0];
|
||||||
|
horizAlignment[i] = items[i].Alignment;
|
||||||
|
vertAlignment[i] = VertAlignment.Middle;
|
||||||
}
|
}
|
||||||
|
|
||||||
tableRows.Add(oneTableRow);
|
tableRows.Add(oneTableRow);
|
||||||
|
horizAlignments.Add(horizAlignment);
|
||||||
|
vertAlignments.Add(vertAlignment);
|
||||||
|
|
||||||
|
WMeterRsltItemSpec.TableRowNr++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void GetContentTestsAreColumns(Results.Entities.WaterMeter wm, IList<WMeterRsltItemSpec> items, out string[] tableHeader, out IList<string[]> tableRows, out Alignment[] itemAlignment)
|
void GetContentTestsAreColumns(Results.Entities.WaterMeter wm, IList<WMeterRsltItemSpec> items,
|
||||||
|
out IList<string[]> tableRows, out IList<Alignment[]> horizAlignments, out IList<VertAlignment[]> vertAlignments)
|
||||||
{
|
{
|
||||||
int tableColumnsCount = 1;
|
/// Left column contains row captions
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Calculate columns count
|
||||||
|
///
|
||||||
|
int tableColumnsCount = 1; /// Left column contains item caption
|
||||||
foreach (var mtr in wm.MeterTestRslts)
|
foreach (var mtr in wm.MeterTestRslts)
|
||||||
{
|
{
|
||||||
if (mtr != null && mtr.IsPilotRslt() && mtr.Publish() == Config.Entities.Publish.Always)
|
if (mtr != null && mtr.IsPilotRslt() && mtr.Publish() == Config.Entities.Publish.Always)
|
||||||
{
|
{
|
||||||
tableColumnsCount++;
|
tableColumnsCount++; /// One additional column for each test to be published
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Alignment of columns
|
||||||
|
///
|
||||||
tableRows = new List<string[]>();
|
tableRows = new List<string[]>();
|
||||||
tableHeader = new string[tableColumnsCount];
|
horizAlignments = new List<Alignment[]>();
|
||||||
itemAlignment = new Alignment[tableColumnsCount];
|
vertAlignments = new List<VertAlignment[]>();
|
||||||
|
|
||||||
tableHeader[0] = string.Empty;
|
|
||||||
itemAlignment[0] = Alignment.Left;
|
|
||||||
int columnsCount = 1;
|
int columnsCount = 1;
|
||||||
foreach (var mtr in wm.MeterTestRslts)
|
foreach (var mtr in wm.MeterTestRslts)
|
||||||
{
|
{
|
||||||
if (mtr != null && mtr.IsPilotRslt() && mtr.Publish() == Config.Entities.Publish.Always)
|
if (mtr != null && mtr.IsPilotRslt() && mtr.Publish() == Config.Entities.Publish.Always)
|
||||||
{
|
{
|
||||||
tableHeader[columnsCount] = mtr.Name();
|
|
||||||
itemAlignment[columnsCount] = Alignment.Left;
|
|
||||||
columnsCount++;
|
columnsCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
WMeterRsltItemSpec.TableRowNr = 0;
|
///
|
||||||
|
/// Table content
|
||||||
|
///
|
||||||
|
WMeterRsltItemSpec.TableRowNr = 1;
|
||||||
for (int i = 0; i < items.Count; i++)
|
for (int i = 0; i < items.Count; i++)
|
||||||
{
|
{
|
||||||
string[] oneTableRow = new string[tableColumnsCount];
|
string[] oneTableRow = new string[tableColumnsCount];
|
||||||
WMeterRsltItemSpec.TableRowNr++;
|
Alignment[] horizAlignment = new Alignment[tableColumnsCount];
|
||||||
|
VertAlignment[] vertAlignment = new VertAlignment[tableColumnsCount];
|
||||||
|
|
||||||
oneTableRow[0] = items[i].Caption;
|
oneTableRow[0] = items[i].Caption;
|
||||||
|
horizAlignment[0] = Alignment.Center;
|
||||||
|
vertAlignment[0] = VertAlignment.Middle;
|
||||||
|
|
||||||
WMeterRsltItemSpec.TableColumnNr = 1;
|
WMeterRsltItemSpec.TableColumnNr = 1;
|
||||||
foreach (var mtr in wm.MeterTestRslts)
|
foreach (var mtr in wm.MeterTestRslts)
|
||||||
@ -347,130 +415,18 @@ namespace Results.Output.Printers.OnePerMeter
|
|||||||
/// Strip color information
|
/// Strip color information
|
||||||
oneTableRow[WMeterRsltItemSpec.TableColumnNr] =
|
oneTableRow[WMeterRsltItemSpec.TableColumnNr] =
|
||||||
items[i].Print(wm, mtr.Name()).Split(new char[] { '|' })[0];
|
items[i].Print(wm, mtr.Name()).Split(new char[] { '|' })[0];
|
||||||
|
horizAlignment[WMeterRsltItemSpec.TableColumnNr] = items[i].Alignment;
|
||||||
|
vertAlignment[WMeterRsltItemSpec.TableColumnNr] = VertAlignment.Middle;
|
||||||
|
|
||||||
WMeterRsltItemSpec.TableColumnNr++;
|
WMeterRsltItemSpec.TableColumnNr++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tableRows.Add(oneTableRow);
|
tableRows.Add(oneTableRow);
|
||||||
}
|
horizAlignments.Add(horizAlignment);
|
||||||
}
|
vertAlignments.Add(vertAlignment);
|
||||||
|
|
||||||
|
WMeterRsltItemSpec.TableRowNr++;
|
||||||
float DrawTable(System.Drawing.Printing.PrintPageEventArgs e, float left, float top, string[] header, IList<string[]> rows, Alignment[] alignment)
|
|
||||||
{
|
|
||||||
int tblColumnsCount = header.Length;
|
|
||||||
|
|
||||||
float[] columnWidth = new float[tblColumnsCount];
|
|
||||||
float[] columnPos = new float[tblColumnsCount + 1];
|
|
||||||
columnPos[0] = left;
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Measure table column widths and header height
|
|
||||||
///
|
|
||||||
float headerHeight = 0;
|
|
||||||
for (int i = 0; i < tblColumnsCount; i++)
|
|
||||||
{
|
|
||||||
SizeF size = e.Graphics.MeasureString(header[i], headerFont);
|
|
||||||
columnWidth[i] = (int)(size.Width + 0.99f);
|
|
||||||
if (size.Height > headerHeight) headerHeight = (int)(size.Height + 0.99f);
|
|
||||||
|
|
||||||
foreach (var tableRow in rows)
|
|
||||||
{
|
|
||||||
int width = (int)(e.Graphics.MeasureString(tableRow[i], font).Width + 0.99f);
|
|
||||||
if (width > columnWidth[i]) columnWidth[i] = width;
|
|
||||||
}
|
|
||||||
columnPos[i + 1] = columnPos[i] + columnWidth[i] + GapBetweenTableColumns;
|
|
||||||
}
|
|
||||||
|
|
||||||
float tableLeftX = columnPos[0];
|
|
||||||
float tableRightX = columnPos[tblColumnsCount] - GapBetweenTableColumns;
|
|
||||||
|
|
||||||
/// Horizontal line
|
|
||||||
float horY = top + 1.5f * spacingOne4Header;
|
|
||||||
e.Graphics.DrawLine(new Pen(Color.Black, 2), new PointF(tableLeftX, horY), new PointF(tableRightX, horY));
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Draw table header
|
|
||||||
///
|
|
||||||
for (int i = 0; i < tblColumnsCount; i++)
|
|
||||||
{
|
|
||||||
PrintAt(e, columnPos[i],
|
|
||||||
top + 1.7f * spacingOne4Header,
|
|
||||||
columnWidth[i],
|
|
||||||
header[i],
|
|
||||||
headerFont,
|
|
||||||
Alignment.Center);
|
|
||||||
}
|
|
||||||
/// Horizontal line
|
|
||||||
horY = top + 2.1f * spacingOne4Header + headerHeight;
|
|
||||||
e.Graphics.DrawLine(new Pen(Color.Black, 2), new PointF(tableLeftX, horY), new PointF(tableRightX, horY));
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Draw table body
|
|
||||||
///
|
|
||||||
int rowsCount = 0;
|
|
||||||
foreach (var oneTableRow in rows)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < tblColumnsCount; i++)
|
|
||||||
{
|
|
||||||
PrintAt(e, columnPos[i],
|
|
||||||
horY + 0.2f * spacingOne4Header + spacingOne * rowsCount,
|
|
||||||
columnWidth[i],
|
|
||||||
oneTableRow[i],
|
|
||||||
font,
|
|
||||||
alignment[i]);
|
|
||||||
}
|
|
||||||
rowsCount++;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Horizontal line
|
|
||||||
horY = horY + spacingOne * rowsCount + (3 * spacingOne4Header / 10);
|
|
||||||
e.Graphics.DrawLine(new Pen(Color.Black, 2), new PointF(tableLeftX, horY), new PointF(tableRightX, horY));
|
|
||||||
|
|
||||||
return horY - top + spacingOne;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static Font lastFont = null;
|
|
||||||
static float lastSpacing = 0;
|
|
||||||
|
|
||||||
SizeF Measure(System.Drawing.Printing.PrintPageEventArgs e, string paragraph, Font font)
|
|
||||||
{
|
|
||||||
if (font != lastFont)
|
|
||||||
{
|
|
||||||
lastFont = font;
|
|
||||||
lastSpacing = e.Graphics.MeasureString("Abcgq", font).Height;
|
|
||||||
}
|
|
||||||
|
|
||||||
string[] lines = paragraph.Split(new char[] { '~' });
|
|
||||||
float width = 0;
|
|
||||||
foreach (var line in lines)
|
|
||||||
{
|
|
||||||
float lineWid = e.Graphics.MeasureString(line, font).Width;
|
|
||||||
if (lineWid > width) width = lineWid;
|
|
||||||
}
|
|
||||||
|
|
||||||
return new SizeF(width, 0.8f * lines.Length * lastSpacing + 0.2f);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void PrintAt(System.Drawing.Printing.PrintPageEventArgs e, float x, float y, float width, string paragraph, Font font, Alignment alignment)
|
|
||||||
{
|
|
||||||
SizeF size = Measure(e, paragraph, font);
|
|
||||||
|
|
||||||
string[] lines = paragraph.Split(new char[] { '~' });
|
|
||||||
foreach (var line in lines)
|
|
||||||
{
|
|
||||||
float xx;
|
|
||||||
switch (alignment)
|
|
||||||
{
|
|
||||||
default:
|
|
||||||
case Alignment.Left: xx = x; break;
|
|
||||||
case Alignment.Center: xx = x + (width - e.Graphics.MeasureString(line, font).Width) / 2; break;
|
|
||||||
case Alignment.Right: xx = x + width - e.Graphics.MeasureString(line, font).Width; break;
|
|
||||||
}
|
|
||||||
e.Graphics.DrawString(line, font, Brushes.Black, new PointF(xx, y));
|
|
||||||
y += 0.8f * lastSpacing;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
225
Results/Output/Printers/PrintersCommon.cs
Normal file
225
Results/Output/Printers/PrintersCommon.cs
Normal file
@ -0,0 +1,225 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Drawing.Printing;
|
||||||
|
using Config.Entities;
|
||||||
|
|
||||||
|
namespace Results.Output.Printers
|
||||||
|
{
|
||||||
|
public enum TableLines
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
FirstAndLast,
|
||||||
|
FirstSecondAndLast,
|
||||||
|
All,
|
||||||
|
}
|
||||||
|
|
||||||
|
public class TableStyle
|
||||||
|
{
|
||||||
|
public float MarginX;
|
||||||
|
public float MarginY;
|
||||||
|
public Font Font;
|
||||||
|
public Font HeaderFont;
|
||||||
|
public int TopHeadersCount;
|
||||||
|
public int LeftHeadersCount;
|
||||||
|
public float LineWidth;
|
||||||
|
public TableLines HorizLines;
|
||||||
|
public TableLines VertLines;
|
||||||
|
}
|
||||||
|
|
||||||
|
public class PrintersCommon : PrintDocument
|
||||||
|
{
|
||||||
|
protected SizeF MeasureTable(System.Drawing.Printing.PrintPageEventArgs e, IList<string[]> rows, TableStyle tableStyle)
|
||||||
|
{
|
||||||
|
SizeF retVal = new SizeF(0, 0);
|
||||||
|
|
||||||
|
if (rows == null || rows.Count == 0) return retVal;
|
||||||
|
|
||||||
|
int tblColumnsCount = rows[0].Length;
|
||||||
|
|
||||||
|
float[] columnWidth = new float[tblColumnsCount];
|
||||||
|
float[] rowHeight = new float[rows.Count];
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Measure table column widths and header height
|
||||||
|
///
|
||||||
|
for (int colIx = 0; colIx < tblColumnsCount; colIx++)
|
||||||
|
{
|
||||||
|
for (int rowIx = 0; rowIx < rows.Count; rowIx++)
|
||||||
|
{
|
||||||
|
bool isHeader = (colIx < tableStyle.LeftHeadersCount) || (rowIx < tableStyle.TopHeadersCount);
|
||||||
|
SizeF size = Measure(e, rows[rowIx][colIx], isHeader ? tableStyle.HeaderFont : tableStyle.Font);
|
||||||
|
if (size.Width > columnWidth[colIx]) columnWidth[colIx] = size.Width;
|
||||||
|
if (size.Height > rowHeight[rowIx]) rowHeight[rowIx] = size.Height;
|
||||||
|
}
|
||||||
|
retVal.Width += columnWidth[colIx] + 2 * tableStyle.MarginX;
|
||||||
|
}
|
||||||
|
for (int rowIx = 0; rowIx < rows.Count; rowIx++)
|
||||||
|
{
|
||||||
|
retVal.Height += rowHeight[rowIx] + 2 * tableStyle.MarginY;
|
||||||
|
}
|
||||||
|
|
||||||
|
return retVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected float DrawTable(System.Drawing.Printing.PrintPageEventArgs e, float left, float top, IList<string[]> rows,
|
||||||
|
IList<Alignment[]> horizAlignments, IList<VertAlignment[]> vertAlignments, TableStyle tableStyle)
|
||||||
|
{
|
||||||
|
if (rows == null || rows.Count == 0) return top;
|
||||||
|
|
||||||
|
int tblColumnsCount = rows[0].Length;
|
||||||
|
float[] columnWidth = new float[tblColumnsCount];
|
||||||
|
float[] columnPos = new float[tblColumnsCount + 1];
|
||||||
|
float[] rowHeight = new float[rows.Count];
|
||||||
|
float[] rowPos = new float[rows.Count + 1];
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Measure table column widths and header height
|
||||||
|
///
|
||||||
|
columnPos[0] = left;
|
||||||
|
rowPos[0] = top;
|
||||||
|
for (int colIx = 0; colIx < tblColumnsCount; colIx++)
|
||||||
|
{
|
||||||
|
for (int rowIx = 0; rowIx < rows.Count; rowIx++)
|
||||||
|
{
|
||||||
|
bool isHeader = (colIx < tableStyle.LeftHeadersCount) || (rowIx < tableStyle.TopHeadersCount);
|
||||||
|
SizeF size = Measure(e, rows[rowIx][colIx], isHeader ? tableStyle.HeaderFont : tableStyle.Font);
|
||||||
|
if (size.Width > columnWidth[colIx]) columnWidth[colIx] = size.Width;
|
||||||
|
if (size.Height > rowHeight[rowIx]) rowHeight[rowIx] = size.Height;
|
||||||
|
}
|
||||||
|
columnPos[colIx + 1] = columnPos[colIx] + columnWidth[colIx] + 2 * tableStyle.MarginX + tableStyle.LineWidth;
|
||||||
|
}
|
||||||
|
for (int rowIx = 0; rowIx < rows.Count; rowIx++)
|
||||||
|
{
|
||||||
|
rowPos[rowIx + 1] = rowPos[rowIx] + rowHeight[rowIx] + 2 * tableStyle.MarginY + tableStyle.LineWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Horizontal lines
|
||||||
|
float tableLeftX = left;
|
||||||
|
float tableRightX = columnPos[tblColumnsCount] + tableStyle.LineWidth;
|
||||||
|
if (tableStyle.HorizLines != TableLines.None)
|
||||||
|
{
|
||||||
|
for (int rowIx = 0; rowIx <= rows.Count; rowIx++)
|
||||||
|
{
|
||||||
|
if (tableStyle.HorizLines == TableLines.All || rowIx == 0 || rowIx == rows.Count || (tableStyle.HorizLines == TableLines.FirstSecondAndLast && rowIx == 1))
|
||||||
|
{
|
||||||
|
e.Graphics.DrawLine(new Pen(Color.Black, tableStyle.LineWidth), new PointF(tableLeftX, rowPos[rowIx] + tableStyle.LineWidth / 2), new PointF(tableRightX, rowPos[rowIx] + tableStyle.LineWidth / 2));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Vertical lines
|
||||||
|
float tableTopY = top;
|
||||||
|
float tableBottomY = rowPos[rows.Count] + tableStyle.LineWidth;
|
||||||
|
if (tableStyle.VertLines != TableLines.None)
|
||||||
|
{
|
||||||
|
for (int colIx = 0; colIx <= tblColumnsCount; colIx++)
|
||||||
|
{
|
||||||
|
if (tableStyle.VertLines == TableLines.All || colIx == 0 || colIx == rows.Count || (tableStyle.VertLines == TableLines.FirstSecondAndLast && colIx == 1))
|
||||||
|
{
|
||||||
|
e.Graphics.DrawLine(new Pen(Color.Black, tableStyle.LineWidth), new PointF(columnPos[colIx] + tableStyle.LineWidth / 2, tableTopY), new PointF(columnPos[colIx] + tableStyle.LineWidth / 2, tableBottomY));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Draw table body
|
||||||
|
///
|
||||||
|
for (int rowIndex = 0; rowIndex < rows.Count; rowIndex++)
|
||||||
|
{
|
||||||
|
string[] oneTableRow = rows[rowIndex];
|
||||||
|
Alignment[] horizAlignment = horizAlignments[(horizAlignments.Count > rowIndex) ? rowIndex : 0];
|
||||||
|
VertAlignment[] vertAlignment = vertAlignments[(vertAlignments.Count > rowIndex) ? rowIndex : 0];
|
||||||
|
for (int colIndex = 0; colIndex < tblColumnsCount; colIndex++)
|
||||||
|
{
|
||||||
|
bool isHeader = (colIndex < tableStyle.LeftHeadersCount) || (rowIndex < tableStyle.TopHeadersCount);
|
||||||
|
PrintAt(e, oneTableRow[colIndex],
|
||||||
|
isHeader ? tableStyle.HeaderFont : tableStyle.Font,
|
||||||
|
columnPos[colIndex] + tableStyle.MarginX + tableStyle.LineWidth,
|
||||||
|
rowPos[rowIndex] + tableStyle.MarginY,
|
||||||
|
columnWidth[colIndex],
|
||||||
|
rowHeight[rowIndex],
|
||||||
|
horizAlignment[colIndex],
|
||||||
|
vertAlignment[colIndex]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return tableBottomY;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static Font lastFont = null;
|
||||||
|
static float lastSpacing = 0;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Measure the size of a paragraph of text, lines are separated by '~'.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="e">PrintPageEventArgs</param>
|
||||||
|
/// <param name="text">Text, lines are separated by '~'</param>
|
||||||
|
/// <param name="font">Font</param>
|
||||||
|
/// <returns>Size of the paragraph of text</returns>
|
||||||
|
protected SizeF Measure(System.Drawing.Printing.PrintPageEventArgs e, string text, Font font)
|
||||||
|
{
|
||||||
|
if (font != lastFont)
|
||||||
|
{
|
||||||
|
lastFont = font;
|
||||||
|
lastSpacing = e.Graphics.MeasureString("Abcgq", font).Height;
|
||||||
|
}
|
||||||
|
|
||||||
|
string[] lines = text.Split(new char[] { '~' });
|
||||||
|
float width = 0;
|
||||||
|
foreach (var line in lines)
|
||||||
|
{
|
||||||
|
float lineWid = e.Graphics.MeasureString(line, font).Width;
|
||||||
|
if (lineWid > width) width = lineWid;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new SizeF(width, 0.8f * lines.Length * lastSpacing + 0.2f);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Print a paragraph of text, lines are separated by '~'.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="e">PrintPageEventArgs</param>
|
||||||
|
/// <param name="text">Text, lines are separated by '~'</param>
|
||||||
|
/// <param name="font">Font</param>
|
||||||
|
/// <param name="x">Position x</param>
|
||||||
|
/// <param name="y">Position y</param>
|
||||||
|
/// <param name="width">Width (required when alignment=Alignment.Center or alignment=Aligmenr.Right</param>
|
||||||
|
/// <param name="height">Height, 0 = no vertical centering</param>
|
||||||
|
/// <param name="horizAlignment">Horizontal alignment</param>
|
||||||
|
/// <param name="vertAlignment">Vertical alignment</param>
|
||||||
|
protected void PrintAt(System.Drawing.Printing.PrintPageEventArgs e, string text, Font font,
|
||||||
|
float x, float y, float width, float height, Alignment horizAlignment, VertAlignment vertAlignment)
|
||||||
|
{
|
||||||
|
SizeF size = Measure(e, text, font);
|
||||||
|
|
||||||
|
string[] lines = text.Split(new char[] { '~' });
|
||||||
|
|
||||||
|
if (height <= size.Height) vertAlignment = VertAlignment.Top;
|
||||||
|
float y0;
|
||||||
|
switch (vertAlignment)
|
||||||
|
{
|
||||||
|
default:
|
||||||
|
case VertAlignment.Top: y0 = y; break;
|
||||||
|
case VertAlignment.Middle: y0 = y + (height - size.Height) / 2; break;
|
||||||
|
case VertAlignment.Bottom: y0 = y + (height - size.Height); break;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var line in lines)
|
||||||
|
{
|
||||||
|
float x0;
|
||||||
|
switch (horizAlignment)
|
||||||
|
{
|
||||||
|
default:
|
||||||
|
case Alignment.Left: x0 = x; break;
|
||||||
|
case Alignment.Center: x0 = x + (width - e.Graphics.MeasureString(line, font).Width) / 2; break;
|
||||||
|
case Alignment.Right: x0 = x + width - e.Graphics.MeasureString(line, font).Width; break;
|
||||||
|
}
|
||||||
|
e.Graphics.DrawString(line, font, Brushes.Black, new PointF(x0, y0));
|
||||||
|
y0 += 0.8f * lastSpacing;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -104,6 +104,9 @@
|
|||||||
<SubType>Component</SubType>
|
<SubType>Component</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="Output\Printers\Enhanced\EnhancedPrinterCfg.cs" />
|
<Compile Include="Output\Printers\Enhanced\EnhancedPrinterCfg.cs" />
|
||||||
|
<Compile Include="Output\Printers\PrintersCommon.cs">
|
||||||
|
<SubType>Component</SubType>
|
||||||
|
</Compile>
|
||||||
<Compile Include="Output\Printers\Munich\MunichPrintDocument.cs">
|
<Compile Include="Output\Printers\Munich\MunichPrintDocument.cs">
|
||||||
<SubType>Component</SubType>
|
<SubType>Component</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user