1 module bgfx_extras.nanovg;
2 
3 private {
4     import bx.bx : AllocatorI;
5     import bgfx_extras.fontstash;
6 }
7 
8 //
9 // Copyright (c) 2013 Mikko Mononen memon@inside.org
10 //
11 // This software is provided 'as-is', without any express or implied
12 // warranty.  In no event will the authors be held liable for any damages
13 // arising from the use of this software.
14 // Permission is granted to anyone to use this software for any purpose,
15 // including commercial applications, and to alter it and redistribute it
16 // freely, subject to the following restrictions:
17 // 1. The origin of this software must not be misrepresented; you must not
18 //    claim that you wrote the original software. If you use this software
19 //    in a product, an acknowledgment in the product documentation would be
20 //    appreciated but is not required.
21 // 2. Altered source versions must be plainly marked as such, and must not be
22 //    misrepresented as being the original software.
23 // 3. This notice may not be removed or altered from any source distribution.
24 //
25 
26 enum NVG_PI = 3.14159265358979323846264338327f;
27 
28 // nanovg.cpp
29 
30 enum NVG_MAX_STATES= 32;
31 enum NVG_MAX_FONTIMAGES = 4;
32 
33 struct NVGstate {
34 	NVGpaint fill;
35 	NVGpaint stroke;
36 	float strokeWidth;
37 	float miterLimit;
38 	int lineJoin;
39 	int lineCap;
40 	float alpha;
41 	float[6] xform;
42 	NVGscissor scissor;
43 	float fontSize;
44 	float letterSpacing;
45 	float lineHeight;
46 	float fontBlur;
47 	int textAlign;
48 	int fontId;
49 }
50 
51 struct NVGpoint {
52 	float x,y;
53 	float dx, dy;
54 	float len;
55 	float dmx, dmy;
56 	ubyte flags;
57 }
58 
59 struct NVGpathCache {
60 	NVGpoint[] points;
61 	int npoints;
62 	int cpoints;
63 	NVGpath[] paths;
64 	int npaths;
65 	int cpaths;
66 	NVGvertex[] verts;
67 	int nverts;
68 	int cverts;
69 	float[4] bounds;
70 }
71 
72 struct NVGcontext {
73 	NVGparams params;
74 	float* commands;
75 	int ccommands;
76 	int ncommands;
77 	float commandx, commandy;
78 	NVGstate[NVG_MAX_STATES] states;
79 	int nstates;
80 	NVGpathCache* cache;
81 	float tessTol;
82 	float distTol;
83 	float fringeWidth;
84 	float devicePxRatio;
85 	FONScontext* fs;
86 	int[NVG_MAX_FONTIMAGES] fontImages;
87 	int fontImageIdx;
88 	int drawCallCount;
89 	int fillTriCount;
90 	int strokeTriCount;
91 	int textTriCount;
92 }
93 
94 // 
95 
96 struct NVGcolor {
97     float r, g, b, a;
98     
99     @property float[4] rgba() {
100         return [r, g, b, a];
101     }
102     @property float[4] rgba(float[4] n_rgba) {
103         r = n_rgba[0];
104         g = n_rgba[1];
105         b = n_rgba[2];
106         a = n_rgba[3];
107         return n_rgba;
108     }
109 }
110 
111 struct NVGpaint {
112 	float[6] xform;
113 	float[2] extent;
114 	float radius;
115 	float feather;
116 	NVGcolor innerColor;
117 	NVGcolor outerColor;
118 	int image;
119 }
120 
121 enum NVGwinding {
122 	NVG_CCW = 1,			// Winding for solid shapes
123 	NVG_CW = 2,				// Winding for holes
124 }
125 
126 enum NVGsolidity {
127 	NVG_SOLID = 1,			// CCW
128 	NVG_HOLE = 2,			// CW
129 }
130 
131 enum NVGlineCap {
132 	NVG_BUTT,
133 	NVG_ROUND,
134 	NVG_SQUARE,
135 	NVG_BEVEL,
136 	NVG_MITER,
137 }
138 
139 enum NVGalign {
140 	// Horizontal align
141 	NVG_ALIGN_LEFT 		= 1<<0,	// Default, align text horizontally to left.
142 	NVG_ALIGN_CENTER 	= 1<<1,	// Align text horizontally to center.
143 	NVG_ALIGN_RIGHT 	= 1<<2,	// Align text horizontally to right.
144 	// Vertical align
145 	NVG_ALIGN_TOP 		= 1<<3,	// Align text vertically to top.
146 	NVG_ALIGN_MIDDLE	= 1<<4,	// Align text vertically to middle.
147 	NVG_ALIGN_BOTTOM	= 1<<5,	// Align text vertically to bottom. 
148 	NVG_ALIGN_BASELINE	= 1<<6, // Default, align text vertically to baseline. 
149 }
150 
151 struct NVGglyphPosition {
152 	const(char)* str;	// Position of the glyph in the input string.
153 	float x;			// The x-coordinate of the logical glyph position.
154 	float minx, maxx;	// The bounds of the glyph shape.
155 }
156 
157 struct NVGtextRow {
158 	const(char)* start;	// Pointer to the input text where the row starts.
159 	const(char)* end;	// Pointer to the input text where the row ends (one past the last character).
160 	const(char)* next;	// Pointer to the beginning of the next row.
161 	float width;		// Logical width of the row.
162 	float minx, maxx;	// Actual bounds of the row. Logical with and bounds can differ because of kerning and some parts over extending.
163 }
164 
165 enum NVGimageFlags {
166     NVG_IMAGE_GENERATE_MIPMAPS	= 1<<0,     // Generate mipmaps during creation of the image.
167 	NVG_IMAGE_REPEATX			= 1<<1,		// Repeat image in X direction.
168 	NVG_IMAGE_REPEATY			= 1<<2,		// Repeat image in Y direction.
169 	NVG_IMAGE_FLIPY				= 1<<3,		// Flips (inverses) image in Y direction when rendered.
170 	NVG_IMAGE_PREMULTIPLIED		= 1<<4,		// Image data has premultiplied alpha.
171 }
172 
173 extern(C) @nogc nothrow {
174 
175     // Begin drawing a new frame
176     // Calls to nanovg drawing API should be wrapped in nvgBeginFrame() & nvgEndFrame()
177     // nvgBeginFrame() defines the size of the window to render to in relation currently
178     // set viewport (i.e. glViewport on GL backends). Device pixel ration allows to
179     // control the rendering on Hi-DPI devices.
180     // For example, GLFW returns two dimension for an opened window: window size and
181     // frame buffer size. In that case you would set windowWidth/Height to the window size
182     // devicePixelRatio to: frameBufferWidth / windowWidth.
183     void nvgBeginFrame(NVGcontext* ctx, int windowWidth, int windowHeight, float devicePixelRatio);
184 
185     // Cancels drawing the current frame.
186     void nvgCancelFrame(NVGcontext* ctx);
187 
188     // Ends drawing flushing remaining render state.
189     void nvgEndFrame(NVGcontext* ctx);
190 
191     //
192     // Color utils
193     //
194     // Colors in NanoVG are stored as unsigned ints in ABGR format.
195 
196     // Returns a color value from red, green, blue values. Alpha will be set to 255 (1.0f).
197     NVGcolor nvgRGB(ubyte r, ubyte g, ubyte b);
198 
199     // Returns a color value from red, green, blue values. Alpha will be set to 1.0f.
200     NVGcolor nvgRGBf(float r, float g, float b);
201 
202 
203     // Returns a color value from red, green, blue and alpha values.
204     NVGcolor nvgRGBA(ubyte r, ubyte g, ubyte b, ubyte a);
205 
206     // Returns a color value from red, green, blue and alpha values.
207     NVGcolor nvgRGBAf(float r, float g, float b, float a);
208 
209 
210     // Linearly interpolates from color c0 to c1, and returns resulting color value.
211     NVGcolor nvgLerpRGBA(NVGcolor c0, NVGcolor c1, float u);
212 
213     // Sets transparency of a color value.
214     NVGcolor nvgTransRGBA(NVGcolor c0, ubyte a);
215 
216     // Sets transparency of a color value.
217     NVGcolor nvgTransRGBAf(NVGcolor c0, float a);
218 
219     // Returns color value specified by hue, saturation and lightness.
220     // HSL values are all in range [0..1], alpha will be set to 255.
221     NVGcolor nvgHSL(float h, float s, float l);
222 
223     // Returns color value specified by hue, saturation and lightness and alpha.
224     // HSL values are all in range [0..1], alpha in range [0..255]
225     NVGcolor nvgHSLA(float h, float s, float l, ubyte a);
226 
227     //
228     // State Handling
229     //
230     // NanoVG contains state which represents how paths will be rendered.
231     // The state contains transform, fill and stroke styles, text and font styles,
232     // and scissor clipping.
233 
234     // Pushes and saves the current render state into a state stack.
235     // A matching nvgRestore() must be used to restore the state.
236     void nvgSave(NVGcontext* ctx);
237 
238     // Pops and restores current render state.
239     void nvgRestore(NVGcontext* ctx);
240 
241     // Resets current render state to default values. Does not affect the render state stack.
242     void nvgReset(NVGcontext* ctx);
243 
244     //
245     // Render styles
246     //
247     // Fill and stroke render style can be either a solid color or a paint which is a gradient or a pattern.
248     // Solid color is simply defined as a color value, different kinds of paints can be created
249     // using nvgLinearGradient(), nvgBoxGradient(), nvgRadialGradient() and nvgImagePattern().
250     //
251     // Current render style can be saved and restored using nvgSave() and nvgRestore(). 
252 
253     // Sets current stroke style to a solid color.
254     void nvgStrokeColor(NVGcontext* ctx, NVGcolor color);
255 
256     // Sets current stroke style to a paint, which can be a one of the gradients or a pattern.
257     void nvgStrokePaint(NVGcontext* ctx, NVGpaint paint);
258 
259     // Sets current fill style to a solid color.
260     void nvgFillColor(NVGcontext* ctx, NVGcolor color);
261 
262     // Sets current fill style to a paint, which can be a one of the gradients or a pattern.
263     void nvgFillPaint(NVGcontext* ctx, NVGpaint paint);
264 
265     // Sets the miter limit of the stroke style.
266     // Miter limit controls when a sharp corner is beveled.
267     void nvgMiterLimit(NVGcontext* ctx, float limit);
268 
269     // Sets the stroke width of the stroke style.
270     void nvgStrokeWidth(NVGcontext* ctx, float size);
271 
272     // Sets how the end of the line (cap) is drawn,
273     // Can be one of: NVG_BUTT (default), NVG_ROUND, NVG_SQUARE.
274     void nvgLineCap(NVGcontext* ctx, int cap);
275 
276     // Sets how sharp path corners are drawn.
277     // Can be one of NVG_MITER (default), NVG_ROUND, NVG_BEVEL.
278     void nvgLineJoin(NVGcontext* ctx, int join);
279 
280     // Sets the transparency applied to all rendered shapes.
281     // Alreade transparent paths will get proportionally more transparent as well.
282     void nvgGlobalAlpha(NVGcontext* ctx, float alpha);
283 
284     //
285     // Transforms
286     //
287     // The paths, gradients, patterns and scissor region are transformed by an transformation
288     // matrix at the time when they are passed to the API.
289     // The current transformation matrix is a affine matrix:
290     //   [sx kx tx]
291     //   [ky sy ty]
292     //   [ 0  0  1]
293     // Where: sx,sy define scaling, kx,ky skewing, and tx,ty translation.
294     // The last row is assumed to be 0,0,1 and is not stored.
295     //
296     // Apart from nvgResetTransform(), each transformation function first creates
297     // specific transformation matrix and pre-multiplies the current transformation by it.
298     //
299     // Current coordinate system (transformation) can be saved and restored using nvgSave() and nvgRestore(). 
300 
301     // Resets current transform to a identity matrix.
302     void nvgResetTransform(NVGcontext* ctx);
303 
304     // Premultiplies current coordinate system by specified matrix.
305     // The parameters are interpreted as matrix as follows:
306     //   [a c e]
307     //   [b d f]
308     //   [0 0 1]
309     void nvgTransform(NVGcontext* ctx, float a, float b, float c, float d, float e, float f);
310 
311     // Translates current coordinate system.
312     void nvgTranslate(NVGcontext* ctx, float x, float y);
313 
314     // Rotates current coordinate system. Angle is specified in radians.
315     void nvgRotate(NVGcontext* ctx, float angle);
316 
317     // Skews the current coordinate system along X axis. Angle is specified in radians.
318     void nvgSkewX(NVGcontext* ctx, float angle);
319 
320     // Skews the current coordinate system along Y axis. Angle is specified in radians.
321     void nvgSkewY(NVGcontext* ctx, float angle);
322 
323     // Scales the current coordinate system.
324     void nvgScale(NVGcontext* ctx, float x, float y);
325 
326     // Stores the top part (a-f) of the current transformation matrix in to the specified buffer.
327     //   [a c e]
328     //   [b d f]
329     //   [0 0 1]
330     // There should be space for 6 floats in the return buffer for the values a-f.
331     void nvgCurrentTransform(NVGcontext* ctx, float* xform);
332 
333 
334     // The following functions can be used to make calculations on 2x3 transformation matrices.
335     // A 2x3 matrix is represented as float[6].
336 
337     // Sets the transform to identity matrix.
338     void nvgTransformIdentity(float* dst);
339 
340     // Sets the transform to translation matrix matrix.
341     void nvgTransformTranslate(float* dst, float tx, float ty);
342 
343     // Sets the transform to scale matrix.
344     void nvgTransformScale(float* dst, float sx, float sy);
345 
346     // Sets the transform to rotate matrix. Angle is specified in radians.
347     void nvgTransformRotate(float* dst, float a);
348 
349     // Sets the transform to skew-x matrix. Angle is specified in radians.
350     void nvgTransformSkewX(float* dst, float a);
351 
352     // Sets the transform to skew-y matrix. Angle is specified in radians.
353     void nvgTransformSkewY(float* dst, float a);
354 
355     // Sets the transform to the result of multiplication of two transforms, of A = A*B.
356     void nvgTransformMultiply(float* dst, const(float)* src);
357 
358     // Sets the transform to the result of multiplication of two transforms, of A = B*A.
359     void nvgTransformPremultiply(float* dst, const(float)* src);
360 
361     // Sets the destination to inverse of specified transform.
362     // Returns 1 if the inverse could be calculated, else 0.
363     int nvgTransformInverse(float* dst, const(float)* src);
364 
365     // Transform a point by given transform.
366     void nvgTransformPoint(float* dstx, float* dsty, const(float)* xform, float srcx, float srcy);
367 
368     // Converts degrees to radians and vice versa.
369     float nvgDegToRad(float deg);
370     float nvgRadToDeg(float rad);
371 
372     //
373     // Images
374     //
375     // NanoVG allows you to load jpg, png, psd, tga, pic and gif files to be used for rendering.
376     // In addition you can upload your own image. The image loading is provided by stb_image.
377     // The parameter imageFlags is combination of flags defined in NVGimageFlags.
378 
379     // Creates image by loading it from the disk from specified file name.
380     // Returns handle to the image.
381     int nvgCreateImage(NVGcontext* ctx, const(char)* filename, int imageFlags);
382 
383     // Creates image by loading it from the specified chunk of memory.
384     // Returns handle to the image.
385     int nvgCreateImageMem(NVGcontext* ctx, int imageFlags, ubyte* data, int ndata);
386 
387     // Creates image from specified image data.
388     // Returns handle to the image.
389     int nvgCreateImageRGBA(NVGcontext* ctx, int w, int h, int imageFlags, const(ubyte)* data);
390 
391     // Updates image data specified by image handle.
392     void nvgUpdateImage(NVGcontext* ctx, int image, const(ubyte)* data);
393 
394     // Returns the dimensions of a created image.
395     void nvgImageSize(NVGcontext* ctx, int image, int* w, int* h);
396 
397     // Deletes created image.
398     void nvgDeleteImage(NVGcontext* ctx, int image);
399 
400     //
401     // Paints
402     //
403     // NanoVG supports four types of paints: linear gradient, box gradient, radial gradient and image pattern.
404     // These can be used as paints for strokes and fills.
405 
406     // Creates and returns a linear gradient. Parameters (sx,sy)-(ex,ey) specify the start and end coordinates
407     // of the linear gradient, icol specifies the start color and ocol the end color.
408     // The gradient is transformed by the current transform when it is passed to nvgFillPaint() or nvgStrokePaint().
409     NVGpaint nvgLinearGradient(NVGcontext* ctx, float sx, float sy, float ex, float ey,
410                             NVGcolor icol, NVGcolor ocol);
411 
412     // Creates and returns a box gradient. Box gradient is a feathered rounded rectangle, it is useful for rendering
413     // drop shadows or hilights for boxes. Parameters (x,y) define the top-left corner of the rectangle,
414     // (w,h) define the size of the rectangle, r defines the corner radius, and f feather. Feather defines how blurry
415     // the border of the rectangle is. Parameter icol specifies the inner color and ocol the outer color of the gradient.
416     // The gradient is transformed by the current transform when it is passed to nvgFillPaint() or nvgStrokePaint().
417     NVGpaint nvgBoxGradient(NVGcontext* ctx, float x, float y, float w, float h,
418                             float r, float f, NVGcolor icol, NVGcolor ocol);
419 
420     // Creates and returns a radial gradient. Parameters (cx,cy) specify the center, inr and outr specify
421     // the inner and outer radius of the gradient, icol specifies the start color and ocol the end color.
422     // The gradient is transformed by the current transform when it is passed to nvgFillPaint() or nvgStrokePaint().
423     NVGpaint nvgRadialGradient(NVGcontext* ctx, float cx, float cy, float inr, float outr,
424                             NVGcolor icol, NVGcolor ocol);
425 
426     // Creates and returns an image patter. Parameters (ox,oy) specify the left-top location of the image pattern,
427     // (ex,ey) the size of one image, angle rotation around the top-left corner, image is handle to the image to render.
428     // The gradient is transformed by the current transform when it is passed to nvgFillPaint() or nvgStrokePaint().
429     NVGpaint nvgImagePattern(NVGcontext* ctx, float ox, float oy, float ex, float ey,
430                             float angle, int image, float alpha);
431 
432     //
433     // Scissoring
434     //
435     // Scissoring allows you to clip the rendering into a rectangle. This is useful for varius
436     // user interface cases like rendering a text edit or a timeline. 
437 
438     // Sets the current scissor rectangle.
439     // The scissor rectangle is transformed by the current transform.
440     void nvgScissor(NVGcontext* ctx, float x, float y, float w, float h);
441 
442     // Intersects current scissor rectangle with the specified rectangle.
443     // The scissor rectangle is transformed by the current transform.
444     // Note: in case the rotation of previous scissor rect differs from
445     // the current one, the intersection will be done between the specified
446     // rectangle and the previous scissor rectangle transformed in the current
447     // transform space. The resulting shape is always rectangle.
448     void nvgIntersectScissor(NVGcontext* ctx, float x, float y, float w, float h);
449 
450     // Reset and disables scissoring.
451     void nvgResetScissor(NVGcontext* ctx);
452 
453     //
454     // Paths
455     //
456     // Drawing a new shape starts with nvgBeginPath(), it clears all the currently defined paths.
457     // Then you define one or more paths and sub-paths which describe the shape. The are functions
458     // to draw common shapes like rectangles and circles, and lower level step-by-step functions,
459     // which allow to define a path curve by curve.
460     //
461     // NanoVG uses even-odd fill rule to draw the shapes. Solid shapes should have counter clockwise
462     // winding and holes should have counter clockwise order. To specify winding of a path you can
463     // call nvgPathWinding(). This is useful especially for the common shapes, which are drawn CCW.
464     //
465     // Finally you can fill the path using current fill style by calling nvgFill(), and stroke it
466     // with current stroke style by calling nvgStroke().
467     //
468     // The curve segments and sub-paths are transformed by the current transform.
469 
470     // Clears the current path and sub-paths.
471     void nvgBeginPath(NVGcontext* ctx);
472 
473     // Starts new sub-path with specified point as first point.
474     void nvgMoveTo(NVGcontext* ctx, float x, float y);
475 
476     // Adds line segment from the last point in the path to the specified point.
477     void nvgLineTo(NVGcontext* ctx, float x, float y);
478 
479     // Adds cubic bezier segment from last point in the path via two control points to the specified point.
480     void nvgBezierTo(NVGcontext* ctx, float c1x, float c1y, float c2x, float c2y, float x, float y);
481 
482     // Adds quadratic bezier segment from last point in the path via a control point to the specified point.
483     void nvgQuadTo(NVGcontext* ctx, float cx, float cy, float x, float y);
484 
485     // Adds an arc segment at the corner defined by the last path point, and two specified points.
486     void nvgArcTo(NVGcontext* ctx, float x1, float y1, float x2, float y2, float radius);
487 
488     // Closes current sub-path with a line segment.
489     void nvgClosePath(NVGcontext* ctx);
490 
491     // Sets the current sub-path winding, see NVGwinding and NVGsolidity. 
492     void nvgPathWinding(NVGcontext* ctx, int dir);
493 
494     // Creates new circle arc shaped sub-path. The arc center is at cx,cy, the arc radius is r,
495     // and the arc is drawn from angle a0 to a1, and swept in direction dir (NVG_CCW, or NVG_CW).
496     // Angles are specified in radians.
497     void nvgArc(NVGcontext* ctx, float cx, float cy, float r, float a0, float a1, int dir);
498 
499     // Creates new rectangle shaped sub-path.
500     void nvgRect(NVGcontext* ctx, float x, float y, float w, float h);
501 
502     // Creates new rounded rectangle shaped sub-path.
503     void nvgRoundedRect(NVGcontext* ctx, float x, float y, float w, float h, float r);
504 
505     // Creates new ellipse shaped sub-path.
506     void nvgEllipse(NVGcontext* ctx, float cx, float cy, float rx, float ry);
507 
508     // Creates new circle shaped sub-path. 
509     void nvgCircle(NVGcontext* ctx, float cx, float cy, float r);
510 
511     // Fills the current path with current fill style.
512     void nvgFill(NVGcontext* ctx);
513 
514     // Fills the current path with current stroke style.
515     void nvgStroke(NVGcontext* ctx);
516 
517 
518     //
519     // Text
520     //
521     // NanoVG allows you to load .ttf files and use the font to render text.
522     //
523     // The appearance of the text can be defined by setting the current text style
524     // and by specifying the fill color. Common text and font settings such as
525     // font size, letter spacing and text align are supported. Font blur allows you
526     // to create simple text effects such as drop shadows.
527     //
528     // At render time the font face can be set based on the font handles or name.
529     //
530     // Font measure functions return values in local space, the calculations are
531     // carried in the same resolution as the final rendering. This is done because
532     // the text glyph positions are snapped to the nearest pixels sharp rendering.
533     //
534     // The local space means that values are not rotated or scale as per the current
535     // transformation. For example if you set font size to 12, which would mean that
536     // line height is 16, then regardless of the current scaling and rotation, the
537     // returned line height is always 16. Some measures may vary because of the scaling
538     // since aforementioned pixel snapping.
539     //
540     // While this may sound a little odd, the setup allows you to always render the
541     // same way regardless of scaling. I.e. following works regardless of scaling:
542     //
543     //		const char* txt = "Text me up.";
544     //		nvgTextBounds(vg, x,y, txt, NULL, bounds);
545     //		nvgBeginPath(vg);
546     //		nvgRoundedRect(vg, bounds[0],bounds[1], bounds[2]-bounds[0], bounds[3]-bounds[1]);
547     //		nvgFill(vg);
548     //
549     // Note: currently only solid color fill is supported for text.
550 
551     // Creates font by loading it from the disk from specified file name.
552     // Returns handle to the font.
553     int nvgCreateFont(NVGcontext* ctx, const(char)* name, const(char)* filename);
554 
555     // Creates image by loading it from the specified memory chunk.
556     // Returns handle to the font.
557     int nvgCreateFontMem(NVGcontext* ctx, const(char)* name, ubyte* data, int ndata, int freeData);
558 
559     // Finds a loaded font of specified name, and returns handle to it, or -1 if the font is not found.
560     int nvgFindFont(NVGcontext* ctx, const(char)* name);
561 
562     // Sets the font size of current text style.
563     void nvgFontSize(NVGcontext* ctx, float size);
564 
565     // Sets the blur of current text style.
566     void nvgFontBlur(NVGcontext* ctx, float blur);
567 
568     // Sets the letter spacing of current text style.
569     void nvgTextLetterSpacing(NVGcontext* ctx, float spacing);
570 
571     // Sets the proportional line height of current text style. The line height is specified as multiple of font size. 
572     void nvgTextLineHeight(NVGcontext* ctx, float lineHeight);
573 
574     // Sets the text align of current text style, see NVGalign for options.
575     void nvgTextAlign(NVGcontext* ctx, int align_);
576 
577     // Sets the font face based on specified id of current text style.
578     void nvgFontFaceId(NVGcontext* ctx, int font);
579 
580     // Sets the font face based on specified name of current text style.
581     void nvgFontFace(NVGcontext* ctx, const(char)* font);
582 
583     // Draws text string at specified location. If end is specified only the sub-string up to the end is drawn.
584     float nvgText(NVGcontext* ctx, float x, float y, const(char)* string, const(char)* end);
585 
586     // 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.
587     // White space is stripped at the beginning of the rows, the text is split at word boundaries or when new-line characters are encountered.
588     // Words longer than the max width are slit at nearest character (i.e. no hyphenation).
589     void nvgTextBox(NVGcontext* ctx, float x, float y, float breakRowWidth, const(char)* string_, const(char)* end);
590 
591     // Measures the specified text string. Parameter bounds should be a pointer to float[4],
592     // if the bounding box of the text should be returned. The bounds value are [xmin,ymin, xmax,ymax]
593     // Returns the horizontal advance of the measured text (i.e. where the next character should drawn).
594     // Measured values are returned in local coordinate space.
595     float nvgTextBounds(NVGcontext* ctx, float x, float y, const(char)* string_, const(char)* end, float* bounds);
596 
597     // Measures the specified multi-text string. Parameter bounds should be a pointer to float[4],
598     // if the bounding box of the text should be returned. The bounds value are [xmin,ymin, xmax,ymax]
599     // Measured values are returned in local coordinate space.
600     void nvgTextBoxBounds(NVGcontext* ctx, float x, float y, float breakRowWidth, const(char)* string_, const(char)* end, float* bounds);
601 
602     // Calculates the glyph x positions of the specified text. If end is specified only the sub-string will be used.
603     // Measured values are returned in local coordinate space.
604     int nvgTextGlyphPositions(NVGcontext* ctx, float x, float y, const(char)* string_, const(char)* end, NVGglyphPosition* positions, int maxPositions);
605 
606     // Returns the vertical metrics based on the current text style.
607     // Measured values are returned in local coordinate space.
608     void nvgTextMetrics(NVGcontext* ctx, float* ascender, float* descender, float* lineh);
609 
610     // Breaks the specified text into lines. If end is specified only the sub-string will be used.
611     // White space is stripped at the beginning of the rows, the text is split at word boundaries or when new-line characters are encountered.
612     // Words longer than the max width are slit at nearest character (i.e. no hyphenation).
613     int nvgTextBreakLines(NVGcontext* ctx, const(char)* string, const(char)* end, float breakRowWidth, NVGtextRow* rows, int maxRows);
614 
615 }
616 
617 //
618 // Internal Render API
619 //
620 enum NVGtexture {
621 	NVG_TEXTURE_ALPHA = 0x01,
622 	NVG_TEXTURE_RGBA = 0x02,
623 }
624 
625 struct NVGscissor {
626 	float[6] xform;
627 	float[2] extent;
628 }
629 
630 struct NVGvertex {
631 	float x,y,u,v;
632 }
633 
634 struct NVGpath {
635 	int first;
636 	int count;
637 	ubyte closed;
638 	int nbevel;
639 	NVGvertex* fill;
640 	int nfill;
641 	NVGvertex* stroke;
642 	int nstroke;
643 	int winding;
644 	int convex;
645 }
646 
647 struct NVGparams {
648 	void* userPtr;
649 	int edgeAntiAlias;
650 	int delegate(void* uptr) renderCreate;
651 	int delegate(void* uptr, int type, int w, int h, int imageFlags, const(ubyte)* data) renderCreateTexture;
652 	int delegate(void* uptr, int image) renderDeleteTexture;
653 	int delegate(void* uptr, int image, int x, int y, int w, int h, const(ubyte)* data) renderUpdateTexture;
654 	int delegate(void* uptr, int image, int* w, int* h) renderGetTextureSize;
655 	void delegate(void* uptr, int width, int height) renderViewport;
656 	void delegate(void* uptr) renderCancel;
657 	void delegate(void* uptr) renderFlush;
658 	void delegate(void* uptr, NVGpaint* paint, NVGscissor* scissor, float fringe, const(float)* bounds, const(NVGpath)* paths, int npaths) renderFill;
659 	void delegate(void* uptr, NVGpaint* paint, NVGscissor* scissor, float fringe, float strokeWidth, const(NVGpath)* paths, int npaths) renderStroke;
660 	void delegate(void* uptr, NVGpaint* paint, NVGscissor* scissor, const(NVGvertex)* verts, int nverts) renderTriangles;
661 	void delegate(void* uptr) renderDelete;
662 }
663 
664 extern(C) @nogc nothrow {
665 
666     NVGcontext* nvgCreate(int edgeaa, ubyte _viewId, AllocatorI* _allocator = null);
667     void nvgViewId(NVGcontext* ctx, ubyte _viewId);
668     void nvgDelete(NVGcontext* ctx);
669 
670     // Constructor and destructor, called by the render back-end.
671     NVGcontext* nvgCreateInternal(NVGparams* params);
672     void nvgDeleteInternal(NVGcontext* ctx);
673 
674     NVGparams* nvgInternalParams(NVGcontext* ctx);
675 
676     // Debug function to dump cached path data.
677     void nvgDebugDumpPathCache(NVGcontext* ctx);
678     
679 }
680 
681 
682 // #define NVG_NOTUSED(v) for (;;) { (void)(1 ? (void)0 : ( (void)(v) ) ); break; }
683