Skip to content

Commit

Permalink
Word Export: LT-21891: Remove first blank line
Browse files Browse the repository at this point in the history
Change-Id: I9492feb443932f3be187e7f61ac64eda235c6cd8
  • Loading branch information
mark-sil committed Dec 10, 2024
1 parent 435ecf4 commit e1fae8a
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions Src/xWorks/LcmWordGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public static void SavePublishedDocx(int[] entryHvos, DictionaryPublicationDecor
{ ContentGenerator = generator, StylesGenerator = generator};
settings.StylesGenerator.AddGlobalStyles(configuration, readOnlyPropertyTable);
string lastHeader = null;
bool firstHeader = true;
string firstGuidewordStyle = null;
var entryContents = new Tuple<ICmObject, IFragment>[entryCount];
var entryActions = new List<Action>();
Expand Down Expand Up @@ -112,7 +113,8 @@ public static void SavePublishedDocx(int[] entryHvos, DictionaryPublicationDecor
if (!entry.Item2.IsNullOrEmpty())
{
IFragment letterHeader = GenerateLetterHeaderIfNeeded(entry.Item1,
ref lastHeader, col, settings, readOnlyPropertyTable, propStyleSheet, clerk);
ref lastHeader, col, settings, readOnlyPropertyTable, propStyleSheet, firstHeader, clerk );
firstHeader = false;

// If needed, append letter header to the word doc
if (!letterHeader.IsNullOrEmpty())
Expand Down Expand Up @@ -234,13 +236,13 @@ public static void SavePublishedDocx(int[] entryHvos, DictionaryPublicationDecor

internal static IFragment GenerateLetterHeaderIfNeeded(ICmObject entry, ref string lastHeader, Collator headwordWsCollator,
ConfiguredLcmGenerator.GeneratorSettings settings, ReadOnlyPropertyTable propertyTable, LcmStyleSheet mediatorStyleSheet,
RecordClerk clerk = null)
bool firstHeader, RecordClerk clerk = null)
{
StringBuilder headerTextBuilder = ConfiguredLcmGenerator.GenerateLetterHeaderIfNeeded(entry, ref lastHeader,
headwordWsCollator, settings, clerk);

// Create LetterHeader doc fragment and link it with the letter heading style.
return DocFragment.GenerateLetterHeaderDocFragment(headerTextBuilder.ToString(), WordStylesGenerator.LetterHeadingDisplayName);
return DocFragment.GenerateLetterHeaderDocFragment(headerTextBuilder.ToString(), WordStylesGenerator.LetterHeadingDisplayName, firstHeader);
}

/*
Expand Down Expand Up @@ -308,22 +310,27 @@ public DocFragment(string str) : this()
/// </summary>
/// <param name="str">Letter header string.</param>
/// <param name="styleDisplayName">Letter header style name to display in Word.</param>
internal static DocFragment GenerateLetterHeaderDocFragment(string str, string styleDisplayName)
/// <param name="firstHeader">True if this is the first header being written.</param>
internal static DocFragment GenerateLetterHeaderDocFragment(string str, string styleDisplayName, bool firstHeader)
{
var docFrag = new DocFragment();
// Only create paragraph, run, and text objects if string is nonempty
if (!string.IsNullOrEmpty(str))
{
// Everything other than the Letter Header should be 2 columns. Create a empty
// paragraph with two columns for the last paragraph in the section that uses 2
// columns. (The section is all the entries after the previous letter header.)
var sectProps2 = new SectionProperties(
new HeaderReference() { Id = WordStylesGenerator.PageHeaderIdEven, Type = HeaderFooterValues.Even },
new HeaderReference() { Id = WordStylesGenerator.PageHeaderIdOdd, Type = HeaderFooterValues.Default },
new Columns() { EqualWidth = true, ColumnCount = 2 },
new SectionType() { Val = SectionMarkValues.Continuous }
);
docFrag.DocBody.AppendChild(new WP.Paragraph(new WP.ParagraphProperties(sectProps2)));
// Don't add this paragraph before the first letter header. It results in an extra blank line.
if (!firstHeader)
{
// Everything other than the Letter Header should be 2 columns. Create a empty
// paragraph with two columns for the last paragraph in the section that uses 2
// columns. (The section is all the entries after the previous letter header.)
var sectProps2 = new SectionProperties(
new HeaderReference() { Id = WordStylesGenerator.PageHeaderIdEven, Type = HeaderFooterValues.Even },
new HeaderReference() { Id = WordStylesGenerator.PageHeaderIdOdd, Type = HeaderFooterValues.Default },
new Columns() { EqualWidth = true, ColumnCount = 2 },
new SectionType() { Val = SectionMarkValues.Continuous }
);
docFrag.DocBody.AppendChild(new WP.Paragraph(new WP.ParagraphProperties(sectProps2)));
}

// Create the letter header in a paragraph.
WP.ParagraphProperties paragraphProps = new WP.ParagraphProperties(new ParagraphStyleId() { Val = styleDisplayName });
Expand Down

0 comments on commit e1fae8a

Please sign in to comment.