@gtkx/cairo 2.0.0-beta.10 → 2.0.0-beta.12
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 +8 -168
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +8 -7
- package/dist/context.js.map +1 -1
- package/dist/device.d.ts.map +1 -1
- package/dist/enums.d.ts +10 -1
- package/dist/enums.d.ts.map +1 -1
- package/dist/enums.js +9 -0
- package/dist/enums.js.map +1 -1
- package/dist/font-face.d.ts +1 -1
- package/dist/font-face.d.ts.map +1 -1
- package/dist/font-face.js +1 -1
- package/dist/font-face.js.map +1 -1
- package/dist/font-options.d.ts +2 -2
- package/dist/font-options.d.ts.map +1 -1
- package/dist/font-options.js +1 -1
- package/dist/font-options.js.map +1 -1
- package/dist/lib.d.ts.map +1 -1
- package/dist/lib.js +7 -35
- package/dist/lib.js.map +1 -1
- package/dist/matrix.d.ts.map +1 -1
- package/dist/path.d.ts.map +1 -1
- package/dist/path.js +9 -22
- package/dist/path.js.map +1 -1
- package/dist/pattern.d.ts.map +1 -1
- package/dist/pattern.js +5 -5
- 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 +3 -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 +3 -3
- package/dist/surface.d.ts.map +1 -1
- package/dist/surface.js +18 -16
- 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 +6 -17
- package/src/context.ts +8 -7
- package/src/enums.ts +10 -1
- package/src/font-face.ts +3 -7
- package/src/font-options.ts +5 -9
- package/src/lib.ts +7 -35
- package/src/path.ts +11 -27
- package/src/pattern.ts +7 -12
- package/src/scaled-font.ts +4 -6
- package/src/structs.ts +32 -48
- package/src/surface.ts +29 -33
package/src/lib.ts
CHANGED
|
@@ -13,11 +13,7 @@ const CONTEXT_T: BoxedDescriptor = t.boxed("CairoContext", {
|
|
|
13
13
|
getTypeFnName: "cairo_gobject_context_get_type",
|
|
14
14
|
});
|
|
15
15
|
|
|
16
|
-
const CONTEXT_FULL_T: BoxedDescriptor =
|
|
17
|
-
ownership: "full",
|
|
18
|
-
sharedLibrary: CAIRO_GOBJECT_LIBRARY,
|
|
19
|
-
getTypeFnName: "cairo_gobject_context_get_type",
|
|
20
|
-
});
|
|
16
|
+
const CONTEXT_FULL_T: BoxedDescriptor = { ...CONTEXT_T, ownership: "full" };
|
|
21
17
|
|
|
22
18
|
const SURFACE_T: BoxedDescriptor = t.boxed("CairoSurface", {
|
|
23
19
|
ownership: "borrowed",
|
|
@@ -25,11 +21,7 @@ const SURFACE_T: BoxedDescriptor = t.boxed("CairoSurface", {
|
|
|
25
21
|
getTypeFnName: "cairo_gobject_surface_get_type",
|
|
26
22
|
});
|
|
27
23
|
|
|
28
|
-
const SURFACE_FULL_T: BoxedDescriptor =
|
|
29
|
-
ownership: "full",
|
|
30
|
-
sharedLibrary: CAIRO_GOBJECT_LIBRARY,
|
|
31
|
-
getTypeFnName: "cairo_gobject_surface_get_type",
|
|
32
|
-
});
|
|
24
|
+
const SURFACE_FULL_T: BoxedDescriptor = { ...SURFACE_T, ownership: "full" };
|
|
33
25
|
|
|
34
26
|
const DEVICE_T: BoxedDescriptor = t.boxed("CairoDevice", {
|
|
35
27
|
ownership: "borrowed",
|
|
@@ -43,11 +35,7 @@ const PATTERN_T: BoxedDescriptor = t.boxed("CairoPattern", {
|
|
|
43
35
|
getTypeFnName: "cairo_gobject_pattern_get_type",
|
|
44
36
|
});
|
|
45
37
|
|
|
46
|
-
const PATTERN_FULL_T: BoxedDescriptor =
|
|
47
|
-
ownership: "full",
|
|
48
|
-
sharedLibrary: CAIRO_GOBJECT_LIBRARY,
|
|
49
|
-
getTypeFnName: "cairo_gobject_pattern_get_type",
|
|
50
|
-
});
|
|
38
|
+
const PATTERN_FULL_T: BoxedDescriptor = { ...PATTERN_T, ownership: "full" };
|
|
51
39
|
|
|
52
40
|
const REGION_T: BoxedDescriptor = t.boxed("CairoRegion", {
|
|
53
41
|
ownership: "borrowed",
|
|
@@ -55,11 +43,7 @@ const REGION_T: BoxedDescriptor = t.boxed("CairoRegion", {
|
|
|
55
43
|
getTypeFnName: "cairo_gobject_region_get_type",
|
|
56
44
|
});
|
|
57
45
|
|
|
58
|
-
const REGION_FULL_T: BoxedDescriptor =
|
|
59
|
-
ownership: "full",
|
|
60
|
-
sharedLibrary: CAIRO_GOBJECT_LIBRARY,
|
|
61
|
-
getTypeFnName: "cairo_gobject_region_get_type",
|
|
62
|
-
});
|
|
46
|
+
const REGION_FULL_T: BoxedDescriptor = { ...REGION_T, ownership: "full" };
|
|
63
47
|
|
|
64
48
|
const FONT_OPTIONS_T: BoxedDescriptor = t.boxed("CairoFontOptions", {
|
|
65
49
|
ownership: "borrowed",
|
|
@@ -67,11 +51,7 @@ const FONT_OPTIONS_T: BoxedDescriptor = t.boxed("CairoFontOptions", {
|
|
|
67
51
|
getTypeFnName: "cairo_gobject_font_options_get_type",
|
|
68
52
|
});
|
|
69
53
|
|
|
70
|
-
const FONT_OPTIONS_FULL_T: BoxedDescriptor =
|
|
71
|
-
ownership: "full",
|
|
72
|
-
sharedLibrary: CAIRO_GOBJECT_LIBRARY,
|
|
73
|
-
getTypeFnName: "cairo_gobject_font_options_get_type",
|
|
74
|
-
});
|
|
54
|
+
const FONT_OPTIONS_FULL_T: BoxedDescriptor = { ...FONT_OPTIONS_T, ownership: "full" };
|
|
75
55
|
|
|
76
56
|
const FONT_FACE_T: BoxedDescriptor = t.boxed("CairoFontFace", {
|
|
77
57
|
ownership: "borrowed",
|
|
@@ -79,11 +59,7 @@ const FONT_FACE_T: BoxedDescriptor = t.boxed("CairoFontFace", {
|
|
|
79
59
|
getTypeFnName: "cairo_gobject_font_face_get_type",
|
|
80
60
|
});
|
|
81
61
|
|
|
82
|
-
const FONT_FACE_FULL_T: BoxedDescriptor =
|
|
83
|
-
ownership: "full",
|
|
84
|
-
sharedLibrary: CAIRO_GOBJECT_LIBRARY,
|
|
85
|
-
getTypeFnName: "cairo_gobject_font_face_get_type",
|
|
86
|
-
});
|
|
62
|
+
const FONT_FACE_FULL_T: BoxedDescriptor = { ...FONT_FACE_T, ownership: "full" };
|
|
87
63
|
|
|
88
64
|
const SCALED_FONT_T: BoxedDescriptor = t.boxed("CairoScaledFont", {
|
|
89
65
|
ownership: "borrowed",
|
|
@@ -91,11 +67,7 @@ const SCALED_FONT_T: BoxedDescriptor = t.boxed("CairoScaledFont", {
|
|
|
91
67
|
getTypeFnName: "cairo_gobject_scaled_font_get_type",
|
|
92
68
|
});
|
|
93
69
|
|
|
94
|
-
const SCALED_FONT_FULL_T: BoxedDescriptor =
|
|
95
|
-
ownership: "full",
|
|
96
|
-
sharedLibrary: CAIRO_GOBJECT_LIBRARY,
|
|
97
|
-
getTypeFnName: "cairo_gobject_scaled_font_get_type",
|
|
98
|
-
});
|
|
70
|
+
const SCALED_FONT_FULL_T: BoxedDescriptor = { ...SCALED_FONT_T, ownership: "full" };
|
|
99
71
|
|
|
100
72
|
const MATRIX_T: BoxedDescriptor = t.boxed("cairo_matrix_t", { ownership: "borrowed", sharedLibrary: CAIRO_LIBRARY });
|
|
101
73
|
|
package/src/path.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { type ExternalObject, getHandle, type Handle, read, t } from "@gtkx/runtime";
|
|
2
|
-
import type { PathData } from "./types.js";
|
|
3
|
-
import { PathDataType } from "./enums.js";
|
|
2
|
+
import type { PathData, Point } from "./types.js";
|
|
3
|
+
import { PathDataType, type Status } from "./enums.js";
|
|
4
|
+
import { checkStatus } from "./status.js";
|
|
4
5
|
|
|
5
6
|
type PathBuffer = ExternalObject<Handle>;
|
|
6
|
-
type Point = { x: number; y: number };
|
|
7
7
|
type SegmentReader = (data: PathBuffer, base: number) => PathData;
|
|
8
8
|
|
|
9
9
|
const ELEMENT_SIZE = 16;
|
|
@@ -31,27 +31,15 @@ const readCurveTo: SegmentReader = (data, base) => {
|
|
|
31
31
|
|
|
32
32
|
const readClosePath: SegmentReader = () => ({ type: "closePath" });
|
|
33
33
|
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
case PathDataType.LINE_TO: {
|
|
40
|
-
return readLineTo;
|
|
41
|
-
}
|
|
42
|
-
case PathDataType.CURVE_TO: {
|
|
43
|
-
return readCurveTo;
|
|
44
|
-
}
|
|
45
|
-
case PathDataType.CLOSE_PATH: {
|
|
46
|
-
return readClosePath;
|
|
47
|
-
}
|
|
48
|
-
default: {
|
|
49
|
-
return null;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
34
|
+
const segmentReaders: Record<PathDataType, SegmentReader> = {
|
|
35
|
+
[PathDataType.MOVE_TO]: readMoveTo,
|
|
36
|
+
[PathDataType.LINE_TO]: readLineTo,
|
|
37
|
+
[PathDataType.CURVE_TO]: readCurveTo,
|
|
38
|
+
[PathDataType.CLOSE_PATH]: readClosePath,
|
|
52
39
|
};
|
|
53
40
|
|
|
54
41
|
const parsePath = (pathHandle: PathBuffer): PathData[] => {
|
|
42
|
+
checkStatus(INT.read(pathHandle, 0) as Status, "path");
|
|
55
43
|
const numData = NUM_DATA.read(pathHandle) as number;
|
|
56
44
|
|
|
57
45
|
if (numData === 0) {
|
|
@@ -64,12 +52,8 @@ const parsePath = (pathHandle: PathBuffer): PathData[] => {
|
|
|
64
52
|
|
|
65
53
|
while (index < numData) {
|
|
66
54
|
const base = index * ELEMENT_SIZE;
|
|
67
|
-
const reader =
|
|
68
|
-
|
|
69
|
-
if (reader !== null) {
|
|
70
|
-
segments.push(reader(data, base));
|
|
71
|
-
}
|
|
72
|
-
|
|
55
|
+
const reader = segmentReaders[INT.read(data, base) as PathDataType];
|
|
56
|
+
segments.push(reader(data, base));
|
|
73
57
|
index += INT.read(data, base + 4) as number;
|
|
74
58
|
}
|
|
75
59
|
|
package/src/pattern.ts
CHANGED
|
@@ -25,12 +25,7 @@ import { parsePath } from "./path.js";
|
|
|
25
25
|
import { checkStatus } from "./status.js";
|
|
26
26
|
import { Surface } from "./surface.js";
|
|
27
27
|
|
|
28
|
-
type RgbaRefs = [
|
|
29
|
-
red: { value: number },
|
|
30
|
-
green: { value: number },
|
|
31
|
-
blue: { value: number },
|
|
32
|
-
alpha: { value: number },
|
|
33
|
-
];
|
|
28
|
+
type RgbaRefs = [red: { value: number }, green: { value: number }, blue: { value: number }, alpha: { value: number }];
|
|
34
29
|
|
|
35
30
|
const PATTERN_TYPE = cairoGType("cairo_gobject_pattern_get_type");
|
|
36
31
|
const FOUR_DOUBLES_OUT = [t.ref(t.float64), t.ref(t.float64), t.ref(t.float64), t.ref(t.float64)];
|
|
@@ -163,19 +158,19 @@ const checkPattern = <T extends Pattern>(pattern: T): T => {
|
|
|
163
158
|
return pattern;
|
|
164
159
|
};
|
|
165
160
|
|
|
166
|
-
const readRgba = (fill: (...refs: RgbaRefs) =>
|
|
161
|
+
const readRgba = (fill: (...refs: RgbaRefs) => unknown): RgbaColor => {
|
|
167
162
|
const red = { value: 0 };
|
|
168
163
|
const green = { value: 0 };
|
|
169
164
|
const blue = { value: 0 };
|
|
170
165
|
const alpha = { value: 0 };
|
|
171
|
-
fill(red, green, blue, alpha);
|
|
166
|
+
checkStatus(fill(red, green, blue, alpha) as Status, "pattern");
|
|
172
167
|
|
|
173
168
|
return { red: red.value, green: green.value, blue: blue.value, alpha: alpha.value };
|
|
174
169
|
};
|
|
175
170
|
|
|
176
171
|
const readCount = (boundFn: BoundFunction, self: object): number => {
|
|
177
172
|
const count = { value: 0 };
|
|
178
|
-
boundFn(getHandle(self), count);
|
|
173
|
+
checkStatus(boundFn(getHandle(self), count) as Status, "pattern");
|
|
179
174
|
|
|
180
175
|
return count.value;
|
|
181
176
|
};
|
|
@@ -352,7 +347,7 @@ class LinearPattern extends Pattern {
|
|
|
352
347
|
const y0 = { value: 0 };
|
|
353
348
|
const x1 = { value: 0 };
|
|
354
349
|
const y1 = { value: 0 };
|
|
355
|
-
cairoPatternGetLinearPoints(getHandle(this), x0, y0, x1, y1);
|
|
350
|
+
checkStatus(cairoPatternGetLinearPoints(getHandle(this), x0, y0, x1, y1) as Status, "pattern");
|
|
356
351
|
|
|
357
352
|
return { x0: x0.value, y0: y0.value, x1: x1.value, y1: y1.value };
|
|
358
353
|
}
|
|
@@ -368,7 +363,7 @@ class RadialPattern extends Pattern {
|
|
|
368
363
|
const x1 = { value: 0 };
|
|
369
364
|
const y1 = { value: 0 };
|
|
370
365
|
const r1 = { value: 0 };
|
|
371
|
-
cairoPatternGetRadialCircles(getHandle(this), x0, y0, r0, x1, y1, r1);
|
|
366
|
+
checkStatus(cairoPatternGetRadialCircles(getHandle(this), x0, y0, r0, x1, y1, r1) as Status, "pattern");
|
|
372
367
|
|
|
373
368
|
return { x0: x0.value, y0: y0.value, r0: r0.value, x1: x1.value, y1: y1.value, r1: r1.value };
|
|
374
369
|
}
|
|
@@ -433,7 +428,7 @@ class MeshPattern extends Pattern {
|
|
|
433
428
|
getControlPoint(patchNum: number, pointNum: number): Point {
|
|
434
429
|
const x = { value: 0 };
|
|
435
430
|
const y = { value: 0 };
|
|
436
|
-
cairoMeshPatternGetControlPoint(getHandle(this), patchNum, pointNum, x, y);
|
|
431
|
+
checkStatus(cairoMeshPatternGetControlPoint(getHandle(this), patchNum, pointNum, x, y) as Status, "pattern");
|
|
437
432
|
|
|
438
433
|
return { x: x.value, y: y.value };
|
|
439
434
|
}
|
package/src/scaled-font.ts
CHANGED
|
@@ -25,6 +25,7 @@ import {
|
|
|
25
25
|
TEXT_EXTENTS_T,
|
|
26
26
|
} from "./lib.js";
|
|
27
27
|
import { allocMatrix, Matrix } from "./matrix.js";
|
|
28
|
+
import { checkStatus } from "./status.js";
|
|
28
29
|
import { allocFontExtents, allocGlyphBuffer, allocTextExtents, readFontExtents, readTextExtents } from "./text.js";
|
|
29
30
|
|
|
30
31
|
const SCALED_FONT_TYPE = cairoGType("cairo_gobject_scaled_font_get_type");
|
|
@@ -43,7 +44,7 @@ const cairoScaledFontCreate = bindCairo(
|
|
|
43
44
|
|
|
44
45
|
const cairoScaledFontTextExtents = bindCairo(
|
|
45
46
|
"cairo_scaled_font_text_extents",
|
|
46
|
-
[SCALED_FONT_T, t.string("
|
|
47
|
+
[SCALED_FONT_T, t.string("borrowed"), TEXT_EXTENTS_T],
|
|
47
48
|
t.void,
|
|
48
49
|
);
|
|
49
50
|
|
|
@@ -65,11 +66,7 @@ const cairoScaledFontGetScaleMatrix = bindCairo(
|
|
|
65
66
|
t.void,
|
|
66
67
|
);
|
|
67
68
|
|
|
68
|
-
const cairoScaledFontGetReferenceCount = bindCairo(
|
|
69
|
-
"cairo_scaled_font_get_reference_count",
|
|
70
|
-
[SCALED_FONT_T],
|
|
71
|
-
t.int32,
|
|
72
|
-
);
|
|
69
|
+
const cairoScaledFontGetReferenceCount = bindCairo("cairo_scaled_font_get_reference_count", [SCALED_FONT_T], t.int32);
|
|
73
70
|
|
|
74
71
|
const readMatrixVia = (self: ScaledFont, boundFn: BoundFunction): Matrix => {
|
|
75
72
|
const { handle, matrix } = allocMatrix();
|
|
@@ -104,6 +101,7 @@ class ScaledFont {
|
|
|
104
101
|
getHandle(options),
|
|
105
102
|
) as ExternalObject<Handle>;
|
|
106
103
|
|
|
104
|
+
checkStatus(cairoScaledFontStatus(handle) as Status, "scaled font");
|
|
107
105
|
setHandle(this, handle);
|
|
108
106
|
}
|
|
109
107
|
|
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
|
@@ -12,6 +12,8 @@ import {
|
|
|
12
12
|
write,
|
|
13
13
|
} from "@gtkx/runtime";
|
|
14
14
|
import type { DeviceOffset, DeviceScale, FallbackResolution, InkExtents, RectangleData } from "./types.js";
|
|
15
|
+
import { Context } from "./context.js";
|
|
16
|
+
import { Device } from "./device.js";
|
|
15
17
|
import { type Content, type Format, type Status, SurfaceType } from "./enums.js";
|
|
16
18
|
import { FontOptions } from "./font-options.js";
|
|
17
19
|
import {
|
|
@@ -29,7 +31,6 @@ import { checkSurface } from "./status.js";
|
|
|
29
31
|
const SURFACE_TYPE = cairoGType("cairo_gobject_surface_get_type");
|
|
30
32
|
const RECTANGLE_SIZE = 32;
|
|
31
33
|
const DOUBLE = t.fieldAt(t.float64);
|
|
32
|
-
const UINT8 = t.fieldAt(t.uint8);
|
|
33
34
|
const DEVICE_PAIR_ARGS = [SURFACE_T, t.float64, t.float64];
|
|
34
35
|
const DEVICE_PAIR_OUT_ARGS = [SURFACE_T, t.ref(t.float64), t.ref(t.float64)];
|
|
35
36
|
const SIMILAR_ARGS = [SURFACE_T, t.int32, t.int32, t.int32];
|
|
@@ -42,7 +43,7 @@ const cairoSurfaceCreateForRectangle = bindCairo(
|
|
|
42
43
|
SURFACE_FULL_T,
|
|
43
44
|
);
|
|
44
45
|
|
|
45
|
-
const cairoSurfaceWriteToPng = bindCairo("cairo_surface_write_to_png", [SURFACE_T, t.string("
|
|
46
|
+
const cairoSurfaceWriteToPng = bindCairo("cairo_surface_write_to_png", [SURFACE_T, t.string("borrowed")], t.int32);
|
|
46
47
|
const cairoSurfaceStatus = bindCairo("cairo_surface_status", [SURFACE_T], t.int32);
|
|
47
48
|
const cairoSurfaceFinish = bindCairo("cairo_surface_finish", [SURFACE_T], t.void);
|
|
48
49
|
const cairoSurfaceFlush = bindCairo("cairo_surface_flush", [SURFACE_T], t.void);
|
|
@@ -77,7 +78,7 @@ const cairoSurfaceHasShowTextGlyphs = bindCairo("cairo_surface_has_show_text_gly
|
|
|
77
78
|
|
|
78
79
|
const cairoSurfaceSupportsMimeType = bindCairo(
|
|
79
80
|
"cairo_surface_supports_mime_type",
|
|
80
|
-
[SURFACE_T, t.string("
|
|
81
|
+
[SURFACE_T, t.string("borrowed")],
|
|
81
82
|
t.boolean,
|
|
82
83
|
);
|
|
83
84
|
|
|
@@ -85,7 +86,7 @@ const cairoImageSurfaceCreate = bindCairo("cairo_image_surface_create", [t.int32
|
|
|
85
86
|
|
|
86
87
|
const cairoImageSurfaceCreateFromPng = bindCairo(
|
|
87
88
|
"cairo_image_surface_create_from_png",
|
|
88
|
-
[t.string("
|
|
89
|
+
[t.string("borrowed")],
|
|
89
90
|
SURFACE_FULL_T,
|
|
90
91
|
);
|
|
91
92
|
|
|
@@ -95,12 +96,6 @@ const cairoImageSurfaceGetFormat = bindCairo("cairo_image_surface_get_format", [
|
|
|
95
96
|
const cairoImageSurfaceGetStride = bindCairo("cairo_image_surface_get_stride", [SURFACE_T], t.int32);
|
|
96
97
|
const cairoRecordingSurfaceCreate = bindCairo("cairo_recording_surface_create", [t.int32, RECTANGLE_T], SURFACE_FULL_T);
|
|
97
98
|
|
|
98
|
-
const cairoRecordingSurfaceCreateUnbounded = bindCairo(
|
|
99
|
-
"cairo_recording_surface_create",
|
|
100
|
-
[t.int32, t.uint64],
|
|
101
|
-
SURFACE_FULL_T,
|
|
102
|
-
);
|
|
103
|
-
|
|
104
99
|
const cairoRecordingSurfaceInkExtents = bindCairo(
|
|
105
100
|
"cairo_recording_surface_ink_extents",
|
|
106
101
|
[SURFACE_T, t.ref(t.float64), t.ref(t.float64), t.ref(t.float64), t.ref(t.float64)],
|
|
@@ -140,10 +135,11 @@ const readRectangle = (buffer: ExternalObject<Handle>): RectangleData => ({
|
|
|
140
135
|
height: DOUBLE.read(buffer, 24) as number,
|
|
141
136
|
});
|
|
142
137
|
|
|
143
|
-
const createRecordingSurface = (content: Content, extents?: RectangleData): ExternalObject<Handle> =>
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
138
|
+
const createRecordingSurface = (content: Content, extents?: RectangleData): ExternalObject<Handle> => {
|
|
139
|
+
const rectangle = extents === undefined ? null : allocRectangle(extents);
|
|
140
|
+
|
|
141
|
+
return cairoRecordingSurfaceCreate(content, rectangle) as ExternalObject<Handle>;
|
|
142
|
+
};
|
|
147
143
|
|
|
148
144
|
const surfaceClassFor: WrapperClassResolver = (handle) => {
|
|
149
145
|
const type = cairoSurfaceGetType(handle) as SurfaceType;
|
|
@@ -179,16 +175,19 @@ abstract class Surface {
|
|
|
179
175
|
|
|
180
176
|
/** Creates an image surface of the given `format` and size as compatible as possible with `other`. */
|
|
181
177
|
static createSimilarImage(other: Surface, format: Format, width: number, height: number): ImageSurface {
|
|
182
|
-
const handle =
|
|
183
|
-
|
|
178
|
+
const handle = cairoSurfaceCreateSimilarImage(
|
|
179
|
+
getHandle(other),
|
|
180
|
+
format,
|
|
181
|
+
width,
|
|
182
|
+
height,
|
|
183
|
+
) as ExternalObject<Handle>;
|
|
184
184
|
|
|
185
185
|
return wrapHandle(checkSurface(handle), ImageSurface);
|
|
186
186
|
}
|
|
187
187
|
|
|
188
188
|
/** Creates a surface that draws onto the given rectangle of `target`. */
|
|
189
189
|
static createForRectangle(target: Surface, x: number, y: number, width: number, height: number): Surface {
|
|
190
|
-
const handle =
|
|
191
|
-
cairoSurfaceCreateForRectangle(getHandle(target), x, y, width, height) as ExternalObject<Handle>;
|
|
190
|
+
const handle = cairoSurfaceCreateForRectangle(getHandle(target), x, y, width, height) as ExternalObject<Handle>;
|
|
192
191
|
|
|
193
192
|
return wrapSurface(checkSurface(handle));
|
|
194
193
|
}
|
|
@@ -216,9 +215,11 @@ abstract class Surface {
|
|
|
216
215
|
cairoSurfaceFlush(getHandle(this));
|
|
217
216
|
}
|
|
218
217
|
|
|
219
|
-
/** Returns the
|
|
220
|
-
getDevice():
|
|
221
|
-
|
|
218
|
+
/** Returns the managed device behind the surface, or null when it has none. */
|
|
219
|
+
getDevice(): Device | null {
|
|
220
|
+
const handle = cairoSurfaceGetDevice(getHandle(this)) as ExternalObject<Handle> | null;
|
|
221
|
+
|
|
222
|
+
return handle === null ? null : wrapHandle(handle, Device);
|
|
222
223
|
}
|
|
223
224
|
|
|
224
225
|
/** Returns the font options the surface's backend prefers for rendering text. */
|
|
@@ -312,10 +313,7 @@ abstract class Surface {
|
|
|
312
313
|
class ImageSurface extends Surface {
|
|
313
314
|
/** Creates an image surface of the given pixel `format` and size, the same as `new ImageSurface(...)`. */
|
|
314
315
|
static create(format: Format, width: number, height: number): ImageSurface {
|
|
315
|
-
return wrapHandle(
|
|
316
|
-
checkSurface(cairoImageSurfaceCreate(format, width, height) as ExternalObject<Handle>),
|
|
317
|
-
this,
|
|
318
|
-
);
|
|
316
|
+
return wrapHandle(checkSurface(cairoImageSurfaceCreate(format, width, height) as ExternalObject<Handle>), this);
|
|
319
317
|
}
|
|
320
318
|
|
|
321
319
|
/** Loads a PNG file into a new image surface; throws when the file is missing or invalid. */
|
|
@@ -351,6 +349,10 @@ class ImageSurface extends Surface {
|
|
|
351
349
|
|
|
352
350
|
/** Returns a copy of the pixel data, `getStride() * getHeight()` bytes in the surface's format. */
|
|
353
351
|
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);
|
|
354
356
|
this.flush();
|
|
355
357
|
const totalBytes = this.getStride() * this.getHeight();
|
|
356
358
|
|
|
@@ -361,16 +363,10 @@ class ImageSurface extends Surface {
|
|
|
361
363
|
const getImageData = bindCairo(
|
|
362
364
|
"cairo_image_surface_get_data",
|
|
363
365
|
[SURFACE_T],
|
|
364
|
-
t.
|
|
366
|
+
t.fixedArray(t.uint8, totalBytes, "borrowed", { isBytes: true }),
|
|
365
367
|
);
|
|
366
368
|
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
if (data === null) {
|
|
370
|
-
return new Uint8Array(0);
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
return Uint8Array.from({ length: totalBytes }, (_, index) => UINT8.read(data, index) as number);
|
|
369
|
+
return getImageData(getHandle(this)) as Uint8Array;
|
|
374
370
|
}
|
|
375
371
|
}
|
|
376
372
|
|