Bug 114738 - EMF+ rendering problems
Summary: EMF+ rendering problems
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: graphics stack (show other bugs)
Version:
(earliest affected)
6.0.0.1 rc
Hardware: All Windows (All)
: medium normal
Assignee: Bartosz
URL:
Whiteboard: target:6.1.0 target:6.0.4 target:6.2....
Keywords: filter:emf
Depends on:
Blocks: EMF-WMF Regressions-EMFPlus-Rework
  Show dependency treegraph
 
Reported: 2017-12-28 17:13 UTC by bugreporter70
Modified: 2018-11-19 14:32 UTC (History)
3 users (show)

See Also:
Crash report or crash signature:


Attachments
Test EMF+ file in dual EMF/EMF+ format. (4.37 KB, image/x-emf)
2017-12-28 17:13 UTC, bugreporter70
Details
Visual Studio project that demonstrates problem (15.69 KB, application/zip)
2017-12-29 15:19 UTC, bugreporter70
Details
rotated text in dual EMF/EMF+ format. (1.91 KB, image/x-emf)
2018-03-01 15:42 UTC, bugreporter70
Details
rotated text in just EMF format. (1.56 KB, image/x-emf)
2018-03-01 15:42 UTC, bugreporter70
Details
rotated text in just EMF+ format. (500 bytes, image/x-emf)
2018-03-01 15:43 UTC, bugreporter70
Details
transparent text in just EMF+ format. (480 bytes, image/x-emf)
2018-03-01 15:43 UTC, bugreporter70
Details
transparent text in dual EMF/EMF+ format. (1.05 KB, image/x-emf)
2018-03-01 15:43 UTC, bugreporter70
Details
transparent ellipses in just EMF+ format (444 bytes, image/x-emf)
2018-03-02 14:26 UTC, bugreporter70
Details
Screeshot from displaying EMF+ files, with patches applied from Review (88.24 KB, image/png)
2018-03-02 15:38 UTC, Bartosz
Details

Note You need to log in before you can comment on or make changes to this bug.
Description bugreporter70 2017-12-28 17:13:37 UTC
Created attachment 138713 [details]
Test EMF+ file in dual EMF/EMF+ format.

I'm a software developer and recently added transparency support to my app using GDI+ which requires EMF+ for transparency support when exporting.

Although my EMF+ images appear fine in MS Office, they aren't rendered properly in LibreOffice 5.4.4.2. I later installed 6.0 and although some issues were fixed, some things were made much worse.

1. Prior to 6.0, rotated text was rendered as horizontal text. In 6.0, the rotated text doesn't appear at all.

2. 5.4 properly renders colors with transparency. 6.0 renders colors with transparency as totally opaque.

I've cobbled together some source code from MSDN that demonstrates the problems. I was originally testing the code against 5.4 so some issues have already been fixed in 6.0.

	Metafile metafile(L"test.emf", hdc, EmfTypeEmfPlusDual, NULL);
	{
		Graphics graphics(&metafile);
		SolidBrush solidBrush(Color(255, 0, 0, 255));
		SolidBrush transparentBrush(Color(128, 0, 0, 255)); // 6.0 renders as opaque
		Pen bluePen(Color(255, 0, 0, 255));
		Pen greenPen(Color(255, 0, 255, 0));

		// Issue #1: 5.4 can't render bezier spline. Fixed in 6.0
		graphics.DrawBezier(&bluePen, 30, 20, 80, 60, 120, 180, 140, 50);

		// Issue #2: 5.4 draws text but won't rotate it. 6.0 renders nothing.
		// Add some text (drawn with antialiasing) to the metafile.
		FontFamily fontFamily(L"Arial");
		Gdiplus::Font font(&fontFamily, 24, FontStyleRegular, UnitPixel);
		graphics.SetTextRenderingHint(TextRenderingHintAntiAlias);
		graphics.DrawString(L"Transparent Text", 16, &font, 
			PointF(50.0f, 50.0f), &transparentBrush);
		graphics.RotateTransform(30.0f);
		graphics.DrawString(L"Rotated Text", 12, &font, 
			PointF(50.0f, 50.0f), &solidBrush);
		graphics.ResetTransform() ;

		GraphicsPath clip;
		clip.AddRectangle(Rect(150, 10, 20, 50));
		graphics.SetClip(&clip);
		// Add an ellipse (drawn with antialiasing) to the metafile.
		graphics.SetSmoothingMode(SmoothingModeHighQuality);
		graphics.FillEllipse(&transparentBrush, Rect(150, 10, 25, 75));
		graphics.ResetClip();

		// Issue #3: 5.4 doesn't support ResetClip() so the following will be clipped out. Fixed in 6.0.
		// Avoided problem by using Save/Restore of graphics state instead.

		// Add a rectangle and an ellipse to the metafile.
		graphics.DrawRectangle(&greenPen, Rect(50, 10, 25, 75));
		graphics.DrawEllipse(&greenPen, Rect(100, 10, 25, 75));
	}
