# Conflicts: # LehrerApp.TemplateDesigner.Tests/ProjectLifecycleTests.cs # LehrerApp.TemplateDesigner/DesignerViewModel.cs # LehrerApp.TemplateDesigner/MainWindow.axaml # LehrerApp.Templating/LayoutParser.cs # LehrerApp.Templating/QuestTemplateRenderer.cs
This commit is contained in:
@@ -19,14 +19,129 @@ public sealed class TemplatingTests : IDisposable
|
||||
IMG logo.png 15 15 30 12 scale=50%
|
||||
TEXT 20 45 $Datum|dd.MM.yyyy size=10
|
||||
TEXTBOX 20 90 170 120 $Brieftext wrap=true
|
||||
FLOWBOX 20 20 170 250 $Brieftext size=11
|
||||
TABLE 20 215 170 40 $Zeilen size=9
|
||||
CHART 20 260 170 25 $Werte type=line
|
||||
""");
|
||||
|
||||
Assert.Equal(6, layout.Elements.Count);
|
||||
Assert.Equal(7, layout.Elements.Count);
|
||||
Assert.Equal("50%", Assert.IsType<ImageElement>(layout.Elements[1]).Attributes["scale"]);
|
||||
Assert.Equal("dd.MM.yyyy", Assert.IsType<TextElement>(layout.Elements[2]).Format);
|
||||
Assert.Equal("line", Assert.IsType<ChartElement>(layout.Elements[5]).ChartType);
|
||||
Assert.IsType<FlowBoxElement>(layout.Elements[4]);
|
||||
Assert.Equal("line", Assert.IsType<ChartElement>(layout.Elements[6]).ChartType);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Systemvariablen_BrauchenKeineManifestDeklarationUndRendernMitSeitenzahlen()
|
||||
{
|
||||
var manifest = new TemplateManifest { Id = "system", Name = "Systemvariablen" };
|
||||
var layout = new LayoutParser().Parse("""
|
||||
PAGE 210 297 mm
|
||||
TEXT 20 10 "Stand: $$today" size=9
|
||||
TEXT 140 285 "Seite $$curPage von $$maxPageNum" size=9
|
||||
FLOWBOX 20 20 170 250 "Langer Inhalt für zwei Seiten.\nLanger Inhalt für zwei Seiten."
|
||||
""");
|
||||
var template = new LoadedTemplate(manifest, layout, new Dictionary<string, byte[]>());
|
||||
|
||||
var validation = new TemplateLoader().Validate(template, new Dictionary<string, PlaceholderType>());
|
||||
var pdf = new QuestTemplateRenderer().RenderToPdf(template,
|
||||
new DictionaryProvider(new Dictionary<string, PlaceholderValue>()));
|
||||
|
||||
Assert.True(validation.IsValid);
|
||||
Assert.Equal("%PDF", System.Text.Encoding.ASCII.GetString(pdf, 0, 4));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FlowBox_FliesstAufFolgeseitenUndPaketEnthaeltFolgeseitenLayout()
|
||||
{
|
||||
var path = Path.Combine(_directory, "flow.lavorlage");
|
||||
var manifest = new TemplateManifest
|
||||
{
|
||||
Id = "flow", Name = "Fließtext", ContinuationLayoutFile = "continuation.tpl",
|
||||
Placeholders = [new("Text", PlaceholderType.Multiline, true)],
|
||||
};
|
||||
var first = "PAGE 210 297 mm\nTEXT 20 10 \"Erste Seite\" size=14\nFLOWBOX 20 25 170 252 $Text size=11";
|
||||
var continuation = "PAGE 210 297 mm\nTEXT 20 10 \"Folgeseite\" size=10\nFLOWBOX 20 25 170 252 $Text size=11";
|
||||
TemplatePackage.Create(path, manifest, first, new Dictionary<string, byte[]>(), continuation);
|
||||
|
||||
var loaded = new TemplateLoader().LoadFromPackage(path);
|
||||
var longText = string.Join('\n', Enumerable.Repeat(
|
||||
"Ein langer Klassenbucheintrag mit ausreichend Inhalt für den automatischen Seitenumbruch.", 250));
|
||||
var pdf = new QuestTemplateRenderer().RenderToPdf(loaded,
|
||||
new DictionaryProvider(new Dictionary<string, PlaceholderValue> { ["Text"] = new MultilineValue(longText) }));
|
||||
var source = System.Text.Encoding.ASCII.GetString(pdf);
|
||||
|
||||
Assert.NotNull(loaded.ContinuationLayout);
|
||||
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]
|
||||
|
||||
Reference in New Issue
Block a user