-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Used chars plugin #660
Used chars plugin #660
Conversation
Improve description.
I don't think it has something with optimizing SVGs (wrt to file size) at all. |
@GreLI: Right, it doesn't reduce file size - but it should fix issues with fonts in embedded SVGs. |
AFAIK, fonts in SVG is outdated and deprecated technology in prefer to CSS fonts, which have better feature set and support. |
@GreLI: This is for using CSS fonts in SVGs that are embedded - browsers have issues displaying the custom font when the SVG is embedded. Also this plugin would allow tailoring a reduced font file for exactly this specific SVG - or when using an API like Google Fonts API for a reduced character set. |
@GreLI: Because this plugin is intended to be used for intelligently/properly embedding CSS fonts (and optimizing the font files) (see comment above) - could a PR reopen be considered? |
Ok, I understand the case, but still it's very specific and hacky one. I don't think it worth bloating the plugin list with this one. Perhaps, the plugin interface would be improved in future for easier use of custom plugins. |
As a precursor to embedding font, it would actually be a good idea. |
So real text in SVG looks usually better than vectorized text and can even be smaller. |
@TrySound; I think the plugin is relevant. |
I'm actually not in favor of this plugin.
For this to be an optimization, it'd be better to specifically check for a supported CDN. For example,
It's been years since this was posted, so understandable, but dead link. ^-^' This does not follow any standards, it's proprietary logic that Google implemented for the Google Fonts service. A plugin like this is too specific to a single proprietary service's non-standard features to be worth maintaining, especially as they can change this logic silently whenever they want. The user experience you've proposed doesn't really align with other SVGO plugins, either. Again, it behaves more like a utility than an optimization, so it can probably be its own-specialized tool outside this repo. |
The used characters determined by this plugin should not be used for loading an external font by CDN (as Google Fonts). |
Ahh, I see. Yeah, that does make more sense. |
I'll close this in favor of the discussion at #992. We might not include such a plugin in this repository due to the large dependency, but I think it makes for a good externally maintained plugin. |
This PR adds the usedChars plugin which adds a list of used characters in the text of a SVG document as
style comment which is helpful for adding/embedding tailored fonts with
reduced character set (e.g. Google Fonts text parameter or by a local font optimization technique).
E.g. a SVG document that contains the texts
I love SVG!
andTest.
would result in a list of used characters like so:
Then e.g. a font can be added using the Google Fonts API and
the API additional text parameter (
&
escaped to&
) for a reduced, tailored character set:Note that for usage in a parameter like this escaping may be necessary in some cases and
be wary of hidden/less obvious unicode characters and that the space character is also important.
Fonts in SVGs are supported by browser when the SVG document is embedded as
<object>
on page,see https://github.com/marians/test-webfonts-in-svg/pull/1 .
It doesn't work when just inlining the whole SVG into the HTML page.
Alternatively, font-face is also interpreted when the font file has
been embedded into the CSS (using base64 encoding). - This seems to be also a candidate for a plugin.
TODO: