Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LT-21674: Use Dictionary-Context style for Before/After #39

Merged
merged 1 commit into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading