From ee8125f348fca043a66d2994949d25bf864bc786 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Thu, 29 Mar 2007 17:36:37 +0000 Subject: [PATCH] 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 --- .../apache/poi/hwpf/usermodel/Picture.java | 14 +- .../apache/poi/hwpf/data/emf_2003_image.doc | Bin 0 -> 24064 bytes .../poi/hwpf/usermodel/TestPictures.java | 154 ++++++++++++++++++ 3 files changed, 163 insertions(+), 5 deletions(-) create mode 100644 src/scratchpad/testcases/org/apache/poi/hwpf/data/emf_2003_image.doc create mode 100644 src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestPictures.java 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 0000000000000000000000000000000000000000..a475813c87c1a2eaeaa8d39d2ad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L^X6@TAvu$td*ta0pRTTtJpWi&W==o$_ZVbNh$sSQ zJjVmaz*8WOhod0Q&mADXNKb+Isq-3$ucfy^9Qz-F_?Ej2;t1u!fir#?cmeo4aNY&2 z0OwcB3UK~%WIZ^?-d6CD;5Fd1&l!TBDYP90X+ONmPn+@TmWEoq#IoaXOmbb#)CpYoi+ztu>HWfaJuHS`^XsN51{W zFYv1XC4X(=o&1FWF=ISA%R$arm)tmmfI+|@U=T0}7z7Lg1_6VBLBJqj5HJYbN(A~_ z|J!H(dbYiMeB_CrVEsSq(-*n^{{X~wGS{v3Ag;@IgSg)R7KrQp?}4~Sa2UiBs~>~7 zZ`Kat`u!+~>-QHx{7(YML0s>j08#g!LD}nih}61Rua`BS;K_eKd8o3%bn5)17d{Eb znUA`oQh*SBT*l>0ywbyJwV4Oj~AYc$M2p9wm0tNwtfI+|@U=T0}7z92y2kx?#!A z3wMX_7QZXGvFC8u=NRIc$<;ph#?;^e+X(bqao;Wuz7xMk;7w2cs{1ojYJ%kDGBZ1Rm<6XuX^F!r@t_FXfd z`VstM`7N}5055pfI(zP(jK0z9{kCX4v2$;8ZA(&J+grJgcitdUV~YNA9bdjcK3@3J Ot?cW%-x_{v5cm)CzXQ|& literal 0 HcmV?d00001 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(); + } +}