Skip to content

Commit

Permalink
Fixed #523 Incorrect management of multi-level rowspan attribute.
Browse files Browse the repository at this point in the history
  • Loading branch information
ylussaud committed Aug 26, 2024
1 parent 66fbf76 commit 503d1ab
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -970,7 +970,6 @@ private void insertTable(MParagraph parent, Context context, Node header, Node b
if ("tr".equals(child.nodeName())) {
final MRow row = new MRowImpl();
table.getRows().add(row);
int currentColumn = 0;
for (Node rowChild : child.childNodes()) {
if ("th".equals(rowChild.nodeName()) || "td".equals(rowChild.nodeName())) {
final MList contents = new MListImpl();
Expand All @@ -985,7 +984,7 @@ private void insertTable(MParagraph parent, Context context, Node header, Node b
CSS_PARSER.setStyle(localContext.cssProperties, cell);
walkChildren(rowChild, localContext, newParagraph);
createNeededParagraphes(newParagraph);
currentColumn = insertMergedCells(row, rowChild, cell, rowSpans, vMergeCopies, currentColumn);
insertMergedCells(row, rowChild, cell, rowSpans, vMergeCopies);
}
}
insertRowspans(row, rowSpans, vMergeCopies);
Expand Down Expand Up @@ -1064,14 +1063,12 @@ private void insertRowspans(final MRow row, final Map<Integer, Integer> rowSpans
* the {@link Map} from the starting column to the number of remaining cells to merge
* @param vMergeCopies
* the {@link Map} from the starting column to the {@link List} of {@link MCell} to copy
* @param currentColumn
* the current column
* @return the new current column
*/
private int insertMergedCells(final MRow row, Node rowChild, final MCell cell, Map<Integer, Integer> rowSpans,
Map<Integer, List<MCell>> vMergeCopies, int currentColumn) {
int res = currentColumn;

private void insertMergedCells(final MRow row, Node rowChild, final MCell cell, Map<Integer, Integer> rowSpans,
Map<Integer, List<MCell>> vMergeCopies) {
insertRowspans(row, rowSpans, vMergeCopies);
final int currentColumn = row.getCells().size();
int lastColumn = currentColumn;
final int rowSpan = getRowSpan(rowChild);
final boolean restartVMerge;
if (rowSpan > -1) {
Expand All @@ -1084,11 +1081,10 @@ private int insertMergedCells(final MRow row, Node rowChild, final MCell cell, M
}
} else {
restartVMerge = false;
insertRowspans(row, rowSpans, vMergeCopies);
}

row.getCells().add(cell);
res++;
lastColumn++;

final int colSpan = getColSpan(rowChild);
final boolean restartHMerge;
Expand All @@ -1101,7 +1097,7 @@ private int insertMergedCells(final MRow row, Node rowChild, final MCell cell, M
hMergedCell.setHMerge(MCell.Merge.CONTINUE);
hMergedCell.setVMerge(cell.getVMerge());
row.getCells().add(hMergedCell);
res++;
lastColumn++;
}
} else {
restartHMerge = false;
Expand All @@ -1117,7 +1113,7 @@ private int insertMergedCells(final MRow row, Node rowChild, final MCell cell, M
}
vMergeCopy.add(vMergedCell);

for (int i = 0; i < res - currentColumn - 1; i++) {
for (int i = 0; i < lastColumn - currentColumn - 1; i++) {
final MList hMergedContents = new MListImpl();
final MCell hMergedCell = new MCellImpl(hMergedContents, null);
hMergedCell.setVMerge(MCell.Merge.CONTINUE);
Expand All @@ -1126,8 +1122,6 @@ private int insertMergedCells(final MRow row, Node rowChild, final MCell cell, M
}
vMergeCopies.put(currentColumn, vMergeCopy);
}

return res;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<html>
<head>
</head>
<body>
<table>
<tr>
<th></th><th>Jeff</th>
<th>Elon</th><th>Bill</th>
<th>Warren</th>
</tr>
<tr>
<td>1</td>
<td rowspan="5">1-5</td>
<td rowspan="3">1-3</td>
<td>1</td>
<td>1</td>
</tr>
<tr>
<td>2</td>
<td rowspan="3">2-4</td>
<td>2</td>
</tr>
<tr>
<td>3</td>
<td rowspan="3">3-5</td>
</tr>
<tr>
<td>4</td><td>4</td>
</tr>
<tr>
<td>5</td><td>5</td><td>5</td>
</tr>
</table>
</body>
</html>


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

=== HEADER ===

=== BODY ===

A simple demonstration of a query :
[query: .fromHTMLURI('doc.html')]
End of demonstration.
=== FOOTER ===

=== TEMPLATES ===
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<genconf:Generation xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:genconf="http://www.obeonetwork.org/m2doc/genconf/1.0" name="table" templateFileName="table-template.docx" resultFileName="table-actual-generation.docx" validationFileName="table-actual-validation.docx"/>

0 comments on commit 503d1ab

Please sign in to comment.