diff --git a/Src/xWorks/LcmWordGenerator.cs b/Src/xWorks/LcmWordGenerator.cs index 6ef11f9bd1..3f863d877b 100644 --- a/Src/xWorks/LcmWordGenerator.cs +++ b/Src/xWorks/LcmWordGenerator.cs @@ -832,8 +832,6 @@ config.DictionaryNodeOptions is DictionaryNodeGroupingOptions && WP.ParagraphProperties paragraphProps = new WP.ParagraphProperties(new ParagraphStyleId() { Val = config.Style }); groupPara.PrependChild(paragraphProps); - - AddStyles(config, false); } groupData.DocBody.AppendChild(groupPara); } diff --git a/Src/xWorks/WordStylesGenerator.cs b/Src/xWorks/WordStylesGenerator.cs index da8b882ab4..753fa0d82a 100644 --- a/Src/xWorks/WordStylesGenerator.cs +++ b/Src/xWorks/WordStylesGenerator.cs @@ -86,8 +86,7 @@ internal static Style GenerateWordStyleFromLcmStyleSheet( string styleName, int wsId, ConfigurableDictionaryNode node, ReadOnlyPropertyTable propertyTable) { - return GenerateWordStyleFromLcmStyleSheet(styleName, wsId, node, propertyTable, - false, true); + return GenerateWordStyleFromLcmStyleSheet(styleName, wsId, node, propertyTable, true); } /// @@ -105,7 +104,7 @@ internal static Style GenerateWordStyleFromLcmStyleSheet( /// internal static Style GenerateWordStyleFromLcmStyleSheet( string styleName, int wsId, ConfigurableDictionaryNode node, - ReadOnlyPropertyTable propertyTable, bool calculateFirstSenseStyle, bool allowFirstLineIndent) + ReadOnlyPropertyTable propertyTable, bool allowFirstLineIndent) { var styleSheet = FontHeightAdjuster.StyleSheetFromPropertyTable(propertyTable); if (styleSheet == null || !styleSheet.Styles.Contains(styleName)) @@ -133,11 +132,6 @@ internal static Style GenerateWordStyleFromLcmStyleSheet( exportStyle.Type = StyleValues.Paragraph; var hangingIndent = 0.0f; - // Tuple ancestorIndents used for ancestor components leadingIndent and hangingIndent. - var ancestorIndents = new AncestorIndents(0.0f, 0.0f); - if (exportStyleInfo.IsParagraphStyle && node != null) - ancestorIndents = CalculateParagraphIndentsFromAncestors(node, styleSheet, ancestorIndents); - if (exportStyleInfo.HasAlignment) { var alignmentStyle = exportStyleInfo.Alignment.AsWordStyle(); @@ -209,34 +203,25 @@ internal static Style GenerateWordStyleFromLcmStyleSheet( parProps.Append(new KeepLines()); } - // calculate leading indent, unless it will be calculated later for first sense style - if (exportStyleInfo.HasLeadingIndent || hangingIndent < 0.0f || - ancestorIndents.TextIndent < 0.0f) + // calculate leading indent. + if (exportStyleInfo.HasLeadingIndent || hangingIndent < 0.0f) { - if (!calculateFirstSenseStyle || ancestorIndents.Ancestor == null) + ConfigurableDictionaryNode ancestor = null; + if (node != null) + ancestor = AncestorWithParagraphStyle(node, styleSheet); + + var senseOptions = ancestor == null ? null : ancestor.DictionaryNodeOptions as DictionaryNodeSenseOptions; + if (ancestor == null || + senseOptions == null || + !senseOptions.DisplayEachSenseInAParagraph) { - var leadingIndent = CalculateMarginLeft(exportStyleInfo, ancestorIndents, hangingIndent); + var leadingIndent = CalculateMarginLeft(exportStyleInfo, hangingIndent); if (exportStyleInfo.DirectionIsRightToLeft == TriStateBool.triTrue) parProps.Append(new Indentation() { Right = leadingIndent.ToString() }); else parProps.Append(new Indentation() { Left = leadingIndent.ToString() }); } - else - { - var senseOptions = ancestorIndents.Ancestor.DictionaryNodeOptions as DictionaryNodeSenseOptions; - if (senseOptions == null || !senseOptions.DisplayEachSenseInAParagraph) - { - var leadingIndent = CalculateMarginLeft(exportStyleInfo, ancestorIndents, hangingIndent); - - if (exportStyleInfo.DirectionIsRightToLeft == TriStateBool.triTrue) - parProps.Append(new Indentation() { Right = leadingIndent.ToString() }); - else - parProps.Append(new Indentation() { Left = leadingIndent.ToString() }); - } - // else, leading indent will be added when we calculate the first sense style. - } - } if (exportStyleInfo.HasLineSpacing) @@ -296,23 +281,6 @@ internal static Style GenerateWordStyleFromLcmStyleSheet( parProps.Append(new Indentation() { Right = MilliPtToTwentiPt(exportStyleInfo.TrailingIndent).ToString() }); } - // if leadingIndent was not calculated above, indent will be calculated now for first sense style - if (calculateFirstSenseStyle && ancestorIndents.Ancestor != null) - { - var senseOptions = ancestorIndents.Ancestor.DictionaryNodeOptions as DictionaryNodeSenseOptions; - if (senseOptions != null && senseOptions.DisplayEachSenseInAParagraph) - { - ancestorIndents = CalculateParagraphIndentsFromAncestors(ancestorIndents.Ancestor, styleSheet, new AncestorIndents(0f, 0f)); - var leadingIndent = CalculateMarginLeft(exportStyleInfo, ancestorIndents, hangingIndent); - - // Check bidirectional flag to determine correct orientation for indent - if (exportStyleInfo.DirectionIsRightToLeft == TriStateBool.triTrue) - parProps.Append(new Indentation() { Right = leadingIndent.ToString() }); - else - parProps.Append(new Indentation() { Left = leadingIndent.ToString() }); - } - } - // If text direction is right to left, add BiDi property to the paragraph. if (exportStyleInfo.DirectionIsRightToLeft == TriStateBool.triTrue) { @@ -609,7 +577,7 @@ internal static Styles GenerateContinuationWordStyles( ConfigurableDictionaryNode node, ReadOnlyPropertyTable propertyTable) { Style contStyle = GenerateWordStyleFromLcmStyleSheet(node.Style, DefaultStyle, node, - propertyTable, false, false); + propertyTable, false); contStyle.StyleName.Val = node.Style + EntryStyleContinue; contStyle.StyleId = node.Style + EntryStyleContinue; @@ -789,21 +757,18 @@ private static bool GetFontValue(InheritableStyleProp wsFontInfo, IStylePr return true; } - private static AncestorIndents CalculateParagraphIndentsFromAncestors(ConfigurableDictionaryNode currentNode, - LcmStyleSheet styleSheet, AncestorIndents ancestorIndents) + private static ConfigurableDictionaryNode AncestorWithParagraphStyle(ConfigurableDictionaryNode currentNode, + LcmStyleSheet styleSheet) { var parentNode = currentNode; do { parentNode = parentNode.Parent; if (parentNode == null) - return ancestorIndents; + return null; } while (!IsParagraphStyle(parentNode, styleSheet)); - var projectStyle = styleSheet.Styles[parentNode.Style]; - var exportStyleInfo = new ExportStyleInfo(projectStyle); - - return new AncestorIndents(parentNode, GetLeadingIndent(exportStyleInfo), GetHangingIndentIfAny(exportStyleInfo)); + return parentNode; } /// @@ -836,7 +801,7 @@ internal static int GetTableIndentInfo(ReadOnlyPropertyTable propertyTable, Conf } if (exportStyleInfo.HasLeadingIndent || hangingIndent < 0.0f) { - var leadingIndent = CalculateMarginLeft(exportStyleInfo, new AncestorIndents(0.0f, 0.0f), hangingIndent); + var leadingIndent = CalculateMarginLeft(exportStyleInfo, hangingIndent); indentVal = (int)leadingIndent; } @@ -847,8 +812,12 @@ internal static int GetTableIndentInfo(ReadOnlyPropertyTable propertyTable, Conf return indentVal; } - private static float CalculateMarginLeft(ExportStyleInfo exportStyleInfo, AncestorIndents ancestorIndents, - float hangingIndent) + /// + /// Calculate the left margin. + /// Note that in Word Styles the left margin is not combined with its ancestor so + /// no adjustment is necessary. + /// + private static float CalculateMarginLeft(ExportStyleInfo exportStyleInfo, float hangingIndent) { var leadingIndent = 0.0f; if (exportStyleInfo.HasLeadingIndent) @@ -856,23 +825,10 @@ private static float CalculateMarginLeft(ExportStyleInfo exportStyleInfo, Ancest leadingIndent = MilliPtToTwentiPt(exportStyleInfo.LeadingIndent); } - var ancestorMargin = ancestorIndents.Margin - ancestorIndents.TextIndent; - leadingIndent -= ancestorMargin + hangingIndent; + leadingIndent -= hangingIndent; return leadingIndent; } - private static float GetHangingIndentIfAny(ExportStyleInfo exportStyleInfo) - { - // Handles both first-line and hanging indent: hanging indent represented as a negative first-line indent value - return exportStyleInfo.HasFirstLineIndent && exportStyleInfo.FirstLineIndent < 0 ? - MilliPtToTwentiPt(exportStyleInfo.FirstLineIndent) : 0.0f; - } - - private static float GetLeadingIndent(ExportStyleInfo exportStyleInfo) - { - return exportStyleInfo.HasLeadingIndent ? MilliPtToTwentiPt(exportStyleInfo.LeadingIndent) : 0.0f; - } - /// /// Returns a style containing only the run properties from the full style declaration /// @@ -1045,25 +1001,6 @@ private static int MilliPtToEighthPt(int millipoints) { return (int)Math.Round((float)millipoints / 125, 0); } - - private class AncestorIndents - { - public AncestorIndents(float margin, float textIndent) : this(null, margin, textIndent) - { - } - - public AncestorIndents(ConfigurableDictionaryNode ancestor, float margin, float textIndent) - { - Ancestor = ancestor; - Margin = margin; - TextIndent = textIndent; - } - - public float Margin { get; private set; } - public float TextIndent { get; private set; } - public ConfigurableDictionaryNode Ancestor { get; private set; } - } - } public static class WordStyleExtensions