Skip to content

Commit fcdb5d2

Browse files
committed
LT-21761: Add Table indenting and right justification
Use the table parent as the basis. Change-Id: I9e49a9570c7c9d09696e1bb4c4ba22636e5cb1af
1 parent 84ae912 commit fcdb5d2

File tree

6 files changed

+47
-46
lines changed

6 files changed

+47
-46
lines changed

Src/xWorks/ConfiguredLcmGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2940,7 +2940,7 @@ select match.Groups["rowcontents"] into rowContentsGroup
29402940
GenerateTableRow(usfm.GetSubstring(row.Item1, row.Item2), writer, config, settings, writingSystem);
29412941
}
29422942
settings.ContentGenerator.EndTableBody(writer);
2943-
settings.ContentGenerator.EndTable(writer);
2943+
settings.ContentGenerator.EndTable(writer, config);
29442944
writer.Flush();
29452945
}
29462946
return bldr;

Src/xWorks/ILcmContentGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ IFragment GenerateGroupingNode(object field, string className, ConfigurableDicti
4747
void AddTableCell(IFragmentWriter writer, bool isHead, int colSpan, HorizontalAlign alignment, IFragment content);
4848
void EndTableRow(IFragmentWriter writer);
4949
void EndTableBody(IFragmentWriter writer);
50-
void EndTable(IFragmentWriter writer);
50+
void EndTable(IFragmentWriter writer, ConfigurableDictionaryNode config);
5151
void StartEntry(IFragmentWriter writer, ConfigurableDictionaryNode config, string className, Guid entryGuid, int index, RecordClerk clerk);
5252
void AddEntryData(IFragmentWriter writer, List<ConfiguredLcmGenerator.ConfigFragment> pieces);
5353
void EndEntry(IFragmentWriter writer);

Src/xWorks/LcmJsonGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ public void EndTableBody(IFragmentWriter writer)
248248
// TODO: decide on a useful json representation for tables
249249
}
250250

251-
public void EndTable(IFragmentWriter writer)
251+
public void EndTable(IFragmentWriter writer, ConfigurableDictionaryNode config)
252252
{
253253
// TODO: decide on a useful json representation for tables
254254
}

Src/xWorks/LcmWordGenerator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,7 +1027,7 @@ public void EndTableBody(IFragmentWriter writer)
10271027
{
10281028
// Nothing to do for Word export.
10291029
}
1030-
public void EndTable(IFragmentWriter writer)
1030+
public void EndTable(IFragmentWriter writer, ConfigurableDictionaryNode config)
10311031
{
10321032
WordFragmentWriter wordWriter = (WordFragmentWriter)writer;
10331033

@@ -1044,7 +1044,7 @@ public void EndTable(IFragmentWriter writer)
10441044
WP.TableProperties tblProp = new WP.TableProperties();
10451045

10461046
WP.TableRowAlignmentValues tableAlignment = WP.TableRowAlignmentValues.Left;
1047-
int indentVal = WordStylesGenerator.GetTableIndentInfo(_propertyTable, ref tableAlignment);
1047+
int indentVal = WordStylesGenerator.GetTableIndentInfo(_propertyTable, config, ref tableAlignment);
10481048

10491049
var tableJustify = new WP.TableJustification();
10501050
tableJustify.Val = tableAlignment;

Src/xWorks/LcmXhtmlGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -857,7 +857,7 @@ public void EndTableBody(IFragmentWriter writer)
857857
((XmlFragmentWriter)writer).Writer.WriteFullEndElement(); // should be </tbody>
858858
}
859859

860-
public void EndTable(IFragmentWriter writer)
860+
public void EndTable(IFragmentWriter writer, ConfigurableDictionaryNode config)
861861
{
862862
((XmlFragmentWriter)writer).Writer.WriteEndElement(); // should be </table>
863863
}

Src/xWorks/WordStylesGenerator.cs

Lines changed: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,47 @@ private static AncestorIndents CalculateParagraphIndentsFromAncestors(Configurab
759759
return new AncestorIndents(parentNode, GetLeadingIndent(exportStyleInfo), GetHangingIndentIfAny(exportStyleInfo));
760760
}
761761

