Top Description Fields Constructors Methods
org.lwjgl.nanovg

public Class NanoSVG

extends Object
Class Inheritance
Imports
javax.annotation.*, java.nio.*, org.lwjgl.system.*

NanoSVG is a simple stupid single-header-file SVG parse. The output of the parser is a list of cubic bezier shapes.

The library suits well for anything from rendering scalable icons in your editor application to prototyping a game.

NanoSVG supports a wide range of SVG features, but something may be missing, feel free to create a pull request!

The shapes in the SVG images are transformed by the viewBox and converted to specified units. That is, you should get the same looking data as your designed in your favorite app.

NanoSVG can return the paths in few different units. For example if you want to render an image, you may choose to get the paths in pixels, or if you are feeding the data into a CNC-cutter, you may want to use millimeters.

The units passed to NanoSVG should be one of: 'px', 'pt', 'pc' 'mm', 'cm', or 'in'. DPI (dots-per-inch) controls how the unit conversion is done.

If you don't know or care about the units stuff, "px" and 96 should get you going.

Field Summary

Modifier and TypeField and Description
public static final int
NSVG_CAP_BUTT

NSVGlineCap Enum values:

public static final int
NSVG_CAP_ROUND

NSVGlineCap Enum values:

public static final int
NSVG_CAP_SQUARE

NSVGlineCap Enum values:

public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
public static native void
nnsvgDelete(long image)

Unsafe version of: Delete

public static native void
nnsvgDeleteRasterizer(long rasterizer)

Unsafe version of: DeleteRasterizer

public static native long
nnsvgDuplicatePath(long p)

Unsafe version of: DuplicatePath

public static native long
nnsvgParse(long input, long units, float dpi)

Unsafe version of: Parse

public static native long
nnsvgParseFromFile(long filename, long units, float dpi)

Unsafe version of: ParseFromFile

public static native void
nnsvgRasterize(long r, long image, float tx, float ty, float scale, long dst, int w, int h, int stride)

Unsafe version of: Rasterize

public static native long
nsvgCreateRasterizer()

Allocates rasterizer context.

public static void
nsvgDelete(NSVGImage image)

Deletes an image.

public static void
nsvgDeleteRasterizer(long
the rasterizer context to delete
rasterizer
)

Deletes rasterizer context.

public static NSVGPath
nsvgDuplicatePath(NSVGPath p)

Duplicates a path.

public static NSVGImage
nsvgParse(ByteBuffer input, ByteBuffer units, float dpi)

Parses SVG file from a null terminated string, returns SVG image as paths.

public static NSVGImage
nsvgParse(CharSequence input, CharSequence units, float dpi)

Parses SVG file from a null terminated string, returns SVG image as paths.

public static NSVGImage
nsvgParseFromFile(ByteBuffer filename, ByteBuffer units, float dpi)

Parses SVG file from a file, returns SVG image as paths.

public static NSVGImage
nsvgParseFromFile(CharSequence filename, CharSequence units, float dpi)

Parses SVG file from a file, returns SVG image as paths.

public static void
nsvgRasterize(long
pointer to rasterizer context
r
,
NSVGImage
pointer to image to rasterize
image
,
float
image x offset (applied after scaling)
tx
,
float
image y offset (applied after scaling)
ty
,
float
image scale
scale
,
ByteBuffer
pointer to destination image data, 4 bytes per pixel (RGBA)
dst
,
int
width of the image to render
w
,
int
height of the image to render
h
,
int
number of bytes per scaleline in the destination buffer
stride
)

Rasterizes SVG image, returns RGBA image (non-premultiplied alpha).

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

NSVG_CAP_BUTTback to summary
public static final int NSVG_CAP_BUTT

NSVGlineCap

Enum values:
NSVG_CAP_ROUNDback to summary
public static final int NSVG_CAP_ROUND

NSVGlineCap

Enum values:
NSVG_CAP_SQUAREback to summary
public static final int NSVG_CAP_SQUARE

NSVGlineCap

Enum values:
NSVG_FILLRULE_EVENODDback to summary
public static final int NSVG_FILLRULE_EVENODD

NSVGfillRule

Enum values:
NSVG_FILLRULE_NONZEROback to summary
public static final int NSVG_FILLRULE_NONZERO

NSVGfillRule

Enum values:
NSVG_FLAGS_VISIBLEback to summary
public static final int NSVG_FLAGS_VISIBLE

NSVGflags

NSVG_JOIN_BEVELback to summary
public static final int NSVG_JOIN_BEVEL

NSVGlineJoin

Enum values:
NSVG_JOIN_MITERback to summary
public static final int NSVG_JOIN_MITER

NSVGlineJoin

