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());
}
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, "Баланс");
}
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");
}
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);
}
}
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());
}
}
Aggregations