Skip to content

Commit

Permalink
LT-21761: Add Table indenting and right justification
Browse files Browse the repository at this point in the history
Change-Id: I7f9835e66c6aaa5cb9039cc586683c1cb0311138
  • Loading branch information
mark-sil committed Apr 30, 2024
1 parent d6b6f79 commit 84ae912
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 2 deletions.
23 changes: 21 additions & 2 deletions Src/xWorks/LcmWordGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
40 changes: 40 additions & 0 deletions Src/xWorks/WordStylesGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,46 @@ private static int MilliPtToEighthPt(int millipoints)
return (int)Math.Round((float)millipoints / 125, 0);
}

/// <summary>
/// Gets the indentation information for a Table.
/// </summary>
/// <param name="tableAlignment">Returns the table alignment.</param>
/// <returns>Returns the indentation value.</returns>
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)
Expand Down

0 comments on commit 84ae912

Please sign in to comment.