From fa991ae966b5f10b68ca4815050694c931659a06 Mon Sep 17 00:00:00 2001 From: henrikjust Date: Wed, 20 Apr 2011 09:14:59 +0000 Subject: [PATCH] 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 --- source/distro/changelog.txt | 2 + .../java/writer2latex/latex/ParConverter.java | 2 - .../writer2latex/latex/TableConverter.java | 41 ++++---- .../writer2latex/latex/TableFormatter.java | 83 +++++++++-------- .../java/writer2latex/office/TableView.java | 70 ++++++++------ .../writer2latex/xhtml/TableConverter.java | 93 ++++++++++--------- 6 files changed, 160 insertions(+), 131 deletions(-) diff --git a/source/distro/changelog.txt b/source/distro/changelog.txt index bf006d3..398b0cc 100644 --- a/source/distro/changelog.txt +++ b/source/distro/changelog.txt @@ -2,6 +2,8 @@ Changelog for Writer2LaTeX version 1.0 -> 1.2 ---------- 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) [w2x] Bugfix: Positioning of text boxes (left, right, center, floating) now works correctly diff --git a/source/java/writer2latex/latex/ParConverter.java b/source/java/writer2latex/latex/ParConverter.java index bdd57bd..a30f093 100644 --- a/source/java/writer2latex/latex/ParConverter.java +++ b/source/java/writer2latex/latex/ParConverter.java @@ -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 diff --git a/source/java/writer2latex/latex/TableConverter.java b/source/java/writer2latex/latex/TableConverter.java index c431220..dc77a7e 100644 --- a/source/java/writer2latex/latex/TableConverter.java +++ b/source/java/writer2latex/latex/TableConverter.java @@ -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 (nCol0); + } + 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); } } diff --git a/source/java/writer2latex/office/TableView.java b/source/java/writer2latex/office/TableView.java index b20b98f..dc49e0d 100644 --- a/source/java/writer2latex/office/TableView.java +++ b/source/java/writer2latex/office/TableView.java @@ -16,11 +16,11 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, * MA 02111-1307 USA * - * Copyright: 2002-2008 by Henrik Just + * Copyright: 2002-2011 by Henrik Just * * 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++) { if (nViewCol1) { - td.setAttribute("rowspan",Integer.toString(nRowSpan)); - } - int nColSpan = view.getColSpan(nRow,nCol); - 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")); - } + if (cell!=null) { + if (XMLString.TABLE_TABLE_CELL.equals(cell.getNodeName())) { + // Create cell + Element td = converter.createElement("td"); + tr.appendChild(td); + int nRowSpan = view.getRowSpan(nRow,nCol); + if (nRowSpan>1) { + td.setAttribute("rowspan",Integer.toString(nRowSpan)); + } + int nColSpan = view.getColSpan(nRow,nCol); + if (nColSpan>1) { + td.setAttribute("colspan",Integer.toString(nColSpan)); + } - // 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); + // 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? + 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())) { - // covered table cells are not part of xhtml table model + else { + // non-existing cell, not needed in the xhtml table model (it will probably be a trailing cell) } } }