Enum values:
NSVG_JOIN_ROUNDback to summary
public static final int NSVG_JOIN_ROUND

NSVGlineJoin

Enum values:
NSVG_PAINT_COLORback to summary
public static final int NSVG_PAINT_COLOR

NSVGpaintType

Enum values:
NSVG_PAINT_LINEAR_GRADIENTback to summary
public static final int NSVG_PAINT_LINEAR_GRADIENT

NSVGpaintType

Enum values:
NSVG_PAINT_NONEback to summary
public static final int NSVG_PAINT_NONE

NSVGpaintType

Enum values:
NSVG_PAINT_RADIAL_GRADIENTback to summary
public static final int NSVG_PAINT_RADIAL_GRADIENT

NSVGpaintType

Enum values:
NSVG_PAINT_UNDEFback to summary
public static final int NSVG_PAINT_UNDEF

NSVGpaintType

Enum values:
NSVG_SPREAD_PADback to summary
public static final int NSVG_SPREAD_PAD

NSVGspreadType

Enum values:
NSVG_SPREAD_REFLECTback to summary
public static final int NSVG_SPREAD_REFLECT

NSVGspreadType

Enum values:
NSVG_SPREAD_REPEATback to summary
public static final int NSVG_SPREAD_REPEAT

NSVGspreadType

Enum values:

Constructor Detail

NanoSVGback to summary
protected NanoSVG()

Method Detail

nnsvgDeleteback to summary
public static native void nnsvgDelete(long image)

Unsafe version of: Delete

nnsvgDeleteRasterizerback to summary
public static native void nnsvgDeleteRasterizer(long rasterizer)

Unsafe version of: DeleteRasterizer

nnsvgDuplicatePathback to summary
public static native long nnsvgDuplicatePath(long p)

Unsafe version of: DuplicatePath

nnsvgParseback to summary
public static native long nnsvgParse(long input, long units, float dpi)

Unsafe version of: Parse

nnsvgParseFromFileback to summary
public static native long nnsvgParseFromFile(long filename, long units, float dpi)

Unsafe version of: ParseFromFile

nnsvgRasterizeback to summary
public static native void nnsvgRasterize(long r, long image, float tx, float ty, float scale, long dst, int w, int h, int stride)

Unsafe version of: Rasterize

nsvgCreateRasterizerback to summary
public static native long nsvgCreateRasterizer()

Allocates rasterizer context.

Annotations
@NativeType:NSVGrasterizer *
nsvgDeleteback to summary
public static void nsvgDelete(NSVGImage image)

Deletes an image.

nsvgDeleteRasterizerback to summary
public static void nsvgDeleteRasterizer(long rasterizer)

Deletes rasterizer context.

Parameters
rasterizer:long

the rasterizer context to delete

nsvgDuplicatePathback to summary
public static NSVGPath nsvgDuplicatePath(NSVGPath p)

Duplicates a path.

Annotations
@Nullable
@NativeType:NSVGpath *
nsvgParseback to summary
public static NSVGImage nsvgParse(ByteBuffer input, ByteBuffer units, float dpi)

Parses SVG file from a null terminated string, returns SVG image as paths.

Important Note

changes the string.

Annotations
@Nullable
@NativeType:NSVGimage *
nsvgParseback to summary
public static NSVGImage nsvgParse(CharSequence input, CharSequence units, float dpi)

Parses SVG file from a null terminated string, returns SVG image as paths.

Important Note

changes the string.

Annotations
@Nullable
@NativeType:NSVGimage *
nsvgParseFromFileback to summary
public static NSVGImage nsvgParseFromFile(ByteBuffer filename, ByteBuffer units, float dpi)

Parses SVG file from a file, returns SVG image as paths.

Annotations
@Nullable
@NativeType:NSVGimage *
nsvgParseFromFileback to summary
public static NSVGImage nsvgParseFromFile(CharSequence filename, CharSequence units, float dpi)

Parses SVG file from a file, returns SVG image as paths.

Annotations
@Nullable
@NativeType:NSVGimage *
nsvgRasterizeback to summary
public static void nsvgRasterize(long r, NSVGImage image, float tx, float ty, float scale, ByteBuffer dst, int w, int h, int stride)

Rasterizes SVG image, returns RGBA image (non-premultiplied alpha).

Parameters
r:long

pointer to rasterizer context

image:NSVGImage

pointer to image to rasterize

tx:float

image x offset (applied after scaling)

ty:float

image y offset (applied after scaling)

scale:float

image scale

dst:ByteBuffer

pointer to destination image data, 4 bytes per pixel (RGBA)

w:int

width of the image to render

h:int

height of the image to render

stride:int

number of bytes per scaleline in the destination buffer