Skip to content

Commit 5418060

Browse files
Merge pull request mozilla#18951 from Snuffleupagus/CMap-isCompressed
[api-minor] Remove the `CMapCompressionType` enumeration
2 parents b5805ca + b048420 commit 5418060

File tree

7 files changed

+10
-38
lines changed

7 files changed

+10
-38
lines changed

src/core/cmap.js

+5-13
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,8 @@
1313
* limitations under the License.
1414
*/
1515

16-
import {
17-
CMapCompressionType,
18-
FormatError,
19-
unreachable,
20-
warn,
21-
} from "../shared/util.js";
2216
import { Cmd, EOF, isCmd, Name } from "./primitives.js";
17+
import { FormatError, unreachable, warn } from "../shared/util.js";
2318
import { BaseStream } from "./base_stream.js";
2419
import { BinaryCMapReader } from "./binary_cmap.js";
2520
import { Lexer } from "./parser.js";
@@ -687,19 +682,16 @@ async function createBuiltInCMap(name, fetchBuiltInCMap) {
687682
throw new Error("Built-in CMap parameters are not provided.");
688683
}
689684

690-
const { cMapData, compressionType } = await fetchBuiltInCMap(name);
685+
const { cMapData, isCompressed } = await fetchBuiltInCMap(name);
691686
const cMap = new CMap(true);
692687

693-
if (compressionType === CMapCompressionType.BINARY) {
688+
if (isCompressed) {
694689
return new BinaryCMapReader().process(cMapData, cMap, useCMap =>
695690
extendCMap(cMap, fetchBuiltInCMap, useCMap)
696691
);
697692
}
698-
if (compressionType === CMapCompressionType.NONE) {
699-
const lexer = new Lexer(new Stream(cMapData));
700-
return parseCMap(cMap, lexer, fetchBuiltInCMap, null);
701-
}
702-
throw new Error(`Invalid CMap "compressionType" value: ${compressionType}`);
693+
const lexer = new Lexer(new Stream(cMapData));
694+
return parseCMap(cMap, lexer, fetchBuiltInCMap, null);
703695
}
704696

705697
class CMapFactory {

src/core/evaluator.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import {
1818
AbortException,
1919
assert,
20-
CMapCompressionType,
2120
FONT_IDENTITY_MATRIX,
2221
FormatError,
2322
IDENTITY_MATRIX,
@@ -392,17 +391,15 @@ class PartialEvaluator {
392391
}
393392
data = {
394393
cMapData: new Uint8Array(await response.arrayBuffer()),
395-
compressionType: CMapCompressionType.BINARY,
394+
isCompressed: true,
396395
};
397396
} else {
398397
// Get the data on the main-thread instead.
399398
data = await this.handler.sendWithPromise("FetchBuiltInCMap", { name });
400399
}
400+
// Cache the CMap data, to avoid fetching it repeatedly.
401+
this.builtInCMapCache.set(name, data);
401402

402-
if (data.compressionType !== CMapCompressionType.NONE) {
403-
// Given the size of uncompressed CMaps, only cache compressed ones.
404-
this.builtInCMapCache.set(name, data);
405-
}
406403
return data;
407404
}
408405

src/display/base_factory.js

+2-7
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* limitations under the License.
1414
*/
1515

16-
import { CMapCompressionType, unreachable } from "../shared/util.js";
16+
import { unreachable } from "../shared/util.js";
1717

1818
class BaseFilterFactory {
1919
constructor() {
@@ -129,12 +129,7 @@ class BaseCMapReaderFactory {
129129
const url = this.baseUrl + name + (this.isCompressed ? ".bcmap" : "");
130130

131131
return this._fetch(url)
132-
.then(cMapData => ({
133-
cMapData,
134-
compressionType: this.isCompressed
135-
? CMapCompressionType.BINARY
136-
: CMapCompressionType.NONE,
137-
}))
132+
.then(cMapData => ({ cMapData, isCompressed: this.isCompressed }))
138133
.catch(reason => {
139134
throw new Error(
140135
`Unable to load ${this.isCompressed ? "binary " : ""}CMap at: ${url}`

src/pdf.js

-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import {
2727
AnnotationEditorParamsType,
2828
AnnotationEditorType,
2929
AnnotationMode,
30-
CMapCompressionType,
3130
createValidAbsoluteUrl,
3231
FeatureTest,
3332
ImageKind,
@@ -96,7 +95,6 @@ export {
9695
AnnotationLayer,
9796
AnnotationMode,
9897
build,
99-
CMapCompressionType,
10098
ColorPicker,
10199
createValidAbsoluteUrl,
102100
DOMSVGFactory,

src/shared/util.js

-6
Original file line numberDiff line numberDiff line change
@@ -240,11 +240,6 @@ const VerbosityLevel = {
240240
INFOS: 5,
241241
};
242242

243-
const CMapCompressionType = {
244-
NONE: 0,
245-
BINARY: 1,
246-
};
247-
248243
// All the possible operations for an operator list.
249244
const OPS = {
250245
// Intentionally start from 1 so it is easy to spot bad operators that will be
@@ -1119,7 +1114,6 @@ export {
11191114
BaseException,
11201115
BASELINE_FACTOR,
11211116
bytesToString,
1122-
CMapCompressionType,
11231117
createValidAbsoluteUrl,
11241118
DocumentActionEventType,
11251119
FeatureTest,

test/unit/pdf_spec.js

-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import {
1818
AnnotationEditorParamsType,
1919
AnnotationEditorType,
2020
AnnotationMode,
21-
CMapCompressionType,
2221
createValidAbsoluteUrl,
2322
FeatureTest,
2423
ImageKind,
@@ -74,7 +73,6 @@ const expectedAPI = Object.freeze({
7473
AnnotationLayer,
7574
AnnotationMode,
7675
build,
77-
CMapCompressionType,
7876
ColorPicker,
7977
createValidAbsoluteUrl,
8078
DOMSVGFactory,

web/pdfjs.js

-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ const {
2222
AnnotationLayer,
2323
AnnotationMode,
2424
build,
25-
CMapCompressionType,
2625
ColorPicker,
2726
createValidAbsoluteUrl,
2827
DOMSVGFactory,
@@ -69,7 +68,6 @@ export {
6968
AnnotationLayer,
7069
AnnotationMode,
7170
build,
72-
CMapCompressionType,
7371
ColorPicker,
7472
createValidAbsoluteUrl,
7573
DOMSVGFactory,

0 commit comments

Comments
 (0)