Merge pull request #18951 from Snuffleupagus/CMap-isCompressed

[api-minor] Remove the `CMapCompressionType` enumeration
This commit is contained in:
Tim van der Meij 2024-10-27 14:42:00 +01:00 committed by GitHub
commit 5418060bbc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 10 additions and 38 deletions

View File

@ -13,13 +13,8 @@
* limitations under the License. * limitations under the License.
*/ */
import {
CMapCompressionType,
FormatError,
unreachable,
warn,
} from "../shared/util.js";
import { Cmd, EOF, isCmd, Name } from "./primitives.js"; import { Cmd, EOF, isCmd, Name } from "./primitives.js";
import { FormatError, unreachable, warn } from "../shared/util.js";
import { BaseStream } from "./base_stream.js"; import { BaseStream } from "./base_stream.js";
import { BinaryCMapReader } from "./binary_cmap.js"; import { BinaryCMapReader } from "./binary_cmap.js";
import { Lexer } from "./parser.js"; import { Lexer } from "./parser.js";
@ -687,19 +682,16 @@ async function createBuiltInCMap(name, fetchBuiltInCMap) {
throw new Error("Built-in CMap parameters are not provided."); 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); const cMap = new CMap(true);
if (compressionType === CMapCompressionType.BINARY) { if (isCompressed) {
return new BinaryCMapReader().process(cMapData, cMap, useCMap => return new BinaryCMapReader().process(cMapData, cMap, useCMap =>
extendCMap(cMap, fetchBuiltInCMap, useCMap) extendCMap(cMap, fetchBuiltInCMap, useCMap)
); );
} }
if (compressionType === CMapCompressionType.NONE) { const lexer = new Lexer(new Stream(cMapData));
const lexer = new Lexer(new Stream(cMapData)); return parseCMap(cMap, lexer, fetchBuiltInCMap, null);
return parseCMap(cMap, lexer, fetchBuiltInCMap, null);
}
throw new Error(`Invalid CMap "compressionType" value: ${compressionType}`);
} }
class CMapFactory { class CMapFactory {

View File

@ -17,7 +17,6 @@
import { import {
AbortException, AbortException,
assert, assert,
CMapCompressionType,
FONT_IDENTITY_MATRIX, FONT_IDENTITY_MATRIX,
FormatError, FormatError,
IDENTITY_MATRIX, IDENTITY_MATRIX,
@ -392,17 +391,15 @@ class PartialEvaluator {
} }
data = { data = {
cMapData: new Uint8Array(await response.arrayBuffer()), cMapData: new Uint8Array(await response.arrayBuffer()),
compressionType: CMapCompressionType.BINARY, isCompressed: true,
}; };
} else { } else {
// Get the data on the main-thread instead. // Get the data on the main-thread instead.
data = await this.handler.sendWithPromise("FetchBuiltInCMap", { name }); 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; return data;
} }

View File

@ -13,7 +13,7 @@
* limitations under the License. * limitations under the License.
*/ */
import { CMapCompressionType, unreachable } from "../shared/util.js"; import { unreachable } from "../shared/util.js";
class BaseFilterFactory { class BaseFilterFactory {
constructor() { constructor() {
@ -129,12 +129,7 @@ class BaseCMapReaderFactory {
const url = this.baseUrl + name + (this.isCompressed ? ".bcmap" : ""); const url = this.baseUrl + name + (this.isCompressed ? ".bcmap" : "");
return this._fetch(url) return this._fetch(url)
.then(cMapData => ({ .then(cMapData => ({ cMapData, isCompressed: this.isCompressed }))
cMapData,
compressionType: this.isCompressed
? CMapCompressionType.BINARY
: CMapCompressionType.NONE,
}))
.catch(reason => { .catch(reason => {
throw new Error( throw new Error(
`Unable to load ${this.isCompressed ? "binary " : ""}CMap at: ${url}` `Unable to load ${this.isCompressed ? "binary " : ""}CMap at: ${url}`

View File

@ -27,7 +27,6 @@ import {
AnnotationEditorParamsType, AnnotationEditorParamsType,
AnnotationEditorType, AnnotationEditorType,
AnnotationMode, AnnotationMode,
CMapCompressionType,
createValidAbsoluteUrl, createValidAbsoluteUrl,
FeatureTest, FeatureTest,
ImageKind, ImageKind,
@ -96,7 +95,6 @@ export {
AnnotationLayer, AnnotationLayer,
AnnotationMode, AnnotationMode,
build, build,
CMapCompressionType,
ColorPicker, ColorPicker,
createValidAbsoluteUrl, createValidAbsoluteUrl,
DOMSVGFactory, DOMSVGFactory,

View File

@ -240,11 +240,6 @@ const VerbosityLevel = {
INFOS: 5, INFOS: 5,
}; };
const CMapCompressionType = {
NONE: 0,
BINARY: 1,
};
// All the possible operations for an operator list. // All the possible operations for an operator list.
const OPS = { const OPS = {
// Intentionally start from 1 so it is easy to spot bad operators that will be // Intentionally start from 1 so it is easy to spot bad operators that will be
@ -1119,7 +1114,6 @@ export {
BaseException, BaseException,
BASELINE_FACTOR, BASELINE_FACTOR,
bytesToString, bytesToString,
CMapCompressionType,
createValidAbsoluteUrl, createValidAbsoluteUrl,
DocumentActionEventType, DocumentActionEventType,
FeatureTest, FeatureTest,

View File

@ -18,7 +18,6 @@ import {
AnnotationEditorParamsType, AnnotationEditorParamsType,
AnnotationEditorType, AnnotationEditorType,
AnnotationMode, AnnotationMode,
CMapCompressionType,
createValidAbsoluteUrl, createValidAbsoluteUrl,
FeatureTest, FeatureTest,
ImageKind, ImageKind,
@ -74,7 +73,6 @@ const expectedAPI = Object.freeze({
AnnotationLayer, AnnotationLayer,
AnnotationMode, AnnotationMode,
build, build,
CMapCompressionType,
ColorPicker, ColorPicker,
createValidAbsoluteUrl, createValidAbsoluteUrl,
DOMSVGFactory, DOMSVGFactory,

View File

@ -22,7 +22,6 @@ const {
AnnotationLayer, AnnotationLayer,
AnnotationMode, AnnotationMode,
build, build,
CMapCompressionType,
ColorPicker, ColorPicker,
createValidAbsoluteUrl, createValidAbsoluteUrl,
DOMSVGFactory, DOMSVGFactory,
@ -69,7 +68,6 @@ export {
AnnotationLayer, AnnotationLayer,
AnnotationMode, AnnotationMode,
build, build,
CMapCompressionType,
ColorPicker, ColorPicker,
createValidAbsoluteUrl, createValidAbsoluteUrl,
DOMSVGFactory, DOMSVGFactory,