Comment 1 Bartosz 2017-12-29 09:44:15 UTC
Hello.
I am new in Windows developer, as I normally use Ubuntu.
Could you please  describe setup  of environment step by step?
Also attaching MS  project will be very useful.
Comment 2 bugreporter70 2017-12-29 15:16:10 UTC
To be honest, I don't think it's important that you be able to run my example as the EMF file demonstrates the problem. I just provided the code to show that the problem could be produced by using basic drawing routines which is why I used Microsoft's example code rather than my own.

But if you insist, I took a GDI+ project I found on codeproject.com, made minor fixes s o that the project can be built, and added the metafile creation code I provided earlier. Please note that where I placed the metafile creation code is not the proper place to do it. I just took the easy way out.

I used Visual Studio 2008 on Windows 10 to create the project. I do have VS 2017 installed but haven't migrated to it yet.

Just open the .sln file in Visual Studio, build it, then run it.
Comment 3 bugreporter70 2017-12-29 15:19:15 UTC
Created attachment 138733 [details]
Visual Studio project that demonstrates problem

This is a simple project that demonstrates the bug. Please note that where I placed the metafile creation code is not the correct place for it. I just wanted to demonstrate the problem with the minimal amount of effort so I took an existing project I found on codeproject.com and modified it.
Comment 4 Bartosz 2018-02-27 14:28:03 UTC
Confirmed with LibreOffice 6.0.1

Could you please create multiple, small .emf files. With every file, only one issue will be visible.
For example:
- rotated_text.emf
- transparent_text.emf

I have some spare time now, and I could fix it, but it will be much easier for me, to have only one issue at file.
Comment 5 bugreporter70 2018-03-01 15:41:00 UTC
I've included several EMF files.

rotated_text.emf      --> just EMF
rotated_text_plus.emf --> just EMF+
rotated_text_dual.emf --> both EMF and EMF+

transparent_text_plus --> just EMF+
transparent_text_dual.emf --> both EMF and EMF+

There is no plain EMF file for transparent text because of course plain EMF doesn't support transparency. The plain EMF file for rotated text does render properly in LibreOffice.

I originally made the comment that in LibreOffice 6.0, rotated text doesn't appear at all. I don't know what's happened to my setup since I made that comment because it does appear now, it's just not rotated. I haven't updated LibreOffice since I first posted the bugs.

FWIW, you can use just WordPad to see how the EMF+ files are properly rendered.

Here's the updated code with all cruft removed:

	Metafile metafile(L"test.emf", hdc, EmfTypeEmfPlusDual, NULL);
	{
		Graphics graphics(&metafile);
		SolidBrush solidBrush(Color(255, 0, 0, 255));
		SolidBrush transparentBrush(Color(128, 0, 0, 255)); // 6.0 renders as opaque

		// Add some text (drawn with antialiasing) to the metafile.
		FontFamily fontFamily(L"Arial");
		Gdiplus::Font font(&fontFamily, 24, FontStyleRegular, UnitPixel);
		graphics.SetTextRenderingHint(TextRenderingHintAntiAlias);
		graphics.DrawString(L"Transparent Text", 16, &font, 
			PointF(50.0f, 50.0f), &transparentBrush);
		graphics.RotateTransform(30.0f);
		graphics.DrawString(L"Rotated Text", 12, &font, 
			PointF(50.0f, 50.0f), &solidBrush);
		graphics.ResetTransform() ;
	}
Comment 6 bugreporter70 2018-03-01 15:42:01 UTC
Created attachment 140255 [details]
rotated text in dual EMF/EMF+ format.
Comment 7 bugreporter70 2018-03-01 15:42:39 UTC
Created attachment 140256 [details]
rotated text in just EMF format.
Comment 8 bugreporter70 2018-03-01 15:43:03 UTC
Created attachment 140257 [details]
rotated text in just EMF+ format.
Comment 9 bugreporter70 2018-03-01 15:43:35 UTC
Created attachment 140258 [details]
transparent text in just EMF+ format.
Comment 10 bugreporter70 2018-03-01 15:43:53 UTC
Created attachment 140259 [details]
transparent text in dual EMF/EMF+ format.
Comment 11 Bartosz 2018-03-02 00:33:35 UTC
Review proposal for FillEllipse figures (still I need to fix unit tests):
https://gerrit.libreoffice.org/#/c/50609/


I need one more file, to make sure that transparency is working correctly.
Could you please create EMF+ image with FillEllipse and transparency set to some extreme values value, like:

SolidBrush transparentBrush(Color(20, 0, 0, 255));
SolidBrush transparentBrushAlmostOpaque(Color(200, 0, 0, 255));

I would like to check if transparency is working correctly (Corner cases: 0 for completely transparent to 0xFF for completely opaque)

Thanks.
Comment 12 bugreporter70 2018-03-02 14:26:10 UTC
Created attachment 140292 [details]
transparent ellipses in just EMF+ format

4 ellipses with opacity of 0, 20, 200, 255 (fully opaque) from left to right.
Comment 13 Bartosz 2018-03-02 15:38:06 UTC
Created attachment 140293 [details]
Screeshot from displaying EMF+ files, with patches applied from Review

In attachment you could find screenshot of sample EMF+ files, rendered using patched version of LO.
Comment 14 bugreporter70 2018-03-07 14:33:27 UTC
(In reply to Bartosz from comment #13)
> Created attachment 140293 [details]
> Screeshot from displaying EMF+ files, with patches applied from Review
> 
> In attachment you could find screenshot of sample EMF+ files, rendered using
> patched version of LO.

Great! Is text rotation going to be fixed too?
Comment 15 Bartosz 2018-04-05 22:50:06 UTC
Hi. Currently I'm working on rotation support.
I need help to accomplish that.
Could you please create EMF+ files, with rotated and transparent DrawDriverString  record?
I would like to use it for testing purposes.
Comment 16 Commit Notification 2018-04-06 14:03:44 UTC
Bartosz Kosiorek committed a patch related to this issue.
It has been pushed to "master":

http://cgit.freedesktop.org/libreoffice/core/commit/?id=2afdea17162731888ad8f09fae2bb50e4246d7e9

tdf#114738 Add support for transparency for EMF+ records

It will be available in 6.1.0.

The patch should be included in the daily builds available at
http://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
http://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 17 Commit Notification 2018-04-06 14:06:33 UTC
Bartosz Kosiorek committed a patch related to this issue.
It has been pushed to "libreoffice-6-0":

http://cgit.freedesktop.org/libreoffice/core/commit/?id=aee1904446cd0508cdf06fd23155373b5018dfed&h=libreoffice-6-0

tdf#114738 Add support for transparency for EMF+ records

It will be available in 6.0.4.

The patch should be included in the daily builds available at
http://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
http://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 18 bugreporter70 2018-04-24 19:54:03 UTC
(In reply to Bartosz from comment #15)
> Hi. Currently I'm working on rotation support.
> I need help to accomplish that.
> Could you please create EMF+ files, with rotated and transparent
> DrawDriverString  record?
> I would like to use it for testing purposes.

Sorry, I got busy at work and almost forgot about this. However, I already created and uploaded rotated and transparent text test cases.
Comment 19 Xisco Faulí 2018-05-29 09:33:25 UTC
A polite ping to Bartosz Kosiorek:
Is this bug fixed? if so, could you please close it as RESOLVED FIXED ?
Otherwise, Could you please explain what's missing?
Thanks
Comment 20 Bartosz 2018-08-26 06:35:56 UTC
There is still missing rotation support. I have added transparency support.
Comment 21 Commit Notification 2018-11-05 18:29:48 UTC
Bartosz Kosiorek committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/+/cd7054b5e49f435349860d55bcff5a78d14a5f67%5E%21

tdf#55058 tdf#106084 tdf#114738 EMF+ Add rotation support for String drawing

It will be available in 6.2.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 22 Bartosz 2018-11-05 21:05:20 UTC
Hello @bugreporter70. All issues which you reported were already resolved in LO 6.2 If you are experiencing same other problems, please report new bug report. Thanks
Comment 23 Bartosz 2018-11-06 00:06:14 UTC
Review for this issue:
https://gerrit.libreoffice.org/#/c/62814/
Comment 24 Commit Notification 2018-11-19 14:32:25 UTC
Bartosz Kosiorek committed a patch related to this issue.
It has been pushed to "libreoffice-6-1":

https://git.libreoffice.org/core/+/1f308f95f88eeea3cbb46c78c39678c0f3860d0b%5E%21

tdf#55058 tdf#106084 tdf#114738 EMF+ Add rotation support for String drawing

It will be available in 6.1.4.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.