Skip to content

Commit

Permalink
Remove _draw and fromString
Browse files Browse the repository at this point in the history
  • Loading branch information
adroitwhiz committed Jan 7, 2021
1 parent 4c6e271 commit 5114796
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 42 deletions.
15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,17 @@ npm install
```js
import SvgRenderer from 'scratch-svg-renderer';

var svgRenderer = new SvgRenderer();
svgRenderer.fromString(svgData, callback);
const svgRenderer = new SvgRenderer();

const svgData = "<svg>...</svg>";
const scale = 1;
const quirksMode = false; // If true, emulate Scratch 2.0 SVG rendering "quirks"
function doSomethingWith(canvas) {...};

svgRenderer.loadSVG(svgData, quirksMode, () => {
svgRenderer.draw(scale);
doSomethingWith(svgRenderer.canvas);
});
```

## How to run locally as part of scratch-gui
Expand All @@ -49,4 +58,4 @@ To run scratch-svg-renderer locally as part of scratch-gui, for development:
6. In scratch-gui, follow its instructions to run it or build its code

## Donate
We provide [Scratch](https://scratch.mit.edu) free of charge, and want to keep it that way! Please consider making a [donation](https://secure.donationpay.org/scratchfoundation/) to support our continued engineering, design, community, and resource development efforts. Donations of any size are appreciated. Thank you!
We provide [Scratch](https://scratch.mit.edu) free of charge, and want to keep it that way! Please consider making a [donation](https://secure.donationpay.org/scratchfoundation/) to support our continued engineering, design, community, and resource development efforts. Donations of any size are appreciated. Thank you!
10 changes: 6 additions & 4 deletions src/playground/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,10 @@
loadSVGString();
}

function renderSVGString(str) {
renderer.fromString(str);
renderer._draw(parseFloat(scaleSlider.value), ()=>{});
function renderSVGString() {
if (renderer.loaded) {
renderer.draw(parseFloat(scaleSlider.value));
}
renderedContent.value = renderer.toString(true);
}

Expand Down Expand Up @@ -103,11 +104,12 @@
function loadSVGString() {
readFileAsText(fileChooser.files[0]).then(str => {
loadedSVGString = str;
renderer.loadSVG(str, false);
})
}

function renderLoadedString() {
renderSVGString(loadedSVGString);
renderSVGString();
referenceContent.value = loadedSVGString;
shouldRenderReference.checked && updateReferenceImage();
}
Expand Down
35 changes: 0 additions & 35 deletions src/svg-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,6 @@ class SvgRenderer {
return this._canvas;
}

/**
* Load an SVG from a string and draw it.
* This will be parsed and transformed, and finally drawn.
* When drawing is finished, the `onFinish` callback is called.
* @param {string} svgString String of SVG data to draw in quirks-mode.
* @param {number} [scale] - Optionally, also scale the image by this factor.
* @param {Function} [onFinish] Optional callback for when drawing finished.
* @deprecated Use the `loadSVG` method and public `draw` method instead.
*/
fromString (svgString, scale, onFinish) {
this.loadSVG(svgString, false, () => {
this.draw(scale);
if (onFinish) onFinish();
});
}

/**
* Load an SVG from a string and measure it.
* @param {string} svgString String of SVG data to draw in quirks-mode.
Expand Down Expand Up @@ -438,25 +422,6 @@ class SvgRenderer {
this._drawFromImage(scale);
}

/**
* Asynchronously draw the (possibly non-loaded) SVG to a canvas.
* @param {number} [scale] - Optionally, also scale the image by this factor.
* @param {Function} [onFinish] - An optional callback to call when the draw operation is complete.
* @deprecated Use the `loadSVG` and public `draw` method instead.
*/
_draw (scale, onFinish) {
// Convert the SVG text to an Image, and then draw it to the canvas.
if (this._cachedImage === null) {
this._createSVGImage(() => {
this._drawFromImage(scale);
onFinish();
});
} else {
this._drawFromImage(scale);
onFinish();
}
}

/**
* Draw to the canvas from a loaded image element.
* @param {number} [scale] - Optionally, also scale the image by this factor.
Expand Down

0 comments on commit 5114796

Please sign in to comment.