Search in sources :

Example 1 with HwmfRecord

use of org.apache.poi.hwmf.record.HwmfRecord in project poi by apache.

the class TestHwmfParsing method parse.

@Test
public void parse() throws IOException {
    File f = POIDataSamples.getSlideShowInstance().getFile("santa.wmf");
    FileInputStream fis = new FileInputStream(f);
    HwmfPicture wmf = new HwmfPicture(fis);
    fis.close();
    List<HwmfRecord> records = wmf.getRecords();
    assertEquals(581, records.size());
}
Also used : HwmfRecord(org.apache.poi.hwmf.record.HwmfRecord) File(java.io.File) FileInputStream(java.io.FileInputStream) HwmfPicture(org.apache.poi.hwmf.usermodel.HwmfPicture) Test(org.junit.Test)

Example 2 with HwmfRecord

use of org.apache.poi.hwmf.record.HwmfRecord in project poi by apache.

the class TestHwmfParsing method testCyrillic.

@Test
@Ignore("If we decide we can use common crawl file specified, we can turn this back on")
public void testCyrillic() throws Exception {
    //TODO: move test file to framework and fix this
    File dir = new File("C:/somethingOrOther");
    File f = new File(dir, "ZMLH54SPLI76NQ7XMKVB7SMUJA2HTXTS-2.wmf");
    HwmfPicture wmf = new HwmfPicture(new FileInputStream(f));
    Charset charset = LocaleUtil.CHARSET_1252;
    StringBuilder sb = new StringBuilder();
    //do what Graphics does by maintaining the stack, etc.!
    for (HwmfRecord r : wmf.getRecords()) {
        if (r.getRecordType().equals(HwmfRecordType.createFontIndirect)) {
            HwmfFont font = ((HwmfText.WmfCreateFontIndirect) r).getFont();
            charset = (font.getCharSet().getCharset() == null) ? LocaleUtil.CHARSET_1252 : font.getCharSet().getCharset();
        }
        if (r.getRecordType().equals(HwmfRecordType.extTextOut)) {
            HwmfText.WmfExtTextOut textOut = (HwmfText.WmfExtTextOut) r;
            sb.append(textOut.getText(charset)).append("\n");
        }
    }
    String txt = sb.toString();
    assertContains(txt, "Общо");
    assertContains(txt, "Баланс");
}
Also used : HwmfRecord(org.apache.poi.hwmf.record.HwmfRecord) Charset(java.nio.charset.Charset) HwmfText(org.apache.poi.hwmf.record.HwmfText) File(java.io.File) FileInputStream(java.io.FileInputStream) HwmfFont(org.apache.poi.hwmf.record.HwmfFont) HwmfPicture(org.apache.poi.hwmf.usermodel.HwmfPicture) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 3 with HwmfRecord

use of org.apache.poi.hwmf.record.HwmfRecord in project poi by apache.

the class TestHwmfParsing method testShift_JIS.

@Test
@Ignore("If we decide we can use the common crawl file attached to Bug 60677, " + "we can turn this back on")
public void testShift_JIS() throws Exception {
    //TODO: move test file to framework and fix this
    File f = new File("C:/data/file8.wmf");
    HwmfPicture wmf = new HwmfPicture(new FileInputStream(f));
    Charset charset = LocaleUtil.CHARSET_1252;
    StringBuilder sb = new StringBuilder();
    //do what Graphics does by maintaining the stack, etc.!
    for (HwmfRecord r : wmf.getRecords()) {
        if (r.getRecordType().equals(HwmfRecordType.createFontIndirect)) {
            HwmfFont font = ((HwmfText.WmfCreateFontIndirect) r).getFont();
            charset = (font.getCharSet().getCharset() == null) ? LocaleUtil.CHARSET_1252 : font.getCharSet().getCharset();
        }
        if (r.getRecordType().equals(HwmfRecordType.extTextOut)) {
            HwmfText.WmfExtTextOut textOut = (HwmfText.WmfExtTextOut) r;
            sb.append(textOut.getText(charset)).append("\n");
        }
    }
    String txt = sb.toString();
    assertContains(txt, "航空情報業務へのGIS");
}
Also used : HwmfRecord(org.apache.poi.hwmf.record.HwmfRecord) Charset(java.nio.charset.Charset) HwmfText(org.apache.poi.hwmf.record.HwmfText) File(java.io.File) FileInputStream(java.io.FileInputStream) HwmfFont(org.apache.poi.hwmf.record.HwmfFont) HwmfPicture(org.apache.poi.hwmf.usermodel.HwmfPicture) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 4 with HwmfRecord

