This module provides the handwriting suite components, including the canvas and toolbar, which are integrated to quickly implement the handwriting capability.
You need to provide entrances and callbacks to the handwriting canvas. The canvas will trigger a callback when the initialization, loading, and saving actions are complete. You can customize app behavior in the callback.
Since: 5.0.0(12)
import { HandwriteController,HandwriteComponent, PenHspInfo, PenType, HiddenToolType, HiddenConfig } from '@kit.Penkit'; Model restriction: This API can be used only in the stage model.
Decorator: @Component
System capability: SystemCapability.Stylus.Handwrite
Since: 5.0.0(12)
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| handwriteController | HandwriteController | No | No | Instance of the handwriting suite function class. |
| onInit | InitCallback | No | Yes | InitCallback:() => void, callback for suite initialization. |
| onScale | ScaleCallback | No | Yes | ScaleCallback: (scale: number) => void, callback for canvas scaling. The parameter of the callback method is the scaling factor of the current canvas. |
| defaultPenType | PenType | No | Yes | Sets the default brush feature. In version 5.1.0(18), only parameters of the number type can be passed. The supported brushes are: 1: pen 2: ballpoint pen 3: pencil 4: marker 5: highlighter 7: mosaic pen 8: rubber 9: lasso 10: laser pointer Since: 5.1.0(18) |
| defaultPenInfo | PenHspInfo[] | No | Yes | Sets the default width of each brush. Since: 5.1.0(18) |
| widthRatio | number | No | Yes | Canvas width ratio. The value range is [0, 1]. The default value is 1. Since: 6.0.0(20) |
| heightRatio | number | No | Yes | Canvas height ratio. The value range is [0, 1]. The default value is 1. Since: 6.0.0(20) |
| maxCanvasHeight | number | No | Yes | Maximum height of the long canvas. The unit is vp. The value must be greater than 0. The default value is infinite. Since: 6.1.0(23) |
| scaleDisabled | boolean | No | Yes | Indicates whether to disable canvas scaling. The options are true (yes) and false (no). The default value is false. When scaleDisabled is set to true, users cannot zoom in or out on the canvas using gestures. This is applicable to scenarios where a fixed aspect ratio is required. Since: 6.1.0(23) |
| onDidScroll | DidScrollCallback | No | Yes | Callback for canvas scrolling. This callback id used to listen for the canvas scrolling position. Since: 6.1.0(23) |
| hiddenTools | HiddenConfig | No | Yes | Customizes handwriting tools. (Hides unnecessary handwriting tools.) Since: 26.0.0 |
build(): void
Default constructor of a struct. This method cannot be directly called.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.Stylus.Handwrite
Since: 5.0.0(12)
type InitCallback = () => void
Callback for suite initialization. This API uses an asynchronous callback to return the result.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.Stylus.Handwrite
Since: 5.1.0(18)
type ScaleCallback = (scale: number) => void
Callback for canvas scaling. This API uses an asynchronous callback to return the result.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.Stylus.Handwrite
Since: 5.1.0(18)
Parameters:
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| scale | number | Yes | Callback used to return the scaling factor of the current canvas. |
type DidScrollCallback = (yOffset: number) => void
Callback for canvas scrolling. This callback is triggered when the canvas is scrolled to obtain the offset of the current canvas. This API uses an asynchronous callback to return the result.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.Stylus.Handwrite
Since: 6.1.0(23)
Parameters:
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| yOffset | number | Yes | Offset of the current canvas. The unit is vp. |
Brush types.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.Stylus.Handwrite
Since: 5.1.0(18)
| Name | Value | Description |
|---|---|---|
| PEN | 1 | Pen. |
| BALLPOINT_PEN | 2 | Ballpoint pen. |
| PENCIL | 3 | Pencil. |
| MARKER | 4 | Marker. |
| HIGHLIGHTER_BRUSH | 5 | Highlighter. |
| MOSAIC | 7 | Mosaic pen. |
| RUBBER | 8 | Rubber. |
| LASSO | 9 | Lasso. |
| LASER | 10 | Laser pointer. |
Brush type and width.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.Stylus.Handwrite
Since: 5.1.0(18)
Parameters:
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| penType | PenType | No | No | Brush type. In version 5.1.0(18), only parameters of the number type can be passed. |
| penWidth | number | No | No | Brush width. The default width and value range of each brush are as follows: - Pen 4(2-10) - Ballpoint pen 4(2-10) - Pencil 8(4-20) - Marker 32(16-80) - Highlighter 32(16-80) - Mosaic pen 40(8-40) - Rubber 50(10-120) - Laser pointer 20(8-48) |