Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@ export default [
"unicorn/prefer-dom-node-remove": "error",
"unicorn/prefer-import-meta-properties": "error",
"unicorn/prefer-includes": "error",
"unicorn/logical-assignment-operators": [
"error",
"always",
{ enforceForIfStatements: true },
],
"unicorn/prefer-logical-operator-over-ternary": "error",
"unicorn/prefer-modern-dom-apis": "error",
"unicorn/prefer-modern-math-apis": "error",
Expand Down
2 changes: 1 addition & 1 deletion extensions/chromium/options/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ function renderDefaultZoomValue(shortDescription) {
document.getElementById("settings-boxes").append(wrapper);

function renderPreference(value) {
value = value || "auto";
value ||= "auto";
select.value = value;
var customOption = select.querySelector("option.custom-zoom");
if (select.selectedIndex === -1 && value) {
Expand Down
2 changes: 1 addition & 1 deletion extensions/chromium/telemetry.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ limitations under the License.
*/
function didUpdateSinceLastCheck() {
var chromeVersion = /Chrome\/(\d+)\./.exec(navigator.userAgent);
chromeVersion = chromeVersion && chromeVersion[1];
chromeVersion &&= chromeVersion[1];
if (!chromeVersion || localStorage.telemetryLastVersion === chromeVersion) {
return false;
}
Expand Down
16 changes: 6 additions & 10 deletions src/core/annotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -3318,13 +3318,11 @@ class ButtonWidgetAnnotation extends WidgetAnnotation {
return super.getOperatorList(evaluator, task, intent, annotationStorage);
}

if (value === null || value === undefined) {
// There is no default appearance so use the one derived
// from the field value.
value = this.data.checkBox
? this.data.fieldValue === this.data.exportValue
: this.data.fieldValue === this.data.buttonValue;
}
// There is no default appearance, `value === null || value === undefined`,
// so use the one derived from the field value.
value ??= this.data.checkBox
? this.data.fieldValue === this.data.exportValue
: this.data.fieldValue === this.data.buttonValue;

return this.#getOperatorListForAppearance(
evaluator,
Expand Down Expand Up @@ -4716,9 +4714,7 @@ class PolylineAnnotation extends MarkupAnnotation {
const strokeAlpha = dict.get("CA");

let fillColor = getRgbColor(dict.getArray("IC"), null);
if (fillColor) {
fillColor = getPdfColorArray(fillColor);
}
fillColor &&= getPdfColorArray(fillColor);

let operator;
if (fillColor) {
Expand Down
8 changes: 3 additions & 5 deletions src/core/ccitt_stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,9 @@ class CCITTFaxStream extends DecodeStream {
if (this.eof) {
return this.buffer;
}
if (!bytes) {
bytes = this.stream.isAsync
? (await this.stream.asyncGetBytes()) || this.bytes
: this.bytes;
}
bytes ??= this.stream.isAsync
? (await this.stream.asyncGetBytes()) || this.bytes
: this.bytes;

this.buffer = await JBig2CCITTFaxImage.instance.decode(
bytes,
Expand Down
14 changes: 6 additions & 8 deletions src/core/cff_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -775,14 +775,12 @@ class CFFParser {
} else if (localSubrIndex) {
localSubrToUse = localSubrIndex;
}
if (valid) {
valid = this.parseCharString(
state,
charstring,
localSubrToUse,
globalSubrIndex
);
}
valid &&= this.parseCharString(
state,
charstring,
localSubrToUse,
globalSubrIndex
);
if (state.width !== null) {
const nominalWidth = privateDictToUse.getByName("nominalWidthX");
widths[i] = nominalWidth + state.width;
Expand Down
4 changes: 1 addition & 3 deletions src/core/colorspace_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,7 @@ class ColorSpaceUtils {
break;
case "Pattern":
baseCS = cs[1] || null;
if (baseCS) {
baseCS = this.#subParse(baseCS, options);
}
baseCS &&= this.#subParse(baseCS, options);
return new PatternCS(baseCS);
case "I":
case "Indexed":
Expand Down
2 changes: 1 addition & 1 deletion src/core/core_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ function encodeToXmlString(str) {
buffer.push(str.substring(start, i));
}
buffer.push(`&#x${char.toString(16).toUpperCase()};`);
if (char > 0xd7ff && (char < 0xe000 || char > 0xfffd)) {
if (char > 0xffff) {
// char is represented by two u16
i++;
}
Expand Down
2 changes: 0 additions & 2 deletions src/core/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -2133,12 +2133,10 @@ class PDFDocument {
.ensureDoc("formInfo")
.then(async formInfo => {
if (!formInfo.hasSignatures || !formInfo.hasFields) {
this.#signatureData = null;
return null;
}
const annotationGlobals = await this.annotationGlobals;
if (!annotationGlobals) {
this.#signatureData = null;
return null;
}
const fields = annotationGlobals.acroForm.get("Fields");
Expand Down
5 changes: 2 additions & 3 deletions src/core/fonts_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,8 @@ function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) {
glyphId = glyphNames.indexOf(glyphName);

if (glyphId === -1) {
if (!glyphsUnicodeMap) {
glyphsUnicodeMap = getGlyphsUnicode();
}
glyphsUnicodeMap ??= getGlyphsUnicode();

const standardGlyphName = recoverGlyphName(glyphName, glyphsUnicodeMap);
if (standardGlyphName !== glyphName) {
glyphId = glyphNames.indexOf(standardGlyphName);
Expand Down
8 changes: 1 addition & 7 deletions src/core/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -579,13 +579,7 @@ class PDFImage {
}

const remainingBits = bits - bpc;
let value = buf >> remainingBits;
if (value < 0) {
value = 0;
} else if (value > max) {
value = max;
}
output[i] = value;
output[i] = MathClamp(buf >> remainingBits, 0, max);
buf &= (1 << remainingBits) - 1;
bits = remainingBits;
}
Expand Down
8 changes: 3 additions & 5 deletions src/core/xfa/factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,9 @@ class XFAFactory {
const { html } = result;
const { attributes } = html;
if (attributes) {
if (attributes.class) {
attributes.class = attributes.class.filter(
attr => !attr.startsWith("xfa")
);
}
attributes.class &&= attributes.class.filter(
attr => !attr.startsWith("xfa")
);
attributes.dir = "auto";
}

Expand Down
9 changes: 2 additions & 7 deletions src/core/xfa/fonts.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ class FontFinder {
this.addPdfFont(pdfFont);
}
for (const pdfFont of this.fonts.values()) {
if (!pdfFont.regular) {
pdfFont.regular = pdfFont.italic || pdfFont.bold || pdfFont.bolditalic;
}
pdfFont.regular ||= pdfFont.italic || pdfFont.bold || pdfFont.bolditalic;
}

if (!reallyMissingFonts || reallyMissingFonts.size === 0) {
Expand Down Expand Up @@ -72,10 +70,7 @@ class FontFinder {
property += "italic";
}
}

if (!property) {
property = "regular";
}
property ||= "regular";

font[property] = pdfFont;
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/xfa/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -3000,7 +3000,7 @@ class Field extends XFAObject {
}

if (!this.ui.imageEdit && ui.children?.[0] && this.h) {
borderDims = borderDims || getBorderDims(this.ui[$getExtra]());
borderDims ||= getBorderDims(this.ui[$getExtra]());

let captionHeight = 0;
if (this.caption && ["top", "bottom"].includes(this.caption.placement)) {
Expand Down
4 changes: 1 addition & 3 deletions src/core/xfa/xfa_object.js
Original file line number Diff line number Diff line change
Expand Up @@ -518,9 +518,7 @@ class XFAObject {
true /* = dotDotAllowed */,
false /* = useCache */
);
if (proto) {
proto = proto[0];
}
proto &&= proto[0];
}

if (!proto) {
Expand Down
9 changes: 3 additions & 6 deletions src/core/xref.js
Original file line number Diff line number Diff line change
Expand Up @@ -740,9 +740,7 @@ class XRef {
if (isCmd(obj, "xref")) {
// Parse end-of-file XRef
dict = this.processXRefTable(parser);
if (!this.topDict) {
this.topDict = dict;
}
this.topDict ||= dict;

// Recursively get other XRefs 'XRefStm', if any
obj = dict.get("XRefStm");
Expand All @@ -762,9 +760,8 @@ class XRef {
throw new FormatError("Invalid XRef stream");
}
dict = this.processXRefStream(obj);
if (!this.topDict) {
this.topDict = dict;
}
this.topDict ||= dict;

if (!dict) {
throw new FormatError("Failed to read XRef stream");
}
Expand Down
4 changes: 1 addition & 3 deletions src/display/annotation_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1187,10 +1187,8 @@ class LinkAnnotationElement extends AnnotationElement {
if (data.overlaidText) {
link.title = data.overlaidText;
}
link.onclick ||= () => false;

if (!link.onclick) {
link.onclick = () => false;
}
this.#setInternalLink();
}

Expand Down
10 changes: 4 additions & 6 deletions src/display/editor/stamp.js
Original file line number Diff line number Diff line change
Expand Up @@ -488,12 +488,10 @@ class StampEditor extends AnnotationEditor {
}

copyCanvas(maxDataDimension, maxPreviewDimension, createImageData = false) {
if (!maxDataDimension) {
// TODO: get this value from Firefox
// (https://bugzilla.mozilla.org/show_bug.cgi?id=1908184)
// It's the maximum dimension that the AI can handle.
maxDataDimension = 224;
}
// TODO: get this value from Firefox
// (https://bugzilla.mozilla.org/show_bug.cgi?id=1908184)
// It's the maximum dimension that the AI can handle.
maxDataDimension ||= 224;

const { width: bitmapWidth, height: bitmapHeight } = this.#bitmap;
const outputScale = new OutputScale();
Expand Down
18 changes: 4 additions & 14 deletions src/scripting_api/field.js
Original file line number Diff line number Diff line change
Expand Up @@ -334,27 +334,19 @@ class Field extends PDFObject {
}

buttonGetCaption(nFace = 0) {
if (this._buttonCaption) {
return this._buttonCaption[nFace];
}
return "";
return this._buttonCaption ? this._buttonCaption[nFace] : "";
}

buttonGetIcon(nFace = 0) {
if (this._buttonIcon) {
return this._buttonIcon[nFace];
}
return null;
return this._buttonIcon ? this._buttonIcon[nFace] : null;
}

buttonImportIcon(cPath = null, nPave = 0) {
/* Not implemented */
}

buttonSetCaption(cCaption, nFace = 0) {
if (!this._buttonCaption) {
this._buttonCaption = ["", "", ""];
}
this._buttonCaption ??= ["", "", ""];
this._buttonCaption[nFace] = cCaption;
// TODO: send to the annotation layer
// Right now the button is drawn on the canvas using its appearance so
Expand All @@ -363,9 +355,7 @@ class Field extends PDFObject {
}

buttonSetIcon(oIcon, nFace = 0) {
if (!this._buttonIcon) {
this._buttonIcon = [null, null, null];
}
this._buttonIcon ??= [null, null, null];
this._buttonIcon[nFace] = oIcon;
}

Expand Down
8 changes: 2 additions & 6 deletions src/scripting_api/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,7 @@ class Util extends PDFObject {
}
cFlags = flags;

if (nWidth) {
nWidth = parseInt(nWidth);
}
nWidth &&= parseInt(nWidth);

let intPart = Math.trunc(arg);

Expand All @@ -136,9 +134,7 @@ class Util extends PDFObject {
return hex;
}

if (nPrecision) {
nPrecision = parseInt(nPrecision.substring(1));
}
nPrecision &&= parseInt(nPrecision.substring(1));

nDecSep = nDecSep ? nDecSep.substring(1) : "0";
const separators = {
Expand Down
4 changes: 1 addition & 3 deletions test/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -968,9 +968,7 @@ class Driver {
if (task.type === "other" || task.enableXfa) {
return;
}
if (!task._prefetchedLoadingTask) {
task._prefetchedLoadingTask = getDocument(this._getDocumentOptions(task));
}
task._prefetchedLoadingTask ??= getDocument(this._getDocumentOptions(task));
}

_cleanup() {
Expand Down
9 changes: 3 additions & 6 deletions test/test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -801,9 +801,8 @@ async function handleWsBinaryResult(data) {
if (!taskResults) {
return;
}
if (!taskResults[round]) {
taskResults[round] = [];
}
taskResults[round] ||= [];

if (taskResults[round][page - 1]) {
console.error(
`Results for ${browser}:${id}:${round}:${page - 1} were already submitted`
Expand Down Expand Up @@ -1010,9 +1009,7 @@ async function startBrowser({
protocolTimeout: 0.75 * /* jasmine.DEFAULT_TIMEOUT_INTERVAL = */ 30000,
};

if (!tempDir) {
tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "pdfjs-"));
}
tempDir ||= fs.mkdtempSync(path.join(os.tmpdir(), "pdfjs-"));
const printFile = path.join(tempDir, "print.pdf");

if (browserName === "chrome") {
Expand Down
5 changes: 5 additions & 0 deletions test/unit/core_utils_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,11 @@ describe("core_utils", function () {
const str = "hello world";
expect(encodeToXmlString(str)).toEqual(str);
});

it("should keep the character after U+FFFE or U+FFFF", function () {
expect(encodeToXmlString("￿A")).toEqual("&#xFFFF;A");
expect(encodeToXmlString("￾B")).toEqual("&#xFFFE;B");
});
});

describe("validateCSSFont", function () {
Expand Down
8 changes: 3 additions & 5 deletions web/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2068,11 +2068,9 @@ const PDFViewerApplication = {
);
this.secondaryToolbar?.setPageNumber(this.pdfViewer.currentPageNumber);

if (!this.pdfViewer.currentScaleValue) {
// Scale was not initialized: invalid bookmark or scale was not specified.
// Setting the default one.
this.pdfViewer.currentScaleValue = DEFAULT_SCALE_VALUE;
}
// Scale was not initialized: invalid bookmark or scale was not specified.
// Setting the default one.
this.pdfViewer.currentScaleValue ||= DEFAULT_SCALE_VALUE;
},

/**
Expand Down
Loading
Loading