Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[api-minor] Remove the CMapCompressionType enumeration #18951

Merged
merged 2 commits into from
Oct 27, 2024
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
18 changes: 5 additions & 13 deletions src/core/cmap.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,8 @@
* limitations under the License.
*/

import {
CMapCompressionType,
FormatError,
unreachable,
warn,
} from "../shared/util.js";
import { Cmd, EOF, isCmd, Name } from "./primitives.js";
import { FormatError, unreachable, warn } from "../shared/util.js";
import { BaseStream } from "./base_stream.js";
import { BinaryCMapReader } from "./binary_cmap.js";
import { Lexer } from "./parser.js";
Expand Down Expand Up @@ -687,19 +682,16 @@ async function createBuiltInCMap(name, fetchBuiltInCMap) {
throw new Error("Built-in CMap parameters are not provided.");
}

const { cMapData, compressionType } = await fetchBuiltInCMap(name);
const { cMapData, isCompressed } = await fetchBuiltInCMap(name);
const cMap = new CMap(true);

if (compressionType === CMapCompressionType.BINARY) {
if (isCompressed) {
return new BinaryCMapReader().process(cMapData, cMap, useCMap =>
extendCMap(cMap, fetchBuiltInCMap, useCMap)
);
}
if (compressionType === CMapCompressionType.NONE) {
const lexer = new Lexer(new Stream(cMapData));
return parseCMap(cMap, lexer, fetchBuiltInCMap, null);
}
throw new Error(`Invalid CMap "compressionType" value: ${compressionType}`);
const lexer = new Lexer(new Stream(cMapData));
return parseCMap(cMap, lexer, fetchBuiltInCMap, null);
}

class CMapFactory {
Expand Down
9 changes: 3 additions & 6 deletions src/core/evaluator.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import {
AbortException,
assert,
CMapCompressionType,
FONT_IDENTITY_MATRIX,
FormatError,
IDENTITY_MATRIX,
Expand Down Expand Up @@ -392,17 +391,15 @@ class PartialEvaluator {
}
data = {
cMapData: new Uint8Array(await response.arrayBuffer()),
compressionType: CMapCompressionType.BINARY,
isCompressed: true,
};
} else {
// Get the data on the main-thread instead.
data = await this.handler.sendWithPromise("FetchBuiltInCMap", { name });
}
// Cache the CMap data, to avoid fetching it repeatedly.
this.builtInCMapCache.set(name, data);

if (data.compressionType !== CMapCompressionType.NONE) {
// Given the size of uncompressed CMaps, only cache compressed ones.
this.builtInCMapCache.set(name, data);
}
return data;
}

Expand Down
9 changes: 2 additions & 7 deletions src/display/base_factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* limitations under the License.
*/

import { CMapCompressionType, unreachable } from "../shared/util.js";
import { unreachable } from "../shared/util.js";

class BaseFilterFactory {
constructor() {
Expand Down Expand Up @@ -129,12 +129,7 @@ class BaseCMapReaderFactory {
const url = this.baseUrl + name + (this.isCompressed ? ".bcmap" : "");

return this._fetch(url)
.then(cMapData => ({
cMapData,
compressionType: this.isCompressed
? CMapCompressionType.BINARY
: CMapCompressionType.NONE,
}))
.then(cMapData => ({ cMapData, isCompressed: this.isCompressed }))
.catch(reason => {
throw new Error(
`Unable to load ${this.isCompressed ? "binary " : ""}CMap at: ${url}`
Expand Down
2 changes: 0 additions & 2 deletions src/pdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import {
AnnotationEditorParamsType,
AnnotationEditorType,
AnnotationMode,
CMapCompressionType,
createValidAbsoluteUrl,
FeatureTest,
ImageKind,
Expand Down Expand Up @@ -96,7 +95,6 @@ export {
AnnotationLayer,
AnnotationMode,
build,
CMapCompressionType,
ColorPicker,
createValidAbsoluteUrl,
DOMSVGFactory,
Expand Down
6 changes: 0 additions & 6 deletions src/shared/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,6 @@ const VerbosityLevel = {
INFOS: 5,
};

const CMapCompressionType = {
NONE: 0,
BINARY: 1,
};

// All the possible operations for an operator list.
const OPS = {
// Intentionally start from 1 so it is easy to spot bad operators that will be
Expand Down Expand Up @@ -1119,7 +1114,6 @@ export {
BaseException,
BASELINE_FACTOR,
bytesToString,
CMapCompressionType,
createValidAbsoluteUrl,
DocumentActionEventType,
FeatureTest,
Expand Down
2 changes: 0 additions & 2 deletions test/unit/pdf_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
AnnotationEditorParamsType,
AnnotationEditorType,
AnnotationMode,
CMapCompressionType,
createValidAbsoluteUrl,
FeatureTest,
ImageKind,
Expand Down Expand Up @@ -74,7 +73,6 @@ const expectedAPI = Object.freeze({
AnnotationLayer,
AnnotationMode,
build,
CMapCompressionType,
ColorPicker,
createValidAbsoluteUrl,
DOMSVGFactory,
Expand Down
2 changes: 0 additions & 2 deletions web/pdfjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ const {
AnnotationLayer,
AnnotationMode,
build,
CMapCompressionType,
ColorPicker,
createValidAbsoluteUrl,
DOMSVGFactory,
Expand Down Expand Up @@ -69,7 +68,6 @@ export {
AnnotationLayer,
AnnotationMode,
build,
CMapCompressionType,
ColorPicker,
createValidAbsoluteUrl,
DOMSVGFactory,
Expand Down