mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-08-02 20:37:21 +02:00
Merge pull request #21041 from timvandermeij/function-type-enumeration
Introduce a function type enumeration
This commit is contained in:
commit
345329e490
@ -60,6 +60,7 @@ import {
|
|||||||
RefSet,
|
RefSet,
|
||||||
RefSetCache,
|
RefSetCache,
|
||||||
} from "./primitives.js";
|
} from "./primitives.js";
|
||||||
|
import { FunctionType, PDFFunctionFactory } from "./function.js";
|
||||||
import { getXfaFontDict, getXfaFontName } from "./xfa_fonts.js";
|
import { getXfaFontDict, getXfaFontName } from "./xfa_fonts.js";
|
||||||
import { NullStream, Stream } from "./stream.js";
|
import { NullStream, Stream } from "./stream.js";
|
||||||
import { BaseStream } from "./base_stream.js";
|
import { BaseStream } from "./base_stream.js";
|
||||||
@ -73,7 +74,6 @@ import { LocalColorSpaceCache } from "./image_utils.js";
|
|||||||
import { ObjectLoader } from "./object_loader.js";
|
import { ObjectLoader } from "./object_loader.js";
|
||||||
import { OperatorList } from "./operator_list.js";
|
import { OperatorList } from "./operator_list.js";
|
||||||
import { PartialEvaluator } from "./evaluator.js";
|
import { PartialEvaluator } from "./evaluator.js";
|
||||||
import { PDFFunctionFactory } from "./function.js";
|
|
||||||
import { PDFImage } from "./image.js";
|
import { PDFImage } from "./image.js";
|
||||||
import { StreamsSequenceStream } from "./decode_stream.js";
|
import { StreamsSequenceStream } from "./decode_stream.js";
|
||||||
import { StructTreePage } from "./struct_tree.js";
|
import { StructTreePage } from "./struct_tree.js";
|
||||||
@ -2131,7 +2131,7 @@ class PDFDocument {
|
|||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dict.get("FunctionType") === 4) {
|
if (dict.get("FunctionType") === FunctionType.POSTSCRIPT_CALCULATOR) {
|
||||||
const source = value.getString();
|
const source = value.getString();
|
||||||
value.reset();
|
value.reset();
|
||||||
const domain = dict.get("Domain") ?? [];
|
const domain = dict.get("Domain") ?? [];
|
||||||
|
|||||||
@ -22,6 +22,13 @@ import { isNumberArray } from "./core_utils.js";
|
|||||||
import { LocalFunctionCache } from "./image_utils.js";
|
import { LocalFunctionCache } from "./image_utils.js";
|
||||||
import { MathClamp } from "../shared/math_clamp.js";
|
import { MathClamp } from "../shared/math_clamp.js";
|
||||||
|
|
||||||
|
const FunctionType = {
|
||||||
|
SAMPLED: 0,
|
||||||
|
EXPONENTIAL_INTERPOLATION: 2,
|
||||||
|
STITCHING: 3,
|
||||||
|
POSTSCRIPT_CALCULATOR: 4,
|
||||||
|
};
|
||||||
|
|
||||||
class PDFFunctionFactory {
|
class PDFFunctionFactory {
|
||||||
static #useWasm = true;
|
static #useWasm = true;
|
||||||
|
|
||||||
@ -126,18 +133,16 @@ class PDFFunction {
|
|||||||
const typeNum = dict.get("FunctionType");
|
const typeNum = dict.get("FunctionType");
|
||||||
|
|
||||||
switch (typeNum) {
|
switch (typeNum) {
|
||||||
case 0:
|
case FunctionType.SAMPLED:
|
||||||
return this.constructSampled(factory, fn, dict);
|
return this.constructSampled(factory, fn, dict);
|
||||||
case 1:
|
case FunctionType.EXPONENTIAL_INTERPOLATION:
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
return this.constructInterpolated(factory, dict);
|
return this.constructInterpolated(factory, dict);
|
||||||
case 3:
|
case FunctionType.STITCHING:
|
||||||
return this.constructStiched(factory, dict);
|
return this.constructStiched(factory, dict);
|
||||||
case 4:
|
case FunctionType.POSTSCRIPT_CALCULATOR:
|
||||||
return this.constructPostScript(factory, fn, dict);
|
return this.constructPostScript(factory, fn, dict);
|
||||||
}
|
}
|
||||||
throw new FormatError("Unknown type of function");
|
throw new FormatError(`Unknown function type: ${typeNum}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
static parseArray(factory, fnObj) {
|
static parseArray(factory, fnObj) {
|
||||||
@ -391,4 +396,4 @@ function isPDFFunction(v) {
|
|||||||
return fnDict.has("FunctionType");
|
return fnDict.has("FunctionType");
|
||||||
}
|
}
|
||||||
|
|
||||||
export { isPDFFunction, PDFFunctionFactory };
|
export { FunctionType, isPDFFunction, PDFFunctionFactory };
|
||||||
|
|||||||
@ -14,6 +14,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { Dict, Name, Ref } from "../../src/core/primitives.js";
|
import { Dict, Name, Ref } from "../../src/core/primitives.js";
|
||||||
|
import { FunctionType, PDFFunctionFactory } from "../../src/core/function.js";
|
||||||
import {
|
import {
|
||||||
GlobalColorSpaceCache,
|
GlobalColorSpaceCache,
|
||||||
LocalColorSpaceCache,
|
LocalColorSpaceCache,
|
||||||
@ -21,7 +22,6 @@ import {
|
|||||||
import { Stream, StringStream } from "../../src/core/stream.js";
|
import { Stream, StringStream } from "../../src/core/stream.js";
|
||||||
import { ColorSpace } from "../../src/core/colorspace.js";
|
import { ColorSpace } from "../../src/core/colorspace.js";
|
||||||
import { ColorSpaceUtils } from "../../src/core/colorspace_utils.js";
|
import { ColorSpaceUtils } from "../../src/core/colorspace_utils.js";
|
||||||
import { PDFFunctionFactory } from "../../src/core/function.js";
|
|
||||||
import { XRefMock } from "./test_utils.js";
|
import { XRefMock } from "./test_utils.js";
|
||||||
|
|
||||||
describe("colorspace", function () {
|
describe("colorspace", function () {
|
||||||
@ -836,7 +836,7 @@ describe("colorspace", function () {
|
|||||||
|
|
||||||
it("should handle the case when cs is an array", function () {
|
it("should handle the case when cs is an array", function () {
|
||||||
const fnDict = new Dict();
|
const fnDict = new Dict();
|
||||||
fnDict.set("FunctionType", 4);
|
fnDict.set("FunctionType", FunctionType.POSTSCRIPT_CALCULATOR);
|
||||||
fnDict.set("Domain", [0.0, 1.0]);
|
fnDict.set("Domain", [0.0, 1.0]);
|
||||||
fnDict.set("Range", [0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0]);
|
fnDict.set("Range", [0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0]);
|
||||||
fnDict.set("Length", 58);
|
fnDict.set("Length", 58);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user