docxkeun 0.1.3 → 0.2.0
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.
- package/CHANGELOG.md +48 -0
- package/README.md +137 -16
- package/dist/api/editor.d.ts +172 -5
- package/dist/api/editor.js +814 -24
- package/dist/api/headers.d.ts +51 -0
- package/dist/api/headers.js +133 -0
- package/dist/api/index.d.ts +5 -1
- package/dist/api/index.js +4 -1
- package/dist/api/lists.d.ts +37 -0
- package/dist/api/lists.js +132 -0
- package/dist/api/parts.js +1 -0
- package/dist/api/positions.js +1 -0
- package/dist/api/revisions.d.ts +61 -0
- package/dist/api/revisions.js +390 -0
- package/dist/api/selection.d.ts +57 -0
- package/dist/api/selection.js +91 -0
- package/dist/charts/color.d.ts +45 -0
- package/dist/charts/color.js +322 -0
- package/dist/charts/format.d.ts +12 -0
- package/dist/charts/format.js +459 -0
- package/dist/charts/index.d.ts +11 -0
- package/dist/charts/index.js +8 -0
- package/dist/charts/model.d.ts +225 -0
- package/dist/charts/model.js +758 -0
- package/dist/charts/outline.d.ts +17 -0
- package/dist/charts/outline.js +214 -0
- package/dist/charts/render.d.ts +20 -0
- package/dist/charts/render.js +1772 -0
- package/dist/drawing/arrows.d.ts +37 -0
- package/dist/drawing/arrows.js +99 -0
- package/dist/drawing/formula.d.ts +40 -0
- package/dist/drawing/formula.js +159 -0
- package/dist/drawing/geometry.d.ts +61 -0
- package/dist/drawing/geometry.js +286 -0
- package/dist/drawing/index.d.ts +12 -0
- package/dist/drawing/index.js +8 -0
- package/dist/drawing/presets.d.ts +72 -0
- package/dist/drawing/presets.js +2874 -0
- package/dist/fonts/shaping/apply.d.ts +94 -0
- package/dist/fonts/shaping/apply.js +349 -0
- package/dist/fonts/shaping/arabic.d.ts +28 -0
- package/dist/fonts/shaping/arabic.js +235 -0
- package/dist/fonts/shaping/buffer.d.ts +53 -0
- package/dist/fonts/shaping/buffer.js +95 -0
- package/dist/fonts/shaping/gdef.d.ts +30 -0
- package/dist/fonts/shaping/gdef.js +66 -0
- package/dist/fonts/shaping/gpos.d.ts +86 -0
- package/dist/fonts/shaping/gpos.js +428 -0
- package/dist/fonts/shaping/gsub.d.ts +65 -0
- package/dist/fonts/shaping/gsub.js +313 -0
- package/dist/fonts/shaping/index.d.ts +32 -0
- package/dist/fonts/shaping/index.js +402 -0
- package/dist/fonts/shaping/indic.d.ts +6 -0
- package/dist/fonts/shaping/indic.js +805 -0
- package/dist/fonts/shaping/layout-common.d.ts +124 -0
- package/dist/fonts/shaping/layout-common.js +349 -0
- package/dist/fonts/shaping/plan.d.ts +87 -0
- package/dist/fonts/shaping/plan.js +152 -0
- package/dist/fonts/shaping/scripts.d.ts +26 -0
- package/dist/fonts/shaping/scripts.js +160 -0
- package/dist/fonts/shaping/shaper.d.ts +23 -0
- package/dist/fonts/shaping/shaper.js +5 -0
- package/dist/fonts/shaping/unicode.d.ts +34 -0
- package/dist/fonts/shaping/unicode.js +138 -0
- package/dist/images/bmp.d.ts +9 -0
- package/dist/images/bmp.js +234 -0
- package/dist/images/gif.d.ts +9 -0
- package/dist/images/gif.js +215 -0
- package/dist/images/index.d.ts +18 -0
- package/dist/images/index.js +63 -0
- package/dist/images/png-encode.d.ts +4 -0
- package/dist/images/png-encode.js +73 -0
- package/dist/images/size.d.ts +10 -0
- package/dist/images/size.js +83 -0
- package/dist/images/tiff.d.ts +14 -0
- package/dist/images/tiff.js +407 -0
- package/dist/index.d.ts +7 -2
- package/dist/index.js +5 -0
- package/dist/layout/bidi.d.ts +18 -0
- package/dist/layout/bidi.js +71 -0
- package/dist/layout/blocks.d.ts +20 -3
- package/dist/layout/blocks.js +88 -58
- package/dist/layout/cache.d.ts +31 -0
- package/dist/layout/cache.js +38 -0
- package/dist/layout/drawing.d.ts +30 -0
- package/dist/layout/drawing.js +120 -0
- package/dist/layout/engine.d.ts +3 -0
- package/dist/layout/engine.js +218 -11
- package/dist/layout/index.d.ts +1 -0
- package/dist/layout/index.js +1 -0
- package/dist/layout/lines.d.ts +63 -5
- package/dist/layout/lines.js +245 -20
- package/dist/layout/paint.d.ts +25 -3
- package/dist/layout/paint.js +26 -10
- package/dist/layout/shapes.d.ts +7 -0
- package/dist/layout/shapes.js +338 -0
- package/dist/layout/style.d.ts +4 -0
- package/dist/layout/style.js +2 -0
- package/dist/layout/types.d.ts +89 -2
- package/dist/math/boxes.d.ts +88 -0
- package/dist/math/boxes.js +166 -0
- package/dist/math/index.d.ts +29 -0
- package/dist/math/index.js +44 -0
- package/dist/math/layout.d.ts +13 -0
- package/dist/math/layout.js +771 -0
- package/dist/math/linear.d.ts +3 -0
- package/dist/math/linear.js +152 -0
- package/dist/math/omml.d.ts +15 -0
- package/dist/math/omml.js +57 -0
- package/dist/math/paths.d.ts +61 -0
- package/dist/math/paths.js +450 -0
- package/dist/math/symbols.d.ts +49 -0
- package/dist/math/symbols.js +269 -0
- package/dist/math/text.d.ts +53 -0
- package/dist/math/text.js +316 -0
- package/dist/metafile/canvas.d.ts +80 -0
- package/dist/metafile/canvas.js +515 -0
- package/dist/metafile/dib.d.ts +27 -0
- package/dist/metafile/dib.js +300 -0
- package/dist/metafile/emf.d.ts +31 -0
- package/dist/metafile/emf.js +591 -0
- package/dist/metafile/geometry.d.ts +49 -0
- package/dist/metafile/geometry.js +85 -0
- package/dist/metafile/index.d.ts +27 -0
- package/dist/metafile/index.js +34 -0
- package/dist/metafile/reader.d.ts +28 -0
- package/dist/metafile/reader.js +59 -0
- package/dist/metafile/state.d.ts +118 -0
- package/dist/metafile/state.js +172 -0
- package/dist/metafile/text.d.ts +17 -0
- package/dist/metafile/text.js +130 -0
- package/dist/metafile/wmf.d.ts +33 -0
- package/dist/metafile/wmf.js +395 -0
- package/dist/model/content.d.ts +92 -7
- package/dist/model/content.js +251 -17
- package/dist/model/document.d.ts +34 -1
- package/dist/model/document.js +80 -1
- package/dist/model/fields.d.ts +4 -0
- package/dist/model/fields.js +10 -0
- package/dist/model/numbering.d.ts +2 -0
- package/dist/model/numbering.js +22 -0
- package/dist/model/props.d.ts +2 -0
- package/dist/model/props.js +3 -0
- package/dist/opc/index.d.ts +1 -1
- package/dist/opc/package.d.ts +34 -0
- package/dist/opc/package.js +58 -4
- package/dist/pdf/export.js +97 -6
- package/dist/pdf/images.d.ts +7 -0
- package/dist/pdf/images.js +39 -2
- package/dist/render/activity.d.ts +138 -0
- package/dist/render/activity.js +794 -0
- package/dist/render/clipboard.d.ts +29 -0
- package/dist/render/clipboard.js +401 -0
- package/dist/render/comments.d.ts +166 -0
- package/dist/render/comments.js +779 -0
- package/dist/render/context-menu.d.ts +124 -0
- package/dist/render/context-menu.js +525 -0
- package/dist/render/editing.d.ts +146 -5
- package/dist/render/editing.js +678 -53
- package/dist/render/index.d.ts +12 -0
- package/dist/render/index.js +11 -0
- package/dist/render/navigation-panel.d.ts +76 -0
- package/dist/render/navigation-panel.js +431 -0
- package/dist/render/selection.js +5 -0
- package/dist/render/svg.d.ts +4 -6
- package/dist/render/svg.js +69 -7
- package/dist/render/toolbar.d.ts +83 -0
- package/dist/render/toolbar.js +505 -0
- package/dist/render/ui/comment-layout.d.ts +39 -0
- package/dist/render/ui/comment-layout.js +79 -0
- package/dist/render/ui/icons.d.ts +6 -0
- package/dist/render/ui/icons.js +38 -0
- package/dist/render/ui/menu.d.ts +38 -0
- package/dist/render/ui/menu.js +274 -0
- package/dist/render/ui/nav-model.d.ts +11 -0
- package/dist/render/ui/nav-model.js +34 -0
- package/dist/render/ui/overflow.d.ts +5 -0
- package/dist/render/ui/overflow.js +18 -0
- package/dist/render/ui/popover.d.ts +18 -0
- package/dist/render/ui/popover.js +109 -0
- package/dist/render/ui/theme.d.ts +2 -0
- package/dist/render/ui/theme.js +29 -0
- package/dist/render/undo.d.ts +76 -0
- package/dist/render/undo.js +144 -0
- package/dist/render/viewer.d.ts +100 -7
- package/dist/render/viewer.js +302 -92
- package/dist/security/policy.d.ts +3 -0
- package/dist/security/policy.js +6 -2
- package/dist/security/protection.d.ts +1 -0
- package/dist/security/protection.js +1 -1
- package/dist/text/bidi-data.d.ts +53 -0
- package/dist/text/bidi-data.js +318 -0
- package/dist/text/bidi.d.ts +37 -0
- package/dist/text/bidi.js +508 -0
- package/dist/xml/ns.d.ts +5 -0
- package/dist/xml/ns.js +7 -0
- package/package.json +9 -2
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type { DisplayItem, FontProvider, RasterImage } from '../layout/types.js';
|
|
2
|
+
import type { Matrix, Pt } from './geometry.js';
|
|
3
|
+
import type { DCState } from './state.js';
|
|
4
|
+
/** Pen width 0 and cosmetic pens are one device pixel wide: drawn as a hairline this wide (pt). */
|
|
5
|
+
export declare const HAIRLINE = 0.25;
|
|
6
|
+
export interface CanvasOptions {
|
|
7
|
+
fonts: FontProvider;
|
|
8
|
+
/** Page space (after the world transform) → page points, for the current window/viewport state. */
|
|
9
|
+
pageToPoints(state: DCState): Matrix;
|
|
10
|
+
/** Page points per device pixel: the unit of cosmetic pen dash patterns. */
|
|
11
|
+
pixel: number;
|
|
12
|
+
/** Em size in points for fonts whose height is 0 (the device's default font). */
|
|
13
|
+
defaultFontSize: number;
|
|
14
|
+
}
|
|
15
|
+
export type ArcKind = 'arc' | 'arcto' | 'chord' | 'pie';
|
|
16
|
+
export declare class Canvas {
|
|
17
|
+
private readonly options;
|
|
18
|
+
readonly items: DisplayItem[];
|
|
19
|
+
state: DCState;
|
|
20
|
+
private readonly saved;
|
|
21
|
+
/** Commands of the path bracket, in page points; undefined when there is no path. */
|
|
22
|
+
private path;
|
|
23
|
+
/** Between BeginPath and EndPath drawing calls add to the path instead of drawing. */
|
|
24
|
+
private recording;
|
|
25
|
+
/** Whether the path's last figure is open and ends at the current position (so "…To" calls extend it). */
|
|
26
|
+
private figureOpen;
|
|
27
|
+
/** The last stroked open path, which a following LineTo from its end point extends instead of starting a new item. */
|
|
28
|
+
private chain;
|
|
29
|
+
constructor(options: CanvasOptions);
|
|
30
|
+
/** Logical → page points for the current state. */
|
|
31
|
+
matrix(): Matrix;
|
|
32
|
+
save(): void;
|
|
33
|
+
/** RestoreDC: negative counts back from the latest SaveDC, positive names a SaveDC instance (1-based). */
|
|
34
|
+
restore(n: number): void;
|
|
35
|
+
beginPath(): void;
|
|
36
|
+
endPath(): void;
|
|
37
|
+
abortPath(): void;
|
|
38
|
+
closeFigure(): void;
|
|
39
|
+
/** FillPath / StrokePath / StrokeAndFillPath: draw the recorded path and discard it. */
|
|
40
|
+
drawPath(fill: boolean, stroke: boolean): void;
|
|
41
|
+
moveTo(x: number, y: number): void;
|
|
42
|
+
lineTo(x: number, y: number): void;
|
|
43
|
+
polylineTo(points: Pt[]): void;
|
|
44
|
+
polyBezierTo(points: Pt[]): void;
|
|
45
|
+
/** Polyline (open, stroked) or Polygon (closed, filled and stroked). */
|
|
46
|
+
poly(points: Pt[], closed: boolean): void;
|
|
47
|
+
/** PolyPolygon draws one filled shape (holes follow the fill mode); PolyPolyline separate strokes. */
|
|
48
|
+
polyPoly(polys: Pt[][], closed: boolean): void;
|
|
49
|
+
polyBezier(points: Pt[]): void;
|
|
50
|
+
/** PolyDraw: PT_MOVETO 6, PT_LINETO 2, PT_BEZIERTO 4, each optionally | PT_CLOSEFIGURE 1. */
|
|
51
|
+
polyDraw(points: Pt[], types: number[]): void;
|
|
52
|
+
rectangle(l: number, t: number, r: number, b: number): void;
|
|
53
|
+
roundRect(l: number, t: number, r: number, b: number, w: number, h: number): void;
|
|
54
|
+
ellipse(l: number, t: number, r: number, b: number): void;
|
|
55
|
+
arc(kind: ArcKind, l: number, t: number, r: number, b: number, xs: number, ys: number, xe: number, ye: number): void;
|
|
56
|
+
/** AngleArc: a line from the current position to the arc's start, then the arc (angles in degrees, counterclockwise). */
|
|
57
|
+
angleArc(cx: number, cy: number, radius: number, startDeg: number, sweepDeg: number): void;
|
|
58
|
+
/** Fill a rectangle with a colour, or the current brush (PatBlt, bitmap-less BitBlt). */
|
|
59
|
+
fillRect(l: number, t: number, r: number, b: number, color: string | undefined): void;
|
|
60
|
+
/** Draw a bitmap into a destination rectangle given in logical units. */
|
|
61
|
+
image(raster: RasterImage, x: number, y: number, w: number, h: number): void;
|
|
62
|
+
/**
|
|
63
|
+
* ExtTextOut / TextOut. (x, y) is the reference point (ignored under TA_UPDATECP); `dx` the
|
|
64
|
+
* advance after each character in logical units; `opaque` a rectangle filled with the
|
|
65
|
+
* background colour first (ETO_OPAQUE), which pictures also use to paint plain rectangles.
|
|
66
|
+
*/
|
|
67
|
+
text(x: number, y: number, chars: string[], dx: number[] | undefined, opaque?: [number, number, number, number]): void;
|
|
68
|
+
private push;
|
|
69
|
+
/** A mirrored mapping in compatible mode: GDI then keeps arc directions in device space. */
|
|
70
|
+
private mirrored;
|
|
71
|
+
/** Arc direction in logical space, as "clockwise when y points down". */
|
|
72
|
+
private clockwise;
|
|
73
|
+
/** A closed or self-contained shape: recorded into the path bracket, or drawn. */
|
|
74
|
+
private shape;
|
|
75
|
+
/** Commands that continue from the current position (LineTo, PolylineTo, ArcTo, …): stroked only. */
|
|
76
|
+
private openFrom;
|
|
77
|
+
private output;
|
|
78
|
+
private fillStyle;
|
|
79
|
+
private strokeStyle;
|
|
80
|
+
}
|
|
@@ -0,0 +1,515 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The drawing back end both metafile players share. It keeps the device context (with the
|
|
3
|
+
* SaveDC stack and the path bracket), maps logical coordinates through the whole transform chain
|
|
4
|
+
* (world → page → window/viewport → frame) into page points, and turns GDI drawing calls into
|
|
5
|
+
* display items. Path points are transformed when they are added, as GDI does, so a transform
|
|
6
|
+
* changed halfway through a path does not move what was already recorded.
|
|
7
|
+
*/
|
|
8
|
+
import { textItem } from '../layout/paint.js';
|
|
9
|
+
import { flipRaster } from './dib.js';
|
|
10
|
+
import { apply, arcCubics, compose, determinant, ellipseCubics, gdiArc } from './geometry.js';
|
|
11
|
+
import { AD_CLOCKWISE, ALTERNATE, OPAQUE, PS_ALTERNATE, PS_DASH, PS_DASHDOT, PS_DASHDOTDOT, PS_DOT, PS_NULL, PS_USERSTYLE, TA_BASELINE, TA_BOTTOM, TA_CENTER, TA_RIGHT, TA_UPDATECP, defaultState, mixColors, } from './state.js';
|
|
12
|
+
/** Pen width 0 and cosmetic pens are one device pixel wide: drawn as a hairline this wide (pt). */
|
|
13
|
+
export const HAIRLINE = 0.25;
|
|
14
|
+
/** How much of the area a GDI hatch covers, for drawing hatched brushes as a flat tint. */
|
|
15
|
+
const HATCH_COVERAGE = 0.35;
|
|
16
|
+
const M = (p) => ({ op: 'M', x: p.x, y: p.y });
|
|
17
|
+
const L = (p) => ({ op: 'L', x: p.x, y: p.y });
|
|
18
|
+
export class Canvas {
|
|
19
|
+
options;
|
|
20
|
+
items = [];
|
|
21
|
+
state = defaultState();
|
|
22
|
+
saved = [];
|
|
23
|
+
/** Commands of the path bracket, in page points; undefined when there is no path. */
|
|
24
|
+
path;
|
|
25
|
+
/** Between BeginPath and EndPath drawing calls add to the path instead of drawing. */
|
|
26
|
+
recording = false;
|
|
27
|
+
/** Whether the path's last figure is open and ends at the current position (so "…To" calls extend it). */
|
|
28
|
+
figureOpen = false;
|
|
29
|
+
/** The last stroked open path, which a following LineTo from its end point extends instead of starting a new item. */
|
|
30
|
+
chain;
|
|
31
|
+
constructor(options) {
|
|
32
|
+
this.options = options;
|
|
33
|
+
}
|
|
34
|
+
/** Logical → page points for the current state. */
|
|
35
|
+
matrix() {
|
|
36
|
+
return compose(this.state.world, this.options.pageToPoints(this.state));
|
|
37
|
+
}
|
|
38
|
+
// ---- device context ----
|
|
39
|
+
save() {
|
|
40
|
+
this.saved.push({ ...this.state });
|
|
41
|
+
}
|
|
42
|
+
/** RestoreDC: negative counts back from the latest SaveDC, positive names a SaveDC instance (1-based). */
|
|
43
|
+
restore(n) {
|
|
44
|
+
const index = n < 0 ? this.saved.length + n : n - 1;
|
|
45
|
+
const state = this.saved[index];
|
|
46
|
+
if (!state || n === 0)
|
|
47
|
+
return;
|
|
48
|
+
this.state = state;
|
|
49
|
+
this.saved.length = index;
|
|
50
|
+
}
|
|
51
|
+
// ---- paths ----
|
|
52
|
+
beginPath() {
|
|
53
|
+
this.path = [];
|
|
54
|
+
this.recording = true;
|
|
55
|
+
this.figureOpen = false;
|
|
56
|
+
}
|
|
57
|
+
endPath() {
|
|
58
|
+
this.recording = false;
|
|
59
|
+
}
|
|
60
|
+
abortPath() {
|
|
61
|
+
this.path = undefined;
|
|
62
|
+
this.recording = false;
|
|
63
|
+
this.figureOpen = false;
|
|
64
|
+
}
|
|
65
|
+
closeFigure() {
|
|
66
|
+
if (this.recording && this.path && this.figureOpen) {
|
|
67
|
+
this.path.push({ op: 'Z' });
|
|
68
|
+
this.figureOpen = false;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/** FillPath / StrokePath / StrokeAndFillPath: draw the recorded path and discard it. */
|
|
72
|
+
drawPath(fill, stroke) {
|
|
73
|
+
const path = this.path;
|
|
74
|
+
this.abortPath();
|
|
75
|
+
if (!path || !path.length)
|
|
76
|
+
return;
|
|
77
|
+
// Filling closes every open figure, and StrokeAndFillPath strokes the closed outline.
|
|
78
|
+
this.output(fill ? closeFigures(path) : path, fill, stroke);
|
|
79
|
+
}
|
|
80
|
+
// ---- lines and curves ----
|
|
81
|
+
moveTo(x, y) {
|
|
82
|
+
this.state.position = { x, y };
|
|
83
|
+
if (this.recording)
|
|
84
|
+
this.figureOpen = false;
|
|
85
|
+
}
|
|
86
|
+
lineTo(x, y) {
|
|
87
|
+
const m = this.matrix();
|
|
88
|
+
this.openFrom(m, [L(apply(m, x, y))]);
|
|
89
|
+
this.state.position = { x, y };
|
|
90
|
+
}
|
|
91
|
+
polylineTo(points) {
|
|
92
|
+
if (!points.length)
|
|
93
|
+
return;
|
|
94
|
+
const m = this.matrix();
|
|
95
|
+
this.openFrom(m, points.map((p) => L(apply(m, p.x, p.y))));
|
|
96
|
+
this.state.position = points[points.length - 1];
|
|
97
|
+
}
|
|
98
|
+
polyBezierTo(points) {
|
|
99
|
+
const n = points.length - (points.length % 3);
|
|
100
|
+
if (!n)
|
|
101
|
+
return;
|
|
102
|
+
const m = this.matrix();
|
|
103
|
+
this.openFrom(m, bezierCommands(m, points, 0, n));
|
|
104
|
+
this.state.position = points[n - 1];
|
|
105
|
+
}
|
|
106
|
+
/** Polyline (open, stroked) or Polygon (closed, filled and stroked). */
|
|
107
|
+
poly(points, closed) {
|
|
108
|
+
if (points.length < 2)
|
|
109
|
+
return;
|
|
110
|
+
const m = this.matrix();
|
|
111
|
+
const cmds = points.map((p, i) => (i ? L(apply(m, p.x, p.y)) : M(apply(m, p.x, p.y))));
|
|
112
|
+
if (closed)
|
|
113
|
+
cmds.push({ op: 'Z' });
|
|
114
|
+
this.shape(cmds, closed, true);
|
|
115
|
+
}
|
|
116
|
+
/** PolyPolygon draws one filled shape (holes follow the fill mode); PolyPolyline separate strokes. */
|
|
117
|
+
polyPoly(polys, closed) {
|
|
118
|
+
const m = this.matrix();
|
|
119
|
+
const cmds = [];
|
|
120
|
+
for (const points of polys) {
|
|
121
|
+
if (points.length < 2)
|
|
122
|
+
continue;
|
|
123
|
+
points.forEach((p, i) => cmds.push(i ? L(apply(m, p.x, p.y)) : M(apply(m, p.x, p.y))));
|
|
124
|
+
if (closed)
|
|
125
|
+
cmds.push({ op: 'Z' });
|
|
126
|
+
}
|
|
127
|
+
if (cmds.length)
|
|
128
|
+
this.shape(cmds, closed, true);
|
|
129
|
+
}
|
|
130
|
+
polyBezier(points) {
|
|
131
|
+
if (points.length < 4)
|
|
132
|
+
return;
|
|
133
|
+
const m = this.matrix();
|
|
134
|
+
const n = 1 + Math.floor((points.length - 1) / 3) * 3;
|
|
135
|
+
const cmds = [M(apply(m, points[0].x, points[0].y)), ...bezierCommands(m, points, 1, n)];
|
|
136
|
+
this.shape(cmds, false, true);
|
|
137
|
+
}
|
|
138
|
+
/** PolyDraw: PT_MOVETO 6, PT_LINETO 2, PT_BEZIERTO 4, each optionally | PT_CLOSEFIGURE 1. */
|
|
139
|
+
polyDraw(points, types) {
|
|
140
|
+
const m = this.matrix();
|
|
141
|
+
const cmds = [];
|
|
142
|
+
let last;
|
|
143
|
+
for (let i = 0; i < points.length; i++) {
|
|
144
|
+
const p = points[i];
|
|
145
|
+
const type = (types[i] ?? 2) & ~1;
|
|
146
|
+
if (type === 4 && i + 2 < points.length) {
|
|
147
|
+
cmds.push(...bezierCommands(m, points, i, i + 3));
|
|
148
|
+
i += 2;
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
cmds.push(type === 6 ? M(apply(m, p.x, p.y)) : L(apply(m, p.x, p.y)));
|
|
152
|
+
}
|
|
153
|
+
last = points[i];
|
|
154
|
+
if ((types[i] ?? 0) & 1)
|
|
155
|
+
cmds.push({ op: 'Z' });
|
|
156
|
+
}
|
|
157
|
+
if (!last)
|
|
158
|
+
return;
|
|
159
|
+
if (cmds[0]?.op === 'M') {
|
|
160
|
+
this.shape(cmds, false, true);
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
this.openFrom(m, cmds);
|
|
164
|
+
}
|
|
165
|
+
this.state.position = last;
|
|
166
|
+
}
|
|
167
|
+
// ---- shapes ----
|
|
168
|
+
rectangle(l, t, r, b) {
|
|
169
|
+
const m = this.matrix();
|
|
170
|
+
this.shape([M(apply(m, l, t)), L(apply(m, r, t)), L(apply(m, r, b)), L(apply(m, l, b)), { op: 'Z' }], true, true);
|
|
171
|
+
}
|
|
172
|
+
roundRect(l, t, r, b, w, h) {
|
|
173
|
+
const left = Math.min(l, r);
|
|
174
|
+
const right = Math.max(l, r);
|
|
175
|
+
const top = Math.min(t, b);
|
|
176
|
+
const bottom = Math.max(t, b);
|
|
177
|
+
const rx = Math.min(Math.abs(w) / 2, (right - left) / 2);
|
|
178
|
+
const ry = Math.min(Math.abs(h) / 2, (bottom - top) / 2);
|
|
179
|
+
if (rx <= 0 || ry <= 0) {
|
|
180
|
+
this.rectangle(left, top, right, bottom);
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
const m = this.matrix();
|
|
184
|
+
const cmds = [M(apply(m, left + rx, top)), L(apply(m, right - rx, top))];
|
|
185
|
+
const corner = (cx, cy, t0) => {
|
|
186
|
+
cmds.push(...cubicCommands(m, arcCubics(cx, cy, rx, ry, t0, Math.PI / 2)));
|
|
187
|
+
};
|
|
188
|
+
corner(right - rx, top + ry, -Math.PI / 2);
|
|
189
|
+
cmds.push(L(apply(m, right, bottom - ry)));
|
|
190
|
+
corner(right - rx, bottom - ry, 0);
|
|
191
|
+
cmds.push(L(apply(m, left + rx, bottom)));
|
|
192
|
+
corner(left + rx, bottom - ry, Math.PI / 2);
|
|
193
|
+
cmds.push(L(apply(m, left, top + ry)));
|
|
194
|
+
corner(left + rx, top + ry, Math.PI);
|
|
195
|
+
cmds.push({ op: 'Z' });
|
|
196
|
+
this.shape(cmds, true, true);
|
|
197
|
+
}
|
|
198
|
+
ellipse(l, t, r, b) {
|
|
199
|
+
const m = this.matrix();
|
|
200
|
+
const e = ellipseCubics(l, t, r, b);
|
|
201
|
+
this.shape([M(apply(m, e.start.x, e.start.y)), ...cubicCommands(m, e.cubics), { op: 'Z' }], true, true);
|
|
202
|
+
}
|
|
203
|
+
arc(kind, l, t, r, b, xs, ys, xe, ye) {
|
|
204
|
+
const m = this.matrix();
|
|
205
|
+
const arc = gdiArc(l, t, r, b, xs, ys, xe, ye, this.clockwise(m));
|
|
206
|
+
const start = apply(m, arc.start.x, arc.start.y);
|
|
207
|
+
const curve = cubicCommands(m, arc.cubics);
|
|
208
|
+
switch (kind) {
|
|
209
|
+
case 'arc':
|
|
210
|
+
this.shape([M(start), ...curve], false, true);
|
|
211
|
+
break;
|
|
212
|
+
case 'arcto':
|
|
213
|
+
this.openFrom(m, [L(start), ...curve]);
|
|
214
|
+
this.state.position = arc.end;
|
|
215
|
+
break;
|
|
216
|
+
case 'chord':
|
|
217
|
+
this.shape([M(start), ...curve, { op: 'Z' }], true, true);
|
|
218
|
+
break;
|
|
219
|
+
case 'pie':
|
|
220
|
+
this.shape([M(apply(m, arc.centre.x, arc.centre.y)), L(start), ...curve, { op: 'Z' }], true, true);
|
|
221
|
+
break;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
/** AngleArc: a line from the current position to the arc's start, then the arc (angles in degrees, counterclockwise). */
|
|
225
|
+
angleArc(cx, cy, radius, startDeg, sweepDeg) {
|
|
226
|
+
const m = this.matrix();
|
|
227
|
+
// The angles turn counterclockwise on a y-down device; a mirrored compatible-mode mapping reverses that in logical space.
|
|
228
|
+
const sign = this.mirrored(m) ? 1 : -1;
|
|
229
|
+
const sweep = Math.max(-360, Math.min(360, sweepDeg));
|
|
230
|
+
const t0 = (sign * startDeg * Math.PI) / 180;
|
|
231
|
+
const cubics = arcCubics(cx, cy, radius, radius, t0, (sign * sweep * Math.PI) / 180);
|
|
232
|
+
const start = { x: cx + radius * Math.cos(t0), y: cy + radius * Math.sin(t0) };
|
|
233
|
+
this.openFrom(m, [L(apply(m, start.x, start.y)), ...cubicCommands(m, cubics)]);
|
|
234
|
+
const end = cubics.length ? cubics[cubics.length - 1][2] : start;
|
|
235
|
+
this.state.position = end;
|
|
236
|
+
}
|
|
237
|
+
/** Fill a rectangle with a colour, or the current brush (PatBlt, bitmap-less BitBlt). */
|
|
238
|
+
fillRect(l, t, r, b, color) {
|
|
239
|
+
const m = this.matrix();
|
|
240
|
+
const commands = [M(apply(m, l, t)), L(apply(m, r, t)), L(apply(m, r, b)), L(apply(m, l, b)), { op: 'Z' }];
|
|
241
|
+
if (color) {
|
|
242
|
+
this.push({ type: 'path', commands, fill: color });
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
const fill = this.fillStyle();
|
|
246
|
+
if (fill)
|
|
247
|
+
this.push({ type: 'path', commands, ...fill });
|
|
248
|
+
}
|
|
249
|
+
// ---- bitmaps ----
|
|
250
|
+
/** Draw a bitmap into a destination rectangle given in logical units. */
|
|
251
|
+
image(raster, x, y, w, h) {
|
|
252
|
+
const m = this.matrix();
|
|
253
|
+
const p0 = apply(m, x, y);
|
|
254
|
+
const p1 = apply(m, x + w, y + h);
|
|
255
|
+
const width = Math.abs(p1.x - p0.x);
|
|
256
|
+
const height = Math.abs(p1.y - p0.y);
|
|
257
|
+
if (!(width > 0 && height > 0) || !Number.isFinite(width + height))
|
|
258
|
+
return;
|
|
259
|
+
// A destination that runs backwards in page space mirrors the bitmap, as StretchBlt does.
|
|
260
|
+
this.push({
|
|
261
|
+
type: 'image',
|
|
262
|
+
x: Math.min(p0.x, p1.x),
|
|
263
|
+
y: Math.min(p0.y, p1.y),
|
|
264
|
+
w: width,
|
|
265
|
+
h: height,
|
|
266
|
+
target: undefined,
|
|
267
|
+
external: false,
|
|
268
|
+
raster: flipRaster(raster, p1.x < p0.x, p1.y < p0.y),
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
// ---- text ----
|
|
272
|
+
/**
|
|
273
|
+
* ExtTextOut / TextOut. (x, y) is the reference point (ignored under TA_UPDATECP); `dx` the
|
|
274
|
+
* advance after each character in logical units; `opaque` a rectangle filled with the
|
|
275
|
+
* background colour first (ETO_OPAQUE), which pictures also use to paint plain rectangles.
|
|
276
|
+
*/
|
|
277
|
+
text(x, y, chars, dx, opaque) {
|
|
278
|
+
const st = this.state;
|
|
279
|
+
const m = this.matrix();
|
|
280
|
+
if (opaque) {
|
|
281
|
+
const [l, t, r, b] = opaque;
|
|
282
|
+
if (r !== l && b !== t)
|
|
283
|
+
this.fillRect(l, t, r, b, st.bkColor);
|
|
284
|
+
}
|
|
285
|
+
if (!chars.length)
|
|
286
|
+
return;
|
|
287
|
+
const { fonts } = this.options;
|
|
288
|
+
const f = st.font;
|
|
289
|
+
const base = fonts.get(f.faceName || undefined, f.weight >= 600, f.italic);
|
|
290
|
+
const xscale = Math.hypot(m.a, m.b);
|
|
291
|
+
const yscale = Math.hypot(m.c, m.d);
|
|
292
|
+
const cell = base.ascent + base.descent || 1;
|
|
293
|
+
// Negative heights give the em size; positive ones the cell height (ascent + descent).
|
|
294
|
+
const size = f.height === 0 ? this.options.defaultFontSize : f.height < 0 ? -f.height * yscale : (f.height * yscale) / cell;
|
|
295
|
+
if (!(size > 0) || !Number.isFinite(size))
|
|
296
|
+
return;
|
|
297
|
+
const cps = chars.map((c) => c.codePointAt(0) ?? 0x20);
|
|
298
|
+
const charFonts = cps.map((cp) => fonts.forChar(base, cp));
|
|
299
|
+
const advances = cps.map((cp, i) => (dx ? (dx[i] ?? 0) * xscale : charFonts[i].advance(cp) * size + st.charExtra * xscale));
|
|
300
|
+
const total = advances.reduce((a, b) => a + b, 0);
|
|
301
|
+
const updateCP = (st.textAlign & TA_UPDATECP) !== 0;
|
|
302
|
+
const ref = updateCP ? st.position : { x, y };
|
|
303
|
+
const origin = apply(m, ref.x, ref.y);
|
|
304
|
+
const horizontal = st.textAlign & TA_CENTER;
|
|
305
|
+
const vertical = st.textAlign & TA_BASELINE;
|
|
306
|
+
// GDI draws text upright on the device whatever the mapping, so alignment works in page points.
|
|
307
|
+
const left = origin.x - (horizontal === TA_CENTER ? total / 2 : horizontal === TA_RIGHT ? total : 0);
|
|
308
|
+
const baseline = origin.y + (vertical === TA_BASELINE ? 0 : vertical === TA_BOTTOM ? -base.descent * size : base.ascent * size);
|
|
309
|
+
const xs = [];
|
|
310
|
+
let cx = left;
|
|
311
|
+
for (const a of advances) {
|
|
312
|
+
xs.push(cx);
|
|
313
|
+
cx += a;
|
|
314
|
+
}
|
|
315
|
+
let runStart = -1;
|
|
316
|
+
let runFont;
|
|
317
|
+
const flush = (end) => {
|
|
318
|
+
if (runStart < 0 || !runFont)
|
|
319
|
+
return;
|
|
320
|
+
const slice = (arr) => arr.slice(runStart, end);
|
|
321
|
+
this.push(textItem(xs[runStart], baseline, chars.slice(runStart, end), slice(xs), slice(advances), runFont, size, st.textColor));
|
|
322
|
+
runStart = -1;
|
|
323
|
+
runFont = undefined;
|
|
324
|
+
};
|
|
325
|
+
for (let i = 0; i < chars.length; i++) {
|
|
326
|
+
// Control characters advance but draw nothing (fonts would show a missing-glyph box).
|
|
327
|
+
if (cps[i] < 0x20) {
|
|
328
|
+
flush(i);
|
|
329
|
+
continue;
|
|
330
|
+
}
|
|
331
|
+
if (runFont !== charFonts[i]) {
|
|
332
|
+
flush(i);
|
|
333
|
+
runStart = i;
|
|
334
|
+
runFont = charFonts[i];
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
flush(chars.length);
|
|
338
|
+
if (f.underline || f.strikeOut) {
|
|
339
|
+
const thickness = Math.max(base.underlineThickness * size, HAIRLINE);
|
|
340
|
+
const line = (yy) => {
|
|
341
|
+
this.push({ type: 'line', x1: left, y1: yy, x2: left + total, y2: yy, width: thickness, color: st.textColor, style: 'solid' });
|
|
342
|
+
};
|
|
343
|
+
if (f.underline)
|
|
344
|
+
line(baseline + base.underlinePosition * size);
|
|
345
|
+
if (f.strikeOut)
|
|
346
|
+
line(baseline - base.ascent * size * 0.3);
|
|
347
|
+
}
|
|
348
|
+
if (updateCP && xscale > 0) {
|
|
349
|
+
const dir = horizontal === TA_CENTER ? 0 : horizontal === TA_RIGHT ? -1 : 1;
|
|
350
|
+
st.position = { x: ref.x + (dir * total * Math.sign(m.a || 1)) / xscale, y: ref.y };
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
// ---- internals ----
|
|
354
|
+
push(item) {
|
|
355
|
+
this.items.push(item);
|
|
356
|
+
this.chain = undefined;
|
|
357
|
+
}
|
|
358
|
+
/** A mirrored mapping in compatible mode: GDI then keeps arc directions in device space. */
|
|
359
|
+
mirrored(m) {
|
|
360
|
+
return !this.state.advanced && determinant(m) < 0;
|
|
361
|
+
}
|
|
362
|
+
/** Arc direction in logical space, as "clockwise when y points down". */
|
|
363
|
+
clockwise(m) {
|
|
364
|
+
const cw = this.state.arcDirection === AD_CLOCKWISE;
|
|
365
|
+
return this.mirrored(m) ? !cw : cw;
|
|
366
|
+
}
|
|
367
|
+
/** A closed or self-contained shape: recorded into the path bracket, or drawn. */
|
|
368
|
+
shape(cmds, fill, stroke) {
|
|
369
|
+
if (this.recording && this.path) {
|
|
370
|
+
this.path.push(...cmds);
|
|
371
|
+
// These calls neither use nor move the current position, so a later LineTo starts afresh.
|
|
372
|
+
this.figureOpen = false;
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
this.output(cmds, fill, stroke);
|
|
376
|
+
}
|
|
377
|
+
/** Commands that continue from the current position (LineTo, PolylineTo, ArcTo, …): stroked only. */
|
|
378
|
+
openFrom(m, cmds) {
|
|
379
|
+
const from = apply(m, this.state.position.x, this.state.position.y);
|
|
380
|
+
if (this.recording && this.path) {
|
|
381
|
+
if (!this.figureOpen)
|
|
382
|
+
this.path.push(M(from));
|
|
383
|
+
this.path.push(...cmds);
|
|
384
|
+
this.figureOpen = cmds[cmds.length - 1]?.op !== 'Z';
|
|
385
|
+
return;
|
|
386
|
+
}
|
|
387
|
+
const stroke = this.strokeStyle(m);
|
|
388
|
+
if (!stroke)
|
|
389
|
+
return;
|
|
390
|
+
const end = lastPoint(cmds) ?? from;
|
|
391
|
+
// Runs of LineTo calls (common in charts) become one path rather than thousands of items.
|
|
392
|
+
const chain = this.chain;
|
|
393
|
+
if (chain && this.items[this.items.length - 1] === chain.item && near(chain.end, from) && sameStroke(chain.item, stroke)) {
|
|
394
|
+
chain.item.commands.push(...cmds);
|
|
395
|
+
chain.end = end;
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
398
|
+
const item = { type: 'path', commands: [M(from), ...cmds], ...stroke };
|
|
399
|
+
this.push(item);
|
|
400
|
+
this.chain = { item, end };
|
|
401
|
+
}
|
|
402
|
+
output(commands, fill, stroke) {
|
|
403
|
+
const m = this.matrix();
|
|
404
|
+
const f = fill ? this.fillStyle() : undefined;
|
|
405
|
+
const s = stroke ? this.strokeStyle(m) : undefined;
|
|
406
|
+
if (!f && !s)
|
|
407
|
+
return;
|
|
408
|
+
this.push({ type: 'path', commands, ...f, ...s });
|
|
409
|
+
}
|
|
410
|
+
fillStyle() {
|
|
411
|
+
const st = this.state;
|
|
412
|
+
const brush = st.brush;
|
|
413
|
+
let style;
|
|
414
|
+
switch (brush.style) {
|
|
415
|
+
case 'null':
|
|
416
|
+
return undefined;
|
|
417
|
+
case 'hatched':
|
|
418
|
+
// A hatch drawn as a flat tint of roughly its coverage; opaque mode fills the gaps with the background.
|
|
419
|
+
style = st.bkMode === OPAQUE ? { fill: mixColors(brush.color, st.bkColor, HATCH_COVERAGE) } : { fill: brush.color, fillOpacity: HATCH_COVERAGE };
|
|
420
|
+
break;
|
|
421
|
+
default:
|
|
422
|
+
style = { fill: brush.color };
|
|
423
|
+
}
|
|
424
|
+
if (st.polyFillMode === ALTERNATE)
|
|
425
|
+
style.evenOdd = true;
|
|
426
|
+
return style;
|
|
427
|
+
}
|
|
428
|
+
strokeStyle(m) {
|
|
429
|
+
const pen = this.state.pen;
|
|
430
|
+
if (pen.style === PS_NULL)
|
|
431
|
+
return undefined;
|
|
432
|
+
const hair = pen.cosmetic || pen.width === 0;
|
|
433
|
+
const scale = Math.sqrt(Math.abs(determinant(m)));
|
|
434
|
+
const width = hair ? HAIRLINE : Math.max(HAIRLINE, pen.width * scale);
|
|
435
|
+
const style = { stroke: pen.color, strokeWidth: width, lineCap: pen.cap, lineJoin: pen.join };
|
|
436
|
+
// Wine's patterns: cosmetic dashes in device pixels, geometric ones in multiples of the width.
|
|
437
|
+
const unit = hair ? Math.max(this.options.pixel, HAIRLINE) : width;
|
|
438
|
+
let pattern;
|
|
439
|
+
switch (pen.style) {
|
|
440
|
+
case PS_DASH:
|
|
441
|
+
pattern = hair ? [18, 6] : [3, 1];
|
|
442
|
+
break;
|
|
443
|
+
case PS_DOT:
|
|
444
|
+
pattern = hair ? [3, 3] : [1, 1];
|
|
445
|
+
break;
|
|
446
|
+
case PS_DASHDOT:
|
|
447
|
+
pattern = hair ? [9, 6, 3, 6] : [3, 1, 1, 1];
|
|
448
|
+
break;
|
|
449
|
+
case PS_DASHDOTDOT:
|
|
450
|
+
pattern = hair ? [9, 3, 3, 3, 3, 3] : [3, 1, 1, 1, 1, 1];
|
|
451
|
+
break;
|
|
452
|
+
case PS_ALTERNATE:
|
|
453
|
+
pattern = [1, 1];
|
|
454
|
+
break;
|
|
455
|
+
case PS_USERSTYLE:
|
|
456
|
+
if (pen.dashes?.length)
|
|
457
|
+
style.dash = pen.dashes.map((d) => Math.abs(d) * (hair ? unit : scale));
|
|
458
|
+
break;
|
|
459
|
+
}
|
|
460
|
+
if (pattern)
|
|
461
|
+
style.dash = pattern.map((d) => d * unit);
|
|
462
|
+
if (style.dash && !style.dash.some((d) => d > 0))
|
|
463
|
+
delete style.dash;
|
|
464
|
+
return style;
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
function near(a, b) {
|
|
468
|
+
return Math.abs(a.x - b.x) < 1e-6 && Math.abs(a.y - b.y) < 1e-6;
|
|
469
|
+
}
|
|
470
|
+
function sameStroke(item, s) {
|
|
471
|
+
return (!item.fill &&
|
|
472
|
+
item.stroke === s.stroke &&
|
|
473
|
+
item.strokeWidth === s.strokeWidth &&
|
|
474
|
+
item.lineCap === s.lineCap &&
|
|
475
|
+
item.lineJoin === s.lineJoin &&
|
|
476
|
+
(item.dash ?? []).join() === (s.dash ?? []).join());
|
|
477
|
+
}
|
|
478
|
+
function lastPoint(cmds) {
|
|
479
|
+
for (let i = cmds.length - 1; i >= 0; i--) {
|
|
480
|
+
const c = cmds[i];
|
|
481
|
+
if (c.op !== 'Z')
|
|
482
|
+
return { x: c.x, y: c.y };
|
|
483
|
+
}
|
|
484
|
+
return undefined;
|
|
485
|
+
}
|
|
486
|
+
function cubicCommands(m, cubics) {
|
|
487
|
+
return cubics.map(([c1, c2, p]) => {
|
|
488
|
+
const a = apply(m, c1.x, c1.y);
|
|
489
|
+
const b = apply(m, c2.x, c2.y);
|
|
490
|
+
const e = apply(m, p.x, p.y);
|
|
491
|
+
return { op: 'C', x1: a.x, y1: a.y, x2: b.x, y2: b.y, x: e.x, y: e.y };
|
|
492
|
+
});
|
|
493
|
+
}
|
|
494
|
+
/** Bézier triples (control, control, end) of points[from, to). */
|
|
495
|
+
function bezierCommands(m, points, from, to) {
|
|
496
|
+
const cubics = [];
|
|
497
|
+
for (let i = from; i + 2 < to && i + 2 < points.length; i += 3)
|
|
498
|
+
cubics.push([points[i], points[i + 1], points[i + 2]]);
|
|
499
|
+
return cubicCommands(m, cubics);
|
|
500
|
+
}
|
|
501
|
+
/** Close every figure that is not closed yet (FillPath and StrokeAndFillPath do this). */
|
|
502
|
+
function closeFigures(path) {
|
|
503
|
+
const out = [];
|
|
504
|
+
let open = false;
|
|
505
|
+
for (const c of path) {
|
|
506
|
+
if (c.op === 'M' && open)
|
|
507
|
+
out.push({ op: 'Z' });
|
|
508
|
+
out.push(c);
|
|
509
|
+
// A figure needs a segment to be worth closing; a bare MoveTo stays as it is.
|
|
510
|
+
open = c.op === 'L' || c.op === 'C';
|
|
511
|
+
}
|
|
512
|
+
if (open)
|
|
513
|
+
out.push({ op: 'Z' });
|
|
514
|
+
return out;
|
|
515
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Device-independent bitmaps (BITMAPINFO header, colour table, pixels) as EMF and WMF records
|
|
3
|
+
* embed them, decoded to RGBA. Covers 1/4/8/16/24/32 bits per pixel with BI_RGB, BI_BITFIELDS
|
|
4
|
+
* and the RLE4/RLE8 run-length forms old WMFs use. JPEG/PNG-compressed DIBs are not decoded.
|
|
5
|
+
*/
|
|
6
|
+
import type { RasterImage } from '../layout/types.js';
|
|
7
|
+
export interface DibOptions {
|
|
8
|
+
/** DIB_PAL_COLORS: the colour table holds palette indices, not colours. */
|
|
9
|
+
paletteIndices?: boolean;
|
|
10
|
+
/** Take 32-bpp alpha as premultiplied (AlphaBlend with AC_SRC_ALPHA); otherwise that byte is ignored. */
|
|
11
|
+
alpha?: boolean;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Decode a DIB. `info` holds the BITMAPINFO; `bits` the pixels, or undefined when they follow the
|
|
15
|
+
* header and colour table in `info` (a packed DIB, as WMF records store it).
|
|
16
|
+
*/
|
|
17
|
+
export declare function decodeDib(info: Uint8Array, bits: Uint8Array | undefined, options?: DibOptions): RasterImage | undefined;
|
|
18
|
+
/** The mean colour of a bitmap (pattern brushes are drawn as a flat fill of it). */
|
|
19
|
+
export declare function averageColor(img: RasterImage): string;
|
|
20
|
+
/** The part of a bitmap inside the rectangle (top-down pixel coordinates), clipped to the bitmap. */
|
|
21
|
+
export declare function cropRaster(img: RasterImage, x: number, y: number, w: number, h: number): RasterImage;
|
|
22
|
+
/** Mirror a bitmap, for destinations whose width or height runs backwards. */
|
|
23
|
+
export declare function flipRaster(img: RasterImage, horizontal: boolean, vertical: boolean): RasterImage;
|
|
24
|
+
/** Make pixels of one colour transparent (TransparentBlt). */
|
|
25
|
+
export declare function keyOut(img: RasterImage, color: string): RasterImage;
|
|
26
|
+
/** Whether a DIB stores its rows bottom-up (positive height), which puts StretchDIBits' source origin at the bottom. */
|
|
27
|
+
export declare function dibIsBottomUp(info: Uint8Array): boolean;
|