@gtkx/cairo 2.0.0-beta.8 → 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.
- package/README.md +8 -168
- package/dist/context.d.ts +27 -6
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +46 -17
- 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 +5 -3
- package/dist/font-face.d.ts.map +1 -1
- package/dist/font-face.js +10 -5
- 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 +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 +17 -26
- 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 +36 -20
- 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 +27 -21
- 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 +52 -19
- package/src/enums.ts +10 -1
- package/src/font-face.ts +13 -11
- package/src/font-options.ts +5 -9
- package/src/lib.ts +11 -36
- package/src/path.ts +21 -31
- package/src/pattern.ts +41 -28
- package/src/scaled-font.ts +4 -6
- package/src/structs.ts +32 -48
- package/src/surface.ts +40 -37
package/README.md
CHANGED
|
@@ -1,177 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
<img src="https://raw.githubusercontent.com/gtkx-org/gtkx/main/logo.svg" alt="GTKX" width="100" />
|
|
3
|
-
</p>
|
|
1
|
+
# @gtkx/cairo
|
|
4
2
|
|
|
5
|
-
|
|
3
|
+
Cairo drawing for GTK apps built with GTKX.
|
|
6
4
|
|
|
7
|
-
|
|
8
|
-
The React framework for Linux.<br />
|
|
9
|
-
Write native GNOME applications with React and TypeScript.
|
|
10
|
-
Real Adwaita and GTK4 widgets with standard web tooling.
|
|
11
|
-
</p>
|
|
5
|
+
Draw paths, text, and images in a `GtkDrawingArea` callback or on an offscreen surface. For drawing techniques, see the [Cairo manual](https://www.cairographics.org/manual/).
|
|
12
6
|
|
|
13
|
-
|
|
14
|
-
<a href="https://www.npmjs.com/package/create-gtkx"><img src="https://img.shields.io/npm/v/create-gtkx?color=cb3837&logo=npm&label=create-gtkx" alt="npm version" /></a>
|
|
15
|
-
<a href="https://www.npmjs.com/package/create-gtkx"><img src="https://img.shields.io/npm/dm/create-gtkx?color=cb3837&logo=npm&label=downloads" alt="npm downloads" /></a>
|
|
16
|
-
<img src="https://img.shields.io/badge/node-%E2%89%A526.7-339933?logo=node.js&logoColor=white" alt="Node >= 26.7" />
|
|
17
|
-
<a href="https://github.com/gtkx-org/gtkx/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MPL--2.0-blue.svg" alt="License: MPL-2.0" /></a>
|
|
18
|
-
<a href="https://github.com/gtkx-org/gtkx/actions/workflows/ci.yml"><img src="https://img.shields.io/github/actions/workflow/status/gtkx-org/gtkx/ci.yml?branch=main&logo=github&label=CI" alt="CI status" /></a>
|
|
19
|
-
<img src="https://img.shields.io/badge/TypeScript-strict-3178c6?logo=typescript&logoColor=white" alt="TypeScript" />
|
|
20
|
-
</p>
|
|
21
|
-
|
|
22
|
-
<p align="center">
|
|
23
|
-
<a href="https://gtkx.dev">Homepage</a> ·
|
|
24
|
-
<a href="https://gtkx.dev/guide/getting-started">Documentation</a> ·
|
|
25
|
-
<a href="https://github.com/gtkx-org/gtkx/tree/main/examples">Examples</a> ·
|
|
26
|
-
<a href="https://github.com/gtkx-org/gtkx/blob/main/CONTRIBUTING.md">Contributing</a>
|
|
27
|
-
</p>
|
|
28
|
-
|
|
29
|
-
---
|
|
30
|
-
|
|
31
|
-
<p align="center">
|
|
32
|
-
<img src="https://raw.githubusercontent.com/gtkx-org/gtkx/main/examples/tutorial/assets/screenshot.png" alt="The Tasks app: an Adwaita window with a sidebar of smart views and colored lists on the left, and a boxed task list on the right." />
|
|
33
|
-
</p>
|
|
34
|
-
|
|
35
|
-
<p align="center">
|
|
36
|
-
<em>The Tasks app you build in the <a href="https://gtkx.dev/tutorial/">tutorial</a>.</em>
|
|
37
|
-
</p>
|
|
38
|
-
|
|
39
|
-
## Demo
|
|
40
|
-
|
|
41
|
-
This app starts with an Adwaita application shell, renders native GTK4 widgets inside it, and uses ordinary React hooks and events:
|
|
42
|
-
|
|
43
|
-
```tsx
|
|
44
|
-
import * as Gtk from "@gtkx/gi/gtk";
|
|
45
|
-
import { AdwApplication, AdwApplicationWindow, AdwHeaderBar, AdwToolbarView } from "@gtkx/jsx/adw";
|
|
46
|
-
import { GtkBox, GtkButton, GtkLabel } from "@gtkx/jsx/gtk";
|
|
47
|
-
import { createRoot, quit } from "@gtkx/react";
|
|
48
|
-
import { useState } from "react";
|
|
49
|
-
|
|
50
|
-
const Counter = () => {
|
|
51
|
-
const [count, setCount] = useState(0);
|
|
52
|
-
|
|
53
|
-
return (
|
|
54
|
-
<AdwApplicationWindow
|
|
55
|
-
title="Hello GTKX"
|
|
56
|
-
defaultWidth={400}
|
|
57
|
-
defaultHeight={300}
|
|
58
|
-
onCloseRequest={quit}
|
|
59
|
-
>
|
|
60
|
-
<AdwToolbarView topBar={<AdwHeaderBar />}>
|
|
61
|
-
<GtkBox
|
|
62
|
-
orientation={Gtk.Orientation.VERTICAL}
|
|
63
|
-
spacing={20}
|
|
64
|
-
marginTop={40}
|
|
65
|
-
marginBottom={40}
|
|
66
|
-
marginStart={40}
|
|
67
|
-
marginEnd={40}
|
|
68
|
-
valign={Gtk.Align.CENTER}
|
|
69
|
-
halign={Gtk.Align.CENTER}
|
|
70
|
-
>
|
|
71
|
-
<GtkLabel cssClasses={["title-1"]}>Welcome to GTKX!</GtkLabel>
|
|
72
|
-
<GtkLabel cssClasses={["title-2"]}>{`Count: ${String(count)}`}</GtkLabel>
|
|
73
|
-
<GtkButton
|
|
74
|
-
label="Increment"
|
|
75
|
-
onClicked={() => setCount((c) => c + 1)}
|
|
76
|
-
cssClasses={["suggested-action", "pill"]}
|
|
77
|
-
/>
|
|
78
|
-
</GtkBox>
|
|
79
|
-
</AdwToolbarView>
|
|
80
|
-
</AdwApplicationWindow>
|
|
81
|
-
);
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
const App = () => (
|
|
85
|
-
<AdwApplication>
|
|
86
|
-
<Counter />
|
|
87
|
-
</AdwApplication>
|
|
88
|
-
);
|
|
89
|
-
|
|
90
|
-
createRoot().render(<App />);
|
|
91
|
-
```
|
|
92
|
-
|
|
93
|
-
This is the [`hello-world`](https://github.com/gtkx-org/gtkx/tree/main/examples/hello-world) example, with `app.tsx` and `index.tsx` combined into a single snippet. `@gtkx/gi` and `@gtkx/jsx` are per-project bindings generated by the CLI, not packages you install from npm.
|
|
94
|
-
|
|
95
|
-
## Why GTKX
|
|
96
|
-
|
|
97
|
-
### Adwaita-first application development
|
|
98
|
-
|
|
99
|
-
GTKX uses Adwaita as the foundation for applications, windows, navigation, dialogs, and adaptive layouts, with the complete GTK4 toolkit underneath. It adds a declarative React layer and an integrated TypeScript toolchain to the GNOME platform:
|
|
100
|
-
|
|
101
|
-
- a React reconciler that exposes every GObject as a JSX element,
|
|
102
|
-
- a CLI for scaffolding, development, and production builds,
|
|
103
|
-
- a dev server with Fast Refresh that patches your running UI in place,
|
|
104
|
-
- CSS-in-JS styling, React Hook Form-powered Adwaita controls, gettext-backed react-i18next localization, React Spring animations, React Navigation stack, tab, drawer, and split view navigators, and high-level list, grid, and dialog components,
|
|
105
|
-
- a Testing Library-style API for querying and driving your widgets in tests,
|
|
106
|
-
- and a Model Context Protocol (MCP) server that exposes your live app to AI agents.
|
|
107
|
-
|
|
108
|
-
### Native GNOME widgets, without a compatibility layer
|
|
109
|
-
|
|
110
|
-
React Native and similar frameworks hide the native toolkit so one API can run everywhere. GTKX renders real Adwaita and GTK4 widgets and exposes any other GObject-Introspection library on your system. It is GNOME-native and Linux-only by design.
|
|
111
|
-
|
|
112
|
-
### Why Node.js, and why generated bindings
|
|
113
|
-
|
|
114
|
-
GTKX runs on Node.js, which puts native modules, the npm ecosystem, and the tooling built for Node.js APIs within reach. GJS is GNOME's own runtime, built on SpiderMonkey rather than V8; node-gtk runs on Node.js but is lightly maintained, on the older nan/V8 ABI rather than N-API, and still centered on GTK3. The [Why GTKX guide](https://gtkx.dev/guide/why-gtkx) covers what running on Node.js means day to day.
|
|
115
|
-
|
|
116
|
-
GTKX generates the TypeScript types and native FFI calls from the same GObject-Introspection data, so the types cannot drift from the calls they back. `Adw-1` is the sole default GIR root; its GIR include pulls in `Gtk-4.0`, so codegen covers both complete API surfaces. Neither belongs in a GTKX 2 `libraries` list.
|
|
117
|
-
|
|
118
|
-
At runtime, the native Rust core calls straight into the system Adwaita, GTK4, and GLib libraries through libffi, without loading libgirepository at all.
|
|
119
|
-
|
|
120
|
-
## Quick start
|
|
121
|
-
|
|
122
|
-
GTKX is Linux-only and needs Node.js 26.7 or later. See [Requirements](#requirements).
|
|
123
|
-
|
|
124
|
-
Scaffold a new app with the `create-gtkx` initializer:
|
|
7
|
+
Apps created with `npm create gtkx` already depend on this package. Otherwise:
|
|
125
8
|
|
|
126
9
|
```sh
|
|
127
|
-
npm
|
|
10
|
+
npm install @gtkx/cairo
|
|
128
11
|
```
|
|
129
12
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
Then run your new app:
|
|
133
|
-
|
|
134
|
-
```sh
|
|
135
|
-
cd my-app
|
|
136
|
-
npm run dev
|
|
137
|
-
```
|
|
138
|
-
|
|
139
|
-
To go further, follow the [tutorial](https://gtkx.dev/tutorial/).
|
|
140
|
-
|
|
141
|
-
## Documentation
|
|
142
|
-
|
|
143
|
-
The documentation at **[gtkx.dev](https://gtkx.dev)** includes a step-by-step tutorial that builds a complete GNOME app, from scaffolding to packaging and shipping, plus guides and a full API reference.
|
|
144
|
-
|
|
145
|
-
**[Read the docs →](https://gtkx.dev/guide/why-gtkx)**
|
|
146
|
-
|
|
147
|
-
## Requirements
|
|
148
|
-
|
|
149
|
-
GTKX is Linux-only. You need:
|
|
150
|
-
|
|
151
|
-
- Linux with the Adwaita (1.8 or later), GTK4 (4.20 or later), and GLib development libraries
|
|
152
|
-
- Node.js 26.7 or later
|
|
153
|
-
|
|
154
|
-
The `@gtkx/native` addon ships prebuilt for x64 and arm64 glibc Linux; other targets need to build it from the GTKX repository, which requires a Rust toolchain.
|
|
155
|
-
|
|
156
|
-
## Examples
|
|
157
|
-
|
|
158
|
-
Explore the [example apps](https://github.com/gtkx-org/gtkx/tree/main/examples):
|
|
159
|
-
|
|
160
|
-
- [`hello-world`](https://github.com/gtkx-org/gtkx/tree/main/examples/hello-world): the Adwaita counter above.
|
|
161
|
-
- [`gtk-demo`](https://github.com/gtkx-org/gtkx/tree/main/examples/gtk-demo): the official GTK4 widget showcase in an Adwaita application shell, covering lists, dialogs, gestures, CSS, and OpenGL.
|
|
162
|
-
- [`browser`](https://github.com/gtkx-org/gtkx/tree/main/examples/browser): an Adwaita browser built around `WebKitWebView`.
|
|
163
|
-
- [`animations`](https://github.com/gtkx-org/gtkx/tree/main/examples/animations): an Adwaita showcase for `@gtkx/animated`, with React Spring animations driven by the GTK frame clock.
|
|
164
|
-
- [`navigation`](https://github.com/gtkx-org/gtkx/tree/main/examples/navigation): a tour of `@gtkx/navigation`, React Navigation's stack, tab, and drawer navigators rendered with libadwaita.
|
|
165
|
-
- [`tutorial`](https://github.com/gtkx-org/gtkx/tree/main/examples/tutorial): the Tasks app the documentation builds.
|
|
166
|
-
|
|
167
|
-
## Status
|
|
168
|
-
|
|
169
|
-
GTKX is stable and ready for production use.
|
|
170
|
-
|
|
171
|
-
## Contributing
|
|
172
|
-
|
|
173
|
-
Contributions are welcome. See [CONTRIBUTING.md](https://github.com/gtkx-org/gtkx/blob/main/CONTRIBUTING.md), the [Code of Conduct](https://github.com/gtkx-org/gtkx/blob/main/CODE_OF_CONDUCT.md), and the [security policy](https://github.com/gtkx-org/gtkx/blob/main/SECURITY.md). Building the repo needs Node.js 26.7 or later, pnpm, and a Rust toolchain.
|
|
13
|
+
[Guide](https://gtkx.dev/guide/cairo) · [API reference](https://gtkx.dev/reference/@gtkx/cairo/) · [GTKX](https://gtkx.dev)
|
|
174
14
|
|
|
175
|
-
|
|
15
|
+
GTKX requires Linux, Node.js, and the [native prerequisites](https://gtkx.dev/guide/getting-started#what-you-need).
|
|
176
16
|
|
|
177
|
-
|
|
17
|
+
[MPL-2.0](https://github.com/gtkx-org/gtkx/blob/main/LICENSE).
|
package/dist/context.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type { CairoGlyph, CairoTextCluster, DashPattern, Distance, Extents, Font
|
|
|
3
3
|
import { FontFace } from "./font-face.js";
|
|
4
4
|
import { FontOptions } from "./font-options.js";
|
|
5
5
|
import { Matrix } from "./matrix.js";
|
|
6
|
+
import { Path } from "./path.js";
|
|
6
7
|
import { Pattern } from "./pattern.js";
|
|
7
8
|
import { ScaledFont } from "./scaled-font.js";
|
|
8
9
|
import { Surface } from "./surface.js";
|
|
@@ -11,13 +12,33 @@ import { Surface } from "./surface.js";
|
|
|
11
12
|
* path, source, transformation, clip and font state for one target surface. GTK hands one to draw callbacks
|
|
12
13
|
* and snapshots, and `new Context(surface)` creates one for offscreen drawing.
|
|
13
14
|
*/
|
|
14
|
-
declare class Context {
|
|
15
|
+
declare class Context implements Disposable {
|
|
15
16
|
/** Creates a context drawing onto `target`, the same as `new Context(target)`. */
|
|
16
17
|
static create(target: Surface): Context;
|
|
17
18
|
/** GType of `CairoContext`, the boxed type this class is registered under. */
|
|
18
19
|
__type__: bigint;
|
|
19
20
|
/** Creates a context drawing onto `target`, throwing when it cannot be created, such as on a finished surface. */
|
|
20
21
|
constructor(target: Surface);
|
|
22
|
+
/**
|
|
23
|
+
* Drops this context's reference to its `cairo_t` now instead of when the garbage collector
|
|
24
|
+
* reclaims the wrapper, as `cairo_destroy` does in C. Release a context the app obtains itself,
|
|
25
|
+
* such as one from `Gtk.Snapshot.appendCairo` or `Context.create` on a long-lived surface, once
|
|
26
|
+
* drawing is done: until then the context keeps its target alive, and Cairo copies a backing
|
|
27
|
+
* surface into each recording that still holds it when the app draws into it again.
|
|
28
|
+
*
|
|
29
|
+
* A `using` declaration calls this when its block exits:
|
|
30
|
+
*
|
|
31
|
+
* ```ts
|
|
32
|
+
* using cr = snapshot.appendCairo(bounds);
|
|
33
|
+
* cr.setSourceSurface(surface, 0, 0);
|
|
34
|
+
* cr.paint();
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* Every later call on the context throws. Calling it again does nothing, and on the context a
|
|
38
|
+
* draw callback receives it only ends that context early, because GTKX releases it when the
|
|
39
|
+
* callback returns anyway.
|
|
40
|
+
*/
|
|
41
|
+
[Symbol.dispose](): void;
|
|
21
42
|
/** Begins a new sub-path at `(x, y)`, which becomes the current point. */
|
|
22
43
|
moveTo(x: number, y: number): void;
|
|
23
44
|
/** Adds a straight line from the current point to `(x, y)`. */
|
|
@@ -212,12 +233,12 @@ declare class Context {
|
|
|
212
233
|
glyphPath(glyphs: CairoGlyph[]): void;
|
|
213
234
|
/** Measures positioned glyphs with the current font. */
|
|
214
235
|
glyphExtents(glyphs: CairoGlyph[]): TextExtents;
|
|
215
|
-
/** Returns a copy of the current path
|
|
216
|
-
copyPath():
|
|
236
|
+
/** Returns a copy of the current path; `toData()` reads its segments. */
|
|
237
|
+
copyPath(): Path;
|
|
217
238
|
/** Returns a copy of the current path with curves flattened into line segments. */
|
|
218
|
-
copyPathFlat():
|
|
219
|
-
/** Appends
|
|
220
|
-
appendPath(
|
|
239
|
+
copyPathFlat(): Path;
|
|
240
|
+
/** Appends a path returned by `copyPath`, or its segments, to the current path. */
|
|
241
|
+
appendPath(path: Path | PathData[]): void;
|
|
221
242
|
/** Opens a tagged structure, such as a link or a destination, on surfaces that record tags. */
|
|
222
243
|
tagBegin(tagName: string, attributes: string): void;
|
|
223
244
|
/** Closes the tagged structure opened by the matching `tagBegin`. */
|
package/dist/context.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EACR,SAAS,EACT,OAAO,EACP,QAAQ,EACR,SAAS,EACT,UAAU,EACV,OAAO,EACP,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,gBAAgB,EACnB,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EACR,UAAU,EACV,gBAAgB,EAChB,WAAW,EACX,QAAQ,EACR,OAAO,EACP,WAAW,EACX,QAAQ,EACR,KAAK,EACL,aAAa,EACb,WAAW,EACd,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAuBhD,OAAO,EAAe,MAAM,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,IAAI,EAAY,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC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GAAG,IAAI,CAElD;IAED,qEAAqE;IACrE,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAE5B;IAED,yGAAyG;IACzG,cAAc,CACV,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,UAAU,EAAE,EACpB,QAAQ,EAAE,gBAAgB,EAAE,EAC5B,YAAY,EAAE,gBAAgB,GAC/B,IAAI,CAcN;CACJ;AAED,OAAO,EAAE,OAAO,EAAE,CAAC"}
|
package/dist/context.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { alloc, getHandle, read, registerWrapperClass, setHandle, t, wrapHandle, } from "@gtkx/runtime";
|
|
2
|
+
import { releaseHandle } from "@gtkx/runtime/internal";
|
|
2
3
|
import { FontFace } from "./font-face.js";
|
|
3
4
|
import { FontOptions } from "./font-options.js";
|
|
4
|
-
import { bindCairo, cairoGType, CONTEXT_FULL_T, CONTEXT_T, DOUBLE_BUFFER_T, FONT_EXTENTS_T, FONT_FACE_T, FONT_OPTIONS_T, GLYPH_T, MATRIX_T, PATH_T, PATTERN_FULL_T, PATTERN_T, RECTANGLE_LIST_T, SCALED_FONT_T, SURFACE_T, TEXT_CLUSTER_T, TEXT_EXTENTS_T, } from "./lib.js";
|
|
5
|
+
import { bindCairo, cairoGType, CONTEXT_FULL_T, CONTEXT_T, DOUBLE_BUFFER_T, FONT_EXTENTS_T, FONT_FACE_T, FONT_OPTIONS_T, GLYPH_T, MATRIX_T, PATH_FULL_T, PATH_T, PATTERN_FULL_T, PATTERN_T, RECTANGLE_LIST_T, SCALED_FONT_T, SURFACE_T, TEXT_CLUSTER_T, TEXT_EXTENTS_T, } from "./lib.js";
|
|
5
6
|
import { allocMatrix, Matrix } from "./matrix.js";
|
|
6
|
-
import {
|
|
7
|
+
import { Path, wrapPath } from "./path.js";
|
|
7
8
|
import { Pattern } from "./pattern.js";
|
|
8
9
|
import { ScaledFont } from "./scaled-font.js";
|
|
9
10
|
import { checkStatus } from "./status.js";
|
|
@@ -67,11 +68,11 @@ const cairoScale = bindCairo("cairo_scale", POINT_ARGS, t.void);
|
|
|
67
68
|
const cairoRotate = bindCairo("cairo_rotate", [CONTEXT_T, t.float64], t.void);
|
|
68
69
|
const cairoSetOperator = bindCairo("cairo_set_operator", [CONTEXT_T, t.int32], t.void);
|
|
69
70
|
const cairoGetOperator = bindCairo("cairo_get_operator", [CONTEXT_T], t.int32);
|
|
70
|
-
const cairoSelectFontFace = bindCairo("cairo_select_font_face", [CONTEXT_T, t.string("
|
|
71
|
+
const cairoSelectFontFace = bindCairo("cairo_select_font_face", [CONTEXT_T, t.string("borrowed"), t.int32, t.int32], t.void);
|
|
71
72
|
const cairoSetFontSize = bindCairo("cairo_set_font_size", [CONTEXT_T, t.float64], t.void);
|
|
72
|
-
const cairoShowText = bindCairo("cairo_show_text", [CONTEXT_T, t.string("
|
|
73
|
-
const cairoTextPath = bindCairo("cairo_text_path", [CONTEXT_T, t.string("
|
|
74
|
-
const cairoTextExtents = bindCairo("cairo_text_extents", [CONTEXT_T, t.string("
|
|
73
|
+
const cairoShowText = bindCairo("cairo_show_text", [CONTEXT_T, t.string("borrowed")], t.void);
|
|
74
|
+
const cairoTextPath = bindCairo("cairo_text_path", [CONTEXT_T, t.string("borrowed")], t.void);
|
|
75
|
+
const cairoTextExtents = bindCairo("cairo_text_extents", [CONTEXT_T, t.string("borrowed"), TEXT_EXTENTS_T], t.void);
|
|
75
76
|
const cairoFontExtents = bindCairo("cairo_font_extents", [CONTEXT_T, FONT_EXTENTS_T], t.void);
|
|
76
77
|
const cairoSetFontOptions = bindCairo("cairo_set_font_options", [CONTEXT_T, FONT_OPTIONS_T], t.void);
|
|
77
78
|
const cairoGetFontOptions = bindCairo("cairo_get_font_options", [CONTEXT_T, FONT_OPTIONS_T], t.void);
|
|
@@ -118,11 +119,12 @@ const cairoGetScaledFont = bindCairo("cairo_get_scaled_font", [CONTEXT_T], SCALE
|
|
|
118
119
|
const cairoShowGlyphs = bindCairo("cairo_show_glyphs", [CONTEXT_T, GLYPH_T, t.int32], t.void);
|
|
119
120
|
const cairoGlyphPath = bindCairo("cairo_glyph_path", [CONTEXT_T, GLYPH_T, t.int32], t.void);
|
|
120
121
|
const cairoGlyphExtents = bindCairo("cairo_glyph_extents", [CONTEXT_T, GLYPH_T, t.int32, TEXT_EXTENTS_T], t.void);
|
|
121
|
-
const cairoCopyPath = bindCairo("cairo_copy_path", [CONTEXT_T],
|
|
122
|
-
const cairoCopyPathFlat = bindCairo("cairo_copy_path_flat", [CONTEXT_T],
|
|
123
|
-
const
|
|
124
|
-
const
|
|
125
|
-
const
|
|
122
|
+
const cairoCopyPath = bindCairo("cairo_copy_path", [CONTEXT_T], PATH_FULL_T);
|
|
123
|
+
const cairoCopyPathFlat = bindCairo("cairo_copy_path_flat", [CONTEXT_T], PATH_FULL_T);
|
|
124
|
+
const cairoAppendPath = bindCairo("cairo_append_path", [CONTEXT_T, PATH_T], t.void);
|
|
125
|
+
const cairoTagBegin = bindCairo("cairo_tag_begin", [CONTEXT_T, t.string("borrowed"), t.string("borrowed")], t.void);
|
|
126
|
+
const cairoTagEnd = bindCairo("cairo_tag_end", [CONTEXT_T, t.string("borrowed")], t.void);
|
|
127
|
+
const cairoShowTextGlyphs = bindCairo("cairo_show_text_glyphs", [CONTEXT_T, t.string("borrowed"), t.int32, GLYPH_T, t.int32, TEXT_CLUSTER_T, t.int32, t.int32], t.void);
|
|
126
128
|
const readExtents = (handle, boundFn) => {
|
|
127
129
|
const x1Ref = { value: 0 };
|
|
128
130
|
const y1Ref = { value: 0 };
|
|
@@ -152,6 +154,7 @@ const readRectangle = (rects, base) => ({
|
|
|
152
154
|
height: DOUBLE.read(rects, base + 24),
|
|
153
155
|
});
|
|
154
156
|
const readRectangleList = (listHandle) => {
|
|
157
|
+
checkStatus(read(listHandle, t.int32, 0), "clip rectangle list");
|
|
155
158
|
const count = RECTANGLE_LIST_COUNT.read(listHandle);
|
|
156
159
|
if (count === 0) {
|
|
157
160
|
return [];
|
|
@@ -197,6 +200,28 @@ class Context {
|
|
|
197
200
|
checkStatus(cairoStatus(handle), "context");
|
|
198
201
|
setHandle(this, handle);
|
|
199
202
|
}
|
|
203
|
+
/**
|
|
204
|
+
* Drops this context's reference to its `cairo_t` now instead of when the garbage collector
|
|
205
|
+
* reclaims the wrapper, as `cairo_destroy` does in C. Release a context the app obtains itself,
|
|
206
|
+
* such as one from `Gtk.Snapshot.appendCairo` or `Context.create` on a long-lived surface, once
|
|
207
|
+
* drawing is done: until then the context keeps its target alive, and Cairo copies a backing
|
|
208
|
+
* surface into each recording that still holds it when the app draws into it again.
|
|
209
|
+
*
|
|
210
|
+
* A `using` declaration calls this when its block exits:
|
|
211
|
+
*
|
|
212
|
+
* ```ts
|
|
213
|
+
* using cr = snapshot.appendCairo(bounds);
|
|
214
|
+
* cr.setSourceSurface(surface, 0, 0);
|
|
215
|
+
* cr.paint();
|
|
216
|
+
* ```
|
|
217
|
+
*
|
|
218
|
+
* Every later call on the context throws. Calling it again does nothing, and on the context a
|
|
219
|
+
* draw callback receives it only ends that context early, because GTKX releases it when the
|
|
220
|
+
* callback returns anyway.
|
|
221
|
+
*/
|
|
222
|
+
[Symbol.dispose]() {
|
|
223
|
+
releaseHandle(getHandle(this));
|
|
224
|
+
}
|
|
200
225
|
/** Begins a new sub-path at `(x, y)`, which becomes the current point. */
|
|
201
226
|
moveTo(x, y) {
|
|
202
227
|
cairoMoveTo(getHandle(this), x, y);
|
|
@@ -614,17 +639,21 @@ class Context {
|
|
|
614
639
|
cairoGlyphExtents(getHandle(this), allocGlyphBuffer(glyphs), glyphs.length, extents);
|
|
615
640
|
return readTextExtents(extents);
|
|
616
641
|
}
|
|
617
|
-
/** Returns a copy of the current path
|
|
642
|
+
/** Returns a copy of the current path; `toData()` reads its segments. */
|
|
618
643
|
copyPath() {
|
|
619
|
-
return
|
|
644
|
+
return wrapPath(cairoCopyPath(getHandle(this)));
|
|
620
645
|
}
|
|
621
646
|
/** Returns a copy of the current path with curves flattened into line segments. */
|
|
622
647
|
copyPathFlat() {
|
|
623
|
-
return
|
|
648
|
+
return wrapPath(cairoCopyPathFlat(getHandle(this)));
|
|
624
649
|
}
|
|
625
|
-
/** Appends
|
|
626
|
-
appendPath(
|
|
627
|
-
|
|
650
|
+
/** Appends a path returned by `copyPath`, or its segments, to the current path. */
|
|
651
|
+
appendPath(path) {
|
|
652
|
+
if (path instanceof Path) {
|
|
653
|
+
cairoAppendPath(getHandle(this), getHandle(path));
|
|
654
|
+
return;
|
|
655
|
+
}
|
|
656
|
+
for (const segment of path) {
|
|
628
657
|
appendSegment(this, segment);
|
|
629
658
|
}
|
|
630
659
|
}
|