From 84ae9121b17ef4e328a88f5d7d45aeb8daf5418d Mon Sep 17 00:00:00 2001 From: mark-sil Date: Tue, 30 Apr 2024 10:28:32 -0400 Subject: [PATCH 1/2] LT-21761: Add Table indenting and right justification Change-Id: I7f9835e66c6aaa5cb9039cc586683c1cb0311138 --- Src/xWorks/LcmWordGenerator.cs | 23 ++++++++++++++++-- Src/xWorks/WordStylesGenerator.cs | 40 +++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 2 deletions(-) diff --git a/Src/xWorks/LcmWordGenerator.cs b/Src/xWorks/LcmWordGenerator.cs index dd48bd9c18..d65464691d 100644 --- a/Src/xWorks/LcmWordGenerator.cs +++ b/Src/xWorks/LcmWordGenerator.cs @@ -1031,14 +1031,33 @@ public void EndTable(IFragmentWriter writer) { 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, 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/WordStylesGenerator.cs b/Src/xWorks/WordStylesGenerator.cs index 9712dbf880..2dc533c839 100644 --- a/Src/xWorks/WordStylesGenerator.cs +++ b/Src/xWorks/WordStylesGenerator.cs @@ -958,6 +958,46 @@ private static int MilliPtToEighthPt(int millipoints) return (int)Math.Round((float)millipoints / 125, 0); } + /// + /// Gets the indentation information for a Table. + /// + /// Returns the table alignment. + /// Returns the indentation value. + internal static int GetTableIndentInfo(ReadOnlyPropertyTable propertyTable, ref TableRowAlignmentValues tableAlignment) + { + var styleSheet = FontHeightAdjuster.StyleSheetFromPropertyTable(propertyTable); + if (styleSheet == null || !styleSheet.Styles.Contains(WordStylesGenerator.DictionaryNormal)) + { + return 0; + } + + var projectStyle = styleSheet.Styles[WordStylesGenerator.DictionaryNormal]; + 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 class AncestorIndents { public AncestorIndents(float margin, float textIndent) : this(null, margin, textIndent) From fcdb5d208f768ef2f4255b07ffac6fd9c53c97cc Mon Sep 17 00:00:00 2001 From: mark-sil Date: Tue, 30 Apr 2024 12:42:28 -0400 Subject: [PATCH 2/2] LT-21761: Add Table indenting and right justification Use the table parent as the basis. Change-Id: I9e49a9570c7c9d09696e1bb4c4ba22636e5cb1af --- Src/xWorks/ConfiguredLcmGenerator.cs | 2 +- Src/xWorks/ILcmContentGenerator.cs | 2 +- Src/xWorks/LcmJsonGenerator.cs | 2 +- Src/xWorks/LcmWordGenerator.cs | 4 +- Src/xWorks/LcmXhtmlGenerator.cs | 2 +- Src/xWorks/WordStylesGenerator.cs | 81 ++++++++++++++-------------- 6 files changed, 47 insertions(+), 46 deletions(-) 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 d65464691d..9c4a236771 100644 --- a/Src/xWorks/LcmWordGenerator.cs +++ b/Src/xWorks/LcmWordGenerator.cs @@ -1027,7 +1027,7 @@ 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; @@ -1044,7 +1044,7 @@ public void EndTable(IFragmentWriter writer) WP.TableProperties tblProp = new WP.TableProperties(); WP.TableRowAlignmentValues tableAlignment = WP.TableRowAlignmentValues.Left; - int indentVal = WordStylesGenerator.GetTableIndentInfo(_propertyTable, ref tableAlignment); + int indentVal = WordStylesGenerator.GetTableIndentInfo(_propertyTable, config, ref tableAlignment); var tableJustify = new WP.TableJustification(); tableJustify.Val = tableAlignment; 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 2dc533c839..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) { @@ -958,46 +999,6 @@ private static int MilliPtToEighthPt(int millipoints) return (int)Math.Round((float)millipoints / 125, 0); } - /// - /// Gets the indentation information for a Table. - /// - /// Returns the table alignment. - /// Returns the indentation value. - internal static int GetTableIndentInfo(ReadOnlyPropertyTable propertyTable, ref TableRowAlignmentValues tableAlignment) - { - var styleSheet = FontHeightAdjuster.StyleSheetFromPropertyTable(propertyTable); - if (styleSheet == null || !styleSheet.Styles.Contains(WordStylesGenerator.DictionaryNormal)) - { - return 0; - } - - var projectStyle = styleSheet.Styles[WordStylesGenerator.DictionaryNormal]; - 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 class AncestorIndents { public AncestorIndents(float margin, float textIndent) : this(null, margin, textIndent)