poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ser...@apache.org
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 GMT
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 @@
 
     <changes>
         <release version="3.9-beta1" date="2012-??-??">
+          <action dev="poi-developers" type="fix">53182 - Reading combined character
styling and direct formatting of a character run</action>
           <action dev="poi-developers" type="fix">52311 - Conversion to html : Problem
in titles number </action>
           <action dev="poi-developers" type="fix">53914 - TableRow#getTopBorder() return
bottom's border</action>
           <action dev="poi-developers" type="fix">53282 - Avoid exception when parsing
OPC relationships with non-breaking spaces</action>

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, "<span>Before text; </span><a " );
         assertContains( result,
-                "<a href=\"http://testuri.org/\"><span>Hyperlink text</span></a>"
);
+                "<a href=\"http://testuri.org/\"><span class=\"s1\">Hyperlink
text</span></a>" );
         assertContains( result, "</a><span>; after text</span>" );
     }
 

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


Mime
View raw message