Skip to content

Commit 103232b

Browse files
author
ArthurHub
committed
handle table center/right alignment
1 parent 2a7a652 commit 103232b

2 files changed

Lines changed: 36 additions & 23 deletions

File tree

Source/Demo/Common/Samples/03.Tables.htm

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -283,29 +283,31 @@ <h2>
283283
</table>
284284
<p>
285285
</p>
286-
<table border="10" cellspacing="0">
287-
<tr>
288-
<td rowspan="2">
289-
Cell One
290-
</td>
291-
<td colspan="2">
292-
Cell Two
293-
</td>
294-
</tr>
295-
<tr>
296-
<td>
297-
Cell Five
298-
</td>
299-
<td rowspan="2">
300-
Cell Six
301-
</td>
302-
</tr>
303-
<tr>
304-
<td colspan="2">
305-
Cell Seven
306-
</td>
307-
</tr>
308-
</table>
286+
<div align="center">
287+
<table border="10" cellspacing="0">
288+
<tr>
289+
<td rowspan="2">
290+
Cell One
291+
</td>
292+
<td colspan="2">
293+
Cell Two
294+
</td>
295+
</tr>
296+
<tr>
297+
<td>
298+
Cell Five
299+
</td>
300+
<td rowspan="2">
301+
Cell Six
302+
</td>
303+
</tr>
304+
<tr>
305+
<td colspan="2">
306+
Cell Seven
307+
</td>
308+
</tr>
309+
</table>
310+
</div>
309311
<p>
310312
</p>
311313
</blockquote>

Source/HtmlRenderer/Core/Dom/CssLayoutEngineTable.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,17 @@ private void LayoutCells(RGraphics g)
613613
double maxBottom = 0f;
614614
int currentrow = 0;
615615

616+
// change start X by if the table should align to center or right
617+
if (_tableBox.TextAlign == CssConstants.Center || _tableBox.TextAlign == CssConstants.Right)
618+
{
619+
double maxRightCalc = GetWidthSum();
620+
startx = _tableBox.TextAlign == CssConstants.Right
621+
? GetAvailableTableWidth() - maxRightCalc
622+
: startx + (GetAvailableTableWidth() - maxRightCalc) / 2;
623+
624+
_tableBox.Location = new RPoint(startx - _tableBox.ActualBorderLeftWidth - _tableBox.ActualPaddingLeft - GetHorizontalSpacing(), _tableBox.Location.Y);
625+
}
626+
616627
for (int i = 0; i < _allRows.Count; i++)
617628
{
618629
var row = _allRows[i];

0 commit comments

Comments
 (0)