A custom field canvas can be used to draw on a custom field using the standard canvas drawing commands in Javascript. The output would be rendered as vector where possible and it will support the color format of MegaEdit, not just RGB.

Hierarchy

  • CustomFieldCanvas

Properties

height: number

The height of the canvas in pixels. This is the field height multiplied by the scale factor defined for the custom field.

width: number

The width of the canvas. This is the field with multiplied by the scale factor defined for the custom field.

Methods

  • Serialize the drawing commands issued so far into the field definition. The field will then reflect the drawing commands when rendered.

    Parameters

    • Optional target: CustomFieldDrawingCommandTarget

      The target defines which canvas to write to. The default is the data canvas.

    • Optional callback: (() => void)

      The callback will be triggered once the field has been written to. This may be asynchronous if images have to be saved.

        • (): void
        • Returns void

    Returns void

  • Generate the 2d drawing context. This is of type CanvasRenderingContext2D https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D

    The drawing context can be used almost normally with a few exceptions:

    • most, but not all drawing commands are supported: check the console log for any warnings
    • the color format is MegaEdit's internal format, not jsut RGB. You can use CMYK or spot colors as well in the drawing commands.

    Parameters

    • type: "2d"

      Must be "2d"

    Returns CanvasRenderingContext2D

  • Generate a blob object from the canvas

    Parameters

    • callback: ((blob) => void)

      The callback to call when the blob is ready

        • (blob): void
        • Parameters

          • blob: Blob

          Returns void

    • Optional type: string

      The type of the blob - defaults to "image/png" - see https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob

    • Optional encoderOptions: number

      Optional encoder options when the type supports them (e.g. JPEG or webp)

    Returns void

Generated using TypeDoc