pdf-parser.js 5.2.27 → 5.2.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (145) hide show
  1. package/dist/{afm-widths-BYiX2L9D.cjs → afm-widths-BHD2HZIL.cjs} +553 -642
  2. package/dist/{afm-widths-blUDDjlI.js → afm-widths-B_IGbGky.js} +553 -642
  3. package/dist/afm-widths.cjs +1 -1
  4. package/dist/afm-widths.js +1 -1
  5. package/dist/annotations.cjs +5 -3
  6. package/dist/annotations.js +5 -3
  7. package/dist/builtin-encoding.cjs +17 -6
  8. package/dist/builtin-encoding.js +17 -6
  9. package/dist/bytes/crc32.cjs +5 -3
  10. package/dist/bytes/crc32.js +5 -3
  11. package/dist/bytes/flate.cjs +0 -1
  12. package/dist/bytes/flate.js +0 -1
  13. package/dist/cff-bounds.cjs +42 -24
  14. package/dist/cff-bounds.js +42 -24
  15. package/dist/cff.cjs +13 -6
  16. package/dist/cff.js +13 -6
  17. package/dist/cmap-table.cjs +54 -26
  18. package/dist/cmap-table.js +54 -26
  19. package/dist/cmap.cjs +5 -3
  20. package/dist/cmap.js +5 -3
  21. package/dist/content-write.cjs +3 -2
  22. package/dist/content-write.js +3 -2
  23. package/dist/crypto/aes.cjs +76 -55
  24. package/dist/crypto/aes.js +76 -55
  25. package/dist/crypto/md5.cjs +345 -149
  26. package/dist/crypto/md5.js +345 -149
  27. package/dist/crypto/rc4.cjs +5 -4
  28. package/dist/crypto/rc4.js +5 -4
  29. package/dist/crypto/sha2.cjs +92 -43
  30. package/dist/crypto/sha2.js +92 -43
  31. package/dist/embedded-font.cjs +4 -2
  32. package/dist/embedded-font.js +4 -2
  33. package/dist/encoding.cjs +1 -1
  34. package/dist/encoding.js +1 -1
  35. package/dist/encrypt-write.cjs +25 -21
  36. package/dist/encrypt-write.js +25 -21
  37. package/dist/encrypt.cjs +43 -64
  38. package/dist/encrypt.js +43 -64
  39. package/dist/filters.cjs +40 -20
  40. package/dist/filters.js +40 -20
  41. package/dist/font-face.cjs +2 -1
  42. package/dist/font-face.js +2 -1
  43. package/dist/font-read.cjs +12 -6
  44. package/dist/font-read.js +12 -6
  45. package/dist/font-tables.cjs +55 -28
  46. package/dist/font-tables.js +55 -28
  47. package/dist/gdef-table.cjs +6 -3
  48. package/dist/gdef-table.js +6 -3
  49. package/dist/glyf-contours.cjs +3 -1
  50. package/dist/glyf-contours.js +3 -1
  51. package/dist/glyf.cjs +22 -11
  52. package/dist/glyf.js +22 -11
  53. package/dist/gpos-table.cjs +37 -19
  54. package/dist/gpos-table.js +37 -19
  55. package/dist/gsub-table.cjs +28 -17
  56. package/dist/gsub-table.js +28 -17
  57. package/dist/hmtx-table.cjs +5 -3
  58. package/dist/hmtx-table.js +5 -3
  59. package/dist/image/ccitt-encode.cjs +8 -5
  60. package/dist/image/ccitt-encode.js +8 -5
  61. package/dist/image/ccitt.cjs +801 -209
  62. package/dist/image/ccitt.js +801 -209
  63. package/dist/image/jbig2-arith.cjs +340 -306
  64. package/dist/image/jbig2-arith.js +340 -306
  65. package/dist/image/jbig2-bitmap.cjs +8 -5
  66. package/dist/image/jbig2-bitmap.js +8 -5
  67. package/dist/image/jbig2-generic.cjs +240 -69
  68. package/dist/image/jbig2-generic.js +240 -69
  69. package/dist/image/jbig2-text.cjs +4 -2
  70. package/dist/image/jbig2-text.js +4 -2
  71. package/dist/image/jbig2.cjs +69 -31
  72. package/dist/image/jbig2.js +69 -31
  73. package/dist/image/jp2-boxes.cjs +52 -27
  74. package/dist/image/jp2-boxes.js +52 -27
  75. package/dist/image/jpeg-info.cjs +29 -24
  76. package/dist/image/jpeg-info.js +29 -24
  77. package/dist/image/jpeg2000-codestream.cjs +44 -24
  78. package/dist/image/jpeg2000-codestream.js +44 -24
  79. package/dist/image/jpeg2000-dwt.cjs +2 -1
  80. package/dist/image/jpeg2000-dwt.js +2 -1
  81. package/dist/image/jpeg2000-t1.cjs +21 -11
  82. package/dist/image/jpeg2000-t1.js +21 -11
  83. package/dist/image/jpeg2000-t2.cjs +12 -5
  84. package/dist/image/jpeg2000-t2.js +12 -5
  85. package/dist/image/jpeg2000-tagtree.cjs +8 -4
  86. package/dist/image/jpeg2000-tagtree.js +8 -4
  87. package/dist/image/jpeg2000.cjs +11 -6
  88. package/dist/image/jpeg2000.js +11 -6
  89. package/dist/image/png-decode.cjs +62 -39
  90. package/dist/image/png-decode.d.cts +3 -2
  91. package/dist/image/png-decode.d.ts +3 -2
  92. package/dist/image/png-decode.js +62 -39
  93. package/dist/image/png-filter.cjs +23 -15
  94. package/dist/image/png-filter.js +23 -15
  95. package/dist/images-read.cjs +41 -36
  96. package/dist/images-read.js +41 -36
  97. package/dist/index.cjs +1 -1
  98. package/dist/index.js +1 -1
  99. package/dist/interpret.cjs +39 -24
  100. package/dist/interpret.js +39 -24
  101. package/dist/lexer.cjs +86 -51
  102. package/dist/lexer.js +86 -51
  103. package/dist/math-content-write.cjs +9 -5
  104. package/dist/math-content-write.js +9 -5
  105. package/dist/math-font-write.cjs +2 -1
  106. package/dist/math-font-write.js +2 -1
  107. package/dist/math-font.cjs +16 -7
  108. package/dist/math-font.js +16 -7
  109. package/dist/math-table.cjs +25 -13
  110. package/dist/math-table.js +25 -13
  111. package/dist/matrix.cjs +3 -2
  112. package/dist/matrix.js +3 -2
  113. package/dist/measure.cjs +1 -1
  114. package/dist/measure.js +1 -1
  115. package/dist/navigation.cjs +10 -5
  116. package/dist/navigation.js +10 -5
  117. package/dist/ot-layout-common.cjs +4 -2
  118. package/dist/ot-layout-common.js +4 -2
  119. package/dist/parse.cjs +7 -5
  120. package/dist/parse.js +7 -5
  121. package/dist/pdf-text.cjs +5 -2
  122. package/dist/pdf-text.js +5 -2
  123. package/dist/predictors.cjs +14 -9
  124. package/dist/predictors.js +14 -9
  125. package/dist/raster.cjs +30 -19
  126. package/dist/raster.js +30 -19
  127. package/dist/read.cjs +17 -8
  128. package/dist/read.js +17 -8
  129. package/dist/serialize.cjs +6 -2
  130. package/dist/serialize.js +6 -2
  131. package/dist/sfnt-subset.cjs +25 -13
  132. package/dist/sfnt-subset.js +25 -13
  133. package/dist/sfnt.cjs +20 -10
  134. package/dist/sfnt.js +20 -10
  135. package/dist/text-group.cjs +0 -1
  136. package/dist/text-group.js +0 -1
  137. package/dist/tounicode.cjs +4 -2
  138. package/dist/tounicode.js +4 -2
  139. package/dist/winansi.cjs +1 -1
  140. package/dist/winansi.js +1 -1
  141. package/dist/write.cjs +20 -12
  142. package/dist/write.js +20 -12
  143. package/dist/xref.cjs +5 -2
  144. package/dist/xref.js +5 -2
  145. package/package.json +2 -2
