From a5278ccad9dcdd779eb004db6c21f2a9a5d9b2be Mon Sep 17 00:00:00 2001 From: Tim Allison Date: Mon, 8 Apr 2019 19:53:21 +0000 Subject: [PATCH] bug 63327 allow retrieval of wmf data embedded in emf git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1857136 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/hemf/record/emf/HemfComment.java | 10 ++++-- .../poi/hemf/usermodel/HemfPictureTest.java | 34 ++++++++++++++++++ test-data/slideshow/60677.wmf | Bin 0 -> 39126 bytes test-data/spreadsheet/63327.emf | Bin 0 -> 1480 bytes 4 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 test-data/slideshow/60677.wmf create mode 100644 test-data/spreadsheet/63327.emf diff --git a/src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfComment.java b/src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfComment.java index 3162ef5e27..c9ea7481e1 100644 --- a/src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfComment.java +++ b/src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfComment.java @@ -408,7 +408,7 @@ public class HemfComment { public static class EmfCommentDataWMF implements EmfCommentData { private final Rectangle2D bounds = new Rectangle2D.Double(); private final List 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 { diff --git a/src/scratchpad/testcases/org/apache/poi/hemf/usermodel/HemfPictureTest.java b/src/scratchpad/testcases/org/apache/poi/hemf/usermodel/HemfPictureTest.java index 5f630b563e..07b58f6473 100644 --- a/src/scratchpad/testcases/org/apache/poi/hemf/usermodel/HemfPictureTest.java +++ b/src/scratchpad/testcases/org/apache/poi/hemf/usermodel/HemfPictureTest.java @@ -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.HemfHeader; 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; @@ -284,6 +289,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")) { diff --git a/test-data/slideshow/60677.wmf b/test-data/slideshow/60677.wmf new file mode 100644 index 0000000000000000000000000000000000000000..6399d7180f45e6f40ecc09a55b2ecb31760616ff GIT binary patch literal 39126 zcmeHQ3zSsVm3^OTx@rDjf%vILjHnb=H;q9hS|}l)d+ngZ0nOW@5G^zQn)7NqQWwRY;urqQn3;FrMK7*XG z*$d~)INJ@{xlW&ZnaJ=X>o~jT0~SBnRSkzs)$sdwd57oC$y|0O(F~(fCND$+S0k*Iv?J76RK|444mK z+p&d=(;sPuqYHgY>2biJ@_fMya0O#@if1+yYD;yQf>TP50uJ>V9j4pc+nwQIdH~{~ zVcJ970H_0u4a?BBy;4~{>Nyq#wXtc~v@79DYI`)0vaiCM802Ee`*7jlToJ^_@koB_0| zP`nBRIL|Lp39RrC3xNcX&$Ul#&pP?``||haAIX0=&x%712g-Y#i0t`c(Yc5@&Z$of za|WM#r#ofNK{vnUy8J`Pe=1v-zw4Yk-7M;_1r(8B+aUa6SP;$m*30j(tsTZ8|M$n# z7o7eQzqvhKpoRN5KjQ^{!b2b;`|iQ-d^XEktePi0QqLx#=UFy!617d${DB= zToY#jR$Lt{AxHW^(MlgEcBN75XilKs&MUDw*=z_FQB{>WSqj7t0T}KEkR0b^9p>c7 zx#e?mB+9a=ug08kzBwmxel~;N5da0vNgouDZ}MwIWLn$>Jz^@9TQF}Uk>3J{&k5zN zbxEByX3!zMO%>>=E*-riQqg-jq&Ef&B0fIVrK2}06}`Ej z!|~l+fu8Ep(HotL-rkU2Gn6YnKGmh6Hv}4!MqgHf4#)R!1$wGWM{h_fdT)gE=E4`n z$EUh<^oFLQ*9tlu-`)!JRF{t4urBE>1Dy{6t^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0j0QCLv;C}pj(?0l3*RD`<&Q#o zB+5tl3jhm|UWBsqQMU+v7NXq(v}ZrU^O@nnHxHiAWP>z0NTdCR)80QhFg9B^n}Yk^ zMX;38W=o@GZOikK&7R>uh`Y-}Vr#2%uUxq1BO6|hHEq3Z^LYx^RR3*oz;n;D=Po>X z+M+o)pBMm}-7okY6x>s8s^1;989!~-!V{*Sh4uq*v$uZ`4+uO)Q~h4F;Wskcu4)UNjZg9v$7IkGjoZl4> vkqwQ`kq-3?k9PSlb_o{1 literal 0 HcmV?d00001 diff --git a/test-data/spreadsheet/63327.emf b/test-data/spreadsheet/63327.emf new file mode 100644 index 0000000000000000000000000000000000000000..8e0e457bcff5324a66ad6dd8bb407e3adf712db6 GIT binary patch literal 1480 zcmb_bziU%b6#m|An*Iv58Z{O~lTb@K7^GHl>JO^5#UCxUg;GTbSjk{$B*E80hJcge zkSs1P{s$sBICSXXAXHpjs$CpJ=-Lt-6yx{ZycZu*9I6Mtcg{WM-gDkL_qz^&dqjfx zKx`BJ4nLmEhJcAyAb#oE1mNH;?PH9!_!~UEeuzddutC)wIIr+}Zwuy=Aus_VjQym( zd~s@=W?6}zUVk)77rqh>I+(mb%iy@2U_o>l--?()4A{tbQ>)7hR8-H_oXcdFa~WVh z)|tnTHY~i{bu&bKwB}Bozx$BQ;52tCXGb%qW9s#~^%+NL6iqu}?I9AaVNAN|;z}`r zBVOemv@rs#*&L2B$=TIHaVZC=3ebsuJhp$t%=IVylSXByIk$s69URe^S_z1qjXxb^ki{}`)cccasq!g`_;#g~GS!lLOHw~` zs--PLIm=s7Yz!yV8m9$><}b7iN5f~dmOMWfYZ&|