Class: Canvg
SVG renderer on canvas.
Constructors​
constructor​
• new Canvg(ctx, svg, options?)
Main constructor.
Parameters​
| Name | Type | Description |
|---|---|---|
ctx | RenderingContext2D | Rendering context. |
svg | Document | SVG Document. |
options | IOptions | Rendering options. |
Defined in​
Properties​
parser​
• Readonly parser: Parser
XML/HTML parser instance.
Defined in​
screen​
• Readonly screen: Screen
Screen instance.
Defined in​
document​
• Readonly document: Document
Canvg Document.
Defined in​
documentElement​
• Private Readonly documentElement: SVGElement
Defined in​
options​
• Private Readonly options: IOptions
Defined in​
Methods​
from​
â–¸ Static from(ctx, svg, options?): Promise<Canvg>
Create Canvg instance from SVG source string or URL.
Parameters​
| Name | Type | Description |
|---|---|---|
ctx | RenderingContext2D | Rendering context. |
svg | string | SVG source string or URL. |
options | IOptions | Rendering options. |
Returns​
Promise<Canvg>
Canvg instance.
Defined in​
fromString​
â–¸ Static fromString(ctx, svg, options?): Canvg
Create Canvg instance from SVG source string.
Parameters​
| Name | Type | Description |
|---|---|---|
ctx | RenderingContext2D | Rendering context. |
svg | string | SVG source string. |
options | IOptions | Rendering options. |
Returns​
Canvg instance.
Defined in​
fork​
â–¸ fork(ctx, svg, options?): Promise<Canvg>
Create new Canvg instance with inherited options.
Parameters​
| Name | Type | Description |
|---|---|---|
ctx | RenderingContext2D | Rendering context. |
svg | string | SVG source string or URL. |
options | IOptions | Rendering options. |
Returns​
Promise<Canvg>
Canvg instance.
Defined in​
forkString​
â–¸ forkString(ctx, svg, options?): Canvg
Create new Canvg instance with inherited options.
Parameters​
| Name | Type | Description |
|---|---|---|
ctx | RenderingContext2D | Rendering context. |
svg | string | SVG source string. |
options | IOptions | Rendering options. |
Returns​
Canvg instance.
Defined in​
ready​
â–¸ ready(): Promise<void>
Document is ready promise.
Returns​
Promise<void>
Ready promise.
Defined in​
isReady​
â–¸ isReady(): boolean
Document is ready value.
Returns​
boolean
Is ready or not.
Defined in​
render​
â–¸ render(options?): Promise<void>
Render only first frame, ignoring animations and mouse.
Parameters​
| Name | Type | Description |
|---|---|---|
options | IScreenStartOptions | Rendering options. |
Returns​
Promise<void>
Defined in​
start​
â–¸ start(options?): void
Start rendering.
Parameters​
| Name | Type | Description |
|---|---|---|
options | IScreenStartOptions | Render options. |
Returns​
void
Defined in​
stop​
â–¸ stop(): void
Stop rendering.
Returns​
void
Defined in​
resize​
â–¸ resize(width, height?, preserveAspectRatio?): void
Resize SVG to fit in given size.
Parameters​
| Name | Type | Default value |
|---|---|---|
width | number | undefined |
height | number | width |
preserveAspectRatio | string | boolean | false |
Returns​
void