This commit is contained in:
@@ -55,6 +55,75 @@ public sealed class TemplatingTests : IDisposable
|
||||
Assert.True(System.Text.RegularExpressions.Regex.Matches(source, @"/Type\s*/Page\b").Count > 1);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DrawBox_RendertDeklarativeExterneZeichenbefehleInFesterBox()
|
||||
{
|
||||
var template = new LoadedTemplate(new TemplateManifest
|
||||
{
|
||||
Placeholders = [new("Grafik", PlaceholderType.Drawing, true)],
|
||||
}, new LayoutParser().Parse("PAGE 210 297 mm\nDRAWBOX 20 20 100 60 $Grafik"),
|
||||
new Dictionary<string, byte[]>());
|
||||
var drawing = new DrawingValue(
|
||||
[new DrawRectangle(0, 0, 100, 60, "#1D4ED8", 1, "#EFF6FF"),
|
||||
new DrawString(5, 5, "Externer Inhalt", 11, Bold: true),
|
||||
new MoveTo(5, 25), new LineTo(95, 25, "#DC2626", 1.5f),
|
||||
new DrawLine(5, 35, 95, 50, "#059669", 1)], 60);
|
||||
|
||||
var pdf = new QuestTemplateRenderer().RenderToPdf(template,
|
||||
new DictionaryProvider(new Dictionary<string, PlaceholderValue> { ["Grafik"] = drawing }));
|
||||
|
||||
Assert.Single(System.Text.RegularExpressions.Regex.Matches(
|
||||
System.Text.Encoding.ASCII.GetString(pdf), @"/Type\s*/Page\b"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FlowDrawBox_PaginertHohenDeklarativenZeichenraum()
|
||||
{
|
||||
var template = new LoadedTemplate(new TemplateManifest
|
||||
{
|
||||
Placeholders = [new("Protokoll", PlaceholderType.Drawing, true)],
|
||||
}, new LayoutParser().Parse("PAGE 210 297 mm\nFLOWDRAWBOX 20 20 170 257 $Protokoll"),
|
||||
new Dictionary<string, byte[]>());
|
||||
var drawing = new DrawingValue(
|
||||
Enumerable.Range(0, 80).SelectMany(i => (DrawingCommand[])
|
||||
[new DrawString(0, i * 10, $"Zeile {i + 1}", 8), new DrawLine(0, i * 10 + 9, 160, i * 10 + 9, "#CBD5E1", .3f)])
|
||||
.ToList(), 800);
|
||||
|
||||
var pdf = new QuestTemplateRenderer().RenderToPdf(template,
|
||||
new DictionaryProvider(new Dictionary<string, PlaceholderValue> { ["Protokoll"] = drawing }));
|
||||
|
||||
Assert.True(System.Text.RegularExpressions.Regex.Matches(
|
||||
System.Text.Encoding.ASCII.GetString(pdf), @"/Type\s*/Page\b").Count >= 4);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FlowDrawBox_CallbackErhaeltSeitenflaecheStateUndSteuertSeitenwechsel()
|
||||
{
|
||||
var template = new LoadedTemplate(new TemplateManifest
|
||||
{
|
||||
Placeholders = [new("Bericht", PlaceholderType.Drawing, true)],
|
||||
}, new LayoutParser().Parse("PAGE 210 297 mm\nFLOWDRAWBOX 20 20 170 257 $Bericht"),
|
||||
new Dictionary<string, byte[]>());
|
||||
var invocations = 0;
|
||||
var drawing = new PagedDrawingValue(context =>
|
||||
{
|
||||
invocations++;
|
||||
var item = context.State is int value ? value : 0;
|
||||
context.Canvas.DrawRectangle(0, 0, context.Width, 20, "#1D4ED8", .5f, "#EFF6FF");
|
||||
context.Canvas.DrawStringEx(0, 2, 14, context.Width, $"Untrennbarer Block {item + 1}",
|
||||
DrawingTextAlignment.AlignCenter, 11, "Arial", "#1E3A8A", bold: true);
|
||||
context.State = item + 1;
|
||||
return context.PageNumber == 3;
|
||||
}, InitialState: 0);
|
||||
|
||||
var pdf = new QuestTemplateRenderer().RenderToPdf(template,
|
||||
new DictionaryProvider(new Dictionary<string, PlaceholderValue> { ["Bericht"] = drawing }));
|
||||
|
||||
Assert.Equal(3, invocations);
|
||||
Assert.Equal(3, System.Text.RegularExpressions.Regex.Matches(
|
||||
System.Text.Encoding.ASCII.GetString(pdf), @"/Type\s*/Page\b").Count);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("scale=0%")]
|
||||
[InlineData("scale=-10%")]
|
||||
|
||||
Reference in New Issue
Block a user