mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-26 10:08:06 +02:00
Merge new API and text search.
This commit is contained in:
commit
92d0d1d694
9 changed files with 1786 additions and 23 deletions
|
@ -153,8 +153,9 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||
|
||||
font = xref.fetchIfRef(font) || fontRes.get(fontName);
|
||||
assertWellFormed(isDict(font));
|
||||
++self.objIdCounter;
|
||||
if (!font.translated) {
|
||||
|
||||
if (!font.loadedName) {
|
||||
++self.objIdCounter;
|
||||
font.translated = self.translateFont(font, xref, resources,
|
||||
dependency);
|
||||
if (font.translated) {
|
||||
|
@ -474,6 +475,71 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||
return queue;
|
||||
},
|
||||
|
||||
getTextContent: function partialEvaluatorGetIRQueue(stream, resources) {
|
||||
|
||||
var self = this;
|
||||
var xref = this.xref;
|
||||
|
||||
function handleSetFont(fontName, fontRef) {
|
||||
var fontRes = resources.get('Font');
|
||||
|
||||
// TODO: TOASK: Is it possible to get here? If so, what does
|
||||
// args[0].name should be like???
|
||||
assert(fontRes, 'fontRes not available');
|
||||
|
||||
fontRes = xref.fetchIfRef(fontRes);
|
||||
fontRef = fontRef || fontRes.get(fontName);
|
||||
var font = xref.fetchIfRef(fontRef), tra;
|
||||
assertWellFormed(isDict(font));
|
||||
if (!font.translated) {
|
||||
font.translated = self.translateFont(font, xref, resources);
|
||||
}
|
||||
return font;
|
||||
}
|
||||
|
||||
resources = xref.fetchIfRef(resources) || new Dict();
|
||||
|
||||
var parser = new Parser(new Lexer(stream), false);
|
||||
var res = resources;
|
||||
var args = [], obj;
|
||||
|
||||
var text = '';
|
||||
var font = null;
|
||||
while (!isEOF(obj = parser.getObj())) {
|
||||
if (isCmd(obj)) {
|
||||
var cmd = obj.cmd;
|
||||
switch (cmd) {
|
||||
case 'Tf':
|
||||
font = handleSetFont(args[0].name);
|
||||
break;
|
||||
case 'TJ':
|
||||
var items = args[0];
|
||||
for (var j = 0, jj = items.length; j < jj; j++) {
|
||||
if (typeof items[j] === 'string') {
|
||||
text += fontCharsToUnicode(items[j],
|
||||
font.translated.properties);
|
||||
} else if (items[j] < 0) {
|
||||
// making all negative offsets a space - better to have
|
||||
// a space in incorrect place than not have them at all
|
||||
text += ' ';
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'Tj':
|
||||
text += fontCharsToUnicode(args[0], font.translated.properties);
|
||||
break;
|
||||
} // switch
|
||||
|
||||
args = [];
|
||||
} else if (obj != null) {
|
||||
assertWellFormed(args.length <= 33, 'Too many arguments');
|
||||
args.push(obj);
|
||||
}
|
||||
}
|
||||
|
||||
return text;
|
||||
},
|
||||
|
||||
extractDataStructures: function
|
||||
partialEvaluatorExtractDataStructures(dict, baseDict,
|
||||
xref, properties) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue