Bug 159401 - When copying embedded SVG, CSS is not retained.
Summary: When copying embedded SVG, CSS is not retained.
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit2 (show other bugs)
Version: Safari 9
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-07-04 00:56 PDT by Samuel Williams
Modified: 2016-07-05 09:32 PDT (History)
3 users (show)

See Also:


Attachments
A case which shows the issue. (17.28 KB, application/zip)
2016-07-04 00:56 PDT, Samuel Williams
no flags Details
Example of copying into Mail.app from chartist-js website. (264.00 KB, image/png)
2016-07-04 03:33 PDT, Samuel Williams
no flags Details
Results of copying from Chrome. (392.93 KB, image/png)
2016-07-04 03:36 PDT, Samuel Williams
no flags Details
Example showing inline stylesheets working. (394.50 KB, image/png)
2016-07-04 04:18 PDT, Samuel Williams
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Samuel Williams 2016-07-04 00:56:57 PDT
Created attachment 282693 [details]
A case which shows the issue.

When copying either via the API or using Command-C, from the attached sample, and then pasting into Mail.app, the circular pie-chart shows black.

There is possibly an additional bug where the sample also shows only one pie chart but on loading in Safari shows two. Not sure why. Perhaps it's evaluating the JavaScript code a second time?
Comment 1 Samuel Williams 2016-07-04 03:32:53 PDT
Another way to reproduce this is to go to https://gionkunz.github.io/chartist-js/ and copy the charts and paste into Mail.app. It shows up as black shapes, i.e. without styles applied.
Comment 2 Samuel Williams 2016-07-04 03:33:28 PDT
Created attachment 282701 [details]
Example of copying into Mail.app from chartist-js website.
Comment 3 Samuel Williams 2016-07-04 03:35:28 PDT
Tried copying from Chrome.. issue was still similar.
Comment 4 Samuel Williams 2016-07-04 03:36:02 PDT
Created attachment 282702 [details]
Results of copying from Chrome.
Comment 5 Samuel Williams 2016-07-04 03:39:08 PDT
If the issue is similar from Chrome and Safari, i.e. the pasteboard content is similar but rendering is broken in both instances, is the problem related to how the pasteboard content is rendered? I assume webkit is responsible for rendering in Mail.app? Could it be a sandbox-related issue? I also noticed for the web archive, quick look was generating some odd previews.

For example, when the preview was the thumbnail type, the shape was black. But when pressing spacebar to open quick look preview, it rendered correctly. Odd.
Comment 6 Samuel Williams 2016-07-04 04:18:27 PDT
Managed to work around the issue by traversing the SVG DOM and using getComputedStyle to apply fill and other related CSS properties as inline styles. Then, copying works.

Here is a simple example of the code I used:

function embedSVGStyle(element) {
	Array.prototype.forEach.call(element.children, function(child) {
		embedSVGStyle(child);
	});
	
	var computedStyle = getComputedStyle(element);
	element.style.fill = computedStyle.fill;
}

Attached is a picture showing it working.
Comment 7 Samuel Williams 2016-07-04 04:18:54 PDT
Created attachment 282705 [details]
Example showing inline stylesheets working.