Skip to content

Commit

Permalink
LT-21761: Add Table indenting and right justification (#35)
Browse files Browse the repository at this point in the history
* LT-21761: Add Table indenting and right justification

Use the table parent as the basis.

Change-Id: I9e49a9570c7c9d09696e1bb4c4ba22636e5cb1af
  • Loading branch information
mark-sil authored Apr 30, 2024
1 parent d6b6f79 commit c351ca8
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Src/xWorks/ConfiguredLcmGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Src/xWorks/ILcmContentGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ConfiguredLcmGenerator.ConfigFragment> pieces);
void EndEntry(IFragmentWriter writer);
Expand Down
2 changes: 1 addition & 1 deletion Src/xWorks/LcmJsonGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
25 changes: 22 additions & 3 deletions Src/xWorks/LcmWordGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Src/xWorks/LcmXhtmlGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,7 @@ public void EndTableBody(IFragmentWriter writer)
((XmlFragmentWriter)writer).Writer.WriteFullEndElement(); // should be </tbody>
}

public void EndTable(IFragmentWriter writer)
public void EndTable(IFragmentWriter writer, ConfigurableDictionaryNode config)
{
((XmlFragmentWriter)writer).Writer.WriteEndElement(); // should be </table>
}
Expand Down
41 changes: 41 additions & 0 deletions Src/xWorks/WordStylesGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,47 @@ private static AncestorIndents CalculateParagraphIndentsFromAncestors(Configurab
return new AncestorIndents(parentNode, GetLeadingIndent(exportStyleInfo), GetHangingIndentIfAny(exportStyleInfo));
}

/// <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, 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)
{
Expand Down

0 comments on commit c351ca8

Please sign in to comment.