226 |
## Step 2 |
## Step 2 |
227 |
my $x_current = 0; |
my $x_current = 0; |
228 |
|
|
229 |
## Step 3 |
## Step 5 |
230 |
my $tr = shift; |
my $tr = shift; |
231 |
$table->{row}->[$y_current] = {element => $tr}; |
$table->{row}->[$y_current] = {element => $tr}; |
232 |
my @tdth = grep { |
my @tdth = grep { |
237 |
} @{$tr->child_nodes}; |
} @{$tr->child_nodes}; |
238 |
my $current_cell = shift @tdth; |
my $current_cell = shift @tdth; |
239 |
|
|
240 |
## Step 4 |
## Step 3 |
241 |
$growing_downward_growing_cells->(); |
$growing_downward_growing_cells->(); |
242 |
|
|
243 |
return unless $current_cell; |
## Step 4 |
244 |
## ISSUE: Support for empty <tr></tr> (removed at revision 1376). |
return unless $current_cell; |
245 |
|
|
246 |
CELL: while (1) { |
CELL: while (1) { |
247 |
## Step 5: cells |
## Step 6: cells |
248 |
$x_current++ |
$x_current++ |
249 |
while ($x_current < $x_width and |
while ($x_current < $x_width and |
250 |
$table->{cell}->[$x_current]->[$y_current]); |
$table->{cell}->[$x_current]->[$y_current]); |
251 |
|
|
252 |
## Step 6 |
## Step 7 |
253 |
$x_width++ if $x_current == $x_width; |
$x_width++ if $x_current == $x_width; |
254 |
|
|
255 |
## Step 7 |
## Step 8 |
256 |
my $colspan = 1; |
my $colspan = 1; |
257 |
my $attr_value = $current_cell->get_attribute_ns (undef, 'colspan'); |
my $attr_value = $current_cell->get_attribute_ns (undef, 'colspan'); |
258 |
if (defined $attr_value and $attr_value =~ /^[\x09-\x0D\x20]*([0-9]+)/) { |
if (defined $attr_value and $attr_value =~ /^[\x09-\x0D\x20]*([0-9]+)/) { |
259 |
$colspan = $1 || 1; |
$colspan = $1 || 1; |
260 |
} |
} |
261 |
|
|
262 |
## Step 8 |
## Step 9 |
263 |
my $rowspan = 1; |
my $rowspan = 1; |
264 |
my $attr_value = $current_cell->get_attribute_ns (undef, 'rowspan'); |
my $attr_value = $current_cell->get_attribute_ns (undef, 'rowspan'); |
265 |
if (defined $attr_value and $attr_value =~ /^[\x09-\x0D\x20]*([0-9]+)/) { |
if (defined $attr_value and $attr_value =~ /^[\x09-\x0D\x20]*([0-9]+)/) { |
266 |
$rowspan = $1; |
$rowspan = $1; |
267 |
} |
} |
268 |
|
|
269 |
## Step 9 |
## Step 10 |
270 |
my $cell_grows_downward; |
my $cell_grows_downward; |
271 |
if ($rowspan == 0) { |
if ($rowspan == 0) { |
272 |
$cell_grows_downward = 1; |
$cell_grows_downward = 1; |
273 |
$rowspan = 1; |
$rowspan = 1; |
274 |
} |
} |
275 |
|
|
276 |
## Step 10 |
## Step 11 |
277 |
if ($x_width < $x_current + $colspan) { |
if ($x_width < $x_current + $colspan) { |
278 |
@column_generated_by[$_] = $current_cell |
@column_generated_by[$_] = $current_cell |
279 |
for $x_width .. $x_current + $colspan - 1; |
for $x_width .. $x_current + $colspan - 1; |
280 |
$x_width = $x_current + $colspan; |
$x_width = $x_current + $colspan; |
281 |
} |
} |
282 |
|
|
283 |
## Step 11 |
## Step 12 |
284 |
if ($y_height < $y_current + $rowspan) { |
if ($y_height < $y_current + $rowspan) { |
285 |
@row_generated_by[$_] = $current_cell |
@row_generated_by[$_] = $current_cell |
286 |
for $y_height .. $y_current + $rowspan - 1; |
for $y_height .. $y_current + $rowspan - 1; |
288 |
$y_max_node = $current_cell; |
$y_max_node = $current_cell; |
289 |
} |
} |
290 |
|
|
291 |
## Step 12 |
## Step 13 |
292 |
my $cell = { |
my $cell = { |
293 |
is_header => ($current_cell->manakai_local_name eq 'th'), |
is_header => ($current_cell->manakai_local_name eq 'th'), |
294 |
element => $current_cell, |
element => $current_cell, |
329 |
## NOTE: Entity references are not supported |
## NOTE: Entity references are not supported |
330 |
} |
} |
331 |
|
|
332 |
## Step 13 |
## Step 14 |
333 |
if ($cell_grows_downward) { |
if ($cell_grows_downward) { |
334 |
push @downward_growing_cells, [$cell, $x_current, $colspan]; |
push @downward_growing_cells, [$cell, $x_current, $colspan]; |
335 |
} |
} |
336 |
|
|
337 |
## Step 14 |
## Step 15 |
338 |
$x_current += $colspan; |
$x_current += $colspan; |
339 |
|
|
340 |
## Step 15-17 |
## Step 16-18 |
341 |
$current_cell = shift @tdth; |
$current_cell = shift @tdth; |
342 |
if (defined $current_cell) { |
if (defined $current_cell) { |
343 |
## Step 16-17 |
## Step 17-18 |
344 |
# |
# |
345 |
} else { |
} else { |
346 |
## Step 15 |
## Step 16 |
347 |
$y_current++; |
$y_current++; |
348 |
last CELL; |
last CELL; |
349 |
} |
} |
549 |
my $_x = $x + $header_width; |
my $_x = $x + $header_width; |
550 |
|
|
551 |
## 3. |
## 3. |
552 |
|
my $_y = $y + $cell->{height}; # $cell->{height} == header_{height} |
553 |
|
|
554 |
|
## 4. |
555 |
HORIZONTAL: { |
HORIZONTAL: { |
556 |
last HORIZONTAL if $_x == $table->{width}; # goto Vertical |
last HORIZONTAL if $_x == $table->{width}; # goto Vertical |
557 |
|
|
558 |
## 4. # goto Vertical |
## 5. # goto Vertical |
559 |
last HORIZONTAL |
last HORIZONTAL |
560 |
if $table->{cell}->[$_x]->[$y] and |
if $table->{cell}->[$_x]->[$y] and |
561 |
$table->{cell}->[$_x]->[$y]->[0] and # anchored |
$table->{cell}->[$_x]->[$y]->[0] and # anchored |
562 |
$table->{cell}->[$_x]->[$y]->[0]->{is_header}; |
$table->{cell}->[$_x]->[$y]->[0]->{is_header}; |
563 |
|
|
564 |
## 5. |
## 6. |
565 |
for my $_y ($y .. $y + $cell->{height} - 1) { |
for my $_y ($y .. $y + $cell->{height} - 1) { |
566 |
$assign_header->($table->{cell}->[$_x]->[$_y] => $x, $y); |
$assign_header->($table->{cell}->[$_x]->[$_y] => $x, $y); |
567 |
} |
} |
568 |
|
|
569 |
## 6. |
## 7. |
570 |
$_x++; |
$_x++; |
571 |
|
|
572 |
## 7. |
## 8. |
573 |
redo HORIZONTAL; |
redo HORIZONTAL; |
574 |
} # HORIZONTAL |
} # HORIZONTAL |
575 |
|
|
576 |
## 8. Vertical |
## 9. Vertical |
|
my $_y = $y + $cell->{height}; |
|
|
|
|
577 |
VERTICAL: { |
VERTICAL: { |
578 |
## 9. # goto END |
last VERTICAL if $_y == $table->{height}; # goto END |
|
last VERTICAL if $_y == $table->{height}; |
|
579 |
|
|
580 |
## 10. |
## 10. |
581 |
if ($table->{cell}->[$x]->[$_y]) { |
if ($table->{cell}->[$x]->[$_y]) { |