From f51d7277a970dc18d7599daa59673ca5156ec69f Mon Sep 17 00:00:00 2001 From: Daniele P Date: Tue, 11 Feb 2014 13:41:44 +0100 Subject: [PATCH 1/4] Added ImageViewerPlugin, edited PluginLoader for images extensions. --- ImageViewerPlugin.js | 113 +++++++++++++++++++++++++++++++++++++++++++ PluginLoader.js | 9 ++++ 2 files changed, 122 insertions(+) create mode 100644 ImageViewerPlugin.js diff --git a/ImageViewerPlugin.js b/ImageViewerPlugin.js new file mode 100644 index 0000000..84adca9 --- /dev/null +++ b/ImageViewerPlugin.js @@ -0,0 +1,113 @@ +/** + * Created in 31/01/2014 21:22:32 + * @author Daniele P. + * + * @license http://www.gnu.org/licenses/gpl.html + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details: + * http://www.gnu.org/licenses/gpl.html + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA + * */ + +function ImageViewerPlugin() { + "use strict"; + + var self = this; + + this.initialize = function (viewerElement, documentUrl) { + var img = new Image(); + img.onload = function () { + self.setImage(img, viewerElement); + }; + // @todo Handle the error when unable to load the image. + img.src = documentUrl; + }; + + this.setImage = function (image, container) { + var domPage, image_container; + domPage = document.createElement('div'); + domPage.id = 'pageContainer1'; + domPage.className = 'page'; + image_container = document.createElement('img'); + image_container.src = image.src; + container.appendChild(domPage); + image_container.width = domPage.clientWidth; + self.image_container = image_container; + self.original_width = image.width; + self.original_height = domPage.clientHeight; + domPage.appendChild(image_container); + self.domPage = domPage; + self.setZoomLevel(image_container.width / image.width); + self.onLoad(image_container.width / image.width); + }; + + + this.isSlideshow = function () { + return false; + }; + + this.onLoad = function (zoomlevel) {}; + + this.getWidth = function () { + return self.image_container.width; + }; + + this.getHeight = function () { + return self.image_container.height; + }; + + this.fitToWidth = function (width) {}; + + this.fitToHeight = function (height) {}; + + + this.fitSmart = function (width) {}; + + this.getZoomLevel = function () { + return self.zoom; + }; + + this.setZoomLevel = function (value) { + self.zoom = value; + self.image_container.width = self.original_width * value; + if (self.image_container.width > self.domPage.clientWidth) { + self.triggerScrollBars(true); + } else { + self.triggerScrollBars(false); + } + }; + + // Sometimes happen the scrollbars get under the toolbars, we must + // find a way to prevent it, but playing with css in this way is not + // the best solution. + this.triggerScrollBars = function (enable) { + /* + if (true === enable) { + document.getElementById('toolbarContainer').style.marginBottom = '10px'; + document.getElementById('toolbarContainer').style.width = (self.domPage.clientWidth - 20) + 'px'; + } else { + document.getElementById('toolbarContainer').style.marginBottom = '0'; + document.getElementById('toolbarContainer').style.width = (self.domPage.clientWidth) + 'px'; + } + */ + }; + + + this.getPages = function () { + return []; + }; + + this.showPage = function (n) { + }; +} diff --git a/PluginLoader.js b/PluginLoader.js index 1713cda..a4cf8a3 100644 --- a/PluginLoader.js +++ b/PluginLoader.js @@ -72,7 +72,16 @@ function loadDocument(documentUrl) { Plugin = PDFViewerPlugin; }); break; + case 'jpg': + case 'jpeg': + case 'png': + case 'gif': + loadPlugin('./ImageViewerPlugin', function () { + Plugin = ImageViewerPlugin; + }); + break; } + window.onload = function () { if (Plugin) { From d0a34d58d33a2b1942718e67238203b975eb67aa Mon Sep 17 00:00:00 2001 From: Daniele P Date: Tue, 11 Feb 2014 14:39:45 +0100 Subject: [PATCH 2/4] Added ImageLoaderPlugin.js into CMakeLists.txt. --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index d4ac72d..ceabb75 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -102,6 +102,7 @@ add_custom_command( COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/PluginLoader.js ${VIEWER_BUILD_DIR}/PluginLoader.js COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/PDFViewerPlugin.js ${VIEWER_BUILD_DIR}/PDFViewerPlugin.js COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/PDFViewerPlugin.css ${VIEWER_BUILD_DIR}/PDFViewerPlugin.css + COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/ImageViewerPlugin.js ${VIEWER_BUILD_DIR}/ImageViewerPlugin.js COMMAND node ARGS ${WEBODF_SOURCE_DIR}/webodf/lib/runtime.js ${WEBODF_SOURCE_DIR}/webodf/tools/zipdir.js ${VIEWER_BUILD_DIR} ${VIEWERZIP} From b3370a5e5d2a7db69092f5ab3c59fba807366b73 Mon Sep 17 00:00:00 2001 From: Daniele P Date: Tue, 11 Feb 2014 14:48:40 +0100 Subject: [PATCH 3/4] Fixed getPluginName --- ImageViewerPlugin.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ImageViewerPlugin.js b/ImageViewerPlugin.js index 84adca9..de1d435 100644 --- a/ImageViewerPlugin.js +++ b/ImageViewerPlugin.js @@ -102,6 +102,10 @@ function ImageViewerPlugin() { } */ }; + + this.getPluginName = function () { + return "ImageViewerPlugin.js" + }; this.getPages = function () { From 645689f5624b450dfba3abb3aa9df74574cbd741 Mon Sep 17 00:00:00 2001 From: Strae Date: Mon, 17 Mar 2014 22:28:20 +0100 Subject: [PATCH 4/4] Added missing functions --- ImageViewerPlugin.js | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/ImageViewerPlugin.js b/ImageViewerPlugin.js index de1d435..d4631db 100644 --- a/ImageViewerPlugin.js +++ b/ImageViewerPlugin.js @@ -34,6 +34,23 @@ function ImageViewerPlugin() { img.src = documentUrl; }; + function loadScript(path, callback) { + var script = document.createElement('script'); + script.async = false; + script.src = path; + script.type = 'text/javascript'; + script.onload = callback || script.onload; + document.getElementsByTagName('head')[0].appendChild(script); + } + + function scrollIntoView(elem) {} + + function isScrolledIntoView(elem) {} + + function getDomPage(page) {} + + function getPageText(page) {} + this.setImage = function (image, container) { var domPage, image_container; domPage = document.createElement('div'); @@ -71,6 +88,7 @@ function ImageViewerPlugin() { this.fitToHeight = function (height) {}; + this.fitToPage = function (width, height) {}; this.fitSmart = function (width) {}; @@ -102,16 +120,31 @@ function ImageViewerPlugin() { } */ }; - + + this.onScroll = function () { + // @todo Some kind of magnify tool would be great. + return true; + }; + this.getPluginName = function () { return "ImageViewerPlugin.js" }; + this.getPluginVersion = function () { + return "From Source"; + }; + + this.getPageInView = function () { + return 1; + }; this.getPages = function () { return []; }; - this.showPage = function (n) { + this.showPage = function (n) {}; + + this.getPluginURL = function () { + return "https://github.com/mozilla/pdf.js/"; }; }