Typed color spaces (CalGray/CalRGB/Lab/ICCBased/Indexed/Separation/DeviceN/NChannel/Pattern) — ISO 32000-2 §8.6.

Module pdfColorSpacesExtended | Source packages/front/office/pdf/src/extra/color-spaces-extended.js | Deps pdfErrors, pdfParserObj | Worker-safe yes

Types color spaces expressed as an array whose first element is the family name, plus the named device families. Coverage: CalGray (§8.6.5.2), CalRGB (§8.6.5.3), Lab (§8.6.5.4), ICCBased (§8.6.5.5, with Metadata), Indexed (§8.6.6.3), Separation (§8.6.6.4), DeviceN (§8.6.6.5) with /Attributes, NChannel (a DeviceN subtype with /Process), Pattern (§8.7).

Resolve

const ext = runtime.resolve('pdfColorSpacesExtended');
// Returns: { typeColorSpace, COLOR_SPACE_FAMILIES, typeColorPart, COLOR_PART_KEYS }

API

Member Signature Returns
typeColorSpace (value) => CS Record { family, ..., raw }.
COLOR_SPACE_FAMILIES Set<string> The 12 known families.
typeColorPart (dict, kind) => ColorPart A DeviceN attributes dictionary (kind deviceN: Subtype, Colorants, Process, MixingHints), its mixing hints (mixingHints), process (process: ColorSpace a name or an array) or solidities (solidities: Default), a resource dictionary's default colour spaces (colorSpaceMap) or a dictionary of functions (functions: Default): one field per key of its list, named after the key in lower case, present only when the key is — a name, a string (its bytes), a number or an integer by its value, an array, a dictionary or a stream as read, a key of several types by the first that fits, a reference as read, null for a value of another type — plus raw and _extras.
COLOR_PART_KEYS frozen object Kind → its keys (the Arlington PDF Model's lists).

Examples

Type a CS array

const ext = runtime.resolve('pdfColorSpacesExtended');
const cs = ext.typeColorSpace(arrayCs);
cs.family;    // 'ICCBased'
cs.n;         // 3
cs.metadata;  // streamObj | null

DeviceN

cs.family;      // 'DeviceN'
cs.names;       // ['Cyan','Magenta','Yellow','Black','PANTONE 185 C']
cs.attributes;  // dict | null

Errors

Code Class When
pdf/extra/colorspace/bad-shape ParseError Neither a name nor an array.
pdf/extra/colorspace/bad-family ParseError Entry 0 is not a name.
pdf/extra/colorspace/unknown ParseError Family outside COLOR_SPACE_FAMILIES.
pdf/extra/color-part/not-dict ParseError typeColorPart: not a dict.
pdf/extra/color-part/kind ContractError typeColorPart: kind missing or not a key of COLOR_PART_KEYS.
pdf/extra/colorspace/cal-no-dict ParseError CalGray/CalRGB without a dict.
pdf/extra/colorspace/cal-truncated ParseError CalGray/CalRGB truncated.
pdf/extra/colorspace/lab-truncated ParseError Lab without a dict.
pdf/extra/colorspace/icc-no-stream ParseError ICCBased without a stream.
pdf/extra/colorspace/indexed-truncated ParseError Indexed incomplete.
pdf/extra/colorspace/indexed-bad-hival ParseError hival is not an int.
pdf/extra/colorspace/sep-truncated ParseError Separation incomplete.
pdf/extra/colorspace/devn-truncated ParseError DeviceN incomplete.

See also