Search in sources :

Example 1 with HemfHeader

use of org.apache.poi.hemf.record.HemfHeader in project poi by apache.

the class HemfExtractorTest method testBasicMac.

@Test
public void testBasicMac() throws Exception {
    InputStream is = POIDataSamples.getSpreadSheetInstance().openResourceAsStream("SimpleEMF_mac.emf");
    HemfExtractor ex = new HemfExtractor(is);
    HemfHeader header = ex.getHeader();
    int records = 0;
    boolean extractedData = false;
    for (HemfRecord record : ex) {
        if (record.getRecordType() == HemfRecordType.comment) {
            AbstractHemfComment comment = ((HemfCommentRecord) record).getComment();
            if (comment instanceof HemfCommentPublic.MultiFormats) {
                for (HemfCommentPublic.HemfMultiFormatsData d : ((HemfCommentPublic.MultiFormats) comment).getData()) {
                    byte[] data = d.getData();
                    //make sure header starts at 0
                    assertEquals('%', data[0]);
                    assertEquals('P', data[1]);
                    assertEquals('D', data[2]);
                    assertEquals('F', data[3]);
                    //make sure byte array ends at EOF\n
                    assertEquals('E', data[data.length - 4]);
                    assertEquals('O', data[data.length - 3]);
                    assertEquals('F', data[data.length - 2]);
                    assertEquals('\n', data[data.length - 1]);
                    extractedData = true;
                }
            }
        }
        records++;
    }
    assertTrue(extractedData);
    assertEquals(header.getRecords() - 1, records);
}
Also used : InputStream(java.io.InputStream) AbstractHemfComment(org.apache.poi.hemf.record.AbstractHemfComment) HemfCommentPublic(org.apache.poi.hemf.record.HemfCommentPublic) HemfRecord(org.apache.poi.hemf.record.HemfRecord) HemfCommentRecord(org.apache.poi.hemf.record.HemfCommentRecord) HemfHeader(org.apache.poi.hemf.record.HemfHeader) Test(org.junit.Test)

Example 2 with HemfHeader

use of org.apache.poi.hemf.record.HemfHeader in project poi by apache.

the class HemfExtractorTest method testBasicWindows.

@Test
public void testBasicWindows() throws Exception {
    InputStream is = POIDataSamples.getSpreadSheetInstance().openResourceAsStream("SimpleEMF_windows.emf");
    HemfExtractor ex = new HemfExtractor(is);
    HemfHeader header = ex.getHeader();
    assertEquals(27864, header.getBytes());
    assertEquals(31, header.getRecords());
    assertEquals(3, header.getHandles());
    assertEquals(346000, header.getMicrometersX());
    assertEquals(194000, header.getMicrometersY());
    int records = 0;
    for (HemfRecord record : ex) {
        records++;
    }
    assertEquals(header.getRecords() - 1, records);
}
Also used : InputStream(java.io.InputStream) HemfRecord(org.apache.poi.hemf.record.HemfRecord) HemfHeader(org.apache.poi.hemf.record.HemfHeader) Test(org.junit.Test)

Aggregations

InputStream (java.io.InputStream)2 HemfHeader (org.apache.poi.hemf.record.HemfHeader)2 HemfRecord (org.apache.poi.hemf.record.HemfRecord)2 Test (org.junit.Test)2 AbstractHemfComment (org.apache.poi.hemf.record.AbstractHemfComment)1 HemfCommentPublic (org.apache.poi.hemf.record.HemfCommentPublic)1 HemfCommentRecord (org.apache.poi.hemf.record.HemfCommentRecord)1