Skip to content

[WIP] SVG export#163

Closed
jnothman wants to merge 1 commit into
amueller:masterfrom
jnothman:svg
Closed

[WIP] SVG export#163
jnothman wants to merge 1 commit into
amueller:masterfrom
jnothman:svg

Conversation

@jnothman
Copy link
Copy Markdown

This is a hacky attempt at SVG support.

Issues:

  • have to hackily inspect font to get name and font-weight, font-style CSS values (and assume font is public on target system)
  • SVG anchors its text from bottom-left rather than PIL's top-left; hence we need to recalculate rendered text size to adjust y offset
  • rendering is far from pixel-identical and results in overlaps

No tests written as yet.

@jnothman
Copy link
Copy Markdown
Author

imshow of bitmap:

imshow

SVG rendered by Chrome

SVG

@jnothman
Copy link
Copy Markdown
Author

There may yet be some consistent errors in my offsets. I've not spent a lot of time thinking precisely about the coordinate transforms.

@amueller
Copy link
Copy Markdown
Owner

Thanks for working on this. I tried to do this with html but couldn't make the alignment work. Congress and several are overlaping or example. The problem with the upper and lower corners is that the height of the text depends on the letters in the word, and I think PIL uses a different baseline. Or rather, you don't know where the baseline of PIL is (because you don't know if there's a capital letter). It could be that this works.

I need to look into it in more detail. I was also considering just moving to cairo instead of using PIL.

@Lumiukko
Copy link
Copy Markdown

This is great, I had precisely the same idea (using PIL to do the calculations and create an SVG alongside). However, I used the svgwrite module for simplicity instead of creating the SVG entirely myself.

This pull request is a good step in the direction of having word cloud vector graphics.

I would not really recommend using cairo, though, as it is a rather heavy dependency to have. Except if you're planning to integrate it as an "optional" engine.

@jnothman
Copy link
Copy Markdown
Author

It's fairly succinct even writing out the XML. I have no plans to complete this, and you are welcome to take it over, @Lumiukko

@amueller
Copy link
Copy Markdown
Owner

totally forgot that this was a thing. Well if anyone wants to work out the right offsets lol.

@jcfr jcfr force-pushed the master branch 10 times, most recently from d5ef10d to ab85b24 Compare July 25, 2018 10:29
@h4ck3rm1k3
Copy link
Copy Markdown

ok, I think we still need something like this even if not perfect, going to test it out when I have time.

This was referenced Nov 13, 2019
@michaelsjackson
Copy link
Copy Markdown

Does it mean saving as .svg or .html are both not possible, because of various reasons? Even saving out as .html would do the job, as we could use other tools converting this .html to .svg

Does html not allow adding layers on top of each other, no matter vertical or horizontal text?

@amueller
Copy link
Copy Markdown
Owner

@michaelsjackson do you meant with this PR or without? Current master doesn't support html or SVG or any form of vector graphic, it's purely pixel based.
This PR (and another PR) attempt to add SVG support but neither is complete. Any help would be most welcome.

@michaelsjackson
Copy link
Copy Markdown

@michaelsjackson do you meant with this PR or without? Current master doesn't support html or SVG or any form of vector graphic, it's purely pixel based.
This PR (and another PR) attempt to add SVG support but neither is complete. Any help would be most welcome.

Here I just quickly commented, did not test this svg modification yet. I know only your pixel solution so far, which works great. Now I was reading the other replies and you tried in the past html, but somehow it did not work?

@jojolebarjos jojolebarjos mentioned this pull request Dec 24, 2019
@amueller
Copy link
Copy Markdown
Owner

amueller commented Jan 8, 2020

closed by #519

@amueller amueller closed this Jan 8, 2020
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

Successfully merging this pull request may close these issues.

5 participants