poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r1332594 - in /poi/trunk: src/documentation/content/xdocs/ src/scratchpad/src/org/apache/poi/hwpf/usermodel/ src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/ test-data/document/
Date Tue, 01 May 2012 09:46:16 GMT
Author: nick
Date: Tue May  1 09:46:15 2012
New Revision: 1332594

URL: http://svn.apache.org/viewvc?rev=1332594&view=rev
Log:
Patch from Josh Holthaus from bug #53165 - HWPF support for fetching the description (alt
text) of a picture

Added:
    poi/trunk/test-data/document/Picture_Alternative_Text.doc   (with props)
Modified:
    poi/trunk/src/documentation/content/xdocs/status.xml
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Picture.java
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestPictures.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=1332594&r1=1332593&r2=1332594&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Tue May  1 09:46:15 2012
@@ -34,6 +34,7 @@
 
     <changes>
         <release version="3.9-beta1" date="2012-??-??">
+          <action dev="poi-developers" type="add">53165 - HWPF support for fetching
the description (alt text) of a picture</action>
           <action dev="poi-developers" type="fix">48528 - support negative arguments
to the DATE() function</action>
           <action dev="poi-developers" type="fix">53092 - allow specifying of a TimeZone
to DateUtil.getJavaDate(), for when it is known that a file comes from a different (known)
timezone to the current machine</action>
           <action dev="poi-developers" type="fix">53043 - don't duplicate hyperlink
relationships when saving XSSF file</action>

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Picture.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Picture.java?rev=1332594&r1=1332593&r2=1332594&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Picture.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Picture.java Tue May  1 09:46:15
2012
@@ -27,11 +27,16 @@ import java.util.zip.InflaterInputStream
 
 import org.apache.poi.ddf.EscherBSERecord;
 import org.apache.poi.ddf.EscherBlipRecord;
+import org.apache.poi.ddf.EscherComplexProperty;
+import org.apache.poi.ddf.EscherOptRecord;
+import org.apache.poi.ddf.EscherProperties;
+import org.apache.poi.ddf.EscherProperty;
 import org.apache.poi.ddf.EscherRecord;
 import org.apache.poi.hwpf.model.PICF;
 import org.apache.poi.hwpf.model.PICFAndOfficeArtData;
 import org.apache.poi.util.POILogFactory;
 import org.apache.poi.util.POILogger;
+import org.apache.poi.util.StringUtil;
 
 /**
  * Represents embedded picture extracted from Word Document
@@ -488,6 +493,28 @@ public final class Picture
         }
         return width;
     }
+    
+    /**
+     * returns the description stored in the alternative text
+     * 
+     * @return pictue description
+     */
+    public String getDescription()
+    {
+       for(EscherRecord escherRecord : _picfAndOfficeArtData.getShape().getChildRecords()){
+          if(escherRecord instanceof EscherOptRecord){
+             EscherOptRecord escherOptRecord = (EscherOptRecord) escherRecord;
+             for(EscherProperty property : escherOptRecord.getEscherProperties()){
+                if(EscherProperties.GROUPSHAPE__DESCRIPTION == property.getPropertyNumber()){
+                   byte[] complexData = ((EscherComplexProperty)property).getComplexData();
+                   return StringUtil.getFromUnicodeLE(complexData,0,complexData.length/2-1);
+                }
+             }
+          }
+       }
+
+       return null;
+    }
 
     /**
      * tries to suggest extension for picture's file by matching signatures of

Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestPictures.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestPictures.java?rev=1332594&r1=1332593&r2=1332594&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestPictures.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestPictures.java Tue
May  1 09:46:15 2012
@@ -333,4 +333,12 @@ public final class TestPictures extends 
         assertEquals(PictureType.PNG, p.suggestPictureType());
         assertEquals("png", p.suggestFileExtension());
     }
+    
+    public void testPictureWithAlternativeText() throws Exception {
+        HWPFDocument document = HWPFTestDataSamples.openSampleFile("Picture_Alternative_Text.doc");
+        PicturesTable pictureTable = document.getPicturesTable();
+        Picture picture = pictureTable.getAllPictures().get(0);
+
+        assertEquals("This is the alternative text for the picture.", picture.getDescription());
+    }
 }

Added: poi/trunk/test-data/document/Picture_Alternative_Text.doc
URL: http://svn.apache.org/viewvc/poi/trunk/test-data/document/Picture_Alternative_Text.doc?rev=1332594&view=auto
==============================================================================
Binary file - no diff available.

Propchange: poi/trunk/test-data/document/Picture_Alternative_Text.doc
------------------------------------------------------------------------------
    svn:mime-type = application/msword



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message