diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 04eb33d..a87a355 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,4 +1,4 @@ -import { decomposeDataUri, uid } from '@pixi/utils'; +import { uid } from '@pixi/utils'; import BaseImageResource from './BaseImageResource'; /** @@ -41,6 +41,13 @@ this._resolve = null; /** + * Cross origin value to use + * @private + * @member {boolean|string} + */ + this._crossorigin = options.crossorigin; + + /** * Promise when loading * @member {Promise} * @private @@ -73,112 +80,35 @@ // Convert SVG inline string to data-uri if ((/^\ - { - if (svgXhr.readyState !== svgXhr.DONE || svgXhr.status !== 200) - { - throw new Error('Failed to load SVG using XHR.'); - } - - this._loadString(svgXhr.response); - }; - - // svgXhr.onerror = () => this.emit('error', this); - - svgXhr.open('GET', this.svg, true); - svgXhr.send(); - } - - /** - * Loads texture using an SVG string. The original SVG Image is stored as `origSource` and the - * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by - * `_loadXhr` or `_loadDataUri`. - * - * @private - * @param {string} svgString SVG source as string - * - * @fires loaded - */ - _loadString(svgString) - { - const svgSize = SVGResource.getSize(svgString); - const tempImage = new Image(); - tempImage.src = `data:image/svg+xml,${svgString}`; - - tempImage.onerror = () => - { - throw new Error(`Unable to load image from: ${tempImage.src}`); - }; + BaseImageResource.crossOrigin(tempImage, this.svg, this._crossorigin); + tempImage.src = this.svg; tempImage.onload = () => { - const svgWidth = svgSize.width; - const svgHeight = svgSize.height; + const svgWidth = tempImage.width; + const svgHeight = tempImage.height; if (!svgWidth || !svgHeight) { @@ -244,6 +174,7 @@ { super.dispose(); this._resolve = null; + this._crossorigin = null; } /** @@ -258,7 +189,9 @@ // url file extension is SVG return extension === 'svg' // source is SVG data-uri - || (typeof source === 'string' && source.indexOf('data:image/svg+xml') === 0); + || (typeof source === 'string' && source.indexOf('data:image/svg+xml;base64') === 0) + // source is SVG inline + || (typeof source === 'string' && source.indexOf('