aboutsummaryrefslogtreecommitdiffstats
path: root/src/scratchpad/testcases
diff options
context:
space:
mode:
authorAndreas Beeker <kiwiwings@apache.org>2019-09-11 21:24:06 +0000
committerAndreas Beeker <kiwiwings@apache.org>2019-09-11 21:24:06 +0000
commit1d4b05ff60cbb1438d1a369025762bf0d50c7989 (patch)
tree205a221ab408c81ff2647e3313c1f0aef42328eb /src/scratchpad/testcases
parentf31281f18f201841a2e963f26205d1fd3e170491 (diff)
downloadpoi-1d4b05ff60cbb1438d1a369025762bf0d50c7989.tar.gz
poi-1d4b05ff60cbb1438d1a369025762bf0d50c7989.zip
#63745 - Add traversing and debugging interface
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1866808 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/scratchpad/testcases')
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hslf/model/TestSlideMaster.java101
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hslf/model/TestTable.java4
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hslf/record/TestRecordTypes.java18
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hslf/record/TestTextHeaderAtom.java10
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hslf/record/TestTxMasterStyleAtom.java22
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestTextShape.java6
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hwmf/TestHwmfParsing.java177
7 files changed, 82 insertions, 256 deletions
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestSlideMaster.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestSlideMaster.java
index e03bded11d..eb4c368bac 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestSlideMaster.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestSlideMaster.java
@@ -17,11 +17,12 @@
package org.apache.poi.hslf.model;
-import static org.apache.poi.hslf.record.TextHeaderAtom.BODY_TYPE;
-import static org.apache.poi.hslf.record.TextHeaderAtom.CENTER_TITLE_TYPE;
-import static org.apache.poi.hslf.record.TextHeaderAtom.CENTRE_BODY_TYPE;
-import static org.apache.poi.hslf.record.TextHeaderAtom.TITLE_TYPE;
+import static org.apache.poi.sl.usermodel.TextShape.TextPlaceholder.BODY;
+import static org.apache.poi.sl.usermodel.TextShape.TextPlaceholder.CENTER_BODY;
+import static org.apache.poi.sl.usermodel.TextShape.TextPlaceholder.CENTER_TITLE;
+import static org.apache.poi.sl.usermodel.TextShape.TextPlaceholder.TITLE;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.io.ByteArrayInputStream;
@@ -33,7 +34,6 @@ import org.apache.poi.POIDataSamples;
import org.apache.poi.hslf.model.textproperties.CharFlagsTextProp;
import org.apache.poi.hslf.model.textproperties.TextProp;
import org.apache.poi.hslf.record.Environment;
-import org.apache.poi.hslf.record.TextHeaderAtom;
import org.apache.poi.hslf.usermodel.HSLFMasterSheet;
import org.apache.poi.hslf.usermodel.HSLFSlide;
import org.apache.poi.hslf.usermodel.HSLFSlideMaster;
@@ -42,6 +42,7 @@ import org.apache.poi.hslf.usermodel.HSLFSlideShowImpl;
import org.apache.poi.hslf.usermodel.HSLFTextParagraph;
import org.apache.poi.hslf.usermodel.HSLFTextRun;
import org.apache.poi.hslf.usermodel.HSLFTitleMaster;
+import org.apache.poi.sl.usermodel.TextShape.TextPlaceholder;
import org.junit.Test;
/**
@@ -63,30 +64,30 @@ public final class TestSlideMaster {
assertEquals(2, ppt.getSlideMasters().size());
//character attributes
- assertEquals(40, getMasterVal(ppt, 0, TITLE_TYPE, "font.size", true));
- assertEquals(48, getMasterVal(ppt, 1, TITLE_TYPE, "font.size", true));
+ assertEquals(40, getMasterVal(ppt, 0, TITLE, "font.size", true));
+ assertEquals(48, getMasterVal(ppt, 1, TITLE, "font.size", true));
- int font1 = getMasterVal(ppt, 0, TITLE_TYPE, "font.index", true);
- int font2 = getMasterVal(ppt, 1, TITLE_TYPE, "font.index", true);
+ int font1 = getMasterVal(ppt, 0, TITLE, "font.index", true);
+ int font2 = getMasterVal(ppt, 1, TITLE, "font.index", true);
assertEquals("Arial", env.getFontCollection().getFontInfo(font1).getTypeface());
assertEquals("Georgia", env.getFontCollection().getFontInfo(font2).getTypeface());
- CharFlagsTextProp prop1 = getMasterProp(ppt, 0, TITLE_TYPE, "char_flags", true);
- assertEquals(false, prop1.getSubValue(CharFlagsTextProp.BOLD_IDX));
- assertEquals(false, prop1.getSubValue(CharFlagsTextProp.ITALIC_IDX));
- assertEquals(true, prop1.getSubValue(CharFlagsTextProp.UNDERLINE_IDX));
+ CharFlagsTextProp prop1 = getMasterProp(ppt, 0, TITLE, "char_flags", true);
+ assertFalse(prop1.getSubValue(CharFlagsTextProp.BOLD_IDX));
+ assertFalse(prop1.getSubValue(CharFlagsTextProp.ITALIC_IDX));
+ assertTrue(prop1.getSubValue(CharFlagsTextProp.UNDERLINE_IDX));
- CharFlagsTextProp prop2 = getMasterProp(ppt, 1, TITLE_TYPE, "char_flags", true);
- assertEquals(false, prop2.getSubValue(CharFlagsTextProp.BOLD_IDX));
- assertEquals(true, prop2.getSubValue(CharFlagsTextProp.ITALIC_IDX));
- assertEquals(false, prop2.getSubValue(CharFlagsTextProp.UNDERLINE_IDX));
+ CharFlagsTextProp prop2 = getMasterProp(ppt, 1, TITLE, "char_flags", true);
+ assertFalse(prop2.getSubValue(CharFlagsTextProp.BOLD_IDX));
+ assertTrue(prop2.getSubValue(CharFlagsTextProp.ITALIC_IDX));
+ assertFalse(prop2.getSubValue(CharFlagsTextProp.UNDERLINE_IDX));
//now paragraph attributes
- assertEquals(0x266B, getMasterVal(ppt, 0, BODY_TYPE, "bullet.char", false));
- assertEquals(0x2022, getMasterVal(ppt, 1, BODY_TYPE, "bullet.char", false));
+ assertEquals(0x266B, getMasterVal(ppt, 0, BODY, "bullet.char", false));
+ assertEquals(0x2022, getMasterVal(ppt, 1, BODY, "bullet.char", false));
- int b1 = getMasterVal(ppt, 0, BODY_TYPE, "bullet.font", false);
- int b2 = getMasterVal(ppt, 1, BODY_TYPE, "bullet.font", false);
+ int b1 = getMasterVal(ppt, 0, BODY, "bullet.font", false);
+ int b2 = getMasterVal(ppt, 1, BODY, "bullet.font", false);
assertEquals("Arial", env.getFontCollection().getFontInfo(b1).getTypeface());
assertEquals("Georgia", env.getFontCollection().getFontInfo(b2).getTypeface());
@@ -94,11 +95,11 @@ public final class TestSlideMaster {
}
@SuppressWarnings("unchecked")
- private static <T extends TextProp> T getMasterProp(HSLFSlideShow ppt, int masterIdx, int txtype, String propName, boolean isCharacter) {
- return (T)ppt.getSlideMasters().get(masterIdx).getPropCollection(txtype, 0, propName, isCharacter).findByName(propName);
+ private static <T extends TextProp> T getMasterProp(HSLFSlideShow ppt, int masterIdx, TextPlaceholder txtype, String propName, boolean isCharacter) {
+ return (T)ppt.getSlideMasters().get(masterIdx).getPropCollection(txtype.nativeId, 0, propName, isCharacter).findByName(propName);
}
- private static int getMasterVal(HSLFSlideShow ppt, int masterIdx, int txtype, String propName, boolean isCharacter) {
+ private static int getMasterVal(HSLFSlideShow ppt, int masterIdx, TextPlaceholder txtype, String propName, boolean isCharacter) {
return getMasterProp(ppt, masterIdx, txtype, propName, isCharacter).getValue();
}
@@ -111,17 +112,17 @@ public final class TestSlideMaster {
HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("slide_master.ppt"));
assertEquals(1, ppt.getTitleMasters().size());
- assertEquals(40, getMasterVal(ppt, 0, CENTER_TITLE_TYPE, "font.size", true));
- CharFlagsTextProp prop1 = getMasterProp(ppt, 0, CENTER_TITLE_TYPE, "char_flags", true);
- assertEquals(false, prop1.getSubValue(CharFlagsTextProp.BOLD_IDX));
- assertEquals(false, prop1.getSubValue(CharFlagsTextProp.ITALIC_IDX));
- assertEquals(true, prop1.getSubValue(CharFlagsTextProp.UNDERLINE_IDX));
+ assertEquals(40, getMasterVal(ppt, 0, CENTER_TITLE, "font.size", true));
+ CharFlagsTextProp prop1 = getMasterProp(ppt, 0, CENTER_TITLE, "char_flags", true);
+ assertFalse(prop1.getSubValue(CharFlagsTextProp.BOLD_IDX));
+ assertFalse(prop1.getSubValue(CharFlagsTextProp.ITALIC_IDX));
+ assertTrue(prop1.getSubValue(CharFlagsTextProp.UNDERLINE_IDX));
- assertEquals(32, getMasterVal(ppt, 0, CENTRE_BODY_TYPE, "font.size", true));
- CharFlagsTextProp prop2 = getMasterProp(ppt, 0, CENTRE_BODY_TYPE, "char_flags", true);
- assertEquals(false, prop2.getSubValue(CharFlagsTextProp.BOLD_IDX));
- assertEquals(false, prop2.getSubValue(CharFlagsTextProp.ITALIC_IDX));
- assertEquals(false, prop2.getSubValue(CharFlagsTextProp.UNDERLINE_IDX));
+ assertEquals(32, getMasterVal(ppt, 0, CENTER_BODY, "font.size", true));
+ CharFlagsTextProp prop2 = getMasterProp(ppt, 0, CENTER_BODY, "char_flags", true);
+ assertFalse(prop2.getSubValue(CharFlagsTextProp.BOLD_IDX));
+ assertFalse(prop2.getSubValue(CharFlagsTextProp.ITALIC_IDX));
+ assertFalse(prop2.getSubValue(CharFlagsTextProp.UNDERLINE_IDX));
ppt.close();
}
@@ -138,18 +139,18 @@ public final class TestSlideMaster {
for (List<HSLFTextParagraph> txt : slide.getTextParagraphs()) {
HSLFTextRun rt = txt.get(0).getTextRuns().get(0);
- switch(txt.get(0).getRunType()){
- case TextHeaderAtom.CENTER_TITLE_TYPE:
+ switch(TextPlaceholder.fromNativeId(txt.get(0).getRunType())){
+ case CENTER_TITLE:
assertEquals("Arial", rt.getFontFamily());
assertEquals(32, rt.getFontSize(), 0);
- assertEquals(true, rt.isBold());
- assertEquals(true, rt.isUnderlined());
+ assertTrue(rt.isBold());
+ assertTrue(rt.isUnderlined());
break;
- case TextHeaderAtom.CENTRE_BODY_TYPE:
+ case CENTER_BODY:
assertEquals("Courier New", rt.getFontFamily());
assertEquals(20, rt.getFontSize(), 0);
- assertEquals(true, rt.isBold());
- assertEquals(false, rt.isUnderlined());
+ assertTrue(rt.isBold());
+ assertFalse(rt.isUnderlined());
break;
}
@@ -167,12 +168,12 @@ public final class TestSlideMaster {
assertEquals(3, slide.size());
for (List<HSLFTextParagraph> tparas : slide.get(0).getTextParagraphs()) {
HSLFTextParagraph tpara = tparas.get(0);
- if (tpara.getRunType() == TextHeaderAtom.TITLE_TYPE){
+ if (tpara.getRunType() == TITLE.nativeId){
HSLFTextRun rt = tpara.getTextRuns().get(0);
assertEquals(40, rt.getFontSize(), 0);
- assertEquals(true, rt.isUnderlined());
+ assertTrue(rt.isUnderlined());
assertEquals("Arial", rt.getFontFamily());
- } else if (tpara.getRunType() == TextHeaderAtom.BODY_TYPE){
+ } else if (tpara.getRunType() == BODY.nativeId){
HSLFTextRun rt = tpara.getTextRuns().get(0);
assertEquals(0, tpara.getIndentLevel());
assertEquals(32, rt.getFontSize(), 0);
@@ -189,12 +190,12 @@ public final class TestSlideMaster {
for (List<HSLFTextParagraph> tparas : slide.get(1).getTextParagraphs()) {
HSLFTextParagraph tpara = tparas.get(0);
- if (tpara.getRunType() == TextHeaderAtom.TITLE_TYPE){
+ if (tpara.getRunType() == TITLE.nativeId){
HSLFTextRun rt = tpara.getTextRuns().get(0);
assertEquals(48, rt.getFontSize(), 0);
- assertEquals(true, rt.isItalic());
+ assertTrue(rt.isItalic());
assertEquals("Georgia", rt.getFontFamily());
- } else if (tpara.getRunType() == TextHeaderAtom.BODY_TYPE){
+ } else if (tpara.getRunType() == BODY.nativeId){
HSLFTextRun rt;
rt = tpara.getTextRuns().get(0);
assertEquals(0, tpara.getIndentLevel());
@@ -253,12 +254,12 @@ public final class TestSlideMaster {
for (List<HSLFTextParagraph> tparas : slide.getTextParagraphs()) {
HSLFTextParagraph tpara = tparas.get(0);
- if (tpara.getRunType() == TextHeaderAtom.TITLE_TYPE){
+ if (tpara.getRunType() == TITLE.nativeId){
HSLFTextRun rt = tpara.getTextRuns().get(0);
assertEquals(40, rt.getFontSize(), 0);
- assertEquals(true, rt.isUnderlined());
+ assertTrue(rt.isUnderlined());
assertEquals("Arial", rt.getFontFamily());
- } else if (tpara.getRunType() == TextHeaderAtom.BODY_TYPE){
+ } else if (tpara.getRunType() == BODY.nativeId){
int[] indents = {32, 28, 24};
for (HSLFTextRun rt : tpara.getTextRuns()) {
int indent = tpara.getIndentLevel();
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTable.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTable.java
index 3c7bc9c9a5..2dddf74950 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTable.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTable.java
@@ -29,7 +29,6 @@ import java.io.IOException;
import java.util.List;
import org.apache.poi.POIDataSamples;
-import org.apache.poi.hslf.record.TextHeaderAtom;
import org.apache.poi.hslf.usermodel.HSLFShape;
import org.apache.poi.hslf.usermodel.HSLFSlide;
import org.apache.poi.hslf.usermodel.HSLFSlideShow;
@@ -39,6 +38,7 @@ import org.apache.poi.sl.usermodel.Shape;
import org.apache.poi.sl.usermodel.Slide;
import org.apache.poi.sl.usermodel.SlideShow;
import org.apache.poi.sl.usermodel.TableShape;
+import org.apache.poi.sl.usermodel.TextShape.TextPlaceholder;
import org.junit.Test;
/**
@@ -60,7 +60,7 @@ public final class TestTable {
HSLFTableCell cell = tbl.getCell(0, 0);
//table cells have type=TextHeaderAtom.OTHER_TYPE, see bug #46033
- assertEquals(TextHeaderAtom.OTHER_TYPE, cell.getTextParagraphs().get(0).getRunType());
+ assertEquals(TextPlaceholder.OTHER.nativeId, cell.getTextParagraphs().get(0).getRunType());
HSLFShape tblSh = slide.getShapes().get(0);
assertTrue(tblSh instanceof HSLFTable);
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestRecordTypes.java b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestRecordTypes.java
index dbf89692bb..be224a9d24 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestRecordTypes.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestRecordTypes.java
@@ -18,10 +18,11 @@
package org.apache.poi.hslf.record;
-import org.junit.Test;
-
import static org.junit.Assert.assertEquals;
+import org.apache.poi.ddf.EscherRecordTypes;
+import org.junit.Test;
+
/**
* Tests that RecordTypes returns the right records and classes when asked
*/
@@ -35,9 +36,9 @@ public final class TestRecordTypes {
@Test
public void testEscherNameLookups() {
- assertEquals("EscherDggContainer", RecordTypes.EscherDggContainer.name());
- assertEquals("EscherClientTextbox", RecordTypes.EscherClientTextbox.name());
- assertEquals("EscherSelection", RecordTypes.EscherSelection.name());
+ assertEquals("DGG_CONTAINER", EscherRecordTypes.DGG_CONTAINER.name());
+ assertEquals("CLIENT_TEXTBOX", EscherRecordTypes.CLIENT_TEXTBOX.name());
+ assertEquals("SELECTION", EscherRecordTypes.SELECTION.name());
}
@Test
@@ -46,11 +47,4 @@ public final class TestRecordTypes {
// This is checking the "unhandled default" stuff works
assertEquals(RecordTypes.UnknownRecordPlaceholder, RecordTypes.forTypeID(-10));
}
-
- @Test
- public void testEscherClassLookups() {
- // Should all come back with null, as DDF handles them
- assertEquals(null, RecordTypes.EscherDggContainer.recordConstructor);
- assertEquals(null, RecordTypes.EscherBStoreContainer.recordConstructor);
- }
}
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestTextHeaderAtom.java b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestTextHeaderAtom.java
index 8ac7453405..fb3c47dc28 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestTextHeaderAtom.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestTextHeaderAtom.java
@@ -18,9 +18,11 @@
package org.apache.poi.hslf.record;
-import junit.framework.TestCase;
import java.io.ByteArrayOutputStream;
+import junit.framework.TestCase;
+import org.apache.poi.sl.usermodel.TextShape.TextPlaceholder;
+
/**
* Tests that TextHeaderAtom works properly
*
@@ -40,9 +42,9 @@ public final class TestTextHeaderAtom extends TestCase {
TextHeaderAtom n_tha = new TextHeaderAtom(notes_data,0,12);
TextHeaderAtom t_tha = new TextHeaderAtom(title_data,0,12);
TextHeaderAtom b_tha = new TextHeaderAtom(body_data,0,12);
- assertEquals(TextHeaderAtom.NOTES_TYPE, n_tha.getTextType());
- assertEquals(TextHeaderAtom.TITLE_TYPE, t_tha.getTextType());
- assertEquals(TextHeaderAtom.BODY_TYPE, b_tha.getTextType());
+ assertEquals(TextPlaceholder.NOTES.nativeId, n_tha.getTextType());
+ assertEquals(TextPlaceholder.TITLE.nativeId, t_tha.getTextType());
+ assertEquals(TextPlaceholder.BODY.nativeId, b_tha.getTextType());
}
public void testWrite() throws Exception {
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestTxMasterStyleAtom.java b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestTxMasterStyleAtom.java
index 7e7c9f4d37..30c177f086 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestTxMasterStyleAtom.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestTxMasterStyleAtom.java
@@ -22,10 +22,10 @@ import java.util.List;
import junit.framework.AssertionFailedError;
import junit.framework.TestCase;
-
import org.apache.poi.hslf.model.textproperties.TextProp;
import org.apache.poi.hslf.model.textproperties.TextPropCollection;
import org.apache.poi.hslf.usermodel.HSLFSlideShow;
+import org.apache.poi.sl.usermodel.TextShape.TextPlaceholder;
/**
@@ -47,26 +47,26 @@ public final class TestTxMasterStyleAtom extends TestCase {
TxMasterStyleAtom[] txmaster = getMasterStyles();
for (final TxMasterStyleAtom atom : txmaster) {
final int txtype = atom.getTextType();
- switch (txtype){
- case TextHeaderAtom.TITLE_TYPE:
+ switch (TextPlaceholder.fromNativeId(txtype)){
+ case TITLE:
checkTitleType(atom);
break;
- case TextHeaderAtom.BODY_TYPE:
+ case BODY:
checkBodyType(atom);
break;
- case TextHeaderAtom.NOTES_TYPE:
+ case NOTES:
checkNotesType(atom);
break;
- case TextHeaderAtom.OTHER_TYPE:
+ case OTHER:
checkOtherType(atom);
break;
- case TextHeaderAtom.CENTRE_BODY_TYPE:
+ case CENTER_BODY:
break;
- case TextHeaderAtom.CENTER_TITLE_TYPE:
+ case CENTER_TITLE:
break;
- case TextHeaderAtom.HALF_BODY_TYPE:
+ case HALF_BODY:
break;
- case TextHeaderAtom.QUARTER_BODY_TYPE:
+ case QUARTER_BODY:
break;
default:
fail("Unknown text type: " + txtype);
@@ -230,7 +230,7 @@ public final class TestTxMasterStyleAtom extends TestCase {
}
assertEquals("Document.Environment must contain TxMasterStyleAtom with type=TextHeaderAtom.OTHER_TYPE",
- TextHeaderAtom.OTHER_TYPE, txstyle.getTextType());
+ TextPlaceholder.OTHER.nativeId, txstyle.getTextType());
lst.add(txstyle);
}
}
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestTextShape.java b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestTextShape.java
index 8499ed7b48..94ee89002a 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestTextShape.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestTextShape.java
@@ -32,8 +32,8 @@ import java.util.List;
import java.util.Map;
import org.apache.poi.hslf.HSLFTestDataSamples;
-import org.apache.poi.hslf.record.TextHeaderAtom;
import org.apache.poi.sl.usermodel.ShapeType;
+import org.apache.poi.sl.usermodel.TextShape.TextPlaceholder;
import org.junit.Test;
/**
@@ -90,9 +90,9 @@ public final class TestTextShape {
assertEquals("Text in a TextBox", rawText);
break;
case RECT:
- if(runType == TextHeaderAtom.OTHER_TYPE) {
+ if(runType == TextPlaceholder.OTHER.nativeId) {
assertEquals("Rectangle", rawText);
- } else if(runType == TextHeaderAtom.TITLE_TYPE) {
+ } else if(runType == TextPlaceholder.TITLE.nativeId) {
assertEquals("Title Placeholder", rawText);
}
break;
diff --git a/src/scratchpad/testcases/org/apache/poi/hwmf/TestHwmfParsing.java b/src/scratchpad/testcases/org/apache/poi/hwmf/TestHwmfParsing.java
index 64fb8563b3..1e2b464015 100644
--- a/src/scratchpad/testcases/org/apache/poi/hwmf/TestHwmfParsing.java
+++ b/src/scratchpad/testcases/org/apache/poi/hwmf/TestHwmfParsing.java
@@ -20,44 +20,22 @@ package org.apache.poi.hwmf;
import static org.apache.poi.POITestCase.assertContains;
import static org.junit.Assert.assertEquals;
-import java.awt.Graphics2D;
-import java.awt.RenderingHints;
-import java.awt.geom.Dimension2D;
-import java.awt.geom.Rectangle2D;
-import java.awt.image.BufferedImage;
import java.io.File;
-import java.io.FileFilter;
import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.FileWriter;
-import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.net.URL;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.List;
-import java.util.Locale;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipInputStream;
-
-import javax.imageio.ImageIO;
import org.apache.poi.POIDataSamples;
-import org.apache.poi.hwmf.record.HwmfFill.HwmfImageRecord;
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;
-import org.apache.poi.sl.usermodel.SlideShow;
-import org.apache.poi.sl.usermodel.SlideShowFactory;
import org.apache.poi.util.LocaleUtil;
import org.apache.poi.util.RecordFormatException;
-import org.apache.poi.util.Units;
import org.junit.Ignore;
import org.junit.Test;
@@ -65,6 +43,9 @@ public class TestHwmfParsing {
private static final POIDataSamples samples = POIDataSamples.getSlideShowInstance();
+ // ******************************************************************************
+ // for manual mass parsing and rendering tests of .wmfs use HemfPictureTest.paint() !
+ // ******************************************************************************
@Test
public void parse() throws IOException {
@@ -82,158 +63,6 @@ public class TestHwmfParsing {
}
}
- @Test
- @Ignore("This is work-in-progress and not a real unit test ...")
- public void paint() throws IOException {
- boolean dumpEmbedded = true;
- boolean dumpRecords = false;
-
- File f = new File("testme.wmf");
- FileInputStream fis = new FileInputStream(f);
- HwmfPicture wmf = new HwmfPicture(fis);
- fis.close();
-
- Dimension2D dim = wmf.getSize();
- double width = Units.pointsToPixel(dim.getWidth());
- // keep aspect ratio for height
- double height = Units.pointsToPixel(dim.getHeight());
- double scale = (width > height) ? 1500 / width : 1500 / width;
- width = Math.abs(width * scale);
- height = Math.abs(height * scale);
-
- BufferedImage bufImg = new BufferedImage((int)width, (int)height, BufferedImage.TYPE_INT_ARGB);
- Graphics2D g = bufImg.createGraphics();
- g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
- g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
- g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
- g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
-
- wmf.draw(g, new Rectangle2D.Double(0,0,width,height));
-
- 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++;
- }
- }
-
- if (dumpRecords) {
- try (FileWriter fw = new FileWriter("wmf-records.log")) {
- for (HwmfRecord r : wmf.getRecords()) {
- fw.write(r.getWmfRecordType().name());
- fw.write(":");
- fw.write(r.toString());
- fw.write("\n");
- }
- }
- }
- }
-
- @Test
- @Ignore("This is work-in-progress and not a real unit test ...")
- public void fetchWmfFromGovdocs() throws IOException {
- URL url = new URL("http://digitalcorpora.org/corpora/files/govdocs1/by_type/ppt.zip");
- File outdir = new File("build/ppt");
- outdir.mkdirs();
- ZipInputStream zis = new ZipInputStream(url.openStream());
- ZipEntry ze;
- while ((ze = zis.getNextEntry()) != null) {
- String basename = ze.getName().replaceAll(".*?([^/]+)\\.wmf", "$1");
- FilterInputStream fis = new FilterInputStream(zis){
- @Override
- public void close() throws IOException {}
- };
- try {
- SlideShow<?,?> ss = SlideShowFactory.create(fis);
- int wmfIdx = 1;
- for (PictureData pd : ss.getPictureData()) {
- if (pd.getType() != PictureType.WMF) {
- continue;
- }
- byte[] wmfData = pd.getData();
- String filename = String.format(Locale.ROOT, "%s-%04d.wmf", basename, wmfIdx);
- FileOutputStream fos = new FileOutputStream(new File(outdir, filename));
- fos.write(wmfData);
- fos.close();
- wmfIdx++;
- }
- ss.close();
- } catch (Exception e) {
- System.out.println(ze.getName()+" ignored.");
- }
- }
- }
-
- @Test
- @Ignore("This is work-in-progress and not a real unit test ...")
- public void parseWmfs() throws IOException {
- // parse and render the extracted wmfs from the fetchWmfFromGovdocs step
- boolean outputFiles = false;
- boolean renderWmf = true;
- File indir = new File("E:\\project\\poi\\misc\\govdocs-ppt");
- File outdir = new File("build/wmf");
- outdir.mkdirs();
- final String startFile = "";
- File[] files = indir.listFiles(new FileFilter() {
- boolean foundStartFile;
-
- @Override
- public boolean accept(File pathname) {
- foundStartFile |= startFile.isEmpty() || pathname.getName().contains(startFile);
- return foundStartFile && pathname.getName().matches("(?i).*\\.wmf?$");
- }
- });
- for (File f : files) {
- try {
- String basename = f.getName().replaceAll(".*?([^/]+)\\.wmf", "$1");
- FileInputStream fis = new FileInputStream(f);
- HwmfPicture wmf = new HwmfPicture(fis);
- fis.close();
-
- int bmpIndex = 1;
- for (HwmfRecord r : wmf.getRecords()) {
- if (r instanceof HwmfImageRecord) {
- BufferedImage bi = ((HwmfImageRecord)r).getImage();
- if (bi != null && outputFiles) {
- String filename = String.format(Locale.ROOT, "%s-%04d.png", basename, bmpIndex);
- ImageIO.write(bi, "PNG", new File(outdir, filename));
- }
- bmpIndex++;
- }
- }
-
- if (renderWmf) {
- Dimension2D dim = wmf.getSize();
- 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);
- g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
- g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
- g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
-
- wmf.draw(g);
-
- g.dispose();
-
- ImageIO.write(bufImg, "PNG", new File(outdir, basename+".png"));
- }
- } catch (Exception e) {
- System.out.println(f.getName()+" ignored.");
- }
- }
- }
@Test
@Ignore("If we decide we can use common crawl file specified, we can turn this back on")