var topLeftCorner = this.rotatePoint(rect[0], rect[1]);
var bottomRightCorner = this.rotatePoint(rect[2], rect[3]);
- var link = {};
- link.x = Math.min(topLeftCorner.x, bottomRightCorner.x);
- link.y = Math.min(topLeftCorner.y, bottomRightCorner.y);
- link.width = Math.abs(topLeftCorner.x - bottomRightCorner.x);
- link.height = Math.abs(topLeftCorner.y - bottomRightCorner.y);
- var a = this.xref.fetchIfRef(annotation.get('A'));
- if (a) {
- switch (a.get('S').name) {
- case 'URI':
- link.url = a.get('URI');
+ var item = {};
+ item.type = subtype.name;
+ item.x = Math.min(topLeftCorner.x, bottomRightCorner.x);
+ item.y = Math.min(topLeftCorner.y, bottomRightCorner.y);
+ item.width = Math.abs(topLeftCorner.x - bottomRightCorner.x);
+ item.height = Math.abs(topLeftCorner.y - bottomRightCorner.y);
+ switch (subtype.name) {
+ case 'Link':
+ var a = this.xref.fetchIfRef(annotation.get('A'));
+ if (a) {
+ switch (a.get('S').name) {
+ case 'URI':
+ link.url = a.get('URI');
+ break;
+ case 'GoTo':
+ link.dest = a.get('D');
+ break;
+ default:
+ TODO('other link types');
+ }
+ } else if (annotation.has('Dest')) {
+ // simple destination link
+ var dest = annotation.get('Dest');
+ link.dest = isName(dest) ? dest.name : dest;
+ }
+ break;
+ case 'Widget':
+ var fieldType = getInheritableProperty(annotation, 'FT');
+ if (!isName(fieldType))
break;
- case 'GoTo':
- link.dest = a.get('D');
- break;
- default:
- TODO('other link types');
- }
- } else if (annotation.has('Dest')) {
- // simple destination link
- var dest = annotation.get('Dest');
- link.dest = isName(dest) ? dest.name : dest;
+ item.fieldType = fieldType.name;
+ // Building the full field name by collecting the field and
+ // its ancestors 'T' properties and joining them using '.'.
+ var fieldName = [];
+ var namedItem = annotation, ref = annotationRef;
+ while (namedItem) {
+ var parentRef = namedItem.get('Parent');
+ var parent = xref.fetchIfRef(parentRef);
+ var name = namedItem.get('T');
+ if (name)
+ fieldName.unshift(stringToPDFString(name));
+ else {
+ // The field name is absent, that means more than one field
+ // with the same name may exist. Replacing the empty name
+ // with the '`' plus index in the parent's 'Kids' array.
+ // This is not in the PDF spec but necessary to id the
+ // the input controls.
+ var kids = xref.fetchIfRef(parent.get('Kids'));
+ var j, jj;
+ for (j = 0, jj = kids.length; j < jj; j++) {
+ if (kids[j].num == ref.num && kids[j].gen == ref.gen)
+ break;
+ }
+ fieldName.unshift('`' + j);
+ }
+ namedItem = parent;
+ ref = parentRef;
+ }
+ item.fullName = fieldName.join('.');
+ var alternativeText = stringToPDFString(annotation.get('TU') || '');
+ item.alternativeText = alternativeText;
+ var da = getInheritableProperty(annotation, 'DA') || '';
+ var m = /([\d\.]+)\sTf/.exec(da);
+ if (m)
+ item.fontSize = parseFloat(m[1]);
+ item.textAlignment = getInheritableProperty(annotation, 'Q');
+ item.flags = getInheritableProperty(annotation, 'Ff') || 0;
+ break;
}
- links.push(link);
+ items.push(item);
}
- return links;
+ return items;
},
- startRendering: function pageStartRendering(ctx, callback) {
+ startRendering: function pageStartRendering(ctx, callback, textLayer) {
this.ctx = ctx;
this.callback = callback;
+ this.textLayer = textLayer;
this.startRenderingTime = Date.now();
this.pdf.startRendering(this);
while (div.hasChildNodes())
div.removeChild(div.lastChild);
div.removeAttribute('data-loaded');
+
+ delete this.canvas;
};
- function setupLinks(content, scale) {
+ function setupAnnotations(content, scale) {
function bindLink(link, dest) {
link.href = PDFView.getDestinationHash(dest);
link.onclick = function pageViewSetupLinksOnclick() {
ctx.translate(-this.x * scale, -this.y * scale);
stats.begin = Date.now();
- this.content.startRendering(ctx, this.updateStats);
+ this.content.startRendering(ctx,
+ (function pageViewDrawCallback(error) {
+ if (error)
+ PDFView.error('An error occurred while rendering the page.', error);
+ this.updateStats();
+ if (this.onAfterDraw)
+ this.onAfterDraw();
+ }).bind(this), textLayer
+ );
- setupLinks(this.content, this.scale);
+ setupAnnotations(this.content, this.scale);
div.setAttribute('data-loaded', true);
return true;