mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-19 22:58:07 +02:00
Merge pull request #19260 from Snuffleupagus/src-core-simplify-ifs
Shorten some `if`-statements in the `src/core/` folder
This commit is contained in:
commit
b4abfec3ac
6 changed files with 16 additions and 26 deletions
|
@ -1686,12 +1686,12 @@ class MarkupAnnotation extends Annotation {
|
|||
buffer.push(`${fillColor[0]} ${fillColor[1]} ${fillColor[2]} rg`);
|
||||
}
|
||||
|
||||
let pointsArray = this.data.quadPoints;
|
||||
if (!pointsArray) {
|
||||
// If there are no quadpoints, the rectangle should be used instead.
|
||||
// Convert the rectangle definition to a points array similar to how the
|
||||
// quadpoints are defined.
|
||||
pointsArray = Float32Array.from([
|
||||
// If there are no quadpoints, the rectangle should be used instead.
|
||||
// Convert the rectangle definition to a points array similar to how the
|
||||
// quadpoints are defined.
|
||||
const pointsArray =
|
||||
this.data.quadPoints ||
|
||||
Float32Array.from([
|
||||
this.rectangle[0],
|
||||
this.rectangle[3],
|
||||
this.rectangle[2],
|
||||
|
@ -1701,7 +1701,6 @@ class MarkupAnnotation extends Annotation {
|
|||
this.rectangle[2],
|
||||
this.rectangle[1],
|
||||
]);
|
||||
}
|
||||
|
||||
for (let i = 0, ii = pointsArray.length; i < ii; i += 8) {
|
||||
const [mX, MX, mY, MY] = pointsCallback(
|
||||
|
@ -1755,11 +1754,8 @@ class MarkupAnnotation extends Annotation {
|
|||
}
|
||||
|
||||
static async createNewAnnotation(xref, annotation, changes, params) {
|
||||
if (!annotation.ref) {
|
||||
annotation.ref = xref.getNewTemporaryRef();
|
||||
}
|
||||
const annotationRef = (annotation.ref ||= xref.getNewTemporaryRef());
|
||||
|
||||
const annotationRef = annotation.ref;
|
||||
const ap = await this.createNewAppearanceStream(annotation, xref, params);
|
||||
let annotationDict;
|
||||
|
||||
|
|
|
@ -567,10 +567,7 @@ class Catalog {
|
|||
const onParsed = [];
|
||||
if (Array.isArray(refs)) {
|
||||
for (const value of refs) {
|
||||
if (!(value instanceof Ref)) {
|
||||
continue;
|
||||
}
|
||||
if (groupRefCache.has(value)) {
|
||||
if (value instanceof Ref && groupRefCache.has(value)) {
|
||||
onParsed.push(value.toString());
|
||||
}
|
||||
}
|
||||
|
@ -629,7 +626,7 @@ class Catalog {
|
|||
return null;
|
||||
}
|
||||
const nestedOrder = parseOrder(value.slice(1), nestedLevels);
|
||||
if (!nestedOrder || !nestedOrder.length) {
|
||||
if (!nestedOrder?.length) {
|
||||
return null;
|
||||
}
|
||||
return { name: stringToPDFString(nestedName), order: nestedOrder };
|
||||
|
|
|
@ -466,7 +466,7 @@ const blackTable3 = [
|
|||
*/
|
||||
class CCITTFaxDecoder {
|
||||
constructor(source, options = {}) {
|
||||
if (!source || typeof source.next !== "function") {
|
||||
if (typeof source?.next !== "function") {
|
||||
throw new Error('CCITTFaxDecoder - invalid "source" parameter.');
|
||||
}
|
||||
this.source = source;
|
||||
|
|
|
@ -36,7 +36,7 @@ class DecryptStream extends DecodeStream {
|
|||
chunk = this.str.getBytes(chunkSize);
|
||||
this.initialized = true;
|
||||
}
|
||||
if (!chunk || chunk.length === 0) {
|
||||
if (!chunk?.length) {
|
||||
this.eof = true;
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -818,7 +818,7 @@ class CompiledFont {
|
|||
}
|
||||
|
||||
compileGlyph(code, glyphId) {
|
||||
if (!code || code.length === 0 || code[0] === 14) {
|
||||
if (!code?.length || code[0] === 14) {
|
||||
return NOOP;
|
||||
}
|
||||
|
||||
|
|
|
@ -310,18 +310,15 @@ class XRef {
|
|||
if (!("streamState" in this)) {
|
||||
// Stores state of the stream as we process it so we can resume
|
||||
// from middle of stream in case of missing data error
|
||||
const streamParameters = stream.dict;
|
||||
const byteWidths = streamParameters.get("W");
|
||||
let range = streamParameters.get("Index");
|
||||
if (!range) {
|
||||
range = [0, streamParameters.get("Size")];
|
||||
}
|
||||
const { dict, pos } = stream;
|
||||
const byteWidths = dict.get("W");
|
||||
const range = dict.get("Index") || [0, dict.get("Size")];
|
||||
|
||||
this.streamState = {
|
||||
entryRanges: range,
|
||||
byteWidths,
|
||||
entryNum: 0,
|
||||
streamPos: stream.pos,
|
||||
streamPos: pos,
|
||||
};
|
||||
}
|
||||
this.readXRefStream(stream);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue