Bug 60656 - EMF image support in slideshows
Summary: EMF image support in slideshows
Status: NEW
Alias: None
Product: POI
Classification: Unclassified
Component: XSLF (show other bugs)
Version: 3.16-dev
Hardware: PC All
: P2 enhancement (vote)
Target Milestone: ---
Assignee: POI Developers List
Depends on:
Reported: 2017-01-26 20:38 UTC by Ghazi Triki
Modified: 2019-11-29 00:41 UTC (History)
0 users

EMF freezing Windows OpenJDK 12 (11.04 KB, application/zip)
2019-10-27 17:13 UTC, Andreas Beeker

Note You need to log in before you can comment on or make changes to this bug.
Description Ghazi Triki 2017-01-26 20:38:45 UTC
Actually if a file contains an EMF or a WMF image, the image is not exported when trying to export it as PNG.
Comment 1 Tim Allison 2017-01-26 20:47:08 UTC
We just added a stub parser for EMF that focuses on text extraction and embedded document extraction (yes, a PDF or a WMF can be embedded in an EMF, yeeha!).  Always looking for patches for rendering...

If you're having problems with rendering WMF, please open a separate issue.  There is support for rendering WMF.

Thank you.
Comment 2 Ghazi Triki 2017-01-26 21:23:36 UTC
I can provide an example of the file I mentioned. Is it a good idea?
Comment 3 Javen O'Neal 2017-03-23 06:31:55 UTC
Sure, as long as the file is licensed under ASL 2.0 and under 1 MB (bugzilla's file attachment limit, I think), otherwise email it to the dev list or upload it to your github.

It might be a while before someone has time and is interested in rendering an EMF or WMF file, but would be a fun exercise.
Comment 4 Andreas Beeker 2018-12-16 18:22:57 UTC
Merged the hemf branch via r1849040

There are still rendering issues and EMF+ is only very rudimentary implemented, but most cases of the common crawl corpus pass, so I hope it doesn't affect the next release too much.

I keep the issue open while still adding functionality.
Comment 5 Andreas Beeker 2019-05-04 23:04:11 UTC
Add more records for EMF+ via r1858625
Furthermore there are now extractors method (getEmbeddings()) in HwmfPicture and HemfPicture available.
Comment 6 Andreas Beeker 2019-05-12 19:50:38 UTC
Add a few more records via r1859159
Comment 7 Andreas Beeker 2019-06-06 22:34:06 UTC
Add some EMF+ drawing methods via r1860732
Comment 8 Andreas Beeker 2019-06-23 22:22:54 UTC
Thanks to Michael Ford, who provided me a test deck with various *SL*/EMF/WMF rendering errors. Applied via r1861952

This patch contains the following fixes:
* changed the EMF/WMF/ImageRenderer API to use Dimension2D instead of Dimension, to cover cases where vector graphic patterns where below 1 pixel unit
* reordered image data loading in DrawPaint because EMF lazy loaded the image data and couldn't access it, when the stream was closed
* reset graphic context clipping after EMF pictures were processed
* inverted the logic for HSLF getForegroundColor()/getBackgroundColor() because of a bit mask handling error
* partly implemented WmfDibStretchBlt
* initialize the WMF viewport with the inner bounds, because some pictures in ANISOTROPIC mapping mode wouldn't be rendered correctly otherwise, i.e. either upside down or with an offset
* empty clippings on WmfTextOut are now ignored
* refactored the clipping handling in HwmfGraphics
* handled offsets/differences of innerBounds (bounds set via WMF records) to the placeable header
* Removed invalid ObjectTable marker of WmfOffsetClipRgn, WmfIntersectClipRect, WmfExcludeClipRect - they are processed immediately
* PPTX2PNG output files are now 1-based, so the file index matches the -slide parameter
* PPTX2PNG output file names can now be configured via -outfile and -outpat switch
* XSLF shapes with a background picture defined as pic element instead of the blip properties are also handled now
Comment 9 Andreas Beeker 2019-07-22 21:32:58 UTC
fix image dimensions via r1863602
Comment 10 Tim Allison 2019-07-23 14:47:25 UTC
Andi, I recently dumped emf and wmf from a batch of hwp files.  If you want Korean-language focused files to work with:
Comment 11 Andreas Beeker 2019-10-27 17:13:45 UTC
Created attachment 36864 [details]
EMF freezing Windows OpenJDK 12

The attached EMF is freezing our OpenJDK 12 build.

My first analysis is, that it is due some over-proportional AffineTransformation state (800x width/scale) and the processing of TextLayout at HwmfGraphics:488.
This is somehow accepted in Linux, but the Windows font renderer freezes in this request.

I think the root source is that the group records (EmfCommentDataBeginGroup/EmfCommentDataEndGroup) aren't processed/rendered at all 
 and their bounds record would need to affect the AffineTransformation state of the graphics context.
Comment 12 Andreas Beeker 2019-10-27 22:53:30 UTC
Ok, I've fixed it locally - it was a two-liner :) in setting the window size before rendering. Before applying the patch, I need to make sure that my huge emf test set still works - IIRC I've already implemented something similar a while ago and it had side-effects.

I'm also extending PPTX2PNG to allow processing files via stdin, e.g. when iterating through compressed archives.
Comment 13 Andreas Beeker 2019-11-01 17:24:01 UTC
Applied via r1869272

- extract option for embedded element in PPTX2PNG
- minor GenericRecordJsonWriter fixes
- fix EMF+ world transformations
- fix initialization of emf pictures, which were partly unbounded -> excessive memory consumption
- change EMF+ brushes to continueable record

There are still wrong transformations, so shapes are misplaced ... tbc.
Comment 14 Andreas Beeker 2019-11-29 00:41:44 UTC
Applied via r1870566

- use Rectangle2D instead of Dimension2D for image bounds
- fix shearing transformation
- fix rendering of font attributes (bold/italic/...)
- emf+: needs its own object table and properties table
- emf+: add linear gradient handler
- emf+: handle brush data of pens
- wmf/emf/emf+: position right aligned text correctly
- emf+: use emf+ instead of emf records in dual-mode
- emf+: handle region data and operations correctly
- emf/+: map font weight to awt font weight correctly