First commit

Send all results
This commit is contained in:
2020-09-04 12:49:15 +05:00
commit 330a2ccfda
2819 changed files with 226201 additions and 0 deletions

View File

@@ -0,0 +1,78 @@
using MigraDoc.DocumentObjectModel;
#pragma warning disable 1591
namespace MigraDoc.Rendering.UnitTest
{
/// <summary>
/// Summary description for TestLayout.
/// </summary>
public class TestLayout
{
public static void TwoParagraphs(string outputFile)
{
Document doc = new Document();
Section sec = doc.Sections.AddSection();
sec.PageSetup.TopMargin = 0;
sec.PageSetup.BottomMargin = 0;
Paragraph par1 = sec.AddParagraph();
TestParagraphRenderer.FillFormattedParagraph(par1);
TestParagraphRenderer.GiveBorders(par1);
par1.Format.SpaceAfter = "2cm";
par1.Format.SpaceBefore = "3cm";
Paragraph par2 = sec.AddParagraph();
TestParagraphRenderer.FillFormattedParagraph(par2);
TestParagraphRenderer.GiveBorders(par2);
par2.Format.SpaceBefore = "3cm";
PdfDocumentRenderer renderer = new PdfDocumentRenderer();
renderer.Document = doc;
renderer.RenderDocument();
renderer.PdfDocument.Save(outputFile);
}
public static void A1000Paragraphs(string outputFile)
{
Document doc = new Document();
Section sec = doc.Sections.AddSection();
sec.PageSetup.TopMargin = 0;
sec.PageSetup.BottomMargin = 0;
for (int idx = 1; idx <= 1000; ++idx)
{
Paragraph par = sec.AddParagraph();
par.AddText("Paragraph " + idx + ": ");
TestParagraphRenderer.FillFormattedParagraph(par);
TestParagraphRenderer.GiveBorders(par);
}
PdfDocumentRenderer renderer = new PdfDocumentRenderer();
renderer.Document = doc;
renderer.RenderDocument();
renderer.PdfDocument.Save(outputFile);
}
public static string DumpParagraph()
{
return "";
// Document doc = new Document();
// Paragraph par = doc.Sections.AddSection().AddParagraph();
// par.Format.SpaceAfter = "3cm";
// par.Format.SpaceBefore = "2cm";
// TestParagraphRenderer.FillFormattedParagraph(par);
// PdfFlattenVisitor visitor = new PdfFlattenVisitor(doc);
// visitor.Visit();
//
// XGraphics gfx = XGraphics.FromGraphics(Graphics.FromHwnd(IntPtr.Zero), new XSize(2000, 2000));
// //Renderer rndrr = Renderer.Create(gfx, par, new FieldInfos(new Hashtable()));
// rndrr.Format(new Rectangle(0, 0, XUnit.FromCentimeter(21), XUnit.FromCentimeter(29)), null);
// string retVal = ValueDumper.DumpValues(rndrr.RenderInfo.LayoutInfo);
// retVal += "\r\n";
//
// retVal += ValueDumper.DumpValues(rndrr.RenderInfo.LayoutInfo.ContentArea);
// return retVal;
}
}
}

View File

@@ -0,0 +1,47 @@
using MigraDoc.DocumentObjectModel;
#pragma warning disable 1591
namespace MigraDoc.Rendering.UnitTest
{
/// <summary>
/// Summary description for TestParagraphIterator.
/// </summary>
public class TestParagraphIterator
{
public TestParagraphIterator()
{ }
public static string GetIterators(Paragraph paragraph)
{
ParagraphIterator iter = new ParagraphIterator(paragraph.Elements);
iter = iter.GetFirstLeaf();
string retString = "";
while (iter != null)
{
retString += "[" + iter.Current.GetType().Name + ":]";
if (iter.Current is Text)
retString += ((Text)iter.Current).Content;
iter = iter.GetNextLeaf();
}
return retString;
}
public static string GetBackIterators(Paragraph paragraph)
{
ParagraphIterator iter = new ParagraphIterator(paragraph.Elements);
iter = iter.GetLastLeaf();
string retString = "";
while (iter != null)
{
retString += "[" + iter.Current.GetType().Name + ":]";
if (iter.Current is Text)
retString += ((Text)iter.Current).Content;
iter = iter.GetPreviousLeaf();
}
return retString;
}
}
}

View File

@@ -0,0 +1,211 @@
using MigraDoc.DocumentObjectModel;
namespace MigraDoc.Rendering.UnitTest
{
/// <summary>
/// Summary description for ParagraphRenderer.
/// </summary>
public class TestParagraphRenderer
{
/// <summary>
/// Tests texts and blanks.
/// </summary>
public static void TextAndBlanks(string pdfOutputFile)
{
Document document = new Document();
Section section = document.AddSection();
Paragraph par = section.AddParagraph("Dies");
for (int idx = 0; idx <= 40; ++idx)
{
par.AddCharacter(SymbolName.Blank);
par.AddText(idx.ToString());
par.AddCharacter(SymbolName.Blank);
par.AddText((idx + 1).ToString());
par.AddCharacter(SymbolName.Blank);
par.AddText((idx + 2).ToString());
}
PdfDocumentRenderer renderer = new PdfDocumentRenderer();
renderer.Document = document;
renderer.RenderDocument();
renderer.PdfDocument.Save(pdfOutputFile);
}
/// <summary>
/// Tests AddFormattedText.
/// </summary>
public static void Formatted(string pdfOutputFile)
{
Document document = new Document();
Section section = document.AddSection();
Paragraph par = section.AddParagraph();
FillFormattedParagraph(par);
PdfDocumentRenderer printer = new PdfDocumentRenderer();
printer.Document = document;
printer.RenderDocument();
printer.PdfDocument.Save(pdfOutputFile);
}
public static void FillFormattedParagraph(Paragraph par)
{
for (int idx = 0; idx <= 140; ++idx)
{
if (idx < 60)
{
FormattedText formText = par.AddFormattedText((idx).ToString(), TextFormat.Bold);
formText.Font.Size = 16;
formText.AddText(" ");
}
else if (idx < 100)
{
par.AddText((idx).ToString());
par.AddText(" ");
}
else
{
FormattedText formText = par.AddFormattedText((idx).ToString(), TextFormat.Italic);
formText.Font.Size = 6;
formText.AddText(" ");
}
if (idx % 50 == 0)
par.AddLineBreak();
}
par.AddText(" ...ready.");
}
/// <summary>
/// Tests alignments.
/// </summary>
public static void Alignment(string pdfOutputFile)
{
Document document = new Document();
Section section = document.AddSection();
section.PageSetup.LeftMargin = 0;
section.PageSetup.RightMargin = 0;
Paragraph par = section.AddParagraph();
// FillFormattedParagraph(par);
// par.Format.Alignment = ParagraphAlignment.Left;
// par = section.AddParagraph();
// FillFormattedParagraph(par);
// par.Format.Alignment = ParagraphAlignment.Right;
// par = section.AddParagraph();
FillFormattedParagraph(par);
par.Format.Alignment = ParagraphAlignment.Center;
//
// par = section.AddParagraph();
// FillFormattedParagraph(par);
// par.Format.Alignment = ParagraphAlignment.Justify;
par.Format.FirstLineIndent = "-2cm";
par.Format.LeftIndent = "2cm";
par.Format.RightIndent = "3cm";
PdfDocumentRenderer renderer = new PdfDocumentRenderer();
renderer.Document = document;
renderer.RenderDocument();
renderer.PdfDocument.Save(pdfOutputFile);
}
/// <summary>
/// Tests tab stops.
/// </summary>
public static void Tabs(string pdfOutputFile)
{
Document document = new Document();
Section section = document.AddSection();
section.PageSetup.LeftMargin = 0;
section.PageSetup.RightMargin = 0;
Paragraph par = section.AddParagraph();
par.Format.TabStops.AddTabStop("20cm", TabAlignment.Right);
par.AddText(" text before tab bla bla bla. text before tab bla bla bla. text before tab bla bla bla. text before tab bla bla bla.");
//par.AddTab();
par.AddText(" ............ after tab bla bla bla.");
PdfDocumentRenderer renderer = new PdfDocumentRenderer();
renderer.Document = document;
renderer.RenderDocument();
renderer.PdfDocument.Save(pdfOutputFile);
}
public static void GiveBorders(Paragraph par)
{
Borders borders = par.Format.Borders;
borders.Top.Color = Colors.Gray;
borders.Top.Width = 4;
borders.Top.Style = BorderStyle.DashDot;
borders.Left.Color = Colors.Red;
borders.Left.Style = BorderStyle.Dot;
borders.Left.Width = 7;
borders.Bottom.Color = Colors.Red;
borders.Bottom.Width = 3;
borders.Bottom.Style = BorderStyle.DashLargeGap;
borders.Right.Style = BorderStyle.DashSmallGap;
borders.Right.Width = 3;
borders.DistanceFromBottom = "1cm";
borders.DistanceFromTop = "1.5cm";
borders.DistanceFromLeft = "0.5cm";
borders.DistanceFromRight = "2cm";
par.Format.Shading.Color = Colors.LightBlue;
}
/// <summary>
/// Tests borders.
/// </summary>
public static void Borders(string outputFile)
{
Document document = new Document();
Section section = document.AddSection();
Paragraph par = section.AddParagraph();
FillFormattedParagraph(par);
GiveBorders(par);
PdfDocumentRenderer renderer = new PdfDocumentRenderer();
renderer.Document = document;
renderer.RenderDocument();
renderer.PdfDocument.Save(outputFile);
}
/// <summary>
/// Tests document fields.
/// </summary>
public static void Fields(string outputFile)
{
Document document = new Document();
Section section = document.AddSection();
Paragraph par = section.AddParagraph();
par.AddText("Section: ");
par.AddSectionField().Format = "ALPHABETIC";
par.AddLineBreak();
par.AddText("SectionPages: ");
par.AddSectionField().Format = "alphabetic";
par.AddLineBreak();
par.AddText("Page: ");
par.AddPageField().Format = "ROMAN";
par.AddLineBreak();
par.AddText("NumPages: ");
par.AddNumPagesField();
par.AddLineBreak();
par.AddText("Date: ");
par.AddDateField();
par.AddLineBreak();
par.AddText("Bookmark: ");
par.AddBookmark("Egal");
par.AddLineBreak();
par.AddText("PageRef: ");
par.AddPageRefField("Egal");
PdfDocumentRenderer renderer = new PdfDocumentRenderer();
renderer.Document = document;
renderer.RenderDocument();
renderer.PdfDocument.Save(outputFile);
}
}
}