use of org.apache.poi.hwmf.record.HwmfRecord in project poi by apache.

the class HwmfPicture method draw.

public void draw(Graphics2D ctx, Rectangle2D graphicsBounds) {
    AffineTransform at = ctx.getTransform();
    try {
        Rectangle2D wmfBounds = getBounds();
        // scale output bounds to image bounds
        ctx.translate(graphicsBounds.getX(), graphicsBounds.getY());
        ctx.scale(graphicsBounds.getWidth() / wmfBounds.getWidth(), graphicsBounds.getHeight() / wmfBounds.getHeight());
        HwmfGraphics g = new HwmfGraphics(ctx, wmfBounds);
        for (HwmfRecord r : records) {
            r.draw(g);
        }
    } finally {
        ctx.setTransform(at);
    }
}
Also used : HwmfRecord(org.apache.poi.hwmf.record.HwmfRecord) Rectangle2D(java.awt.geom.Rectangle2D) AffineTransform(java.awt.geom.AffineTransform) HwmfGraphics(org.apache.poi.hwmf.draw.HwmfGraphics)

Example 5 with HwmfRecord

use of org.apache.poi.hwmf.record.HwmfRecord in project poi by apache.

the class HwmfPicture method getBounds.

/**
     * Returns the bounding box in device-independent units. Usually this is taken from the placeable header.
     * 
     * @return the bounding box
     */
public Rectangle2D getBounds() {
    if (placeableHeader != null) {
        return placeableHeader.getBounds();
    } else {
        WmfSetWindowOrg wOrg = null;
        WmfSetWindowExt wExt = null;
        for (HwmfRecord r : getRecords()) {
            if (wOrg != null && wExt != null) {
                break;
            }
            if (r instanceof WmfSetWindowOrg) {
                wOrg = (WmfSetWindowOrg) r;
            } else if (r instanceof WmfSetWindowExt) {
                wExt = (WmfSetWindowExt) r;
            }
        }
        if (wOrg == null || wExt == null) {
            throw new RuntimeException("invalid wmf file - window records are incomplete.");
        }
        return new Rectangle2D.Double(wOrg.getX(), wOrg.getY(), wExt.getWidth(), wExt.getHeight());
    }
}
Also used : WmfSetWindowOrg(org.apache.poi.hwmf.record.HwmfWindowing.WmfSetWindowOrg) HwmfRecord(org.apache.poi.hwmf.record.HwmfRecord) WmfSetWindowExt(org.apache.poi.hwmf.record.HwmfWindowing.WmfSetWindowExt)

Aggregations

HwmfRecord (org.apache.poi.hwmf.record.HwmfRecord)7 HwmfPicture (org.apache.poi.hwmf.usermodel.HwmfPicture)5 File (java.io.File)4 FileInputStream (java.io.FileInputStream)4 Test (org.junit.Test)4 Charset (java.nio.charset.Charset)3 HwmfFont (org.apache.poi.hwmf.record.HwmfFont)3 HwmfText (org.apache.poi.hwmf.record.HwmfText)3 Ignore (org.junit.Ignore)3 Dimension (java.awt.Dimension)1 Graphics2D (java.awt.Graphics2D)1 AffineTransform (java.awt.geom.AffineTransform)1 Rectangle2D (java.awt.geom.Rectangle2D)1 BufferedImage (java.awt.image.BufferedImage)1 FileFilter (java.io.FileFilter)1 IOException (java.io.IOException)1 HwmfGraphics (org.apache.poi.hwmf.draw.HwmfGraphics)1 HwmfImageRecord (org.apache.poi.hwmf.record.HwmfFill.HwmfImageRecord)1 WmfSetWindowExt (org.apache.poi.hwmf.record.HwmfWindowing.WmfSetWindowExt)1 WmfSetWindowOrg (org.apache.poi.hwmf.record.HwmfWindowing.WmfSetWindowOrg)1