office-gobmx/emfio
Stephan Bergmann 8abe691630 Make TestEmfPlusDrawPathWithCustomCap succeed on Aarch64
CppunitTest_emfio_emf CPPUNIT_TEST_NAME=Test::TestEmfPlusDrawPathWithCustomCap
introduced in 5b21b65572 "tdf#142770 tdf#143031
EMF+ Implement CustomLineCap" failed for me both in a local master build on
macOS on Apple M1 and in a Linux aarch64 test build of the libreoffice-7.4.0.1
Flathub flatpak (at <https://buildbot.flathub.org/#/builders/21/builds/7749>)
with

> xmltesttools.cxx:195:Assertion
> Test name: (anonymous namespace)::Test::TestEmfPlusDrawPathWithCustomCap
> equality assertion failed
> - Expected: 1423.297394625,1268.98481214025 830.006276132353,558.656004112967
> - Actual  : 1423.297394625,1268.98481214025 830.006276132352,558.656004112967
> - In <>, XPath contents of child does not match

As this failed in exactly the same way for rather different builds (Clang vs.
GCC; Apple M1 vs. whatever ARM processor used by <https://flathub.org/builds>),
it smells like the test input might trigger a case where operations can
legitimately produce slightly different floating point results, which would then
cause the test to erroneously fail for some builds.

So I hacked the test input
emfio/qa/cppunit/emf/data/TestEmfPlusDrawPathWithCustomCap.emf slightly, making
the EmfPlusPath's 2nd EmfPlusPointF Y coordinate identical to the 1st one's, so
that the arrow now points west rather than north-west,

>  00000190: 02 10 c0 db 00 00 00 00 00 00 cc ff 08 40 0e 03
>  000001a0: 2c 00 00 00 20 00 00 00 02 10 c0 db 02 00 00 00
>  000001b0: 00 00 00 00 2b b5 05 45 05 54 56 45 d6 66 00 45
> -000001c0: 05 54 56 45 00 01 81 01 15 40 0e 00 10 00 00 00
> +000001c0: 51 23 4d 45 00 01 81 01 15 40 0e 00 10 00 00 00
>  000001d0: 04 00 00 00 0f 00 00 00 0e 00 00 00 14 00 00 00
>  000001e0: 00 00 00 00 10 00 00 00 14 00 00 00

which happens to let the test compute a different polygonstrokearrow/polygon
value now, but which appears to be stable across at least my x86-64 and aarch64
test builds.

And temporarily reverting the non-test (i.e., drawinglayer) parts of
5b21b65572 would make the test fail with

> xmltesttools.cxx:121:Assertion
> Test name: (anonymous namespace)::Test::TestEmfPlusDrawPathWithCustomCap
> assertion failed
> - Expression: xmlXPathNodeSetGetLength(pXmlNodes) > 0
> - In <>, XPath '/primitive2D/metafile/transform/polygonstrokearrow/polygon' not found

so the test appears to still faithfully check the intended difference in
behavior.

Change-Id: Iec31246dd7666ec764176622ccc4f246eea6e4ba
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136896
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2022-07-08 13:49:29 +02:00
..
inc
qa/cppunit Make TestEmfPlusDrawPathWithCustomCap succeed on Aarch64 2022-07-08 13:49:29 +02:00
source new loplugin:moveit 2022-06-10 13:13:15 +02:00
CppunitTest_emfio_emf.mk
CppunitTest_emfio_wmf.mk
emfio.component
IwyuFilter_emfio.yaml
Library_emfio.mk
Makefile
Module_emfio.mk
README.md

WMF/EMF/EMF+ Reader

Introduction

The emfio module is used to read WMF (Windows Metafile), EMF (Enhanced Metafiles) and also EMF+ (enhanced EMF) files [1], which are binary formats for vector images from Microsoft. These files can contain vector graphics, bitmap components and text.

This folder contains emfio/source/reader which is used for reading the WMF/EMF/EMF+ files, either directly, or inside a document. For embedding Windows Metafiles inside a document, one can use "Insert -> Picture -> From File" to put such a file into the document. It is possible to export the Windows Metafile by using right click and choose "save".

Most of the records of WMF/EMF formats come from the Windows Graphics Device. For Interface (GDI) API and EMF+ they come from the newer Windows GDI+.

More information about rendering Windows Metafiles can be found in the Visual Class Library (VCL) and also in the GDIMetaFile documentation.

An example demo that renders a metafile using vcl be seen by invoking:

./bin/run mtfdemo odk/examples/basic/forms_and_controls/burger.wmf

This opens the burger.wmf file from the ODK examples.

It is also possible to dump metaactions created as the intermediary format before rendering the metafile using:

./bin/run mtfdemo -d odk/examples/basic/forms_and_controls/burger.wmf

If the command is successful, this message will be shown, and metadump.xml will be put in the current folder:

"Dumped metaactions as metadump.xml"

The demo code structure is described in GDIMetaFile documentation.

[1] Windows Meta File, Wikipedia

EMF+ Specifics

Handling EMF+ is to some extent different from handling WMF/EMF. More information can be found in the VCL documentation.

How does it work?

emfio module takes a byte array and turns it into a drawinglayer primitive container. The rendering is done via drawinglayer primitives. For more information, you should refer to VCL documentation.

The drawinglayer primitives created to draw the emf/wmf files can be dumped as xml for debugging purposes. For more information, please refer to the drawinglayer documentation.

Limitations

Not all the WMF/EMF/EMF+ records are supported by this module. Unsupported records are marked as "not implemented", and a warning message will printed if they are actually read within a file. You can file a bug report for implementing these records.

Currently, these records are not implemented for WMF (specified in wmfreader.cxx):

W_META_SETRELABS W_META_SETPOLYFILLMODE W_META_SETSTRETCHBLTMODE
W_META_SETTEXTCHAREXTRA W_META_SETTEXTJUSTIFICATION W_META_FLOODFILL
W_META_FILLREGION W_META_FRAMEREGION W_META_INVERTREGION
W_META_PAINTREGION W_META_DRAWTEXT W_META_SETMAPPERFLAGS
W_META_SETDIBTODEV W_META_REALIZEPALETTE W_META_ANIMATEPALETTE
W_META_SETPALENTRIES W_META_RESIZEPALETTE W_META_EXTFLOODFILL
W_META_RESETDC W_META_STARTDOC W_META_STARTPAGE W_META_ENDPAGE
W_META_ABORTDOC W_META_ENDDOC

And these records are not implemented for EMF/EMF+ (specified in emfreader.cxx):

EMR_MASKBLT EMR_PLGBLT EMR_SETDIBITSTODEVICE EMR_FRAMERGN
EMR_INVERTRGN EMR_FLATTENPATH EMR_WIDENPATH EMR_POLYDRAW
EMR_SETPALETTEENTRIES EMR_RESIZEPALETTE
EMR_EXTFLOODFILL EMR_ANGLEARC EMR_SETCOLORADJUSTMENT EMR_POLYDRAW16
EMR_CREATECOLORSPACE EMR_SETCOLORSPACE EMR_DELETECOLORSPACE
EMR_GLSRECORD EMR_GLSBOUNDEDRECORD EMR_PIXELFORMAT EMR_DRAWESCAPE
EMR_EXTESCAPE EMR_STARTDOC EMR_SMALLTEXTOUT EMR_FORCEUFIMAPPING
EMR_NAMEDESCAPE EMR_COLORCORRECTPALETTE EMR_SETICMPROFILEA
EMR_SETICMPROFILEW EMR_TRANSPARENTBLT EMR_TRANSPARENTDIB
EMR_GRADIENTFILL EMR_SETLINKEDUFIS EMR_SETMAPPERFLAGS EMR_SETICMMODE
EMR_CREATEMONOBRUSH EMR_SETBRUSHORGEX EMR_SETMETARGN EMR_SETMITERLIMIT
EMR_EXCLUDECLIPRECT EMR_REALIZEPALETTE EMR_SELECTPALETTE
EMR_CREATEPALETTE EMR_ALPHADIBBLEND EMR_SETTEXTJUSTIFICATION

Due to the difference on the fonts available on various platforms, the outcome of text rendering can be different on Linux, Windows, macOS and elsewhere.

Known Bugs

Known remaining bugs for this module is gathered here:

Dependencies

The direct dependency for emfio is drawinglayer. The complete list of dependencies including the indirect dependencies is as below:

basegfx drawinglayer cppu cppuhelper sal comphelper tl salhelper vcl svt utl

Tools

Several tools are available for inspecting WMF/EMF/EMF+ files, which are binary formats. Some of them are:

  • mso-dumper: Reads and dumps various binary formats from Microsoft including WMF/EMF/EMF+. The output is in a custom XML format. emf-dump.py and wmf-dump.py are usable.
  • RE-lab (Formerly OLEToy): Reads, dumps and modifies several binary formats from Microsoft including WMF/EMF/EMF+, and also other companies.
  • EMF+ diagnostics reporting tool
  • limerest: A new gui tool based on OLEToy for working with various binary formats

References

Documentation for WMF/EMF/EMF+ formats are available on Microsoft website: