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

@ -103,7 +103,6 @@ public class ParConverter extends StyleConverter {
// Get the style name for this paragraph
String sStyleName = node.getAttribute(XMLString.TEXT_STYLE_NAME);
String sDisplayName = ofr.getParStyles().getDisplayName(sStyleName);
// Check for strict handling of styles
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"); }
}
nBreakAfter = styleMap.getBreakAfter(sName);
System.out.println(sName+"-"+nBreakAfter);
}
// Update context

View file

@ -16,11 +16,11 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
* Copyright: 2002-2010 by Henrik Just
* Copyright: 2002-2011 by Henrik Just
*
* 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;
while (nCol<nColCount) {
Element cell = (Element) table.getCell(nRow,nCol);
if (XMLString.TABLE_TABLE_CELL.equals(cell.getNodeName())) {
Context icCell = (Context) icRow.clone();
BeforeAfter baCell = new BeforeAfter();
formatter.applyCellStyle(nRow,nCol,baCell,icCell);
ldp.append(baCell.getBefore());
if (nCol==nColCount-1) { icCell.setInLastTableColumn(true); }
palette.getBlockCv().traverseBlockText(cell,ldp,icCell);
ldp.append(baCell.getAfter());
if (cell!=null) {
if (XMLString.TABLE_TABLE_CELL.equals(cell.getNodeName())) {
Context icCell = (Context) icRow.clone();
BeforeAfter baCell = new BeforeAfter();
formatter.applyCellStyle(nRow,nCol,baCell,icCell);
ldp.append(baCell.getBefore());
if (nCol==nColCount-1) { icCell.setInLastTableColumn(true); }
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.
// (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(); }
else { // Non-existing cell, ignore (assuming it is a trailing cell)
nCol++;
}
nCol+=nColSpan;
}
ldp.append("\\\\");
}

View file

@ -16,11 +16,11 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
* Copyright: 2002-2009 by Henrik Just
* Copyright: 2002-2011 by Henrik Just
*
* 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
for (int nRow=0; nRow<nRowCount; nRow++) {
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
if (OfficeReader.isSingleParagraph(cell)) {
Node par = Misc.getChildByTagName(cell,XMLString.TEXT_P);
@ -160,43 +160,48 @@ public class TableFormatter extends ConverterHelper {
int nCol = 0;
while (nCol<nColCount) {
Node cell = table.getCell(nRow,nCol);
String sStyleName = Misc.getAttribute(cell,XMLString.TABLE_STYLE_NAME);
StyleWithProperties style = ofr.getCellStyle(sStyleName);
int nColSpan = Misc.getPosInteger(Misc.getAttribute(cell,
XMLString.TABLE_NUMBER_COLUMNS_SPANNED),1);
boolean bLeft = false;
boolean bRight = false;
boolean bTop = false;
boolean bBottom = false;
if (style!=null) {
String sBorder = style.getProperty(XMLString.FO_BORDER);
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)) {
bLeft = true;
}
sBorder = style.getProperty(XMLString.FO_BORDER_RIGHT);
if (sBorder!=null && !"none".equals(sBorder)) {
bRight = true;
}
sBorder = style.getProperty(XMLString.FO_BORDER_TOP);
if (sBorder!=null && !"none".equals(sBorder)) {
bTop = true;
}
sBorder = style.getProperty(XMLString.FO_BORDER_BOTTOM);
if (sBorder!=null && !"none".equals(sBorder)) {
bBottom = true;
}
if (cell!=null) {
String sStyleName = Misc.getAttribute(cell,XMLString.TABLE_STYLE_NAME);
StyleWithProperties style = ofr.getCellStyle(sStyleName);
int nColSpan = Misc.getPosInteger(Misc.getAttribute(cell,
XMLString.TABLE_NUMBER_COLUMNS_SPANNED),1);
boolean bLeft = false;
boolean bRight = false;
boolean bTop = false;
boolean bBottom = false;
if (style!=null) {
String sBorder = style.getProperty(XMLString.FO_BORDER);
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)) {
bLeft = true;
}
sBorder = style.getProperty(XMLString.FO_BORDER_RIGHT);
if (sBorder!=null && !"none".equals(sBorder)) {
bRight = true;
}
sBorder = style.getProperty(XMLString.FO_BORDER_TOP);
if (sBorder!=null && !"none".equals(sBorder)) {
bTop = true;
}
sBorder = style.getProperty(XMLString.FO_BORDER_BOTTOM);
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);
}
}