@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.
Files changed (86) hide show
  1. package/dist/context.d.ts +229 -0
  2. package/dist/context.d.ts.map +1 -0
  3. package/dist/context.js +646 -0
  4. package/dist/context.js.map +1 -0
  5. package/dist/device.d.ts +21 -0
  6. package/dist/device.d.ts.map +1 -0
  7. package/dist/device.js +39 -0
  8. package/dist/device.js.map +1 -0
  9. package/dist/enums.d.ts +526 -0
  10. package/dist/enums.d.ts.map +1 -0
  11. package/dist/enums.js +482 -0
  12. package/dist/enums.js.map +1 -0
  13. package/dist/font-face.d.ts +55 -0
  14. package/dist/font-face.d.ts.map +1 -0
  15. package/dist/font-face.js +103 -0
  16. package/dist/font-face.js.map +1 -0
  17. package/dist/font-options.d.ts +43 -0
  18. package/dist/font-options.d.ts.map +1 -0
  19. package/dist/font-options.js +95 -0
  20. package/dist/font-options.js.map +1 -0
  21. package/dist/index.d.ts +29 -0
  22. package/dist/index.d.ts.map +1 -0
  23. package/dist/index.js +27 -0
  24. package/dist/index.js.map +1 -0
  25. package/dist/lib.d.ts +36 -0
  26. package/dist/lib.d.ts.map +1 -0
  27. package/dist/lib.js +120 -0
  28. package/dist/lib.js.map +1 -0
  29. package/dist/matrix.d.ts +40 -0
  30. package/dist/matrix.d.ts.map +1 -0
  31. package/dist/matrix.js +93 -0
  32. package/dist/matrix.js.map +1 -0
  33. package/dist/path.d.ts +14 -0
  34. package/dist/path.d.ts.map +1 -0
  35. package/dist/path.js +67 -0
  36. package/dist/path.js.map +1 -0
  37. package/dist/pattern.d.ts +95 -0
  38. package/dist/pattern.d.ts.map +1 -0
  39. package/dist/pattern.js +250 -0
  40. package/dist/pattern.js.map +1 -0
  41. package/dist/region.d.ts +59 -0
  42. package/dist/region.d.ts.map +1 -0
  43. package/dist/region.js +154 -0
  44. package/dist/region.js.map +1 -0
  45. package/dist/scaled-font.d.ts +43 -0
  46. package/dist/scaled-font.d.ts.map +1 -0
  47. package/dist/scaled-font.js +156 -0
  48. package/dist/scaled-font.js.map +1 -0
  49. package/dist/structs.d.ts +120 -0
  50. package/dist/structs.d.ts.map +1 -0
  51. package/dist/structs.js +185 -0
  52. package/dist/structs.js.map +1 -0
  53. package/dist/surface.d.ts +98 -0
  54. package/dist/surface.d.ts.map +1 -0
  55. package/dist/surface.js +274 -0
  56. package/dist/surface.js.map +1 -0
  57. package/dist/text.d.ts +10 -0
  58. package/dist/text.d.ts.map +1 -0
  59. package/dist/text.js +45 -0
  60. package/dist/text.js.map +1 -0
  61. package/dist/types.d.ts +245 -0
  62. package/dist/types.d.ts.map +1 -0
  63. package/dist/types.js +2 -0
  64. package/dist/types.js.map +1 -0
  65. package/dist/version.d.ts +9 -0
  66. package/dist/version.d.ts.map +1 -0
  67. package/dist/version.js +13 -0
  68. package/dist/version.js.map +1 -0
  69. package/package.json +64 -0
  70. package/src/context.ts +899 -0
  71. package/src/device.ts +50 -0
  72. package/src/enums.ts +571 -0
  73. package/src/font-face.ts +157 -0
  74. package/src/font-options.ts +142 -0
  75. package/src/index.ts +28 -0
  76. package/src/lib.ts +186 -0
  77. package/src/matrix.ts +135 -0
  78. package/src/path.ts +87 -0
  79. package/src/pattern.ts +423 -0
  80. package/src/region.ts +216 -0
  81. package/src/scaled-font.ts +268 -0
  82. package/src/structs.ts +306 -0
  83. package/src/surface.ts +411 -0
  84. package/src/text.ts +56 -0
  85. package/src/types.ts +290 -0
  86. package/src/version.ts +16 -0
