From: notmasteryet Date: Sun, 22 Jan 2012 19:56:56 +0000 (-0600) Subject: Merge remote-tracking branch 'mozilla/master' into textsearch-1 X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=1ac24dbc015989fff82b1224ab587334c377608a;p=pdf.js.git Merge remote-tracking branch 'mozilla/master' into textsearch-1 Conflicts: src/core.js src/fonts.js --- 1ac24dbc015989fff82b1224ab587334c377608a diff --cc src/core.js index dc46ec7,7a9f3ee..5cb8b1d --- a/src/core.js +++ b/src/core.js @@@ -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 + '_'); diff --cc src/fonts.js index 68fe9fb,f96c154..d236289 --- a/src/fonts.js +++ b/src/fonts.js @@@ -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 web/viewer.js index c8032f6,b6b62af..bc41e36 --- a/web/viewer.js +++ b/web/viewer.js @@@ -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) {