@gtkx/cairo 1.2.2
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/dist/context.d.ts +229 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +646 -0
- package/dist/context.js.map +1 -0
- package/dist/device.d.ts +21 -0
- package/dist/device.d.ts.map +1 -0
- package/dist/device.js +39 -0
- package/dist/device.js.map +1 -0
- package/dist/enums.d.ts +526 -0
- package/dist/enums.d.ts.map +1 -0
- package/dist/enums.js +482 -0
- package/dist/enums.js.map +1 -0
- package/dist/font-face.d.ts +55 -0
- package/dist/font-face.d.ts.map +1 -0
- package/dist/font-face.js +103 -0
- package/dist/font-face.js.map +1 -0
- package/dist/font-options.d.ts +43 -0
- package/dist/font-options.d.ts.map +1 -0
- package/dist/font-options.js +95 -0
- package/dist/font-options.js.map +1 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +27 -0
- package/dist/index.js.map +1 -0
- package/dist/lib.d.ts +36 -0
- package/dist/lib.d.ts.map +1 -0
- package/dist/lib.js +120 -0
- package/dist/lib.js.map +1 -0
- package/dist/matrix.d.ts +40 -0
- package/dist/matrix.d.ts.map +1 -0
- package/dist/matrix.js +93 -0
- package/dist/matrix.js.map +1 -0
- package/dist/path.d.ts +14 -0
- package/dist/path.d.ts.map +1 -0
- package/dist/path.js +67 -0
- package/dist/path.js.map +1 -0
- package/dist/pattern.d.ts +95 -0
- package/dist/pattern.d.ts.map +1 -0
- package/dist/pattern.js +250 -0
- package/dist/pattern.js.map +1 -0
- package/dist/region.d.ts +59 -0
- package/dist/region.d.ts.map +1 -0
- package/dist/region.js +154 -0
- package/dist/region.js.map +1 -0
- package/dist/scaled-font.d.ts +43 -0
- package/dist/scaled-font.d.ts.map +1 -0
- package/dist/scaled-font.js +156 -0
- package/dist/scaled-font.js.map +1 -0
- package/dist/structs.d.ts +120 -0
- package/dist/structs.d.ts.map +1 -0
- package/dist/structs.js +185 -0
- package/dist/structs.js.map +1 -0
- package/dist/surface.d.ts +98 -0
- package/dist/surface.d.ts.map +1 -0
- package/dist/surface.js +274 -0
- package/dist/surface.js.map +1 -0
- package/dist/text.d.ts +10 -0
- package/dist/text.d.ts.map +1 -0
- package/dist/text.js +45 -0
- package/dist/text.js.map +1 -0
- package/dist/types.d.ts +245 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/version.d.ts +9 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +13 -0
- package/dist/version.js.map +1 -0
- package/package.json +64 -0
- package/src/context.ts +899 -0
- package/src/device.ts +50 -0
- package/src/enums.ts +571 -0
- package/src/font-face.ts +157 -0
- package/src/font-options.ts +142 -0
- package/src/index.ts +28 -0
- package/src/lib.ts +186 -0
- package/src/matrix.ts +135 -0
- package/src/path.ts +87 -0
- package/src/pattern.ts +423 -0
- package/src/region.ts +216 -0
- package/src/scaled-font.ts +268 -0
- package/src/structs.ts +306 -0
- package/src/surface.ts +411 -0
- package/src/text.ts +56 -0
- package/src/types.ts +290 -0
- package/src/version.ts +16 -0
package/src/context.ts
ADDED
|
@@ -0,0 +1,899 @@
|
|
|
1
|
+
import {
|
|
2
|
+
alloc,
|
|
3
|
+
type ExternalObject,
|
|
4
|
+
getHandle,
|
|
5
|
+
type Handle,
|
|
6
|
+
read,
|
|
7
|
+
registerWrapperClass,
|
|
8
|
+
setHandle,
|
|
9
|
+
t,
|
|
10
|
+
wrapHandle,
|
|
11
|
+
write,
|
|
12
|
+
} from "@gtkx/runtime";
|
|
13
|
+
import type {
|
|
14
|
+
Antialias,
|
|
15
|
+
Content,
|
|
16
|
+
FillRule,
|
|
17
|
+
FontSlant,
|
|
18
|
+
FontWeight,
|
|
19
|
+
LineCap,
|
|
20
|
+
LineJoin,
|
|
21
|
+
Operator,
|
|
22
|
+
Status,
|
|
23
|
+
TextClusterFlags,
|
|
24
|
+
} from "./enums.js";
|
|
25
|
+
import type {
|
|
26
|
+
CairoGlyph,
|
|
27
|
+
CairoTextCluster,
|
|
28
|
+
DashPattern,
|
|
29
|
+
Distance,
|
|
30
|
+
Extents,
|
|
31
|
+
FontExtents,
|
|
32
|
+
PathData,
|
|
33
|
+
Point,
|
|
34
|
+
RectangleData,
|
|
35
|
+
TextExtents,
|
|
36
|
+
} from "./types.js";
|
|
37
|
+
import { FontFace } from "./font-face.js";
|
|
38
|
+
import { FontOptions } from "./font-options.js";
|
|
39
|
+
import {
|
|
40
|
+
bindCairo,
|
|
41
|
+
type BoundFunction,
|
|
42
|
+
cairoGType,
|
|
43
|
+
CONTEXT_FULL_T,
|
|
44
|
+
CONTEXT_T,
|
|
45
|
+
DOUBLE_BUFFER_T,
|
|
46
|
+
FONT_EXTENTS_T,
|
|
47
|
+
FONT_FACE_T,
|
|
48
|
+
FONT_OPTIONS_T,
|
|
49
|
+
GLYPH_T,
|
|
50
|
+
MATRIX_T,
|
|
51
|
+
PATH_T,
|
|
52
|
+
PATTERN_FULL_T,
|
|
53
|
+
PATTERN_T,
|
|
54
|
+
RECTANGLE_LIST_T,
|
|
55
|
+
SCALED_FONT_T,
|
|
56
|
+
SURFACE_T,
|
|
57
|
+
TEXT_CLUSTER_T,
|
|
58
|
+
TEXT_EXTENTS_T,
|
|
59
|
+
} from "./lib.js";
|
|
60
|
+
import { allocMatrix, Matrix } from "./matrix.js";
|
|
61
|
+
import { parsePath } from "./path.js";
|
|
62
|
+
import { Pattern } from "./pattern.js";
|
|
63
|
+
import { ScaledFont } from "./scaled-font.js";
|
|
64
|
+
import { Surface } from "./surface.js";
|
|
65
|
+
import {
|
|
66
|
+
allocClusterBuffer,
|
|
67
|
+
allocFontExtents,
|
|
68
|
+
allocGlyphBuffer,
|
|
69
|
+
allocTextExtents,
|
|
70
|
+
readFontExtents,
|
|
71
|
+
readTextExtents,
|
|
72
|
+
} from "./text.js";
|
|
73
|
+
|
|
74
|
+
const CONTEXT_TYPE = cairoGType("cairo_gobject_context_get_type");
|
|
75
|
+
const RECTANGLE_SIZE = 32;
|
|
76
|
+
const RECTANGLE_LIST_COUNT_OFFSET = 16;
|
|
77
|
+
const RECTANGLE_LIST_DATA_OFFSET = 8;
|
|
78
|
+
const POINT_ARGS = [CONTEXT_T, t.float64, t.float64];
|
|
79
|
+
const EXTENTS_ARGS = [CONTEXT_T, t.ref(t.float64), t.ref(t.float64), t.ref(t.float64), t.ref(t.float64)];
|
|
80
|
+
const COORD_ARGS = [CONTEXT_T, t.ref(t.float64), t.ref(t.float64)];
|
|
81
|
+
const CURVE_ARGS = [CONTEXT_T, t.float64, t.float64, t.float64, t.float64, t.float64, t.float64];
|
|
82
|
+
const ARC_ARGS = [CONTEXT_T, t.float64, t.float64, t.float64, t.float64, t.float64];
|
|
83
|
+
const cairoCreate = bindCairo("cairo_create", [SURFACE_T], CONTEXT_FULL_T);
|
|
84
|
+
const cairoMoveTo = bindCairo("cairo_move_to", POINT_ARGS, t.void);
|
|
85
|
+
const cairoLineTo = bindCairo("cairo_line_to", POINT_ARGS, t.void);
|
|
86
|
+
const cairoRelMoveTo = bindCairo("cairo_rel_move_to", POINT_ARGS, t.void);
|
|
87
|
+
const cairoRelLineTo = bindCairo("cairo_rel_line_to", POINT_ARGS, t.void);
|
|
88
|
+
const cairoRelCurveTo = bindCairo("cairo_rel_curve_to", CURVE_ARGS, t.void);
|
|
89
|
+
const cairoCurveTo = bindCairo("cairo_curve_to", CURVE_ARGS, t.void);
|
|
90
|
+
const cairoArc = bindCairo("cairo_arc", ARC_ARGS, t.void);
|
|
91
|
+
const cairoArcNegative = bindCairo("cairo_arc_negative", ARC_ARGS, t.void);
|
|
92
|
+
const cairoRectangle = bindCairo("cairo_rectangle", [CONTEXT_T, t.float64, t.float64, t.float64, t.float64], t.void);
|
|
93
|
+
const cairoClosePath = bindCairo("cairo_close_path", [CONTEXT_T], t.void);
|
|
94
|
+
const cairoNewPath = bindCairo("cairo_new_path", [CONTEXT_T], t.void);
|
|
95
|
+
const cairoNewSubPath = bindCairo("cairo_new_sub_path", [CONTEXT_T], t.void);
|
|
96
|
+
const cairoStroke = bindCairo("cairo_stroke", [CONTEXT_T], t.void);
|
|
97
|
+
const cairoStrokePreserve = bindCairo("cairo_stroke_preserve", [CONTEXT_T], t.void);
|
|
98
|
+
const cairoFill = bindCairo("cairo_fill", [CONTEXT_T], t.void);
|
|
99
|
+
const cairoFillPreserve = bindCairo("cairo_fill_preserve", [CONTEXT_T], t.void);
|
|
100
|
+
const cairoPaint = bindCairo("cairo_paint", [CONTEXT_T], t.void);
|
|
101
|
+
const cairoPaintWithAlpha = bindCairo("cairo_paint_with_alpha", [CONTEXT_T, t.float64], t.void);
|
|
102
|
+
const cairoClip = bindCairo("cairo_clip", [CONTEXT_T], t.void);
|
|
103
|
+
const cairoClipPreserve = bindCairo("cairo_clip_preserve", [CONTEXT_T], t.void);
|
|
104
|
+
const cairoResetClip = bindCairo("cairo_reset_clip", [CONTEXT_T], t.void);
|
|
105
|
+
const cairoSetSourceRgb = bindCairo("cairo_set_source_rgb", [CONTEXT_T, t.float64, t.float64, t.float64], t.void);
|
|
106
|
+
|
|
107
|
+
const cairoSetSourceRgba = bindCairo(
|
|
108
|
+
"cairo_set_source_rgba",
|
|
109
|
+
[CONTEXT_T, t.float64, t.float64, t.float64, t.float64],
|
|
110
|
+
t.void,
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
const cairoSetSource = bindCairo("cairo_set_source", [CONTEXT_T, PATTERN_T], t.void);
|
|
114
|
+
const cairoSetLineWidth = bindCairo("cairo_set_line_width", [CONTEXT_T, t.float64], t.void);
|
|
115
|
+
const cairoGetLineWidth = bindCairo("cairo_get_line_width", [CONTEXT_T], t.float64);
|
|
116
|
+
const cairoSetLineCap = bindCairo("cairo_set_line_cap", [CONTEXT_T, t.int32], t.void);
|
|
117
|
+
const cairoGetLineCap = bindCairo("cairo_get_line_cap", [CONTEXT_T], t.int32);
|
|
118
|
+
const cairoSetLineJoin = bindCairo("cairo_set_line_join", [CONTEXT_T, t.int32], t.void);
|
|
119
|
+
const cairoGetLineJoin = bindCairo("cairo_get_line_join", [CONTEXT_T], t.int32);
|
|
120
|
+
const cairoSetDash = bindCairo("cairo_set_dash", [CONTEXT_T, DOUBLE_BUFFER_T, t.int32, t.float64], t.void);
|
|
121
|
+
const cairoGetDashCount = bindCairo("cairo_get_dash_count", [CONTEXT_T], t.int32);
|
|
122
|
+
const cairoGetDash = bindCairo("cairo_get_dash", [CONTEXT_T, DOUBLE_BUFFER_T, t.ref(t.float64)], t.void);
|
|
123
|
+
const cairoSetMiterLimit = bindCairo("cairo_set_miter_limit", [CONTEXT_T, t.float64], t.void);
|
|
124
|
+
const cairoGetMiterLimit = bindCairo("cairo_get_miter_limit", [CONTEXT_T], t.float64);
|
|
125
|
+
const cairoSetTolerance = bindCairo("cairo_set_tolerance", [CONTEXT_T, t.float64], t.void);
|
|
126
|
+
const cairoGetTolerance = bindCairo("cairo_get_tolerance", [CONTEXT_T], t.float64);
|
|
127
|
+
const cairoSetFillRule = bindCairo("cairo_set_fill_rule", [CONTEXT_T, t.int32], t.void);
|
|
128
|
+
const cairoGetFillRule = bindCairo("cairo_get_fill_rule", [CONTEXT_T], t.int32);
|
|
129
|
+
const cairoSave = bindCairo("cairo_save", [CONTEXT_T], t.void);
|
|
130
|
+
const cairoRestore = bindCairo("cairo_restore", [CONTEXT_T], t.void);
|
|
131
|
+
const cairoTranslate = bindCairo("cairo_translate", POINT_ARGS, t.void);
|
|
132
|
+
const cairoScale = bindCairo("cairo_scale", POINT_ARGS, t.void);
|
|
133
|
+
const cairoRotate = bindCairo("cairo_rotate", [CONTEXT_T, t.float64], t.void);
|
|
134
|
+
const cairoSetOperator = bindCairo("cairo_set_operator", [CONTEXT_T, t.int32], t.void);
|
|
135
|
+
const cairoGetOperator = bindCairo("cairo_get_operator", [CONTEXT_T], t.int32);
|
|
136
|
+
|
|
137
|
+
const cairoSelectFontFace = bindCairo(
|
|
138
|
+
"cairo_select_font_face",
|
|
139
|
+
[CONTEXT_T, t.string("full"), t.int32, t.int32],
|
|
140
|
+
t.void,
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
const cairoSetFontSize = bindCairo("cairo_set_font_size", [CONTEXT_T, t.float64], t.void);
|
|
144
|
+
const cairoShowText = bindCairo("cairo_show_text", [CONTEXT_T, t.string("full")], t.void);
|
|
145
|
+
const cairoTextPath = bindCairo("cairo_text_path", [CONTEXT_T, t.string("full")], t.void);
|
|
146
|
+
const cairoTextExtents = bindCairo("cairo_text_extents", [CONTEXT_T, t.string("full"), TEXT_EXTENTS_T], t.void);
|
|
147
|
+
const cairoFontExtents = bindCairo("cairo_font_extents", [CONTEXT_T, FONT_EXTENTS_T], t.void);
|
|
148
|
+
const cairoSetFontOptions = bindCairo("cairo_set_font_options", [CONTEXT_T, FONT_OPTIONS_T], t.void);
|
|
149
|
+
const cairoGetFontOptions = bindCairo("cairo_get_font_options", [CONTEXT_T, FONT_OPTIONS_T], t.void);
|
|
150
|
+
const cairoSetAntialias = bindCairo("cairo_set_antialias", [CONTEXT_T, t.int32], t.void);
|
|
151
|
+
const cairoGetAntialias = bindCairo("cairo_get_antialias", [CONTEXT_T], t.int32);
|
|
152
|
+
const cairoShowPage = bindCairo("cairo_show_page", [CONTEXT_T], t.void);
|
|
153
|
+
const cairoCopyPage = bindCairo("cairo_copy_page", [CONTEXT_T], t.void);
|
|
154
|
+
const cairoGetTarget = bindCairo("cairo_get_target", [CONTEXT_T], SURFACE_T);
|
|
155
|
+
|
|
156
|
+
const cairoSetSourceSurface = bindCairo(
|
|
157
|
+
"cairo_set_source_surface",
|
|
158
|
+
[CONTEXT_T, SURFACE_T, t.float64, t.float64],
|
|
159
|
+
t.void,
|
|
160
|
+
);
|
|
161
|
+
|
|
162
|
+
const cairoHasCurrentPoint = bindCairo("cairo_has_current_point", [CONTEXT_T], t.boolean);
|
|
163
|
+
const cairoGetCurrentPoint = bindCairo("cairo_get_current_point", COORD_ARGS, t.void);
|
|
164
|
+
const cairoGetSource = bindCairo("cairo_get_source", [CONTEXT_T], PATTERN_T);
|
|
165
|
+
const cairoStrokeExtents = bindCairo("cairo_stroke_extents", EXTENTS_ARGS, t.void);
|
|
166
|
+
const cairoFillExtents = bindCairo("cairo_fill_extents", EXTENTS_ARGS, t.void);
|
|
167
|
+
const cairoClipExtents = bindCairo("cairo_clip_extents", EXTENTS_ARGS, t.void);
|
|
168
|
+
const cairoPathExtents = bindCairo("cairo_path_extents", EXTENTS_ARGS, t.void);
|
|
169
|
+
const cairoInStroke = bindCairo("cairo_in_stroke", POINT_ARGS, t.boolean);
|
|
170
|
+
const cairoInFill = bindCairo("cairo_in_fill", POINT_ARGS, t.boolean);
|
|
171
|
+
const cairoInClip = bindCairo("cairo_in_clip", POINT_ARGS, t.boolean);
|
|
172
|
+
const cairoCopyClipRectangleList = bindCairo("cairo_copy_clip_rectangle_list", [CONTEXT_T], RECTANGLE_LIST_T);
|
|
173
|
+
const cairoRectangleListDestroy = bindCairo("cairo_rectangle_list_destroy", [RECTANGLE_LIST_T], t.void);
|
|
174
|
+
const cairoMask = bindCairo("cairo_mask", [CONTEXT_T, PATTERN_T], t.void);
|
|
175
|
+
const cairoMaskSurface = bindCairo("cairo_mask_surface", [CONTEXT_T, SURFACE_T, t.float64, t.float64], t.void);
|
|
176
|
+
const cairoSetMatrix = bindCairo("cairo_set_matrix", [CONTEXT_T, MATRIX_T], t.void);
|
|
177
|
+
const cairoGetMatrix = bindCairo("cairo_get_matrix", [CONTEXT_T, MATRIX_T], t.void);
|
|
178
|
+
const cairoTransform = bindCairo("cairo_transform", [CONTEXT_T, MATRIX_T], t.void);
|
|
179
|
+
const cairoIdentityMatrix = bindCairo("cairo_identity_matrix", [CONTEXT_T], t.void);
|
|
180
|
+
const cairoUserToDevice = bindCairo("cairo_user_to_device", COORD_ARGS, t.void);
|
|
181
|
+
const cairoUserToDeviceDistance = bindCairo("cairo_user_to_device_distance", COORD_ARGS, t.void);
|
|
182
|
+
const cairoDeviceToUser = bindCairo("cairo_device_to_user", COORD_ARGS, t.void);
|
|
183
|
+
const cairoDeviceToUserDistance = bindCairo("cairo_device_to_user_distance", COORD_ARGS, t.void);
|
|
184
|
+
const cairoStatus = bindCairo("cairo_status", [CONTEXT_T], t.int32);
|
|
185
|
+
const cairoGetReferenceCount = bindCairo("cairo_get_reference_count", [CONTEXT_T], t.int32);
|
|
186
|
+
const cairoPushGroup = bindCairo("cairo_push_group", [CONTEXT_T], t.void);
|
|
187
|
+
const cairoPushGroupWithContent = bindCairo("cairo_push_group_with_content", [CONTEXT_T, t.int32], t.void);
|
|
188
|
+
const cairoPopGroup = bindCairo("cairo_pop_group", [CONTEXT_T], PATTERN_FULL_T);
|
|
189
|
+
const cairoPopGroupToSource = bindCairo("cairo_pop_group_to_source", [CONTEXT_T], t.void);
|
|
190
|
+
const cairoGetGroupTarget = bindCairo("cairo_get_group_target", [CONTEXT_T], SURFACE_T);
|
|
191
|
+
const cairoSetFontFace = bindCairo("cairo_set_font_face", [CONTEXT_T, FONT_FACE_T], t.void);
|
|
192
|
+
const cairoGetFontFace = bindCairo("cairo_get_font_face", [CONTEXT_T], FONT_FACE_T);
|
|
193
|
+
const cairoSetFontMatrix = bindCairo("cairo_set_font_matrix", [CONTEXT_T, MATRIX_T], t.void);
|
|
194
|
+
const cairoGetFontMatrix = bindCairo("cairo_get_font_matrix", [CONTEXT_T, MATRIX_T], t.void);
|
|
195
|
+
const cairoSetScaledFont = bindCairo("cairo_set_scaled_font", [CONTEXT_T, SCALED_FONT_T], t.void);
|
|
196
|
+
const cairoGetScaledFont = bindCairo("cairo_get_scaled_font", [CONTEXT_T], SCALED_FONT_T);
|
|
197
|
+
const cairoShowGlyphs = bindCairo("cairo_show_glyphs", [CONTEXT_T, GLYPH_T, t.int32], t.void);
|
|
198
|
+
const cairoGlyphPath = bindCairo("cairo_glyph_path", [CONTEXT_T, GLYPH_T, t.int32], t.void);
|
|
199
|
+
const cairoGlyphExtents = bindCairo("cairo_glyph_extents", [CONTEXT_T, GLYPH_T, t.int32, TEXT_EXTENTS_T], t.void);
|
|
200
|
+
const cairoCopyPath = bindCairo("cairo_copy_path", [CONTEXT_T], PATH_T);
|
|
201
|
+
const cairoCopyPathFlat = bindCairo("cairo_copy_path_flat", [CONTEXT_T], PATH_T);
|
|
202
|
+
const cairoTagBegin = bindCairo("cairo_tag_begin", [CONTEXT_T, t.string("full"), t.string("full")], t.void);
|
|
203
|
+
const cairoTagEnd = bindCairo("cairo_tag_end", [CONTEXT_T, t.string("full")], t.void);
|
|
204
|
+
|
|
205
|
+
const cairoShowTextGlyphs = bindCairo(
|
|
206
|
+
"cairo_show_text_glyphs",
|
|
207
|
+
[CONTEXT_T, t.string("full"), t.int32, GLYPH_T, t.int32, TEXT_CLUSTER_T, t.int32, t.int32],
|
|
208
|
+
t.void,
|
|
209
|
+
);
|
|
210
|
+
|
|
211
|
+
const readExtents = (handle: ExternalObject<Handle>, boundFn: BoundFunction): Extents => {
|
|
212
|
+
const x1Ref = { value: 0 };
|
|
213
|
+
const y1Ref = { value: 0 };
|
|
214
|
+
const x2Ref = { value: 0 };
|
|
215
|
+
const y2Ref = { value: 0 };
|
|
216
|
+
boundFn(handle, x1Ref, y1Ref, x2Ref, y2Ref);
|
|
217
|
+
|
|
218
|
+
return { x1: x1Ref.value, y1: y1Ref.value, x2: x2Ref.value, y2: y2Ref.value };
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
const transformCoords = (
|
|
222
|
+
handle: ExternalObject<Handle>,
|
|
223
|
+
boundFn: BoundFunction,
|
|
224
|
+
a: number,
|
|
225
|
+
b: number,
|
|
226
|
+
): [number, number] => {
|
|
227
|
+
const aRef = { value: a };
|
|
228
|
+
const bRef = { value: b };
|
|
229
|
+
boundFn(handle, aRef, bRef);
|
|
230
|
+
|
|
231
|
+
return [aRef.value, bRef.value];
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
const allocDashBuffer = (dashes: number[]): ExternalObject<Handle> => {
|
|
235
|
+
const buffer = alloc(dashes.length * 8);
|
|
236
|
+
|
|
237
|
+
for (const [index, dash] of dashes.entries()) {
|
|
238
|
+
write(buffer, t.float64, index * 8, dash);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
return buffer;
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
const readDashes = (buffer: ExternalObject<Handle>, count: number): number[] =>
|
|
245
|
+
Array.from({ length: count }, (_, index) => read(buffer, t.float64, index * 8) as number);
|
|
246
|
+
|
|
247
|
+
const readRectangle = (rects: ExternalObject<Handle>, base: number): RectangleData => ({
|
|
248
|
+
x: read(rects, t.float64, base) as number,
|
|
249
|
+
y: read(rects, t.float64, base + 8) as number,
|
|
250
|
+
width: read(rects, t.float64, base + 16) as number,
|
|
251
|
+
height: read(rects, t.float64, base + 24) as number,
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
const readRectangleList = (listHandle: ExternalObject<Handle>): RectangleData[] => {
|
|
255
|
+
const count = read(listHandle, t.int32, RECTANGLE_LIST_COUNT_OFFSET) as number;
|
|
256
|
+
|
|
257
|
+
if (count === 0) {
|
|
258
|
+
return [];
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
const rects = read(
|
|
262
|
+
listHandle,
|
|
263
|
+
t.struct("borrowed", { size: count * RECTANGLE_SIZE }),
|
|
264
|
+
RECTANGLE_LIST_DATA_OFFSET,
|
|
265
|
+
) as ExternalObject<Handle>;
|
|
266
|
+
|
|
267
|
+
return Array.from({ length: count }, (_, index) => readRectangle(rects, index * RECTANGLE_SIZE));
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
const appendSegment = (ctx: Context, segment: PathData): void => {
|
|
271
|
+
switch (segment.type) {
|
|
272
|
+
case "moveTo": {
|
|
273
|
+
ctx.moveTo(segment.x, segment.y);
|
|
274
|
+
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
case "lineTo": {
|
|
278
|
+
ctx.lineTo(segment.x, segment.y);
|
|
279
|
+
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
case "curveTo": {
|
|
283
|
+
ctx.curveTo(segment.x1, segment.y1, segment.x2, segment.y2, segment.x3, segment.y3);
|
|
284
|
+
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
case "closePath": {
|
|
288
|
+
ctx.closePath();
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* A cairo drawing context (`cairo_t`): the object every drawing operation goes through, holding the current
|
|
295
|
+
* path, source, transformation, clip and font state for one target surface. GTK hands one to draw callbacks
|
|
296
|
+
* and snapshots, and `new Context(surface)` creates one for offscreen drawing.
|
|
297
|
+
*/
|
|
298
|
+
class Context {
|
|
299
|
+
static {
|
|
300
|
+
registerWrapperClass(this, CONTEXT_TYPE);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/** Creates a context drawing onto `target`, the same as `new Context(target)`. */
|
|
304
|
+
static create(target: Surface): Context {
|
|
305
|
+
return new Context(target);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/** GType of `CairoContext`, the boxed type this class is registered under. */
|
|
309
|
+
declare __type__: bigint;
|
|
310
|
+
|
|
311
|
+
/** Creates a context drawing onto `target`. */
|
|
312
|
+
constructor(target: Surface) {
|
|
313
|
+
setHandle(this, cairoCreate(getHandle(target)) as ExternalObject<Handle>);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/** Begins a new sub-path at `(x, y)`, which becomes the current point. */
|
|
317
|
+
moveTo(x: number, y: number): void {
|
|
318
|
+
cairoMoveTo(getHandle(this), x, y);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/** Adds a straight line from the current point to `(x, y)`. */
|
|
322
|
+
lineTo(x: number, y: number): void {
|
|
323
|
+
cairoLineTo(getHandle(this), x, y);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/** Begins a new sub-path offset from the current point by `(dx, dy)`. */
|
|
327
|
+
relMoveTo(dx: number, dy: number): void {
|
|
328
|
+
cairoRelMoveTo(getHandle(this), dx, dy);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/** Adds a straight line from the current point to the point offset by `(dx, dy)`. */
|
|
332
|
+
relLineTo(dx: number, dy: number): void {
|
|
333
|
+
cairoRelLineTo(getHandle(this), dx, dy);
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/** Adds a cubic Bézier curve whose control points and end point are offsets from the current point. */
|
|
337
|
+
relCurveTo(dx1: number, dy1: number, dx2: number, dy2: number, dx3: number, dy3: number): void {
|
|
338
|
+
cairoRelCurveTo(getHandle(this), dx1, dy1, dx2, dy2, dx3, dy3);
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
/** Adds a cubic Bézier curve from the current point through two control points to `(x3, y3)`. */
|
|
342
|
+
curveTo(x1: number, y1: number, x2: number, y2: number, x3: number, y3: number): void {
|
|
343
|
+
cairoCurveTo(getHandle(this), x1, y1, x2, y2, x3, y3);
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/** Adds a circular arc centred on `(xc, yc)`, drawn clockwise from `angle1` to `angle2`. */
|
|
347
|
+
arc(xc: number, yc: number, radius: number, angle1: number, angle2: number): void {
|
|
348
|
+
cairoArc(getHandle(this), xc, yc, radius, angle1, angle2);
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/** Adds a circular arc centred on `(xc, yc)`, drawn counter-clockwise from `angle1` to `angle2`. */
|
|
352
|
+
arcNegative(xc: number, yc: number, radius: number, angle1: number, angle2: number): void {
|
|
353
|
+
cairoArcNegative(getHandle(this), xc, yc, radius, angle1, angle2);
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
/** Adds a closed rectangular sub-path. */
|
|
357
|
+
rectangle(x: number, y: number, width: number, height: number): void {
|
|
358
|
+
cairoRectangle(getHandle(this), x, y, width, height);
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/** Closes the current sub-path with a line back to its start. */
|
|
362
|
+
closePath(): void {
|
|
363
|
+
cairoClosePath(getHandle(this));
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/** Clears the current path. */
|
|
367
|
+
newPath(): void {
|
|
368
|
+
cairoNewPath(getHandle(this));
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/** Begins a new sub-path without a current point, so the next `arc` needs no leading `moveTo`. */
|
|
372
|
+
newSubPath(): void {
|
|
373
|
+
cairoNewSubPath(getHandle(this));
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
/** Strokes the current path with the current line settings and clears it. */
|
|
377
|
+
stroke(): void {
|
|
378
|
+
cairoStroke(getHandle(this));
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
/** Strokes the current path and keeps it. */
|
|
382
|
+
strokePreserve(): void {
|
|
383
|
+
cairoStrokePreserve(getHandle(this));
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
/** Fills the current path with the current fill rule and clears it. */
|
|
387
|
+
fill(): void {
|
|
388
|
+
cairoFill(getHandle(this));
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
/** Fills the current path and keeps it. */
|
|
392
|
+
fillPreserve(): void {
|
|
393
|
+
cairoFillPreserve(getHandle(this));
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
/** Paints the current source everywhere inside the clip. */
|
|
397
|
+
paint(): void {
|
|
398
|
+
cairoPaint(getHandle(this));
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
/** Paints the current source everywhere inside the clip, faded by `alpha`. */
|
|
402
|
+
paintWithAlpha(alpha: number): void {
|
|
403
|
+
cairoPaintWithAlpha(getHandle(this), alpha);
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
/** Intersects the clip with the current path and clears the path. */
|
|
407
|
+
clip(): void {
|
|
408
|
+
cairoClip(getHandle(this));
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
/** Intersects the clip with the current path and keeps the path. */
|
|
412
|
+
clipPreserve(): void {
|
|
413
|
+
cairoClipPreserve(getHandle(this));
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
/** Removes the clip, so drawing reaches the whole surface again. */
|
|
417
|
+
resetClip(): void {
|
|
418
|
+
cairoResetClip(getHandle(this));
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
/** Sets the source to an opaque color with components in the 0 to 1 range. */
|
|
422
|
+
setSourceRgb(red: number, green: number, blue: number): void {
|
|
423
|
+
cairoSetSourceRgb(getHandle(this), red, green, blue);
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
/** Sets the source to a translucent color with components in the 0 to 1 range. */
|
|
427
|
+
setSourceRgba(red: number, green: number, blue: number, alpha: number): void {
|
|
428
|
+
cairoSetSourceRgba(getHandle(this), red, green, blue, alpha);
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
/** Sets the source pattern drawing operations paint with. */
|
|
432
|
+
setSource(pattern: Pattern): void {
|
|
433
|
+
cairoSetSource(getHandle(this), getHandle(pattern));
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
/** Sets the width of stroked lines in user space. */
|
|
437
|
+
setLineWidth(width: number): void {
|
|
438
|
+
cairoSetLineWidth(getHandle(this), width);
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
/** Returns the width of stroked lines. */
|
|
442
|
+
getLineWidth(): number {
|
|
443
|
+
return cairoGetLineWidth(getHandle(this)) as number;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
/** Sets how the ends of stroked lines are drawn. */
|
|
447
|
+
setLineCap(lineCap: LineCap): void {
|
|
448
|
+
cairoSetLineCap(getHandle(this), lineCap);
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
/** Returns how the ends of stroked lines are drawn. */
|
|
452
|
+
getLineCap(): LineCap {
|
|
453
|
+
return cairoGetLineCap(getHandle(this)) as LineCap;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
/** Sets how the corners of stroked lines are joined. */
|
|
457
|
+
setLineJoin(lineJoin: LineJoin): void {
|
|
458
|
+
cairoSetLineJoin(getHandle(this), lineJoin);
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
/** Returns how the corners of stroked lines are joined. */
|
|
462
|
+
getLineJoin(): LineJoin {
|
|
463
|
+
return cairoGetLineJoin(getHandle(this)) as LineJoin;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
/** Sets the dash pattern of strokes as alternating on and off lengths; an empty list draws solid lines. */
|
|
467
|
+
setDash(dashes: number[], offset: number): void {
|
|
468
|
+
cairoSetDash(getHandle(this), allocDashBuffer(dashes), dashes.length, offset);
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
/** Returns how many lengths the dash pattern has, zero for a solid line. */
|
|
472
|
+
getDashCount(): number {
|
|
473
|
+
return cairoGetDashCount(getHandle(this)) as number;
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
/** Returns the dash pattern and its offset. */
|
|
477
|
+
getDash(): DashPattern {
|
|
478
|
+
const count = this.getDashCount();
|
|
479
|
+
|
|
480
|
+
if (count === 0) {
|
|
481
|
+
return { dashes: [], offset: 0 };
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
const buffer = alloc(count * 8);
|
|
485
|
+
const offsetRef = { value: 0 };
|
|
486
|
+
cairoGetDash(getHandle(this), buffer, offsetRef);
|
|
487
|
+
|
|
488
|
+
return { dashes: readDashes(buffer, count), offset: offsetRef.value };
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
/** Sets the miter limit above which a mitered join is drawn beveled. */
|
|
492
|
+
setMiterLimit(limit: number): void {
|
|
493
|
+
cairoSetMiterLimit(getHandle(this), limit);
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
/** Returns the miter limit. */
|
|
497
|
+
getMiterLimit(): number {
|
|
498
|
+
return cairoGetMiterLimit(getHandle(this)) as number;
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
/** Sets the tolerance used when curves are flattened into line segments. */
|
|
502
|
+
setTolerance(tolerance: number): void {
|
|
503
|
+
cairoSetTolerance(getHandle(this), tolerance);
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
/** Returns the tolerance used when curves are flattened. */
|
|
507
|
+
getTolerance(): number {
|
|
508
|
+
return cairoGetTolerance(getHandle(this)) as number;
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
/** Sets the rule deciding which areas a self-intersecting path fills. */
|
|
512
|
+
setFillRule(fillRule: FillRule): void {
|
|
513
|
+
cairoSetFillRule(getHandle(this), fillRule);
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
/** Returns the fill rule. */
|
|
517
|
+
getFillRule(): FillRule {
|
|
518
|
+
return cairoGetFillRule(getHandle(this)) as FillRule;
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
/** Pushes the current drawing state (source, transformation, clip, line and font settings) onto a stack. */
|
|
522
|
+
save(): void {
|
|
523
|
+
cairoSave(getHandle(this));
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
/** Restores the drawing state saved by the matching `save`. */
|
|
527
|
+
restore(): void {
|
|
528
|
+
cairoRestore(getHandle(this));
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
/** Moves the user-space origin by `(tx, ty)`. */
|
|
532
|
+
translate(tx: number, ty: number): void {
|
|
533
|
+
cairoTranslate(getHandle(this), tx, ty);
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
/** Scales user space by `sx` and `sy`. */
|
|
537
|
+
scale(sx: number, sy: number): void {
|
|
538
|
+
cairoScale(getHandle(this), sx, sy);
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
/** Rotates user space by `angle` radians. */
|
|
542
|
+
rotate(angle: number): void {
|
|
543
|
+
cairoRotate(getHandle(this), angle);
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
/** Sets the compositing operator used by drawing operations. */
|
|
547
|
+
setOperator(op: Operator): void {
|
|
548
|
+
cairoSetOperator(getHandle(this), op);
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
/** Returns the compositing operator. */
|
|
552
|
+
getOperator(): Operator {
|
|
553
|
+
return cairoGetOperator(getHandle(this)) as Operator;
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
/** Selects a toy font face by family name, slant and weight. */
|
|
557
|
+
selectFontFace(family: string, slant: FontSlant, weight: FontWeight): void {
|
|
558
|
+
cairoSelectFontFace(getHandle(this), family, slant, weight);
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
/** Sets the font size in user space, replacing the font matrix with a uniform scale. */
|
|
562
|
+
setFontSize(size: number): void {
|
|
563
|
+
cairoSetFontSize(getHandle(this), size);
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
/** Draws `text` with the current font at the current point. */
|
|
567
|
+
showText(text: string): void {
|
|
568
|
+
cairoShowText(getHandle(this), text);
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
/** Adds the outlines of `text` to the current path. */
|
|
572
|
+
textPath(text: string): void {
|
|
573
|
+
cairoTextPath(getHandle(this), text);
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
/** Measures `text` with the current font. */
|
|
577
|
+
textExtents(text: string): TextExtents {
|
|
578
|
+
const extents = allocTextExtents();
|
|
579
|
+
cairoTextExtents(getHandle(this), text, extents);
|
|
580
|
+
|
|
581
|
+
return readTextExtents(extents);
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
/** Returns the metrics of the current font. */
|
|
585
|
+
fontExtents(): FontExtents {
|
|
586
|
+
const extents = allocFontExtents();
|
|
587
|
+
cairoFontExtents(getHandle(this), extents);
|
|
588
|
+
|
|
589
|
+
return readFontExtents(extents);
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
/** Sets the font rendering options merged over the surface's defaults. */
|
|
593
|
+
setFontOptions(options: FontOptions): void {
|
|
594
|
+
cairoSetFontOptions(getHandle(this), getHandle(options));
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
/** Returns a copy of the font rendering options set on the context. */
|
|
598
|
+
getFontOptions(): FontOptions {
|
|
599
|
+
const options = FontOptions.create();
|
|
600
|
+
cairoGetFontOptions(getHandle(this), getHandle(options));
|
|
601
|
+
|
|
602
|
+
return options;
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
/** Sets the antialiasing mode of the rasterizer. */
|
|
606
|
+
setAntialias(antialias: Antialias): void {
|
|
607
|
+
cairoSetAntialias(getHandle(this), antialias);
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
/** Returns the antialiasing mode. */
|
|
611
|
+
getAntialias(): Antialias {
|
|
612
|
+
return cairoGetAntialias(getHandle(this)) as Antialias;
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
/** Emits the current page and clears it, on surfaces that support pages. */
|
|
616
|
+
showPage(): void {
|
|
617
|
+
cairoShowPage(getHandle(this));
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
/** Emits the current page without clearing it, on surfaces that support pages. */
|
|
621
|
+
copyPage(): void {
|
|
622
|
+
cairoCopyPage(getHandle(this));
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
/** Returns the surface the context was created for, wrapped as its concrete class. */
|
|
626
|
+
getTarget(): Surface {
|
|
627
|
+
return wrapHandle(cairoGetTarget(getHandle(this)) as ExternalObject<Handle>, Surface);
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
/** Sets the source to `surface` placed with its origin at `(x, y)` in user space. */
|
|
631
|
+
setSourceSurface(surface: Surface, x: number, y: number): void {
|
|
632
|
+
cairoSetSourceSurface(getHandle(this), getHandle(surface), x, y);
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
/** Returns whether the path has a current point. */
|
|
636
|
+
hasCurrentPoint(): boolean {
|
|
637
|
+
return cairoHasCurrentPoint(getHandle(this)) as boolean;
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
/** Returns the current point of the path, or null when there is none. */
|
|
641
|
+
getCurrentPoint(): Point | null {
|
|
642
|
+
if (!this.hasCurrentPoint()) {
|
|
643
|
+
return null;
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
const xRef = { value: 0 };
|
|
647
|
+
const yRef = { value: 0 };
|
|
648
|
+
cairoGetCurrentPoint(getHandle(this), xRef, yRef);
|
|
649
|
+
|
|
650
|
+
return { x: xRef.value, y: yRef.value };
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
/** Returns the current source pattern, wrapped as its concrete class. */
|
|
654
|
+
getSource(): Pattern {
|
|
655
|
+
return wrapHandle(cairoGetSource(getHandle(this)) as ExternalObject<Handle>, Pattern);
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
/** Returns the bounding box a `stroke` of the current path would cover. */
|
|
659
|
+
strokeExtents(): Extents {
|
|
660
|
+
return readExtents(getHandle(this), cairoStrokeExtents);
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
/** Returns the bounding box a `fill` of the current path would cover. */
|
|
664
|
+
fillExtents(): Extents {
|
|
665
|
+
return readExtents(getHandle(this), cairoFillExtents);
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
/** Returns the bounding box of the current clip. */
|
|
669
|
+
clipExtents(): Extents {
|
|
670
|
+
return readExtents(getHandle(this), cairoClipExtents);
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
/** Returns the bounding box of the current path. */
|
|
674
|
+
pathExtents(): Extents {
|
|
675
|
+
return readExtents(getHandle(this), cairoPathExtents);
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
/** Returns whether `(x, y)` lies inside the area a `stroke` of the current path would cover. */
|
|
679
|
+
inStroke(x: number, y: number): boolean {
|
|
680
|
+
return cairoInStroke(getHandle(this), x, y) as boolean;
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
/** Returns whether `(x, y)` lies inside the area a `fill` of the current path would cover. */
|
|
684
|
+
inFill(x: number, y: number): boolean {
|
|
685
|
+
return cairoInFill(getHandle(this), x, y) as boolean;
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
/** Returns whether `(x, y)` lies inside the current clip. */
|
|
689
|
+
inClip(x: number, y: number): boolean {
|
|
690
|
+
return cairoInClip(getHandle(this), x, y) as boolean;
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
/** Returns the current clip as a list of rectangles in user space. */
|
|
694
|
+
copyClipRectangleList(): RectangleData[] {
|
|
695
|
+
const listHandle = cairoCopyClipRectangleList(getHandle(this)) as ExternalObject<Handle>;
|
|
696
|
+
const rects = readRectangleList(listHandle);
|
|
697
|
+
cairoRectangleListDestroy(listHandle);
|
|
698
|
+
|
|
699
|
+
return rects;
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
/** Paints the current source using the alpha channel of `pattern` as a mask. */
|
|
703
|
+
mask(pattern: Pattern): void {
|
|
704
|
+
cairoMask(getHandle(this), getHandle(pattern));
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
/** Paints the current source using the alpha channel of `surface`, placed at `(x, y)`, as a mask. */
|
|
708
|
+
maskSurface(surface: Surface, x: number, y: number): void {
|
|
709
|
+
cairoMaskSurface(getHandle(this), getHandle(surface), x, y);
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
/** Replaces the transformation from user space to device space. */
|
|
713
|
+
setMatrix(matrix: Matrix): void {
|
|
714
|
+
cairoSetMatrix(getHandle(this), getHandle(matrix));
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
/** Returns the transformation from user space to device space. */
|
|
718
|
+
getMatrix(): Matrix {
|
|
719
|
+
const { handle, matrix } = allocMatrix();
|
|
720
|
+
cairoGetMatrix(getHandle(this), handle);
|
|
721
|
+
|
|
722
|
+
return matrix;
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
/** Applies `matrix` before the existing transformation. */
|
|
726
|
+
transform(matrix: Matrix): void {
|
|
727
|
+
cairoTransform(getHandle(this), getHandle(matrix));
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
/** Resets the transformation to the identity. */
|
|
731
|
+
identityMatrix(): void {
|
|
732
|
+
cairoIdentityMatrix(getHandle(this));
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
/** Maps a point from user space to device space. */
|
|
736
|
+
userToDevice(x: number, y: number): Point {
|
|
737
|
+
const [px, py] = transformCoords(getHandle(this), cairoUserToDevice, x, y);
|
|
738
|
+
|
|
739
|
+
return { x: px, y: py };
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
/** Maps a distance from user space to device space, ignoring translation. */
|
|
743
|
+
userToDeviceDistance(dx: number, dy: number): Distance {
|
|
744
|
+
const [ddx, ddy] = transformCoords(getHandle(this), cairoUserToDeviceDistance, dx, dy);
|
|
745
|
+
|
|
746
|
+
return { dx: ddx, dy: ddy };
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
/** Maps a point from device space to user space. */
|
|
750
|
+
deviceToUser(x: number, y: number): Point {
|
|
751
|
+
const [px, py] = transformCoords(getHandle(this), cairoDeviceToUser, x, y);
|
|
752
|
+
|
|
753
|
+
return { x: px, y: py };
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
/** Maps a distance from device space to user space, ignoring translation. */
|
|
757
|
+
deviceToUserDistance(dx: number, dy: number): Distance {
|
|
758
|
+
const [ddx, ddy] = transformCoords(getHandle(this), cairoDeviceToUserDistance, dx, dy);
|
|
759
|
+
|
|
760
|
+
return { dx: ddx, dy: ddy };
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
/** Returns the error status of the context, `Status.SUCCESS` while every operation so far succeeded. */
|
|
764
|
+
status(): Status {
|
|
765
|
+
return cairoStatus(getHandle(this)) as Status;
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
/** Returns the reference count of the underlying `cairo_t`. */
|
|
769
|
+
getReferenceCount(): number {
|
|
770
|
+
return cairoGetReferenceCount(getHandle(this)) as number;
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
/** Redirects drawing to an intermediate surface until `popGroup` or `popGroupToSource`. */
|
|
774
|
+
pushGroup(): void {
|
|
775
|
+
cairoPushGroup(getHandle(this));
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
/** Redirects drawing to an intermediate surface of the given content. */
|
|
779
|
+
pushGroupWithContent(content: Content): void {
|
|
780
|
+
cairoPushGroupWithContent(getHandle(this), content);
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
/** Ends the current group and returns what was drawn into it as a pattern. */
|
|
784
|
+
popGroup(): Pattern {
|
|
785
|
+
return wrapHandle(cairoPopGroup(getHandle(this)) as ExternalObject<Handle>, Pattern);
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
/** Ends the current group and installs what was drawn into it as the source. */
|
|
789
|
+
popGroupToSource(): void {
|
|
790
|
+
cairoPopGroupToSource(getHandle(this));
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
/** Returns the surface drawing currently goes to: the group surface inside a group, else the target. */
|
|
794
|
+
getGroupTarget(): Surface {
|
|
795
|
+
return wrapHandle(cairoGetGroupTarget(getHandle(this)) as ExternalObject<Handle>, Surface);
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
/** Sets the font face used by text operations. */
|
|
799
|
+
setFontFace(fontFace: FontFace): void {
|
|
800
|
+
cairoSetFontFace(getHandle(this), getHandle(fontFace));
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
/** Returns the current font face, wrapped as its concrete class. */
|
|
804
|
+
getFontFace(): FontFace {
|
|
805
|
+
return wrapHandle(cairoGetFontFace(getHandle(this)) as ExternalObject<Handle>, FontFace);
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
/** Sets the matrix mapping font space to user space, which sizes and shapes the glyphs. */
|
|
809
|
+
setFontMatrix(matrix: Matrix): void {
|
|
810
|
+
cairoSetFontMatrix(getHandle(this), getHandle(matrix));
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
/** Returns the matrix mapping font space to user space. */
|
|
814
|
+
getFontMatrix(): Matrix {
|
|
815
|
+
const { handle, matrix } = allocMatrix();
|
|
816
|
+
cairoGetFontMatrix(getHandle(this), handle);
|
|
817
|
+
|
|
818
|
+
return matrix;
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
/** Replaces the font face, font matrix and font options with those of `scaledFont`. */
|
|
822
|
+
setScaledFont(scaledFont: ScaledFont): void {
|
|
823
|
+
cairoSetScaledFont(getHandle(this), getHandle(scaledFont));
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
/** Returns the scaled font text operations currently use. */
|
|
827
|
+
getScaledFont(): ScaledFont {
|
|
828
|
+
return wrapHandle(cairoGetScaledFont(getHandle(this)) as ExternalObject<Handle>, ScaledFont);
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
/** Draws positioned glyphs with the current font. */
|
|
832
|
+
showGlyphs(glyphs: CairoGlyph[]): void {
|
|
833
|
+
cairoShowGlyphs(getHandle(this), allocGlyphBuffer(glyphs), glyphs.length);
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
/** Adds the outlines of positioned glyphs to the current path. */
|
|
837
|
+
glyphPath(glyphs: CairoGlyph[]): void {
|
|
838
|
+
cairoGlyphPath(getHandle(this), allocGlyphBuffer(glyphs), glyphs.length);
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
/** Measures positioned glyphs with the current font. */
|
|
842
|
+
glyphExtents(glyphs: CairoGlyph[]): TextExtents {
|
|
843
|
+
const extents = allocTextExtents();
|
|
844
|
+
cairoGlyphExtents(getHandle(this), allocGlyphBuffer(glyphs), glyphs.length, extents);
|
|
845
|
+
|
|
846
|
+
return readTextExtents(extents);
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
/** Returns a copy of the current path as segments. */
|
|
850
|
+
copyPath(): PathData[] {
|
|
851
|
+
return parsePath(cairoCopyPath(getHandle(this)) as ExternalObject<Handle>);
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
/** Returns a copy of the current path with curves flattened into line segments. */
|
|
855
|
+
copyPathFlat(): PathData[] {
|
|
856
|
+
return parsePath(cairoCopyPathFlat(getHandle(this)) as ExternalObject<Handle>);
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
/** Appends segments, as returned by `copyPath`, to the current path. */
|
|
860
|
+
appendPath(data: PathData[]): void {
|
|
861
|
+
for (const segment of data) {
|
|
862
|
+
appendSegment(this, segment);
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
/** Opens a tagged structure, such as a link or a destination, on surfaces that record tags. */
|
|
867
|
+
tagBegin(tagName: string, attributes: string): void {
|
|
868
|
+
cairoTagBegin(getHandle(this), tagName, attributes);
|
|
869
|
+
}
|
|
870
|
+
|
|
871
|
+
/** Closes the tagged structure opened by the matching `tagBegin`. */
|
|
872
|
+
tagEnd(tagName: string): void {
|
|
873
|
+
cairoTagEnd(getHandle(this), tagName);
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
/** Draws glyphs together with the text and clusters they came from, so the backend can keep the text. */
|
|
877
|
+
showTextGlyphs(
|
|
878
|
+
text: string,
|
|
879
|
+
glyphs: CairoGlyph[],
|
|
880
|
+
clusters: CairoTextCluster[],
|
|
881
|
+
clusterFlags: TextClusterFlags,
|
|
882
|
+
): void {
|
|
883
|
+
const glyphBuffer = allocGlyphBuffer(glyphs);
|
|
884
|
+
const clusterBuffer = allocClusterBuffer(clusters);
|
|
885
|
+
|
|
886
|
+
cairoShowTextGlyphs(
|
|
887
|
+
getHandle(this),
|
|
888
|
+
text,
|
|
889
|
+
-1,
|
|
890
|
+
glyphBuffer,
|
|
891
|
+
glyphs.length,
|
|
892
|
+
clusterBuffer,
|
|
893
|
+
clusters.length,
|
|
894
|
+
clusterFlags,
|
|
895
|
+
);
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
|
|
899
|
+
export { Context };
|