@@ -34,15 +34,20 @@ const MATH_VALUE_RECORD_INDEX = {
34
34
  const MATH_VALUE_RECORDS_START = 8;
35
35
  const MATH_VALUE_RECORD_SIZE = 4;
36
36
  const RADICAL_DEGREE_BOTTOM_RAISE_PERCENT_OFFSET = 212;
37
+ const MATH_TABLE_HEADER_CONSTANTS_OFFSET_FIELD = 4;
38
+ const MATH_TABLE_HEADER_GLYPH_INFO_OFFSET_FIELD = 6;
39
+ const MATH_TABLE_HEADER_VARIANTS_OFFSET_FIELD = 8;
40
+ const PERCENT_SCALE_DENOMINATOR = 100;
41
+ const MATH_VALUE_TABLE_HEADER_SIZE = 4;
37
42
  function mathValueRecord(bytes, constantsOffset, index) {
38
43
  return require_sfnt.i16(bytes, constantsOffset + MATH_VALUE_RECORDS_START + index * MATH_VALUE_RECORD_SIZE);
39
44
  }
40
45
  function parseMathConstants(bytes, mathTableOffset) {
41
- const constantsOffset = mathTableOffset + require_sfnt.u16(bytes, mathTableOffset + 4);
46
+ const constantsOffset = mathTableOffset + require_sfnt.u16(bytes, mathTableOffset + MATH_TABLE_HEADER_CONSTANTS_OFFSET_FIELD);
42
47
  const field = (index) => mathValueRecord(bytes, constantsOffset, index);
43
48
  return {
44
- scriptPercentScaleDown: require_sfnt.i16(bytes, constantsOffset + 0) / 100,
45
- scriptScriptPercentScaleDown: require_sfnt.i16(bytes, constantsOffset + 2) / 100,
49
+ scriptPercentScaleDown: require_sfnt.i16(bytes, constantsOffset + 0) / PERCENT_SCALE_DENOMINATOR,
50
+ scriptScriptPercentScaleDown: require_sfnt.i16(bytes, constantsOffset + 2) / PERCENT_SCALE_DENOMINATOR,
46
51
  axisHeight: field(MATH_VALUE_RECORD_INDEX.axisHeight),
47
52
  subscriptShiftDown: field(MATH_VALUE_RECORD_INDEX.subscriptShiftDown),
48
53
  subscriptBaselineDropMin: field(MATH_VALUE_RECORD_INDEX.subscriptBaselineDropMin),
@@ -77,11 +82,11 @@ function parseGlyphValueTable(bytes, tableOffset) {
77
82
  const coverage = require_ot_layout_common.parseCoverage(bytes, tableOffset + require_sfnt.u16(bytes, tableOffset));
78
83
  const values = /* @__PURE__ */ new Map();
79
84
  if (coverage === void 0) return values;
80
- for (const [glyphId, coverageIndex] of coverage.entries()) values.set(glyphId, require_sfnt.i16(bytes, tableOffset + 4 + coverageIndex * 4));
85
+ for (const [glyphId, coverageIndex] of coverage.entries()) values.set(glyphId, require_sfnt.i16(bytes, tableOffset + MATH_VALUE_TABLE_HEADER_SIZE + coverageIndex * MATH_VALUE_RECORD_SIZE));
81
86
  return values;
82
87
  }
83
88
  function parseMathGlyphInfo(bytes, mathTableOffset) {
84
- const glyphInfoOffset = mathTableOffset + require_sfnt.u16(bytes, mathTableOffset + 6);
89
+ const glyphInfoOffset = mathTableOffset + require_sfnt.u16(bytes, mathTableOffset + MATH_TABLE_HEADER_GLYPH_INFO_OFFSET_FIELD);
85
90
  const italicsInfoOffset = require_sfnt.u16(bytes, glyphInfoOffset + 0);
86
91
  const topAccentOffset = require_sfnt.u16(bytes, glyphInfoOffset + 2);
87
92
  return {
@@ -93,6 +98,13 @@ const MATH_GLYPH_VARIANT_RECORD_SIZE = 4;
93
98
  const GLYPH_PART_RECORD_SIZE = 10;
94
99
  const GLYPH_PART_FLAG_EXTENDER = 1;
95
100
  const MATH_VARIANTS_HEADER_SIZE = 10;
101
+ const GLYPH_PART_END_CONNECTOR_OFFSET = 4;
102
+ const GLYPH_PART_FULL_ADVANCE_OFFSET = 6;
103
+ const GLYPH_PART_FLAGS_OFFSET = 8;
104
+ const MATH_GLYPH_CONSTRUCTION_HEADER_SIZE = 4;
105
+ const MATH_VARIANTS_HORIZONTAL_COVERAGE_OFFSET_FIELD = 4;
106
+ const MATH_VARIANTS_VERTICAL_COUNT_FIELD = 6;
107
+ const MATH_VARIANTS_HORIZONTAL_COUNT_FIELD = 8;
96
108
  function parseGlyphAssembly(bytes, assemblyOffset) {
97
109
  const partCount = require_sfnt.u16(bytes, assemblyOffset + MATH_VALUE_RECORD_SIZE);
98
110
  const parts = [];
@@ -101,9 +113,9 @@ function parseGlyphAssembly(bytes, assemblyOffset) {
101
113
  parts.push({
102
114
  glyphId: require_sfnt.u16(bytes, recordOffset),
103
115
  startConnectorLength: require_sfnt.u16(bytes, recordOffset + 2),
104
- endConnectorLength: require_sfnt.u16(bytes, recordOffset + 4),
105
- fullAdvance: require_sfnt.u16(bytes, recordOffset + 6),
106
- isExtender: (require_sfnt.u16(bytes, recordOffset + 8) & GLYPH_PART_FLAG_EXTENDER) !== 0
116
+ endConnectorLength: require_sfnt.u16(bytes, recordOffset + GLYPH_PART_END_CONNECTOR_OFFSET),
117
+ fullAdvance: require_sfnt.u16(bytes, recordOffset + GLYPH_PART_FULL_ADVANCE_OFFSET),
118
+ isExtender: (require_sfnt.u16(bytes, recordOffset + GLYPH_PART_FLAGS_OFFSET) & GLYPH_PART_FLAG_EXTENDER) !== 0
107
119
  });
108
120
  }
109
121
  return {
@@ -116,7 +128,7 @@ function parseGlyphConstruction(bytes, constructionOffset) {
116
128
  const variantCount = require_sfnt.u16(bytes, constructionOffset + 2);
117
129
  const variants = [];
118
130
  for (let i = 0; i < variantCount; i++) {
119
- const recordOffset = constructionOffset + 4 + i * MATH_GLYPH_VARIANT_RECORD_SIZE;
131
+ const recordOffset = constructionOffset + MATH_GLYPH_CONSTRUCTION_HEADER_SIZE + i * MATH_GLYPH_VARIANT_RECORD_SIZE;
120
132
  variants.push({
121
133
  glyphId: require_sfnt.u16(bytes, recordOffset),
122
134
  advanceMeasurement: require_sfnt.u16(bytes, recordOffset + 2)
@@ -139,7 +151,7 @@ function parseConstructionsForAxis(bytes, variantsOffset, coverageOffset, count,
139
151
  return constructions;
140
152
  }
141
153
  function parseMathVariants(bytes, mathTableOffset) {
142
- const variantsTableOffset = require_sfnt.u16(bytes, mathTableOffset + 8);
154
+ const variantsTableOffset = require_sfnt.u16(bytes, mathTableOffset + MATH_TABLE_HEADER_VARIANTS_OFFSET_FIELD);
143
155
  if (variantsTableOffset === 0) return {
144
156
  minConnectorOverlap: 0,
145
157
  vertical: /* @__PURE__ */ new Map(),
@@ -147,9 +159,9 @@ function parseMathVariants(bytes, mathTableOffset) {
147
159
  };
148
160
  const variantsOffset = mathTableOffset + variantsTableOffset;
149
161
  const verticalCoverageOffset = require_sfnt.u16(bytes, variantsOffset + 2);
150
- const horizontalCoverageOffset = require_sfnt.u16(bytes, variantsOffset + 4);
151
- const verticalCount = require_sfnt.u16(bytes, variantsOffset + 6);
152
- const horizontalCount = require_sfnt.u16(bytes, variantsOffset + 8);
162
+ const horizontalCoverageOffset = require_sfnt.u16(bytes, variantsOffset + MATH_VARIANTS_HORIZONTAL_COVERAGE_OFFSET_FIELD);
163
+ const verticalCount = require_sfnt.u16(bytes, variantsOffset + MATH_VARIANTS_VERTICAL_COUNT_FIELD);
164
+ const horizontalCount = require_sfnt.u16(bytes, variantsOffset + MATH_VARIANTS_HORIZONTAL_COUNT_FIELD);
153
165
  const verticalArrayOffset = variantsOffset + MATH_VARIANTS_HEADER_SIZE;
154
166
  const horizontalArrayOffset = verticalArrayOffset + verticalCount * 2;
155
167
  return {
@@ -33,15 +33,20 @@ const MATH_VALUE_RECORD_INDEX = {
33
33
  const MATH_VALUE_RECORDS_START = 8;
34
34
  const MATH_VALUE_RECORD_SIZE = 4;
35
35
  const RADICAL_DEGREE_BOTTOM_RAISE_PERCENT_OFFSET = 212;
36
+ const MATH_TABLE_HEADER_CONSTANTS_OFFSET_FIELD = 4;
37
+ const MATH_TABLE_HEADER_GLYPH_INFO_OFFSET_FIELD = 6;
38
+ const MATH_TABLE_HEADER_VARIANTS_OFFSET_FIELD = 8;
39
+ const PERCENT_SCALE_DENOMINATOR = 100;
40
+ const MATH_VALUE_TABLE_HEADER_SIZE = 4;
36
41
  function mathValueRecord(bytes, constantsOffset, index) {
37
42
  return i16(bytes, constantsOffset + MATH_VALUE_RECORDS_START + index * MATH_VALUE_RECORD_SIZE);
38
43
  }
39
44
  function parseMathConstants(bytes, mathTableOffset) {
40
- const constantsOffset = mathTableOffset + u16(bytes, mathTableOffset + 4);
45
+ const constantsOffset = mathTableOffset + u16(bytes, mathTableOffset + MATH_TABLE_HEADER_CONSTANTS_OFFSET_FIELD);
41
46
  const field = (index) => mathValueRecord(bytes, constantsOffset, index);
42
47
  return {
43
- scriptPercentScaleDown: i16(bytes, constantsOffset + 0) / 100,
44
- scriptScriptPercentScaleDown: i16(bytes, constantsOffset + 2) / 100,
48
+ scriptPercentScaleDown: i16(bytes, constantsOffset + 0) / PERCENT_SCALE_DENOMINATOR,
49
+ scriptScriptPercentScaleDown: i16(bytes, constantsOffset + 2) / PERCENT_SCALE_DENOMINATOR,
45
50
  axisHeight: field(MATH_VALUE_RECORD_INDEX.axisHeight),
46
51
  subscriptShiftDown: field(MATH_VALUE_RECORD_INDEX.subscriptShiftDown),
47
52
  subscriptBaselineDropMin: field(MATH_VALUE_RECORD_INDEX.subscriptBaselineDropMin),
@@ -76,11 +81,11 @@ function parseGlyphValueTable(bytes, tableOffset) {
76
81
  const coverage = parseCoverage(bytes, tableOffset + u16(bytes, tableOffset));
77
82
  const values = /* @__PURE__ */ new Map();
78
83
  if (coverage === void 0) return values;
79
- for (const [glyphId, coverageIndex] of coverage.entries()) values.set(glyphId, i16(bytes, tableOffset + 4 + coverageIndex * 4));
84
+ for (const [glyphId, coverageIndex] of coverage.entries()) values.set(glyphId, i16(bytes, tableOffset + MATH_VALUE_TABLE_HEADER_SIZE + coverageIndex * MATH_VALUE_RECORD_SIZE));
80
85
  return values;
81
86
  }
82
87
  function parseMathGlyphInfo(bytes, mathTableOffset) {
83
- const glyphInfoOffset = mathTableOffset + u16(bytes, mathTableOffset + 6);
88
+ const glyphInfoOffset = mathTableOffset + u16(bytes, mathTableOffset + MATH_TABLE_HEADER_GLYPH_INFO_OFFSET_FIELD);
84
89
  const italicsInfoOffset = u16(bytes, glyphInfoOffset + 0);
85
90
  const topAccentOffset = u16(bytes, glyphInfoOffset + 2);
86
91
  return {
@@ -92,6 +97,13 @@ const MATH_GLYPH_VARIANT_RECORD_SIZE = 4;
92
97
  const GLYPH_PART_RECORD_SIZE = 10;
93
98
  const GLYPH_PART_FLAG_EXTENDER = 1;
94
99
  const MATH_VARIANTS_HEADER_SIZE = 10;
100
+ const GLYPH_PART_END_CONNECTOR_OFFSET = 4;
101
+ const GLYPH_PART_FULL_ADVANCE_OFFSET = 6;
102
+ const GLYPH_PART_FLAGS_OFFSET = 8;
103
+ const MATH_GLYPH_CONSTRUCTION_HEADER_SIZE = 4;
104
+ const MATH_VARIANTS_HORIZONTAL_COVERAGE_OFFSET_FIELD = 4;
105
+ const MATH_VARIANTS_VERTICAL_COUNT_FIELD = 6;
106
+ const MATH_VARIANTS_HORIZONTAL_COUNT_FIELD = 8;
95
107
  function parseGlyphAssembly(bytes, assemblyOffset) {
96
108
  const partCount = u16(bytes, assemblyOffset + MATH_VALUE_RECORD_SIZE);
97
109
  const parts = [];
@@ -100,9 +112,9 @@ function parseGlyphAssembly(bytes, assemblyOffset) {
100
112
  parts.push({
101
113
  glyphId: u16(bytes, recordOffset),
102
114
  startConnectorLength: u16(bytes, recordOffset + 2),
103
- endConnectorLength: u16(bytes, recordOffset + 4),
104
- fullAdvance: u16(bytes, recordOffset + 6),
105
- isExtender: (u16(bytes, recordOffset + 8) & GLYPH_PART_FLAG_EXTENDER) !== 0
115
+ endConnectorLength: u16(bytes, recordOffset + GLYPH_PART_END_CONNECTOR_OFFSET),
116
+ fullAdvance: u16(bytes, recordOffset + GLYPH_PART_FULL_ADVANCE_OFFSET),
117
+ isExtender: (u16(bytes, recordOffset + GLYPH_PART_FLAGS_OFFSET) & GLYPH_PART_FLAG_EXTENDER) !== 0
106
118
  });
107
119
  }
108
120
  return {
@@ -115,7 +127,7 @@ function parseGlyphConstruction(bytes, constructionOffset) {
115
127
  const variantCount = u16(bytes, constructionOffset + 2);
116
128
  const variants = [];
117
129
  for (let i = 0; i < variantCount; i++) {
118
- const recordOffset = constructionOffset + 4 + i * MATH_GLYPH_VARIANT_RECORD_SIZE;
130
+ const recordOffset = constructionOffset + MATH_GLYPH_CONSTRUCTION_HEADER_SIZE + i * MATH_GLYPH_VARIANT_RECORD_SIZE;
119
131
  variants.push({
120
132
  glyphId: u16(bytes, recordOffset),
121
133
  advanceMeasurement: u16(bytes, recordOffset + 2)
@@ -138,7 +150,7 @@ function parseConstructionsForAxis(bytes, variantsOffset, coverageOffset, count,
138
150
  return constructions;
139
151
  }
140
152
  function parseMathVariants(bytes, mathTableOffset) {
141
- const variantsTableOffset = u16(bytes, mathTableOffset + 8);
153
+ const variantsTableOffset = u16(bytes, mathTableOffset + MATH_TABLE_HEADER_VARIANTS_OFFSET_FIELD);
142
154
  if (variantsTableOffset === 0) return {
143
155
  minConnectorOverlap: 0,
144
156
  vertical: /* @__PURE__ */ new Map(),
@@ -146,9 +158,9 @@ function parseMathVariants(bytes, mathTableOffset) {
146
158
  };
147
159
  const variantsOffset = mathTableOffset + variantsTableOffset;
148
160
  const verticalCoverageOffset = u16(bytes, variantsOffset + 2);
149
- const horizontalCoverageOffset = u16(bytes, variantsOffset + 4);
150
- const verticalCount = u16(bytes, variantsOffset + 6);
151
- const horizontalCount = u16(bytes, variantsOffset + 8);
161
+ const horizontalCoverageOffset = u16(bytes, variantsOffset + MATH_VARIANTS_HORIZONTAL_COVERAGE_OFFSET_FIELD);
162
+ const verticalCount = u16(bytes, variantsOffset + MATH_VARIANTS_VERTICAL_COUNT_FIELD);
163
+ const horizontalCount = u16(bytes, variantsOffset + MATH_VARIANTS_HORIZONTAL_COUNT_FIELD);
152
164
  const verticalArrayOffset = variantsOffset + MATH_VARIANTS_HEADER_SIZE;
153
165
  const horizontalArrayOffset = verticalArrayOffset + verticalCount * 2;
154
166
  return {
package/dist/matrix.cjs CHANGED
@@ -48,8 +48,9 @@ function scaleMatrix(sx, sy) {
48
48
  ];
49
49
  }
50
50
  const BEZIER_KAPPA = .5522847498;
51
+ const DEGREES_PER_HALF_TURN = 180;
51
52
  function rotationMatrix(degrees) {
52
- const radians = degrees * Math.PI / 180;
53
+ const radians = degrees * Math.PI / DEGREES_PER_HALF_TURN;
53
54
  const cos = Math.cos(radians);
54
55
  const sin = Math.sin(radians);
55
56
  return [
@@ -68,7 +69,7 @@ function matrixScaleY(m) {
68
69
  return Math.hypot(m[2], m[3]);
69
70
  }
70
71
  function matrixRotationDegrees(m) {
71
- return Math.atan2(m[1], m[0]) * 180 / Math.PI;
72
+ return Math.atan2(m[1], m[0]) * DEGREES_PER_HALF_TURN / Math.PI;
72
73
  }
73
74
  function rotatePointAboutCenter(point, center, degrees) {
74
75
  const relative = {
package/dist/matrix.js CHANGED
@@ -47,8 +47,9 @@ function scaleMatrix(sx, sy) {
47
47
  ];
48
48
  }
49
49
  const BEZIER_KAPPA = .5522847498;
50
+ const DEGREES_PER_HALF_TURN = 180;
50
51
  function rotationMatrix(degrees) {
51
- const radians = degrees * Math.PI / 180;
52
+ const radians = degrees * Math.PI / DEGREES_PER_HALF_TURN;
52
53
  const cos = Math.cos(radians);
53
54
  const sin = Math.sin(radians);
54
55
  return [
@@ -67,7 +68,7 @@ function matrixScaleY(m) {
67
68
  return Math.hypot(m[2], m[3]);
68
69
  }
69
70
  function matrixRotationDegrees(m) {
70
- return Math.atan2(m[1], m[0]) * 180 / Math.PI;
71
+ return Math.atan2(m[1], m[0]) * DEGREES_PER_HALF_TURN / Math.PI;
71
72
  }
72
73
  function rotatePointAboutCenter(point, center, degrees) {
73
74
  const relative = {
package/dist/measure.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_afm_widths = require("./afm-widths-BYiX2L9D.cjs");
2
+ const require_afm_widths = require("./afm-widths-BHD2HZIL.cjs");
3
3
  const require_embedded_font = require("./embedded-font.cjs");
4
4
  const require_font_registry = require("./font-registry.cjs");
5
5
  //#region src/measure.ts
package/dist/measure.js CHANGED
@@ -1,4 +1,4 @@
1
- import { h as encodeForShow, t as STANDARD_METRICS } from "./afm-widths-blUDDjlI.js";
1
+ import { h as encodeForShow, t as STANDARD_METRICS } from "./afm-widths-B_IGbGky.js";
2
2
  import { encodeForShowEmbedded } from "./embedded-font.js";
3
3
  import { resolveFaceWithRegistry } from "./font-registry.js";
4
4
  //#region src/measure.ts
@@ -6,6 +6,11 @@ const require_names = require("./names.cjs");
6
6
  function coordinateAt(arr, index) {
7
7
  return require_objects.asNumber(arr[index]);
8
8
  }
9
+ const DEST_XYZ_TOP_INDEX = 3;
10
+ const DEST_XYZ_ZOOM_INDEX = 4;
11
+ const DEST_FITR_BOTTOM_INDEX = 3;
12
+ const DEST_FITR_RIGHT_INDEX = 4;
13
+ const DEST_FITR_TOP_INDEX = 5;
9
14
  function parseDestination(value, resolver, pageIndex, sink) {
10
15
  const arr = require_objects.asArray(resolver.resolve(value));
11
16
  if (arr === void 0 || arr.length < 2) {
@@ -33,8 +38,8 @@ function parseDestination(value, resolver, pageIndex, sink) {
33
38
  kind: "xyz",
34
39
  ...optionalCoords(arr, [
35
40
  ["leftPt", 2],
36
- ["topPt", 3],
37
- ["zoom", 4]
41
+ ["topPt", DEST_XYZ_TOP_INDEX],
42
+ ["zoom", DEST_XYZ_ZOOM_INDEX]
38
43
  ])
39
44
  }
40
45
  };
@@ -62,9 +67,9 @@ function parseDestination(value, resolver, pageIndex, sink) {
62
67
  kind: "fitR",
63
68
  ...optionalCoords(arr, [
64
69
  ["leftPt", 2],
65
- ["bottomPt", 3],
66
- ["rightPt", 4],
67
- ["topPt", 5]
70
+ ["bottomPt", DEST_FITR_BOTTOM_INDEX],
71
+ ["rightPt", DEST_FITR_RIGHT_INDEX],
72
+ ["topPt", DEST_FITR_TOP_INDEX]
68
73
  ])
69
74
  }
70
75
  };
@@ -5,6 +5,11 @@ import { walkNameTree } from "./names.js";
5
5
  function coordinateAt(arr, index) {
6
6
  return asNumber(arr[index]);
7
7
  }
8
+ const DEST_XYZ_TOP_INDEX = 3;
9
+ const DEST_XYZ_ZOOM_INDEX = 4;
10
+ const DEST_FITR_BOTTOM_INDEX = 3;
11
+ const DEST_FITR_RIGHT_INDEX = 4;
12
+ const DEST_FITR_TOP_INDEX = 5;
8
13
  function parseDestination(value, resolver, pageIndex, sink) {
9
14
  const arr = asArray(resolver.resolve(value));
10
15
  if (arr === void 0 || arr.length < 2) {
@@ -32,8 +37,8 @@ function parseDestination(value, resolver, pageIndex, sink) {
32
37
  kind: "xyz",
33
38
  ...optionalCoords(arr, [
34
39
  ["leftPt", 2],
35
- ["topPt", 3],
36
- ["zoom", 4]
40
+ ["topPt", DEST_XYZ_TOP_INDEX],
41
+ ["zoom", DEST_XYZ_ZOOM_INDEX]
37
42
  ])
38
43
  }
39
44
  };
@@ -61,9 +66,9 @@ function parseDestination(value, resolver, pageIndex, sink) {
61
66
  kind: "fitR",
62
67
  ...optionalCoords(arr, [
63
68
  ["leftPt", 2],
64
- ["bottomPt", 3],
65
- ["rightPt", 4],
66
- ["topPt", 5]
69
+ ["bottomPt", DEST_FITR_BOTTOM_INDEX],
70
+ ["rightPt", DEST_FITR_RIGHT_INDEX],
71
+ ["topPt", DEST_FITR_TOP_INDEX]
67
72
  ])
68
73
  }
69
74
  };
@@ -26,6 +26,7 @@ function placeGlyph(ranges, glyphId, value, valueStep) {
26
26
  } };
27
27
  }
28
28
  const RANGE_RECORD_SIZE = 6;
29
+ const RANGE_RECORD_VALUE_OFFSET = 4;
29
30
  function parseRangeRecords(bytes, recordsOffset, recordCount) {
30
31
  if (!require_sfnt.hasBytes(bytes, recordsOffset, recordCount * RANGE_RECORD_SIZE)) return;
31
32
  const ranges = [];
@@ -37,7 +38,7 @@ function parseRangeRecords(bytes, recordsOffset, recordCount) {
37
38
  ranges.push({
38
39
  startGlyphId,
39
40
  endGlyphId,
40
- value: require_sfnt.u16(bytes, recordOffset + 4)
41
+ value: require_sfnt.u16(bytes, recordOffset + RANGE_RECORD_VALUE_OFFSET)
41
42
  });
42
43
  }
43
44
  ranges.sort((a, b) => a.startGlyphId - b.startGlyphId);
@@ -73,6 +74,7 @@ function parseCoverage(bytes, coverageOffset) {
73
74
  };
74
75
  }
75
76
  const CLASS_DEF_FORMAT_1_HEADER_SIZE = 6;
77
+ const CLASS_DEF_FORMAT_1_GLYPH_COUNT_OFFSET = 4;
76
78
  const CLASS_DEF_FORMAT_2_HEADER_SIZE = 4;
77
79
  function parseClassDef(bytes, classDefOffset) {
78
80
  if (!require_sfnt.hasBytes(bytes, classDefOffset, CLASS_DEF_FORMAT_2_HEADER_SIZE)) return;
@@ -81,7 +83,7 @@ function parseClassDef(bytes, classDefOffset) {
81
83
  if (format === 1) {
82
84
  if (!require_sfnt.hasBytes(bytes, classDefOffset, CLASS_DEF_FORMAT_1_HEADER_SIZE)) return;
83
85
  const startGlyphId = require_sfnt.u16(bytes, classDefOffset + 2);
84
- const glyphCount = require_sfnt.u16(bytes, classDefOffset + 4);
86
+ const glyphCount = require_sfnt.u16(bytes, classDefOffset + CLASS_DEF_FORMAT_1_GLYPH_COUNT_OFFSET);
85
87
  const classArrayOffset = classDefOffset + CLASS_DEF_FORMAT_1_HEADER_SIZE;
86
88
  if (!require_sfnt.hasBytes(bytes, classArrayOffset, glyphCount * 2)) return;
87
89
  ranges = [];
@@ -25,6 +25,7 @@ function placeGlyph(ranges, glyphId, value, valueStep) {
25
25
  } };
26
26
  }
27
27
  const RANGE_RECORD_SIZE = 6;
28
+ const RANGE_RECORD_VALUE_OFFSET = 4;
28
29
  function parseRangeRecords(bytes, recordsOffset, recordCount) {
29
30
  if (!hasBytes(bytes, recordsOffset, recordCount * RANGE_RECORD_SIZE)) return;
30
31
  const ranges = [];
@@ -36,7 +37,7 @@ function parseRangeRecords(bytes, recordsOffset, recordCount) {
36
37
  ranges.push({
37
38
  startGlyphId,
38
39
  endGlyphId,
39
- value: u16(bytes, recordOffset + 4)
40
+ value: u16(bytes, recordOffset + RANGE_RECORD_VALUE_OFFSET)
40
41
  });
41
42
  }
42
43
  ranges.sort((a, b) => a.startGlyphId - b.startGlyphId);
@@ -72,6 +73,7 @@ function parseCoverage(bytes, coverageOffset) {
72
73
  };
73
74
  }
74
75
  const CLASS_DEF_FORMAT_1_HEADER_SIZE = 6;
76
+ const CLASS_DEF_FORMAT_1_GLYPH_COUNT_OFFSET = 4;
75
77
  const CLASS_DEF_FORMAT_2_HEADER_SIZE = 4;
76
78
  function parseClassDef(bytes, classDefOffset) {
77
79
  if (!hasBytes(bytes, classDefOffset, CLASS_DEF_FORMAT_2_HEADER_SIZE)) return;
@@ -80,7 +82,7 @@ function parseClassDef(bytes, classDefOffset) {
80
82
  if (format === 1) {
81
83
  if (!hasBytes(bytes, classDefOffset, CLASS_DEF_FORMAT_1_HEADER_SIZE)) return;
82
84
  const startGlyphId = u16(bytes, classDefOffset + 2);
83
- const glyphCount = u16(bytes, classDefOffset + 4);
85
+ const glyphCount = u16(bytes, classDefOffset + CLASS_DEF_FORMAT_1_GLYPH_COUNT_OFFSET);
84
86
  const classArrayOffset = classDefOffset + CLASS_DEF_FORMAT_1_HEADER_SIZE;
85
87
  if (!hasBytes(bytes, classArrayOffset, glyphCount * 2)) return;
86
88
  ranges = [];
package/dist/parse.cjs CHANGED
@@ -110,10 +110,12 @@ function parseDictOrStreamBody(reader, sink) {
110
110
  reader.reset(afterDictMark);
111
111
  return dict;
112
112
  }
113
+ const CARRIAGE_RETURN = 13;
114
+ const LINE_FEED = 10;
113
115
  function skipStreamDataStart(reader, sink) {
114
- if (reader.peek() === 13) {
116
+ if (reader.peek() === CARRIAGE_RETURN) {
115
117
  reader.next();
116
- if (reader.peek() === 10) reader.next();
118
+ if (reader.peek() === LINE_FEED) reader.next();
117
119
  else sink({
118
120
  code: "pdf/stream-bad-eol",
119
121
  severity: "warning",
@@ -121,7 +123,7 @@ function skipStreamDataStart(reader, sink) {
121
123
  });
122
124
  return;
123
125
  }
124
- if (reader.peek() === 10) {
126
+ if (reader.peek() === LINE_FEED) {
125
127
  reader.next();
126
128
  return;
127
129
  }
@@ -187,8 +189,8 @@ function findEndstreamOffset(reader, fromOffset) {
187
189
  }
188
190
  function trimTrailingStreamEol(reader, dataStart, endstreamOffset) {
189
191
  const precedingTwo = reader.slice(Math.max(dataStart, endstreamOffset - 2), endstreamOffset);
190
- if (precedingTwo.length >= 2 && precedingTwo[precedingTwo.length - 2] === 13 && precedingTwo[precedingTwo.length - 1] === 10) return endstreamOffset - 2;
191
- if (precedingTwo.length >= 1 && (precedingTwo[precedingTwo.length - 1] === 10 || precedingTwo[precedingTwo.length - 1] === 13)) return endstreamOffset - 1;
192
+ if (precedingTwo.length >= 2 && precedingTwo[precedingTwo.length - 2] === CARRIAGE_RETURN && precedingTwo[precedingTwo.length - 1] === LINE_FEED) return endstreamOffset - 2;
193
+ if (precedingTwo.length >= 1 && (precedingTwo[precedingTwo.length - 1] === LINE_FEED || precedingTwo[precedingTwo.length - 1] === CARRIAGE_RETURN)) return endstreamOffset - 1;
192
194
  return endstreamOffset;
193
195
  }
194
196
  function parseIndirectObject(reader, sink) {
package/dist/parse.js CHANGED
@@ -109,10 +109,12 @@ function parseDictOrStreamBody(reader, sink) {
109
109
  reader.reset(afterDictMark);
110
110
  return dict;
111
111
  }
112
+ const CARRIAGE_RETURN = 13;
113
+ const LINE_FEED = 10;
112
114
  function skipStreamDataStart(reader, sink) {
113
- if (reader.peek() === 13) {
115
+ if (reader.peek() === CARRIAGE_RETURN) {
114
116
  reader.next();
115
- if (reader.peek() === 10) reader.next();
117
+ if (reader.peek() === LINE_FEED) reader.next();
116
118
  else sink({
117
119
  code: "pdf/stream-bad-eol",
118
120
  severity: "warning",
@@ -120,7 +122,7 @@ function skipStreamDataStart(reader, sink) {
120
122
  });
121
123
  return;
122
124
  }
123
- if (reader.peek() === 10) {
125
+ if (reader.peek() === LINE_FEED) {
124
126
  reader.next();
125
127
  return;
126
128
  }
@@ -186,8 +188,8 @@ function findEndstreamOffset(reader, fromOffset) {
186
188
  }
187
189
  function trimTrailingStreamEol(reader, dataStart, endstreamOffset) {
188
190
  const precedingTwo = reader.slice(Math.max(dataStart, endstreamOffset - 2), endstreamOffset);
189
- if (precedingTwo.length >= 2 && precedingTwo[precedingTwo.length - 2] === 13 && precedingTwo[precedingTwo.length - 1] === 10) return endstreamOffset - 2;
190
- if (precedingTwo.length >= 1 && (precedingTwo[precedingTwo.length - 1] === 10 || precedingTwo[precedingTwo.length - 1] === 13)) return endstreamOffset - 1;
191
+ if (precedingTwo.length >= 2 && precedingTwo[precedingTwo.length - 2] === CARRIAGE_RETURN && precedingTwo[precedingTwo.length - 1] === LINE_FEED) return endstreamOffset - 2;
192
+ if (precedingTwo.length >= 1 && (precedingTwo[precedingTwo.length - 1] === LINE_FEED || precedingTwo[precedingTwo.length - 1] === CARRIAGE_RETURN)) return endstreamOffset - 1;
191
193
  return endstreamOffset;
192
194
  }
193
195
  function parseIndirectObject(reader, sink) {
package/dist/pdf-text.cjs CHANGED
@@ -1,9 +1,12 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  //#region src/pdf-text.ts
3
+ const UTF16BE_BOM_BYTE_0 = 254;
4
+ const UTF16BE_BOM_BYTE_1 = 255;
5
+ const BITS_PER_BYTE = 8;
3
6
  function decodePdfString(bytes) {
4
- if (bytes.length >= 2 && bytes[0] === 254 && bytes[1] === 255) {
7
+ if (bytes.length >= 2 && bytes[0] === UTF16BE_BOM_BYTE_0 && bytes[1] === UTF16BE_BOM_BYTE_1) {
5
8
  let out = "";
6
- for (let i = 2; i + 1 < bytes.length; i += 2) out += String.fromCharCode((bytes[i] ?? 0) << 8 | (bytes[i + 1] ?? 0));
9
+ for (let i = 2; i + 1 < bytes.length; i += 2) out += String.fromCharCode((bytes[i] ?? 0) << BITS_PER_BYTE | (bytes[i + 1] ?? 0));
7
10
  return out;
8
11
  }
9
12
  return Array.from(bytes, (b) => String.fromCharCode(b)).join("");
package/dist/pdf-text.js CHANGED
@@ -1,8 +1,11 @@
1
1
  //#region src/pdf-text.ts
2
+ const UTF16BE_BOM_BYTE_0 = 254;
3
+ const UTF16BE_BOM_BYTE_1 = 255;
4
+ const BITS_PER_BYTE = 8;
2
5
  function decodePdfString(bytes) {
3
- if (bytes.length >= 2 && bytes[0] === 254 && bytes[1] === 255) {
6
+ if (bytes.length >= 2 && bytes[0] === UTF16BE_BOM_BYTE_0 && bytes[1] === UTF16BE_BOM_BYTE_1) {
4
7
  let out = "";
5
- for (let i = 2; i + 1 < bytes.length; i += 2) out += String.fromCharCode((bytes[i] ?? 0) << 8 | (bytes[i + 1] ?? 0));
8
+ for (let i = 2; i + 1 < bytes.length; i += 2) out += String.fromCharCode((bytes[i] ?? 0) << BITS_PER_BYTE | (bytes[i + 1] ?? 0));
6
9
  return out;
7
10
  }
8
11
  return Array.from(bytes, (b) => String.fromCharCode(b)).join("");
@@ -6,6 +6,11 @@ const DEFAULT_PREDICTOR = 1;
6
6
  const DEFAULT_COLORS = 1;
7
7
  const DEFAULT_BITS_PER_COMPONENT = 8;
8
8
  const DEFAULT_COLUMNS = 1;
9
+ const BITS_PER_BYTE = 8;
10
+ const BYTE_MASK = 255;
11
+ const PNG_PREDICTOR_CODE_MIN = 10;
12
+ const SIXTEEN_BIT_COMPONENT = 16;
13
+ const SIXTEEN_BIT_SAMPLE_MASK = 65535;
9
14
  function readPredictorParams(parms) {
10
15
  return {
11
16
  predictor: require_objects.asNumber(parms ? require_objects.dictGet(parms, "Predictor") : void 0) ?? DEFAULT_PREDICTOR,
@@ -16,10 +21,10 @@ function readPredictorParams(parms) {
16
21
  }
17
22
  function applyPredictor(data, params, sink) {
18
23
  if (params.predictor <= 1) return data;
19
- const bpp = Math.max(1, Math.ceil(params.colors * params.bitsPerComponent / 8));
20
- const bytesPerRow = Math.ceil(params.colors * params.bitsPerComponent * params.columns / 8);
24
+ const bpp = Math.max(1, Math.ceil(params.colors * params.bitsPerComponent / BITS_PER_BYTE));
25
+ const bytesPerRow = Math.ceil(params.colors * params.bitsPerComponent * params.columns / BITS_PER_BYTE);
21
26
  if (params.predictor === 2) return applyTiffPredictor(data, params, bytesPerRow, sink);
22
- if (params.predictor >= 10) {
27
+ if (params.predictor >= PNG_PREDICTOR_CODE_MIN) {
23
28
  const height = bytesPerRow > 0 ? Math.floor(data.length / (bytesPerRow + 1)) : 0;
24
29
  return require_image_png_filter.unfilterScanlines(data, height, bytesPerRow, bpp);
25
30
  }
@@ -31,7 +36,7 @@ function applyPredictor(data, params, sink) {
31
36
  return data;
32
37
  }
33
38
  function applyTiffPredictor(data, params, bytesPerRow, sink) {
34
- if (params.bitsPerComponent !== 8 && params.bitsPerComponent !== 16) {
39
+ if (params.bitsPerComponent !== BITS_PER_BYTE && params.bitsPerComponent !== SIXTEEN_BIT_COMPONENT) {
35
40
  sink({
36
41
  code: "pdf/unsupported-predictor",
37
42
  severity: "warning",
@@ -42,18 +47,18 @@ function applyTiffPredictor(data, params, bytesPerRow, sink) {
42
47
  const out = new Uint8Array(data.length);
43
48
  out.set(data);
44
49
  const rowCount = bytesPerRow > 0 ? Math.floor(out.length / bytesPerRow) : 0;
45
- const componentStride = params.bitsPerComponent === 16 ? 2 : 1;
50
+ const componentStride = params.bitsPerComponent === SIXTEEN_BIT_COMPONENT ? 2 : 1;
46
51
  const componentsPerPixel = params.colors;
47
52
  for (let row = 0; row < rowCount; row++) {
48
53
  const rowStart = row * bytesPerRow;
49
54
  for (let component = componentsPerPixel; component * componentStride < bytesPerRow; component++) {
50
55
  const i = rowStart + component * componentStride;
51
56
  const prevI = i - componentsPerPixel * componentStride;
52
- if (componentStride === 1) out[i] = (out[i] ?? 0) + (out[prevI] ?? 0) & 255;
57
+ if (componentStride === 1) out[i] = (out[i] ?? 0) + (out[prevI] ?? 0) & BYTE_MASK;
53
58
  else {
54
- const sum = ((out[i] ?? 0) << 8 | (out[i + 1] ?? 0)) + ((out[prevI] ?? 0) << 8 | (out[prevI + 1] ?? 0)) & 65535;
55
- out[i] = sum >> 8 & 255;
56
- out[i + 1] = sum & 255;
59
+ const sum = ((out[i] ?? 0) << BITS_PER_BYTE | (out[i + 1] ?? 0)) + ((out[prevI] ?? 0) << BITS_PER_BYTE | (out[prevI + 1] ?? 0)) & SIXTEEN_BIT_SAMPLE_MASK;
60
+ out[i] = sum >> BITS_PER_BYTE & BYTE_MASK;
61
+ out[i + 1] = sum & BYTE_MASK;
57
62
  }
58
63
  }
59
64
  }
@@ -5,6 +5,11 @@ const DEFAULT_PREDICTOR = 1;
5
5
  const DEFAULT_COLORS = 1;
6
6
  const DEFAULT_BITS_PER_COMPONENT = 8;
7
7
  const DEFAULT_COLUMNS = 1;
8
+ const BITS_PER_BYTE = 8;
9
+ const BYTE_MASK = 255;
10
+ const PNG_PREDICTOR_CODE_MIN = 10;
11
+ const SIXTEEN_BIT_COMPONENT = 16;
12
+ const SIXTEEN_BIT_SAMPLE_MASK = 65535;
8
13
  function readPredictorParams(parms) {
9
14
  return {
10
15
  predictor: asNumber(parms ? dictGet(parms, "Predictor") : void 0) ?? DEFAULT_PREDICTOR,
@@ -15,10 +20,10 @@ function readPredictorParams(parms) {
15
20
  }
16
21
  function applyPredictor(data, params, sink) {
17
22
  if (params.predictor <= 1) return data;
18
- const bpp = Math.max(1, Math.ceil(params.colors * params.bitsPerComponent / 8));
19
- const bytesPerRow = Math.ceil(params.colors * params.bitsPerComponent * params.columns / 8);
23
+ const bpp = Math.max(1, Math.ceil(params.colors * params.bitsPerComponent / BITS_PER_BYTE));
24
+ const bytesPerRow = Math.ceil(params.colors * params.bitsPerComponent * params.columns / BITS_PER_BYTE);
20
25
  if (params.predictor === 2) return applyTiffPredictor(data, params, bytesPerRow, sink);
21
- if (params.predictor >= 10) {
26
+ if (params.predictor >= PNG_PREDICTOR_CODE_MIN) {
22
27
  const height = bytesPerRow > 0 ? Math.floor(data.length / (bytesPerRow + 1)) : 0;
23
28
  return unfilterScanlines(data, height, bytesPerRow, bpp);
24
29
  }
@@ -30,7 +35,7 @@ function applyPredictor(data, params, sink) {
30
35
  return data;
31
36
  }
32
37
  function applyTiffPredictor(data, params, bytesPerRow, sink) {
33
- if (params.bitsPerComponent !== 8 && params.bitsPerComponent !== 16) {
38
+ if (params.bitsPerComponent !== BITS_PER_BYTE && params.bitsPerComponent !== SIXTEEN_BIT_COMPONENT) {
34
39
  sink({
35
40
  code: "pdf/unsupported-predictor",
36
41
  severity: "warning",
@@ -41,18 +46,18 @@ function applyTiffPredictor(data, params, bytesPerRow, sink) {
41
46
  const out = new Uint8Array(data.length);
42
47
  out.set(data);
43
48
  const rowCount = bytesPerRow > 0 ? Math.floor(out.length / bytesPerRow) : 0;
44
- const componentStride = params.bitsPerComponent === 16 ? 2 : 1;
49
+ const componentStride = params.bitsPerComponent === SIXTEEN_BIT_COMPONENT ? 2 : 1;
45
50
  const componentsPerPixel = params.colors;
46
51
  for (let row = 0; row < rowCount; row++) {
47
52
  const rowStart = row * bytesPerRow;
48
53
  for (let component = componentsPerPixel; component * componentStride < bytesPerRow; component++) {
49
54
  const i = rowStart + component * componentStride;
50
55
  const prevI = i - componentsPerPixel * componentStride;
51
- if (componentStride === 1) out[i] = (out[i] ?? 0) + (out[prevI] ?? 0) & 255;
56
+ if (componentStride === 1) out[i] = (out[i] ?? 0) + (out[prevI] ?? 0) & BYTE_MASK;
52
57
  else {
53
- const sum = ((out[i] ?? 0) << 8 | (out[i + 1] ?? 0)) + ((out[prevI] ?? 0) << 8 | (out[prevI + 1] ?? 0)) & 65535;
54
- out[i] = sum >> 8 & 255;
55
- out[i + 1] = sum & 255;
58
+ const sum = ((out[i] ?? 0) << BITS_PER_BYTE | (out[i + 1] ?? 0)) + ((out[prevI] ?? 0) << BITS_PER_BYTE | (out[prevI + 1] ?? 0)) & SIXTEEN_BIT_SAMPLE_MASK;
59
+ out[i] = sum >> BITS_PER_BYTE & BYTE_MASK;
60
+ out[i + 1] = sum & BYTE_MASK;
56
61
  }
57
62
  }
58
63
  }