imagescript 3.1.0 → 3.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/README.md +12 -4
  2. package/dist/animation.d.ts +92 -7
  3. package/dist/animation.js +50 -20
  4. package/dist/codecs/exif.js +62 -0
  5. package/dist/codecs/gif.js +43 -27
  6. package/dist/codecs/jpeg.js +13 -1
  7. package/dist/codecs/png.js +85 -21
  8. package/dist/codecs/quantize.js +2 -2
  9. package/dist/codecs/tga.js +47 -4
  10. package/dist/codecs/vp8l.js +27 -30
  11. package/dist/codecs/webp.js +23 -10
  12. package/dist/frame.d.ts +30 -2
  13. package/dist/frame.js +20 -9
  14. package/dist/gif.d.ts +10 -7
  15. package/dist/gif.js +7 -5
  16. package/dist/image-type.d.ts +1 -0
  17. package/dist/image-type.js +1 -0
  18. package/dist/image.d.ts +231 -31
  19. package/dist/image.js +118 -53
  20. package/dist/index.d.ts +14 -4
  21. package/dist/index.js +6 -4
  22. package/dist/metadata.d.ts +35 -0
  23. package/dist/metadata.js +43 -0
  24. package/dist/render/svg.js +39 -21
  25. package/dist/util/blur.js +88 -0
  26. package/dist/util/optimize.js +264 -0
  27. package/dist/util/options.js +3 -0
  28. package/dist/util/resample.js +244 -63
  29. package/dist/util/utf8.js +4 -51
  30. package/dist/version.js +1 -1
  31. package/package.json +9 -2
  32. package/dist/codecs/crc.d.ts +0 -9
  33. package/dist/codecs/exif.d.ts +0 -11
  34. package/dist/codecs/gif.d.ts +0 -44
  35. package/dist/codecs/jpeg.d.ts +0 -35
  36. package/dist/codecs/png.d.ts +0 -97
  37. package/dist/codecs/quantize.d.ts +0 -25
  38. package/dist/codecs/tga.d.ts +0 -16
  39. package/dist/codecs/tiff.d.ts +0 -6
  40. package/dist/codecs/vp8-tables.d.ts +0 -10
  41. package/dist/codecs/vp8.d.ts +0 -8
  42. package/dist/codecs/vp8l.d.ts +0 -62
  43. package/dist/codecs/webp.d.ts +0 -67
  44. package/dist/codecs/zlib.d.ts +0 -22
  45. package/dist/render/font.d.ts +0 -92
  46. package/dist/render/hinting.d.ts +0 -110
  47. package/dist/render/svg.d.ts +0 -11
  48. package/dist/render/text.d.ts +0 -63
  49. package/dist/util/blur.d.ts +0 -13
  50. package/dist/util/resample.d.ts +0 -12
  51. package/dist/util/utf8.d.ts +0 -5
  52. package/dist/version.d.ts +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "imagescript",
3
- "version": "3.1.0",
3
+ "version": "3.2.1",
4
4
  "description": "zero-dependency javascript image manipulation",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -47,7 +47,14 @@
47
47
  "bitmap",
48
48
  "gif",
49
49
  "picture",
50
- "thumbnail"
50
+ "thumbnail",
51
+ "webp",
52
+ "apng",
53
+ "tiff",
54
+ "tga",
55
+ "animation",
56
+ "text rendering",
57
+ "font"
51
58
  ],
52
59
  "author": "Mathis Mensing <mathis@matmen.dev>",
53
60
  "license": "(AGPL-3.0-or-later OR MIT)",
@@ -1,9 +0,0 @@
1
- /*!
2
- * Slice-by-16 CRC-32, derived from "Fast CRC32 in JavaScript" (https://gist.github.com/101arrowz/e58695f7ccfdf74f60ba22018093edea)
3
- * Copyright (c) 2021 Arjun Barrett, MIT License (see THIRD_PARTY_NOTICES.md)
4
- */
5
- /**
6
- * CRC-32 (ISO 3309), as used by PNG and zlib. Processes 16 bytes per step (slice-by-16, see #12), byte by byte so
7
- * it doesn't depend on alignment or endianness
8
- */
9
- export declare function crc32(buffer: Uint8Array): number;
@@ -1,11 +0,0 @@
1
- /**
2
- * Reads the orientation tag (0x0112) from the first IFD of Exif data
3
- * @param data a TIFF header and IFDs, optionally preceded by "Exif\0\0" (as in JPEG's APP1)
4
- * @return the orientation (1-8), 1 if it is missing or invalid
5
- */
6
- export declare function orientation(data: Uint8Array): number;
7
- /**
8
- * Reads tiff:Orientation from an XMP packet, as attribute or element
9
- * @return the orientation (1-8), 1 if it is missing or invalid
10
- */
11
- export declare function xmpOrientation(xmp: string): number;
@@ -1,44 +0,0 @@
1
- export interface GIFFrame {
2
- x: number;
3
- y: number;
4
- width: number;
5
- height: number;
6
- /** Frame delay in centiseconds */
7
- delay: number;
8
- /** ImageScript disposal mode (0 any, 1 keep, 2 previous, 3 background) */
9
- dispose: number;
10
- /** RGBA pixel data */
11
- pixels: Uint8Array;
12
- }
13
- export interface GIFData {
14
- width: number;
15
- height: number;
16
- /** -1 loops forever, 0 plays once, n repeats n times */
17
- loopCount: number;
18
- frames: GIFFrame[];
19
- }
20
- /**
21
- * Encodes frames into a GIF
22
- * @param {{width: number, height: number, loopCount?: number, frames: GIFFrame[]}} gif loopCount -1 loops forever, 0 plays once, n repeats n times
23
- * @param {number} [quality=95] 1-100, scales the palette size (1 = 8 colors, 50 = 55, 90 and above = 256)
24
- * @return {Uint8Array}
25
- */
26
- export declare function encode({ width, height, loopCount, frames }: Omit<GIFData, 'loopCount'> & {
27
- loopCount?: number;
28
- }, quality?: number): Uint8Array;
29
- /**
30
- * Decodes a GIF into its individual (uncomposited) frames, zero-sized images are skipped
31
- * @param {Uint8Array} data
32
- * @param {boolean} [onlyFirstFrame=false]
33
- * @return {{width: number, height: number, loopCount: number, frames: GIFFrame[]}}
34
- */
35
- export declare function decode(data: Uint8Array, onlyFirstFrame?: boolean): GIFData;
36
- /**
37
- * Composites decoded frames onto the logical screen, applying their disposal modes
38
- * @param {{width: number, height: number, frames: GIFFrame[]}} gif output of {@link decode}
39
- * @return {Array<{pixels: Uint8Array, delay: number}>} full screen RGBA frames
40
- */
41
- export declare function composite({ width, height, frames }: GIFData): Array<{
42
- pixels: Uint8Array;
43
- delay: number;
44
- }>;
@@ -1,35 +0,0 @@
1
- /*!
2
- * JPEG codec. This software is based in part on the work of the Independent JPEG Group: the IDCT, FDCT, upsampling,
3
- * color conversion, progressive refinement and optimal Huffman tables are translated from libjpeg/libjpeg-turbo
4
- * (IJG license, see licenses/README.ijg). The scan decoder follows the structure of pdf.js' jpg.js
5
- * (Copyright 2014 Mozilla Foundation, Apache License 2.0). See THIRD_PARTY_NOTICES.md
6
- */
7
- export interface DecodeOptions {
8
- /** overrides the color transform detected from JFIF/Adobe markers (used by TIFF) */
9
- transform?: 'ycc' | 'rgb' | 'cmyk' | null;
10
- }
11
- /**
12
- * Decodes a JPEG into 8-bit RGBA pixel data
13
- * Supports baseline, extended and progressive huffman coded JPEGs with any
14
- * sampling factors, restart intervals and greyscale, YCbCr, RGB, CMYK and YCCK color
15
- * The output matches libjpeg's defaults (islow IDCT, fancy upsampling)
16
- * @param {Uint8Array} data
17
- * @param {{transform?: 'ycc'|'rgb'|'cmyk'}} [options] overrides the color transform detected from JFIF/Adobe markers (used by TIFF)
18
- * @return {{width: number, height: number, pixels: Uint8Array}}
19
- */
20
- export declare function decode(data: Uint8Array, { transform }?: DecodeOptions): {
21
- width: number;
22
- height: number;
23
- pixels: Uint8Array;
24
- orientation: number;
25
- };
26
- /**
27
- * Encodes RGBA pixel data into a baseline JPEG (alpha is ignored)
28
- * Uses 4:2:0 chroma subsampling up to quality 90 and 4:4:4 above, with optimized huffman tables
29
- * @param {Uint8Array} pixels
30
- * @param {number} width
31
- * @param {number} height
32
- * @param {number} [quality=90] 1-100
33
- * @return {Uint8Array}
34
- */
35
- export declare function encode(pixels: Uint8Array, width: number, height: number, quality?: number): Uint8Array;
@@ -1,97 +0,0 @@
1
- export interface EncodeOptions {
2
- /** tEXt chunks, empty values are skipped */
3
- text?: Record<string, string | undefined>;
4
- width: number;
5
- height: number;
6
- channels: number;
7
- depth?: number;
8
- level?: number;
9
- /** packed RGB palette, makes the data palette indices (1 channel) */
10
- palette?: Uint8Array;
11
- /** alpha per palette entry */
12
- transparency?: Uint8Array;
13
- /** whether to paeth filter the rows (pays off for truecolor and greyscale images) */
14
- filter?: boolean;
15
- }
16
- export interface Decoded {
17
- width: number;
18
- height: number;
19
- /** 8-bit RGBA */
20
- pixels: Uint8Array;
21
- /** Exif orientation (1-8) */
22
- orientation: number;
23
- }
24
- /**
25
- * Encodes raw pixel data into a PNG
26
- * @param data Raw pixel data, rows packed MSB first for depths below 8
27
- */
28
- export declare function encode(data: Uint8Array, { text, width, height, channels, depth, level, palette, transparency, filter: filterRows }: EncodeOptions): Promise<Uint8Array>;
29
- /**
30
- * Encodes 8-bit RGBA pixels into a PNG with the smallest lossless color type (see {@link pixelFormat}).
31
- * Rows of non-palette images are paeth filtered (unless the data isn't compressed), palette indices aren't
32
- * filtered (like libpng recommends)
33
- */
34
- export declare function encodeRGBA(rgba: Uint8Array, width: number, height: number, level: number, text?: EncodeOptions['text']): Promise<Uint8Array>;
35
- export interface APNGEncodeFrame {
36
- x: number;
37
- y: number;
38
- width: number;
39
- height: number;
40
- /** milliseconds (stored as a fraction of up to 65535/65535 seconds) */
41
- duration: number;
42
- /** 0 none, 1 background (transparent), 2 previous */
43
- dispose: number;
44
- /** RGBA */
45
- pixels: Uint8Array;
46
- }
47
- /**
48
- * Encodes frames into an APNG. Frames are alpha blended onto the canvas ("over"); the first frame is also the
49
- * default image that viewers without APNG support show
50
- * @param plays How often to play the animation, 0 = forever
51
- */
52
- export declare function encodeAnimation(frames: APNGEncodeFrame[], width: number, height: number, plays: number, level: number): Promise<Uint8Array>;
53
- /**
54
- * Decodes a PNG into 8-bit RGBA pixel data (for APNGs, the default image)
55
- * Supports all color types, bit depths, tRNS transparency and adam7 interlacing
56
- * The orientation comes from the eXIf chunk, or, if there is none, from the Exif text ImageMagick wrote before eXIf
57
- * existed ("Raw profile type exif") or from the XMP packet
58
- */
59
- export declare function decode(array: Uint8Array): Promise<Decoded>;
60
- export interface APNGFrame {
61
- x: number;
62
- y: number;
63
- width: number;
64
- height: number;
65
- /** milliseconds */
66
- duration: number;
67
- /** 0 none, 1 background (transparent), 2 previous */
68
- dispose: number;
69
- /** 0 source (replace), 1 over */
70
- blend: number;
71
- pixels: Uint8Array;
72
- }
73
- /** Whether the PNG is an APNG (has an acTL chunk) */
74
- export declare function isAnimated(array: Uint8Array): boolean;
75
- /**
76
- * Decodes an APNG (https://wiki.mozilla.org/APNG_Specification) into its (uncomposited) frames; a plain PNG becomes
77
- * a single frame
78
- * @return plays: 0 = forever
79
- */
80
- export declare function decodeAnimation(array: Uint8Array, onlyFirstFrame?: boolean): Promise<{
81
- width: number;
82
- height: number;
83
- plays: number;
84
- frames: APNGFrame[];
85
- }>;
86
- /**
87
- * Composites APNG frames onto the canvas, as the APNG specification describes (the integer "over" operation of its
88
- * blend_op section, https://wiki.mozilla.org/APNG_Specification)
89
- */
90
- export declare function compositeAnimation({ width, height, frames }: {
91
- width: number;
92
- height: number;
93
- frames: APNGFrame[];
94
- }): Array<{
95
- pixels: Uint8Array;
96
- duration: number;
97
- }>;
@@ -1,25 +0,0 @@
1
- /**
2
- * Reduces RGBA pixel data to an indexed palette
3
- * Pixels with alpha < 128 are mapped to a dedicated transparent index
4
- * @param {Uint8Array} pixels RGBA pixel data
5
- * @param {number} width Image width in pixels (needed for dithering)
6
- * @param {{maxColors?: number, quality?: number}} [options] quality (1-100) scales the palette size exponentially (1 = 8 colors, 50 = 55, 90 and above = 256)
7
- * @return {{palette: Uint8Array, indices: Uint8Array, transparentIndex: number}} palette is packed RGB, transparentIndex is -1 if unused
8
- */
9
- export interface QuantizeOptions {
10
- maxColors?: number;
11
- quality?: number;
12
- }
13
- export interface Quantized {
14
- /** packed RGB */
15
- palette: Uint8Array;
16
- indices: Uint8Array;
17
- /** -1 if no pixel is transparent */
18
- transparentIndex: number;
19
- }
20
- /**
21
- * Finds the color of the largest cluster among the opaque pixels that pass the filter
22
- * @return packed RGB, or null if no pixel qualifies
23
- */
24
- export declare function dominantColor(pixels: Uint8Array, include: (r: number, g: number, b: number) => boolean, clusters?: number): [number, number, number] | null;
25
- export declare function quantize(pixels: Uint8Array, width: number, { maxColors, quality }?: QuantizeOptions): Quantized;
@@ -1,16 +0,0 @@
1
- /**
2
- * Whether the data looks like a TGA. Older TGAs have no signature, so this checks that the header is consistent
3
- */
4
- export declare function isTGA(d: Uint8Array): boolean;
5
- /**
6
- * Decodes a TGA into RGBA
7
- */
8
- export declare function decode(d: Uint8Array): {
9
- width: number;
10
- height: number;
11
- pixels: Uint8Array;
12
- };
13
- /**
14
- * Encodes RGBA pixels into a run length encoded TGA (32 bit with alpha, 24 bit if opaque), top left origin
15
- */
16
- export declare function encode(rgba: Uint8Array, width: number, height: number): Uint8Array;
@@ -1,6 +0,0 @@
1
- export declare function decode(data: Uint8Array): Promise<{
2
- width: number;
3
- height: number;
4
- pixels: Uint8Array;
5
- orientation: number;
6
- }>;
@@ -1,10 +0,0 @@
1
- /*!
2
- * VP8 constant tables, extracted from RFC 6386 ("VP8 Data Format and Decoding Guide", sections 9.6, 11.5, 13.4,
3
- * 13.5 and 14.1). Copyright (c) 2010, 2011 Google Inc., BSD license (see THIRD_PARTY_NOTICES.md)
4
- */
5
- export declare const KF_BMODE_PROBS: Uint8Array<ArrayBuffer>;
6
- export declare const COEFF_UPDATE_PROBS: Uint8Array<ArrayBuffer>;
7
- export declare const DEFAULT_COEFF_PROBS: Uint8Array<ArrayBuffer>;
8
- export declare const DC_QLOOKUP: Uint8Array<ArrayBuffer>;
9
- export declare const AC_QLOOKUP: Int16Array<ArrayBuffer>;
10
- export declare const PCAT: Uint8Array<ArrayBuffer>[];
@@ -1,8 +0,0 @@
1
- /**
2
- * Decodes a VP8 key frame (the payload of a VP8 chunk) into RGBA
3
- */
4
- export declare function decode(data: Uint8Array): {
5
- width: number;
6
- height: number;
7
- pixels: Uint8Array;
8
- };
@@ -1,62 +0,0 @@
1
- /*!
2
- * WebP lossless (VP8L) bitstream, as specified in RFC 9649 ("WebP Image Format") section 3 onwards, including its
3
- * table of short distance codes. Copyright (c) 2024 IETF Trust and the persons identified as the document authors,
4
- * Revised BSD License (see THIRD_PARTY_NOTICES.md)
5
- */
6
- /** decoded VP8L image: ARGB pixels (0xAARRGGBB) */
7
- export interface VP8LImage {
8
- width: number;
9
- height: number;
10
- argb: Uint32Array;
11
- hasAlpha: boolean;
12
- }
13
- /**
14
- * LSB-first bit reader
15
- */
16
- export declare class BitReader {
17
- data: Uint8Array;
18
- pos: number;
19
- private buffer;
20
- private count;
21
- constructor(data: Uint8Array, offset?: number);
22
- private fill;
23
- /** reads up to 24 bits */
24
- read(bits: number): number;
25
- /** the next 24 bits without consuming them */
26
- peek(): number;
27
- skip(bits: number): void;
28
- /** whether reading went past the end of the data */
29
- get overrun(): boolean;
30
- }
31
- /** canonical prefix code as lookup table */
32
- export interface PrefixCode {
33
- table: Int32Array;
34
- /** set if the code has a single symbol (which takes zero bits) */
35
- single: number;
36
- }
37
- /**
38
- * Builds a lookup table from code lengths (RFC 9649 section 3.7.2.1.1: canonical codes, read LSB first)
39
- */
40
- export declare function buildCode(lengths: ArrayLike<number>, size: number): PrefixCode;
41
- /** reads one symbol */
42
- export declare function readSymbol(reader: BitReader, code: PrefixCode): number;
43
- /**
44
- * Reads the VP8L header (signature, dimensions)
45
- */
46
- export declare function readHeader(data: Uint8Array): {
47
- width: number;
48
- height: number;
49
- hasAlpha: boolean;
50
- };
51
- /**
52
- * Decodes a VP8L bitstream (the payload of a VP8L chunk)
53
- */
54
- export declare function decode(data: Uint8Array): VP8LImage;
55
- /**
56
- * Decodes transforms and the main image from the bit reader (used by the ALPH chunk too, which has no header)
57
- */
58
- export declare function decodeStream(reader: BitReader, width: number, height: number): Uint32Array;
59
- /**
60
- * Encodes ARGB pixels into a VP8L bitstream (the payload of a VP8L chunk)
61
- */
62
- export declare function encode(argb: Uint32Array, width: number, height: number): Uint8Array;
@@ -1,67 +0,0 @@
1
- export interface WebPFrame {
2
- x: number;
3
- y: number;
4
- width: number;
5
- height: number;
6
- /** milliseconds */
7
- duration: number;
8
- /** whether the frame is alpha blended onto the canvas (false: it replaces the covered area) */
9
- blend: boolean;
10
- /** whether the frame's area is cleared to transparent after it was shown */
11
- dispose: boolean;
12
- /** RGBA */
13
- pixels: Uint8Array;
14
- }
15
- export interface WebPAnimation {
16
- width: number;
17
- height: number;
18
- /** 0 = forever */
19
- loopCount: number;
20
- /** ARGB background color hint (decoders, like browsers, are free to ignore it) */
21
- background: number;
22
- frames: WebPFrame[];
23
- }
24
- /** Whether the WebP is animated */
25
- export declare function isAnimated(data: Uint8Array): boolean;
26
- /**
27
- * Decodes a still WebP into RGBA pixels. Animated WebPs decode to their first frame composited on the canvas
28
- */
29
- export declare function decode(data: Uint8Array): {
30
- width: number;
31
- height: number;
32
- pixels: Uint8Array;
33
- orientation: number;
34
- };
35
- /**
36
- * Decodes an animated WebP into its frames (not composited); still WebPs become a single frame
37
- */
38
- export declare function decodeAnimation(data: Uint8Array, onlyFirstFrame?: boolean): WebPAnimation;
39
- /**
40
- * Composites animation frames onto the canvas like browsers do (transparent background, the background color hint
41
- * is ignored as the spec allows)
42
- */
43
- export declare function composite({ width, height, frames }: WebPAnimation): Array<{
44
- pixels: Uint8Array;
45
- duration: number;
46
- }>;
47
- /**
48
- * Encodes RGBA pixels into a lossless WebP
49
- */
50
- export declare function encode(rgba: Uint8Array, width: number, height: number): Uint8Array;
51
- export interface WebPEncodeFrame {
52
- x: number;
53
- y: number;
54
- width: number;
55
- height: number;
56
- /** milliseconds */
57
- duration: number;
58
- /** whether the frame's area is cleared after it was shown */
59
- dispose: boolean;
60
- /** RGBA, alpha blended onto the canvas */
61
- pixels: Uint8Array;
62
- }
63
- /**
64
- * Encodes frames into a lossless animated WebP. Frame offsets have to be even (the format stores them halved)
65
- * @param plays How often to play the animation, 0 = forever
66
- */
67
- export declare function encodeAnimation(frames: WebPEncodeFrame[], width: number, height: number, plays: number): Uint8Array;
@@ -1,22 +0,0 @@
1
- /*!
2
- * zlib deflate/inflate, derived from fflate (https://github.com/101arrowz/fflate)
3
- * Copyright (c) 2020 Arjun Barrett, MIT License (see THIRD_PARTY_NOTICES.md)
4
- */
5
- /**
6
- * Compresses data into a zlib stream
7
- * @param level compression level 0-9
8
- */
9
- export declare function compress(data: Uint8Array, level: number): Uint8Array;
10
- /**
11
- * Decompresses a zlib stream into at most limit bytes
12
- */
13
- export declare function decompress(data: Uint8Array, limit: number): Uint8Array;
14
- /**
15
- * Compresses data into a zlib stream, with the runtime's native zlib when available
16
- * @param level compression level 0-9
17
- */
18
- export declare function compressAsync(data: Uint8Array, level: number): Promise<Uint8Array>;
19
- /**
20
- * Decompresses a zlib stream into at most limit bytes, using the runtime's native zlib when available
21
- */
22
- export declare function decompressAsync(data: Uint8Array, limit: number): Promise<Uint8Array>;
@@ -1,92 +0,0 @@
1
- /**
2
- * A path command in font units (y up) or user units:
3
- * ['M', x, y], ['L', x, y], ['Q', cx, cy, x, y], ['C', c1x, c1y, c2x, c2y, x, y], ['Z']
4
- */
5
- export type PathCommand = [string, ...number[]];
6
- /** a TrueType glyph's points (font units) and instructions, for hinting */
7
- export interface GlyfPoints {
8
- xs: number[];
9
- ys: number[];
10
- /** on curve flags */
11
- on: boolean[];
12
- /** index of the last point of every contour */
13
- ends: number[];
14
- instructions: Uint8Array;
15
- /** glyph bounding box minimum x (the left side bearing's reference) */
16
- xMin: number;
17
- /** components of composite glyphs (their points are not included in xs/ys) */
18
- components: Array<{
19
- glyph: number;
20
- dx: number;
21
- dy: number;
22
- matrix: [number, number, number, number];
23
- round: boolean;
24
- match: [number, number] | null;
25
- useMetrics: boolean;
26
- }> | null;
27
- }
28
- interface CFF {
29
- charStrings: Uint8Array[];
30
- globalSubrs: Uint8Array[];
31
- privateFor: (glyph: number) => {
32
- subrs: Uint8Array[];
33
- };
34
- }
35
- /**
36
- * Parses TrueType (glyf) and OpenType (CFF) fonts, including the first font of a collection
37
- */
38
- export declare class Font {
39
- data: Uint8Array;
40
- view: DataView;
41
- tables: Record<string, {
42
- offset: number;
43
- length: number;
44
- }>;
45
- unitsPerEm: number;
46
- indexToLocFormat: number;
47
- ascender: number;
48
- descender: number;
49
- lineGap: number;
50
- numberOfHMetrics: number;
51
- numGlyphs: number;
52
- outlines: 'glyf' | 'cff';
53
- cff: CFF | null;
54
- cmap: (codepoint: number) => number;
55
- outlineCache: Map<number, PathCommand[]>;
56
- /** kerning between two glyphs in font units, null if the font has none */
57
- kerning: ((left: number, right: number) => number) | null;
58
- constructor(data: Uint8Array);
59
- u8(o: number): number;
60
- i8(o: number): number;
61
- u16(o: number): number;
62
- i16(o: number): number;
63
- u32(o: number): number;
64
- i32(o: number): number;
65
- /**
66
- * @param {number} codepoint
67
- * @return {number} glyph index, 0 (.notdef) if the font has no glyph for it
68
- */
69
- glyphIndex(codepoint: number): number;
70
- /**
71
- * @param {number} glyph
72
- * @return {number} advance width in font units
73
- */
74
- advance(glyph: number): number;
75
- /** left side bearing in font units */
76
- leftSideBearing(glyph: number): number;
77
- /**
78
- * A TrueType glyph's points and instructions (null for empty glyphs or CFF fonts)
79
- */
80
- glyfPoints(glyph: number): GlyfPoints | null;
81
- /**
82
- * @param {number} glyph
83
- * @return {Array} path commands in font units
84
- */
85
- outline(glyph: number): PathCommand[];
86
- glyfOutline(glyph: number, depth: number): PathCommand[];
87
- simpleGlyph(offset: number, contourCount: number): PathCommand[];
88
- compositeGlyph(offset: number, depth: number): PathCommand[];
89
- cffOutline(glyph: number): PathCommand[];
90
- }
91
- export declare function contourToPath(path: PathCommand[], xs: ArrayLike<number>, ys: ArrayLike<number>, flags: ArrayLike<number | boolean>, first: number, last: number): void;
92
- export {};
@@ -1,110 +0,0 @@
1
- /*!
2
- * TrueType hinting interpreter. Where the TrueType specification leaves details open, its behavior and parts of its
3
- * logic follow FreeType's TrueType interpreter (src/truetype/ttinterp.c): fixed point rounding, original distances
4
- * on the unscaled outline (IP, IUP, MDRP, MD), the IUP interpolation, the movement along near-perpendicular vectors
5
- * and the tolerance of invalid references. Portions of this software are copyright © 2026 The FreeType Project
6
- * (https://freetype.org). All rights reserved. FreeType License, see THIRD_PARTY_NOTICES.md and licenses/FTL.txt
7
- */
8
- import { Font, PathCommand } from './font.js';
9
- interface Vector {
10
- x: number;
11
- y: number;
12
- }
13
- interface GraphicsState {
14
- pv: Vector;
15
- fv: Vector;
16
- dv: Vector;
17
- rp0: number;
18
- rp1: number;
19
- rp2: number;
20
- zp0: number;
21
- zp1: number;
22
- zp2: number;
23
- loop: number;
24
- minimumDistance: number;
25
- cvtCutIn: number;
26
- singleWidthCutIn: number;
27
- singleWidth: number;
28
- deltaBase: number;
29
- deltaShift: number;
30
- autoFlip: boolean;
31
- /** null: rounding off */
32
- round: {
33
- period: number;
34
- phase: number;
35
- threshold: number;
36
- } | null;
37
- instructControl: number;
38
- }
39
- interface Zone {
40
- curX: Float64Array;
41
- curY: Float64Array;
42
- orgX: Float64Array;
43
- orgY: Float64Array;
44
- /** unscaled original positions (font units), measurements between original glyph points use them */
45
- orusX: Float64Array;
46
- orusY: Float64Array;
47
- touchX: Uint8Array;
48
- touchY: Uint8Array;
49
- on: Uint8Array;
50
- ends: number[];
51
- }
52
- interface FunctionDef {
53
- code: Uint8Array;
54
- start: number;
55
- end: number;
56
- }
57
- /** state of a font at one size, after the font and control value programs ran */
58
- interface SizeState {
59
- ppem: number;
60
- /** 26.6 units per font unit */
61
- scale: number;
62
- /** the same as 16.16 fixed point number */
63
- scaleFixed: number;
64
- cvt: Float64Array;
65
- storage: Int32Array;
66
- state: GraphicsState;
67
- twilight: Zone;
68
- functions: Map<number, FunctionDef>;
69
- instructions: Map<number, FunctionDef>;
70
- /** set if the font and control value programs failed, the font is then rendered unhinted */
71
- broken: boolean;
72
- }
73
- export interface HintedGlyph {
74
- /** outline in pixels, relative to the pen position (y up) */
75
- path: PathCommand[];
76
- /** advance width in whole pixels */
77
- advance: number;
78
- }
79
- /**
80
- * Executes TrueType instructions for one font
81
- */
82
- export declare class Hinter {
83
- font: Font;
84
- fpgm: Uint8Array;
85
- prep: Uint8Array;
86
- cvt: Int16Array;
87
- maxStack: number;
88
- maxStorage: number;
89
- maxTwilight: number;
90
- sizes: Map<number, SizeState>;
91
- /** 26.6 units per font unit (16.16 fixed point) of the glyph being loaded */
92
- private scaleFixed;
93
- constructor(font: Font);
94
- /** whether the font has hinting instructions (a font program, control value program or control values) */
95
- get hasInstructions(): boolean;
96
- private size;
97
- /**
98
- * Hints a glyph at a size
99
- * @param size pixels per em
100
- * @return the hinted outline, or null if the glyph can't be hinted (it is then rendered unhinted)
101
- */
102
- glyph(glyph: number, size: number): HintedGlyph | null;
103
- /**
104
- * Loads, scales and hints a glyph (recursively for composites)
105
- * @return the glyph zone (with 4 phantom points after the outline points)
106
- */
107
- private load;
108
- private phantoms;
109
- }
110
- export {};
@@ -1,11 +0,0 @@
1
- /**
2
- * @param {string|Uint8Array} source
3
- * @param {number} mode 1 = scale by size, 2 = fit width to size, 3 = fit height to size
4
- * @param {number} size
5
- * @return {{width: number, height: number, pixels: Uint8Array}}
6
- */
7
- export declare function render(source: string | Uint8Array, mode: number, size: number): {
8
- width: number;
9
- height: number;
10
- pixels: Uint8Array;
11
- };