add libpdfjs library

This commit is contained in:
Xuan Sang LE 2021-02-11 14:49:19 +01:00
parent 53b23e51f7
commit 61584357c1
757 changed files with 211277 additions and 14119 deletions

View File

@ -1,11 +0,0 @@
coffee_files = main.coffee
jsfiles = pdf.js
cssfiles = main.css
copyfiles = pdf.worker.js scheme.html package.json bg.jpg
PKG_NAME=Preview
include ../pkg.mk

View File

@ -1,3 +1,6 @@
# Preview # Preview
Image and PDF file viewer for AntOS Image and PDF file viewer for AntOS
## Change logs
* v0.1.0-a: add depends on libpdfjs, user the default PDFJS viewer

View File

@ -1,3 +0,0 @@
# Preview
Image and PDF file viewer for antOS

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.5 KiB

View File

@ -1,36 +0,0 @@
afx-app-window[data-id = "preview-win"] afx-vbox[data-id="container"] div[data-id = "view"]
{
display: block;
overflow:auto;
background-image: url("bg.jpg");
background-repeat: repeat;
}
afx-app-window[data-id = "preview-win"] afx-vbox[data-id="container"] afx-hbox[data-id = "statcontainer"]
{
background-color: transparent;
border-bottom: 1px solid #cbcbcb;
}
afx-app-window[data-id = "preview-win"] afx-vbox[data-id="container"] afx-hbox[data-id = "statcontainer"] button,
afx-app-window[data-id = "preview-win"] afx-vbox[data-id="container"] afx-hbox[data-id = "statcontainer"] input
{
height: 24px;
}
afx-app-window[data-id = "preview-win"] afx-vbox[data-id="container"] canvas{
margin-left: auto;
margin-right: auto;
display: block;
}
afx-app-window[data-id = "preview-win"] afx-vbox[data-id="container"] div.pdf-page {
margin-bottom: 5px;
}
afx-app-window[data-id = "preview-win"] afx-vbox[data-id="container"] div[data-id = "view"].image
{
display: flex;
align-items: center;
justify-content: center;
}

File diff suppressed because one or more lines are too long

View File

@ -1,13 +0,0 @@
{
"app":"Preview",
"name":"Preview",
"description":"Media files viewer",
"info":{
"author": "Xuan Sang LE",
"email": "xsang.le@gmail.com"
},
"version":"0.0.7-a",
"category":"Utils",
"iconclass":"fa fa-eye",
"mimes":["[^\/]*/.*pdf", "image/.*"]
}

File diff suppressed because one or more lines are too long

View File

@ -1,17 +0,0 @@
<afx-app-window data-id = "preview-win" apptitle="Preview" width="600" height="400">
<afx-vbox data-id = "container">
<afx-hbox data-height = "25" data-id = "statcontainer" >
<div data-width = "5" ></div>
<afx-button data-width="20" iconclass="fa fa-chevron-left" data-id="btprev"></afx-button>
<input type="text" data-width="30" data-id="txtpage" />
<afx-button data-width="20" iconclass="fa fa-chevron-right" data-id="btnext"></afx-button>
<div data-width = "5" ></div>
<afx-button data-width="20" iconclass="fa fa-arrows-alt" data-id="btreset"></afx-button>
<div data-width = "5" ></div>
<afx-slider data-width="150" data-id="zoom" ></afx-slider>
<div data-id = "status" style="text-align: right;"></div>
<div data-width = "10" ></div>
</afx-hbox>
<div data-id="view" ></div>
</afx-vbox>
</afx-app-window>

Binary file not shown.

View File

@ -26,10 +26,7 @@ class Preview extends this.OS.application.BaseApplication
@view = @find "view" @view = @find "view"
@status = @find "status" @status = @find "status"
@zoom = @find "zoom" @zoom = @find "zoom"
@btnext = @find "btnext"
@btprev = @find "btprev"
@btreset = @find "btreset" @btreset = @find "btreset"
@txtpage = @find "txtpage"
@zoom.onvaluechange = (e) => @setViewScale e.data @zoom.onvaluechange = (e) => @setViewScale e.data
@ -37,24 +34,6 @@ class Preview extends this.OS.application.BaseApplication
@zoom.value = 100 @zoom.value = 100
@setViewScale 100 @setViewScale 100
@btnext.onbtclick = (e) =>
val = parseInt $(@txtpage).val()
return if isNaN val
$(@txtpage).val val + 1
@gotoPage()
@btprev.onbtclick = (e) =>
val = parseInt $(@txtpage).val()
return if isNaN val
$(@txtpage).val val - 1
@gotoPage()
$(@txtpage).keyup (e) =>
return unless e.which is 13
return unless @pdf
@gotoPage()
PDFJS.workerSrc = "#{@path()}/pdf.worker.js".asFileHandle().getlink()
@pdf = undefined
@img = undefined @img = undefined
@bindKey "ALT-O", () => @actionFile "#{@name}-Open" @bindKey "ALT-O", () => @actionFile "#{@name}-Open"
@ -74,19 +53,9 @@ class Preview extends this.OS.application.BaseApplication
@error __("File not found {0}", file.path), err @error __("File not found {0}", file.path), err
gotoPage: () ->
return unless @pdf
val = parseInt $(@txtpage).val()
return if isNaN(val)
return if val <= 0 or val > @pdf.numPages
($ @view).empty()
@renderPDFPages val, (@zoom.value / 100), false
.catch (e) => @error __("Unable to render page {0}", val), e
renderFile: () -> renderFile: () ->
mime = @currfile.info.mime mime = @currfile.info.mime
return unless mime return unless mime
@pdf = undefined
@img = undefined @img = undefined
($ @view).empty() ($ @view).empty()
@zoom.value = 100 @zoom.value = 100
@ -106,13 +75,7 @@ class Preview extends this.OS.application.BaseApplication
return unless @currfile return unless @currfile
mime = @currfile.info.mime mime = @currfile.info.mime
scale = (value / 100) scale = (value / 100)
if mime.match /^[^\/]+\/.*pdf.*/g if mime.match /image\/.*svg.*/g
return unless @pdf
($ @view).empty()
@load @renderPDFPages 1, scale
.catch (e) => @error __("Unable to set view scale"), e
else if mime.match /image\/.*svg.*/g
$($(@view).children()[0]) $($(@view).children()[0])
.css "width", "#{Math.round(value)}%" .css "width", "#{Math.round(value)}%"
.css "height", "#{Math.round(value)}%" .css "height", "#{Math.round(value)}%"
@ -129,53 +92,21 @@ class Preview extends this.OS.application.BaseApplication
context.scale scale, scale context.scale scale, scale
context.drawImage @img, 0, 0 context.drawImage @img, 0, 0
renderPDFPages: (n, scale, recursive) ->
new Promise (resolve, reject) =>
status = "#{@currfile.info.name} (#{@currfile.info.size} Kb)"
return resolve() if n > @pdf.numPages
@pdf.getPage(n).then (page) =>
viewport = page.getViewport scale
div = ($ "<div/>")
.attr("id", "page-" + (page.pageIndex + 1))
.attr("scale", scale)
.addClass "pdf-page"
($ @view).append div
canvas = ($ "<canvas>")[0]
div.append canvas
context = canvas.getContext '2d'
canvas.height = viewport.height
canvas.width = viewport.width
renderContext =
canvasContext: context
viewport: viewport
page.render renderContext
page._canvas = canvas
@setStatus "#{status} - page #{n}/#{@pdf.numPages} loaded"
if recursive
@renderPDFPages n + 1, scale, recursive
.then () -> resolve()
.catch (e) -> reject __e e
else
resolve()
.catch (e) -> reject __e e
renderPDF: () -> renderPDF: () ->
@load new Promise (resolve, reject) => $(@find("statcontainer")).hide()
@currfile.read("binary").then (d) => @trigger "resize"
($ @view).removeClass() ($ @view).attr("class", "pdf")
PDFJS.getDocument { data: d } frame = ($ "<iframe/>")
.then (pdf) => .css "width", "100%"
@pdf = pdf .css "height", "100%"
@renderPDFPages 1, 1, false ($ @view).append frame[0]
.then () => frame[0].src = "pkg://libpdfjs/web/viewer.html".asFileHandle().getlink() + "?file=" + @currfile.getlink()
$(@txtpage).val("1")
resolve()
.catch (e) -> reject __e e
.catch (e) -> reject __e e
.catch (e) -> reject __e e
.catch (e) => @error __("Unable to view file: {0}", @currfile.path), e
renderSVG: () -> renderSVG: () ->
$(@find("statcontainer")).show()
@trigger "resize"
($ @view).attr("class", "image") ($ @view).attr("class", "image")
@currfile.read().then (d) => @currfile.read().then (d) =>
@view.innerHTML = d @view.innerHTML = d
@ -185,6 +116,8 @@ class Preview extends this.OS.application.BaseApplication
.catch (e) => @error __("Unable to read file: {0}", @currfile.path), e .catch (e) => @error __("Unable to read file: {0}", @currfile.path), e
renderImage: () -> renderImage: () ->
$(@find("statcontainer")).show()
@trigger "resize"
($ @view).attr("class", "image") ($ @view).attr("class", "image")
@currfile.read("binary").then (d) => @currfile.read("binary").then (d) =>

View File

@ -33,3 +33,7 @@ afx-app-window[data-id = "preview-win"] afx-vbox[data-id="container"] div[data-i
align-items: center; align-items: center;
justify-content: center; justify-content: center;
} }
afx-app-window[data-id = "preview-win"] afx-vbox[data-id="container"] div[data-id = "view"].pdf
{
overflow: hidden;
}

View File

@ -6,8 +6,9 @@
"author": "Xuan Sang LE", "author": "Xuan Sang LE",
"email": "xsang.le@gmail.com" "email": "xsang.le@gmail.com"
}, },
"version":"0.0.7-a", "version":"0.1.0-a",
"category":"Utils", "category":"Utils",
"iconclass":"fa fa-eye", "iconclass":"fa fa-eye",
"mimes":["[^\/]*/.*pdf", "image/.*"] "mimes":["[^\/]*/.*pdf", "image/.*"],
"dependencies": ["libpdfjs@2.6.347-r"]
} }

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -1,7 +1,7 @@
{ {
"name": "Preview", "name": "Preview",
"css": ["main.css"], "css": ["main.css"],
"javascripts": ["pdf.js"], "javascripts": [],
"coffees": ["main.coffee"], "coffees": ["main.coffee"],
"copies": ["pdf.worker.js","scheme.html", "package.json", "README.md", "bg.jpg"] "copies": ["scheme.html", "package.json", "README.md", "bg.jpg"]
} }

View File

@ -1,10 +1,7 @@
<afx-app-window data-id = "preview-win" apptitle="Preview" width="600" height="400"> <afx-app-window data-id = "preview-win" apptitle="Preview" width="600" height="400">
<afx-vbox data-id = "container"> <afx-vbox data-id = "container">
<div data-id="view" ></div>
<afx-hbox data-height = "25" data-id = "statcontainer" > <afx-hbox data-height = "25" data-id = "statcontainer" >
<div data-width = "5" ></div>
<afx-button data-width="20" iconclass="fa fa-chevron-left" data-id="btprev"></afx-button>
<input type="text" data-width="30" data-id="txtpage" />
<afx-button data-width="20" iconclass="fa fa-chevron-right" data-id="btnext"></afx-button>
<div data-width = "5" ></div> <div data-width = "5" ></div>
<afx-button data-width="20" iconclass="fa fa-arrows-alt" data-id="btreset"></afx-button> <afx-button data-width="20" iconclass="fa fa-arrows-alt" data-id="btreset"></afx-button>
<div data-width = "5" ></div> <div data-width = "5" ></div>
@ -12,6 +9,5 @@
<div data-id = "status" style="text-align: right;"></div> <div data-id = "status" style="text-align: right;"></div>
<div data-width = "10" ></div> <div data-width = "10" ></div>
</afx-hbox> </afx-hbox>
<div data-id="view" ></div>
</afx-vbox> </afx-vbox>
</afx-app-window> </afx-app-window>

11
libpdfjs/README.md Normal file
View File

