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
Add to_svg #519
Add to_svg #519
Conversation
Paste pics?
…On Wed., 25 Dec. 2019, 8:34 am Jojo le Barjos, ***@***.***> wrote:
This is another tentative at vector file export. I initially did some
experiments using freetype-py <https://pypi.org/project/freetype-py/>,
but I was able to get the same results using Pillow bindings of FreeType
(there are inconsistencies
<https://stackoverflow.com/questions/43060479/how-to-get-the-font-pixel-height-using-pil-imagefont>,
though).
There are however slight mismatches between rasterized and vector outputs.
I also spotted inconsistencies using different browsers for some fonts
(e.g. Segoe Script). I added an option (embed_image) to include the
output of to_image in the SVG file, which is useful for debugging. I
believe most differences are due to subtleties in kerning and ligatures,
which is not significant in common fonts.
It may also be useful to consider embedding the font file directly in the
SVG file (or only the required subset, ideally). As my personal use case
does not require fancy fonts, I did not dig any further on this topic. This
means that using the default font will render properly only if Droid Sans
Mono is available to the SVG reader.
I have attached two modified examples
<https://github.com/amueller/word_cloud/files/3999068/examples.zip>,
which use different fonts for portability.
Also, contour is not implemented.
Last but not least, I want to credit @jnothman
<https://github.com/jnothman> and his pull request
<#163> (in particular, his
hack to detect font name/weight/style). As I am not fluent in forks and
pull requests, I had to create a new pull request. But I would be glad to
learn how to extend an existing pull request!
------------------------------
You can view, comment on, or merge this pull request online at:
#519
Commit Summary
- Add to_svg prototype, using freetype-py to get metrics
- Use PIL bindings instead of freetype-py
- Handle scale attribute
- Small fix in offset
- Add option to embed image in SVG, useful for debug
File Changes
- *M* wordcloud/wordcloud.py
<https://github.com/amueller/word_cloud/pull/519/files#diff-0> (126)
Patch Links:
- https://github.com/amueller/word_cloud/pull/519.patch
- https://github.com/amueller/word_cloud/pull/519.diff
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#519?email_source=notifications&email_token=AAATH2ZPRYUNRBE3UFHGJKLQ2J55XA5CNFSM4J7A3HP2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4ICRP27A>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAATH24K7U6NXLV2PXGJCVTQ2J55XANCNFSM4J7A3HPQ>
.
|
Sure, here are rasterized versions of the SVG I attached: I also attach an example that use Segoe Script, to highlight differences between browsers: |
Your PR has flake8 failures. Please add another commit rectifying these:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Neat!
I agree the masking of each word is not perfect, but it's decent... |
Thank you for your feedback, I really appreciate. I have fixed my code, according to your suggestions. Indeed, I'm not sure whether we can do anything about these differences in SVG renderers. |
This lgtm
|
I have added an option to embed the required font subset inside the SVG. This does solve the missing font problem, for instance when using the default wordcloud font. fonttools is required only if embed_font is true. |
Hm looks like python34 is failing but looks unrelated. Thanks a lot for the contribution. Good to merge? |
would it be worth adding at least a smoke test before merge, if not an image comparison test? |
Smoke test should be good. So far I have not done any image comparison tests, for better or worse, so I wouldn't ask for that. |
I added a small smoke test, which run |
It seems we (I) can not access this new svg export feature from the command line yet? (wordcloud_cli.py). It would be cool if it could be added there as well. It could work as follows:
Or anything similar which works in the end. |
@michaelsjackson I think that would be cool! |
Hi, when will the method to_svg() uploaded to pip ? |
Sorry for the late reply. |
Thanks! |
Thanks, guys! |
which repository has to_svg, if any? |
released as 1.7.0 https://pypi.org/project/wordcloud/ |
Is SVG export now possible from the command line? If yes, how? |
@KonradHoeffner looks like it hasn't been added to the CLI yet. PR welcome :) |
@amueller: I tried to create a PR but I'm not a Python expert and couldn't figure out how to develop your tool quickly, as the README doesn't contain a section about it. Maybe you could add a section about that to the README? Steps tried
It seems to me like it denies being called directly and only wants to be called as a production version? Unfortunately I don't have more time right now and I'm not versed enough in Python and the project so I hope someone with more knowledge about both can do that PR. P.S.: I asked my colleague, who is more experienced in Python, but he also couldn't figure it out how the development workflow is supposed to be. |
This is another tentative at vector file export. I initially did some experiments using freetype-py, but I was able to get the same results using Pillow bindings of FreeType (there are inconsistencies, though).
There are however slight mismatches between rasterized and vector outputs. I also spotted inconsistencies using different browsers for some fonts (e.g. Segoe Script). I added an option (
embed_image
) to include the output ofto_image
in the SVG file, which is useful for debugging. I believe most differences are due to subtleties in kerning and ligatures, which is not significant in common fonts.It may also be useful to consider embedding the font file directly in the SVG file (or only the required subset, ideally). As my personal use case does not require fancy fonts, I did not dig any further on this topic. This means that using the default font will render properly only if Droid Sans Mono is available to the SVG reader.
I have attached two modified examples, which use different fonts for portability.
Also, contour is not implemented.
Last but not least, I want to credit @jnothman and his pull request (in particular, his hack to detect font name/weight/style). As I am not fluent in forks and pull requests, I had to create a new pull request. But I would be glad to learn how to extend an existing pull request!