Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LT-21761: Add Table indenting and right justification #35

Merged
merged 2 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading