diff options
author | Pacien TRAN-GIRARD | 2014-08-10 17:28:37 +0200 |
---|---|---|
committer | Pacien TRAN-GIRARD | 2014-08-10 17:28:37 +0200 |
commit | e7bf5952d0729b37e677168b6e8fbd1ce58ed1a2 (patch) | |
tree | 189988e3e272b806262d1df6b87f1da089ef4af8 /point/data | |
parent | a32e898c8d7ad3774f5654e88bb24d5c26482137 (diff) | |
download | whatsthepoint-master.tar.gz |
Diffstat (limited to 'point/data')
-rw-r--r-- | point/data/html.js | 86 | ||||
-rw-r--r-- | point/data/markdown.js | 61 | ||||
-rw-r--r-- | point/data/pdf.js | 130 | ||||
-rw-r--r-- | point/data/renderSlide.js | 127 |
4 files changed, 404 insertions, 0 deletions
diff --git a/point/data/html.js b/point/data/html.js new file mode 100644 index 0000000..66448cc --- /dev/null +++ b/point/data/html.js | |||
@@ -0,0 +1,86 @@ | |||
1 | /* | ||
2 | * This file is part of "What's The Point" <https://github.com/Pacien/WhatsThePoint> | ||
3 | * Copyright (C) 2014 Pacien TRAN-GIRARD | ||
4 | * | ||
5 | * "What's The Point" is free software: you can redistribute it and/or modify | ||
6 | * it under the terms of the GNU Affero General Public License as | ||
7 | * published by the Free Software Foundation, either version 3 of the | ||
8 | * License, or (at your option) any later version. | ||
9 | * | ||
10 | * "What's The Point" is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU Affero General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU Affero General Public License | ||
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | */ | ||
18 | |||
19 | define(function () { | ||
20 | |||
21 | var xml = { | ||
22 | |||
23 | init: function () { | ||
24 | return; | ||
25 | }, | ||
26 | |||
27 | getProp: function (object, dom, property, method) { | ||
28 | var elements = dom.getElementsByTagName(property); | ||
29 | if (elements.length > 0) { | ||
30 | object[property] = method(elements[0]); | ||
31 | } | ||
32 | return object; | ||
33 | }, | ||
34 | |||
35 | getInnerText: function (object, dom, property) { | ||
36 | return this.getProp(object, dom, property, function (element) { | ||
37 | return element.textContent; | ||
38 | }); | ||
39 | }, | ||
40 | |||
41 | getInnerHtml: function (object, dom, property) { | ||
42 | return this.getProp(object, dom, property, function (element) { | ||
43 | if (window.XMLSerializer !== undefined) { | ||
44 | return (new window.XMLSerializer()).serializeToString(element); | ||
45 | } else if (element.xml !== undefined) { | ||
46 | return element.xml; | ||
47 | } | ||
48 | return element.innerHTML; | ||
49 | }); | ||
50 | }, | ||
51 | |||
52 | parseSlide: function (domSlide) { | ||
53 | var slide = {}; | ||
54 | |||
55 | ["type", "title", "subtitle"].forEach(function (tag) { | ||
56 | xml.getInnerText(slide, domSlide, tag); | ||
57 | }); | ||
58 | |||
59 | ["content", "notes"].forEach(function (tag) { | ||
60 | xml.getInnerHtml(slide, domSlide, tag); | ||
61 | }); | ||
62 | |||
63 | return slide; | ||
64 | }, | ||
65 | |||
66 | parseSlides: function (domSlides) { | ||
67 | var slides = []; | ||
68 | |||
69 | for (var i = 0; i < domSlides.length; i++) { | ||
70 | slides.push(this.parseSlide(domSlides[i])); | ||
71 | } | ||
72 | |||
73 | return slides; | ||
74 | }, | ||
75 | |||
76 | parse: function (rawData, callback) { | ||
77 | var dom = new DOMParser().parseFromString(rawData, "text/xml"); | ||
78 | var domSlides = dom.getElementsByTagName("slide"); | ||
79 | |||
80 | callback(this.parseSlides(domSlides)); | ||
81 | }, | ||
82 | }; | ||
83 | |||
84 | return xml; | ||
85 | |||
86 | }); | ||
diff --git a/point/data/markdown.js b/point/data/markdown.js new file mode 100644 index 0000000..38a564d --- /dev/null +++ b/point/data/markdown.js | |||
@@ -0,0 +1,61 @@ | |||
1 | /* | ||
2 | * This file is part of "What's The Point" <https://github.com/Pacien/WhatsThePoint> | ||
3 | * Copyright (C) 2014 Pacien TRAN-GIRARD | ||
4 | * | ||
5 | * "What's The Point" is free software: you can redistribute it and/or modify | ||
6 | * it under the terms of the GNU Affero General Public License as | ||
7 | * published by the Free Software Foundation, either version 3 of the | ||
8 | * License, or (at your option) any later version. | ||
9 | * | ||
10 | * "What's The Point" is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU Affero General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU Affero General Public License | ||
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | */ | ||
18 | |||
19 | requirejs.config({ | ||
20 | shim: { | ||
21 | "markdownjs": { | ||
22 | exports: "markdown", | ||
23 | }, | ||
24 | }, | ||
25 | paths: { | ||
26 | "markdownjs": "libs/markdownjs/markdown.min", | ||
27 | }, | ||
28 | }); | ||
29 | |||
30 | define(["js-yaml", "markdownjs"], function (jsyaml, markdownjs) { | ||
31 | |||
32 | var markdown = { | ||
33 | |||
34 | init: function () { | ||
35 | return; | ||
36 | }, | ||
37 | |||
38 | renderSlide: function (slide) { | ||
39 | if (slide.content !== undefined) { | ||
40 | slide.content = markdownjs.toHTML(slide.content); | ||
41 | } | ||
42 | if (slide.notes !== undefined) { | ||
43 | slide.notes = markdownjs.toHTML(slide.notes); | ||
44 | } | ||
45 | return slide; | ||
46 | }, | ||
47 | |||
48 | parse: function (rawData, callback) { | ||
49 | var slides = []; | ||
50 | |||
51 | jsyaml.safeLoadAll(rawData, function (slide) { | ||
52 | slides.push(markdown.renderSlide(slide)); | ||
53 | }); | ||
54 | |||
55 | callback(slides); | ||
56 | }, | ||
57 | }; | ||
58 | |||
59 | return markdown; | ||
60 | |||
61 | }); | ||
diff --git a/point/data/pdf.js b/point/data/pdf.js new file mode 100644 index 0000000..f789bdf --- /dev/null +++ b/point/data/pdf.js | |||
@@ -0,0 +1,130 @@ | |||
1 | /* | ||
2 | * This file is part of "What's The Point" <https://github.com/Pacien/WhatsThePoint> | ||
3 | * Copyright (C) 2014 Pacien TRAN-GIRARD | ||
4 | * | ||
5 | * "What's The Point" is free software: you can redistribute it and/or modify | ||
6 | * it under the terms of the GNU Affero General Public License as | ||
7 | * published by the Free Software Foundation, either version 3 of the | ||
8 | * License, or (at your option) any later version. | ||
9 | * | ||
10 | * "What's The Point" is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU Affero General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU Affero General Public License | ||
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | */ | ||
18 | |||
19 | requirejs.config({ | ||
20 | shim: { | ||
21 | "pdfjs": { | ||
22 | exports: "PDFJS", | ||
23 | }, | ||
24 | }, | ||
25 | paths: { | ||
26 | "pdfjs": "libs/pdfjs/pdf", | ||
27 | }, | ||
28 | }); | ||
29 | |||
30 | define(["pdfjs"], function (pdfjs) { | ||
31 | |||
32 | var pdf = { | ||
33 | |||
34 | init: function (settings) { | ||
35 | this.fileUrl = settings.data.file; | ||
36 | this.width = settings.dimension.width; | ||
37 | this.height = settings.dimension.height; | ||
38 | |||
39 | this.slides = []; | ||
40 | |||
41 | pdfjs.disableRange = true; | ||
42 | pdfjs.workerSrc = "point/libs/pdfjs/pdf.worker.js"; | ||
43 | }, | ||
44 | |||
45 | makeCanvas: function () { | ||
46 | var canvas = document.createElement("canvas"); | ||
47 | canvas.width = pdf.width; | ||
48 | canvas.height = pdf.height; | ||
49 | return canvas; | ||
50 | }, | ||
51 | |||
52 | clearOutline: function (context, slideWidth, slideHeight, offsetX, offsetY) { | ||
53 | context.clearRect(0, 0, offsetX, pdf.height); | ||
54 | context.clearRect(offsetX + slideWidth, 0, offsetX, pdf.height); | ||
55 | context.clearRect(0, 0, pdf.width, offsetY); | ||
56 | context.clearRect(0, offsetY + slideHeight, pdf.width, offsetY); | ||
57 | return context; | ||
58 | }, | ||
59 | |||
60 | renderSlide: function (pdfDocument, slideIndex, callback) { | ||
61 | pdfDocument.getPage(slideIndex).then(function (pdfPage) { | ||
62 | |||
63 | var viewport = pdfPage.getViewport(1); | ||
64 | var slideWidth = viewport.width / 2; | ||
65 | var slideHeight = viewport.height; | ||
66 | |||
67 | var widthRatio = pdf.width / slideWidth; | ||
68 | var heightRatio = pdf.height / slideHeight; | ||
69 | var scale = Math.min(widthRatio, heightRatio); | ||
70 | slideWidth *= scale; | ||
71 | slideHeight *= scale; | ||
72 | |||
73 | var offsetX = (pdf.width - slideWidth) / 2; | ||
74 | var offsetY = (pdf.height - slideHeight) / 2; | ||
75 | |||
76 | var contentViewport = new pdfjs.PageViewport(pdfPage.view, scale, 0, offsetX, offsetY); | ||
77 | var notesViewport = new pdfjs.PageViewport(pdfPage.view, scale, 0, -slideWidth + offsetX, offsetY); | ||
78 | |||
79 | var contentCanvas = pdf.makeCanvas(); | ||
80 | var contentContext = contentCanvas.getContext("2d"); | ||
81 | |||
82 | var notesCanvas = pdf.makeCanvas(); | ||
83 | var notesContext = notesCanvas.getContext("2d"); | ||
84 | |||