762+
/// <summary>
763+
/// Gets the indentation information for a Table.
764+
/// </summary>
765+
/// <param name="tableAlignment">Returns the table alignment.</param>
766+
/// <returns>Returns the indentation value.</returns>
767+
internal static int GetTableIndentInfo(ReadOnlyPropertyTable propertyTable, ConfigurableDictionaryNode config, ref TableRowAlignmentValues tableAlignment)
768+
{
769+
var style = config.Parent?.Style;
770+
var styleSheet = FontHeightAdjuster.StyleSheetFromPropertyTable(propertyTable);
771+
if (style == null || styleSheet == null || !styleSheet.Styles.Contains(style))
772+
{
773+
return 0;
774+
}
775+
776+
var projectStyle = styleSheet.Styles[style];
777+
var exportStyleInfo = new ExportStyleInfo(projectStyle);
778+
779+
// Get the indentation value.
780+
int indentVal = 0;
781+
var hangingIndent = 0.0f;
782+
if (exportStyleInfo.HasFirstLineIndent)
783+
{
784+
var firstLineIndentValue = MilliPtToTwentiPt(exportStyleInfo.FirstLineIndent);
785+
if (firstLineIndentValue < 0.0f)
786+
{
787+
hangingIndent = firstLineIndentValue;
788+
}
789+
}
790+
if (exportStyleInfo.HasLeadingIndent || hangingIndent < 0.0f)
791+
{
792+
var leadingIndent = CalculateMarginLeft(exportStyleInfo, new AncestorIndents(0.0f, 0.0f), hangingIndent);
793+
indentVal = (int)leadingIndent;
794+
}
795+
796+
// Get the alignment direction.
797+
tableAlignment = exportStyleInfo.DirectionIsRightToLeft == TriStateBool.triTrue ?
798+
TableRowAlignmentValues.Right : TableRowAlignmentValues.Left;
799+
800+
return indentVal;
801+
}
802+
762803
private static float CalculateMarginLeft(ExportStyleInfo exportStyleInfo, AncestorIndents ancestorIndents,
763804
float hangingIndent)
764805
{
@@ -958,46 +999,6 @@ private static int MilliPtToEighthPt(int millipoints)
958999
return (int)Math.Round((float)millipoints / 125, 0);
9591000
}
9601001

961-
/// <summary>
962-
/// Gets the indentation information for a Table.
963-
/// </summary>
964-
/// <param name="tableAlignment">Returns the table alignment.</param>
965-
/// <returns>Returns the indentation value.</returns>
966-
internal static int GetTableIndentInfo(ReadOnlyPropertyTable propertyTable, ref TableRowAlignmentValues tableAlignment)
967-
{
968-
var styleSheet = FontHeightAdjuster.StyleSheetFromPropertyTable(propertyTable);
969-
if (styleSheet == null || !styleSheet.Styles.Contains(WordStylesGenerator.DictionaryNormal))
970-
{
971-
return 0;
972-
}
973-
974-
var projectStyle = styleSheet.Styles[WordStylesGenerator.DictionaryNormal];
975-
var exportStyleInfo = new ExportStyleInfo(projectStyle);
976-
977-
// Get the indentation value.
978-
int indentVal = 0;
979-
var hangingIndent = 0.0f;
980-
if (exportStyleInfo.HasFirstLineIndent)
981-
{
982-
var firstLineIndentValue = MilliPtToTwentiPt(exportStyleInfo.FirstLineIndent);
983-
if (firstLineIndentValue < 0.0f)
984-
{
985-
hangingIndent = firstLineIndentValue;
986-
}
987-
}
988-
if (exportStyleInfo.HasLeadingIndent || hangingIndent < 0.0f )
989-
{
990-
var leadingIndent = CalculateMarginLeft(exportStyleInfo, new AncestorIndents(0.0f, 0.0f), hangingIndent);
991-
indentVal = (int)leadingIndent;
992-
}
993-
994-
// Get the alignment direction.
995-
tableAlignment = exportStyleInfo.DirectionIsRightToLeft == TriStateBool.triTrue ?
996-
TableRowAlignmentValues.Right : TableRowAlignmentValues.Left;
997-
998-
return indentVal;
999-
}
1000-
10011002
private class AncestorIndents
10021003
{
10031004
public AncestorIndents(float margin, float textIndent) : this(null, margin, textIndent)

0 commit comments

Comments
 (0)