-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
82893e7
commit a422c7c
Showing
2 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package haxe.ui.backend.html5.loaders.image; | ||
|
||
import haxe.ui.assets.ImageInfo; | ||
import haxe.ui.loaders.image.ImageLoaderBase; | ||
import haxe.ui.util.Variant; | ||
import js.Browser; | ||
import js.html.Blob; | ||
import js.html.Image; | ||
import js.html.URL; | ||
|
||
using StringTools; | ||
|
||
class SvgImageLoader extends ImageLoaderBase { | ||
public override function load(resource:Variant, callback:ImageInfo->Void) { | ||
var image = new Image(); | ||
var svgData:String = resource.toString(); | ||
if (svgData.startsWith("svg://")) { | ||
svgData = svgData.substr("svg://".length); | ||
} | ||
var svg = new Blob([svgData], {type: "image/svg+xml;charset=utf-8"}); | ||
var url = URL.createObjectURL(svg); | ||
image.onload = function() { | ||
callback({ | ||
data:image, | ||
width: image.width, | ||
height: image.height | ||
}); | ||
} | ||
image.onerror = function(e) { | ||
trace(e); | ||
callback(null); | ||
} | ||
image.src = url; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters