-
Notifications
You must be signed in to change notification settings - Fork 6
/
nanovg.ts
1378 lines (1220 loc) · 62.9 KB
/
nanovg.ts
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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import * as Bind from "./bind-nanovg";
export { Bind };
let bind: Bind.Module;
export default async function (value?: Partial<Bind.Module>): Promise<void> {
return new Promise<void>((resolve: () => void) => {
Bind.default(value).then((value: Bind.Module): void => {
bind = value;
resolve();
});
});
}
export { bind };
export const NVG_PI = 3.14159265358979323846264338327;
// typedef struct NVGcontext NVGcontext;
export type NVGcontext = Bind.NVGcontext;
// static float nvg__sqrtf(float a) { return sqrtf(a); }
function nvg__modf(a: number, b: number): number { return a % b; }
// static float nvg__sinf(float a) { return sinf(a); }
// static float nvg__cosf(float a) { return cosf(a); }
// static float nvg__tanf(float a) { return tanf(a); }
// static float nvg__atan2f(float a,float b) { return atan2f(a, b); }
// static float nvg__acosf(float a) { return acosf(a); }
// static int nvg__mini(int a, int b) { return a < b ? a : b; }
// static int nvg__maxi(int a, int b) { return a > b ? a : b; }
// static int nvg__clampi(int a, int mn, int mx) { return a < mn ? mn : (a > mx ? mx : a); }
// static float nvg__minf(float a, float b) { return a < b ? a : b; }
// static float nvg__maxf(float a, float b) { return a > b ? a : b; }
// static float nvg__absf(float a) { return a >= 0.0f ? a : -a; }
// static float nvg__signf(float a) { return a >= 0.0f ? 1.0f : -1.0f; }
function nvg__clampf(a: number, mn: number, mx: number): number { return a < mn ? mn : mx < a ? mx : a; }
// static float nvg__cross(float dx0, float dy0, float dx1, float dy1) { return dx1*dy0 - dx0*dy1; }
// struct NVGcolor {
// union {
// float rgba[4];
// struct {
// float r,g,b,a;
// };
// };
// };
// typedef struct NVGcolor NVGcolor;
export class NVGcolor implements Bind.NVGcolor {
constructor(public rgba: Float32Array = new Float32Array(4)) {
}
get r(): number { return this.rgba[0]; } set r(value: number) { this.rgba[0] = value; }
get g(): number { return this.rgba[1]; } set g(value: number) { this.rgba[1] = value; }
get b(): number { return this.rgba[2]; } set b(value: number) { this.rgba[2] = value; }
get a(): number { return this.rgba[3]; } set a(value: number) { this.rgba[3] = value; }
}
// struct NVGpaint {
// float xform[6];
// float extent[2];
// float radius;
// float feather;
// NVGcolor innerColor;
// NVGcolor outerColor;
// int image;
// };
// typedef struct NVGpaint NVGpaint;
export class NVGpaint implements Bind.NVGpaint {
readonly xform: Float32Array;
readonly extent: Float32Array;
readonly _radius: Float32Array;
readonly _feather: Float32Array;
readonly innerColor: NVGcolor;
readonly outerColor: NVGcolor;
image: number = 0;
constructor(_array = new Float32Array(18)) {
this.xform = new Float32Array(_array.subarray(0, 6));
this.extent = new Float32Array(_array.subarray(6, 8));
this._radius = new Float32Array(_array.subarray(8, 9));
this._feather = new Float32Array(_array.subarray(9, 10));
this.innerColor = new NVGcolor(new Float32Array(_array.subarray(10, 14)));
this.outerColor = new NVGcolor(new Float32Array(_array.subarray(14, 18)));
}
get radius(): number { return this._radius[0]; }
set radius(value: number) { this._radius[0] = value; }
get feather(): number { return this._feather[0]; }
set feather(value: number) { this._feather[0] = value; }
}
export enum NVGwinding {
CCW = 1, // Winding for solid shapes
CW = 2, // Winding for holes
}
export enum NVGsolidity {
SOLID = 1, // CCW
HOLE = 2, // CW
}
export enum NVGlineCap {
BUTT,
ROUND,
NVG_SQUARE,
BEVEL,
MITER,
}
export enum NVGalign {
// Horizontal align
LEFT = 1 << 0, // Default, align text horizontally to left.
CENTER = 1 << 1, // Align text horizontally to center.
RIGHT = 1 << 2, // Align text horizontally to right.
// Vertical align
TOP = 1 << 3, // Align text vertically to top.
MIDDLE = 1 << 4, // Align text vertically to middle.
BOTTOM = 1 << 5, // Align text vertically to bottom.
BASELINE = 1 << 6, // Default, align text vertically to baseline.
}
export enum NVGblendFactor {
ZERO = 1 << 0,
ONE = 1 << 1,
SRC_COLOR = 1 << 2,
ONE_MINUS_SRC_COLOR = 1 << 3,
DST_COLOR = 1 << 4,
ONE_MINUS_DST_COLOR = 1 << 5,
SRC_ALPHA = 1 << 6,
ONE_MINUS_SRC_ALPHA = 1 << 7,
DST_ALPHA = 1 << 8,
ONE_MINUS_DST_ALPHA = 1 << 9,
SRC_ALPHA_SATURATE = 1 << 10,
}
export enum NVGcompositeOperation {
SOURCE_OVER,
SOURCE_IN,
SOURCE_OUT,
ATOP,
DESTINATION_OVER,
DESTINATION_IN,
DESTINATION_OUT,
DESTINATION_ATOP,
LIGHTER,
COPY,
XOR,
}
// struct NVGcompositeOperationState {
// int srcRGB;
// int dstRGB;
// int srcAlpha;
// int dstAlpha;
// };
// typedef struct NVGcompositeOperationState NVGcompositeOperationState;
export class NVGcompositeOperationState implements Bind.NVGcompositeOperationState {
srcRGB: NVGblendFactor = NVGblendFactor.ONE;
dstRGB: NVGblendFactor = NVGblendFactor.ZERO;
srcAlpha: NVGblendFactor = NVGblendFactor.ONE;
dstAlpha: NVGblendFactor = NVGblendFactor.ZERO;
}
// struct NVGglyphPosition {
// const char* str; // Position of the glyph in the input string.
// float x; // The x-coordinate of the logical glyph position.
// float minx, maxx; // The bounds of the glyph shape.
// };
// typedef struct NVGglyphPosition NVGglyphPosition;
export class NVGglyphPosition implements Bind.NVGglyphPosition {
str: number = 0;
x: number = 0.0;
minx: number = 0.0;
maxx: number = 0.0;
}
// struct NVGtextRow {
// const char* start; // Pointer to the input text where the row starts.
// const char* end; // Pointer to the input text where the row ends (one past the last character).
// const char* next; // Pointer to the beginning of the next row.
// float width; // Logical width of the row.
// float minx, maxx; // Actual bounds of the row. Logical with and bounds can differ because of kerning and some parts over extending.
// };
// typedef struct NVGtextRow NVGtextRow;
export class NVGtextRow implements Bind.NVGtextRow {
start: number = 0;
end: number = 0;
next: number = 0;
width: number = 0.0;
minx: number = 0.0;
maxx: number = 0.0;
}
export enum NVGimageFlags {
NONE = 0,
GENERATE_MIPMAPS = 1 << 0, // Generate mipmaps during creation of the image.
REPEATX = 1 << 1, // Repeat image in X direction.
REPEATY = 1 << 2, // Repeat image in Y direction.
FLIPY = 1 << 3, // Flips (inverses) image in Y direction when rendered.
PREMULTIPLIED = 1 << 4, // Image data has premultiplied alpha.
NEAREST = 1 << 5, // Image interpolation is Nearest instead Linear
};
// Begin drawing a new frame
// Calls to nanovg drawing API should be wrapped in nvgBeginFrame() & nvgEndFrame()
// nvgBeginFrame() defines the size of the window to render to in relation currently
// set viewport (i.e. glViewport on GL backends). Device pixel ration allows to
// control the rendering on Hi-DPI devices.
// For example, GLFW returns two dimension for an opened window: window size and
// frame buffer size. In that case you would set windowWidth/Height to the window size
// devicePixelRatio to: frameBufferWidth / windowWidth.
// void nvgBeginFrame(NVGcontext* ctx, float windowWidth, float windowHeight, float devicePixelRatio);
export function nvgBeginFrame(ctx: NVGcontext, windowWidth: number, windowHeight: number, devicePixelRatio: number): void {
bind.nvgBeginFrame(ctx, windowWidth, windowHeight, devicePixelRatio);
}
// Cancels drawing the current frame.
// void nvgCancelFrame(NVGcontext* ctx);
export function nvgCancelFrame(ctx: NVGcontext): void {
bind.nvgCancelFrame(ctx);
}
// Ends drawing flushing remaining render state.
// void nvgEndFrame(NVGcontext* ctx);
export function nvgEndFrame(ctx: NVGcontext): void {
bind.nvgEndFrame(ctx);
}
//
// Composite operation
//
// The composite operations in NanoVG are modeled after HTML Canvas API, and
// the blend func is based on OpenGL (see corresponding manuals for more info).
// The colors in the blending state have premultiplied alpha.
// Sets the composite operation. The op parameter should be one of NVGcompositeOperation.
// void nvgGlobalCompositeOperation(NVGcontext* ctx, int op);
export function nvgGlobalCompositeOperation(ctx: NVGcontext, op: NVGcompositeOperation): void {
bind.nvgGlobalCompositeOperation(ctx, op);
}
// Sets the composite operation with custom pixel arithmetic. The parameters should be one of NVGblendFactor.
// void nvgGlobalCompositeBlendFunc(NVGcontext* ctx, int sfactor, int dfactor);
export function nvgGlobalCompositeBlendFunc(ctx: NVGcontext, sfactor: NVGblendFactor, dfactor: NVGblendFactor): void {
bind.nvgGlobalCompositeBlendFunc(ctx, sfactor, dfactor);
}
// Sets the composite operation with custom pixel arithmetic for RGB and alpha components separately. The parameters should be one of NVGblendFactor.
// void nvgGlobalCompositeBlendFuncSeparate(NVGcontext* ctx, int srcRGB, int dstRGB, int srcAlpha, int dstAlpha);
export function nvgGlobalCompositeBlendFuncSeparate(ctx: NVGcontext, srcRGB: NVGblendFactor, dstRGB: NVGblendFactor, srcAlpha: NVGblendFactor, dstAlpha: NVGblendFactor): void {
bind.nvgGlobalCompositeBlendFuncSeparate(ctx, srcRGB, dstRGB, srcAlpha, dstAlpha);
}
//
// Color utils
//
// Colors in NanoVG are stored as unsigned ints in ABGR format.
// Returns a color value from red, green, blue values. Alpha will be set to 255 (1.0f).
// NVGcolor nvgRGB(unsigned char r, unsigned char g, unsigned char b);
export function nvgRGB(r: number, g: number, b: number, out: NVGcolor = new NVGcolor()): NVGcolor {
return nvgRGBA(r, g, b, 255, out);
}
// Returns a color value from red, green, blue values. Alpha will be set to 1.0f.
// NVGcolor nvgRGBf(float r, float g, float b);
export function nvgRGBf(r: number, g: number, b: number, out: NVGcolor = new NVGcolor()): NVGcolor {
return nvgRGBAf(r, g, b, 1.0, out);
}
// Returns a color value from red, green, blue and alpha values.
// NVGcolor nvgRGBA(unsigned char r, unsigned char g, unsigned char b, unsigned char a);
export function nvgRGBA(r: number, g: number, b: number, a: number, out: NVGcolor = new NVGcolor()): NVGcolor {
out.r = r / 255.0;
out.g = g / 255.0;
out.b = b / 255.0;
out.a = a / 255.0;
return out;
}
// Returns a color value from red, green, blue and alpha values.
// NVGcolor nvgRGBAf(float r, float g, float b, float a);
export function nvgRGBAf(r: number, g: number, b: number, a: number, out: NVGcolor = new NVGcolor()): NVGcolor {
out.r = r;
out.g = g;
out.b = b;
out.a = a;
return out;
}
// Linearly interpolates from color c0 to c1, and returns resulting color value.
// NVGcolor nvgLerpRGBA(NVGcolor c0, NVGcolor c1, float u);
export function nvgLerpRGBA(c0: NVGcolor, c1: NVGcolor, u: number, out: NVGcolor = new NVGcolor()): NVGcolor {
u = nvg__clampf(u, 0.0, 1.0);
const oneminu = 1.0 - u;
for (let i = 0; i < 4; ++i) {
out.rgba[i] = c0.rgba[i] * oneminu + c1.rgba[i] * u;
}
return out;
}
// Sets transparency of a color value.
// NVGcolor nvgTransRGBA(NVGcolor c0, unsigned char a);
export function nvgTransRGBA(c: NVGcolor, a: number): NVGcolor {
c.a = a / 255.0;
return c;
}
// Sets transparency of a color value.
// NVGcolor nvgTransRGBAf(NVGcolor c0, float a);
export function nvgTransRGBAf(c: NVGcolor, a: number): NVGcolor {
c.a = a;
return c;
}
// Returns color value specified by hue, saturation and lightness.
// HSL values are all in range [0..1], alpha will be set to 255.
// NVGcolor nvgHSL(float h, float s, float l);
export function nvgHSL(h: number, s: number, l: number, out: NVGcolor = new NVGcolor()): NVGcolor {
return nvgHSLA(h, s, l, 255, out);
}
// static float nvg__hue(float h, float m1, float m2)
function nvg__hue(h: number, m1: number, m2: number): number {
if (h < 0) h += 1;
if (h > 1) h -= 1;
if (h < 1.0 / 6.0)
return m1 + (m2 - m1) * h * 6.0;
else if (h < 3.0 / 6.0)
return m2;
else if (h < 4.0 / 6.0)
return m1 + (m2 - m1) * (2.0 / 3.0 - h) * 6.0;
return m1;
}
// Returns color value specified by hue, saturation and lightness and alpha.
// HSL values are all in range [0..1], alpha in range [0..255]
// NVGcolor nvgHSLA(float h, float s, float l, unsigned char a);
export function nvgHSLA(h: number, s: number, l: number, a: number, out: NVGcolor = new NVGcolor()): NVGcolor {
h = nvg__modf(h, 1.0);
if (h < 0.0) h += 1.0;
s = nvg__clampf(s, 0.0, 1.0);
l = nvg__clampf(l, 0.0, 1.0);
const m2 = l <= 0.5 ? (l * (1 + s)) : (l + s - l * s);
const m1 = 2 * l - m2;
out.r = nvg__clampf(nvg__hue(h + 1.0 / 3.0, m1, m2), 0.0, 1.0);
out.g = nvg__clampf(nvg__hue(h, m1, m2), 0.0, 1.0);
out.b = nvg__clampf(nvg__hue(h - 1.0 / 3.0, m1, m2), 0.0, 1.0);
out.a = a / 255.0;
return out;
}
//
// State Handling
//
// NanoVG contains state which represents how paths will be rendered.
// The state contains transform, fill and stroke styles, text and font styles,
// and scissor clipping.
// Pushes and saves the current render state into a state stack.
// A matching nvgRestore() must be used to restore the state.
// void nvgSave(NVGcontext* ctx);
export function nvgSave(ctx: NVGcontext): void {
bind.nvgSave(ctx);
}
// Pops and restores current render state.
// void nvgRestore(NVGcontext* ctx);
export function nvgRestore(ctx: NVGcontext): void {
bind.nvgRestore(ctx);
}
// Resets current render state to default values. Does not affect the render state stack.
// void nvgReset(NVGcontext* ctx);
export function nvgReset(ctx: NVGcontext): void {
bind.nvgReset(ctx);
}
//
// Render styles
//
// Fill and stroke render style can be either a solid color or a paint which is a gradient or a pattern.
// Solid color is simply defined as a color value, different kinds of paints can be created
// using nvgLinearGradient(), nvgBoxGradient(), nvgRadialGradient() and nvgImagePattern().
//
// Current render style can be saved and restored using nvgSave() and nvgRestore().
// Sets whether to draw antialias for nvgStroke() and nvgFill(). It's enabled by default.
// void nvgShapeAntiAlias(NVGcontext* ctx, int enabled);
export function nvgShapeAntiAlias(ctx: NVGcontext, enabled: boolean = true): void {
bind.nvgShapeAntiAlias(ctx, enabled ? 1 : 0);
}
// Sets current stroke style to a solid color.
// void nvgStrokeColor(NVGcontext* ctx, NVGcolor color);
export function nvgStrokeColor(ctx: NVGcontext, color: NVGcolor): void {
bind.nvgStrokeColor(ctx, color);
}
// Sets current stroke style to a paint, which can be a one of the gradients or a pattern.
// void nvgStrokePaint(NVGcontext* ctx, NVGpaint paint);
export function nvgStrokePaint(ctx: NVGcontext, paint: NVGpaint): void {
bind.nvgStrokePaint(ctx, paint);
}
// Sets current fill style to a solid color.
// void nvgFillColor(NVGcontext* ctx, NVGcolor color);
export function nvgFillColor(ctx: NVGcontext, color: NVGcolor): void {
bind.nvgFillColor(ctx, color);
}
// Sets current fill style to a paint, which can be a one of the gradients or a pattern.
// void nvgFillPaint(NVGcontext* ctx, NVGpaint paint);
export function nvgFillPaint(ctx: NVGcontext, paint: NVGpaint): void {
bind.nvgFillPaint(ctx, paint);
}
// Sets the miter limit of the stroke style.
// Miter limit controls when a sharp corner is beveled.
// void nvgMiterLimit(NVGcontext* ctx, float limit);
export function nvgMiterLimit(ctx: NVGcontext, limit: number): void {
bind.nvgMiterLimit(ctx, limit);
}
// Sets the stroke width of the stroke style.
// void nvgStrokeWidth(NVGcontext* ctx, float size);
export function nvgStrokeWidth(ctx: NVGcontext, size: number): void {
bind.nvgStrokeWidth(ctx, size);
}
// Sets how the end of the line (cap) is drawn,
// Can be one of: NVG_BUTT (default), NVG_ROUND, NVG_SQUARE.
// void nvgLineCap(NVGcontext* ctx, int cap);
export function nvgLineCap(ctx: NVGcontext, cap: NVGlineCap.BUTT | NVGlineCap.ROUND | NVGlineCap.NVG_SQUARE): void {
bind.nvgLineCap(ctx, cap);
}
// Sets how sharp path corners are drawn.
// Can be one of NVG_MITER (default), NVG_ROUND, NVG_BEVEL.
// void nvgLineJoin(NVGcontext* ctx, int join);
export function nvgLineJoin(ctx: NVGcontext, join: NVGlineCap.MITER | NVGlineCap.ROUND | NVGlineCap.BEVEL): void {
bind.nvgLineJoin(ctx, join);
}
// Sets the transparency applied to all rendered shapes.
// Already transparent paths will get proportionally more transparent as well.
// void nvgGlobalAlpha(NVGcontext* ctx, float alpha);
export function nvgGlobalAlpha(ctx: NVGcontext, alpha: number): void {
bind.nvgGlobalAlpha(ctx, alpha);
}
//
// Transforms
//
// The paths, gradients, patterns and scissor region are transformed by an transformation
// matrix at the time when they are passed to the API.
// The current transformation matrix is a affine matrix:
// [sx kx tx]
// [ky sy ty]
// [ 0 0 1]
// Where: sx,sy define scaling, kx,ky skewing, and tx,ty translation.
// The last row is assumed to be 0,0,1 and is not stored.
//
// Apart from nvgResetTransform(), each transformation function first creates
// specific transformation matrix and pre-multiplies the current transformation by it.
//
// Current coordinate system (transformation) can be saved and restored using nvgSave() and nvgRestore().
// Resets current transform to a identity matrix.
// void nvgResetTransform(NVGcontext* ctx);
export function nvgResetTransform(ctx: NVGcontext): void {
bind.nvgResetTransform(ctx);
}
// Premultiplies current coordinate system by specified matrix.
// The parameters are interpreted as matrix as follows:
// [a c e]
// [b d f]
// [0 0 1]
// void nvgTransform(NVGcontext* ctx, float a, float b, float c, float d, float e, float f);
export function nvgTransform(ctx: NVGcontext, a: number, b: number, c: number, d: number, e: number, f: number): void {
bind.nvgTransform(ctx, a, b, c, d, e, f);
}
// Translates current coordinate system.
// void nvgTranslate(NVGcontext* ctx, float x, float y);
export function nvgTranslate(ctx: NVGcontext, x: number, y: number): void {
bind.nvgTranslate(ctx, x, y);
}
// Rotates current coordinate system. Angle is specified in radians.
// void nvgRotate(NVGcontext* ctx, float angle);
export function nvgRotate(ctx: NVGcontext, angle: number): void {
bind.nvgRotate(ctx, angle);
}
// Skews the current coordinate system along X axis. Angle is specified in radians.
// void nvgSkewX(NVGcontext* ctx, float angle);
export function nvgSkewX(ctx: NVGcontext, angle: number): void {
bind.nvgSkewX(ctx, angle);
}
// Skews the current coordinate system along Y axis. Angle is specified in radians.
// void nvgSkewY(NVGcontext* ctx, float angle);
export function nvgSkewY(ctx: NVGcontext, angle: number): void {
bind.nvgSkewY(ctx, angle);
}
// Scales the current coordinate system.
// void nvgScale(NVGcontext* ctx, float x, float y);
export function nvgScale(ctx: NVGcontext, x: number, y: number): void {
bind.nvgScale(ctx, x, y);
}
// Stores the top part (a-f) of the current transformation matrix in to the specified buffer.
// [a c e]
// [b d f]
// [0 0 1]
// There should be space for 6 floats in the return buffer for the values a-f.
// void nvgCurrentTransform(NVGcontext* ctx, float* xform);
export function nvgCurrentTransform(ctx: NVGcontext, xform: Float32Array): void {
bind.nvgCurrentTransform(ctx, xform);
}
// The following functions can be used to make calculations on 2x3 transformation matrices.
// A 2x3 matrix is represented as float[6].
// Sets the transform to identity matrix.
// void nvgTransformIdentity(float* dst);
export function nvgTransformIdentity(dst: Float32Array): void {
dst[0] = 1.0; dst[1] = 0.0;
dst[2] = 0.0; dst[3] = 1.0;
dst[4] = 0.0; dst[5] = 0.0;
}
// Sets the transform to translation matrix matrix.
// void nvgTransformTranslate(float* dst, float tx, float ty);
export function nvgTransformTranslate(dst: Float32Array, tx: number, ty: number): void {
dst[0] = 1.0; dst[1] = 0.0;
dst[2] = 0.0; dst[3] = 1.0;
dst[4] = tx; dst[5] = ty;
}
// Sets the transform to scale matrix.
// void nvgTransformScale(float* dst, float sx, float sy);
export function nvgTransformScale(dst: Float32Array, sx: number, sy: number): void {
dst[0] = sx; dst[1] = 0.0;
dst[2] = 0.0; dst[3] = sy;
dst[4] = 0.0; dst[5] = 0.0;
}
// Sets the transform to rotate matrix. Angle is specified in radians.
// void nvgTransformRotate(float* dst, float a);
export function nvgTransformRotate(dst: Float32Array, a: number): void {
const cs = Math.cos(a), sn = Math.sin(a);
dst[0] = cs; dst[1] = sn;
dst[2] = -sn; dst[3] = cs;
dst[4] = 0.0; dst[5] = 0.0;
}
// Sets the transform to skew-x matrix. Angle is specified in radians.
// void nvgTransformSkewX(float* dst, float a);
export function nvgTransformSkewX(dst: Float32Array, a: number): void {
dst[0] = 1.0; dst[1] = 0.0;
dst[2] = Math.tan(a); dst[3] = 1.0;
dst[4] = 0.0; dst[5] = 0.0;
}
// Sets the transform to skew-y matrix. Angle is specified in radians.
// void nvgTransformSkewY(float* dst, float a);
export function nvgTransformSkewY(dst: Float32Array, a: number): void {
dst[0] = 1.0; dst[1] = Math.tan(a);
dst[2] = 0.0; dst[3] = 1.0;
dst[4] = 0.0; dst[5] = 0.0;
}
// Sets the transform to the result of multiplication of two transforms, of A = A*B.
// void nvgTransformMultiply(float* dst, const float* src);
export function nvgTransformMultiply(dst: Float32Array, src: Float32Array): void {
const t0 = dst[0] * src[0] + dst[1] * src[2];
const t2 = dst[2] * src[0] + dst[3] * src[2];
const t4 = dst[4] * src[0] + dst[5] * src[2] + src[4];
dst[1] = dst[0] * src[1] + dst[1] * src[3];
dst[3] = dst[2] * src[1] + dst[3] * src[3];
dst[5] = dst[4] * src[1] + dst[5] * src[3] + src[5];
dst[0] = t0;
dst[2] = t2;
dst[4] = t4;
}
// Sets the transform to the result of multiplication of two transforms, of A = B*A.
// void nvgTransformPremultiply(float* dst, const float* src);
const s2 = new Float32Array(6); // float s2[6];
export function nvgTransformPremultiply(dst: Float32Array, src: Float32Array): void {
s2.set(src); // memcpy(s2, src, sizeof(float)*6);
nvgTransformMultiply(s2, dst);
dst.set(s2); // memcpy(dst, s2, sizeof(float)*6);
}
// Sets the destination to inverse of specified transform.
// Returns 1 if the inverse could be calculated, else 0.
// int nvgTransformInverse(float* dst, const float* src);
export function nvgTransformInverse(dst: Float32Array, src: Float32Array): number {
const det = src[0] * src[3] - src[2] * src[1];
if (det > -1e-6 && det < 1e-6) {
nvgTransformIdentity(dst);
return 0;
}
const invdet = 1.0 / det;
dst[0] = src[3] * invdet;
dst[2] = -src[2] * invdet;
dst[4] = (src[2] * src[5] - src[3] * src[4]) * invdet;
dst[1] = -src[1] * invdet;
dst[3] = src[0] * invdet;
dst[5] = (src[1] * src[4] - src[0] * src[5]) * invdet;
return 1;
}
// Transform a point by given transform.
// void nvgTransformPoint(float* dstx, float* dsty, const float* xform, float srcx, float srcy);
export function nvgTransformPoint(dst: Float32Array, xform: Float32Array, src: Float32Array): void {
const srcx = src[0], srcy = src[1];
dst[0] = srcx * xform[0] + srcy * xform[2] + xform[4];
dst[1] = srcx * xform[1] + srcy * xform[3] + xform[5];
}
// Converts degrees to radians and vice versa.
// float nvgDegToRad(float deg);
export function nvgDegToRad(deg: number): number {
return deg / 180.0 * NVG_PI;
}
// float nvgRadToDeg(float rad);
export function nvgRadToDeg(rad: number): number {
return rad / NVG_PI * 180.0;
}
//
// Images
//
// NanoVG allows you to load jpg, png, psd, tga, pic and gif files to be used for rendering.
// In addition you can upload your own image. The image loading is provided by stb_image.
// The parameter imageFlags is combination of flags defined in NVGimageFlags.
// Creates image by loading it from the disk from specified file name.
// Returns handle to the image.
// int nvgCreateImage(NVGcontext* ctx, const char* filename, int imageFlags);
export function nvgCreateImage(ctx: NVGcontext, filename: string, imageFlags: NVGimageFlags): number {
return nvgCreateImage(ctx, filename, imageFlags);
}
// Creates image by loading it from the specified chunk of memory.
// Returns handle to the image.
// int nvgCreateImageMem(NVGcontext* ctx, int imageFlags, unsigned char* data, int ndata);
export function nvgCreateImageMem(ctx: NVGcontext, imageFlags: NVGimageFlags, data: Uint8Array): number {
return bind.nvgCreateImageMem(ctx, imageFlags, data);
}
// Creates image from specified image data.
// Returns handle to the image.
// int nvgCreateImageRGBA(NVGcontext* ctx, int w, int h, int imageFlags, const unsigned char* data);
export function nvgCreateImageRGBA(ctx: NVGcontext, w: number, h: number, imageFlags: NVGimageFlags, data: Uint8Array): number {
return bind.nvgCreateImageRGBA(ctx, w, h, imageFlags, data);
}
// Updates image data specified by image handle.
// void nvgUpdateImage(NVGcontext* ctx, int image, const unsigned char* data);
export function nvgUpdateImage(ctx: NVGcontext, image: number, data: Uint8Array): void {
bind.nvgUpdateImage(ctx, image, data);
}
// Returns the dimensions of a created image.
// void nvgImageSize(NVGcontext* ctx, int image, int* w, int* h);
export function nvgImageSize(ctx: NVGcontext, image: number, w: [number], h: [number]): void {
bind.nvgImageSize(ctx, image, w, h);
}
// Deletes created image.
// void nvgDeleteImage(NVGcontext* ctx, int image);
export function nvgDeleteImage(ctx: NVGcontext, image: number): void {
bind.nvgDeleteImage(ctx, image);
}
//
// Paints
//
// NanoVG supports four types of paints: linear gradient, box gradient, radial gradient and image pattern.
// These can be used as paints for strokes and fills.
// Creates and returns a linear gradient. Parameters (sx,sy)-(ex,ey) specify the start and end coordinates
// of the linear gradient, icol specifies the start color and ocol the end color.
// The gradient is transformed by the current transform when it is passed to nvgFillPaint() or nvgStrokePaint().
// NVGpaint nvgLinearGradient(NVGcontext* ctx, float sx, float sy, float ex, float ey, NVGcolor icol, NVGcolor ocol);
export function nvgLinearGradient(ctx: NVGcontext, sx: number, sy: number, ex: number, ey: number, icol: NVGcolor, ocol: NVGcolor, out: NVGpaint = new NVGpaint()): NVGpaint {
bind.nvgLinearGradient(ctx, sx, sy, ex, ey, icol, ocol, out);
return out;
}
// Creates and returns a box gradient. Box gradient is a feathered rounded rectangle, it is useful for rendering
// drop shadows or highlights for boxes. Parameters (x,y) define the top-left corner of the rectangle,
// (w,h) define the size of the rectangle, r defines the corner radius, and f feather. Feather defines how blurry
// the border of the rectangle is. Parameter icol specifies the inner color and ocol the outer color of the gradient.
// The gradient is transformed by the current transform when it is passed to nvgFillPaint() or nvgStrokePaint().
// NVGpaint nvgBoxGradient(NVGcontext* ctx, float x, float y, float w, float h, float r, float f, NVGcolor icol, NVGcolor ocol);
export function nvgBoxGradient(ctx: NVGcontext, x: number, y: number, w: number, h: number, r: number, f: number, icol: NVGcolor, ocol: NVGcolor, out: NVGpaint = new NVGpaint()): NVGpaint {
bind.nvgBoxGradient(ctx, x, y, w, h, r, f, icol, ocol, out);
return out;
}
// Creates and returns a radial gradient. Parameters (cx,cy) specify the center, inr and outr specify
// the inner and outer radius of the gradient, icol specifies the start color and ocol the end color.
// The gradient is transformed by the current transform when it is passed to nvgFillPaint() or nvgStrokePaint().
// NVGpaint nvgRadialGradient(NVGcontext* ctx, float cx, float cy, float inr, float outr, NVGcolor icol, NVGcolor ocol);
export function nvgRadialGradient(ctx: NVGcontext, cx: number, cy: number, inr: number, outr: number, icol: NVGcolor, ocol: NVGcolor, out: NVGpaint = new NVGpaint()): NVGpaint {
bind.nvgRadialGradient(ctx, cx, cy, inr, outr, icol, ocol, out);
return out;
}
// Creates and returns an image patter. Parameters (ox,oy) specify the left-top location of the image pattern,
// (ex,ey) the size of one image, angle rotation around the top-left corner, image is handle to the image to render.
// The gradient is transformed by the current transform when it is passed to nvgFillPaint() or nvgStrokePaint().
// NVGpaint nvgImagePattern(NVGcontext* ctx, float ox, float oy, float ex, float ey, float angle, int image, float alpha);
export function nvgImagePattern(ctx: NVGcontext, ox: number, oy: number, ex: number, ey: number, angle: number, image: number, alpha: number, out: NVGpaint = new NVGpaint()): NVGpaint {
bind.nvgImagePattern(ctx, ox, oy, ex, ey, angle, image, alpha, out);
return out;
}
//
// Scissoring
//
// Scissoring allows you to clip the rendering into a rectangle. This is useful for various
// user interface cases like rendering a text edit or a timeline.
// Sets the current scissor rectangle.
// The scissor rectangle is transformed by the current transform.
// void nvgScissor(NVGcontext* ctx, float x, float y, float w, float h);
export function nvgScissor(ctx: NVGcontext, x: number, y: number, w: number, h: number): void {
bind.nvgScissor(ctx, x, y, w, h);
}
// Intersects current scissor rectangle with the specified rectangle.
// The scissor rectangle is transformed by the current transform.
// Note: in case the rotation of previous scissor rect differs from
// the current one, the intersection will be done between the specified
// rectangle and the previous scissor rectangle transformed in the current
// transform space. The resulting shape is always rectangle.
// void nvgIntersectScissor(NVGcontext* ctx, float x, float y, float w, float h);
export function nvgIntersectScissor(ctx: NVGcontext, x: number, y: number, w: number, h: number): void {
bind.nvgIntersectScissor(ctx, x, y, w, h);
}
// Reset and disables scissoring.
// void nvgResetScissor(NVGcontext* ctx);
export function nvgResetScissor(ctx: NVGcontext): void {
bind.nvgResetScissor(ctx);
}
//
// Paths
//
// Drawing a new shape starts with nvgBeginPath(), it clears all the currently defined paths.
// Then you define one or more paths and sub-paths which describe the shape. The are functions
// to draw common shapes like rectangles and circles, and lower level step-by-step functions,
// which allow to define a path curve by curve.
//
// NanoVG uses even-odd fill rule to draw the shapes. Solid shapes should have counter clockwise
// winding and holes should have counter clockwise order. To specify winding of a path you can
// call nvgPathWinding(). This is useful especially for the common shapes, which are drawn CCW.
//
// Finally you can fill the path using current fill style by calling nvgFill(), and stroke it
// with current stroke style by calling nvgStroke().
//
// The curve segments and sub-paths are transformed by the current transform.
// Clears the current path and sub-paths.
// void nvgBeginPath(NVGcontext* ctx);
export function nvgBeginPath(ctx: NVGcontext): void {
bind.nvgBeginPath(ctx);
}
// Starts new sub-path with specified point as first point.
// void nvgMoveTo(NVGcontext* ctx, float x, float y);
export function nvgMoveTo(ctx: NVGcontext, x: number, y: number): void {
bind.nvgMoveTo(ctx, x, y);
}
// Adds line segment from the last point in the path to the specified point.
// void nvgLineTo(NVGcontext* ctx, float x, float y);
export function nvgLineTo(ctx: NVGcontext, x: number, y: number): void {
bind.nvgLineTo(ctx, x, y);
}
// Adds cubic bezier segment from last point in the path via two control points to the specified point.
// void nvgBezierTo(NVGcontext* ctx, float c1x, float c1y, float c2x, float c2y, float x, float y);
export function nvgBezierTo(ctx: NVGcontext, c1x: number, c1y: number, c2x: number, c2y: number, x: number, y: number): void {
bind.nvgBezierTo(ctx, c1x, c1y, c2x, c2y, x, y);
}
// Adds quadratic bezier segment from last point in the path via a control point to the specified point.
// void nvgQuadTo(NVGcontext* ctx, float cx, float cy, float x, float y);
export function nvgQuadTo(ctx: NVGcontext, cx: number, cy: number, x: number, y: number): void {
bind.nvgQuadTo(ctx, cx, cy, x, y);
}
// Adds an arc segment at the corner defined by the last path point, and two specified points.
// void nvgArcTo(NVGcontext* ctx, float x1, float y1, float x2, float y2, float radius);
export function nvgArcTo(ctx: NVGcontext, x1: number, y1: number, x2: number, y2: number, radius: number): void {
bind.nvgArcTo(ctx, x1, y1, x2, y2, radius);
}
// Closes current sub-path with a line segment.
// void nvgClosePath(NVGcontext* ctx);
export function nvgClosePath(ctx: NVGcontext): void {
bind.nvgClosePath(ctx);
}
// Sets the current sub-path winding, see NVGwinding and NVGsolidity.
// void nvgPathWinding(NVGcontext* ctx, int dir);
export function nvgPathWinding(ctx: NVGcontext, dir: NVGwinding | NVGsolidity): void {
bind.nvgPathWinding(ctx, dir);
}
// Creates new circle arc shaped sub-path. The arc center is at cx,cy, the arc radius is r,
// and the arc is drawn from angle a0 to a1, and swept in direction dir (NVG_CCW, or NVG_CW).
// Angles are specified in radians.
// void nvgArc(NVGcontext* ctx, float cx, float cy, float r, float a0, float a1, int dir);
export function nvgArc(ctx: NVGcontext, cx: number, cy: number, r: number, a0: number, a1: number, dir: NVGwinding | NVGsolidity): void {
bind.nvgArc(ctx, cx, cy, r, a0, a1, dir);
}
// Creates new rectangle shaped sub-path.
// void nvgRect(NVGcontext* ctx, float x, float y, float w, float h);
export function nvgRect(ctx: NVGcontext, x: number, y: number, w: number, h: number): void {
bind.nvgRect(ctx, x, y, w, h);
}
// Creates new rounded rectangle shaped sub-path.
// void nvgRoundedRect(NVGcontext* ctx, float x, float y, float w, float h, float r);
export function nvgRoundedRect(ctx: NVGcontext, x: number, y: number, w: number, h: number, r: number): void {
bind.nvgRoundedRect(ctx, x, y, w, h, r);
}
// Creates new rounded rectangle shaped sub-path with varying radii for each corner.
// void nvgRoundedRectVarying(NVGcontext* ctx, float x, float y, float w, float h, float radTopLeft, float radTopRight, float radBottomRight, float radBottomLeft);
export function nvgRoundedRectVarying(ctx: NVGcontext, x: number, y: number, w: number, h: number, radTopLeft: number, radTopRight: number, radBottomRight: number, radBottomLeft: number): void {
bind.nvgRoundedRectVarying(ctx, x, y, w, h, radTopLeft, radTopRight, radBottomRight, radBottomLeft);
}
// Creates new ellipse shaped sub-path.
// void nvgEllipse(NVGcontext* ctx, float cx, float cy, float rx, float ry);
export function nvgEllipse(ctx: NVGcontext, cx: number, cy: number, rx: number, ry: number): void {
bind.nvgEllipse(ctx, cx, cy, rx, ry);
}
// Creates new circle shaped sub-path.
// void nvgCircle(NVGcontext* ctx, float cx, float cy, float r);
export function nvgCircle(ctx: NVGcontext, cx: number, cy: number, r: number): void {
bind.nvgCircle(ctx, cx, cy, r);
}
// Fills the current path with current fill style.
// void nvgFill(NVGcontext* ctx);
export function nvgFill(ctx: NVGcontext): void {
bind.nvgFill(ctx);
}
// Fills the current path with current stroke style.
// void nvgStroke(NVGcontext* ctx);
export function nvgStroke(ctx: NVGcontext): void {
bind.nvgStroke(ctx);
}
//
// Text
//
// NanoVG allows you to load .ttf files and use the font to render text.
//
// The appearance of the text can be defined by setting the current text style
// and by specifying the fill color. Common text and font settings such as
// font size, letter spacing and text align are supported. Font blur allows you
// to create simple text effects such as drop shadows.
//
// At render time the font face can be set based on the font handles or name.
//
// Font measure functions return values in local space, the calculations are
// carried in the same resolution as the final rendering. This is done because
// the text glyph positions are snapped to the nearest pixels sharp rendering.
//
// The local space means that values are not rotated or scale as per the current
// transformation. For example if you set font size to 12, which would mean that
// line height is 16, then regardless of the current scaling and rotation, the
// returned line height is always 16. Some measures may vary because of the scaling
// since aforementioned pixel snapping.
//
// While this may sound a little odd, the setup allows you to always render the
// same way regardless of scaling. I.e. following works regardless of scaling:
//
// const char* txt = "Text me up.";
// nvgTextBounds(vg, x,y, txt, NULL, bounds);
// nvgBeginPath(vg);
// nvgRoundedRect(vg, bounds[0],bounds[1], bounds[2]-bounds[0], bounds[3]-bounds[1]);
// nvgFill(vg);
//
// Note: currently only solid color fill is supported for text.
// Creates font by loading it from the disk from specified file name.
// Returns handle to the font.
// int nvgCreateFont(NVGcontext* ctx, const char* name, const char* filename);
export function nvgCreateFont(ctx: NVGcontext, name: string, filename: string): number {
return bind.nvgCreateFont(ctx, name, filename);
}
// Creates font by loading it from the specified memory chunk.
// Returns handle to the font.
// int nvgCreateFontMem(NVGcontext* ctx, const char* name, unsigned char* data, int ndata, int freeData);
export function nvgCreateFontMem(ctx: NVGcontext, name: string, data: Uint8Array): number {
return bind.nvgCreateFontMem(ctx, name, data);
}
// Finds a loaded font of specified name, and returns handle to it, or -1 if the font is not found.
// int nvgFindFont(NVGcontext* ctx, const char* name);
export function nvgFindFont(ctx: NVGcontext, name: string): number {
return bind.nvgFindFont(ctx, name);
}
// Adds a fallback font by handle.
// int nvgAddFallbackFontId(NVGcontext* ctx, int baseFont, int fallbackFont);
export function nvgAddFallbackFontId(ctx: NVGcontext, baseFont: number, fallbackFont: number): number {
return bind.nvgAddFallbackFontId(ctx, baseFont, fallbackFont);
}
// Adds a fallback font by name.
// int nvgAddFallbackFont(NVGcontext* ctx, const char* baseFont, const char* fallbackFont);
export function nvgAddFallbackFont(ctx: NVGcontext, baseFont: string, fallbackFont: string): number {
return bind.nvgAddFallbackFont(ctx, baseFont, fallbackFont);
}
// Sets the font size of current text style.
// void nvgFontSize(NVGcontext* ctx, float size);
export function nvgFontSize(ctx: NVGcontext, size: number): void {
bind.nvgFontSize(ctx, size);
}
// Sets the blur of current text style.
// void nvgFontBlur(NVGcontext* ctx, float blur);
export function nvgFontBlur(ctx: NVGcontext, blur: number): void {
bind.nvgFontBlur(ctx, blur);
}
// Sets the letter spacing of current text style.
// void nvgTextLetterSpacing(NVGcontext* ctx, float spacing);
export function nvgTextLetterSpacing(ctx: NVGcontext, spacing: number): void {
bind.nvgTextLetterSpacing(ctx, spacing);
}
// Sets the proportional line height of current text style. The line height is specified as multiple of font size.
// void nvgTextLineHeight(NVGcontext* ctx, float lineHeight);
export function nvgTextLineHeight(ctx: NVGcontext, lineHeight: number): void {
bind.nvgTextLineHeight(ctx, lineHeight);
}
// Sets the text align of current text style, see NVGalign for options.
// void nvgTextAlign(NVGcontext* ctx, int align);
export function nvgTextAlign(ctx: NVGcontext, align: NVGalign): void {
bind.nvgTextAlign(ctx, align);
}
// Sets the font face based on specified id of current text style.
// void nvgFontFaceId(NVGcontext* ctx, int font);
export function nvgFontFaceId(ctx: NVGcontext, font: number): void {
bind.nvgFontFaceId(ctx, font);
}
// Sets the font face based on specified name of current text style.
// void nvgFontFace(NVGcontext* ctx, const char* font);
export function nvgFontFace(ctx: NVGcontext, font: string): void {
bind.nvgFontFace(ctx, font);
}
// Draws text string at specified location. If end is specified only the sub-string up to the end is drawn.
// float nvgText(NVGcontext* ctx, float x, float y, const char* string, const char* end);
export function nvgText(ctx: NVGcontext, x: number, y: number, string: string, end: number | null = null): number {
return bind.nvgText(ctx, x, y, string, end === null ? 0 : end);
}
// Draws multi-line text string at specified location wrapped at the specified width. If end is specified only the sub-string up to the end is drawn.
// White space is stripped at the beginning of the rows, the text is split at word boundaries or when new-line characters are encountered.
// Words longer than the max width are slit at nearest character (i.e. no hyphenation).
// void nvgTextBox(NVGcontext* ctx, float x, float y, float breakRowWidth, const char* string, const char* end);
export function nvgTextBox(ctx: NVGcontext, x: number, y: number, breakRowWidth: number, string: string, end: number | null = null): void {
bind.nvgTextBox(ctx, x, y, breakRowWidth, string, end === null ? 0 : end);
}
// Measures the specified text string. Parameter bounds should be a pointer to float[4],
// if the bounding box of the text should be returned. The bounds value are [xmin,ymin, xmax,ymax]
// Returns the horizontal advance of the measured text (i.e. where the next character should drawn).
// Measured values are returned in local coordinate space.
// float nvgTextBounds(NVGcontext* ctx, float x, float y, const char* string, const char* end, float* bounds);
export function nvgTextBounds(ctx: NVGcontext, x: number, y: number, string: string, end: number | null = null, bounds: Float32Array | null = null): number {
return bind.nvgTextBounds(ctx, x, y, string, end === null ? 0 : end, bounds);
}