Class NanoSVG
- java.lang.Object
-
- org.lwjgl.nanovg.NanoSVG
-
public class NanoSVG extends java.lang.Object
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
Fields Modifier and Type Field Description static int
NSVG_CAP_BUTT
NSVG_CAP_ROUND
NSVG_CAP_SQUARENSVGlineCapstatic int
NSVG_FILLRULE_EVENODD
NSVG_FILLRULE_NONZERONSVGfillRulestatic int
NSVG_FLAGS_VISIBLE
NSVGflagsstatic int
NSVG_JOIN_BEVEL
NSVG_JOIN_MITER
NSVG_JOIN_ROUNDNSVGlineJoinstatic int
NSVG_PAINT_COLOR
NSVG_PAINT_LINEAR_GRADIENT
NSVG_PAINT_NONE
NSVG_PAINT_RADIAL_GRADIENTNSVGpaintTypestatic int
NSVG_SPREAD_PAD
NSVG_SPREAD_REFLECT
NSVG_SPREAD_REPEATNSVGspreadType
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
nnsvgDelete(long image)
Unsafe version of:Delete
static void
nnsvgDeleteRasterizer(long rasterizer)
Unsafe version of:DeleteRasterizer
static long
nnsvgDuplicatePath(long p)
Unsafe version of:DuplicatePath
static long
nnsvgParse(long input, long units, float dpi)
Unsafe version of:Parse
static long
nnsvgParseFromFile(long filename, long units, float dpi)
Unsafe version of:ParseFromFile
static void
nnsvgRasterize(long r, long image, float tx, float ty, float scale, long dst, int w, int h, int stride)
Unsafe version of:Rasterize
static long
nsvgCreateRasterizer()
Allocates rasterizer context.static void
nsvgDelete(NSVGImage image)
Deletes an image.static void
nsvgDeleteRasterizer(long rasterizer)
Deletes rasterizer context.static NSVGPath
nsvgDuplicatePath(NSVGPath p)
Duplicates a path.static NSVGImage
nsvgParse(java.lang.CharSequence input, java.lang.CharSequence units, float dpi)
Parses SVG file from a null terminated string, returns SVG image as paths.static NSVGImage
nsvgParse(java.nio.ByteBuffer input, java.nio.ByteBuffer units, float dpi)
Parses SVG file from a null terminated string, returns SVG image as paths.static NSVGImage
nsvgParseFromFile(java.lang.CharSequence filename, java.lang.CharSequence units, float dpi)
Parses SVG file from a file, returns SVG image as paths.static NSVGImage
nsvgParseFromFile(java.nio.ByteBuffer filename, java.nio.ByteBuffer units, float dpi)
Parses SVG file from a file, returns SVG image as paths.static void
nsvgRasterize(long r, NSVGImage image, float tx, float ty, float scale, java.nio.ByteBuffer dst, int w, int h, int stride)
Rasterizes SVG image, returns RGBA image (non-premultiplied alpha).
-
-
-
Field Detail
-
NSVG_PAINT_NONE, NSVG_PAINT_COLOR, NSVG_PAINT_LINEAR_GRADIENT, NSVG_PAINT_RADIAL_GRADIENT
NSVGpaintTypeEnum values:
-
NSVG_SPREAD_PAD, NSVG_SPREAD_REFLECT, NSVG_SPREAD_REPEAT
NSVGspreadTypeEnum values:
-
NSVG_JOIN_MITER, NSVG_JOIN_ROUND, NSVG_JOIN_BEVEL
NSVGlineJoinEnum values:
-
NSVG_CAP_BUTT, NSVG_CAP_ROUND, NSVG_CAP_SQUARE
NSVGlineCapEnum values:
-
NSVG_FILLRULE_NONZERO, NSVG_FILLRULE_EVENODD
NSVGfillRuleEnum values:
-
NSVG_FLAGS_VISIBLE
NSVGflags
-
-
Method Detail
-
nnsvgParseFromFile
public static long nnsvgParseFromFile(long filename, long units, float dpi)
Unsafe version of:ParseFromFile
-
nsvgParseFromFile
@Nullable public static NSVGImage nsvgParseFromFile(java.nio.ByteBuffer filename, java.nio.ByteBuffer units, float dpi) @Nullable public static NSVGImage nsvgParseFromFile(java.lang.CharSequence filename, java.lang.CharSequence units, float dpi)
Parses SVG file from a file, returns SVG image as paths.
-
nnsvgParse
public static long nnsvgParse(long input, long units, float dpi)
Unsafe version of:Parse
-
nsvgParse
@Nullable public static NSVGImage nsvgParse(java.nio.ByteBuffer input, java.nio.ByteBuffer units, float dpi) @Nullable public static NSVGImage nsvgParse(java.lang.CharSequence input, java.lang.CharSequence units, float dpi)
Parses SVG file from a null terminated string, returns SVG image as paths.Important note: changes the string.
-
nnsvgDuplicatePath
public static long nnsvgDuplicatePath(long p)
Unsafe version of:DuplicatePath
-
nsvgDuplicatePath
@Nullable public static NSVGPath nsvgDuplicatePath(NSVGPath p)
Duplicates a path.
-
nnsvgDelete
public static void nnsvgDelete(long image)
Unsafe version of:Delete
-
nsvgDelete
public static void nsvgDelete(NSVGImage image)
Deletes an image.
-
nsvgCreateRasterizer
public static long nsvgCreateRasterizer()
Allocates rasterizer context.
-
nnsvgRasterize
public static void nnsvgRasterize(long r, long image, float tx, float ty, float scale, long dst, int w, int h, int stride)
Unsafe version of:Rasterize
-
nsvgRasterize
public static void nsvgRasterize(long r, NSVGImage image, float tx, float ty, float scale, java.nio.ByteBuffer dst, int w, int h, int stride)
Rasterizes SVG image, returns RGBA image (non-premultiplied alpha).- Parameters:
r
- pointer to rasterizer contextimage
- pointer to image to rasterizetx
- image x offset (applied after scaling)ty
- image y offset (applied after scaling)scale
- image scaledst
- pointer to destination image data, 4 bytes per pixel (RGBA)w
- width of the image to renderh
- height of the image to renderstride
- number of bytes per scaleline in the destination buffer
-
nnsvgDeleteRasterizer
public static void nnsvgDeleteRasterizer(long rasterizer)
Unsafe version of:DeleteRasterizer
-
nsvgDeleteRasterizer
public static void nsvgDeleteRasterizer(long rasterizer)
Deletes rasterizer context.- Parameters:
rasterizer
- the rasterizer context to delete
-
-