View File

@@ -0,0 +1,99 @@
using MigraDoc.DocumentObjectModel;
using MigraDoc.DocumentObjectModel.Tables;
#pragma warning disable 1591
namespace MigraDoc.Rendering.UnitTest
{
/// <summary>
/// Summary description for TestTable.
/// </summary>
public class TestTable
{
public static void Borders(string outputFile)
{
Document document = new Document();
Section sec = document.Sections.AddSection();
sec.AddParagraph("A paragraph before.");
Table table = sec.AddTable();
table.Borders.Visible = true;
table.AddColumn();
table.AddColumn();
table.Rows.HeightRule = RowHeightRule.Exactly;
table.Rows.Height = 14;
Row row = table.AddRow();
Cell cell = row.Cells[0];
cell.Borders.Visible = true;
cell.Borders.Left.Width = 8;
cell.Borders.Right.Width = 2;
cell.AddParagraph("First Cell");
row = table.AddRow();
cell = row.Cells[1];
cell.AddParagraph("Last Cell within this table");
cell.Borders.Bottom.Width = 15;
cell.Shading.Color = Colors.LightBlue;
sec.AddParagraph("A Paragraph afterwards");
PdfDocumentRenderer renderer = new PdfDocumentRenderer();
renderer.Document = document;
renderer.RenderDocument();
renderer.PdfDocument.Save(outputFile);
}
public static void CellMerge(string outputFile)
{
Document document = new Document();
Section sec = document.Sections.AddSection();
sec.AddParagraph("A paragraph before.");
Table table = sec.AddTable();
table.Borders.Visible = true;
table.AddColumn();
table.AddColumn();
Row row = table.AddRow();
Cell cell = row.Cells[0];
cell.MergeRight = 1;
cell.Borders.Visible = true;
cell.Borders.Left.Width = 8;
cell.Borders.Right.Width = 2;
cell.AddParagraph("First Cell");
row = table.AddRow();
cell = row.Cells[1];
cell.AddParagraph("Last Cell within this row");
cell.MergeDown = 1;
cell.Borders.Bottom.Width = 15;
cell.Borders.Right.Width = 30;
cell.Shading.Color = Colors.LightBlue;
row = table.AddRow();
sec.AddParagraph("A Paragraph afterwards");
PdfDocumentRenderer renderer = new PdfDocumentRenderer();
renderer.Document = document;
renderer.RenderDocument();
renderer.PdfDocument.Save(outputFile);
}
public static void VerticalAlign(string outputFile)
{
Document document = new Document();
Section sec = document.Sections.AddSection();
sec.AddParagraph("A paragraph before.");
Table table = sec.AddTable();
table.Borders.Visible = true;
table.AddColumn();
table.AddColumn();
Row row = table.AddRow();
row.HeightRule = RowHeightRule.Exactly;
row.Height = 70;
row.VerticalAlignment = VerticalAlignment.Center;
row[0].AddParagraph("First Cell");
row[1].AddParagraph("Second Cell");
sec.AddParagraph("A Paragraph afterwards.");
PdfDocumentRenderer renderer = new PdfDocumentRenderer();
renderer.Document = document;
renderer.RenderDocument();
renderer.PdfDocument.Save(outputFile);
}
}
}

View File

@@ -0,0 +1,26 @@
using System.Reflection;
namespace MigraDoc.Rendering.UnitTest
{
/// <summary>
/// Summary description for ValueDumper.
/// </summary>
public class ValueDumper
{
public ValueDumper()
{ }
public static string DumpValues(object obj)
{
string dumpString = "[" + obj.GetType() + "]\r\n";
foreach (FieldInfo fieldInfo in obj.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Instance))
{
if (fieldInfo.FieldType.IsValueType)
{
dumpString += " " + fieldInfo.Name + " = " + fieldInfo.GetValue(obj) + "\r\n";
}
}
return dumpString;
}
}
}