Discuss Scratch

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.

tosh · slowly becoming a grown-up adult and very confused about it
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.

nXIII · GitHub
procd
Scratcher
100+ posts

Scratch SVG's

nXIII wrote:

@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.
Thanks for the info. You could always remove that bit of code when/if it gets fixed!
blob8108
Scratcher
1000+ posts

Scratch SVG's

procd wrote:

You could always remove that bit of code when/if it gets fixed!
Ah, but there will still be some SVGs on the site saved using the old Scratch, that don't have the fix…

tosh · slowly becoming a grown-up adult and very confused about it
procd
Scratcher
100+ posts

Scratch SVG's

blob8108 wrote:

procd wrote:

You could always remove that bit of code when/if it gets fixed!
Ah, but there will still be some SVGs on the site saved using the old Scratch, that don't have the fix…
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
blob8108
Scratcher
1000+ posts

Scratch SVG's

procd wrote:

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
Oh, sure. Because I have permissions to overwrite everyone's costume files…

tosh · slowly becoming a grown-up adult and very confused about it
djdolphin
Scratcher
1000+ posts

Scratch SVG's

blob8108 wrote:

procd wrote:

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
Oh, sure. Because I have permissions to overwrite everyone's costume files…
Of course.

!
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
MathWizzJsScratch && sb.js & Amber (coming soon! maybe)
procd
Scratcher
100+ posts

Scratch SVG's

var bb = element.getBBox();
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);
}
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?
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
MathWizzJsScratch && sb.js & Amber (coming soon! maybe)
procd
Scratcher
100+ posts

Scratch SVG's

MathWizz wrote:

They were determined by trial and error and I think they match fairly well.
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.
nXIII
Scratcher
1000+ posts

Scratch SVG's

procd wrote:

MathWizz wrote:

They were determined by trial and error and I think they match fairly well.
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.
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.

nXIII · GitHub
procd
Scratcher
100+ posts

Scratch SVG's

nXIII wrote:

procd wrote:

MathWizz wrote:

They were determined by trial and error and I think they match fairly well.
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.
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.
Thanks, thought consolidate was a javascript function.

Powered by DjangoBB