Skip to content

Commit ff0f04f

Browse files
author
DD Liu
committed
Go back to only using svgrenderer to process vectors that we think are coming from scratch 2
1 parent d01f04b commit ff0f04f

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

src/import/load-costume.js

+17-11
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,28 @@ const {loadSvgString, serializeSvgToString} = require('scratch-svg-renderer');
44

55
const loadVector_ = function (costume, runtime, rotationCenter, optVersion) {
66
return new Promise(resolve => {
7-
const svgString = costume.asset.decodeText();
8-
// scratch-svg-renderer fixes syntax that causes loading issues,
9-
// and if optVersion is 2, fixes "quirks" associated with Scratch 2 SVGs,
10-
const fixedSvgString = serializeSvgToString(loadSvgString(svgString, optVersion === 2/* fromVersion2 */));
7+
let svgString = costume.asset.decodeText();
8+
// SVG Renderer load fixes "quirks" associated with Scratch 2 projects
9+
if (optVersion && optVersion === 2 && !runtime.v2SvgAdapter) {
10+
log.error('No V2 SVG adapter present; SVGs may not render correctly.');
11+
} else if (optVersion && optVersion === 2 && runtime.v2SvgAdapter) {
12+
// scratch-svg-renderer fixes syntax that causes loading issues,
13+
// and if optVersion is 2, fixes "quirks" associated with Scratch 2 SVGs,
14+
const fixedSvgString = serializeSvgToString(loadSvgString(svgString, true /* fromVersion2 */));
1115

12-
// If the string changed, put back into storage
13-
if (svgString !== fixedSvgString) {
14-
const storage = runtime.storage;
15-
costume.asset.encodeTextData(fixedSvgString, storage.DataFormat.SVG, true);
16-
costume.assetId = costume.asset.assetId;
17-
costume.md5 = `${costume.assetId}.${costume.dataFormat}`;
16+
// If the string changed, put back into storage
17+
if (svgString !== fixedSvgString) {
18+
svgString = fixedSvgString;
19+
const storage = runtime.storage;
20+
costume.asset.encodeTextData(fixedSvgString, storage.DataFormat.SVG, true);
21+
costume.assetId = costume.asset.assetId;
22+
costume.md5 = `${costume.assetId}.${costume.dataFormat}`;
23+
}
1824
}
1925

2026
// createSVGSkin does the right thing if rotationCenter isn't provided, so it's okay if it's
2127
// undefined here
22-
costume.skinId = runtime.renderer.createSVGSkin(fixedSvgString, rotationCenter);
28+
costume.skinId = runtime.renderer.createSVGSkin(svgString, rotationCenter);
2329
costume.size = runtime.renderer.getSkinSize(costume.skinId);
2430
// Now we should have a rotationCenter even if we didn't before
2531
if (!rotationCenter) {

0 commit comments

Comments
 (0)