mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-07-24 16:07:22 +02:00
Remove unnecessary class constructors in the src folder
There's a number of classes where the constructors can be removed completely by instead using class fields, which help to slightly shorten the code. It seems that `unicorn/prefer-class-fields` ESLint plugin, see PR 20657, unfortunately isn't able to detect all of these cases.
This commit is contained in:
parent
74ab1a98a6
commit
7fd939763e
@ -1051,9 +1051,7 @@ class CFFHeader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class CFFStrings {
|
class CFFStrings {
|
||||||
constructor() {
|
strings = [];
|
||||||
this.strings = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
get(index) {
|
get(index) {
|
||||||
if (index >= 0 && index <= NUM_STANDARD_CFF_STRINGS - 1) {
|
if (index >= 0 && index <= NUM_STANDARD_CFF_STRINGS - 1) {
|
||||||
@ -1087,10 +1085,9 @@ class CFFStrings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class CFFIndex {
|
class CFFIndex {
|
||||||
constructor() {
|
objects = [];
|
||||||
this.objects = [];
|
|
||||||
this.length = 0;
|
length = 0;
|
||||||
}
|
|
||||||
|
|
||||||
add(data) {
|
add(data) {
|
||||||
this.length += data.length;
|
this.length += data.length;
|
||||||
@ -1323,9 +1320,7 @@ class CFFFDSelect {
|
|||||||
// Helper class to keep track of where an offset is within the data and helps
|
// Helper class to keep track of where an offset is within the data and helps
|
||||||
// filling in that offset once it's known.
|
// filling in that offset once it's known.
|
||||||
class CFFOffsetTracker {
|
class CFFOffsetTracker {
|
||||||
constructor() {
|
offsets = Object.create(null);
|
||||||
this.offsets = Object.create(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
isTracking(key) {
|
isTracking(key) {
|
||||||
return key in this.offsets;
|
return key in this.offsets;
|
||||||
|
|||||||
@ -27,10 +27,7 @@ function decodeString(str) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class DatasetXMLParser extends SimpleXMLParser {
|
class DatasetXMLParser extends SimpleXMLParser {
|
||||||
constructor(options) {
|
node = null;
|
||||||
super(options);
|
|
||||||
this.node = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
onEndElement(name) {
|
onEndElement(name) {
|
||||||
const node = super.onEndElement(name);
|
const node = super.onEndElement(name);
|
||||||
|
|||||||
@ -5042,21 +5042,31 @@ class StateManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class TextState {
|
class TextState {
|
||||||
constructor() {
|
ctm = new Float32Array(IDENTITY_MATRIX);
|
||||||
this.ctm = new Float32Array(IDENTITY_MATRIX);
|
|
||||||
this.fontName = null;
|
fontName = null;
|
||||||
this.fontSize = 0;
|
|
||||||
this.loadedName = null;
|
fontSize = 0;
|
||||||
this.font = null;
|
|
||||||
this.fontMatrix = FONT_IDENTITY_MATRIX;
|
loadedName = null;
|
||||||
this.textMatrix = IDENTITY_MATRIX.slice();
|
|
||||||
this.textLineMatrix = IDENTITY_MATRIX.slice();
|
font = null;
|
||||||
this.charSpacing = 0;
|
|
||||||
this.wordSpacing = 0;
|
fontMatrix = FONT_IDENTITY_MATRIX;
|
||||||
this.leading = 0;
|
|
||||||
this.textHScale = 1;
|
textMatrix = IDENTITY_MATRIX.slice();
|
||||||
this.textRise = 0;
|
|
||||||
}
|
textLineMatrix = IDENTITY_MATRIX.slice();
|
||||||
|
|
||||||
|
charSpacing = 0;
|
||||||
|
|
||||||
|
wordSpacing = 0;
|
||||||
|
|
||||||
|
leading = 0;
|
||||||
|
|
||||||
|
textHScale = 1;
|
||||||
|
|
||||||
|
textRise = 0;
|
||||||
|
|
||||||
setTextMatrix(a, b, c, d, e, f) {
|
setTextMatrix(a, b, c, d, e, f) {
|
||||||
const m = this.textMatrix;
|
const m = this.textMatrix;
|
||||||
@ -5105,24 +5115,28 @@ class TextState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class EvalState {
|
class EvalState {
|
||||||
constructor() {
|
ctm = new Float32Array(IDENTITY_MATRIX);
|
||||||
this.ctm = new Float32Array(IDENTITY_MATRIX);
|
|
||||||
this.font = null;
|
|
||||||
this.textRenderingMode = TextRenderingMode.FILL;
|
|
||||||
this._fillColorSpace = this._strokeColorSpace = ColorSpaceUtils.gray;
|
|
||||||
this.patternFillColorSpace = null;
|
|
||||||
this.patternStrokeColorSpace = null;
|
|
||||||
|
|
||||||
// Path stuff.
|
font = null;
|
||||||
this.currentPointX = this.currentPointY = 0;
|
|
||||||
this.pathMinMax = new Float32Array([
|
textRenderingMode = TextRenderingMode.FILL;
|
||||||
Infinity,
|
|
||||||
Infinity,
|
_fillColorSpace = ColorSpaceUtils.gray;
|
||||||
-Infinity,
|
|
||||||
-Infinity,
|
_strokeColorSpace = ColorSpaceUtils.gray;
|
||||||
]);
|
|
||||||
this.pathBuffer = [];
|
patternFillColorSpace = null;
|
||||||
}
|
|
||||||
|
patternStrokeColorSpace = null;
|
||||||
|
|
||||||
|
// Path stuff.
|
||||||
|
currentPointX = 0;
|
||||||
|
|
||||||
|
currentPointY = 0;
|
||||||
|
|
||||||
|
pathMinMax = new Float32Array([Infinity, Infinity, -Infinity, -Infinity]);
|
||||||
|
|
||||||
|
pathBuffer = [];
|
||||||
|
|
||||||
get fillColorSpace() {
|
get fillColorSpace() {
|
||||||
return this._fillColorSpace;
|
return this._fillColorSpace;
|
||||||
|
|||||||
@ -836,9 +836,7 @@ class AstVariableDefinition extends AstNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class ExpressionBuilderVisitor {
|
class ExpressionBuilderVisitor {
|
||||||
constructor() {
|
parts = [];
|
||||||
this.parts = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
visitArgument(arg) {
|
visitArgument(arg) {
|
||||||
this.parts.push(
|
this.parts.push(
|
||||||
|
|||||||
@ -398,9 +398,7 @@ class RefSet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class RefSetCache {
|
class RefSetCache {
|
||||||
constructor() {
|
_map = new Map();
|
||||||
this._map = new Map();
|
|
||||||
}
|
|
||||||
|
|
||||||
get size() {
|
get size() {
|
||||||
return this._map.size;
|
return this._map.size;
|
||||||
|
|||||||
@ -17,21 +17,32 @@ import { ColorConverters } from "../shared/scripting_utils.js";
|
|||||||
import { PDFObject } from "./pdf_object.js";
|
import { PDFObject } from "./pdf_object.js";
|
||||||
|
|
||||||
class Color extends PDFObject {
|
class Color extends PDFObject {
|
||||||
|
transparent = ["T"];
|
||||||
|
|
||||||
|
black = ["G", 0];
|
||||||
|
|
||||||
|
white = ["G", 1];
|
||||||
|
|
||||||
|
red = ["RGB", 1, 0, 0];
|
||||||
|
|
||||||
|
green = ["RGB", 0, 1, 0];
|
||||||
|
|
||||||
|
blue = ["RGB", 0, 0, 1];
|
||||||
|
|
||||||
|
cyan = ["CMYK", 1, 0, 0, 0];
|
||||||
|
|
||||||
|
magenta = ["CMYK", 0, 1, 0, 0];
|
||||||
|
|
||||||
|
yellow = ["CMYK", 0, 0, 1, 0];
|
||||||
|
|
||||||
|
dkGray = ["G", 0.25];
|
||||||
|
|
||||||
|
gray = ["G", 0.5];
|
||||||
|
|
||||||
|
ltGray = ["G", 0.75];
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super({});
|
super({});
|
||||||
|
|
||||||
this.transparent = ["T"];
|
|
||||||
this.black = ["G", 0];
|
|
||||||
this.white = ["G", 1];
|
|
||||||
this.red = ["RGB", 1, 0, 0];
|
|
||||||
this.green = ["RGB", 0, 1, 0];
|
|
||||||
this.blue = ["RGB", 0, 0, 1];
|
|
||||||
this.cyan = ["CMYK", 1, 0, 0, 0];
|
|
||||||
this.magenta = ["CMYK", 0, 1, 0, 0];
|
|
||||||
this.yellow = ["CMYK", 0, 0, 1, 0];
|
|
||||||
this.dkGray = ["G", 0.25];
|
|
||||||
this.gray = ["G", 0.5];
|
|
||||||
this.ltGray = ["G", 0.75];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static _isValidSpace(cColorSpace) {
|
static _isValidSpace(cColorSpace) {
|
||||||
|
|||||||
@ -17,20 +17,25 @@ import { Cursor } from "./constants.js";
|
|||||||
import { PDFObject } from "./pdf_object.js";
|
import { PDFObject } from "./pdf_object.js";
|
||||||
|
|
||||||
class FullScreen extends PDFObject {
|
class FullScreen extends PDFObject {
|
||||||
constructor(data) {
|
_backgroundColor = [];
|
||||||
super(data);
|
|
||||||
|
|
||||||
this._backgroundColor = [];
|
_clickAdvances = true;
|
||||||
this._clickAdvances = true;
|
|
||||||
this._cursor = Cursor.hidden;
|
_cursor = Cursor.hidden;
|
||||||
this._defaultTransition = "";
|
|
||||||
this._escapeExits = true;
|
_defaultTransition = "";
|
||||||
this._isFullScreen = true;
|
|
||||||
this._loop = false;
|
_escapeExits = true;
|
||||||
this._timeDelay = 3600;
|
|
||||||
this._usePageTiming = false;
|
_isFullScreen = true;
|
||||||
this._useTimer = false;
|
|
||||||
}
|
_loop = false;
|
||||||
|
|
||||||
|
_timeDelay = 3600;
|
||||||
|
|
||||||
|
_usePageTiming = false;
|
||||||
|
|
||||||
|
_useTimer = false;
|
||||||
|
|
||||||
get backgroundColor() {
|
get backgroundColor() {
|
||||||
return this._backgroundColor;
|
return this._backgroundColor;
|
||||||
|
|||||||
@ -14,12 +14,10 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
class ProxyHandler {
|
class ProxyHandler {
|
||||||
constructor() {
|
// Don't dispatch an event for those properties.
|
||||||
// Don't dispatch an event for those properties.
|
// - delay: allow to delay field redraw until delay is set to false.
|
||||||
// - delay: allow to delay field redraw until delay is set to false.
|
// Likely it's useless to implement that stuff.
|
||||||
// Likely it's useless to implement that stuff.
|
nosend = new Set(["delay"]);
|
||||||
this.nosend = new Set(["delay"]);
|
|
||||||
}
|
|
||||||
|
|
||||||
get(obj, prop) {
|
get(obj, prop) {
|
||||||
// script may add some properties to the object
|
// script may add some properties to the object
|
||||||
|
|||||||
@ -16,14 +16,13 @@
|
|||||||
import { PDFObject } from "./pdf_object.js";
|
import { PDFObject } from "./pdf_object.js";
|
||||||
|
|
||||||
class Thermometer extends PDFObject {
|
class Thermometer extends PDFObject {
|
||||||
constructor(data) {
|
_cancelled = false;
|
||||||
super(data);
|
|
||||||
|
|
||||||
this._cancelled = false;
|
_duration = 100;
|
||||||
this._duration = 100;
|
|
||||||
this._text = "";
|
_text = "";
|
||||||
this._value = 0;
|
|
||||||
}
|
_value = 0;
|
||||||
|
|
||||||
get cancelled() {
|
get cancelled() {
|
||||||
return this._cancelled;
|
return this._cancelled;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user