@lexmata/micropdf 0.4.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/LICENSE +191 -0
- package/README.md +985 -0
- package/binding.gyp +73 -0
- package/dist/annot.d.ts +458 -0
- package/dist/annot.d.ts.map +1 -0
- package/dist/annot.js +697 -0
- package/dist/annot.js.map +1 -0
- package/dist/archive.d.ts +128 -0
- package/dist/archive.d.ts.map +1 -0
- package/dist/archive.js +268 -0
- package/dist/archive.js.map +1 -0
- package/dist/buffer.d.ts +572 -0
- package/dist/buffer.d.ts.map +1 -0
- package/dist/buffer.js +971 -0
- package/dist/buffer.js.map +1 -0
- package/dist/colorspace.d.ts +287 -0
- package/dist/colorspace.d.ts.map +1 -0
- package/dist/colorspace.js +542 -0
- package/dist/colorspace.js.map +1 -0
- package/dist/context.d.ts +184 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +320 -0
- package/dist/context.js.map +1 -0
- package/dist/cookie.d.ts +164 -0
- package/dist/cookie.d.ts.map +1 -0
- package/dist/cookie.js +306 -0
- package/dist/cookie.js.map +1 -0
- package/dist/device.d.ts +169 -0
- package/dist/device.d.ts.map +1 -0
- package/dist/device.js +350 -0
- package/dist/device.js.map +1 -0
- package/dist/display-list.d.ts +202 -0
- package/dist/display-list.d.ts.map +1 -0
- package/dist/display-list.js +410 -0
- package/dist/display-list.js.map +1 -0
- package/dist/document.d.ts +637 -0
- package/dist/document.d.ts.map +1 -0
- package/dist/document.js +902 -0
- package/dist/document.js.map +1 -0
- package/dist/easy.d.ts +423 -0
- package/dist/easy.d.ts.map +1 -0
- package/dist/easy.js +644 -0
- package/dist/easy.js.map +1 -0
- package/dist/enhanced.d.ts +226 -0
- package/dist/enhanced.d.ts.map +1 -0
- package/dist/enhanced.js +368 -0
- package/dist/enhanced.js.map +1 -0
- package/dist/filter.d.ts +51 -0
- package/dist/filter.d.ts.map +1 -0
- package/dist/filter.js +381 -0
- package/dist/filter.js.map +1 -0
- package/dist/font.d.ts +222 -0
- package/dist/font.d.ts.map +1 -0
- package/dist/font.js +381 -0
- package/dist/font.js.map +1 -0
- package/dist/form.d.ts +214 -0
- package/dist/form.d.ts.map +1 -0
- package/dist/form.js +497 -0
- package/dist/form.js.map +1 -0
- package/dist/geometry.d.ts +469 -0
- package/dist/geometry.d.ts.map +1 -0
- package/dist/geometry.js +780 -0
- package/dist/geometry.js.map +1 -0
- package/dist/image.d.ts +172 -0
- package/dist/image.d.ts.map +1 -0
- package/dist/image.js +348 -0
- package/dist/image.js.map +1 -0
- package/dist/index.d.ts +171 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +339 -0
- package/dist/index.js.map +1 -0
- package/dist/link.d.ts +168 -0
- package/dist/link.d.ts.map +1 -0
- package/dist/link.js +343 -0
- package/dist/link.js.map +1 -0
- package/dist/micropdf.d.ts +40 -0
- package/dist/micropdf.d.ts.map +1 -0
- package/dist/micropdf.js +45 -0
- package/dist/micropdf.js.map +1 -0
- package/dist/nanopdf.d.ts +40 -0
- package/dist/nanopdf.d.ts.map +1 -0
- package/dist/nanopdf.js +45 -0
- package/dist/nanopdf.js.map +1 -0
- package/dist/native.d.ts +242 -0
- package/dist/native.d.ts.map +1 -0
- package/dist/native.js +509 -0
- package/dist/native.js.map +1 -0
- package/dist/output.d.ts +166 -0
- package/dist/output.d.ts.map +1 -0
- package/dist/output.js +365 -0
- package/dist/output.js.map +1 -0
- package/dist/path.d.ts +420 -0
- package/dist/path.d.ts.map +1 -0
- package/dist/path.js +687 -0
- package/dist/path.js.map +1 -0
- package/dist/pdf/object.d.ts +489 -0
- package/dist/pdf/object.d.ts.map +1 -0
- package/dist/pdf/object.js +1045 -0
- package/dist/pdf/object.js.map +1 -0
- package/dist/pixmap.d.ts +315 -0
- package/dist/pixmap.d.ts.map +1 -0
- package/dist/pixmap.js +590 -0
- package/dist/pixmap.js.map +1 -0
- package/dist/profiler.d.ts +159 -0
- package/dist/profiler.d.ts.map +1 -0
- package/dist/profiler.js +380 -0
- package/dist/profiler.js.map +1 -0
- package/dist/render-options.d.ts +227 -0
- package/dist/render-options.d.ts.map +1 -0
- package/dist/render-options.js +130 -0
- package/dist/render-options.js.map +1 -0
- package/dist/resource-tracking.d.ts +332 -0
- package/dist/resource-tracking.d.ts.map +1 -0
- package/dist/resource-tracking.js +653 -0
- package/dist/resource-tracking.js.map +1 -0
- package/dist/simple.d.ts +276 -0
- package/dist/simple.d.ts.map +1 -0
- package/dist/simple.js +343 -0
- package/dist/simple.js.map +1 -0
- package/dist/stext.d.ts +290 -0
- package/dist/stext.d.ts.map +1 -0
- package/dist/stext.js +312 -0
- package/dist/stext.js.map +1 -0
- package/dist/stream.d.ts +174 -0
- package/dist/stream.d.ts.map +1 -0
- package/dist/stream.js +476 -0
- package/dist/stream.js.map +1 -0
- package/dist/text.d.ts +337 -0
- package/dist/text.d.ts.map +1 -0
- package/dist/text.js +454 -0
- package/dist/text.js.map +1 -0
- package/dist/typed-arrays.d.ts +127 -0
- package/dist/typed-arrays.d.ts.map +1 -0
- package/dist/typed-arrays.js +410 -0
- package/dist/typed-arrays.js.map +1 -0
- package/dist/types.d.ts +358 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +216 -0
- package/dist/types.js.map +1 -0
- package/native/annot.cc +557 -0
- package/native/buffer.cc +204 -0
- package/native/colorspace.cc +166 -0
- package/native/context.cc +84 -0
- package/native/cookie.cc +179 -0
- package/native/device.cc +179 -0
- package/native/display_list.cc +179 -0
- package/native/document.cc +268 -0
- package/native/enhanced.cc +70 -0
- package/native/font.cc +282 -0
- package/native/form.cc +523 -0
- package/native/geometry.cc +255 -0
- package/native/image.cc +216 -0
- package/native/include/micropdf/enhanced.h +38 -0
- package/native/include/micropdf/types.h +36 -0
- package/native/include/micropdf.h +106 -0
- package/native/include/mupdf-ffi.h +39 -0
- package/native/include/mupdf.h +11 -0
- package/native/include/mupdf_minimal.h +381 -0
- package/native/lib/linux-x64/libmicropdf.a +0 -0
- package/native/link.cc +234 -0
- package/native/micropdf.cc +71 -0
- package/native/output.cc +229 -0
- package/native/page.cc +572 -0
- package/native/path.cc +259 -0
- package/native/pixmap.cc +240 -0
- package/native/stext.cc +610 -0
- package/native/stream.cc +239 -0
- package/package.json +120 -0
- package/scripts/build-from-rust.js +97 -0
- package/scripts/install.js +184 -0
package/dist/path.d.ts
ADDED
|
@@ -0,0 +1,420 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Path - PDF path construction and vector graphics
|
|
3
|
+
*
|
|
4
|
+
* This module provides comprehensive support for creating and manipulating vector paths
|
|
5
|
+
* used in PDF graphics. Paths are fundamental building blocks for drawing lines, curves,
|
|
6
|
+
* shapes, and complex vector graphics in PDF documents.
|
|
7
|
+
*
|
|
8
|
+
* This module provides 100% API compatibility with MuPDF's path operations.
|
|
9
|
+
*
|
|
10
|
+
* @module path
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { Path, StrokeState, LineCap, LineJoin, Matrix } from 'micropdf';
|
|
14
|
+
*
|
|
15
|
+
* // Create a simple path
|
|
16
|
+
* const path = Path.create();
|
|
17
|
+
* path.moveTo(10, 10);
|
|
18
|
+
* path.lineTo(100, 10);
|
|
19
|
+
* path.lineTo(100, 100);
|
|
20
|
+
* path.close();
|
|
21
|
+
*
|
|
22
|
+
* // Create a rectangle
|
|
23
|
+
* const rect = Path.create();
|
|
24
|
+
* rect.rect(0, 0, 200, 100);
|
|
25
|
+
*
|
|
26
|
+
* // Create a curve
|
|
27
|
+
* const curve = Path.create();
|
|
28
|
+
* curve.moveTo(0, 0);
|
|
29
|
+
* curve.curveTo(50, 100, 100, 100, 150, 0);
|
|
30
|
+
*
|
|
31
|
+
* // Configure stroke
|
|
32
|
+
* const stroke = StrokeState.create();
|
|
33
|
+
* stroke.setLineWidth(2);
|
|
34
|
+
* stroke.setLineCap(LineCap.Round);
|
|
35
|
+
* stroke.setLineJoin(LineJoin.Round);
|
|
36
|
+
* stroke.setDash([5, 3], 0); // 5 on, 3 off
|
|
37
|
+
*
|
|
38
|
+
* // Transform path
|
|
39
|
+
* const matrix = Matrix.scale(2, 2);
|
|
40
|
+
* path.transform(matrix);
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
import { Point, Rect, type PointLike, type MatrixLike } from './geometry.js';
|
|
44
|
+
/**
|
|
45
|
+
* Line cap styles determine how the ends of stroked paths are rendered.
|
|
46
|
+
*
|
|
47
|
+
* @enum {number}
|
|
48
|
+
* @example
|
|
49
|
+
* ```typescript
|
|
50
|
+
* const stroke = StrokeState.create();
|
|
51
|
+
* stroke.setLineCap(LineCap.Round); // Rounded end caps
|
|
52
|
+
* stroke.setStartCap(LineCap.Square); // Square start cap
|
|
53
|
+
* stroke.setEndCap(LineCap.Butt); // Flat end cap
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
export declare enum LineCap {
|
|
57
|
+
/**
|
|
58
|
+
* Butt cap - Line ends exactly at the endpoint (no extension).
|
|
59
|
+
* This is the most common and default cap style.
|
|
60
|
+
*/
|
|
61
|
+
Butt = 0,
|
|
62
|
+
/**
|
|
63
|
+
* Round cap - Line extends with a semicircular cap at the endpoint.
|
|
64
|
+
* The diameter equals the line width.
|
|
65
|
+
*/
|
|
66
|
+
Round = 1,
|
|
67
|
+
/**
|
|
68
|
+
* Square cap - Line extends with a square cap at the endpoint.
|
|
69
|
+
* The extension equals half the line width.
|
|
70
|
+
*/
|
|
71
|
+
Square = 2,
|
|
72
|
+
/**
|
|
73
|
+
* Triangle cap - Line extends with a triangular cap at the endpoint.
|
|
74
|
+
* Less common, used for special effects.
|
|
75
|
+
*/
|
|
76
|
+
Triangle = 3
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Line join styles determine how path segments connect at corners.
|
|
80
|
+
*
|
|
81
|
+
* @enum {number}
|
|
82
|
+
* @example
|
|
83
|
+
* ```typescript
|
|
84
|
+
* const stroke = StrokeState.create();
|
|
85
|
+
* stroke.setLineJoin(LineJoin.Round); // Smooth rounded corners
|
|
86
|
+
* stroke.setLineJoin(LineJoin.Miter); // Sharp pointed corners
|
|
87
|
+
* stroke.setMiterLimit(10); // Limit miter length
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
export declare enum LineJoin {
|
|
91
|
+
/**
|
|
92
|
+
* Miter join - Extends the outer edges until they meet at a point.
|
|
93
|
+
* Creates sharp corners but can become very long at acute angles.
|
|
94
|
+
* Use miterLimit to prevent excessive extension.
|
|
95
|
+
*/
|
|
96
|
+
Miter = 0,
|
|
97
|
+
/**
|
|
98
|
+
* Round join - Joins segments with a circular arc.
|
|
99
|
+
* Creates smooth, rounded corners with radius equal to half the line width.
|
|
100
|
+
*/
|
|
101
|
+
Round = 1,
|
|
102
|
+
/**
|
|
103
|
+
* Bevel join - Joins segments with a straight line across the corner.
|
|
104
|
+
* Creates a flat, beveled corner. Safe for all angles.
|
|
105
|
+
*/
|
|
106
|
+
Bevel = 2,
|
|
107
|
+
/**
|
|
108
|
+
* Miter XPS join - Miter join variant used in XPS documents.
|
|
109
|
+
* Similar to standard miter but with slightly different behavior.
|
|
110
|
+
*/
|
|
111
|
+
MiterXPS = 3
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Type alias for line cap styles (backwards compatibility).
|
|
115
|
+
* @deprecated Use {@link LineCap} instead
|
|
116
|
+
* @type {typeof LineCap}
|
|
117
|
+
*/
|
|
118
|
+
export declare const LineCapStyle: typeof LineCap;
|
|
119
|
+
/**
|
|
120
|
+
* Type alias for line join styles (backwards compatibility).
|
|
121
|
+
* @deprecated Use {@link LineJoin} instead
|
|
122
|
+
* @type {typeof LineJoin}
|
|
123
|
+
*/
|
|
124
|
+
export declare const LineJoinStyle: typeof LineJoin;
|
|
125
|
+
/**
|
|
126
|
+
* Stroke state configuration for path rendering.
|
|
127
|
+
*
|
|
128
|
+
* StrokeState encapsulates all the properties that control how paths are stroked
|
|
129
|
+
* (drawn with lines). This includes line width, cap styles, join styles, miter limits,
|
|
130
|
+
* and dash patterns.
|
|
131
|
+
*
|
|
132
|
+
* **Reference Counting**: StrokeState uses manual reference counting. Call `keep()` to
|
|
133
|
+
* increment the reference count and `drop()` to decrement it.
|
|
134
|
+
*
|
|
135
|
+
* @class StrokeState
|
|
136
|
+
* @example
|
|
137
|
+
* ```typescript
|
|
138
|
+
* // Create default stroke state
|
|
139
|
+
* const stroke = StrokeState.create();
|
|
140
|
+
*
|
|
141
|
+
* // Configure stroke properties
|
|
142
|
+
* stroke.setLineWidth(2.5);
|
|
143
|
+
* stroke.setStartCap(LineCap.Round);
|
|
144
|
+
* stroke.setLineJoin(LineJoin.Round);
|
|
145
|
+
* stroke.setMiterLimit(10);
|
|
146
|
+
*
|
|
147
|
+
* // Set dash pattern: 5 units on, 3 units off
|
|
148
|
+
* stroke.setDash([5, 3], 0);
|
|
149
|
+
*
|
|
150
|
+
* // Clone for variations
|
|
151
|
+
* const thickStroke = stroke.clone();
|
|
152
|
+
* thickStroke.setLineWidth(5);
|
|
153
|
+
*
|
|
154
|
+
* // Clean up
|
|
155
|
+
* stroke.drop();
|
|
156
|
+
* thickStroke.drop();
|
|
157
|
+
* ```
|
|
158
|
+
*
|
|
159
|
+
* @example
|
|
160
|
+
* ```typescript
|
|
161
|
+
* // Create dotted line
|
|
162
|
+
* const dotted = StrokeState.create();
|
|
163
|
+
* dotted.setLineWidth(1);
|
|
164
|
+
* dotted.setLineCap(LineCap.Round);
|
|
165
|
+
* dotted.setDash([2, 2], 0); // 2 on, 2 off
|
|
166
|
+
*
|
|
167
|
+
* // Create dashed line
|
|
168
|
+
* const dashed = StrokeState.create();
|
|
169
|
+
* dashed.setLineWidth(2);
|
|
170
|
+
* dashed.setDash([10, 5], 0); // 10 on, 5 off
|
|
171
|
+
*
|
|
172
|
+
* // Create solid line with rounded corners
|
|
173
|
+
* const rounded = StrokeState.create();
|
|
174
|
+
* rounded.setLineWidth(3);
|
|
175
|
+
* rounded.setLineCap(LineCap.Round);
|
|
176
|
+
* rounded.setLineJoin(LineJoin.Round);
|
|
177
|
+
* ```
|
|
178
|
+
*/
|
|
179
|
+
export declare class StrokeState {
|
|
180
|
+
private _lineWidth;
|
|
181
|
+
private _startCap;
|
|
182
|
+
private _dashCap;
|
|
183
|
+
private _endCap;
|
|
184
|
+
private _lineJoin;
|
|
185
|
+
private _miterLimit;
|
|
186
|
+
private _dashPhase;
|
|
187
|
+
private _dashPattern;
|
|
188
|
+
private _refCount;
|
|
189
|
+
constructor();
|
|
190
|
+
/**
|
|
191
|
+
* Create a new stroke state
|
|
192
|
+
*/
|
|
193
|
+
static create(): StrokeState;
|
|
194
|
+
/**
|
|
195
|
+
* Create stroke state with specific dash pattern length
|
|
196
|
+
*/
|
|
197
|
+
static createWithDashLen(dashLen: number): StrokeState;
|
|
198
|
+
/**
|
|
199
|
+
* Clone this stroke state
|
|
200
|
+
*/
|
|
201
|
+
clone(): StrokeState;
|
|
202
|
+
/**
|
|
203
|
+
* Keep (increment ref count)
|
|
204
|
+
*/
|
|
205
|
+
keep(): this;
|
|
206
|
+
/**
|
|
207
|
+
* Drop (decrement ref count)
|
|
208
|
+
*/
|
|
209
|
+
drop(): void;
|
|
210
|
+
/**
|
|
211
|
+
* Unshare (make a unique copy if shared)
|
|
212
|
+
*/
|
|
213
|
+
unshare(): StrokeState;
|
|
214
|
+
get lineWidth(): number;
|
|
215
|
+
set lineWidth(width: number);
|
|
216
|
+
get startCap(): LineCap;
|
|
217
|
+
set startCap(cap: LineCap);
|
|
218
|
+
get dashCap(): LineCap;
|
|
219
|
+
set dashCap(cap: LineCap);
|
|
220
|
+
get endCap(): LineCap;
|
|
221
|
+
set endCap(cap: LineCap);
|
|
222
|
+
get lineJoin(): LineJoin;
|
|
223
|
+
set lineJoin(join: LineJoin);
|
|
224
|
+
get miterLimit(): number;
|
|
225
|
+
set miterLimit(limit: number);
|
|
226
|
+
get dashPhase(): number;
|
|
227
|
+
get dashLength(): number;
|
|
228
|
+
getDashPattern(): number[];
|
|
229
|
+
setDash(pattern: number[], phase?: number): void;
|
|
230
|
+
/**
|
|
231
|
+
* Check if stroke state is valid
|
|
232
|
+
*/
|
|
233
|
+
isValid(): boolean;
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Path walker interface for traversing path commands
|
|
237
|
+
*/
|
|
238
|
+
export interface PathWalker {
|
|
239
|
+
moveTo?(x: number, y: number): void;
|
|
240
|
+
lineTo?(x: number, y: number): void;
|
|
241
|
+
curveTo?(cx1: number, cy1: number, cx2: number, cy2: number, x: number, y: number): void;
|
|
242
|
+
closePath?(): void;
|
|
243
|
+
quadTo?(cx: number, cy: number, x: number, y: number): void;
|
|
244
|
+
rectTo?(x: number, y: number, w: number, h: number): void;
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* A graphics path for constructing vector shapes and drawings.
|
|
248
|
+
*
|
|
249
|
+
* Path represents a sequence of drawing commands that define vector graphics.
|
|
250
|
+
* Paths can contain lines, curves, rectangles, and other geometric primitives.
|
|
251
|
+
* They can be stroked (outlined) or filled to create visible graphics in PDFs.
|
|
252
|
+
*
|
|
253
|
+
* **Path Construction**: Paths are built using a sequence of commands:
|
|
254
|
+
* - `moveTo()` - Start a new subpath at a point
|
|
255
|
+
* - `lineTo()` - Draw a straight line to a point
|
|
256
|
+
* - `curveTo()` - Draw a cubic Bézier curve
|
|
257
|
+
* - `quadTo()` - Draw a quadratic Bézier curve
|
|
258
|
+
* - `rect()` - Add a rectangle
|
|
259
|
+
* - `closePath()` / `close()` - Close the current subpath
|
|
260
|
+
*
|
|
261
|
+
* **Reference Counting**: Paths use manual reference counting. Call `keep()` to
|
|
262
|
+
* increment the reference count and `drop()` to decrement it.
|
|
263
|
+
*
|
|
264
|
+
* @class Path
|
|
265
|
+
* @example
|
|
266
|
+
* ```typescript
|
|
267
|
+
* // Draw a triangle
|
|
268
|
+
* const triangle = Path.create();
|
|
269
|
+
* triangle.moveTo(50, 0);
|
|
270
|
+
* triangle.lineTo(100, 100);
|
|
271
|
+
* triangle.lineTo(0, 100);
|
|
272
|
+
* triangle.close();
|
|
273
|
+
*
|
|
274
|
+
* // Draw a rectangle
|
|
275
|
+
* const rect = Path.create();
|
|
276
|
+
* rect.rect(10, 10, 200, 100);
|
|
277
|
+
*
|
|
278
|
+
* // Draw a rounded rectangle
|
|
279
|
+
* const roundedRect = Path.create();
|
|
280
|
+
* const x = 10, y = 10, w = 200, h = 100, r = 10;
|
|
281
|
+
* roundedRect.moveTo(x + r, y);
|
|
282
|
+
* roundedRect.lineTo(x + w - r, y);
|
|
283
|
+
* roundedRect.curveTo(x + w, y, x + w, y, x + w, y + r);
|
|
284
|
+
* roundedRect.lineTo(x + w, y + h - r);
|
|
285
|
+
* roundedRect.curveTo(x + w, y + h, x + w, y + h, x + w - r, y + h);
|
|
286
|
+
* roundedRect.lineTo(x + r, y + h);
|
|
287
|
+
* roundedRect.curveTo(x, y + h, x, y + h, x, y + h - r);
|
|
288
|
+
* roundedRect.lineTo(x, y + r);
|
|
289
|
+
* roundedRect.curveTo(x, y, x, y, x + r, y);
|
|
290
|
+
* roundedRect.close();
|
|
291
|
+
* ```
|
|
292
|
+
*
|
|
293
|
+
* @example
|
|
294
|
+
* ```typescript
|
|
295
|
+
* // Draw a sine wave
|
|
296
|
+
* const wave = Path.create();
|
|
297
|
+
* wave.moveTo(0, 50);
|
|
298
|
+
* for (let x = 0; x <= 200; x += 5) {
|
|
299
|
+
* const y = 50 + Math.sin(x * 0.1) * 20;
|
|
300
|
+
* wave.lineTo(x, y);
|
|
301
|
+
* }
|
|
302
|
+
*
|
|
303
|
+
* // Transform the path
|
|
304
|
+
* const matrix = Matrix.scale(2, 2);
|
|
305
|
+
* wave.transform(matrix);
|
|
306
|
+
*
|
|
307
|
+
* // Check if empty
|
|
308
|
+
* if (!wave.isEmpty()) {
|
|
309
|
+
* console.log('Path has commands');
|
|
310
|
+
* }
|
|
311
|
+
*
|
|
312
|
+
* // Clean up
|
|
313
|
+
* wave.drop();
|
|
314
|
+
* ```
|
|
315
|
+
*
|
|
316
|
+
* @example
|
|
317
|
+
* ```typescript
|
|
318
|
+
* // Draw a circle approximation with cubic Bézier curves
|
|
319
|
+
* const circle = Path.create();
|
|
320
|
+
* const cx = 100, cy = 100, r = 50;
|
|
321
|
+
* const k = 0.5522847498; // 4/3 * (sqrt(2) - 1)
|
|
322
|
+
* const kr = r * k;
|
|
323
|
+
*
|
|
324
|
+
* circle.moveTo(cx, cy - r);
|
|
325
|
+
* circle.curveTo(cx + kr, cy - r, cx + r, cy - kr, cx + r, cy);
|
|
326
|
+
* circle.curveTo(cx + r, cy + kr, cx + kr, cy + r, cx, cy + r);
|
|
327
|
+
* circle.curveTo(cx - kr, cy + r, cx - r, cy + kr, cx - r, cy);
|
|
328
|
+
* circle.curveTo(cx - r, cy - kr, cx - kr, cy - r, cx, cy - r);
|
|
329
|
+
* circle.close();
|
|
330
|
+
* ```
|
|
331
|
+
*/
|
|
332
|
+
export declare class Path {
|
|
333
|
+
private _commands;
|
|
334
|
+
private _currentPoint;
|
|
335
|
+
private _refCount;
|
|
336
|
+
constructor();
|
|
337
|
+
/**
|
|
338
|
+
* Create a new empty path
|
|
339
|
+
*/
|
|
340
|
+
static create(): Path;
|
|
341
|
+
/**
|
|
342
|
+
* Keep (increment ref count)
|
|
343
|
+
*/
|
|
344
|
+
keep(): this;
|
|
345
|
+
/**
|
|
346
|
+
* Drop (decrement ref count)
|
|
347
|
+
*/
|
|
348
|
+
drop(): void;
|
|
349
|
+
/**
|
|
350
|
+
* Clone this path
|
|
351
|
+
*/
|
|
352
|
+
clone(): Path;
|
|
353
|
+
/**
|
|
354
|
+
* Get the current point
|
|
355
|
+
*/
|
|
356
|
+
get currentPoint(): Point;
|
|
357
|
+
/**
|
|
358
|
+
* Check if the path is empty
|
|
359
|
+
*/
|
|
360
|
+
isEmpty(): boolean;
|
|
361
|
+
/**
|
|
362
|
+
* Move to a point (start a new subpath)
|
|
363
|
+
*/
|
|
364
|
+
moveTo(x: number, y: number): this;
|
|
365
|
+
moveTo(point: PointLike): this;
|
|
366
|
+
/**
|
|
367
|
+
* Draw a line to a point
|
|
368
|
+
*/
|
|
369
|
+
lineTo(x: number, y: number): this;
|
|
370
|
+
lineTo(point: PointLike): this;
|
|
371
|
+
/**
|
|
372
|
+
* Draw a cubic Bézier curve
|
|
373
|
+
*/
|
|
374
|
+
curveTo(cx1: number, cy1: number, cx2: number, cy2: number, x: number, y: number): this;
|
|
375
|
+
/**
|
|
376
|
+
* Draw a quadratic Bézier curve
|
|
377
|
+
*/
|
|
378
|
+
quadTo(cx: number, cy: number, x: number, y: number): this;
|
|
379
|
+
/**
|
|
380
|
+
* Close the current subpath
|
|
381
|
+
*/
|
|
382
|
+
closePath(): this;
|
|
383
|
+
/**
|
|
384
|
+
* Close the current subpath (alias for closePath)
|
|
385
|
+
*/
|
|
386
|
+
close(): this;
|
|
387
|
+
/**
|
|
388
|
+
* Add a rectangle to the path
|
|
389
|
+
*/
|
|
390
|
+
rectTo(x: number, y: number, w: number, h: number): this;
|
|
391
|
+
/**
|
|
392
|
+
* Add a rectangle from corners
|
|
393
|
+
*/
|
|
394
|
+
rect(x1: number, y1: number, x2: number, y2: number): this;
|
|
395
|
+
/**
|
|
396
|
+
* Get the bounding box of the path
|
|
397
|
+
*/
|
|
398
|
+
getBounds(): Rect;
|
|
399
|
+
/**
|
|
400
|
+
* Transform the path by a matrix
|
|
401
|
+
*/
|
|
402
|
+
transform(matrix: MatrixLike): this;
|
|
403
|
+
/**
|
|
404
|
+
* Walk the path commands
|
|
405
|
+
*/
|
|
406
|
+
walk(walker: PathWalker): void;
|
|
407
|
+
/**
|
|
408
|
+
* Check if path is valid
|
|
409
|
+
*/
|
|
410
|
+
isValid(): boolean;
|
|
411
|
+
/**
|
|
412
|
+
* Get the number of commands in the path
|
|
413
|
+
*/
|
|
414
|
+
get length(): number;
|
|
415
|
+
/**
|
|
416
|
+
* Clear all commands from the path
|
|
417
|
+
*/
|
|
418
|
+
clear(): this;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