From 832787c7b4fb382bf3001e83efb779283f846d1a Mon Sep 17 00:00:00 2001 From: Mark Kidder <83427558+mark-sil@users.noreply.github.com> Date: Thu, 2 May 2024 15:00:36 -0400 Subject: [PATCH] LT-21674: Use Dictionary-Context style for Before/After (#39) Change-Id: I3c558a1a9337dfa2bf11ae21133fb49df2461f14 --- Src/xWorks/LcmWordGenerator.cs | 44 ++++++++++++++++++++----------- Src/xWorks/WordStylesGenerator.cs | 5 ++++ 2 files changed, 34 insertions(+), 15 deletions(-) diff --git a/Src/xWorks/LcmWordGenerator.cs b/Src/xWorks/LcmWordGenerator.cs index 9c4a236771..dbdb300cb9 100644 --- a/Src/xWorks/LcmWordGenerator.cs +++ b/Src/xWorks/LcmWordGenerator.cs @@ -665,21 +665,15 @@ config.DictionaryNodeOptions is IParaOption && // Add Before text, if it is not going to be displayed in it's own paragraph. if (!displayEachInAParagraph && !string.IsNullOrEmpty(config.Before)) { - WP.Text txt = new WP.Text(config.Before); - txt.Space = SpaceProcessingModeValues.Preserve; - var beforeRun = new WP.Run(txt); + var beforeRun = CreateBeforeAfterBetweenRun(config.Before); ((DocFragment)elementContent).DocBody.PrependChild(beforeRun); } // Add After text, if it is not going to be displayed in it's own paragraph. if (!displayEachInAParagraph && !string.IsNullOrEmpty(config.After)) { - WP.Text txt = new WP.Text(config.After); - txt.Space = SpaceProcessingModeValues.Preserve; - var afterRun = new WP.Run(txt); + var afterRun = CreateBeforeAfterBetweenRun(config.After); ((DocFragment)elementContent).DocBody.Append(afterRun); - // To be consistent with the xhtml output, only the after text uses the same style. - DocFragment.LinkStyleOrInheritParentStyle(elementContent, config); } return elementContent; @@ -778,7 +772,8 @@ config.DictionaryNodeOptions is IParaOption && !eachInAParagraph && !string.IsNullOrEmpty(config.Between)) { - ((DocFragment)collData).Append(config.Between); + var betweenRun = CreateBeforeAfterBetweenRun(config.Between); + ((DocFragment)collData).DocBody.Append(betweenRun); } collData.Append(content); @@ -1253,18 +1248,14 @@ public IFragment WriteProcessedSenses(bool isBlock, IFragment senseContent, Conf // Add Before text for the sharedGramInfo. if (!string.IsNullOrEmpty(config.Before)) { - WP.Text txt = new WP.Text(config.Before); - txt.Space = SpaceProcessingModeValues.Preserve; - var beforeRun = new WP.Run(txt); + var beforeRun = CreateBeforeAfterBetweenRun(config.Before); ((DocFragment)sharedGramInfo).DocBody.PrependChild(beforeRun); } // Add After text for the sharedGramInfo. if (!string.IsNullOrEmpty(config.After)) { - WP.Text txt = new WP.Text(config.After); - txt.Space = SpaceProcessingModeValues.Preserve; - var afterRun = new WP.Run(txt); + var afterRun = CreateBeforeAfterBetweenRun(config.After); ((DocFragment)sharedGramInfo).DocBody.Append(afterRun); } @@ -1303,6 +1294,10 @@ public void AddGlobalStyles(DictionaryConfigurationModel model, ReadOnlyProperty if (letterHeaderStyle != null) _styleSheet.Append(letterHeaderStyle); + var beforeAfterBetweenStyle = WordStylesGenerator.GenerateBeforeAfterBetweenStyle(propertyTable); + if (beforeAfterBetweenStyle != null) + _styleSheet.Append(beforeAfterBetweenStyle); + Styles defaultStyles = WordStylesGenerator.GetDefaultWordStyles(propertyTable, propStyleSheet, model); if (defaultStyles != null) { @@ -1533,5 +1528,24 @@ public static string GetBestUniqueNameForNode(Dictionary styles, } return className; } + + /// + /// Creates a BeforeAfterBetween run using the text provided and using the BeforeAfterBetween style. + /// + /// Text for the run. + /// The BeforeAfterBetween run. + private WP.Run CreateBeforeAfterBetweenRun(string text) + { + WP.Run run = new WP.Run(); + WP.RunProperties runProps = + new WP.RunProperties(new RunStyle() { Val = WordStylesGenerator.BeforeAfterBetweenStyleName }); + run.Append(runProps); + + WP.Text txt = new WP.Text(text); + txt.Space = SpaceProcessingModeValues.Preserve; + run.Append(txt); + + return run; + } } } diff --git a/Src/xWorks/WordStylesGenerator.cs b/Src/xWorks/WordStylesGenerator.cs index 90ddcfb63e..e2ea56a62a 100644 --- a/Src/xWorks/WordStylesGenerator.cs +++ b/Src/xWorks/WordStylesGenerator.cs @@ -39,6 +39,11 @@ public static Style GenerateLetterHeaderStyle( return GenerateWordStyleFromLcmStyleSheet(LetterHeadingStyleName, 0, propertyTable); } + public static Style GenerateBeforeAfterBetweenStyle(ReadOnlyPropertyTable propertyTable) + { + return GenerateWordStyleFromLcmStyleSheet(BeforeAfterBetweenStyleName, 0, propertyTable); + } + public static Styles GetDefaultWordStyles(ReadOnlyPropertyTable propertyTable, LcmStyleSheet propStyleSheet, DictionaryConfigurationModel model) { var styles = new Styles();