Fixed null pointer exception for tables with unbalanced rows

git-svn-id: svn://svn.code.sf.net/p/writer2latex/code/trunk@104 f0f2a975-2e09-46c8-9428-3b39399b9f3c
This commit is contained in:
henrikjust 2011-04-20 09:14:59 +00:00
parent 9fc63c43cb
commit fa991ae966
6 changed files with 160 additions and 131 deletions

View file

@ -2,6 +2,8 @@ Changelog for Writer2LaTeX version 1.0 -> 1.2
---------- version 1.1.7 ---------- ---------- version 1.1.7 ----------
[all] Bugfix: Fixed null pointer exception for tables with unbalanced rows
[w2l] Added the attribute break-after to paragraph style maps with values none, line and par (default) [w2l] Added the attribute break-after to paragraph style maps with values none, line and par (default)
[w2x] Bugfix: Positioning of text boxes (left, right, center, floating) now works correctly [w2x] Bugfix: Positioning of text boxes (left, right, center, floating) now works correctly

View file

@ -103,7 +103,6 @@ public class ParConverter extends StyleConverter {
// Get the style name for this paragraph // Get the style name for this paragraph
String sStyleName = node.getAttribute(XMLString.TEXT_STYLE_NAME); String sStyleName = node.getAttribute(XMLString.TEXT_STYLE_NAME);
String sDisplayName = ofr.getParStyles().getDisplayName(sStyleName); String sDisplayName = ofr.getParStyles().getDisplayName(sStyleName);
// Check for strict handling of styles // Check for strict handling of styles
if (config.otherStyles()!=LaTeXConfig.ACCEPT && !config.getParStyleMap().contains(sDisplayName)) { if (config.otherStyles()!=LaTeXConfig.ACCEPT && !config.getParStyleMap().contains(sDisplayName)) {
@ -340,7 +339,6 @@ public class ParConverter extends StyleConverter {
if (sAfter.length()>0 && !"}".equals(sAfter)) { ba.add("","\n"); } if (sAfter.length()>0 && !"}".equals(sAfter)) { ba.add("","\n"); }
} }
nBreakAfter = styleMap.getBreakAfter(sName); nBreakAfter = styleMap.getBreakAfter(sName);
System.out.println(sName+"-"+nBreakAfter);
} }
// Update context // Update context

View file

@ -16,11 +16,11 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA * MA 02111-1307 USA
* *
* Copyright: 2002-2010 by Henrik Just * Copyright: 2002-2011 by Henrik Just
* *
* All Rights Reserved. * All Rights Reserved.
* *
* Version 1.2 (2010-04-29) * Version 1.2 (2011-04-20)
* *
*/ */
@ -440,24 +440,29 @@ public class TableConverter extends ConverterHelper {
int nCol = 0; int nCol = 0;
while (nCol<nColCount) { while (nCol<nColCount) {
Element cell = (Element) table.getCell(nRow,nCol); Element cell = (Element) table.getCell(nRow,nCol);
if (XMLString.TABLE_TABLE_CELL.equals(cell.getNodeName())) { if (cell!=null) {
Context icCell = (Context) icRow.clone(); if (XMLString.TABLE_TABLE_CELL.equals(cell.getNodeName())) {
BeforeAfter baCell = new BeforeAfter(); Context icCell = (Context) icRow.clone();
formatter.applyCellStyle(nRow,nCol,baCell,icCell); BeforeAfter baCell = new BeforeAfter();
ldp.append(baCell.getBefore()); formatter.applyCellStyle(nRow,nCol,baCell,icCell);
if (nCol==nColCount-1) { icCell.setInLastTableColumn(true); } ldp.append(baCell.getBefore());
palette.getBlockCv().traverseBlockText(cell,ldp,icCell); if (nCol==nColCount-1) { icCell.setInLastTableColumn(true); }
ldp.append(baCell.getAfter()); palette.getBlockCv().traverseBlockText(cell,ldp,icCell);
ldp.append(baCell.getAfter());
}
// Otherwise ignore; the cell is covered by a \multicolumn entry.
// (table:covered-table-cell)
int nColSpan = Misc.getPosInteger(cell.getAttribute(
XMLString.TABLE_NUMBER_COLUMNS_SPANNED),1);
if (nCol+nColSpan<nColCount) {
if (formatter.isSimple()) { ldp.append(" & "); }
else { ldp.append(" &").nl(); }
}
nCol+=nColSpan;
} }
// Otherwise ignore; the cell is covered by a \multicolumn entry. else { // Non-existing cell, ignore (assuming it is a trailing cell)
// (table:covered-table-cell) nCol++;
int nColSpan = Misc.getPosInteger(cell.getAttribute(
XMLString.TABLE_NUMBER_COLUMNS_SPANNED),1);
if (nCol+nColSpan<nColCount) {
if (formatter.isSimple()) { ldp.append(" & "); }
else { ldp.append(" &").nl(); }
} }
nCol+=nColSpan;
} }
ldp.append("\\\\"); ldp.append("\\\\");
} }

