1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
|
// Copyright (c) 2018-2020 Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
//
// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
using System;
using System.Runtime.InteropServices;
using Drawing2D;
namespace Crow.VkvgBackend
{
internal static class NativeMethods
{
const string libvkvg = "vkvg";
#region Device
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern IntPtr vkvg_device_create(SampleCount samples, bool deferredResolve);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern IntPtr vkvg_device_create_from_vk(IntPtr instance, IntPtr phy, IntPtr dev, uint qFamIdx, uint qIndex);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern IntPtr vkvg_device_create_from_vk_multisample(IntPtr inst, IntPtr phy, IntPtr vkdev, uint qFamIdx, uint qIndex, SampleCount samples, bool deferredResolve);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern IntPtr vkvg_device_destroy(IntPtr device);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern IntPtr vkvg_device_reference(IntPtr dev);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern uint vkvg_device_get_reference_count(IntPtr dev);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern void vkvg_device_set_dpy(IntPtr dev, int hdpy, int vdpy);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern void vkvg_device_get_dpy(IntPtr dev, out int hdpy, out int vdpy);
#endregion
#region Context
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern IntPtr vkvg_create(IntPtr surface);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern void vkvg_destroy(IntPtr ctx);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern void vkvg_flush(IntPtr ctx);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern void vkvg_new_path(IntPtr ctx);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern void vkvg_new_sub_path(IntPtr ctx);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern void vkvg_close_path(IntPtr ctx);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern void vkvg_line_to(IntPtr ctx, float x, float y);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern void vkvg_rel_line_to(IntPtr ctx, float x, float y);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern void vkvg_move_to(IntPtr ctx, float x, float y);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern void vkvg_rel_move_to(IntPtr ctx, float x, float y);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern void vkvg_arc(IntPtr ctx, float xc, float yc, float radius, float a1, float a2);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern void vkvg_arc_negative(IntPtr ctx, float xc, float yc, float radius, float a1, float a2);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern void vkvg_curve_to(IntPtr ctx, float x1, float y1, float x2, float y2, float x3, float y3);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern void vkvg_rel_curve_to(IntPtr ctx, float x1, float y1, float x2, float y2, float x3, float y3);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern void vkvg_rectangle(IntPtr ctx, float x, float y, float width, float height);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern void vkvg_scale(IntPtr ctx, float sx, float sy);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern void vkvg_translate(IntPtr ctx, float dx, float dy);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern void vkvg_rotate(IntPtr ctx, float alpha);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern void vkvg_transform(IntPtr ctx, ref Matrix matrix);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern void vkvg_set_matrix(IntPtr ctx, ref Matrix matrix);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern void vkvg_get_matrix(IntPtr ctx, out Matrix matrix);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern void vkvg_identity_matrix(IntPtr ctx);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern void vkvg_stroke(IntPtr ctx);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern void vkvg_stroke_preserve(IntPtr ctx);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern void vkvg_clip(IntPtr ctx);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern void vkvg_clip_preserve(IntPtr ctx);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern void vkvg_reset_clip(IntPtr ctx);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern void vkvg_fill(IntPtr ctx);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern void vkvg_fill_preserve(IntPtr ctx);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern void vkvg_paint(IntPtr ctx);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern void vkvg_set_source_rgba(IntPtr ctx, float r, float g, float b, float a);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern void vkvg_set_line_width(IntPtr ctx, float width);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern void vkvg_set_line_cap(IntPtr ctx, LineCap cap);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern void vkvg_set_line_join(IntPtr ctx, LineJoin join);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern void vkvg_set_operator(IntPtr ctx, Operator op);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern FillRule vkvg_get_fill_rule(IntPtr ctx);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern void vkvg_set_fill_rule(IntPtr ctx, FillRule fr);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern Operator vkvg_get_operator(IntPtr ctx);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern void vkvg_set_source_surface(IntPtr ctx, IntPtr surf, float x, float y);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern void vkvg_set_source(IntPtr ctx, IntPtr pattern);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern void vkvg_font_extents(IntPtr ctx, out FontExtents extents);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern void vkvg_text_extents(IntPtr ctx, byte[] utf8, out TextExtents extents);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern void vkvg_text_extents(IntPtr cr, ref byte utf8, out TextExtents extents);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern void vkvg_select_font_face(IntPtr ctx, string name);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern void vkvg_set_font_size(IntPtr ctx, uint size);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern void vkvg_show_text(IntPtr ctx, byte [] utf8);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern void vkvg_show_text(IntPtr cr, ref byte utf8);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern void vkvg_save(IntPtr ctx);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern void vkvg_restore(IntPtr ctx);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern void vkvg_clear(IntPtr ctx);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern float vkvg_get_line_width(IntPtr ctx);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern LineCap vkvg_get_line_cap(IntPtr ctx);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern LineJoin vkvg_get_line_join(IntPtr ctx);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern IntPtr vkvg_get_source(IntPtr ctx);
[DllImport (libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern void vkvg_set_dash (IntPtr ctx, float[] dashes, uint dashCount, float offset);
[DllImport (libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern void vkvg_path_extents (IntPtr ctx, out float x1, out float y1, out float x2, out float y2);
//void vkvg_set_dash (VkvgContext ctx, const float* dashes, uint32_t num_dashes, float offset);
//void vkvg_get_dash (VkvgContext ctx, const float* dashes, uint32_t* num_dashes, float* offset
[DllImport (libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern IntPtr vkvg_reference(IntPtr ctx);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern uint vkvg_get_reference_count(IntPtr ctx);
#endregion
#region TextRun
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern IntPtr vkvg_text_run_create(IntPtr ctx, byte[] utf8);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern void vkvg_text_run_destroy(IntPtr textRun);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern void vkvg_show_text_run(IntPtr ctx, IntPtr textRun);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern void vkvg_text_run_get_extents(IntPtr textRun, out TextExtents extents);
#endregion
#region Pattern
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern IntPtr vkvg_pattern_create();
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern IntPtr vkvg_pattern_reference(IntPtr pat);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern uint vkvg_pattern_get_reference_count(IntPtr pat);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern IntPtr vkvg_pattern_create_rgba(float r, float g, float b, float a);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern IntPtr vkvg_pattern_create_rgb(float r, float g, float b);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern IntPtr vkvg_pattern_create_for_surface(IntPtr surf);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern IntPtr vkvg_pattern_create_linear(float x0, float y0, float x1, float y1);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern IntPtr vkvg_pattern_create_radial(float cx0, float cy0, float radius0,
float cx1, float cy1, float radius1);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern void vkvg_pattern_destroy(IntPtr pat);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern void vkvg_pattern_add_color_stop(IntPtr pat, float offset, float r, float g, float b, float a);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern void vkvg_pattern_set_extend(IntPtr pat, Extend extend);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern void vkvg_pattern_set_filter(IntPtr pat, Filter filter);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern Extend vkvg_pattern_get_extend(IntPtr pat);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern Filter vkvg_pattern_get_filter(IntPtr pat);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern PatternType vkvg_pattern_get_type(IntPtr pat);
#endregion
#region Matrices
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern void vkvg_matrix_init_identity(out Matrix matrix);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern void vkvg_matrix_init(out Matrix matrix,
float xx, float yx,
float xy, float yy,
float x0, float y0);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern void vkvg_matrix_init_translate(out Matrix matrix, float tx, float ty);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern void vkvg_matrix_init_scale(out Matrix matrix, float sx, float sy);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern void vkvg_matrix_init_rotate(out Matrix matrix, float radians);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern void vkvg_matrix_translate(ref Matrix matrix, float tx, float ty);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern void vkvg_matrix_scale(ref Matrix matrix, float sx, float sy);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern void vkvg_matrix_rotate(ref Matrix matrix, float radians);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern void vkvg_matrix_multiply(out Matrix result, ref Matrix a, ref Matrix b);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern void vkvg_matrix_transform_distance(ref Matrix matrix, ref float dx, ref float dy);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern void vkvg_matrix_transform_point(ref Matrix matrix, ref float x, ref float y);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern void vkvg_matrix_invert(ref Matrix matrix);
#endregion
#region Surface
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern IntPtr vkvg_surface_create(IntPtr device, uint width, uint height);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern IntPtr vkvg_surface_create_from_image(IntPtr dev, string filePath);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern IntPtr vkvg_surface_create_from_svg(IntPtr dev, string filePath);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern IntPtr vkvg_surface_create_from_svg_fragment(IntPtr dev, byte[] filePath);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern IntPtr vkvg_surface_create_from_bitmap(IntPtr dev, ref byte data, uint width, uint height);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern void vkvg_surface_destroy(IntPtr surf);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern IntPtr vkvg_surface_get_vk_image(IntPtr surf);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern int vkvg_surface_get_width(IntPtr surf);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern int vkvg_surface_get_height(IntPtr surf);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern void vkvg_surface_clear(IntPtr surf);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern IntPtr vkvg_surface_reference(IntPtr surf);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern uint vkvg_surface_get_reference_count(IntPtr surf);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern void vkvg_surface_write_to_png(IntPtr surf, [MarshalAs(UnmanagedType.LPStr)]string path);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern void vkvg_surface_write_to_memory(IntPtr surf, IntPtr pBitmap);
#endregion
#region NSVG
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern IntPtr nsvg_load_file(IntPtr dev, string filePath);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern IntPtr nsvg_load(IntPtr dev, ref byte fragment);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern void nsvg_destroy(IntPtr nsvgImage);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern void nsvg_get_size(IntPtr nsvgImage, out int width, out int height);
[DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
internal static extern void vkvg_render_svg(IntPtr ctx, IntPtr nsvgImage, string subId);
#endregion
}
}
|