Skip to content

Commit

Permalink
Merge pull request #15018 from Snuffleupagus/issue-15016
Browse files Browse the repository at this point in the history
Expose `TextLayerRenderTask` in the TypeScript definitions (issue 15016, PR 14013 follow-up)
  • Loading branch information
timvandermeij authored Jun 10, 2022
2 parents f0b5aee + e046b81 commit a57a4bc
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/display/text_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -857,4 +857,4 @@ function renderTextLayer(renderParameters) {
return task;
}

export { renderTextLayer };
export { renderTextLayer, TextLayerRenderTask };
2 changes: 2 additions & 0 deletions src/pdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
/** @typedef {import("./display/api").PDFPageProxy} PDFPageProxy */
/** @typedef {import("./display/api").RenderTask} RenderTask */
/** @typedef {import("./display/display_utils").PageViewport} PageViewport */
// eslint-disable-next-line max-len
/** @typedef {import("./display/text_layer").TextLayerRenderTask} TextLayerRenderTask */

import {
AnnotationEditorType,
Expand Down
1 change: 1 addition & 0 deletions test/unit/clitests.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"primitives_spec.js",
"stream_spec.js",
"struct_tree_spec.js",
"text_layer_spec.js",
"type1_parser_spec.js",
"ui_utils_spec.js",
"unicode_spec.js",
Expand Down
1 change: 1 addition & 0 deletions test/unit/jasmine-boot.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ async function initializePDFJS(callback) {
"pdfjs-test/unit/scripting_spec.js",
"pdfjs-test/unit/stream_spec.js",
"pdfjs-test/unit/struct_tree_spec.js",
"pdfjs-test/unit/text_layer_spec.js",
"pdfjs-test/unit/type1_parser_spec.js",
"pdfjs-test/unit/ui_utils_spec.js",
"pdfjs-test/unit/unicode_spec.js",
Expand Down
62 changes: 62 additions & 0 deletions test/unit/text_layer_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/* Copyright 2022 Mozilla Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import {
renderTextLayer,
TextLayerRenderTask,
} from "../../src/display/text_layer.js";
import { buildGetDocumentParams } from "./test_utils.js";
import { getDocument } from "../../src/display/api.js";
import { isNodeJS } from "../../src/shared/is_node.js";

describe("textLayer", function () {
it("creates textLayer from ReadableStream", async function () {
if (isNodeJS) {
pending("document.createDocumentFragment is not supported in Node.js.");
}
const loadingTask = getDocument(buildGetDocumentParams("basicapi.pdf"));
const pdfDocument = await loadingTask.promise;
const page = await pdfDocument.getPage(1);

const textContentItemsStr = [];

const textLayerRenderTask = renderTextLayer({
textContentStream: page.streamTextContent(),
container: document.createDocumentFragment(),
viewport: page.getViewport(),
textContentItemsStr,
});
expect(textLayerRenderTask instanceof TextLayerRenderTask).toEqual(true);

await textLayerRenderTask.promise;
expect(textContentItemsStr).toEqual([
"Table Of Content",
"",
"Chapter 1",
" ",
"..........................................................",
" ",
"2",
"",
"Paragraph 1.1",
" ",
"......................................................",
" ",
"3",
"",
"page 1 / 3",
]);
});
});

0 comments on commit a57a4bc

Please sign in to comment.