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

Stroke width is not transformed #157

Closed
mavit opened this issue Oct 17, 2020 · 6 comments
Closed

Stroke width is not transformed #157

mavit opened this issue Oct 17, 2020 · 6 comments

Comments

@mavit
Copy link
Contributor

mavit commented Oct 17, 2020

I'm trying to build the SVGs from the OpenMoji project into a font, but the source SVG files typically contain a lot of padding around the edges, and hence each character appears rather small when converted.

To try to work around this, I'm hacking a transform=scale(1.3) attribute into the root node of each SVG file. This seems to work as expected if I view the hacked files with any SVG viewer I've tried, but it doesn't quite work correctly with nanoemoji. The shapes are upscaled, but the stroke width is not.

This can be quite hard to see, so for this screenshot I have exaggerated the effect with scale(10). Scaled:
image

Unscaled:
image

Relates to hfg-gmuend/openmoji#260.

@mavit
Copy link
Contributor Author

mavit commented Oct 17, 2020

I should add, here's an example of one of the original SVGs, my hacked SVG, and the SVG found in the picosvg directory after building with nanoemoji --color_format=picosvgz (which looks okay to me). I have used scale(2) for these examples.

samples.tar.gz

@rsheeter
Copy link
Collaborator

Apologies for the slow response, we've been busy trying to update a chain of things after a spec (or pre-spec) shift for COLR v1 (https:/googlefonts/colr-gradients-spec).

The scale need sounds similar to #2 where you have a set of svgs but want a transform applied.

@rsheeter
Copy link
Collaborator

I wonder if we can should explore adding OpenMoji to https:/googlefonts/color-fonts?

@anthrotype
Copy link
Member

hacking a transform=scale(1.3) attribute into the root node of each SVG file

I'm having troubles understanding whether/how we should handle transform attribute on a root <svg> element. IIUC, it appears that for SVG 1.1 that is not supported, and it's a feature of SVG2:
w3c/csswg-drafts#894

Right now, picosvg doesn't treat the svg root transform specially, but simply applies it the same way it would for an all-enclosing hypothetical <g transform="..."> element.

However here they say that the default transform-origin for transforms on <svg> element is 50% 50%, not 0 0 like the rest of its children: https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/transform-origin

I even tried patching picosvg locally to interpret the root transform this way (i.e. equivalent of applying the combined translate(dx, dy) [root-transform] translate(-dx, -dy), where (dx, dy) is the center point in the svg canvas) but I am getting unexpected results that don't match the way Chrome renders the original svg with a root <svg> transform..

I'm tempted to say that picosvg should not support transform attribute on root svg element. Until i figure this out, maybe in the interim, could you try achieving the same result by adding your transform to a <g> element that wraps everything else?

@mavit
Copy link
Contributor Author

mavit commented Nov 23, 2020

could you try achieving the same result by adding your transform to a <g> element that wraps everything else?

Seems reasonable. I've not been able to test it yet, though, because if I use picosvg master I run into googlefonts/picosvg#138.

mavit added a commit to mavit/openmoji that referenced this issue Nov 28, 2020
- Itʼs suggested in googlefonts/nanoemoji#157 that we donʼt apply scaling by transforming the root `svg` element, but rather by enclosing the body of the SVG in an element that applies the transform.
- Recent nanoemoji versions are configured with a file rather than on the command line.
@mavit
Copy link
Contributor Author

mavit commented Nov 28, 2020

Yes, wrapping everything in a <g> element worked well for me. Thanks.

@mavit mavit closed this as completed Nov 28, 2020
JeppeKlitgaard pushed a commit to JeppeKlitgaard/openmoji that referenced this issue Nov 16, 2022
- Itʼs suggested in googlefonts/nanoemoji#157 that we donʼt apply scaling by transforming the root `svg` element, but rather by enclosing the body of the SVG in an element that applies the transform.
- Recent nanoemoji versions are configured with a file rather than on the command line.
JeppeKlitgaard pushed a commit to JeppeKlitgaard/openmoji that referenced this issue Dec 6, 2022
- Itʼs suggested in googlefonts/nanoemoji#157 that we donʼt apply scaling by transforming the root `svg` element, but rather by enclosing the body of the SVG in an element that applies the transform.
- Recent nanoemoji versions are configured with a file rather than on the command line.
JeppeKlitgaard pushed a commit to JeppeKlitgaard/openmoji that referenced this issue Dec 6, 2022
- Itʼs suggested in googlefonts/nanoemoji#157 that we donʼt apply scaling by transforming the root `svg` element, but rather by enclosing the body of the SVG in an element that applies the transform.
- Recent nanoemoji versions are configured with a file rather than on the command line.
JeppeKlitgaard pushed a commit to JeppeKlitgaard/openmoji that referenced this issue Jan 6, 2023
- Itʼs suggested in googlefonts/nanoemoji#157 that we donʼt apply scaling by transforming the root `svg` element, but rather by enclosing the body of the SVG in an element that applies the transform.
- Recent nanoemoji versions are configured with a file rather than on the command line.
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

No branches or pull requests

3 participants