Skip to content

editorGlobalsCanvasHelper

Class: CanvasHelper

Hierarchy

  • CanvasHelper

Index

Properties

Methods

Properties

Static Private rasterizationCanvs

rasterizationCanvs: HTMLCanvasElement = null

Defined in src/util/CanvasHelper.ts:12

A shared canvas that is used to transforms SVGs into rasterized bitmaps (@see SvgDrawable._rasterizeImageToPseudoTransparency())

Methods

Static applyCLAHE

applyCLAHE(context: CanvasRenderingContext2D, width: number, height: number, clipLimit: number, tileSize: number[]): void

Defined in src/util/CanvasHelper.ts:73

Parameters:

Name Type Default
context CanvasRenderingContext2D -
width number -
height number -
clipLimit number 0.01
tileSize number[] [32, 32]

Returns: void


Static brightnessToTransparency

brightnessToTransparency(context: CanvasRenderingContext2D, width: number, height: number, maxTransparency: number, r: number, g: number, b: number): void

Defined in src/util/CanvasHelper.ts:51

To create the final image for the svg use grayscale, to avoid transparent backgrounds.

Parameters:

Name Type Default
context CanvasRenderingContext2D -
width number -
height number -
maxTransparency number 1
r number 0.2126
g number 0.7152
b number 0.0722

Returns: void


Static drawPolygon

drawPolygon(context: CanvasRenderingContext2D, polygonOutline: ArrayPoint2[], polygonHoles: ArrayPoint2[][], polygonToCanvasMapper: function): void

Defined in src/util/CanvasHelper.ts:193

Draw the polygon as path to the context. Outlines and holes must be in opposite winding order.

Parameters:

context: CanvasRenderingContext2D

-

polygonOutline: ArrayPoint2[]

-

polygonHoles: ArrayPoint2[][]

-

Default value polygonToCanvasMapper: function= v => v

-

▸ (Vector3: any): Vector3

Parameters:

Name Type
Vector3 any

Returns: void


Static fillPolygons

fillPolygons(context: CanvasRenderingContext2D, polygons: Polygon[], polygonToCanvasMapper: function): void

Defined in src/util/CanvasHelper.ts:89

Draws and fill the given polygons on the rendering context.

Parameters:

context: CanvasRenderingContext2D

-

polygons: Polygon[]

-

Default value polygonToCanvasMapper: function= v => v

-

▸ (Vector3: any): Vector3

Parameters:

Name Type
Vector3 any

Returns: void


Static grayscale

grayscale(context: CanvasRenderingContext2D, width: number, height: number, r: number, g: number, b: number): void

Defined in src/util/CanvasHelper.ts:14

Parameters:

Name Type Default
context CanvasRenderingContext2D -
width number -
height number -
r number 0.2126
g number 0.7152
b number 0.0722

Returns: void


Static svgStringToImage

svgStringToImage(svgString: string): Promise‹HTMLImageElement›

Defined in src/util/CanvasHelper.ts:104

Transforms an svg to an HTMLImageElement

Parameters:

Name Type Description
svgString string the string that describes the svg

Returns: Promise‹HTMLImageElement›


Static svgStringToRasterizedImage

svgStringToRasterizedImage(svgString: string, backgroundStyle: string, asJPG: boolean, overrideSize: Vector2, overrideAspectRatio: boolean): Promise‹HTMLImageElement›

Defined in src/util/CanvasHelper.ts:126

Renders an svg to a canvas to rasterize it

Parameters:

Name Type Default Description
svgString string - the string that describes the svg
backgroundStyle string "rgba(255, 255, 255, 255)" the style string to fill the background with
asJPG boolean true will be rasterized as jpg when set to true
overrideSize Vector2 null the size of the rastered image. the natural width and height of the svg will be used if not set
overrideAspectRatio boolean false - the svg will keep it's aspect ratio when false and stretch to the given overrideSize when true

Returns: Promise‹HTMLImageElement›