[Pkg-javascript-commits] [pdf.js] 115/207: Splits shared/annotation.js into core/ and display/

David Prévot taffit at moszumanska.debian.org
Mon Jul 28 15:36:38 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository pdf.js.

commit bdeca30fbfe000c05643b4a8cdda692e2fd549a2
Author: Yury Delendik <ydelendik at mozilla.com>
Date:   Tue Jun 17 17:43:33 2014 -0500

    Splits shared/annotation.js into core/ and display/
---
 examples/acroforms/index.html      |   2 +-
 examples/helloworld/index.html     |   2 +-
 make.js                            |   4 +-
 src/{shared => core}/annotation.js | 314 ++-----------------------------------
 src/display/annotation_helper.js   | 252 +++++++++++++++++++++++++++++
 src/shared/util.js                 |   6 +
 src/worker_loader.js               |   4 +-
 test/font/font_test.html           |   3 +-
 test/test_slave.html               |   2 +-
 test/unit/unit_test.html           |   3 +-
 web/page_view.js                   |   8 +-
 web/viewer.html                    |   2 +-
 12 files changed, 284 insertions(+), 318 deletions(-)

diff --git a/examples/acroforms/index.html b/examples/acroforms/index.html
index 5ac3fdc..85b60f3 100644
--- a/examples/acroforms/index.html
+++ b/examples/acroforms/index.html
@@ -5,13 +5,13 @@
   <!-- In production, only one script (pdf.js) is necessary -->
   <!-- In production, change the content of PDFJS.workerSrc below -->
   <script src="../../src/shared/util.js"></script>
-  <script src="../../src/shared/annotation.js"></script>
   <script src="../../src/display/api.js"></script>
   <script src="../../src/display/metadata.js"></script>
   <script src="../../src/display/canvas.js"></script>
   <script src="../../src/display/webgl.js"></script>
   <script src="../../src/display/pattern_helper.js"></script>
   <script src="../../src/display/font_loader.js"></script>
+  <script src="../../src/display/annotation_helper.js"></script>
 
   <script>
     // Specify the main script used to create a new PDF.JS web worker.
diff --git a/examples/helloworld/index.html b/examples/helloworld/index.html
index b38060b..748d606 100644
--- a/examples/helloworld/index.html
+++ b/examples/helloworld/index.html
@@ -5,13 +5,13 @@
   <!-- In production, only one script (pdf.js) is necessary -->
   <!-- In production, change the content of PDFJS.workerSrc below -->
   <script src="../../src/shared/util.js"></script>
-  <script src="../../src/shared/annotation.js"></script>
   <script src="../../src/display/api.js"></script>
   <script src="../../src/display/metadata.js"></script>
   <script src="../../src/display/canvas.js"></script>
   <script src="../../src/display/webgl.js"></script>
   <script src="../../src/display/pattern_helper.js"></script>
   <script src="../../src/display/font_loader.js"></script>
+  <script src="../../src/display/annotation_helper.js"></script>
 
   <script>
     // Specify the main script used to create a new PDF.JS web worker.
