|
| ";
+ echo " | ";
+ echo "t("CardDav Link") . "\" class=\"action\"> | t("Download") . "\" class=\"action\"> | t("Edit") . "\" class=\"action\" onclick=\"Contacts.UI.Addressbooks.editAddressbook(this, " . $_['addressbook']["id"] . ");\"> | t("Delete") . "\" class=\"action\"> | ";
diff --git a/apps/contacts/templates/part.contacts.php b/apps/contacts/templates/part.contacts.php
index 6664a3671ac..8d89e9c7ad1 100644
--- a/apps/contacts/templates/part.contacts.php
+++ b/apps/contacts/templates/part.contacts.php
@@ -1,3 +1,3 @@
-
+
diff --git a/apps/contacts/templates/part.editaddressbook.php b/apps/contacts/templates/part.editaddressbook.php
new file mode 100644
index 00000000000..cb1371731b1
--- /dev/null
+++ b/apps/contacts/templates/part.editaddressbook.php
@@ -0,0 +1,31 @@
+
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+?>
+t("Edit Address Book"); ?>" colspan="6">
+
+);" value="t("Save") : $l->t("Submit"); ?>">
+);" value="t("Cancel"); ?>">
+ |
diff --git a/apps/contacts/templates/part.property.php b/apps/contacts/templates/part.property.php
index 6264f296743..d930a9ca99d 100644
--- a/apps/contacts/templates/part.property.php
+++ b/apps/contacts/templates/part.property.php
@@ -20,7 +20,7 @@
- t('Preferred').' ' : '' ?>t('Phone'); ?>
+ t('Preferred').' ' : '' ?>t('Phone'); ?>
diff --git a/apps/contacts/thumbnail.php b/apps/contacts/thumbnail.php
new file mode 100644
index 00000000000..bf0a6e96a5d
--- /dev/null
+++ b/apps/contacts/thumbnail.php
@@ -0,0 +1,150 @@
+.
+ *
+ */
+
+// Init owncloud
+require_once('../../lib/base.php');
+OC_Util::checkLoggedIn();
+OC_Util::checkAppEnabled('contacts');
+
+if(!function_exists('imagecreatefromjpeg')) {
+ OC_Log::write('contacts','GD module not installed',OC_Log::ERROR);
+ header('Content-Type: image/png');
+ // TODO: Check if it works to read the file and echo the content.
+ return 'img/person.png';
+}
+
+function getStandardImage(){
+ $src_img = imagecreatefrompng('img/person.png');
+ header('Content-Type: image/png');
+ imagepng($src_img);
+ imagedestroy($src_img);
+}
+
+
+$id = $_GET['id'];
+
+$l10n = new OC_L10N('contacts');
+
+$card = OC_Contacts_VCard::find( $id );
+if( $card === false ){
+ echo $l10n->t('Contact could not be found.');
+ exit();
+}
+
+$addressbook = OC_Contacts_Addressbook::find( $card['addressbookid'] );
+if( $addressbook === false || $addressbook['userid'] != OC_USER::getUser()){
+ echo $l10n->t('This is not your contact.'); // This is a weird error, why would it come up? (Better feedback for users?)
+ exit();
+}
+
+$content = OC_VObject::parse($card['carddata']);
+
+// invalid vcard
+if( is_null($content)){
+ echo $l10n->t('This card is not RFC compatible.');
+ exit();
+}
+
+// define the width and height for the thumbnail
+// note that theese dimmensions are considered the maximum dimmension and are not fixed,
+// because we have to keep the image ratio intact or it will be deformed
+$thumbnail_width = 23;
+$thumbnail_height = 23;
+
+// Photo :-)
+foreach($content->children as $child){
+ if($child->name == 'PHOTO'){
+ foreach($child->parameters as $parameter){
+ if( $parameter->name == 'TYPE' ){
+ $mime = $parameter->value;
+ }
+ }
+ $data = base64_decode($child->value);
+ $src_img = imagecreatefromstring($data);
+ if ($src_img !== false) {
+ //gets the dimmensions of the image
+ $width_orig=imageSX($src_img);
+ $height_orig=imageSY($src_img);
+ $ratio_orig = $width_orig/$height_orig;
+
+ if ($thumbnail_width/$thumbnail_height > $ratio_orig) {
+ $new_height = $thumbnail_width/$ratio_orig;
+ $new_width = $thumbnail_width;
+ } else {
+ $new_width = $thumbnail_height*$ratio_orig;
+ $new_height = $thumbnail_height;
+ }
+
+ $x_mid = $new_width/2; //horizontal middle
+ $y_mid = $new_height/2; //vertical middle
+
+ $process = imagecreatetruecolor(round($new_width), round($new_height));
+ if ($process == false) {
+ getStandardImage();
+ //echo 'Error creating process image: '.$new_width.'x'.$new_height;
+ OC_Log::write('contacts','Error creating process image for '.$id.' '.$new_width.'x'.$new_height,OC_Log::ERROR);
+ imagedestroy($process);
+ imagedestroy($src_img);
+ exit();
+ }
+
+ imagecopyresampled($process, $src_img, 0, 0, 0, 0, $new_width, $new_height, $width_orig, $height_orig);
+ if ($process == false) {
+ getStandardImage();
+ //echo 'Error resampling process image: '.$new_width.'x'.$new_height;
+ OC_Log::write('contacts','Error resampling process image for '.$id.' '.$new_width.'x'.$new_height,OC_Log::ERROR);
+ imagedestroy($process);
+ imagedestroy($src_img);
+ exit();
+ }
+ $thumb = imagecreatetruecolor($thumbnail_width, $thumbnail_height);
+ if ($process == false) {
+ getStandardImage();
+ //echo 'Error creating thumb image: '.$thumbnail_width.'x'.$thumbnail_height;
+ OC_Log::write('contacts','Error creating thumb image for '.$id.' '.$thumbnail_width.'x'.$thumbnail_height,OC_Log::ERROR);
+ imagedestroy($process);
+ imagedestroy($src_img);
+ exit();
+ }
+ imagecopyresampled($thumb, $process, 0, 0, ($x_mid-($thumbnail_width/2)), ($y_mid-($thumbnail_height/2)), $thumbnail_width, $thumbnail_height, $thumbnail_width, $thumbnail_height);
+ if ($thumb !== false) {
+ header('Content-Type: image/png');
+ imagepng($thumb);
+ } else {
+ getStandardImage();
+ OC_Log::write('contacts','Error resampling thumb image for '.$id.' '.$thumbnail_width.'x'.$thumbnail_height,OC_Log::ERROR);
+ //echo 'An error occurred resampling thumb.';
+ }
+ imagedestroy($thumb);
+ imagedestroy($process);
+ imagedestroy($src_img);
+ }
+ else {
+ getStandardImage();
+ }
+ exit();
+ }
+}
+getStandardImage();
+
+// Not found :-(
+//echo $l10n->t('This card does not contain a photo.');
diff --git a/apps/files_pdfviewer/appinfo/app.php b/apps/files_pdfviewer/appinfo/app.php
new file mode 100755
index 00000000000..a446b4caa41
--- /dev/null
+++ b/apps/files_pdfviewer/appinfo/app.php
@@ -0,0 +1,9 @@
+
diff --git a/apps/files_pdfviewer/appinfo/info.xml b/apps/files_pdfviewer/appinfo/info.xml
new file mode 100755
index 00000000000..86a6c3f22f7
--- /dev/null
+++ b/apps/files_pdfviewer/appinfo/info.xml
@@ -0,0 +1,10 @@
+
+
+ files_pdfviewer
+ PDF viewer (pdfjs-based)
+ 0.1
+ GPL
+ Joan Creus
+ 2
+
+
diff --git a/apps/files_pdfviewer/css/history.png b/apps/files_pdfviewer/css/history.png
new file mode 100755
index 00000000000..afa0e4ab70f
Binary files /dev/null and b/apps/files_pdfviewer/css/history.png differ
diff --git a/apps/files_pdfviewer/css/style.css b/apps/files_pdfviewer/css/style.css
new file mode 100755
index 00000000000..9ad6eeaa814
--- /dev/null
+++ b/apps/files_pdfviewer/css/style.css
@@ -0,0 +1,27 @@
+#editor{
+ position: absoloute;
+ display: block;
+ top: 80px;
+ left: 160px;
+}
+#editorwrapper{
+ position: absoloute;
+ height: 0;
+ width: 0;
+ top: 41px;
+ left: 160px;
+ display: none;
+}
+#editor_close{
+ margin-left: auto;
+ margin-right: 167px;
+ display: block;
+}
+#editor_save{
+ margin-left: 7px;
+ float: left;
+}
+#saving_icon{
+ margin-top: 3px;
+ float: left;
+}
\ No newline at end of file
diff --git a/apps/files_pdfviewer/css/viewer.css b/apps/files_pdfviewer/css/viewer.css
new file mode 100755
index 00000000000..cbab9e70dc2
--- /dev/null
+++ b/apps/files_pdfviewer/css/viewer.css
@@ -0,0 +1,277 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- /
+/* vim: set shiftwidth=4 tabstop=8 autoindent cindent expandtab: */
+
+#viewer {
+ background-color: #929292;
+ font-family: 'Lucida Grande', 'Lucida Sans Unicode', Helvetica, Arial, Verdana, sans-serif;
+ /*margin: 0px;*/
+ padding: 0px;
+ /*position:absolute;*/
+}
+
+[hidden] {
+ display: none;
+}
+
+.separator {
+ display: inline;
+ border-left: 1px solid #d3d3d3;
+ border-right: 1px solid #fff;
+ height: 10px;
+ width:0px;
+ margin: 4px;
+}
+
+#controls2 > a > img {
+ margin: 4px;
+ height: 10px;
+}
+
+#controls2 > button {
+ line-height: 10px;
+}
+
+#controls2 > button > img {
+ width: 10px;
+ height: 10px;
+}
+
+#controls2 > button[disabled] > img {
+ opacity: 0.5;
+}
+
+#pageNumber {
+ text-align: right;
+}
+
+span#info {
+ display: none;
+}
+
+@-moz-document regexp("http:.*debug=1.*") {
+ span#info {
+ display: inline-block;
+ }
+}
+
+/* === Sidebar === */
+#sidebar {
+ position: fixed;
+ width: 350px;
+ top: 62px;
+ bottom: 18px;
+ left: -290px;
+ transition: left 0.25s ease-in-out 1s;
+ -moz-transition: left 0.25s ease-in-out 1s;
+ -webkit-transition: left 0.25s ease-in-out 1s;
+ z-index: 1;
+}
+
+#sidebar:hover {
+ left: 0px;
+ transition: left 0.25s ease-in-out 0s;
+ -moz-transition: left 0.25s ease-in-out 0s;
+ -webkit-transition: left 0.25s ease-in-out 0s;
+}
+
+#sidebarBox {
+ background-color: rgba(0, 0, 0, 0.7);
+ width: 300px;
+ height: 100%;
+ border-top-right-radius: 8px;
+ border-bottom-right-radius: 8px;
+ -moz-border-radius-topright: 8px;
+ -moz-border-radius-bottomright: 8px;
+ -webkit-border-top-right-radius: 8px;
+ -webkit-border-bottom-right-radius: 8px;
+ box-shadow: 0px 2px 8px #000;
+ -moz-box-shadow: 0px 2px 8px #000;
+ -webkit-box-shadow: 0px 2px 8px #000;
+}
+
+#sidebarScrollView {
+ position: absolute;
+ overflow: hidden;
+ overflow-y: auto;
+ top: 10px;
+ bottom: 10px;
+ left: 10px;
+ width: 280px;
+}
+
+.thumbnail {
+ width: 134px;
+ height: 134px;
+ margin-top: 5px;
+ margin-bottom: 5px;
+ margin-left:auto;
+ margin-right:auto;
+ line-height: 134px;
+ text-align: center;
+ overflow: hidden;
+}
+
+.thumbnail:not([data-loaded]) {
+ background-color: gray;
+}
+
+.thumbnail > canvas {
+ vertical-align: middle;
+ display: inline-block;
+}
+
+#outlineScrollView {
+ position: absolute;
+ background-color: #fff;
+ overflow: auto;
+ top: 10px;
+ bottom: 10px;
+ left: 10px;
+ width: 280px;
+}
+
+#outlineView {
+ padding-top: 4px;
+ padding-bottom: 100px;
+ padding-left: 6px;
+ padding-right: 6px;
+ font-size: smaller;
+}
+
+.outlineItem > .outlineItems {
+ margin-left: 20px;
+}
+
+.outlineItem > a {
+ text-decoration: none;
+ color: black;
+}
+
+.outlineItem > a:hover {
+ background: #ff0;
+ box-shadow: 0px 2px 10px #ff0;
+}
+
+#sidebarControls {
+ position:absolute;
+ width: 120px;
+ height: 32px;
+ left: 15px;
+ bottom: 35px;
+}
+
+#sidebarControls > button {
+ box-shadow: 0px 4px 10px #000;
+ -moz-box-shadow: 0px 4px 10px #000;
+ -webkit-box-shadow: 0px 4px 10px #000;
+}
+
+#sidebarControls > button > img {
+ width: 32px;
+ height: 32px;
+}
+
+#sidebarControls > button[disabled] > img {
+ opacity: 0.5;
+}
+
+#sidebarControls > button[data-selected] {
+ box-shadow: 0px 4px 10px #ff0;
+ -moz-box-shadow: 0px 4px 10px #ff0;
+ -webkit-box-shadow: 0px 4px 10px #ff0;
+}
+
+/* === Content view === */
+canvas {
+ margin: auto;
+ display: block;
+}
+
+.page {
+ width: 816px;
+ height: 1056px;
+ margin: 10px auto;
+ position: relative;
+ overflow: hidden;
+ box-shadow: 0px 4px 10px #000;
+ -moz-box-shadow: 0px 4px 10px #000;
+ -webkit-box-shadow: 0px 4px 10px #000;
+ background-color: white;
+}
+
+.page > a {
+ display: block;
+ position: absolute;
+}
+
+.page > a:hover {
+ opacity: 0.2;
+ background: #ff0;
+ box-shadow: 0px 2px 10px #ff0;
+ -moz-box-shadow: 0px 2px 10px #ff0;
+ -webkit-box-shadow: 0px 2px 10px #ff0;
+}
+
+#viewer {
+ /*overflow:auto;*/
+ margin: 6.3em 0 0 0;
+ margin-right:12.5em;
+ padding: 8px 0px;
+ position:static;
+ height:100%;
+ width:100%;
+ text-align:center;
+}
+
+#sidebarView canvas:hover {
+ background: #ff0;
+ box-shadow: 0px 2px 10px #ff0;
+ -moz-box-shadow: 0px 2px 10px #ff0;
+ -webkit-box-shadow: 0px 2px 10px #ff0;
+}
+
+#pageWidthOption {
+ border-top: 1px solid black;
+}
+
+#customScaleOption {
+ display: none;
+}
+
+/* === Printed media overrides === */
+@media print {
+ #sidebar {
+ display: none;
+ }
+
+ #controls2 {
+ display: none;
+ }
+
+ #viewer {
+ margin: 0;
+ padding: 0;
+ }
+
+ .page {
+ display: none;
+ margin: 0;
+ }
+
+ .page canvas {
+ box-shadow: none;
+ -moz-box-shadow: none;
+ -webkit-box-shadow: none;
+ }
+
+ .page[data-loaded] {
+ display: block;
+ page-break-after: always;
+ }
+}
+
+#loading {
+ margin: 100px 0;
+ text-align: center;
+}
+
diff --git a/apps/files_pdfviewer/js/pdfjs/LICENSE b/apps/files_pdfviewer/js/pdfjs/LICENSE
new file mode 100755
index 00000000000..f8a84820570
--- /dev/null
+++ b/apps/files_pdfviewer/js/pdfjs/LICENSE
@@ -0,0 +1,30 @@
+
+ Copyright (c) 2011 Mozilla Foundation
+
+ Contributors: Andreas Gal
+ Chris G Jones
+ Shaon Barman
+ Vivien Nicolas <21@vingtetun.org>
+ Justin D'Arcangelo
+ Yury Delendik
+ Kalervo Kujala
+ Adil Allawi <@ironymark>
+
+ Permission is hereby granted, free of charge, to any person obtaining a
+ copy of this software and associated documentation files (the "Software"),
+ to deal in the Software without restriction, including without limitation
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ and/or sell copies of the Software, and to permit persons to whom the
+ Software is furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ DEALINGS IN THE SOFTWARE.
+
diff --git a/apps/files_pdfviewer/js/pdfjs/build/pdf.js b/apps/files_pdfviewer/js/pdfjs/build/pdf.js
new file mode 100755
index 00000000000..3447358d3bb
--- /dev/null
+++ b/apps/files_pdfviewer/js/pdfjs/build/pdf.js
@@ -0,0 +1,27022 @@
+/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
+
+var PDFJS = {};
+
+(function pdfjsWrapper() {
+ // Use strict in our context only - users might not want it
+ 'use strict';
+
+ PDFJS.build = 'PDFJSSCRIPT_BUNDLE_VER';
+
+ // Files are inserted below - see Makefile
+ /* PDFJSSCRIPT_INCLUDE_ALL */
+/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
+
+'use strict';
+
+var globalScope = (typeof window === 'undefined') ? this : window;
+
+var ERRORS = 0, WARNINGS = 1, TODOS = 5;
+var verbosity = WARNINGS;
+
+// The global PDFJS object exposes the API
+// In production, it will be declared outside a global wrapper
+// In development, it will be declared here
+if (!globalScope.PDFJS) {
+ globalScope.PDFJS = {};
+}
+
+// getPdf()
+// Convenience function to perform binary Ajax GET
+// Usage: getPdf('http://...', callback)
+// getPdf({
+// url:String ,
+// [,progress:Function, error:Function]
+// },
+// callback)
+function getPdf(arg, callback) {
+ var params = arg;
+ if (typeof arg === 'string')
+ params = { url: arg };
+
+ var xhr = new XMLHttpRequest();
+ xhr.open('GET', params.url);
+ xhr.mozResponseType = xhr.responseType = 'arraybuffer';
+ xhr.expected = (document.URL.indexOf('file:') === 0) ? 0 : 200;
+
+ if ('progress' in params)
+ xhr.onprogress = params.progress || undefined;
+
+ if ('error' in params)
+ xhr.onerror = params.error || undefined;
+
+ xhr.onreadystatechange = function getPdfOnreadystatechange() {
+ if (xhr.readyState === 4 && xhr.status === xhr.expected) {
+ var data = (xhr.mozResponseArrayBuffer || xhr.mozResponse ||
+ xhr.responseArrayBuffer || xhr.response);
+ callback(data);
+ }
+ };
+ xhr.send(null);
+}
+globalScope.PDFJS.getPdf = getPdf;
+
+var Page = (function pagePage() {
+ function constructor(xref, pageNumber, pageDict, ref) {
+ this.pageNumber = pageNumber;
+ this.pageDict = pageDict;
+ this.stats = {
+ create: Date.now(),
+ compile: 0.0,
+ fonts: 0.0,
+ images: 0.0,
+ render: 0.0
+ };
+ this.xref = xref;
+ this.ref = ref;
+ }
+
+ constructor.prototype = {
+ getPageProp: function pageGetPageProp(key) {
+ return this.xref.fetchIfRef(this.pageDict.get(key));
+ },
+ inheritPageProp: function pageInheritPageProp(key) {
+ var dict = this.pageDict;
+ var obj = dict.get(key);
+ while (obj === undefined) {
+ dict = this.xref.fetchIfRef(dict.get('Parent'));
+ if (!dict)
+ break;
+ obj = dict.get(key);
+ }
+ return obj;
+ },
+ get content() {
+ return shadow(this, 'content', this.getPageProp('Contents'));
+ },
+ get resources() {
+ return shadow(this, 'resources', this.inheritPageProp('Resources'));
+ },
+ get mediaBox() {
+ var obj = this.inheritPageProp('MediaBox');
+ // Reset invalid media box to letter size.
+ if (!isArray(obj) || obj.length !== 4)
+ obj = [0, 0, 612, 792];
+ return shadow(this, 'mediaBox', obj);
+ },
+ get view() {
+ var obj = this.inheritPageProp('CropBox');
+ var view = {
+ x: 0,
+ y: 0,
+ width: this.width,
+ height: this.height
+ };
+ if (isArray(obj) && obj.length == 4) {
+ var tl = this.rotatePoint(obj[0], obj[1]);
+ var br = this.rotatePoint(obj[2], obj[3]);
+ view.x = Math.min(tl.x, br.x);
+ view.y = Math.min(tl.y, br.y);
+ view.width = Math.abs(tl.x - br.x);
+ view.height = Math.abs(tl.y - br.y);
+ }
+
+ return shadow(this, 'cropBox', view);
+ },
+ get annotations() {
+ return shadow(this, 'annotations', this.inheritPageProp('Annots'));
+ },
+ get width() {
+ var mediaBox = this.mediaBox;
+ var rotate = this.rotate;
+ var width;
+ if (rotate == 0 || rotate == 180) {
+ width = (mediaBox[2] - mediaBox[0]);
+ } else {
+ width = (mediaBox[3] - mediaBox[1]);
+ }
+ return shadow(this, 'width', width);
+ },
+ get height() {
+ var mediaBox = this.mediaBox;
+ var rotate = this.rotate;
+ var height;
+ if (rotate == 0 || rotate == 180) {
+ height = (mediaBox[3] - mediaBox[1]);
+ } else {
+ height = (mediaBox[2] - mediaBox[0]);
+ }
+ return shadow(this, 'height', height);
+ },
+ get rotate() {
+ var rotate = this.inheritPageProp('Rotate') || 0;
+ // Normalize rotation so it's a multiple of 90 and between 0 and 270
+ if (rotate % 90 != 0) {
+ rotate = 0;
+ } else if (rotate >= 360) {
+ rotate = rotate % 360;
+ } else if (rotate < 0) {
+ // The spec doesn't cover negatives, assume its counterclockwise
+ // rotation. The following is the other implementation of modulo.
+ rotate = ((rotate % 360) + 360) % 360;
+ }
+ return shadow(this, 'rotate', rotate);
+ },
+
+ startRenderingFromIRQueue: function pageStartRenderingFromIRQueue(
+ IRQueue, fonts) {
+ var self = this;
+ this.IRQueue = IRQueue;
+ var gfx = new CanvasGraphics(this.ctx, this.objs);
+
+ var displayContinuation = function pageDisplayContinuation() {
+ // Always defer call to display() to work around bug in
+ // Firefox error reporting from XHR callbacks.
+ setTimeout(function pageSetTimeout() {
+ try {
+ self.display(gfx, self.callback);
+ } catch (e) {
+ if (self.callback) self.callback(e.toString());
+ throw e;
+ }
+ });
+ };
+
+ this.ensureFonts(fonts,
+ function pageStartRenderingFromIRQueueEnsureFonts() {
+ displayContinuation();
+ });
+ },
+
+ getIRQueue: function pageGetIRQueue(handler, dependency) {
+ if (this.IRQueue) {
+ // content was compiled
+ return this.IRQueue;
+ }
+
+ var xref = this.xref;
+ var content = xref.fetchIfRef(this.content);
+ var resources = xref.fetchIfRef(this.resources);
+ if (isArray(content)) {
+ // fetching items
+ var i, n = content.length;
+ for (i = 0; i < n; ++i)
+ content[i] = xref.fetchIfRef(content[i]);
+ content = new StreamsSequenceStream(content);
+ }
+
+ var pe = this.pe = new PartialEvaluator(
+ xref, handler, 'p' + this.pageNumber + '_');
+ var IRQueue = {};
+ return (this.IRQueue = pe.getIRQueue(content, resources, IRQueue,
+ dependency));
+ },
+
+ ensureFonts: function pageEnsureFonts(fonts, callback) {
+ // Convert the font names to the corresponding font obj.
+ for (var i = 0, ii = fonts.length; i < ii; i++) {
+ fonts[i] = this.objs.objs[fonts[i]].data;
+ }
+
+ // Load all the fonts
+ var fontObjs = FontLoader.bind(
+ fonts,
+ function pageEnsureFontsFontObjs(fontObjs) {
+ this.stats.fonts = Date.now();
+
+ callback.call(this);
+ }.bind(this),
+ this.objs
+ );
+ },
+
+ display: function pageDisplay(gfx, callback) {
+ var xref = this.xref;
+ var resources = xref.fetchIfRef(this.resources);
+ var mediaBox = xref.fetchIfRef(this.mediaBox);
+ assertWellFormed(isDict(resources), 'invalid page resources');
+
+ gfx.xref = xref;
+ gfx.res = resources;
+ gfx.beginDrawing({ x: mediaBox[0], y: mediaBox[1],
+ width: this.width,
+ height: this.height,
+ rotate: this.rotate });
+
+ var startIdx = 0;
+ var length = this.IRQueue.fnArray.length;
+ var IRQueue = this.IRQueue;
+
+ var self = this;
+ function next() {
+ startIdx = gfx.executeIRQueue(IRQueue, startIdx, next);
+ if (startIdx == length) {
+ self.stats.render = Date.now();
+ if (callback) callback();
+ }
+ }
+ next();
+ },
+ rotatePoint: function pageRotatePoint(x, y, reverse) {
+ var rotate = reverse ? (360 - this.rotate) : this.rotate;
+ switch (rotate) {
+ case 180:
+ return {x: this.width - x, y: y};
+ case 90:
+ return {x: this.width - y, y: this.height - x};
+ case 270:
+ return {x: y, y: x};
+ case 360:
+ case 0:
+ default:
+ return {x: x, y: this.height - y};
+ }
+ },
+ getLinks: function pageGetLinks() {
+ var xref = this.xref;
+ var annotations = xref.fetchIfRef(this.annotations) || [];
+ var i, n = annotations.length;
+ var links = [];
+ for (i = 0; i < n; ++i) {
+ var annotation = xref.fetch(annotations[i]);
+ if (!isDict(annotation))
+ continue;
+ var subtype = annotation.get('Subtype');
+ if (!isName(subtype) || subtype.name != 'Link')
+ continue;
+ var rect = annotation.get('Rect');
+ var topLeftCorner = this.rotatePoint(rect[0], rect[1]);
+ var bottomRightCorner = this.rotatePoint(rect[2], rect[3]);
+
+ var link = {};
+ link.x = Math.min(topLeftCorner.x, bottomRightCorner.x);
+ link.y = Math.min(topLeftCorner.y, bottomRightCorner.y);
+ link.width = Math.abs(topLeftCorner.x - bottomRightCorner.x);
+ link.height = Math.abs(topLeftCorner.y - bottomRightCorner.y);
+ var a = this.xref.fetchIfRef(annotation.get('A'));
+ if (a) {
+ switch (a.get('S').name) {
+ case 'URI':
+ link.url = a.get('URI');
+ break;
+ case 'GoTo':
+ link.dest = a.get('D');
+ break;
+ default:
+ TODO('other link types');
+ }
+ } else if (annotation.has('Dest')) {
+ // simple destination link
+ var dest = annotation.get('Dest');
+ link.dest = isName(dest) ? dest.name : dest;
+ }
+ links.push(link);
+ }
+ return links;
+ },
+ startRendering: function pageStartRendering(ctx, callback) {
+ this.ctx = ctx;
+ this.callback = callback;
+
+ this.startRenderingTime = Date.now();
+ this.pdf.startRendering(this);
+ }
+ };
+
+ return constructor;
+})();
+
+/**
+ * The `PDFDocModel` holds all the data of the PDF file. Compared to the
+ * `PDFDoc`, this one doesn't have any job management code.
+ * Right now there exists one PDFDocModel on the main thread + one object
+ * for each worker. If there is no worker support enabled, there are two
+ * `PDFDocModel` objects on the main thread created.
+ * TODO: Refactor the internal object structure, such that there is no
+ * need for the `PDFDocModel` anymore and there is only one object on the
+ * main thread and not one entire copy on each worker instance.
+ */
+var PDFDocModel = (function pdfDoc() {
+ function constructor(arg, callback) {
+ if (isStream(arg))
+ init.call(this, arg);
+ else if (isArrayBuffer(arg))
+ init.call(this, new Stream(arg));
+ else
+ error('PDFDocModel: Unknown argument type');
+ }
+
+ function init(stream) {
+ assertWellFormed(stream.length > 0, 'stream must have data');
+ this.stream = stream;
+ this.setup();
+ }
+
+ function find(stream, needle, limit, backwards) {
+ var pos = stream.pos;
+ var end = stream.end;
+ var str = '';
+ if (pos + limit > end)
+ limit = end - pos;
+ for (var n = 0; n < limit; ++n)
+ str += stream.getChar();
+ stream.pos = pos;
+ var index = backwards ? str.lastIndexOf(needle) : str.indexOf(needle);
+ if (index == -1)
+ return false; /* not found */
+ stream.pos += index;
+ return true; /* found */
+ }
+
+ constructor.prototype = {
+ get linearization() {
+ var length = this.stream.length;
+ var linearization = false;
+ if (length) {
+ linearization = new Linearization(this.stream);
+ if (linearization.length != length)
+ linearization = false;
+ }
+ // shadow the prototype getter with a data property
+ return shadow(this, 'linearization', linearization);
+ },
+ get startXRef() {
+ var stream = this.stream;
+ var startXRef = 0;
+ var linearization = this.linearization;
+ if (linearization) {
+ // Find end of first obj.
+ stream.reset();
+ if (find(stream, 'endobj', 1024))
+ startXRef = stream.pos + 6;
+ } else {
+ // Find startxref at the end of the file.
+ var start = stream.end - 1024;
+ if (start < 0)
+ start = 0;
+ stream.pos = start;
+ if (find(stream, 'startxref', 1024, true)) {
+ stream.skip(9);
+ var ch;
+ do {
+ ch = stream.getChar();
+ } while (Lexer.isSpace(ch));
+ var str = '';
+ while ((ch - '0') <= 9) {
+ str += ch;
+ ch = stream.getChar();
+ }
+ startXRef = parseInt(str, 10);
+ if (isNaN(startXRef))
+ startXRef = 0;
+ }
+ }
+ // shadow the prototype getter with a data property
+ return shadow(this, 'startXRef', startXRef);
+ },
+ get mainXRefEntriesOffset() {
+ var mainXRefEntriesOffset = 0;
+ var linearization = this.linearization;
+ if (linearization)
+ mainXRefEntriesOffset = linearization.mainXRefEntriesOffset;
+ // shadow the prototype getter with a data property
+ return shadow(this, 'mainXRefEntriesOffset', mainXRefEntriesOffset);
+ },
+ // Find the header, remove leading garbage and setup the stream
+ // starting from the header.
+ checkHeader: function pdfDocCheckHeader() {
+ var stream = this.stream;
+ stream.reset();
+ if (find(stream, '%PDF-', 1024)) {
+ // Found the header, trim off any garbage before it.
+ stream.moveStart();
+ return;
+ }
+ // May not be a PDF file, continue anyway.
+ },
+ setup: function pdfDocSetup(ownerPassword, userPassword) {
+ this.checkHeader();
+ this.xref = new XRef(this.stream,
+ this.startXRef,
+ this.mainXRefEntriesOffset);
+ this.catalog = new Catalog(this.xref);
+ },
+ get numPages() {
+ var linearization = this.linearization;
+ var num = linearization ? linearization.numPages : this.catalog.numPages;
+ // shadow the prototype getter
+ return shadow(this, 'numPages', num);
+ },
+ getPage: function pdfDocGetPage(n) {
+ return this.catalog.getPage(n);
+ }
+ };
+
+ return constructor;
+})();
+
+var PDFDoc = (function pdfDoc() {
+ function constructor(arg, callback) {
+ var stream = null;
+ var data = null;
+
+ if (isStream(arg)) {
+ stream = arg;
+ data = arg.bytes;
+ } else if (isArrayBuffer(arg)) {
+ stream = new Stream(arg);
+ data = arg;
+ } else {
+ error('PDFDoc: Unknown argument type');
+ }
+
+ this.data = data;
+ this.stream = stream;
+ this.pdf = new PDFDocModel(stream);
+
+ this.catalog = this.pdf.catalog;
+ this.objs = new PDFObjects();
+
+ this.pageCache = [];
+ this.fontsLoading = {};
+ this.workerReadyPromise = new Promise('workerReady');
+
+ // If worker support isn't disabled explicit and the browser has worker
+ // support, create a new web worker and test if it/the browser fullfills
+ // all requirements to run parts of pdf.js in a web worker.
+ // Right now, the requirement is, that an Uint8Array is still an Uint8Array
+ // as it arrives on the worker. Chrome added this with version 15.
+ if (!globalScope.PDFJS.disableWorker && typeof Worker !== 'undefined') {
+ var workerSrc = PDFJS.workerSrc;
+ if (typeof workerSrc === 'undefined') {
+ throw 'No PDFJS.workerSrc specified';
+ }
+
+ var worker;
+ try {
+ worker = new Worker(workerSrc);
+ } catch (e) {
+ // Some versions of FF can't create a worker on localhost, see:
+ // https://bugzilla.mozilla.org/show_bug.cgi?id=683280
+ globalScope.PDFJS.disableWorker = true;
+ this.setupFakeWorker();
+ return;
+ }
+
+ var messageHandler = new MessageHandler('main', worker);
+
+ // Tell the worker the file it was created from.
+ messageHandler.send('workerSrc', workerSrc);
+
+ messageHandler.on('test', function pdfDocTest(supportTypedArray) {
+ if (supportTypedArray) {
+ this.worker = worker;
+ this.setupMessageHandler(messageHandler);
+ } else {
+ this.setupFakeWorker();
+ }
+ }.bind(this));
+
+ var testObj = new Uint8Array(1);
+ messageHandler.send('test', testObj);
+ } else {
+ this.setupFakeWorker();
+ }
+ }
+
+ constructor.prototype = {
+ setupFakeWorker: function() {
+ // If we don't use a worker, just post/sendMessage to the main thread.
+ var fakeWorker = {
+ postMessage: function pdfDocPostMessage(obj) {
+ fakeWorker.onmessage({data: obj});
+ },
+ terminate: function pdfDocTerminate() {}
+ };
+
+ var messageHandler = new MessageHandler('main', fakeWorker);
+ this.setupMessageHandler(messageHandler);
+
+ // If the main thread is our worker, setup the handling for the messages
+ // the main thread sends to it self.
+ WorkerMessageHandler.setup(messageHandler);
+ },
+
+
+ setupMessageHandler: function(messageHandler) {
+ this.messageHandler = messageHandler;
+
+ messageHandler.on('page', function pdfDocPage(data) {
+ var pageNum = data.pageNum;
+ var page = this.pageCache[pageNum];
+ var depFonts = data.depFonts;
+
+ page.startRenderingFromIRQueue(data.IRQueue, depFonts);
+ }, this);
+
+ messageHandler.on('obj', function pdfDocObj(data) {
+ var id = data[0];
+ var type = data[1];
+
+ switch (type) {
+ case 'JpegStream':
+ var IR = data[2];
+ new JpegImageLoader(id, IR, this.objs);
+ break;
+ case 'Font':
+ var name = data[2];
+ var file = data[3];
+ var properties = data[4];
+
+ if (file) {
+ var fontFileDict = new Dict();
+ fontFileDict.map = file.dict.map;
+
+ var fontFile = new Stream(file.bytes, file.start,
+ file.end - file.start, fontFileDict);
+
+ // Check if this is a FlateStream. Otherwise just use the created
+ // Stream one. This makes complex_ttf_font.pdf work.
+ var cmf = file.bytes[0];
+ if ((cmf & 0x0f) == 0x08) {
+ file = new FlateStream(fontFile);
+ } else {
+ file = fontFile;
+ }
+ }
+
+ // For now, resolve the font object here direclty. The real font
+ // object is then created in FontLoader.bind().
+ this.objs.resolve(id, {
+ name: name,
+ file: file,
+ properties: properties
+ });
+ break;
+ default:
+ throw 'Got unkown object type ' + type;
+ }
+ }, this);
+
+ messageHandler.on('font_ready', function pdfDocFontReady(data) {
+ var id = data[0];
+ var font = new FontShape(data[1]);
+
+ // If there is no string, then there is nothing to attach to the DOM.
+ if (!font.str) {
+ this.objs.resolve(id, font);
+ } else {
+ this.objs.setData(id, font);
+ }
+ }.bind(this));
+
+ setTimeout(function pdfDocFontReadySetTimeout() {
+ messageHandler.send('doc', this.data);
+ this.workerReadyPromise.resolve(true);
+ }.bind(this));
+ },
+
+ get numPages() {
+ return this.pdf.numPages;
+ },
+
+ startRendering: function pdfDocStartRendering(page) {
+ // The worker might not be ready to receive the page request yet.
+ this.workerReadyPromise.then(function pdfDocStartRenderingThen() {
+ this.messageHandler.send('page_request', page.pageNumber + 1);
+ }.bind(this));
+ },
+
+ getPage: function pdfDocGetPage(n) {
+ if (this.pageCache[n])
+ return this.pageCache[n];
+
+ var page = this.pdf.getPage(n);
+ // Add a reference to the objects such that Page can forward the reference
+ // to the CanvasGraphics and so on.
+ page.objs = this.objs;
+ page.pdf = this;
+ return (this.pageCache[n] = page);
+ },
+
+ destroy: function pdfDocDestroy() {
+ if (this.worker)
+ this.worker.terminate();
+
+ if (this.fontWorker)
+ this.fontWorker.terminate();
+
+ for (var n in this.pageCache)
+ delete this.pageCache[n];
+
+ delete this.data;
+ delete this.stream;
+ delete this.pdf;
+ delete this.catalog;
+ }
+ };
+
+ return constructor;
+})();
+
+globalScope.PDFJS.PDFDoc = PDFDoc;
+
+/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
+
+'use strict';
+
+function log(msg) {
+ if (console && console.log)
+ console.log(msg);
+ else if (print)
+ print(msg);
+}
+
+function warn(msg) {
+ if (verbosity >= WARNINGS)
+ log('Warning: ' + msg);
+}
+
+function backtrace() {
+ try {
+ throw new Error();
+ } catch (e) {
+ return e.stack ? e.stack.split('\n').slice(2).join('\n') : '';
+ }
+}
+
+function error(msg) {
+ log('Error: ' + msg);
+ log(backtrace());
+ throw new Error(msg);
+}
+
+function TODO(what) {
+ if (verbosity >= TODOS)
+ log('TODO: ' + what);
+}
+
+function malformed(msg) {
+ error('Malformed PDF: ' + msg);
+}
+
+function assert(cond, msg) {
+ if (!cond)
+ error(msg);
+}
+
+// In a well-formed PDF, |cond| holds. If it doesn't, subsequent
+// behavior is undefined.
+function assertWellFormed(cond, msg) {
+ if (!cond)
+ malformed(msg);
+}
+
+function shadow(obj, prop, value) {
+ Object.defineProperty(obj, prop, { value: value,
+ enumerable: true,
+ configurable: true,
+ writable: false });
+ return value;
+}
+
+function bytesToString(bytes) {
+ var str = '';
+ var length = bytes.length;
+ for (var n = 0; n < length; ++n)
+ str += String.fromCharCode(bytes[n]);
+ return str;
+}
+
+function stringToBytes(str) {
+ var length = str.length;
+ var bytes = new Uint8Array(length);
+ for (var n = 0; n < length; ++n)
+ bytes[n] = str.charCodeAt(n) & 0xFF;
+ return bytes;
+}
+
+var IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
+
+var Util = (function utilUtil() {
+ function constructor() {}
+ constructor.makeCssRgb = function makergb(r, g, b) {
+ var ri = (255 * r) | 0, gi = (255 * g) | 0, bi = (255 * b) | 0;
+ return 'rgb(' + ri + ',' + gi + ',' + bi + ')';
+ };
+ constructor.makeCssCmyk = function makecmyk(c, m, y, k) {
+ c = (new DeviceCmykCS()).getRgb([c, m, y, k]);
+ var ri = (255 * c[0]) | 0, gi = (255 * c[1]) | 0, bi = (255 * c[2]) | 0;
+ return 'rgb(' + ri + ',' + gi + ',' + bi + ')';
+ };
+ constructor.applyTransform = function apply(p, m) {
+ var xt = p[0] * m[0] + p[1] * m[2] + m[4];
+ var yt = p[0] * m[1] + p[1] * m[3] + m[5];
+ return [xt, yt];
+ };
+
+ return constructor;
+})();
+
+var PDFStringTranslateTable = [
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0x2D8, 0x2C7, 0x2C6, 0x2D9, 0x2DD, 0x2DB, 0x2DA, 0x2DC, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2022, 0x2020, 0x2021, 0x2026, 0x2014,
+ 0x2013, 0x192, 0x2044, 0x2039, 0x203A, 0x2212, 0x2030, 0x201E, 0x201C,
+ 0x201D, 0x2018, 0x2019, 0x201A, 0x2122, 0xFB01, 0xFB02, 0x141, 0x152, 0x160,
+ 0x178, 0x17D, 0x131, 0x142, 0x153, 0x161, 0x17E, 0, 0x20AC
+];
+
+function stringToPDFString(str) {
+ var i, n = str.length, str2 = '';
+ if (str[0] === '\xFE' && str[1] === '\xFF') {
+ // UTF16BE BOM
+ for (i = 2; i < n; i += 2)
+ str2 += String.fromCharCode(
+ (str.charCodeAt(i) << 8) | str.charCodeAt(i + 1));
+ } else {
+ for (i = 0; i < n; ++i) {
+ var code = PDFStringTranslateTable[str.charCodeAt(i)];
+ str2 += code ? String.fromCharCode(code) : str.charAt(i);
+ }
+ }
+ return str2;
+}
+
+function isBool(v) {
+ return typeof v == 'boolean';
+}
+
+function isInt(v) {
+ return typeof v == 'number' && ((v | 0) == v);
+}
+
+function isNum(v) {
+ return typeof v == 'number';
+}
+
+function isString(v) {
+ return typeof v == 'string';
+}
+
+function isNull(v) {
+ return v === null;
+}
+
+function isName(v) {
+ return v instanceof Name;
+}
+
+function isCmd(v, cmd) {
+ return v instanceof Cmd && (!cmd || v.cmd == cmd);
+}
+
+function isDict(v, type) {
+ return v instanceof Dict && (!type || v.get('Type').name == type);
+}
+
+function isArray(v) {
+ return v instanceof Array;
+}
+
+function isStream(v) {
+ return typeof v == 'object' && v != null && ('getChar' in v);
+}
+
+function isArrayBuffer(v) {
+ return typeof v == 'object' && v != null && ('byteLength' in v);
+}
+
+function isRef(v) {
+ return v instanceof Ref;
+}
+
+function isPDFFunction(v) {
+ var fnDict;
+ if (typeof v != 'object')
+ return false;
+ else if (isDict(v))
+ fnDict = v;
+ else if (isStream(v))
+ fnDict = v.dict;
+ else
+ return false;
+ return fnDict.has('FunctionType');
+}
+
+/**
+ * 'Promise' object.
+ * Each object that is stored in PDFObjects is based on a Promise object that
+ * contains the status of the object and the data. There migth be situations,
+ * where a function want to use the value of an object, but it isn't ready at
+ * that time. To get a notification, once the object is ready to be used, s.o.
+ * can add a callback using the `then` method on the promise that then calls
+ * the callback once the object gets resolved.
+ * A promise can get resolved only once and only once the data of the promise
+ * can be set. If any of these happens twice or the data is required before
+ * it was set, an exception is throw.
+ */
+var Promise = (function promise() {
+ var EMPTY_PROMISE = {};
+
+ /**
+ * If `data` is passed in this constructor, the promise is created resolved.
+ * If there isn't data, it isn't resolved at the beginning.
+ */
+ function Promise(name, data) {
+ this.name = name;
+ // If you build a promise and pass in some data it's already resolved.
+ if (data != null) {
+ this.isResolved = true;
+ this._data = data;
+ this.hasData = true;
+ } else {
+ this.isResolved = false;
+ this._data = EMPTY_PROMISE;
+ }
+ this.callbacks = [];
+ };
+
+ Promise.prototype = {
+ hasData: false,
+
+ set data(value) {
+ if (value === undefined) {
+ return;
+ }
+ if (this._data !== EMPTY_PROMISE) {
+ throw 'Promise ' + this.name +
+ ': Cannot set the data of a promise twice';
+ }
+ this._data = value;
+ this.hasData = true;
+
+ if (this.onDataCallback) {
+ this.onDataCallback(value);
+ }
+ },
+
+ get data() {
+ if (this._data === EMPTY_PROMISE) {
+ throw 'Promise ' + this.name + ': Cannot get data that isn\'t set';
+ }
+ return this._data;
+ },
+
+ onData: function promiseOnData(callback) {
+ if (this._data !== EMPTY_PROMISE) {
+ callback(this._data);
+ } else {
+ this.onDataCallback = callback;
+ }
+ },
+
+ resolve: function promiseResolve(data) {
+ if (this.isResolved) {
+ throw 'A Promise can be resolved only once ' + this.name;
+ }
+
+ this.isResolved = true;
+ this.data = data;
+ var callbacks = this.callbacks;
+
+ for (var i = 0, ii = callbacks.length; i < ii; i++) {
+ callbacks[i].call(null, data);
+ }
+ },
+
+ then: function promiseThen(callback) {
+ if (!callback) {
+ throw 'Requiring callback' + this.name;
+ }
+
+ // If the promise is already resolved, call the callback directly.
+ if (this.isResolved) {
+ var data = this.data;
+ callback.call(null, data);
+ } else {
+ this.callbacks.push(callback);
+ }
+ }
+ };
+
+ return Promise;
+})();
+
+/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
+
+'use strict';
+
+//