Merge pull request #18170 from Snuffleupagus/TextLayerBuilder-rm-setTextContentSource
[api-minor] Remove the `setTextContentSource` method in `TextLayerBuilder` (PR 18104 follow-up)
This commit is contained in:
commit
027ada81a7
@ -361,6 +361,14 @@ class PDFPageView {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#dispatchLayerRendered(name, error) {
|
||||||
|
this.eventBus.dispatch(name, {
|
||||||
|
source: this,
|
||||||
|
pageNumber: this.id,
|
||||||
|
error,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
async #renderAnnotationLayer() {
|
async #renderAnnotationLayer() {
|
||||||
let error = null;
|
let error = null;
|
||||||
try {
|
try {
|
||||||
@ -369,11 +377,7 @@ class PDFPageView {
|
|||||||
console.error(`#renderAnnotationLayer: "${ex}".`);
|
console.error(`#renderAnnotationLayer: "${ex}".`);
|
||||||
error = ex;
|
error = ex;
|
||||||
} finally {
|
} finally {
|
||||||
this.eventBus.dispatch("annotationlayerrendered", {
|
this.#dispatchLayerRendered("annotationlayerrendered", error);
|
||||||
source: this,
|
|
||||||
pageNumber: this.id,
|
|
||||||
error,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -385,11 +389,7 @@ class PDFPageView {
|
|||||||
console.error(`#renderAnnotationEditorLayer: "${ex}".`);
|
console.error(`#renderAnnotationEditorLayer: "${ex}".`);
|
||||||
error = ex;
|
error = ex;
|
||||||
} finally {
|
} finally {
|
||||||
this.eventBus.dispatch("annotationeditorlayerrendered", {
|
this.#dispatchLayerRendered("annotationeditorlayerrendered", error);
|
||||||
source: this,
|
|
||||||
pageNumber: this.id,
|
|
||||||
error,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -422,31 +422,18 @@ class PDFPageView {
|
|||||||
this.#addLayer(this.xfaLayer.div, "xfaLayer");
|
this.#addLayer(this.xfaLayer.div, "xfaLayer");
|
||||||
this.l10n.resume();
|
this.l10n.resume();
|
||||||
}
|
}
|
||||||
|
this.#dispatchLayerRendered("xfalayerrendered", error);
|
||||||
this.eventBus.dispatch("xfalayerrendered", {
|
|
||||||
source: this,
|
|
||||||
pageNumber: this.id,
|
|
||||||
error,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async #renderTextLayer() {
|
async #renderTextLayer() {
|
||||||
const { pdfPage, textLayer, viewport } = this;
|
if (!this.textLayer) {
|
||||||
if (!textLayer) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let error = null;
|
let error = null;
|
||||||
try {
|
try {
|
||||||
if (!textLayer.renderingDone) {
|
await this.textLayer.render(this.viewport);
|
||||||
const readableStream = pdfPage.streamTextContent({
|
|
||||||
includeMarkedContent: true,
|
|
||||||
disableNormalization: true,
|
|
||||||
});
|
|
||||||
textLayer.setTextContentSource(readableStream);
|
|
||||||
}
|
|
||||||
await textLayer.render(viewport);
|
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
if (ex instanceof AbortException) {
|
if (ex instanceof AbortException) {
|
||||||
return;
|
return;
|
||||||
@ -454,12 +441,7 @@ class PDFPageView {
|
|||||||
console.error(`#renderTextLayer: "${ex}".`);
|
console.error(`#renderTextLayer: "${ex}".`);
|
||||||
error = ex;
|
error = ex;
|
||||||
}
|
}
|
||||||
|
this.#dispatchLayerRendered("textlayerrendered", error);
|
||||||
this.eventBus.dispatch("textlayerrendered", {
|
|
||||||
source: this,
|
|
||||||
pageNumber: this.id,
|
|
||||||
error,
|
|
||||||
});
|
|
||||||
|
|
||||||
this.#renderStructTreeLayer();
|
this.#renderStructTreeLayer();
|
||||||
}
|
}
|
||||||
@ -917,6 +899,7 @@ class PDFPageView {
|
|||||||
this._accessibilityManager ||= new TextAccessibilityManager();
|
this._accessibilityManager ||= new TextAccessibilityManager();
|
||||||
|
|
||||||
this.textLayer = new TextLayerBuilder({
|
this.textLayer = new TextLayerBuilder({
|
||||||
|
pdfPage,
|
||||||
highlighter: this._textHighlighter,
|
highlighter: this._textHighlighter,
|
||||||
accessibilityManager: this._accessibilityManager,
|
accessibilityManager: this._accessibilityManager,
|
||||||
enablePermissions:
|
enablePermissions:
|
||||||
@ -1047,7 +1030,7 @@ class PDFPageView {
|
|||||||
annotationCanvasMap: this._annotationCanvasMap,
|
annotationCanvasMap: this._annotationCanvasMap,
|
||||||
pageColors,
|
pageColors,
|
||||||
};
|
};
|
||||||
const renderTask = (this.renderTask = this.pdfPage.render(renderContext));
|
const renderTask = (this.renderTask = pdfPage.render(renderContext));
|
||||||
renderTask.onContinue = renderContinueCallback;
|
renderTask.onContinue = renderContinueCallback;
|
||||||
|
|
||||||
const resultPromise = renderTask.promise.then(
|
const resultPromise = renderTask.promise.then(
|
||||||
|
|||||||
@ -13,9 +13,9 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/** @typedef {import("../src/display/api").PDFPageProxy} PDFPageProxy */
|
||||||
// eslint-disable-next-line max-len
|
// eslint-disable-next-line max-len
|
||||||
/** @typedef {import("../src/display/display_utils").PageViewport} PageViewport */
|
/** @typedef {import("../src/display/display_utils").PageViewport} PageViewport */
|
||||||
/** @typedef {import("../src/display/api").TextContent} TextContent */
|
|
||||||
/** @typedef {import("./text_highlighter").TextHighlighter} TextHighlighter */
|
/** @typedef {import("./text_highlighter").TextHighlighter} TextHighlighter */
|
||||||
// eslint-disable-next-line max-len
|
// eslint-disable-next-line max-len
|
||||||
/** @typedef {import("./text_accessibility.js").TextAccessibilityManager} TextAccessibilityManager */
|
/** @typedef {import("./text_accessibility.js").TextAccessibilityManager} TextAccessibilityManager */
|
||||||
@ -25,7 +25,8 @@ import { removeNullCharacters } from "./ui_utils.js";
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {Object} TextLayerBuilderOptions
|
* @typedef {Object} TextLayerBuilderOptions
|
||||||
* @property {TextHighlighter} highlighter - Optional object that will handle
|
* @property {PDFPageProxy} pdfPage
|
||||||
|
* @property {TextHighlighter} [highlighter] - Optional object that will handle
|
||||||
* highlighting text from the find controller.
|
* highlighting text from the find controller.
|
||||||
* @property {TextAccessibilityManager} [accessibilityManager]
|
* @property {TextAccessibilityManager} [accessibilityManager]
|
||||||
* @property {function} [onAppend]
|
* @property {function} [onAppend]
|
||||||
@ -41,7 +42,7 @@ class TextLayerBuilder {
|
|||||||
|
|
||||||
#onAppend = null;
|
#onAppend = null;
|
||||||
|
|
||||||
#textContentSource = null;
|
#renderingDone = false;
|
||||||
|
|
||||||
#textLayer = null;
|
#textLayer = null;
|
||||||
|
|
||||||
@ -50,12 +51,13 @@ class TextLayerBuilder {
|
|||||||
static #selectionChangeAbortController = null;
|
static #selectionChangeAbortController = null;
|
||||||
|
|
||||||
constructor({
|
constructor({
|
||||||
|
pdfPage,
|
||||||
highlighter = null,
|
highlighter = null,
|
||||||
accessibilityManager = null,
|
accessibilityManager = null,
|
||||||
enablePermissions = false,
|
enablePermissions = false,
|
||||||
onAppend = null,
|
onAppend = null,
|
||||||
}) {
|
}) {
|
||||||
this.renderingDone = false;
|
this.pdfPage = pdfPage;
|
||||||
this.highlighter = highlighter;
|
this.highlighter = highlighter;
|
||||||
this.accessibilityManager = accessibilityManager;
|
this.accessibilityManager = accessibilityManager;
|
||||||
this.#enablePermissions = enablePermissions === true;
|
this.#enablePermissions = enablePermissions === true;
|
||||||
@ -67,7 +69,7 @@ class TextLayerBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#finishRendering() {
|
#finishRendering() {
|
||||||
this.renderingDone = true;
|
this.#renderingDone = true;
|
||||||
|
|
||||||
const endOfContent = document.createElement("div");
|
const endOfContent = document.createElement("div");
|
||||||
endOfContent.className = "endOfContent";
|
endOfContent.className = "endOfContent";
|
||||||
@ -79,13 +81,10 @@ class TextLayerBuilder {
|
|||||||
/**
|
/**
|
||||||
* Renders the text layer.
|
* Renders the text layer.
|
||||||
* @param {PageViewport} viewport
|
* @param {PageViewport} viewport
|
||||||
|
* @param {Object} [textContentParams]
|
||||||
*/
|
*/
|
||||||
async render(viewport) {
|
async render(viewport, textContentParams = null) {
|
||||||
if (!this.#textContentSource) {
|
if (this.#renderingDone && this.#textLayer) {
|
||||||
throw new Error('No "textContentSource" parameter specified.');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.renderingDone && this.#textLayer) {
|
|
||||||
this.#textLayer.update({
|
this.#textLayer.update({
|
||||||
viewport,
|
viewport,
|
||||||
onBefore: this.hide.bind(this),
|
onBefore: this.hide.bind(this),
|
||||||
@ -96,7 +95,12 @@ class TextLayerBuilder {
|
|||||||
|
|
||||||
this.cancel();
|
this.cancel();
|
||||||
this.#textLayer = new TextLayer({
|
this.#textLayer = new TextLayer({
|
||||||
textContentSource: this.#textContentSource,
|
textContentSource: this.pdfPage.streamTextContent(
|
||||||
|
textContentParams || {
|
||||||
|
includeMarkedContent: true,
|
||||||
|
disableNormalization: true,
|
||||||
|
}
|
||||||
|
),
|
||||||
container: this.div,
|
container: this.div,
|
||||||
viewport,
|
viewport,
|
||||||
});
|
});
|
||||||
@ -115,7 +119,7 @@ class TextLayerBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
hide() {
|
hide() {
|
||||||
if (!this.div.hidden && this.renderingDone) {
|
if (!this.div.hidden && this.#renderingDone) {
|
||||||
// We turn off the highlighter in order to avoid to scroll into view an
|
// We turn off the highlighter in order to avoid to scroll into view an
|
||||||
// element of the text layer which could be hidden.
|
// element of the text layer which could be hidden.
|
||||||
this.highlighter?.disable();
|
this.highlighter?.disable();
|
||||||
@ -124,7 +128,7 @@ class TextLayerBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
show() {
|
show() {
|
||||||
if (this.div.hidden && this.renderingDone) {
|
if (this.div.hidden && this.#renderingDone) {
|
||||||
this.div.hidden = false;
|
this.div.hidden = false;
|
||||||
this.highlighter?.enable();
|
this.highlighter?.enable();
|
||||||
}
|
}
|
||||||
@ -142,14 +146,6 @@ class TextLayerBuilder {
|
|||||||
TextLayerBuilder.#removeGlobalSelectionListener(this.div);
|
TextLayerBuilder.#removeGlobalSelectionListener(this.div);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {ReadableStream | TextContent} source
|
|
||||||
*/
|
|
||||||
setTextContentSource(source) {
|
|
||||||
this.cancel();
|
|
||||||
this.#textContentSource = source;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Improves text selection by adding an additional div where the mouse was
|
* Improves text selection by adding an additional div where the mouse was
|
||||||
* clicked. This reduces flickering of the content if the mouse is slowly
|
* clicked. This reduces flickering of the content if the mouse is slowly
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user