From 932099875b755338cd832bbb6a1e07a4839a019e Mon Sep 17 00:00:00 2001 From: Sergey Vladimirov Date: Mon, 5 Nov 2012 16:06:36 +0000 Subject: [PATCH] 52863 - add workaround for files with broken CHP SPRMs git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1405861 13f79535-47bb-0310-9956-ffa450edef68 --- src/documentation/content/xdocs/status.xml | 1 + .../hwpf/sprm/CharacterSprmUncompressor.java | 28 +++++++++++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index 4a76471aee..ad3b0f62b9 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -34,6 +34,7 @@ + 52863 - add workaround for files with broken CHP SPRMs 53182 - Reading combined character styling and direct formatting of a character run 52311 - Conversion to html : Problem in titles number 53914 - TableRow#getTopBorder() return bottom's border diff --git a/src/scratchpad/src/org/apache/poi/hwpf/sprm/CharacterSprmUncompressor.java b/src/scratchpad/src/org/apache/poi/hwpf/sprm/CharacterSprmUncompressor.java index c1b718709f..6bb3785f4c 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/sprm/CharacterSprmUncompressor.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/sprm/CharacterSprmUncompressor.java @@ -71,14 +71,30 @@ public final class CharacterSprmUncompressor extends SprmUncompressor Integer style = getIstd( grpprl, offset ); if ( style != null ) { - applySprms( parStyle, styleSheet.getCHPX( style ), 0, false, - newProperties ); + try + { + applySprms( parStyle, styleSheet.getCHPX( style ), 0, false, + newProperties ); + } + catch ( Exception exc ) + { + logger.log( POILogger.ERROR, "Unable to apply all style ", + style, " CHP SPRMs to CHP: ", exc, exc ); + } } CharacterProperties styleProperties = newProperties; newProperties = styleProperties.clone(); - applySprms( styleProperties, grpprl, offset, true, newProperties ); + try + { + applySprms( styleProperties, grpprl, offset, true, newProperties ); + } + catch ( Exception exc ) + { + logger.log( POILogger.ERROR, + "Unable to process all direct CHP SPRMs: ", exc, exc ); + } return newProperties; } @@ -109,6 +125,7 @@ public final class CharacterSprmUncompressor extends SprmUncompressor private static Integer getIstd( byte[] grpprl, int offset ) { Integer style = null; + try { SprmIterator sprmIt = new SprmIterator( grpprl, offset ); while ( sprmIt.hasNext() ) @@ -122,6 +139,11 @@ public final class CharacterSprmUncompressor extends SprmUncompressor } } } + catch ( Exception exc ) + { + logger.log( POILogger.ERROR, + "Unable to extract istd from direct CHP SPRM: ", exc, exc ); + } return style; } -- 2.39.5