@gtkx/cairo 2.0.0-beta.9 → 2.0.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.
Files changed (56) hide show
  1. package/README.md +8 -168
  2. package/dist/context.d.ts +27 -6
  3. package/dist/context.d.ts.map +1 -1
  4. package/dist/context.js +46 -17
  5. package/dist/context.js.map +1 -1
  6. package/dist/device.d.ts.map +1 -1
  7. package/dist/enums.d.ts +10 -1
  8. package/dist/enums.d.ts.map +1 -1
  9. package/dist/enums.js +9 -0
  10. package/dist/enums.js.map +1 -1
  11. package/dist/font-face.d.ts +5 -3
  12. package/dist/font-face.d.ts.map +1 -1
  13. package/dist/font-face.js +10 -5
  14. package/dist/font-face.js.map +1 -1
  15. package/dist/font-options.d.ts +2 -2
  16. package/dist/font-options.d.ts.map +1 -1
  17. package/dist/font-options.js +1 -1
  18. package/dist/font-options.js.map +1 -1
  19. package/dist/lib.d.ts +2 -1
  20. package/dist/lib.d.ts.map +1 -1
  21. package/dist/lib.js +10 -37
  22. package/dist/lib.js.map +1 -1
  23. package/dist/matrix.d.ts.map +1 -1
  24. package/dist/path.d.ts +4 -3
  25. package/dist/path.d.ts.map +1 -1
  26. package/dist/path.js +17 -26
  27. package/dist/path.js.map +1 -1
  28. package/dist/pattern.d.ts +13 -7
  29. package/dist/pattern.d.ts.map +1 -1
  30. package/dist/pattern.js +36 -20
  31. package/dist/pattern.js.map +1 -1
  32. package/dist/region.d.ts.map +1 -1
  33. package/dist/scaled-font.d.ts.map +1 -1
  34. package/dist/scaled-font.js +3 -1
  35. package/dist/scaled-font.js.map +1 -1
  36. package/dist/status.d.ts.map +1 -1
  37. package/dist/structs.d.ts.map +1 -1
  38. package/dist/structs.js +32 -36
  39. package/dist/structs.js.map +1 -1
  40. package/dist/surface.d.ts +3 -3
  41. package/dist/surface.d.ts.map +1 -1
  42. package/dist/surface.js +27 -21
  43. package/dist/surface.js.map +1 -1
  44. package/dist/text.d.ts.map +1 -1
  45. package/dist/version.d.ts.map +1 -1
  46. package/package.json +6 -17
  47. package/src/context.ts +52 -19
  48. package/src/enums.ts +10 -1
  49. package/src/font-face.ts +13 -11
  50. package/src/font-options.ts +5 -9
  51. package/src/lib.ts +11 -36
  52. package/src/path.ts +21 -31
  53. package/src/pattern.ts +41 -28
  54. package/src/scaled-font.ts +4 -6
  55. package/src/structs.ts +32 -48
  56. package/src/surface.ts +40 -37
package/src/font-face.ts CHANGED
@@ -4,15 +4,15 @@ import {
4
4
  type Handle,
5
5
  registerWrapperClass,
6
6
  registerWrapperClassResolver,
7
+ setHandle,
7
8
  t,
8
- wrapHandle,
9
9
  type WrapperClassResolver,
10
10
  } from "@gtkx/runtime";
11
11
  import { type FontSlant, FontType, type FontWeight, type Status } from "./enums.js";
12
12
  import { bindCairo, cairoGType, FONT_FACE_FULL_T, FONT_FACE_T } from "./lib.js";
13
13
 
14
14
  /** One of the `FtSynthesize` styles a FreeType font face synthesizes. */
15
- type FtSynthesize = (typeof FtSynthesize)[keyof typeof FtSynthesize];
15
+ type FtSynthesize = number;
16
16
 
17
17
  const FONT_FACE_TYPE = cairoGType("cairo_gobject_font_face_get_type");
18
18
  const cairoFontFaceStatus = bindCairo("cairo_font_face_status", [FONT_FACE_T], t.int32);
@@ -26,15 +26,11 @@ const cairoToyFontFaceGetFamily = bindCairo("cairo_toy_font_face_get_family", [F
26
26
 
27
27
  const cairoToyFontFaceCreate = bindCairo(
28
28
  "cairo_toy_font_face_create",
29
- [t.string("full"), t.int32, t.int32],
29
+ [t.string("borrowed"), t.int32, t.int32],
30
30
  FONT_FACE_FULL_T,
31
31
  );
32
32
 
33
- const cairoFtFontFaceUnsetSynthesize = bindCairo(
34
- "cairo_ft_font_face_unset_synthesize",
35
- [FONT_FACE_T, t.int32],
36
- t.void,
37
- );
33
+ const cairoFtFontFaceUnsetSynthesize = bindCairo("cairo_ft_font_face_unset_synthesize", [FONT_FACE_T, t.int32], t.void);
38
34
 
39
35
  /**
40
36
  * Styles a FreeType font face synthesizes when the font itself lacks them.
@@ -72,9 +68,9 @@ abstract class FontFace {
72
68
  registerWrapperClassResolver(this, fontFaceClassFor);
73
69
  }
74
70
 
75
- /** Creates a toy font face from a family name, slant and weight. */
71
+ /** Creates a toy font face, the same as `new ToyFontFace(...)`. */
76
72
  static create(family: string, slant: FontSlant, weight: FontWeight): ToyFontFace {
77
- return wrapHandle(cairoToyFontFaceCreate(family, slant, weight) as ExternalObject<Handle>, ToyFontFace);
73
+ return new ToyFontFace(family, slant, weight);
78
74
  }
79
75
 
80
76
  /** GType of `CairoFontFace`, the boxed type this class is registered under. */
@@ -96,8 +92,14 @@ abstract class FontFace {
96
92
  }
97
93
  }
98
94
 
99
- /** A toy font face, created with `FontFace.create` or a context's `selectFontFace`. */
95
+ /** A toy font face, created with `new ToyFontFace(...)`, `FontFace.create` or a context's `selectFontFace`. */
100
96
  class ToyFontFace extends FontFace {
97
+ /** Creates a toy font face from a family name, slant and weight. */
98
+ constructor(family: string, slant: FontSlant, weight: FontWeight) {
99
+ super();
100
+ setHandle(this, cairoToyFontFaceCreate(family, slant, weight) as ExternalObject<Handle>);
101
+ }
102
+
101
103
  /** Returns the family name the font face was created with. */
102
104
  getFamily(): string {
103
105
  return cairoToyFontFaceGetFamily(getHandle(this)) as string;
@@ -23,7 +23,7 @@ const cairoFontOptionsGetVariations = bindCairo(
23
23
 
24
24
  const cairoFontOptionsSetVariations = bindCairo(
25
25
  "cairo_font_options_set_variations",
26
- [FONT_OPTIONS_T, t.string("full")],
26
+ [FONT_OPTIONS_T, t.string("borrowed")],
27
27
  t.void,
28
28
  );
29
29
 
@@ -39,11 +39,7 @@ const cairoFontOptionsSetSubpixelOrder = bindCairo(
39
39
  t.void,
40
40
  );
41
41
 
42
- const cairoFontOptionsGetSubpixelOrder = bindCairo(
43
- "cairo_font_options_get_subpixel_order",
44
- [FONT_OPTIONS_T],
45
- t.int32,
46
- );
42
+ const cairoFontOptionsGetSubpixelOrder = bindCairo("cairo_font_options_get_subpixel_order", [FONT_OPTIONS_T], t.int32);
47
43
 
48
44
  /**
49
45
  * Cairo font options (`cairo_font_options_t`): the rendering settings applied to text, such as antialiasing,
@@ -129,13 +125,13 @@ class FontOptions {
129
125
  }
130
126
 
131
127
  /** Sets the OpenType font variations to apply, as a comma-separated `axis=value` string. */
132
- setVariations(variations: string): void {
128
+ setVariations(variations: string | null): void {
133
129
  cairoFontOptionsSetVariations(getHandle(this), variations);
134
130
  }
135
131
 
136
132
  /** Returns the OpenType font variations to apply. */
137
- getVariations(): string {
138
- return cairoFontOptionsGetVariations(getHandle(this)) as string;
133
+ getVariations(): string | null {
134
+ return cairoFontOptionsGetVariations(getHandle(this)) as string | null;
139
135
  }
140
136
  }
141
137
 
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 = t.boxed("CairoContext", {
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 = t.boxed("CairoSurface", {
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 = t.boxed("CairoPattern", {
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 = t.boxed("CairoRegion", {
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 = t.boxed("CairoFontOptions", {
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 = t.boxed("CairoFontFace", {
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 = t.boxed("CairoScaledFont", {
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
 
@@ -138,11 +110,13 @@ const FONT_EXTENTS_T: BoxedDescriptor = t.boxed("cairo_font_extents_t", {
138
110
  });
139
111
 
140
112
  const PATH_T: BoxedDescriptor = t.boxed("cairo_path_t", {
141
- ownership: "full",
113
+ ownership: "borrowed",
142
114
  sharedLibrary: CAIRO_LIBRARY,
143
115
  freeFnName: "cairo_path_destroy",
144
116
  });
145
117
 
118
+ const PATH_FULL_T: BoxedDescriptor = { ...PATH_T, ownership: "full" };
119
+
146
120
  const DOUBLE_BUFFER_T: BoxedDescriptor = t.boxed("double[]", { ownership: "borrowed", sharedLibrary: CAIRO_LIBRARY });
147
121
 
148
122
  const bindCairo = (symbol: string, args: Descriptor[], returns: Descriptor): BoundFunction =>
@@ -165,6 +139,7 @@ export {
165
139
  FONT_OPTIONS_T,
166
140
  GLYPH_T,
167
141
  MATRIX_T,
142
+ PATH_FULL_T,
168
143
  PATH_T,
169
144
  PATTERN_FULL_T,
170
145
  PATTERN_T,
package/src/path.ts CHANGED
@@ -1,9 +1,9 @@
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";
1
+ import { type ExternalObject, getHandle, type Handle, read, t, wrapHandle } from "@gtkx/runtime";
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 segmentReaderFor = (headerType: PathDataType): SegmentReader | null => {
35
- switch (headerType) {
36
- case PathDataType.MOVE_TO: {
37
- return readMoveTo;
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 = segmentReaderFor(INT.read(data, base) as PathDataType);
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
 
@@ -77,8 +61,8 @@ const parsePath = (pathHandle: PathBuffer): PathData[] => {
77
61
  };
78
62
 
79
63
  /**
80
- * A cairo path (`cairo_path_t`). Instances come from the bindings that hand one back, and the bindings that take
81
- * one, such as `Gsk.PathBuilder.addCairoPath`, accept it as is.
64
+ * A cairo path (`cairo_path_t`). `Context.copyPath()` and `Context.copyPathFlat()` return one, and
65
+ * `Context.appendPath` and bindings that take one, such as `Gsk.PathBuilder.addCairoPath`, accept it as is.
82
66
  */
83
67
  abstract class Path {
84
68
  /** Reads the segments of the path in drawing order. */
@@ -87,4 +71,10 @@ abstract class Path {
87
71
  }
88
72
  }
89
73
 
90
- export { parsePath, Path };
74
+ const wrapPath = (pathHandle: PathBuffer): Path => {
75
+ checkStatus(INT.read(pathHandle, 0) as Status, "path");
76
+
77
+ return wrapHandle(pathHandle, Path);
78
+ };
79
+
80
+ export { parsePath, Path, wrapPath };
package/src/pattern.ts CHANGED
@@ -4,6 +4,7 @@ import {
4
4
  type Handle,
5
5
  registerWrapperClass,
6
6
  registerWrapperClassResolver,
7
+ setHandle,
7
8
  t,
8
9
  wrapHandle,
9
10
  type WrapperClassResolver,
@@ -15,7 +16,7 @@ import {
15
16
  type BoundFunction,
16
17
  cairoGType,
17
18
  MATRIX_T,
18
- PATH_T,
19
+ PATH_FULL_T,
19
20
  PATTERN_FULL_T,
20
21
  PATTERN_T,
21
22
  SURFACE_T,
@@ -25,12 +26,7 @@ import { parsePath } from "./path.js";
25
26
  import { checkStatus } from "./status.js";
26
27
  import { Surface } from "./surface.js";
27
28
 
28
- type RgbaRefs = [
29
- red: { value: number },
30
- green: { value: number },
31
- blue: { value: number },
32
- alpha: { value: number },
33
- ];
29
+ type RgbaRefs = [red: { value: number }, green: { value: number }, blue: { value: number }, alpha: { value: number }];
34
30
 
35
31
  const PATTERN_TYPE = cairoGType("cairo_gobject_pattern_get_type");
36
32
  const FOUR_DOUBLES_OUT = [t.ref(t.float64), t.ref(t.float64), t.ref(t.float64), t.ref(t.float64)];
@@ -141,7 +137,7 @@ const cairoMeshPatternGetPatchCount = bindCairo(
141
137
  t.int32,
142
138
  );
143
139
 
144
- const cairoMeshPatternGetPath = bindCairo("cairo_mesh_pattern_get_path", [PATTERN_T, t.int32], PATH_T);
140
+ const cairoMeshPatternGetPath = bindCairo("cairo_mesh_pattern_get_path", [PATTERN_T, t.int32], PATH_FULL_T);
145
141
 
146
142
  const cairoMeshPatternGetControlPoint = bindCairo(
147
143
  "cairo_mesh_pattern_get_control_point",
@@ -163,19 +159,19 @@ const checkPattern = <T extends Pattern>(pattern: T): T => {
163
159
  return pattern;
164
160
  };
165
161
 
166
- const readRgba = (fill: (...refs: RgbaRefs) => void): RgbaColor => {
162
+ const readRgba = (fill: (...refs: RgbaRefs) => unknown): RgbaColor => {
167
163
  const red = { value: 0 };
168
164
  const green = { value: 0 };
169
165
  const blue = { value: 0 };
170
166
  const alpha = { value: 0 };
171
- fill(red, green, blue, alpha);
167
+ checkStatus(fill(red, green, blue, alpha) as Status, "pattern");
172
168
 
173
169
  return { red: red.value, green: green.value, blue: blue.value, alpha: alpha.value };
174
170
  };
175
171
 
176
172
  const readCount = (boundFn: BoundFunction, self: object): number => {
177
173
  const count = { value: 0 };
178
- boundFn(getHandle(self), count);
174
+ checkStatus(boundFn(getHandle(self), count) as Status, "pattern");
179
175
 
180
176
  return count.value;
181
177
  };
@@ -219,14 +215,12 @@ abstract class Pattern {
219
215
  return checkPattern(wrapPattern(cairoPatternCreateRgba(red, green, blue, alpha)));
220
216
  }
221
217
 
222
- /** Creates a linear gradient between `(x0, y0)` and `(x1, y1)`; add stops with `addColorStopRgba`. */
218
+ /** Creates a linear gradient, the same as `new LinearPattern(...)`. */
223
219
  static createLinear(x0: number, y0: number, x1: number, y1: number): LinearPattern {
224
- const handle = cairoPatternCreateLinear(x0, y0, x1, y1) as ExternalObject<Handle>;
225
-
226
- return checkPattern(wrapHandle(handle, LinearPattern));
220
+ return new LinearPattern(x0, y0, x1, y1);
227
221
  }
228
222
 
229
- /** Creates a radial gradient between two circles; add stops with `addColorStopRgba`. */
223
+ /** Creates a radial gradient, the same as `new RadialPattern(...)`. */
230
224
  static createRadial(
231
225
  cx0: number,
232
226
  cy0: number,
@@ -235,14 +229,12 @@ abstract class Pattern {
235
229
  cy1: number,
236
230
  radius1: number,
237
231
  ): RadialPattern {
238
- const handle = cairoPatternCreateRadial(cx0, cy0, radius0, cx1, cy1, radius1) as ExternalObject<Handle>;
239
-
240
- return checkPattern(wrapHandle(handle, RadialPattern));
232
+ return new RadialPattern(cx0, cy0, radius0, cx1, cy1, radius1);
241
233
  }
242
234
 
243
- /** Creates an empty mesh gradient; describe its patches with the `MeshPattern` methods. */
235
+ /** Creates an empty mesh gradient, the same as `new MeshPattern()`. */
244
236
  static createMesh(): MeshPattern {
245
- return checkPattern(wrapHandle(cairoPatternCreateMesh() as ExternalObject<Handle>, MeshPattern));
237
+ return new MeshPattern();
246
238
  }
247
239
 
248
240
  /** Creates a pattern that paints with the content of `surface`. */
@@ -344,22 +336,36 @@ abstract class Pattern {
344
336
  }
345
337
  }
346
338
 
347
- /** A linear gradient pattern, created with `Pattern.createLinear`. */
339
+ /** A linear gradient pattern, created with `new LinearPattern(...)` or `Pattern.createLinear`. */
348
340
  class LinearPattern extends Pattern {
341
+ /** Creates a linear gradient between `(x0, y0)` and `(x1, y1)`; add stops with `addColorStopRgba`. */
342
+ constructor(x0: number, y0: number, x1: number, y1: number) {
343
+ super();
344
+ setHandle(this, cairoPatternCreateLinear(x0, y0, x1, y1) as ExternalObject<Handle>);
345
+ checkPattern(this);
346
+ }
347
+
349
348
  /** Returns the two end points of the gradient. */
350
349
  getLinearPoints(): LinearPoints {
351
350
  const x0 = { value: 0 };
352
351
  const y0 = { value: 0 };
353
352
  const x1 = { value: 0 };
354
353
  const y1 = { value: 0 };
355
- cairoPatternGetLinearPoints(getHandle(this), x0, y0, x1, y1);
354
+ checkStatus(cairoPatternGetLinearPoints(getHandle(this), x0, y0, x1, y1) as Status, "pattern");
356
355
 
357
356
  return { x0: x0.value, y0: y0.value, x1: x1.value, y1: y1.value };
358
357
  }
359
358
  }
360
359
 
361
- /** A radial gradient pattern, created with `Pattern.createRadial`. */
360
+ /** A radial gradient pattern, created with `new RadialPattern(...)` or `Pattern.createRadial`. */
362
361
  class RadialPattern extends Pattern {
362
+ /** Creates a radial gradient between two circles; add stops with `addColorStopRgba`. */
363
+ constructor(cx0: number, cy0: number, radius0: number, cx1: number, cy1: number, radius1: number) {
364
+ super();
365
+ setHandle(this, cairoPatternCreateRadial(cx0, cy0, radius0, cx1, cy1, radius1) as ExternalObject<Handle>);
366
+ checkPattern(this);
367
+ }
368
+
363
369
  /** Returns the two circles of the gradient. */
364
370
  getRadialCircles(): RadialCircles {
365
371
  const x0 = { value: 0 };
@@ -368,17 +374,24 @@ class RadialPattern extends Pattern {
368
374
  const x1 = { value: 0 };
369
375
  const y1 = { value: 0 };
370
376
  const r1 = { value: 0 };
371
- cairoPatternGetRadialCircles(getHandle(this), x0, y0, r0, x1, y1, r1);
377
+ checkStatus(cairoPatternGetRadialCircles(getHandle(this), x0, y0, r0, x1, y1, r1) as Status, "pattern");
372
378
 
373
379
  return { x0: x0.value, y0: y0.value, r0: r0.value, x1: x1.value, y1: y1.value, r1: r1.value };
374
380
  }
375
381
  }
376
382
 
377
383
  /**
378
- * A mesh gradient pattern, created with `Pattern.createMesh`: a set of Coons patches, each described between
379
- * `beginPatch` and `endPatch` by a path of up to four sides and the colors of its corners.
384
+ * A mesh gradient pattern, created with `new MeshPattern()` or `Pattern.createMesh`: a set of Coons patches, each
385
+ * described between `beginPatch` and `endPatch` by a path of up to four sides and the colors of its corners.
380
386
  */
381
387
  class MeshPattern extends Pattern {
388
+ /** Creates an empty mesh gradient; describe its patches with the methods below. */
389
+ constructor() {
390
+ super();
391
+ setHandle(this, cairoPatternCreateMesh() as ExternalObject<Handle>);
392
+ checkPattern(this);
393
+ }
394
+
382
395
  /** Starts describing a new patch. */
383
396
  beginPatch(): void {
384
397
  cairoMeshPatternBeginPatch(getHandle(this));
@@ -433,7 +446,7 @@ class MeshPattern extends Pattern {
433
446
  getControlPoint(patchNum: number, pointNum: number): Point {
434
447
  const x = { value: 0 };
435
448
  const y = { value: 0 };
436
- cairoMeshPatternGetControlPoint(getHandle(this), patchNum, pointNum, x, y);
449
+ checkStatus(cairoMeshPatternGetControlPoint(getHandle(this), patchNum, pointNum, x, y) as Status, "pattern");
437
450
 
438
451
  return { x: x.value, y: y.value };
439
452
  }
@@ -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("full"), TEXT_EXTENTS_T],
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