Files
QuestPDF/QuestPDF.Examples/TextExample.cs
T

167 lines
6.1 KiB
C#
Raw Normal View History

2021-04-28 00:24:26 +02:00
using System;
using System.Collections.Generic;
using System.Linq;
using QuestPDF.Elements;
using QuestPDF.Examples.Engine;
using QuestPDF.Fluent;
using QuestPDF.Helpers;
using QuestPDF.Infrastructure;
2021-04-28 23:49:22 +02:00
using SkiaSharp;
2021-04-28 00:24:26 +02:00
namespace QuestPDF.Examples
{
public class TextExample : ExampleTestBase
{
[ShowResult]
2021-04-28 23:49:22 +02:00
[ImageSize(1600, 500)]
2021-04-28 00:24:26 +02:00
public void Test(IContainer container)
{
List<TextElement> Lorem()
{
return new List<TextElement>
{
2021-04-29 11:18:16 +02:00
new TextElement()
{
Style = TextStyle.Default.Size(32).BackgroundColor(Placeholders.BackgroundColor()),
Text = "Podstawowy łaciński Tabela znaków Unicode"
},
new TextElement()
{
Style = TextStyle.Default.FontType("Segoe UI Emoji").Size(32).BackgroundColor(Placeholders.BackgroundColor()),
Text = "✔"
},
new TextElement()
{
Style = TextStyle.Default.FontType("Segoe UI Emoji").Size(32).BackgroundColor(Placeholders.BackgroundColor()),
Text = "🥛"
},
new TextElement()
{
Style = TextStyle.Default.FontType("Segoe UI Emoji").Size(32).BackgroundColor(Placeholders.BackgroundColor()),
Text = "🧀"
},
new TextElement()
{
Style = TextStyle.Default.FontType("Segoe UI Emoji").Size(32).BackgroundColor(Placeholders.BackgroundColor()),
Text = "❤🚵‍♀️"
},
2021-04-28 00:24:26 +02:00
new TextElement()
{
2021-04-28 23:49:22 +02:00
Style = TextStyle.Default.Size(32).BackgroundColor(Placeholders.BackgroundColor()),
2021-04-28 00:24:26 +02:00
Text = "Lorem ipsum "
},
new TextElement()
{
2021-04-28 23:49:22 +02:00
Style = TextStyle.Default.Size(24).BackgroundColor(Placeholders.BackgroundColor()),
2021-04-28 00:24:26 +02:00
Text = " dolor "
},
new TextElement()
{
2021-04-28 23:49:22 +02:00
Style = TextStyle.Default.Size(64).BackgroundColor(Placeholders.BackgroundColor()),
Text = " sijt "
2021-04-28 00:24:26 +02:00
},
new TextElement()
{
2021-04-28 23:49:22 +02:00
Style = TextStyle.Default.Size(32).BackgroundColor(Placeholders.BackgroundColor()),
2021-04-28 00:24:26 +02:00
Text = " amet"
}
};
}
2021-04-28 23:49:22 +02:00
Func<List<TextElement>> Source = () => Split(RandomText());
2021-04-28 00:24:26 +02:00
container
.Padding(50)
2021-04-28 23:49:22 +02:00
.Box().Border(1).Stack(stack =>
2021-04-28 00:24:26 +02:00
{
stack
.Element()
.Box()
//.Background(Placeholders.BackgroundColor())
.Element(new TextRun()
{
2021-04-29 11:18:16 +02:00
Elements = Lorem()
2021-04-28 00:24:26 +02:00
});
stack
.Element()
.Box()
//.Background(Placeholders.BackgroundColor())
.Element(new TextRun()
{
Elements = Source()
});
2021-04-28 23:49:22 +02:00
2021-04-28 00:24:26 +02:00
stack
.Element()
.Box()
//.Background(Placeholders.BackgroundColor())
.Element(new TextRun()
{
2021-04-28 23:49:22 +02:00
Elements = Source()
2021-04-28 00:24:26 +02:00
});
stack
.Element()
.Box()
2021-04-28 23:49:22 +02:00
//.Background(Placeholders.BackgroundColor())
2021-04-28 00:24:26 +02:00
.Element(new TextRun()
{
2021-04-28 23:49:22 +02:00
Elements = Source()
2021-04-28 00:24:26 +02:00
});
2021-04-28 23:49:22 +02:00
2021-04-28 00:24:26 +02:00
stack
.Element()
.Box()
2021-04-28 23:49:22 +02:00
//.Background(Placeholders.BackgroundColor())
2021-04-28 00:24:26 +02:00
.Element(new TextRun()
{
2021-04-28 23:49:22 +02:00
Elements = Source()
});
stack
.Element()
.Box()
//.Background(Placeholders.BackgroundColor())
.Element(new TextRun()
{
Elements = Source()
2021-04-28 00:24:26 +02:00
});
});
}
List<TextElement> RandomText()
{
2021-04-28 23:49:22 +02:00
var sizes = new[] { 24, 32, 48, 64};
2021-04-28 00:24:26 +02:00
return Placeholders
.Sentence()
.Split(" ")
.Select(x => new TextElement
{
Text = $"{x} ",
2021-04-28 23:49:22 +02:00
Style = TextStyle
.Default
//.Size(sizes[Placeholders.Random.Next(0, 3)])
.Size(24)
.BackgroundColor(Placeholders.BackgroundColor())
//.LineHeight((float)Placeholders.Random.NextDouble() / 2 + 1f)
.LineHeight(1.2f)
2021-04-28 00:24:26 +02:00
})
.ToList();
}
List<TextElement> Split(List<TextElement> elements)
{
return elements
.SelectMany(x => x
.Text
.Select(y => new TextElement
{
Style = x.Style,
Text = y.ToString()
}))
.ToList();
}
}
}