import { CieSpace } from './cie-color.js'; import { IccTransform } from './icc.js'; import { PdfFunction } from './function.js'; import { ShapeGradient } from '../core/vector.js'; import { PdfDict } from '../pdf/objects.js'; import { PdfFile } from './document.js'; /** * Resolve a page's `/Pattern` resources into gradient fills (E-PDF EP16c, ISO * 32000-1 §8.7.4.5). Every `PatternType` 2 (shading) pattern is evaluated — its * `/Shading` type 2 (axial) or 3 (radial) plus the `/Function` colour stops — * and keyed by resource name; the interpreter looks the name up when a shape is * filled with `/Pattern cs /Pn scn`. The bare `sh` operator (clip-bounded) is * not captured. * * @param file The owning file. * @param resources The resource dictionary in force — a page's, or the form or * annotation appearance's own. * @returns A map from pattern resource name to its {@link ShapeGradient}. */ export declare function buildShadingMap(file: PdfFile, resources: PdfDict | undefined): Map; /** * §8.7.4.5.2 — an axial or radial shading as a gradient, for a bare `sh`. * * A `sh` paints the CLIP rather than a path, so what it needs is not a fill for * a shape the page drew but the gradient itself, to fill the region with. It is * the same reading `buildShadingMap` does for a pattern. * * @param file The owning file. * @param sh The shading dictionary. * @returns The gradient, or `undefined` for a type this does not read. */ export declare function gradientShading(file: PdfFile, sh: PdfDict): ShapeGradient | undefined; /** * §8.7.4.5 — which kind of shading this is, as the file states it. * * @param file The owning file. * @param sh The shading dictionary. * @returns Its `/ShadingType`, or 0 where the file states none. */ export declare function shadingTypeOf(file: PdfFile, sh: PdfDict): number; /** * §8.7.4.5.3 — a FUNCTION-BASED shading, sampled into a picture. * * Type 1 is not a ramp between two points: it is a function of two variables * over a rectangle, and no gradient can stand for one. Painted by a bare `sh` * it fills the clip, and nothing here lifted it at all — * function_based_shading.pdf is nine such squares and 43% of the page's ink, * and reconstructed to a blank sheet. * * Sampled it is exactly a picture, which every format downstream can show. The * grid is fixed: the function is smooth by construction (§8.7.4.5.3 gives it a * `/Domain` and nothing else), so more samples buy nothing a reader can see. * * @param file The owning file. * @param shading The shading dictionary. * @returns The picture and the domain it covers, or `undefined` for a shading * of another type or one whose function cannot be run. */ export declare function sampledShading(file: PdfFile, shading: PdfDict): { rgb: Uint8Array; size: number; domain: [number, number, number, number]; } | undefined; /** * §8.6.8 — the colour a run of `sc` / `scn` components comes to. * * The space in force decides, and where it was not read the COUNT is the next * best witness: three numbers are RGB and four are CMYK on every device space * there is. One number is the ambiguous case — grey in a device space, but the * strength of a colorant in a Separation, where 1 is the ink at full and reads * dark — so a lone component is only taken where the space said what it means. * * @param nums The components, as the page or a shading's function states them. * @param space The space in force, where it was read. * @returns The colour as 6 hex digits, or `undefined` where the numbers do not * say what colour they are. */ export declare function spaceColor(nums: ReadonlyArray, space: ColorSpaceInfo | undefined): string | undefined; /** Three channels, each 0..1, as 6 upper-case hex digits. */ export declare function rgbHex(r: number, g: number, b: number): string; /** One grey level, 0..1, as 6 upper-case hex digits. */ export declare function grayHex(v: number): string; /** §8.6.4.4 — four inks, each 0..1, as 6 upper-case hex digits. */ export declare function cmykHex(c: number, m: number, y: number, k: number): string; /** * §11.6.4.4 — the constant fill alpha (`/ca`) of every `/ExtGState` the page * names, by name. * * `gs` sets a whole graphics state at once, and one of the things in it is how * opaque the paint is. 22060_A1_01_Plans.pdf marks its evacuation routes with * a green band at `ca` 0.6, meant to be read THROUGH: painted solid, the floor * plan under each band disappears. * * §11.3.5 `/BM` comes off the same dictionary. A blend nothing downstream can * perform is still worth knowing: `Multiply` and `Darken` both let dark ink * under the paint show through, which is what a highlighter IS, and a mark that * only darkens belongs UNDER the words rather than over them. * * @param file The owning file. * @param resources The resource dictionary in force — a page's, or the form or * annotation appearance's own, since `gs` resolves against * whichever is current. * @returns Name → the fill alpha and blend worth carrying, for the states that * state one. */ export declare function buildAlphaMap(file: PdfFile, resources: PdfDict | undefined): Map; /** * What a `/ExtGState` says about paint that the reconstruction can carry. * * Every field is absent when the state does not NAME that parameter, because a * `gs` leaves what it does not name alone (§8.4.5). */ export interface GsPaint { /** §11.6.4.4 `/ca` — the constant fill alpha, where the state names one. */ readonly alpha?: number; /** §11.3.5 — whether `/BM` is named at all, since naming `/Normal` ends a blend. */ readonly statesBlend?: boolean; /** §11.3.5 `/BM` — the paint only darkens, so what it covers shows through. */ readonly darkens?: boolean; /** * §11.3.5 `/BM` — a blend NOTHING downstream can perform, named so the loss * report can say which. `Normal` is no blend at all and is never named here. */ readonly blend?: string; /** * §11.6.5 `/SMask` — the paint's opacity varies from place to place, out of * another group's luminosity or alpha. Nothing downstream has a mask like it. * `false` where the state names `/None`, which takes a mask off. */ readonly masked?: boolean; } /** * §8.6 — how many components a colour space takes, and what they mean. * * `sc` / `scn` give bare numbers; only the space in force says whether `1 1 1` * is white or something else, and whether a lone `1` is white (DeviceGray) or * the colorant at full strength (Separation), which is usually black. */ export interface ColorSpaceInfo { readonly kind: 'gray' | 'rgb' | 'cmyk' | 'tint'; readonly components: number; /** * §8.6.5.6/§8.6.5.7 — the CIE parameters, for a `CalGray` or `CalRGB` space. * Its numbers look like a device space's and are not: they mean what comes * out of this transform. */ readonly cie?: CieSpace; /** * §8.6.5.5 — the transform an `/ICCBased` profile states, where its form is * one this reads. Its numbers mean what the PROFILE makes of them, which for * anything but an sRGB-like profile is not what a device space would. */ readonly icc?: IccTransform; /** * §8.6.6.4/§8.6.6.5 — for a `Separation` or `DeviceN`, the way OUT of it: the * tint transform and the space its numbers land in. Absent where the file * states a transform this cannot run, and then a tint is only "this much ink". */ readonly tint?: { readonly transform: PdfFunction; readonly alternate: ColorSpaceInfo; }; } /** * The spaces a `/ColorSpace` resource dictionary names, by name. * * @param file The owning file. * @param resources The resource dictionary in force. * @returns Name → what the space comes to, for the spaces that are read. */ export declare function buildColorSpaceMap(file: PdfFile, resources: PdfDict | undefined): Map;