Bug 74921

Summary: EMF pictures pasted via clipboard do not show properly if they contain clip regions
Product: LibreOffice Reporter: rbruenner
Component: WriterAssignee: Not Assigned <libreoffice-bugs>
Status: NEW --- QA Contact:
Severity: normal    
Priority: medium CC: philipz85, rbruenner
Version: Inherited From OOo   
Hardware: Other   
OS: All   
Whiteboard:
i915 platform: i915 features:
Attachments: The second image in the file shows the problem.
Contains a simple test programme for generating EMF content showing the issue

Description rbruenner 2014-02-13 09:50:40 UTC
Created attachment 93993 [details]
The second image in the file shows the problem.

An EMF picture which has been created using the SelectClipRgn API does not show properly in Writer. I have tested with LO 3.6 both on Windows 8 Enterprise and on Mac OS X 10.7.5, and with the freshly released LO 4.1.5 on Mac OS X 10.7.5.

The attached file contains a Writer document where an example image of our proprietary software has been included. The first image was inserted from an EMF file on disk. The second image was inserted as an EMF image from the clipboard created using the same drawing code. The third image was inserted from the clipboard using the bitmap format. While the EMF image from the file looks as expected (and similar to the bitmap image), the EMF image from clipboard lacks the content in the graph. It only shows the graph's axes, labels and grid lines.
I noticed that when scrolling using the mouse wheel over image 2 in version 3.6, the content in the graph partially showed up and disappeared again after scrolling further. In version 4.1, this was no longer the case.

Steps to reproduce: Open the attached file. Using LO 3.6, scroll down using the mouse wheel. The graph of picture 2 is empty. At the end of the document, scroll up. You can see the graph of picture 2 partially. When scrolling down again, the graph in picture 2 is empty again. In version 4.1.5 it is always empty. The same is true for the Page Preview.

I was able to identify the responsible code for this behaviour. Between drawing the graph and its contents, there are calls to the SelectClipRgn API. This has been done so that "overdrawing" beyond the limits of the graph rectangle was avoided. In an experimental build of the software, I omitted the clipping calls and the EMF was displayed in all three cases mentioned above. However, clipping is necessary in most cases in order to display the image properly, so leaving it out in production code is not an option for us.

From the findings, I suspect that the EMF records for selecting the clip rectangle might not be processed correctly in all cases.
Comment 1 rbruenner 2014-02-13 13:24:49 UTC
Created attachment 94002 [details]
Contains a simple test programme for generating EMF content showing the issue

With the test programme, you may create EMF clipboard content which shows this problem easily - just press the Copy icon on the toolbar. The image shows a black filled rectangle and a red line. There is also a blue diagonal line of the same length as the red one, but which is clipped to the rectangle area. This line is not properly handled by LO.

The attachment also contains the VC++ project with the source code for your reference.

It is interesting that the bug disappears when line 162 in EMFTestView.cpp is commented out:
<code>
OnPrepareDC(&dcClient);
</code>
I am not quite sure whether this call is redundant or not, however, in the presence of this call, the drawings after applying the clipping rectangle do not work properly.
Comment 2 Jay Philips 2014-07-07 06:18:42 UTC
Hello rbruenner,

I can confirm that 3.3 & 3.6 to 4.1 for image 1 has grid lines if at my screen resolution, i zoom to 120%. grid lines appear in image 2 if i zoom to 90%.

In 3.6, if i scroll up and down, portions of image 2's missing red lines do appear.

4.2 and above will not show the grid lines at any zoom level or the red lines at if scrolling up and down.

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.