From 0ac6f0fd5a28e3f5f9a39d3d54214c379973a500 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Tue, 1 May 2012 09:46:15 +0000 Subject: [PATCH] Patch from Josh Holthaus from bug #53165 - HWPF support for fetching the description (alt text) of a picture git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1332594 13f79535-47bb-0310-9956-ffa450edef68 --- src/documentation/content/xdocs/status.xml | 1 + .../apache/poi/hwpf/usermodel/Picture.java | 27 ++++++++++++++++++ .../poi/hwpf/usermodel/TestPictures.java | 8 ++++++ .../document/Picture_Alternative_Text.doc | Bin 0 -> 26112 bytes 4 files changed, 36 insertions(+) create mode 100644 test-data/document/Picture_Alternative_Text.doc diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index 17c2490df..7b085461f 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -34,6 +34,7 @@ + 53165 - HWPF support for fetching the description (alt text) of a picture 48528 - support negative arguments to the DATE() function 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 53043 - don't duplicate hyperlink relationships when saving XSSF file diff --git a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Picture.java b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Picture.java index 58ad7aefa..ff7af7cf2 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Picture.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Picture.java @@ -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 diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestPictures.java b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestPictures.java index c2d4093fd..cddaee7e4 100644 --- a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestPictures.java +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestPictures.java @@ -333,4 +333,12 @@ public final class TestPictures extends TestCase { 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()); + } } diff --git a/test-data/document/Picture_Alternative_Text.doc b/test-data/document/Picture_Alternative_Text.doc new file mode 100644 index 0000000000000000000000000000000000000000..55bf875d0d27bca9488930e5250c4dd535875dde GIT binary patch literal 26112 zcmeHv2_ThQ*YI-;$1&wNBvTwxhzyx^&61&zB;r=4Oow9(X;74@LAMf-3=K+TNRyC+ z26K_20VNH(Nrp7=uYEYxb+3DS@Bh8ucfaqoSkK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