Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pseudoelement white-space problem #186

Open
Logo121 opened this issue Jun 6, 2017 · 4 comments
Open

Pseudoelement white-space problem #186

Logo121 opened this issue Jun 6, 2017 · 4 comments

Comments

@Logo121
Copy link

Logo121 commented Jun 6, 2017

It seems that css pseudo-elements (::before and ::after) will have its white-space:pre-wrap rule ignored when drawn to canvas. The problem doesn't seem to happen in normal elements.

I cannot reproduce it (or even make rasterizeHTML work) in other places, but here's a few screenshots:

These 2 series of jjj kkk hhh gggs are stored in the content of li::after pseudoelement. The second one is later processed such that the contents are moved to the normal content. This is what happened after rasterizing it.

@cburgmer
Copy link
Owner

cburgmer commented Jun 6, 2017

This could be a limitation in the browser. If you want you can try eliminating this library from the equation by getting hold of the underlying SVG that rasterizeHTML.js produces (see https://github.com/cburgmer/rasterizeHTML.js/wiki/API#on-success) to rule out any other influences.

Also feel free to post a minimal HTML example for me to debug.

@Logo121
Copy link
Author

Logo121 commented Jun 7, 2017

http://jsfiddle.net/jnp8kz84/
Here's a simple HTML example forked from a JSFiddle sample I found.

From what I've tested, it seems that if the content of the pseudoelement depends on an attribute, this bug will occur. If the text is put directly in the CSS, it works properly.

@cburgmer
Copy link
Owner

Sorry for the late answer. Here's the minimal code that demonstrates the issue without this library being involved:

<meta charset="utf-8" />
<svg id="svg" xmlns="http://www.w3.org/2000/svg" width="500" height="200" font-size="25px"><foreignObject x="0" y="0" width="500" height="200" style="float: left;" externalResourcesRequired="true"><div xmlns="http://www.w3.org/1999/xhtml"><style>
* {
font-size: 25px;
font-family:monospace;
margin: 0;
}
.test {
color: green;
border: 2px dashed blue;
padding: 10px;
white-space:pre-wrap;
width:500px;
height:200px;
box-sizing:border-box;
}
.test::after{
content:attr(data-text);
color:red;
white-space:pre-wrap;
}
</style>
<div class="test" data-text="
Some
  more
    example">    Some
example
HTML</div>


</div></foreignObject></svg>

<canvas id="canvas" width="500" height="200"></canvas>

<script>
  var svgContent = svg.outerHTML,
      image = new Image();
  image.onload = function () {
    canvas.getContext('2d').drawImage(image, 0, 0);
  };
  image.src = "data:image/svg+xml;charset=utf-8," + encodeURIComponent(svgContent);
</script>

As all browsers I tested (Safari, Chrome, and Firefox) seem to render the exact same (in our view wrong) image, this might be by design, possibly in the SVG bits. I'll leave the code here for somebody else to debug, maybe there is a solution. At the moment I cannot see one though.

@cburgmer
Copy link
Owner

Here's the jsfiddle for that: https://jsfiddle.net/cburgmer/frg1oq0b/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants