aboutsummaryrefslogtreecommitdiffstats
path: root/src/scratchpad
diff options
context:
space:
mode:
authorSergey Vladimirov <sergey@apache.org>2011-07-28 08:49:38 +0000
committerSergey Vladimirov <sergey@apache.org>2011-07-28 08:49:38 +0000
commitcc28ea53f78bad0289ef569d98a72e6033ae1933 (patch)
treef7d3879b49b33614e41f5018f8c23101f8a68cb0 /src/scratchpad
parentdbd10a67c0437cc713727aa1d14c105ca3ec86bd (diff)
downloadpoi-cc28ea53f78bad0289ef569d98a72e6033ae1933.tar.gz
poi-cc28ea53f78bad0289ef569d98a72e6033ae1933.zip
fix picture matching procedure
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1151766 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/scratchpad')
-rw-r--r--src/scratchpad/src/org/apache/poi/hwpf/usermodel/Picture.java42
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestPictures.java19
2 files changed, 41 insertions, 20 deletions
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 926946d921..b42ad00637 100644
--- a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Picture.java
+++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Picture.java
@@ -168,26 +168,26 @@ public final class Picture extends PictureDescriptor
return dataBlockStartOfsset;
}
- /**
- * @return picture's content as byte array
- */
- public byte[] getContent()
- {
- if (content == null || content.length<=0)
+ /**
+ * @return picture's content as byte array
+ */
+ public byte[] getContent()
{
- fillImageContent();
+ fillImageContent();
+ return content;
}
- return content;
- }
- public byte[] getRawContent()
- {
- if (rawContent == null || rawContent.length <= 0)
+ /**
+ * Returns picture's content as it stored in Word file, i.e. possibly in
+ * compressed form.
+ *
+ * @return picture's content as it stored in Word file
+ */
+ public byte[] getRawContent()
{
- fillRawImageContent();
+ fillRawImageContent();
+ return rawContent;
}
- return rawContent;
- }
/**
*
@@ -304,12 +304,10 @@ public final class Picture extends PictureDescriptor
public PictureType suggestPictureType()
{
- fillImageContent();
-
+ final byte[] imageContent = getContent();
for ( PictureType pictureType : PictureType.values() )
for ( byte[] signature : pictureType.getSignatures() )
- if ( matchSignature( _dataStream, signature,
- pictureBytesStartOffset ) )
+ if ( matchSignature( imageContent, signature, 0 ) )
return pictureType;
// TODO: DIB, PICT
@@ -355,12 +353,18 @@ public final class Picture extends PictureDescriptor
private void fillRawImageContent()
{
+ if ( rawContent != null && rawContent.length > 0 )
+ return;
+
this.rawContent = new byte[size];
System.arraycopy(_dataStream, pictureBytesStartOffset, rawContent, 0, size);
}
private void fillImageContent()
{
+ if ( content != null && content.length > 0 )
+ return;
+
byte[] rawContent = getRawContent();
// HACK: Detect compressed images. In reality there should be some way to determine
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 81bf2be56a..938b77a018 100644
--- a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestPictures.java
+++ b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestPictures.java
@@ -261,7 +261,24 @@ public final class TestPictures extends TestCase {
assertEquals("10a8", picture.suggestFullFileName());
assertEquals("image/unknown", picture.getMimeType());
}
-
+
+ public void testEquation()
+ {
+ HWPFDocument doc = HWPFTestDataSamples.openSampleFile( "equation.doc" );
+ PicturesTable pictures = doc.getPicturesTable();
+
+ final List<Picture> allPictures = pictures.getAllPictures();
+ assertEquals( 1, allPictures.size() );
+
+ Picture picture = allPictures.get( 0 );
+ assertNotNull( picture );
+ assertEquals( PictureType.EMF, picture.suggestPictureType() );
+ assertEquals( PictureType.EMF.getExtension(),
+ picture.suggestFileExtension() );
+ assertEquals( PictureType.EMF.getMime(), picture.getMimeType() );
+ assertEquals( "0.emf", picture.suggestFullFileName() );
+ }
+
/**
* In word you can have floating or fixed pictures.
* Fixed have a \u0001 in place with an offset to the