From: Nick Burch Date: Thu, 29 Mar 2007 17:36:37 +0000 (+0000) Subject: Apply Trejkax's fix from bug #41653, and do a whole load of tests for the HWPF pictur... X-Git-Tag: REL_3_0_RC3~3 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=ee8125f348fca043a66d2994949d25bf864bc786;p=poi.git Apply Trejkax's fix from bug #41653, and do a whole load of tests for the HWPF picture stuff. Includes a stub test for the problem identified in bug #41898 git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@523777 13f79535-47bb-0310-9956-ffa450edef68 --- 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 535b834cbd..e9ee228c12 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Picture.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Picture.java @@ -223,11 +223,15 @@ public class Picture } else if (matchSignature(_dataStream, TIFF, pictureBytesStartOffset) || matchSignature(_dataStream, TIFF1, pictureBytesStartOffset)) { return "tiff"; - } else if (matchSignature(content, WMF1, 0) || - matchSignature(content, WMF2, 0)) { - return "wmf"; - } else if (matchSignature(content, EMF, 0)) { - return "emf"; + } else { + // Need to load the image content before we can try the following tests + fillImageContent(); + + if (matchSignature(content, WMF1, 0) || matchSignature(content, WMF2, 0)) { + return "wmf"; + } else if (matchSignature(content, EMF, 0)) { + return "emf"; + } } // TODO: DIB, PICT return ""; diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/data/emf_2003_image.doc b/src/scratchpad/testcases/org/apache/poi/hwpf/data/emf_2003_image.doc new file mode 100644 index 0000000000..a475813c87 Binary files /dev/null and b/src/scratchpad/testcases/org/apache/poi/hwpf/data/emf_2003_image.doc differ diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestPictures.java b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestPictures.java new file mode 100644 index 0000000000..686e558c84 --- /dev/null +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestPictures.java @@ -0,0 +1,154 @@ +/* +* Licensed to the Apache Software Foundation (ASF) under one or more +* contributor license agreements. See the NOTICE file distributed with +* this work for additional information regarding copyright ownership. +* The ASF licenses this file to You under the Apache License, Version 2.0 +* (the "License"); you may not use this file except in compliance with +* the License. You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package org.apache.poi.hwpf.usermodel; + +import java.io.ByteArrayOutputStream; +import java.io.FileInputStream; +import java.util.Iterator; +import java.util.List; + +import org.apache.poi.hwpf.HWPFDocument; +import org.apache.poi.hwpf.model.TextPiece; +import org.apache.poi.hwpf.usermodel.Paragraph; +import org.apache.poi.hwpf.usermodel.Range; +import org.apache.poi.util.LittleEndian; + +import junit.framework.TestCase; + +/** + * Test the picture handling + * + * @author Nick Burch (nick at torchbox dot com) + */ +public class TestPictures extends TestCase { + private String dirname = System.getProperty("HWPF.testdata.path"); + + protected void setUp() throws Exception { + } + + /** + * two jpegs + */ + public void testTwoImages() throws Exception { + HWPFDocument doc = new HWPFDocument(new FileInputStream(dirname + "/two_images.doc")); + List pics = doc.getPicturesTable().getAllPictures(); + + assertNotNull(pics); + assertEquals(pics.size(), 2); + for(int i=0; i 128); + + // Check right contents + byte[] emf = loadImage("vector_image.emf"); + byte[] pemf = pic.getContent(); + assertEquals(emf.length, pemf.length); + for(int i=0; i -1 ) { + b.write(buf, 0, read); + } + return b.toByteArray(); + } +}