diff --git a/Src/xWorks/LcmWordGenerator.cs b/Src/xWorks/LcmWordGenerator.cs index 0de6ef18c1..d7589d7667 100644 --- a/Src/xWorks/LcmWordGenerator.cs +++ b/Src/xWorks/LcmWordGenerator.cs @@ -71,7 +71,7 @@ public static void SavePublishedDocx(int[] entryHvos, DictionaryPublicationDecor { ContentGenerator = generator, StylesGenerator = generator}; settings.StylesGenerator.AddGlobalStyles(configuration, readOnlyPropertyTable); string lastHeader = null; - string firstHeadwordStyle = null; + string firstGuidewordStyle = null; var entryContents = new Tuple[entryCount]; var entryActions = new List(); @@ -121,9 +121,9 @@ public static void SavePublishedDocx(int[] entryHvos, DictionaryPublicationDecor // Append the entry to the word doc fragment.Append(entry.Item2); - if (string.IsNullOrEmpty(firstHeadwordStyle)) + if (string.IsNullOrEmpty(firstGuidewordStyle)) { - firstHeadwordStyle = GetFirstHeadwordStyle((DocFragment)entry.Item2); + firstGuidewordStyle = GetFirstGuidewordStyle((DocFragment)entry.Item2, configuration.Type); } } } @@ -181,7 +181,7 @@ public static void SavePublishedDocx(int[] entryHvos, DictionaryPublicationDecor var headerParts = fragment.mainDocPart.HeaderParts; if (!headerParts.Any()) { - AddPageHeaderPartsToPackage(fragment.DocFrag, firstHeadwordStyle); + AddPageHeaderPartsToPackage(fragment.DocFrag, firstGuidewordStyle); } // Add document settings @@ -2008,35 +2008,35 @@ public static NumberingDefinitionsPart AddNumberingPartToPackage(WordprocessingD } // Add the page HeaderParts to the document. - public static void AddPageHeaderPartsToPackage(WordprocessingDocument doc, string headwordStyle) + public static void AddPageHeaderPartsToPackage(WordprocessingDocument doc, string guidewordStyle) { // Generate header for even pages. HeaderPart even = doc.MainDocumentPart.AddNewPart(WordStylesGenerator.PageHeaderIdEven); - GenerateHeaderPartContent(even, true, headwordStyle); + GenerateHeaderPartContent(even, true, guidewordStyle); // Generate header for odd pages. HeaderPart odd = doc.MainDocumentPart.AddNewPart(WordStylesGenerator.PageHeaderIdOdd); - GenerateHeaderPartContent(odd, false, headwordStyle); + GenerateHeaderPartContent(odd, false, guidewordStyle); } /// - /// Adds the page number and the first or last headword to the HeaderPart. + /// Adds the page number and the first or last guideword to the HeaderPart. /// /// HeaderPart to modify. /// True = generate content for even pages. /// False = generate content for odd pages. - /// The style that will be used to find the first or last headword on the page. - private static void GenerateHeaderPartContent(HeaderPart part, bool even, string headwordStyle) + /// The style that will be used to find the first or last guideword on the page. + private static void GenerateHeaderPartContent(HeaderPart part, bool even, string guidewordStyle) { ParagraphStyleId paraStyleId = new ParagraphStyleId() { Val = WordStylesGenerator.PageHeaderStyleName }; Paragraph para = new Paragraph(new ParagraphProperties(paraStyleId)); if (even) { - if (!string.IsNullOrEmpty(headwordStyle)) + if (!string.IsNullOrEmpty(guidewordStyle)) { - // Add the first headword on the page to the header. - para.Append(new Run(new SimpleField() { Instruction = "STYLEREF " + headwordStyle + " \\* MERGEFORMAT" })); + // Add the first guideword on the page to the header. + para.Append(new Run(new SimpleField() { Instruction = "STYLEREF \"" + guidewordStyle + "\" \\* MERGEFORMAT" })); } para.Append(new WP.Run(new WP.TabChar())); // Add the page number to the header. @@ -2047,10 +2047,10 @@ private static void GenerateHeaderPartContent(HeaderPart part, bool even, string // Add the page number to the header. para.Append(new WP.Run(new SimpleField() { Instruction = "PAGE" })); para.Append(new WP.Run(new WP.TabChar())); - if (!string.IsNullOrEmpty(headwordStyle)) + if (!string.IsNullOrEmpty(guidewordStyle)) { - // Add the last headword on the page to the header. - para.Append(new WP.Run(new SimpleField() { Instruction = "STYLEREF " + headwordStyle + " \\l \\* MERGEFORMAT" })); + // Add the last guideword on the page to the header. + para.Append(new WP.Run(new SimpleField() { Instruction = "STYLEREF \"" + guidewordStyle + "\" \\l \\* MERGEFORMAT" })); } } @@ -2931,16 +2931,20 @@ internal static bool IsWritingSystemRightToLeft(LcmCache cache, int wsId) } /// - /// Get the full style name for the first RunStyle that begins with "Headword". + /// Get the full style name for the first RunStyle that begins with the guideword style. /// - /// The full style name that begins with "Headword". + /// Indicates if we are are exporting a Reversal or regular dictionary. + /// The full style name that begins with the guideword style. /// Null if none are found. - public static string GetFirstHeadwordStyle(DocFragment frag) + public static string GetFirstGuidewordStyle(DocFragment frag, DictionaryConfigurationModel.ConfigType type) { - // Find the first run style with a value that begins with "Headword". + string guidewordStyle = type == DictionaryConfigurationModel.ConfigType.Reversal ? + WordStylesGenerator.ReversalFormDisplayName : WordStylesGenerator.HeadwordDisplayName; + + // Find the first run style with a value that begins with the guideword style. foreach (RunStyle runStyle in frag.DocBody.Descendants()) { - if (runStyle.Val.Value.StartsWith(WordStylesGenerator.HeadwordDisplayName)) + if (runStyle.Val.Value.StartsWith(guidewordStyle)) { return runStyle.Val.Value; } diff --git a/Src/xWorks/WordStylesGenerator.cs b/Src/xWorks/WordStylesGenerator.cs index 82e20afee1..f1454eda26 100644 --- a/Src/xWorks/WordStylesGenerator.cs +++ b/Src/xWorks/WordStylesGenerator.cs @@ -32,6 +32,7 @@ public class WordStylesGenerator internal const string WritingSystemStyleName = "Writing System Abbreviation"; internal const string WritingSystemDisplayName = "Writing System Abbreviation"; internal const string HeadwordDisplayName = "Headword"; + internal const string ReversalFormDisplayName = "Reversal Form"; internal const string StyleSeparator = " : "; internal const string LangTagPre = "[lang=\'"; internal const string LangTagPost = "\']"; diff --git a/Src/xWorks/xWorksTests/LcmWordGeneratorTests.cs b/Src/xWorks/xWorksTests/LcmWordGeneratorTests.cs index c59067e5cd..ca2974f9c5 100644 --- a/Src/xWorks/xWorksTests/LcmWordGeneratorTests.cs +++ b/Src/xWorks/xWorksTests/LcmWordGeneratorTests.cs @@ -849,7 +849,7 @@ public void GetFirstHeadwordStyle() var result = ConfiguredLcmGenerator.GenerateContentForEntry(entry, mainEntryNode, null, DefaultSettings, 0) as DocFragment; //SUT - string firstHeadwordStyle = LcmWordGenerator.GetFirstHeadwordStyle(result); + string firstHeadwordStyle = LcmWordGenerator.GetFirstGuidewordStyle(result, DictionaryConfigurationModel.ConfigType.Root); Assert.True(firstHeadwordStyle == "Headword[lang='en']"); }