Skip to content

Commit 24e622e

Browse files
committed
table rendering fix
1 parent 180529b commit 24e622e

File tree

6 files changed

+50
-5
lines changed

6 files changed

+50
-5
lines changed

src/render_table.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ int litehtml::render_item_table::_render(int x, int y, int max_width, const cont
166166
int min_table_width = 0;
167167
int max_table_width = 0;
168168

169-
if (cb_size.width_type != containing_block_context::cbc_value_type_auto)
169+
if (cb_size.width_type == containing_block_context::cbc_value_type_absolute)
170170
{
171171
table_width = m_grid->calc_table_width(cb_size.width - table_width_spacing, false, min_table_width, max_table_width);
172172
}
@@ -370,15 +370,17 @@ int litehtml::render_item_table::_render(int x, int y, int max_width, const cont
370370
}
371371
}
372372

373-
calc_auto_margins(containing_block_size.width);
373+
int ret = std::min(table_width, max_table_width) + content_offset_width();
374374

375375
m_pos.move_to(x, y);
376-
m_pos.x += content_offset_left();
377-
m_pos.y += content_offset_top();
378376
m_pos.width = table_width;
379377
m_pos.height = table_height + captions_height;
380378

381-
return std::min(table_width, max_table_width) + content_offset_width();
379+
calc_auto_margins(containing_block_size.width);
380+
m_pos.x += content_offset_left();
381+
m_pos.y += content_offset_top();
382+
383+
return ret;
382384
}
383385

384386
std::shared_ptr<litehtml::render_item> litehtml::render_item_table::init()

test/render/-test21.htm

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<table style="background-color: red; width: 300px">
2+
<tr>
3+
<td>
4+
<table style="margin:0.5em auto">
5+
<tr>
6+
<th>
7+
Lorem ipsum
8+
</th>
9+
</tr>
10+
</table>
11+
</td>
12+
</tr>
13+
</table>

test/render/test22.htm

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<div style="background-color: red; width: 300px">
2+
<table style="margin-left:auto; margin-right: auto">
3+
<tr>
4+
<th>
5+
Lorem ipsum
6+
</th>
7+
</tr>
8+
</table>
9+
</div>

test/render/test22.htm.png

199 Bytes
Loading

test/render/test23.htm

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<style>
2+
table {
3+
border: none;
4+
background-color: green;
5+
}
6+
</style>
7+
8+
<table>
9+
<tr>
10+
<td>
11+
<table style="width: 100%; border: none; background-color: red">
12+
<tr>
13+
<td>Pellentesque</td>
14+
<td>
15+
Duis rutrum nibh vestibulum finibus luctus. Sed ac gravida urna. Phasellus at est ut augue interdum condimentum. Nunc scelerisque, ligula a feugiat aliquet, est enim pulvinar nunc, at feugiat velit quam vel leo.
16+
</td>
17+
</tr>
18+
</table>
19+
</td>
20+
</tr>
21+
</table>

test/render/test23.htm.png

1.31 KB
Loading

0 commit comments

Comments
 (0)