mirror of
https://github.com/lxsang/antos-frontend.git
synced 2024-12-27 17:58:22 +01:00
add svg support to Preview
This commit is contained in:
parent
7133bdcbab
commit
f548c241af
@ -46,6 +46,8 @@ class Preview extends this.OS.GUI.BaseApplication
|
|||||||
return unless mime
|
return unless mime
|
||||||
if mime.match /^[^\/]+\/.*pdf.*/g
|
if mime.match /^[^\/]+\/.*pdf.*/g
|
||||||
@renderPDF file
|
@renderPDF file
|
||||||
|
else if mime.match /image\/.*svg.*/g
|
||||||
|
@renderSVG file
|
||||||
else if mime.match /image\/.*/g
|
else if mime.match /image\/.*/g
|
||||||
@renderImage file
|
@renderImage file
|
||||||
else
|
else
|
||||||
@ -90,14 +92,19 @@ class Preview extends this.OS.GUI.BaseApplication
|
|||||||
me._api.loaded q, "FAIL"
|
me._api.loaded q, "FAIL"
|
||||||
, "binary"
|
, "binary"
|
||||||
|
|
||||||
|
renderSVG: (file) ->
|
||||||
|
me = @
|
||||||
|
($ @view).attr("class", "image").empty()
|
||||||
|
file.read (d) ->
|
||||||
|
#console.log d
|
||||||
|
me.view.innerHTML = d
|
||||||
|
|
||||||
renderImage: (file) ->
|
renderImage: (file) ->
|
||||||
me = @
|
me = @
|
||||||
($ @view).attr("class", "image").empty()
|
($ @view).attr("class", "image").empty()
|
||||||
|
|
||||||
file.read (d) ->
|
file.read (d) ->
|
||||||
blob = new Blob [d], { type: file.mime }
|
|
||||||
img = new Image()
|
img = new Image()
|
||||||
img.src = URL.createObjectURL blob
|
|
||||||
canvas = ($ "<canvas/>")[0]
|
canvas = ($ "<canvas/>")[0]
|
||||||
($ me.view).append canvas
|
($ me.view).append canvas
|
||||||
|
|
||||||
@ -106,9 +113,12 @@ class Preview extends this.OS.GUI.BaseApplication
|
|||||||
context = canvas.getContext '2d'
|
context = canvas.getContext '2d'
|
||||||
canvas.height = img.height
|
canvas.height = img.height
|
||||||
canvas.width = img.width
|
canvas.width = img.width
|
||||||
console.log canvas.width, canvas.height
|
#console.log canvas.width, canvas.height
|
||||||
context.drawImage img, 0, 0
|
context.drawImage img, 0, 0
|
||||||
me.setStatus "#{file.info.name} (#{file.info.size} Kb) - #{img.width}x#{img.height}"
|
me.setStatus "#{file.info.name} (#{file.info.size} Kb) - #{img.width}x#{img.height}"
|
||||||
|
|
||||||
|
blob = new Blob [d], { type: file.info.mime }
|
||||||
|
img.src = URL.createObjectURL blob
|
||||||
, "binary"
|
, "binary"
|
||||||
|
|
||||||
menu: () ->
|
menu: () ->
|
||||||
|
Loading…
Reference in New Issue
Block a user