# PaintToolsPlugin

## Content

# Class: PaintToolsPlugin

Paint Tools Plugin.
Adds the "Paint tools", "Effects" and "Text and Objects" buttons.

## Example

```html
<script src="dsimageviewer.js"></script></head>
<script src="plugins/paintTools.js"></script>
<script>
  const viewer = new DsImageViewer("#root");
  viewer.addPlugin(new PaintToolsPlugin());
</script>
```

## Properties

### viewer

```ts
viewer: ImageViewerAPI;
```

Gets the image viewer instance.
The image viewer instance.

#### Implementation of

```ts
PaintToolsPluginAPI.viewer
```

***

### options

```ts
options: PaintToolsPluginOptions;
```

Plugin options passed at construction time.

#### Implementation of

```ts
PaintToolsPluginAPI.options
```

***

### toolsOptions

```ts
toolsOptions: Required<ToolsOptions>;
```

Gets or sets the default visual properties for each paint and object tool at runtime.

Reading this property returns the last value set either via the constructor option
`toolsOptions` or by a previous assignment.

Setting this property immediately:
- updates the paint toolbar state (size, color, opacity, hardness for Pencil, Brush, Eraser, Clone Stamp, and Text),
- updates the default style applied to **newly created** shape objects (Rectangle, Line, Arrow, Circle, Brackets, Image).

Previously placed objects and the user's own interactive adjustments are not affected.

#### Example

```javascript
// Change arrow and pencil defaults after the viewer has opened
const plugin = viewer.findPlugin('paintTools');
plugin.toolsOptions = {
  lineWidth: 3,
  lineColor: '#cc0000',
  penSize: 5,
  penColor: '#333333',
};
```

#### Implementation of

```ts
PaintToolsPluginAPI.toolsOptions
```

***

### effectsToolbarLayout

```ts
effectsToolbarLayout: ToolbarItemType[];
```

Returns the resolved item layout for the Effects toolbar.
Reflects `toolbarLayout.effectsTools` from plugin options:
`true`/`undefined`/`null` → default layout; `false` → empty array; array → used as-is.

#### See

#### Implementation of

```ts
PaintToolsPluginAPI.effectsToolbarLayout
```

***

### paintToolbarLayout

```ts
paintToolbarLayout: ToolbarItemType[];
```

Returns the layout for the effects tools toolbar.
If the value is `true`, `undefined`, or `null`, a default layout is returned.
If the value is `false`, an empty layout is returned.
Otherwise, the provided custom layout is used.

#### See

#### Implementation of

```ts
PaintToolsPluginAPI.paintToolbarLayout
```

***

### textToolbarLayout

```ts
textToolbarLayout: ToolbarItemType[];
```

Returns the layout for the effects tools toolbar.
If the value is `true`, `undefined`, or `null`, a default layout is returned.
If the value is `false`, an empty layout is returned.
Otherwise, the provided custom layout is used.

#### See

#### Implementation of

```ts
PaintToolsPluginAPI.textToolbarLayout
```

***

### objectsToolbarLayout

```ts
objectsToolbarLayout: ToolbarItemType[];
```

Returns the layout for the effects tools toolbar.
If the value is `true`, `undefined`, or `null`, a default layout is returned.
If the value is `false`, an empty layout is returned.
Otherwise, the provided custom layout is used.

#### See

#### Implementation of

```ts
PaintToolsPluginAPI.objectsToolbarLayout
```

***

### paintLayer

```ts
paintLayer: ImageLayer;
```

Gets the paint layer containing the HTML canvas for drawing the image.

#### Implementation of

```ts
PaintToolsPluginAPI.paintLayer
```

***

### isReady

```ts
isReady: boolean;
```

Returns true if the image is loaded into the viewer and the image format is supported by the Image Filters plugin.

#### Implementation of

```ts
PaintToolsPluginAPI.isReady
```

***

### naturalSize

```ts
naturalSize: Size;
```

Natural image size.

#### Implementation of

```ts
PaintToolsPluginAPI.naturalSize
```

***

### id

```ts
id: PluginType;
```

Unique plug-in identifier.

#### Implementation of

```ts
PaintToolsPluginAPI.id
```

## Methods

### isImageFormatSupported()

```ts
isImageFormatSupported(imageFormat, allowUnknown?): boolean;
```

Determines whether the specified image format is supported for modifications.

#### Parameters

##### imageFormat

The image format to check, either as an enum value or string.

`string` | `ImageFormatCode`

##### allowUnknown?

`boolean`

If true, allows unknown formats (ImageFormatCode.Default) to be considered supported.

#### Returns

`boolean`

True if the format is supported for modifications, false otherwise.

#### Remarks

The following formats are explicitly not supported:
- TIFF (ImageFormatCode.TIFF)
- SVG (ImageFormatCode.SVG)
- ICO (ImageFormatCode.ICO)
- GIF (ImageFormatCode.GIF)

#### Examples

```ts
// Check if PNG is supported
const supported = isImageFormatSupported(ImageFormatCode.PNG);
```

```ts
// Check if an unknown format is supported (returns false by default)
const supported = isImageFormatSupported('custom-format');
```

```ts
// Check if an unknown format is supported (returns true when allowUnknown is true)
const supported = isImageFormatSupported('custom-format', true);
```

#### Implementation of

```ts
PaintToolsPluginAPI.isImageFormatSupported
```

***

### dispose()

```ts
dispose(): void;
```

Cleans up resources and disposes the plugin.

#### Returns

`void`

#### Implementation of

```ts
PaintToolsPluginAPI.dispose
```

***

### removePaintLayer()

```ts
removePaintLayer(): void;
```

Removes and disposes the active paint layer. If no paint layer exists, this method does nothing.

#### Returns

`void`

#### Implementation of

```ts
PaintToolsPluginAPI.removePaintLayer
```

***

### initialize()

```ts
initialize(viewer): void;
```

The method is called when the GcImageViewer component is initialized.

#### Parameters

##### viewer

[`ImageViewerAPI`](../interfaces/ImageViewerAPI)

#### Returns

`void`

#### Implementation of

```ts
PaintToolsPluginAPI.initialize
```
