Skip to content

Commit

Permalink
LT-21761: Add Table indenting and right justification
Browse files Browse the repository at this point in the history
Use the table parent as the basis.

Change-Id: I9e49a9570c7c9d09696e1bb4c4ba22636e5cb1af
  • Loading branch information
mark-sil committed Apr 30, 2024
1 parent 84ae912 commit fcdb5d2
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 46 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
4 changes: 2 additions & 2 deletions Src/xWorks/LcmWordGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
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
81 changes: 41 additions & 40 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 Expand Up @@ -958,46 +999,6 @@ 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 fcdb5d2

Please sign in to comment.