Skip to content
This repository has been archived by the owner on Jun 25, 2020. It is now read-only.

Primitive inlining of custom fonts #122

Merged
merged 4 commits into from
Dec 4, 2016
Merged

Conversation

anvaka
Copy link
Contributor

@anvaka anvaka commented Dec 3, 2016

I saw a few bugs for the custom fonts inlining and one PR: #29

In this change I'm loading fonts asynchronously. The custom fonts need way more care than I have time now, but I was hoping this could be a good start.

You can find working demo here: https://anvaka.github.io/saveSvgAsPng/ - if you don't immediately see custom fonts loaded - try clicking on "Save as PNG" button - it should work there.

image

There are plenty things to do to make this fix production quality, and I left a few TODOs there. Hope someone will find it useful.

The support is done by parsing all font-face urls, fetching them as
binary files, and inlining them as data uri (https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs)

Note: it's very rudimentary and fragile. But it works when applied
correctly, and I thought it could be useful for more people.

exupero#24
@@ -151,8 +272,6 @@
clone.setAttribute('transform', clone.getAttribute('transform').replace(/translate\(.*?\)/, ''));

var svg = document.createElementNS('http://www.w3.org/2000/svg','svg')
svg.appendChild(clone)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure why this is removed.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That logic is only hit if you pass a node within an SVG rather than the SVG itself. It probably shouldn't be removed for the changes you've made.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like the only blocker to merging this in.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess I pressed a wrong button in vim and the code was removed in mistake :).

Added it back.

@exupero
Copy link
Owner

exupero commented Dec 3, 2016

This looks great! Thanks for tackling this. Your approach to add rudimentary support makes a good starting point for further refinements.

@exupero exupero merged commit cd5e963 into exupero:gh-pages Dec 4, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants