@@ -113,11 +113,11 @@ Turn on the switch and the default delivery address is used. When the switch is
```
-```
+```css
/* xxx.css */
.container {
width: 100%;
- height: 100%;
+ height: 100%;
background-color: #F1F3F5;
flex-direction: column;
padding: 50px;
@@ -168,7 +168,7 @@ switch{
```
-```
+```js
// xxx.js
import prompt from '@system.prompt';
export default {
diff --git a/en/device-dev/driver/driver-platform-uart-des.md b/en/device-dev/driver/driver-platform-uart-des.md
index 20340bfd49d68136a9ca711cca35ca5c2cdb0834..3ddb92b532569df4718931c9c3ca32b7e7e010c1 100644
--- a/en/device-dev/driver/driver-platform-uart-des.md
+++ b/en/device-dev/driver/driver-platform-uart-des.md
@@ -1,156 +1,86 @@
-# UART
+# UART
-## Overview
-The Universal Asynchronous Receiver/Transmitter \(UART\) is a universal serial data bus used for asynchronous communication. It enables bi-directional communication between devices in full-duplex mode.
+## Overview
+
+The Universal Asynchronous Receiver/Transmitter (UART) is a universal serial data bus used for asynchronous communication. It enables bi-directional communication between devices in full-duplex mode.
+
UART is widely used to print information for debugging or to connect to various external modules such as GPS and Bluetooth.
-A UART is connected to other modules through two wires \(as shown in [Figure 1](#fig68294715408)\) or four wires \(as shown in [Figure 2](#fig179241542163112)\).
-- TX: TX pin of the transmitting UART. It is connected to the RX pin of the peer UART.
-- RX: RX pin of the receiving UART. It is connected to the TX pin of the peer UART.
-- RTS: Request to Send signal pin. It is connected to the CTS pin of the peer UART and is used to indicate whether the local UART is ready to receive data.
-- CTS: Clear to Send signal pin. It is connected to the RTS pin of the peer UART and is used to indicate whether the local UART is allowed to send data to the peer end.
-
- **Figure 1** 2-wire UART communication
- ![](figures/2-wire-uart-communication.png "2-wire-uart-communication")
-
- **Figure 2** 4-wire UART communication
- ![](figures/4-wire-uart-communication.png "4-wire-uart-communication")
-
-
-The transmitting and receiving UARTs must ensure that they have the same settings on particular attributes such as the baud rate and data format \(start bit, data bit, parity bit, and stop bit\) before they start to communicate. During data transmission, a UART sends data to the peer end over the TX pin and receives data from the peer end over the RX pin. When the size of the buffer used by a UART for storing received data reaches the preset threshold, the RTS signal of the UART changes to **1** \(data cannot be received\), and the peer UART stops sending data to it because its CTS signal does not allow it to send data.
-
-
-## Available APIs
-
-The UART interface defines a set of common functions for operating a UART port, including obtaining and releasing device handles, reading and writing data of a specified length, and obtaining and setting the baud rate, as well as the device attributes.
-
-**Table 1** APIs for the UART driver
-
-
-
Capability
- |
-Function
- |
-Description
- |
-
-
-Obtaining and releasing device handles
-
- |
-UartOpen
- |
-Obtains the UART device handle.
- |
-
-UartClose
- |
-Releases a specified UART device handle.
- |
-
-Reading and writing data
-
- |
-UartRead
- |
-Reads data of a specified length from a UART device.
- |
-
-UartWrite
- |
-Writes data of a specified length into a UART device.
- |
-
-Obtaining and setting the baud rate
- |
-UartGetBaud
- |
-Obtains the UART baud rate.
- |
-
-UartSetBaud
- |
-Sets the UART baud rate.
- |
-
-Obtaining and setting device attributes
-
- |
-UartGetAttribute
- |
-Obtains the UART device attributes.
- |
-
-UartSetAttribute
- |
-Sets the UART device attributes.
- |
-
-Setting the transmission mode
- |
-UartSetTransMode
- |
-Sets the UART transmission mode.
- |
-
-
-
-
->![](../public_sys-resources/icon-note.gif) **NOTE**
->All functions provided in this document can be called only in kernel space.
-
-## Usage Guidelines
-
-### How to Use
+
+A UART is connected to other modules through two wires (as shown in Figure 1) or four wires (as shown in Figure 2).
+ - TX: TX pin of the transmitting UART. It is connected to the RX pin of the peer UART.
+ - RX: RX pin of the receiving UART. It is connected to the TX pin of the peer UART.
+ - RTS: Request to Send signal pin. It is connected to the CTS pin of the peer UART and is used to indicate whether the local UART is ready to receive data.
+ - CTS: Clear to Send signal pin. It is connected to the RTS pin of the peer UART and is used to indicate whether the local UART is allowed to send data to the peer end.
+
+ **Figure 1** Two-wire UART communication
+
+ ![](figures/2-wire-uart-communication.png "2-wire-uart-communication")
+
+ **Figure 2** Four-wire UART communication
+
+ ![](figures/4-wire-uart-communication.png "4-wire-uart-communication")
+
+- The transmitting and receiving UARTs must ensure that they have the same settings on particular attributes such as the baud rate and data format (start bit, data bit, parity bit, and stop bit) before they start to communicate. During data transmission, a UART sends data to the peer end over the TX pin and receives data from the peer end over the RX pin. When the size of the buffer used by a UART for storing received data reaches the preset threshold, the RTS signal of the UART changes to **1** (data cannot be received), and the peer UART stops sending data to it because its CTS signal does not allow it to send data.
+
+- The UART interface defines a set of common functions for operating a UART port, including obtaining and releasing device handles, reading and writing data of a specified length, and obtaining and setting the baud rate, as well as the device attributes.
+
+
+## Available APIs
+
+ **Table 1** UART driver APIs
+
+| API| Description|
+| -------- | -------- |
+| UartOpen | Obtains a UART device handle.|
+| UartClose | Releases a UART device handle.|
+| UartRead | Reads data of the specified length from a UART device.|
+| UartWrite | Writes data of the specified length to a UART device.|
+| UartGetBaud | Obtains the UART baud rate.|
+| UartSetBaud | Sets the UART baud rate.|
+| UartGetAttribute | Obtains UART device attributes.|
+| UartSetAttribute | Sets UART device attributes.|
+| UartSetTransMode | Sets the UART transmission mode.|
+
+> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
+> All APIs described in this document can be called only in kernel mode.
+
+
+## Usage Guidelines
+
+
+### How to Use
The figure below illustrates how to use the APIs.
-**Figure 3** Using UART driver APIs
-![](figures/using-uart-process.png "process-of-using-a-uart-device")
-
-### Obtaining a UART Device Handle
-
-Before performing UART communication, call **UartOpen** to obtain a UART device handle. This function returns the pointer to the UART device handle with a specified port number.
-
-DevHandle UartOpen\(uint32\_t port\);
-
-**Table 2** Description of UartOpen
-
-
-
Parameter
- |
-Description
- |
-
-
-port
- |
-UART port number.
- |
-
-Return Value
- |
-Description
- |
-
-NULL
- |
-Failed to obtain the UART device handle.
- |
-
-Device handle
- |
-UART device handle.
- |
-
-
-
-
-The following example shows how to obtain a UART device handle based on the assumption that the UART port number is **3**:
-
-```
-DevHandle handle = NULL; /* The UART device handle */
-uint32_t port = 3; /* UART port number */
+ **Figure 3** Using UART driver APIs
+
+ ![](figures/using-UART-process.png)
+
+
+### Opening a UART Device Handle
+
+Before performing UART communication, call **UartOpen** to obtain a UART device handle. This function returns the pointer to the UART device handle with the specified port number.
+
+
+```
+DevHandle UartOpen(uint32_t port);
+```
+
+ **Table 2** Description of UartOpen
+
+| Parameter| Description|
+| -------- | -------- |
+| port | UART port number.|
+| **Return Value**| **Description**|
+| NULL | The operation failed.|
+| Device handle| The operation is successful. The obtained UART device handle is returned.|
+
+ Example: Obtain the device handle of UART port 3.
+
+```
+DevHandle handle = NULL; /* UART device handle */
+uint32_t port = 3; /* UART port number */
handle = UartOpen(port);
if (handle == NULL) {
HDF_LOGE("UartOpen: failed!\n");
@@ -158,51 +88,29 @@ if (handle == NULL) {
}
```
-### Setting the UART Baud Rate
-
-After obtaining the UART device handle, set the UART baud rate by calling the following function:
-
-int32\_t UartSetBaud\(DevHandle handle, uint32\_t baudRate\);
-
-**Table 3** Description of UartSetBaud
-
-
-
Parameter
- |
-Description
- |
-
-
-handle
- |
-UART device handle.
- |
-
-baudRate
- |
-Baud rate of the UART to set.
- |
-
-Return Value
- |
-Description
- |
-
-0
- |
-Succeeded in setting the UART baud rate.
- |
-
-Negative value
- |
-Failed to set the UART baud rate.
- |
-
-
-
-
-The following example shows how to set the UART baud rate to **9600**:
+### Setting the UART Baud Rate
+
+Call **UartSetBaud()** to set the UART baud rate.
+
+
+```
+int32_t UartSetBaud(DevHandle handle, uint32_t baudRate);
+```
+
+ **Table 3** Description of UartSetBaud
+
+| Parameter| Description|
+| -------- | -------- |
+| handle | UART device handle.|
+| baudRate | Baud rate to set.|
+| **Return Value**| **Description**|
+| 0 | The operation is successful.|
+| Negative value| The operation failed.|
+
+Example: Set the UART baud rate to **9600**.
+
+
```
int32_t ret;
/* Set the UART baud rate to 9600. */
@@ -212,51 +120,29 @@ if (ret != 0) {
}
```
-### Obtaining the UART Baud Rate
-
-After setting the UART baud rate, obtain the current baud rate by calling the following function:
-
-int32\_t UartGetBaud\(DevHandle handle, uint32\_t \*baudRate\);
-
-**Table 4** Description of UartGetBaud
-
-
-
Parameter
- |
-Description
- |
-
-
-handle
- |
-UART device handle.
- |
-
-baudRate
- |
-Pointer to the UART baud rate.
- |
-
-Return Value
- |
-Description
- |
-
-0
- |
-Succeeded in obtaining the UART baud rate.
- |
-
-Negative value
- |
-Failed to obtain the UART baud rate.
- |
-
-
-
-
-The following example shows how to obtain the UART baud rate:
+### Obtaining the UART Baud Rate
+
+Call **UartGetBaud()** to obtain the UART baud rate.
+
+
+```
+int32_t UartGetBaud(DevHandle handle, uint32_t *baudRate);
+```
+
+ **Table 4** Description of UartGetBaud
+
+| Parameter| Description|
+| -------- | -------- |
+| handle | UART device handle.|
+| baudRate | Pointer to the UART baud rate obtained.|
+| **Return Value**| **Description**|
+| 0 | The operation is successful.|
+| Negative value| The operation failed.|
+
+Example: Obtain the UART baud rate.
+
+
```
int32_t ret;
uint32_t baudRate;
@@ -267,168 +153,102 @@ if (ret != 0) {
}
```
-### Setting the UART Device Attributes
-
-Before performing UART communication, set the UART device attributes by calling the following function:
-
-int32\_t UartSetAttribute\(DevHandle handle, struct UartAttribute \*attribute\);
-
-**Table 5** Description of UartSetAttribute
-
-
-
Parameter
- |
-Description
- |
-
-
-handle
- |
-UART device handle.
- |
-
-attribute
- |
-Pointer to the UART device attributes to set.
- |
-
-Return Value
- |
-Description
- |
-
-0
- |
-Succeeded in setting the UART device attributes.
- |
-
-Negative value
- |
-Failed to set the UART device attributes.
- |
-
-
-
-
-The following example shows how to set the UART device attributes:
+### Setting UART Device Attributes
+
+Call **UartSetAttribute()** to set UART device attributes.
+
+
+```
+int32_t UartSetAttribute(DevHandle handle, struct UartAttribute *attribute);
+```
+
+ **Table 5** Description of UartSetAttribute
+
+| Parameter| Description|
+| -------- | -------- |
+| handle | UART device handle.|
+| attribute | Pointer to the UART device attributes to set.|
+| **Return Value**| **Description**|
+| 0 | The operation is successful.|
+| Negative value| The operation failed.|
+
+Example: Set UART device attributes.
+
+
```
int32_t ret;
struct UartAttribute attribute;
-attribute.dataBits = UART_ATTR_DATABIT_7; /* Set the number of data bits to 7. */
-attribute.parity = UART_ATTR_PARITY_NONE; /* Set the parity bit to no parity. */
+attribute.dataBits = UART_ATTR_DATABIT_7; /* Enable 7 bits to be transferred each time. */
+attribute.parity = UART_ATTR_PARITY_NONE; /* Disable parity check. */
attribute.stopBits = UART_ATTR_STOPBIT_1; /* Set the stop bit to 1. */
attribute.rts = UART_ATTR_RTS_DIS; /* Disable the RTS signal. */
attribute.cts = UART_ATTR_CTS_DIS; /* Disable the CTS signal. */
attribute.fifoRxEn = UART_ATTR_RX_FIFO_EN; /* Enable RX FIFO. */
attribute.fifoTxEn = UART_ATTR_TX_FIFO_EN; /* Enable TX FIFO. */
-/* Set the UART device attributes. */
+/* Set UART device attributes. */
ret = UartSetAttribute(handle, &attribute);
if (ret != 0) {
HDF_LOGE("UartSetAttribute: failed, ret %d\n", ret);
}
```
-### Obtaining UART Device Attributes
-
-After setting the UART device attributes, obtain the current device attributes by calling the following function:
-
-int32\_t UartGetAttribute\(DevHandle handle, struct UartAttribute \*attribute\);
-
-**Table 6** Description of UartGetAttribute
-
-
-
Parameter
- |
-Description
- |
-
-
-handle
- |
-UART device handle.
- |
-
-attribute
- |
-Pointer to the UART device attributes.
- |
-
-Return Value
- |
-Description
- |
-
-0
- |
-Succeeded in obtaining the UART device attributes.
- |
-
-Negative value
- |
-Failed to obtain the UART device attributes.
- |
-
-
-
-
-The following example shows how to obtain the UART device attributes:
+### Obtaining UART Device Attributes
+
+Call **UartGetAttribute()** to obtain the current UART device attributes.
+
+
+```
+int32_t UartGetAttribute(DevHandle handle, struct UartAttribute *attribute);
+```
+
+ **Table 6** Description of UartGetAttribute
+
+| Parameter| Description|
+| -------- | -------- |
+| handle | UART device handle.|
+| attribute | Pointer to the UART device attributes obtained.|
+| **Return Value**| **Description**|
+| 0 | The operation is successful.|
+| Negative value| The operation failed.|
+
+Example: Obtain UART device attributes.
+
+
```
int32_t ret;
struct UartAttribute attribute;
-/* Obtain the UART attributes. */
+/* Obtain UART device attributes. */
ret = UartGetAttribute(handle, &attribute);
if (ret != 0) {
HDF_LOGE("UartGetAttribute: failed, ret %d\n", ret);
}
```
-### Setting the UART Transmission Mode
-
-Before performing UART communication, set the UART transmission mode by calling the following function:
-
-int32\_t UartSetTransMode\(DevHandle handle, enum UartTransMode mode\);
-
-**Table 7** Description of UartSetTransMode
-
-
-
Parameter
- |
-Description
- |
-
-
-handle
- |
-UART device handle.
- |
-
-mode
- |
-UART transmission mode to set.
- |
-
-Return Value
- |
-Description
- |
-
-0
- |
-Succeeded in setting the UART transmission mode.
- |
-
-Negative value
- |
-Failed to set the UART transmission mode.
- |
-
-
-
-
-The following example shows how to set the transmission mode to **UART\_MODE\_RD\_BLOCK**:
+### Setting the UART Transmission Mode
+
+Call **UartSetTransMode()** to set the UART transmission mode.
+
+
+```
+int32_t UartSetTransMode(DevHandle handle, enum UartTransMode mode);
+```
+
+ **Table 7** Description of UartSetTransMode
+
+| Parameter| Description|
+| -------- | -------- |
+| handle | UART device handle.|
+| mode | UART transmission mode to set.|
+| **Return Value**| **Description**|
+| 0 | The operation is successful.|
+| Negative value| The operation failed.|
+
+Example: Set the UART transmission mode to **UART_MODE_RD_BLOCK**.
+
+
```
int32_t ret;
/* Set the UART transmission mode. */
@@ -438,116 +258,64 @@ if (ret != 0) {
}
```
-### Writing Data of a Specified Length into a UART Device
-
-To write data into a UART device, call the following function:
-
-int32\_t UartWrite\(DevHandle handle, uint8\_t \*data, uint32\_t size\);
-
-**Table 8** Description of UartWrite
-
-
-
Parameter
- |
-Description
- |
-
-
-handle
- |
-UART device handle.
- |
-
-data
- |
-Pointer to the data to write.
- |
-
-size
- |
-Length of the data to write.
- |
-
-Return Value
- |
-Description
- |
-
-0
- |
-Succeeded in writing data into the UART device.
- |
-
-Negative value
- |
-Failed to write data into the UART device.
- |
-
-
-
-
-The following example shows how to write data of a specified length into the UART device:
+### Writing Data to a UART Device
+
+Call **UartWrite()** to write data of the specified length to a UART device.
+
+
+```
+int32_t UartWrite(DevHandle handle, uint8_t *data, uint32_t size);
+```
+
+ **Table 8** Description of UartWrite
+
+| Parameter| Description|
+| -------- | -------- |
+| handle | UART device handle.|
+| data | Pointer to the data to write.|
+| size | Length of the data to write.|
+| **Return Value**| **Description**|
+| 0 | The operation is successful.|
+| Negative value| The operation failed.|
+
+Example: Write data to a UART device.
+
+
```
int32_t ret;
uint8_t wbuff[5] = {1, 2, 3, 4, 5};
-/* Write 5-byte data into the UART device. */
+/* Write 5-byte data to the UART device. */
ret = UartWrite(handle, wbuff, 5);
if (ret != 0) {
HDF_LOGE("UartWrite: failed, ret %d\n", ret);
}
```
-### Reading Data of a Specified Length from a UART Device
-
-To write data into a UART device, call the following function:
-
-int32\_t UartRead\(DevHandle handle, uint8\_t \*data, uint32\_t size\);
-
-**Table 9** Description of UartRead
-
-
-
Parameter
- |
-Description
- |
-
-
-handle
- |
-UART device handle.
- |
-
-data
- |
-Pointer to the buffer for receiving the data.
- |
-
-size
- |
-Length of the data to read.
- |
-
-Return Value
- |
-Description
- |
-
-Non-negative value
- |
-Length of the data read from the UART device.
- |
-
-Negative value
- |
-Failed to read data from the UART device.
- |
-
-
-
-
-The following example shows how to read data of a specified length from the UART device:
+### Reading Data from a UART Device
+
+Call **UartRead()** to read data of the specified length from a UART device.
+
+
+```
+int32_t UartRead(DevHandle handle, uint8_t *data, uint32_t size);
+```
+
+ **Table 9** Description of UartRead
+
+| Parameter| Description|
+| -------- | -------- |
+| handle | UART device handle.|
+| data | Pointer to the buffer for receiving the data.|
+| size | Length of the data to read.|
+| **Return Value**| **Description**|
+| Non-negative value| The operation is successful. The length of the data read is returned.|
+| Negative value| The operation failed.|
+
+Example: Read data of the specified length from a UART device.
+
+
```
int32_t ret;
uint8_t rbuff[5] = {0};
@@ -558,44 +326,39 @@ if (ret < 0) {
}
```
->![](../public_sys-resources/icon-caution.gif) **CAUTION:**
->Data is successfully read from the UART device if a non-negative value is returned. If the return value is **0**, no valid data can be read from the UART device. If the return value is greater than **0**, the return value is the length of the data actually read from the UART device. The length is less than or equal to the value of **size** and does not exceed the maximum length of data to read at a time specified by the UART controller in use.
+> ![icon-caution.gif](../public_sys-resources/icon-caution.gif) **CAUTION**
+> Data is successfully read from the UART device if a non-negative value is returned. If **0** is returned, no valid data can be read from the UART device. A value greater than **0** indicates the length of the data read from the UART device. The data length must be less than or equal to the value of **size** and cannot exceed the maximum length of the data to read at a time specified by the UART controller in use.
-### Destroying the UART Device Handle
-After the UART communication, destroy the UART device handle by calling the following function:
+### Closing a UART Device Handle
-void UartClose\(DevHandle handle\);
+Call **UartClose()** to close a UART device handle.
-This function will release the resources previously obtained.
+
+```
+void UartClose(DevHandle handle);
+```
-**Table 10** Description of UartClose
+This function releases the resources requested by **UartOpen**.
-
-
Parameter
- |
-Description
- |
-
-
-handle
- |
-UART device handle.
- |
-
-
-
+ **Table 10** Description of UartClose
-The following example shows how to destroy the UART device handle:
+| Parameter| Description|
+| -------- | -------- |
+| handle | UART device handle to close.|
+Example: Close a UART device handle.
+
+
```
-UartClose(handle); /* Destroy the UART device handle. */
+UartClose(handle); /* Close the UART device handle. */
```
-## Usage Example
-The following is a usage example of a UART device, including how to obtain the UART device handle, set the baud rate, device attributes, and transmission mode, read data from or write data into the UART device, and then destroy the UART device handle.
+## Example
+ The following example shows how to open a UART device handle, set the baud rate, device attributes, and transmission mode, read data from or write data into the UART device, and then close the UART device handle.
+
```
#include "hdf_log.h"
#include "uart_if.h"
@@ -608,16 +371,16 @@ void UartTestSample(void)
uint8_t wbuff[5] = { 1, 2, 3, 4, 5 };
uint8_t rbuff[5] = { 0 };
struct UartAttribute attribute;
- attribute.dataBits = UART_ATTR_DATABIT_7; /* Set the number of data bits to 7. */
- attribute.parity = UART_ATTR_PARITY_NONE; /* Set the parity bit to no parity. */
+ attribute.dataBits = UART_ATTR_DATABIT_7; /* Enable 7 bits to be transferred each time. */
+ attribute.parity = UART_ATTR_PARITY_NONE; /* Disable parity check. */
attribute.stopBits = UART_ATTR_STOPBIT_1; /* Set the stop bit to 1. */
attribute.rts = UART_ATTR_RTS_DIS; /* Disable the RTS signal. */
attribute.cts = UART_ATTR_CTS_DIS; /* Disable the CTS signal. */
attribute.fifoRxEn = UART_ATTR_RX_FIFO_EN; /* Enable RX FIFO. */
attribute.fifoTxEn = UART_ATTR_TX_FIFO_EN; /* Enable TX FIFO. */
- /* Set the UART port number actually used. */
+ /* Enter the UART port number. */
port = 1;
- /* Obtain the UART device handle. */
+ /* Open the UART device handle based on the port number. */
handle = UartOpen(port);
if (handle == NULL) {
HDF_LOGE("UartOpen: failed!\n");
@@ -629,7 +392,7 @@ void UartTestSample(void)
HDF_LOGE("UartSetBaud: failed, ret %d\n", ret);
goto _ERR;
}
- /* Set the UART device attributes. */
+ /* Set UART device attributes. */
ret = UartSetAttribute(handle, &attribute);
if (ret != 0) {
HDF_LOGE("UartSetAttribute: failed, ret %d\n", ret);
@@ -641,7 +404,7 @@ void UartTestSample(void)
HDF_LOGE("UartSetTransMode: failed, ret %d\n", ret);
goto _ERR;
}
- /* Write 5-byte data into the UART device. */
+ /* Write 5-byte data to the UART device. */
ret = UartWrite(handle, wbuff, 5);
if (ret != 0) {
HDF_LOGE("UartWrite: failed, ret %d\n", ret);
@@ -654,7 +417,7 @@ void UartTestSample(void)
goto _ERR;
}
_ERR:
- /* Destroy the UART device handle. */
+ /* Close the UART device handle. */
UartClose(handle);
}
-```
\ No newline at end of file
+```
diff --git a/en/device-dev/driver/driver-platform-uart-develop.md b/en/device-dev/driver/driver-platform-uart-develop.md
index 5f5e3d25e3f8c801251fac77286bcc45489df717..cf3393d01505ceccb7c34b643a9ce218f148ce6c 100644
--- a/en/device-dev/driver/driver-platform-uart-develop.md
+++ b/en/device-dev/driver/driver-platform-uart-develop.md
@@ -14,7 +14,7 @@ In the Hardware Driver Foundation (HDF), the Universal Asynchronous Receiver/Tra
**UartHostMethod**:
-
+
```
struct UartHostMethod {
int32_t (*Init)(struct UartHost *host);
@@ -32,18 +32,18 @@ struct UartHostMethod {
**Table 1** Description of the callback functions in UartHostMethod
-| Function| Input Parameter| Output Parameter| Return Value| Description|
+| Function| Input Parameter| Output Parameter| Return Value| Description|
| -------- | -------- | -------- | -------- | -------- |
-| Init | **host**: structure pointer to the UART controller at the core layer.| –| HDF_STATUS| Initializes a UART device.|
-| Deinit | **host**: structure pointer to the UART controller at the core layer.| –| HDF_STATUS| Deinitializes a UART device.|
-| Read | **host**: structure pointer to the UART controller at the core layer.
**size**: data size, which is of the uint32_t type.| **data**: pointer to the output data. The value is of the uint8_t type.| HDF_STATUS| Reads data.|
-| Write | **host**: structure pointer to the UART controller at the core layer.
**data**: pointer to the input data. The value is of the uint8_t type.
**size**: data size, which is of the uint32_t type.| –| HDF_STATUS| Writes data.|
-| SetBaud | **host**: structure pointer to the UART controller at the core layer.
**baudRate**: pointer to the input baud rate. The value is of the uint32_t type. | –| HDF_STATUS| Sets the baud rate.|
-| GetBaud | **host**: structure pointer to the UART controller at the core layer.| **baudRate**: pointer to the output baud rate. The value is of the uint32_t type.| HDF_STATUS| Obtains the current baud rate.|
-| GetAttribute | **host**: structure pointer to the UART controller at the core layer.| **attribute**: structure pointer to the UART attributes. For details, see **UartAttribute** in **uart_if.h**.| HDF_STATUS| Obtains UART attributes.|
-| SetAttribute | **host**: structure pointer to the UART controller at the core layer.
**attribute**: structure pointer to the UART attributes to set.| –| HDF_STATUS| Sets UART attributes.|
-| SetTransMode | **host**: structure pointer to the UART controller at the core layer.
**mode**: transfer mode to set. For details, see **UartTransMode** in **uart_if.h**.| –| HDF_STATUS| Sets the UART transfer mode.|
-| PollEvent | **host**: structure pointer to the UART controller at the core layer.
**filep**: void pointer to a file.
**table**: void pointer to poll_table.| –| HDF_STATUS| Polls for pending events.|
+| Init | **host**: structure pointer to the UART controller at the core layer.| –| HDF_STATUS| Initializes a UART device.|
+| Deinit | **host**: structure pointer to the UART controller at the core layer.| –| HDF_STATUS| Deinitializes a UART device.|
+| Read | **host**: structure pointer to the UART controller at the core layer.
**size**: data size, which is of the uint32_t type.| **data**: pointer to the data read. The value is of the uint8_t type. | HDF_STATUS| Reads data.|
+| Write | **host**: structure pointer to the UART controller at the core layer.
**data**: pointer to the data to write. The value is of the uint8_t type.
**size**: data size, which is of the uint32_t type. | –| HDF_STATUS| Writes data.|
+| SetBaud | **host**: structure pointer to the UART controller at the core layer.
**baudRate**: pointer to the baud rate to set. The value is of the uint32_t type. | –| HDF_STATUS| Sets the baud rate.|
+| GetBaud | **host**: structure pointer to the UART controller at the core layer.| **baudRate**: pointer to the baud rate obtained. The value is of the uint32_t type. | HDF_STATUS| Obtains the current baud rate.|
+| GetAttribute | **host**: structure pointer to the UART controller at the core layer.| **attribute**: structure pointer to the attribute obtained. For details, see **UartAttribute** in **uart_if.h**. | HDF_STATUS| Obtains UART attributes.|
+| SetAttribute | **host**: structure pointer to the UART controller at the core layer.
**attribute**: structure pointer to the attribute to set. | –| HDF_STATUS| Sets UART attributes.|
+| SetTransMode | **host**: structure pointer to the UART controller at the core layer.
**mode**: transfer mode to set. For details, see **UartTransMode** in **uart_if.h**.| –| HDF_STATUS| Sets the UART transfer mode.|
+| PollEvent | **host**: structure pointer to the UART controller at the core layer.
**filep**: void pointer to a file.
**table**: void pointer to poll_table.| –| HDF_STATUS| Polls for pending events.|
## How to Develop
@@ -61,10 +61,11 @@ The UART module adaptation involves the following steps:
3. Instantiate the UART controller object.
- Initialize **UartHost**.
- Instantiate **UartHostMethod** in the **UartHost** object.
- > ![icon-note.gif](../public_sys-resources/icon-note.gif) **NOTE**
+ > ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
> For details about the functions in **UartHostMethod**, see [Available APIs](#available-apis).
-4. Debug the driver.
+4. Debug the driver.
+
(Optional) For new drivers, verify the basic functions, such as the UART status control and response to interrupts.
@@ -72,11 +73,16 @@ The UART module adaptation involves the following steps:
The following uses **uart_hi35xx.c** as an example to present the information required for implementing device functions.
-1. Instantiate the driver entry.
The driver entry must be a global variable of the **HdfDriverEntry** type (defined in **hdf_device_desc.h**), and the value of **moduleName** must be the same as that in **device_info.hcs**. In the HDF, the start address of each **HdfDriverEntry** object of all loaded drivers is collected to form a segment address space similar to an array for the upper layer to invoke.
+1. Instantiate the driver entry.
+
+ The driver entry must be a global variable of the **HdfDriverEntry** type (defined in **hdf_device_desc.h**), and the value of **moduleName** must be the same as that in **device_info.hcs**.
+
+ In the HDF, the start address of each **HdfDriverEntry** object of all loaded drivers is collected to form a segment address space similar to an array for the upper layer to invoke.
+
Generally, the HDF calls the **Bind** function and then the **Init** function to load a driver. If **Init** fails to be called, the HDF calls **Release** to release driver resources and exit.
- UART driver entry example:
-
+ UART driver entry example:
+
```
struct HdfDriverEntry g_hdfUartDevice = {
.moduleVersion = 1,
@@ -89,11 +95,15 @@ The following uses **uart_hi35xx.c** as an example to present the information re
HDF_INIT(g_hdfUartDevice);
```
-2. Add the **deviceNode** information to the **device_info.hcs** file and configure the device attributes in the **uart_config.hcs** file.
The **deviceNode** information is related to registration of the driver entry. The device attribute values are closely related to the default values or value ranges of the **UartHost** members at the core layer.
- In this example, there is only one UART controller. If there are multiple UART controllers, you need to add the **deviceNode** information to the **device_info** file and add the corresponding device attributes to the **uart_config** file for each controller.
- - **device_info.hcs** configuration example
+2. Add the **deviceNode** information to the **device_info.hcs** file and configure the device attributes in the **uart_config.hcs** file.
+
+ The **deviceNode** information is related to registration of the driver entry. The device attribute values are closely related to the default values or value ranges of the **UartHost** members at the core layer.
+
+ In this example, there is only one UART controller. If there are multiple UART controllers, you need to add the **deviceNode** information to the **device_info** file and add the corresponding device attributes to the **uart_config** file for each controller.
+
+ - **device_info.hcs** configuration example:
-
+
```
root {
device_info {
@@ -103,11 +113,11 @@ The following uses **uart_hi35xx.c** as an example to present the information re
priority = 50;
device_uart :: device {
device0 :: deviceNode {
- policy = 1; // The driver publishes services only for kernel-mode processes.
- priority = 40; // Driver startup priority.
- permission = 0644; // Permission for the driver to create a device node.
- moduleName = "HDF_PLATFORM_UART"; // Driver name, which must be the same as moduleName in the HdfDriverEntry structure.
- serviceName = "HDF_PLATFORM_UART_0";// Unique name of the service published by the driver. The name is in the HDF_PLATFORM_UART_X format. X indicates the UART controller number.
+ policy = 1; // The driver publishes services only for kernel-mode processes.
+ priority = 40; // Driver startup priority.
+ permission = 0644; // Permission for the driver to create a device node.
+ moduleName = "HDF_PLATFORM_UART"; // Driver name, which must be the same as moduleName in the HdfDriverEntry structure.
+ serviceName = "HDF_PLATFORM_UART_0"; // Unique name of the service published by the driver. The name is in the HDF_PLATFORM_UART_X format. X indicates the UART controller number.
deviceMatchAttr = "hisilicon_hi35xx_uart_0"; // Keyword for matching the private data of the driver. The value must be the same as that of match_attr in the private data configuration table of the driver.
}
device1 :: deviceNode {
@@ -127,20 +137,20 @@ The following uses **uart_hi35xx.c** as an example to present the information re
- **uart_config.hcs** configuration example
-
+
```
root {
platform {
- template uart_controller { // Template configuration. In the template, you can configure the common parameters shared by device nodes.
+ template uart_controller { // Template configuration. In the template, you can configure the common parameters shared by device nodes.
match_attr = "";
- num = 0; // (Mandatory) Device number
- baudrate = 115200; // (Mandatory) Baud rate. Set the value based on service requirements.
- fifoRxEn = 1; // (Mandatory) Enable FIFOs to be received.
- fifoTxEn = 1; // (Mandatory) Enable FIFOs to be transferred.
- flags = 4; // (Mandatory) Flag signal.
- regPbase = 0x120a0000; // (Mandatory) Used for address mapping.
- interrupt = 38; // (Mandatory) Interrupt number.
- iomemCount = 0x48; // (Mandatory) Used for address mapping.
+ num = 0; // (Mandatory) Device number.
+ baudrate = 115200; // (Mandatory) Baud rate. Set the value based on service requirements.
+ fifoRxEn = 1; // (Mandatory) Enable FIFOs to be received.
+ fifoTxEn = 1; // (Mandatory) Enable FIFOs to be transferred.
+ flags = 4; // (Mandatory) Flag signal.
+ regPbase = 0x120a0000; // (Mandatory) Used for address mapping.
+ interrupt = 38; // (Mandatory) Interrupt number.
+ iomemCount = 0x48; // (Mandatory) Used for address mapping.
}
controller_0x120a0000 :: uart_controller {
match_attr = "hisilicon_hi35xx_uart_0";// (Mandatory) The value must be the same as that of deviceMatchAttr of the corresponding device in device_info.hcs.
@@ -159,43 +169,44 @@ The following uses **uart_hi35xx.c** as an example to present the information re
```
3. Initialize the **UartHost** object at the core layer, including defining a custom structure (to pass parameters and data) and implementing the **HdfDriverEntry** member functions (**Bind**, **Init**, and **Release**) to instantiate **UartHostMethod** in **UartHost** (so that the underlying driver functions can be called).
+
- Defining a custom structure
To the driver, the custom structure holds parameters and data. The **DeviceResourceIface** method provided by the HDF reads the values in the **uart_config.hcs** file to initialize the members in the custom structure and passes important parameters, such as the device number, to the **UartHost** object at the core layer.
-
+
```
- struct UartPl011Port { // Interface structure
+ struct UartPl011Port { // Interface structure
int32_t enable;
- unsigned long physBase; // Physical address
+ unsigned long physBase; // Physical address
uint32_t irqNum; // Interrupt number
- uint32_t defaultBaudrate;// Default baud rate
- uint32_t flags; // Flags related to the following three macros.
+ uint32_t defaultBaudrate; // Default baud rate
+ uint32_t flags; // Flags related to the following three macros
#define PL011_FLG_IRQ_REQUESTED (1 << 0)
#define PL011_FLG_DMA_RX_REQUESTED (1 << 1)
#define PL011_FLG_DMA_TX_REQUESTED (1 << 2)
- struct UartDmaTransfer *rxUdt; // DMA transfer
- struct UartDriverData *udd; // The data structure is defined as follows:
+ struct UartDmaTransfer *rxUdt; // DMA transfer
+ struct UartDriverData *udd; // The data structure is defined as follows:
};
- struct UartDriverData { // Structure related to data transfer
+ struct UartDriverData { // Structure related to data transfer
uint32_t num;
- uint32_t baudrate; // Baud rate (configurable)
- struct UartAttribute attr; // Attributes, such as the data bit and stop bit, related to data transfer
- struct UartTransfer *rxTransfer; // Buffer (FIFO structure)
- wait_queue_head_t wait; // Queuing signal related to conditional variables
- int32_t count; // Data count
- int32_t state; // UART controller state
+ uint32_t baudrate; // Baud rate (configurable)
+ struct UartAttribute attr; // Attributes, such as the data bit and stop bit, related to data transfer.
+ struct UartTransfer *rxTransfer; // Buffer (FIFO structure)
+ wait_queue_head_t wait; // Queuing signal related to conditional variables
+ int32_t count; // Data count
+ int32_t state; // UART controller state
#define UART_STATE_NOT_OPENED 0
#define UART_STATE_OPENING 1
#define UART_STATE_USEABLE 2
#define UART_STATE_SUSPENDED 3
- uint32_t flags; // Status flags
+ uint32_t flags; // Status flags
#define UART_FLG_DMA_RX (1 << 0)
#define UART_FLG_DMA_TX (1 << 1)
#define UART_FLG_RD_BLOCK (1 << 2)
- RecvNotify recv; // Pointer to the function that receives serial port data
- struct UartOps *ops; // Custom function pointer structure. For details, see device/hisilicon/drivers/uart/uart_pl011.c.
- void *private; // It stores the pointer to the start address of UartPl011Port for easy invocation.
+ RecvNotify recv; // Pointer to the function that receives serial port data.
+ struct UartOps *ops; // Custom function pointer structure. For details, see device/hisilicon/drivers/uart/uart_pl011.c.
+ void *private; // It stores the pointer to the start address of UartPl011Port for easy invocation.
};
// UartHost is the controller structure at the core layer. The Init function assigns values to the members of UartHost.
@@ -205,12 +216,13 @@ The following uses **uart_hi35xx.c** as an example to present the information re
uint32_t num;
OsalAtomic atom;
void *priv; // It stores the pointer to the start address of the vendor's custom structure for easy invocation.
- struct UartHostMethod *method; // Hook at the core layer. You need to implement and instantiate its member functions.
+ struct UartHostMethod *method; // Hook at the core layer. You need to implement and instantiate its member functions.
};
```
+
- Instantiating **UartHostMethod** in **UartHost** (other members are initialized by **Bind**)
-
+
```
// Example in uart_hi35xx.c: instantiate the hook.
struct UartHostMethod g_uartHostMethod = {
@@ -229,30 +241,30 @@ The following uses **uart_hi35xx.c** as an example to present the information re
- **Bind** function
- Input parameter:
+ **Input parameter**:
**HdfDeviceObject**, an interface parameter exposed by the driver, contains the .hcs information.
- Return value:
+ **Return value**:
- HDF_STATUS
The table below describes some status. For more information, see **HDF_STATUS** in the **/drivers/framework/include/utils/hdf_base.h** file.
+ **HDF_STATUS**
The table below describes some status. For more information, see **HDF_STATUS** in the **/drivers/framework/include/utils/hdf_base.h** file.
- **Table 2** HDF_STATUS
+ **Table 2** Description of HDF_STATUS
- | Status| Description|
+ | Status| Description|
| -------- | -------- |
- | HDF_ERR_INVALID_OBJECT | Invalid controller object.|
- | HDF_ERR_MALLOC_FAIL | Failed to allocate memory.|
- | HDF_ERR_INVALID_PARAM | Invalid parameter.|
- | HDF_ERR_IO | I/O error.|
- | HDF_SUCCESS | Initialization successful.|
- | HDF_FAILURE | Initialization failed.|
+ | HDF_ERR_INVALID_OBJECT | Invalid controller object.|
+ | HDF_ERR_MALLOC_FAIL | Failed to allocate memory.|
+ | HDF_ERR_INVALID_PARAM | Invalid parameter.|
+ | HDF_ERR_IO | I/O error.|
+ | HDF_SUCCESS | Initialization successful.|
+ | HDF_FAILURE | Initialization failed.|
- Function description:
+ **Function description**:
Initializes the custom structure object and **UartHost**.
-
+
```
//uart_hi35xx.c
static int32_t HdfUartDeviceBind(struct HdfDeviceObject *device)
@@ -267,10 +279,10 @@ The following uses **uart_hi35xx.c** as an example to present the information re
...
host = (struct UartHost *)OsalMemCalloc(sizeof(*host));// Allocate memory.
...
- host->device = device; // (Mandatory) Prerequisites for conversion between HdfDeviceObject and UartHost
- device->service = &(host->service; // (Mandatory) Prerequisites for conversion between HdfDeviceObject and UartHost
- host->device->service->Dispatch = UartIoDispatch;// Assign values to Dispatch of service.
- OsalAtomicSet(&host->atom, 0); // Initialize or set the atomic services.
+ host->device = device; // (Mandatory) Prerequisites for conversion between HdfDeviceObject and UartHost.
+ device->service = &(host->service; // (Mandatory) Prerequisites for conversion between HdfDeviceObject and UartHost.
+ host->device->service->Dispatch = UartIoDispatch; // Assign values to Dispatch of service.
+ OsalAtomicSet(&host->atom, 0); // Initialize or set the atomic services.
host->priv = NULL;
host->method = NULL;
return host;
@@ -279,19 +291,19 @@ The following uses **uart_hi35xx.c** as an example to present the information re
- **Init** function
- Input parameter:
+ **Input parameter**:
**HdfDeviceObject**, an interface parameter exposed by the driver, contains the .hcs information.
- Return value:
+ **Return value**:
- HDF_STATUS
+ **HDF_STATUS**
- Function description:
+ **Function description**:
Initializes the custom structure object and **UartHost**, calls the **artAddDev** function at the core layer, and connects to the VFS.
-
+
```
int32_t HdfUartDeviceInit(struct HdfDeviceObject *device)
{
@@ -303,7 +315,7 @@ The following uses **uart_hi35xx.c** as an example to present the information re
...
ret = Hi35xxAttach(host, device); // Initialize the UartHost object.
...
- host->method = &g_uartHostMethod; // Hook the UartHostMethod instance.
+ host->method = &g_uartHostMethod; // Attach the UartHostMethod instance.
return ret;
}
// Initialize UartHost.
@@ -351,30 +363,34 @@ The following uses **uart_hi35xx.c** as an example to present the information re
```
- **Release** function
- Input parameter:
+ **Input parameter**:
**HdfDeviceObject**, an interface parameter exposed by the driver, contains the .hcs information.
- Return value:
+ **Return value**:
No value is returned.
- Function description:
+ **Function description**:
- Releases the memory and deletes the controller. This function assigns values to the **Release** API in the driver entry structure. When the HDF fails to call the **Init** function to initialize the driver, the **Release** function can be called to release driver resources. All forced conversion operations for obtaining the corresponding object can be successful only when **Init()** has the corresponding value assignment operations.
+ Releases the memory and deletes the controller. This function assigns values to the **Release** API in the driver entry structure. When the HDF fails to call the **Init** function to initialize the driver, the **Release** function can be called to release driver resources.
-
+ > ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
+ >
+ > All forced conversion operations for obtaining the corresponding object can be successful only when **Init()** has the corresponding value assignment operations.
+
+
```
void HdfUartDeviceRelease(struct HdfDeviceObject *device)
{
struct UartHost *host = NULL;
...
- host = UartHostFromDevice(device);// Forcibly convert HdfDeviceObject to UartHost by using service. For details about the value assignment, see the Bind function.
+ host = UartHostFromDevice(device); // Forcibly convert HdfDeviceObject to UartHost by using service. For details about the value assignment, see the Bind function.
...
if (host->priv != NULL) {
- Hi35xxDetach(host); // Customized memory release function.
+ Hi35xxDetach(host); // Customized memory release function.
}
- UartHostDestroy(host); // Call the function of the core layer to release the host.
+ UartHostDestroy(host); // Call the function of the core layer to release the host.
}
static void Hi35xxDetach(struct UartHost *host)
@@ -382,10 +398,10 @@ The following uses **uart_hi35xx.c** as an example to present the information re
struct UartDriverData *udd = NULL;
struct UartPl011Port *port = NULL;
...
- udd = host->priv; // Convert UartHost to UartDriverData.
+ udd = host->priv; // The conversion from UartHost to UartDriverData is involved.
...
- UartRemoveDev(host);// Remove the VFS.
- port = udd->private;// Convert UartDriverData to UartPl011Port.
+ UartRemoveDev (host); // Remove the VFS.
+ port = udd->private; // The conversion from UartDriverData to UartPl011Port is involved.
if (port != NULL) {
if (port->physBase != 0) {
OsalIoUnmap((void *)port->physBase);// Unmap addresses.
@@ -393,7 +409,7 @@ The following uses **uart_hi35xx.c** as an example to present the information re
OsalMemFree(port);
udd->private = NULL;
}
- OsalMemFree(udd);//Release UartDriverData.
+ OsalMemFree (udd); // Release UartDriverData.
host->priv = NULL;
}
```
diff --git a/zh-cn/application-dev/database/database-mdds-guidelines.md b/zh-cn/application-dev/database/database-mdds-guidelines.md
index e0d7dec04939ad98fc08acbaade047545a77a597..46ef54dafa6d3044c7a966afc6eb2f4c283a4f1d 100644
--- a/zh-cn/application-dev/database/database-mdds-guidelines.md
+++ b/zh-cn/application-dev/database/database-mdds-guidelines.md
@@ -14,13 +14,13 @@
| 接口名称 | 描述 |
| ------------------------------------------------------------ | ----------------------------------------------- |
-| createKVManager(config:KVManagerConfig,callback:AsyncCallback<KVManager>):void
createKVManager(config:KVManagerConfig):Promise<KVManager> | 创建一个`KVManager`对象实例,用于管理数据库对象。 |
-| getKVStore<TextendsKVStore>(storeId:string,options:Options,callback:AsyncCallback<T>):void
getKVStore<TextendsKVStore>(storeId:string,options:Options):Promise<T> | 指定`Options`和`storeId`,创建并获取`KVStore`数据库。 |
-| put(key:string,value:Uint8Array\|string\|number\|boolean,callback:AsyncCallback<void>):void
put(key:string,value:Uint8Array\|string\|number\|boolean):Promise<void> | 插入和更新数据。 |
-| delete(key:string,callback:AsyncCallback<void>):void
delete(key:string):Promise<void> | 删除数据。 |
-| get(key:string,callback:AsyncCallback<Uint8Array\|string\|boolean\|number>):void
get(key:string):Promise<Uint8Array\|string\|boolean\|number> | 查询数据。 |
-| on(event:'dataChange',type:SubscribeType,observer:Callback<ChangeNotification>):void
on(event:'syncComplete',syncCallback:Callback<Array<[string,number]>>):void | 订阅数据库中数据的变化。 |
-| sync(deviceIdList:string[],mode:SyncMode,allowedDelayMs?:number):void | 在手动模式下,触发数据库同步。 |
+| createKVManager(config: KVManagerConfig, callback: AsyncCallback<KVManager>): void
createKVManager(config: KVManagerConfig): Promise<KVManager> | 创建一个`KVManager`对象实例,用于管理数据库对象。 |
+| getKVStore<TextendsKVStore>(storeId: string, options: Options, callback: AsyncCallback<T>): void
getKVStore<TextendsKVStore>(storeId: string, options: Options): Promise<T> | 指定`Options`和`storeId`,创建并获取`KVStore`数据库。 |
+| put(key: string, value: Uint8Array\|string\|number\|boolean, callback: AsyncCallback<void>): void
put(key: string, value: Uint8Array\|string\|number\|boolean): Promise<void> | 插入和更新数据。 |
+| delete(key: string, callback: AsyncCallback<void>): void
delete(key: string): Promise<void> | 删除数据。 |
+| get(key: string, callback: AsyncCallback<Uint8Array\|string\|boolean\|number>): void
get(key: string): Promise<Uint8Array\|string\|boolean\|number> | 查询数据。 |
+| on(event: 'dataChange', type: SubscribeType, observer: Callback<ChangeNotification>): void
on(event: 'syncComplete', syncCallback: Callback<Array<[string,number]>>): void | 订阅数据库中数据的变化。 |
+| sync(deviceIdList: string[], mode: SyncMode, allowedDelayMs?: number): void | 在手动模式下,触发数据库同步。 |
@@ -34,8 +34,40 @@
```js
import distributedData from '@ohos.data.distributedData';
```
+2. 请求权限(同步操作时进行该步骤)。
-2. 根据配置构造分布式数据库管理类实例。
+ 需要在`config.json`文件里进行配置请求权限,示例代码如下:
+
+ ```json
+ {
+ "module": {
+ "reqPermissions": [
+ {
+ "name": "ohos.permission.DISTRIBUTED_DATASYNC"
+ }
+ ]
+ }
+ }
+ ```
+ 这个权限还需要在应用首次启动的时候弹窗获取用户授权,可以通过如下代码实现:
+
+ ```js
+ import featureAbility from '@ohos.ability.featureAbility';
+
+ function grantPermission() {
+ console.info('grantPermission');
+ let context = featureAbility.getContext();
+ context.requestPermissionsFromUser(['ohos.permission.DISTRIBUTED_DATASYNC'], 666, function (result) {
+ console.info(`result.requestCode=${result.requestCode}`)
+
+ })
+ console.info('end grantPermission');
+ }
+
+ grantPermission();
+ ```
+
+3. 根据配置构造分布式数据库管理类实例。
1. 根据应用上下文创建`kvManagerConfig`对象。
2. 创建分布式数据库管理器实例。
@@ -64,7 +96,7 @@
}
```
-3. 获取/创建分布式数据库。
+4. 获取/创建分布式数据库。
1. 声明需要创建的分布式数据库ID描述。
2. 创建分布式数据库,建议关闭自动同步功能(`autoSync:false`),需要同步时主动调用`sync`接口。
@@ -98,7 +130,7 @@
>
> 组网设备间同步数据的场景,建议在应用启动时打开分布式数据库,获取数据库的句柄。在该句柄(如示例中的`kvStore`)的生命周期内无需重复创建数据库,可直接使用句柄对数据库进行数据的插入等操作。
-4. 订阅分布式数据变化。
+5. 订阅分布式数据变化。
以下为订阅单版本分布式数据库数据变化通知的代码示例:
```js
@@ -107,7 +139,7 @@
});
```
-5. 将数据写入分布式数据库。
+6. 将数据写入分布式数据库。
1. 构造需要写入分布式数据库的`Key`(键)和`Value`(值)。
2. 将键值数据写入分布式数据库。
@@ -130,7 +162,7 @@
}
```
-6. 查询分布式数据库数据。
+7. 查询分布式数据库数据。
1. 构造需要从单版本分布式数据库中查询的`Key`(键)。
2. 从单版本分布式数据库中获取数据。
@@ -155,7 +187,7 @@
}
```
-7. 同步数据到其他设备。
+8. 同步数据到其他设备。
选择同一组网环境下的设备以及同步模式,进行数据同步。
diff --git a/zh-cn/application-dev/database/database-relational-guidelines.md b/zh-cn/application-dev/database/database-relational-guidelines.md
index f60d4a06d6cbd0d68e1be99fccd268f32a6200e2..3a10ebb1d43ba88f9b4ff788232163c0b1e8c9c7 100644
--- a/zh-cn/application-dev/database/database-relational-guidelines.md
+++ b/zh-cn/application-dev/database/database-relational-guidelines.md
@@ -16,8 +16,8 @@
| 接口名 | 描述 |
| -------- | -------- |
-|getRdbStore(config:StoreConfig,version:number):Promise<RdbStore> | 获得一个相关的RdbStore,操作关系型数据库,用户可以根据自己的需求配置RdbStore的参数,然后通过RdbStore调用相关接口可以执行相关的数据操作,使用Promise异步回调。
-config:与此RDB存储相关的数据库配置。
-version:数据库版本。 |
-| deleteRdbStore(name:string):Promise<void> | 使用指定的数据库文件配置删除数据库,使用Promise异步回调。
-name:数据库名称。 |
+|getRdbStore(config: StoreConfig, version: number): Promise<RdbStore> | 获得一个相关的RdbStore,操作关系型数据库,用户可以根据自己的需求配置RdbStore的参数,然后通过RdbStore调用相关接口可以执行相关的数据操作,使用Promise异步回调。
-config:与此RDB存储相关的数据库配置。
-version:数据库版本。 |
+| deleteRdbStore(name: string): Promise<void> | 使用指定的数据库文件配置删除数据库,使用Promise异步回调。
-name:数据库名称。 |
### 数据库的增删改查
@@ -31,7 +31,7 @@
| 类名 | 接口名 | 描述 |
| -------- | -------- | -------- |
- | RdbStore | insert(name:string,values:ValuesBucket):Promise<number> | 向目标表中插入一行数据,使用Promise异步回调。
如果操作成功,返回行ID;否则返回-1。
-name:指定的目标表名。
-values:表示要插入到表中的数据行。 |
+ | RdbStore | insert(name: string, values: ValuesBucket): Promise<number> | 向目标表中插入一行数据,使用Promise异步回调。
如果操作成功,返回行ID;否则返回-1。
-name:指定的目标表名。
-values:表示要插入到表中的数据行。 |
- **更新**
@@ -41,7 +41,7 @@
| 类名 | 接口名 | 描述 |
| -------- | -------- | -------- |
- | RdbStore | update(values:ValuesBucket,rdbPredicates:RdbPredicates):Promise\
| 根据RdbPredicates的指定实例对象更新数据库中的数据,使用Promise异步回调。
返回受影响的行数。
-values:以ValuesBucket存储的要更新的数据。
-rdbPredicates:表示RdbPredicates的实例对象指定的更新条件。 |
+ | RdbStore | update(values: ValuesBucket, rdbPredicates: RdbPredicates): Promise\ | 根据RdbPredicates的指定实例对象更新数据库中的数据,使用Promise异步回调。
返回受影响的行数。
-values:以ValuesBucket存储的要更新的数据。
-rdbPredicates:表示RdbPredicates的实例对象指定的更新条件。 |
- **删除**
@@ -51,7 +51,7 @@
| 类名 | 接口名 | 描述 |
| -------- | -------- | -------- |
- | RdbStore | delete(rdbPredicates:RdbPredicates):Promise\ | 根据rdbPredicates的指定实例对象从数据库中删除数据,使用Promise异步回调。
返回受影响的行数。
-rdbPredicates:RdbPredicates的实例对象指定的删除条件。 |
+ | RdbStore | delete(rdbPredicates: RdbPredicates): Promise\ | 根据rdbPredicates的指定实例对象从数据库中删除数据,使用Promise异步回调。
返回受影响的行数。
-rdbPredicates:RdbPredicates的实例对象指定的删除条件。 |
- **查询**
@@ -64,8 +64,8 @@
| 类名 | 接口名 | 描述 |
| -------- | -------- | -------- |
- | RdbStore | query(rdbPredicates:RdbPredicates,columns:Array):Promise<ResultSet> | 根据指定条件查询数据库中的数据,使用Promise异步回调。
-rdbPredicates:表示RdbPredicates的实例对象指定的查询条件。
-columns:表示要查询的列。如果值为空,则查询应用于所有列。 |
- | RdbStore | querySql(sql:string,bindArgs?:Array<ValueType>):Promise<ResultSet> | 根据指定SQL语句查询数据库中的数据,使用Promise异步回调。
-sql:指定要查询的SQL语句。
-bindArgs:SQL语句中参数的值。 |
+ | RdbStore | query(rdbPredicates: RdbPredicates, columns: Array): Promise<ResultSet> | 根据指定条件查询数据库中的数据,使用Promise异步回调。
-rdbPredicates:表示RdbPredicates的实例对象指定的查询条件。
-columns:表示要查询的列。如果值为空,则查询应用于所有列。 |
+ | RdbStore | querySql(sql: string, bindArgs?: Array<ValueType>): Promise<ResultSet> | 根据指定SQL语句查询数据库中的数据,使用Promise异步回调。
-sql:指定要查询的SQL语句。
-bindArgs:SQL语句中参数的值。 |
### 数据库谓词的使用
@@ -77,11 +77,11 @@
| 类名 | 接口名 | 描述 |
| -------- | -------- | -------- |
-| RdbPredicates | equalTo(field:string,value:ValueType):RdbPredicates | 配置谓词以匹配数据字段为ValueType且值等于指定值的字段。
-field:数据库表中的列名。
-value:指示要与谓词匹配的值。
-RdbPredicates:返回与指定字段匹配的谓词。 |
-| RdbPredicates | notEqualTo(field:string,value:ValueType):RdbPredicates | 配置谓词以匹配数据字段为ValueType且值不等于指定值的字段。
-field:数据库表中的列名。
-value:指示要与谓词匹配的值。
-RdbPredicates:返回与指定字段匹配的谓词。 |
-| RdbPredicates | or():RdbPredicates | 将或条件添加到谓词中。
-RdbPredicates:返回带有或条件的谓词。 |
-| RdbPredicates | and():RdbPredicates | 向谓词添加和条件。
-RdbPredicates:返回带有和条件的谓词。 |
-| RdbPredicates | contains(field:string,value:string):RdbPredicats | 配置谓词以匹配数据字段为String且value包含指定值的字段。
-field:数据库表中的列名。
-value:指示要与谓词匹配的值。
-RdbPredicates:返回带有包含条件的谓词。 |
+| RdbPredicates | equalTo(field: string, value: ValueType): RdbPredicates | 配置谓词以匹配数据字段为ValueType且值等于指定值的字段。
-field:数据库表中的列名。
-value:指示要与谓词匹配的值。
-RdbPredicates:返回与指定字段匹配的谓词。 |
+| RdbPredicates | notEqualTo(field: string, value: ValueType): RdbPredicates | 配置谓词以匹配数据字段为ValueType且值不等于指定值的字段。
-field:数据库表中的列名。
-value:指示要与谓词匹配的值。
-RdbPredicates:返回与指定字段匹配的谓词。 |
+| RdbPredicates | or(): RdbPredicates | 将或条件添加到谓词中。
-RdbPredicates:返回带有或条件的谓词。 |
+| RdbPredicates | and(): RdbPredicates | 向谓词添加和条件。
-RdbPredicates:返回带有和条件的谓词。 |
+| RdbPredicates | contains(field: string, value: string): RdbPredicats | 配置谓词以匹配数据字段为String且value包含指定值的字段。
-field:数据库表中的列名。
-value:指示要与谓词匹配的值。
-RdbPredicates:返回带有包含条件的谓词。 |
### 查询结果集的使用
@@ -97,12 +97,12 @@
| 类名 | 接口名 | 描述 |
| -------- | -------- | -------- |
-| ResultSet | goToFirstRow():boolean | 将结果集移动到第一行。 |
-| ResultSet | getString(columnIndex:number):string | 获取当前行指定列的值,以String类型返回。 |
-| ResultSet | getBlob(columnIndex:number):Uint8Array | 获取当前行指定列的值,以字节数组形式返回。 |
-| ResultSet | getDouble(columnIndex:number):number | 获取当前行指定列的值,以double型返回。 |
-| ResultSet | getLong(columnIndex:number):number | 获取当前行指定列的值,以Long形式返回。 |
-| ResultSet | close():void | 关闭结果集。 |
+| ResultSet | goToFirstRow(): boolean | 将结果集移动到第一行。 |
+| ResultSet | getString(columnIndex:number): string | 获取当前行指定列的值,以String类型返回。 |
+| ResultSet | getBlob(columnIndex:number): Uint8Array | 获取当前行指定列的值,以字节数组形式返回。 |
+| ResultSet | getDouble(columnIndex:number): number | 获取当前行指定列的值,以double型返回。 |
+| ResultSet | getLong(columnIndex:number): number | 获取当前行指定列的值,以Long形式返回。 |
+| ResultSet | close(): void | 关闭结果集。 |
diff --git a/zh-cn/application-dev/device/usb-guidelines.md b/zh-cn/application-dev/device/usb-guidelines.md
index 8c836de6508cd2a01eeb76f4a74b93bba695db9c..02a0b2500f8446aebd7482eef124037bd1973be8 100644
--- a/zh-cn/application-dev/device/usb-guidelines.md
+++ b/zh-cn/application-dev/device/usb-guidelines.md
@@ -17,19 +17,19 @@ USB类开放能力如下,具体请查阅[API参考文档](../reference/apis/js
| 接口名 | 描述 |
| -------- | -------- |
-| hasRight(deviceName:string):boolean | 如果“使用者”(如各种App或系统)有权访问设备则返回true;无权访问设备则返回false。 |
-| requestRight(deviceName:string):Promise<boolean> | 请求给定软件包的临时权限以访问设备。 |
-| connectDevice(device:USBDevice):Readonly<USBDevicePipe> | 根据`getDevices()`返回的设备信息打开USB设备。 |
-| getDevices():Array<Readonly<USBDevice>> | 返回USB设备列表。 |
-| setConfiguration(pipe:USBDevicePipe,config:USBConfig):number | 设置设备的配置。 |
-| setInterface(pipe:USBDevicePipe,iface:USBInterface):number | 设置设备的接口。 |
-| claimInterface(pipe:USBDevicePipe,iface:USBInterface,force?:boolean):number | 获取接口。 |
-|bulkTransfer(pipe:USBDevicePipe,endpoint:USBEndpoint,buffer:Uint8Array,timeout?:number):Promise<number> | 批量传输。 |
-| closePipe(pipe:USBDevicePipe):number | 关闭设备消息控制通道。 |
-| releaseInterface(pipe:USBDevicePipe,iface:USBInterface):number | 释放接口。 |
-| getFileDescriptor(pipe:USBDevicePipe):number | 获取文件描述符。 |
-| getRawDescriptor(pipe:USBDevicePipe):Uint8Array | 获取原始的USB描述符。 |
-| controlTransfer(pipe:USBDevicePipe,contrlparam:USBControlParams,timeout?:number):Promise<number> | 控制传输。 |
+| hasRight(deviceName: string): boolean | 如果“使用者”(如各种App或系统)有权访问设备则返回true;无权访问设备则返回false。 |
+| requestRight(deviceName: string): Promise<boolean> | 请求给定软件包的临时权限以访问设备。 |
+| connectDevice(device: USBDevice): Readonly<USBDevicePipe> | 根据`getDevices()`返回的设备信息打开USB设备。 |
+| getDevices(): Array<Readonly<USBDevice>> | 返回USB设备列表。 |
+| setConfiguration(pipe: USBDevicePipe, config: USBConfig): number | 设置设备的配置。 |
+| setInterface(pipe: USBDevicePipe, iface: USBInterface): number | 设置设备的接口。 |
+| claimInterface(pipe: USBDevicePipe, iface: USBInterface, force?: boolean): number | 获取接口。 |
+|bulkTransfer(pipe: USBDevicePipe, endpoint: USBEndpoint, buffer: Uint8Array, timeout?: number): Promise<number> | 批量传输。 |
+| closePipe(pipe: USBDevicePipe): number | 关闭设备消息控制通道。 |
+| releaseInterface(pipe: USBDevicePipe, iface: USBInterface): number | 释放接口。 |
+| getFileDescriptor(pipe: USBDevicePipe): number | 获取文件描述符。 |
+| getRawDescriptor(pipe: USBDevicePipe): Uint8Array | 获取原始的USB描述符。 |
+| controlTransfer(pipe: USBDevicePipe, contrlparam: USBControlParams, timeout?: number): Promise<number> | 控制传输。 |
## 开发步骤
diff --git a/zh-cn/application-dev/device/usb-overview.md b/zh-cn/application-dev/device/usb-overview.md
index 4b5b525645fd43beed25f740843ff900d27ea2d5..10732adccacaf2aaf9dc1664f7ae22a8b7d1ea65 100644
--- a/zh-cn/application-dev/device/usb-overview.md
+++ b/zh-cn/application-dev/device/usb-overview.md
@@ -9,7 +9,7 @@ USB服务是应用访问底层的一种设备抽象概念。开发者根据提
USB服务系统包含USB API、USB Service、USB HAL。
-**图2** USB服务运作机制
+**图1** USB服务运作机制
![zh-cn_image_0000001237821727](figures/zh-cn_image_0000001237821727.png)
diff --git a/zh-cn/application-dev/media/audio-recorder.md b/zh-cn/application-dev/media/audio-recorder.md
index 85b07eaef0a61cf7e161c3c37a70928b2d1aa031..739116e193db4ad8f0519ffe6e4784301712d6b7 100644
--- a/zh-cn/application-dev/media/audio-recorder.md
+++ b/zh-cn/application-dev/media/audio-recorder.md
@@ -191,6 +191,5 @@ export class AudioRecorderDemo {
针对音频录制开发,有以下相关实例可供参考:
- [`Recorder:`录音机(eTS)(API8)(Full SDK)](https://gitee.com/openharmony/applications_app_samples/tree/master/media/Recorder)
-- [`JsRecorder`:录音机(JS)(API8)](https://gitee.com/openharmony/applications_app_samples/tree/master/media/JSRecorder)
- [`eTsAudioPlayer`: 音频播放器(eTS)(API8)](https://gitee.com/openharmony/applications_app_samples/blob/master/media/Recorder/entry/src/main/ets/MainAbility/pages/Play.ets)
- [音频播放器(eTS)(API9)](https://gitee.com/openharmony/codelabs/tree/master/Media/Audio_OH_ETS)
diff --git a/zh-cn/application-dev/reference/apis/js-apis-data-rdb.md b/zh-cn/application-dev/reference/apis/js-apis-data-rdb.md
index 2961ee3c783d04e968ccc4398fe8b50ac27e8e22..c9729deab958b26754d49b727a4818a97343f468 100644
--- a/zh-cn/application-dev/reference/apis/js-apis-data-rdb.md
+++ b/zh-cn/application-dev/reference/apis/js-apis-data-rdb.md
@@ -29,7 +29,7 @@ getRdbStore(context: Context, config: StoreConfig, version: number, callback: As
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
-| context | Context | 是 | 应用程序或功能的上下文。
API version 9之前的Context定义见[Context](js-apis-Context.md)。
API version 9及之后的Context定义见[Context](js-apis-ability-context.md)。|
+| context | [Context](js-apis-Context.md) | 是 | 应用上下文。|
| config | [StoreConfig](#storeconfig) | 是 | 与此RDB存储相关的数据库配置。 |
| version | number | 是 | 数据库版本。 |
| callback | AsyncCallback<[RdbStore](#rdbstore)> | 是 | 指定callback回调函数,返回一个RdbStore。 |
@@ -37,8 +37,13 @@ getRdbStore(context: Context, config: StoreConfig, version: number, callback: As
**示例:**
```js
+// 获取context
+import featureAbility from '@ohos.ability.featureAbility'
+var context = featureAbility.getContext()
+
+// 获取context后调用getRdbStore
const STORE_CONFIG = { name: "RdbTest.db"}
-data_rdb.getRdbStore(this.context, STORE_CONFIG, 1, function (err, rdbStore) {
+data_rdb.getRdbStore(context, STORE_CONFIG, 1, function (err, rdbStore) {
if (err) {
console.info("Get RdbStore failed, err: " + err)
return
@@ -59,7 +64,7 @@ getRdbStore(context: Context, config: StoreConfig, version: number): Promise<
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
-| context | Context | 是 | 应用程序或功能的上下文。
API version 9之前的Context定义见[Context](js-apis-Context.md)。
API version 9及之后的Context定义见[Context](js-apis-ability-context.md)。 |
+| context | [Context](js-apis-Context.md) | 是 | 应用上下文。 |
| config | [StoreConfig](#storeconfig) | 是 | 与此RDB存储相关的数据库配置。 |
| version | number | 是 | 数据库版本。 |
@@ -72,8 +77,13 @@ getRdbStore(context: Context, config: StoreConfig, version: number): Promise<
**示例:**
```js
+// 获取context
+import featureAbility from '@ohos.ability.featureAbility'
+var context = featureAbility.getContext()
+
+// 获取context后调用getRdbStore
const STORE_CONFIG = { name: "RdbTest.db" }
-let promise = data_rdb.getRdbStore(this.context, STORE_CONFIG, 1);
+let promise = data_rdb.getRdbStore(context, STORE_CONFIG, 1);
promise.then(async (rdbStore) => {
console.log("Get RdbStore successfully.")
}).catch((err) => {
@@ -92,13 +102,18 @@ deleteRdbStore(context: Context, name: string, callback: AsyncCallback<void&g
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
-| context | Context | 是 | 应用程序或功能的上下文。
API version 9之前的Context定义见[Context](js-apis-Context.md)。
API version 9及之后的Context定义见[Context](js-apis-ability-context.md)。|
+| context | [Context](js-apis-Context.md) | 是 | 应用上下文。|
| name | string | 是 | 数据库名称。 |
| callback | AsyncCallback<void> | 是 | 指定callback回调函数。 |
**示例:**
```js
-data_rdb.deleteRdbStore(this.context, "RdbTest.db", function (err, rdbStore) {
+// 获取context
+import featureAbility from '@ohos.ability.featureAbility'
+var context = featureAbility.getContext()
+
+// 获取context后调用deleteRdbStore
+data_rdb.deleteRdbStore(context, "RdbTest.db", function (err) {
if (err) {
console.info("Delete RdbStore failed, err: " + err)
return
@@ -118,7 +133,7 @@ deleteRdbStore(context: Context, name: string): Promise<void>
**参数**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
-| context | Context | 是 | 应用程序或功能的上下文。
API version 9之前的Context定义见[Context](js-apis-Context.md)。
API version 9及之后的Context定义见[Context](js-apis-ability-context.md)。|
+| context | [Context](js-apis-Context.md) | 是 | 应用上下文。|
| name | string | 是 | 数据库名称。 |
**返回值**:
@@ -128,7 +143,12 @@ deleteRdbStore(context: Context, name: string): Promise<void>
**示例:**
```js
-let promise = data_rdb.deleteRdbStore(this.context, "RdbTest.db")
+// 获取context
+import featureAbility from '@ohos.ability.featureAbility'
+var context = featureAbility.getContext()
+
+// 获取context后调用deleteRdbStore
+let promise = data_rdb.deleteRdbStore(context, "RdbTest.db")
promise.then(()=>{
console.log("Delete RdbStore successfully.")
}).catch((err) => {
diff --git a/zh-cn/application-dev/reference/apis/js-apis-prompt.md b/zh-cn/application-dev/reference/apis/js-apis-prompt.md
index 475fd483adb8d59ee6b39ee809491787e1628f34..1d5a74215d16113afb684fda480645764ca0874c 100644
--- a/zh-cn/application-dev/reference/apis/js-apis-prompt.md
+++ b/zh-cn/application-dev/reference/apis/js-apis-prompt.md
@@ -45,7 +45,7 @@ showToast(options: ShowToastOptions): void
| 名称 | 类型 | 必填 | 说明 |
| -------- | -------------- | ---- | ---------------------------------------- |
| message | string | 是 | 显示的文本信息。 |
-| duration | number | 否 | 默认值1500ms,建议区间:1500ms-10000ms,若小于1500ms则取默认值。 |
+| duration | number | 否 | 默认值1500ms,取值区间:1500ms-10000ms。若小于1500ms则取默认值,若大于10000ms则取上限值10000ms。 |
| bottom | <length> | 否 | 设置弹窗边框距离屏幕底部的位置。 |
## prompt.showDialog
diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001194352434.png b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001194352434.png
index b2728fd1b4e050edddf499398b44a7e3aa634109..f1b942fee8437b1197ef3e9f40c98187a76f8c44 100644
Binary files a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001194352434.png and b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001194352434.png differ
diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238712439.png b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238712439.png
index b2728fd1b4e050edddf499398b44a7e3aa634109..f1b942fee8437b1197ef3e9f40c98187a76f8c44 100644
Binary files a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238712439.png and b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001238712439.png differ
diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_000000127777771.png b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_000000127777771.png
new file mode 100644
index 0000000000000000000000000000000000000000..06cbacf1470de12c79c2020aa8c6be95506e58b5
Binary files /dev/null and b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_000000127777771.png differ
diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_000000127777772.png b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_000000127777772.png
new file mode 100644
index 0000000000000000000000000000000000000000..9c68b723dd3966886d384028663d4a7d6633c027
Binary files /dev/null and b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_000000127777772.png differ
diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_000000127777773.png b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_000000127777773.png
new file mode 100644
index 0000000000000000000000000000000000000000..7dbcbb2d5710b17866b9d5b034437b91a700a3f9
Binary files /dev/null and b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_000000127777773.png differ
diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_000000127777774.png b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_000000127777774.png
new file mode 100644
index 0000000000000000000000000000000000000000..60f430b646b45a3e3b16a9bb024e4a14e48bf4d3
Binary files /dev/null and b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_000000127777774.png differ
diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_000000127777775.png b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_000000127777775.png
new file mode 100644
index 0000000000000000000000000000000000000000..60f430b646b45a3e3b16a9bb024e4a14e48bf4d3
Binary files /dev/null and b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_000000127777775.png differ
diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-textclock.md b/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-textclock.md
index eb6d626447062499f886c054f30cb79ae5b1c89b..740d95324f07a4273850097a8cb7798fc173876e 100644
--- a/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-textclock.md
+++ b/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-textclock.md
@@ -27,9 +27,9 @@ TextClock(options?: {timeZoneOffset?: number, controller?: TextClockController})
## 属性
-| 名称 | 参数类型 | 默认值 | 描述 |
-| ------ | ------ | -------- | ---------------------------------------- |
-| format | string | 'hhmmss' | 设置显示时间格式,如“yyyy/mm/dd”、“yyyy-mm-dd”等。支持的时间格式化字符串:- yyyy(年份)
- mm(英文月份简写)
- mmm(英文月份简写)
- mmmm(英文月份全称)
- dd(英文星期简写)
- ddd(英文星期简写)
- dddd(英文星期全称)
- HH(24小时制)
- hh(12小时制)
- MM/mm(分钟)
- SS/ss(秒)
|
+| 名称 | 参数类型 | 默认值 | 描述 |
+| ------ | -------- | ------ | ------------------------------------------------------------ |
+| format | string | 'hms' | 设置显示时间格式。
日期间隔符固定为"/",时间间隔符为":"。
如yyyyMMdd,yyyy-MM-dd显示为yyyy/MM/dd,
hhmmss显示为hh:mm:ss。
时间格式只用写一位即可,如"hhmmss"等同于"hms"。
支持的时间格式化字符串:
- YYYY/yyyy:完整年份。
- YY/yy:年份后两位。
- M:月份(若想使用01月则使用MM)。
- d:日期(若想使用01日则使用dd)。
- D:年中日(一年中的第几天)。
- H:24小时制。
- h:12小时制。
- m:分钟。
- s:秒。
- SSS:毫秒。 |
## 事件
diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-textpicker.md b/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-textpicker.md
index 1dcf6750980351550ba965e01d69f01588cced28..7b8e7fc87f81f2e8f04cb580de47dc9085018675 100644
--- a/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-textpicker.md
+++ b/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-textpicker.md
@@ -42,7 +42,7 @@ TextPicker(options?: {range: string[] | [Resource](ts-types.md#resource), select
| 名称 | 描述 |
| ------------------------------------------------------------ | ------------------------------------------------------------ |
-| onChange(callback: (value: string, index: number) => void) | 滑动选中TextPicker文本内容后,触发该回调。
- value: 当前选中项的文本。
- index: 当前选中项的下标。 |
+| onChange(callback: (value: string, index: number) => void) | 滑动选中TextPicker文本内容后,触发该回调。
- value: 当前选中项的文本。
- index: 当前选中项的索引值。 |
## 示例
diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-xcomponent.md b/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-xcomponent.md
index 7ec01cd1c95acabd638e8f78acef211df9a65aee..2c2803ddd9ef2b27c80651ea30214036a745545b 100644
--- a/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-xcomponent.md
+++ b/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-xcomponent.md
@@ -49,7 +49,7 @@ onDestroy(event: () => void )
## XComponentController
-xcomponent 组件的控制器,可以将此对象绑定至XComponent组件,然后通过控制器带调用组件方法。
+xcomponent 组件的控制器,可以将此对象绑定至XComponent组件,然后通过控制器来调用组件方法。
### 创建对象
@@ -59,7 +59,7 @@ xcomponentController: XComponentController = new XComponentController()
### getXComponentSurfaceId
-getXComponentSurfaceId(): string
+getXComponentSurfaceId()
获取XComponent对应Surface的ID,供@ohos接口使用,比如camera相关接口。
@@ -71,9 +71,10 @@ getXComponentSurfaceId(): string
| ------ | ----------------------- |
| string | XComponent持有Surface的ID。 |
+
### setXComponentSurfaceSize
-setXComponentSurfaceSize(value: {surfaceWidth: number, surfaceHeight: number}): void
+setXComponentSurfaceSize(value: {surfaceWidth: number, surfaceHeight: number})
设置XComponent持有Surface的宽度和高度。
@@ -86,9 +87,10 @@ setXComponentSurfaceSize(value: {surfaceWidth: number, surfaceHeight: number}):
| surfaceWidth | number | 是 | XComponent持有Surface的宽度。 |
| surfaceHeight | number | 是 | XComponent持有Surface的高度。 |
+
### getXComponentContext
-getXComponentContext(): Object
+getXComponentContext()
获取XComponent实例对象的context。
@@ -98,6 +100,7 @@ getXComponentContext(): Object
| ------ | ---------------------------------------- |
| Object | 获取XComponent实例对象的context,context包含的具体接口方法由开发者自定义。 |
+
## 示例
提供surface类型XComponent,支持相机预览等能力。
diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-basic-gestures-longpressgesture.md b/zh-cn/application-dev/reference/arkui-ts/ts-basic-gestures-longpressgesture.md
index 9c0ee70cedd0cf0c0aa98db7f2af2dfe832431ef..240e6c31690e49873829c8b1c115ad8c62d323bc 100644
--- a/zh-cn/application-dev/reference/arkui-ts/ts-basic-gestures-longpressgesture.md
+++ b/zh-cn/application-dev/reference/arkui-ts/ts-basic-gestures-longpressgesture.md
@@ -1,7 +1,6 @@
# LongPressGesture
> **说明:**
->
> 从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
@@ -16,25 +15,21 @@ LongPressGesture(options?: { fingers?: number, repeat?: boolean, duration?: numb
**参数:**
-| 参数名称 | 参数类型 | 必填 | 默认值 | 参数描述 |
-| -------- | ------- | ---- | ----- | -------------------------------- |
-| fingers | number | 否 | 1 | 触发长按的最少手指数,最小为1指, 最大取值为10指。 |
-| repeat | boolean | 否 | false | 是否连续触发事件回调。 |
-| duration | number | 否 | 500 | 最小触发长按的时间,单位为毫秒(ms)。 |
+ | 参数名称 | 参数类型 | 必填 | 默认值 | 参数描述 |
+ | -------- | -------- | -------- | -------- | -------- |
+ | fingers | number | 否 | 1 | 触发长按的最少手指数,最小为1指, 最大取值为10指。 |
+ | repeat | boolean | 否 | false | 是否连续触发事件回调。 |
+ | duration | number | 否 | 500 | 触发长按的最短时间,单位为毫秒(ms)。 |
+
## 事件
-| 名称 | 功能描述 |
-| ---------------------------------------- | ------------------------------ |
-| onAction((event?: GestureEvent) => void) | LongPress手势识别成功回调。 |
-| onActionEnd((event?: GestureEvent) => void) | LongPress手势识别成功,手指抬起后触发回调。 |
+| 名称 | 功能描述 |
+| -------- | -------- |
+| onAction((event?: [GestureEvent](ts-gesture-settings.md)) => void) | LongPress手势识别成功回调。 |
+| onActionEnd((event?: [GestureEvent](ts-gesture-settings.md)) => void) | LongPress手势识别成功,手指抬起后触发回调。 |
| onActionCancel(event: () => void) | LongPress手势识别成功,接收到触摸取消事件触发回调。 |
-## GestureEvent对象中与LongPress手势相关的属性
-
-| 属性名称 | 属性类型 | 描述 |
-| ------ | ------- | ------------ |
-| repeat | boolean | 事件是否为重复触发事件。 |
## 示例
diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-basic-gestures-pangesture.md b/zh-cn/application-dev/reference/arkui-ts/ts-basic-gestures-pangesture.md
index e68833ad709882e28935663f2e0578c901e9018e..1d810cf405b2c758fe151fa88544868d48e8aa8e 100644
--- a/zh-cn/application-dev/reference/arkui-ts/ts-basic-gestures-pangesture.md
+++ b/zh-cn/application-dev/reference/arkui-ts/ts-basic-gestures-pangesture.md
@@ -1,7 +1,6 @@
# PanGesture
> **说明:**
->
> 从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
@@ -16,24 +15,25 @@ PanGesture(options?: { fingers?: number, direction?: PanDirection, distance?: nu
**参数:**
-| 参数名称 | 参数类型 | 必填 | 默认值 | 参数描述 |
-| --------- | ------------ | ---- | ------ | ------------------------------------------------------------ |
-| fingers | number | 否 | 1 | 触发滑动的最少手指数,最小为1指, 最大取值为10指。 |
-| direction | PanDirection | 否 | All | 设置滑动方向,此枚举值支持逻辑与(&)和逻辑或(\|)运算。 |
-| distance | number | 否 | 5.0 | 最小滑动识别距离,单位为vp。
**说明:**
> tab滑动与该拖动手势事件同时存在时,可将distance值设为1,使拖动更灵敏,避免造成事件错乱。 |
+ | 参数名称 | 参数类型 | 必填 | 默认值 | 参数描述 |
+ | -------- | -------- | -------- | -------- | -------- |
+ | fingers | number | 否 | 1 | 触发拖动的最少手指数,最小为1指, 最大取值为10指。 |
+ | direction | PanDirection | 否 | PanDirection.All | 触发拖动的手势方向,此枚举值支持逻辑与(&)和逻辑或(\|)运算。 |
+ | distance | number | 否 | 5.0 | 最小拖动识别距离,单位为vp。
**说明:**
> tab滑动与该拖动手势事件同时存在时,可将distance值设为1,使拖动更灵敏,避免造成事件错乱。 |
## PanDirection枚举说明
-| 名称 | 描述 |
-| ---------- | ---------- |
-| All | 所有方向可滑动。 |
-| Horizontal | 水平方向可滑动。 |
-| Vertical | 竖直方向可滑动。 |
-| Left | 向左滑动。 |
-| Right | 向右滑动。 |
-| Up | 向上滑动。 |
-| Down | 向下滑动。 |
-| None | 任何方向都不可滑动。 |
+ | 名称 | 描述 |
+ | -------- | -------- |
+ | All | 所有方向。 |
+ | Horizontal | 水平方向。 |
+ | Vertical | 竖直方向。 |
+ | Left | 向左拖动。 |
+ | Right | 向右拖动。 |
+ | Up | 向上拖动。 |
+ | Down | 向下拖动。 |
+ | None | 任何方向都不可触发拖动手势事件。 |
+
## PanGestureOptions
@@ -43,31 +43,26 @@ PanGestureOptions(options?: { fingers?: number, direction?: PanDirection, distan
**参数:**
-同PanGesture参数说明。
+ 同PanGesture参数说明。
**接口:**
-| 名称 | 功能描述 |
-| -------------------------------------- | -------------- |
-| setDirection(value: PanDirection) | 设置direction属性。 |
-| setDistance(value: number) | 设置distance属性。 |
-| setFingers(value: number) | 设置fingers属性。 |
+ | 名称 | 功能描述 |
+ | -------- | -------- |
+ | setDirection(value: PanDirection) | 设置direction属性。 |
+ | setDistance(value: number) | 设置distance属性。 |
+ | setFingers(value: number) | 设置fingers属性。 |
+
## 事件
-| 名称 | 功能描述 |
-| ---------------------------------------- | ------------------------ |
-| onActionStart(callback: (event?: GestureEvent) => void) | Pan手势识别成功回调。 |
-| onActionUpdate(callback: (event?: GestureEvent) => void) | Pan手势移动过程中回调。 |
-| onActionEnd(callback: (event?: GestureEvent) => void) | Pan手势识别成功,手指抬起后触发回调。 |
+| 名称 | 功能描述 |
+| -------- | -------- |
+| onActionStart(callback: (event?: [GestureEvent](ts-gesture-settings.md)) => void) | Pan手势识别成功回调。 |
+| onActionUpdate(callback: (event?: [GestureEvent](ts-gesture-settings.md)) => void) | Pan手势移动过程中回调。 |
+| onActionEnd(callback: (event?: [GestureEvent](ts-gesture-settings.md)) => void) | Pan手势识别成功,手指抬起后触发回调。 |
| onActionCancel(callback: () => void) | Pan手势识别成功,接收到触摸取消事件触发回调。 |
-## GestureEvent对象中与Pan手势相关的属性
-
-| 属性名称 | 属性类型 | 描述 |
-| ------- | ------ | -------------- |
-| offsetX | number | 手势事件偏移量,单位为vp。 |
-| offsetY | number | 手势事件偏移量,单位为vp。 |
## 示例
diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-basic-gestures-pinchgesture.md b/zh-cn/application-dev/reference/arkui-ts/ts-basic-gestures-pinchgesture.md
index 9a0c0617016eeaba265be78b3ebda0a10704d4aa..9b71bd3d53acef438a11632a872786845c6c41b7 100644
--- a/zh-cn/application-dev/reference/arkui-ts/ts-basic-gestures-pinchgesture.md
+++ b/zh-cn/application-dev/reference/arkui-ts/ts-basic-gestures-pinchgesture.md
@@ -1,7 +1,6 @@
# PinchGesture
> **说明:**
->
> 从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
@@ -16,27 +15,21 @@ PinchGesture(options?: { fingers?: number, distance?: number })
**参数:**
-| 参数名称 | 参数类型 | 必填 | 默认值 | 参数描述 |
-| -------- | ------ | ---- | ---- | ----------------------------- |
-| fingers | number | 否 | 2 | 触发捏合的最少手指数, 最小为2指,最大为5指。 |
-| distance | number | 否 | 3.0 | 最小识别距离,单位为vp。 |
+ | 参数名称 | 参数类型 | 必填 | 默认值 | 参数描述 |
+ | -------- | -------- | -------- | -------- | -------- |
+ | fingers | number | 否 | 2 | 触发捏合的最少手指数, 最小为2指,最大为5指。 |
+ | distance | number | 否 | 3.0 | 最小识别距离,单位为vp。 |
+
## 事件
-| 名称 | 功能描述 |
-| ---------------------------------------- | -------------------------- |
-| onActionStart((event?: GestureEvent) => void) | Pinch手势识别成功回调。 |
-| onActionUpdate((event?: GestureEvent) => void) | Pinch手势移动过程中回调。 |
-| onActionEnd((event?: GestureEvent) => void) | Pinch手势识别成功,手指抬起后触发回调。 |
+| 名称 | 功能描述 |
+| -------- | -------- |
+| onActionStart((event?: [GestureEvent](ts-gesture-settings.md)) => void) | Pinch手势识别成功回调。 |
+| onActionUpdate((event?: [GestureEvent](ts-gesture-settings.md)) => void) | Pinch手势移动过程中回调。 |
+| onActionEnd((event?: [GestureEvent](ts-gesture-settings.md)) => void) | Pinch手势识别成功,手指抬起后触发回调。 |
| onActionCancel(event: () => void) | Pinch手势识别成功,接收到触摸取消事件触发回调。 |
-## GestureEvent对象中与Pinch手势相关的属性
-
-| 属性名称 | 属性类型 | 描述 |
-| ------------ | ------ | -------------------------- |
-| scale | number | 缩放比例,用于PinchGesture手势触发场景。 |
-| pinchCenterX | number | 捏合手势中心点X轴坐标,单位为px。 |
-| pinchCenterY | number | 捏合手势中心点Y轴坐标,单位为px。 |
## 示例
diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-basic-gestures-rotationgesture.md b/zh-cn/application-dev/reference/arkui-ts/ts-basic-gestures-rotationgesture.md
index b7d7b34289a953ae15aa191215dec83e362093bd..423403653600c4e9f7bb8ece19513c7fe8c6bd7c 100644
--- a/zh-cn/application-dev/reference/arkui-ts/ts-basic-gestures-rotationgesture.md
+++ b/zh-cn/application-dev/reference/arkui-ts/ts-basic-gestures-rotationgesture.md
@@ -1,7 +1,6 @@
# RotationGesture
> **说明:**
->
> 从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
@@ -16,25 +15,21 @@ RotationGesture(options?: { fingers?: number, angle?: number })
**参数:**
-| 参数名称 | 参数类型 | 必填 | 默认值 | 参数描述 |
-| ------- | ------ | ---- | ---- | ----------------------------- |
-| fingers | number | 否 | 2 | 触发旋转的最少手指数, 最小为2指,最大为5指。 |
-| angle | number | 否 | 1.0 | 触发旋转手势的最小改变度数,单位为度数。 |
+ | 参数名称 | 参数类型 | 必填 | 默认值 | 参数描述 |
+ | -------- | -------- | -------- | -------- | -------- |
+ | fingers | number | 否 | 2 | 触发旋转的最少手指数, 最小为2指,最大为5指。 |
+ | angle | number | 否 | 1.0 | 触发旋转手势的最小改变度数,单位为deg。 |
+
## 事件
-| 名称 | 功能描述 |
-| ---------------------------------------- | ----------------------------- |
-| onActionStart((event?: GestureEvent) => void) | Rotation手势识别成功回调。 |
-| onActionUpdate((event?: GestureEvent) => void) | Rotation手势移动过程中回调。 |
-| onActionEnd((event?: GestureEvent) => void) | Rotation手势识别成功,手指抬起后触发回调。 |
+| 名称 | 功能描述 |
+| -------- | -------- |
+| onActionStart((event?: [GestureEvent](ts-gesture-settings.md)) => void) | Rotation手势识别成功回调。 |
+| onActionUpdate((event?: [GestureEvent](ts-gesture-settings.md)) => void) | Rotation手势移动过程中回调。 |
+| onActionEnd((event?: [GestureEvent](ts-gesture-settings.md)) => void) | Rotation手势识别成功,手指抬起后触发回调。 |
| onActionCancel(event: () => void) | Rotation手势识别成功,接收到触摸取消事件触发回调。 |
-## GestureEvent对象中与Rotation手势相关的属性
-
-| 属性名称 | 属性类型 | 描述 |
-| ----- | ------ | ----- |
-| angle | number | 旋转角度。 |
## 示例
diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-basic-gestures-swipegesture.md b/zh-cn/application-dev/reference/arkui-ts/ts-basic-gestures-swipegesture.md
index 7ed289a2dbb41da40eafbfad3b991a956ddb61b3..191414d1ab44fb1227e1cdc9c73f8fd671432d8c 100644
--- a/zh-cn/application-dev/reference/arkui-ts/ts-basic-gestures-swipegesture.md
+++ b/zh-cn/application-dev/reference/arkui-ts/ts-basic-gestures-swipegesture.md
@@ -1,7 +1,6 @@
# SwipeGesture
> **说明:**
->
> 从API Version 8开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
@@ -16,32 +15,28 @@ SwipeGesture(value?: { fingers?: number; direction?: SwipeDirection; speed?: num
**参数:**
-| 参数名称 | 参数类型 | 必填 | 默认值 | 参数描述 |
-| --------- | -------------- | ---- | ------------------ | ----------------------------- |
-| fingers | number | 否 | 1 | 触发滑动的最少手指数,默认为1,最小为1指,最大为10指。 |
-| direction | SwipeDirection | 否 | SwipeDirection.All | 滑动方向。 |
-| speed | number | 否 | 100 | 识别滑动的最小速度(100VP/秒)。 |
+ | 参数名称 | 参数类型 | 必填 | 默认值 | 参数描述 |
+ | -------- | -------- | -------- | -------- | -------- |
+ | fingers | number | 否 | 1 | 触发滑动的最少手指数,默认为1,最小为1指,最大为10指。 |
+ | direction | SwipeDirection | 否 | SwipeDirection.All | 触发滑动手势的滑动方向。 |
+ | speed | number | 否 | 100 | 识别滑动的最小速度(默认为100vp/秒)。 |
## SwipeDirection枚举说明
-| 名称 | 描述 |
-| ---------- | ----- |
-| All | 所有方向。 |
-| Horizontal | 水平方向。 |
-| Vertical | 竖直方向。 |
+ | 名称 | 描述 |
+ | -------- | -------- |
+ | All | 所有方向。 |
+ | Horizontal | 水平方向。 |
+ | Vertical | 竖直方向。 |
+ | None | 任何方向均不可触发。 |
-## 事件
-| 名称 | 功能描述 |
-| ---------------------------------------- | ----------- |
-| onAction(callback:(event?: GestureEvent) => void) | 滑动手势识别成功回调。 |
+## 事件
-## GestureEvent对象中与Swipe手势相关的属性
+| 名称 | 功能描述 |
+| -------- | -------- |
+| onAction(callback:(event?: [GestureEvent](ts-gesture-settings.md)) => void) | 滑动手势识别成功回调。 |
-| 参数名 | 类型 | 说明 |
-| ----- | ------ | ---------------------------------------- |
-| angle | number | 滑动手势的角度,即两根手指间的线段与水平方向的夹角变化的度数。
> **说明:**
> 角度计算方式:滑动手势被识别到后,连接两根手指之间的线被识别为起始线条,随着手指的滑动,手指之间的线条会发生旋转,根据起始线条两端点和当前线条两端点的坐标,使用反正切函数分别计算其相对于水平方向的夹角,最后arctan2(cy2-cy1,cx2-cx1)-arctan2(y2-y1,x2-x1)为旋转的角度。以起始线条为坐标系,顺时针旋转为0到180度,逆时针旋转为-180到0度。 |
-| speed | number | 滑动手势的速度,是所有手指滑动的平均速度,单位为VP/秒。 |
![zh-cn_image_0000001231374559](figures/zh-cn_image_0000001231374661.png)
## 示例
@@ -64,7 +59,7 @@ struct SwipeGestureExample {
.width(260).height(260)
.rotate({x: 0, y: 0, z: 1, angle: this.rotateAngle})
.gesture(
- SwipeGesture({fingers: 1, direction:SwipeDirection.Vertical})
+ SwipeGesture({fingers: 1, direction: SwipeDirection.Vertical})
.onAction((event: GestureEvent) => {
this.speed = event.speed
this.rotateAngle = event.angle
diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-basic-gestures-tapgesture.md b/zh-cn/application-dev/reference/arkui-ts/ts-basic-gestures-tapgesture.md
index 4c332ec0f342a372c72e8a3074c88675d8c2b956..21e18a8c72a40bea2e59101c035fb54a7e3f8eaa 100644
--- a/zh-cn/application-dev/reference/arkui-ts/ts-basic-gestures-tapgesture.md
+++ b/zh-cn/application-dev/reference/arkui-ts/ts-basic-gestures-tapgesture.md
@@ -1,7 +1,6 @@
# TapGesture
> **说明:**
->
> 从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
@@ -16,15 +15,16 @@ TapGesture(options?: { count?: number, fingers?: number })
**参数:**
-| 参数名称 | 参数类型 | 必填 | 默认值 | 参数描述 |
-| ------- | ------ | ---- | ---- | ---------------------------------------- |
-| count | number | 否 | 1 | 识别的连续点击次数。如果设置小于1,会被转化为默认值。
> **说明:**
> 如配置多击,上一次抬起和下一次按下的超时时间为300毫秒(ms)。 |
-| fingers | number | 否 | 1 | 触发点击的最少手指数,最小为1指, 最大为10指。
> **说明:**
> 1. 当配置多指时,第一根手指按下后300毫秒(ms)内未有足够的手指数按下,手势识别失败。
>
> 2. 实际点击手指数超过配置值,手势识别失败。 |
+ | 参数名称 | 参数类型 | 必填 | 默认值 | 参数描述 |
+ | -------- | -------- | -------- | -------- | -------- |
+ | count | number | 否 | 1 | 识别的连续点击次数。如果设置小于1,会被转化为默认值。
> **说明:**
> 如配置多击,上一次抬起和下一次按下的超时时间为300毫秒(ms)。 |
+ | fingers | number | 否 | 1 | 触发点击的最少手指数,最小为1指, 最大为10指。
> **说明:**
> 1. 当配置多指时,第一根手指按下后300毫秒(ms)内未有足够的手指数按下,手势识别失败。
> 2. 实际点击手指数超过配置值,手势识别失败。 |
+
## 事件
-| 名称 | 功能描述 |
-| ---------------------------------------- | ------------ |
+| 名称 | 功能描述 |
+| -------- | -------- |
| onAction((event?: [GestureEvent](ts-gesture-settings.md)) => void) | Tap手势识别成功回调。 |
diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-canvasrenderingcontext2d.md b/zh-cn/application-dev/reference/arkui-ts/ts-canvasrenderingcontext2d.md
index 08db299f856f4fdae23a238e0bc16c6c6bfcdee4..152ff182e77fc382f99a785de5ad2aa95194deb9 100644
--- a/zh-cn/application-dev/reference/arkui-ts/ts-canvasrenderingcontext2d.md
+++ b/zh-cn/application-dev/reference/arkui-ts/ts-canvasrenderingcontext2d.md
@@ -1,8 +1,7 @@
# CanvasRenderingContext2D对象
-> **说明:**
->
-> 从API Version 8开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
+> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
+> 从API Version 8开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
使用RenderingContext在Canvas组件上进行绘制,绘制对象可以是矩形、文本、图片等。
@@ -12,51 +11,50 @@
CanvasRenderingContext2D(setting: RenderingContextSetting)
-**参数:**
+**参数:**
-| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 |
-| ------- | ---------------------------------------- | ---- | ---- | ---------------------------------------- |
-| setting | [RenderingContextSettings](#renderingcontextsettings) | 是 | - | 见[RenderingContextSettings](#renderingcontextsettings)。 |
+ | 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 |
+ | ------- | ---------------------------------------- | ---- | ---- | ---------------------------------------- |
+ | setting | [RenderingContextSettings](#renderingcontextsettings) | 是 | - | 见[RenderingContextSettings](#renderingcontextsettings)。 |
### RenderingContextSettings
-RenderingContextSettings(antialias?: bool)
+RenderingContextSettings(antialias?: boolean)
用来配置CanvasRenderingContext2D对象的参数,包括是否开启抗锯齿。
-**参数:**
-| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 |
-| --------- | ---- | ---- | ----- | ---------------- |
-| antialias | bool | 否 | false | 表明canvas是否开启抗锯齿。 |
+**参数:**
+
+ | 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 |
+ | --------- | ------- | ---- | ----- | ---------------- |
+ | antialias | boolean | 否 | false | 表明canvas是否开启抗锯齿。 |
## 属性
-| 名称 | 类型 | 默认值 | 描述 |
-| ---------------------------------------- | ---------------------------------------- | ---------------------------------------- | ---------------------------------------- |
-| [fillStyle](#fillstyle) | <color> \| [CanvasGradient](ts-components-canvas-canvasgradient.md) \| [CanvasPattern](#canvaspattern) | - | 指定绘制的填充色。
- 类型为<color>时,表示设置填充区域的颜色。
- 类型为CanvasGradient时,表示渐变对象,使用[createLinearGradient](#createlineargradient)方法创建。
- 类型为CanvasPattern时,使用[createPattern](#createpattern)方法创建。 |
-| [lineWidth](#linewidth) | number | - | 设置绘制线条的宽度。 |
-| [strokeStyle](#strokestyle) | <color> \| [CanvasGradient](ts-components-canvas-canvasgradient.md) \| [CanvasPattern](#canvaspattern) | - | 设置描边的颜色。
- 类型为<color>时,表示设置描边使用的颜色。
- 类型为CanvasGradient时,表示渐变对象,使用[createLinearGradient](#createlineargradient)方法创建。
- 类型为CanvasPattern时,使用[createPattern](#createpattern)方法创建。 |
-| [lineCap](#linecap) | string | 'butt' | 指定线端点的样式,可选值为:
- 'butt':线端点以方形结束。
- 'round':线端点以圆形结束。
- 'square':线端点以方形结束,该样式下会增加一个长度和线段厚度相同,宽度是线段厚度一半的矩形。 |
-| [lineJoin](#linejoin) | string | 'miter' | 指定线段间相交的交点样式,可选值为:
- 'round':在线段相连处绘制一个扇形,扇形的圆角半径是线段的宽度。
- 'bevel':在线段相连处使用三角形为底填充, 每个部分矩形拐角独立。
- 'miter':在相连部分的外边缘处进行延伸,使其相交于一点,形成一个菱形区域,该属性可以通过设置miterLimit属性展现效果。 |
-| [miterLimit](#miterlimit) | number | 10 | 设置斜接面限制值,该值指定了线条相交处内角和外角的距离。 |
-| [font](#font) | string | 'normal normal 14px sans-serif' | 设置文本绘制中的字体样式。
语法:ctx.font='font-size font-family'
- font-size(可选),指定字号和行高,单位只支持px。
- font-family(可选),指定字体系列。
语法:ctx.font='font-style font-weight font-size font-family'
- font-style(可选),用于指定字体样式,支持如下几种样式:'normal',talic。
- font-weight(可选),用于指定字体的粗细,支持如下几种类型:'normal', 'bold', 'bolder', 'lighter', 100, 200, 300, 400, 500, 600, 700, 800, 900。
- font-size(可选),指定字号和行高,单位只支持px。
- font-family(可选),指定字体系列,支持如下几种类型:'sans-serif', 'serif', 'monospace'。 |
-| [textAlign](#textalign) | string | 'left' | 设置文本绘制中的文本对齐方式,可选值为:
- 'left':文本左对齐。
- 'right':文本右对齐。
- 'center':文本居中对齐。
- 'start':文本对齐界线开始的地方。
- 'end':文本对齐界线结束的地方。
> **说明:**
> ltr布局模式下'start'和'left'一致,rtl布局模式下'start'和'right'一致·。 |
-| [textBaseline](#textbaseline) | string | 'alphabetic' | 设置文本绘制中的水平对齐方式,可选值为:
- 'alphabetic':文本基线是标准的字母基线。
- 'top':文本基线在文本块的顶部。
- 'hanging':文本基线是悬挂基线。
- 'middle':文本基线在文本块的中间。
- 'ideographic':文字基线是表意字基线;如果字符本身超出了alphabetic基线,那么ideograhpic基线位置在字符本身的底部。
- 'bottom':文本基线在文本块的底部。 与ideographic基线的区别在于ideographic基线不需要考虑下行字母。 |
-| [globalAlpha](#globalalpha) | number | - | 设置透明度,0.0为完全透明,1.0为完全不透明。 |
-| [lineDashOffset](#linedashoffset) | number | 0.0 | 设置画布的虚线偏移量,精度为float。 |
-| [globalCompositeOperation](#globalcompositeoperation) | string | 'source-over' | 设置合成操作的方式。类型字段可选值有'source-over','source-atop','source-in','source-out','destination-over','destination-atop','destination-in','destination-out','lighter','copy','xor'。 |
-| [shadowBlur](#shadowblur) | number | 0.0 | 设置绘制阴影时的模糊级别,值越大越模糊,精度为float。 |
-| [shadowColor](#shadowcolor) | <color> | - | 设置绘制阴影时的阴影颜色。 |
-| [shadowOffsetX](#shadowoffsetx) | number | - | 设置绘制阴影时和原有对象的水平偏移值。 |
-| [shadowOffsetY](#shadowoffsety) | number | - | 设置绘制阴影时和原有对象的垂直偏移值。 |
-| [imageSmoothingEnabled](#imagesmoothingenabled) | boolean | true | 用于设置绘制图片时是否进行图像平滑度调整,true为启用,false为不启用。 |
-| imageSmoothingQuality | string | 'low' | 用于设置图像平滑度,支持如下三种类型:'low', 'medium', 'high'。 |
-
-> **说明:**
->
-> <color>类型格式为 'rgb(255, 255, 255)','rgba(255, 255, 255, 1.0)','\#FFFFFF'。
+| 名称 | 类型 | 描述 |
+| ---------------------------------------- | ---------------------------------------- | ---------------------------------------- |
+| [fillStyle](#fillstyle) | string \| [CanvasGradient](ts-components-canvas-canvasgradient.md) \| [CanvasPattern](#canvaspattern) | 指定绘制的填充色。
- 类型为string时,表示设置填充区域的颜色。
- 类型为CanvasGradient时,表示渐变对象,使用[createLinearGradient](#createlineargradient)方法创建。
- 类型为CanvasPattern时,使用[createPattern](#createpattern)方法创建。 |
+| [lineWidth](#linewidth) | number | 设置绘制线条的宽度。 |
+| [strokeStyle](#strokestyle) | string \| [CanvasGradient](ts-components-canvas-canvasgradient.md) \| [CanvasPattern](#canvaspattern) | 设置描边的颜色。
- 类型为string时,表示设置描边使用的颜色。
- 类型为CanvasGradient时,表示渐变对象,使用[createLinearGradient](#createlineargradient)方法创建。
- 类型为CanvasPattern时,使用[createPattern](#createpattern)方法创建。 |
+| [lineCap](#linecap) | CanvasLineCap | 指定线端点的样式,可选值为:
- 'butt':线端点以方形结束。
- 'round':线端点以圆形结束。
- 'square':线端点以方形结束,该样式下会增加一个长度和线段厚度相同,宽度是线段厚度一半的矩形。
默认值:'butt'。 |
+| [lineJoin](#linejoin) | CanvasLineJoin | 指定线段间相交的交点样式,可选值为:
- 'round':在线段相连处绘制一个扇形,扇形的圆角半径是线段的宽度。
- 'bevel':在线段相连处使用三角形为底填充, 每个部分矩形拐角独立。
- 'miter':在相连部分的外边缘处进行延伸,使其相交于一点,形成一个菱形区域,该属性可以通过设置miterLimit属性展现效果。
默认值:'miter'。 |
+| [miterLimit](#miterlimit) | number | 设置斜接面限制值,该值指定了线条相交处内角和外角的距离。
默认值:10。 |
+| [font](#font) | string | 设置文本绘制中的字体样式。
语法:ctx.font='font-size font-family'
- font-size(可选),指定字号和行高,单位只支持px。
- font-family(可选),指定字体系列。
语法:ctx.font='font-style font-weight font-size font-family'
- font-style(可选),用于指定字体样式,支持如下几种样式:'normal','italic'。
- font-weight(可选),用于指定字体的粗细,支持如下几种类型:'normal', 'bold', 'bolder', 'lighter', 100, 200, 300, 400, 500, 600, 700, 800, 900。
- font-size(可选),指定字号和行高,单位只支持px。
- font-family(可选),指定字体系列,支持如下几种类型:'sans-serif', 'serif', 'monospace'。
默认值:'normal normal 14px sans-serif'。 |
+| [textAlign](#textalign) | CanvasTextAlign | 设置文本绘制中的文本对齐方式,可选值为:
- 'left':文本左对齐。
- 'right':文本右对齐。
- 'center':文本居中对齐。
- 'start':文本对齐界线开始的地方。
- 'end':文本对齐界线结束的地方。
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> ltr布局模式下'start'和'left'一致,rtl布局模式下'start'和'right'一致·。
默认值:'left'。 |
+| [textBaseline](#textbaseline) | CanvasTextBaseline | 设置文本绘制中的水平对齐方式,可选值为:
- 'alphabetic':文本基线是标准的字母基线。
- 'top':文本基线在文本块的顶部。
- 'hanging':文本基线是悬挂基线。
- 'middle':文本基线在文本块的中间。
- 'ideographic':文字基线是表意字基线;如果字符本身超出了alphabetic基线,那么ideograhpic基线位置在字符本身的底部。
- 'bottom':文本基线在文本块的底部。 与ideographic基线的区别在于ideographic基线不需要考虑下行字母。
默认值:'alphabetic'。 |
+| [globalAlpha](#globalalpha) | number | 设置透明度,0.0为完全透明,1.0为完全不透明。 |
+| [lineDashOffset](#linedashoffset) | number | 设置画布的虚线偏移量,精度为float。
默认值:0.0。 |
+| [globalCompositeOperation](#globalcompositeoperation) | string | 设置合成操作的方式。类型字段可选值有'source-over','source-atop','source-in','source-out','destination-over','destination-atop','destination-in','destination-out','lighter','copy','xor'。
默认值:'source-over'。 |
+| [shadowBlur](#shadowblur) | number | 设置绘制阴影时的模糊级别,值越大越模糊,精度为float。
默认值:0.0。 |
+| [shadowColor](#shadowcolor) | string | 设置绘制阴影时的阴影颜色。 |
+| [shadowOffsetX](#shadowoffsetx) | number | 设置绘制阴影时和原有对象的水平偏移值。 |
+| [shadowOffsetY](#shadowoffsety) | number | 设置绘制阴影时和原有对象的垂直偏移值。 |
+| [imageSmoothingEnabled](#imagesmoothingenabled) | boolean | 用于设置绘制图片时是否进行图像平滑度调整,true为启用,false为不启用。
默认值:true。 |
+
+> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
+>fillStyle、shadowColor与 strokeStyle 中string类型格式为 'rgb(255, 255, 255)','rgba(255, 255, 255, 1.0)','\#FFFFFF'。
### fillStyle
@@ -427,6 +425,7 @@ struct LineDashOffset {
.onReady(() =>{
this.context.arc(100, 75, 50, 0, 6.28)
this.context.setLineDash([10,20])
+ this.context.lineDashOffset = 10.0;
this.context.stroke();
})
}
@@ -597,6 +596,7 @@ struct ShadowOffsetX {
struct ShadowOffsetY {
private settings: RenderingContextSettings = new RenderingContextSettings(true)
private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
+
build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Canvas(this.context)
@@ -660,16 +660,19 @@ fillRect(x: number, y: number, w: number, h: number): void
填充一个矩形。
-**参数:**
-| 参数 | 类型 | 必填 | 默认值 | 说明 |
-| ------ | ------ | ---- | ---- | ------------- |
-| x | number | 是 | 0 | 指定矩形左上角点的x坐标。 |
-| y | number | 是 | 0 | 指定矩形左上角点的y坐标。 |
-| width | number | 是 | 0 | 指定矩形的宽度。 |
-| height | number | 是 | 0 | 指定矩形的高度。 |
+**参数:**
-**示例:**
- ```
+ | 参数 | 类型 | 必填 | 默认值 | 说明 |
+ | ------ | ------ | ---- | ---- | ------------- |
+ | x | number | 是 | 0 | 指定矩形左上角点的x坐标。 |
+ | y | number | 是 | 0 | 指定矩形左上角点的y坐标。 |
+ | width | number | 是 | 0 | 指定矩形的宽度。 |
+ | height | number | 是 | 0 | 指定矩形的高度。 |
+
+**示例:**
+
+ ```ts
+ // xxx.ets
@Entry
@Component
struct FillRect {
@@ -701,21 +704,25 @@ strokeRect(x: number, y: number, w: number, h: number): void
绘制具有边框的矩形,矩形内部不填充。
-**参数:**
-| 参数 | 类型 | 必填 | 默认值 | 说明 |
-| ------ | ------ | ---- | ---- | ------------ |
-| x | number | 是 | 0 | 指定矩形的左上角x坐标。 |
-| y | number | 是 | 0 | 指定矩形的左上角y坐标。 |
-| width | number | 是 | 0 | 指定矩形的宽度。 |
-| height | number | 是 | 0 | 指定矩形的高度。 |
+**参数:**
-**示例:**
- ```
+ | 参数 | 类型 | 必填 | 默认值 | 说明 |
+ | ------ | ------ | ---- | ---- | ------------ |
+ | x | number | 是 | 0 | 指定矩形的左上角x坐标。 |
+ | y | number | 是 | 0 | 指定矩形的左上角y坐标。 |
+ | w | number | 是 | 0 | 指定矩形的宽度。 |
+ | h | number | 是 | 0 | 指定矩形的高度。 |
+
+**示例:**
+
+ ```ts
+ // xxx.ets
@Entry
@Component
struct StrokeRect {
private settings: RenderingContextSettings = new RenderingContextSettings(true)
private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
+
build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Canvas(this.context)
@@ -741,21 +748,25 @@ clearRect(x: number, y: number, w: number, h: number): void
删除指定区域内的绘制内容。
-**参数:**
-| 参数 | 类型 | 必填 | 默认值 | 描述 |
-| ------ | ------ | ---- | ---- | ------------- |
-| x | number | 是 | 0 | 指定矩形上的左上角x坐标。 |
-| y | number | 是 | 0 | 指定矩形上的左上角y坐标。 |
-| width | number | 是 | 0 | 指定矩形的宽度。 |
-| height | number | 是 | 0 | 指定矩形的高度。 |
+**参数:**
-**示例:**
- ```
+ | 参数 | 类型 | 必填 | 默认值 | 描述 |
+ | ------ | ------ | ---- | ---- | ------------- |
+ | x | number | 是 | 0 | 指定矩形上的左上角x坐标。 |
+ | y | number | 是 | 0 | 指定矩形上的左上角y坐标。 |
+ | w | number | 是 | 0 | 指定矩形的宽度。 |
+ | h | number | 是 | 0 | 指定矩形的高度。 |
+
+**示例:**
+
+ ```ts
+ // xxx.ets
@Entry
@Component
struct ClearRect {
private settings: RenderingContextSettings = new RenderingContextSettings(true)
private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
+
build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Canvas(this.context)
@@ -779,24 +790,29 @@ clearRect(x: number, y: number, w: number, h: number): void
### fillText
-fillText(text: string, x: number, y: number): void
+fillText(text: string, x: number, y: number, maxWidth?: number): void
绘制填充类文本。
-**参数:**
-| 参数 | 类型 | 必填 | 默认值 | 说明 |
-| ---- | ------ | ---- | ---- | --------------- |
-| text | string | 是 | “” | 需要绘制的文本内容。 |
-| x | number | 是 | 0 | 需要绘制的文本的左下角x坐标。 |
-| y | number | 是 | 0 | 需要绘制的文本的左下角y坐标。 |
+**参数:**
-**示例:**
- ```
+ | 参数 | 类型 | 必填 | 默认值 | 说明 |
+ | ---- | ------ | ---- | ---- | --------------- |
+ | text | string | 是 | “” | 需要绘制的文本内容。 |
+ | x | number | 是 | 0 | 需要绘制的文本的左下角x坐标。 |
+ | y | number | 是 | 0 | 需要绘制的文本的左下角y坐标。 |
+ | maxWidth | number | 否 | - | 指定文本允许的最大宽度。 |
+
+**示例:**
+
+ ```ts
+ // xxx.ets
@Entry
@Component
struct FillText {
private settings: RenderingContextSettings = new RenderingContextSettings(true)
private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
+
build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Canvas(this.context)
@@ -819,24 +835,29 @@ fillText(text: string, x: number, y: number): void
### strokeText
-strokeText(text: string, x: number, y: number): void
+strokeText(text: string, x: number, y: number, maxWidth?:number): void
绘制描边类文本。
-**参数:**
-| 参数 | 类型 | 必填 | 默认值 | 描述 |
-| ---- | ------ | ---- | ---- | --------------- |
-| text | string | 是 | “” | 需要绘制的文本内容。 |
-| x | number | 是 | 0 | 需要绘制的文本的左下角x坐标。 |
-| y | number | 是 | 0 | 需要绘制的文本的左下角y坐标。 |
+**参数:**
-**示例:**
- ```
+ | 参数 | 类型 | 必填 | 默认值 | 描述 |
+ | ---- | ------ | ---- | ---- | --------------- |
+ | text | string | 是 | “” | 需要绘制的文本内容。 |
+ | x | number | 是 | 0 | 需要绘制的文本的左下角x坐标。 |
+ | y | number | 是 | 0 | 需要绘制的文本的左下角y坐标。 |
+ | maxWidth | number | 否 | - | 需要绘制的文本的最大宽度 。|
+
+**示例:**
+
+ ```ts
+ // xxx.ets
@Entry
@Component
struct StrokeText {
private settings: RenderingContextSettings = new RenderingContextSettings(true)
private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
+
build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Canvas(this.context)
@@ -863,28 +884,49 @@ measureText(text: string): TextMetrics
该方法返回一个文本测算的对象,通过该对象可以获取指定文本的宽度值。
-**参数:**
-| 参数 | 类型 | 必填 | 默认值 | 说明 |
-| ---- | ------ | ---- | ---- | ---------- |
-| text | string | 是 | "" | 需要进行测量的文本。 |
+**参数:**
+
+ | 参数 | 类型 | 必填 | 默认值 | 说明 |
+ | ---- | ------ | ---- | ---- | ---------- |
+ | text | string | 是 | "" | 需要进行测量的文本。 |
+
+**返回值:**
-- 返回值
| 类型 | 说明 |
| ----------- | ------- |
| TextMetrics | 文本的尺寸信息 |
-- TextMetrics类型描述
- | 属性 | 类型 | 描述 |
- | ----- | ------ | ------- |
- | width | number | 字符串的宽度。 |
+**TextMetrics类型描述:**
+
+ | 属性 | 类型 | 描述 |
+ | ----- | ------ | ------- |
+ | width | number | 字符串的宽度。 |
+ | height | number | 字符串的高度。 |
+ | actualBoundingBoxAscent | number | 从CanvasRenderingContext2D.textBaseline 属性标明的水平线到渲染文本的矩形边界顶部的距离,当前值为0。 |
+ | actualBoundingBoxDescent | number | 从CanvasRenderingContext2D.textBaseline 属性标明的水平线到渲染文本的矩形边界底部的距离,当前值为0。 |
+ | actualBoundingBoxLeft | number | 平行于基线,从CanvasRenderingContext2D.textAlign 属性确定的对齐点到文本矩形边界左侧的距离,当前值为0。 |
+ | actualBoundingBoxRight | number | 平行于基线,从CanvasRenderingContext2D.textAlign 属性确定的对齐点到文本矩形边界右侧的距离,当前值为0。|
+ | alphabeticBaseline | number | 从CanvasRenderingContext2D.textBaseline 属性标明的水平线到线框的 alphabetic 基线的距离,当前值为0。|
+ | emHeightAscent | number | 从CanvasRenderingContext2D.textBaseline 属性标明的水平线到线框中 em 方块顶部的距离,当前值为0。|
+ | emHeightDescent | number | 从CanvasRenderingContext2D.textBaseline 属性标明的水平线到线框中 em 方块底部的距离,当前值为0。|
+ | fontBoundingBoxAscent | number | 从CanvasRenderingContext2D.textBaseline 属性标明的水平线到渲染文本的所有字体的矩形最高边界顶部的距离,当前值为0。|
+ | fontBoundingBoxDescent | number | 从CanvasRenderingContext2D.textBaseline 属性标明的水平线到渲染文本的所有字体的矩形边界最底部的距离,当前值为0。|
+ | hangingBaseline | number | 从CanvasRenderingContext2D.textBaseline 属性标明的水平线到线框的 hanging 基线的距离,当前值为0。|
+ | ideographicBaseline | number | 从CanvasRenderingContext2D.textBaseline 属性标明的水平线到线框的 ideographic 基线的距离,当前值为0。|
-**示例:**
- ```
+
+
+
+**示例:**
+
+ ```ts
+ // xxx.ets
@Entry
@Component
struct MeasureText {
private settings: RenderingContextSettings = new RenderingContextSettings(true)
private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
+
build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Canvas(this.context)
@@ -912,19 +954,22 @@ stroke(path?: Path2D): void
进行边框绘制操作。
-**参数:**
-| 参数 | 类型 | 必填 | 默认值 | 描述 |
-| ---- | ---------------------------------------- | ---- | ---- | ------------ |
-| path | [Path2D](ts-components-canvas-path2d.md) | 否 | null | 需要绘制的Path2D。 |
+**参数:**
-**示例:**
- ```
+ | 参数 | 类型 | 必填 | 默认值 | 描述 |
+ | ---- | ---------------------------------------- | ---- | ---- | ------------ |
+ | path | [Path2D](ts-components-canvas-path2d.md) | 否 | null | 需要绘制的Path2D。 |
+
+**示例:**
+
+ ```ts
+ // xxx.ets
@Entry
@Component
struct Stroke {
private settings: RenderingContextSettings = new RenderingContextSettings(true)
private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
-
+
build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Canvas(this.context)
@@ -953,14 +998,16 @@ beginPath(): void
创建一个新的绘制路径。
-**示例:**
- ```
+**示例:**
+
+ ```ts
+ // xxx.ets
@Entry
@Component
struct BeginPath {
private settings: RenderingContextSettings = new RenderingContextSettings(true)
private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
-
+
build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Canvas(this.context)
@@ -991,20 +1038,23 @@ moveTo(x: number, y: number): void
路径从当前点移动到指定点。
-**参数:**
-| 参数 | 类型 | 必填 | 默认值 | 说明 |
-| ---- | ------ | ---- | ---- | --------- |
-| x | number | 是 | 0 | 指定位置的x坐标。 |
-| y | number | 是 | 0 | 指定位置的y坐标。 |
+**参数:**
-**示例:**
- ```
+ | 参数 | 类型 | 必填 | 默认值 | 说明 |
+ | ---- | ------ | ---- | ---- | --------- |
+ | x | number | 是 | 0 | 指定位置的x坐标。 |
+ | y | number | 是 | 0 | 指定位置的y坐标。 |
+
+**示例:**
+
+ ```ts
+ // xxx.ets
@Entry
@Component
struct MoveTo {
private settings: RenderingContextSettings = new RenderingContextSettings(true)
private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
-
+
build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Canvas(this.context)
@@ -1033,20 +1083,23 @@ lineTo(x: number, y: number): void
从当前点到指定点进行路径连接。
-**参数:**
-| 参数 | 类型 | 必填 | 默认值 | 描述 |
-| ---- | ------ | ---- | ---- | --------- |
-| x | number | 是 | 0 | 指定位置的x坐标。 |
-| y | number | 是 | 0 | 指定位置的y坐标。 |
+**参数:**
-**示例:**
- ```
+ | 参数 | 类型 | 必填 | 默认值 | 描述 |
+ | ---- | ------ | ---- | ---- | --------- |
+ | x | number | 是 | 0 | 指定位置的x坐标。 |
+ | y | number | 是 | 0 | 指定位置的y坐标。 |
+
+**示例:**
+
+ ```ts
+ // xxx.ets
@Entry
@Component
struct LineTo {
private settings: RenderingContextSettings = new RenderingContextSettings(true)
private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
-
+
build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Canvas(this.context)
@@ -1075,14 +1128,16 @@ closePath(): void
结束当前路径形成一个封闭路径。
-**示例:**
- ```
+**示例:**
+
+ ```ts
+ // xxx.ets
@Entry
@Component
struct ClosePath {
private settings: RenderingContextSettings = new RenderingContextSettings(true)
private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
-
+
build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Canvas(this.context)
@@ -1109,25 +1164,34 @@ closePath(): void
### createPattern
-createPattern(image: ImageBitmap, repetition: string): void
+createPattern(image: ImageBitmap, repetition: string | null): CanvasPattern | null
通过指定图像和重复方式创建图片填充的模板。
-**参数:**
-| 参数 | 类型 | 必填 | 默认值 | 描述 |
-| ---------- | ---------------------------------------- | ---- | ---- | ---------------------------------------- |
-| image | [ImageBitmap](ts-components-canvas-imagebitmap.md) | 是 | null | 图源对象,具体参考ImageBitmap对象。 |
-| repetition | string | 是 | “” | 设置图像重复的方式,取值为:'repeat'、'repeat-x'、 'repeat-y'、'no-repeat'。 |
+**参数:**
-**示例:**
- ```
+ | 参数 | 类型 | 必填 | 默认值 | 描述 |
+ | ---------- | ---------------------------------------- | ---- | ---- | ---------------------------------------- |
+ | image | [ImageBitmap](ts-components-canvas-imagebitmap.md) | 是 | null | 图源对象,具体参考ImageBitmap对象。 |
+ | repetition | string | 是 | “” | 设置图像重复的方式,取值为:'repeat'、'repeat-x'、 'repeat-y'、'no-repeat'。 |
+
+**返回值:**:
+
+ | 类型 | 说明 |
+ | ---------- | ---------------------------------------- |
+ | [CanvasPattern](#canvaspattern) | 通过指定图像和重复方式创建图片填充的模板对象。 |
+
+**示例:**
+
+ ```ts
+ // xxx.ets
@Entry
@Component
struct CreatePattern {
private settings: RenderingContextSettings = new RenderingContextSettings(true)
private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
private img:ImageBitmap = new ImageBitmap("common/images/icon.jpg")
-
+
build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Canvas(this.context)
@@ -1155,24 +1219,27 @@ bezierCurveTo(cp1x: number, cp1y: number, cp2x: number, cp2y: number, x: number,
创建三次贝赛尔曲线的路径。
-**参数:**
-| 参数 | 类型 | 必填 | 默认值 | 描述 |
-| ---- | ------ | ---- | ---- | -------------- |
-| cp1x | number | 是 | 0 | 第一个贝塞尔参数的x坐标值。 |
-| cp1y | number | 是 | 0 | 第一个贝塞尔参数的y坐标值。 |
-| cp2x | number | 是 | 0 | 第二个贝塞尔参数的x坐标值。 |
-| cp2y | number | 是 | 0 | 第二个贝塞尔参数的y坐标值。 |
-| x | number | 是 | 0 | 路径结束时的x坐标值。 |
-| y | number | 是 | 0 | 路径结束时的y坐标值。 |
+**参数:**
-**示例:**
- ```
+ | 参数 | 类型 | 必填 | 默认值 | 描述 |
+ | ---- | ------ | ---- | ---- | -------------- |
+ | cp1x | number | 是 | 0 | 第一个贝塞尔参数的x坐标值。 |
+ | cp1y | number | 是 | 0 | 第一个贝塞尔参数的y坐标值。 |
+ | cp2x | number | 是 | 0 | 第二个贝塞尔参数的x坐标值。 |
+ | cp2y | number | 是 | 0 | 第二个贝塞尔参数的y坐标值。 |
+ | x | number | 是 | 0 | 路径结束时的x坐标值。 |
+ | y | number | 是 | 0 | 路径结束时的y坐标值。 |
+
+**示例:**
+
+ ```ts
+ // xxx.ets
@Entry
@Component
struct BezierCurveTo {
private settings: RenderingContextSettings = new RenderingContextSettings(true)
private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
-
+
build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Canvas(this.context)
@@ -1201,21 +1268,25 @@ quadraticCurveTo(cpx: number, cpy: number, x: number, y: number): void
创建二次贝赛尔曲线的路径。
-**参数:**
-| 参数 | 类型 | 必填 | 默认值 | 描述 |
-| ---- | ------ | ---- | ---- | ----------- |
-| cpx | number | 是 | 0 | 贝塞尔参数的x坐标值。 |
-| cpy | number | 是 | 0 | 贝塞尔参数的y坐标值。 |
-| x | number | 是 | 0 | 路径结束时的x坐标值。 |
-| y | number | 是 | 0 | 路径结束时的y坐标值。 |
+**参数:**
-**示例:**
- ```
+ | 参数 | 类型 | 必填 | 默认值 | 描述 |
+ | ---- | ------ | ---- | ---- | ----------- |
+ | cpx | number | 是 | 0 | 贝塞尔参数的x坐标值。 |
+ | cpy | number | 是 | 0 | 贝塞尔参数的y坐标值。 |
+ | x | number | 是 | 0 | 路径结束时的x坐标值。 |
+ | y | number | 是 | 0 | 路径结束时的y坐标值。 |
+
+**示例:**
+
+ ```ts
+ // xxx.ets
@Entry
@Component
struct QuadraticCurveTo {
private settings: RenderingContextSettings = new RenderingContextSettings(true);
private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings);
+
build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Canvas(this.context)
@@ -1240,28 +1311,31 @@ quadraticCurveTo(cpx: number, cpy: number, x: number, y: number): void
### arc
-arc(x: number, y: number, radius: number, startAngle: number, endAngle: number, anticlockwise?: boolean): void
+arc(x: number, y: number, radius: number, startAngle: number, endAngle: number, counterclockwise?: boolean): void
绘制弧线路径。
-**参数:**
-| 参数 | 类型 | 必填 | 默认值 | 描述 |
-| ------------- | ------- | ---- | ----- | ---------- |
-| x | number | 是 | 0 | 弧线圆心的x坐标值。 |
-| y | number | 是 | 0 | 弧线圆心的y坐标值。 |
-| radius | number | 是 | 0 | 弧线的圆半径。 |
-| startAngle | number | 是 | 0 | 弧线的起始弧度。 |
-| endAngle | number | 是 | 0 | 弧线的终止弧度。 |
-| anticlockwise | boolean | 否 | false | 是否逆时针绘制圆弧。 |
+**参数:**
-**示例:**
- ```
+ | 参数 | 类型 | 必填 | 默认值 | 描述 |
+ | ------------- | ------- | ---- | ----- | ---------- |
+ | x | number | 是 | 0 | 弧线圆心的x坐标值。 |
+ | y | number | 是 | 0 | 弧线圆心的y坐标值。 |
+ | radius | number | 是 | 0 | 弧线的圆半径。 |
+ | startAngle | number | 是 | 0 | 弧线的起始弧度。 |
+ | endAngle | number | 是 | 0 | 弧线的终止弧度。 |
+ | counterclockwise | boolean | 否 | false | 是否逆时针绘制圆弧。 |
+
+**示例:**
+
+ ```ts
+ // xxx.ets
@Entry
@Component
struct Arc {
private settings: RenderingContextSettings = new RenderingContextSettings(true)
private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
-
+
build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Canvas(this.context)
@@ -1289,23 +1363,26 @@ arcTo(x1: number, y1: number, x2: number, y2: number, radius: number): void
依据圆弧经过的点和圆弧半径创建圆弧路径。
-**参数:**
-| 参数 | 类型 | 必填 | 默认值 | 描述 |
-| ------ | ------ | ---- | ---- | --------------- |
-| x1 | number | 是 | 0 | 圆弧经过的第一个点的x坐标值。 |
-| y1 | number | 是 | 0 | 圆弧经过的第一个点的y坐标值。 |
-| x2 | number | 是 | 0 | 圆弧经过的第二个点的x坐标值。 |
-| y2 | number | 是 | 0 | 圆弧经过的第二个点的y坐标值。 |
-| radius | number | 是 | 0 | 圆弧的圆半径值。 |
+**参数:**
-**示例:**
- ```
+ | 参数 | 类型 | 必填 | 默认值 | 描述 |
+ | ------ | ------ | ---- | ---- | --------------- |
+ | x1 | number | 是 | 0 | 圆弧经过的第一个点的x坐标值。 |
+ | y1 | number | 是 | 0 | 圆弧经过的第一个点的y坐标值。 |
+ | x2 | number | 是 | 0 | 圆弧经过的第二个点的x坐标值。 |
+ | y2 | number | 是 | 0 | 圆弧经过的第二个点的y坐标值。 |
+ | radius | number | 是 | 0 | 圆弧的圆半径值。 |
+
+**示例:**
+
+ ```ts
+ // xxx.ets
@Entry
@Component
struct ArcTo {
private settings: RenderingContextSettings = new RenderingContextSettings(true)
private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
-
+
build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Canvas(this.context)
@@ -1329,31 +1406,33 @@ arcTo(x1: number, y1: number, x2: number, y2: number, radius: number): void
### ellipse
-ellipse(x: number, y: number, radiusX: number, radiusY: number, rotation: number, startAngle: number, endAngle: number, anticlockwise?: boolean): void
+ellipse(x: number, y: number, radiusX: number, radiusY: number, rotation: number, startAngle: number, endAngle: number, counterclockwise?: boolean): void
在规定的矩形区域绘制一个椭圆。
-**参数:**
-| 参数 | 类型 | 必填 | 默认值 | 说明 |
-| ------------- | ------- | ---- | ----- | ----------------- |
-| x | number | 是 | 0 | 椭圆圆心的x轴坐标。 |
-| y | number | 是 | 0 | 椭圆圆心的y轴坐标。 |
-| radiusX | number | 是 | 0 | 椭圆x轴的半径长度。 |
-| radiusY | number | 是 | 0 | 椭圆y轴的半径长度。 |
-| rotation | number | 是 | 0 | 椭圆的旋转角度,单位为弧度。 |
-| startAngle | number | 是 | 0 | 椭圆绘制的起始点角度,以弧度表示。 |
-| endAngle | number | 是 | 0 | 椭圆绘制的结束点角度,以弧度表示。 |
-| anticlockwise | boolean | 否 | false | 是否以逆时针方向绘制椭圆。 |
+**参数:**
-**示例:**
+ | 参数 | 类型 | 必填 | 默认值 | 说明 |
+ | ------------- | ------- | ---- | ----- | ----------------- |
+ | x | number | 是 | 0 | 椭圆圆心的x轴坐标。 |
+ | y | number | 是 | 0 | 椭圆圆心的y轴坐标。 |
+ | radiusX | number | 是 | 0 | 椭圆x轴的半径长度。 |
+ | radiusY | number | 是 | 0 | 椭圆y轴的半径长度。 |
+ | rotation | number | 是 | 0 | 椭圆的旋转角度,单位为弧度。 |
+ | startAngle | number | 是 | 0 | 椭圆绘制的起始点角度,以弧度表示。 |
+ | endAngle | number | 是 | 0 | 椭圆绘制的结束点角度,以弧度表示。 |
+ | counterclockwise | boolean | 否 | false | 是否以逆时针方向绘制椭圆。 |
- ```
+**示例:**
+
+ ```ts
+ // xxx.ets
@Entry
@Component
struct CanvasExample {
private settings: RenderingContextSettings = new RenderingContextSettings(true)
private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
-
+
build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Canvas(this.context)
@@ -1377,26 +1456,29 @@ ellipse(x: number, y: number, radiusX: number, radiusY: number, rotation: number
### rect
-rect(x: number, y: number, width: number, height: number): void
+rect(x: number, y: number, w: number, h: number): void
创建矩形路径。
-**参数:**
-| 参数 | 类型 | 必填 | 默认值 | 描述 |
-| ------ | ------ | ---- | ---- | ------------- |
-| x | number | 是 | 0 | 指定矩形的左上角x坐标值。 |
-| y | number | 是 | 0 | 指定矩形的左上角y坐标值。 |
-| width | number | 是 | 0 | 指定矩形的宽度。 |
-| height | number | 是 | 0 | 指定矩形的高度。 |
+**参数:**
-**示例:**
- ```
+ | 参数 | 类型 | 必填 | 默认值 | 描述 |
+ | ------ | ------ | ---- | ---- | ------------- |
+ | x | number | 是 | 0 | 指定矩形的左上角x坐标值。 |
+ | y | number | 是 | 0 | 指定矩形的左上角y坐标值。 |
+ | w | number | 是 | 0 | 指定矩形的宽度。 |
+ | h | number | 是 | 0 | 指定矩形的高度。 |
+
+**示例:**
+
+ ```ts
+ // xxx.ets
@Entry
@Component
struct CanvasExample {
private settings: RenderingContextSettings = new RenderingContextSettings(true)
private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
-
+
build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Canvas(this.context)
@@ -1419,12 +1501,21 @@ rect(x: number, y: number, width: number, height: number): void
### fill
-fill(): void
+fill(fillRule?: CanvasFillRule): void
对封闭路径进行填充。
-**示例:**
- ```
+**参数:**
+
+ | 参数 | 类型 | 必填 | 默认值 | 描述 |
+ | ------ | ------ | ---- | ---- | ------------- |
+ | fillRule | CanvasFillRule | 否 | "nonzero" | 指定要填充对象的规则。
可选参数为:"nonzero", "evenodd"。|
+
+
+**示例:**
+
+ ```ts
+ // xxx.ets
@Entry
@Component
struct Fill {
@@ -1451,14 +1542,73 @@ fill(): void
![zh-cn_image_0000001238952381](figures/zh-cn_image_0000001238952381.png)
+fill(path: Path2D, fillRule?: CanvasFillRule): void
+
+对封闭路径进行填充。
+
+**参数:**
+
+ | 参数 | 类型 | 必填 | 默认值 | 描述 |
+ | ------ | ------ | ---- | ---- | ------------- |
+ | path | Path2D | 是 | | Path2D填充路径。 |
+ | fillRule | CanvasFillRule | 否 | "nonzero" | 指定要填充对象的规则。
可选参数为:"nonzero", "evenodd"。|
+
+
+**示例:**
+
+```ts
+// xxx.ets
+@Entry
+@Component
+struct Fill {
+ private settings: RenderingContextSettings = new RenderingContextSettings(true)
+ private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
+
+ build() {
+ Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
+ Canvas(this.context)
+ .width('100%')
+ .height('100%')
+ .backgroundColor('#ffff00')
+ .onReady(() =>{
+ let region = new Path2D();
+ region.moveTo(30, 90);
+ region.lineTo(110, 20);
+ region.lineTo(240, 130);
+ region.lineTo(60, 130);
+ region.lineTo(190, 20);
+ region.lineTo(270, 90);
+ region.closePath();
+ // Fill path
+ this.context.fillStyle = 'green';
+ this.context.fill(region, "evenodd");
+ })
+ }
+ .width('100%')
+ .height('100%')
+ }
+}
+ ```
+
+ ![zh-cn_image_000000127777774](figures/zh-cn_image_000000127777774.png)
+
+
### clip
-clip(): void
+clip(fillRule?: CanvasFillRule): void
设置当前路径为剪切路径。
-**示例:**
- ```
+**参数:**
+
+ | 参数 | 类型 | 必填 | 默认值 | 描述 |
+ | ------ | ------ | ---- | ---- | ------------- |
+ | fillRule | CanvasFillRule | 否 | "nonzero" | 指定要剪切对象的规则。
可选参数为:"nonzero", "evenodd"。|
+
+**示例:**
+
+ ```ts
+ // xxx.ets
@Entry
@Component
struct Clip {
@@ -1488,25 +1638,75 @@ clip(): void
![zh-cn_image_0000001194032462](figures/zh-cn_image_0000001194032462.png)
+clip(path: Path2D, fillRule?: CanvasFillRule): void
+
+对封闭路径进行填充。该接口为空接口。
+
+**参数:**
+
+ | 参数 | 类型 | 必填 | 默认值 | 描述 |
+ | ------ | ------ | ---- | ---- | ------------- |
+ | path | Path2D | 是 | - | Path2D剪切路径。 |
+ | fillRule | CanvasFillRule | 否 | "nonzero" | 指定要剪切对象的规则。
可选参数为:"nonzero", "evenodd"。|
+
+
+
+### filter
+
+filter(filter: string): void
+
+为Canvas图形设置各类滤镜效果。该接口为空接口。
+
+**参数:**
+
+ | 参数 | 类型 | 必填 | 默认值 | 说明 |
+ | ------ | ------ | ---- | ---- | ------------- |
+ | filter | string | 是 | - | 接受各类滤镜效果的函数。|
+
+
+### getTransform
+
+getTransform(): Matrix2D
+
+获取当前被应用到上下文的转换矩阵。该接口为空接口。
+
+
+### resetTransform
+
+resetTransform(): void
+
+使用单位矩阵重新设置当前变形。该接口为空接口。
+
+
+### direction
+
+direction(direction: CanvasDirection): void
+
+绘制文本时,描述当前文本方向的属性。该接口为空接口。
+
+
### rotate
-rotate(rotate: number): void
+rotate(angle: number): void
针对当前坐标轴进行顺时针旋转。
-**参数:**
-| 参数 | 类型 | 必填 | 默认值 | 描述 |
-| ------ | ------ | ---- | ---- | ---------------------------------------- |
-| rotate | number | 是 | 0 | 设置顺时针旋转的弧度值,可以通过Math.PI / 180将角度转换为弧度值。 |
+**参数:**
-**示例:**
- ```
+ | 参数 | 类型 | 必填 | 默认值 | 描述 |
+ | ------ | ------ | ---- | ---- | ---------------------------------------- |
+ | angle | number | 是 | 0 | 设置顺时针旋转的弧度值,可以通过Math.PI / 180将角度转换为弧度值。 |
+
+**示例:**
+
+ ```ts
+ // xxx.ets
@Entry
@Component
struct Rotate {
private settings: RenderingContextSettings = new RenderingContextSettings(true)
private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
-
+
build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Canvas(this.context)
@@ -1533,20 +1733,23 @@ scale(x: number, y: number): void
设置canvas画布的缩放变换属性,后续的绘制操作将按照缩放比例进行缩放。
-**参数:**
-| 参数 | 类型 | 必填 | 默认值 | 描述 |
-| ---- | ------ | ---- | ---- | ----------- |
-| x | number | 是 | 0 | 设置水平方向的缩放值。 |
-| y | number | 是 | 0 | 设置垂直方向的缩放值。 |
+**参数:**
-**示例:**
- ```
+ | 参数 | 类型 | 必填 | 默认值 | 描述 |
+ | ---- | ------ | ---- | ---- | ----------- |
+ | x | number | 是 | 0 | 设置水平方向的缩放值。 |
+ | y | number | 是 | 0 | 设置垂直方向的缩放值。 |
+
+**示例:**
+
+ ```ts
+ // xxx.ets
@Entry
@Component
struct Scale {
private settings: RenderingContextSettings = new RenderingContextSettings(true)
private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
-
+
build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Canvas(this.context)
@@ -1570,35 +1773,38 @@ scale(x: number, y: number): void
### transform
-transform(scaleX: number, skewX: number, skewY: number, scaleY: number, translateX: number, translateY: number): void
+transform(a: number, b: number, c: number, d: number, e: number, f: number): void
transform方法对应一个变换矩阵,想对一个图形进行变化的时候,只要设置此变换矩阵相应的参数,对图形的各个定点的坐标分别乘以这个矩阵,就能得到新的定点的坐标。矩阵变换效果可叠加。
-> **说明:**
-> 变换后的坐标计算方式(x和y为变换前坐标,x'和y'为变换后坐标):
+> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
+> 变换后的坐标计算方式(x和y为变换前坐标,x'和y'为变换后坐标):
>
-> - x' = scaleX \* x + skewY \* y + translateX
+> - x' = scaleX \* x + skewY \* y + translateX
>
-> - y' = skewX \* x + scaleY \* y + translateY
+> - y' = skewX \* x + scaleY \* y + translateY
-**参数:**
-| 参数 | 类型 | 必填 | 默认值 | 描述 |
-| ---------- | ------ | ---- | ---- | -------- |
-| scaleX | number | 是 | 0 | 指定水平缩放值。 |
-| skewX | number | 是 | 0 | 指定水平倾斜值。 |
-| skewY | number | 是 | 0 | 指定垂直倾斜值。 |
-| scaleY | number | 是 | 0 | 指定垂直缩放值。 |
-| translateX | number | 是 | 0 | 指定水平移动值。 |
-| translateY | number | 是 | 0 | 指定垂直移动值。 |
+**参数:**
-**示例:**
- ```
+ | 参数 | 类型 | 必填 | 默认值 | 描述 |
+ | ---------- | ------ | ---- | ---- | -------- |
+ | a | number | 是 | 0 |scaleX: 指定水平缩放值。 |
+ | b | number | 是 | 0 |skewX: 指定水平倾斜值。 |
+ | c | number | 是 | 0 |skewY: 指定垂直倾斜值。 |
+ | d | number | 是 | 0 |scaleY: 指定垂直缩放值。 |
+ | e | number | 是 | 0 |translateX: 指定水平移动值。 |
+ | f | number | 是 | 0 |translateY: 指定垂直移动值。 |
+
+**示例:**
+
+ ```ts
+ // xxx.ets
@Entry
@Component
struct Transform {
private settings: RenderingContextSettings = new RenderingContextSettings(true)
private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
-
+
build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Canvas(this.context)
@@ -1627,28 +1833,31 @@ transform方法对应一个变换矩阵,想对一个图形进行变化的时
### setTransform
-setTransform(scaleX: number, skewX: number, skewY: number, scale: number, translateX: number, translateY: number): void
+setTransform(a: number, b: number, c: number, d: number, e: number, f: number): void
setTransfrom方法使用的参数和transform()方法相同,但setTransform()方法会重置现有的变换矩阵并创建新的变换矩阵。
-**参数:**
-| 参数 | 类型 | 必填 | 默认值 | 描述 |
-| ---------- | ------ | ---- | ---- | -------- |
-| scaleX | number | 是 | 0 | 指定水平缩放值。 |
-| skewX | number | 是 | 0 | 指定水平倾斜值。 |
-| skewY | number | 是 | 0 | 指定垂直倾斜值。 |
-| scaleY | number | 是 | 0 | 指定垂直缩放值。 |
-| translateX | number | 是 | 0 | 指定水平移动值。 |
-| translateY | number | 是 | 0 | 指定垂直移动值。 |
+**参数:**
-**示例:**
- ```
+ | 参数 | 类型 | 必填 | 默认值 | 描述 |
+ | ---------- | ------ | ---- | ---- | -------- |
+ | a | number | 是 | 0 |scaleX: 指定水平缩放值。 |
+ | b | number | 是 | 0 |skewX: 指定水平倾斜值。 |
+ | c | number | 是 | 0 |skewY: 指定垂直倾斜值。 |
+ | d | number | 是 | 0 |scaleY: 指定垂直缩放值。 |
+ | e | number | 是 | 0 |translateX: 指定水平移动值。 |
+ | f | number | 是 | 0 |translateY: 指定垂直移动值。 |
+
+**示例:**
+
+ ```ts
+ // xxx.ets
@Entry
@Component
struct SetTransform {
private settings: RenderingContextSettings = new RenderingContextSettings(true)
private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
-
+
build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Canvas(this.context)
@@ -1672,26 +1881,34 @@ setTransfrom方法使用的参数和transform()方法相同,但setTransform()
![zh-cn_image_0000001238712421](figures/zh-cn_image_0000001238712421.png)
+setTransform(transform?: Matrix2D): void
+
+以Matrix2D对象为模板重置现有的变换矩阵并创建新的变换矩阵。该接口为空接口。
+
+
### translate
translate(x: number, y: number): void
移动当前坐标系的原点。
-**参数:**
-| 参数 | 类型 | 必填 | 默认值 | 描述 |
-| ---- | ------ | ---- | ---- | -------- |
-| x | number | 是 | 0 | 设置水平平移量。 |
-| y | number | 是 | 0 | 设置竖直平移量。 |
+**参数:**
-**示例:**
- ```
+ | 参数 | 类型 | 必填 | 默认值 | 描述 |
+ | ---- | ------ | ---- | ---- | -------- |
+ | x | number | 是 | 0 | 设置水平平移量。 |
+ | y | number | 是 | 0 | 设置竖直平移量。 |
+
+**示例:**
+
+ ```ts
+ // xxx.ets
@Entry
@Component
struct Translate {
private settings: RenderingContextSettings = new RenderingContextSettings(true)
private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
-
+
build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Canvas(this.context)
@@ -1717,34 +1934,38 @@ translate(x: number, y: number): void
drawImage(image: ImageBitmap | PixelMap, dx: number, dy: number): void
-drawImage(image: ImageBitmap | PixelMap, dx: number, dy: number, dWidth: number, dHeight: number): void
+drawImage(image: ImageBitmap | PixelMap, dx: number, dy: number, dw: number, dh: number): void
-drawImage(image: ImageBitmap | PixelMap, sx: number, sy: number, sWidth: number, sHeight: number, dx: number, dy: number, dWidth: number, dHeight: number):void
+drawImage(image: ImageBitmap | PixelMap, sx: number, sy: number, sw: number, sh: number, dx: number, dy: number, dw: number, dh: number):void
进行图像绘制。
-**参数:**
-| 参数 | 类型 | 必填 | 默认值 | 描述 |
-| ------- | ---------------------------------------- | ---- | ---- | ---------------------------------------- |
-| image | [ImageBitmap](ts-components-canvas-imagebitmap.md)或[PixelMap](../apis/js-apis-image.md#pixelmap7) | 是 | null | 图片资源,请参考ImageBitmap或PixelMap。 |
-| sx | number | 否 | 0 | 裁切源图像时距离源图像左上角的x坐标值。 |
-| sy | number | 否 | 0 | 裁切源图像时距离源图像左上角的y坐标值。 |
-| sWidth | number | 否 | 0 | 裁切源图像时需要裁切的宽度。 |
-| sHeight | number | 否 | 0 | 裁切源图像时需要裁切的高度。 |
-| dx | number | 是 | 0 | 绘制区域左上角在x轴的位置。 |
-| dy | number | 是 | 0 | 绘制区域左上角在y 轴的位置。 |
-| dWidth | number | 否 | 0 | 绘制区域的宽度。 当绘制区域的宽度和裁剪图像的宽度不一致时,将图像宽度拉伸或压缩为绘制区域的宽度。 |
-| dHeight | number | 否 | 0 | 绘制区域的高度。 当绘制区域的高度和裁剪图像的高度不一致时,将图像高度拉伸或压缩为绘制区域的高度。 |
+**参数:**
+ | 参数 | 类型 | 必填 | 默认值 | 描述 |
+ | ------- | ---------------------------------------- | ---- | ---- | ---------------------------------------- |
+ | image | [ImageBitmap](ts-components-canvas-imagebitmap.md)或[PixelMap](../apis/js-apis-image.md#pixelmap7) | 是 | null | 图片资源,请参考ImageBitmap或PixelMap。 |
+ | sx | number | 否 | 0 | 裁切源图像时距离源图像左上角的x坐标值。 |
+ | sy | number | 否 | 0 | 裁切源图像时距离源图像左上角的y坐标值。 |
+ | sw | number | 否 | 0 | 裁切源图像时需要裁切的宽度。 |
+ | sh | number | 否 | 0 | 裁切源图像时需要裁切的高度。 |
+ | dx | number | 是 | 0 | 绘制区域左上角在x轴的位置。 |
+ | dy | number | 是 | 0 | 绘制区域左上角在y 轴的位置。 |
+ | dw | number | 否 | 0 | 绘制区域的宽度。当绘制区域的宽度和裁剪图像的宽度不一致时,将图像宽度拉伸或压缩为绘制区域的宽度。 |
+ | dh | number | 否 | 0 | 绘制区域的高度。当绘制区域的高度和裁剪图像的高度不一致时,将图像高度拉伸或压缩为绘制区域的高度。 |
-**示例:**
- ```
+
+**示例:**
+
+ ```ts
+ // xxx.ets
@Entry
@Component
struct ImageExample {
private settings: RenderingContextSettings = new RenderingContextSettings(true);
private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings);
private img:ImageBitmap = new ImageBitmap("common/images/example.jpg");
+
build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Canvas(this.context)
@@ -1766,79 +1987,257 @@ drawImage(image: ImageBitmap | PixelMap, sx: number, sy: number, sWidth: number,
### createImageData
-createImageData(width: number, height: number): Object
+createImageData(sw: number, sh: number): ImageData
创建新的ImageData 对象,请参考[ImageData](ts-components-canvas-imagebitmap.md)。
-**参数:**
-| 参数 | 类型 | 必填 | 默认 | 描述 |
-| ------ | ------ | ---- | ---- | ------------- |
-| width | number | 是 | 0 | ImageData的宽度。 |
-| height | number | 是 | 0 | ImageData的高度。 |
+**参数:**
+
+ | 参数 | 类型 | 必填 | 默认 | 描述 |
+ | ------ | ------ | ---- | ---- | ------------- |
+ | sw | number | 是 | 0 | ImageData的宽度。 |
+ | sh | number | 是 | 0 | ImageData的高度。 |
### createImageData
-createImageData(imageData: Object): Object
+createImageData(imageData: ImageData): ImageData
创建新的ImageData 对象,请参考[ImageData](ts-components-canvas-imagebitmap.md)。
-**参数:**
-| 参数 | 类型 | 必填 | 默认 | 描述 |
-| --------- | ------ | ---- | ---- | ----------------- |
-| imagedata | Object | 是 | null | 复制现有的ImageData对象。 |
+**参数:**
+
+ | 参数 | 类型 | 必填 | 默认 | 描述 |
+ | --------- | ------ | ---- | ---- | ----------------- |
+ | imagedata | [ImageData](ts-components-canvas-imagebitmap.md)| 是 | null | 复制现有的ImageData对象。 |
+
+ **返回值:**
+
+ | 类型 | 说明 |
+ | ---------- | ---------------------------------------- |
+ | [ImageData](ts-components-canvas-imagebitmap.md) | 新的ImageData对象。|
+
### getPixelMap
getPixelMap(sx: number, sy: number, sw: number, sh: number): PixelMap
以当前canvas指定区域内的像素创建[PixelMap](../apis/js-apis-image.md#pixelmap7)对象。
-**参数:**
-| 参数 | 类型 | 必填 | 默认值 | 描述 |
-| ---- | ------ | ---- | ---- | --------------- |
-| sx | number | 是 | 0 | 需要输出的区域的左上角x坐标。 |
-| sy | number | 是 | 0 | 需要输出的区域的左上角y坐标。 |
-| sw | number | 是 | 0 | 需要输出的区域的宽度。 |
-| sh | number | 是 | 0 | 需要输出的区域的高度。 |
+
+**参数:**
+
+ | 参数 | 类型 | 必填 | 默认值 | 描述 |
+ | ---- | ------ | ---- | ---- | --------------- |
+ | sx | number | 是 | 0 | 需要输出的区域的左上角x坐标。 |
+ | sy | number | 是 | 0 | 需要输出的区域的左上角y坐标。 |
+ | sw | number | 是 | 0 | 需要输出的区域的宽度。 |
+ | sh | number | 是 | 0 | 需要输出的区域的高度。 |
+
+**返回值:**
+
+ | 类型 | 说明 |
+ | ---------- | ---------------------------------------- |
+ | [PixelMap](../apis/js-apis-image.md#pixelmap7) | 新的PixelMap对象。 |
### getImageData
-getImageData(sx: number, sy: number, sw: number, sh: number): Object
+getImageData(sx: number, sy: number, sw: number, sh: number): ImageData
以当前canvas指定区域内的像素创建[ImageData](ts-components-canvas-imagebitmap.md)对象。
-**参数:**
-| 参数 | 类型 | 必填 | 默认值 | 描述 |
-| ---- | ------ | ---- | ---- | --------------- |
-| sx | number | 是 | 0 | 需要输出的区域的左上角x坐标。 |
-| sy | number | 是 | 0 | 需要输出的区域的左上角y坐标。 |
-| sw | number | 是 | 0 | 需要输出的区域的宽度。 |
-| sh | number | 是 | 0 | 需要输出的区域的高度。 |
+
+**参数:**
+
+ | 参数 | 类型 | 必填 | 默认值 | 描述 |
+ | ---- | ------ | ---- | ---- | --------------- |
+ | sx | number | 是 | 0 | 需要输出的区域的左上角x坐标。 |
+ | sy | number | 是 | 0 | 需要输出的区域的左上角y坐标。 |
+ | sw | number | 是 | 0 | 需要输出的区域的宽度。 |
+ | sh | number | 是 | 0 | 需要输出的区域的高度。 |
+
+ **返回值:**
+
+ | 类型 | 说明 |
+ | ---------- | ---------------------------------------- |
+ | [ImageData](ts-components-canvas-imagebitmap.md) | 新的ImageData对象。 |
### putImageData
-putImageData(imageData: Object, dx: number, dy: number, dirtyX?: number, dirtyY?: number, dirtyWidth?: number, dirtyHeight?: number): void
+putImageData(imageData: ImageData, dx: number, dy: number): void
+
+putImageData(imageData: ImageData, dx: number, dy: number, dirtyX: number, dirtyY: number, dirtyWidth: number, dirtyHeight: number): void
使用[ImageData](ts-components-canvas-imagebitmap.md)数据填充新的矩形区域。
+**参数:**
+
+ | 参数 | 类型 | 必填 | 默认值 | 描述 |
+ | ----------- | ------ | ---- | ------------ | ----------------------------- |
+ | imagedata | [ImageData](ts-components-canvas-imagebitmap.md) | 是 | null | 包含像素值的ImageData对象。 |
+ | dx | number | 是 | 0 | 填充区域在x轴方向的偏移量。 |
+ | dy | number | 是 | 0 | 填充区域在y轴方向的偏移量。 |
+ | dirtyX | number | 否 | 0 | 源图像数据矩形裁切范围左上角距离源图像左上角的x轴偏移量。 |
+ | dirtyY | number | 否 | 0 | 源图像数据矩形裁切范围左上角距离源图像左上角的y轴偏移量。 |
+ | dirtyWidth | number | 否 | imagedata的宽度 | 源图像数据矩形裁切范围的宽度。 |
+ | dirtyHeight | number | 否 | imagedata的高度 | 源图像数据矩形裁切范围的高度。 |
+
+**示例:**
+
+ ```ts
+ // xxx.ets
+ @Entry
+ @Component
+ struct PutImageData {
+ private settings: RenderingContextSettings = new RenderingContextSettings(true)
+ private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
+
+ build() {
+ Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
+ Canvas(this.context)
+ .width('100%')
+ .height('100%')
+ .backgroundColor('#ffff00')
+ .onReady(() =>{
+ var imageData = this.context.createImageData(100, 100)
+ for (var i = 0; i < imageData.data.length; i += 4) {
+ imageData.data[i + 0] = 255
+ imageData.data[i + 1] = 0
+ imageData.data[i + 2] = 255
+ imageData.data[i + 3] = 255
+ }
+ this.context.putImageData(imageData, 10, 10)
+ })
+ }
+ .width('100%')
+ .height('100%')
+ }
+ }
+ ```
+
+ ![zh-cn_image_0000001238952387](figures/zh-cn_image_0000001238952387.png)
+
+
+### setLineDash
+
+setLineDash(segments: number[]): void
+
+设置画布的虚线样式。
+
**参数:**
-| 参数 | 类型 | 必填 | 默认值 | 描述 |
-| ----------- | ------ | ---- | ------------ | ----------------------------- |
-| imagedata | Object | 是 | null | 包含像素值的ImageData对象。 |
-| dx | number | 是 | 0 | 填充区域在x轴方向的偏移量。 |
-| dy | number | 是 | 0 | 填充区域在y轴方向的偏移量。 |
-| dirtyX | number | 否 | 0 | 源图像数据矩形裁切范围左上角距离源图像左上角的x轴偏移量。 |
-| dirtyY | number | 否 | 0 | 源图像数据矩形裁切范围左上角距离源图像左上角的y轴偏移量。 |
-| dirtyWidth | number | 否 | imagedata的宽度 | 源图像数据矩形裁切范围的宽度。 |
-| dirtyHeight | number | 否 | imagedata的高度 | 源图像数据矩形裁切范围的高度。 |
+
+| 参数 | 类型 | 描述 |
+| -------- | ----- | -------------------- |
+| segments | number[] | 描述线段如何交替和线段间距长度的数组。 |
+
+**示例:**
+
+ ```ts
+ // xxx.ets
+ @Entry
+ @Component
+ struct SetLineDash {
+ private settings: RenderingContextSettings = new RenderingContextSettings(true)
+ private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
+
+ build() {
+ Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
+ Canvas(this.context)
+ .width('100%')
+ .height('100%')
+ .backgroundColor('#ffff00')
+ .onReady(() =>{
+ this.context.arc(100, 75, 50, 0, 6.28)
+ this.context.setLineDash([10,20])
+ })
+ }
+ .width('100%')
+ .height('100%')
+ }
+ }
+ ```
+
+ ![zh-cn_image_000000127777771](figures/zh-cn_image_000000127777771.png)
+
+
+### getLineDash
+
+getLineDash(): number[]
+
+获得当前画布的虚线样式。
+
+**返回值:**
+
+| 类型 | 说明 |
+| ----- | ------------------------ |
+| number[] | 返回数组,该数组用来描述线段如何交替和间距长度。 |
**示例:**
+
+ ```ts
+ // xxx.ets
+ @Entry
+ @Component
+ struct GetLineDash {
+ private settings: RenderingContextSettings = new RenderingContextSettings(true)
+ private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
+
+ build() {
+ Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
+ Canvas(this.context)
+ .width('100%')
+ .height('100%')
+ .backgroundColor('#ffff00')
+ .onReady(() =>{
+ var grad = this.context.createLinearGradient(50,0, 300,100)
+ this.context.arc(100, 75, 50, 0, 6.28)
+ this.context.setLineDash([10,20])
+ this.context.stroke();
+ let res = this.context.getLineDash()
+ })
+ }
+ .width('100%')
+ .height('100%')
+ }
+ }
```
+
+
+### imageSmoothingQuality
+
+imageSmoothingQuality(quality: imageSmoothingQuality)
+
+用于设置图像平滑度。该接口为空接口。
+
+ **参数:**
+
+| 参数 | 类型 | 描述 |
+| ------ | ----------- | ------------------ |
+| quality |imageSmoothingQuality | 支持如下三种类型:'low', 'medium', 'high'。 |
+
+
+
+### transferFromImageBitmap
+
+transferFromImageBitmap(bitmap: ImageBitmap): void
+
+显示给定的ImageBitmap对象。
+
+**参数:**
+
+| 参数 | 类型 | 描述 |
+| ------ | ----------- | ------------------ |
+| bitmap |[ImageData](ts-components-canvas-imagebitmap.md) | 待显示的ImageBitmap对象。 |
+
+**示例:**
+
+ ```ts
+ // xxx.ets
@Entry
@Component
struct PutImageData {
private settings: RenderingContextSettings = new RenderingContextSettings(true)
private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
+ private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings)
build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
@@ -1847,14 +2246,16 @@ putImageData(imageData: Object, dx: number, dy: number, dirtyX?: number, dirtyY?
.height('100%')
.backgroundColor('#ffff00')
.onReady(() =>{
- var imageData = this.context.createImageData(100, 100)
+ var imageData = this.offContext.createImageData(100, 100)
for (var i = 0; i < imageData.data.length; i += 4) {
imageData.data[i + 0] = 255
imageData.data[i + 1] = 0
imageData.data[i + 2] = 255
imageData.data[i + 3] = 255
}
- this.context.putImageData(imageData, 10, 10)
+ this.offContext.putImageData(imageData, 10, 10)
+ var image = this.offContext.transferToImageBitmap()
+ this.context.transferFromImageBitmap(image)
})
}
.width('100%')
@@ -1862,8 +2263,52 @@ putImageData(imageData: Object, dx: number, dy: number, dirtyX?: number, dirtyY?
}
}
```
+ ![zh-cn_image_000000127777773](figures/zh-cn_image_000000127777773.png)
- ![zh-cn_image_0000001238952387](figures/zh-cn_image_0000001238952387.png)
+### toDataURL
+
+toDataURL(type?: string, quality?: number): string
+
+生成一个包含图片展示的URL。
+
+**参数:**
+
+| 参数名 | 参数类型 | 必填 | 描述 |
+| ------- | ------ | ---- | ---------------------------------------- |
+| type | string | 否 | 可选参数,用于指定图像格式,默认格式为image/png。 |
+| quality | number | 否 | 在指定图片格式为image/jpeg或image/webp的情况下,可以从0到1的区间内选择图片的质量。如果超出取值范围,将会使用默认值0.92。 |
+
+**返回值:**
+
+| 类型 | 说明 |
+| ------ | --------- |
+| string | 图像的URL地址。 |
+
+**示例:**
+
+ ```ts
+ // xxx.ets
+@Entry
+@Component
+struct ToDataURL {
+ private settings: RenderingContextSettings = new RenderingContextSettings(true)
+ private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
+
+ build() {
+ Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
+ Canvas(this.context)
+ .width('100%')
+ .height('100%')
+ .backgroundColor('#ffff00')
+ .onReady(() =>{
+ var dataURL = this.context.toDataURL();
+ })
+ }
+ .width('100%')
+ .height('100%')
+ }
+}
+ ```
### restore
@@ -1872,14 +2317,17 @@ restore(): void
对保存的绘图上下文进行恢复。
-**示例:**
- ```
+**示例:**
+
+ ```ts
+ // xxx.ets
@Entry
@Component
struct CanvasExample {
private settings: RenderingContextSettings = new RenderingContextSettings(true)
private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
-
+ private img:ImageBitmap = new ImageBitmap("common/images/icon.jpg")
+
build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Canvas(this.context)
@@ -1901,16 +2349,18 @@ restore(): void
save(): void
-对当前的绘图上下文进行保存。
+将当前状态放入栈中,保存canvas的全部状态,通常在需要保存绘制状态时调用。
-**示例:**
- ```
+**示例:**
+
+ ```ts
+ // xxx.ets
@Entry
@Component
struct CanvasExample {
private settings: RenderingContextSettings = new RenderingContextSettings(true)
private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
-
+
build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Canvas(this.context)
@@ -1934,16 +2384,19 @@ createLinearGradient(x0: number, y0: number, x1: number, y1: number): void
创建一个线性渐变色。
-**参数:**
-| 参数 | 类型 | 必填 | 默认值 | 描述 |
-| ---- | ------ | ---- | ---- | -------- |
-| x0 | number | 是 | 0 | 起点的x轴坐标。 |
-| y0 | number | 是 | 0 | 起点的y轴坐标。 |
-| x1 | number | 是 | 0 | 终点的x轴坐标。 |
-| y1 | number | 是 | 0 | 终点的y轴坐标。 |
+**参数:**
-**示例:**
- ```
+ | 参数 | 类型 | 必填 | 默认值 | 描述 |
+ | ---- | ------ | ---- | ---- | -------- |
+ | x0 | number | 是 | 0 | 起点的x轴坐标。 |
+ | y0 | number | 是 | 0 | 起点的y轴坐标。 |
+ | x1 | number | 是 | 0 | 终点的x轴坐标。 |
+ | y1 | number | 是 | 0 | 终点的y轴坐标。 |
+
+**示例:**
+
+ ```ts
+ // xxx.ets
@Entry
@Component
struct CreateLinearGradient {
@@ -1980,18 +2433,21 @@ createRadialGradient(x0: number, y0: number, r0: number, x1: number, y1: number,
创建一个径向渐变色。
-**参数:**
-| 参数 | 类型 | 必填 | 默认值 | 描述 |
-| ---- | ------ | ---- | ---- | ----------------- |
-| x0 | number | 是 | 0 | 起始圆的x轴坐标。 |
-| y0 | number | 是 | 0 | 起始圆的y轴坐标。 |
-| r0 | number | 是 | 0 | 起始圆的半径。必须是非负且有限的。 |
-| x1 | number | 是 | 0 | 终点圆的x轴坐标。 |
-| y1 | number | 是 | 0 | 终点圆的y轴坐标。 |
-| r1 | number | 是 | 0 | 终点圆的半径。必须为非负且有限的。 |
+**参数:**
-**示例:**
- ```
+ | 参数 | 类型 | 必填 | 默认值 | 描述 |
+ | ---- | ------ | ---- | ---- | ----------------- |
+ | x0 | number | 是 | 0 | 起始圆的x轴坐标。 |
+ | y0 | number | 是 | 0 | 起始圆的y轴坐标。 |
+ | r0 | number | 是 | 0 | 起始圆的半径。必须是非负且有限的。 |
+ | x1 | number | 是 | 0 | 终点圆的x轴坐标。 |
+ | y1 | number | 是 | 0 | 终点圆的y轴坐标。 |
+ | r1 | number | 是 | 0 | 终点圆的半径。必须为非负且有限的。 |
+
+**示例:**
+
+ ```ts
+ // xxx.ets
@Entry
@Component
struct CreateRadialGradient {
diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-components-canvas-canvas.md b/zh-cn/application-dev/reference/arkui-ts/ts-components-canvas-canvas.md
index 32a14b8bc4e168b013a9f8380f68e43c1cb56231..e74488c562835c6153ba7e8127e8f27a44cdb25d 100644
--- a/zh-cn/application-dev/reference/arkui-ts/ts-components-canvas-canvas.md
+++ b/zh-cn/application-dev/reference/arkui-ts/ts-components-canvas-canvas.md
@@ -1,8 +1,6 @@
# Canvas
-> **说明:**
->
-> 该组件从API Version 8开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
+> **说明:** 该组件从API Version 8开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
提供画布组件,用于自定义绘制图形。
@@ -16,13 +14,13 @@
## 接口
-Canvas(context: CanvasRenderingContext2D)
+Canvas(context?: CanvasRenderingContext2D)
**参数:**
-| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 |
-| ------- | ---------------------------------------- | ---- | ---- | ---------------------------- |
-| context | [CanvasRenderingContext2D](ts-canvasrenderingcontext2d.md) | 是 | - | 见CanvasRenderingContext2D对象。 |
+ | 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 |
+ | ------- | ---------------------------------------- | ---- | ---- | ---------------------------- |
+ | context | [CanvasRenderingContext2D](ts-canvasrenderingcontext2d.md) | 否 | - | 见CanvasRenderingContext2D对象。 |
## 属性
@@ -34,7 +32,7 @@ Canvas(context: CanvasRenderingContext2D)
| 名称 | 参数 | 描述 |
| ----------------------------- | ---- | -------------------- |
-| onReady(callback: () => void) | 无 | 画布组件的事件回调,可以在此时进行绘制。 |
+| onReady(event: () => void) | 无 | 画布组件的事件回调,可以在此时进行绘制。 |
## 示例
diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-components-canvas-imagebitmap.md b/zh-cn/application-dev/reference/arkui-ts/ts-components-canvas-imagebitmap.md
index 503f356cdfb8a25f2fd707d7f910198f409a4322..e2f3f510bef985abf5c868223bf71f477219ea80 100644
--- a/zh-cn/application-dev/reference/arkui-ts/ts-components-canvas-imagebitmap.md
+++ b/zh-cn/application-dev/reference/arkui-ts/ts-components-canvas-imagebitmap.md
@@ -1,17 +1,25 @@
# ImageBitmap对象
> **说明:**
->
-> 从 API Version 8 开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
+> 从 API Version 8 开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
-CanvasImageData对象可以存储canvas渲染的像素数据。
+ImageBitmap对象可以存储canvas渲染的像素数据。
## 属性
-| 属性 | 类型 | 描述 |
-| ------ | ------------------------- | ---------------------------- |
-| width | number | 矩形区域实际像素宽度。 |
-| height | number | 矩形区域实际像素高度。 |
-| data | <Uint8ClampedArray> | 一维数组,保存了相应的颜色数据,数据值范围为0到255。 |
+| 属性 | 类型 | 描述 |
+| -------- | -------- | -------- |
+| width | number | ImageBitmap的像素宽度。 |
+| height | number | ImageBitmap的像素高度。 |
+
+
+## 方法
+
+
+### close
+
+close()
+
+释放ImageBitmap对象相关联的所有图形资源。该接口为空接口。
\ No newline at end of file
diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-components-canvas-imagedata.md b/zh-cn/application-dev/reference/arkui-ts/ts-components-canvas-imagedata.md
index 7a0306444c98c9e9f42f4d966d7515813c554bc5..d1df7c7a5ec2294b75c43ee390e0cfb3ccfad0ff 100644
--- a/zh-cn/application-dev/reference/arkui-ts/ts-components-canvas-imagedata.md
+++ b/zh-cn/application-dev/reference/arkui-ts/ts-components-canvas-imagedata.md
@@ -1,8 +1,7 @@
# ImageData对象
> **说明:**
->
-> 从 API Version 8 开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
+> 从 API Version 8 开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
ImageData对象可以存储canvas渲染的像素数据。
@@ -10,8 +9,9 @@ ImageData对象可以存储canvas渲染的像素数据。
## 属性
-| 属性 | 类型 | 描述 |
-| ------ | ------------------------- | ---------------------------- |
-| width | number | 矩形区域实际像素宽度。 |
-| height | number | 矩形区域实际像素高度。 |
-| data | <Uint8ClampedArray> | 一维数组,保存了相应的颜色数据,数据值范围为0到255。 |
+| 属性 | 类型 | 描述 |
+| -------- | -------- | -------- |
+| width | number | 矩形区域实际像素宽度。 |
+| height | number | 矩形区域实际像素高度。 |
+| data | Uint8ClampedArray | 一维数组,保存了相应的颜色数据,数据值范围为0到255。 |
+
diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-components-canvas-path2d.md b/zh-cn/application-dev/reference/arkui-ts/ts-components-canvas-path2d.md
index e457d286728476cdd8a566903c5622843104270f..63004c2e78848e356e474a5ee4b38d13f6162c66 100644
--- a/zh-cn/application-dev/reference/arkui-ts/ts-components-canvas-path2d.md
+++ b/zh-cn/application-dev/reference/arkui-ts/ts-components-canvas-path2d.md
@@ -1,8 +1,7 @@
# Path2D对象
> **说明:**
->
-> 从 API Version 8 开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
+> 从 API Version 8 开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
路径对象,支持通过对象的接口进行路径的描述,并通过Canvas的stroke接口进行绘制。
@@ -10,26 +9,31 @@
## addPath
-addPath(path: Object): void
+addPath(path: path2D, transform?:Matrix2D): void
将另一个路径添加到当前的路径对象中。
-- 参数
- | 参数 | 类型 | 必填 | 默认值 | 描述 |
- | ---- | ------ | ---- | ---- | -------------- |
- | path | Object | 是 | null | 需要添加到当前路径的路径对象 |
+**参数:**
-- 示例
- ```
+ | 参数 | 类型 | 必填 | 默认值 | 描述 |
+ | -------- | -------- | -------- | -------- | -------- |
+ | path | path2D | 是 | - | 需要添加到当前路径的路径对象。|
+ | transform | Matrix2D | 否 | null | 新增路径的变换矩阵对象。 |
+
+
+**示例:**
+
+ ```ts
+ // xxx.ets
@Entry
@Component
struct AddPath {
private settings: RenderingContextSettings = new RenderingContextSettings(true)
private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
-
+
private path2Da: Path2D = new Path2D("M250 150 L150 350 L350 350 Z")
private path2Db: Path2D = new Path2D()
-
+
build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Canvas(this.context)
@@ -56,15 +60,17 @@ closePath(): void
将路径的当前点移回到路径的起点,当前点到起点间画一条直线。如果形状已经闭合或只有一个点,则此功能不执行任何操作。
-- 示例
- ```
+**示例:**
+
+ ```ts
+ // xxx.ets
@Entry
@Component
struct ClosePath {
private settings: RenderingContextSettings = new RenderingContextSettings(true)
private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
private path2Db: Path2D = new Path2D()
-
+
build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Canvas(this.context)
@@ -94,21 +100,24 @@ moveTo(x: number, y: number): void
将路径的当前坐标点移动到目标点,移动过程中不绘制线条。
-- 参数
- | 参数 | 类型 | 必填 | 默认值 | 描述 |
- | ---- | ------ | ---- | ---- | ------- |
- | x | number | 是 | 0 | 目标点X轴坐标 |
- | y | number | 是 | 0 | 目标点Y轴坐标 |
+**参数:**
-- 示例
- ```
+ | 参数 | 类型 | 必填 | 默认值 | 描述 |
+ | -------- | -------- | -------- | -------- | -------- |
+ | x | number | 是 | 0 | 目标点X轴坐标。 |
+ | y | number | 是 | 0 | 目标点Y轴坐标。 |
+
+**示例:**
+
+ ```ts
+ // xxx.ets
@Entry
@Component
struct MoveTo {
private settings: RenderingContextSettings = new RenderingContextSettings(true)
private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
private path2Db: Path2D = new Path2D()
-
+
build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Canvas(this.context)
@@ -138,21 +147,24 @@ lineTo(x: number, y: number): void
从当前点绘制一条直线到目标点。
-- 参数
- | 参数 | 类型 | 必填 | 默认值 | 描述 |
- | ---- | ------ | ---- | ---- | ------- |
- | x | number | 是 | 0 | 目标点X轴坐标 |
- | y | number | 是 | 0 | 目标点Y轴坐标 |
+**参数:**
-- 示例
- ```
+ | 参数 | 类型 | 必填 | 默认值 | 描述 |
+ | -------- | -------- | -------- | -------- | -------- |
+ | x | number | 是 | 0 | 目标点X轴坐标。 |
+ | y | number | 是 | 0 | 目标点Y轴坐标。 |
+
+**示例:**
+
+ ```ts
+ // xxx.ets
@Entry
@Component
struct LineTo {
private settings: RenderingContextSettings = new RenderingContextSettings(true)
private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
private path2Db: Path2D = new Path2D()
-
+
build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Canvas(this.context)
@@ -183,25 +195,28 @@ bezierCurveTo(cp1x: number, cp1y: number, cp2x: number, cp2y: number, x: number,
创建三次贝赛尔曲线的路径。
-- 参数
- | 参数 | 类型 | 必填 | 默认值 | 描述 |
- | ---- | ------ | ---- | ---- | -------------- |
- | cp1x | number | 是 | 0 | 第一个贝塞尔参数的x坐标值。 |
- | cp1y | number | 是 | 0 | 第一个贝塞尔参数的y坐标值。 |
- | cp2x | number | 是 | 0 | 第二个贝塞尔参数的x坐标值。 |
- | cp2y | number | 是 | 0 | 第二个贝塞尔参数的y坐标值。 |
- | x | number | 是 | 0 | 路径结束时的x坐标值。 |
- | y | number | 是 | 0 | 路径结束时的y坐标值。 |
-
-- 示例
- ```
+**参数:**
+
+ | 参数 | 类型 | 必填 | 默认值 | 描述 |
+ | -------- | -------- | -------- | -------- | -------- |
+ | cp1x | number | 是 | 0 | 第一个贝塞尔参数的x坐标值。 |
+ | cp1y | number | 是 | 0 | 第一个贝塞尔参数的y坐标值。 |
+ | cp2x | number | 是 | 0 | 第二个贝塞尔参数的x坐标值。 |
+ | cp2y | number | 是 | 0 | 第二个贝塞尔参数的y坐标值。 |
+ | x | number | 是 | 0 | 路径结束时的x坐标值。 |
+ | y | number | 是 | 0 | 路径结束时的y坐标值。 |
+
+**示例:**
+
+ ```ts
+ // xxx.ets
@Entry
@Component
struct BezierCurveTo {
private settings: RenderingContextSettings = new RenderingContextSettings(true)
private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
private path2Db: Path2D = new Path2D()
-
+
build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Canvas(this.context)
@@ -228,23 +243,26 @@ quadraticCurveTo(cpx: number, cpy: number, x: number ,y: number): void
创建二次贝赛尔曲线的路径。
-- 参数
- | 参数 | 类型 | 必填 | 默认值 | 描述 |
- | ---- | ------ | ---- | ---- | ----------- |
- | cpx | number | 是 | 0 | 贝塞尔参数的x坐标值。 |
- | cpy | number | 是 | 0 | 贝塞尔参数的y坐标值。 |
- | x | number | 是 | 0 | 路径结束时的x坐标值。 |
- | y | number | 是 | 0 | 路径结束时的y坐标值。 |
+**参数:**
-- 示例
- ```
+ | 参数 | 类型 | 必填 | 默认值 | 描述 |
+ | -------- | -------- | -------- | -------- | -------- |
+ | cpx | number | 是 | 0 | 贝塞尔参数的x坐标值。 |
+ | cpy | number | 是 | 0 | 贝塞尔参数的y坐标值。 |
+ | x | number | 是 | 0 | 路径结束时的x坐标值。 |
+ | y | number | 是 | 0 | 路径结束时的y坐标值。 |
+
+**示例:**
+
+ ```ts
+ // xxx.ets
@Entry
@Component
struct QuadraticCurveTo {
private settings: RenderingContextSettings = new RenderingContextSettings(true)
private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
private path2Db: Path2D = new Path2D()
-
+
build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Canvas(this.context)
@@ -268,29 +286,32 @@ quadraticCurveTo(cpx: number, cpy: number, x: number ,y: number): void
## arc
-arc(x: number, y: number, radius: number, startAngle: number, endAngle: number, anticlockwise?: boolean): void
+arc(x: number, y: number, radius: number, startAngle: number, endAngle: number, counterclockwise?: boolean): void
绘制弧线路径。
-- 参数
- | 参数 | 类型 | 必填 | 默认值 | 描述 |
- | ------------- | ------- | ---- | ----- | ---------- |
- | x | number | 是 | 0 | 弧线圆心的x坐标值。 |
- | y | number | 是 | 0 | 弧线圆心的y坐标值。 |
- | radius | number | 是 | 0 | 弧线的圆半径。 |
- | startAngle | number | 是 | 0 | 弧线的起始弧度。 |
- | endAngle | number | 是 | 0 | 弧线的终止弧度。 |
- | anticlockwise | boolean | 否 | false | 是否逆时针绘制圆弧。 |
-
-- 示例
- ```
+**参数:**
+
+ | 参数 | 类型 | 必填 | 默认值 | 描述 |
+ | -------- | -------- | -------- | -------- | -------- |
+ | x | number | 是 | 0 | 弧线圆心的x坐标值。 |
+ | y | number | 是 | 0 | 弧线圆心的y坐标值。 |
+ | radius | number | 是 | 0 | 弧线的圆半径。 |
+ | startAngle | number | 是 | 0 | 弧线的起始弧度。 |
+ | endAngle | number | 是 | 0 | 弧线的终止弧度。 |
+ | counterclockwise | boolean | 否 | false | 是否逆时针绘制圆弧。 |
+
+**示例:**
+
+ ```ts
+ // xxx.ets
@Entry
@Component
struct Arc {
private settings: RenderingContextSettings = new RenderingContextSettings(true)
private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
private path2Db: Path2D = new Path2D()
-
+
build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Canvas(this.context)
@@ -316,24 +337,27 @@ arcTo(x1: number, y1: number, x2: number, y2: number, radius: number): void
依据圆弧经过的点和圆弧半径创建圆弧路径。
-- 参数
- | 参数 | 类型 | 必填 | 默认值 | 描述 |
- | ------ | ------ | ---- | ---- | --------------- |
- | x1 | number | 是 | 0 | 圆弧经过的第一个点的x坐标值。 |
- | y1 | number | 是 | 0 | 圆弧经过的第一个点的y坐标值。 |
- | x2 | number | 是 | 0 | 圆弧经过的第二个点的x坐标值。 |
- | y2 | number | 是 | 0 | 圆弧经过的第二个点的y坐标值。 |
- | radius | number | 是 | 0 | 圆弧的圆半径值。 |
+**参数:**
-- 示例
- ```
+ | 参数 | 类型 | 必填 | 默认值 | 描述 |
+ | -------- | -------- | -------- | -------- | -------- |
+ | x1 | number | 是 | 0 | 圆弧经过的第一个点的x坐标值。 |
+ | y1 | number | 是 | 0 | 圆弧经过的第一个点的y坐标值。 |
+ | x2 | number | 是 | 0 | 圆弧经过的第二个点的x坐标值。 |
+ | y2 | number | 是 | 0 | 圆弧经过的第二个点的y坐标值。 |
+ | radius | number | 是 | 0 | 圆弧的圆半径值。 |
+
+**示例:**
+
+ ```ts
+ // xxx.ets
@Entry
@Component
struct ArcTo {
private settings: RenderingContextSettings = new RenderingContextSettings(true)
private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
private path2Db: Path2D = new Path2D()
-
+
build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Canvas(this.context)
@@ -356,31 +380,34 @@ arcTo(x1: number, y1: number, x2: number, y2: number, radius: number): void
## ellipse
-ellipse(x: number, y: number, radiusX: number, radiusY: number, rotation: number, startAngle: number, endAngle: number, anticlockwise?: number): void
+ellipse(x: number, y: number, radiusX: number, radiusY: number, rotation: number, startAngle: number, endAngle: number, counterclockwise?: number): void
在规定的矩形区域绘制一个椭圆。
-- 参数
- | 参数 | 类型 | 必填 | 默认值 | 描述 |
- | ------------- | ------ | ---- | ---- | ------------------------------------ |
- | x | number | 是 | 0 | 椭圆圆心的x轴坐标。 |
- | y | number | 是 | 0 | 椭圆圆心的y轴坐标。 |
- | radiusX | number | 是 | 0 | 椭圆x轴的半径长度。 |
- | radiusY | number | 是 | 0 | 椭圆y轴的半径长度。 |
- | rotation | number | 是 | 0 | 椭圆的旋转角度,单位为弧度。 |
- | startAngle | number | 是 | 0 | 椭圆绘制的起始点角度,以弧度表示。 |
- | endAngle | number | 是 | 0 | 椭圆绘制的结束点角度,以弧度表示。 |
- | anticlockwise | number | 否 | 0 | 是否以逆时针方向绘制椭圆,0为顺时针,1为逆时针。(可选参数,默认为0) |
-
-- 示例
- ```
+**参数:**
+
+ | 参数 | 类型 | 必填 | 默认值 | 描述 |
+ | -------- | -------- | -------- | -------- | -------- |
+ | x | number | 是 | 0 | 椭圆圆心的x轴坐标。 |
+ | y | number | 是 | 0 | 椭圆圆心的y轴坐标。 |
+ | radiusX | number | 是 | 0 | 椭圆x轴的半径长度。 |
+ | radiusY | number | 是 | 0 | 椭圆y轴的半径长度。 |
+ | rotation | number | 是 | 0 | 椭圆的旋转角度,单位为弧度。 |
+ | startAngle | number | 是 | 0 | 椭圆绘制的起始点角度,以弧度表示。 |
+ | endAngle | number | 是 | 0 | 椭圆绘制的结束点角度,以弧度表示。 |
+ | counterclockwise | number | 否 | 0 | 是否以逆时针方向绘制椭圆,0为顺时针,1为逆时针。(可选参数,默认为0) |
+
+**示例:**
+
+ ```ts
+ // xxx.ets
@Entry
@Component
struct CanvasExample {
private settings: RenderingContextSettings = new RenderingContextSettings(true)
private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
private path2Db: Path2D = new Path2D()
-
+
build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Canvas(this.context)
@@ -403,27 +430,30 @@ ellipse(x: number, y: number, radiusX: number, radiusY: number, rotation: number
## rect
-rect(x: number, y: number, width: number, height: number): void
+rect(x: number, y: number, w: number, h: number): void
创建矩形路径。
-- 参数
- | 参数 | 类型 | 必填 | 默认值 | 描述 |
- | ------ | ------ | ---- | ---- | ------------- |
- | x | number | 是 | 0 | 指定矩形的左上角x坐标值。 |
- | y | number | 是 | 0 | 指定矩形的左上角y坐标值。 |
- | width | number | 是 | 0 | 指定矩形的宽度。 |
- | height | number | 是 | 0 | 指定矩形的高度。 |
+**参数:**
-- 示例
- ```
+ | 参数 | 类型 | 必填 | 默认值 | 描述 |
+ | -------- | -------- | -------- | -------- | -------- |
+ | x | number | 是 | 0 | 指定矩形的左上角x坐标值。 |
+ | y | number | 是 | 0 | 指定矩形的左上角y坐标值。 |
+ | w | number | 是 | 0 | 指定矩形的宽度。 |
+ | h | number | 是 | 0 | 指定矩形的高度。 |
+
+**示例:**
+
+ ```ts
+ // xxx.ets
@Entry
@Component
struct CanvasExample {
private settings: RenderingContextSettings = new RenderingContextSettings(true)
private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
private path2Db: Path2D = new Path2D()
-
+
build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Canvas(this.context)
diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-drawing-components-circle.md b/zh-cn/application-dev/reference/arkui-ts/ts-drawing-components-circle.md
index c9883c3e88261d2626e10e20a8f6f44f066d664c..6a9f1a8f1ee8e78ea521df05e11b5f0b697b4372 100644
--- a/zh-cn/application-dev/reference/arkui-ts/ts-drawing-components-circle.md
+++ b/zh-cn/application-dev/reference/arkui-ts/ts-drawing-components-circle.md
@@ -19,21 +19,32 @@
## 接口
-Circle(value?: {width: string | number, height: string | number})
+Circle(options?: {width?: string | number, height?: string | number})
-**参数:**
+- 参数
+ | 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 |
+ | -------- | -------- | -------- | -------- | -------- |
+ | width | string \| number | 否 | 0 | 宽度。 |
+ | height | string \| number | 否 | 0 | 高度。 |
-| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 |
-| ------ | -------------------------- | ---- | ------ | -------- |
-| width | string \| number | 是 | - | 宽度。 |
-| height | string \| number | 是 | - | 高度。 |
## 属性
-| 参数名称 | 参数类型 | 默认值 | 必填 | 参数描述 |
-| -------- | -------- | ------ | ---- | ------------------ |
-| width | Length | 0 | 否 | 圆所在矩形的宽度。 |
-| height | Length | 0 | 否 | 圆所在矩形的高度。 |
+除支持[通用属性](ts-universal-attributes-size.md)外,还支持以下属性:
+
+| 参数名称 | 参数类型 | 默认值 | 必填 | 参数描述 |
+| -------- | -------- | -------- | -------- | -------- |
+| fill | [ResourceColor](../../ui/ts-types.md) | Color.Black | 否 | 设置填充区域颜色。 |
+| fillOpacity | number \| string \| [Resource](../../ui/ts-types.md#resource类型) | 1 | 否 | 设置填充区域透明度。 |
+| stroke | [ResourceColor](../../ui/ts-types.md) | Color.Black | 否 | 设置线条颜色。 |
+| strokeDashArray | Array<Length> | [] | 否 | 设置线条间隙。 |
+| strokeDashOffset | number \| string | 0 | 否 | 线条绘制起点的偏移量。 |
+| strokeLineCap | [LineCapStyle](ts-appendix-enums.md#linecapstyle) | LineCapStyle.Butt | 否 | 设置线条端点绘制样式。 |
+| strokeLineJoin | [LineJoinStyle](ts-appendix-enums.md#linejoinstyle) | LineJoinStyle.Miter | 否 | 设置线条拐角绘制样式。 |
+| strokeMiterLimit | number \| string | 4 | 否 | 设置锐角绘制成斜角的极限值。 |
+| strokeOpacity | number \| string \| [Resource](../../ui/ts-types.md#resource类型) | 1 | 否 | 设置线条透明度。 |
+| strokeWidth | Length | 1 | 否 | 设置线条宽度。 |
+| antiAlias | boolean | true | 否 | 是否开启抗锯齿效果。 |
## 示例
diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-drawing-components-ellipse.md b/zh-cn/application-dev/reference/arkui-ts/ts-drawing-components-ellipse.md
index 8bd5b9e6a42a870e5685abb223235498460b73d4..fc57ec26d00126bf70d81ef531589a5dabcb43f5 100644
--- a/zh-cn/application-dev/reference/arkui-ts/ts-drawing-components-ellipse.md
+++ b/zh-cn/application-dev/reference/arkui-ts/ts-drawing-components-ellipse.md
@@ -20,21 +20,32 @@
## 接口
-Ellipse(value?: {width: string | number, height: string | number})
+ellipse(options?: {width?: string | number, height?: string | number})
-**参数:**
+- 参数
+ | 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 |
+ | -------- | -------- | -------- | -------- | -------- |
+ | width | string \| number | 否 | 0 | 宽度。 |
+ | height | string \| number | 否 | 0 | 高度。 |
-| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 |
-| ------ | -------------------------- | ---- | ------ | -------- |
-| width | string \| number | 是 | - | 宽度。 |
-| height | string \| number | 是 | - | 高度。 |
## 属性
-| 参数名称 | 参数类型 | 默认值 | 必填 | 参数描述 |
-| -------- | -------- | ------ | ---- | -------------------- |
-| width | Length | 0 | 否 | 椭圆所在矩形的宽度。 |
-| height | Length | 0 | 否 | 椭圆所在矩形的高度。 |
+除支持[通用属性](ts-universal-attributes-size.md)外,还支持以下属性:
+
+| 参数名称 | 参数类型 | 默认值 | 必填 | 参数描述 |
+| -------- | -------- | -------- | -------- | -------- |
+| fill | [ResourceColor](../../ui/ts-types.md) | Color.Black | 否 | 设置填充区域颜色。 |
+| fillOpacity | number \| string \| [Resource](../../ui/ts-types.md#resource类型) | 1 | 否 | 设置填充区域透明度。 |
+| stroke | [ResourceColor](../../ui/ts-types.md) | Color.Black | 否 |设置线条颜色。 |
+| strokeDashArray | Array<Length> | [] | 否 | 设置线条间隙。 |
+| strokeDashOffset | number \| string | 0 | 否 | 线条绘制起点的偏移量。 |
+| strokeLineCap | [LineCapStyle](ts-appendix-enums.md#linecapstyle) | LineCapStyle.Butt | 否 | 设置线条端点绘制样式。 |
+| strokeLineJoin | [LineJoinStyle](ts-appendix-enums.md#linejoinstyle) | LineJoinStyle.Miter | 否 | 设置线条拐角绘制样式。 |
+| strokeMiterLimit | number \| string | 4 | 否 | 设置锐角绘制成斜角的极限值。 |
+| strokeOpacity | number \| string \| [Resource](../../ui/ts-types.md#resource类型) | 1 | 否 | 设置线条透明度。 |
+| strokeWidth | Length | 1 | 否 | 设置线条宽度。 |
+| antiAlias | boolean | true | 否 | 是否开启抗锯齿效果。 |
## 示例
diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-drawing-components-line.md b/zh-cn/application-dev/reference/arkui-ts/ts-drawing-components-line.md
index 54f78ab10a643a4773e19ee14ad645750a93ce0b..cc7e767ef5e05905bcbccc945dd6a8b267dc637e 100644
--- a/zh-cn/application-dev/reference/arkui-ts/ts-drawing-components-line.md
+++ b/zh-cn/application-dev/reference/arkui-ts/ts-drawing-components-line.md
@@ -19,23 +19,34 @@
## 接口
-Line(value?: {width: string | number, height: string | number})
+Line(options?: {width?: string | number, height?: string | number})
-**参数:**
+- 参数
+ | 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 |
+ | -------- | -------- | -------- | -------- | -------- |
+ | width | string \| number | 否 | 0 | 宽度。 |
+ | height | string \| number | 否 | 0 | 高度。 |
-| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 |
-| ------ | -------------------------- | ---- | ------ | -------- |
-| width | string \| number | 是 | - | 宽度。 |
-| height | string \| number | 是 | - | 高度。 |
## 属性
-| 参数名称 | 参数类型 | 默认值 | 必填 | 参数描述 |
-| ---------- | ------------- | ----------- | ---- | ------------------------ |
-| width | [Length](ts-types.md#length) | 0 | 否 | 直线所在矩形的宽度。 |
-| height | [Length](ts-types.md#length) | 0 | 否 | 直线所在矩形的高度。 |
+除支持[通用属性](ts-universal-attributes-size.md)外,还支持以下属性:
+
+| 参数名称 | 参数类型 | 默认值 | 必填 | 参数描述 |
+| -------- | -------- | -------- | -------- | -------- |
| startPoint | Array | [0, 0] | 是 | 直线起点坐标点(相对坐标)。 |
| endPoint | Array | [0, 0] | 是 | 直线终点坐标点(相对坐标)。 |
+| fill | [ResourceColor](../../ui/ts-types.md) | Color.Black | 否 | 设置填充区域颜色。 |
+| fillOpacity | number \| string \| [Resource](../../ui/ts-types.md#resource类型) | 1 | 否 | 设置填充区域透明度。 |
+| stroke | [ResourceColor](../../ui/ts-types.md) | Color.Black | 否 | 设置线条颜色。 |
+| strokeDashArray | Array<Length> | [] | 否 | 设置线条间隙。 |
+| strokeDashOffset | number \| string | 0 | 否 | 线条绘制起点的偏移量。 |
+| strokeLineCap | [LineCapStyle](ts-appendix-enums.md#linecapstyle) | LineCapStyle.Butt | 否 | 设置线条端点绘制样式。 |
+| strokeLineJoin | [LineJoinStyle](ts-appendix-enums.md#linejoinstyle) | LineJoinStyle.Miter | 否 | 设置线条拐角绘制样式。 |
+| strokeMiterLimit | number \| string | 4 | 否 | 设置锐角绘制成斜角的极限值。 |
+| strokeOpacity | number \| string \| [Resource](../../ui/ts-types.md#resource类型) | 1 | 否 | 设置线条透明度。 |
+| strokeWidth | Length | 1 | 否 | 设置线条宽度。 |
+| antiAlias | boolean | true | 否 | 是否开启抗锯齿效果。 |
## 示例
diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-drawing-components-path.md b/zh-cn/application-dev/reference/arkui-ts/ts-drawing-components-path.md
index 1846c4a63257deb3cd99566af1baf231b2b43e2e..9ad93694d6b5feb317d6d014e733e51344eb5737 100644
--- a/zh-cn/application-dev/reference/arkui-ts/ts-drawing-components-path.md
+++ b/zh-cn/application-dev/reference/arkui-ts/ts-drawing-components-path.md
@@ -14,50 +14,54 @@
## 接口
-Path(value?: { width?: number | string, height?: number | string, commands?: string })
+Path(value?: { width?: number | string; height?: number | string; commands?: string })
-**参数:**
+- 参数
-| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 |
-| -------- | ---------------- | ---- | ---- | ----------- |
-| width | number \| string | 否 | 0 | 路径所在矩形的宽度。 |
-| height | number \| string | 否 | 0 | 路径所在矩形的高度。 |
-| commands | string | 否 | '' | 路径绘制的命令字符串。 |
+ | 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 |
+ | -------- | -------- | ---- | ------ | -------------------- |
+ | width | number \| string | 否 | 0 | 路径所在矩形的宽度 |
+ | height | number \| string | 否 | 0 | 路径所在矩形的高度 |
+ | commands | string | 否 | '' | 路径绘制的命令字符串 |
-## 属性
-
-| 参数名称 | 参数类型 | 默认值 | 必填 | 参数描述 |
-| -------- | --------------------------------------- | ------ | ---- | ------------------------ |
-| width | [Length](../../ui/ts-types.md#长度类型) | 0 | 否 | 路径所在矩形画布的宽度。 |
-| height | [Length](../../ui/ts-types.md#长度类型) | 0 | 否 | 路径所在矩形画布的高度。 |
-| commands | string | '' | 否 | 路径绘制的命令字符串。 |
-
-
-支持的绘制命令如下:
-
-
-- M = moveto
-
-- L = lineto
-
-- H = horizontal lineto
-
-- V = vertical lineto
-
-- C = curveto
-
-- S = smooth curveto
-
-- Q = quadratic Belzier curve
-
-- T = smooth quadratic Belzier curveto
-
-- A = elliptical Arc
-
-- Z = closepath
+
+## 属性
-如 commands('M0 20 L50 50 L50 100 Z')定义了一条路径,开始于位置(0,20),到达位置(50,50)后再到(50,100),最后在(0,20)处关闭路径。
+除支持[通用属性](ts-universal-attributes-size.md)外,还支持以下属性:
+
+| 参数名称 | 参数类型 | 默认值 | 必填 | 参数描述 |
+| -------- | ----------------------------------- | ---- | ---- | ---------------------------------------- |
+| commands | string | '' | 否 | 路径绘制的命令字符串,单位为px。像素单位转换方法请参考[像素单位转换](../../ui/ts-pixel-units.md)。 |
+| fill | [ResourceColor](../../ui/ts-types.md) | Color.Black | 否 | 设置填充区域颜色。 |
+| fillOpacity | number \| string \| [Resource](../../ui/ts-types.md#resource类型) | 1 | 否 | 设置填充区域透明度。 |
+| stroke | [ResourceColor](../../ui/ts-types.md) | Color.Black | 否 | 设置线条颜色。 |
+| strokeDashArray | Array<Length> | [] | 否 | 设置线条间隙。 |
+| strokeDashOffset | number \| string | 0 | 否 | 线条绘制起点的偏移量。 |
+| strokeLineCap | [LineCapStyle](ts-appendix-enums.md#linecapstyle) | LineCapStyle.Butt | 否 | 设置线条端点绘制样式。 |
+| strokeLineJoin | [LineJoinStyle](ts-appendix-enums.md#linejoinstyle) | LineJoinStyle.Miter | 否 | 设置线条拐角绘制样式。 |
+| strokeMiterLimit | number \| string | 4 | 否 | 设置锐角绘制成斜角的极限值。 |
+| strokeOpacity | number \| string \| [Resource](../../ui/ts-types.md#resource类型) | 1 | 否 | 设置线条透明度。 |
+| strokeWidth | Length | 1 | 否 | 设置线条宽度。 |
+| antiAlias | boolean | true | 否 | 是否开启抗锯齿效果。 |
+
+
+commands支持的绘制命令如下:
+
+| 命令 | 名称 | 参数 | 说明 |
+| ---- | -------------------------------- | ---------------------------------------- | ---------------------------------------- |
+| M | moveto | (x y) | 在给定的 (x, y) 坐标处开始一个新的子路径。例如,`M 0 0` 表示将(0, 0)点作为新子路径的起始点。 |
+| L | lineto | (x y) | 从当前点到给定的 (x, y) 坐标画一条线,该坐标成为新的当前点。例如,`L 50 50` 表示绘制当前点到(50, 50)点的直线,并将(50, 50)点作为新子路径的起始点。 |
+| H | horizontal lineto | x | 从当前点绘制一条水平线,等效于将y坐标指定为0的L命令。例如,`H 50 ` 表示绘制当前点到(50, 0)点的直线,并将(50, 0)点作为新子路径的起始点。 |
+| V | vertical lineto | y | 从当前点绘制一条垂直线,等效于将x坐标指定为0的L命令。例如,`V 50 ` 表示绘制当前点到(0, 50)点的直线,并将(0, 50)点作为新子路径的起始点。 |
+| C | curveto | (x1 y1 x2 y2 x y) | 使用 (x1, y1) 作为曲线起点的控制点, (x2, y2) 作为曲线终点的控制点,从当前点到 (x, y) 绘制三次贝塞尔曲线。例如,`C100 100 250 100 250 200 ` 表示绘制当前点到(250, 200)点的三次贝塞尔曲线,并将(250, 200)点作为新子路径的起始点。 |
+| S | smooth curveto | (x2 y2 x y) | (x2, y2) 作为曲线终点的控制点,绘制从当前点到 (x, y) 绘制三次贝塞尔曲线。若前一个命令是C或S,则起点控制点是上一个命令的终点控制点相对于起点的映射。 例如,`C100 100 250 100 250 200 S400 300 400 200`第二段贝塞尔曲线的起点控制点为(250, 300)。如果没有前一个命令或者前一个命令不是 C或S,则第一个控制点与当前点重合。 |
+| Q | quadratic Belzier curve | (x1 y1 x y) | 使用 (x1, y1) 作为控制点,从当前点到 (x, y) 绘制二次贝塞尔曲线。例如,`Q400 50 600 300 ` 表示绘制当前点到(600, 300)点的二次贝塞尔曲线,并将(600, 300)点作为新子路径的起始点。 |
+| T | smooth quadratic Belzier curveto | (x y) | 绘制从当前点到 (x, y) 绘制二次贝塞尔曲线。若前一个命令是Q或T,则控制点是上一个命令的终点控制点相对于起点的映射。 例如,`Q400 50 600 300 T1000 300`第二段贝塞尔曲线的控制点为(800, 350)。 如果没有前一个命令或者前一个命令不是 Q或T,则第一个控制点与当前点重合。 |
+| A | elliptical Arc | (rx ry x-axis-rotation large-arc-flag sweep-flag x y) | 从当前点到 (x, y) 绘制一条椭圆弧。椭圆的大小和方向由两个半径 (rx, ry) 和x-axis-rotation定义,指示整个椭圆相对于当前坐标系如何旋转(以度为单位)。 large-arc-flag 和 sweep-flag确定弧的绘制方式。 |
+| Z | closepath | none | 通过将当前路径连接回当前子路径的初始点来关闭当前子路径。 |
+
+例如: commands('M0 20 L50 50 L50 100 Z')定义了一个三角形,起始于位置(0,20),接着绘制点(0,20)到点(50,50)的直线,再绘制点(50,50)到点(50,100)的直线,最后绘制点(50,100)到(0,20)的直线关闭路径,形成封闭三角形。
## 示例
diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-drawing-components-polygon.md b/zh-cn/application-dev/reference/arkui-ts/ts-drawing-components-polygon.md
index ed3a3a4d402b5e6d2246a02b8c7b23c5954c94b1..31188de70e296d8251ec0ce82b98789b492f0ddf 100644
--- a/zh-cn/application-dev/reference/arkui-ts/ts-drawing-components-polygon.md
+++ b/zh-cn/application-dev/reference/arkui-ts/ts-drawing-components-polygon.md
@@ -19,22 +19,41 @@
## 接口
-Polygon(value?:{width?: string | number, height?: string | number})
+Polygon(options?: {width?: string | number, height?: string | number})
-**参数:**
+- 参数
+ | 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 |
+ | -------- | -------- | -------- | -------- | -------- |
+ | width | string \| number | 否 | 0 | 宽度。 |
+ | height | string \| number | 否 | 0 | 高度。 |
-| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 |
-| ------ | -------------------------- | ---- | ------ | -------- |
-| width | string \| number | 是 | - | 宽度。 |
-| height | string \| number | 是 | - | 高度。 |
## 属性
-| 参数名称 | 参数类型 | 默认值 | 必填 | 参数描述 |
-| -------- | ---------------- | ------ | ---- | ---------------------- |
-| width | Length | 0 | 否 | 多边形所在矩形的宽度。 |
-| height | Length | 0 | 否 | 多边形所在矩形的高度。 |
-| points | Array<any> | - | 是 | 多边形的顶点坐标列表。 |
+除支持[通用属性](ts-universal-attributes-size.md)外,还支持以下属性:
+
+| 参数名称 | 参数类型 | 默认值 | 必填 | 参数描述 |
+| -------- | -------- | -------- | -------- | -------- |
+| points | Array<Point> | [] | 否 | 多边形的顶点坐标列表。 |
+| fill | [ResourceColor](../../ui/ts-types.md) | Color.Black | 否 | 设置填充区域颜色。 |
+| fillOpacity | number \| string \| [Resource](../../ui/ts-types.md#resource类型) | 1 | 否 | 设置填充区域透明度。 |
+| stroke | [ResourceColor](../../ui/ts-types.md) | Color.Black | 否 | 设置线条颜色。 |
+| strokeDashArray | Array<Length> | [] | 否 | 设置线条间隙。 |
+| strokeDashOffset | number \| string | 0 | 否 | 线条绘制起点的偏移量。 |
+| strokeLineCap | [LineCapStyle](ts-appendix-enums.md#linecapstyle) | LineCapStyle.Butt | 否 | 设置线条端点绘制样式。 |
+| strokeLineJoin | [LineJoinStyle](ts-appendix-enums.md#linejoinstyle) | LineJoinStyle.Miter | 否 | 设置线条拐角绘制样式。 |
+| strokeMiterLimit | number \| string | 4 | 否 | 设置锐角绘制成斜角的极限值。 |
+| strokeOpacity | number \| string \| [Resource](../../ui/ts-types.md#resource类型) | 1 | 否 | 设置线条透明度。 |
+| strokeWidth | Length | 1 | 否 | 设置线条宽度。 |
+| antiAlias | boolean | true | 否 | 是否开启抗锯齿效果。 |
+
+## Point
+
+点坐标类型。
+
+| 名称 | 类型定义 | 描述 |
+| --------- | -------------------- | ------------------------------------------------------------ |
+| Point | [number, number] | 第一个参数为x轴坐标,第二个参数为y轴坐标(相对坐标)。 |
## 示例
diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-drawing-components-polyline.md b/zh-cn/application-dev/reference/arkui-ts/ts-drawing-components-polyline.md
index cd7e78f61fca6fc2bf15433cfbd2c34e4c9894bd..6d754199f6e8fe2025d4d806519b89c3638ca0e6 100644
--- a/zh-cn/application-dev/reference/arkui-ts/ts-drawing-components-polyline.md
+++ b/zh-cn/application-dev/reference/arkui-ts/ts-drawing-components-polyline.md
@@ -20,22 +20,41 @@
## 接口
-Polyline(value?: {width?: string | number, height?: string | number})
+Polyline(options?: {width?: string | number, height?: string | number})
-**参数:**
+- 参数
+ | 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 |
+ | -------- | -------- | -------- | -------- | -------- |
+ | width | string \| number | 否 | 0 | 宽度。 |
+ | height | string \| number | 否 | 0 | 高度。 |
-| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 |
-| ------ | -------------------------- | ---- | ------ | -------- |
-| width | string \| number | 是 | - | 宽度。 |
-| height | string \| number | 是 | - | 高度。 |
## 属性
-| 参数名称 | 参数类型 | 默认值 | 必填 | 参数描述 |
-| -------- | ---------------- | ------ | ---- | -------------------- |
-| width | Length | 0 | 否 | 折线所在矩形的宽度。 |
-| height | Length | 0 | 否 | 折线所在矩形的高度。 |
-| points | Array<any> | - | 是 | 折线经过坐标点列表。 |
+除支持[通用属性](ts-universal-attributes-size.md)外,还支持以下属性:
+
+| 参数名称 | 参数类型 | 默认值 | 必填 | 参数描述 |
+| -------- | -------- | -------- | -------- | -------- |
+| points | Array<Point> | [] | 否 | 折线经过坐标点列表。 |
+| fill | [ResourceColor](../../ui/ts-types.md) | Color.Black | 否 | 设置填充区域颜色。 |
+| fillOpacity | number \| string \| [Resource](../../ui/ts-types.md#resource类型) | 1 | 否 | 设置填充区域透明度。 |
+| stroke | [ResourceColor](../../ui/ts-types.md) | Color.Black | 否 | 设置线条颜色。 |
+| strokeDashArray | Array<Length> | [] | 否 | 设置线条间隙。 |
+| strokeDashOffset | number \| string | 0 | 否 | 线条绘制起点的偏移量。 |
+| strokeLineCap | [LineCapStyle](ts-appendix-enums.md#linecapstyle) | LineCapStyle.Butt | 否 | 设置线条端点绘制样式。 |
+| strokeLineJoin | [LineJoinStyle](ts-appendix-enums.md#linejoinstyle) | LineJoinStyle.Miter | 否 | 设置线条拐角绘制样式。 |
+| strokeMiterLimit | number \| string | 4 | 否 | 设置锐角绘制成斜角的极限值。 |
+| strokeOpacity | number \| string \| [Resource](../../ui/ts-types.md#resource类型) | 1 | 否 | 设置线条透明度。 |
+| strokeWidth | Length | 1 | 否 | 设置线条宽度。 |
+| antiAlias | boolean | true | 否 | 是否开启抗锯齿效果。 |
+
+## Point
+
+点坐标类型。
+
+| 名称 | 类型定义 | 描述 |
+| --------- | -------------------- | ------------------------------------------------------------ |
+| Point | [number, number] | 第一个参数为x轴坐标,第二个参数为y轴坐标(相对坐标)。 |
## 示例
diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-drawing-components-rect.md b/zh-cn/application-dev/reference/arkui-ts/ts-drawing-components-rect.md
index ab63e2c22bac7962b5ff03a45405d15bcd1b157a..a0668570471f2d1c3bd9651bfaa6abef790411b6 100644
--- a/zh-cn/application-dev/reference/arkui-ts/ts-drawing-components-rect.md
+++ b/zh-cn/application-dev/reference/arkui-ts/ts-drawing-components-rect.md
@@ -20,27 +20,39 @@
## 接口
-Rect(value:{value?: {width?: number | string ,height?: number | string ,radius?: number | string | Array<Length>} | {width?: number | string ,height?: number | string ,radiusWidth?: number | string ,radiusHeight?: number | string }})
+Rect(options?: {width?: string | number,height?: string | number,radius?: string | number | Array<string | number>} |
+ {width?: string | number,height?: string | number,radiusWidth?: string | number,radiusHeight?: string | number})
-**options参数说明:**
+- 参数
+ | 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 |
+ | -------- | -------- | -------- | -------- | -------- |
+ | width | string \| number | 否 | 0 | 宽度。 |
+ | height | string \| number | 否 | 0 | 高度。 |
+ | radius | string \| number \| Array<string \| number> | 否 | 0 | 圆角半径,支持分别设置四个角的圆角度数。 |
+ | radiusWidth | string \| number | 否 | 0 | 圆角宽度。 |
+ | radiusHeight | string \| number | 否 | 0 | 圆角高度。 |
-| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 |
-| ------------ | ----------------------------------------------------------- | ---- | ------ | ---------------------------------------- |
-| width | number \| string | 是 | - | 宽度。 |
-| height | number \| string | 是 | - | 高度。 |
-| radius | number \| string \| Array<any> | 否 | 0 | 圆角半径,支持分别设置四个角的圆角度数。 |
-| radiusWidth | number \| string | 否 | 0 | 圆角宽度。 |
-| radiusHeight | number \| string | 否 | 0 | 圆角高度。 |
## 属性
-| 参数名称 | 参数类型 | 默认值 | 必填 | 参数描述 |
-| ------------ | ------------------------------------ | ------ | ---- | -------------------------------- |
-| width | Length | 0 | 否 | 宽度。 |
-| height | Length | 0 | 否 | 高度。 |
-| radiusWidth | string \| number | 0 | 否 | 圆角的宽度,仅设置宽时宽高一致。 |
-| radiusHeight | string \| number | 0 | 否 | 圆角的高度,仅设置高时宽高一致。 |
-| radius | Length \| Array<any> | 0 | 否 | 圆角大小。 |
+除支持[通用属性](ts-universal-attributes-size.md)外,还支持以下属性:
+
+| 参数名称 | 参数类型 | 默认值 | 必填 | 参数描述 |
+| -------- | -------- | -------- | -------- | -------- |
+| radiusWidth | string \| number | 0 | 否 | 圆角的宽度,仅设置宽时宽高一致。 |
+| radiusHeight | string \| number | 0 | 否 | 圆角的高度,仅设置高时宽高一致。 |
+| radius | string \| number \| Array<string \| number> | 0 | 否 | 圆角半径大小。 |
+| fill | [ResourceColor](../../ui/ts-types.md) | Color.Black | 否 | 设置填充区域颜色。 |
+| fillOpacity | number \| string \| [Resource](../../ui/ts-types.md#resource类型) | 1 | 否 | 设置填充区域透明度。 |
+| stroke | [ResourceColor](../../ui/ts-types.md) | Color.Black | 否 | 设置线条颜色。 |
+| strokeDashArray | Array<Length> | [] | 否 | 设置线条间隙。 |
+| strokeDashOffset | number \| string | 0 | 否 | 线条绘制起点的偏移量。 |
+| strokeLineCap | [LineCapStyle](ts-appendix-enums.md#linecapstyle) | LineCapStyle.Butt | 否 | 设置线条端点绘制样式。 |
+| strokeLineJoin | [LineJoinStyle](ts-appendix-enums.md#linejoinstyle) | LineJoinStyle.Miter | 否 | 设置线条拐角绘制样式。 |
+| strokeMiterLimit | number \| string | 4 | 否 | 设置锐角绘制成斜角的极限值。 |
+| strokeOpacity | number \| string \| [Resource](../../ui/ts-types.md#resource类型) | 1 | 否 | 设置线条透明度。 |
+| strokeWidth | Length | 1 | 否 | 设置线条宽度。 |
+| antiAlias | boolean | true | 否 | 是否开启抗锯齿效果。 |
## 示例
diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-drawing-components-shape.md b/zh-cn/application-dev/reference/arkui-ts/ts-drawing-components-shape.md
index b00ca3fa6b198dbafc1a1152e163b9f03310f91a..70472c53c508d202710a7211d9da7aa2b5b5b409 100644
--- a/zh-cn/application-dev/reference/arkui-ts/ts-drawing-components-shape.md
+++ b/zh-cn/application-dev/reference/arkui-ts/ts-drawing-components-shape.md
@@ -23,31 +23,33 @@
## 接口
-Shape(value?: {target?: PixelMap})
+Shape(value?: PixelMap)
-**参数:**
+- 参数
+ | 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 |
+ | -------- | -------- | -------- | -------- | -------- |
+ | value | PixelMap | 否 | - | 绘制目标,可将图形绘制在指定的PixelMap对象中,若未设置,则在当前绘制目标中进行绘制。 |
-| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 |
-| ------ | -------- | ---- | ------ | ------------------------------------------------------------ |
-| target | PixelMap | 否 | null | 绘制目标,可将图形绘制在指定的PixelMap对象中,若未设置,则在当前绘制目标中进行绘制。 |
## 属性
-| 参数名称 | 参数类型 | 默认值 | 必填 | 参数描述 |
-| ---------------- | ------------------------------------------------------------ | ------------------- | ---- | -------------------------- |
-| viewPort | {
x?: [Length](ts-types.md#length),
y?: [Length](ts-types.md#length),
width?: [Length](ts-types.md#length),
height?: [Length](ts-types.md#length)
} | - | 是 | 形状的视口。 |
-| fill | [ResourceColor](ts-types.md#resourcecolor8) | Black | 否 | 填充颜色。 |
-| stroke | [ResourceColor](ts-types.md#resourcecolor8) | - | 否 | 边框颜色。 |
-| strokeDashArray | Array<any> | [] | 否 | 设置边框的间隙。 |
-| strokeDashOffset | number \| string | 0 | 否 | 边框绘制起点的偏移量。 |
-| strokeLineCap | [LineCapStyle](ts-appendix-enums.md#linecapstyle) | LineCapStyle.Butt | 否 | 路径端点绘制样式。 |
-| strokeLineJoin | [LineJoinStyle](ts-appendix-enums.md#linejoinstyle) | LineJoinStyle.Miter | 否 | 边框拐角绘制样式。 |
-| strokeMiterLimit | number \| string | 4 | 否 | 锐角绘制成斜角的极限值。 |
-| strokeOpacity | number \| string \| [Resource](ts-types.md#resource) | 1 | 否 | 设置边框的不透明度。 |
-| strokeWidth | number \| string | 1 | 否 | 设置边框的宽度。 |
-| antiAlias | boolean | true | 否 | 是否开启抗锯齿。 |
-| mesh | Array<any>,
column:number,
row:number | - | 否 | 绘制网格时调用。 |
-| fillOpacity | number \| string \| [Resource](ts-types.md#resource) | 1 | 否 | 设置形状填充部分的透明度。 |
+除支持[通用属性](ts-universal-attributes-size.md)外,还支持以下属性:
+
+| 参数名称 | 参数类型 | 默认值 | 必填 | 参数描述 |
+| -------- | -------- | -------- | -------- | -------- |
+| viewPort | {
x?: number \| string,
y?: number \| string,
width?: number \| string,
height?: number \| string
} | { x:0, y:0, width:0, height:0 } | 否 | 形状的视口。 |
+| fill | [ResourceColor](../../ui/ts-types.md) | Color.Black | 否 | 设置填充区域颜色。 |
+| fillOpacity | number \| string \| [Resource](../../ui/ts-types.md#resource类型) | 1 | 否 | 设置填充区域透明度。 |
+| stroke | [ResourceColor](../../ui/ts-types.md) | Color.Black | 否 | 设置线条颜色。 |
+| strokeDashArray | Array<Length> | [] | 否 | 设置线条间隙。 |
+| strokeDashOffset | number \| string | 0 | 否 | 线条绘制起点的偏移量。 |
+| strokeLineCap | [LineCapStyle](ts-appendix-enums.md#linecapstyle) | LineCapStyle.Butt | 否 | 设置线条端点绘制样式。 |
+| strokeLineJoin | [LineJoinStyle](ts-appendix-enums.md#linejoinstyle) | LineJoinStyle.Miter | 否 | 设置线条拐角绘制样式。 |
+| strokeMiterLimit | number \| string | 4 | 否 | 设置锐角绘制成斜角的极限值。 |
+| strokeOpacity | number \| string \| [Resource](../../ui/ts-types.md#resource类型) | 1 | 否 | 设置线条透明度。 |
+| strokeWidth | number \| string | 1 | 否 | 设置线条宽度。 |
+| antiAlias | boolean | true | 否 | 是否开启抗锯齿效果。 |
+| mesh8+ | Array<number>,number,number | [],0,0 | 否 | 设置mesh效果。第一个参数为长度(column + 1)* (row + 1)* 2的数组,它记录了扭曲后的位图各个顶点位置,第二个参数为mesh矩阵列数column,第三个参数为mesh矩阵行数row。 |
## 示例
diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-gesture-settings.md b/zh-cn/application-dev/reference/arkui-ts/ts-gesture-settings.md
index 50268acf5cdb0f46cfe5cb04d8124660b7880d27..8fe61b8d874cf99ed9f63ed79ddd9ea49cadec63 100644
--- a/zh-cn/application-dev/reference/arkui-ts/ts-gesture-settings.md
+++ b/zh-cn/application-dev/reference/arkui-ts/ts-gesture-settings.md
@@ -43,7 +43,7 @@
## 响应手势事件
-组件通过gesture方法绑定手势对象,可以通过手势对象提供的事件相应响应手势操作。如通过TapGesture对象的onAction事件响应点击事件。具体事件定义见各个手势对象章节。
+组件通过gesture方法绑定手势对象,可以通过手势对象提供的事件相应响应手势操作。例如通过TapGesture对象的onAction事件响应点击事件。其余手势的事件定义见各个手势对象章节。
- TapGesture事件说明
| 名称 | 功能描述 |
@@ -51,10 +51,36 @@
| onAction((event?:GestureEvent) => void) | Tap手势识别成功回调。 |
- GestureEvent对象说明
- | 属性名称 | 属性类型 | 描述 |
+ | 名称 | 类型 | 描述 |
| -------- | -------- | -------- |
- | timestamp | number | 事件时间戳。 |
- | target8+ | [EventTarget](ts-universal-events-click.md) | 触发手势事件的元素对象。 |
+ | timestamp8+ | number | 事件时间戳。 |
+ | target8+ | [EventTarget](ts-universal-events-click.md) | 触发手势事件的元素对象显示区域。 |
+ | source8+ | SourceType | 事件输入设备。 |
+ | repeat | boolean | 是否为重复触发事件,用于LongPressGesture手势触发场景。 |
+ | fingerList8+ | FingerInfo[] | 触发事件的所有手指信息,用于LongPressGesture与TapGesture手势触发场景。 |
+ | offsetX | number | 手势事件x轴偏移量,单位为vp,用于PanGesture手势触发场景。 |
+ | offsetY | number | 手势事件y轴偏移量,单位为vp,用于PanGesture手势触发场景。 |
+ | angle | number | 用于RotationGesture手势触发场景时,表示旋转角度;用于SwipeGesture手势触发场景时,表示滑动手势的角度,即两根手指间的线段与水平方向的夹角变化的度数。
> **说明:**
> 角度计算方式:滑动手势被识别到后,连接两根手指之间的线被识别为起始线条,随着手指的滑动,手指之间的线条会发生旋转,根据起始线条两端点和当前线条两端点的坐标,使用反正切函数分别计算其相对于水平方向的夹角,最后arctan2(cy2-cy1,cx2-cx1)-arctan2(y2-y1,x2-x1)为旋转的角度。以起始线条为坐标系,顺时针旋转为0到180度,逆时针旋转为-180到0度。 |
+ | speed8+ | number | 滑动手势速度,即所有手指滑动的平均速度,单位为vp/秒,用于SwipeGesture手势触发场景。 |
+ | scale | number | 缩放比例,用于PinchGesture手势触发场景。 |
+ | pinchCenterX | number | 捏合手势中心点x轴坐标,单位为vp,用于PinchGesture手势触发场景。 |
+ | pinchCenterY | number | 捏合手势中心点y轴坐标,单位为vp,用于PinchGesture手势触发场景。 |
+
+- SourceType
+ | 名称 | 描述 |
+ | -------- | -------- |
+ | Unknown | 未知设备。 |
+ | Mouse | 鼠标。 |
+ | TouchScreen | 触摸屏。 |
+
+- FingerInfo对象说明
+ | 名称 | 类型 | 描述 |
+ | -------- | -------- | -------- |
+ | id | number | 手指的索引编号。 |
+ | globalX | number | 相对于设备屏幕左上角的x轴坐标。 |
+ | globalY | number | 相对于设备屏幕左上角的y轴坐标。 |
+ | localX | number | 相对于当前组件元素左上角的x轴坐标。 |
+ | localY | number | 相对于当前组件元素左上角的y轴坐标。 |
## 示例
diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-methods-textpicker-dialog.md b/zh-cn/application-dev/reference/arkui-ts/ts-methods-textpicker-dialog.md
index 94cb1603b4f6efd9eec769a04b6aa27c80efbf2f..8105b2ed1eb65069c16d37442f3ee997695fa3d1 100644
--- a/zh-cn/application-dev/reference/arkui-ts/ts-methods-textpicker-dialog.md
+++ b/zh-cn/application-dev/reference/arkui-ts/ts-methods-textpicker-dialog.md
@@ -21,7 +21,7 @@ show(options: TextPickerDialogOptions)
| range | string[] | 是 | - | 选择器的数据选择范围。 |
| selected | number | 否 | 0 | 选中项在数组中的index值。 |
| value | string | 否 | 第一个元素值 | 选中项的值,优先级低于selected。 |
- | defaultPickerItemHeight | number | 否 | - | 默认Picker内容项元素高度。 |
+ | defaultPickerItemHeight | number \| string | 否 | - | 默认Picker内容项元素高度。 |
| onAccept | (value: TextPickerResult) => void | 否 | - | 点击弹窗中确定按钮时触发。 |
| onCancel | () => void | 否 | - | 点击弹窗中取消按钮时触发。 |
| onChange | (value: TextPickerResult) => void | 否 | - | 滑动选择器,当前选择项改变时触发。 |
diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-offscreencanvasrenderingcontext2d.md b/zh-cn/application-dev/reference/arkui-ts/ts-offscreencanvasrenderingcontext2d.md
index f62674077b93bb96247757fbbdd6d202fdbd3e39..29f42de35dc9438639a8b5fe09b9959b92871aed 100644
--- a/zh-cn/application-dev/reference/arkui-ts/ts-offscreencanvasrenderingcontext2d.md
+++ b/zh-cn/application-dev/reference/arkui-ts/ts-offscreencanvasrenderingcontext2d.md
@@ -11,39 +11,40 @@
OffscreenCanvasRenderingContext2D(width: number, height: number, setting: RenderingContextSettings)
-- 参数
- | 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 |
- | ------- | ---------------------------------------- | ---- | ---- | ------------------------------ |
- | width | number | 是 | - | 离屏画布的宽度 |
- | height | number | 是 | - | 离屏画布的高度 |
- | setting | [RenderingContextSettings](ts-canvasrenderingcontext2d.md#renderingcontextsettings) | 是 | - | 见RenderingContextSettings接口描述。 |
+**参数:**
+| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 |
+| ------- | ---------------------------------------- | ---- | ---- | ------------------------------ |
+| width | number | 是 | - | 离屏画布的宽度 |
+| height | number | 是 | - | 离屏画布的高度 |
+| setting | [RenderingContextSettings](ts-canvasrenderingcontext2d.md#renderingcontextsettings) | 是 | - | 见RenderingContextSettings接口描述。 |
-## 属性
-| 名称 | 类型 | 默认值 | 描述 |
-| ---------------------------------------- | ---------------------------------------- | ---------------------------------------- | ---------------------------------------- |
-| [fillStyle](#fillstyle) | <color> \| [CanvasGradient](ts-components-canvas-canvasgradient.md) \| [CanvasPattern](#canvaspattern) | - | 指定绘制的填充色。
- 类型为<color>时,表示设置填充区域的颜色。
- 类型为CanvasGradient时,表示渐变对象,使用 [createLinearGradient](#createlineargradient)方法创建。
- 类型为CanvasPattern时,使用[createPattern](#createpattern)方法创建。 |
-| [lineWidth](#linewidth) | number | - | 设置绘制线条的宽度。 |
-| [strokeStyle](#strokestyle) | <color> \| [CanvasGradient](ts-components-canvas-canvasgradient.md) \| [CanvasPattern](#canvaspattern) | - | 设置描边的颜色。
- 类型为<color>时,表示设置描边使用的颜色。
- 类型为CanvasGradient时,表示渐变对象,使用[createLinearGradient](#createlineargradient)方法创建。
- 类型为CanvasPattern时,使用[createPattern](#createpattern)方法创建。 |
-| [lineCap](#linecap) | string | 'butt' | 指定线端点的样式,可选值为:
- 'butt':线端点以方形结束。
- 'round':线端点以圆形结束。
- 'square':线端点以方形结束,该样式下会增加一个长度和线段厚度相同,宽度是线段厚度一半的矩形。 |
-| [lineJoin](#linejoin) | string | 'miter' | 指定线段间相交的交点样式,可选值为:
- 'round':在线段相连处绘制一个扇形,扇形的圆角半径是线段的宽度。
- 'bevel':在线段相连处使用三角形为底填充, 每个部分矩形拐角独立。
- 'miter':在相连部分的外边缘处进行延伸,使其相交于一点,形成一个菱形区域,该属性可以通过设置miterLimit属性展现效果。 |
-| [miterLimit](#miterlimit) | number | 10 | 设置斜接面限制值,该值指定了线条相交处内角和外角的距离。 |
-| [font](#font) | string | 'normal normal 14px sans-serif' | 设置文本绘制中的字体样式。
语法:ctx.font='font-size font-family'
- font-size(可选),指定字号和行高,单位只支持px。
- font-family(可选),指定字体系列。
语法:ctx.font='font-style font-weight font-size font-family'
- font-style(可选),用于指定字体样式,支持如下几种样式:'normal', 'italic'。
- font-weight(可选),用于指定字体的粗细,支持如下几种类型:'normal', 'bold', 'bolder', 'lighter', 100, 200, 300, 400, 500, 600, 700, 800, 900。
- font-size(可选),指定字号和行高,单位只支持px。
- font-family(可选),指定字体系列,支持如下几种类型:'sans-serif', 'serif', 'monospace'。 |
-| [textAlign](#textalign) | string | 'left' | 设置文本绘制中的文本对齐方式,可选值为:
- 'left':文本左对齐。
- 'right':文本右对齐。
- 'center':文本居中对齐。
- 'start':文本对齐界线开始的地方。
- 'end':文本对齐界线结束的地方。
> **说明:**
> ltr布局模式下start和left一致,rtl布局模式下start和right一致·。 |
-| [textBaseline](#textbaseline) | string | 'alphabetic' | 设置文本绘制中的水平对齐方式,可选值为:
- 'alphabetic':文本基线是标准的字母基线。
- 'top':文本基线在文本块的顶部。
- 'hanging':文本基线是悬挂基线。
- 'middle':文本基线在文本块的中间。
- 'ideographic':文字基线是表意字基线;如果字符本身超出了alphabetic基线,那么ideograhpic基线位置在字符本身的底部。
- 'bottom':文本基线在文本块的底部。 与ideographic基线的区别在于ideographic 基线不需要考虑下行字母。 |
-| [globalAlpha](#globalalpha) | number | - | 设置透明度,0.0为完全透明,1.0为完全不透明。 |
-| [lineDashOffset](#linedashoffset) | number | 0.0 | 设置画布的虚线偏移量,精度为float。 |
-| [globalCompositeOperation](#globalcompositeoperation) | string | 'source-over' | 设置合成操作的方式。类型字段可选值有'source-over','source-atop','source-in','source-out','destination-over','destination-atop','destination-in','destination-out','lighter','copy','xor'。 |
-| [shadowBlur](#shadowblur) | number | 0.0 | 设置绘制阴影时的模糊级别,值越大越模糊,精度为float。 |
-| [shadowColor](#shadowcolor) | <color> | - | 设置绘制阴影时的阴影颜色。 |
-| [shadowOffsetX](#shadowoffsetx) | number | - | 设置绘制阴影时和原有对象的水平偏移值。 |
-| [shadowOffsetY](#shadowoffsety) | number | - | 设置绘制阴影时和原有对象的垂直偏移值。 |
-| [imageSmoothingEnabled](#imagesmoothingenabled) | boolean | true | 用于设置绘制图片时是否进行图像平滑度调整,true为启用,false为不启用。 |
-| imageSmoothingQuality | string | 'low' | 用于设置图像平滑度,支持如下三种类型:'low', 'medium', 'high'。 |
+## 属性
-> **说明:**
-> <color>类型格式为 'rgb(255, 255, 255)','rgba(255, 255, 255, 1.0)','\#FFFFFF'。
+| 名称 | 类型 | 描述 |
+| ---------------------------------------- | ---------------------------------------- | ---------------------------------------- |
+| [fillStyle](#fillstyle) | string \| [CanvasGradient](ts-components-canvas-canvasgradient.md) \| [CanvasPattern](#canvaspattern) | 指定绘制的填充色。
- 类型为string时,表示设置填充区域的颜色。
- 类型为CanvasGradient时,表示渐变对象,使用[createLinearGradient](#createlineargradient)方法创建。
- 类型为CanvasPattern时,使用[createPattern](#createpattern)方法创建。 |
+| [lineWidth](#linewidth) | number | 设置绘制线条的宽度。 |
+| [strokeStyle](#strokestyle) | string \| [CanvasGradient](ts-components-canvas-canvasgradient.md) \| [CanvasPattern](#canvaspattern) | 设置描边的颜色。
- 类型为string时,表示设置描边使用的颜色。
- 类型为CanvasGradient时,表示渐变对象,使用[createLinearGradient](#createlineargradient)方法创建。
- 类型为CanvasPattern时,使用[createPattern](#createpattern)方法创建。 |
+| [lineCap](#linecap) | CanvasLineCap | 指定线端点的样式,可选值为:
- 'butt':线端点以方形结束。
- 'round':线端点以圆形结束。
- 'square':线端点以方形结束,该样式下会增加一个长度和线段厚度相同,宽度是线段厚度一半的矩形。
- 默认值:'butt'。 |
+| [lineJoin](#linejoin) | CanvasLineJoin | 指定线段间相交的交点样式,可选值为:
- 'round':在线段相连处绘制一个扇形,扇形的圆角半径是线段的宽度。
- 'bevel':在线段相连处使用三角形为底填充, 每个部分矩形拐角独立。
- 'miter':在相连部分的外边缘处进行延伸,使其相交于一点,形成一个菱形区域,该属性可以通过设置miterLimit属性展现效果。
- 默认值:'miter'。 |
+| [miterLimit](#miterlimit) | number | 设置斜接面限制值,该值指定了线条相交处内角和外角的距离。
- 默认值:10。 |
+| [font](#font) | string | 设置文本绘制中的字体样式。
语法:ctx.font='font-size font-family'
- font-size(可选),指定字号和行高,单位只支持px。
- font-family(可选),指定字体系列。
语法:ctx.font='font-style font-weight font-size font-family'
- font-style(可选),用于指定字体样式,支持如下几种样式:'normal','italic'。
- font-weight(可选),用于指定字体的粗细,支持如下几种类型:'normal', 'bold', 'bolder', 'lighter', 100, 200, 300, 400, 500, 600, 700, 800, 900。
- font-size(可选),指定字号和行高,单位只支持px。
- font-family(可选),指定字体系列,支持如下几种类型:'sans-serif', 'serif', 'monospace'。
- 默认值:'normal normal 14px sans-serif'。 |
+| [textAlign](#textalign) | CanvasTextAlign | 设置文本绘制中的文本对齐方式,可选值为:
- 'left':文本左对齐。
- 'right':文本右对齐。
- 'center':文本居中对齐。
- 'start':文本对齐界线开始的地方。
- 'end':文本对齐界线结束的地方。
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> ltr布局模式下'start'和'left'一致,rtl布局模式下'start'和'right'一致·。
- 默认值:'left'。 |
+| [textBaseline](#textbaseline) | CanvasTextBaseline | 设置文本绘制中的水平对齐方式,可选值为:
- 'alphabetic':文本基线是标准的字母基线。
- 'top':文本基线在文本块的顶部。
- 'hanging':文本基线是悬挂基线。
- 'middle':文本基线在文本块的中间。
- 'ideographic':文字基线是表意字基线;如果字符本身超出了alphabetic基线,那么ideograhpic基线位置在字符本身的底部。
- 'bottom':文本基线在文本块的底部。 与ideographic基线的区别在于ideographic基线不需要考虑下行字母。
- 默认值:'alphabetic'。 |
+| [globalAlpha](#globalalpha) | number | 设置透明度,0.0为完全透明,1.0为完全不透明。 |
+| [lineDashOffset](#linedashoffset) | number | 设置画布的虚线偏移量,精度为float。
- 默认值:0.0。 |
+| [globalCompositeOperation](#globalcompositeoperation) | string | 设置合成操作的方式。类型字段可选值有'source-over','source-atop','source-in','source-out','destination-over','destination-atop','destination-in','destination-out','lighter','copy','xor'。
- 默认值:'source-over'。 |
+| [shadowBlur](#shadowblur) | number | 设置绘制阴影时的模糊级别,值越大越模糊,精度为float。
- 默认值:0.0。 |
+| [shadowColor](#shadowcolor) | string | 设置绘制阴影时的阴影颜色。 |
+| [shadowOffsetX](#shadowoffsetx) | number | 设置绘制阴影时和原有对象的水平偏移值。 |
+| [shadowOffsetY](#shadowoffsety) | number | 设置绘制阴影时和原有对象的垂直偏移值。 |
+| [imageSmoothingEnabled](#imagesmoothingenabled) | boolean | 用于设置绘制图片时是否进行图像平滑度调整,true为启用,false为不启用。
- 默认值:true。 |
+| imageSmoothingQuality | string | 用于设置图像平滑度,支持如下三种类型:'low', 'medium', 'high'。
- 默认值:'low'。 |
+
+> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
+>fillStyle、shadowColor与 strokeStyle 中string类型格式为 'rgb(255, 255, 255)','rgba(255, 255, 255, 1.0)','\#FFFFFF'。
### fillStyle
@@ -143,7 +144,6 @@ struct StrokeStyleExample {
}
```
-
![zh-cn_image_0000001238712437](figures/zh-cn_image_0000001238712437.png)
@@ -445,6 +445,7 @@ struct LineDashOffset {
.onReady(() =>{
this.offContext.arc(100, 75, 50, 0, 6.28)
this.offContext.setLineDash([10,20])
+ this.offContext.lineDashOffset = 10.0;
this.offContext.stroke();
var image = this.offContext.transferToImageBitmap()
this.context.transferFromImageBitmap(image)
@@ -454,8 +455,8 @@ struct LineDashOffset {
.height('100%')
}
}
-```
+```
![zh-cn_image_0000001238712439](figures/zh-cn_image_0000001238712439.png)
@@ -700,7 +701,8 @@ fillRect(x: number, y: number, w: number, h: number): void
填充一个矩形。
-- 参数
+ **参数:**
+
| 参数 | 类型 | 必填 | 默认值 | 说明 |
| ------ | ------ | ---- | ---- | ------------- |
| x | number | 是 | 0 | 指定矩形左上角点的x坐标。 |
@@ -708,8 +710,10 @@ fillRect(x: number, y: number, w: number, h: number): void
| width | number | 是 | 0 | 指定矩形的宽度。 |
| height | number | 是 | 0 | 指定矩形的高度。 |
-- 示例
- ```
+ **示例:**
+
+ ```ts
+ // xxx.ets
@Entry
@Component
struct FillRect {
@@ -744,7 +748,8 @@ strokeRect(x: number, y: number, w: number, h: number): void
绘制具有边框的矩形,矩形内部不填充。
-- 参数
+ **参数:**
+
| 参数 | 类型 | 必填 | 默认值 | 说明 |
| ------ | ------ | ---- | ---- | ------------ |
| x | number | 是 | 0 | 指定矩形的左上角x坐标。 |
@@ -752,8 +757,10 @@ strokeRect(x: number, y: number, w: number, h: number): void
| width | number | 是 | 0 | 指定矩形的宽度。 |
| height | number | 是 | 0 | 指定矩形的高度。 |
-- 示例
- ```
+ **示例:**
+
+ ```ts
+ // xxx.ets
@Entry
@Component
struct StrokeRect {
@@ -787,7 +794,8 @@ clearRect(x: number, y: number, w: number, h: number): void
删除指定区域内的绘制内容。
-- 参数
+ **参数:**
+
| 参数 | 类型 | 必填 | 默认值 | 描述 |
| ------ | ------ | ---- | ---- | ------------- |
| x | number | 是 | 0 | 指定矩形上的左上角x坐标。 |
@@ -795,8 +803,10 @@ clearRect(x: number, y: number, w: number, h: number): void
| width | number | 是 | 0 | 指定矩形的宽度。 |
| height | number | 是 | 0 | 指定矩形的高度。 |
-- 示例
- ```
+ **示例:**
+
+ ```ts
+ // xxx.ets
@Entry
@Component
struct ClearRect {
@@ -828,19 +838,23 @@ clearRect(x: number, y: number, w: number, h: number): void
### fillText
-fillText(text: string, x: number, y: number): void
+fillText(text: string, x: number, y: number, maxWidth?: number): void
绘制填充类文本。
-- 参数
+**参数:**
+
| 参数 | 类型 | 必填 | 默认值 | 说明 |
| ---- | ------ | ---- | ---- | --------------- |
| text | string | 是 | “” | 需要绘制的文本内容。 |
| x | number | 是 | 0 | 需要绘制的文本的左下角x坐标。 |
| y | number | 是 | 0 | 需要绘制的文本的左下角y坐标。 |
+ | maxWidth | number | 否 | - | 指定文本允许的最大宽度。 |
-- 示例
- ```
+ **示例:**
+
+ ```ts
+ // xxx.ets
@Entry
@Component
struct FillText {
@@ -875,15 +889,19 @@ strokeText(text: string, x: number, y: number): void
绘制描边类文本。
-- 参数
+**参数:**
+
| 参数 | 类型 | 必填 | 默认值 | 描述 |
| ---- | ------ | ---- | ---- | --------------- |
| text | string | 是 | “” | 需要绘制的文本内容。 |
| x | number | 是 | 0 | 需要绘制的文本的左下角x坐标。 |
| y | number | 是 | 0 | 需要绘制的文本的左下角y坐标。 |
+ | maxWidth | number | 否 | - | 需要绘制的文本的最大宽度 。|
-- 示例
- ```
+ **示例:**
+
+ ```ts
+ // xxx.ets
@Entry
@Component
struct StrokeText {
@@ -918,23 +936,40 @@ measureText(text: string): TextMetrics
该方法返回一个文本测算的对象,通过该对象可以获取指定文本的宽度值。
-- 参数
+ **参数:**
+
| 参数 | 类型 | 必填 | 默认值 | 说明 |
| ---- | ------ | ---- | ---- | ---------- |
| text | string | 是 | "" | 需要进行测量的文本。 |
-- 返回值
+ **返回值:**
+
| 类型 | 说明 |
| ----------- | ------- |
| TextMetrics | 文本的尺寸信息 |
-- TextMetrics类型描述
- | 属性 | 类型 | 描述 |
- | ----- | ------ | ------- |
- | width | number | 字符串的宽度。 |
-
-- 示例
- ```
+**TextMetrics类型描述:**
+
+ | 属性 | 类型 | 描述 |
+ | ----- | ------ | ------- |
+ | width | number | 字符串的宽度。 |
+ | height | number | 字符串的高度。 |
+ | actualBoundingBoxAscent | number | 从CanvasRenderingContext2D.textBaseline 属性标明的水平线到渲染文本的矩形边界顶部的距离,当前值为0。 |
+ | actualBoundingBoxDescent | number | 从CanvasRenderingContext2D.textBaseline 属性标明的水平线到渲染文本的矩形边界底部的距离,当前值为0。 |
+ | actualBoundingBoxLeft | number | 平行于基线,从CanvasRenderingContext2D.textAlign 属性确定的对齐点到文本矩形边界左侧的距离,当前值为0。 |
+ | actualBoundingBoxRight | number | 平行于基线,从CanvasRenderingContext2D.textAlign 属性确定的对齐点到文本矩形边界右侧的距离,当前值为0。|
+ | alphabeticBaseline | number | 从CanvasRenderingContext2D.textBaseline 属性标明的水平线到线框的 alphabetic 基线的距离,当前值为0。|
+ | emHeightAscent | number | 从CanvasRenderingContext2D.textBaseline 属性标明的水平线到线框中 em 方块顶部的距离,当前值为0。|
+ | emHeightDescent | number | 从CanvasRenderingContext2D.textBaseline 属性标明的水平线到线框中 em 方块底部的距离,当前值为0。|
+ | fontBoundingBoxAscent | number | 从CanvasRenderingContext2D.textBaseline 属性标明的水平线到渲染文本的所有字体的矩形最高边界顶部的距离,当前值为0。|
+ | fontBoundingBoxDescent | number | 从CanvasRenderingContext2D.textBaseline 属性标明的水平线到渲染文本的所有字体的矩形边界最底部的距离,当前值为0。|
+ | hangingBaseline | number | 从CanvasRenderingContext2D.textBaseline 属性标明的水平线到线框的 hanging 基线的距离,当前值为0。|
+ | ideographicBaseline | number | 从CanvasRenderingContext2D.textBaseline 属性标明的水平线到线框的 ideographic 基线的距离,当前值为0。|
+
+ **示例:**
+
+ ```ts
+ // xxx.ets
@Entry
@Component
struct MeasureText {
@@ -970,13 +1005,16 @@ stroke(path?: Path2D): void
进行边框绘制操作。
-- 参数
+ **参数:**
+
| 参数 | 类型 | 必填 | 默认值 | 描述 |
| ---- | ---------------------------------------- | ---- | ---- | ------------ |
| path | [Path2D](ts-components-canvas-path2d.md) | 否 | null | 需要绘制的Path2D。 |
-- 示例
- ```
+ **示例:**
+
+ ```ts
+ // xxx.ets
@Entry
@Component
struct Stroke {
@@ -1013,8 +1051,10 @@ beginPath(): void
创建一个新的绘制路径。
-- 示例
- ```
+ **示例:**
+
+ ```ts
+ // xxx.ets
@Entry
@Component
struct BeginPath {
@@ -1053,14 +1093,17 @@ moveTo(x: number, y: number): void
路径从当前点移动到指定点。
-- 参数
+ **参数:**
+
| 参数 | 类型 | 必填 | 默认值 | 说明 |
| ---- | ------ | ---- | ---- | --------- |
| x | number | 是 | 0 | 指定位置的x坐标。 |
| y | number | 是 | 0 | 指定位置的y坐标。 |
-- 示例
- ```
+ **示例:**
+
+ ```ts
+ // xxx.ets
@Entry
@Component
struct MoveTo {
@@ -1097,14 +1140,17 @@ lineTo(x: number, y: number): void
从当前点到指定点进行路径连接。
-- 参数
+ **参数:**
+
| 参数 | 类型 | 必填 | 默认值 | 描述 |
| ---- | ------ | ---- | ---- | --------- |
| x | number | 是 | 0 | 指定位置的x坐标。 |
| y | number | 是 | 0 | 指定位置的y坐标。 |
-- 示例
- ```
+ **示例:**
+
+ ```ts
+ // xxx.ets
@Entry
@Component
struct LineTo {
@@ -1141,8 +1187,10 @@ closePath(): void
结束当前路径形成一个封闭路径。
-- 示例
- ```
+ **示例:**
+
+ ```ts
+ // xxx.ets
@Entry
@Component
struct ClosePath {
@@ -1177,18 +1225,27 @@ closePath(): void
### createPattern
-createPattern(image: ImageBitmap, repetition: string): CanvasPattern
+createPattern(image: ImageBitmap, repetition: string | null): CanvasPattern | null
通过指定图像和重复方式创建图片填充的模板。
-- 参数
+**参数:**
+
| 参数 | 类型 | 必填 | 默认值 | 描述 |
| ---------- | ---------------------------------------- | ---- | ---- | ---------------------------------------- |
| image | [ImageBitmap](ts-components-canvas-imagebitmap.md) | 是 | null | 图源对象,具体参考ImageBitmap对象。 |
| repetition | string | 是 | “” | 设置图像重复的方式,取值为:'repeat'、'repeat-x'、 'repeat-y'、'no-repeat'。 |
-- 示例
- ```
+**返回值:**
+
+ | 类型 | 说明 |
+ | ---------- | ---------------------------------------- |
+ | [CanvasPattern](#canvaspattern) | 通过指定图像和重复方式创建图片填充的模板对象。 |
+
+ **示例:**
+
+ ```ts
+ // xxx.ets
@Entry
@Component
struct CreatePattern {
@@ -1225,7 +1282,8 @@ bezierCurveTo(cp1x: number, cp1y: number, cp2x: number, cp2y: number, x: number,
创建三次贝赛尔曲线的路径。
-- 参数
+ **参数:**
+
| 参数 | 类型 | 必填 | 默认值 | 描述 |
| ---- | ------ | ---- | ---- | -------------- |
| cp1x | number | 是 | 0 | 第一个贝塞尔参数的x坐标值。 |
@@ -1235,8 +1293,10 @@ bezierCurveTo(cp1x: number, cp1y: number, cp2x: number, cp2y: number, x: number,
| x | number | 是 | 0 | 路径结束时的x坐标值。 |
| y | number | 是 | 0 | 路径结束时的y坐标值。 |
-- 示例
- ```
+ **示例:**
+
+ ```ts
+ // xxx.ets
@Entry
@Component
struct BezierCurveTo {
@@ -1273,7 +1333,8 @@ quadraticCurveTo(cpx: number, cpy: number, x: number, y: number): void
创建二次贝赛尔曲线的路径。
-- 参数
+ **参数:**
+
| 参数 | 类型 | 必填 | 默认值 | 描述 |
| ---- | ------ | ---- | ---- | ----------- |
| cpx | number | 是 | 0 | 贝塞尔参数的x坐标值。 |
@@ -1281,8 +1342,10 @@ quadraticCurveTo(cpx: number, cpy: number, x: number, y: number): void
| x | number | 是 | 0 | 路径结束时的x坐标值。 |
| y | number | 是 | 0 | 路径结束时的y坐标值。 |
-- 示例
- ```
+ **示例:**
+
+ ```ts
+ // xxx.ets
@Entry
@Component
struct QuadraticCurveTo {
@@ -1315,11 +1378,12 @@ quadraticCurveTo(cpx: number, cpy: number, x: number, y: number): void
### arc
-arc(x: number, y: number, radius: number, startAngle: number, endAngle: number, anticlockwise?: boolean): void
+arc(x: number, y: number, radius: number, startAngle: number, endAngle: number, counterclockwise?: boolean): void
绘制弧线路径。
-- 参数
+ **参数:**
+
| 参数 | 类型 | 必填 | 默认值 | 描述 |
| ------------- | ------- | ---- | ----- | ---------- |
| x | number | 是 | 0 | 弧线圆心的x坐标值。 |
@@ -1327,10 +1391,12 @@ arc(x: number, y: number, radius: number, startAngle: number, endAngle: number,
| radius | number | 是 | 0 | 弧线的圆半径。 |
| startAngle | number | 是 | 0 | 弧线的起始弧度。 |
| endAngle | number | 是 | 0 | 弧线的终止弧度。 |
- | anticlockwise | boolean | 否 | false | 是否逆时针绘制圆弧。 |
+ | counterclockwise | boolean | 否 | false | 是否逆时针绘制圆弧。 |
-- 示例
- ```
+ **示例:**
+
+ ```ts
+ // xxx.ets
@Entry
@Component
struct Arc {
@@ -1366,7 +1432,8 @@ arcTo(x1: number, y1: number, x2: number, y2: number, radius: number): void
依据圆弧经过的点和圆弧半径创建圆弧路径。
-- 参数
+ **参数:**
+
| 参数 | 类型 | 必填 | 默认值 | 描述 |
| ------ | ------ | ---- | ---- | --------------- |
| x1 | number | 是 | 0 | 圆弧经过的第一个点的x坐标值。 |
@@ -1375,8 +1442,10 @@ arcTo(x1: number, y1: number, x2: number, y2: number, radius: number): void
| y2 | number | 是 | 0 | 圆弧经过的第二个点的y坐标值。 |
| radius | number | 是 | 0 | 圆弧的圆半径值。 |
-- 示例
- ```
+ **示例:**
+
+ ```ts
+ // xxx.ets
@Entry
@Component
struct ArcTo {
@@ -1408,11 +1477,12 @@ arcTo(x1: number, y1: number, x2: number, y2: number, radius: number): void
### ellipse
-ellipse(x: number, y: number, radiusX: number, radiusY: number, rotation: number, startAngle: number, endAngle: number, anticlockwise?: boolean): void
+ellipse(x: number, y: number, radiusX: number, radiusY: number, rotation: number, startAngle: number, endAngle: number, counterclockwise?: boolean): void
在规定的矩形区域绘制一个椭圆。
-- 参数
+ **参数:**
+
| 参数 | 类型 | 必填 | 默认值 | 说明 |
| ------------- | ------- | ---- | ----- | ----------------- |
| x | number | 是 | 0 | 椭圆圆心的x轴坐标。 |
@@ -1422,11 +1492,12 @@ ellipse(x: number, y: number, radiusX: number, radiusY: number, rotation: number
| rotation | number | 是 | 0 | 椭圆的旋转角度,单位为弧度。 |
| startAngle | number | 是 | 0 | 椭圆绘制的起始点角度,以弧度表示。 |
| endAngle | number | 是 | 0 | 椭圆绘制的结束点角度,以弧度表示。 |
- | anticlockwise | boolean | 否 | false | 是否以逆时针方向绘制椭圆。 |
+ | counterclockwise | boolean | 否 | false | 是否以逆时针方向绘制椭圆。 |
-- 示例
+ **示例:**
- ```
+ ```ts
+ // xxx.ets
@Entry
@Component
struct CanvasExample {
@@ -1458,20 +1529,23 @@ ellipse(x: number, y: number, radiusX: number, radiusY: number, rotation: number
### rect
-rect(x: number, y: number, width: number, height: number): void
+rect(x: number, y: number, w: number, h: number): void
创建矩形路径。
-- 参数
+ **参数:**
+
| 参数 | 类型 | 必填 | 默认值 | 描述 |
| ------ | ------ | ---- | ---- | ------------- |
| x | number | 是 | 0 | 指定矩形的左上角x坐标值。 |
| y | number | 是 | 0 | 指定矩形的左上角y坐标值。 |
- | width | number | 是 | 0 | 指定矩形的宽度。 |
- | height | number | 是 | 0 | 指定矩形的高度。 |
+ | w | number | 是 | 0 | 指定矩形的宽度。 |
+ | h | number | 是 | 0 | 指定矩形的高度。 |
-- 示例
- ```
+ **示例:**
+
+ ```ts
+ // xxx.ets
@Entry
@Component
struct CanvasExample {
@@ -1506,8 +1580,10 @@ fill(): void
对封闭路径进行填充。
-- 示例
- ```
+ **示例:**
+
+ ```ts
+ // xxx.ets
@Entry
@Component
struct Fill {
@@ -1542,8 +1618,10 @@ clip(): void
设置当前路径为剪切路径。
-- 示例
- ```
+ **示例:**
+
+ ```ts
+ // xxx.ets
@Entry
@Component
struct Clip {
@@ -1577,17 +1655,20 @@ clip(): void
### rotate
-rotate(rotate: number): void
+rotate(angle: number): void
针对当前坐标轴进行顺时针旋转。
-- 参数
+ **参数:**
+
| 参数 | 类型 | 必填 | 默认值 | 描述 |
| ------ | ------ | ---- | ---- | ---------------------------------------- |
- | rotate | number | 是 | 0 | 设置顺时针旋转的弧度值,可以通过Math.PI / 180将角度转换为弧度值。 |
+ | angle | number | 是 | 0 | 设置顺时针旋转的弧度值,可以通过Math.PI / 180将角度转换为弧度值。 |
-- 示例
- ```
+ **示例:**
+
+ ```ts
+ // xxx.ets
@Entry
@Component
struct Rotate {
@@ -1622,14 +1703,17 @@ scale(x: number, y: number): void
设置canvas画布的缩放变换属性,后续的绘制操作将按照缩放比例进行缩放。
-- 参数
+ **参数:**
+
| 参数 | 类型 | 必填 | 默认值 | 描述 |
| ---- | ------ | ---- | ---- | ----------- |
| x | number | 是 | 0 | 设置水平方向的缩放值。 |
| y | number | 是 | 0 | 设置垂直方向的缩放值。 |
-- 示例
- ```
+ **示例:**
+
+ ```ts
+ // xxx.ets
@Entry
@Component
struct Scale {
@@ -1661,29 +1745,32 @@ scale(x: number, y: number): void
### transform
-transform(scaleX: number, skewX: number, skewY: number, scaleY: number, translateX: number, translateY: number): void
+transform(a: number, b: number, c: number, d: number, e: number, f: number): void
transform方法对应一个变换矩阵,想对一个图形进行变化的时候,只要设置此变换矩阵相应的参数,对图形的各个定点的坐标分别乘以这个矩阵,就能得到新的定点的坐标。矩阵变换效果可叠加。
-> **说明:**
+> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> 变换后的坐标计算方式(x和y为变换前坐标,x'和y'为变换后坐标):
>
> - x' = scaleX \* x + skewY \* y + translateX
>
> - y' = skewX \* x + scaleY \* y + translateY
-- 参数
+**参数:**
+
| 参数 | 类型 | 必填 | 默认值 | 描述 |
| ---------- | ------ | ---- | ---- | -------- |
- | scaleX | number | 是 | 0 | 指定水平缩放值。 |
- | skewX | number | 是 | 0 | 指定水平倾斜值。 |
- | skewY | number | 是 | 0 | 指定垂直倾斜值。 |
- | scaleY | number | 是 | 0 | 指定垂直缩放值。 |
- | translateX | number | 是 | 0 | 指定水平移动值。 |
- | translateY | number | 是 | 0 | 指定垂直移动值。 |
-
-- 示例
- ```
+ | a | number | 是 | 0 |scaleX: 指定水平缩放值。 |
+ | b | number | 是 | 0 |skewX: 指定水平倾斜值。 |
+ | c | number | 是 | 0 |skewY: 指定垂直倾斜值。 |
+ | d | number | 是 | 0 |scaleY: 指定垂直缩放值。 |
+ | e | number | 是 | 0 |translateX: 指定水平移动值。 |
+ | f | number | 是 | 0 |translateY: 指定垂直移动值。 |
+
+ **示例:**
+
+ ```ts
+ // xxx.ets
@Entry
@Component
struct Transform {
@@ -1720,22 +1807,25 @@ transform方法对应一个变换矩阵,想对一个图形进行变化的时
### setTransform
-setTransform(scaleX: number, skewX: number, skewY: number, scale: number, translateX: number, translateY: number): void
+setTransform(a: number, b: number, c: number, d: number, e: number, f: number): void
setTransfrom方法使用的参数和transform()方法相同,但setTransform()方法会重置现有的变换矩阵并创建新的变换矩阵。
-- 参数
+**参数:**
+
| 参数 | 类型 | 必填 | 默认值 | 描述 |
| ---------- | ------ | ---- | ---- | -------- |
- | scaleX | number | 是 | 0 | 指定水平缩放值。 |
- | skewX | number | 是 | 0 | 指定水平倾斜值。 |
- | skewY | number | 是 | 0 | 指定垂直倾斜值。 |
- | scaleY | number | 是 | 0 | 指定垂直缩放值。 |
- | translateX | number | 是 | 0 | 指定水平移动值。 |
- | translateY | number | 是 | 0 | 指定垂直移动值。 |
-
-- 示例
- ```
+ | a | number | 是 | 0 |scaleX: 指定水平缩放值。 |
+ | b | number | 是 | 0 |skewX: 指定水平倾斜值。 |
+ | c | number | 是 | 0 |skewY: 指定垂直倾斜值。 |
+ | d | number | 是 | 0 |scaleY: 指定垂直缩放值。 |
+ | e | number | 是 | 0 |translateX: 指定水平移动值。 |
+ | f | number | 是 | 0 |translateY: 指定垂直移动值。 |
+
+ **示例:**
+
+ ```ts
+ // xxx.ets
@Entry
@Component
struct SetTransform {
@@ -1773,14 +1863,17 @@ translate(x: number, y: number): void
移动当前坐标系的原点。
-- 参数
+ **参数:**
+
| 参数 | 类型 | 必填 | 默认值 | 描述 |
| ---- | ------ | ---- | ---- | -------- |
| x | number | 是 | 0 | 设置水平平移量。 |
| y | number | 是 | 0 | 设置竖直平移量。 |
-- 示例
- ```
+ **示例:**
+
+ ```ts
+ // xxx.ets
@Entry
@Component
struct Translate {
@@ -1814,28 +1907,31 @@ translate(x: number, y: number): void
drawImage(image: ImageBitmap | PixelMap, dx: number, dy: number): void
-drawImage(image: ImageBitmap | PixelMap, dx: number, dy: number, dWidth: number, dHeight: number): void
+drawImage(image: ImageBitmap | PixelMap, dx: number, dy: number, dw: number, dh: number): void
-drawImage(image: ImageBitmap | PixelMap, sx: number, sy: number, sWidth: number, sHeight: number, dx: number, dy: number, dWidth: number, dHeight: number):void
+drawImage(image: ImageBitmap | PixelMap, sx: number, sy: number, sw: number, sh: number, dx: number, dy: number, dw: number, dh: number):void
进行图像绘制。
-- 参数
+ **参数:**
+
| 参数 | 类型 | 必填 | 默认值 | 描述 |
| ------- | ---------------------------------------- | ---- | ---- | -------------------- |
| image | [ImageBitmap](ts-components-canvas-imagebitmap.md) 或[PixelMap](../apis/js-apis-image.md#pixelmap7)| 是 | null | 图片资源,请参考ImageBitmap或PixelMap。 |
| sx | number | 否 | 0 | 裁切源图像时距离源图像左上角的x坐标值。 |
| sy | number | 否 | 0 | 裁切源图像时距离源图像左上角的y坐标值。 |
- | sWidth | number | 否 | 0 | 裁切源图像时需要裁切的宽度。 |
- | sHeight | number | 否 | 0 | 裁切源图像时需要裁切的高度。 |
+ | sw | number | 否 | 0 | 裁切源图像时需要裁切的宽度。 |
+ | sh | number | 否 | 0 | 裁切源图像时需要裁切的高度。 |
| dx | number | 是 | 0 | 绘制区域左上角在x轴的位置。 |
| dy | number | 是 | 0 | 绘制区域左上角在y 轴的位置。 |
- | dWidth | number | 否 | 0 | 绘制区域的宽度。 |
- | dHeight | number | 否 | 0 | 绘制区域的高度。 |
+ | dw | number | 否 | 0 | 绘制区域的宽度。 |
+ | dh | number | 否 | 0 | 绘制区域的高度。 |
-- 示例
- ```
+ **示例:**
+
+ ```ts
+ // xxx.ets
@Entry
@Component
struct Index {
@@ -1866,34 +1962,44 @@ drawImage(image: ImageBitmap | PixelMap, sx: number, sy: number, sWidth: number,
### createImageData
-createImageData(width: number, height: number): Object
+createImageData(sw: number, sh: number): ImageData
根据宽高创建ImageData对象,请参考[ImageData](ts-components-canvas-imagebitmap.md)。
-- 参数
+ **参数:**
+
| 参数 | 类型 | 必填 | 默认 | 描述 |
| ------ | ------ | ---- | ---- | ------------- |
- | width | number | 是 | 0 | ImageData的宽度。 |
- | height | number | 是 | 0 | ImageData的高度。 |
+ | sw | number | 是 | 0 | ImageData的宽度。 |
+ | sh | number | 是 | 0 | ImageData的高度。 |
### createImageData
-createImageData(imageData: ImageData): Object
+createImageData(imageData: ImageData): ImageData
根据已创建的ImageData对象创建新的ImageData对象,请参考[ImageData](ts-components-canvas-imagebitmap.md)。
-- 参数
+ **参数:**
+
| 参数 | 类型 | 必填 | 默认 | 描述 |
| --------- | ---------------------------------------- | ---- | ---- | ---------------- |
| imagedata | [ImageData](ts-components-canvas-imagebitmap.md) | 是 | null | 被复制的ImageData对象。 |
+ **返回值:**
+
+ | 类型 | 说明 |
+ | ---------- | ---------------------------------------- |
+ | [ImageData](ts-components-canvas-imagebitmap.md) | 新的ImageData对象 |
+
### getPixelMap
getPixelMap(sx: number, sy: number, sw: number, sh: number): PixelMap
以当前canvas指定区域内的像素创建[PixelMap](../apis/js-apis-image.md#pixelmap7)对象。
-- 参数
+
+ **参数:**
+
| 参数 | 类型 | 必填 | 默认值 | 描述 |
| -------- | -------- | -------- | -------- | -------- |
| sx | number | 是 | 0 | 需要输出的区域的左上角x坐标。 |
@@ -1901,13 +2007,21 @@ getPixelMap(sx: number, sy: number, sw: number, sh: number): PixelMap
| sw | number | 是 | 0 | 需要输出的区域的宽度。 |
| sh | number | 是 | 0 | 需要输出的区域的高度。 |
+**返回值:**
+
+ | 类型 | 说明 |
+ | ---------- | ---------------------------------------- |
+ | [PixelMap](../apis/js-apis-image.md#pixelmap7) | 新的PixelMap对象 |
+
+
### getImageData
-getImageData(sx: number, sy: number, sw: number, sh: number): Object
+getImageData(sx: number, sy: number, sw: number, sh: number): ImageData
以当前canvas指定区域内的像素创建[ImageData](ts-components-canvas-imagebitmap.md)对象。
-- 参数
+ **参数:**
+
| 参数 | 类型 | 必填 | 默认值 | 描述 |
| ---- | ------ | ---- | ---- | --------------- |
| sx | number | 是 | 0 | 需要输出的区域的左上角x坐标。 |
@@ -1915,14 +2029,23 @@ getImageData(sx: number, sy: number, sw: number, sh: number): Object
| sw | number | 是 | 0 | 需要输出的区域的宽度。 |
| sh | number | 是 | 0 | 需要输出的区域的高度。 |
+ **返回值:**
+
+ | 类型 | 说明 |
+ | ---------- | ---------------------------------------- |
+ | [ImageData](ts-components-canvas-imagebitmap.md) | 新的ImageData对象 |
+
### putImageData
-putImageData(imageData: Object, dx: number, dy: number, dirtyX?: number, dirtyY?: number, dirtyWidth?: number, dirtyHeight?: number): void
+putImageData(imageData: Object, dx: number, dy: number): void
+
+putImageData(imageData: Object, dx: number, dy: number, dirtyX: number, dirtyY: number, dirtyWidth?: number, dirtyHeight: number): void
使用[ImageData](ts-components-canvas-imagebitmap.md)数据填充新的矩形区域。
-- 参数
+ **参数:**
+
| 参数 | 类型 | 必填 | 默认值 | 描述 |
| ----------- | ------ | ---- | ------------ | ----------------------------- |
| imagedata | Object | 是 | null | 包含像素值的ImageData对象。 |
@@ -1933,8 +2056,10 @@ putImageData(imageData: Object, dx: number, dy: number, dirtyX?: number, dirtyY?
| dirtyWidth | number | 否 | imagedata的宽度 | 源图像数据矩形裁切范围的宽度。 |
| dirtyHeight | number | 否 | imagedata的高度 | 源图像数据矩形裁切范围的高度。 |
-- 示例
- ```
+ **示例:**
+
+ ```ts
+ // xxx.ets
@Entry
@Component
struct PutImageData {
@@ -1968,6 +2093,225 @@ putImageData(imageData: Object, dx: number, dy: number, dirtyX?: number, dirtyY?
![zh-cn_image_0000001194192464](figures/zh-cn_image_0000001194192464.png)
+### setLineDash
+
+setLineDash(segments: number[]): void
+
+设置画布的虚线样式。
+
+**参数:**
+
+| 参数 | 类型 | 描述 |
+| -------- | ----- | -------------------- |
+| segments | number[] | 描述线段如何交替和线段间距长度的数组。 |
+
+**示例:**
+
+ ```ts
+@Entry
+@Component
+struct SetLineDash {
+ private settings: RenderingContextSettings = new RenderingContextSettings(true)
+ private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
+ private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings)
+
+ build() {
+ Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
+ Canvas(this.context)
+ .width('100%')
+ .height('100%')
+ .backgroundColor('#ffff00')
+ .onReady(() =>{
+ this.offContext.arc(100, 75, 50, 0, 6.28)
+ this.offContext.setLineDash([10,20])
+ this.offContext.stroke();
+ var image = this.offContext.transferToImageBitmap()
+ this.context.transferFromImageBitmap(image)
+ })
+ }
+ .width('100%')
+ .height('100%')
+ }
+}
+ ```
+ ![zh-cn_image_000000127777772](figures/zh-cn_image_000000127777772.png)
+
+
+### getLineDash
+
+getLineDash(): number[]
+
+获得当前画布的虚线样式。
+
+**返回值:**
+
+| 类型 | 说明 |
+| ----- | ------------------------ |
+| number[] | 返回数组,该数组用来描述线段如何交替和间距长度。 |
+
+**示例:**
+
+ ```ts
+ // xxx.ets
+ @Entry
+ @Component
+ struct GetLineDash {
+ private settings: RenderingContextSettings = new RenderingContextSettings(true)
+ private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
+ private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings)
+
+ build() {
+ Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
+ Canvas(this.context)
+ .width('100%')
+ .height('100%')
+ .backgroundColor('#ffff00')
+ .onReady(() =>{
+ var grad = this.context.createLinearGradient(50,0, 300,100)
+ this.offContext.arc(100, 75, 50, 0, 6.28)
+ this.offContext.setLineDash([10,20])
+ this.offContext.stroke();
+ let res = this.offContext.getLineDash()
+ var image = this.offContext.transferToImageBitmap()
+ this.context.transferFromImageBitmap(image)
+ })
+ }
+ .width('100%')
+ .height('100%')
+ }
+ }
+ ```
+
+
+### transferFromImageBitmap
+
+transferFromImageBitmap(bitmap: ImageBitmap): void
+
+显示给定的ImageBitmap对象。
+
+**参数:**
+
+| 参数 | 类型 | 描述 |
+| ------ | ----------- | ------------------ |
+| bitmap | [ImageData](ts-components-canvas-imagebitmap.md) | 待显示的ImageBitmap对象。 |
+
+**示例:**
+
+ ```ts
+ // xxx.ets
+ @Entry
+ @Component
+ struct GetLineDash {
+ private settings: RenderingContextSettings = new RenderingContextSettings(true)
+ private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
+ private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings)
+
+ build() {
+ Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
+ Canvas(this.context)
+ .width('100%')
+ .height('100%')
+ .backgroundColor('#ffff00')
+ .onReady(() =>{
+ this.offContext.fillRect(0, 0, 200, 200)
+ var image = this.offContext.transferToImageBitmap()
+ this.context.transferFromImageBitmap(image)
+ })
+ }
+ .width('100%')
+ .height('100%')
+ }
+ }
+ ```
+ ![zh-cn_image_000000127777773](figures/zh-cn_image_000000127777773.png)
+
+### toDataURL
+
+toDataURL(type?: string, quality?: number): string
+
+生成一个包含图片展示的URL。
+
+**参数:**
+
+| 参数名 | 参数类型 | 必填 | 描述 |
+| ------- | ------ | ---- | ---------------------------------------- |
+| type | string | 否 | 可选参数,用于指定图像格式,默认格式为image/png。 |
+| quality | number | 否 | 在指定图片格式为image/jpeg或image/webp的情况下,可以从0到1的区间内选择图片的质量。如果超出取值范围,将会使用默认值0.92。 |
+
+**返回值:**
+
+| 类型 | 说明 |
+| ------ | --------- |
+| string | 图像的URL地址。 |
+
+**示例:**
+
+ ```ts
+ // xxx.ets
+@Entry
+@Component
+struct ToDataURL {
+ private settings: RenderingContextSettings = new RenderingContextSettings(true)
+ private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
+ private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings)
+
+ build() {
+ Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
+ Canvas(this.context)
+ .width('100%')
+ .height('100%')
+ .backgroundColor('#ffff00')
+ .onReady(() =>{
+ var dataURL = this.offContext.toDataURL();
+ })
+ }
+ .width('100%')
+ .height('100%')
+ }
+}
+ ```
+
+
+### transferToImageBitmap
+
+transferToImageBitmap(): ImageBitmap
+
+在离屏画布最近渲染的图像上创建一个ImageBitmap对象。
+
+**返回值:**
+
+| 类型 | 说明 |
+| ---------------------------------------- | --------------- |
+| [ImageData](ts-components-canvas-imagebitmap.md)| 存储离屏画布上渲染的像素数据。 |
+
+
+ **示例:**
+
+ ```ts
+ // xxx.ets
+ @Entry
+ @Component
+ struct CanvasExample {
+ private settings: RenderingContextSettings = new RenderingContextSettings(true)
+ private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
+ private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings)
+ build() {
+ Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
+ Canvas(this.context)
+ .width('100%')
+ .height('100%')
+ .backgroundColor('#ffff00')
+ .onReady(() =>{
+ this.offContext.restore()
+ var image = this.offContext.transferToImageBitmap()
+ this.context.transferFromImageBitmap(image)
+ })
+ }
+ .width('100%')
+ .height('100%')
+ }
+ }
+ ```
### restore
@@ -1975,8 +2319,10 @@ restore(): void
对保存的绘图上下文进行恢复。
-- 示例
- ```
+ **示例:**
+
+ ```ts
+ // xxx.ets
@Entry
@Component
struct CanvasExample {
@@ -2008,8 +2354,10 @@ save(): void
对当前的绘图上下文进行保存。
-- 示例
- ```
+ **示例:**
+
+ ```ts
+ // xxx.ets
@Entry
@Component
struct CanvasExample {
@@ -2041,7 +2389,8 @@ createLinearGradient(x0: number, y0: number, x1: number, y1: number): void
创建一个线性渐变色。
-- 参数
+ **参数:**
+
| 参数 | 类型 | 必填 | 默认值 | 描述 |
| ---- | ------ | ---- | ---- | -------- |
| x0 | number | 是 | 0 | 起点的x轴坐标。 |
@@ -2049,8 +2398,10 @@ createLinearGradient(x0: number, y0: number, x1: number, y1: number): void
| x1 | number | 是 | 0 | 终点的x轴坐标。 |
| y1 | number | 是 | 0 | 终点的y轴坐标。 |
-- 示例
- ```
+ **示例:**
+
+ ```ts
+ // xxx.ets
@Entry
@Component
struct CreateLinearGradient {
@@ -2090,7 +2441,8 @@ createRadialGradient(x0: number, y0: number, r0: number, x1: number, y1: number,
创建一个径向渐变色。
-- 参数
+ **参数:**
+
| 参数 | 类型 | 必填 | 默认值 | 描述 |
| ---- | ------ | ---- | ---- | ----------------- |
| x0 | number | 是 | 0 | 起始圆的x轴坐标。 |
@@ -2100,8 +2452,10 @@ createRadialGradient(x0: number, y0: number, r0: number, x1: number, y1: number,
| y1 | number | 是 | 0 | 终点圆的y轴坐标。 |
| r1 | number | 是 | 0 | 终点圆的半径。必须为非负且有限的。 |
-- 示例
- ```
+ **示例:**
+
+ ```ts
+ // xxx.ets
@Entry
@Component
struct CreateRadialGradient {
diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-universal-events-key.md b/zh-cn/application-dev/reference/arkui-ts/ts-universal-events-key.md
index 09498cc8ea25edbd6770891c8b2881f558ac71cc..e25e4e76fdf9a41d9c947f05b6a35be53b5fe35a 100644
--- a/zh-cn/application-dev/reference/arkui-ts/ts-universal-events-key.md
+++ b/zh-cn/application-dev/reference/arkui-ts/ts-universal-events-key.md
@@ -21,23 +21,16 @@
## KeyEvent对象说明
-### 属性
-
-| 属性名称 | 类型 | 描述 |
-| ------------------------------------- | --------------------------- | -------------------------- |
-| type | [KeyType](ts-appendix-enums.md#keytype) | 按键的类型。 |
-| [keyCode](../apis/js-apis-keycode.md) | number | 按键的键码。 |
-| keyText | string | 按键的键值。 |
-| keySource | [KeySource](ts-appendix-enums.md#keysource) | 触发当前按键的输入设备类型。 |
-| deviceId | number | 触发当前按键的输入设备ID。 |
-| metaKey | number | 按键发生时元键的状态,1表示按压态,0表示未按压态。 |
-| timestamp | number | 按键发生时的时间戳。 |
-
-### 接口
-
-| 接口名称 | 功能描述 |
-| ---------------------------- | --------- |
-| stopPropagation(): void | 阻塞事件冒泡传递。 |
+ | 名称 | 类型 | 描述 |
+ | ------------------------------------- | --------------------------- | -------------------------- |
+ | type | [KeyType](ts-appendix-enums.md#keytype) | 按键的类型。 |
+ | [keyCode](../apis/js-apis-keycode.md) | number | 按键的键码。 |
+ | keyText | string | 按键的键值。 |
+ | keySource | [KeySource](ts-appendix-enums.md#keysource) | 触发当前按键的输入设备类型。 |
+ | deviceId | number | 触发当前按键的输入设备ID。 |
+ | metaKey | number | 按键发生时元键的状态,1表示按压态,0表示未按压态。 |
+ | timestamp | number | 按键发生时的时间戳。 |
+ | stopPropagation | () => void | 阻塞事件冒泡传递。 |
## 示例
diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-universal-events-touch.md b/zh-cn/application-dev/reference/arkui-ts/ts-universal-events-touch.md
index 508837cd92455f5408800d076e530833d2a25358..9f94105c21c5eee879c1ce401df723112bfe6086 100644
--- a/zh-cn/application-dev/reference/arkui-ts/ts-universal-events-touch.md
+++ b/zh-cn/application-dev/reference/arkui-ts/ts-universal-events-touch.md
@@ -14,24 +14,20 @@
## TouchEvent对象说明
-### 属性
+ | 名称 | 类型 | 描述 |
+ | ------------------- | ---------------------------------------- | ------------ |
+ | type | [TouchType](ts-appendix-enums.md#touchtype) | 触摸事件的类型。 |
+ | touches | Array<[TouchObject](#touchobject对象说明)> | 全部手指信息。 |
+ | changedTouches | Array<[TouchObject](#touchobject对象说明)> | 当前发生变化的手指信息。 |
+ | stopPropagation | () => void | 阻塞事件冒泡。 |
+ | timestamp8+ | number | 事件时间戳。 |
+ | target8+ | [EventTarget](ts-universal-events-click.md) | 触发手势事件的元素对象显示区域。 |
+ | source8+ | [SourceType](ts-gesture-settings.md) | 事件输入设备。 |
-| 属性名称 | 类型 | 描述 |
-| ------------------- | ------------------------------------------------------------ | ---------------------------------- |
-| type | [TouchType](ts-appendix-enums.md#touchtype) | 触摸事件的类型。 |
-| touches | Array<[TouchObject](#touchobject对象说明)> | 全部手指信息。 |
-| changedTouches | Array<[TouchObject](#touchobject对象说明)> | 当前发生变化的手指信息。 |
-| timestamp | number | 距离开机时间的时间戳,单位为毫秒。 |
-| target8+ | [EventTarget](ts-universal-events-click.md#eventtarget8对象说明) | 被触摸元素对象。 |
-
-### 接口
-
-| 接口名称 | 功能描述 |
-| ---------------------- | ------- |
-| stopPropagation():void | 阻塞事件冒泡。 |
## TouchObject对象说明
-| 属性名称 | 类型 | 描述 |
+
+| 名称 | 类型 | 描述 |
| ------- | --------------------------- | ------------------- |
| type | [TouchType](ts-appendix-enums.md#touchtype) | 触摸事件的类型。 |
| id | number | 手指唯一标识符。 |
diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-universal-mouse-key.md b/zh-cn/application-dev/reference/arkui-ts/ts-universal-mouse-key.md
index e0a3a5d3a57e2f0897cb6c8216ca7fabfbb4b2e9..2264ace64b057a1b55edc3d52c4e84d8a28d0fa6 100644
--- a/zh-cn/application-dev/reference/arkui-ts/ts-universal-mouse-key.md
+++ b/zh-cn/application-dev/reference/arkui-ts/ts-universal-mouse-key.md
@@ -14,15 +14,19 @@
## MouseEvent对象说明
-| 属性名称 | 属性类型 | 描述 |
+
+| 名称 | 属性类型 | 描述 |
| --------- | ------------------------------- | -------------------- |
-| timestamp | number | 触发事件时的时间戳。 |
| screenX | number | 点击触点相对于屏幕左上角的x轴坐标。 |
| screenY | number | 点击触点相对于屏幕左上角的y轴坐标。 |
| x | number | 点击触点相对于当前组件左上角的x轴坐标。 |
| y | number | 点击触点相对于当前组件左上角的y轴坐标。 |
| button | [MouseButton](ts-appendix-enums.md#mousebutton) | 鼠标按键。 |
| action | [MouseAction](ts-appendix-enums.md#mouseaction) | 事件动作。 |
+| stopPropagation | () => void | 阻塞事件冒泡。 |
+| timestamp8+ | number | 事件时间戳。 |
+| target8+ | [EventTarget](ts-universal-events-click.md) | 触发手势事件的元素对象显示区域。 |
+| source8+ | [SourceType](ts-gesture-settings.md) | 事件输入设备。 |
## 示例