]> git.parisson.com Git - pdf.js.git/commitdiff
Merge remote-tracking branch 'mozilla/master' into textsearch-1
authornotmasteryet <async.processingjs@yahoo.com>
Sun, 22 Jan 2012 19:56:56 +0000 (13:56 -0600)
committernotmasteryet <async.processingjs@yahoo.com>
Sun, 22 Jan 2012 19:56:56 +0000 (13:56 -0600)
Conflicts:
src/core.js
src/fonts.js

1  2 
src/core.js
src/evaluator.js
src/fonts.js
src/worker.js
web/viewer.css
web/viewer.html
web/viewer.js

diff --cc src/core.js
index dc46ec71733f80fa45f8c8cdefc861ef4040d039,7a9f3ee03094d12bb12c64af2bd946e7ecf7502f..5cb8b1d5273092b826f94c571a8c6f0b783fac6d
@@@ -202,12 -193,13 +193,16 @@@ var Page = (function PageClosure() 
        if (isArray(content)) {
          // fetching items
          var i, n = content.length;
 +        var streams = [];
          for (i = 0; i < n; ++i)
 -          content[i] = xref.fetchIfRef(content[i]);
 -        content = new StreamsSequenceStream(content);
 +          streams.push(xref.fetchIfRef(content[i]));
 +        content = new StreamsSequenceStream(streams);
-       } else if (isStream(content))
++      } else if (isStream(content)) {
 +        content.reset();
+       } else if (!content) {
+         // replacing non-existent page content with empty one
+         content = new Stream(new Uint8Array(0));
+       }
  
        var pe = this.pe = new PartialEvaluator(
                                  xref, handler, 'p' + this.pageNumber + '_');
Simple merge
diff --cc src/fonts.js
index 68fe9fb59069ad1ba0662f571c2c0f903f97db5e,f96c15458518c28f2d2af84a438781f4743d2458..d236289238f03cb59595f0ae2837b6b2e4113715
@@@ -2911,22 -2226,18 +2956,18 @@@ var Font = (function FontClosure() 
            if (!isNum(width))
              width = this.widths[glyphName];
            if (this.noUnicodeAdaptation) {
 -            unicode = GlyphsUnicode[glyphName] || charcode;
 +            fontChar = GlyphsUnicode[glyphName] || charcode;
              break;
            }
-           if (!this.hasEncoding) {
+           if (!this.hasEncoding || this.isSymbolicFont) {
 -            unicode = this.useToUnicode ? this.toUnicode[charcode] : charcode;
 +            fontChar = this.useToUnicode ? this.toUnicode[charcode] : charcode;
              break;
            }
-           if (this.hasShortCmap && false) {
-             var j = Encodings.MacRomanEncoding.indexOf(glyphName);
-             fontChar = j >= 0 ? j :
-               this.glyphNameMap[glyphName];
-           } else {
-             fontChar = glyphName in GlyphsUnicode ?
-               GlyphsUnicode[glyphName] :
-               this.glyphNameMap[glyphName];
-           }
+           // MacRoman encoding address by re-encoding the cmap table
 -          unicode = glyphName in GlyphsUnicode ?
++          fontChar = glyphName in GlyphsUnicode ?
+             GlyphsUnicode[glyphName] :
+             this.glyphNameMap[glyphName];
            break;
          default:
            warn('Unsupported font type: ' + this.type);
diff --cc src/worker.js
Simple merge
diff --cc web/viewer.css
Simple merge
diff --cc web/viewer.html
Simple merge
diff --cc web/viewer.js
index c8032f62d789a51d502c962a8b9d8d486e0cd2c6,b6b62af8332a891ed3610f2266e9dbe613420679..bc41e36d6664892b43839b64f9137f5b0240c483
@@@ -435,71 -453,9 +453,71 @@@ var PDFView = 
      else if (storedHash)
        this.setHash(storedHash);
      else {
-       this.setScale(scale || kDefaultScale, true);
+       this.parseScale(scale || kDefaultScale, true);
        this.page = 1;
      }
 +
 +    // loosing pdf reference here, starting text indexing in 500ms
 +    setTimeout((function loadStartTextExtraction() {
 +      this.startTextExtraction(pdf);
 +    }).bind(this), 500);
 +    delete PDFView.extractedText;
 +  },
 +
 +  startTextExtraction: function pdfViewStartTextExtraction(pdf) {
 +    var searchResults = document.getElementById('searchResults');
 +    searchResults.textContent = '';
 +
 +    pdf.textExtracted = function pdfTextExtracted(index) {
 +      PDFView.extractedText = index;
 +    };
 +    pdf.extractText();
 +  },
 +
 +  search: function pdfViewStartSearch() {
 +    function bindLink(link, pageNumber) {
 +      link.href = '#' + pageNumber;
 +      link.onclick = function searchBindLink() {
 +        PDFView.page = pageNumber;
 +        return false;
 +      };
 +    }
 +
 +    var searchResults = document.getElementById('searchResults');
 +    if (!('extractedText' in PDFView)) {
 +      // not indexed yet, repeat in 1 second
 +      searchResults.textContent = 'Searching...';
 +      setTimeout(this.search.bind(this), 1000);
 +      return;
 +    }
 +
 +    var searchTermsInput = document.getElementById('searchTermsInput');
 +    searchResults.removeAttribute('hidden');
 +    searchResults.textContent = '';
 +
 +    var terms = searchTermsInput.value;
 +    // simple search: removing spaces and hyphens, then scanning every
 +    terms = terms.replace(/\s-/g, '').toLowerCase();
 +    var index = PDFView.extractedText;
 +    var pageFound = false;
 +    for (var i = 0, ii = index.length; i < ii; i++) {
 +      var pageText = index[i].replace(/\s-/g, '').toLowerCase();
 +      var j = pageText.indexOf(terms);
 +      if (j < 0)
 +        continue;
 +
 +      var pageNumber = i + 1;
 +      var textSample = index[i].substr(j, 50);
 +      var link = document.createElement('a');
 +      bindLink(link, pageNumber);
 +      link.textContent = 'Page ' + pageNumber + ': ' + textSample;
 +      searchResults.appendChild(link);
 +
 +      pageFound = true;
 +    }
 +    if (!pageFound) {
 +      searchResults.textContent = '(Not found)';
 +    }
    },
  
    setHash: function pdfViewSetHash(hash) {