diff --git a/Src/xWorks/ConfiguredLcmGenerator.cs b/Src/xWorks/ConfiguredLcmGenerator.cs index 4f9a7f71df..7ec0d6d567 100644 --- a/Src/xWorks/ConfiguredLcmGenerator.cs +++ b/Src/xWorks/ConfiguredLcmGenerator.cs @@ -2940,7 +2940,7 @@ select match.Groups["rowcontents"] into rowContentsGroup GenerateTableRow(usfm.GetSubstring(row.Item1, row.Item2), writer, config, settings, writingSystem); } settings.ContentGenerator.EndTableBody(writer); - settings.ContentGenerator.EndTable(writer); + settings.ContentGenerator.EndTable(writer, config); writer.Flush(); } return bldr; diff --git a/Src/xWorks/ILcmContentGenerator.cs b/Src/xWorks/ILcmContentGenerator.cs index 0a861ab44b..19e045ee81 100644 --- a/Src/xWorks/ILcmContentGenerator.cs +++ b/Src/xWorks/ILcmContentGenerator.cs @@ -47,7 +47,7 @@ IFragment GenerateGroupingNode(object field, string className, ConfigurableDicti void AddTableCell(IFragmentWriter writer, bool isHead, int colSpan, HorizontalAlign alignment, IFragment content); void EndTableRow(IFragmentWriter writer); void EndTableBody(IFragmentWriter writer); - void EndTable(IFragmentWriter writer); + void EndTable(IFragmentWriter writer, ConfigurableDictionaryNode config); void StartEntry(IFragmentWriter writer, ConfigurableDictionaryNode config, string className, Guid entryGuid, int index, RecordClerk clerk); void AddEntryData(IFragmentWriter writer, List pieces); void EndEntry(IFragmentWriter writer); diff --git a/Src/xWorks/LcmJsonGenerator.cs b/Src/xWorks/LcmJsonGenerator.cs index b55c1294f9..232c83a413 100644 --- a/Src/xWorks/LcmJsonGenerator.cs +++ b/Src/xWorks/LcmJsonGenerator.cs @@ -248,7 +248,7 @@ public void EndTableBody(IFragmentWriter writer) // TODO: decide on a useful json representation for tables } - public void EndTable(IFragmentWriter writer) + public void EndTable(IFragmentWriter writer, ConfigurableDictionaryNode config) { // TODO: decide on a useful json representation for tables } diff --git a/Src/xWorks/LcmWordGenerator.cs b/Src/xWorks/LcmWordGenerator.cs index dd48bd9c18..9c4a236771 100644 --- a/Src/xWorks/LcmWordGenerator.cs +++ b/Src/xWorks/LcmWordGenerator.cs @@ -1027,18 +1027,37 @@ public void EndTableBody(IFragmentWriter writer) { // Nothing to do for Word export. } - public void EndTable(IFragmentWriter writer) + public void EndTable(IFragmentWriter writer, ConfigurableDictionaryNode config) { WordFragmentWriter wordWriter = (WordFragmentWriter)writer; - // If there is a Table Title, then add it now, when we know the number of columns. + // If there is a Table Title, then prepend it now, when we know the number of columns. if (wordWriter.TableTitleContent != null) { wordWriter.CurrentTableRow = new WP.TableRow(); AddTableCell(writer, false, wordWriter.TableColumns, HorizontalAlign.Center, wordWriter.TableTitleContent); - wordWriter.CurrentTable.PrependChild(wordWriter.CurrentTableRow); + wordWriter.CurrentTable.PrependChild(wordWriter.CurrentTableRow); // Prepend so that it is the first row. wordWriter.CurrentTableRow = null; } + + // Create a TableProperties object and specify the indent information. + WP.TableProperties tblProp = new WP.TableProperties(); + + WP.TableRowAlignmentValues tableAlignment = WP.TableRowAlignmentValues.Left; + int indentVal = WordStylesGenerator.GetTableIndentInfo(_propertyTable, config, ref tableAlignment); + + var tableJustify = new WP.TableJustification(); + tableJustify.Val = tableAlignment; + tblProp.Append(tableJustify); + + var tableIndent = new WP.TableIndentation(); + tableIndent.Type = WP.TableWidthUnitValues.Dxa; + tableIndent.Width = indentVal; + tblProp.Append(tableIndent); + + // TableProperties MUST be first, so prepend them. + wordWriter.CurrentTable.PrependChild(tblProp); + wordWriter.TableColumns = 0; wordWriter.TableTitleContent = null; wordWriter.CurrentTable = null; diff --git a/Src/xWorks/LcmXhtmlGenerator.cs b/Src/xWorks/LcmXhtmlGenerator.cs index ca0bbd984e..de97d90c9d 100644 --- a/Src/xWorks/LcmXhtmlGenerator.cs +++ b/Src/xWorks/LcmXhtmlGenerator.cs @@ -857,7 +857,7 @@ public void EndTableBody(IFragmentWriter writer) ((XmlFragmentWriter)writer).Writer.WriteFullEndElement(); // should be } - public void EndTable(IFragmentWriter writer) + public void EndTable(IFragmentWriter writer, ConfigurableDictionaryNode config) { ((XmlFragmentWriter)writer).Writer.WriteEndElement(); // should be } diff --git a/Src/xWorks/WordStylesGenerator.cs b/Src/xWorks/WordStylesGenerator.cs index 9712dbf880..90ddcfb63e 100644 --- a/Src/xWorks/WordStylesGenerator.cs +++ b/Src/xWorks/WordStylesGenerator.cs @@ -759,6 +759,47 @@ private static AncestorIndents CalculateParagraphIndentsFromAncestors(Configurab return new AncestorIndents(parentNode, GetLeadingIndent(exportStyleInfo), GetHangingIndentIfAny(exportStyleInfo)); } + /// + /// Gets the indentation information for a Table. + /// + /// Returns the table alignment. + /// Returns the indentation value. + internal static int GetTableIndentInfo(ReadOnlyPropertyTable propertyTable, ConfigurableDictionaryNode config, ref TableRowAlignmentValues tableAlignment) + { + var style = config.Parent?.Style; + var styleSheet = FontHeightAdjuster.StyleSheetFromPropertyTable(propertyTable); + if (style == null || styleSheet == null || !styleSheet.Styles.Contains(style)) + { + return 0; + } + + var projectStyle = styleSheet.Styles[style]; + var exportStyleInfo = new ExportStyleInfo(projectStyle); + + // Get the indentation value. + int indentVal = 0; + var hangingIndent = 0.0f; + if (exportStyleInfo.HasFirstLineIndent) + { + var firstLineIndentValue = MilliPtToTwentiPt(exportStyleInfo.FirstLineIndent); + if (firstLineIndentValue < 0.0f) + { + hangingIndent = firstLineIndentValue; + } + } + if (exportStyleInfo.HasLeadingIndent || hangingIndent < 0.0f) + { + var leadingIndent = CalculateMarginLeft(exportStyleInfo, new AncestorIndents(0.0f, 0.0f), hangingIndent); + indentVal = (int)leadingIndent; + } + + // Get the alignment direction. + tableAlignment = exportStyleInfo.DirectionIsRightToLeft == TriStateBool.triTrue ? + TableRowAlignmentValues.Right : TableRowAlignmentValues.Left; + + return indentVal; + } + private static float CalculateMarginLeft(ExportStyleInfo exportStyleInfo, AncestorIndents ancestorIndents, float hangingIndent) {