mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-08-03 04:47:21 +02:00
Compare commits
No commits in common. "af89e77124bf9ccf271d27e3d3f619ce5878c7c4" and "dea35aed4ae3a97277ed97304d16aca2037b9733" have entirely different histories.
af89e77124
...
dea35aed4a
@ -4905,13 +4905,13 @@ class StrikeOutAnnotation extends MarkupAnnotation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class StampAnnotation extends MarkupAnnotation {
|
class StampAnnotation extends MarkupAnnotation {
|
||||||
#savedHasOwnCanvas = null;
|
#savedHasOwnCanvas;
|
||||||
|
|
||||||
constructor(params) {
|
constructor(params) {
|
||||||
super(params);
|
super(params);
|
||||||
|
|
||||||
this.data.annotationType = AnnotationType.STAMP;
|
this.data.annotationType = AnnotationType.STAMP;
|
||||||
this.data.hasOwnCanvas = this.data.noRotate;
|
this.#savedHasOwnCanvas = this.data.hasOwnCanvas = this.data.noRotate;
|
||||||
this.data.isEditable = !this.data.noHTML;
|
this.data.isEditable = !this.data.noHTML;
|
||||||
// We want to be able to add mouse listeners to the annotation.
|
// We want to be able to add mouse listeners to the annotation.
|
||||||
this.data.noHTML = false;
|
this.data.noHTML = false;
|
||||||
@ -4920,18 +4920,15 @@ class StampAnnotation extends MarkupAnnotation {
|
|||||||
mustBeViewedWhenEditing(isEditing, modifiedIds = null) {
|
mustBeViewedWhenEditing(isEditing, modifiedIds = null) {
|
||||||
if (isEditing) {
|
if (isEditing) {
|
||||||
if (!this.data.isEditable) {
|
if (!this.data.isEditable) {
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
// When we're editing, we want to ensure that the stamp annotation is
|
// When we're editing, we want to ensure that the stamp annotation is
|
||||||
// drawn on a canvas in order to use it in the annotation editor layer.
|
// drawn on a canvas in order to use it in the annotation editor layer.
|
||||||
this.#savedHasOwnCanvas ??= this.data.hasOwnCanvas;
|
this.#savedHasOwnCanvas = this.data.hasOwnCanvas;
|
||||||
this.data.hasOwnCanvas = true;
|
this.data.hasOwnCanvas = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (this.#savedHasOwnCanvas !== null) {
|
this.data.hasOwnCanvas = this.#savedHasOwnCanvas;
|
||||||
this.data.hasOwnCanvas = this.#savedHasOwnCanvas;
|
|
||||||
this.#savedHasOwnCanvas = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return !modifiedIds?.has(this.data.id);
|
return !modifiedIds?.has(this.data.id);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,7 +18,6 @@ import {
|
|||||||
FeatureTest,
|
FeatureTest,
|
||||||
FormatError,
|
FormatError,
|
||||||
info,
|
info,
|
||||||
MathClamp,
|
|
||||||
shadow,
|
shadow,
|
||||||
unreachable,
|
unreachable,
|
||||||
warn,
|
warn,
|
||||||
@ -947,7 +946,7 @@ class CalRGBCS extends ColorSpace {
|
|||||||
#sRGBTransferFunction(color) {
|
#sRGBTransferFunction(color) {
|
||||||
// See http://en.wikipedia.org/wiki/SRGB.
|
// See http://en.wikipedia.org/wiki/SRGB.
|
||||||
if (color <= 0.0031308) {
|
if (color <= 0.0031308) {
|
||||||
return MathClamp(12.92 * color, 0, 1);
|
return this.#adjustToRange(0, 1, 12.92 * color);
|
||||||
}
|
}
|
||||||
// Optimization:
|
// Optimization:
|
||||||
// If color is close enough to 1, skip calling the following transform
|
// If color is close enough to 1, skip calling the following transform
|
||||||
@ -958,7 +957,11 @@ class CalRGBCS extends ColorSpace {
|
|||||||
if (color >= 0.99554525) {
|
if (color >= 0.99554525) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return MathClamp((1 + 0.055) * color ** (1 / 2.4) - 0.055, 0, 1);
|
return this.#adjustToRange(0, 1, (1 + 0.055) * color ** (1 / 2.4) - 0.055);
|
||||||
|
}
|
||||||
|
|
||||||
|
#adjustToRange(min, max, value) {
|
||||||
|
return Math.max(min, Math.min(max, value));
|
||||||
}
|
}
|
||||||
|
|
||||||
#decodeL(L) {
|
#decodeL(L) {
|
||||||
@ -1054,9 +1057,9 @@ class CalRGBCS extends ColorSpace {
|
|||||||
#toRgb(src, srcOffset, dest, destOffset, scale) {
|
#toRgb(src, srcOffset, dest, destOffset, scale) {
|
||||||
// A, B and C represent a red, green and blue components of a calibrated
|
// A, B and C represent a red, green and blue components of a calibrated
|
||||||
// rgb space.
|
// rgb space.
|
||||||
const A = MathClamp(src[srcOffset] * scale, 0, 1);
|
const A = this.#adjustToRange(0, 1, src[srcOffset] * scale);
|
||||||
const B = MathClamp(src[srcOffset + 1] * scale, 0, 1);
|
const B = this.#adjustToRange(0, 1, src[srcOffset + 1] * scale);
|
||||||
const C = MathClamp(src[srcOffset + 2] * scale, 0, 1);
|
const C = this.#adjustToRange(0, 1, src[srcOffset + 2] * scale);
|
||||||
|
|
||||||
// A <---> AGR in the spec
|
// A <---> AGR in the spec
|
||||||
// B <---> BGG in the spec
|
// B <---> BGG in the spec
|
||||||
|
|||||||
@ -26,7 +26,7 @@ import {
|
|||||||
PatternCS,
|
PatternCS,
|
||||||
} from "./colorspace.js";
|
} from "./colorspace.js";
|
||||||
import { Dict, Name, Ref } from "./primitives.js";
|
import { Dict, Name, Ref } from "./primitives.js";
|
||||||
import { MathClamp, shadow, unreachable, warn } from "../shared/util.js";
|
import { shadow, unreachable, warn } from "../shared/util.js";
|
||||||
import { IccColorSpace } from "./icc_colorspace.js";
|
import { IccColorSpace } from "./icc_colorspace.js";
|
||||||
import { MissingDataException } from "./core_utils.js";
|
import { MissingDataException } from "./core_utils.js";
|
||||||
|
|
||||||
@ -245,7 +245,7 @@ class ColorSpaceUtils {
|
|||||||
case "I":
|
case "I":
|
||||||
case "Indexed":
|
case "Indexed":
|
||||||
baseCS = this.#subParse(cs[1], options);
|
baseCS = this.#subParse(cs[1], options);
|
||||||
const hiVal = MathClamp(xref.fetchIfRef(cs[2]), 0, 255);
|
const hiVal = Math.max(0, Math.min(xref.fetchIfRef(cs[2]), 255));
|
||||||
const lookup = xref.fetchIfRef(cs[3]);
|
const lookup = xref.fetchIfRef(cs[3]);
|
||||||
return new IndexedCS(baseCS, hiVal, lookup);
|
return new IndexedCS(baseCS, hiVal, lookup);
|
||||||
case "Separation":
|
case "Separation":
|
||||||
|
|||||||
@ -18,7 +18,6 @@ import {
|
|||||||
FeatureTest,
|
FeatureTest,
|
||||||
FormatError,
|
FormatError,
|
||||||
info,
|
info,
|
||||||
MathClamp,
|
|
||||||
shadow,
|
shadow,
|
||||||
unreachable,
|
unreachable,
|
||||||
} from "../shared/util.js";
|
} from "../shared/util.js";
|
||||||
@ -264,7 +263,10 @@ class PDFFunction {
|
|||||||
// x_i' = min(max(x_i, Domain_2i), Domain_2i+1)
|
// x_i' = min(max(x_i, Domain_2i), Domain_2i+1)
|
||||||
const domain_2i = domain[i][0];
|
const domain_2i = domain[i][0];
|
||||||
const domain_2i_1 = domain[i][1];
|
const domain_2i_1 = domain[i][1];
|
||||||
const xi = MathClamp(src[srcOffset + i], domain_2i, domain_2i_1);
|
const xi = Math.min(
|
||||||
|
Math.max(src[srcOffset + i], domain_2i),
|
||||||
|
domain_2i_1
|
||||||
|
);
|
||||||
|
|
||||||
// e_i = Interpolate(x_i', Domain_2i, Domain_2i+1,
|
// e_i = Interpolate(x_i', Domain_2i, Domain_2i+1,
|
||||||
// Encode_2i, Encode_2i+1)
|
// Encode_2i, Encode_2i+1)
|
||||||
@ -278,7 +280,7 @@ class PDFFunction {
|
|||||||
|
|
||||||
// e_i' = min(max(e_i, 0), Size_i - 1)
|
// e_i' = min(max(e_i, 0), Size_i - 1)
|
||||||
const size_i = size[i];
|
const size_i = size[i];
|
||||||
e = MathClamp(e, 0, size_i - 1);
|
e = Math.min(Math.max(e, 0), size_i - 1);
|
||||||
|
|
||||||
// Adjusting the cube: N and vertex sample index
|
// Adjusting the cube: N and vertex sample index
|
||||||
const e0 = e < size_i - 1 ? Math.floor(e) : e - 1; // e1 = e0 + 1;
|
const e0 = e < size_i - 1 ? Math.floor(e) : e - 1; // e1 = e0 + 1;
|
||||||
@ -312,7 +314,7 @@ class PDFFunction {
|
|||||||
rj = interpolate(rj, 0, 1, decode[j][0], decode[j][1]);
|
rj = interpolate(rj, 0, 1, decode[j][0], decode[j][1]);
|
||||||
|
|
||||||
// y_j = min(max(r_j, range_2j), range_2j+1)
|
// y_j = min(max(r_j, range_2j), range_2j+1)
|
||||||
dest[destOffset + j] = MathClamp(rj, range[j][0], range[j][1]);
|
dest[destOffset + j] = Math.min(Math.max(rj, range[j][0]), range[j][1]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -359,8 +361,17 @@ class PDFFunction {
|
|||||||
const tmpBuf = new Float32Array(1);
|
const tmpBuf = new Float32Array(1);
|
||||||
|
|
||||||
return function constructStichedFn(src, srcOffset, dest, destOffset) {
|
return function constructStichedFn(src, srcOffset, dest, destOffset) {
|
||||||
// Clamp to domain.
|
const clip = function constructStichedFromIRClip(v, min, max) {
|
||||||
const v = MathClamp(src[srcOffset], domain[0], domain[1]);
|
if (v > max) {
|
||||||
|
v = max;
|
||||||
|
} else if (v < min) {
|
||||||
|
v = min;
|
||||||
|
}
|
||||||
|
return v;
|
||||||
|
};
|
||||||
|
|
||||||
|
// clip to domain
|
||||||
|
const v = clip(src[srcOffset], domain[0], domain[1]);
|
||||||
// calculate which bound the value is in
|
// calculate which bound the value is in
|
||||||
const length = bounds.length;
|
const length = bounds.length;
|
||||||
let i;
|
let i;
|
||||||
|
|||||||
@ -18,7 +18,6 @@ import {
|
|||||||
FeatureTest,
|
FeatureTest,
|
||||||
FormatError,
|
FormatError,
|
||||||
ImageKind,
|
ImageKind,
|
||||||
MathClamp,
|
|
||||||
warn,
|
warn,
|
||||||
} from "../shared/util.js";
|
} from "../shared/util.js";
|
||||||
import {
|
import {
|
||||||
@ -34,6 +33,21 @@ import { JpegStream } from "./jpeg_stream.js";
|
|||||||
import { JpxImage } from "./jpx.js";
|
import { JpxImage } from "./jpx.js";
|
||||||
import { Name } from "./primitives.js";
|
import { Name } from "./primitives.js";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decode and clamp a value. The formula is different from the spec because we
|
||||||
|
* don't decode to float range [0,1], we decode it in the [0,max] range.
|
||||||
|
*/
|
||||||
|
function decodeAndClamp(value, addend, coefficient, max) {
|
||||||
|
value = addend + value * coefficient;
|
||||||
|
// Clamp the value to the range
|
||||||
|
if (value < 0) {
|
||||||
|
value = 0;
|
||||||
|
} else if (value > max) {
|
||||||
|
value = max;
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resizes an image mask with 1 component.
|
* Resizes an image mask with 1 component.
|
||||||
* @param {TypedArray} src - The source buffer.
|
* @param {TypedArray} src - The source buffer.
|
||||||
@ -473,11 +487,10 @@ class PDFImage {
|
|||||||
let index = 0;
|
let index = 0;
|
||||||
for (i = 0, ii = this.width * this.height; i < ii; i++) {
|
for (i = 0, ii = this.width * this.height; i < ii; i++) {
|
||||||
for (let j = 0; j < numComps; j++) {
|
for (let j = 0; j < numComps; j++) {
|
||||||
// Decode and clamp. The formula is different from the spec because we
|
buffer[index] = decodeAndClamp(
|
||||||
// don't decode to float range [0,1], we decode it in the [0,max] range.
|
buffer[index],
|
||||||
buffer[index] = MathClamp(
|
decodeAddends[j],
|
||||||
decodeAddends[j] + buffer[index] * decodeCoefficients[j],
|
decodeCoefficients[j],
|
||||||
0,
|
|
||||||
max
|
max
|
||||||
);
|
);
|
||||||
index++;
|
index++;
|
||||||
|
|||||||
@ -13,7 +13,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { MathClamp, shadow } from "../../shared/util.js";
|
import { shadow } from "../../shared/util.js";
|
||||||
|
|
||||||
const dimConverters = {
|
const dimConverters = {
|
||||||
pt: x => x,
|
pt: x => x,
|
||||||
@ -143,7 +143,7 @@ function getColor(data, def = [0, 0, 0]) {
|
|||||||
const color = data
|
const color = data
|
||||||
.trim()
|
.trim()
|
||||||
.split(/\s*,\s*/)
|
.split(/\s*,\s*/)
|
||||||
.map(c => MathClamp(parseInt(c.trim(), 10), 0, 255))
|
.map(c => Math.min(Math.max(0, parseInt(c.trim(), 10)), 255))
|
||||||
.map(c => (isNaN(c) ? 0 : c));
|
.map(c => (isNaN(c) ? 0 : c));
|
||||||
|
|
||||||
if (color.length < 3) {
|
if (color.length < 3) {
|
||||||
|
|||||||
@ -13,8 +13,8 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { MathClamp, Util } from "../../../shared/util.js";
|
|
||||||
import { Outline } from "./outline.js";
|
import { Outline } from "./outline.js";
|
||||||
|
import { Util } from "../../../shared/util.js";
|
||||||
|
|
||||||
class InkDrawOutliner {
|
class InkDrawOutliner {
|
||||||
// The last 3 points of the line.
|
// The last 3 points of the line.
|
||||||
@ -616,10 +616,10 @@ class InkDrawOutline extends Outline {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const [marginX, marginY] = this.#getMarginComponents();
|
const [marginX, marginY] = this.#getMarginComponents();
|
||||||
bbox[0] = MathClamp(bbox[0] - marginX, 0, 1);
|
bbox[0] = Math.min(1, Math.max(0, bbox[0] - marginX));
|
||||||
bbox[1] = MathClamp(bbox[1] - marginY, 0, 1);
|
bbox[1] = Math.min(1, Math.max(0, bbox[1] - marginY));
|
||||||
bbox[2] = MathClamp(bbox[2] + marginX, 0, 1);
|
bbox[2] = Math.min(1, Math.max(0, bbox[2] + marginX));
|
||||||
bbox[3] = MathClamp(bbox[3] + marginY, 0, 1);
|
bbox[3] = Math.min(1, Math.max(0, bbox[3] + marginY));
|
||||||
|
|
||||||
bbox[2] -= bbox[0];
|
bbox[2] -= bbox[0];
|
||||||
bbox[3] -= bbox[1];
|
bbox[3] -= bbox[1];
|
||||||
|
|||||||
@ -22,12 +22,7 @@ import {
|
|||||||
ColorManager,
|
ColorManager,
|
||||||
KeyboardManager,
|
KeyboardManager,
|
||||||
} from "./tools.js";
|
} from "./tools.js";
|
||||||
import {
|
import { FeatureTest, shadow, unreachable } from "../../shared/util.js";
|
||||||
FeatureTest,
|
|
||||||
MathClamp,
|
|
||||||
shadow,
|
|
||||||
unreachable,
|
|
||||||
} from "../../shared/util.js";
|
|
||||||
import { noContextMenu, stopEvent } from "../display_utils.js";
|
import { noContextMenu, stopEvent } from "../display_utils.js";
|
||||||
import { AltText } from "./alt_text.js";
|
import { AltText } from "./alt_text.js";
|
||||||
import { EditorToolbar } from "./toolbar.js";
|
import { EditorToolbar } from "./toolbar.js";
|
||||||
@ -618,20 +613,20 @@ class AnnotationEditor {
|
|||||||
if (this._mustFixPosition) {
|
if (this._mustFixPosition) {
|
||||||
switch (rotation) {
|
switch (rotation) {
|
||||||
case 0:
|
case 0:
|
||||||
x = MathClamp(x, 0, pageWidth - width);
|
x = Math.max(0, Math.min(pageWidth - width, x));
|
||||||
y = MathClamp(y, 0, pageHeight - height);
|
y = Math.max(0, Math.min(pageHeight - height, y));
|
||||||
break;
|
break;
|
||||||
case 90:
|
case 90:
|
||||||
x = MathClamp(x, 0, pageWidth - height);
|
x = Math.max(0, Math.min(pageWidth - height, x));
|
||||||
y = MathClamp(y, width, pageHeight);
|
y = Math.min(pageHeight, Math.max(width, y));
|
||||||
break;
|
break;
|
||||||
case 180:
|
case 180:
|
||||||
x = MathClamp(x, width, pageWidth);
|
x = Math.min(pageWidth, Math.max(width, x));
|
||||||
y = MathClamp(y, height, pageHeight);
|
y = Math.min(pageHeight, Math.max(height, y));
|
||||||
break;
|
break;
|
||||||
case 270:
|
case 270:
|
||||||
x = MathClamp(x, height, pageWidth);
|
x = Math.min(pageWidth, Math.max(height, x));
|
||||||
y = MathClamp(y, 0, pageHeight - width);
|
y = Math.max(0, Math.min(pageHeight - width, y));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -42,6 +42,17 @@ function bindEvents(obj, element, names) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert a number between 0 and 100 into an hex number between 0 and 255.
|
||||||
|
* @param {number} opacity
|
||||||
|
* @return {string}
|
||||||
|
*/
|
||||||
|
function opacityToHex(opacity) {
|
||||||
|
return Math.round(Math.min(255, Math.max(1, 255 * opacity)))
|
||||||
|
.toString(16)
|
||||||
|
.padStart(2, "0");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class to create some unique ids for the different editors.
|
* Class to create some unique ids for the different editors.
|
||||||
*/
|
*/
|
||||||
@ -2551,4 +2562,5 @@ export {
|
|||||||
ColorManager,
|
ColorManager,
|
||||||
CommandManager,
|
CommandManager,
|
||||||
KeyboardManager,
|
KeyboardManager,
|
||||||
|
opacityToHex,
|
||||||
};
|
};
|
||||||
|
|||||||
@ -33,7 +33,6 @@ import {
|
|||||||
getUuid,
|
getUuid,
|
||||||
ImageKind,
|
ImageKind,
|
||||||
InvalidPDFException,
|
InvalidPDFException,
|
||||||
MathClamp,
|
|
||||||
normalizeUnicode,
|
normalizeUnicode,
|
||||||
OPS,
|
OPS,
|
||||||
PasswordResponses,
|
PasswordResponses,
|
||||||
@ -120,7 +119,6 @@ export {
|
|||||||
isDataScheme,
|
isDataScheme,
|
||||||
isPdfFile,
|
isPdfFile,
|
||||||
isValidExplicitDest,
|
isValidExplicitDest,
|
||||||
MathClamp,
|
|
||||||
noContextMenu,
|
noContextMenu,
|
||||||
normalizeUnicode,
|
normalizeUnicode,
|
||||||
OPS,
|
OPS,
|
||||||
|
|||||||
@ -1128,12 +1128,6 @@ function _isValidExplicitDest(validRef, validName, dest) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TOOD: Replace all occurrences of this function with `Math.clamp` once
|
|
||||||
// https://github.com/tc39/proposal-math-clamp/ is generally available.
|
|
||||||
function MathClamp(v, min, max) {
|
|
||||||
return Math.min(Math.max(v, min), max);
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Remove this once `Uint8Array.prototype.toHex` is generally available.
|
// TODO: Remove this once `Uint8Array.prototype.toHex` is generally available.
|
||||||
function toHexUtil(arr) {
|
function toHexUtil(arr) {
|
||||||
if (Uint8Array.prototype.toHex) {
|
if (Uint8Array.prototype.toHex) {
|
||||||
@ -1208,7 +1202,6 @@ export {
|
|||||||
isNodeJS,
|
isNodeJS,
|
||||||
LINE_DESCENT_FACTOR,
|
LINE_DESCENT_FACTOR,
|
||||||
LINE_FACTOR,
|
LINE_FACTOR,
|
||||||
MathClamp,
|
|
||||||
normalizeUnicode,
|
normalizeUnicode,
|
||||||
objectFromMap,
|
objectFromMap,
|
||||||
objectSize,
|
objectSize,
|
||||||
|
|||||||
@ -28,7 +28,7 @@ import {
|
|||||||
getRect,
|
getRect,
|
||||||
getSerialized,
|
getSerialized,
|
||||||
hover,
|
hover,
|
||||||
isCanvasMonochrome,
|
isCanvasWhite,
|
||||||
kbBigMoveDown,
|
kbBigMoveDown,
|
||||||
kbBigMoveLeft,
|
kbBigMoveLeft,
|
||||||
kbBigMoveRight,
|
kbBigMoveRight,
|
||||||
@ -837,7 +837,7 @@ describe("FreeText Editor", () => {
|
|||||||
await switchToFreeText(page);
|
await switchToFreeText(page);
|
||||||
|
|
||||||
// The page has been re-rendered but with no freetext annotations.
|
// The page has been re-rendered but with no freetext annotations.
|
||||||
let isWhite = await isCanvasMonochrome(page, 1, null, 0xffffffff);
|
let isWhite = await isCanvasWhite(page, 1);
|
||||||
expect(isWhite).withContext(`In ${browserName}`).toBeTrue();
|
expect(isWhite).withContext(`In ${browserName}`).toBeTrue();
|
||||||
|
|
||||||
let editorIds = await getEditors(page, "freeText");
|
let editorIds = await getEditors(page, "freeText");
|
||||||
@ -880,7 +880,7 @@ describe("FreeText Editor", () => {
|
|||||||
editorIds = await getEditors(page, "freeText");
|
editorIds = await getEditors(page, "freeText");
|
||||||
expect(editorIds.length).withContext(`In ${browserName}`).toEqual(1);
|
expect(editorIds.length).withContext(`In ${browserName}`).toEqual(1);
|
||||||
|
|
||||||
isWhite = await isCanvasMonochrome(page, 1, editorRect, 0xffffffff);
|
isWhite = await isCanvasWhite(page, 1, editorRect);
|
||||||
expect(isWhite).withContext(`In ${browserName}`).toBeTrue();
|
expect(isWhite).withContext(`In ${browserName}`).toBeTrue();
|
||||||
|
|
||||||
// Check we've now a div containing the text.
|
// Check we've now a div containing the text.
|
||||||
|
|||||||
@ -23,7 +23,7 @@ import {
|
|||||||
getEditorSelector,
|
getEditorSelector,
|
||||||
getRect,
|
getRect,
|
||||||
getSerialized,
|
getSerialized,
|
||||||
isCanvasMonochrome,
|
isCanvasWhite,
|
||||||
kbRedo,
|
kbRedo,
|
||||||
kbUndo,
|
kbUndo,
|
||||||
loadAndWait,
|
loadAndWait,
|
||||||
@ -747,12 +747,7 @@ describe("Ink Editor", () => {
|
|||||||
await switchToInk(page);
|
await switchToInk(page);
|
||||||
|
|
||||||
// The page has been re-rendered but with no ink annotations.
|
// The page has been re-rendered but with no ink annotations.
|
||||||
let isWhite = await isCanvasMonochrome(
|
let isWhite = await isCanvasWhite(page, 1, annotationsRect);
|
||||||
page,
|
|
||||||
1,
|
|
||||||
annotationsRect,
|
|
||||||
0xffffffff
|
|
||||||
);
|
|
||||||
expect(isWhite).withContext(`In ${browserName}`).toBeTrue();
|
expect(isWhite).withContext(`In ${browserName}`).toBeTrue();
|
||||||
|
|
||||||
let editorIds = await getEditors(page, "ink");
|
let editorIds = await getEditors(page, "ink");
|
||||||
@ -786,7 +781,7 @@ describe("Ink Editor", () => {
|
|||||||
editorIds = await getEditors(page, "ink");
|
editorIds = await getEditors(page, "ink");
|
||||||
expect(editorIds.length).withContext(`In ${browserName}`).toEqual(1);
|
expect(editorIds.length).withContext(`In ${browserName}`).toEqual(1);
|
||||||
|
|
||||||
isWhite = await isCanvasMonochrome(page, 1, editorRect, 0xffffffff);
|
isWhite = await isCanvasWhite(page, 1, editorRect);
|
||||||
expect(isWhite).withContext(`In ${browserName}`).toBeTrue();
|
expect(isWhite).withContext(`In ${browserName}`).toBeTrue();
|
||||||
|
|
||||||
// Check we've now a svg with a red stroke.
|
// Check we've now a svg with a red stroke.
|
||||||
|
|||||||
@ -30,7 +30,6 @@ import {
|
|||||||
getFirstSerialized,
|
getFirstSerialized,
|
||||||
getRect,
|
getRect,
|
||||||
getSerialized,
|
getSerialized,
|
||||||
isCanvasMonochrome,
|
|
||||||
isVisible,
|
isVisible,
|
||||||
kbBigMoveDown,
|
kbBigMoveDown,
|
||||||
kbBigMoveRight,
|
kbBigMoveRight,
|
||||||
@ -46,7 +45,6 @@ import {
|
|||||||
waitForAnnotationEditorLayer,
|
waitForAnnotationEditorLayer,
|
||||||
waitForAnnotationModeChanged,
|
waitForAnnotationModeChanged,
|
||||||
waitForEntryInStorage,
|
waitForEntryInStorage,
|
||||||
waitForPageRendered,
|
|
||||||
waitForSelectedEditor,
|
waitForSelectedEditor,
|
||||||
waitForSerialized,
|
waitForSerialized,
|
||||||
waitForTimeout,
|
waitForTimeout,
|
||||||
@ -1821,57 +1819,4 @@ describe("Stamp Editor", () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("Switch to edit mode, zoom and check that the non-editable stamp is still there", () => {
|
|
||||||
const annotationSelector = getAnnotationSelector("14R");
|
|
||||||
|
|
||||||
let pages;
|
|
||||||
|
|
||||||
beforeAll(async () => {
|
|
||||||
pages = await loadAndWait("red_stamp.pdf", annotationSelector, 20);
|
|
||||||
});
|
|
||||||
|
|
||||||
afterAll(async () => {
|
|
||||||
await closePages(pages);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("must check if the canvas is still red", async () => {
|
|
||||||
await Promise.all(
|
|
||||||
pages.map(async ([, page]) => {
|
|
||||||
expect(
|
|
||||||
await isCanvasMonochrome(page, 1, null, 0xff0000ff)
|
|
||||||
).toBeTrue();
|
|
||||||
|
|
||||||
await switchToStamp(page);
|
|
||||||
|
|
||||||
expect(
|
|
||||||
await isCanvasMonochrome(page, 1, null, 0xff0000ff)
|
|
||||||
).toBeTrue();
|
|
||||||
|
|
||||||
const rectPage = await getRect(
|
|
||||||
page,
|
|
||||||
`.page[data-page-number = "1"] .annotationEditorLayer`
|
|
||||||
);
|
|
||||||
|
|
||||||
const handle = await waitForPageRendered(page, 1);
|
|
||||||
const originX = rectPage.x + rectPage.width / 2;
|
|
||||||
const originY = rectPage.y + rectPage.height / 2;
|
|
||||||
await page.evaluate(
|
|
||||||
origin => {
|
|
||||||
window.PDFViewerApplication.pdfViewer.increaseScale({
|
|
||||||
scaleFactor: 2,
|
|
||||||
origin,
|
|
||||||
});
|
|
||||||
},
|
|
||||||
[originX, originY]
|
|
||||||
);
|
|
||||||
await awaitPromise(handle);
|
|
||||||
|
|
||||||
expect(
|
|
||||||
await isCanvasMonochrome(page, 1, null, 0xff0000ff)
|
|
||||||
).toBeTrue();
|
|
||||||
})
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|||||||
@ -838,9 +838,9 @@ function waitForNoElement(page, selector) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function isCanvasMonochrome(page, pageNumber, rectangle, color) {
|
function isCanvasWhite(page, pageNumber, rectangle) {
|
||||||
return page.evaluate(
|
return page.evaluate(
|
||||||
(rect, pageN, col) => {
|
(rect, pageN) => {
|
||||||
const canvas = document.querySelector(
|
const canvas = document.querySelector(
|
||||||
`.page[data-page-number = "${pageN}"] .canvasWrapper canvas`
|
`.page[data-page-number = "${pageN}"] .canvasWrapper canvas`
|
||||||
);
|
);
|
||||||
@ -853,11 +853,10 @@ function isCanvasMonochrome(page, pageNumber, rectangle, color) {
|
|||||||
rect.width,
|
rect.width,
|
||||||
rect.height
|
rect.height
|
||||||
);
|
);
|
||||||
return new Uint32Array(data.buffer).every(x => x === col);
|
return new Uint32Array(data.buffer).every(x => x === 0xffffffff);
|
||||||
},
|
},
|
||||||
rectangle,
|
rectangle,
|
||||||
pageNumber,
|
pageNumber
|
||||||
color
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -926,7 +925,7 @@ export {
|
|||||||
getSpanRectFromText,
|
getSpanRectFromText,
|
||||||
getXY,
|
getXY,
|
||||||
hover,
|
hover,
|
||||||
isCanvasMonochrome,
|
isCanvasWhite,
|
||||||
isVisible,
|
isVisible,
|
||||||
kbBigMoveDown,
|
kbBigMoveDown,
|
||||||
kbBigMoveLeft,
|
kbBigMoveLeft,
|
||||||
|
|||||||
1
test/pdfs/.gitignore
vendored
1
test/pdfs/.gitignore
vendored
@ -710,4 +710,3 @@
|
|||||||
!bug1019475_2.pdf
|
!bug1019475_2.pdf
|
||||||
!issue19505.pdf
|
!issue19505.pdf
|
||||||
!colors.pdf
|
!colors.pdf
|
||||||
!red_stamp.pdf
|
|
||||||
|
|||||||
Binary file not shown.
@ -24,7 +24,6 @@ import {
|
|||||||
getUuid,
|
getUuid,
|
||||||
ImageKind,
|
ImageKind,
|
||||||
InvalidPDFException,
|
InvalidPDFException,
|
||||||
MathClamp,
|
|
||||||
normalizeUnicode,
|
normalizeUnicode,
|
||||||
OPS,
|
OPS,
|
||||||
PasswordResponses,
|
PasswordResponses,
|
||||||
@ -97,7 +96,6 @@ const expectedAPI = Object.freeze({
|
|||||||
isDataScheme,
|
isDataScheme,
|
||||||
isPdfFile,
|
isPdfFile,
|
||||||
isValidExplicitDest,
|
isValidExplicitDest,
|
||||||
MathClamp,
|
|
||||||
noContextMenu,
|
noContextMenu,
|
||||||
normalizeUnicode,
|
normalizeUnicode,
|
||||||
OPS,
|
OPS,
|
||||||
|
|||||||
@ -40,7 +40,6 @@ const {
|
|||||||
isDataScheme,
|
isDataScheme,
|
||||||
isPdfFile,
|
isPdfFile,
|
||||||
isValidExplicitDest,
|
isValidExplicitDest,
|
||||||
MathClamp,
|
|
||||||
noContextMenu,
|
noContextMenu,
|
||||||
normalizeUnicode,
|
normalizeUnicode,
|
||||||
OPS,
|
OPS,
|
||||||
@ -93,7 +92,6 @@ export {
|
|||||||
isDataScheme,
|
isDataScheme,
|
||||||
isPdfFile,
|
isPdfFile,
|
||||||
isValidExplicitDest,
|
isValidExplicitDest,
|
||||||
MathClamp,
|
|
||||||
noContextMenu,
|
noContextMenu,
|
||||||
normalizeUnicode,
|
normalizeUnicode,
|
||||||
OPS,
|
OPS,
|
||||||
|
|||||||
@ -13,8 +13,6 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { MathClamp } from "pdfjs-lib";
|
|
||||||
|
|
||||||
const DEFAULT_SCALE_VALUE = "auto";
|
const DEFAULT_SCALE_VALUE = "auto";
|
||||||
const DEFAULT_SCALE = 1.0;
|
const DEFAULT_SCALE = 1.0;
|
||||||
const DEFAULT_SCALE_DELTA = 1.1;
|
const DEFAULT_SCALE_DELTA = 1.1;
|
||||||
@ -678,6 +676,10 @@ const docStyle =
|
|||||||
? null
|
? null
|
||||||
: document.documentElement.style;
|
: document.documentElement.style;
|
||||||
|
|
||||||
|
function clamp(v, min, max) {
|
||||||
|
return Math.min(Math.max(v, min), max);
|
||||||
|
}
|
||||||
|
|
||||||
class ProgressBar {
|
class ProgressBar {
|
||||||
#classList = null;
|
#classList = null;
|
||||||
|
|
||||||
@ -699,7 +701,7 @@ class ProgressBar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
set percent(val) {
|
set percent(val) {
|
||||||
this.#percent = MathClamp(val, 0, 100);
|
this.#percent = clamp(val, 0, 100);
|
||||||
|
|
||||||
if (isNaN(val)) {
|
if (isNaN(val)) {
|
||||||
this.#classList.add("indeterminate");
|
this.#classList.add("indeterminate");
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user