@gtkx/cairo 2.0.0-beta.11 → 2.0.0-beta.13
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/README.md +3 -3
- package/dist/context.d.ts +27 -6
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +38 -10
- package/dist/context.js.map +1 -1
- package/dist/device.d.ts.map +1 -1
- package/dist/enums.d.ts.map +1 -1
- package/dist/font-face.d.ts +4 -2
- package/dist/font-face.d.ts.map +1 -1
- package/dist/font-face.js +9 -4
- package/dist/font-face.js.map +1 -1
- package/dist/font-options.d.ts.map +1 -1
- package/dist/font-options.js.map +1 -1
- package/dist/lib.d.ts +2 -1
- package/dist/lib.d.ts.map +1 -1
- package/dist/lib.js +10 -37
- package/dist/lib.js.map +1 -1
- package/dist/matrix.d.ts.map +1 -1
- package/dist/path.d.ts +4 -3
- package/dist/path.d.ts.map +1 -1
- package/dist/path.js +8 -4
- package/dist/path.js.map +1 -1
- package/dist/pattern.d.ts +13 -7
- package/dist/pattern.d.ts.map +1 -1
- package/dist/pattern.js +31 -15
- package/dist/pattern.js.map +1 -1
- package/dist/region.d.ts.map +1 -1
- package/dist/scaled-font.d.ts.map +1 -1
- package/dist/scaled-font.js.map +1 -1
- package/dist/status.d.ts.map +1 -1
- package/dist/structs.d.ts.map +1 -1
- package/dist/structs.js +32 -36
- package/dist/structs.js.map +1 -1
- package/dist/surface.d.ts.map +1 -1
- package/dist/surface.js +14 -10
- package/dist/surface.js.map +1 -1
- package/dist/text.d.ts.map +1 -1
- package/dist/version.d.ts.map +1 -1
- package/package.json +4 -14
- package/src/context.ts +44 -12
- package/src/font-face.ts +11 -9
- package/src/font-options.ts +1 -5
- package/src/lib.ts +11 -36
- package/src/path.ts +10 -4
- package/src/pattern.ts +35 -22
- package/src/scaled-font.ts +1 -5
- package/src/structs.ts +32 -48
- package/src/surface.ts +24 -17
package/src/structs.ts
CHANGED
|
@@ -3,17 +3,13 @@ import {
|
|
|
3
3
|
type ExternalObject,
|
|
4
4
|
getHandle,
|
|
5
5
|
type Handle,
|
|
6
|
-
read,
|
|
7
6
|
registerWrapperClass,
|
|
8
7
|
resolveType,
|
|
9
8
|
setHandle,
|
|
9
|
+
type StridedField,
|
|
10
10
|
t,
|
|
11
|
-
toNative,
|
|
12
|
-
write,
|
|
13
11
|
} from "@gtkx/runtime";
|
|
14
12
|
|
|
15
|
-
type FieldDescriptor = typeof t.float64 | typeof t.int32 | typeof t.biguint64;
|
|
16
|
-
|
|
17
13
|
/** Initial field values for a `Rectangle`; a field left out or set to null keeps zero. */
|
|
18
14
|
type RectangleConstructorProps = {
|
|
19
15
|
/** Horizontal position of the left edge. */
|
|
@@ -65,25 +61,13 @@ const RECTANGLE_SIZE = 32;
|
|
|
65
61
|
const RECTANGLE_INT_SIZE = 16;
|
|
66
62
|
const GLYPH_SIZE = 24;
|
|
67
63
|
const TEXT_CLUSTER_SIZE = 8;
|
|
68
|
-
const DOUBLE = t.float64;
|
|
69
|
-
const INT = t.int32;
|
|
70
|
-
const ULONG = t.biguint64;
|
|
71
|
-
|
|
72
|
-
const readField = (instance: object, descriptor: FieldDescriptor, offset: number): number =>
|
|
73
|
-
read(getHandle(instance), descriptor, offset) as number;
|
|
74
|
-
|
|
75
|
-
const writeField = (instance: object, descriptor: FieldDescriptor, offset: number, value: unknown): void => {
|
|
76
|
-
write(getHandle(instance), descriptor, offset, toNative(descriptor, value));
|
|
77
|
-
};
|
|
64
|
+
const DOUBLE = t.fieldAt(t.float64);
|
|
65
|
+
const INT = t.fieldAt(t.int32);
|
|
66
|
+
const ULONG = t.fieldAt(t.biguint64);
|
|
78
67
|
|
|
79
|
-
const writeInitial = (
|
|
80
|
-
handle: ExternalObject<Handle>,
|
|
81
|
-
descriptor: FieldDescriptor,
|
|
82
|
-
offset: number,
|
|
83
|
-
value: unknown,
|
|
84
|
-
): void => {
|
|
68
|
+
const writeInitial = (handle: ExternalObject<Handle>, field: StridedField, offset: number, value: unknown): void => {
|
|
85
69
|
if (value != null) {
|
|
86
|
-
write(handle,
|
|
70
|
+
field.write(handle, offset, value);
|
|
87
71
|
}
|
|
88
72
|
};
|
|
89
73
|
|
|
@@ -108,42 +92,42 @@ class Rectangle {
|
|
|
108
92
|
|
|
109
93
|
/** Horizontal position of the left edge. */
|
|
110
94
|
get x(): number {
|
|
111
|
-
return
|
|
95
|
+
return DOUBLE.read(getHandle(this), 0) as number;
|
|
112
96
|
}
|
|
113
97
|
|
|
114
98
|
/** Horizontal position of the left edge. */
|
|
115
99
|
set x(value: number) {
|
|
116
|
-
|
|
100
|
+
DOUBLE.write(getHandle(this), 0, value);
|
|
117
101
|
}
|
|
118
102
|
|
|
119
103
|
/** Vertical position of the top edge. */
|
|
120
104
|
get y(): number {
|
|
121
|
-
return
|
|
105
|
+
return DOUBLE.read(getHandle(this), 8) as number;
|
|
122
106
|
}
|
|
123
107
|
|
|
124
108
|
/** Vertical position of the top edge. */
|
|
125
109
|
set y(value: number) {
|
|
126
|
-
|
|
110
|
+
DOUBLE.write(getHandle(this), 8, value);
|
|
127
111
|
}
|
|
128
112
|
|
|
129
113
|
/** Width of the rectangle. */
|
|
130
114
|
get width(): number {
|
|
131
|
-
return
|
|
115
|
+
return DOUBLE.read(getHandle(this), 16) as number;
|
|
132
116
|
}
|
|
133
117
|
|
|
134
118
|
/** Width of the rectangle. */
|
|
135
119
|
set width(value: number) {
|
|
136
|
-
|
|
120
|
+
DOUBLE.write(getHandle(this), 16, value);
|
|
137
121
|
}
|
|
138
122
|
|
|
139
123
|
/** Height of the rectangle. */
|
|
140
124
|
get height(): number {
|
|
141
|
-
return
|
|
125
|
+
return DOUBLE.read(getHandle(this), 24) as number;
|
|
142
126
|
}
|
|
143
127
|
|
|
144
128
|
/** Height of the rectangle. */
|
|
145
129
|
set height(value: number) {
|
|
146
|
-
|
|
130
|
+
DOUBLE.write(getHandle(this), 24, value);
|
|
147
131
|
}
|
|
148
132
|
}
|
|
149
133
|
|
|
@@ -168,42 +152,42 @@ class RectangleInt {
|
|
|
168
152
|
|
|
169
153
|
/** Horizontal position of the left edge. */
|
|
170
154
|
get x(): number {
|
|
171
|
-
return
|
|
155
|
+
return INT.read(getHandle(this), 0) as number;
|
|
172
156
|
}
|
|
173
157
|
|
|
174
158
|
/** Horizontal position of the left edge. */
|
|
175
159
|
set x(value: number) {
|
|
176
|
-
|
|
160
|
+
INT.write(getHandle(this), 0, value);
|
|
177
161
|
}
|
|
178
162
|
|
|
179
163
|
/** Vertical position of the top edge. */
|
|
180
164
|
get y(): number {
|
|
181
|
-
return
|
|
165
|
+
return INT.read(getHandle(this), 4) as number;
|
|
182
166
|
}
|
|
183
167
|
|
|
184
168
|
/** Vertical position of the top edge. */
|
|
185
169
|
set y(value: number) {
|
|
186
|
-
|
|
170
|
+
INT.write(getHandle(this), 4, value);
|
|
187
171
|
}
|
|
188
172
|
|
|
189
173
|
/** Width of the rectangle. */
|
|
190
174
|
get width(): number {
|
|
191
|
-
return
|
|
175
|
+
return INT.read(getHandle(this), 8) as number;
|
|
192
176
|
}
|
|
193
177
|
|
|
194
178
|
/** Width of the rectangle. */
|
|
195
179
|
set width(value: number) {
|
|
196
|
-
|
|
180
|
+
INT.write(getHandle(this), 8, value);
|
|
197
181
|
}
|
|
198
182
|
|
|
199
183
|
/** Height of the rectangle. */
|
|
200
184
|
get height(): number {
|
|
201
|
-
return
|
|
185
|
+
return INT.read(getHandle(this), 12) as number;
|
|
202
186
|
}
|
|
203
187
|
|
|
204
188
|
/** Height of the rectangle. */
|
|
205
189
|
set height(value: number) {
|
|
206
|
-
|
|
190
|
+
INT.write(getHandle(this), 12, value);
|
|
207
191
|
}
|
|
208
192
|
}
|
|
209
193
|
|
|
@@ -227,32 +211,32 @@ class Glyph {
|
|
|
227
211
|
|
|
228
212
|
/** Index of the glyph in the font. */
|
|
229
213
|
get index(): bigint {
|
|
230
|
-
return read(getHandle(this),
|
|
214
|
+
return ULONG.read(getHandle(this), 0) as bigint;
|
|
231
215
|
}
|
|
232
216
|
|
|
233
217
|
/** Index of the glyph in the font. */
|
|
234
218
|
set index(value: bigint) {
|
|
235
|
-
|
|
219
|
+
ULONG.write(getHandle(this), 0, value);
|
|
236
220
|
}
|
|
237
221
|
|
|
238
222
|
/** Horizontal position of the glyph origin. */
|
|
239
223
|
get x(): number {
|
|
240
|
-
return
|
|
224
|
+
return DOUBLE.read(getHandle(this), 8) as number;
|
|
241
225
|
}
|
|
242
226
|
|
|
243
227
|
/** Horizontal position of the glyph origin. */
|
|
244
228
|
set x(value: number) {
|
|
245
|
-
|
|
229
|
+
DOUBLE.write(getHandle(this), 8, value);
|
|
246
230
|
}
|
|
247
231
|
|
|
248
232
|
/** Vertical position of the glyph origin. */
|
|
249
233
|
get y(): number {
|
|
250
|
-
return
|
|
234
|
+
return DOUBLE.read(getHandle(this), 16) as number;
|
|
251
235
|
}
|
|
252
236
|
|
|
253
237
|
/** Vertical position of the glyph origin. */
|
|
254
238
|
set y(value: number) {
|
|
255
|
-
|
|
239
|
+
DOUBLE.write(getHandle(this), 16, value);
|
|
256
240
|
}
|
|
257
241
|
}
|
|
258
242
|
|
|
@@ -275,22 +259,22 @@ class TextCluster {
|
|
|
275
259
|
|
|
276
260
|
/** Number of UTF-8 bytes the cluster covers. */
|
|
277
261
|
get numBytes(): number {
|
|
278
|
-
return
|
|
262
|
+
return INT.read(getHandle(this), 0) as number;
|
|
279
263
|
}
|
|
280
264
|
|
|
281
265
|
/** Number of UTF-8 bytes the cluster covers. */
|
|
282
266
|
set numBytes(value: number) {
|
|
283
|
-
|
|
267
|
+
INT.write(getHandle(this), 0, value);
|
|
284
268
|
}
|
|
285
269
|
|
|
286
270
|
/** Number of glyphs the cluster covers. */
|
|
287
271
|
get numGlyphs(): number {
|
|
288
|
-
return
|
|
272
|
+
return INT.read(getHandle(this), 4) as number;
|
|
289
273
|
}
|
|
290
274
|
|
|
291
275
|
/** Number of glyphs the cluster covers. */
|
|
292
276
|
set numGlyphs(value: number) {
|
|
293
|
-
|
|
277
|
+
INT.write(getHandle(this), 4, value);
|
|
294
278
|
}
|
|
295
279
|
}
|
|
296
280
|
|
package/src/surface.ts
CHANGED
|
@@ -11,8 +11,8 @@ import {
|
|
|
11
11
|
type WrapperClassResolver,
|
|
12
12
|
write,
|
|
13
13
|
} from "@gtkx/runtime";
|
|
14
|
+
import { reportExternalMemory } from "@gtkx/runtime/internal";
|
|
14
15
|
import type { DeviceOffset, DeviceScale, FallbackResolution, InkExtents, RectangleData } from "./types.js";
|
|
15
|
-
import { Context } from "./context.js";
|
|
16
16
|
import { Device } from "./device.js";
|
|
17
17
|
import { type Content, type Format, type Status, SurfaceType } from "./enums.js";
|
|
18
18
|
import { FontOptions } from "./font-options.js";
|
|
@@ -110,6 +110,17 @@ const cairoRecordingSurfaceGetExtents = bindCairo(
|
|
|
110
110
|
|
|
111
111
|
const wrapSurface = (handle: unknown): Surface => wrapHandle(handle as ExternalObject<Handle>, Surface);
|
|
112
112
|
|
|
113
|
+
const ownSurface = (handle: ExternalObject<Handle>): ExternalObject<Handle> => {
|
|
114
|
+
const surface = checkSurface(handle);
|
|
115
|
+
|
|
116
|
+
if (cairoSurfaceGetType(surface) === SurfaceType.IMAGE) {
|
|
117
|
+
const bytes = (cairoImageSurfaceGetStride(surface) as number) * (cairoImageSurfaceGetHeight(surface) as number);
|
|
118
|
+
reportExternalMemory(surface, bytes);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return surface;
|
|
122
|
+
};
|
|
123
|
+
|
|
113
124
|
const readPair = <T>(boundFn: BoundFunction, self: object, build: (first: number, second: number) => T): T => {
|
|
114
125
|
const first = { value: 0 };
|
|
115
126
|
const second = { value: 0 };
|
|
@@ -170,21 +181,24 @@ abstract class Surface {
|
|
|
170
181
|
static createSimilar(other: Surface, content: Content, width: number, height: number): Surface {
|
|
171
182
|
const handle = cairoSurfaceCreateSimilar(getHandle(other), content, width, height) as ExternalObject<Handle>;
|
|
172
183
|
|
|
173
|
-
return wrapSurface(
|
|
184
|
+
return wrapSurface(ownSurface(handle));
|
|
174
185
|
}
|
|
175
186
|
|
|
176
187
|
/** Creates an image surface of the given `format` and size as compatible as possible with `other`. */
|
|
177
188
|
static createSimilarImage(other: Surface, format: Format, width: number, height: number): ImageSurface {
|
|
178
|
-
const handle =
|
|
179
|
-
|
|
189
|
+
const handle = cairoSurfaceCreateSimilarImage(
|
|
190
|
+
getHandle(other),
|
|
191
|
+
format,
|
|
192
|
+
width,
|
|
193
|
+
height,
|
|
194
|
+
) as ExternalObject<Handle>;
|
|
180
195
|
|
|
181
|
-
return wrapHandle(
|
|
196
|
+
return wrapHandle(ownSurface(handle), ImageSurface);
|
|
182
197
|
}
|
|
183
198
|
|
|
184
199
|
/** Creates a surface that draws onto the given rectangle of `target`. */
|
|
185
200
|
static createForRectangle(target: Surface, x: number, y: number, width: number, height: number): Surface {
|
|
186
|
-
const handle =
|
|
187
|
-
cairoSurfaceCreateForRectangle(getHandle(target), x, y, width, height) as ExternalObject<Handle>;
|
|
201
|
+
const handle = cairoSurfaceCreateForRectangle(getHandle(target), x, y, width, height) as ExternalObject<Handle>;
|
|
188
202
|
|
|
189
203
|
return wrapSurface(checkSurface(handle));
|
|
190
204
|
}
|
|
@@ -310,21 +324,18 @@ abstract class Surface {
|
|
|
310
324
|
class ImageSurface extends Surface {
|
|
311
325
|
/** Creates an image surface of the given pixel `format` and size, the same as `new ImageSurface(...)`. */
|
|
312
326
|
static create(format: Format, width: number, height: number): ImageSurface {
|
|
313
|
-
return wrapHandle(
|
|
314
|
-
checkSurface(cairoImageSurfaceCreate(format, width, height) as ExternalObject<Handle>),
|
|
315
|
-
this,
|
|
316
|
-
);
|
|
327
|
+
return wrapHandle(ownSurface(cairoImageSurfaceCreate(format, width, height) as ExternalObject<Handle>), this);
|
|
317
328
|
}
|
|
318
329
|
|
|
319
330
|
/** Loads a PNG file into a new image surface; throws when the file is missing or invalid. */
|
|
320
331
|
static createFromPng(filename: string): ImageSurface {
|
|
321
|
-
return wrapHandle(
|
|
332
|
+
return wrapHandle(ownSurface(cairoImageSurfaceCreateFromPng(filename) as ExternalObject<Handle>), this);
|
|
322
333
|
}
|
|
323
334
|
|
|
324
335
|
/** Creates an image surface of the given pixel `format` and size. */
|
|
325
336
|
constructor(format: Format, width: number, height: number) {
|
|
326
337
|
super();
|
|
327
|
-
setHandle(this,
|
|
338
|
+
setHandle(this, ownSurface(cairoImageSurfaceCreate(format, width, height) as ExternalObject<Handle>));
|
|
328
339
|
}
|
|
329
340
|
|
|
330
341
|
/** Returns the width of the surface in pixels. */
|
|
@@ -349,10 +360,6 @@ class ImageSurface extends Surface {
|
|
|
349
360
|
|
|
350
361
|
/** Returns a copy of the pixel data, `getStride() * getHeight()` bytes in the surface's format. */
|
|
351
362
|
getData(): Uint8Array {
|
|
352
|
-
/* TODO: Keep this finished-state check until Cairo stops exposing released image storage.
|
|
353
|
-
* https://github.com/gtkx-org/gtkx/issues/730
|
|
354
|
-
*/
|
|
355
|
-
Context.create(this);
|
|
356
363
|
this.flush();
|
|
357
364
|
const totalBytes = this.getStride() * this.getHeight();
|
|
358
365
|
|