poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From talli...@apache.org
Subject svn commit: r1857136 - in /poi/trunk: src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfComment.java src/scratchpad/testcases/org/apache/poi/hemf/usermodel/HemfPictureTest.java test-data/slideshow/60677.wmf test-data/spreadsheet/63327.emf
Date Mon, 08 Apr 2019 19:53:22 GMT
Author: tallison
Date: Mon Apr  8 19:53:21 2019
New Revision: 1857136

URL: http://svn.apache.org/viewvc?rev=1857136&view=rev
Log:
bug 63327 allow retrieval of wmf data embedded in emf

Added:
    poi/trunk/test-data/slideshow/60677.wmf   (with props)
    poi/trunk/test-data/spreadsheet/63327.emf   (with props)
Modified:
    poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfComment.java
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hemf/usermodel/HemfPictureTest.java

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfComment.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfComment.java?rev=1857136&r1=1857135&r2=1857136&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfComment.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfComment.java Mon Apr 
8 19:53:21 2019
@@ -408,7 +408,7 @@ public class HemfComment {
     public static class EmfCommentDataWMF implements EmfCommentData {
         private final Rectangle2D bounds = new Rectangle2D.Double();
         private final List<EmfCommentDataFormat> formats = new ArrayList<>();
-
+        private byte[] wmfData;
         @Override
         public HemfCommentRecordType getCommentRecordType() {
             return HemfCommentRecordType.emfWMF;
@@ -439,12 +439,16 @@ public class HemfComment {
             // WMF metafile in the WinMetafile field.
             int winMetafileSize = (int)leis.readUInt();
 
-            byte[] winMetafile = IOUtils.safelyAllocate(winMetafileSize, MAX_RECORD_LENGTH);
+            wmfData = IOUtils.safelyAllocate(winMetafileSize, MAX_RECORD_LENGTH);
             // some emf comments are truncated, so we don't use readFully here
-            leis.read(winMetafile);
+            leis.read(wmfData);
 
             return leis.getReadIndex()-startIdx;
         }
+
+        public byte[] getWMFData() {
+            return wmfData;
+        }
     }
 
     public static class EmfCommentDataUnicode implements EmfCommentData {

Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hemf/usermodel/HemfPictureTest.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hemf/usermodel/HemfPictureTest.java?rev=1857136&r1=1857135&r2=1857136&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hemf/usermodel/HemfPictureTest.java
(original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hemf/usermodel/HemfPictureTest.java
Mon Apr  8 19:53:21 2019
@@ -20,6 +20,7 @@ package org.apache.poi.hemf.usermodel;
 
 import static org.apache.poi.POITestCase.assertContains;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
 import java.awt.geom.Point2D;
@@ -39,6 +40,7 @@ import java.util.List;
 import java.util.Set;
 import java.util.stream.Stream;
 
+import com.sun.xml.bind.api.impl.NameConverter;
 import org.apache.poi.POIDataSamples;
 import org.apache.poi.hemf.record.emf.HemfComment;
 import org.apache.poi.hemf.record.emf.HemfComment.EmfComment;
@@ -48,6 +50,9 @@ import org.apache.poi.hemf.record.emf.He
 import org.apache.poi.hemf.record.emf.HemfRecord;
 import org.apache.poi.hemf.record.emf.HemfRecordType;
 import org.apache.poi.hemf.record.emf.HemfText;
+import org.apache.poi.hwmf.record.HwmfRecord;
+import org.apache.poi.hwmf.record.HwmfText;
+import org.apache.poi.hwmf.usermodel.HwmfPicture;
 import org.apache.poi.util.IOUtils;
 import org.apache.poi.util.RecordFormatException;
 import org.junit.Test;
@@ -285,6 +290,35 @@ public class HemfPictureTest {
     }
 
     @Test
+    public void testWMFInsideEMF() throws Exception {
+
+        byte[] wmfData = null;
+        try (InputStream is = ss_samples.openResourceAsStream("63327.emf")) {
+            HemfPicture pic = new HemfPicture(is);
+            for (HemfRecord record : pic) {
+                if (record.getEmfRecordType() == HemfRecordType.comment) {
+                    HemfComment.EmfComment commentRecord = (HemfComment.EmfComment) record;
+                    HemfComment.EmfCommentData emfCommentData = commentRecord.getCommentData();
+                    if (emfCommentData instanceof HemfComment.EmfCommentDataWMF) {
+                        wmfData = ((HemfComment.EmfCommentDataWMF) emfCommentData).getWMFData();
+                    }
+                }
+            }
+        }
+        assertNotNull(wmfData);
+        assertEquals(230, wmfData.length);
+        HwmfPicture pict = new HwmfPicture(new ByteArrayInputStream(wmfData));
+        String embedded = null;
+        for (HwmfRecord r : pict.getRecords()) {
+            if (r instanceof HwmfText.WmfTextOut) {
+                embedded = ((HwmfText.WmfTextOut) r).getText(StandardCharsets.US_ASCII);
+            }
+        }
+        assertNotNull(embedded);
+        assertEquals("Hw.txt", embedded);
+    }
+
+    @Test
     public void testWindowsText() throws Exception {
         try (InputStream is = ss_samples.openResourceAsStream("SimpleEMF_windows.emf")) {
             HemfPicture pic = new HemfPicture(is);

Added: poi/trunk/test-data/slideshow/60677.wmf
URL: http://svn.apache.org/viewvc/poi/trunk/test-data/slideshow/60677.wmf?rev=1857136&view=auto
==============================================================================
Binary file - no diff available.

Propchange: poi/trunk/test-data/slideshow/60677.wmf
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: poi/trunk/test-data/spreadsheet/63327.emf
URL: http://svn.apache.org/viewvc/poi/trunk/test-data/spreadsheet/63327.emf?rev=1857136&view=auto
==============================================================================
Binary file - no diff available.

Propchange: poi/trunk/test-data/spreadsheet/63327.emf
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream



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


Mime
View raw message