Bug 124424 - EMF+ Linear gradients are not displayed correctly
Summary: EMF+ Linear gradients are not displayed correctly
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Draw (show other bugs)
Version:
(earliest affected)
4.2.6.2 release
Hardware: All All
: medium normal
Assignee: Not Assigned
URL:
Whiteboard: target:7.0.0
Keywords: filter:emf
Depends on:
Blocks: EMF-WMF
  Show dependency treegraph
 
Reported: 2019-03-29 13:18 UTC by Bartosz
Modified: 2020-03-23 18:17 UTC (History)
4 users (show)

See Also:
Crash report or crash signature:


Attachments
EMF+ image with gradients to import (1.84 MB, image/emf)
2019-03-29 13:19 UTC, Bartosz
Details
Reference PNG image exported with MS Paint (427.05 KB, image/png)
2019-03-29 13:20 UTC, Bartosz
Details
EMF+ test image with linear and path gradient. It could be used for testing (196.89 KB, image/emf)
2020-03-11 21:46 UTC, Bartosz
Details
EMF+ test image with linear and path gradient exported to PNG (8.15 MB, image/png)
2020-03-11 21:47 UTC, Bartosz
Details
EMF+ simple linear gradient (312.25 KB, image/emf)
2020-03-11 22:09 UTC, Bartosz
Details
EMF+ simple linear gradient exported to PNG (10.99 KB, image/png)
2020-03-11 22:13 UTC, Bartosz
Details
EMF+ Path gradient (48.87 KB, image/emf)
2020-03-11 22:14 UTC, Bartosz
Details
EMF+ Path gradient exported to PNG (26.23 KB, image/png)
2020-03-11 22:14 UTC, Bartosz
Details
EMF+ Path gradient with two ellipses. All path gradients is imported into LibreOffice as Ellipse gradients (49.76 KB, image/emf)
2020-03-14 21:33 UTC, Bartosz
Details
EMF+ Path gradient with two ellipses exported to PNG (20.85 KB, image/png)
2020-03-14 21:33 UTC, Bartosz
Details
EMF+ different linear gradients (1.16 MB, image/emf)
2020-03-15 11:12 UTC, Bartosz
Details
EMF+ different linear gradients exported to PNG (30.68 KB, image/png)
2020-03-15 11:15 UTC, Bartosz
Details
Looks better (514.66 KB, image/svg+xml)
2020-03-15 18:09 UTC, Armin Le Grand (allotropia)
Details
HAS to work (1.20 KB, image/svg+xml)
2020-03-15 18:10 UTC, Armin Le Grand (allotropia)
Details
HAS to work (983 bytes, image/svg+xml)
2020-03-15 18:10 UTC, Armin Le Grand (allotropia)
Details
The metafile, extracted from ssaved ODG (1.69 MB, application/octet-stream)
2020-03-19 15:52 UTC, Armin Le Grand (allotropia)
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Bartosz 2019-03-29 13:18:53 UTC
Description:
There are several issues with displaying Gradients in EMF+ format:
1. Missing transparency
2. Gradients are sometimes not displayed



Steps to Reproduce:
1. Open attachaed file
2. 
3.

Actual Results:
1. Missing transparency
2. Not all gradients are displayed
3. The angle of gradient is wrong

Expected Results:
The image is displayed as with MS Paint (see attachment)


Reproducible: Always


User Profile Reset: No



Additional Info:
Comment 1 Bartosz 2019-03-29 13:19:33 UTC
Created attachment 150394 [details]
EMF+ image with gradients to import
Comment 2 Bartosz 2019-03-29 13:20:19 UTC
Created attachment 150395 [details]
Reference PNG image exported with MS Paint
Comment 3 Xisco Faulí 2019-07-01 15:08:13 UTC
Dear Bartosz,
This bug has been in ASSIGNED status for more than 3 months without any
activity. Resetting it to NEW.
Please assigned it back to yourself if you're still working on this.
Comment 4 Bartosz 2019-07-12 10:27:09 UTC
The partial fix was submitted with Commit:
https://gerrit.libreoffice.org/plugins/gitiles/core/+/4a215887a845452f984c5453de883b538f660ad4%5E%21

Unfortunately I made mistake with ticket number
Comment 5 Bartosz 2020-03-06 15:02:17 UTC
Hello @Armin

I have a big problem with implementing proper gradient support as it seems that gradients are behave unexpectectly.

If I use the SpreadMethod Repeat, the gradient is displayed only at first image and on next is gone:
https://gerrit.libreoffice.org/c/core/+/66932/7/drawinglayer/source/tools/emfphelperdata.cxx

I saw that you are working on #130478. I suspect that the issue is in Graphic Stack which I'm not experinced.

Could you please take a look at this issue?
Comment 6 Armin Le Grand (allotropia) 2020-03-06 16:05:02 UTC
grepping...
Comment 7 Armin Le Grand (allotropia) 2020-03-11 08:43:24 UTC
Started to check yesterday, seems as if support for brush->wrapMode in EmfPlusHelperData::EMFPPlusFillPolygon is missing. This is in principle https://apireference.aspose.com/net/imaging/aspose.imaging.fileformats.emf.emfplus.consts/emfpluswrapmode and needs to be mapped to https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/spreadMethod since we use SVG gradients in Primitives (the most advanced we have currently, new ones possible anytime).
Just mapping is not enough, seems as if modes

