Class NanoSVG
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
FieldsModifier and TypeFieldDescriptionstatic final intNSVGlineCapstatic final intNSVGlineCapstatic final intNSVGlineCapstatic final intNSVGfillRulestatic final intNSVGfillRulestatic final intNSVGflagsstatic final intNSVGlineJoinstatic final intNSVGlineJoinstatic final intNSVGlineJoinstatic final intNSVGpaintTypestatic final intNSVGpaintTypestatic final intNSVGpaintTypestatic final intNSVGpaintTypestatic final intNSVGpaintTypestatic final intNSVGspreadTypestatic final intNSVGspreadTypestatic final intNSVGspreadType -
Method Summary
Modifier and TypeMethodDescriptionstatic voidnnsvgDelete(long image) Unsafe version of:Deletestatic voidnnsvgDeleteRasterizer(long rasterizer) Unsafe version of:DeleteRasterizerstatic longnnsvgDuplicatePath(long p) Unsafe version of:DuplicatePathstatic longnnsvgParse(long input, long units, float dpi) Unsafe version of:Parsestatic longnnsvgParseFromFile(long filename, long units, float dpi) Unsafe version of:ParseFromFilestatic voidnnsvgRasterize(long r, long image, float tx, float ty, float scale, long dst, int w, int h, int stride) Unsafe version of:Rasterizestatic longAllocates rasterizer context.static voidnsvgDelete(NSVGImage image) Deletes an image.static voidnsvgDeleteRasterizer(long rasterizer) Deletes rasterizer context.static NSVGPathDuplicates a path.static NSVGImagensvgParse(CharSequence input, CharSequence units, float dpi) Parses SVG file from a null terminated string, returns SVG image as paths.static NSVGImagensvgParse(ByteBuffer input, ByteBuffer units, float dpi) Parses SVG file from a null terminated string, returns SVG image as paths.static NSVGImagensvgParseFromFile(CharSequence filename, CharSequence units, float dpi) Parses SVG file from a file, returns SVG image as paths.static NSVGImagensvgParseFromFile(ByteBuffer filename, ByteBuffer units, float dpi) Parses SVG file from a file, returns SVG image as paths.static voidnsvgRasterize(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).
-
Field Details
-
NSVG_PAINT_UNDEF
public static final int NSVG_PAINT_UNDEFNSVGpaintTypeEnum values:
- See Also:
-
NSVG_PAINT_NONE
public static final int NSVG_PAINT_NONENSVGpaintTypeEnum values:
- See Also:
-
NSVG_PAINT_COLOR
public static final int NSVG_PAINT_COLORNSVGpaintTypeEnum values:
- See Also:
-
NSVG_PAINT_LINEAR_GRADIENT
public static final int NSVG_PAINT_LINEAR_GRADIENTNSVGpaintTypeEnum values:
- See Also:
-
NSVG_PAINT_RADIAL_GRADIENT
public static final int NSVG_PAINT_RADIAL_GRADIENTNSVGpaintTypeEnum values:
- See Also:
-
NSVG_SPREAD_PAD
public static final int NSVG_SPREAD_PADNSVGspreadTypeEnum values:
- See Also:
-
NSVG_SPREAD_REFLECT
public static final int NSVG_SPREAD_REFLECTNSVGspreadTypeEnum values:
- See Also:
-
NSVG_SPREAD_REPEAT
public static final int NSVG_SPREAD_REPEATNSVGspreadTypeEnum values:
- See Also:
-
NSVG_JOIN_MITER
public static final int NSVG_JOIN_MITERNSVGlineJoinEnum values:
- See Also:
-
NSVG_JOIN_ROUND
public static final int NSVG_JOIN_ROUNDNSVGlineJoinEnum values:
- See Also:
-
NSVG_JOIN_BEVEL
public static final int NSVG_JOIN_BEVELNSVGlineJoinEnum values:
- See Also:
-
NSVG_CAP_BUTT
public static final int NSVG_CAP_BUTTNSVGlineCapEnum values:
- See Also:
-
NSVG_CAP_ROUND
public static final int NSVG_CAP_ROUNDNSVGlineCapEnum values:
- See Also:
-
NSVG_CAP_SQUARE
public static final int NSVG_CAP_SQUARENSVGlineCapEnum values:
- See Also:
-
NSVG_FILLRULE_NONZERO
public static final int NSVG_FILLRULE_NONZERONSVGfillRuleEnum values:
- See Also:
-
NSVG_FILLRULE_EVENODD
public static final int NSVG_FILLRULE_EVENODDNSVGfillRuleEnum values:
- See Also:
-
NSVG_FLAGS_VISIBLE
public static final int NSVG_FLAGS_VISIBLENSVGflags- See Also:
-
-
Method Details
-
nnsvgParseFromFile
public static long nnsvgParseFromFile(long filename, long units, float dpi) Unsafe version of:ParseFromFile -
nsvgParseFromFile
@Nullable public static NSVGImage nsvgParseFromFile(ByteBuffer filename, ByteBuffer units, float dpi) Parses SVG file from a file, returns SVG image as paths. -
nsvgParseFromFile
@Nullable public static NSVGImage nsvgParseFromFile(CharSequence filename, 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
Parses SVG file from a null terminated string, returns SVG image as paths.Important note: changes the string.
-
nsvgParse
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
Duplicates a path. -
nnsvgDelete
public static void nnsvgDelete(long image) Unsafe version of:Delete -
nsvgDelete
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, 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
-