Skip to content

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

Open
wentin wants to merge 1 commit into
Lorp:masterfrom
wentin:patch-2
Open

make SamsaGlyph.prototype.svg dynamically sized and responsive#76
wentin wants to merge 1 commit into
Lorp:masterfrom
wentin:patch-2

Conversation

@wentin

@wentin wentin commented Feb 10, 2022

Copy link
Copy Markdown
Contributor

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

Lorp commented Feb 12, 2022

Copy link
Copy Markdown
Owner

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

wentin commented Feb 13, 2022

Copy link
Copy Markdown
Contributor Author

@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

Lorp commented Feb 13, 2022

Copy link
Copy Markdown
Owner

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