From: notmasteryet Date: Mon, 5 Dec 2011 23:01:45 +0000 (-0600) Subject: Merge branch 'master' of git://github.com/mozilla/pdf.js.git into forms-1 X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=dbf869f19537dda6b47be3ae1d8b70569147b22c;p=pdf.js.git Merge branch 'master' of git://github.com/mozilla/pdf.js.git into forms-1 Conflicts: web/viewer.css --- dbf869f19537dda6b47be3ae1d8b70569147b22c diff --cc src/core.js index 8ec227a,284b3cb..d6d70a2 --- a/src/core.js +++ b/src/core.js @@@ -299,82 -287,36 +309,83 @@@ var Page = (function pagePage() 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); diff --cc web/viewer.css index bc38d7f,a1ef928..28418f2 --- a/web/viewer.css +++ b/web/viewer.css @@@ -232,23 -232,27 +232,44 @@@ canvas -webkit-box-shadow: 0px 2px 10px #ff0; } +.page > .inputHint { + opacity: 0.2; + background: #ccc; + position: absolute; +} + +.page > .inputControl { + background: transparent; + border: 0px none; + position: absolute; + margin: auto; +} + +.page > .inputControl[type='checkbox'] { + margin: 0px; +} + + .textLayer { + position: absolute; + left: 0; + top: 0; + right: 0; + bottom: 0; + color: #000; + } + + .textLayer > div { + color: transparent; + position: absolute; + line-height:1.3; + } + + /* TODO: file FF bug to support ::-moz-selection:window-inactive + so we can override the opaque grey background when the window is inactive; + see https://bugzilla.mozilla.org/show_bug.cgi?id=706209 */ + ::selection { background:rgba(0,0,255,0.3); } + ::-moz-selection { background:rgba(0,0,255,0.3); } + #viewer { margin: 44px 0px 0px; padding: 8px 0px; diff --cc web/viewer.js index 6f052ba,5cccd61..970833e --- a/web/viewer.js +++ b/web/viewer.js @@@ -361,9 -425,11 +426,11 @@@ var PageView = function pageView(contai 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() { @@@ -563,9 -559,17 +635,17 @@@ 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;