Skip to content
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

make SamsaGlyph.prototype.svg dynamically sized and responsive #76

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

wentin
Copy link
Contributor

@wentin wentin commented Feb 10, 2022

update SamsaGlyph.prototype.svg function so the exported SVG's width and height is set dynamically with font.unitsPerEm
this helps with fonts with non-standard canvas size.
use viewBox instead of width and height to make the svg responsive

update SamsaGlyph.prototype.svg function so the exported SVG's width and height is set dynamically with font.unitsPerEm
this helps with fonts with non-standard canvas size.
use `viewBox` instead of `width` and `height` to make the svg responsive
@Lorp
Copy link
Owner

Lorp commented Feb 12, 2022

I don’t think a viewBox based on font.unitsPerEm is the way to do it, because all glyphs are scaled by 1000/unitsPerEm by a group in the SVG.

BTW the reason I am not scaling the entire SVG is that I want to keep the sizes of UI elements (cartesian axes, point icons, arrows, outline stroke thickness) consistent for any value of unitsPerEm.

@wentin
Copy link
Contributor Author

wentin commented Feb 13, 2022

@Lorp scaled by 1000/unitsPerEm by a group makes sense to me, in that case, the SVG width height should be hardcoded 1000. However I don't see the group being scaled when I call the glyph.decompose(tuple).svg(). I made a simplified Codepen to demostrate the issue I see.
My test font unitsPerEm is 240, and the glyph is rendered based on the unitsPerEm inside the 1000 by 1000 svg
https://codepen.io/wentin/pen/eYeEZww?editors=1011

@Lorp
Copy link
Owner

Lorp commented Feb 13, 2022

The svg() method has an optional style argument. Try supplying {transform: "scale(${1/font.unitsPerEm})"}. This is how the web app calls the method.

SamsaGlyph.prototype.svg = function (style={}) {
...

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.

2 participants