aboutsummaryrefslogtreecommitdiffstats
path: root/src/scratchpad/testcases
diff options
context:
space:
mode:
authorAndreas Beeker <kiwiwings@apache.org>2019-05-04 23:01:53 +0000
committerAndreas Beeker <kiwiwings@apache.org>2019-05-04 23:01:53 +0000
commitea0e01acc11dbec8a120a7583535935abe3f8f6c (patch)
treee1425c2fa926d29dbcf5bd869eb23e9892ce6bad /src/scratchpad/testcases
parentdfbf788201ace853547edd60d4581ca416b6a5b3 (diff)
downloadpoi-ea0e01acc11dbec8a120a7583535935abe3f8f6c.tar.gz
poi-ea0e01acc11dbec8a120a7583535935abe3f8f6c.zip
Bug 60656 - EMF image support in slideshows
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1858625 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/scratchpad/testcases')
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hemf/usermodel/HemfPictureTest.java56
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hwmf/TestHwmfParsing.java30
2 files changed, 70 insertions, 16 deletions
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 ba7e1e3ad8..d7862c451f 100644
--- a/src/scratchpad/testcases/org/apache/poi/hemf/usermodel/HemfPictureTest.java
+++ b/src/scratchpad/testcases/org/apache/poi/hemf/usermodel/HemfPictureTest.java
@@ -35,6 +35,7 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
+import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -51,6 +52,8 @@ 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.HwmfEmbedded;
+import org.apache.poi.hwmf.usermodel.HwmfEmbeddedType;
import org.apache.poi.hwmf.usermodel.HwmfPicture;
import org.apache.poi.util.IOUtils;
import org.apache.poi.util.RecordFormatException;
@@ -73,16 +76,17 @@ public class HemfPictureTest {
// emfs/govdocs1/844/844795.ppt_2.emf
// emfs/commoncrawl2/TO/TOYZSTNUSW5OFCFUQ6T5FBLIDLCRF3NH_0.emf
- final boolean writeLog = true;
+ final boolean writeLog = false;
final boolean dumpRecords = false;
- final boolean savePng = true;
+ final boolean savePng = false;
+ final boolean dumpEmbedded = true;
Set<String> passed = new HashSet<>();
try (BufferedWriter sucWrite = parseEmfLog(passed, "emf-success.txt");
BufferedWriter parseError = parseEmfLog(passed, "emf-parse.txt");
BufferedWriter renderError = parseEmfLog(passed, "emf-render.txt");
- SevenZFile sevenZFile = new SevenZFile(new File("tmp/render_emf.7z"))) {
+ SevenZFile sevenZFile = new SevenZFile(new File("tmp/plus_emf.7z"))) {
for (int idx=0;;idx++) {
SevenZArchiveEntry entry = sevenZFile.getNextEntry();
if (entry == null) break;
@@ -90,6 +94,11 @@ public class HemfPictureTest {
if (entry.isDirectory() || !etName.endsWith(".emf") || passed.contains(etName)) continue;
+ if (!etName.equals("emfs/commoncrawl2/2S/2SYMYPLNJURGCXJKLNZCJQGIBHVMQTRS_0.emf")) continue;
+
+ // emfs/commoncrawl2/ZJ/ZJT2BZPLQR7DKSKYLYL6GRDEUM2KIO5F_4.emf
+ // emfs/govdocs1/005/005203.ppt_3.emf
+
System.out.println(etName);
int size = sevenZFile.read(buf);
@@ -116,6 +125,18 @@ public class HemfPictureTest {
dumpRecords(emf);
}
+ if (dumpEmbedded) {
+ int embIdx = 0;
+ for (HwmfEmbedded emb : emf.getEmbeddings()) {
+ final File embName = new File("build/tmp", "emb_"+etName.replaceFirst(".+/", "").replace(".emf", "_"+embIdx + emb.getEmbeddedType().extension) );
+// try (FileOutputStream fos = new FileOutputStream(embName)) {
+// fos.write(emb.getRawData());
+// }
+ embIdx++;
+ }
+ }
+
+
Graphics2D g = null;
try {
Dimension2D dim = emf.getSize();
@@ -194,7 +215,7 @@ public class HemfPictureTest {
if (Files.exists(log)) {
soo = StandardOpenOption.APPEND;
try (Stream<String> stream = Files.lines(log)) {
- stream.forEach((s) -> passed.add(s.split("\\s")[0]));
+ stream.filter(s -> !s.startsWith("#")).forEach((s) -> passed.add(s.split("\\s")[0]));
}
} else {
soo = StandardOpenOption.CREATE;
@@ -380,7 +401,28 @@ public class HemfPictureTest {
}
}
- /*
- govdocs1 064213.doc-0.emf contains an example of extextouta
- */
+ @Test
+ public void nestedWmfEmf() throws Exception {
+ try (InputStream is = sl_samples.openResourceAsStream("nested_wmf.emf")) {
+ HemfPicture emf1 = new HemfPicture(is);
+ List<HwmfEmbedded> embeds = new ArrayList<>();
+ emf1.getEmbeddings().forEach(embeds::add);
+ assertEquals(1, embeds.size());
+ assertEquals(HwmfEmbeddedType.WMF, embeds.get(0).getEmbeddedType());
+
+ HwmfPicture wmf = new HwmfPicture(new ByteArrayInputStream(embeds.get(0).getRawData()));
+ embeds.clear();
+ wmf.getEmbeddings().forEach(embeds::add);
+ assertEquals(3, embeds.size());
+ assertEquals(HwmfEmbeddedType.EMF, embeds.get(0).getEmbeddedType());
+
+ HemfPicture emf2 = new HemfPicture(new ByteArrayInputStream(embeds.get(0).getRawData()));
+ embeds.clear();
+ emf2.getEmbeddings().forEach(embeds::add);
+ assertTrue(embeds.isEmpty());
+ }
+ }
+
+
+ /* govdocs1 064213.doc-0.emf contains an example of extextouta */
} \ No newline at end of file
diff --git a/src/scratchpad/testcases/org/apache/poi/hwmf/TestHwmfParsing.java b/src/scratchpad/testcases/org/apache/poi/hwmf/TestHwmfParsing.java
index 7632284296..5b0651a93f 100644
--- a/src/scratchpad/testcases/org/apache/poi/hwmf/TestHwmfParsing.java
+++ b/src/scratchpad/testcases/org/apache/poi/hwmf/TestHwmfParsing.java
@@ -47,6 +47,7 @@ import org.apache.poi.hwmf.record.HwmfFont;
import org.apache.poi.hwmf.record.HwmfRecord;
import org.apache.poi.hwmf.record.HwmfRecordType;
import org.apache.poi.hwmf.record.HwmfText;
+import org.apache.poi.hwmf.usermodel.HwmfEmbedded;
import org.apache.poi.hwmf.usermodel.HwmfPicture;
import org.apache.poi.sl.usermodel.PictureData;
import org.apache.poi.sl.usermodel.PictureData.PictureType;
@@ -82,8 +83,10 @@ public class TestHwmfParsing {
@Test
@Ignore("This is work-in-progress and not a real unit test ...")
public void paint() throws IOException {
- File f = samples.getFile("santa.wmf");
- // File f = new File("bla.wmf");
+ boolean dumpEmbedded = true;
+
+// File f = samples.getFile("santa.wmf");
+ File f = new File("testme.wmf");
FileInputStream fis = new FileInputStream(f);
HwmfPicture wmf = new HwmfPicture(fis);
fis.close();
@@ -92,12 +95,10 @@ public class TestHwmfParsing {
int width = Units.pointsToPixel(dim.getWidth());
// keep aspect ratio for height
int height = Units.pointsToPixel(dim.getHeight());
- double max = Math.max(width, height);
- if (max > 1500) {
- width *= 1500/max;
- height *= 1500/max;
- }
-
+ double scale = (width > height) ? 1500 / width : 1500 / width;
+ width *= scale;
+ height *= scale;
+
BufferedImage bufImg = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
Graphics2D g = bufImg.createGraphics();
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
@@ -110,6 +111,17 @@ public class TestHwmfParsing {
g.dispose();
ImageIO.write(bufImg, "PNG", new File("bla.png"));
+
+ if (dumpEmbedded) {
+ int embIdx = 0;
+ for (HwmfEmbedded emb : wmf.getEmbeddings()) {
+ final File embName = new File("build/tmp", "emb_"+embIdx + emb.getEmbeddedType().extension);
+ try (FileOutputStream fos = new FileOutputStream(embName)) {
+ fos.write(emb.getRawData());
+ }
+ embIdx++;
+ }
+ }
}
@Test
@@ -190,7 +202,7 @@ public class TestHwmfParsing {
int width = Units.pointsToPixel(dim.getWidth());
// keep aspect ratio for height
int height = Units.pointsToPixel(dim.getHeight());
-
+
BufferedImage bufImg = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
Graphics2D g = bufImg.createGraphics();
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);