Discuss Scratch
- Discussion Forums
- » Advanced Topics
- » Scratch SVG's
- procd
- Scratcher
100+ posts
Scratch SVG's
I'm no SVG expert but I've got to the point where I believe Scratch doesn't store SVG “text” properly. If you get the svg files from a project file and they contain text then has anyone found a program that renders that text. I haven't, apart from Scratch itself. I can only get the text to render if I make the “sprite” costume bigger than it should be. Then I can see the rendered text. The reason being that the x,y positions for the text are, I think, relative to the stage not the sprite and so conventional SVG rendering clips it out. Anyone know why text is like that?
- blob8108
- Scratcher
1000+ posts
Scratch SVG's
It doesn't. SVGs in Scratch are broken. Ask @nXIII for workarounds (use 0/line-height rather than x/y?). I think the plan is to fix them eventually.
https://github.com/LLK/scratch-flash/issues/31 may be relevant.
https://github.com/LLK/scratch-flash/issues/31 may be relevant.
- procd
- Scratcher
100+ posts
Scratch SVG's
Thank you. I'd reached the end of my tether with SVG's at least it seems it wasn't me.
- nXIII
- Scratcher
1000+ posts
Scratch SVG's
@MathWizz wrote (and I tweaked a bit) an SVG patcher for this: <https://github.com/nathan/phosphorus/blob/master/phosphorus.js#L392>. I have no idea what we'll do if/when this gets fixed in Scratch.
- procd
- Scratcher
100+ posts
Scratch SVG's
https://github.com/nathan/phosphorus/blob/master/phosphorus.js#L392>. I have no idea what we'll do if/when this gets fixed in Scratch.Thanks for the info. You could always remove that bit of code when/if it gets fixed! @MathWizz wrote (and I tweaked a bit) an SVG patcher for this: <
- procd
- Scratcher
100+ posts
Scratch SVG's
Ah, but you could add a translator into Kurt and run all the images from 5.5 million projects through it. Shouldn't take longAh, but there will still be some SVGs on the site saved using the old Scratch, that don't have the fix… You could always remove that bit of code when/if it gets fixed!
- blob8108
- Scratcher
1000+ posts
Scratch SVG's
Oh, sure. Because I have permissions to overwrite everyone's costume files… Ah, but you could add a translator into Kurt and run all the images from 5.5 million projects through it. Shouldn't take long
- djdolphin
- Scratcher
1000+ posts
Scratch SVG's
Of course.Oh, sure. Because I have permissions to overwrite everyone's costume files… Ah, but you could add a translator into Kurt and run all the images from 5.5 million projects through it. Shouldn't take long
!
- MathWizz
- Scratcher
100+ posts
Scratch SVG's
Is there any particular step in the code nXIII linked to that you need help understanding?
running Chromium 42.0.2311.90 with Flash Player 15.0.0.189 on Arch Linux 3.19.5-1-ck
MathWizz — JsScratch && sb.js & Amber (coming soon! maybe)
- procd
- Scratcher
100+ posts
Scratch SVG's
var bb = element.getBBox();Presumably bb is the bounding box for the text element and you are fixing up each text element by changing the x, y coordinates. Just wondering what the magic numbers 1.1 and 4-.6* etc are doing in terms of changing the x,y values?
element.setAttribute('y', (element.getAttribute('y') - bb.y) * 1.1);
element.setAttribute('x', 4 - .6 * element.transform.baseVal.consolidate().matrix.a);
// svg.style.cssText = ‘';
// console.log(element.textContent, ’data:image/svg+xml;base64,' + btoa(svg.outerHTML));
} else if ((element.hasAttribute('x') || element.hasAttribute('y')) && element.hasAttribute('transform')) {
element.setAttribute('x', 0);
element.setAttribute('y', 0);
}
- MathWizz
- Scratcher
100+ posts
Scratch SVG's
They were determined by trial and error and I think they match fairly well.
running Chromium 42.0.2311.90 with Flash Player 15.0.0.189 on Arch Linux 3.19.5-1-ck
MathWizz — JsScratch && sb.js & Amber (coming soon! maybe)
- procd
- Scratcher
100+ posts
Scratch SVG's
Ah thanks. Hopefully finally what is “element.transform.baseVal.consolidate().matrix.a”? Is it the transform matrix of the text element but the first element in it? Not sure what consolidate does though, sounds like an addition. They were determined by trial and error and I think they match fairly well.
- nXIII
- Scratcher
1000+ posts
Scratch SVG's
If you want to know exactly how that works, look at http://www.w3.org/TR/SVG/idl.html. Basically it gets the top-left entry of the combined transform matrix of the element.Ah thanks. Hopefully finally what is “element.transform.baseVal.consolidate().matrix.a”? Is it the transform matrix of the text element but the first element in it? Not sure what consolidate does though, sounds like an addition. They were determined by trial and error and I think they match fairly well.
- procd
- Scratcher
100+ posts
Scratch SVG's
Thanks, thought consolidate was a javascript function.If you want to know exactly how that works, look at http://www.w3.org/TR/SVG/idl.html. Basically it gets the top-left entry of the combined transform matrix of the element.Ah thanks. Hopefully finally what is “element.transform.baseVal.consolidate().matrix.a”? Is it the transform matrix of the text element but the first element in it? Not sure what consolidate does though, sounds like an addition. They were determined by trial and error and I think they match fairly well.
- Discussion Forums
- » Advanced Topics
- » Scratch SVG's