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 + '_');
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);
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) {