diff --git a/LehrerApp.TemplateDesigner/LayoutOverlayEditor.cs b/LehrerApp.TemplateDesigner/LayoutOverlayEditor.cs index 26815ba..ea4ca6d 100644 --- a/LehrerApp.TemplateDesigner/LayoutOverlayEditor.cs +++ b/LehrerApp.TemplateDesigner/LayoutOverlayEditor.cs @@ -209,7 +209,7 @@ public sealed class LayoutOverlayEditor : Control TableElement => "TABLE", ChartElement => "CHART", _ => "?" }; var (width, height, resizable) = element switch { - TextElement text => (Math.Min(70d, Math.Max(5, PageWidth - text.X)), + TextElement text => (TextLineWidth(text), Math.Max(3, PointsToUnit(ParseSize(text.Attributes) * 1.8)), false), ImageElement image => (image.Width * ImageScale(image), image.Height * ImageScale(image), true), _ => ((double)element.Width, element.Height, true), @@ -254,6 +254,18 @@ public sealed class LayoutOverlayEditor : Control private static float ParseSize(IReadOnlyDictionary attributes) => attributes.TryGetValue("size", out var raw) && float.TryParse(raw, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out var size) ? size : 11; + // Mit w= oder align=center/right entspricht der Rahmen der Zeilenbreite, in der der Renderer ausrichtet. + private double TextLineWidth(TextElement text) + { + var remaining = Math.Max(5, PageWidth - text.X); + if (text.Attributes.TryGetValue("w", out var raw) && float.TryParse(raw, + System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out var width) + && width > 0) + return width; + return text.Attributes.TryGetValue("align", out var align) + && (align.Equals("center", StringComparison.OrdinalIgnoreCase) || align.Equals("right", StringComparison.OrdinalIgnoreCase)) + ? remaining : Math.Min(70d, remaining); + } private static float ImageScale(ImageElement image) => image.Attributes.TryGetValue("scale", out var raw) ? LayoutParser.Percentage(raw) : 1; private double PointsToUnit(double points) => PageUnit.ToLowerInvariant() switch diff --git a/LehrerApp.Templating/QuestTemplateRenderer.cs b/LehrerApp.Templating/QuestTemplateRenderer.cs index eb0f115..79dad51 100644 --- a/LehrerApp.Templating/QuestTemplateRenderer.cs +++ b/LehrerApp.Templating/QuestTemplateRenderer.cs @@ -333,11 +333,11 @@ public sealed class QuestTemplateRenderer : ITemplateRenderer, ITemplatePreviewR values, template.Manifest, text.Attributes); break; case TextBoxElement box: - RenderResolvedText(Position(root, box, unit).Shrink(), box.Content, box.Placeholder, box.Format, + RenderResolvedText(Position(root, box, unit).ShrinkVertical(), box.Content, box.Placeholder, box.Format, values, template.Manifest, box.Attributes); break; case FlowBoxElement box: - RenderResolvedText(Position(root, box, unit).Shrink(), box.Content, box.Placeholder, box.Format, + RenderResolvedText(Position(root, box, unit).ShrinkVertical(), box.Content, box.Placeholder, box.Format, values, template.Manifest, box.Attributes); break; case DrawBoxElement drawing: