@gtkx/cairo 2.0.0-beta.11 → 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/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, descriptor, offset, toNative(descriptor, value));
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 readField(this, DOUBLE, 0);
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
- writeField(this, DOUBLE, 0, value);
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 readField(this, DOUBLE, 8);
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
- writeField(this, DOUBLE, 8, value);
110
+ DOUBLE.write(getHandle(this), 8, value);
127
111
  }
128
112
 
129
113
  /** Width of the rectangle. */
130
114
  get width(): number {
131
- return readField(this, DOUBLE, 16);
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
- writeField(this, DOUBLE, 16, value);
120
+ DOUBLE.write(getHandle(this), 16, value);
137
121
  }
138
122
 
139
123
  /** Height of the rectangle. */
140
124
  get height(): number {
141
- return readField(this, DOUBLE, 24);
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
- writeField(this, DOUBLE, 24, value);
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 readField(this, INT, 0);
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
- writeField(this, INT, 0, value);
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 readField(this, INT, 4);
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
- writeField(this, INT, 4, value);
170
+ INT.write(getHandle(this), 4, value);
187
171
  }
188
172
 
189
173
  /** Width of the rectangle. */
190
174
  get width(): number {
191
- return readField(this, INT, 8);
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
- writeField(this, INT, 8, value);
180
+ INT.write(getHandle(this), 8, value);
197
181
  }
198
182
 
199
183
  /** Height of the rectangle. */
200
184
  get height(): number {
201
- return readField(this, INT, 12);
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
- writeField(this, INT, 12, value);
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), ULONG, 0) as bigint;
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
- writeField(this, ULONG, 0, value);
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 readField(this, DOUBLE, 8);
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
- writeField(this, DOUBLE, 8, value);
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 readField(this, DOUBLE, 16);
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
- writeField(this, DOUBLE, 16, value);
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 readField(this, INT, 0);
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
- writeField(this, INT, 0, value);
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 readField(this, INT, 4);
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
- writeField(this, INT, 4, value);
277
+ INT.write(getHandle(this), 4, value);
294
278
  }
295
279
  }
296
280
 
package/src/surface.ts CHANGED
@@ -175,16 +175,19 @@ abstract class Surface {
175
175
 
176
176
  /** Creates an image surface of the given `format` and size as compatible as possible with `other`. */
177
177
  static createSimilarImage(other: Surface, format: Format, width: number, height: number): ImageSurface {
178
- const handle =
179
- cairoSurfaceCreateSimilarImage(getHandle(other), format, width, height) as ExternalObject<Handle>;
178
+ const handle = cairoSurfaceCreateSimilarImage(
179
+ getHandle(other),
180
+ format,
181
+ width,
182
+ height,
183
+ ) as ExternalObject<Handle>;
180
184
 
181
185
  return wrapHandle(checkSurface(handle), ImageSurface);
182
186
  }
183
187
 
184
188
  /** Creates a surface that draws onto the given rectangle of `target`. */
185
189
  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>;
190
+ const handle = cairoSurfaceCreateForRectangle(getHandle(target), x, y, width, height) as ExternalObject<Handle>;
188
191
 
189
192
  return wrapSurface(checkSurface(handle));
190
193
  }
@@ -310,10 +313,7 @@ abstract class Surface {
310
313
  class ImageSurface extends Surface {
311
314
  /** Creates an image surface of the given pixel `format` and size, the same as `new ImageSurface(...)`. */
312
315
  static create(format: Format, width: number, height: number): ImageSurface {
313
- return wrapHandle(
314
- checkSurface(cairoImageSurfaceCreate(format, width, height) as ExternalObject<Handle>),
315
- this,
316
- );
316
+ return wrapHandle(checkSurface(cairoImageSurfaceCreate(format, width, height) as ExternalObject<Handle>), this);
317
317
  }
318
318
 
319
319
  /** Loads a PNG file into a new image surface; throws when the file is missing or invalid. */