@ -0,0 +1,11 @@
# PDF.js [![Build Status](https://github.com/mozilla/pdf.js/workflows/CI/badge.svg?branch=master)](https://github.com/mozilla/pdf.js/actions?query=workflow%3ACI+branch%3Amaster)
[PDF.js](https://mozilla.github.io/pdf.js/) is a Portable Document Format (PDF) viewer that is built with HTML5.
PDF.js is community-driven and supported by Mozilla. Our goal is to
create a general-purpose, web standards-based platform for parsing and
rendering PDFs.
This is a AntOS package wrapper for PDFJS that can be used by another AntOS package, it includes the
library and the default pdf viewer

View File

@ -0,0 +1,11 @@
# PDF.js [![Build Status](https://github.com/mozilla/pdf.js/workflows/CI/badge.svg?branch=master)](https://github.com/mozilla/pdf.js/actions?query=workflow%3ACI+branch%3Amaster)
[PDF.js](https://mozilla.github.io/pdf.js/) is a Portable Document Format (PDF) viewer that is built with HTML5.
PDF.js is community-driven and supported by Mozilla. Our goal is to
create a general-purpose, web standards-based platform for parsing and
rendering PDFs.
This is a AntOS package wrapper for PDFJS that can be used by another AntOS package, it includes the
library and the default pdf viewer

View File

@ -0,0 +1 @@
(function(){}).call(this);

View File

@ -0,0 +1,15 @@
{
"pkgname": "libpdfjs",
"name":"PDF JS library",
"description":"AntOS wrapper for PDF JS",
"info":{
"author": "Xuan Sang LE",
"email": "mrsang@iohub.dev"
},
"version":"2.6.347-r",
"category":"Library",
"iconclass":"fa fa-cog",
"mimes":["none"],
"dependencies":[],
"locale": {}
}

14140
libpdfjs/build/debug/pdf.js Normal file

File diff suppressed because it is too large Load Diff

47638
libpdfjs/build/debug/pdf.worker.js vendored Normal file

File diff suppressed because it is too large Load Diff

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,3 @@
àRCopyright 1990-2009 Adobe Systems Incorporated.
All rights reserved.
See ./LICENSEáCNS2-H

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,3 @@
àRCopyright 1990-2009 Adobe Systems Incorporated.
All rights reserved.
See ./LICENSEá ETen-B5-H` ^

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,4 @@
àRCopyright 1990-2009 Adobe Systems Incorporated.
All rights reserved.
See ./LICENSE!!<21>º]aX!!]`<60>21<32>> <09>p <0B>z<EFBFBD>$]<06>"Rd<E2809A>-Uƒ7<C692>*4„%<25>+ „Z „{<7B>/%…<<3C>9K…b<E280A6>1]†.<2E>" ‰`]‡,<2C>"]ˆ
<EFBFBD>"]ˆh<CB86>"]‰F<E280B0>"]Š$<24>"]<02>"]`<60>"]Œ><3E>"]<5D><1C>"]<5D>z<EFBFBD>"]ŽX<C5BD>"]<5D>6<EFBFBD>"]<5D><14>"]<5D>r<EFBFBD>"]P<E28098>"].<2E>"]“ <0C>"]“j<E2809C>"]”H<E2809D>"]•&<26>"]<04>"]b<E28093>"]—@<40>"]˜<1E>"]˜|<7C>"]™Z<E284A2>"]š8<C5A1>"]<16>"]t<E280BA>"]œR<C593>"]<5D>0<EFBFBD>"]ž<0E>"]žl<C5BE>"]ŸJ<C5B8>"] (<28>"]¡<06>"]¡d<C2A1>"]¢B<C2A2>"]£ <20>"X£~<7E>']¤W<C2A4>"]¥5<C2A5>"]¦<13>"]¦q<C2A6>"]§O<C2A7>"]¨-<2D>"]© <0B>"]©i<C2A9>"]ªG<C2AA>"]«%<25>"]¬<03>"]¬a<C2AC>"]­?<3F>"]®<1D>"]®{<7B>"]¯Y<C2AF>"]°7<C2B0>"]±<15>"]±s<C2B1>"]²Q<C2B2>"]³/<2F>"]´ <0A>"]´k<C2B4>"]µI<C2B5>"]¶'<27>"]·<05>"]·c<C2B7>"]¸A<C2B8>"]¹<1F>"]¹}<7D>"]º[<5B>"]»9

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Some files were not shown because too many files have changed in this diff Show More