]> git.parisson.com Git - pdf.js.git/commitdiff
Merge branch 'master' of git://github.com/mozilla/pdf.js.git into forms-1
authornotmasteryet <async.processingjs@yahoo.com>
Mon, 5 Dec 2011 23:01:45 +0000 (17:01 -0600)
committernotmasteryet <async.processingjs@yahoo.com>
Mon, 5 Dec 2011 23:01:45 +0000 (17:01 -0600)
Conflicts:
web/viewer.css

1  2 
src/core.js
web/viewer.css
web/viewer.js

diff --cc src/core.js
index 8ec227a362f1d8418296ce5585e004e82a71f6cd,284b3cb4021af57e1c5a56e3fbc467e1c9f34c19..d6d70a2ed0e5516c2d09977d61c661f527653943
@@@ -299,82 -287,36 +309,83 @@@ var Page = (function pagePage() 
          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');
 +        var item = {};
 +        item.type = subtype.name;
 +        item.x = Math.min(topLeftCorner.x, bottomRightCorner.x);
 +        item.y = Math.min(topLeftCorner.y, bottomRightCorner.y);
 +        item.width = Math.abs(topLeftCorner.x - bottomRightCorner.x);
 +        item.height = Math.abs(topLeftCorner.y - bottomRightCorner.y);
 +        switch (subtype.name) {
 +          case 'Link':
 +            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;
 +            }
 +            break;
 +          case 'Widget':
 +            var fieldType = getInheritableProperty(annotation, 'FT');
 +            if (!isName(fieldType))
                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;
 +            item.fieldType = fieldType.name;
 +            // Building the full field name by collecting the field and
 +            // its ancestors 'T' properties and joining them using '.'.
 +            var fieldName = [];
 +            var namedItem = annotation, ref = annotationRef;
 +            while (namedItem) {
 +              var parentRef = namedItem.get('Parent');
 +              var parent = xref.fetchIfRef(parentRef);
 +              var name = namedItem.get('T');
 +              if (name)
 +                fieldName.unshift(stringToPDFString(name));
 +              else {
 +                // The field name is absent, that means more than one field
 +                // with the same name may exist. Replacing the empty name
 +                // with the '`' plus index in the parent's 'Kids' array.
 +                // This is not in the PDF spec but necessary to id the
 +                // the input controls.
 +                var kids = xref.fetchIfRef(parent.get('Kids'));
 +                var j, jj;
 +                for (j = 0, jj = kids.length; j < jj; j++) {
 +                  if (kids[j].num == ref.num && kids[j].gen == ref.gen)
 +                    break;
 +                }
 +                fieldName.unshift('`' + j);
 +              }
 +              namedItem = parent;
 +              ref = parentRef;
 +            }
 +            item.fullName = fieldName.join('.');
 +            var alternativeText = stringToPDFString(annotation.get('TU') || '');
 +            item.alternativeText = alternativeText;
 +            var da = getInheritableProperty(annotation, 'DA') || '';
 +            var m = /([\d\.]+)\sTf/.exec(da);
 +            if (m)
 +              item.fontSize = parseFloat(m[1]);
 +            item.textAlignment = getInheritableProperty(annotation, 'Q');
 +            item.flags = getInheritableProperty(annotation, 'Ff') || 0;
 +            break;
          }
 -        links.push(link);
 +        items.push(item);
        }
 -      return links;
 +      return items;
      },
-     startRendering: function pageStartRendering(ctx, callback)  {
+     startRendering: function pageStartRendering(ctx, callback, textLayer)  {
        this.ctx = ctx;
        this.callback = callback;
+       this.textLayer = textLayer;
  
        this.startRenderingTime = Date.now();
        this.pdf.startRendering(this);
diff --cc web/viewer.css
index bc38d7fda88d9cbfa6d41012984586202ab73843,a1ef928104ea2d45978319fa6556f8cb9e830901..28418f290480cc80e638037435e7304429d05f49
@@@ -232,23 -232,27 +232,44 @@@ canvas 
    -webkit-box-shadow: 0px 2px 10px #ff0;
  }
  
 +.page > .inputHint {
 +  opacity: 0.2;
 +  background: #ccc;
 +  position: absolute;
 +}
 +
 +.page > .inputControl {
 +  background: transparent;
 +  border: 0px none;
 +  position: absolute;
 +  margin: auto;
 +}
 +
 +.page > .inputControl[type='checkbox'] {
 +  margin: 0px;
 +}
 +
+ .textLayer {
+   position: absolute;
+   left: 0;
+   top: 0;
+   right: 0;
+   bottom: 0;
+   color: #000;
+ }
+ .textLayer > div {
+   color: transparent;
+   position: absolute;
+   line-height:1.3;
+ }
+ /* TODO: file FF bug to support ::-moz-selection:window-inactive
+    so we can override the opaque grey background when the window is inactive;
+    see https://bugzilla.mozilla.org/show_bug.cgi?id=706209 */
+ ::selection { background:rgba(0,0,255,0.3); }
+ ::-moz-selection { background:rgba(0,0,255,0.3); }
  #viewer {
    margin: 44px 0px 0px;
    padding: 8px 0px;
diff --cc web/viewer.js
index 6f052ba85a39c79126d55bab4049a0ea589e4aa8,5cccd61f1e75a169f7bd927641be8435945ac9c9..970833e11152a7424ac344868381339a52b94aa9
@@@ -361,9 -425,11 +426,11 @@@ var PageView = function pageView(contai
      while (div.hasChildNodes())
        div.removeChild(div.lastChild);
      div.removeAttribute('data-loaded');
+     delete this.canvas;
    };
  
 -  function setupLinks(content, scale) {
 +  function setupAnnotations(content, scale) {
      function bindLink(link, dest) {
        link.href = PDFView.getDestinationHash(dest);
        link.onclick = function pageViewSetupLinksOnclick() {
      ctx.translate(-this.x * scale, -this.y * scale);
  
      stats.begin = Date.now();
-     this.content.startRendering(ctx, this.updateStats);
+     this.content.startRendering(ctx,
+       (function pageViewDrawCallback(error) {
+         if (error)
+           PDFView.error('An error occurred while rendering the page.', error);
+         this.updateStats();
+         if (this.onAfterDraw)
+           this.onAfterDraw();
+       }).bind(this), textLayer
+     );
  
 -    setupLinks(this.content, this.scale);
 +    setupAnnotations(this.content, this.scale);
      div.setAttribute('data-loaded', true);
  
      return true;