Class 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.

    • 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 context
        image - pointer to image to rasterize
        tx - image x offset (applied after scaling)
        ty - image y offset (applied after scaling)
        scale - image scale
        dst - pointer to destination image data, 4 bytes per pixel (RGBA)
        w - width of the image to render
        h - height of the image to render
        stride - 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