drawinglayer::primitive2d::SpreadMethod::Repeat
drawinglayer::primitive2d::SpreadMethod::Reflect

are not well supported in SvgLinearGradientPrimitive2D::create2DDecomposition yet, on it...
Comment 8 Bartosz 2020-03-11 09:20:40 UTC
Thanks Armin. If you would need some additional/specific EMF+ gradient samples, just let me know. I could produce is.
Comment 9 Armin Le Grand (allotropia) 2020-03-11 13:06:01 UTC
After supporting these modes had to masively adapt SvgGradientHelper/SvgLinearGradientPrimitive2D/SvgRadialGradientPrimitive2D. These were not able to handle cases where the logical color gradient spread was e.g. completely negative but mode on repeat. Made this now to create the needed sub-runs in a single call.
Adapted creation of color runs to do in a single effort. Previous version tried to do this from [0.0 .. 1.0] and to re-use transformed versions in the caller if SpreadMethod was on some repeat mode, but had problems when e.g. like in the bugdoc from the task a negative-only fStart/fEnd run was requested in which case it did nothing. Even when reusing the spread might not have been a full one from [0.0 .. 1.0].
This gets complicated due to mirrored runs, but also for gradient definitions with missing entries for 0.0 and 1.0 in which case these have to be guessed to be there with same parametrisation as their nearest existing entries. These *could* have been added at checkPreconditions() but would then create unnecessary spreads on zone overlaps.
Comment 10 Armin Le Grand (allotropia) 2020-03-11 13:15:21 UTC
Added https://gerrit.libreoffice.org/c/core/+/90329 a 1st version to gerrit. This already does something better, but is not yet correct. There might still be errors in setting up the gradients in drawinglayer\source\tools\emfphelperdata.cxx

More important: We need to check if the deep changes keep the SVG import stuff unchanged - it should, but you never know. The gradient spread is just done different (and better, more reliable), but doing this deep change as own commit will allow to better detect problems, including bisecting.

@Bartosz: You may check this early 1st step locally if you have the possibility to do so. It is necessary to also create some radial gradients in EMF if possible. It would also be good to some SVG tests with linear and radial gradients - I'll also do some more...
Comment 11 Commit Notification 2020-03-11 15:25:36 UTC
Armin Le Grand committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/c3f0c527b31f5c88263ea63d3d0e332c4783917c

tdf#124424 Enhanced SvgGradientHelper for EMF+

It will be available in 7.0.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 12 Bartosz 2020-03-11 21:46:56 UTC
Created attachment 158627 [details]
EMF+ test image with linear and path gradient. It could be used for testing
Comment 13 Bartosz 2020-03-11 21:47:54 UTC
Created attachment 158628 [details]
EMF+ test image with linear and path gradient exported to PNG
Comment 14 Bartosz 2020-03-11 22:09:48 UTC
Created attachment 158630 [details]
EMF+ simple linear gradient
Comment 15 Bartosz 2020-03-11 22:13:30 UTC
Created attachment 158631 [details]
EMF+ simple linear gradient exported to PNG
Comment 16 Bartosz 2020-03-11 22:14:14 UTC
Created attachment 158632 [details]
EMF+ Path gradient
Comment 17 Bartosz 2020-03-11 22:14:45 UTC
Created attachment 158633 [details]
EMF+ Path gradient exported to PNG
Comment 18 Armin Le Grand (allotropia) 2020-03-12 12:30:58 UTC
Have detected some smaller glitches using SVG simple examples. Correcting these...
Comment 19 Armin Le Grand (allotropia) 2020-03-12 12:37:33 UTC
Corrections done inhttps://gerrit.libreoffice.org/c/core/+/90382.

@Bartosz: Thanks for the examples. Could you add/create some for radiant gradients?
You are aware that we do not really support PathGradients - that's a missing feature and hard to do correctly. We do currently not have the correct tools for that, like we have for linear and radial by re-using the SvgGradientHelper-based primitives that I did once for SVG.
Thus I would say we/you can continue to fix/enhance the linear/radial ones in drawinglayer\source\tools\emfphelperdata.cxx at EmfPlusHelperData::EMFPPlusFillPolygon, but I see no simple way to support BrushTypePathGradient proper anytime soon.
Comment 20 Commit Notification 2020-03-12 13:51:12 UTC
Armin Le Grand committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/c20e70d28df21429bba92b6d8a7d7061c2aa5d8b

tdf#124424 Corrections at SvgGradientHelper for EMF+

It will be available in 7.0.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 21 Armin Le Grand (allotropia) 2020-03-12 18:48:07 UTC
I cannot find out why the rotation(s) of the gradients is wrong, I am checking LinearGradientSimple.emf. Left to right the 1st two have a TextureTransformation with 45deg resp. -90deg rotation, the 3rd has no TextureTransformation.
When looking at

https://docs.microsoft.com/en-us/dotnet/api/system.windows.media.lineargradientbrush?view=netframework-4.8

it is clear that without TextureTransformation all are diagonal.

The left obj shall be diagonal, but with the TextureTransformation of 45deg it gets horizontal.

The mid shall be horizontal, but starting from diagonal (default, see url above) and a rot of -90deg in the transformation I see no way to get there...?

The right shall be vertical, but has no TextureTransformation at all, so has to stay on default (diagonal).

I checked now

https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-emfplus/fa7c00e7-ef14-4070-b12a-cb047d964ebe

and corresp. pages deeply, but see no hint yet - in the other doc al least a 'RelativeTransform' and 'Transform' is mentioned, but I see only one transform in Brush. I have no clue...

Bartosz..?
Comment 22 Armin Le Grand (allotropia) 2020-03-14 19:42:42 UTC
@Bartosz: Please take over again. I have enhanced the linear/radial gradients to do all you will need (hopefully). Have checked if I could identify errors in orienation (comment 21), but seems to require more knowledge on EMF+ do do so.
Please also see comment 19 regarding BrushTypePathGradient.
Comment 23 Bartosz 2020-03-14 21:33:14 UTC
Created attachment 158679 [details]
EMF+ Path gradient with two ellipses. All path gradients is imported into LibreOffice as Ellipse gradients

Hello Armin.
In EMF+ format there is no radiant gradients. Everything other than Linear Gradients is handled by Path Gradients.
As a workaround while Path Gradients is needed during EMF+ import, we are using Radial gradients.
Comment 24 Bartosz 2020-03-14 21:33:44 UTC
Created attachment 158680 [details]
EMF+ Path gradient with two ellipses exported to PNG
Comment 25 Commit Notification 2020-03-15 10:39:38 UTC
Bartosz Kosiorek committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/490804ade1103c3fd7569ea093d8d90beab445a3

tdf#124424 Fix orientation of the LinearGradient

It will be available in 7.0.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 26 Bartosz 2020-03-15 11:12:46 UTC
Created attachment 158696 [details]
EMF+ different linear gradients
Comment 27 Bartosz 2020-03-15 11:15:18 UTC
Created attachment 158697 [details]
EMF+ different linear gradients exported to PNG
Comment 28 Bartosz 2020-03-15 11:23:24 UTC
Thanks Armin for your patches
.
I have attached next EMF+ image where I found following issues:
1. The image is not imported with full size. Bottom and right part of EMF+ image is not displayed
2. Some of the linear gradients are not displayed correclty
3. There are overlap lines between the gradients images.
Comment 29 Commit Notification 2020-03-15 14:27:03 UTC
Bartosz Kosiorek committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/87c2d3a3d9d91c18ff8c32760a3c34a99c629c1a

tdf#124424 Fix WrapModeTileFlipY option for LinearGradient

It will be available in 7.0.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 30 Armin Le Grand (allotropia) 2020-03-15 18:09:55 UTC
Created attachment 158699 [details]
Looks better

@Bartosz: wow- looks much better now. Also SVG, adding some test files
Comment 31 Armin Le Grand (allotropia) 2020-03-15 18:10:32 UTC
Created attachment 158700 [details]
HAS to work
Comment 32 Armin Le Grand (allotropia) 2020-03-15 18:10:50 UTC
Created attachment 158701 [details]
HAS to work
Comment 33 Commit Notification 2020-03-15 18:21:36 UTC
Bartosz Kosiorek committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/1f540cc7613cdbc0048f4013efe43886d256f86b

tdf#124424 EMF+ Add tests for LinearGradient

It will be available in 7.0.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 34 Commit Notification 2020-03-16 15:52:54 UTC
Bartosz Kosiorek committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/e11796866f94d2f51023e6bc2b23a39af10a7d96

tdf#124424 EMF+ Extend test options of SvgLinearGradientPrimitive2D

It will be available in 7.0.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 35 Armin Le Grand (allotropia) 2020-03-19 15:52:21 UTC
Created attachment 158819 [details]
The metafile, extracted from ssaved ODG
Comment 36 Armin Le Grand (allotropia) 2020-03-19 15:54:39 UTC
Comment on attachment 158819 [details]
The metafile, extracted from ssaved ODG

OOps -  sorry, wrong task. Can I ssomehow remove this again..?
Comment 37 Bartosz 2020-03-19 22:30:47 UTC
Hello Armin,
Could you please take a look at attachment 158697 [details] from comment 26, and check how displaying of gradients could be fixed?

As I noticed, the wrongly displayed gradients have negative values.
It will be great to fix this issue as it impacts many EMF+ images with Linear Gradients.

Thanks
Comment 38 Commit Notification 2020-03-20 07:23:01 UTC
Bartosz Kosiorek committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/ad4ee3bb3bf99c3b02ddca2318d39a1c0f2469a0

EMF+ tdf#124424 Add support for transparency to LinearGradient and blend points

It will be available in 7.0.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 39 Bartosz 2020-03-22 22:27:03 UTC
Almost all issues with gradients were resolved. The remaining quirks will be resolved in separate bug reports.