@gtkx/cairo 2.0.0-beta.1 → 2.0.0-beta.11
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 -165
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +8 -7
- package/dist/context.js.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/path.d.ts.map +1 -1
- package/dist/path.js +9 -22
- package/dist/path.js.map +1 -1
- package/dist/pattern.js +5 -5
- package/dist/pattern.js.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/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/package.json +7 -6
- package/src/context.ts +8 -7
- package/src/enums.ts +10 -1
- package/src/font-face.ts +2 -2
- package/src/font-options.ts +4 -4
- package/src/path.ts +11 -27
- package/src/pattern.ts +6 -6
- package/src/scaled-font.ts +3 -1
- package/src/surface.ts +21 -25
package/src/enums.ts
CHANGED
|
@@ -13,7 +13,7 @@ type LineCap = (typeof LineCap)[keyof typeof LineCap];
|
|
|
13
13
|
/** One of the `LineJoin` styles for the corners of a stroked path. */
|
|
14
14
|
type LineJoin = (typeof LineJoin)[keyof typeof LineJoin];
|
|
15
15
|
/** One of the `TextClusterFlags` values describing a cluster mapping. */
|
|
16
|
-
type TextClusterFlags =
|
|
16
|
+
type TextClusterFlags = number;
|
|
17
17
|
/** One of the `FontSlant` values for a toy font face. */
|
|
18
18
|
type FontSlant = (typeof FontSlant)[keyof typeof FontSlant];
|
|
19
19
|
/** One of the `FontWeight` values for a toy font face. */
|
|
@@ -126,6 +126,12 @@ const Status = {
|
|
|
126
126
|
DEVICE_FINISHED: 37,
|
|
127
127
|
/** A JBIG2 global data stream was attached without its global identifier. */
|
|
128
128
|
JBIG2_GLOBAL_MISSING: 38,
|
|
129
|
+
PNG_ERROR: 39,
|
|
130
|
+
FREETYPE_ERROR: 40,
|
|
131
|
+
WIN32_GDI_ERROR: 41,
|
|
132
|
+
TAG_ERROR: 42,
|
|
133
|
+
DWRITE_ERROR: 43,
|
|
134
|
+
SVG_FONT_ERROR: 44,
|
|
129
135
|
} as const;
|
|
130
136
|
|
|
131
137
|
/**
|
|
@@ -359,6 +365,7 @@ const FontType = {
|
|
|
359
365
|
QUARTZ: 3,
|
|
360
366
|
/** A font created with the user font API. */
|
|
361
367
|
USER: 4,
|
|
368
|
+
DWRITE: 5,
|
|
362
369
|
} as const;
|
|
363
370
|
|
|
364
371
|
/**
|
|
@@ -477,6 +484,8 @@ const Format = {
|
|
|
477
484
|
RGB16_565: 4,
|
|
478
485
|
/** 30 bits per pixel with 10 bits per color channel. */
|
|
479
486
|
RGB30: 5,
|
|
487
|
+
RGB96F: 6,
|
|
488
|
+
RGBA128F: 7,
|
|
480
489
|
} as const;
|
|
481
490
|
|
|
482
491
|
/**
|
package/src/font-face.ts
CHANGED
|
@@ -12,7 +12,7 @@ import { type FontSlant, FontType, type FontWeight, type Status } from "./enums.
|
|
|
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 =
|
|
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,7 +26,7 @@ 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("
|
|
29
|
+
[t.string("borrowed"), t.int32, t.int32],
|
|
30
30
|
FONT_FACE_FULL_T,
|
|
31
31
|
);
|
|
32
32
|
|
package/src/font-options.ts
CHANGED
|
@@ -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("
|
|
26
|
+
[FONT_OPTIONS_T, t.string("borrowed")],
|
|
27
27
|
t.void,
|
|
28
28
|
);
|
|
29
29
|
|
|
@@ -129,13 +129,13 @@ class FontOptions {
|
|
|
129
129
|
}
|
|
130
130
|
|
|
131
131
|
/** Sets the OpenType font variations to apply, as a comma-separated `axis=value` string. */
|
|
132
|
-
setVariations(variations: string): void {
|
|
132
|
+
setVariations(variations: string | null): void {
|
|
133
133
|
cairoFontOptionsSetVariations(getHandle(this), variations);
|
|
134
134
|
}
|
|
135
135
|
|
|
136
136
|
/** Returns the OpenType font variations to apply. */
|
|
137
|
-
getVariations(): string {
|
|
138
|
-
return cairoFontOptionsGetVariations(getHandle(this)) as string;
|
|
137
|
+
getVariations(): string | null {
|
|
138
|
+
return cairoFontOptionsGetVariations(getHandle(this)) as string | null;
|
|
139
139
|
}
|
|
140
140
|
}
|
|
141
141
|
|
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
|
@@ -163,19 +163,19 @@ const checkPattern = <T extends Pattern>(pattern: T): T => {
|
|
|
163
163
|
return pattern;
|
|
164
164
|
};
|
|
165
165
|
|
|
166
|
-
const readRgba = (fill: (...refs: RgbaRefs) =>
|
|
166
|
+
const readRgba = (fill: (...refs: RgbaRefs) => unknown): RgbaColor => {
|
|
167
167
|
const red = { value: 0 };
|
|
168
168
|
const green = { value: 0 };
|
|
169
169
|
const blue = { value: 0 };
|
|
170
170
|
const alpha = { value: 0 };
|
|
171
|
-
fill(red, green, blue, alpha);
|
|
171
|
+
checkStatus(fill(red, green, blue, alpha) as Status, "pattern");
|
|
172
172
|
|
|
173
173
|
return { red: red.value, green: green.value, blue: blue.value, alpha: alpha.value };
|
|
174
174
|
};
|
|
175
175
|
|
|
176
176
|
const readCount = (boundFn: BoundFunction, self: object): number => {
|
|
177
177
|
const count = { value: 0 };
|
|
178
|
-
boundFn(getHandle(self), count);
|
|
178
|
+
checkStatus(boundFn(getHandle(self), count) as Status, "pattern");
|
|
179
179
|
|
|
180
180
|
return count.value;
|
|
181
181
|
};
|
|
@@ -352,7 +352,7 @@ class LinearPattern extends Pattern {
|
|
|
352
352
|
const y0 = { value: 0 };
|
|
353
353
|
const x1 = { value: 0 };
|
|
354
354
|
const y1 = { value: 0 };
|
|
355
|
-
cairoPatternGetLinearPoints(getHandle(this), x0, y0, x1, y1);
|
|
355
|
+
checkStatus(cairoPatternGetLinearPoints(getHandle(this), x0, y0, x1, y1) as Status, "pattern");
|
|
356
356
|
|
|
357
357
|
return { x0: x0.value, y0: y0.value, x1: x1.value, y1: y1.value };
|
|
358
358
|
}
|
|
@@ -368,7 +368,7 @@ class RadialPattern extends Pattern {
|
|
|
368
368
|
const x1 = { value: 0 };
|
|
369
369
|
const y1 = { value: 0 };
|
|
370
370
|
const r1 = { value: 0 };
|
|
371
|
-
cairoPatternGetRadialCircles(getHandle(this), x0, y0, r0, x1, y1, r1);
|
|
371
|
+
checkStatus(cairoPatternGetRadialCircles(getHandle(this), x0, y0, r0, x1, y1, r1) as Status, "pattern");
|
|
372
372
|
|
|
373
373
|
return { x0: x0.value, y0: y0.value, r0: r0.value, x1: x1.value, y1: y1.value, r1: r1.value };
|
|
374
374
|
}
|
|
@@ -433,7 +433,7 @@ class MeshPattern extends Pattern {
|
|
|
433
433
|
getControlPoint(patchNum: number, pointNum: number): Point {
|
|
434
434
|
const x = { value: 0 };
|
|
435
435
|
const y = { value: 0 };
|
|
436
|
-
cairoMeshPatternGetControlPoint(getHandle(this), patchNum, pointNum, x, y);
|
|
436
|
+
checkStatus(cairoMeshPatternGetControlPoint(getHandle(this), patchNum, pointNum, x, y) as Status, "pattern");
|
|
437
437
|
|
|
438
438
|
return { x: x.value, y: y.value };
|
|
439
439
|
}
|
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
|
|
|
@@ -104,6 +105,7 @@ class ScaledFont {
|
|
|
104
105
|
getHandle(options),
|
|
105
106
|
) as ExternalObject<Handle>;
|
|
106
107
|
|
|
108
|
+
checkStatus(cairoScaledFontStatus(handle) as Status, "scaled font");
|
|
107
109
|
setHandle(this, handle);
|
|
108
110
|
}
|
|
109
111
|
|
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;
|
|
@@ -216,9 +212,11 @@ abstract class Surface {
|
|
|
216
212
|
cairoSurfaceFlush(getHandle(this));
|
|
217
213
|
}
|
|
218
214
|
|
|
219
|
-
/** Returns the
|
|
220
|
-
getDevice():
|
|
221
|
-
|
|
215
|
+
/** Returns the managed device behind the surface, or null when it has none. */
|
|
216
|
+
getDevice(): Device | null {
|
|
217
|
+
const handle = cairoSurfaceGetDevice(getHandle(this)) as ExternalObject<Handle> | null;
|
|
218
|
+
|
|
219
|
+
return handle === null ? null : wrapHandle(handle, Device);
|
|
222
220
|
}
|
|
223
221
|
|
|
224
222
|
/** Returns the font options the surface's backend prefers for rendering text. */
|
|
@@ -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
|
|