Merge pull request #15710 from Snuffleupagus/issue-10791

Add localization support for the `annotationLayer` reference tests (issue 10791)
This commit is contained in:
Tim van der Meij 2022-11-19 11:25:15 +01:00 committed by GitHub
commit ae7c97aef8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 5 deletions

View File

@ -27,7 +27,8 @@ const {
shadow, shadow,
XfaLayer, XfaLayer,
} = pdfjsLib; } = pdfjsLib;
const { parseQueryString, SimpleLinkService } = pdfjsViewer; const { GenericL10n, NullL10n, parseQueryString, SimpleLinkService } =
pdfjsViewer;
const WAITING_TIME = 100; // ms const WAITING_TIME = 100; // ms
const CMAP_URL = "/build/generic/web/cmaps/"; const CMAP_URL = "/build/generic/web/cmaps/";
@ -35,6 +36,7 @@ const CMAP_PACKED = true;
const STANDARD_FONT_DATA_URL = "/build/generic/web/standard_fonts/"; const STANDARD_FONT_DATA_URL = "/build/generic/web/standard_fonts/";
const IMAGE_RESOURCES_PATH = "/web/images/"; const IMAGE_RESOURCES_PATH = "/web/images/";
const VIEWER_CSS = "../build/components/pdf_viewer.css"; const VIEWER_CSS = "../build/components/pdf_viewer.css";
const VIEWER_LOCALE = "en-US";
const WORKER_SRC = "../build/generic/build/pdf.worker.js"; const WORKER_SRC = "../build/generic/build/pdf.worker.js";
const RENDER_TASK_ON_CONTINUE_DELAY = 5; // ms const RENDER_TASK_ON_CONTINUE_DELAY = 5; // ms
const SVG_NS = "http://www.w3.org/2000/svg"; const SVG_NS = "http://www.w3.org/2000/svg";
@ -203,7 +205,8 @@ class Rasterize {
annotationCanvasMap, annotationCanvasMap,
page, page,
imageResourcesPath, imageResourcesPath,
renderForms = false renderForms = false,
l10n = NullL10n
) { ) {
try { try {
const { svg, foreignObject, style, div } = this.createContainer(viewport); const { svg, foreignObject, style, div } = this.createContainer(viewport);
@ -232,6 +235,7 @@ class Rasterize {
annotationCanvasMap: annotationImageMap, annotationCanvasMap: annotationImageMap,
}; };
AnnotationLayer.render(parameters); AnnotationLayer.render(parameters);
await l10n.translate(div);
// Inline SVG images from text annotations. // Inline SVG images from text annotations.
await inlineImages(div); await inlineImages(div);
@ -324,6 +328,8 @@ class Driver {
// Configure the global worker options. // Configure the global worker options.
GlobalWorkerOptions.workerSrc = WORKER_SRC; GlobalWorkerOptions.workerSrc = WORKER_SRC;
this._l10n = new GenericL10n(VIEWER_LOCALE);
// Set the passed options // Set the passed options
this.inflight = options.inflight; this.inflight = options.inflight;
this.disableScrolling = options.disableScrolling; this.disableScrolling = options.disableScrolling;
@ -794,7 +800,7 @@ class Driver {
this._snapshot(task, error); this._snapshot(task, error);
}; };
initPromise initPromise
.then(function (data) { .then(data => {
const renderTask = page.render(renderContext); const renderTask = page.render(renderContext);
if (task.renderTaskOnContinue) { if (task.renderTaskOnContinue) {
@ -803,7 +809,7 @@ class Driver {
setTimeout(cont, RENDER_TASK_ON_CONTINUE_DELAY); setTimeout(cont, RENDER_TASK_ON_CONTINUE_DELAY);
}; };
} }
return renderTask.promise.then(function () { return renderTask.promise.then(() => {
if (annotationCanvasMap) { if (annotationCanvasMap) {
Rasterize.annotationLayer( Rasterize.annotationLayer(
annotationLayerContext, annotationLayerContext,
@ -813,7 +819,8 @@ class Driver {
annotationCanvasMap, annotationCanvasMap,
page, page,
IMAGE_RESOURCES_PATH, IMAGE_RESOURCES_PATH,
renderForms renderForms,
this._l10n
).then(() => { ).then(() => {
completeRender(false); completeRender(false);
}); });

View File

@ -21,6 +21,8 @@ limitations under the License.
<script src="../build/generic/build/pdf.js"></script> <script src="../build/generic/build/pdf.js"></script>
<script src="../build/components/pdf_viewer.js"></script> <script src="../build/components/pdf_viewer.js"></script>
<script src="driver.js"></script> <script src="driver.js"></script>
<link rel="resource" type="application/l10n" href="../build/generic/web/locale/locale.properties">
</head> </head>
<body> <body>
<p>Inflight requests: <span id="inflight"></span></p> <p>Inflight requests: <span id="inflight"></span></p>