View file

@ -16,11 +16,11 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA * MA 02111-1307 USA
* *
* Copyright: 2002-2009 by Henrik Just * Copyright: 2002-2011 by Henrik Just
* *
* All Rights Reserved. * All Rights Reserved.
* *
* Version 1.0 (2009-05-22) * Version 1.2 (2011-04-20)
* *
*/ */
@ -82,7 +82,7 @@ public class TableFormatter extends ConverterHelper {
// Collect chars to be counted in this column // Collect chars to be counted in this column
for (int nRow=0; nRow<nRowCount; nRow++) { for (int nRow=0; nRow<nRowCount; nRow++) {
Element cell = table.getCell(nRow, nCol); Element cell = table.getCell(nRow, nCol);
if (Misc.isElement(cell, XMLString.TABLE_TABLE_CELL)) { if (cell!=null && Misc.isElement(cell, XMLString.TABLE_TABLE_CELL)) {
// Now we're here: Collect alignment // Now we're here: Collect alignment
if (OfficeReader.isSingleParagraph(cell)) { if (OfficeReader.isSingleParagraph(cell)) {
Node par = Misc.getChildByTagName(cell,XMLString.TEXT_P); Node par = Misc.getChildByTagName(cell,XMLString.TEXT_P);
@ -160,43 +160,48 @@ public class TableFormatter extends ConverterHelper {
int nCol = 0; int nCol = 0;
while (nCol<nColCount) { while (nCol<nColCount) {
Node cell = table.getCell(nRow,nCol); Node cell = table.getCell(nRow,nCol);
String sStyleName = Misc.getAttribute(cell,XMLString.TABLE_STYLE_NAME); if (cell!=null) {
StyleWithProperties style = ofr.getCellStyle(sStyleName); String sStyleName = Misc.getAttribute(cell,XMLString.TABLE_STYLE_NAME);
int nColSpan = Misc.getPosInteger(Misc.getAttribute(cell, StyleWithProperties style = ofr.getCellStyle(sStyleName);
XMLString.TABLE_NUMBER_COLUMNS_SPANNED),1); int nColSpan = Misc.getPosInteger(Misc.getAttribute(cell,
boolean bLeft = false; XMLString.TABLE_NUMBER_COLUMNS_SPANNED),1);
boolean bRight = false; boolean bLeft = false;
boolean bTop = false; boolean bRight = false;
boolean bBottom = false; boolean bTop = false;
if (style!=null) { boolean bBottom = false;
String sBorder = style.getProperty(XMLString.FO_BORDER); if (style!=null) {
if (sBorder!=null && !"none".equals(sBorder)) { String sBorder = style.getProperty(XMLString.FO_BORDER);
bLeft = true; bRight = true; bTop = true; bBottom = true; if (sBorder!=null && !"none".equals(sBorder)) {
} bLeft = true; bRight = true; bTop = true; bBottom = true;
sBorder = style.getProperty(XMLString.FO_BORDER_LEFT); }
if (sBorder!=null && !"none".equals(sBorder)) { sBorder = style.getProperty(XMLString.FO_BORDER_LEFT);
bLeft = true; if (sBorder!=null && !"none".equals(sBorder)) {
} bLeft = true;
sBorder = style.getProperty(XMLString.FO_BORDER_RIGHT); }
if (sBorder!=null && !"none".equals(sBorder)) { sBorder = style.getProperty(XMLString.FO_BORDER_RIGHT);
bRight = true; if (sBorder!=null && !"none".equals(sBorder)) {
} bRight = true;
sBorder = style.getProperty(XMLString.FO_BORDER_TOP); }
if (sBorder!=null && !"none".equals(sBorder)) { sBorder = style.getProperty(XMLString.FO_BORDER_TOP);
bTop = true; if (sBorder!=null && !"none".equals(sBorder)) {
} bTop = true;
sBorder = style.getProperty(XMLString.FO_BORDER_BOTTOM); }
if (sBorder!=null && !"none".equals(sBorder)) { sBorder = style.getProperty(XMLString.FO_BORDER_BOTTOM);
bBottom = true; if (sBorder!=null && !"none".equals(sBorder)) {
} bBottom = true;
}
}
bVBorder[nRow][nCol] |= bLeft;
bVBorder[nRow][nCol+nColSpan] |= bRight;
do {
bHBorder[nRow][nCol] |= bTop;
bHBorder[nRow+1][nCol] |= bBottom;
nCol++;
} while (--nColSpan>0);
}
else { // Non-existing cell, treat as empty cell with no borders
nCol++;
} }
bVBorder[nRow][nCol] |= bLeft;
bVBorder[nRow][nCol+nColSpan] |= bRight;
do {
bHBorder[nRow][nCol] |= bTop;
bHBorder[nRow+1][nCol] |= bBottom;
nCol++;
} while (--nColSpan>0);
} }
} }

View file

@ -16,11 +16,11 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA * MA 02111-1307 USA
* *
* Copyright: 2002-2008 by Henrik Just * Copyright: 2002-2011 by Henrik Just
* *
* All Rights Reserved. * All Rights Reserved.
* *
* Version 1.0 (2008-09-07) * Version 1.2 (2011-04-20)
* *
*/ */
@ -97,33 +97,47 @@ public class TableView {
for (int nCol=0; nCol<=range.getLastCol(); nCol++) { for (int nCol=0; nCol<=range.getLastCol(); nCol++) {
if (nViewCol<nColCount && nColMap[nViewCol]<nCol) { nViewCol++; } if (nViewCol<nColCount && nColMap[nViewCol]<nCol) { nViewCol++; }
Element cell = reader.getCell(nRow,nCol); Element cell = reader.getCell(nRow,nCol);
if (Misc.isElement(cell,XMLString.TABLE_TABLE_CELL)) { if (cell!=null) {
int nRowSpan = Misc.getPosInteger(cell.getAttribute(XMLString.TABLE_NUMBER_ROWS_SPANNED),1); if (Misc.isElement(cell,XMLString.TABLE_TABLE_CELL)) {
int nColSpan = Misc.getPosInteger(cell.getAttribute(XMLString.TABLE_NUMBER_COLUMNS_SPANNED),1); int nRowSpan = Misc.getPosInteger(cell.getAttribute(XMLString.TABLE_NUMBER_ROWS_SPANNED),1);
// Test if (parts of) the cell belongs the view int nColSpan = Misc.getPosInteger(cell.getAttribute(XMLString.TABLE_NUMBER_COLUMNS_SPANNED),1);
if (nViewRow<nRowCount && nRowMap[nViewRow]<nRow+nRowSpan && // Test if (parts of) the cell belongs the view
nViewCol<nColCount && nColMap[nViewCol]<nCol+nColSpan) { if (nViewRow<nRowCount && nRowMap[nViewRow]<nRow+nRowSpan &&
cells[nViewRow][nViewCol].cell=cell; nViewCol<nColCount && nColMap[nViewCol]<nCol+nColSpan) {
cells[nViewRow][nViewCol].nOriginalRow=nRow; cells[nViewRow][nViewCol].cell=cell;
cells[nViewRow][nViewCol].nOriginalCol=nCol; cells[nViewRow][nViewCol].nOriginalRow=nRow;
// Calculate rowspan in view cells[nViewRow][nViewCol].nOriginalCol=nCol;
int i=nViewRow+1; // Calculate rowspan in view
while (i<nRowCount && nRowMap[i]<nRow+nRowSpan) { i++; } int i=nViewRow+1;
cells[nViewRow][nViewCol].nRowSpan = i-nViewRow; while (i<nRowCount && nRowMap[i]<nRow+nRowSpan) { i++; }
// Calculate colspan in view cells[nViewRow][nViewCol].nRowSpan = i-nViewRow;
int j=nViewCol+1; // Calculate colspan in view
while (j<nColCount && nColMap[j]<nCol+nColSpan) { j++; } int j=nViewCol+1;
cells[nViewRow][nViewCol].nColSpan = j-nViewCol; while (j<nColCount && nColMap[j]<nCol+nColSpan) { j++; }
} cells[nViewRow][nViewCol].nColSpan = j-nViewCol;
}
}
else if (Misc.isElement(cell,XMLString.TABLE_COVERED_TABLE_CELL)) {
// Don't overwrite, the position may be occupied with a relocated cell
if (cells[nViewRow][nViewCol].cell==null) {
cells[nViewRow][nViewCol].cell=cell;
cells[nViewRow][nViewCol].nOriginalRow=nRow;
cells[nViewRow][nViewCol].nOriginalCol=nCol;
}
}
}
else { // Non-existing cell, treat as empty
// Test if the cell belongs the view
if (nViewRow<nRowCount && nRowMap[nViewRow]<nRow+1 &&
nViewCol<nColCount && nColMap[nViewCol]<nCol+1) {
cells[nViewRow][nViewCol].cell=null;
cells[nViewRow][nViewCol].nOriginalRow=nRow;
cells[nViewRow][nViewCol].nOriginalCol=nCol;
cells[nViewRow][nViewCol].nRowSpan = 1;
cells[nViewRow][nViewCol].nColSpan = 1;
}
} }
if (Misc.isElement(cell,XMLString.TABLE_COVERED_TABLE_CELL)) {
// Don't overwrite, the position may be occupied with a relocated cell
if (cells[nViewRow][nViewCol].cell==null) {
cells[nViewRow][nViewCol].cell=cell;
cells[nViewRow][nViewCol].nOriginalRow=nRow;
cells[nViewRow][nViewCol].nOriginalCol=nCol;
}
}
} }
} }
} }

View file

@ -20,7 +20,7 @@
* *
* All Rights Reserved. * All Rights Reserved.
* *
* Version 1.2 (2011-03-21) * Version 1.2 (2011-04-20)
* *
*/ */
@ -251,51 +251,56 @@ public class TableConverter extends ConverterHelper {
for (int nCol=0; nCol<view.getColCount(); nCol++) { for (int nCol=0; nCol<view.getColCount(); nCol++) {
Node cell = view.getCell(nRow,nCol); Node cell = view.getCell(nRow,nCol);
if (cell!=null && XMLString.TABLE_TABLE_CELL.equals(cell.getNodeName())) { if (cell!=null) {
// Create cell if (XMLString.TABLE_TABLE_CELL.equals(cell.getNodeName())) {
Element td = converter.createElement("td"); // Create cell
tr.appendChild(td); Element td = converter.createElement("td");
int nRowSpan = view.getRowSpan(nRow,nCol); tr.appendChild(td);
if (nRowSpan>1) { int nRowSpan = view.getRowSpan(nRow,nCol);
td.setAttribute("rowspan",Integer.toString(nRowSpan)); if (nRowSpan>1) {
} td.setAttribute("rowspan",Integer.toString(nRowSpan));
int nColSpan = view.getColSpan(nRow,nCol); }
if (nColSpan>1) { int nColSpan = view.getColSpan(nRow,nCol);
td.setAttribute("colspan",Integer.toString(nColSpan)); if (nColSpan>1) {
} td.setAttribute("colspan",Integer.toString(nColSpan));
}
// Handle content
if (!isEmptyCell(cell)) {
String sWidth = view.getCellWidth(nRow, nCol);
if (sWidth!=null) {
converter.pushContentWidth(sWidth);
}
getTextCv().traverseBlockText(cell,td);
if (sWidth!=null) {
converter.popContentWidth();
}
}
else {
// Hack to display empty cells even in msie...
Element par = converter.createElement("p");
td.appendChild(par);
par.setAttribute("style","margin:0;font-size:1px");
par.appendChild(converter.createTextNode("\u00A0"));
}
// Is this a subtable? // Handle content
Node subTable = Misc.getChildByTagName(cell,XMLString.TABLE_SUB_TABLE); if (!isEmptyCell(cell)) {
String sTotalWidth=null; String sWidth = view.getCellWidth(nRow, nCol);
if (nColSpan==1) { if (sWidth!=null) {
sTotalWidth = view.getCellWidth(nRow,nCol); converter.pushContentWidth(sWidth);
} }
String sValueType = ofr.isOpenDocument() ? getTextCv().traverseBlockText(cell,td);
Misc.getAttribute(cell,XMLString.OFFICE_VALUE_TYPE) : if (sWidth!=null) {
Misc.getAttribute(cell,XMLString.TABLE_VALUE_TYPE); converter.popContentWidth();
applyCellStyle(view.getCellStyleName(nRow,nCol), view.getRelTableWidth()!=null, sTotalWidth, sValueType, td, subTable!=null); }
}
else {
// Hack to display empty cells even in msie...
Element par = converter.createElement("p");
td.appendChild(par);
par.setAttribute("style","margin:0;font-size:1px");
par.appendChild(converter.createTextNode("\u00A0"));
}
// Is this a subtable?
Node subTable = Misc.getChildByTagName(cell,XMLString.TABLE_SUB_TABLE);
String sTotalWidth=null;
if (nColSpan==1) {
sTotalWidth = view.getCellWidth(nRow,nCol);
}
String sValueType = ofr.isOpenDocument() ?
Misc.getAttribute(cell,XMLString.OFFICE_VALUE_TYPE) :
Misc.getAttribute(cell,XMLString.TABLE_VALUE_TYPE);
applyCellStyle(view.getCellStyleName(nRow,nCol), view.getRelTableWidth()!=null, sTotalWidth, sValueType, td, subTable!=null);
}
else if (XMLString.TABLE_COVERED_TABLE_CELL.equals(cell.getNodeName())) {
// covered table cells are not part of xhtml table model
}
} }
else if (XMLString.TABLE_COVERED_TABLE_CELL.equals(cell.getNodeName())) { else {
// covered table cells are not part of xhtml table model // non-existing cell, not needed in the xhtml table model (it will probably be a trailing cell)
} }
} }
} }