Skip to content

Commit

Permalink
LT-21674: Use Dictionary-Context style for Before/After (#39)
Browse files Browse the repository at this point in the history
Change-Id: I3c558a1a9337dfa2bf11ae21133fb49df2461f14
  • Loading branch information
mark-sil authored May 2, 2024
1 parent bea232f commit 832787c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 15 deletions.
44 changes: 29 additions & 15 deletions Src/xWorks/LcmWordGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -1533,5 +1528,24 @@ public static string GetBestUniqueNameForNode(Dictionary<string, Style> styles,
}
return className;
}

/// <summary>
/// Creates a BeforeAfterBetween run using the text provided and using the BeforeAfterBetween style.
/// </summary>
/// <param name="text">Text for the run.</param>
/// <returns>The BeforeAfterBetween run.</returns>
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;
}
}
}
5 changes: 5 additions & 0 deletions Src/xWorks/WordStylesGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 832787c

Please sign in to comment.