mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-26 10:08:06 +02:00
[Annotation] Add a div containing the text of a FreeText annotation (bug 1780375)
An annotation doesn't have to be in the text flow, hence it's likely a bad idea to insert its text in the text layer. But the text must be visible from a screen reader point of view so it must somewhere in the DOM. So with this patch, the text from a FreeText annotation is extracted and added in a div in its HTML counterpart, and with the patch #15237 the text should be visible and positioned relatively to the text flow.
This commit is contained in:
parent
159f853e06
commit
31155740c3
7 changed files with 178 additions and 20 deletions
|
@ -578,30 +578,56 @@ class Page {
|
|||
return tree;
|
||||
}
|
||||
|
||||
getAnnotationsData(intent) {
|
||||
return this._parsedAnnotations.then(function (annotations) {
|
||||
const annotationsData = [];
|
||||
async getAnnotationsData(handler, task, intent) {
|
||||
const annotations = await this._parsedAnnotations;
|
||||
if (annotations.length === 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (annotations.length === 0) {
|
||||
return annotationsData;
|
||||
const textContentPromises = [];
|
||||
const annotationsData = [];
|
||||
let partialEvaluator;
|
||||
|
||||
const intentAny = !!(intent & RenderingIntentFlag.ANY),
|
||||
intentDisplay = !!(intent & RenderingIntentFlag.DISPLAY),
|
||||
intentPrint = !!(intent & RenderingIntentFlag.PRINT);
|
||||
|
||||
for (const annotation of annotations) {
|
||||
// Get the annotation even if it's hidden because
|
||||
// JS can change its display.
|
||||
const isVisible = intentAny || (intentDisplay && annotation.viewable);
|
||||
if (isVisible || (intentPrint && annotation.printable)) {
|
||||
annotationsData.push(annotation.data);
|
||||
}
|
||||
const intentAny = !!(intent & RenderingIntentFlag.ANY),
|
||||
intentDisplay = !!(intent & RenderingIntentFlag.DISPLAY),
|
||||
intentPrint = !!(intent & RenderingIntentFlag.PRINT);
|
||||
|
||||
for (const annotation of annotations) {
|
||||
// Get the annotation even if it's hidden because
|
||||
// JS can change its display.
|
||||
if (
|
||||
intentAny ||
|
||||
(intentDisplay && annotation.viewable) ||
|
||||
(intentPrint && annotation.printable)
|
||||
) {
|
||||
annotationsData.push(annotation.data);
|
||||
if (annotation.hasTextContent && isVisible) {
|
||||
if (!partialEvaluator) {
|
||||
partialEvaluator = new PartialEvaluator({
|
||||
xref: this.xref,
|
||||
handler,
|
||||
pageIndex: this.pageIndex,
|
||||
idFactory: this._localIdFactory,
|
||||
fontCache: this.fontCache,
|
||||
builtInCMapCache: this.builtInCMapCache,
|
||||
standardFontDataCache: this.standardFontDataCache,
|
||||
globalImageCache: this.globalImageCache,
|
||||
options: this.evaluatorOptions,
|
||||
});
|
||||
}
|
||||
textContentPromises.push(
|
||||
annotation
|
||||
.extractTextContent(partialEvaluator, task, this.view)
|
||||
.catch(function (reason) {
|
||||
warn(
|
||||
`getAnnotationsData - ignoring textContent during "${task.name}" task: "${reason}".`
|
||||
);
|
||||
})
|
||||
);
|
||||
}
|
||||
return annotationsData;
|
||||
});
|
||||
}
|
||||
|
||||
await Promise.all(textContentPromises);
|
||||
return annotationsData;
|
||||
}
|
||||
|
||||
get annotations() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue