1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-26 10:08:06 +02:00

Support rendering appearance streams for annotations

This commit is contained in:
Mack Duan 2013-03-13 12:24:55 -07:00
parent 772c7894fb
commit 79831d7ec5
6 changed files with 218 additions and 5 deletions

View file

@ -100,7 +100,28 @@ function getPdf(arg, callback) {
globalScope.PDFJS.getPdf = getPdf;
globalScope.PDFJS.pdfBug = false;
var Page = (function PageClosure() {
function getDefaultAnnotationAppearance(annotationDict) {
var appearanceState = annotationDict.get('AP');
if (!isDict(appearanceState)) {
return;
}
var appearance;
var appearances = appearanceState.get('N');
if (isDict(appearances)) {
var as = annotationDict.get('AS');
if (as && appearances.has(as.name)) {
appearance = appearances.get(as.name);
}
} else {
appearance = appearances;
}
return appearance;
}
function Page(xref, pageIndex, pageDict, ref) {
this.pageIndex = pageIndex;
this.pageDict = pageDict;
@ -198,6 +219,17 @@ var Page = (function PageClosure() {
'p' + this.pageIndex + '_');
var list = pe.getOperatorList(contentStream, resources, dependency);
var annotations = this.getAnnotationsForDraw();
var annotationEvaluator = new PartialEvaluator(
xref, handler, this.pageIndex,
'p' + this.pageIndex + '_annotation');
var annotationsList = annotationEvaluator.getAnnotationsOperatorList(
annotations, dependency);
Util.concatenateToArray(list.fnArray, annotationsList.fnArray);
Util.concatenateToArray(list.argsArray, annotationsList.argsArray);
pe.optimizeQueue(list);
return list;
},
@ -227,7 +259,59 @@ var Page = (function PageClosure() {
}
return links;
},
getAnnotations: function Page_getAnnotations() {
var annotations = this.getAnnotationsBase();
var items = [];
for (var i = 0, length = annotations.length; i < length; ++i) {
items.push(annotations[i].item);
}
return items;
},
getAnnotationsForDraw: function Page_getAnnotationsForDraw() {
var annotations = this.getAnnotationsBase();
var items = [];
for (var i = 0, length = annotations.length; i < length; ++i) {
var item = annotations[i].item;
var annotationDict = annotations[i].dict;
item.annotationFlags = annotationDict.get('F');
var appearance = getDefaultAnnotationAppearance(annotationDict);
if (appearance &&
// TODO(mack): The proper implementation requires that the
// appearance stream overrides Name, but we're currently
// doing it the other way around for 'Text' annotations since we
// have special rendering for it
item.type !== 'Text') {
item.appearance = appearance;
var appearanceDict = appearance.dict;
item.resources = appearanceDict.get('Resources');
item.bbox = appearanceDict.get('BBox') || [0, 0, 1, 1];
item.matrix = appearanceDict.get('Matrix') || [1, 0, 0, 1, 0 ,0];
}
var border = annotationDict.get('BS');
if (isDict(border) && !item.appearance) {
var borderWidth = border.has('W') ? border.get('W') : 1;
if (borderWidth !== 0) {
item.border = {
width: borderWidth,
type: border.get('S') || 'S',
rgb: annotationDict.get('C') || [0, 0, 1]
};
}
}
items.push(item);
}
return items;
},
getAnnotationsBase: function Page_getAnnotationsBase() {
var xref = this.xref;
function getInheritableProperty(annotation, name) {
var item = annotation;
@ -267,11 +351,13 @@ var Page = (function PageClosure() {
var subtype = annotation.get('Subtype');
if (!isName(subtype))
continue;
var rect = annotation.get('Rect');
var item = {};
item.type = subtype.name;
item.rect = rect;
var rect = annotation.get('Rect');
item.rect = Util.normalizeRect(rect);
var includeAnnotation = true;
switch (subtype.name) {
case 'Link':
var a = annotation.get('A');
@ -316,6 +402,14 @@ var Page = (function PageClosure() {
var fieldType = getInheritableProperty(annotation, 'FT');
if (!isName(fieldType))
break;
// Do not display digital signatures since we do not currently
// validate them.
if (fieldType.name === 'Sig') {
includeAnnotation = false;
break;
}
item.fieldType = fieldType.name;
// Building the full field name by collecting the field and
// its ancestors 'T' properties and joining them using '.'.
@ -364,10 +458,18 @@ var Page = (function PageClosure() {
annotation.get('Name').name;
break;
default:
TODO('unimplemented annotation type: ' + subtype.name);
var appearance = getDefaultAnnotationAppearance(annotation);
if (!appearance) {
TODO('unimplemented annotation type: ' + subtype.name);
}
break;
}
items.push(item);
if (includeAnnotation) {
items.push({
item: item,
dict: annotation
});
}
}
return items;
}