transcoder: add a CSS rendering helper utility (issue#35)#60
Merged
transcoder: add a CSS rendering helper utility (issue#35)#60
Conversation
46fc8da to
3b68ce1
Compare
bfiics
approved these changes
Aug 21, 2022
Member
Author
|
Thank you @bfiics for your feedback. I'm pushing a new version where I added a dark-mode toggle, and also a I plan to merge this today. |
3b68ce1 to
4f1b1e2
Compare
|
Keep up the good work man! |
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
CSSTranscodingHelper
Utility for transcoding documents that use modern CSS, bypassing the EchoSVG style computations.
To obtain the best results, your document should define style properties in a style sheet or the style attribute, instead of using style-like attributes like
font-size.For example it is preferable:
to:
Supported CSS
Modern CSS is allowed, with most of the following specifications being supported:
• Selectors Level 4
• Values and Units Level 4 (
calc(), viewport-based units)• Values and Units Level 5 (advanced
attr())• Color Level 4 (
color(display-p3 -0.61 1.09 -0.22)).• Custom properties Level 1 (
var()).• Properties and Values API Level 1 (
@propertyrule).• Media Queries Level 4 (
@media screen and (400px <= width <= 700px)).• Conditional Rules Level 3 (
@supports (color: lch(45% 30 60))).Configuring for Media Queries
Media Queries use the SVG viewport dimensions by default, but you can set the dimensions used by queries by setting the
SVGAbstractTranscoder.KEY_WIDTHandSVGAbstractTranscoder.KEY_HEIGHTtranscoding hints. And the target medium (screen, print, etc.) can be set via theSVGAbstractTranscoder.KEY_MEDIAhint.For example:
Using a selector
You can also render
<svg>elements that are located inside an HTML document. By default, the first<svg>element (in document order) will be used, but you can point to a specific one using a CSS selector. For example:Foreign Elements
The processing of foreign elements is performed via SVG 1.2 features. Therefore, if a document contains foreign elements, the
<svg>element should either not have a version attribute, or that attribute's value must be 1.2 or 2.