Package ej.microvg

## Class VectorGraphicsPainter

- java.lang.Object
- - ej.microvg.VectorGraphicsPainter

-     public class VectorGraphicsPainter
      extends Object

  Provides static methods to draw paths, texts and images.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class | Description
    --- | --- | ---
    `static class` | `VectorGraphicsPainter.Direction` | Enum for specifying the direction in which a rotation can occur.
    `static class` | `VectorGraphicsPainter.FillType` | Enum for the ways a path may be filled.

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `VectorGraphicsPainter()` |

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `static void` | `drawAnimatedImage​(GraphicsContext g, VectorImage image, float x, float y, long elapsedTime)` | Draws an animated vector image at a specific time.
    `static void` | `drawAnimatedImage​(GraphicsContext g, VectorImage image, Matrix matrix, long elapsedTime)` | Draws an animated vector image at a specific time.
    `static void` | `drawAnimatedImage​(GraphicsContext g, VectorImage image, Matrix matrix, long elapsedTime, int alpha)` | Draws an animated vector image at a specific time.
    `static void` | `drawFilteredAnimatedImage​(GraphicsContext g, VectorImage image, Matrix matrix, long elapsedTime, float[] colorMatrix)` | Draws an animated vector image at a specific time with a color filter.
    `static void` | `drawFilteredImage​(GraphicsContext g, VectorImage image, Matrix matrix, float[] colorMatrix)` | Draws a vector image with a color filter.
    `static void` | `drawGradientString​(GraphicsContext g, String string, VectorFont font, float size, Matrix matrix, LinearGradient gradient, int alpha, BlendMode blendMode, float letterSpacing)` | Draws a text with a gradient.
    `static void` | `drawGradientStringOnCircle​(GraphicsContext g, String string, VectorFont font, float size, Matrix matrix, LinearGradient gradient, float radius, VectorGraphicsPainter.Direction direction, int alpha, BlendMode blendMode, float letterSpacing)` | Draws a text with a gradient along a circle.
    `static void` | `drawImage​(GraphicsContext g, VectorImage image, float x, float y)` | Draws a vector image.
    `static void` | `drawImage​(GraphicsContext g, VectorImage image, Matrix matrix)` | Draws a vector image.
    `static void` | `drawImage​(GraphicsContext g, VectorImage image, Matrix matrix, int alpha)` | Draws a vector image.
    `static void` | `drawString​(GraphicsContext g, String string, VectorFont font, float size, float x, float y)` | Draws a text.
    `static void` | `drawString​(GraphicsContext g, String string, VectorFont font, float size, Matrix matrix, int alpha, BlendMode blendMode, float letterSpacing)` | Draws a text.
    `static void` | `drawStringOnCircle​(GraphicsContext g, String string, VectorFont font, float size, Matrix matrix, float radius, VectorGraphicsPainter.Direction direction)` | Draws a text along a circle.
    `static void` | `drawStringOnCircle​(GraphicsContext g, String string, VectorFont font, float size, Matrix matrix, float radius, VectorGraphicsPainter.Direction direction, int alpha, BlendMode blendMode, float letterSpacing)` | Draws a text along a circle.
    `static void` | `fillGradientPath​(GraphicsContext g, Path path, Matrix matrix, LinearGradient gradient)` | Draws a path filled with a linear gradient and winding fill type and source over blending.
    `static void` | `fillGradientPath​(GraphicsContext g, Path path, Matrix matrix, LinearGradient gradient, VectorGraphicsPainter.FillType fillType, int alpha, BlendMode blendMode)` | Draws a path filled with a linear gradient.
    `static void` | `fillPath​(GraphicsContext g, Path path, float x, float y)` | Draws a path filled with the color of the graphics context and winding fill type and source over blending.
    `static void` | `fillPath​(GraphicsContext g, Path path, Matrix matrix)` | Draws a path filled with the color of the graphics context and winding fill type and source over blending.
    `static void` | `fillPath​(GraphicsContext g, Path path, Matrix matrix, VectorGraphicsPainter.FillType fillType, int alpha, BlendMode blendMode)` | Draws a path filled with the color of the graphics context.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### VectorGraphicsPainter

          public VectorGraphicsPainter()

  - ### Method Detail

    - #### fillPath

          public static void fillPath​(GraphicsContext g,
                                      Path path,
                                      float x,
                                      float y)

      Draws a path filled with the color of the graphics context and winding fill type and source over blending.

      Equivalent to:

           Matrix matrix = new Matrix();
           matrix.setTranslate(x, y);
           fillPath(g, path, matrix, FillType.WINDING, GraphicsContext.OPAQUE, BlendMode.SRC_OVER);

      Parameters:
        `g` - the graphics context to draw on
        `path` - the path to draw
        `x` - the x coordinate of the path
        `y` - the y coordinate of the path

    - #### fillPath

          public static void fillPath​(GraphicsContext g,
                                      Path path,
                                      Matrix matrix)

      Draws a path filled with the color of the graphics context and winding fill type and source over blending.

      Equivalent to:

           fillPath(g, path, matrix, FillType.WINDING, GraphicsContext.OPAQUE, BlendMode.SRC_OVER);

      Parameters:
        `g` - the graphics context to draw on
        `path` - the path to draw
        `matrix` - the matrix to apply

    - #### fillPath

          public static void fillPath​(GraphicsContext g,
                                      Path path,
                                      Matrix matrix,
                                      VectorGraphicsPainter.FillType fillType,
                                      int alpha,
                                      BlendMode blendMode)

      Draws a path filled with the color of the graphics context.
      Parameters:
        `g` - the graphics context to draw on
        `path` - the path to draw
        `matrix` - the matrix to apply
        `fillType` - the fill type
        `alpha` - the global opacity rendering value, between 0 (transparent) and 255 (opaque)
        `blendMode` - the blend mode
      See Also:
        `GraphicsContext.getAlpha(int)`

    - #### fillGradientPath

          public static void fillGradientPath​(GraphicsContext g,
                                              Path path,
                                              Matrix matrix,
                                              LinearGradient gradient)

      Draws a path filled with a linear gradient and winding fill type and source over blending.

      The color of the graphics context is not used by this drawing.

      Equivalent to:

           fillGradientPath(g, path, matrix, gradient, FillType.WINDING, GraphicsContext.OPAQUE, BlendMode.SRC_OVER);

      Parameters:
        `g` - the graphics context to draw on
        `path` - the path to draw
        `matrix` - the matrix to apply
        `gradient` - the gradient to fill with

    - #### fillGradientPath

          public static void fillGradientPath​(GraphicsContext g,
                                              Path path,
                                              Matrix matrix,
                                              LinearGradient gradient,
                                              VectorGraphicsPainter.FillType fillType,
                                              int alpha,
                                              BlendMode blendMode)

      Draws a path filled with a linear gradient.

      The color of the graphics context is not used by this drawing.

      Parameters:
        `g` - the graphics context to draw on
        `path` - the path to draw
        `matrix` - the matrix to apply
        `gradient` - the gradient to fill with
        `fillType` - the fill type
        `alpha` - the global opacity rendering value, between 0 (transparent) and 255 (opaque)
        `blendMode` - the blend mode
      See Also:
        `GraphicsContext.getAlpha(int)`

    - #### drawImage

          public static void drawImage​(GraphicsContext g,
                                       VectorImage image,
                                       float x,
                                       float y)

      Draws a vector image.

      Equivalent to:

           Matrix matrix = new Matrix();
           matrix.setTranslate(x, y);
           drawImage(g, image, matrix, GraphicsContext.OPAQUE);

      Parameters:
        `g` - the graphics context to draw on
        `image` - the image to draw
        `x` - the x coordinate of the image
        `y` - the y coordinate of the image
      Throws:
        `VectorGraphicsException` - if the image could not be drawn for any reason (see `VectorGraphicsException.getErrorCode()`)

    - #### drawImage

          public static void drawImage​(GraphicsContext g,
                                       VectorImage image,
                                       Matrix matrix)

      Draws a vector image.

      Equivalent to:

           drawImage(g, image, matrix, GraphicsContext.OPAQUE);

      Parameters:
        `g` - the graphics context to draw on
        `image` - the image to draw
        `matrix` - the matrix to apply
      Throws:
        `VectorGraphicsException` - if the image could not be drawn for any reason (see `VectorGraphicsException.getErrorCode()`)

    - #### drawImage

          public static void drawImage​(GraphicsContext g,
                                       VectorImage image,
                                       Matrix matrix,
                                       int alpha)

      Draws a vector image.
      Parameters:
        `g` - the graphics context to draw on
        `image` - the image to draw
        `matrix` - the matrix to apply
        `alpha` - the global opacity rendering value, between 0 (transparent) and 255 (opaque)
      Throws:
        `VectorGraphicsException` - if the image could not be drawn for any reason (see `VectorGraphicsException.getErrorCode()`)
      See Also:
        `GraphicsContext.getAlpha(int)`

    - #### drawAnimatedImage

          public static void drawAnimatedImage​(GraphicsContext g,
                                               VectorImage image,
                                               float x,
                                               float y,
                                               long elapsedTime)

      Draws an animated vector image at a specific time.

      The given elapsed time is cropped between 0 and the image duration.

      Equivalent to:

           Matrix matrix = new Matrix();
           matrix.setTranslate(x, y);
           drawAnimatedImage(g, image, matrix, elapsedTime, GraphicsContext.OPAQUE);

      Parameters:
        `g` - the graphics context to draw on
        `image` - the image to draw
        `x` - the x coordinate of the image
        `y` - the y coordinate of the image
        `elapsedTime` - the elapsed time since the beginning of the animation, in milliseconds
      Throws:
        `VectorGraphicsException` - if the image could not be drawn for any reason (see `VectorGraphicsException.getErrorCode()`)

    - #### drawAnimatedImage

          public static void drawAnimatedImage​(GraphicsContext g,
                                               VectorImage image,
                                               Matrix matrix,
                                               long elapsedTime)

      Draws an animated vector image at a specific time.

      The given elapsed time is cropped between 0 and the image duration.

      Equivalent to:

           drawAnimatedImage(g, image, matrix, elapsedTime, GraphicsContext.OPAQUE);

      Parameters:
        `g` - the graphics context to draw on
        `image` - the image to draw
        `matrix` - the matrix to apply
        `elapsedTime` - the elapsed time since the beginning of the animation, in milliseconds
      Throws:
        `VectorGraphicsException` - if the image could not be drawn for any reason (see `VectorGraphicsException.getErrorCode()`)

    - #### drawAnimatedImage

          public static void drawAnimatedImage​(GraphicsContext g,
                                               VectorImage image,
                                               Matrix matrix,
                                               long elapsedTime,
                                               int alpha)

      Draws an animated vector image at a specific time.

      The given elapsed time is cropped between 0 and the image duration.

      Parameters:
        `g` - the graphics context to draw on
        `image` - the image to draw
        `matrix` - the matrix to apply
        `elapsedTime` - the elapsed time since the beginning of the animation, in milliseconds
        `alpha` - the global opacity rendering value, between 0 (transparent) and 255 (opaque)
      Throws:
        `VectorGraphicsException` - if the image could not be drawn for any reason (see `VectorGraphicsException.getErrorCode()`)
      See Also:
        `GraphicsContext.getAlpha(int)`

    - #### drawFilteredImage

          public static void drawFilteredImage​(GraphicsContext g,
                                               VectorImage image,
                                               Matrix matrix,
                                               float[] colorMatrix)

      Draws a vector image with a color filter.
      Parameters:
        `g` - the graphics context to draw on
        `image` - the image to draw
        `matrix` - the matrix to apply
        `colorMatrix` - the color matrix used to transform colors
      Throws:
        `VectorGraphicsException` - if the image could not be drawn for any reason (see `VectorGraphicsException.getErrorCode()`)
        `ArrayIndexOutOfBoundsException` - if the given color matrix is shorter than 20 entries
      See Also:
        `VectorImage.filterImage(float[])`

    - #### drawFilteredAnimatedImage

          public static void drawFilteredAnimatedImage​(GraphicsContext g,
                                                       VectorImage image,
                                                       Matrix matrix,
                                                       long elapsedTime,
                                                       float[] colorMatrix)

      Draws an animated vector image at a specific time with a color filter.
      Parameters:
        `g` - the graphics context to draw on
        `image` - the image to draw
        `matrix` - the matrix to apply
        `elapsedTime` - the elapsed time since the beginning of the animation, in milliseconds
        `colorMatrix` - the color matrix used to transform colors
      Throws:
        `VectorGraphicsException` - if the image could not be drawn for any reason (see `VectorGraphicsException.getErrorCode()`)
        `ArrayIndexOutOfBoundsException` - if the given color matrix is shorter than 20 entries
      See Also:
        `VectorImage.filterImage(float[])`

    - #### drawString

          public static void drawString​(GraphicsContext g,
                                        String string,
                                        VectorFont font,
                                        float size,
                                        float x,
                                        float y)

      Draws a text.

      This method uses the color of the graphics context as font color.

      The anchor point is the top left corner of the text render box (related to font height; different from the text bounding box, which is related to font size; see class comment `VectorFont`). The position of this anchor point within the graphics context is defined by the `(x,y)` coordinates.

      For example, to draw a text where `yBaseline` defines the y coordinate of the text baseline, use `yBaseline - font.getBaselinePosition()` as argument of this method (see `VectorFont.getBaselinePosition(float)`).

      The font size must be positive. If it is less than or equal to 0, nothing is drawn.

      Equivalent to:

           Matrix matrix = new Matrix();
           matrix.setTranslate(x, y);
           drawString(g, string font, size, matrix, GraphicsContext.OPAQUE, BlendMode.SRC_OVER, 0);

      Parameters:
        `g` - the graphics context to draw on
        `string` - the text to draw
        `font` - the font to use
        `size` - the font size, in pixels
        `x` - the x coordinate of the string
        `y` - the y coordinate of the string
      Throws:
        `VectorGraphicsException` - if the text could not be drawn for any reason (see `VectorGraphicsException.getErrorCode()`)

    - #### drawString

          public static void drawString​(GraphicsContext g,
                                        String string,
                                        VectorFont font,
                                        float size,
                                        Matrix matrix,
                                        int alpha,
                                        BlendMode blendMode,
                                        float letterSpacing)

      Draws a text.

      This method uses the color of the graphics context as font color.

      The anchor point is the top left corner of the text render box (related to font height; different from the text bounding box, which is related to font size; see class comment `VectorFont`). The matrix defines the transformations to apply to the text (translation, scale, rotation). For example, passing the identity matrix to this method will draw an horizontal text whose top-left corner is aligned with the origin of the graphics context.

      The font size must be positive. If it is less than or equal to 0, nothing is drawn.

      This method allows to specify the global opacity value to apply during the rendering. The alpha must be a value between 0 and 255. If the specified alpha is outside this range, nothing is drawn.

      The blend mode specifies the algorithm to use when blending the pixels of the source and destination.

      The letter spacing argument specifies the extra space to add between the characters. A positive value will move the characters apart, a negative value will move them together. The default value is 0.

      Parameters:
        `g` - the graphics context to draw on
        `string` - the text to draw
        `font` - the font to use
        `size` - the font size, in pixels
        `matrix` - the transformation matrix to apply
        `alpha` - the global opacity rendering value
        `blendMode` - the blend mode to use
        `letterSpacing` - the extra letter spacing to use, in pixels
      Throws:
        `VectorGraphicsException` - if the text could not be drawn for any reason (see `VectorGraphicsException.getErrorCode()`)
      See Also:
        `GraphicsContext.getAlpha(int)`, `BlendMode`

    - #### drawStringOnCircle

          public static void drawStringOnCircle​(GraphicsContext g,
                                                String string,
                                                VectorFont font,
                                                float size,
                                                Matrix matrix,
                                                float radius,
                                                VectorGraphicsPainter.Direction direction)

      Draws a text along a circle. The circle represents the text baseline.

      This method uses the color of the graphics context as font color.

      The anchor point is the center of the circle. The matrix defines the transformations to apply to the text (translation, scale, rotation). For example, passing the identity matrix to this method will align the center of the circle with the origin of the graphics context.

      The position where the text starts along the circle is the 3 o'clock position (positive X axis). This starting position can be modified by specifying a rotation into the transformation matrix.

      The text winds along the circle in the specified direction (clockwise or counter-clockwise). The radius of the circle must be positive. If it is less than or equal to 0, nothing is drawn.

      The font size must be positive. If it is less than or equal to 0, nothing is drawn.

      Equivalent to:

           drawStringOnCircle(g, string font, size, matrix, radius, direction, GraphicsContext.OPAQUE, BlendMode.SRC_OVER, 0);

      Parameters:
        `g` - the graphics context to draw on
        `string` - the string to draw
        `font` - the font to use
        `size` - the font size, in pixels
        `matrix` - the matrix to apply
        `radius` - the radius of the circle, in pixels
        `direction` - the winding direction of the text along the circle.
      Throws:
        `VectorGraphicsException` - if the text could not be drawn for any reason (see `VectorGraphicsException.getErrorCode()`)
      See Also:
        `VectorGraphicsPainter.Direction`

    - #### drawStringOnCircle

          public static void drawStringOnCircle​(GraphicsContext g,
                                                String string,
                                                VectorFont font,
                                                float size,
                                                Matrix matrix,
                                                float radius,
                                                VectorGraphicsPainter.Direction direction,
                                                int alpha,
                                                BlendMode blendMode,
                                                float letterSpacing)

      Draws a text along a circle. The circle represents the text baseline.

      This method uses the color of the graphics context as font color.

      The anchor point is the center of the circle. The matrix defines the transformations to apply to the text (translation, scale, rotation). For example, passing the identity matrix to this method will align the center of the circle with the origin of the graphics context.

      The position where the text starts along the circle is the 3 o'clock position (positive X axis). This starting position can be modified by specifying a rotation into the transformation matrix.

      The text winds along the circle in the specified direction (clockwise or counter-clockwise). The radius of the circle must be positive. If it is less than or equal to 0, nothing is drawn.

      The font size must be positive. If it is less than or equal to 0, nothing is drawn.

      This method allows to specify the global opacity value to apply during the rendering. The alpha must be a value between 0 and 255. If the specified alpha is outside this range, nothing is drawn.

      The blend mode specifies the algorithm to use when blending the pixels of the source and destination.

      The letter spacing argument specifies the extra space to add between the characters. A positive value will move the characters apart, a negative value will move them together. The default value is 0.

      Parameters:
        `g` - the graphics context to draw on
        `string` - the string to draw
        `font` - the font to use
        `size` - the font size, in pixels
        `matrix` - the matrix to apply
        `radius` - the radius of the circle, in pixels
        `direction` - the winding direction of the text along the circle
        `alpha` - the global opacity rendering value
        `blendMode` - the blend mode
        `letterSpacing` - the extra letter spacing to use, in pixels
      Throws:
        `VectorGraphicsException` - if the text could not be drawn for any reason (see `VectorGraphicsException.getErrorCode()`)
      See Also:
        `GraphicsContext.getAlpha(int)`, `BlendMode`, `VectorGraphicsPainter.Direction`

    - #### drawGradientString

          public static void drawGradientString​(GraphicsContext g,
                                                String string,
                                                VectorFont font,
                                                float size,
                                                Matrix matrix,
                                                LinearGradient gradient,
                                                int alpha,
                                                BlendMode blendMode,
                                                float letterSpacing)

      Draws a text with a gradient.

      This method uses the given gradient for the font coloring. The color of the graphics context is not used by this drawing.

      The anchor point is the top left corner of the text render box (related to font height; different from the text bounding box, which is related to font size; see class comment `VectorFont`). The matrix defines the transformations to apply to the text (translation, scale, rotation). For example, passing the identity matrix to this method will draw an horizontal text whose top-left corner is aligned with the origin of the graphics context.

      The font size must be positive. If it is less than or equal to 0, nothing is drawn.

      This method allows to specify the global opacity value to apply during the rendering. The alpha must be a value between 0 and 255. If the specified alpha is outside this range, nothing is drawn.

      The blend mode specifies the algorithm to use when blending the pixels of the source and destination.

      The letter spacing argument specifies the extra space to add between the characters. A positive value will move the characters apart, a negative value will move them together. The default value is 0.

      Parameters:
        `g` - the graphics context to draw on
        `string` - the text to draw
        `font` - the font to use
        `size` - the font size, in pixels
        `matrix` - the transformation matrix to apply
        `gradient` - the gradient to color the text with
        `alpha` - the global opacity rendering value
        `blendMode` - the blend mode
        `letterSpacing` - the extra letter spacing to use, in pixels
      Throws:
        `VectorGraphicsException` - if the text could not be drawn for any reason (see `VectorGraphicsException.getErrorCode()`)
      See Also:
        `GraphicsContext.getAlpha(int)`, `BlendMode`

    - #### drawGradientStringOnCircle

          public static void drawGradientStringOnCircle​(GraphicsContext g,
                                                        String string,
                                                        VectorFont font,
                                                        float size,
                                                        Matrix matrix,
                                                        LinearGradient gradient,
                                                        float radius,
                                                        VectorGraphicsPainter.Direction direction,
                                                        int alpha,
                                                        BlendMode blendMode,
                                                        float letterSpacing)

      Draws a text with a gradient along a circle. The circle represents the text baseline.

      This method uses the given gradient for the font coloring. The color of the graphics context is not used by this drawing.

      The anchor point is the center of the circle. The matrix defines the transformations to apply to the text (translation, scale, rotation). For example, passing the identity matrix to this method will align the center of the circle with the origin of the graphics context.

      The position where the text starts along the circle is the 3 o'clock position (positive X axis). This starting position can be modified by specifying a rotation into the transformation matrix.

      The text winds along the circle in the specified direction (clockwise or counter-clockwise). The radius of the circle must be positive. If it is less than or equal to 0, nothing is drawn.

      The font size must be positive. If it is less than or equal to 0, nothing is drawn.

      This method allows to specify the global opacity value to apply during the rendering. The alpha must be a value between 0 and 255. If the specified alpha is outside this range, nothing is drawn.

      The blend mode specifies the algorithm to use when blending the pixels of the source and destination.

      The letter spacing argument specifies the extra space to add between the characters. A positive value will move the characters apart, a negative value will move them together. The default value is 0.

      Parameters:
        `g` - the graphics context to draw on
        `string` - the string to draw
        `font` - the font to use
        `size` - the font size, in pixels
        `matrix` - the matrix to apply
        `gradient` - the gradient to color the string with
        `alpha` - the global opacity rendering value
        `blendMode` - the blend mode
        `letterSpacing` - the extra letter spacing to use, in pixels
        `radius` - the radius of the circle, in pixels
        `direction` - the winding direction of the text along the circle
      Throws:
        `VectorGraphicsException` - if the text could not be drawn for any reason (see `VectorGraphicsException.getErrorCode()`)
      See Also:
        `GraphicsContext.getAlpha(int)`, `BlendMode`, `VectorGraphicsPainter.Direction`