/** * Contour wrap (#883): the shape of a picture that text runs round. * * A shape is a polygon (`Resource.contour.points`) or a bitmap's alpha * channel. The layout never decodes pictures (it knows their sizes only), * so the alpha channel is traced by the host that holds the file * ({@link traceResourceContour}: the bundle reader, the Sandbox) and comes * with the resource as `contour.traced`, rows of the picture with the * extent of their opaque pixels. Both kinds come to the same thing here: * rows of the picture, each with its leftmost and rightmost edge, in * fractions of the picture ({@link contourRowsOf}). The layout maps those * onto the page where the picture is set, through its crop and scale * ({@link contourOnPage}), and every line beside it is set short by the * shape's width at its height ({@link contourInsetSteps}). */ import type { ContourTrace, Resource, ResourceContour } from '../types.js'; import type { BoundingBox, ResolvedResourceBlock, VDTExclusionContour } from '../vdt.js'; import type { LineInsetStep } from '../measure/types.js'; import { type AlphaRaster } from './png.js'; export { decodePngAlpha, isPng, type AlphaRaster } from './png.js'; /** `ResourceContour.threshold` when unset. */ export declare const DEFAULT_CONTOUR_THRESHOLD = 0.5; /** The most rows a picture is cut into. */ export declare const MAX_CONTOUR_ROWS = 256; /** The shape of a picture in rows: per row, the leftmost and rightmost * edge of the shape in fractions of its width (`-1` both for a row the * shape does not reach). */ export interface ContourRows { rows: number; spans: readonly number[]; } /** The threshold a contour reads its alpha channel at, 0 to 1. */ export declare function contourThreshold(contour: ResourceContour | undefined): number; /** Whether the contour's polygon can be used: three points or more, all * finite. */ export declare function contourPolygon(contour: ResourceContour | undefined): { x: number; y: number; }[] | undefined; /** Whether a resource's shape is read from its alpha channel: a bitmap * with no polygon whose contour does not turn the alpha channel off. */ export declare function contourWantsAlpha(resource: Resource): boolean; /** * Trace an alpha raster at `threshold` (0 to 1): the picture is cut into * at most {@link MAX_CONTOUR_ROWS} rows, and each row keeps the leftmost * and rightmost edge of the pixels at least that opaque. */ export declare function traceAlpha(raster: AlphaRaster, threshold: number, fileId: string): ContourTrace; /** RGBA pixels as a canvas gives them (`ImageData`). */ export interface RgbaPixels { width: number; height: number; data: Uint8ClampedArray | Uint8Array; } /** The alpha raster of RGBA pixels; `null` when every pixel is opaque. */ export declare function alphaOfRgba(pixels: RgbaPixels): AlphaRaster | null; export interface TraceContourOptions { /** Decode a picture the engine does not read itself (a WebP, a GIF) to * RGBA pixels. Default: `createImageBitmap` and an `OffscreenCanvas`, * where the host has them (a browser, a worker). */ decode?: (bytes: Uint8Array, mime: string) => Promise | RgbaPixels | undefined; } /** * Trace the alpha channel of a bitmap resource from its file's bytes, for * `contour.traced` (#883). A PNG is read here, in any host; another format * goes through `options.decode` (by default the browser's decoder, where * there is one). `null`: the picture has no transparency (a JPEG, an * opaque PNG): it has no shape and runs round its box. `undefined`: the * resource asks for no alpha contour, or the file cannot be read here. */ export declare function traceResourceContour(resource: Resource, bytes: ArrayBuffer | Uint8Array, mime: string, options?: TraceContourOptions): Promise; /** The resource with `contour.traced` set to `trace` (or cleared). */ export declare function withContourTrace(resource: Resource, trace: ContourTrace | null | undefined): Resource; /** A polygon (fractions of the picture) as rows: per row the extent of the * polygon's intersection with it. */ export declare function polygonRows(points: readonly { x: number; y: number; }[], rows?: number): ContourRows; /** * The shape of a resource in rows, when it has one: its polygon, else the * alpha channel its host traced (a trace of this file at this threshold). * `undefined`: no shape is known (an SVG with no polygon, a bitmap whose * alpha channel was not traced, or has no transparency). */ export declare function contourRowsOf(resource: Resource): ContourRows | undefined; export interface ContourOnPageOptions { /** The margin kept round the shape (px). */ margin: number; /** The page lays its flow out mirrored (a right-to-left page): the * picture is painted unturned at a mirrored place, so its shape turns * in the flow's coordinates. */ mirrored?: boolean; /** `VDTExclusionContour.quantum`. */ quantum?: number; /** Where the figure's block stands on the page: `rb.bodyRect` is * relative to it. Default (0, 0). */ originX?: number; originY?: number; } /** * The shape of a picture set on the page as `rb` (its body at * `rb.bodyRect` from the block's origin, showing `rb.bodySource` of the * picture: the crop within its safe area), in page px: the shape's rows * inside the crop, scaled to the body; and `box` (page px), the rest of * the figure (its caption and note under the picture) as bands of its own * width. `undefined` when the resource * has no known shape. */ export declare function contourOnPage(resource: Resource, rb: Pick, box: BoundingBox | undefined, options: ContourOnPageOptions): VDTExclusionContour | undefined; /** A contour moved by `(dx, dy)`. */ export declare function shiftContour(c: VDTExclusionContour, dx: number, dy: number): VDTExclusionContour; /** A contour scaled by `s` about `(ox, oy)`: a frame's content laid out * at another scale than it is painted (#858). `margin: false` keeps the * margin (and the CJK quantum) as they are: they are page px already. */ export declare function scaleContourAbout(c: VDTExclusionContour, ox: number, oy: number, s: number, margin?: boolean): VDTExclusionContour; /** The contour's bounds, its margin included. */ export declare function contourBounds(c: VDTExclusionContour): BoundingBox | undefined; /** The shape's extent across the band `[top, bottom]` of the page: the * spans that lie within its margin of it. `undefined`: the band passes * clear of the shape. */ export declare function contourExtent(c: VDTExclusionContour, top: number, bottom: number): { left: number; right: number; } | undefined; /** * The insets of lines `from` to `to` (0-based, of a text whose line 0's * top is at `y0`, lines `lineHeight` apart) beside a shape at `side` of a * measure `[x, x + width]`: each line is set short by the room the shape * takes across its band (its margin included), none where it passes clear * of it. Line numbers in the steps count from `firstLine`. */ export declare function contourInsetSteps(c: VDTExclusionContour, side: 'left' | 'right', x: number, width: number, y0: number, lineHeight: number, from: number, to: number, firstLine?: number): LineInsetStep[]; //# sourceMappingURL=index.d.ts.map