diff --git a/make.js b/make.js
index a234017..7b5c544 100644
--- a/make.js
+++ b/make.js
@@ -370,7 +370,6 @@ target.bundle = function(args) {
 
   var SHARED_SRC_FILES = [
     'shared/util.js',
-    'shared/annotation.js',
   ];
 
   var MAIN_SRC_FILES = SHARED_SRC_FILES.concat([
@@ -379,7 +378,8 @@ target.bundle = function(args) {
     'display/canvas.js',
     'display/webgl.js',
     'display/pattern_helper.js',
-    'display/font_loader.js'
+    'display/font_loader.js',
+    'display/annotation_helper.js',
   ]);
 
   var srcFiles = builder.getWorkerSrcFiles('src/worker_loader.js');
diff --git a/src/shared/annotation.js b/src/core/annotation.js
similarity index 62%
rename from src/shared/annotation.js
rename to src/core/annotation.js
index 8eae8c2..0d55bd8 100644
--- a/src/shared/annotation.js
+++ b/src/core/annotation.js
@@ -14,15 +14,13 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-/* globals Util, isDict, isName, stringToPDFString, warn, Dict, Stream,
-           stringToBytes, PDFJS, isWorker, assert, NotImplementedException,
-           Promise, isArray, ObjectLoader, isValidUrl, OperatorList, OPS,
-           createPromiseCapability */
+/* globals PDFJS, Util, isDict, isName, stringToPDFString, warn, Dict, Stream,
+           stringToBytes, assert, Promise, isArray, ObjectLoader, OperatorList,
+           isValidUrl, OPS, createPromiseCapability, AnnotationType */
 
 'use strict';
 
 var DEFAULT_ICON_SIZE = 22; // px
-var HIGHLIGHT_OFFSET = 4; // px
 var SUPPORTED_TYPES = ['Link', 'Text', 'Widget'];
 
 var Annotation = (function AnnotationClosure() {
@@ -72,11 +70,6 @@ var Annotation = (function AnnotationClosure() {
   }
 
   function Annotation(params) {
-    if (params.data) {
-      this.data = params.data;
-      return;
-    }
-
     var dict = params.dict;
     var data = this.data = {};
 
@@ -145,33 +138,6 @@ var Annotation = (function AnnotationClosure() {
       return this.data;
     },
 
-    hasHtml: function Annotation_hasHtml() {
-      return false;
-    },
-
-    getHtmlElement: function Annotation_getHtmlElement(commonObjs) {
-      throw new NotImplementedException(
-        'getHtmlElement() should be implemented in subclass');
-    },
-
-    // TODO(mack): Remove this, it's not really that helpful.
-    getEmptyContainer: function Annotation_getEmptyContainer(tagName, rect,
-                                                             borderWidth) {
-      assert(!isWorker,
-        'getEmptyContainer() should be called from main thread');
-
-      var bWidth = borderWidth || 0;
-
-      rect = rect || this.data.rect;
-      var element = document.createElement(tagName);
-      element.style.borderWidth = bWidth + 'px';
-      var width = rect[2] - rect[0] - 2 * bWidth;
-      var height = rect[3] - rect[1] - 2 * bWidth;
-      element.style.width = width + 'px';
-      element.style.height = height + 'px';
-      return element;
-    },
-
     isInvisible: function Annotation_isInvisible() {
       var data = this.data;
       if (data && SUPPORTED_TYPES.indexOf(data.subtype) !== -1) {
@@ -283,16 +249,6 @@ var Annotation = (function AnnotationClosure() {
     }
   };
 
-  // TODO(mack): Support loading annotation from data
-  Annotation.fromData = function Annotation_fromData(data) {
-    var subtype = data.subtype;
-    var fieldType = data.fieldType;
-    var Constructor = Annotation.getConstructor(subtype, fieldType);
-    if (Constructor) {
-      return new Constructor({ data: data });
-    }
-  };
-
   Annotation.fromRef = function Annotation_fromRef(xref, ref) {
 
     var dict = xref.fetchIfRef(ref);
@@ -370,10 +326,6 @@ var WidgetAnnotation = (function WidgetAnnotationClosure() {
   function WidgetAnnotation(params) {
     Annotation.call(this, params);
 
-    if (params.data) {
-      return;
-    }
-
     var dict = params.dict;
     var data = this.data;
 
@@ -438,66 +390,12 @@ var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
   function TextWidgetAnnotation(params) {
     WidgetAnnotation.call(this, params);
 
-    if (params.data) {
-      return;
-    }
-
     this.data.textAlignment = Util.getInheritableProperty(params.dict, 'Q');
+    this.data.annotationType = AnnotationType.WIDGET;
+    this.data.hasHtml = !this.data.hasAppearance && !!this.data.fieldValue;
   }
 
-  // TODO(mack): This dupes some of the logic in CanvasGraphics.setFont()
-  function setTextStyles(element, item, fontObj) {
-
-    var style = element.style;
-    style.fontSize = item.fontSize + 'px';
-    style.direction = item.fontDirection < 0 ? 'rtl': 'ltr';
-
-    if (!fontObj) {
-      return;
-    }
-
-    style.fontWeight = fontObj.black ?
-                            (fontObj.bold ? 'bolder' : 'bold') :
-                            (fontObj.bold ? 'bold' : 'normal');
-    style.fontStyle = fontObj.italic ? 'italic' : 'normal';
-
-    var fontName = fontObj.loadedName;
-    var fontFamily = fontName ? '"' + fontName + '", ' : '';
-    // Use a reasonable default font if the font doesn't specify a fallback
-    var fallbackName = fontObj.fallbackName || 'Helvetica, sans-serif';
-    style.fontFamily = fontFamily + fallbackName;
-  }
-
-
   Util.inherit(TextWidgetAnnotation, WidgetAnnotation, {
-    hasHtml: function TextWidgetAnnotation_hasHtml() {
-      return !this.data.hasAppearance && !!this.data.fieldValue;
-    },
-
-    getHtmlElement: function TextWidgetAnnotation_getHtmlElement(commonObjs) {
-      assert(!isWorker, 'getHtmlElement() shall be called from main thread');
-
-      var item = this.data;
-
-      var element = this.getEmptyContainer('div');
-      element.style.display = 'table';
-
-      var content = document.createElement('div');
-      content.textContent = item.fieldValue;
-      var textAlignment = item.textAlignment;
-      content.style.textAlign = ['left', 'center', 'right'][textAlignment];
-      content.style.verticalAlign = 'middle';
-      content.style.display = 'table-cell';
-
-      var fontObj = item.fontRefName ?
-                    commonObjs.getData(item.fontRefName) : null;
-      setTextStyles(content, item, fontObj);
-
-      element.appendChild(content);
-
-      return element;
-    },
-
     getOperatorList: function TextWidgetAnnotation_getOperatorList(evaluator) {
       if (this.appearance) {
         return Annotation.prototype.getOperatorList.call(this, evaluator);
@@ -526,54 +424,11 @@ var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
 var InteractiveAnnotation = (function InteractiveAnnotationClosure() {
   function InteractiveAnnotation(params) {
     Annotation.call(this, params);
-  }
-
-  Util.inherit(InteractiveAnnotation, Annotation, {
-    hasHtml: function InteractiveAnnotation_hasHtml() {
-      return true;
-    },
-
-    highlight: function InteractiveAnnotation_highlight() {
-      if (this.highlightElement &&
-         this.highlightElement.hasAttribute('hidden')) {
-        this.highlightElement.removeAttribute('hidden');
-      }
-    },
-
-    unhighlight: function InteractiveAnnotation_unhighlight() {
-      if (this.highlightElement &&
-         !this.highlightElement.hasAttribute('hidden')) {
-        this.highlightElement.setAttribute('hidden', true);
-      }
-    },
-
-    initContainer: function InteractiveAnnotation_initContainer() {
-
-      var item = this.data;
-      var rect = item.rect;
 
-      var container = this.getEmptyContainer('section', rect, item.borderWidth);
-      container.style.backgroundColor = item.color;
-
-      var color = item.color;
-      var rgb = [];
-      for (var i = 0; i < 3; ++i) {
-        rgb[i] = Math.round(color[i] * 255);
-      }
-      item.colorCssRgb = Util.makeCssRgb(rgb);
-
-      var highlight = document.createElement('div');
-      highlight.className = 'annotationHighlight';
-      highlight.style.left = highlight.style.top = -HIGHLIGHT_OFFSET + 'px';
-      highlight.style.right = highlight.style.bottom = -HIGHLIGHT_OFFSET + 'px';
-      highlight.setAttribute('hidden', true);
-
-      this.highlightElement = highlight;
-      container.appendChild(this.highlightElement);
+    this.data.hasHtml = true;
+  }
 
-      return container;
-    }
-  });
+  Util.inherit(InteractiveAnnotation, Annotation, { });
 
   return InteractiveAnnotation;
 })();
@@ -582,15 +437,12 @@ var TextAnnotation = (function TextAnnotationClosure() {
   function TextAnnotation(params) {
     InteractiveAnnotation.call(this, params);
 
-    if (params.data) {
-      return;
-    }
-
     var dict = params.dict;
     var data = this.data;
 
     var content = dict.get('Contents');
     var title = dict.get('T');
+    data.annotationType = AnnotationType.TEXT;
     data.content = stringToPDFString(content || '');
     data.title = stringToPDFString(title || '');
 
@@ -607,130 +459,7 @@ var TextAnnotation = (function TextAnnotationClosure() {
     }
   }
 
-  var ANNOT_MIN_SIZE = 10;
-
-  Util.inherit(TextAnnotation, InteractiveAnnotation, {
-
-    getHtmlElement: function TextAnnotation_getHtmlElement(commonObjs) {
-      assert(!isWorker, 'getHtmlElement() shall be called from main thread');
-
-      var item = this.data;
-      var rect = item.rect;
-
-      // sanity check because of OOo-generated PDFs
-      if ((rect[3] - rect[1]) < ANNOT_MIN_SIZE) {
-        rect[3] = rect[1] + ANNOT_MIN_SIZE;
-      }
-      if ((rect[2] - rect[0]) < ANNOT_MIN_SIZE) {
-        rect[2] = rect[0] + (rect[3] - rect[1]); // make it square
-      }
-
-      var container = this.initContainer();
-      container.className = 'annotText';
-
-      var image  = document.createElement('img');
-      image.style.height = container.style.height;
-      image.style.width = container.style.width;
-      var iconName = item.name;
-      image.src = PDFJS.imageResourcesPath + 'annotation-' +
-        iconName.toLowerCase() + '.svg';
-      image.alt = '[{{type}} Annotation]';
-      image.dataset.l10nId = 'text_annotation_type';
-      image.dataset.l10nArgs = JSON.stringify({type: iconName});
-
-      var contentWrapper = document.createElement('div');
-      contentWrapper.className = 'annotTextContentWrapper';
-      contentWrapper.style.left = Math.floor(rect[2] - rect[0] + 5) + 'px';
-      contentWrapper.style.top = '-10px';
-
-      var content = document.createElement('div');
-      content.className = 'annotTextContent';
-      content.setAttribute('hidden', true);
-
-      var i, ii;
-      if (item.hasBgColor) {
-        var color = item.color;
-        var rgb = [];
-        for (i = 0; i < 3; ++i) {
-          // Enlighten the color (70%)
-          var c = Math.round(color[i] * 255);
-          rgb[i] = Math.round((255 - c) * 0.7) + c;
-        }
-        content.style.backgroundColor = Util.makeCssRgb(rgb);
-      }
-
-      var title = document.createElement('h1');
-      var text = document.createElement('p');
-      title.textContent = item.title;
-
-      if (!item.content && !item.title) {
-        content.setAttribute('hidden', true);
-      } else {
-        var e = document.createElement('span');
-        var lines = item.content.split(/(?:\r\n?|\n)/);
-        for (i = 0, ii = lines.length; i < ii; ++i) {
-          var line = lines[i];
-          e.appendChild(document.createTextNode(line));
-          if (i < (ii - 1)) {
-            e.appendChild(document.createElement('br'));
-          }
-        }
-        text.appendChild(e);
-
-        var pinned = false;
-
-        var showAnnotation = function showAnnotation(pin) {
-          if (pin) {
-            pinned = true;
-          }
-          if (content.hasAttribute('hidden')) {
-            container.style.zIndex += 1;
-            content.removeAttribute('hidden');
-          }
-        };
-
-        var hideAnnotation = function hideAnnotation(unpin) {
-          if (unpin) {
-            pinned = false;
-          }
-          if (!content.hasAttribute('hidden') && !pinned) {
-            container.style.zIndex -= 1;
-            content.setAttribute('hidden', true);
-          }
-        };
-
-        var toggleAnnotation = function toggleAnnotation() {
-          if (pinned) {
-            hideAnnotation(true);
-          } else {
-            showAnnotation(true);
-          }
-        };
-
-        image.addEventListener('click', function image_clickHandler() {
-          toggleAnnotation();
-        }, false);
-        image.addEventListener('mouseover', function image_mouseOverHandler() {
-          showAnnotation();
-        }, false);
-        image.addEventListener('mouseout', function image_mouseOutHandler() {
-          hideAnnotation();
-        }, false);
-
-        content.addEventListener('click', function content_clickHandler() {
-          hideAnnotation(true);
-        }, false);
-      }
-
-      content.appendChild(title);
-      content.appendChild(text);
-      contentWrapper.appendChild(content);
-      container.appendChild(image);
-      container.appendChild(contentWrapper);
-
-      return container;
-    }
-  });
+  Util.inherit(TextAnnotation, InteractiveAnnotation, { });
 
   return TextAnnotation;
 })();
@@ -739,12 +468,9 @@ var LinkAnnotation = (function LinkAnnotationClosure() {
   function LinkAnnotation(params) {
     InteractiveAnnotation.call(this, params);
 
-    if (params.data) {
-      return;
-    }
-
     var dict = params.dict;
     var data = this.data;
+    data.annotationType = AnnotationType.LINK;
 
     var action = dict.get('A');
     if (action) {
@@ -803,24 +529,6 @@ var LinkAnnotation = (function LinkAnnotationClosure() {
   Util.inherit(LinkAnnotation, InteractiveAnnotation, {
     hasOperatorList: function LinkAnnotation_hasOperatorList() {
       return false;
-    },
-
-    getHtmlElement: function LinkAnnotation_getHtmlElement(commonObjs) {
-
-      var container = this.initContainer();
-      container.className = 'annotLink';
-
-      var item = this.data;
-
-      container.style.borderColor = item.colorCssRgb;
-      container.style.borderStyle = 'solid';
-
-      var link = document.createElement('a');
-      link.href = link.title = this.data.url || '';
-
-      container.appendChild(link);
-
-      return container;
     }
   });
 
diff --git a/src/display/annotation_helper.js b/src/display/annotation_helper.js
new file mode 100644
index 0000000..f0ca1f9
--- /dev/null
+++ b/src/display/annotation_helper.js
@@ -0,0 +1,252 @@
+/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
+/* Copyright 2014 Mozilla Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/* globals PDFJS, Util, AnnotationType */
+
+'use strict';
+
+var HIGHLIGHT_OFFSET = 4; // px
+var ANNOT_MIN_SIZE = 10; // px
+
+var AnnotationUtils = (function AnnotationUtilsClosure() {
+  // TODO(mack): This dupes some of the logic in CanvasGraphics.setFont()
+  function setTextStyles(element, item, fontObj) {
+
+    var style = element.style;
+    style.fontSize = item.fontSize + 'px';
+    style.direction = item.fontDirection < 0 ? 'rtl': 'ltr';
+
+    if (!fontObj) {
+      return;
+    }
+
+    style.fontWeight = fontObj.black ?
+      (fontObj.bold ? 'bolder' : 'bold') :
+      (fontObj.bold ? 'bold' : 'normal');
+    style.fontStyle = fontObj.italic ? 'italic' : 'normal';
+
+    var fontName = fontObj.loadedName;
+    var fontFamily = fontName ? '"' + fontName + '", ' : '';
+    // Use a reasonable default font if the font doesn't specify a fallback
+    var fallbackName = fontObj.fallbackName || 'Helvetica, sans-serif';
+    style.fontFamily = fontFamily + fallbackName;
+  }
+
+  // TODO(mack): Remove this, it's not really that helpful.
+  function getEmptyContainer(tagName, rect, borderWidth) {
+    var bWidth = borderWidth || 0;
+    var element = document.createElement(tagName);
+    element.style.borderWidth = bWidth + 'px';
+    var width = rect[2] - rect[0] - 2 * bWidth;
+    var height = rect[3] - rect[1] - 2 * bWidth;
+    element.style.width = width + 'px';
+    element.style.height = height + 'px';
+    return element;
+  }
+
+  function initContainer(item) {
+    var container = getEmptyContainer('section', item.rect, item.borderWidth);
+    container.style.backgroundColor = item.color;
+
+    var color = item.color;
+    var rgb = [];
+    for (var i = 0; i < 3; ++i) {
+      rgb[i] = Math.round(color[i] * 255);
+    }
+    item.colorCssRgb = Util.makeCssRgb(rgb);
+
+    var highlight = document.createElement('div');
+    highlight.className = 'annotationHighlight';
+    highlight.style.left = highlight.style.top = -HIGHLIGHT_OFFSET + 'px';
+    highlight.style.right = highlight.style.bottom = -HIGHLIGHT_OFFSET + 'px';
+    highlight.setAttribute('hidden', true);
+
+    item.highlightElement = highlight;
+    container.appendChild(item.highlightElement);
+
+    return container;
+  }
+
+  function getHtmlElementForTextWidgetAnnotation(item, commonObjs) {
+    var element = getEmptyContainer('div', item.rect, 0);
+    element.style.display = 'table';
+
+    var content = document.createElement('div');
+    content.textContent = item.fieldValue;
+    var textAlignment = item.textAlignment;
+    content.style.textAlign = ['left', 'center', 'right'][textAlignment];
+    content.style.verticalAlign = 'middle';
+    content.style.display = 'table-cell';
+
+    var fontObj = item.fontRefName ?
+      commonObjs.getData(item.fontRefName) : null;
+    setTextStyles(content, item, fontObj);
+
+    element.appendChild(content);
+
+    return element;
+  }
+
+  function getHtmlElementForTextAnnotation(item, commonObjs) {
+    var rect = item.rect;
+
+    // sanity check because of OOo-generated PDFs
+    if ((rect[3] - rect[1]) < ANNOT_MIN_SIZE) {
+      rect[3] = rect[1] + ANNOT_MIN_SIZE;
+    }
+    if ((rect[2] - rect[0]) < ANNOT_MIN_SIZE) {
+      rect[2] = rect[0] + (rect[3] - rect[1]); // make it square
+    }
+
+    var container = initContainer(item);
+    container.className = 'annotText';
+
+    var image  = document.createElement('img');
+    image.style.height = container.style.height;
+    image.style.width = container.style.width;
+    var iconName = item.name;
+    image.src = PDFJS.imageResourcesPath + 'annotation-' +
+      iconName.toLowerCase() + '.svg';
+    image.alt = '[{{type}} Annotation]';
+    image.dataset.l10nId = 'text_annotation_type';
+    image.dataset.l10nArgs = JSON.stringify({type: iconName});
+
+    var contentWrapper = document.createElement('div');
+    contentWrapper.className = 'annotTextContentWrapper';
+    contentWrapper.style.left = Math.floor(rect[2] - rect[0] + 5) + 'px';
+    contentWrapper.style.top = '-10px';
+
+    var content = document.createElement('div');
+    content.className = 'annotTextContent';
+    content.setAttribute('hidden', true);
+
+    var i, ii;
+    if (item.hasBgColor) {
+      var color = item.color;
+      var rgb = [];
+      for (i = 0; i < 3; ++i) {
+        // Enlighten the color (70%)
+        var c = Math.round(color[i] * 255);
+        rgb[i] = Math.round((255 - c) * 0.7) + c;
+      }
+      content.style.backgroundColor = Util.makeCssRgb(rgb);
+    }
+
+    var title = document.createElement('h1');
+    var text = document.createElement('p');
+    title.textContent = item.title;
+
+    if (!item.content && !item.title) {
+      content.setAttribute('hidden', true);
+    } else {
+      var e = document.createElement('span');
+      var lines = item.content.split(/(?:\r\n?|\n)/);
+      for (i = 0, ii = lines.length; i < ii; ++i) {
+        var line = lines[i];
+        e.appendChild(document.createTextNode(line));
+        if (i < (ii - 1)) {
+          e.appendChild(document.createElement('br'));
+        }
+      }
+      text.appendChild(e);
+
+      var pinned = false;
+
+      var showAnnotation = function showAnnotation(pin) {
+        if (pin) {
+          pinned = true;
+        }
+        if (content.hasAttribute('hidden')) {
+          container.style.zIndex += 1;
+          content.removeAttribute('hidden');
+        }
+      };
+
+      var hideAnnotation = function hideAnnotation(unpin) {
+        if (unpin) {
+          pinned = false;
+        }
+        if (!content.hasAttribute('hidden') && !pinned) {
+          container.style.zIndex -= 1;
+          content.setAttribute('hidden', true);
+        }
+      };
+
+      var toggleAnnotation = function toggleAnnotation() {
+        if (pinned) {
+          hideAnnotation(true);
+        } else {
+          showAnnotation(true);
+        }
+      };
+
+      image.addEventListener('click', function image_clickHandler() {
+        toggleAnnotation();
+      }, false);
+      image.addEventListener('mouseover', function image_mouseOverHandler() {
+        showAnnotation();
+      }, false);
+      image.addEventListener('mouseout', function image_mouseOutHandler() {
+        hideAnnotation();
+      }, false);
+
+      content.addEventListener('click', function content_clickHandler() {
+        hideAnnotation(true);
+      }, false);
+    }
+
+    content.appendChild(title);
+    content.appendChild(text);
+    contentWrapper.appendChild(content);
+    container.appendChild(image);
+    container.appendChild(contentWrapper);
+
+    return container;
+  }
+
+  function getHtmlElementForLinkAnnotation(item, commonObjs) {
+
+    var container = initContainer(item);
+    container.className = 'annotLink';
+
+    container.style.borderColor = item.colorCssRgb;
+    container.style.borderStyle = 'solid';
+
+    var link = document.createElement('a');
+    link.href = link.title = item.url || '';
+
+    container.appendChild(link);
+
+    return container;
+  }
+
+  function getHtmlElement(data, objs) {
+    switch (data.annotationType) {
+      case AnnotationType.WIDGET:
+        return getHtmlElementForTextWidgetAnnotation(data, objs);
+      case AnnotationType.TEXT:
+        return getHtmlElementForTextAnnotation(data, objs);
+      case AnnotationType.LINK:
+        return getHtmlElementForLinkAnnotation(data, objs);
+      default:
+        throw new Error('Unsupported annotationType: ' + data.annotationType);
+    }
+  }
+
+  return {
+    getHtmlElement: getHtmlElement
+  };
+})();
diff --git a/src/shared/util.js b/src/shared/util.js
index e434891..3e47b78 100644
--- a/src/shared/util.js
+++ b/src/shared/util.js
@@ -44,6 +44,12 @@ var ImageKind = {
   RGBA_32BPP: 3
 };
 
+var AnnotationType = {
+  WIDGET: 1,
+  TEXT: 2,
+  LINK: 3
+};
+
 var StreamType = {
   UNKNOWN: 0,
   FLATE: 1,
diff --git a/src/worker_loader.js b/src/worker_loader.js
index 6a8ddbf..627aaec 100644
--- a/src/worker_loader.js
+++ b/src/worker_loader.js
@@ -20,8 +20,7 @@
 
 // List of shared files to include;
 var sharedFiles = [
-  'shared/util.js',
-  'shared/annotation.js'
+  'shared/util.js'
 ];
 
 // List of other files to include;
@@ -33,6 +32,7 @@ var otherFiles = [
   'core/obj.js',
   'core/charsets.js',
   'core/cidmaps.js',
+  'core/annotation.js',
   'core/function.js',
   'core/colorspace.js',
   'core/crypto.js',
diff --git a/test/font/font_test.html b/test/font/font_test.html
index 743363f..d0575ff 100644
--- a/test/font/font_test.html
+++ b/test/font/font_test.html
@@ -21,7 +21,7 @@
   <script src="../../src/display/canvas.js"></script>
   <script src="../../src/display/webgl.js"></script>
   <script src="../../src/core/obj.js"></script>
-  <script src="../../src/shared/annotation.js"></script>
+  <script src="../../src/core/annotation.js"></script>
   <script src="../../src/core/function.js"></script>
   <script src="../../src/core/charsets.js"></script>
   <script src="../../src/core/cidmaps.js"></script>
@@ -37,6 +37,7 @@
   <script src="../../src/core/parser.js"></script>
   <script src="../../src/core/ps_parser.js"></script>
   <script src="../../src/display/pattern_helper.js"></script>
+  <script src="../../src/display/annotation_helper.js"></script>
   <script src="../../src/core/stream.js"></script>
   <script src="../../src/core/worker.js"></script>
   <script src="../../src/display/metadata.js"></script>
diff --git a/test/test_slave.html b/test/test_slave.html
index 1e03be4..1fa8345 100644
--- a/test/test_slave.html
+++ b/test/test_slave.html
@@ -20,13 +20,13 @@ limitations under the License.
     <title>pdf.js test slave</title>
     <style type="text/css"></style>
     <script src="/src/shared/util.js"></script>
-    <script src="/src/shared/annotation.js"></script>
     <script src="/src/display/api.js"></script>
     <script src="/src/display/metadata.js"></script>
     <script src="/src/display/canvas.js"></script>
     <script src="/src/display/webgl.js"></script>
     <script src="/src/display/pattern_helper.js"></script>
     <script src="/src/display/font_loader.js"></script>
+    <script src="/src/display/annotation_helper.js"></script>
     <script src="driver.js"></script>
 
     <script>
diff --git a/test/unit/unit_test.html b/test/unit/unit_test.html
index 2db04b1..0b04ff7 100644
--- a/test/unit/unit_test.html
+++ b/test/unit/unit_test.html
@@ -20,7 +20,7 @@
   <script src="../../src/display/canvas.js"></script>
   <script src="../../src/display/webgl.js"></script>
   <script src="../../src/core/obj.js"></script>
-  <script src="../../src/shared/annotation.js"></script>
+  <script src="../../src/core/annotation.js"></script>
   <script src="../../src/core/function.js"></script>
   <script src="../../src/core/charsets.js"></script>
   <script src="../../src/core/cidmaps.js"></script>
@@ -36,6 +36,7 @@
   <script src="../../src/core/parser.js"></script>
   <script src="../../src/core/ps_parser.js"></script>
   <script src="../../src/display/pattern_helper.js"></script>
+  <script src="../../src/display/annotation_helper.js"></script>
   <script src="../../src/core/stream.js"></script>
   <script src="../../src/core/worker.js"></script>
   <script src="../../src/display/metadata.js"></script>
diff --git a/web/page_view.js b/web/page_view.js
index 636e477..066e2dc 100644
--- a/web/page_view.js
+++ b/web/page_view.js
@@ -17,7 +17,7 @@
 /* globals RenderingStates, PDFView, PDFHistory, PDFFindBar, PDFJS, mozL10n,
            CustomStyle, PresentationMode, scrollIntoView, SCROLLBAR_PADDING,
            CSS_UNITS, UNKNOWN_SCALE, DEFAULT_SCALE, getOutputScale,
-           TextLayerBuilder, cache, Stats */
+           TextLayerBuilder, cache, Stats, AnnotationUtils */
 
 'use strict';
 
@@ -322,16 +322,14 @@ var PageView = function pageView(container, id, scale,
       } else {
         for (i = 0, ii = annotationsData.length; i < ii; i++) {
           data = annotationsData[i];
-          var annotation = PDFJS.Annotation.fromData(data);
-          if (!annotation || !annotation.hasHtml()) {
+          if (!data || !data.hasHtml) {
             continue;
           }
 
-          element = annotation.getHtmlElement(pdfPage.commonObjs);
+          element = AnnotationUtils.getHtmlElement(data, pdfPage.commonObjs);
           element.setAttribute('data-annotation-id', data.id);
           mozL10n.translate(element);
 
-          data = annotation.getData();
           var rect = data.rect;
           var view = pdfPage.view;
           rect = PDFJS.Util.normalizeRect([
diff --git a/web/viewer.html b/web/viewer.html
index ee75ec2..f814574 100644
--- a/web/viewer.html
+++ b/web/viewer.html
@@ -48,13 +48,13 @@ http://sourceforge.net/adobe/cmap/wiki/License/
 
 <!--#if !PRODUCTION-->
     <script src="../src/shared/util.js"></script>
-    <script src="../src/shared/annotation.js"></script>
     <script src="../src/display/api.js"></script>
     <script src="../src/display/metadata.js"></script>
     <script src="../src/display/canvas.js"></script>
     <script src="../src/display/webgl.js"></script>
     <script src="../src/display/pattern_helper.js"></script>
     <script src="../src/display/font_loader.js"></script>
+    <script src="../src/display/annotation_helper.js"></script>
     <script>PDFJS.workerSrc = '../src/worker_loader.js';</script>
 <!--#endif-->
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/pdf.js.git



More information about the Pkg-javascript-commits mailing list