From 4348e7cc14e9d0fa91a54027226d7d267f8d587c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pauli=20Ojanper=C3=A4?= Date: Tue, 10 Oct 2023 01:38:51 +0300 Subject: [PATCH 1/2] Expand TextMacros in descriptions' 2ndary titles. --- src/PurplePen/DescriptionFormatter.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/PurplePen/DescriptionFormatter.cs b/src/PurplePen/DescriptionFormatter.cs index f88f42aed..596a1108f 100644 --- a/src/PurplePen/DescriptionFormatter.cs +++ b/src/PurplePen/DescriptionFormatter.cs @@ -608,7 +608,7 @@ public DescriptionLine[] CreateDescription(bool createKey) DescriptionLine line; DescriptionLine[] lines; Dictionary descriptionKey = new Dictionary(); // dictionary for any symbols encountered with custom text. - + // Get the first title line. text = GetTitleLine1(); Debug.Assert(text != null); @@ -618,7 +618,7 @@ public DescriptionLine[] CreateDescription(bool createKey) // Get the second title line. text = GetTitleLine2(); if (text != null) { - lines = GetTitleLineFromText(DescriptionLineKind.SecondaryTitle, text); + lines = GetTitleLineFromText(DescriptionLineKind.SecondaryTitle, CourseFormatter.ExpandText(eventDB, courseView, text)); list.AddRange(lines); } From f456274fd297da5c303006315061b100e159aae7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pauli=20Ojanper=C3=A4?= Date: Sat, 4 Nov 2023 20:40:56 +0200 Subject: [PATCH 2/2] Preserve macros for editing. --- src/PurplePen/DescriptionFormatter.cs | 56 +++++++++++---------------- src/PurplePen/DescriptionRenderer.cs | 6 +-- src/PurplePen/PurplePen.csproj | 2 + src/PurplePen/SystemExtensions.cs | 12 ++++++ 4 files changed, 40 insertions(+), 36 deletions(-) create mode 100644 src/PurplePen/SystemExtensions.cs diff --git a/src/PurplePen/DescriptionFormatter.cs b/src/PurplePen/DescriptionFormatter.cs index 596a1108f..c16d0706c 100644 --- a/src/PurplePen/DescriptionFormatter.cs +++ b/src/PurplePen/DescriptionFormatter.cs @@ -175,22 +175,16 @@ private string GetTitleLine2() // Given the text, create descriptions line for a title line with that text. Lines are split by vertical bars. private DescriptionLine[] GetTitleLineFromText(DescriptionLineKind kind, string text) { - string[] texts = text.Split(new char[] { '|' }); - int lineCount = texts.Length; - - DescriptionLine[] lines = new DescriptionLine[lineCount]; - for (int index = 0; index < lineCount; ++index) { - DescriptionLine line = new DescriptionLine(); - - line.kind = kind; - line.boxes = new object[1]; - line.boxes[0] = texts[index]; - line.textual = texts[index]; - - lines[index] = line; - } - - return lines; + return text.Split(new char[] { '|' }) + .ConvertAll(t => + { + DescriptionLine line = new DescriptionLine(); + line.kind = kind; + line.boxes = new object[1]; + line.boxes[0] = t; + line.textual = CourseFormatter.ExpandText(eventDB, courseView, t); + return line; + }); } // Create a description line for a normal header line: name, length, climb @@ -274,23 +268,19 @@ private DescriptionLine GetScoreHeaderLine() // Given the text, create one or more text lines for that text. Lines are split by vertical bars. private DescriptionLine[] GetTextLineFromText(string text, Id courseControlId, Id controlId, DescriptionLine.TextLineKind textLineKind) { - string[] texts = text.Split(new char[] { '|' }); - int lineCount = texts.Length; - - DescriptionLine[] lines = new DescriptionLine[lineCount]; - for (int index = 0; index < lineCount; ++index) { - DescriptionLine line = new DescriptionLine(); - line.kind = DescriptionLineKind.Text; - line.boxes = new object[1]; - line.boxes[0] = texts[index]; - line.textual = texts[index]; - line.courseControlId = courseControlId; - line.controlId = controlId; - line.textLineKind = textLineKind; - lines[index] = line; - } - - return lines; + return text.Split(new char[] { '|' }) + .ConvertAll(t => + { + DescriptionLine line = new DescriptionLine(); + line.kind = DescriptionLineKind.Text; + line.boxes = new object[1]; + line.boxes[0] = t; + line.textual = CourseFormatter.ExpandText(eventDB, courseView, t); + line.courseControlId = courseControlId; + line.controlId = controlId; + line.textLineKind = textLineKind; + return line; + }); } // Given some text, a text line for it to a list if the text is non-empty. diff --git a/src/PurplePen/DescriptionRenderer.cs b/src/PurplePen/DescriptionRenderer.cs index 2ece6ac00..bbb465968 100644 --- a/src/PurplePen/DescriptionRenderer.cs +++ b/src/PurplePen/DescriptionRenderer.cs @@ -719,11 +719,11 @@ private void RenderLine(IRenderer renderer, DescriptionLine descriptionLine, Des switch (descriptionLine.kind) { case DescriptionLineKind.Title: - RenderSingleLineText(renderer, TITLE_FONT, StringAlignment.Center, (string) (descriptionLine.boxes[0]), 0, 0, fullWidth, 100, clipRect); + RenderSingleLineText(renderer, TITLE_FONT, StringAlignment.Center, (string) (descriptionLine.textual), 0, 0, fullWidth, 100, clipRect); break; case DescriptionLineKind.SecondaryTitle: - RenderSingleLineText(renderer, TITLE_FONT, StringAlignment.Center, (string) (descriptionLine.boxes[0]), 0, 0, fullWidth, 100, clipRect); + RenderSingleLineText(renderer, TITLE_FONT, StringAlignment.Center, (string) (descriptionLine.textual), 0, 0, fullWidth, 100, clipRect); break; case DescriptionLineKind.Header2Box: @@ -810,7 +810,7 @@ private void RenderLine(IRenderer renderer, DescriptionLine descriptionLine, Des break; case DescriptionLineKind.Text: - RenderWrappedText(renderer, TEXTLINE_FONT, StringAlignment.Near, (string) (descriptionLine.boxes[0]), 20, 0, fullWidth, 100, clipRect); + RenderWrappedText(renderer, TEXTLINE_FONT, StringAlignment.Near, (string) (descriptionLine.textual), 20, 0, fullWidth, 100, clipRect); break; default: diff --git a/src/PurplePen/PurplePen.csproj b/src/PurplePen/PurplePen.csproj index ef16c8092..a889b3ab8 100644 --- a/src/PurplePen/PurplePen.csproj +++ b/src/PurplePen/PurplePen.csproj @@ -172,6 +172,7 @@ ChangeText.cs + Form @@ -1500,6 +1501,7 @@ ResXFileCodeGenerator CommandNameText.pl.Designer.cs + Designer ResXFileCodeGenerator diff --git a/src/PurplePen/SystemExtensions.cs b/src/PurplePen/SystemExtensions.cs new file mode 100644 index 000000000..4345f4076 --- /dev/null +++ b/src/PurplePen/SystemExtensions.cs @@ -0,0 +1,12 @@ +using System; + +namespace PurplePen +{ + public static class SystemExtensions + { + public static TResult[] ConvertAll(this TSource[] _, Converter converter) + { + return Array.ConvertAll(_, converter); + } + } +} \ No newline at end of file