@@ -0,0 +1,59 @@
1
+ import type { RegionOverlap, Status } from "./enums.js";
2
+ import type { RectangleData } from "./types.js";
3
+ import { RectangleInt } from "./structs.js";
4
+ /**
5
+ * A cairo region (`cairo_region_t`): a set of integer rectangles, as GTK uses for clip and damage areas.
6
+ * Set operations modify the region in place.
7
+ */
8
+ declare class Region {
9
+ /** Creates an empty region. */
10
+ static empty(): Region;
11
+ /** Creates a region with the same rectangles as `original`. */
12
+ static copy(original: Region): Region;
13
+ /** Creates a region covering `rect`. */
14
+ static forRectangle(rect: RectangleInt): Region;
15
+ /** Creates a region covering the union of `rects`; an empty list yields an empty region. */
16
+ static createRectangles(rects: RectangleData[]): Region;
17
+ /** GType of `CairoRegion`, the boxed type this class is registered under. */
18
+ __type__: bigint;
19
+ /** Creates a region covering `rect`. */
20
+ constructor(rect: RectangleInt);
21
+ /** Returns a region with the same rectangles as this one. */
22
+ copy(): Region;
23
+ /** Returns the error status of the region, `Status.SUCCESS` when it is usable. */
24
+ status(): Status;
25
+ /** Returns the bounding rectangle of the region. */
26
+ getExtents(): RectangleInt;
27
+ /** Returns how many rectangles make up the region. */
28
+ numRectangles(): number;
29
+ /** Returns the `nth` rectangle of the region, counting from zero. */
30
+ getRectangle(nth: number): RectangleInt;
31
+ /** Returns whether the region covers no area. */
32
+ isEmpty(): boolean;
33
+ /** Returns whether the point `(x, y)` lies inside the region. */
34
+ containsPoint(x: number, y: number): boolean;
35
+ /** Returns whether `rect` lies inside, outside or partly inside the region. */
36
+ containsRectangle(rect: RectangleInt): RegionOverlap;
37
+ /** Returns whether the region covers the same area as `other`. */
38
+ equal(other: Region): boolean;
39
+ /** Moves the region by `dx` and `dy`. */
40
+ translate(dx: number, dy: number): void;
41
+ /** Keeps only the area the region shares with `other`. */
42
+ intersect(other: Region): void;
43
+ /** Keeps only the area the region shares with `rect`. */
44
+ intersectRectangle(rect: RectangleInt): void;
45
+ /** Removes the area of `other` from the region. */
46
+ subtract(other: Region): void;
47
+ /** Removes the area of `rect` from the region. */
48
+ subtractRectangle(rect: RectangleInt): void;
49
+ /** Adds the area of `other` to the region. */
50
+ union(other: Region): void;
51
+ /** Adds the area of `rect` to the region. */
52
+ unionRectangle(rect: RectangleInt): void;
53
+ /** Keeps the area covered by exactly one of the region and `other`. */
54
+ xor(other: Region): void;
55
+ /** Keeps the area covered by exactly one of the region and `rect`. */
56
+ xorRectangle(rect: RectangleInt): void;
57
+ }
58
+ export { Region };
59
+ //# sourceMappingURL=region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AG,IAAI;IAIvC,0DAA0D;IAC1D,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAI9B,yDAAyD;IACzD,kBAAkB,CAAC,IAAI,EAAE,YAAY,GAAG,IAAI;IAI5C,mDAAmD;IACnD,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAI7B,kDAAkD;IAClD,iBAAiB,CAAC,IAAI,EAAE,YAAY,GAAG,IAAI;IAI3C,8CAA8C;IAC9C,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAI1B,6CAA6C;IAC7C,cAAc,CAAC,IAAI,EAAE,YAAY,GAAG,IAAI;IAIxC,uEAAuE;IACvE,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAIxB,sEAAsE;IACtE,YAAY,CAAC,IAAI,EAAE,YAAY,GAAG,IAAI;CAGzC;AAED,OAAO,EAAE,MAAM,EAAE,CAAC"}
package/dist/region.js ADDED
@@ -0,0 +1,154 @@
1
+ import { alloc, getHandle, registerWrapperClass, setHandle, t, wrapHandle, write, } from "@gtkx/runtime";
2
+ import { bindCairo, cairoGType, RECTANGLE_INT_ARRAY_T, RECTANGLE_INT_T, REGION_FULL_T, REGION_T, } from "./lib.js";
3
+ import { RectangleInt } from "./structs.js";
4
+ const REGION_TYPE = cairoGType("cairo_gobject_region_get_type");
5
+ const RECTANGLE_INT_SIZE = 16;
6
+ const BINARY_OP_ARGS = [REGION_T, REGION_T];
7
+ const RECTANGLE_OP_ARGS = [REGION_T, RECTANGLE_INT_T];
8
+ const cairoRegionCreate = bindCairo("cairo_region_create", [], REGION_FULL_T);
9
+ const cairoRegionCreateRectangle = bindCairo("cairo_region_create_rectangle", [RECTANGLE_INT_T], REGION_FULL_T);
10
+ const cairoRegionCreateRectangles = bindCairo("cairo_region_create_rectangles", [RECTANGLE_INT_ARRAY_T, t.int32], REGION_FULL_T);
11
+ const cairoRegionCopy = bindCairo("cairo_region_copy", [REGION_T], REGION_FULL_T);
12
+ const cairoRegionStatus = bindCairo("cairo_region_status", [REGION_T], t.int32);
13
+ const cairoRegionGetExtents = bindCairo("cairo_region_get_extents", [REGION_T, RECTANGLE_INT_T], t.void);
14
+ const cairoRegionNumRectangles = bindCairo("cairo_region_num_rectangles", [REGION_T], t.int32);
15
+ const cairoRegionGetRectangle = bindCairo("cairo_region_get_rectangle", [REGION_T, t.int32, RECTANGLE_INT_T], t.void);
16
+ const cairoRegionIsEmpty = bindCairo("cairo_region_is_empty", [REGION_T], t.boolean);
17
+ const cairoRegionContainsPoint = bindCairo("cairo_region_contains_point", [REGION_T, t.int32, t.int32], t.boolean);
18
+ const cairoRegionContainsRectangle = bindCairo("cairo_region_contains_rectangle", RECTANGLE_OP_ARGS, t.int32);
19
+ const cairoRegionEqual = bindCairo("cairo_region_equal", BINARY_OP_ARGS, t.boolean);
20
+ const cairoRegionTranslate = bindCairo("cairo_region_translate", [REGION_T, t.int32, t.int32], t.void);
21
+ const cairoRegionIntersect = bindCairo("cairo_region_intersect", BINARY_OP_ARGS, t.int32);
22
+ const cairoRegionSubtract = bindCairo("cairo_region_subtract", BINARY_OP_ARGS, t.int32);
23
+ const cairoRegionUnion = bindCairo("cairo_region_union", BINARY_OP_ARGS, t.int32);
24
+ const cairoRegionXor = bindCairo("cairo_region_xor", BINARY_OP_ARGS, t.int32);
25
+ const cairoRegionIntersectRectangle = bindCairo("cairo_region_intersect_rectangle", RECTANGLE_OP_ARGS, t.int32);
26
+ const cairoRegionSubtractRectangle = bindCairo("cairo_region_subtract_rectangle", RECTANGLE_OP_ARGS, t.int32);
27
+ const cairoRegionUnionRectangle = bindCairo("cairo_region_union_rectangle", RECTANGLE_OP_ARGS, t.int32);
28
+ const cairoRegionXorRectangle = bindCairo("cairo_region_xor_rectangle", RECTANGLE_OP_ARGS, t.int32);
29
+ const allocRectangleBuffer = (rects) => {
30
+ const buffer = alloc(rects.length * RECTANGLE_INT_SIZE);
31
+ let offset = 0;
32
+ for (const rect of rects) {
33
+ write(buffer, t.int32, offset, rect.x);
34
+ write(buffer, t.int32, offset + 4, rect.y);
35
+ write(buffer, t.int32, offset + 8, rect.width);
36
+ write(buffer, t.int32, offset + 12, rect.height);
37
+ offset += RECTANGLE_INT_SIZE;
38
+ }
39
+ return buffer;
40
+ };
41
+ const applyRegionOp = (self, boundFn, arg) => {
42
+ boundFn(getHandle(self), getHandle(arg));
43
+ };
44
+ /**
45
+ * A cairo region (`cairo_region_t`): a set of integer rectangles, as GTK uses for clip and damage areas.
46
+ * Set operations modify the region in place.
47
+ */
48
+ class Region {
49
+ static {
50
+ registerWrapperClass(this, REGION_TYPE);
51
+ }
52
+ /** Creates an empty region. */
53
+ static empty() {
54
+ return wrapHandle(cairoRegionCreate(), this);
55
+ }
56
+ /** Creates a region with the same rectangles as `original`. */
57
+ static copy(original) {
58
+ return wrapHandle(cairoRegionCopy(getHandle(original)), this);
59
+ }
60
+ /** Creates a region covering `rect`. */
61
+ static forRectangle(rect) {
62
+ return wrapHandle(cairoRegionCreateRectangle(getHandle(rect)), this);
63
+ }
64
+ /** Creates a region covering the union of `rects`; an empty list yields an empty region. */
65
+ static createRectangles(rects) {
66
+ if (rects.length === 0) {
67
+ return this.empty();
68
+ }
69
+ const buffer = allocRectangleBuffer(rects);
70
+ return wrapHandle(cairoRegionCreateRectangles(buffer, rects.length), this);
71
+ }
72
+ /** Creates a region covering `rect`. */
73
+ constructor(rect) {
74
+ setHandle(this, cairoRegionCreateRectangle(getHandle(rect)));
75
+ }
76
+ /** Returns a region with the same rectangles as this one. */
77
+ copy() {
78
+ return wrapHandle(cairoRegionCopy(getHandle(this)), Region);
79
+ }
80
+ /** Returns the error status of the region, `Status.SUCCESS` when it is usable. */
81
+ status() {
82
+ return cairoRegionStatus(getHandle(this));
83
+ }
84
+ /** Returns the bounding rectangle of the region. */
85
+ getExtents() {
86
+ const rect = new RectangleInt();
87
+ cairoRegionGetExtents(getHandle(this), getHandle(rect));
88
+ return rect;
89
+ }
90
+ /** Returns how many rectangles make up the region. */
91
+ numRectangles() {
92
+ return cairoRegionNumRectangles(getHandle(this));
93
+ }
94
+ /** Returns the `nth` rectangle of the region, counting from zero. */
95
+ getRectangle(nth) {
96
+ const rect = new RectangleInt();
97
+ cairoRegionGetRectangle(getHandle(this), nth, getHandle(rect));
98
+ return rect;
99
+ }
100
+ /** Returns whether the region covers no area. */
101
+ isEmpty() {
102
+ return cairoRegionIsEmpty(getHandle(this));
103
+ }
104
+ /** Returns whether the point `(x, y)` lies inside the region. */
105
+ containsPoint(x, y) {
106
+ return cairoRegionContainsPoint(getHandle(this), x, y);
107
+ }
108
+ /** Returns whether `rect` lies inside, outside or partly inside the region. */
109
+ containsRectangle(rect) {
110
+ return cairoRegionContainsRectangle(getHandle(this), getHandle(rect));
111
+ }
112
+ /** Returns whether the region covers the same area as `other`. */
113
+ equal(other) {
114
+ return cairoRegionEqual(getHandle(this), getHandle(other));
115
+ }
116
+ /** Moves the region by `dx` and `dy`. */
117
+ translate(dx, dy) {
118
+ cairoRegionTranslate(getHandle(this), dx, dy);
119
+ }
120
+ /** Keeps only the area the region shares with `other`. */
121
+ intersect(other) {
122
+ applyRegionOp(this, cairoRegionIntersect, other);
123
+ }
124
+ /** Keeps only the area the region shares with `rect`. */
125
+ intersectRectangle(rect) {
126
+ applyRegionOp(this, cairoRegionIntersectRectangle, rect);
127
+ }
128
+ /** Removes the area of `other` from the region. */
129
+ subtract(other) {
130
+ applyRegionOp(this, cairoRegionSubtract, other);
131
+ }
132
+ /** Removes the area of `rect` from the region. */
133
+ subtractRectangle(rect) {
134
+ applyRegionOp(this, cairoRegionSubtractRectangle, rect);
135
+ }
136
+ /** Adds the area of `other` to the region. */
137
+ union(other) {
138
+ applyRegionOp(this, cairoRegionUnion, other);
139
+ }
140
+ /** Adds the area of `rect` to the region. */
141
+ unionRectangle(rect) {
142
+ applyRegionOp(this, cairoRegionUnionRectangle, rect);
143
+ }
144
+ /** Keeps the area covered by exactly one of the region and `other`. */
145
+ xor(other) {
146
+ applyRegionOp(this, cairoRegionXor, other);
147
+ }
148
+ /** Keeps the area covered by exactly one of the region and `rect`. */
149
+ xorRectangle(rect) {
150
+ applyRegionOp(this, cairoRegionXorRectangle, rect);
151
+ }
152
+ }
153
+ export { Region };
154
+ //# sourceMappingURL=region.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"region.js","sourceRoot":"","sources":["../src/region.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,KAAK,EAEL,SAAS,EAET,oBAAoB,EACpB,SAAS,EACT,CAAC,EACD,UAAU,EACV,KAAK,GACR,MAAM,eAAe,CAAC;AAGvB,OAAO,EACH,SAAS,EAET,UAAU,EACV,qBAAqB,EACrB,eAAe,EACf,aAAa,EACb,QAAQ,GACX,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C,MAAM,WAAW,GAAG,UAAU,CAAC,+BAA+B,CAAC,CAAC;AAChE,MAAM,kBAAkB,GAAG,EAAE,CAAC;AAC9B,MAAM,cAAc,GAAG,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;AAC5C,MAAM,iBAAiB,GAAG,CAAC,QAAQ,EAAE,eAAe,CAAC,CAAC;AACtD,MAAM,iBAAiB,GAAG,SAAS,CAAC,qBAAqB,EAAE,EAAE,EAAE,aAAa,CAAC,CAAC;AAC9E,MAAM,0BAA0B,GAAG,SAAS,CAAC,+BAA+B,EAAE,CAAC,eAAe,CAAC,EAAE,aAAa,CAAC,CAAC;AAEhH,MAAM,2BAA2B,GAAG,SAAS,CACzC,gCAAgC,EAChC,CAAC,qBAAqB,EAAE,CAAC,CAAC,KAAK,CAAC,EAChC,aAAa,CAChB,CAAC;AAEF,MAAM,eAAe,GAAG,SAAS,CAAC,mBAAmB,EAAE,CAAC,QAAQ,CAAC,EAAE,aAAa,CAAC,CAAC;AAClF,MAAM,iBAAiB,GAAG,SAAS,CAAC,qBAAqB,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,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,KAAK,CAAC,CAAY,CAAC;IAC1E,CAAC;IAED,yCAAyC;IACzC,SAAS,CAAC,EAAU,EAAE,EAAU;QAC5B,oBAAoB,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;IAClD,CAAC;IAED,0DAA0D;IAC1D,SAAS,CAAC,KAAa;QACnB,aAAa,CAAC,IAAI,EAAE,oBAAoB,EAAE,KAAK,CAAC,CAAC;IACrD,CAAC;IAED,yDAAyD;IACzD,kBAAkB,CAAC,IAAkB;QACjC,aAAa,CAAC,IAAI,EAAE,6BAA6B,EAAE,IAAI,CAAC,CAAC;IAC7D,CAAC;IAED,mDAAmD;IACnD,QAAQ,CAAC,KAAa;QAClB,aAAa,CAAC,IAAI,EAAE,mBAAmB,EAAE,KAAK,CAAC,CAAC;IACpD,CAAC;IAED,kDAAkD;IAClD,iBAAiB,CAAC,IAAkB;QAChC,aAAa,CAAC,IAAI,EAAE,4BAA4B,EAAE,IAAI,CAAC,CAAC;IAC5D,CAAC;IAED,8CAA8C;IAC9C,KAAK,CAAC,KAAa;QACf,aAAa,CAAC,IAAI,EAAE,gBAAgB,EAAE,KAAK,CAAC,CAAC;IACjD,CAAC;IAED,6CAA6C;IAC7C,cAAc,CAAC,IAAkB;QAC7B,aAAa,CAAC,IAAI,EAAE,yBAAyB,EAAE,IAAI,CAAC,CAAC;IACzD,CAAC;IAED,uEAAuE;IACvE,GAAG,CAAC,KAAa;QACb,aAAa,CAAC,IAAI,EAAE,cAAc,EAAE,KAAK,CAAC,CAAC;IAC/C,CAAC;IAED,sEAAsE;IACtE,YAAY,CAAC,IAAkB;QAC3B,aAAa,CAAC,IAAI,EAAE,uBAAuB,EAAE,IAAI,CAAC,CAAC;IACvD,CAAC;CACJ;AAED,OAAO,EAAE,MAAM,EAAE,CAAC","sourcesContent":["import {\n alloc,\n type ExternalObject,\n getHandle,\n type Handle,\n registerWrapperClass,\n setHandle,\n t,\n wrapHandle,\n write,\n} from \"@gtkx/runtime\";\nimport type { RegionOverlap, Status } from \"./enums.js\";\nimport type { RectangleData } from \"./types.js\";\nimport {\n bindCairo,\n type BoundFunction,\n cairoGType,\n RECTANGLE_INT_ARRAY_T,\n RECTANGLE_INT_T,\n REGION_FULL_T,\n REGION_T,\n} from \"./lib.js\";\nimport { RectangleInt } from \"./structs.js\";\n\nconst REGION_TYPE = cairoGType(\"cairo_gobject_region_get_type\");\nconst RECTANGLE_INT_SIZE = 16;\nconst BINARY_OP_ARGS = [REGION_T, REGION_T];\nconst RECTANGLE_OP_ARGS = [REGION_T, RECTANGLE_INT_T];\nconst cairoRegionCreate = bindCairo(\"cairo_region_create\", [], REGION_FULL_T);\nconst cairoRegionCreateRectangle = bindCairo(\"cairo_region_create_rectangle\", [RECTANGLE_INT_T], REGION_FULL_T);\n\nconst cairoRegionCreateRectangles = bindCairo(\n \"cairo_region_create_rectangles\",\n [RECTANGLE_INT_ARRAY_T, t.int32],\n REGION_FULL_T,\n);\n\nconst cairoRegionCopy = bindCairo(\"cairo_region_copy\", [REGION_T], REGION_FULL_T);\nconst cairoRegionStatus = bindCairo(\"cairo_region_status\", [REGION_T], t.int32);\nconst cairoRegionGetExtents = bindCairo(\"cairo_region_get_extents\", [REGION_T, RECTANGLE_INT_T], t.void);\nconst cairoRegionNumRectangles = bindCairo(\"cairo_region_num_rectangles\", [REGION_T], t.int32);\nconst cairoRegionGetRectangle = bindCairo(\"cairo_region_get_rectangle\", [REGION_T, t.int32, RECTANGLE_INT_T], t.void);\nconst cairoRegionIsEmpty = bindCairo(\"cairo_region_is_empty\", [REGION_T], t.boolean);\nconst cairoRegionContainsPoint = bindCairo(\"cairo_region_contains_point\", [REGION_T, t.int32, t.int32], t.boolean);\nconst cairoRegionContainsRectangle = bindCairo(\"cairo_region_contains_rectangle\", RECTANGLE_OP_ARGS, t.int32);\nconst cairoRegionEqual = bindCairo(\"cairo_region_equal\", BINARY_OP_ARGS, t.boolean);\nconst cairoRegionTranslate = bindCairo(\"cairo_region_translate\", [REGION_T, t.int32, t.int32], t.void);\nconst cairoRegionIntersect = bindCairo(\"cairo_region_intersect\", BINARY_OP_ARGS, t.int32);\nconst cairoRegionSubtract = bindCairo(\"cairo_region_subtract\", BINARY_OP_ARGS, t.int32);\nconst cairoRegionUnion = bindCairo(\"cairo_region_union\", BINARY_OP_ARGS, t.int32);\nconst cairoRegionXor = bindCairo(\"cairo_region_xor\", BINARY_OP_ARGS, t.int32);\nconst cairoRegionIntersectRectangle = bindCairo(\"cairo_region_intersect_rectangle\", RECTANGLE_OP_ARGS, t.int32);\nconst cairoRegionSubtractRectangle = bindCairo(\"cairo_region_subtract_rectangle\", RECTANGLE_OP_ARGS, t.int32);\nconst cairoRegionUnionRectangle = bindCairo(\"cairo_region_union_rectangle\", RECTANGLE_OP_ARGS, t.int32);\nconst cairoRegionXorRectangle = bindCairo(\"cairo_region_xor_rectangle\", RECTANGLE_OP_ARGS, t.int32);\n\nconst allocRectangleBuffer = (rects: RectangleData[]): ExternalObject<Handle> => {\n const buffer = alloc(rects.length * RECTANGLE_INT_SIZE);\n let offset = 0;\n\n for (const rect of rects) {\n write(buffer, t.int32, offset, rect.x);\n write(buffer, t.int32, offset + 4, rect.y);\n write(buffer, t.int32, offset + 8, rect.width);\n write(buffer, t.int32, offset + 12, rect.height);\n offset += RECTANGLE_INT_SIZE;\n }\n\n return buffer;\n};\n\nconst applyRegionOp = (self: object, boundFn: BoundFunction, arg: object): void => {\n boundFn(getHandle(self), getHandle(arg));\n};\n\n/**\n * A cairo region (`cairo_region_t`): a set of integer rectangles, as GTK uses for clip and damage areas.\n * Set operations modify the region in place.\n */\nclass Region {\n static {\n registerWrapperClass(this, REGION_TYPE);\n }\n\n /** Creates an empty region. */\n static empty(): Region {\n return wrapHandle(cairoRegionCreate() as ExternalObject<Handle>, this);\n }\n\n /** Creates a region with the same rectangles as `original`. */\n static copy(original: Region): Region {\n return wrapHandle(cairoRegionCopy(getHandle(original)) as ExternalObject<Handle>, this);\n }\n\n /** Creates a region covering `rect`. */\n static forRectangle(rect: RectangleInt): Region {\n return wrapHandle(cairoRegionCreateRectangle(getHandle(rect)) as ExternalObject<Handle>, this);\n }\n\n /** Creates a region covering the union of `rects`; an empty list yields an empty region. */\n static createRectangles(rects: RectangleData[]): Region {\n if (rects.length === 0) {\n return this.empty();\n }\n\n const buffer = allocRectangleBuffer(rects);\n\n return wrapHandle(cairoRegionCreateRectangles(buffer, rects.length) as ExternalObject<Handle>, this);\n }\n\n /** GType of `CairoRegion`, the boxed type this class is registered under. */\n declare __type__: bigint;\n\n /** Creates a region covering `rect`. */\n constructor(rect: RectangleInt) {\n setHandle(this, cairoRegionCreateRectangle(getHandle(rect)) as ExternalObject<Handle>);\n }\n\n /** Returns a region with the same rectangles as this one. */\n copy(): Region {\n return wrapHandle(cairoRegionCopy(getHandle(this)) as ExternalObject<Handle>, Region);\n }\n\n /** Returns the error status of the region, `Status.SUCCESS` when it is usable. */\n status(): Status {\n return cairoRegionStatus(getHandle(this)) as Status;\n }\n\n /** Returns the bounding rectangle of the region. */\n getExtents(): RectangleInt {\n const rect = new RectangleInt();\n cairoRegionGetExtents(getHandle(this), getHandle(rect));\n\n return rect;\n }\n\n /** Returns how many rectangles make up the region. */\n numRectangles(): number {\n return cairoRegionNumRectangles(getHandle(this)) as number;\n }\n\n /** Returns the `nth` rectangle of the region, counting from zero. */\n getRectangle(nth: number): RectangleInt {\n const rect = new RectangleInt();\n cairoRegionGetRectangle(getHandle(this), nth, getHandle(rect));\n\n return rect;\n }\n\n /** Returns whether the region covers no area. */\n isEmpty(): boolean {\n return cairoRegionIsEmpty(getHandle(this)) as boolean;\n }\n\n /** Returns whether the point `(x, y)` lies inside the region. */\n containsPoint(x: number, y: number): boolean {\n return cairoRegionContainsPoint(getHandle(this), x, y) as boolean;\n }\n\n /** Returns whether `rect` lies inside, outside or partly inside the region. */\n containsRectangle(rect: RectangleInt): RegionOverlap {\n return cairoRegionContainsRectangle(getHandle(this), getHandle(rect)) as RegionOverlap;\n }\n\n /** Returns whether the region covers the same area as `other`. */\n equal(other: Region): boolean {\n return cairoRegionEqual(getHandle(this), getHandle(other)) as boolean;\n }\n\n /** Moves the region by `dx` and `dy`. */\n translate(dx: number, dy: number): void {\n cairoRegionTranslate(getHandle(this), dx, dy);\n }\n\n /** Keeps only the area the region shares with `other`. */\n intersect(other: Region): void {\n applyRegionOp(this, cairoRegionIntersect, other);\n }\n\n /** Keeps only the area the region shares with `rect`. */\n intersectRectangle(rect: RectangleInt): void {\n applyRegionOp(this, cairoRegionIntersectRectangle, rect);\n }\n\n /** Removes the area of `other` from the region. */\n subtract(other: Region): void {\n applyRegionOp(this, cairoRegionSubtract, other);\n }\n\n /** Removes the area of `rect` from the region. */\n subtractRectangle(rect: RectangleInt): void {\n applyRegionOp(this, cairoRegionSubtractRectangle, rect);\n }\n\n /** Adds the area of `other` to the region. */\n union(other: Region): void {\n applyRegionOp(this, cairoRegionUnion, other);\n }\n\n /** Adds the area of `rect` to the region. */\n unionRectangle(rect: RectangleInt): void {\n applyRegionOp(this, cairoRegionUnionRectangle, rect);\n }\n\n /** Keeps the area covered by exactly one of the region and `other`. */\n xor(other: Region): void {\n applyRegionOp(this, cairoRegionXor, other);\n }\n\n /** Keeps the area covered by exactly one of the region and `rect`. */\n xorRectangle(rect: RectangleInt): void {\n applyRegionOp(this, cairoRegionXorRectangle, rect);\n }\n}\n\nexport { Region };\n"]}
@@ -0,0 +1,43 @@
1
+ import type { FontType, Status, TextClusterFlags } from "./enums.js";
2
+ import type { CairoGlyph, CairoTextCluster, FontExtents, TextExtents } from "./types.js";
3
+ import { FontFace } from "./font-face.js";
4
+ import { FontOptions } from "./font-options.js";
5
+ import { Matrix } from "./matrix.js";
6
+ /**
7
+ * A cairo scaled font (`cairo_scaled_font_t`): a font face frozen at a given font matrix, transformation and
8
+ * set of font options, ready to measure and shape text.
9
+ */
10
+ declare class ScaledFont {
11
+ /** Creates a scaled font, the same as `new ScaledFont(fontFace, fontMatrix, ctm, options)`. */
12
+ static create(fontFace: FontFace, fontMatrix: Matrix, ctm: Matrix, options: FontOptions): ScaledFont;
13
+ /** GType of `CairoScaledFont`, the boxed type this class is registered under. */
14
+ __type__: bigint;
15
+ /** Creates a scaled font from a font face, a font matrix, a user-to-device transformation and font options. */
16
+ constructor(fontFace: FontFace, fontMatrix: Matrix, ctm: Matrix, options: FontOptions);
17
+ /** Returns the error status of the scaled font, `Status.SUCCESS` when it is usable. */
18
+ status(): Status;
19
+ /** Returns the metrics of the font. */
20
+ extents(): FontExtents;
21
+ /** Measures `text` with the font. */
22
+ textExtents(text: string): TextExtents;
23
+ /** Measures positioned glyphs with the font. */
24
+ glyphExtents(glyphs: CairoGlyph[]): TextExtents;
25
+ /** Returns the font face the scaled font was created from, wrapped as its concrete class. */
26
+ getFontFace(): FontFace;
27
+ /** Returns a copy of the font options the scaled font was created with. */
28
+ getFontOptions(): FontOptions;
29
+ /** Returns the font matrix the scaled font was created with. */
30
+ getFontMatrix(): Matrix;
31
+ /** Returns the user-to-device transformation the scaled font was created with. */
32
+ getCtm(): Matrix;
33
+ /** Returns the scale matrix: the font matrix multiplied by the transformation, without translation. */
34
+ getScaleMatrix(): Matrix;
35
+ /** Returns the backend the scaled font belongs to. */
36
+ getType(): FontType;
37
+ /** Returns the reference count of the scaled font. */
38
+ getReferenceCount(): number;
39
+ /** Shapes `text` starting at `(x, y)` into glyphs, clusters and the flags describing their order. */
40
+ textToGlyphs(x: number, y: number, text: string): [CairoGlyph[], CairoTextCluster[], TextClusterFlags];
41
+ }
42
+ export { ScaledFont };
43
+ //# sourceMappingURL=scaled-font.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scaled-font.d.ts","sourceRoot":"","sources":["../src/scaled-font.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AACrE,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,WAAW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AAE,CAAC"}
@@ -0,0 +1,156 @@
1
+ import { getHandle, read, registerWrapperClass, setHandle, t, wrapHandle, } from "@gtkx/runtime";
2
+ import { FontFace } from "./font-face.js";
3
+ import { FontOptions } from "./font-options.js";
4
+ import { bindCairo, cairoGType, FONT_EXTENTS_T, FONT_FACE_T, FONT_OPTIONS_T, GLYPH_T, MATRIX_T, SCALED_FONT_FULL_T, SCALED_FONT_T, TEXT_CLUSTER_T, TEXT_EXTENTS_T, } from "./lib.js";
5
+ import { allocMatrix, Matrix } from "./matrix.js";
6
+ import { allocFontExtents, allocGlyphBuffer, allocTextExtents, readFontExtents, readTextExtents } from "./text.js";
7
+ const SCALED_FONT_TYPE = cairoGType("cairo_gobject_scaled_font_get_type");
8
+ const GLYPH_SIZE = 24;
9
+ const CLUSTER_SIZE = 8;
10
+ const cairoScaledFontStatus = bindCairo("cairo_scaled_font_status", [SCALED_FONT_T], t.int32);
11
+ const cairoScaledFontExtents = bindCairo("cairo_scaled_font_extents", [SCALED_FONT_T, FONT_EXTENTS_T], t.void);
12
+ const cairoScaledFontGetFontFace = bindCairo("cairo_scaled_font_get_font_face", [SCALED_FONT_T], FONT_FACE_T);
13
+ const cairoScaledFontGetFontMatrix = bindCairo("cairo_scaled_font_get_font_matrix", [SCALED_FONT_T, MATRIX_T], t.void);
14
+ const cairoScaledFontGetCtm = bindCairo("cairo_scaled_font_get_ctm", [SCALED_FONT_T, MATRIX_T], t.void);
15
+ const cairoScaledFontGetType = bindCairo("cairo_scaled_font_get_type", [SCALED_FONT_T], t.int32);
16
+ const cairoGlyphFree = bindCairo("cairo_glyph_free", [GLYPH_T], t.void);
17
+ const cairoTextClusterFree = bindCairo("cairo_text_cluster_free", [TEXT_CLUSTER_T], t.void);
18
+ const cairoScaledFontCreate = bindCairo("cairo_scaled_font_create", [FONT_FACE_T, MATRIX_T, MATRIX_T, FONT_OPTIONS_T], SCALED_FONT_FULL_T);
19
+ const cairoScaledFontTextExtents = bindCairo("cairo_scaled_font_text_extents", [SCALED_FONT_T, t.string("full"), TEXT_EXTENTS_T], t.void);
20
+ const cairoScaledFontGlyphExtents = bindCairo("cairo_scaled_font_glyph_extents", [SCALED_FONT_T, GLYPH_T, t.int32, TEXT_EXTENTS_T], t.void);
21
+ const cairoScaledFontGetFontOptions = bindCairo("cairo_scaled_font_get_font_options", [SCALED_FONT_T, FONT_OPTIONS_T], t.void);
22
+ const cairoScaledFontGetScaleMatrix = bindCairo("cairo_scaled_font_get_scale_matrix", [SCALED_FONT_T, MATRIX_T], t.void);
23
+ const cairoScaledFontGetReferenceCount = bindCairo("cairo_scaled_font_get_reference_count", [SCALED_FONT_T], t.int32);
24
+ const cairoScaledFontTextToGlyphs = bindCairo("cairo_scaled_font_text_to_glyphs", [
25
+ SCALED_FONT_T,
26
+ t.float64,
27
+ t.float64,
28
+ t.string("full"),
29
+ t.int32,
30
+ t.ref(t.struct("borrowed")),
31
+ t.ref(t.int32),
32
+ t.ref(t.struct("borrowed")),
33
+ t.ref(t.int32),
34
+ t.ref(t.int32),
35
+ ], t.int32);
36
+ const readMatrixVia = (self, boundFn) => {
37
+ const { handle, matrix } = allocMatrix();
38
+ boundFn(getHandle(self), handle);
39
+ return matrix;
40
+ };
41
+ const readGlyphs = (buffer, count) => {
42
+ if (buffer === null) {
43
+ return [];
44
+ }
45
+ return Array.from({ length: count }, (_, index) => {
46
+ const offset = index * GLYPH_SIZE;
47
+ return {
48
+ index: read(buffer, t.uint64, offset),
49
+ x: read(buffer, t.float64, offset + 8),
50
+ y: read(buffer, t.float64, offset + 16),
51
+ };
52
+ });
53
+ };
54
+ const readClusters = (buffer, count) => {
55
+ if (buffer === null) {
56
+ return [];
57
+ }
58
+ return Array.from({ length: count }, (_, index) => {
59
+ const offset = index * CLUSTER_SIZE;
60
+ return {
61
+ numBytes: read(buffer, t.int32, offset),
62
+ numGlyphs: read(buffer, t.int32, offset + 4),
63
+ };
64
+ });
65
+ };
66
+ /**
67
+ * A cairo scaled font (`cairo_scaled_font_t`): a font face frozen at a given font matrix, transformation and
68
+ * set of font options, ready to measure and shape text.
69
+ */
70
+ class ScaledFont {
71
+ static {
72
+ registerWrapperClass(this, SCALED_FONT_TYPE);
73
+ }
74
+ /** Creates a scaled font, the same as `new ScaledFont(fontFace, fontMatrix, ctm, options)`. */
75
+ static create(fontFace, fontMatrix, ctm, options) {
76
+ return new ScaledFont(fontFace, fontMatrix, ctm, options);
77
+ }
78
+ /** Creates a scaled font from a font face, a font matrix, a user-to-device transformation and font options. */
79
+ constructor(fontFace, fontMatrix, ctm, options) {
80
+ const handle = cairoScaledFontCreate(getHandle(fontFace), getHandle(fontMatrix), getHandle(ctm), getHandle(options));
81
+ setHandle(this, handle);
82
+ }
83
+ /** Returns the error status of the scaled font, `Status.SUCCESS` when it is usable. */
84
+ status() {
85
+ return cairoScaledFontStatus(getHandle(this));
86
+ }
87
+ /** Returns the metrics of the font. */
88
+ extents() {
89
+ const ext = allocFontExtents();
90
+ cairoScaledFontExtents(getHandle(this), ext);
91
+ return readFontExtents(ext);
92
+ }
93
+ /** Measures `text` with the font. */
94
+ textExtents(text) {
95
+ const ext = allocTextExtents();
96
+ cairoScaledFontTextExtents(getHandle(this), text, ext);
97
+ return readTextExtents(ext);
98
+ }
99
+ /** Measures positioned glyphs with the font. */
100
+ glyphExtents(glyphs) {
101
+ const buf = allocGlyphBuffer(glyphs);
102
+ const ext = allocTextExtents();
103
+ cairoScaledFontGlyphExtents(getHandle(this), buf, glyphs.length, ext);
104
+ return readTextExtents(ext);
105
+ }
106
+ /** Returns the font face the scaled font was created from, wrapped as its concrete class. */
107
+ getFontFace() {
108
+ return wrapHandle(cairoScaledFontGetFontFace(getHandle(this)), FontFace);
109
+ }
110
+ /** Returns a copy of the font options the scaled font was created with. */
111
+ getFontOptions() {
112
+ const options = FontOptions.create();
113
+ cairoScaledFontGetFontOptions(getHandle(this), getHandle(options));
114
+ return options;
115
+ }
116
+ /** Returns the font matrix the scaled font was created with. */
117
+ getFontMatrix() {
118
+ return readMatrixVia(this, cairoScaledFontGetFontMatrix);
119
+ }
120
+ /** Returns the user-to-device transformation the scaled font was created with. */
121
+ getCtm() {
122
+ return readMatrixVia(this, cairoScaledFontGetCtm);
123
+ }
124
+ /** Returns the scale matrix: the font matrix multiplied by the transformation, without translation. */
125
+ getScaleMatrix() {
126
+ return readMatrixVia(this, cairoScaledFontGetScaleMatrix);
127
+ }
128
+ /** Returns the backend the scaled font belongs to. */
129
+ getType() {
130
+ return cairoScaledFontGetType(getHandle(this));
131
+ }
132
+ /** Returns the reference count of the scaled font. */
133
+ getReferenceCount() {
134
+ return cairoScaledFontGetReferenceCount(getHandle(this));
135
+ }
136
+ /** Shapes `text` starting at `(x, y)` into glyphs, clusters and the flags describing their order. */
137
+ textToGlyphs(x, y, text) {
138
+ const glyphsRef = { value: null };
139
+ const numGlyphsRef = { value: 0 };
140
+ const clustersRef = { value: null };
141
+ const numClustersRef = { value: 0 };
142
+ const clusterFlagsRef = { value: 0 };
143
+ cairoScaledFontTextToGlyphs(getHandle(this), x, y, text, -1, glyphsRef, numGlyphsRef, clustersRef, numClustersRef, clusterFlagsRef);
144
+ const glyphs = readGlyphs(glyphsRef.value, numGlyphsRef.value);
145
+ const clusters = readClusters(clustersRef.value, numClustersRef.value);
146
+ if (glyphsRef.value !== null) {
147
+ cairoGlyphFree(glyphsRef.value);
148
+ }
149
+ if (clustersRef.value !== null) {
150
+ cairoTextClusterFree(clustersRef.value);
151
+ }
152
+ return [glyphs, clusters, clusterFlagsRef.value];
153
+ }
154
+ }
155
+ export { ScaledFont };
156
+ //# sourceMappingURL=scaled-font.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scaled-font.js","sourceRoot":"","sources":["../src/scaled-font.ts"],"names":[],"mappings":"AAAA,OAAO,EAEH,SAAS,EAET,IAAI,EACJ,oBAAoB,EACpB,SAAS,EACT,CAAC,EACD,UAAU,GACb,MAAM,eAAe,CAAC;AAGvB,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAA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EAAE,CAAC","sourcesContent":["import {\n type ExternalObject,\n getHandle,\n type Handle,\n read,\n registerWrapperClass,\n setHandle,\n t,\n wrapHandle,\n} from \"@gtkx/runtime\";\nimport type { FontType, Status, TextClusterFlags } from \"./enums.js\";\nimport type { CairoGlyph, CairoTextCluster, FontExtents, TextExtents } from \"./types.js\";\nimport { FontFace } from \"./font-face.js\";\nimport { FontOptions } from \"./font-options.js\";\nimport {\n bindCairo,\n type BoundFunction,\n cairoGType,\n FONT_EXTENTS_T,\n FONT_FACE_T,\n FONT_OPTIONS_T,\n GLYPH_T,\n MATRIX_T,\n SCALED_FONT_FULL_T,\n SCALED_FONT_T,\n TEXT_CLUSTER_T,\n TEXT_EXTENTS_T,\n} from \"./lib.js\";\nimport { allocMatrix, Matrix } from \"./matrix.js\";\nimport { allocFontExtents, allocGlyphBuffer, allocTextExtents, readFontExtents, readTextExtents } from \"./text.js\";\n\nconst SCALED_FONT_TYPE = cairoGType(\"cairo_gobject_scaled_font_get_type\");\nconst GLYPH_SIZE = 24;\nconst CLUSTER_SIZE = 8;\nconst cairoScaledFontStatus = bindCairo(\"cairo_scaled_font_status\", [SCALED_FONT_T], t.int32);\nconst cairoScaledFontExtents = bindCairo(\"cairo_scaled_font_extents\", [SCALED_FONT_T, FONT_EXTENTS_T], t.void);\nconst cairoScaledFontGetFontFace = bindCairo(\"cairo_scaled_font_get_font_face\", [SCALED_FONT_T], FONT_FACE_T);\nconst cairoScaledFontGetFontMatrix = bindCairo(\"cairo_scaled_font_get_font_matrix\", [SCALED_FONT_T, MATRIX_T], t.void);\nconst cairoScaledFontGetCtm = bindCairo(\"cairo_scaled_font_get_ctm\", [SCALED_FONT_T, MATRIX_T], t.void);\nconst cairoScaledFontGetType = bindCairo(\"cairo_scaled_font_get_type\", [SCALED_FONT_T], t.int32);\nconst cairoGlyphFree = bindCairo(\"cairo_glyph_free\", [GLYPH_T], t.void);\nconst cairoTextClusterFree = bindCairo(\"cairo_text_cluster_free\", [TEXT_CLUSTER_T], t.void);\n\nconst cairoScaledFontCreate = bindCairo(\n \"cairo_scaled_font_create\",\n [FONT_FACE_T, MATRIX_T, MATRIX_T, FONT_OPTIONS_T],\n SCALED_FONT_FULL_T,\n);\n\nconst cairoScaledFontTextExtents = bindCairo(\n \"cairo_scaled_font_text_extents\",\n [SCALED_FONT_T, t.string(\"full\"), TEXT_EXTENTS_T],\n t.void,\n);\n\nconst cairoScaledFontGlyphExtents = bindCairo(\n \"cairo_scaled_font_glyph_extents\",\n [SCALED_FONT_T, GLYPH_T, t.int32, TEXT_EXTENTS_T],\n t.void,\n);\n\nconst cairoScaledFontGetFontOptions = bindCairo(\n \"cairo_scaled_font_get_font_options\",\n [SCALED_FONT_T, FONT_OPTIONS_T],\n t.void,\n);\n\nconst cairoScaledFontGetScaleMatrix = bindCairo(\n \"cairo_scaled_font_get_scale_matrix\",\n [SCALED_FONT_T, MATRIX_T],\n t.void,\n);\n\nconst cairoScaledFontGetReferenceCount = bindCairo(\n \"cairo_scaled_font_get_reference_count\",\n [SCALED_FONT_T],\n t.int32,\n);\n\nconst cairoScaledFontTextToGlyphs = bindCairo(\n \"cairo_scaled_font_text_to_glyphs\",\n [\n SCALED_FONT_T,\n t.float64,\n t.float64,\n t.string(\"full\"),\n t.int32,\n t.ref(t.struct(\"borrowed\")),\n t.ref(t.int32),\n t.ref(t.struct(\"borrowed\")),\n t.ref(t.int32),\n t.ref(t.int32),\n ],\n t.int32,\n);\n\nconst readMatrixVia = (self: ScaledFont, boundFn: BoundFunction): Matrix => {\n const { handle, matrix } = allocMatrix();\n boundFn(getHandle(self), handle);\n\n return matrix;\n};\n\nconst readGlyphs = (buffer: ExternalObject<Handle> | null, count: number): CairoGlyph[] => {\n if (buffer === null) {\n return [];\n }\n\n return Array.from({ length: count }, (_, index) => {\n const offset = index * GLYPH_SIZE;\n\n return {\n index: read(buffer, t.uint64, offset) as number,\n x: read(buffer, t.float64, offset + 8) as number,\n y: read(buffer, t.float64, offset + 16) as number,\n };\n });\n};\n\nconst readClusters = (buffer: ExternalObject<Handle> | null, count: number): CairoTextCluster[] => {\n if (buffer === null) {\n return [];\n }\n\n return Array.from({ length: count }, (_, index) => {\n const offset = index * CLUSTER_SIZE;\n\n return {\n numBytes: read(buffer, t.int32, offset) as number,\n numGlyphs: read(buffer, t.int32, offset + 4) as number,\n };\n });\n};\n\n/**\n * A cairo scaled font (`cairo_scaled_font_t`): a font face frozen at a given font matrix, transformation and\n * set of font options, ready to measure and shape text.\n */\nclass ScaledFont {\n static {\n registerWrapperClass(this, SCALED_FONT_TYPE);\n }\n\n /** Creates a scaled font, the same as `new ScaledFont(fontFace, fontMatrix, ctm, options)`. */\n static create(fontFace: FontFace, fontMatrix: Matrix, ctm: Matrix, options: FontOptions): ScaledFont {\n return new ScaledFont(fontFace, fontMatrix, ctm, options);\n }\n\n /** GType of `CairoScaledFont`, the boxed type this class is registered under. */\n declare __type__: bigint;\n\n /** Creates a scaled font from a font face, a font matrix, a user-to-device transformation and font options. */\n constructor(fontFace: FontFace, fontMatrix: Matrix, ctm: Matrix, options: FontOptions) {\n const handle = cairoScaledFontCreate(\n getHandle(fontFace),\n getHandle(fontMatrix),\n getHandle(ctm),\n getHandle(options),\n ) as ExternalObject<Handle>;\n\n setHandle(this, handle);\n }\n\n /** Returns the error status of the scaled font, `Status.SUCCESS` when it is usable. */\n status(): Status {\n return cairoScaledFontStatus(getHandle(this)) as Status;\n }\n\n /** Returns the metrics of the font. */\n extents(): FontExtents {\n const ext = allocFontExtents();\n cairoScaledFontExtents(getHandle(this), ext);\n\n return readFontExtents(ext);\n }\n\n /** Measures `text` with the font. */\n textExtents(text: string): TextExtents {\n const ext = allocTextExtents();\n cairoScaledFontTextExtents(getHandle(this), text, ext);\n\n return readTextExtents(ext);\n }\n\n /** Measures positioned glyphs with the font. */\n glyphExtents(glyphs: CairoGlyph[]): TextExtents {\n const buf = allocGlyphBuffer(glyphs);\n const ext = allocTextExtents();\n cairoScaledFontGlyphExtents(getHandle(this), buf, glyphs.length, ext);\n\n return readTextExtents(ext);\n }\n\n /** Returns the font face the scaled font was created from, wrapped as its concrete class. */\n getFontFace(): FontFace {\n return wrapHandle(cairoScaledFontGetFontFace(getHandle(this)) as ExternalObject<Handle>, FontFace);\n }\n\n /** Returns a copy of the font options the scaled font was created with. */\n getFontOptions(): FontOptions {\n const options = FontOptions.create();\n cairoScaledFontGetFontOptions(getHandle(this), getHandle(options));\n\n return options;\n }\n\n /** Returns the font matrix the scaled font was created with. */\n getFontMatrix(): Matrix {\n return readMatrixVia(this, cairoScaledFontGetFontMatrix);\n }\n\n /** Returns the user-to-device transformation the scaled font was created with. */\n getCtm(): Matrix {\n return readMatrixVia(this, cairoScaledFontGetCtm);\n }\n\n /** Returns the scale matrix: the font matrix multiplied by the transformation, without translation. */\n getScaleMatrix(): Matrix {\n return readMatrixVia(this, cairoScaledFontGetScaleMatrix);\n }\n\n /** Returns the backend the scaled font belongs to. */\n getType(): FontType {\n return cairoScaledFontGetType(getHandle(this)) as FontType;\n }\n\n /** Returns the reference count of the scaled font. */\n getReferenceCount(): number {\n return cairoScaledFontGetReferenceCount(getHandle(this)) as number;\n }\n\n /** Shapes `text` starting at `(x, y)` into glyphs, clusters and the flags describing their order. */\n textToGlyphs(x: number, y: number, text: string): [CairoGlyph[], CairoTextCluster[], TextClusterFlags] {\n const glyphsRef: { value: ExternalObject<Handle> | null } = { value: null };\n const numGlyphsRef = { value: 0 };\n const clustersRef: { value: ExternalObject<Handle> | null } = { value: null };\n const numClustersRef = { value: 0 };\n const clusterFlagsRef = { value: 0 };\n\n cairoScaledFontTextToGlyphs(\n getHandle(this),\n x,\n y,\n text,\n -1,\n glyphsRef,\n numGlyphsRef,\n clustersRef,\n numClustersRef,\n clusterFlagsRef,\n );\n\n const glyphs = readGlyphs(glyphsRef.value, numGlyphsRef.value);\n const clusters = readClusters(clustersRef.value, numClustersRef.value);\n\n if (glyphsRef.value !== null) {\n cairoGlyphFree(glyphsRef.value);\n }\n\n if (clustersRef.value !== null) {\n cairoTextClusterFree(clustersRef.value);\n }\n\n return [glyphs, clusters, clusterFlagsRef.value as TextClusterFlags];\n }\n}\n\nexport { ScaledFont };\n"]}
@@ -0,0 +1,120 @@
1
+ /** Initial field values for a `Rectangle`; a field left out or set to null keeps zero. */
2
+ type RectangleConstructorProps = {
3
+ /** Horizontal position of the left edge. */
4
+ x?: number | null;
5
+ /** Vertical position of the top edge. */
6
+ y?: number | null;
7
+ /** Width of the rectangle. */
8
+ width?: number | null;
9
+ /** Height of the rectangle. */
10
+ height?: number | null;
11
+ };
12
+ /** Initial field values for a `RectangleInt`; a field left out or set to null keeps zero. */
13
+ type RectangleIntConstructorProps = {
14
+ /** Horizontal position of the left edge. */
15
+ x?: number | null;
16
+ /** Vertical position of the top edge. */
17
+ y?: number | null;
18
+ /** Width of the rectangle. */
19
+ width?: number | null;
20
+ /** Height of the rectangle. */
21
+ height?: number | null;
22
+ };
23
+ /** Initial field values for a `Glyph`; a field left out or set to null keeps zero. */
24
+ type GlyphConstructorProps = {
25
+ /** Index of the glyph in the font. */
26
+ index?: bigint | null;
27
+ /** Horizontal position of the glyph origin. */
28
+ x?: number | null;
29
+ /** Vertical position of the glyph origin. */
30
+ y?: number | null;
31
+ };
32
+ /** Initial field values for a `TextCluster`; a field left out or set to null keeps zero. */
33
+ type TextClusterConstructorProps = {
34
+ /** Number of UTF-8 bytes the cluster covers. */
35
+ numBytes?: number | null;
36
+ /** Number of glyphs the cluster covers. */
37
+ numGlyphs?: number | null;
38
+ };
39
+ /** A rectangle with double-precision edges, as `copyClipRectangleList` and recording surfaces report. */
40
+ declare class Rectangle {
41
+ /** GType of `CairoRectangle`, the boxed type this struct is registered under. */
42
+ __type__: bigint;
43
+ /** Allocates a rectangle, writing the given fields and leaving the others at zero. */
44
+ constructor(props?: RectangleConstructorProps);
45
+ /** Horizontal position of the left edge. */
46
+ get x(): number;
47
+ /** Horizontal position of the left edge. */
48
+ set x(value: number);
49
+ /** Vertical position of the top edge. */
50
+ get y(): number;
51
+ /** Vertical position of the top edge. */
52
+ set y(value: number);
53
+ /** Width of the rectangle. */
54
+ get width(): number;
55
+ /** Width of the rectangle. */
56
+ set width(value: number);
57
+ /** Height of the rectangle. */
58
+ get height(): number;
59
+ /** Height of the rectangle. */
60
+ set height(value: number);
61
+ }
62
+ /** A rectangle with integer edges, as regions and `Surface.mapToImage` use. */
63
+ declare class RectangleInt {
64
+ /** GType of `CairoRectangleInt`, the boxed type this struct is registered under. */
65
+ __type__: bigint;
66
+ /** Allocates a rectangle, writing the given fields and leaving the others at zero. */
67
+ constructor(props?: RectangleIntConstructorProps);
68
+ /** Horizontal position of the left edge. */
69
+ get x(): number;
70
+ /** Horizontal position of the left edge. */
71
+ set x(value: number);
72
+ /** Vertical position of the top edge. */
73
+ get y(): number;
74
+ /** Vertical position of the top edge. */
75
+ set y(value: number);
76
+ /** Width of the rectangle. */
77
+ get width(): number;
78
+ /** Width of the rectangle. */
79
+ set width(value: number);
80
+ /** Height of the rectangle. */
81
+ get height(): number;
82
+ /** Height of the rectangle. */
83
+ set height(value: number);
84
+ }
85
+ /** A `cairo_glyph_t`: one glyph index and where to draw it. */
86
+ declare class Glyph {
87
+ /** GType of `CairoGlyph`, the boxed type this struct is registered under. */
88
+ __type__: bigint;
89
+ /** Allocates a glyph, writing the given fields and leaving the others at zero. */
90
+ constructor(props?: GlyphConstructorProps);
91
+ /** Index of the glyph in the font. */
92
+ get index(): bigint;
93
+ /** Index of the glyph in the font. */
94
+ set index(value: bigint);
95
+ /** Horizontal position of the glyph origin. */
96
+ get x(): number;
97
+ /** Horizontal position of the glyph origin. */
98
+ set x(value: number);
99
+ /** Vertical position of the glyph origin. */
100
+ get y(): number;
101
+ /** Vertical position of the glyph origin. */
102
+ set y(value: number);
103
+ }
104
+ /** A `cairo_text_cluster_t`: how many bytes of text map to how many glyphs. */
105
+ declare class TextCluster {
106
+ /** GType of `CairoTextCluster`, the boxed type this struct is registered under. */
107
+ __type__: bigint;
108
+ /** Allocates a cluster, writing the given fields and leaving the others at zero. */
109
+ constructor(props?: TextClusterConstructorProps);
110
+ /** Number of UTF-8 bytes the cluster covers. */
111
+ get numBytes(): number;
112
+ /** Number of UTF-8 bytes the cluster covers. */
113
+ set numBytes(value: number);
114
+ /** Number of glyphs the cluster covers. */
115
+ get numGlyphs(): number;
116
+ /** Number of glyphs the cluster covers. */
117
+ set numGlyphs(value: number);
118
+ }
119
+ export { Glyph, type GlyphConstructorProps, Rectangle, type RectangleConstructorProps, RectangleInt, type RectangleIntConstructorProps, TextCluster, type TextClusterConstructorProps, };
120
+ //# sourceMappingURL=structs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"structs.d.ts","sourceRoot":"","sources":["../src/structs.ts"],"names":[],"mappings":"AAgBA,0FAA0F;AAC1F,KAAK,yBAAyB,GAAG;IAC7B,4CAA4C;IAC5C,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAClB,yCAAyC;IACzC,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAClB,8BAA8B;IAC9B,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,+BAA+B;IAC/B,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B,CAAC;AAEF,6FAA6F;AAC7F,KAAK,4BAA4B,GAAG;IAChC,4CAA4C;IAC5C,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAClB,yCAAyC;IACzC,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAClB,8BAA8B;IAC9B,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,+BAA+B;IAC/B,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B,CAAC;AAEF,sFAAsF;AACtF,KAAK,qBAAqB,GAAG;IACzB,sCAAsC;IACtC,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,+CAA+C;IAC/C,CAAC,CAAC,EAA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