Return-Path: X-Original-To: apmail-poi-commits-archive@minotaur.apache.org Delivered-To: apmail-poi-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 574E3DA09 for ; Mon, 5 Nov 2012 15:52:10 +0000 (UTC) Received: (qmail 35807 invoked by uid 500); 5 Nov 2012 15:52:10 -0000 Delivered-To: apmail-poi-commits-archive@poi.apache.org Received: (qmail 35739 invoked by uid 500); 5 Nov 2012 15:52:08 -0000 Mailing-List: contact commits-help@poi.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@poi.apache.org Delivered-To: mailing list commits@poi.apache.org Received: (qmail 35712 invoked by uid 99); 5 Nov 2012 15:52:07 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 05 Nov 2012 15:52:07 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 05 Nov 2012 15:52:04 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 5903723888CD for ; Mon, 5 Nov 2012 15:51:42 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1405850 - in /poi/trunk: src/documentation/content/xdocs/ src/scratchpad/src/org/apache/poi/hwpf/model/ src/scratchpad/src/org/apache/poi/hwpf/sprm/ src/scratchpad/src/org/apache/poi/hwpf/usermodel/ src/scratchpad/testcases/org/apache/poi/... Date: Mon, 05 Nov 2012 15:51:42 -0000 To: commits@poi.apache.org From: sergey@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20121105155142.5903723888CD@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: sergey Date: Mon Nov 5 15:51:41 2012 New Revision: 1405850 URL: http://svn.apache.org/viewvc?rev=1405850&view=rev Log: fix bug 53182 - Reading combined character styling and direct formatting of a character run Added: poi/trunk/test-data/document/Bug53182.doc (with props) Modified: poi/trunk/src/documentation/content/xdocs/status.xml poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/CHPX.java poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/sprm/CharacterSprmUncompressor.java poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/CharacterProperties.java poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/CharacterRun.java poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/converter/TestWordToHtmlConverter.java Modified: poi/trunk/src/documentation/content/xdocs/status.xml URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/status.xml?rev=1405850&r1=1405849&r2=1405850&view=diff ============================================================================== --- poi/trunk/src/documentation/content/xdocs/status.xml (original) +++ poi/trunk/src/documentation/content/xdocs/status.xml Mon Nov 5 15:51:41 2012 @@ -34,6 +34,7 @@ + 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 53282 - Avoid exception when parsing OPC relationships with non-breaking spaces Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/CHPX.java URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/CHPX.java?rev=1405850&r1=1405849&r2=1405850&view=diff ============================================================================== --- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/CHPX.java (original) +++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/CHPX.java Mon Nov 5 15:51:41 2012 @@ -72,11 +72,8 @@ public final class CHPX extends ByteProp } CharacterProperties baseStyle = ss.getCharacterStyle( istd ); - if (baseStyle == null) - baseStyle = new CharacterProperties(); - CharacterProperties props = CharacterSprmUncompressor.uncompressCHP( - baseStyle, getGrpprl(), 0 ); + ss, baseStyle, getGrpprl(), 0 ); return props; } Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/sprm/CharacterSprmUncompressor.java URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/sprm/CharacterSprmUncompressor.java?rev=1405850&r1=1405849&r2=1405850&view=diff ============================================================================== --- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/sprm/CharacterSprmUncompressor.java (original) +++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/sprm/CharacterSprmUncompressor.java Mon Nov 5 15:51:41 2012 @@ -21,6 +21,7 @@ import org.apache.poi.hwpf.usermodel.Sha import org.apache.poi.hwpf.model.Colorref; import org.apache.poi.hwpf.model.Hyphenation; +import org.apache.poi.hwpf.model.StyleSheet; import org.apache.poi.hwpf.usermodel.BorderCode; import org.apache.poi.hwpf.usermodel.CharacterProperties; import org.apache.poi.hwpf.usermodel.DateAndTime; @@ -40,35 +41,89 @@ public final class CharacterSprmUncompre { } - public static CharacterProperties uncompressCHP(CharacterProperties parent, - byte[] grpprl, - int offset) - { - CharacterProperties newProperties = null; - try + @Deprecated + public static CharacterProperties uncompressCHP( + CharacterProperties parent, byte[] grpprl, int offset ) { - newProperties = (CharacterProperties) parent.clone(); + CharacterProperties newProperties = parent.clone(); + applySprms( parent, grpprl, offset, true, newProperties ); + return newProperties; } - catch (CloneNotSupportedException cnse) + + public static CharacterProperties uncompressCHP( StyleSheet styleSheet, + CharacterProperties parStyle, byte[] grpprl, int offset ) { - throw new RuntimeException("There is no way this exception should happen!!"); + CharacterProperties newProperties; + if ( parStyle == null ) + { + parStyle = new CharacterProperties(); + newProperties = new CharacterProperties(); + } + else + { + newProperties = parStyle.clone(); + } + + /* + * not fully conform to specification, but the fastest way to make it + * work. Shall be rewritten if any errors would be found -- vlsergey + */ + Integer style = getIstd( grpprl, offset ); + if ( style != null ) + { + applySprms( parStyle, styleSheet.getCHPX( style ), 0, false, + newProperties ); + } + + CharacterProperties styleProperties = newProperties; + newProperties = styleProperties.clone(); + + applySprms( styleProperties, grpprl, offset, true, newProperties ); + return newProperties; } - SprmIterator sprmIt = new SprmIterator(grpprl, offset); - while (sprmIt.hasNext()) + private static void applySprms( CharacterProperties parentProperties, + byte[] grpprl, int offset, boolean warnAboutNonChpSprms, + CharacterProperties targetProperties ) { - SprmOperation sprm = sprmIt.next(); + SprmIterator sprmIt = new SprmIterator( grpprl, offset ); + + while ( sprmIt.hasNext() ) + { + SprmOperation sprm = sprmIt.next(); - if (sprm.getType() != 2) { - logger.log( POILogger.WARN, "Non-CHP SPRM returned by SprmIterator: " + sprm ); - continue; - } + if ( sprm.getType() != 2 ) + { + if ( warnAboutNonChpSprms ) + { + logger.log( POILogger.WARN, + "Non-CHP SPRM returned by SprmIterator: " + sprm ); + } + continue; + } - unCompressCHPOperation(parent, newProperties, sprm); + unCompressCHPOperation( parentProperties, targetProperties, sprm ); + } } - return newProperties; - } + private static Integer getIstd( byte[] grpprl, int offset ) + { + Integer style = null; + { + SprmIterator sprmIt = new SprmIterator( grpprl, offset ); + while ( sprmIt.hasNext() ) + { + SprmOperation sprm = sprmIt.next(); + + if ( sprm.getType() == 2 && sprm.getOperation() == 0x30 ) + { + // sprmCIstd (0x4A30) + style = Integer.valueOf( sprm.getOperand() ); + } + } + } + return style; + } /** * Used in decompression of a chpx. This performs an operation defined by @@ -238,9 +293,10 @@ public final class CharacterSprmUncompre break; case 0x2f: break; - case 0x30: - newCHP.setIstd (sprm.getOperand()); - break; + case 0x30: + newCHP.setIstd( sprm.getOperand() ); + // 0x30 is supported by uncompressCHP(...) + break; case 0x31: //permutation vector for fast saves, who cares! @@ -257,20 +313,12 @@ public final class CharacterSprmUncompre newCHP.setKul ((byte) 0); newCHP.setIco ((byte) 0); break; - case 0x33: - try - { - // preserve the fSpec setting from the original CHP - boolean fSpec = newCHP.isFSpec (); - newCHP = (CharacterProperties) oldCHP.clone (); - newCHP.setFSpec (fSpec); - - } - catch (CloneNotSupportedException e) - { - //do nothing - } - return; + case 0x33: + // preserve the fSpec setting from the original CHP + boolean fSpec = newCHP.isFSpec(); + newCHP = oldCHP.clone(); + newCHP.setFSpec( fSpec ); + return; case 0x34: // sprmCKcd break; Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/CharacterProperties.java URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/CharacterProperties.java?rev=1405850&r1=1405849&r2=1405850&view=diff ============================================================================== --- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/CharacterProperties.java (original) +++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/CharacterProperties.java Mon Nov 5 15:51:41 2012 @@ -370,19 +370,27 @@ public final class CharacterProperties setCv( new Colorref( colour24 & 0xFFFFFF ) ); } - public Object clone() throws CloneNotSupportedException + public CharacterProperties clone() { - CharacterProperties cp = (CharacterProperties) super.clone(); + try + { + CharacterProperties cp = (CharacterProperties) super.clone(); - cp.setCv( getCv().clone() ); - cp.setDttmRMark( (DateAndTime) getDttmRMark().clone() ); - cp.setDttmRMarkDel( (DateAndTime) getDttmRMarkDel().clone() ); - cp.setDttmPropRMark( (DateAndTime) getDttmPropRMark().clone() ); - cp.setDttmDispFldRMark( (DateAndTime) getDttmDispFldRMark().clone() ); - cp.setXstDispFldRMark( getXstDispFldRMark().clone() ); - cp.setShd( (ShadingDescriptor) getShd().clone() ); - cp.setBrc( (BorderCode) getBrc().clone() ); + cp.setCv( getCv().clone() ); + cp.setDttmRMark( (DateAndTime) getDttmRMark().clone() ); + cp.setDttmRMarkDel( (DateAndTime) getDttmRMarkDel().clone() ); + cp.setDttmPropRMark( (DateAndTime) getDttmPropRMark().clone() ); + cp.setDttmDispFldRMark( (DateAndTime) getDttmDispFldRMark().clone() ); + cp.setXstDispFldRMark( getXstDispFldRMark().clone() ); + cp.setShd( (ShadingDescriptor) getShd().clone() ); + cp.setBrc( (BorderCode) getBrc().clone() ); - return cp; + return cp; + } + catch ( CloneNotSupportedException exc ) + { + throw new UnsupportedOperationException( + "Impossible CloneNotSupportedException occured", exc ); + } } } Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/CharacterRun.java URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/CharacterRun.java?rev=1405850&r1=1405849&r2=1405850&view=diff ============================================================================== --- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/CharacterRun.java (original) +++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/CharacterRun.java Mon Nov 5 15:51:41 2012 @@ -535,20 +535,18 @@ public final class CharacterRun _props.setIco24(colour24); } - /** - * clone the CharacterProperties object associated with this - * characterRun so that you can apply it to another CharacterRun - * - * @deprecated This method shall not be public and should not be called from high-level code - */ - @Deprecated - public CharacterProperties cloneProperties() { - try { - return (CharacterProperties)_props.clone(); - } catch(java.lang.CloneNotSupportedException e) { - throw new RuntimeException(e); + /** + * clone the CharacterProperties object associated with this characterRun so + * that you can apply it to another CharacterRun + * + * @deprecated This method shall not be public and should not be called from + * high-level code + */ + @Deprecated + public CharacterProperties cloneProperties() + { + return _props.clone(); } - } /** * Used to create a deep copy of this object. Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/converter/TestWordToHtmlConverter.java URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/converter/TestWordToHtmlConverter.java?rev=1405850&r1=1405849&r2=1405850&view=diff ============================================================================== --- poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/converter/TestWordToHtmlConverter.java (original) +++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/converter/TestWordToHtmlConverter.java Mon Nov 5 15:51:41 2012 @@ -141,6 +141,12 @@ public class TestWordToHtmlConverter ext getHtmlText( "Bug48075.doc" ); } + public void testBug53182() throws Exception + { + String result = getHtmlText( "Bug53182.doc" ); + assertFalse( result.contains( "italic" ) ); + } + public void testDocumentProperties() throws Exception { String result = getHtmlText( "documentProperties.doc" ); @@ -183,7 +189,7 @@ public class TestWordToHtmlConverter ext assertContains( result, "Before text; Hyperlink text" ); + "Hyperlink text" ); assertContains( result, "; after text" ); } Added: poi/trunk/test-data/document/Bug53182.doc URL: http://svn.apache.org/viewvc/poi/trunk/test-data/document/Bug53182.doc?rev=1405850&view=auto ============================================================================== Binary file - no diff available. Propchange: poi/trunk/test-data/document/Bug53182.doc ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org For additional commands, e-mail: commits-help@poi.apache.org