Merge remote branch 'upstream/master'
This commit is contained in:
		
						commit
						0c091ca855
					
				
							
								
								
									
										4
									
								
								pdf.js
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								pdf.js
									
									
									
									
									
								
							@ -5480,8 +5480,8 @@ var DeviceGrayCS = (function() {
 | 
				
			|||||||
    },
 | 
					    },
 | 
				
			||||||
    getRgbBuffer: function graycs_getRgbBuffer(input, bits) {
 | 
					    getRgbBuffer: function graycs_getRgbBuffer(input, bits) {
 | 
				
			||||||
      var scale = 255 / ((1 << bits) - 1);
 | 
					      var scale = 255 / ((1 << bits) - 1);
 | 
				
			||||||
      var length = input.length * 3;
 | 
					      var length = input.length;
 | 
				
			||||||
      var rgbBuf = new Uint8Array(length);
 | 
					      var rgbBuf = new Uint8Array(length * 3);
 | 
				
			||||||
      for (var i = 0, j = 0; i < length; ++i) {
 | 
					      for (var i = 0, j = 0; i < length; ++i) {
 | 
				
			||||||
        var c = (scale * input[i]) | 0;
 | 
					        var c = (scale * input[i]) | 0;
 | 
				
			||||||
        rgbBuf[j++] = c;
 | 
					        rgbBuf[j++] = c;
 | 
				
			||||||
 | 
				
			|||||||
@ -126,14 +126,15 @@ class PDFTestHandler(BaseHTTPRequestHandler):
 | 
				
			|||||||
        self.wfile.write("<html><body><h1>PDFs of " + path + "</h1>\n")
 | 
					        self.wfile.write("<html><body><h1>PDFs of " + path + "</h1>\n")
 | 
				
			||||||
        for filename in os.listdir(location):
 | 
					        for filename in os.listdir(location):
 | 
				
			||||||
          if filename.lower().endswith('.pdf'):
 | 
					          if filename.lower().endswith('.pdf'):
 | 
				
			||||||
            self.wfile.write("<a href='/web/viewer.html?file=" + path + filename + "' target=pdf>" +
 | 
					            self.wfile.write("<a href='/web/viewer.html?file=" +
 | 
				
			||||||
 | 
					              urllib.quote_plus(path + filename, '/') + "' target=pdf>" +
 | 
				
			||||||
              filename + "</a><br>\n")
 | 
					              filename + "</a><br>\n")
 | 
				
			||||||
        self.wfile.write("</body></html>")
 | 
					        self.wfile.write("</body></html>")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def do_GET(self):
 | 
					    def do_GET(self):
 | 
				
			||||||
        url = urlparse(self.path)
 | 
					        url = urlparse(self.path)
 | 
				
			||||||
        # Ignore query string
 | 
					        # Ignore query string
 | 
				
			||||||
        path, _ = url.path, url.query
 | 
					        path, _ = urllib.unquote_plus(url.path), url.query
 | 
				
			||||||
        path = os.path.abspath(os.path.realpath(DOC_ROOT + os.sep + path))
 | 
					        path = os.path.abspath(os.path.realpath(DOC_ROOT + os.sep + path))
 | 
				
			||||||
        prefix = os.path.commonprefix(( path, DOC_ROOT ))
 | 
					        prefix = os.path.commonprefix(( path, DOC_ROOT ))
 | 
				
			||||||
        _, ext = os.path.splitext(path.lower())
 | 
					        _, ext = os.path.splitext(path.lower())
 | 
				
			||||||
 | 
				
			|||||||
@ -8,6 +8,8 @@ var kDefaultScale = 1.5;
 | 
				
			|||||||
var kDefaultScaleDelta = 1.1;
 | 
					var kDefaultScaleDelta = 1.1;
 | 
				
			||||||
var kCacheSize = 20;
 | 
					var kCacheSize = 20;
 | 
				
			||||||
var kCssUnits = 96.0 / 72.0;
 | 
					var kCssUnits = 96.0 / 72.0;
 | 
				
			||||||
 | 
					var kScrollbarPadding = 40;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var Cache = function(size) {
 | 
					var Cache = function(size) {
 | 
				
			||||||
  var data = [];
 | 
					  var data = [];
 | 
				
			||||||
@ -44,7 +46,7 @@ var PDFView = {
 | 
				
			|||||||
    window.dispatchEvent(event);
 | 
					    window.dispatchEvent(event);
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  parseScale: function(value) {
 | 
					  parseScale: function(value, resetAutoSettings) {
 | 
				
			||||||
    if ('custom' == value)
 | 
					    if ('custom' == value)
 | 
				
			||||||
      return;
 | 
					      return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -55,15 +57,18 @@ var PDFView = {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    var currentPage = this.pages[this.page - 1];
 | 
					    var currentPage = this.pages[this.page - 1];
 | 
				
			||||||
    var scrollbarPadding = 40;
 | 
					    var pageWidthScale = (window.innerWidth - kScrollbarPadding) /
 | 
				
			||||||
    var pageWidthScale = (window.innerWidth - scrollbarPadding) /
 | 
					 | 
				
			||||||
      currentPage.width / kCssUnits;
 | 
					      currentPage.width / kCssUnits;
 | 
				
			||||||
    var pageHeightScale = (window.innerHeight - scrollbarPadding) /
 | 
					    var pageHeightScale = (window.innerHeight - kScrollbarPadding) /
 | 
				
			||||||
      currentPage.height / kCssUnits;
 | 
					      currentPage.height / kCssUnits;
 | 
				
			||||||
    if ('page-width' == value)
 | 
					    if ('page-width' == value)
 | 
				
			||||||
      this.setScale(pageWidthScale);
 | 
					      this.setScale(pageWidthScale, resetAutoSettings);
 | 
				
			||||||
    else if ('page-fit' == value)
 | 
					    if ('page-height' == value)
 | 
				
			||||||
      this.setScale(Math.min(pageWidthScale, pageHeightScale));
 | 
					      this.setScale(pageHeightScale, resetAutoSettings);
 | 
				
			||||||
 | 
					    if ('page-fit' == value) {
 | 
				
			||||||
 | 
					      this.setScale(
 | 
				
			||||||
 | 
					        Math.min(pageWidthScale, pageHeightScale), resetAutoSettings);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  zoomIn: function() {
 | 
					  zoomIn: function() {
 | 
				
			||||||
@ -130,8 +135,8 @@ var PDFView = {
 | 
				
			|||||||
      this.pagesRefMap[destRef.num + ' ' + destRef.gen + ' R'] : (destRef + 1);
 | 
					      this.pagesRefMap[destRef.num + ' ' + destRef.gen + ' R'] : (destRef + 1);
 | 
				
			||||||
    if (pageNumber) {
 | 
					    if (pageNumber) {
 | 
				
			||||||
      this.page = pageNumber;
 | 
					      this.page = pageNumber;
 | 
				
			||||||
      // TODO scroll to specific region on the page, the precise scaling
 | 
					      var currentPage = this.pages[pageNumber - 1];
 | 
				
			||||||
      // required.
 | 
					      currentPage.scrollIntoView(dest);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -267,11 +272,80 @@ var PageView = function(container, content, id, width, height,
 | 
				
			|||||||
      link.style.width = Math.ceil(links[i].width * scale) + 'px';
 | 
					      link.style.width = Math.ceil(links[i].width * scale) + 'px';
 | 
				
			||||||
      link.style.height = Math.ceil(links[i].height * scale) + 'px';
 | 
					      link.style.height = Math.ceil(links[i].height * scale) + 'px';
 | 
				
			||||||
      link.href = links[i].url || '';
 | 
					      link.href = links[i].url || '';
 | 
				
			||||||
      bindLink(link, ('dest' in links[i]) ? links[i].dest : null);
 | 
					      if (!links[i].url)
 | 
				
			||||||
 | 
					        bindLink(link, ('dest' in links[i]) ? links[i].dest : null);
 | 
				
			||||||
      div.appendChild(link);
 | 
					      div.appendChild(link);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  this.scrollIntoView = function(dest) {
 | 
				
			||||||
 | 
					      var x = 0, y = 0;
 | 
				
			||||||
 | 
					      var width = 0, height = 0, widthScale, heightScale;
 | 
				
			||||||
 | 
					      var scale = 0;
 | 
				
			||||||
 | 
					      switch (dest[1].name) {
 | 
				
			||||||
 | 
					        default:
 | 
				
			||||||
 | 
					          return;
 | 
				
			||||||
 | 
					        case 'XYZ':
 | 
				
			||||||
 | 
					          x = dest[2];
 | 
				
			||||||
 | 
					          y = dest[3];
 | 
				
			||||||
 | 
					          scale = dest[4];
 | 
				
			||||||
 | 
					          break;
 | 
				
			||||||
 | 
					        case 'Fit':
 | 
				
			||||||
 | 
					        case 'FitB':
 | 
				
			||||||
 | 
					          scale = 'page-fit';
 | 
				
			||||||
 | 
					          break;
 | 
				
			||||||
 | 
					        case 'FitH':
 | 
				
			||||||
 | 
					        case 'FitBH':
 | 
				
			||||||
 | 
					          y = dest[2];
 | 
				
			||||||
 | 
					          scale = 'page-width';
 | 
				
			||||||
 | 
					          break;
 | 
				
			||||||
 | 
					        case 'FitV':
 | 
				
			||||||
 | 
					        case 'FitBV':
 | 
				
			||||||
 | 
					          x = dest[2];
 | 
				
			||||||
 | 
					          scale = 'page-height';
 | 
				
			||||||
 | 
					          break;
 | 
				
			||||||
 | 
					        case 'FitR':
 | 
				
			||||||
 | 
					          x = dest[2];
 | 
				
			||||||
 | 
					          y = dest[3];
 | 
				
			||||||
 | 
					          width = dest[4] - x;
 | 
				
			||||||
 | 
					          height = dest[5] - y;
 | 
				
			||||||
 | 
					          widthScale = (window.innerWidth - kScrollbarPadding) /
 | 
				
			||||||
 | 
					            width / kCssUnits;
 | 
				
			||||||
 | 
					          heightScale = (window.innerHeight - kScrollbarPadding) /
 | 
				
			||||||
 | 
					            height / kCssUnits;
 | 
				
			||||||
 | 
					          scale = Math.min(widthScale, heightScale);
 | 
				
			||||||
 | 
					          break;
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      var boundingRect = [
 | 
				
			||||||
 | 
					        this.content.rotatePoint(x, y),
 | 
				
			||||||
 | 
					        this.content.rotatePoint(x + width, y + height)
 | 
				
			||||||
 | 
					      ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      if (scale)
 | 
				
			||||||
 | 
					        PDFView.setScale(scale, true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      setTimeout(function() {
 | 
				
			||||||
 | 
					        // letting page to re-layout before scrolling
 | 
				
			||||||
 | 
					        var scale = PDFView.currentScale;
 | 
				
			||||||
 | 
					        var x = Math.min(boundingRect[0].x, boundingRect[1].x);
 | 
				
			||||||
 | 
					        var y = Math.min(boundingRect[0].y, boundingRect[1].y);
 | 
				
			||||||
 | 
					        var width = Math.abs(boundingRect[0].x - boundingRect[1].x);
 | 
				
			||||||
 | 
					        var height = Math.abs(boundingRect[0].y - boundingRect[1].y);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // using temporary div to scroll it into view
 | 
				
			||||||
 | 
					        var tempDiv = document.createElement('div');
 | 
				
			||||||
 | 
					        tempDiv.style.position = 'absolute';
 | 
				
			||||||
 | 
					        tempDiv.style.left = Math.floor(x * scale) + 'px';
 | 
				
			||||||
 | 
					        tempDiv.style.top = Math.floor(y * scale) + 'px';
 | 
				
			||||||
 | 
					        tempDiv.style.width = Math.ceil(width * scale) + 'px';
 | 
				
			||||||
 | 
					        tempDiv.style.height = Math.ceil(height * scale) + 'px';
 | 
				
			||||||
 | 
					        div.appendChild(tempDiv);
 | 
				
			||||||
 | 
					        tempDiv.scrollIntoView(true);
 | 
				
			||||||
 | 
					        div.removeChild(tempDiv);
 | 
				
			||||||
 | 
					      }, 0);
 | 
				
			||||||
 | 
					  };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  this.draw = function() {
 | 
					  this.draw = function() {
 | 
				
			||||||
    if (div.hasChildNodes()) {
 | 
					    if (div.hasChildNodes()) {
 | 
				
			||||||
      this.updateStats();
 | 
					      this.updateStats();
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user