提交 4a117f44 编写于 作者: G ge-yafang

update docs

Signed-off-by: Nge-yafang <geyafang@huawei.com>
上级 93eda80d
# Using Native APIs in Application Projects
OpenHarmony applications use JavaScript (JS) when calling native APIs. The native APIs (NAPIs) provided by the **arkui_napi** repository are used to implement the interaction with JS. Currently, the **arkui_napi** repository supports some third-party **Node.js** interfaces. The names of the NAPIs are the same as those in the third-party **Node.js**. For details about the interfaces supported, see `libnapi.ndk.json` in this repository.
## How to Develop
The IDE has a default project that uses NAPIs. You can choose `File` > `New` > `Create Project` to create a `Native C++` project. The **cpp** directory is generated in the **main** directory. You can use the NAPIs provided by the **arkui_napi** repository for development.
You can `import` the native .so that contains the JS processing logic. For example, `import hello from 'libhello.so'` to use the **libhello.so** capability. Then, the JS object created using the NAPI can be passed to the `hello` object of the application to call the native capability.
## Development Guidelines
### Registration
* Add **static** to the **nm_register_func** function to prevent symbol conflicts with other .so files.
* The name of the module registration entry, that is, the function decorated by **\_\_attribute\_\_((constructor))**, must be unique.
### .so Naming Rules
Each module has a .so file. For example, if the module name is `hello`, name the .so file **libhello.so**. The `nm_modname` field in `napi_module` must be `hello`, which is the same as the module name. The sample code for importing the .so file is `import hello from 'libhello.so'`.
### JS Objects and Threads
The Ark engine prevents NAPIs from being called to operate JS objects in non-JS threads. Otherwise, the application will crash.
* The NAPIs can be used only in JS threads.
* **env** is bound to a thread and cannot be used across threads. The JS object created by a NAPI can be used only in the thread, in which the object is created, that is, the JS object is bound to the **env** of the thread.
### napi_create_async_work
**napi_create_async_work** has two callbacks:
* **execute**: processes service logic asynchronously. This callback is not executed by a JS thread; therefore, it cannot call any NAPI. The return value of **execute** is processed by the **complete** callback.
* **complete**: calls the NAPI to encapsulate the return value of **execute** into a JS object and return it for processing. This callback is executed by a JS thread.
```c++
napi_status napi_create_async_work(napi_env env,
napi_value async_resource,
napi_value async_resource_name,
napi_async_execute_callback execute,
napi_async_complete_callback complete,
void* data,
napi_async_work* result)
```
## Example 1: Encapsulating Synchronous and Asynchronous APIs for the Storage Module
### Overview
This example shows how to encapsulate the synchronous and asynchronous APIs of the storage module. The storage module implements the functions of storing, obtaining, deleting, and clearing data.
### API Declaration
```typescript
import { AsyncCallback } from './basic';
declare namespace storage {
function get(key: string, callback: AsyncCallback<string>): void;
function get(key: string, defaultValue: string, callback: AsyncCallback<string>): void;
function get(key: string, defaultValue?: string): Promise<string>;
function set(key: string, value: string, callback: AsyncCallback<string>): void;
function remove(key: string, callback: AsyncCallback<void>): void;
function clear(callback: AsyncCallback<void>): void;
function getSync(key: string, defaultValue?: string): string;
function setSync(key: string, value: string): void;
function removeSync(key: string): void;
function clearClear(): void;
}
export default storage;
```
### Implementation
You can obtain the complete code from `sample/native_module_storage/` in the **arkui_napi** repository.
#### Registering the Module
Register four synchronous APIs (`getSync`, `setSync`, `removeSync`, and`clearSync`) and four asynchronous APIs (`get`, `set`, `remove`, and `clear`).
```c++
/***********************************************
* Module export and register
***********************************************/
static napi_value StorgeExport(napi_env env, napi_value exports)
{
napi_property_descriptor desc[] = {
DECLARE_NAPI_FUNCTION("get", JSStorageGet),
DECLARE_NAPI_FUNCTION("set", JSStorageSet),
DECLARE_NAPI_FUNCTION("remove", JSStorageDelete),
DECLARE_NAPI_FUNCTION("clear", JSStorageClear),
DECLARE_NAPI_FUNCTION("getSync", JSStorageGetSync),
DECLARE_NAPI_FUNCTION("setSync", JSStorageSetSync),
DECLARE_NAPI_FUNCTION("deleteSync", JSStorageDeleteSync),
DECLARE_NAPI_FUNCTION("clearSync", JSStorageClearSync),
};
NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc));
return exports;
}
// Storage module
static napi_module storage_module = {.nm_version = 1,
.nm_flags = 0,
.nm_filename = nullptr,
.nm_register_func = StorgeExport,
.nm_modname = "storage",
.nm_priv = ((void*)0),
.reserved = {0}};
// Register the storage module
extern "C" __attribute__((constructor)) void StorageRegister()
{
napi_module_register(&storage_module);
}
```
#### Implementing getSync
The **getSync** function registered for the storage module is **JSStorageGetSync**. Obtain data from `gKeyValueStorage`, create a string object, and return it.
```c
static napi_value JSStorageGetSync(napi_env env, napi_callback_info info)
{
GET_PARAMS(env, info, 2);
NAPI_ASSERT(env, argc >= 1, "requires 1 parameter");
char key[32] = {0};
size_t keyLen = 0;
char value[128] = {0};
size_t valueLen = 0;
// Parse parameters.
for (size_t i = 0; i < argc; i++) {
napi_valuetype valueType;
napi_typeof(env, argv[i], &valueType);
if (i == 0 && valueType == napi_string) {
napi_get_value_string_utf8(env, argv[i], key, 31, &keyLen);
} else if (i == 1 && valueType == napi_string) {
napi_get_value_string_utf8(env, argv[i], value, 127, &valueLen);
break;
} else {
NAPI_ASSERT(env, false, "type mismatch");
}
}
// Service logic for obtaining data. This example simply obtains data from a global variable.
auto itr = gKeyValueStorage.find(key);
napi_value result = nullptr;
if (itr != gKeyValueStorage.end()) {
// Use the data obtained to create a JS object of the string type.
napi_create_string_utf8(env, itr->second.c_str(), itr->second.length(), &result);
} else if (valueLen > 0) {
// If no data is obtained, use the default value to create a JS object.
napi_create_string_utf8(env, value, valueLen, &result);
} else {
NAPI_ASSERT(env, false, "key does not exist");
}
// Return the result.
return result;
}
```
#### Implementing get
The `get` function registered for the storage module is `JSStorageGet`.
```c
static napi_value JSStorageGet(napi_env env, napi_callback_info info)
{
GET_PARAMS(env, info, 3);
NAPI_ASSERT(env, argc >= 1, "requires 1 parameter");
// StorageAsyncContext is a custom class used to store data during execution.
StorageAsyncContext* asyncContext = new StorageAsyncContext();
asyncContext->env = env;
// Obtain parameters.
for (size_t i = 0; i < argc; i++) {
napi_valuetype valueType;
napi_typeof(env, argv[i], &valueType);
if (i == 0 && valueType == napi_string) {
napi_get_value_string_utf8(env, argv[i], asyncContext->key, 31, &asyncContext->keyLen);
} else if (i == 1 && valueType == napi_string) {
napi_get_value_string_utf8(env, argv[i], asyncContext->value, 127, &asyncContext->valueLen);
} else if (i == 1 && valueType == napi_function) {
napi_create_reference(env, argv[i], 1, &asyncContext->callbackRef);
break;
} else if (i == 2 && valueType == napi_function) {
napi_create_reference(env, argv[i], 1, &asyncContext->callbackRef);
} else {
NAPI_ASSERT(env, false, "type mismatch");
}
}
napi_value result = nullptr;
// Determine whether promise or callback is used based on the parameters.
if (asyncContext->callbackRef == nullptr) {
// Create a promise.
napi_create_promise(env, &asyncContext->deferred, &result);
} else {
napi_get_undefined(env, &result);
}
napi_value resource = nullptr;
napi_create_string_utf8(env, "JSStorageGet", NAPI_AUTO_LENGTH, &resource);
napi_create_async_work(
env, nullptr, resource,
// Callback 1: This callback contains the service logic to be asynchronously executed and is asynchronously executed by the NAPI. Do not operate JS objects using theNAPI because the execution is asynchronous.
[](napi_env env, void* data) {
StorageAsyncContext* asyncContext = (StorageAsyncContext*)data;
auto itr = gKeyValueStorage.find(asyncContext->key);
if (itr != gKeyValueStorage.end()) {
strncpy_s(asyncContext->value, 127, itr->second.c_str(), itr->second.length());
asyncContext->status = 0;
} else {
asyncContext->status = 1;
}
},
// Callback 2: This callback is invoked after callback 1 is complete. The JS thread invokes the callback passed in.
[](napi_env env, napi_status status, void* data) {
StorageAsyncContext* asyncContext = (StorageAsyncContext*)data;
napi_value result[2] = {0};
if (!asyncContext->status) {
napi_get_undefined(env, &result[0]);
napi_create_string_utf8(env, asyncContext->value, strlen(asyncContext->value), &result[1]);
} else {
napi_value message = nullptr;
napi_create_string_utf8(env, "key does not exist", NAPI_AUTO_LENGTH, &message);
napi_create_error(env, nullptr, message, &result[0]);
napi_get_undefined(env, &result[1]);
}
if (asyncContext->deferred) {
// If a promise is used, check the result of callback 1.
if (!asyncContext->status) {
// Triggered when callback 1 is successful (status is 1), that is, to invoke the callback passed in then in the promise.
napi_resolve_deferred(env, asyncContext->deferred, result[1]);
} else {
// Triggered when callback 1 fails (status is 0), that is, to invoke the callback passed in catch in the promise.
napi_reject_deferred(env, asyncContext->deferred, result[0]);
}
} else {
// If a callback is used, use napi_call_function to invoke the callback to return the result.
napi_value callback = nullptr;
napi_value returnVal;
napi_get_reference_value(env, asyncContext->callbackRef, &callback);
napi_call_function(env, nullptr, callback, 2, result, &returnVal);
napi_delete_reference(env, asyncContext->callbackRef);
}
napi_delete_async_work(env, asyncContext->work);
delete asyncContext;
},
(void*)asyncContext, &asyncContext->work);
napi_queue_async_work(env, asyncContext->work);
return result;
}
```
### JS Sample Code
```js
import storage from 'libstorage.so';
export default {
testGetSync() {
const name = storage.getSync('name');
console.log('name is ' + name);
},
testGet() {
storage.get('name')
.then(date => {
console.log('name is ' + data);
})
.catch(error => {
console.log('error: ' + error);
});
}
}
```
## Example 2: Binding Native and JS Objects for the NetServer Module
### Overview
This example shows how to implement the `on/off/once` method and bind C++ and JS objects using the **wrap** API. The NetServer module implements the network service.
### API Declaration
```typescript
export class NetServer {
function start(port: number): void;
function stop(): void;
function on('start' | 'stop', callback: Function): void;
function once('start' | 'stop', callback: Function): void;
function off('start' | 'stop', callback: Function): void;
}
```
### Implementation
You can obtain the complete code from `sample/native_module_netserver/` in the **arkui_napi** repository.
#### Registering the Module
```c
static napi_value NetServer::Export(napi_env env, napi_value exports)
{
const char className[] = "NetServer";
napi_property_descriptor properties[] = {
DECLARE_NAPI_FUNCTION("start", JS_Start),
DECLARE_NAPI_FUNCTION("stop", JS_Stop),
DECLARE_NAPI_FUNCTION("on", JS_On),
DECLARE_NAPI_FUNCTION("once", JS_Once),
DECLARE_NAPI_FUNCTION("off", JS_Off),
};
napi_value netServerClass = nullptr;
napi_define_class(env, className, sizeof(className), JS_Constructor, nullptr, countof(properties), properties,
&netServerClass);
napi_set_named_property(env, exports, "NetServer", netServerClass);
return exports;
}
```
#### Binding C++ and JS Objects in a Constructor
```c
napi_value NetServer::JS_Constructor(napi_env env, napi_callback_info cbinfo)
{
napi_value thisVar = nullptr;
void* data = nullptr;
napi_get_cb_info(env, cbinfo, nullptr, nullptr, &thisVar, &data);
// C++ native object to be mapped to the JS object.
NetServer* netServer = new NetServer(env, thisVar);
// Use napi_wrap to bind netServer and thisVar (JS object created).
napi_wrap(
env, thisVar, netServer,
// The JS object is automatically released by the engine. When the JS object is released, the callback is triggered to release netServer.
[](napi_env env, void* data, void* hint) {
printf("NetServer::Destructor\n");
NetServer* netServer = (NetServer*)data;
delete netServer;
},
nullptr, nullptr);
return thisVar;
}
```
#### Obtaining the C++ Object from the JS Object
```c
napi_value NetServer::JS_Start(napi_env env, napi_callback_info cbinfo)
{
size_t argc = 1;
napi_value argv[1] = {0};
napi_value thisVar = nullptr;
void* data = nullptr;
napi_get_cb_info(env, cbinfo, &argc, argv, &thisVar, &data);
NetServer* netServer = nullptr;
// Obtain the C++ object from thisVar using napi_unwrap.
napi_unwrap(env, thisVar, (void**)&netServer);
NAPI_ASSERT(env, argc >= 1, "requires 1 parameter");
napi_valuetype valueType;
napi_typeof(env, argv[0], &valueType);
NAPI_ASSERT(env, valueType == napi_number, "type mismatch for parameter 1");
int32_t port = 0;
napi_get_value_int32(env, argv[0], &port);
// Start the netServer service.
netServer->Start(port);
napi_value result = nullptr;
napi_get_undefined(env, &result);
return result;
}
```
After `netServer->Start` is executed, call back the `start` event registered by `on`.
```c
int NetServer::Start(int port)
{
printf("NetServer::Start thread_id: %ld \n", uv_thread_self());
struct sockaddr_in addr;
int r;
uv_ip4_addr("0.0.0.0", port, &addr);
r = uv_tcp_init(loop_, &tcpServer_);
if (r) {
fprintf(stderr, "Socket creation error\n");
return 1;
}
r = uv_tcp_bind(&tcpServer_, (const struct sockaddr*)&addr, 0);
if (r) {
fprintf(stderr, "Bind error\n");
return 1;
}
r = uv_listen((uv_stream_t*)&tcpServer_, SOMAXCONN, OnConnection);
if (r) {
fprintf(stderr, "Listen error %s\n", uv_err_name(r));
return 1;
}
// Trigger the start event after the service is started.
Emit("start", nullptr);
return 0;
}
```
#### Registering Events (on)
```c
napi_value NetServer::JS_On(napi_env env, napi_callback_info cbinfo)
{
size_t argc = 2;
napi_value argv[2] = {0};
napi_value thisVar = 0;
void* data = nullptr;
napi_get_cb_info(env, cbinfo, &argc, argv, &thisVar, &data);
NetServer* netServer = nullptr;
// Obtain the NetServer pointer using napi_unwrap.
napi_unwrap(env, thisVar, (void**)&netServer);
NAPI_ASSERT(env, argc >= 2, "requires 2 parameter");
// Verify the parameter type.
napi_valuetype eventValueType;
napi_typeof(env, argv[0], &eventValueType);
NAPI_ASSERT(env, eventValueType == napi_string, "type mismatch for parameter 1");
napi_valuetype eventHandleType;
napi_typeof(env, argv[1], &eventHandleType);
NAPI_ASSERT(env, eventHandleType == napi_function, "type mismatch for parameter 2");
char type[64] = {0};
size_t typeLen = 0;
napi_get_value_string_utf8(env, argv[0], type, 63, &typeLen);
// Register the event handler.
netServer->On((const char*)type, argv[1]);
napi_value result = nullptr;
napi_get_undefined(env, &result);
return result;
}
```
### JS Sample Code
```javascript
import { NetServer } from 'libnetserver.so';
export default {
testNetServer() {
var netServer = new NetServer();
netServer.on('start', (event) => {});
netServer.start(1000); // The port number is 1000. After start is executed, invoke the start callback registered.
}
}
```
## Example 3: Calling Back a JS API in a Non-JS Thread
### Overview
This example describes how to invoke a JS callback in a non-JS thread. For example, a sensor listener is registered for a JS application. The sensor data is reported by an SA. When the SA invokes the client through Inter-Process Communication (IPC), the execution thread is an IPC thread, which is different from the JS thread of the SA. In this case, the JS callback must be thrown to the JS thread to execute. Otherwise, the application will crash.
### Implementation
You can obtain the complete code from `sample/native_module_callback/` in the **arkui_napi** repository.
#### Registering the Module
Register the `test` API to pass in a parameter.
```c++
/***********************************************
* Module export and register
***********************************************/
static napi_value CallbackExport(napi_env env, napi_value exports)
{
static napi_property_descriptor desc[] = {
DECLARE_NAPI_FUNCTION("test", JSTest)
};
NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc));
return exports;
}
// Define the callback.
static napi_module callbackModule = {
.nm_version = 1,
.nm_flags = 0,
.nm_filename = nullptr,
.nm_register_func = CallbackExport,
.nm_modname = "callback",
.nm_priv = ((void*)0),
.reserved = { 0 },
};
// Register the callback.
extern "C" __attribute__((constructor)) void CallbackTestRegister()
{
napi_module_register(&callbackModule);
}
```
#### Obtaining the Loop in env and Throwing the Task to the JS Thread
```c++
#include <thread>
#include "napi/native_api.h"
#include "napi/native_node_api.h"
#include "uv.h"
struct CallbackContext {
napi_env env = nullptr;
napi_ref callbackRef = nullptr;
int retData = 0;
};
void callbackTest(CallbackContext* context)
{
uv_loop_s* loop = nullptr;
// Save the env when the JS callback is registered. Obtain the loop of the JS thread from env.
napi_get_uv_event_loop(context->env, &loop);
// Create uv_work_t to transfer private data (int type 1 in this example). Note that memory must be released after the callback is complete. The logic for generating the returned data is omitted here.
uv_work_t* work = new uv_work_t;
context->retData = 1;
work->data = (void*)context;
// Call the libuv API to throw the JS task to the loop for execution.
uv_queue_work(
loop,
work,
// This callback is executed in another common thread to process tasks asynchronously. After the callback is complete, execute the next callback. In this scenario, the callback does not need to execute any task.
[](uv_work_t* work) {},
// This callback is executed in the JS thread bound to env.
[](uv_work_t* work, int status) {
CallbackContext* context = (CallbackContext*)work->data;
napi_handle_scope scope = nullptr;
// Open the handle scope to manage the lifecycle of napi_value. Otherwise, memory leakage occurs.
napi_open_handle_scope(context->env, &scope);
if (scope == nullptr) {
return;
}
// Call the NAPIs.
napi_value callback = nullptr;
napi_get_reference_value(context->env, context->callbackRef, &callback);
napi_value retArg;
napi_create_int32(context->env, context->retData, &retArg);
napi_value ret;
napi_call_function(context->env, nullptr, callback, 1, &retArg, &ret);
napi_delete_reference(context->env, context->callbackRef);
// Close the handle scope to release napi_value.
napi_close_handle_scope(context->env, scope);
// Release the work pointer.
if (work != nullptr) {
delete work;
}
delete context;
}
);
}
static napi_value JSTest(napi_env env, napi_callback_info info)
{
size_t argc = 1;
napi_value argv[1] = { 0 };
napi_value thisVar = nullptr;
void* data = nullptr;
napi_get_cb_info(env, info, &argc, argv, &thisVar, &data);
// Obtain the first input parameter, that is, the callback to be invoked subsequently.
napi_valuetype valueType = napi_undefined;
napi_typeof(env, argv[0], &valueType);
if (valueType != napi_function) {
return nullptr;
}
// Save the env and callback for subsequent transfer.
auto asyncContext = new CallbackContext();
asyncContext->env = env;
napi_create_reference(env, argv[0], 1, &asyncContext->callbackRef);
// Simulate the logic for throwing a task to a non-JS thread.
std::thread testThread(callbackTest, asyncContext);
testThread.detach();
return nullptr;
}
```
### JS Sample Code
```js
import callback from 'libcallback.so';
export default {
testcallback() {
callback.test((data) => {
console.error('test result = ' + data)
})
}
}
```
......@@ -7,13 +7,14 @@
- [版本说明](../release-notes/Readme.md)
- 快速开始
- 快速入门
- [前言](quick-start/start-overview.md)
- [开发准备](quick-start/start-overview.md)
- [使用eTS语言开发(传统代码方式)](quick-start/start-with-ets.md)
- [使用eTS语言开发(低代码方式)](quick-start/start-with-ets-low-code.md)
- [使用JS语言开发(传统代码方式)](quick-start/start-with-js.md)
- [使用JS语言开发(低代码方式)](quick-start/start-with-js-low-code.md)
- 开发基础知识
- [应用包结构说明](quick-start/package-structure.md)
- [应用包结构说明(FA模型)](quick-start/package-structure.md)
- [应用包结构说明(Stage模型)](quick-start/stage-structure.md)
- [资源文件的分类](quick-start/basic-resource-file-categories.md)
- [SysCap说明](quick-start/syscap.md)
- 开发
......@@ -34,6 +35,7 @@
- [设备使用信息统计](device-usage-statistics/Readme-CN.md)
- [DFX](dfx/Readme-CN.md)
- [国际化](internationalization/Readme-CN.md)
- [Native API的相关指导](napi/Readme-CN.md)
- 工具
- [DevEco Studio(OpenHarmony)使用指南](quick-start/deveco-studio-user-guide-for-openharmony.md)
- 示例教程
......@@ -42,6 +44,11 @@
- API参考
- [组件参考(基于JS扩展的类Web开发范式)](reference/arkui-js/Readme-CN.md)
- [组件参考(基于TS扩展的声明式开发范式)](reference/arkui-ts/Readme-CN.md)
- [接口参考](reference/apis/Readme-CN.md)
- 接口
- [JS(含eTS) API参考](reference/apis/Readme-CN.md)
- Native API
- [OpenHarmony Native API](reference/native-apis/Readme-CN.md)
- [标准库](reference/native-lib/third_party_libc/musl.md)
- [Node_API](reference/native-lib/third_party_napi/napi.md)
- 贡献
- [参与贡献](../contribute/贡献文档.md)
......@@ -21,7 +21,7 @@ wantAgent封装了一个指定行为的意图,可以通过wantAgent.trigger接
import wantAgent from '@ohos.wantAgent';
```
2. 创建WantAgentInfo信息,详细的WantAgentInfo信息数据类型及包含的参数请见[WantAgentInfo文档](../reference/apis/js-apis-wantAgent.md#WantAgentInfo)介绍。
2. 创建WantAgentInfo信息,详细的WantAgentInfo信息数据类型及包含的参数请见[WantAgentInfo文档](../reference/apis/js-apis-wantAgent.md#wantagentinfo)介绍。
```javascript
private wantAgentObj = null //用于保存创建成功的wantAgent对象,后续使用其完成触发的动作
......
# Native API的相关指导
- [Native API在应用工程中的使用指导](napi-guidelines.md)
- [drawing开发指导](drawing-guidelines.md)
- [rawfile开发指导](rawfile-guidelines.md)
# drawing开发指导
## 场景介绍
native drawing模块提供了一系列的接口用于基本图形和字体的绘制。常见的应用场景举例:
* 2D图形绘制。
* 文本绘制和显示。
## 接口说明
| 接口名 | 描述 |
| -------- | -------- |
| OH_Drawing_BitmapCreate (void) | 创建一个位图对象。 |
| OH_Drawing_BitmapBuild (OH_Drawing_Bitmap *, const uint32_t width, const uint32_t height, const OH_Drawing_BitmapFormat *) | 初始化位图对象的宽度和高度,并且为该位图设置像素格式。 |
| OH_Drawing_CanvasCreate (void) | 创建一个画布对象。 |
| OH_Drawing_CanvasBind (OH_Drawing_Canvas *, OH_Drawing_Bitmap *) | 将一个位图对象绑定到画布中,使得画布绘制的内容输出到位图中(即CPU渲染)。 |
| OH_Drawing_CanvasAttachBrush (OH_Drawing_Canvas *, const OH_Drawing_Brush *) | 设置画刷给画布,画布将会使用设置的画刷样式和颜色去填充绘制的图形形状。 |
| OH_Drawing_CanvasAttachPen (OH_Drawing_Canvas *, const OH_Drawing_Pen *) | 设置画笔给画布,画布将会使用设置画笔的样式和颜色去绘制图形形状的轮廓。 |
| OH_Drawing_CanvasDrawPath (OH_Drawing_Canvas *, const OH_Drawing_Path *) | 画一个自定义路径。 |
| OH_Drawing_PathCreate (void) | 创建一个路径对象。 |
| OH_Drawing_PathMoveTo (OH_Drawing_Path *, float x, float y) | 设置自定义路径的起始点位置。 |
| OH_Drawing_PathLineTo (OH_Drawing_Path *, float x, float y) | 添加一条到目标点的线段。 |
| OH_Drawing_PathClose (OH_Drawing_Path *) | 闭合路径,会添加一条到路径起点位置的线段。 |
| OH_Drawing_PenCreate (void) | 创建一个画笔对象。 |
| OH_Drawing_PenSetAntiAlias (OH_Drawing_Pen *, bool) | 设置抗锯齿属性,如果为真则说明画笔会启用抗锯齿功能,在绘制图形时会对图形的边缘像素进行半透明的模糊处理。 |
| OH_Drawing_PenSetWidth (OH_Drawing_Pen *, float width) | 设置画笔的厚度属性,厚度属性描述了画笔绘制图形轮廓的宽度。 |
| OH_Drawing_BrushCreate (void) | 创建一个画刷对象。 |
| OH_Drawing_BrushSetColor (OH_Drawing_Brush *, uint32_t color) | 设置画刷的颜色属性,颜色属性描述了画刷填充图形时使用的颜色,用一个32位(ARGB)的变量表示。 |
| OH_Drawing_CreateTypographyStyle (void) | 创建一个排版对象,用于定义排版样式。 |
| OH_Drawing_CreateTextStyle (void) | 创建一个文本对象,用于定义文本样式。 |
| OH_Drawing_TypographyHandlerAddText (OH_Drawing_TypographyCreate *, const char *) | 设置文本内容。 |
| OH_Drawing_TypographyPaint (OH_Drawing_Typography *, OH_Drawing_Canvas *, double, double) | 显示文本。 |
详细的接口说明请参考[Drawing](../reference/native-apis/_drawing.md)
## 2D图形绘制开发步骤
以下步骤描述了在**OpenHarmony**如何使用 **native drawing** 模块的画布画笔绘制一个基本的2D图形:
1. **创建Bitmap实例**。使用 **drawing_bitmap.h****OH_Drawing_BitmapCreate** 接口创建一个Bitmap实例 **cBitmap**,并使用 **OH_Drawing_BitmapBuild** 指定其长宽大小和像素格式。
```c++
// 创建一个bitmap对象
OH_Drawing_Bitmap* cBitmap = OH_Drawing_BitmapCreate();
// 定义bitmap的像素格式
OH_Drawing_BitmapFormat cFormat {COLOR_FORMAT_RGBA_8888, ALPHA_FORMAT_OPAQUYE};
// 构造对应格式的bitmap
OH_Drawing_BitmapBuild(cBitmap, width, height, &cFormat);
```
2. **创建画布实例**。使用 **drawing_canvas.h****OH_Drawing_CanvasCreate** 接口创建一个画布实例 **cCanvas**,并使用 **OH_Drawing_CanvasBind** 接口将 **cBitmap** 实例绑定到 **cCanvas** 上,后续在画布上绘制的内容会输出到绑定的 **cBitmap** 实例中。
```c++
// 创建一个canvas对象
OH_Drawing_Canvas* cCanvas = OH_Drawing_CanvasCreate();
// 将画布与bitmap绑定,画布画的内容会输出到绑定的bitmap内存中
OH_Drawing_CanvasBind(cCanvas, cBitmap);
// 使用白色清除画布内容
OH_Drawing_CanvasClear(cCanvas, OH_Drawing_ColorSetArgb(0xFF, 0xFF, 0xFF, 0xFF));
```
3. **构造Path形状**。使用 **drawing_path.h** 提供的接口完成一个五角星形状的构造 **cPath**
```c++
int len = 300;
float aX = 500;
float aY = 500;
float dX = aX - len * std::sin(18.0f);
float dY = aY + len * std::cos(18.0f);
float cX = aX + len * std::sin(18.0f);
float cY = dY;
float bX = aX + (len / 2.0);
float bY = aY + std::sqrt((cX - dX) * (cX - dX) + (len / 2.0) * (len / 2.0));
float eX = aX - (len / 2.0);
float eY = bY;
// 创建一个path对象,然后使用接口连接成一个五角星形状
OH_Drawing_Path* cPath = OH_Drawing_PathCreate();
// 指定path的起始位置
OH_Drawing_PathMoveTo(cPath, aX, aY);
// 用直线连接到目标点
OH_Drawing_PathLineTo(cPath, bX, bY);
OH_Drawing_PathLineTo(cPath, cX, cY);
OH_Drawing_PathLineTo(cPath, dX, dY);
OH_Drawing_PathLineTo(cPath, eX, eY);
// 闭合形状,path绘制完毕
OH_Drawing_PathClose(cPath);
```
4. **设置画笔和画刷样式**。使用 **drawing_pen.h****OH_Drawing_PenCreate** 接口创建一个画笔实例 **cPen**, 并设置抗锯齿、颜色、线宽等属性,画笔用于形状边框线的绘制。使用**drawing_brush.h****OH_Drawing_BrushCreate** 接口创建一个画刷实例 **cBrush**, 并设置填充颜色, 画刷用于形状内部的填充。使用 **drawing_canvas.h****OH_Drawing_CanvasAttachPen****OH_Drawing_CanvasAttachBrush** 接口将画笔画刷的实例设置到画布实例中。
```c++
// 创建一个画笔Pen对象,Pen对象用于形状的边框线绘制
OH_Drawing_Pen* cPen = OH_Drawing_PenCreate();
OH_Drawing_PenSetAntiAlias(cPen, true);
OH_Drawing_PenSetColor(cPen, OH_Drawing_ColorSetArgb(0xFF, 0xFF, 0x00, 0x00));
OH_Drawing_PenSetWidth(cPen, 10.0);
OH_Drawing_PenSetJoin(cPen, LINE_ROUND_JOIN);
// 将Pen画笔设置到canvas中
OH_Drawing_CanvasAttachPen(cCanvas, cPen);
// 创建一个画刷Brush对象,Brush对象用于形状的填充
OH_Drawing_Brush* cBrush = OH_Drawing_BrushCreate();
OH_Drawing_BrushSetColor(cBrush, OH_Drawing_ColorSetArgb(0xFF, 0x00, 0xFF, 0x00));
// 将Brush画刷设置到canvas中
OH_Drawing_CanvasAttachBrush(cCanvas, cBrush);
```
5. **绘制Path形状**。使用 **drawing_canvas.h****OH_Drawing_CanvasDrawPath** 接口将五角星绘制到画布上,绘制完毕后不再使用的实例需要调用对应的接口进行销毁。
```c++
// 在画布上画path的形状,五角星的边框样式为pen设置,颜色填充为Brush设置
OH_Drawing_CanvasDrawPath(cCanvas, cPath);
// 销毁创建的对象
OH_Drawing_BrushDestory(cBrush);
OH_Drawing_PenDestory(cPen);
OH_Drawing_PathDestory(cPath);
```
6. **获取像素数据**。使用 **drawing_bitmap.h****OH_Drawing_BitmapGetPixels** 接口获取到画布绑定bitmap实例的像素地址,该地址指向的内存包含画布刚刚绘制的像素数据。
```c++
// 画完后获取像素地址,地址指向的内存包含画布画的像素数据
void* bitmapAddr = OH_Drawing_BitmapGetPixels(cBitmap);
auto ret = memcpy_s(addr, addrSize, bitmapAddr, addrSize);
if (ret != EOK) {
LOGI("memcpy_s failed");
}
// 销毁canvas对象
OH_Drawing_CanvasDestory(cCanvas);
// 销毁bitmap对象
OH_Drawing_BitmapDestory(cBitmap);
```
## 文本绘制显示开发步骤
以下步骤描述了在OpenHarmony中,如何使用**native drawing**模块的文字显示功能:
1. **创建画布和bitmap实例**
```c++
// 创建bitmap
OH_Drawing_Bitmap* cBitmap = OH_Drawing_BitmapCreate();
OH_Drawing_BitmapFormat cFormat {COLOR_FORMAT_RGBA_8888, ALPHA_FORMAT_OPAQUE};
OH_Drawing_BitmapBuild(cBitmap, width, height, &cFormat);
// 创建canvas
OH_Drawing_Canvas* cCanvas = OH_Drawing_CanvasCreate();
OH_Drawing_CanvasBind(cCanvas, cBitmap);
OH_Drawing_CanvasClear(cCanvas, OH_Drawing_ColorSetArgb(0xFF, 0xFF, 0xFF, 0xFF));
```
2. **设置排版风格**
```c++
// 选择左对齐/居中对齐等排版属性
OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
OH_Drawing_SetTypographyTextDirection(typoStyle, TEXT_DIRECTION_LTR);
OH_Drawing_SetTypographyTextAlign(typoStyle, TEXT_ALIGN_LEFT);
```
3. **设置文本风格**
```c++
// 设置文字颜色,例如黑色
OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
OH_Drawing_SetTextStyleColor(txtStyle, OH_Drawing_ColorSetArgb(0xFF, 0x00, 0x00, 0x00));
// 设置文字大小、字重等属性
double fontSize = 30;
OH_Drawing_SetTextStyleFontSize(txtStyle, fontSize);
OH_Drawing_SetTextStyleFontWeight(txtStyle, FONT_WEIGHT_400);
OH_Drawing_SetTextStyleBaseLine(txtStyle, TEXT_BASELINE_ALPHABETIC);
OH_Drawing_SetTextStyleFontHeight(txtStyle, 1);
// 设置字体类型等
const char* fontFamilies[] = {"Roboto"};
OH_Drawing_SetTextStyleFontFamilies(txtStyle, 1, fontFamilies);
OH_Drawing_SetTextStyleFontStyle(txtStyle, FONT_STYLE_NORMAL);
OH_Drawing_SetTextStyleLocale(txtStyle, "en");
```
4. **生成最终文字显示效果**
```c++
OH_Drawing_TypographyCreate* handler = OH_Drawing_CreateTypographyHandler(typoStyle,
OH_Drawing_CreateFontCollection());
OH_Drawing_TypographyHandlerPushTextStyle(handler, txtStyle);
// 设置文字内容
const char* text = "OpenHarmony\n";
OH_Drawing_TypographyHandlerAddText(handler, text);
OH_Drawing_TypographyHandlerPopTextStyle(handler);
OH_Drawing_Typography* typography = OH_Drawing_CreateTypography(handler);
// 设置页面最大宽度
double maxWidth = 800.0;
OH_Drawing_TypographyLayout(typography, maxWidth);
// 设置文字显示起始位置
double position[2] = {10.0, 15.0};
OH_Drawing_TypographyPaint(typography, cCanvas, position[0], position[1]);
```
## 相关实例
针对Drawing模块的使用,有以下相关实例可供参考:
* [Drawing模块2D图形绘制](https://gitee.com/openharmony/graphic_standard/blob/master/rosen/samples/2d_graphics/drawing_c_sample.cpp)
* [Drawing模块文本绘制显示](https://gitee.com/openharmony/graphic_standard/blob/master/rosen/samples/text/renderservice/drawing_text_c_sample.cpp)
# Native API在应用工程中的使用指导
OpenHarmony的应用必须用js来桥接native。需要使用ace_napi仓中提供的napi接口来处理js交互。napi提供的接口名与三方Node.js一致,目前支持部分接口,符号表见仓下的该文件`libnapi.ndk.json`
## 开发流程:
IDE中会包含使用Native API的默认工程,使用`File`->`New`->`Create Project`创建`Native C++`模板工程。创建后在`main`目录下会包含`cpp`目录,可以使用ace_napi仓下提供的napi接口进行开发。
js侧通过`import`引入native侧包含处理js逻辑的so,如:`import hello from 'libhello.so'`,意为使用libhello.so的能力,native侧通过napi接口创建的js对象会给到应用js侧的`hello`对象。
## 开发建议:
### 1、注册建议
* nm_register_func对应的函数需要加上static,防止与其他so里的符号冲突。
* 模块注册的入口,即使用\_\_attribute\_\_((constructor))修饰的函数的函数名需要确保不与其他模块重复。
### 2、so命名规则
* 每个模块对应一个so
* 如模块名为`hello`,则so的名字为`libhello.so``napi_module``nm_modname`字段应为`hello`,大小写与模块名保持一致,应用使用时写作:`import hello from 'libhello.so'`
### 3、js对象线程限制
ark引擎会对js对象线程使用进行保护,不正确使用会引起应用crash。
* napi接口只能在js线程使用。
* env与线程绑定,不能跨线程使用。native侧js对象只能在创建时的线程使用,即与线程所持有的env绑定。
### 4. napi_create_async_work接口说明
napi_create_async_work里有两个回调:
* execute:用于异步处理业务逻辑。因为不在JS线程中,所以不允许调用napi的接口。业务逻辑的返回值可以返回到complete回调中处理。
* complete:可以调用napi的接口,将execute中的返回值封装成JS对象返回。此回调在JS线程中执行。
```c++
napi_status napi_create_async_work(napi_env env,
napi_value async_resource,
napi_value async_resource_name,
napi_async_execute_callback execute,
napi_async_complete_callback complete,
void* data,
napi_async_work* result)
```
## 示例一,storage 模块——同步异步接口封装
### 模块简介
本例通过实现 `storage` 模块展示了同步和异步方法的封装。`storage ` 模块实现了数据的保存、获取、删除、清除功能。
### 接口声明
```typescript
import { AsyncCallback } from './basic';
declare namespace storage {
function get(key: string, callback: AsyncCallback<string>): void;
function get(key: string, defaultValue: string, callback: AsyncCallback<string>): void;
function get(key: string, defaultValue?: string): Promise<string>;
function set(key: string, value: string, callback: AsyncCallback<string>): void;
function remove(key: string, callback: AsyncCallback<void>): void;
function clear(callback: AsyncCallback<void>): void;
function getSync(key: string, defaultValue?: string): string;
function setSync(key: string, value: string): void;
function removeSync(key: string): void;
function clearClear(): void;
}
export default storage;
```
### 具体实现
完整代码参见仓下路径:`sample/native_module_storage/`
#### 模块注册
如下,注册了4个同步接口(`getSync``setSync``removeSync``clearSync`)、4个异步接口(`get``set``remove``clear`)。
```c++
/***********************************************
* Module export and register
***********************************************/
static napi_value StorgeExport(napi_env env, napi_value exports)
{
napi_property_descriptor desc[] = {
DECLARE_NAPI_FUNCTION("get", JSStorageGet),
DECLARE_NAPI_FUNCTION("set", JSStorageSet),
DECLARE_NAPI_FUNCTION("remove", JSStorageDelete),
DECLARE_NAPI_FUNCTION("clear", JSStorageClear),
DECLARE_NAPI_FUNCTION("getSync", JSStorageGetSync),
DECLARE_NAPI_FUNCTION("setSync", JSStorageSetSync),
DECLARE_NAPI_FUNCTION("deleteSync", JSStorageDeleteSync),
DECLARE_NAPI_FUNCTION("clearSync", JSStorageClearSync),
};
NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc));
return exports;
}
// storage module
static napi_module storage_module = {.nm_version = 1,
.nm_flags = 0,
.nm_filename = nullptr,
.nm_register_func = StorgeExport,
.nm_modname = "storage",
.nm_priv = ((void*)0),
.reserved = {0}};
// storage module register
extern "C" __attribute__((constructor)) void StorageRegister()
{
napi_module_register(&storage_module);
}
```
#### getSync 函数实现
如上注册时所写,`getSync` 对应的函数是 `JSStorageGetSync` 。从 `gKeyValueStorage` 中获取数据后,创建一个字符串对象并返回。
```c
static napi_value JSStorageGetSync(napi_env env, napi_callback_info info)
{
GET_PARAMS(env, info, 2);
NAPI_ASSERT(env, argc >= 1, "requires 1 parameter");
char key[32] = {0};
size_t keyLen = 0;
char value[128] = {0};
size_t valueLen = 0;
// 参数解析
for (size_t i = 0; i < argc; i++) {
napi_valuetype valueType;
napi_typeof(env, argv[i], &valueType);
if (i == 0 && valueType == napi_string) {
napi_get_value_string_utf8(env, argv[i], key, 31, &keyLen);
} else if (i == 1 && valueType == napi_string) {
napi_get_value_string_utf8(env, argv[i], value, 127, &valueLen);
break;
} else {
NAPI_ASSERT(env, false, "type mismatch");
}
}
// 获取数据的业务逻辑,这里简单地从一个全局变量中获取
auto itr = gKeyValueStorage.find(key);
napi_value result = nullptr;
if (itr != gKeyValueStorage.end()) {
// 获取到数据后创建一个string类型的JS对象
napi_create_string_utf8(env, itr->second.c_str(), itr->second.length(), &result);
} else if (valueLen > 0) {
// 没有获取到数据使用默认值创建JS对象
napi_create_string_utf8(env, value, valueLen, &result);
} else {
NAPI_ASSERT(env, false, "key does not exist");
}
// 返回结果
return result;
}
```
#### get 函数实现
如上注册时所写,`get`对应的函数式`JSStorageGet`
```c
static napi_value JSStorageGet(napi_env env, napi_callback_info info)
{
GET_PARAMS(env, info, 3);
NAPI_ASSERT(env, argc >= 1, "requires 1 parameter");
// StorageAsyncContext是自己定义的一个类,用于保存执行过程中的数据
StorageAsyncContext* asyncContext = new StorageAsyncContext();
asyncContext->env = env;
// 获取参数
for (size_t i = 0; i < argc; i++) {
napi_valuetype valueType;
napi_typeof(env, argv[i], &valueType);
if (i == 0 && valueType == napi_string) {
napi_get_value_string_utf8(env, argv[i], asyncContext->key, 31, &asyncContext->keyLen);
} else if (i == 1 && valueType == napi_string) {
napi_get_value_string_utf8(env, argv[i], asyncContext->value, 127, &asyncContext->valueLen);
} else if (i == 1 && valueType == napi_function) {
napi_create_reference(env, argv[i], 1, &asyncContext->callbackRef);
break;
} else if (i == 2 && valueType == napi_function) {
napi_create_reference(env, argv[i], 1, &asyncContext->callbackRef);
} else {
NAPI_ASSERT(env, false, "type mismatch");
}
}
napi_value result = nullptr;
// 根据参数判断开发者使用的是promise还是callback
if (asyncContext->callbackRef == nullptr) {
// 创建promise
napi_create_promise(env, &asyncContext->deferred, &result);
} else {
napi_get_undefined(env, &result);
}
napi_value resource = nullptr;
napi_create_string_utf8(env, "JSStorageGet", NAPI_AUTO_LENGTH, &resource);
napi_create_async_work(
env, nullptr, resource,
// 回调1:此回调由napi异步执行,里面就是需要异步执行的业务逻辑。由于是异步线程执行,所以不要在此通过napi接口操作JS对象。
[](napi_env env, void* data) {
StorageAsyncContext* asyncContext = (StorageAsyncContext*)data;
auto itr = gKeyValueStorage.find(asyncContext->key);
if (itr != gKeyValueStorage.end()) {
strncpy_s(asyncContext->value, 127, itr->second.c_str(), itr->second.length());
asyncContext->status = 0;
} else {
asyncContext->status = 1;
}
},
// 回调2:此回调在上述异步回调执行完后执行,此时回到了JS线程来回调开发者传入的回调
[](napi_env env, napi_status status, void* data) {
StorageAsyncContext* asyncContext = (StorageAsyncContext*)data;
napi_value result[2] = {0};
if (!asyncContext->status) {
napi_get_undefined(env, &result[0]);
napi_create_string_utf8(env, asyncContext->value, strlen(asyncContext->value), &result[1]);
} else {
napi_value message = nullptr;
napi_create_string_utf8(env, "key does not exist", NAPI_AUTO_LENGTH, &message);
napi_create_error(env, nullptr, message, &result[0]);
napi_get_undefined(env, &result[1]);
}
if (asyncContext->deferred) {
// 如果走的是promise,那么判断回调1的结果
if (!asyncContext->status) {
// 回调1执行成功(status为1)时触发,也就是触发promise里then里面的回调
napi_resolve_deferred(env, asyncContext->deferred, result[1]);
} else {
// 回调1执行失败(status为0)时触发,也就是触发promise里catch里面的回调
napi_reject_deferred(env, asyncContext->deferred, result[0]);
}
} else {
// 如果走的是callback,则通过napi_call_function调用callback回调返回结果
napi_value callback = nullptr;
napi_value returnVal;
napi_get_reference_value(env, asyncContext->callbackRef, &callback);
napi_call_function(env, nullptr, callback, 2, result, &returnVal);
napi_delete_reference(env, asyncContext->callbackRef);
}
napi_delete_async_work(env, asyncContext->work);
delete asyncContext;
},
(void*)asyncContext, &asyncContext->work);
napi_queue_async_work(env, asyncContext->work);
return result;
}
```
### JS Sample Code
```js
import storage from 'libstorage.so';
export default {
testGetSync() {
const name = storage.getSync('name');
console.log('name is ' + name);
},
testGet() {
storage.get('name')
.then(date => {
console.log('name is ' + data);
})
.catch(error => {
console.log('error: ' + error);
});
}
}
```
## 示例二,NetServer 模块——native与js对象绑定
### 模块简介
本例展示了`on/off/once`订阅方法的实现,同时也包含了 C++ 与 JS 对象通过 wrap 接口的绑定。NetServer 模块实现了一个网络服务。
### 接口声明
```typescript
export class NetServer {
function start(port: number): void;
function stop(): void;
function on('start' | 'stop', callback: Function): void;
function once('start' | 'stop', callback: Function): void;
function off('start' | 'stop', callback: Function): void;
}
```
### 具体实现
完整代码参见:`sample/native_module_netserver/`
#### 模块注册
```c
static napi_value NetServer::Export(napi_env env, napi_value exports)
{
const char className[] = "NetServer";
napi_property_descriptor properties[] = {
DECLARE_NAPI_FUNCTION("start", JS_Start),
DECLARE_NAPI_FUNCTION("stop", JS_Stop),
DECLARE_NAPI_FUNCTION("on", JS_On),
DECLARE_NAPI_FUNCTION("once", JS_Once),
DECLARE_NAPI_FUNCTION("off", JS_Off),
};
napi_value netServerClass = nullptr;
napi_define_class(env, className, sizeof(className), JS_Constructor, nullptr, countof(properties), properties,
&netServerClass);
napi_set_named_property(env, exports, "NetServer", netServerClass);
return exports;
}
```
#### 在构造函数中绑定 C++ 与 JS 对象
```c
napi_value NetServer::JS_Constructor(napi_env env, napi_callback_info cbinfo)
{
napi_value thisVar = nullptr;
void* data = nullptr;
napi_get_cb_info(env, cbinfo, nullptr, nullptr, &thisVar, &data);
// C++ Native对象,准备与JS对象映射在一起
NetServer* netServer = new NetServer(env, thisVar);
// 使用napi_wrap将netServer与thisVar(即当前创建的这个JS对象)做绑定
napi_wrap(
env, thisVar, netServer,
// JS对象由引擎自动回收释放,当JS对象释放时触发该回调,在改回调中释放netServer
[](napi_env env, void* data, void* hint) {
printf("NetServer::Destructor\n");
NetServer* netServer = (NetServer*)data;
delete netServer;
},
nullptr, nullptr);
return thisVar;
}
```
#### 从 JS 对象中取出 C++ 对象
```c
napi_value NetServer::JS_Start(napi_env env, napi_callback_info cbinfo)
{
size_t argc = 1;
napi_value argv[1] = {0};
napi_value thisVar = nullptr;
void* data = nullptr;
napi_get_cb_info(env, cbinfo, &argc, argv, &thisVar, &data);
NetServer* netServer = nullptr;
// 通过napi_unwrap从thisVar中取出C++对象
napi_unwrap(env, thisVar, (void**)&netServer);
NAPI_ASSERT(env, argc >= 1, "requires 1 parameter");
napi_valuetype valueType;
napi_typeof(env, argv[0], &valueType);
NAPI_ASSERT(env, valueType == napi_number, "type mismatch for parameter 1");
int32_t port = 0;
napi_get_value_int32(env, argv[0], &port);
// 开启服务
netServer->Start(port);
napi_value result = nullptr;
napi_get_undefined(env, &result);
return result;
}
```
`netServer->Start`后回调通过`on`注册的`start`事件。
```c
int NetServer::Start(int port)
{
printf("NetServer::Start thread_id: %ld \n", uv_thread_self());
struct sockaddr_in addr;
int r;
uv_ip4_addr("0.0.0.0", port, &addr);
r = uv_tcp_init(loop_, &tcpServer_);
if (r) {
fprintf(stderr, "Socket creation error\n");
return 1;
}
r = uv_tcp_bind(&tcpServer_, (const struct sockaddr*)&addr, 0);
if (r) {
fprintf(stderr, "Bind error\n");
return 1;
}
r = uv_listen((uv_stream_t*)&tcpServer_, SOMAXCONN, OnConnection);
if (r) {
fprintf(stderr, "Listen error %s\n", uv_err_name(r));
return 1;
}
// 服务启动后触发“start”事件
Emit("start", nullptr);
return 0;
}
```
#### 注册或释放(on/off/once)事件,以 on 为例
```c
napi_value NetServer::JS_On(napi_env env, napi_callback_info cbinfo)
{
size_t argc = 2;
napi_value argv[2] = {0};
napi_value thisVar = 0;
void* data = nullptr;
napi_get_cb_info(env, cbinfo, &argc, argv, &thisVar, &data);
NetServer* netServer = nullptr;
// 通过napi_unwrap取出NetServer指针
napi_unwrap(env, thisVar, (void**)&netServer);
NAPI_ASSERT(env, argc >= 2, "requires 2 parameter");
// 参数类型校验
napi_valuetype eventValueType;
napi_typeof(env, argv[0], &eventValueType);
NAPI_ASSERT(env, eventValueType == napi_string, "type mismatch for parameter 1");
napi_valuetype eventHandleType;
napi_typeof(env, argv[1], &eventHandleType);
NAPI_ASSERT(env, eventHandleType == napi_function, "type mismatch for parameter 2");
char type[64] = {0};
size_t typeLen = 0;
napi_get_value_string_utf8(env, argv[0], type, 63, &typeLen);
// 注册事件handler
netServer->On((const char*)type, argv[1]);
napi_value result = nullptr;
napi_get_undefined(env, &result);
return result;
}
```
### JS Sample Code
```javascript
import { NetServer } from 'libnetserver.so';
export default {
testNetServer() {
var netServer = new NetServer();
netServer.on('start', (event) => {});
netServer.start(1000); // 端口号1000, start完成后回调上面注册的 “start” 回调
}
}
```
## 示例三,在非JS线程中回调JS接口
### 模块简介
本模块介绍如何在非JS线程中回调JS应用的回调函数。例如JS应用中注册了某个sensor的监听,这个sensor的数据是由一个SA服务来上报的,当SA通过IPC调到客户端时,此时的执行线程是一个IPC通信线程,与应用的JS线程是两个不同的线程。这时就需要将执行JS回调的任务抛到JS线程中才能执行,否则会出现崩溃。
### 具体实现
完整代码参见:`sample/native_module_callback/`
#### 模块注册
如下,注册了1个接口`test`,会传入一个参数,类型为包含一个参数的函数。
```c++
/***********************************************
* Module export and register
***********************************************/
static napi_value CallbackExport(napi_env env, napi_value exports)
{
static napi_property_descriptor desc[] = {
DECLARE_NAPI_FUNCTION("test", JSTest)
};
NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc));
return exports;
}
// callback module define
static napi_module callbackModule = {
.nm_version = 1,
.nm_flags = 0,
.nm_filename = nullptr,
.nm_register_func = CallbackExport,
.nm_modname = "callback",
.nm_priv = ((void*)0),
.reserved = { 0 },
};
// callback module register
extern "C" __attribute__((constructor)) void CallbackTestRegister()
{
napi_module_register(&callbackModule);
}
```
#### 获取env中的loop,抛任务回JS线程
```c++
#include <thread>
#include "napi/native_api.h"
#include "napi/native_node_api.h"
#include "uv.h"
struct CallbackContext {
napi_env env = nullptr;
napi_ref callbackRef = nullptr;
int retData = 0;
};
void callbackTest(CallbackContext* context)
{
uv_loop_s* loop = nullptr;
// 此处的env需要在注册JS回调时保存下来。从env中获取对应的JS线程的loop。
napi_get_uv_event_loop(context->env, &loop);
// 创建uv_work_t用于传递私有数据,注意回调完成后需要释放内存,此处省略生成回传数据的逻辑,传回int类型1。
uv_work_t* work = new uv_work_t;
context->retData = 1;
work->data = (void*)context;
// 调用libuv接口抛JS任务到loop中执行。
uv_queue_work(
loop,
work,
// 此回调在另一个普通线程中执行,用于处理异步任务,回调执行完后执行下面的回调。本场景下该回调不需要执行任务。
[](uv_work_t* work) {},
// 此回调会在env对应的JS线程中执行。
[](uv_work_t* work, int status) {
CallbackContext* context = (CallbackContext*)work->data;
napi_handle_scope scope = nullptr;
// 打开handle scope用于管理napi_value的生命周期,否则会内存泄露。
napi_open_handle_scope(context->env, &scope);
if (scope == nullptr) {
return;
}
// 调用napi。
napi_value callback = nullptr;
napi_get_reference_value(context->env, context->callbackRef, &callback);
napi_value retArg;
napi_create_int32(context->env, context->retData, &retArg);
napi_value ret;
napi_call_function(context->env, nullptr, callback, 1, &retArg, &ret);
napi_delete_reference(context->env, context->callbackRef);
// 关闭handle scope释放napi_value。
napi_close_handle_scope(context->env, scope);
// 释放work指针。
if (work != nullptr) {
delete work;
}
delete context;
}
);
}
static napi_value JSTest(napi_env env, napi_callback_info info)
{
size_t argc = 1;
napi_value argv[1] = { 0 };
napi_value thisVar = nullptr;
void* data = nullptr;
napi_get_cb_info(env, info, &argc, argv, &thisVar, &data);
// 获取第一个入参,即需要后续触发的回调函数
napi_valuetype valueType = napi_undefined;
napi_typeof(env, argv[0], &valueType);
if (valueType != napi_function) {
return nullptr;
}
// 存下env与回调函数,用于传递
auto asyncContext = new CallbackContext();
asyncContext->env = env;
napi_create_reference(env, argv[0], 1, &asyncContext->callbackRef);
// 模拟抛到非js线程执行逻辑
std::thread testThread(callbackTest, asyncContext);
testThread.detach();
return nullptr;
}
```
### JS Sample Code
```js
import callback from 'libcallback.so';
export default {
testcallback() {
callback.test((data) => {
console.error('test result = ' + data)
})
}
}
```
# rawfile开发指导
## 场景介绍
开发者可以通过本指导了解在OpenHarmony应用中,如何使用rawfile native接口操作rawfile目录和文件。功能包括遍历、打开、搜索、读取和关闭rawfile。
## 接口说明
| 接口名 | 描述 |
| :----------------------------------------------------------- | :--------------------------------------- |
| NativeResourceManager *OH_ResourceManager_InitNativeResourceManager(napi_env env, napi_value jsResMgr) | 初始化native resource manager。 |
| RawDir *OH_ResourceManager_OpenRawDir(const NativeResourceManager *mgr, const char *dirName) | 打开指定rawfile目录。 |
| int OH_ResourceManager_GetRawFileCount(RawDir *rawDir) | 获取指定rawfile目录下的rawfile文件数量。 |
| const char *OH_ResourceManager_GetRawFileName(RawDir *rawDir, int index) | 获取rawfile名字。 |
| RawFile *OH_ResourceManager_OpenRawFile(const NativeResourceManager *mgr, const char *fileName) | 打开指定rawfile文件。 |
| long OH_ResourceManager_GetRawFileSize(RawFile *rawFile) | 获取rawfile文件大小。 |
| int OH_ResourceManager_SeekRawFile(const RawFile *rawFile, long offset, int whence) | 指定rawfile内偏移量。 |
| long OH_ResourceManager_GetRawFileOffset(const RawFile *rawFile) | 获取rawfile偏移量。 |
| int OH_ResourceManager_ReadRawFile(const RawFile *rawFile, void *buf, size_t length) | 读取rawfile文件内容。 |
| void OH_ResourceManager_CloseRawFile(RawFile *rawFile) | 释放rawfile文件相关资源。 |
| void OH_ResourceManager_CloseRawDir(RawDir *rawDir) | 释放rawfile目录相关资源。 |
| bool OH_ResourceManager_GetRawFileDescriptor(const RawFile *rawFile, RawFileDescriptor &descriptor) | 获取rawfile的fd。 |
| bool OH_ResourceManager_ReleaseRawFileDescriptor(const RawFileDescriptor &descriptor) | 释放rawfile的fd。 |
| void OH_ResourceManager_ReleaseNativeResourceManager(NativeResourceManager *resMgr) | 释放native resource manager相关资源。 |
## 开发步骤
1. 添加头文件。
```c++
#include "raw_file_manager.h"
```
2. 使用OH_ResourceManager_InitNativeResourceManager(napi_env env, napi_value jsResMgr)接口获取NativeResourceManager实例。
```js
// js侧传递js resource manager。
import resManager from '@ohos.resourceManager'
import rawfileTest from 'librawFileTest.so'
resManager.getResourceManager().then(resmgr => {
rawfileTest.testRawFile("test", resmgr, (error, value) => {
console.log("test rawFile");
})
});
```
```c++
// C++侧获取解析js侧传递的参数。
NativeResourceManager* nativeResourceManager = nullptr;
std::string path;
if (i == 0 && valueType == napi_string) {
// 解析第一个参数,参数为相对rawfile目录的文件/目录路径。
......
path = buf.data();
} else if (i == 1 && valueType == napi_object) {
// 解析第二个参数,参数为js resource manager。
nativeResourceManager = OH_ResourceManager_InitNativeResourceManager(env, argv[i]);
}
```
3. 根据NativeResourceManager实例,使用OH_ResourceManager_OpenRawDir接口获取RawDir实例。
```c++
RawDir* rawDir = OH_ResourceManager_OpenRawDir(nativeResourceManager, path.c_str());
```
4. 根据RawDir实例,使用OH_ResourceManager_GetRawFileCount接口获取对应目录下的rawfile文件总数 。
```c++
int count = OH_ResourceManager_GetRawFileCount(rawDir);
```
5. 根据RawDir实例,使用OH_ResourceManager_GetRawFileName接口获取目录下对应index的rawfile文件名。
```c++
for (int index = 0; index < count; index++) {
std::string fileName = OH_ResourceManager_GetRawFileName(rawDir, index);
}
```
6. 根据NativeResourceManager实例,使用OH_ResourceManager_OpenRawFile接口获取指定文件名的RawFile实例
```c++
RawFile* rawFile = OH_ResourceManager_OpenRawFile(nativeResourceManager, fileName.c_str());
```
7. 根据RawFile实例,使用OH_ResourceManager_GetRawFileSize接口获取对应rawfile文件大小。
```c++
long rawFileSize = OH_ResourceManager_GetRawFileSize(rawFile);
```
8. 根据RawFile实例,使用OH_ResourceManager_SeekRawFile接口指定rawfile偏移量。
```c++
int position = OH_ResourceManager_SeekRawFile(rawFile, 10, 0);
int position = OH_ResourceManager_SeekRawFile(rawFile, 0 , 1);
int position = OH_ResourceManager_SeekRawFile(rawFile, -10, 2);
```
9. 根据RawFile实例,使用OH_ResourceManager_GetRawFileOffset接口获取rawfile偏移量。
```c++
long rawFileOffset = OH_ResourceManager_GetRawFileOffset(rawFile)
```
10. 根据RawFile实例,使用OH_ResourceManager_ReadRawFile接口读取rawfile文件内容。
```c++
std::unique_ptr<char[]> mediaData = std::make_unique<char[]>(rawFileSize);
long rawFileOffset = OH_ResourceManager_ReadRawFile(rawFile, mediaData.get(), rawFileSize);
```
11. 根据RawFile实例,使用OH_ResourceManager_CloseRawFile接口释放rawfile文件相关资源。
```c++
OH_ResourceManager_CloseRawFile(rawFile);
```
12. 根据RawDir实例,使用OH_ResourceManager_CloseRawDir接口释放rawfile目录相关资源。
```c++
OH_ResourceManager_CloseRawDir(rawDir);
```
13. 根据RawFile实例,使用OH_ResourceManager_GetRawFileDescriptor接口获取rawfile的RawFileDescriptor。
```c++
RawFileDescriptor descriptor;
bool result = OH_ResourceManager_GetRawFileDescriptor(rawFile, descriptor);
```
14. 根据RawFileDescriptor实例,使用OH_ResourceManager_ReleaseRawFileDescriptor接口关闭rawfile的fd。
```c++
OH_ResourceManager_ReleaseRawFileDescriptor(descriptor);
```
15. 根据NativeResourceManager实例,使用OH_ResourceManager_ReleaseNativeResourceManager接口释放native resource manager。
```c++
OH_ResourceManager_ReleaseNativeResourceManager(nativeResourceManager);
```
......@@ -8,7 +8,7 @@
- [使用JS语言开发(低代码方式)](start-with-js-low-code.md)
- 开发基础知识
- [应用包结构说明(FA模型)](package-structure.md)
- [应用包结构说明(Stage模型)](module-structure.md)
- [应用包结构说明(Stage模型)](stage-structure.md)
- [资源文件的分类](basic-resource-file-categories.md)
- [SysCap说明](syscap.md)
# 开发参考
- [基于JS扩展的类Web开发范式](arkui-js/Readme-CN.md)
- [基于TS扩展的声明式开发范式](arkui-ts/Readme-CN.md)
- 接口
- [JS(含eTS) API参考](apis/Readme-CN.md)
- Native API
- [OpenHarmony Native API](./native-apis/Readme-CN.md)
- [标准库](native-lib/third_party_libc/musl.md)
- [Node_API](native-lib/third_party_napi/napi.md)
- [接口](apis/Readme-CN.md)
# Native API
- MyProject
- [Native XComponent](_o_h___native_x_component.md)
- [Native_Bundle](_native___bundle.md)
- [HiLog](_hi_log.md)
- [NativeWindow](_native_window.md)
- [Drawing](_drawing.md)
- [Rawfile](rawfile.md)
- 头文件和结构体
- 头文件
- [drawing_bitmap.h](drawing__bitmap_8h.md)
- [drawing_brush.h](drawing__brush_8h.md)
- [drawing_canvas.h](drawing__canvas_8h.md)
- [drawing_color.h](drawing__color_8h.md)
- [drawing_font_collection.h](drawing__font__collection_8h.md)
- [drawing_path.h](drawing__path_8h.md)
- [drawing_pen.h](drawing__pen_8h.md)
- [drawing_text_declaration.h](drawing__text__declaration_8h.md)
- [drawing_text_typography.h](drawing__text__typography_8h.md)
- [drawing_types.h](drawing__types_8h.md)
- [external_window.h](external__window_8h.md)
- [log.h](log_8h.md)
- [native_interface_bundle.h](native__interface__bundle_8h.md)
- [native_interface_xcomponent.h](native__interface__xcomponent_8h.md)
- [raw_dir.h](raw__dir_8h.md)
- [raw_file.h](raw__file_8h.md)
- 结构体
- [OH_Drawing_BitmapFormat](_o_h___drawing___bitmap_format.md)
- [OH_NativeXComponent_Callback](_o_h___native_x_component___callback.md)
- [OH_NativeXComponent_TouchEvent](_o_h___native_x_component___touch_event.md)
- [OH_NativeXComponent_TouchPoint](_o_h___native_x_component___touch_point.md)
- [RawFileDescriptor](_raw_file_descriptor.md)
# Drawing
## **Overview**
**Description:**
Drawing模块提供包括2D图形渲染、文字绘制和图片显示等功能函数
Drawing模块提供包括2D图形渲染、文字绘制和图片显示等功能函数.
提供2D绘制功能
\@syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
**Since:**
8
**Version:**
1.0
## **Summary**
### Files
| File&nbsp;Name | Description |
| -------- | -------- |
| [drawing_bitmap.h](drawing__bitmap_8h.md) | 文件中定义了与位图相关的功能函数 |
| [drawing_brush.h](drawing__brush_8h.md) | 文件中定义了与画刷相关的功能函数 |
| [drawing_canvas.h](drawing__canvas_8h.md) | 文件中定义了与画布相关的功能函数 |
| [drawing_color.h](drawing__color_8h.md) | 文件中定义了与颜色相关的功能函数 |
| [drawing_font_collection.h](drawing__font__collection_8h.md) | 定义绘制模块中与fontCollection相关的函数 |
| [drawing_path.h](drawing__path_8h.md) | 文件中定义了与自定义路径相关的功能函数 |
| [drawing_pen.h](drawing__pen_8h.md) | 文件中定义了与画笔相关的功能函数 |
| [drawing_text_declaration.h](drawing__text__declaration_8h.md) | 提供2d&nbsp;drawing文本相关的数据结构声明 |
| [drawing_text_typography.h](drawing__text__typography_8h.md) | 定义绘制模块中排版相关的函数 |
| [drawing_types.h](drawing__types_8h.md) | 文件中定义了用于绘制2d图形的数据类型,包括画布、画笔、画刷、位图和路径 |
### Classes
| Classe&nbsp;Name | Description |
| -------- | -------- |
| [OH_Drawing_BitmapFormat](_o_h___drawing___bitmap_format.md) | 结构体用于描述位图像素的格式,包括颜色类型和透明度类型 |
### Typedefs
| Typedef&nbsp;Name | Description |
| -------- | -------- |
| OH_Drawing_FontCollection | typedef&nbsp;struct&nbsp;OH_Drawing_FontCollection<br/>OH_Drawing_FontCollection用于加载字体 |
| OH_Drawing_Typography | typedef&nbsp;struct&nbsp;OH_Drawing_Typography<br/>OH_Drawing_Typography用于管理排版的布局和显示等 |
| OH_Drawing_TextStyle | typedef&nbsp;struct&nbsp;OH_Drawing_TextStyle<br/>OH_Drawing_TextStyle用于管理字体颜色、装饰等 |
| OH_Drawing_TypographyStyle | typedef&nbsp;struct&nbsp;OH_Drawing_TypographyStyle<br/>OH_Drawing_TypographyStyle用于管理排版风格,如文字方向等 |
| OH_Drawing_TypographyCreate | typedef&nbsp;struct&nbsp;OH_Drawing_TypographyCreate<br/>OH_Drawing_TypographyCreate用于创建OH_Drawing_Typography. |
| OH_Drawing_Canvas | typedef&nbsp;struct&nbsp;OH_Drawing_Canvas<br/>OH_Drawing_Canvas定义为一块矩形的画布,可以结合画笔和画刷在上面绘制各种形状、图片和文字 |
| OH_Drawing_Pen | typedef&nbsp;struct&nbsp;OH_Drawing_Pen<br/>OH_Drawing_Pen定义为画笔,画笔用于描述绘制图形轮廓的样式和颜色 |
| OH_Drawing_Brush | typedef&nbsp;struct&nbsp;OH_Drawing_Brush<br/>OH_Drawing_Brush定义为画刷,画刷用于描述填充图形的样式和颜色 |
| OH_Drawing_Path | typedef&nbsp;struct&nbsp;OH_Drawing_Path<br/>OH_Drawing_Path定义为路径,路径用于自定义各种形状 |
| OH_Drawing_Bitmap | typedef&nbsp;struct&nbsp;OH_Drawing_Bitmap<br/>OH_Drawing_Bitmap定义为位图,位图是一块内存,内存中包含了描述一张图片的像素数据 |
### Enumerations
| Enumeration&nbsp;Name | Description |
| -------- | -------- |
| OH_Drawing_PenLineCapStyle&nbsp;{&nbsp;LINE_FLAT_CAP,&nbsp;LINE_SQUARE_CAP,&nbsp;LINE_ROUND_CAP&nbsp;} | 枚举集合定义了画笔笔帽的样式,即画笔在绘制线段时,在线段头尾端点的样式 |
| OH_Drawing_PenLineJoinStyle&nbsp;{&nbsp;LINE_MITER_JOIN,&nbsp;LINE_ROUND_JOIN,&nbsp;LINE_BEVEL_JOIN&nbsp;} | 枚举集合定义了线条转角的样式,即画笔在绘制折线段时,在折线转角处的样式 |
| OH_Drawing_TextDirection&nbsp;{&nbsp;TEXT_DIRECTION_RTL,&nbsp;TEXT_DIRECTION_LTR&nbsp;} | 文字方向 |
| OH_Drawing_TextAlign&nbsp;{&nbsp;&nbsp;&nbsp;TEXT_ALIGN_LEFT,&nbsp;TEXT_ALIGN_RIGHT,&nbsp;TEXT_ALIGN_CENTER,&nbsp;TEXT_ALIGN_JUSTIFY,&nbsp;&nbsp;&nbsp;TEXT_ALIGN_START,&nbsp;TEXT_ALIGN_END&nbsp;} | 文字对齐方式 |
| OH_Drawing_FontWeight&nbsp;{&nbsp;&nbsp;&nbsp;FONT_WEIGHT_100,&nbsp;FONT_WEIGHT_200,&nbsp;FONT_WEIGHT_300,&nbsp;FONT_WEIGHT_400,&nbsp;&nbsp;&nbsp;FONT_WEIGHT_500,&nbsp;FONT_WEIGHT_600,&nbsp;FONT_WEIGHT_700,&nbsp;FONT_WEIGHT_800,&nbsp;&nbsp;&nbsp;FONT_WEIGHT_900&nbsp;} | 字重 |
| OH_Drawing_TextBaseline&nbsp;{&nbsp;TEXT_BASELINE_ALPHABETIC,&nbsp;TEXT_BASELINE_IDEOGRAPHIC&nbsp;} | 基线位置 |
| OH_Drawing_TextDecoration&nbsp;{&nbsp;TEXT_DECORATION_NONE&nbsp;=&nbsp;0x0,&nbsp;TEXT_DECORATION_UNDERLINE&nbsp;=&nbsp;0x1,&nbsp;TEXT_DECORATION_OVERLINE&nbsp;=&nbsp;0x2,&nbsp;TEXT_DECORATION_LINE_THROUGH&nbsp;=&nbsp;0x4&nbsp;} | 文本装饰 |
| OH_Drawing_FontStyle&nbsp;{&nbsp;FONT_STYLE_NORMAL,&nbsp;FONT_STYLE_ITALIC&nbsp;} | 区分字体是否为斜体 |
| OH_Drawing_ColorFormat&nbsp;{&nbsp;&nbsp;&nbsp;COLOR_FORMAT_UNKNOWN,&nbsp;COLOR_FORMAT_ALPHA_8,&nbsp;COLOR_FORMAT_RGB_565,&nbsp;COLOR_FORMAT_ARGB_4444,&nbsp;&nbsp;&nbsp;COLOR_FORMAT_RGBA_8888,&nbsp;COLOR_FORMAT_BGRA_8888&nbsp;} | OH_Drawing_ColorFormat用于描述位图像素的存储格式 |
| OH_Drawing_AlphaFormat&nbsp;{&nbsp;ALPHA_FORMAT_UNKNOWN,&nbsp;ALPHA_FORMAT_OPAQUE,&nbsp;ALPHA_FORMAT_PREMUL,&nbsp;ALPHA_FORMAT_UNPREMUL&nbsp;} | OH_Drawing_AlphaFormat用于描述位图像素的透明度分量 |
### Functions
| Function | Description |
| -------- | -------- |
| OH_Drawing_BitmapCreate&nbsp;(void) | OH_Drawing_Bitmap&nbsp;\*<br/>函数用于创建一个位图对象。 |
| OH_Drawing_BitmapDestroy&nbsp;(OH_Drawing_Bitmap&nbsp;\*) | void<br/>函数用于销毁位图对象并回收该对象占有内存。 |
| OH_Drawing_BitmapBuild&nbsp;(OH_Drawing_Bitmap&nbsp;\*,&nbsp;const&nbsp;uint32_t&nbsp;width,&nbsp;const&nbsp;uint32_t&nbsp;height,&nbsp;const&nbsp;OH_Drawing_BitmapFormat&nbsp;\*) | void<br/>函数用于初始化位图对象的宽度和高度,并且为该位图设置像素格式 |
| OH_Drawing_BitmapGetWidth&nbsp;(OH_Drawing_Bitmap&nbsp;\*) | uint32_t<br/>该函数用于获取指定位图的宽度 |
| OH_Drawing_BitmapGetHeight&nbsp;(OH_Drawing_Bitmap&nbsp;\*) | uint32_t<br/>函数用于获取指定位图的高度 |
| OH_Drawing_BitmapGetPixels&nbsp;(OH_Drawing_Bitmap&nbsp;\*) | void&nbsp;\*<br/>函数用于获取指定位图的像素地址,可以通过像素地址获取到位图的像素数据 |
| OH_Drawing_BrushCreate&nbsp;(void) | OH_Drawing_Brush&nbsp;\*<br/>函数用于创建一个画刷对象 |
| OH_Drawing_BrushDestroy&nbsp;(OH_Drawing_Brush&nbsp;\*) | void<br/>函数用于销毁画刷对象并回收该对象占有的内存。 |
| OH_Drawing_BrushIsAntiAlias&nbsp;(const&nbsp;OH_Drawing_Brush&nbsp;\*) | bool<br/>函数用于获取画刷是否设置抗锯齿属性,如果为真则说明画刷会启用抗锯齿功能,在绘制图形时会对图形的边缘像素进行半透明的模糊处理 |
| OH_Drawing_BrushSetAntiAlias&nbsp;(OH_Drawing_Brush&nbsp;\*,&nbsp;bool) | void<br/>函数用于设置画刷的抗锯齿属性,设置为真则画刷在绘制图形时会对图形的边缘像素进行半透明的模糊处理 |
| OH_Drawing_BrushGetColor&nbsp;(const&nbsp;OH_Drawing_Brush&nbsp;\*) | uint32_t<br/>函数用于获取画刷的颜色属性,颜色属性描述了画刷填充图形时使用的颜色,用一个32位(ARGB)的变量表示 |
| OH_Drawing_BrushSetColor&nbsp;(OH_Drawing_Brush&nbsp;\*,&nbsp;uint32_t&nbsp;color) | void<br/>函数用于设置画刷的颜色属性,颜色属性描述了画刷填充图形时使用的颜色,用一个32位(ARGB)的变量表示 |
| OH_Drawing_CanvasCreate&nbsp;(void) | OH_Drawing_Canvas&nbsp;\*<br/>函数用于创建一个画布对象 |
| OH_Drawing_CanvasDestroy&nbsp;(OH_Drawing_Canvas&nbsp;\*) | void<br/>函数用于销毁画布对象并回收该对象占有的内存 |
| OH_Drawing_CanvasBind&nbsp;(OH_Drawing_Canvas&nbsp;\*,&nbsp;OH_Drawing_Bitmap&nbsp;\*) | void<br/>函数用于将一个位图对象绑定到画布中,使得画布绘制的内容输出到位图中(即CPU渲染) |
| OH_Drawing_CanvasAttachPen&nbsp;(OH_Drawing_Canvas&nbsp;\*,&nbsp;const&nbsp;OH_Drawing_Pen&nbsp;\*) | void<br/>函数用于设置画笔给画布,画布将会使用设置画笔的样式和颜色去绘制图形形状的轮廓 |
| OH_Drawing_CanvasDetachPen&nbsp;(OH_Drawing_Canvas&nbsp;\*) | void<br/>函数用于去除掉画布中的画笔,使用后画布将不去绘制图形形状的轮廓 |
| OH_Drawing_CanvasAttachBrush&nbsp;(OH_Drawing_Canvas&nbsp;\*,&nbsp;const&nbsp;OH_Drawing_Brush&nbsp;\*) | void<br/>函数用于设置画刷给画布,画布将会使用设置的画刷样式和颜色去填充绘制的图形形状 |
| OH_Drawing_CanvasDetachBrush&nbsp;(OH_Drawing_Canvas&nbsp;\*) | void<br/>函数用于去除掉画布中的画刷,使用后画布将不去填充图形形状 |
| OH_Drawing_CanvasSave&nbsp;(OH_Drawing_Canvas&nbsp;\*) | void<br/>函数用于保存当前画布的状态(画布矩阵)到一个栈顶 |
| OH_Drawing_CanvasRestore&nbsp;(OH_Drawing_Canvas&nbsp;\*) | void<br/>函数用于恢复保存在栈顶的画布状态(画布矩阵) |
| OH_Drawing_CanvasDrawLine&nbsp;(OH_Drawing_Canvas&nbsp;\*,&nbsp;float&nbsp;x1,&nbsp;float&nbsp;y1,&nbsp;float&nbsp;x2,&nbsp;float&nbsp;y2) | void<br/>函数用于画一条直线段 |
| OH_Drawing_CanvasDrawPath&nbsp;(OH_Drawing_Canvas&nbsp;\*,&nbsp;const&nbsp;OH_Drawing_Path&nbsp;\*) | void<br/>函数用于画一个自定义路径 |
| OH_Drawing_CanvasClear&nbsp;(OH_Drawing_Canvas&nbsp;\*,&nbsp;uint32_t&nbsp;color) | void<br/>函数用于使用指定颜色去清空画布 |
| OH_Drawing_ColorSetArgb&nbsp;(uint32_t&nbsp;alpha,&nbsp;uint32_t&nbsp;red,&nbsp;uint32_t&nbsp;green,&nbsp;uint32_t&nbsp;blue) | uint32_t<br/>函数用于将4个变量(分别描述透明度、红色、绿色和蓝色)转化为一个描述颜色的32位(ARGB)变量 |
| OH_Drawing_CreateFontCollection&nbsp;(void) | OH_Drawing_FontCollection&nbsp;\*<br/>创建OH_Drawing_FontCollection |
| OH_Drawing_DestroyFontCollection&nbsp;(OH_Drawing_FontCollection&nbsp;\*) | void<br/>释放被OH_Drawing_FontCollection对象占据的内存 |
| OH_Drawing_PathCreate&nbsp;(void) | OH_Drawing_Path&nbsp;\*<br/>函数用于创建一个路径对象 |
| OH_Drawing_PathDestroy&nbsp;(OH_Drawing_Path&nbsp;\*) | void<br/>函数用于销毁路径对象并回收该对象占有的内存 |
| OH_Drawing_PathMoveTo&nbsp;(OH_Drawing_Path&nbsp;\*,&nbsp;float&nbsp;x,&nbsp;float&nbsp;y) | void<br/>函数用于设置自定义路径的起始点位置 |
| OH_Drawing_PathLineTo&nbsp;(OH_Drawing_Path&nbsp;\*,&nbsp;float&nbsp;x,&nbsp;float&nbsp;y) | void<br/>函数用于添加一条从路径的最后点位置到目标点位置的线段 |
| OH_Drawing_PathArcTo&nbsp;(OH_Drawing_Path&nbsp;\*,&nbsp;float&nbsp;x1,&nbsp;float&nbsp;y1,&nbsp;float&nbsp;x2,&nbsp;float&nbsp;y2,&nbsp;float&nbsp;startDeg,&nbsp;float&nbsp;sweepDeg) | void<br/>函数用于给路径添加一段弧线,绘制弧线的方式为角度弧,该方式首先会指定一个矩形边框,矩形边框会包裹椭圆,&nbsp;然后会指定一个起始角度和扫描度数,从起始角度扫描截取的椭圆周长一部分即为绘制的弧线。另外会默认添加一条从路径的最后点位置到弧线起始点位置的线段 |
| OH_Drawing_PathQuadTo&nbsp;(OH_Drawing_Path&nbsp;\*,&nbsp;float&nbsp;ctrlX,&nbsp;float&nbsp;ctrlY,&nbsp;float&nbsp;endX,&nbsp;float&nbsp;endY) | void<br/>函数用于添加一条从路径最后点位置到目标点位置的二阶贝塞尔圆滑曲线 |
| OH_Drawing_PathCubicTo&nbsp;(OH_Drawing_Path&nbsp;\*,&nbsp;float&nbsp;ctrlX1,&nbsp;float&nbsp;ctrlY1,&nbsp;float&nbsp;ctrlX2,&nbsp;float&nbsp;ctrlY2,&nbsp;float&nbsp;endX,&nbsp;float&nbsp;endY) | void<br/>函数用于添加一条从路径最后点位置到目标点位置的三阶贝塞尔圆滑曲线 |
| OH_Drawing_PathClose&nbsp;(OH_Drawing_Path&nbsp;\*) | void<br/>函数用于闭合路径,会添加一条从路径起点位置到最后点位置的线段 |
| OH_Drawing_PathReset&nbsp;(OH_Drawing_Path&nbsp;\*) | void<br/>函数用于重置自定义路径数据 |
| OH_Drawing_PenCreate&nbsp;(void) | OH_Drawing_Pen&nbsp;\*<br/>函数用于创建一个画笔对象 |
| OH_Drawing_PenDestroy&nbsp;(OH_Drawing_Pen&nbsp;\*) | void<br/>函数用于销毁画笔对象并回收该对象占有的内存 |
| OH_Drawing_PenIsAntiAlias&nbsp;(const&nbsp;OH_Drawing_Pen&nbsp;\*) | bool<br/>函数用于获取画笔是否设置抗锯齿属性,如果为真则说明画笔会启用抗锯齿功能,在绘制图形时会对图形的边缘像素进行半透明的模糊处理 |
| OH_Drawing_PenSetAntiAlias&nbsp;(OH_Drawing_Pen&nbsp;\*,&nbsp;bool) | void<br/>函数用于设置画笔的抗锯齿属性,设置为真则画笔在绘制图形时会对图形的边缘像素进行半透明的模糊处理 |
| OH_Drawing_PenGetColor&nbsp;(const&nbsp;OH_Drawing_Pen&nbsp;\*) | uint32_t<br/>函数用于获取画笔的颜色属性,颜色属性描述了画笔绘制图形轮廓时使用的颜色,用一个32位(ARGB)的变量表示 |
| OH_Drawing_PenSetColor&nbsp;(OH_Drawing_Pen&nbsp;\*,&nbsp;uint32_t&nbsp;color) | void<br/>函数用于设置画笔的颜色属性,颜色属性描述了画笔绘制图形轮廓时使用的颜色,用一个32位(ARGB)的变量表示 |
| OH_Drawing_PenGetWidth&nbsp;(const&nbsp;OH_Drawing_Pen&nbsp;\*) | float<br/>函数用于获取画笔的厚度属性,厚度属性描述了画笔绘制图形轮廓的宽度 |
| OH_Drawing_PenSetWidth&nbsp;(OH_Drawing_Pen&nbsp;\*,&nbsp;float&nbsp;width) | void<br/>函数用于设置画笔的厚度属性,厚度属性描述了画笔绘制图形轮廓的宽度 |
| OH_Drawing_PenGetMiterLimit&nbsp;(const&nbsp;OH_Drawing_Pen&nbsp;\*) | float<br/>函数用于获取折线尖角的限制值,当画笔绘制一条折线,转角类型设置为尖角时,那么此时该属性用于限制出现尖角的长度范围,如果超出则平角显示,不超出依然为尖角 |
| OH_Drawing_PenSetMiterLimit&nbsp;(OH_Drawing_Pen&nbsp;\*,&nbsp;float&nbsp;miter) | void<br/>函数用于设置折线尖角的限制值,当画笔绘制一条折线,转角类型设置为尖角时,那么此时该属性用于限制出现尖角的长度范围,如果超出则平角显示,不超出依然为尖角 |
| OH_Drawing_PenGetCap&nbsp;(const&nbsp;OH_Drawing_Pen&nbsp;\*) | OH_Drawing_PenLineCapStyle<br/>函数用于获取画笔笔帽的样式 |
| OH_Drawing_PenSetCap&nbsp;(OH_Drawing_Pen&nbsp;\*,&nbsp;OH_Drawing_PenLineCapStyle) | void<br/>函数用于设置画笔笔帽样式 |
| OH_Drawing_PenGetJoin&nbsp;(const&nbsp;OH_Drawing_Pen&nbsp;\*) | OH_Drawing_PenLineJoinStyle<br/>函数用于获取画笔绘制折线转角的样式 |
| OH_Drawing_PenSetJoin&nbsp;(OH_Drawing_Pen&nbsp;\*,&nbsp;OH_Drawing_PenLineJoinStyle) | void<br/>函数用于设置画笔绘制转角的样式 |
| OH_Drawing_CreateTypographyStyle&nbsp;(void) | OH_Drawing_TypographyStyle&nbsp;\*<br/>创建OH_Drawing_TypographyStyle |
| OH_Drawing_DestroyTypographyStyle&nbsp;(OH_Drawing_TypographyStyle&nbsp;\*) | void<br/>释放被OH_Drawing_TypographyStyle对象占据的内存 |
| OH_Drawing_SetTypographyTextDirection&nbsp;(OH_Drawing_TypographyStyle&nbsp;\*,&nbsp;int) | void<br/>设置文本方向 |
| OH_Drawing_SetTypographyTextAlign&nbsp;(OH_Drawing_TypographyStyle&nbsp;\*,&nbsp;int) | void<br/>设置文本对齐方式 |
| OH_Drawing_SetTypographyTextMaxLines&nbsp;(OH_Drawing_TypographyStyle&nbsp;\*,&nbsp;int) | void<br/>设置文本最大行数 |
| OH_Drawing_CreateTextStyle&nbsp;(void) | OH_Drawing_TextStyle&nbsp;\*<br/>创建OH_Drawing_TextStyle |
| OH_Drawing_DestroyTextStyle&nbsp;(OH_Drawing_TextStyle&nbsp;\*) | void<br/>释放被OH_Drawing_TextStyle对象占据的内存 |
| OH_Drawing_SetTextStyleColor&nbsp;(OH_Drawing_TextStyle&nbsp;\*,&nbsp;uint32_t) | void<br/>设置文本颜色 |
| OH_Drawing_SetTextStyleFontSize&nbsp;(OH_Drawing_TextStyle&nbsp;\*,&nbsp;double) | void<br/>设置字号 |
| OH_Drawing_SetTextStyleFontWeight&nbsp;(OH_Drawing_TextStyle&nbsp;\*,&nbsp;int) | void<br/>设置字重 |
| OH_Drawing_SetTextStyleBaseLine&nbsp;(OH_Drawing_TextStyle&nbsp;\*,&nbsp;int) | void<br/>设置字体基线位置 |
| OH_Drawing_SetTextStyleDecoration&nbsp;(OH_Drawing_TextStyle&nbsp;\*,&nbsp;int) | void<br/>设置装饰 |
| OH_Drawing_SetTextStyleDecorationColor&nbsp;(OH_Drawing_TextStyle&nbsp;\*,&nbsp;uint32_t) | void<br/>设置装饰颜色 |
| OH_Drawing_SetTextStyleFontHeight&nbsp;(OH_Drawing_TextStyle&nbsp;\*,&nbsp;double) | void<br/>设置字体高度 |
| OH_Drawing_SetTextStyleFontFamilies&nbsp;(OH_Drawing_TextStyle&nbsp;\*,&nbsp;int,&nbsp;const&nbsp;char&nbsp;\*fontFamilies[]) | void<br/>设置字体类型 |
| OH_Drawing_SetTextStyleFontStyle&nbsp;(OH_Drawing_TextStyle&nbsp;\*,&nbsp;int) | void<br/>设置字体风格 |
| OH_Drawing_SetTextStyleLocale&nbsp;(OH_Drawing_TextStyle&nbsp;\*,&nbsp;const&nbsp;char&nbsp;\*) | void<br/>设置语言区域 |
| OH_Drawing_CreateTypographyHandler&nbsp;(OH_Drawing_TypographyStyle&nbsp;\*,&nbsp;OH_Drawing_FontCollection&nbsp;\*) | OH_Drawing_TypographyCreate&nbsp;\*<br/>创建指向OH_Drawing_TypographyCreate对象的指针 |
| OH_Drawing_DestroyTypographyHandler&nbsp;(OH_Drawing_TypographyCreate&nbsp;\*) | void<br/>释放被OH_Drawing_TypographyCreate对象占据的内存 |
| OH_Drawing_TypographyHandlerPushStyle&nbsp;(OH_Drawing_TypographyCreate&nbsp;\*,&nbsp;OH_Drawing_TextStyle&nbsp;\*) | void<br/>设置排版风格 |
| OH_Drawing_TypographyHandlerAddText&nbsp;(OH_Drawing_TypographyCreate&nbsp;\*,&nbsp;const&nbsp;char&nbsp;\*) | void<br/>设置文本内容 |
| OH_Drawing_TypographyHandlerPop&nbsp;(OH_Drawing_TypographyCreate&nbsp;\*) | void<br/>排版弹出 |
| OH_Drawing_CreateTypography&nbsp;(OH_Drawing_TypographyCreate&nbsp;\*) | OH_Drawing_Typography&nbsp;\*<br/>创建OH_Drawing_Typography |
| OH_Drawing_DestroyTypography&nbsp;(OH_Drawing_Typography&nbsp;\*) | void<br/>释放OH_Drawing_Typography对象占据的内存 |
| OH_Drawing_TypographyLayout&nbsp;(OH_Drawing_Typography&nbsp;\*,&nbsp;double) | void<br/>排版布局 |
| OH_Drawing_TypographyPaint&nbsp;(OH_Drawing_Typography&nbsp;\*,&nbsp;OH_Drawing_Canvas&nbsp;\*,&nbsp;double,&nbsp;double) | void<br/>显示文本 |
## **Details**
## **Typedef**
### OH_Drawing_Bitmap
```
typedef struct OH_Drawing_Bitmap OH_Drawing_Bitmap
```
**Description:**
OH_Drawing_Bitmap定义为位图,位图是一块内存,内存中包含了描述一张图片的像素数据
### OH_Drawing_Brush
```
typedef struct OH_Drawing_Brush OH_Drawing_Brush
```
**Description:**
OH_Drawing_Brush定义为画刷,画刷用于描述填充图形的样式和颜色
### OH_Drawing_Canvas
```
typedef struct OH_Drawing_Canvas OH_Drawing_Canvas
```
**Description:**
OH_Drawing_Canvas定义为一块矩形的画布,可以结合画笔和画刷在上面绘制各种形状、图片和文字
### OH_Drawing_FontCollection
```
typedef struct OH_Drawing_FontCollection OH_Drawing_FontCollection
```
**Description:**
OH_Drawing_FontCollection用于加载字体
### OH_Drawing_Path
```
typedef struct OH_Drawing_Path OH_Drawing_Path
```
**Description:**
OH_Drawing_Path定义为路径,路径用于自定义各种形状
### OH_Drawing_Pen
```
typedef struct OH_Drawing_Pen OH_Drawing_Pen
```
**Description:**
OH_Drawing_Pen定义为画笔,画笔用于描述绘制图形轮廓的样式和颜色
### OH_Drawing_TextStyle
```
typedef struct OH_Drawing_TextStyle OH_Drawing_TextStyle
```
**Description:**
OH_Drawing_TextStyle用于管理字体颜色、装饰等
### OH_Drawing_Typography
```
typedef struct OH_Drawing_Typography OH_Drawing_Typography
```
**Description:**
OH_Drawing_Typography用于管理排版的布局和显示等
### OH_Drawing_TypographyCreate
```
typedef struct OH_Drawing_TypographyCreate OH_Drawing_TypographyCreate
```
**Description:**
OH_Drawing_TypographyCreate用于创建OH_Drawing_Typography.
### OH_Drawing_TypographyStyle
```
typedef struct OH_Drawing_TypographyStyle OH_Drawing_TypographyStyle
```
**Description:**
OH_Drawing_TypographyStyle用于管理排版风格,如文字方向等
## **Enumeration Type**
### OH_Drawing_AlphaFormat
```
enum OH_Drawing_AlphaFormat
```
**Description:**
OH_Drawing_AlphaFormat用于描述位图像素的透明度分量
| Enumerator | Description |
| -------- | -------- |
| ALPHA_FORMAT_UNKNOWN | 未知格式 |
| ALPHA_FORMAT_OPAQUE | 位图无透明度 |
| ALPHA_FORMAT_PREMUL | 每个像素的颜色组件由透明度分量预先乘以 |
| ALPHA_FORMAT_UNPREMUL | 每个像素的颜色组件未由透明度分量预先乘以 |
### OH_Drawing_ColorFormat
```
enum OH_Drawing_ColorFormat
```
**Description:**
OH_Drawing_ColorFormat用于描述位图像素的存储格式
| Enumerator | Description |
| -------- | -------- |
| COLOR_FORMAT_UNKNOWN | 未知格式. |
| COLOR_FORMAT_ALPHA_8 | 每个像素用一个8位的量表示,8个位比特位表示透明度 |
| COLOR_FORMAT_RGB_565 | 每个像素用一个16位的量表示,高位到低位依次是5个比特位表示红,6个比特位表示绿,5个比特位表示蓝 |
| COLOR_FORMAT_ARGB_4444 | 每个像素用一个16位的量表示,高位到低位依次是4个比特位表示透明度,4个比特位表示红,4个比特位表示绿,4个比特位表示蓝 |
| COLOR_FORMAT_RGBA_8888 | 每个像素用一个32位的量表示,高位到低位依次是8个比特位表示透明度,8个比特位表示红,8个比特位表示绿,8个比特位表示蓝 |
| COLOR_FORMAT_BGRA_8888 | 每个像素用一个32位的量表示,高位到低位依次是8个比特位表示蓝,8个比特位表示绿,8个比特位表示红,8个比特位表示透明度 |
### OH_Drawing_FontStyle
```
enum OH_Drawing_FontStyle
```
**Description:**
区分字体是否为斜体
| Enumerator | Description |
| -------- | -------- |
| FONT_STYLE_NORMAL | 非斜体 |
| FONT_STYLE_ITALIC | 斜体 |
### OH_Drawing_FontWeight
```
enum OH_Drawing_FontWeight
```
**Description:**
字重
| Enumerator | Description |
| -------- | -------- |
| FONT_WEIGHT_100 | 字重为thin |
| FONT_WEIGHT_200 | 字重为extra-light |
| FONT_WEIGHT_300 | 字重为light |
| FONT_WEIGHT_400 | 字重为normal/regular |
| FONT_WEIGHT_500 | 字重为medium |
| FONT_WEIGHT_600 | 字重为semi-bold |
| FONT_WEIGHT_700 | 字重为bold |
| FONT_WEIGHT_800 | 字重为extra-bold |
| FONT_WEIGHT_900 | 字重为black |
### OH_Drawing_PenLineCapStyle
```
enum OH_Drawing_PenLineCapStyle
```
**Description:**
枚举集合定义了画笔笔帽的样式,即画笔在绘制线段时,在线段头尾端点的样式
| Enumerator | Description |
| -------- | -------- |
| LINE_FLAT_CAP | 没有笔帽样式,线条头尾端点处横切 |
| LINE_SQUARE_CAP | 笔帽的样式为方框,线条的头尾端点处多出一个方框,方框宽度和线段一样宽,高度时线段厚度的一半 |
| LINE_ROUND_CAP | 笔帽的样式为圆弧,线条的头尾端点处多出一个半圆弧,半圆的直径与线段厚度一致 |
### OH_Drawing_PenLineJoinStyle
```
enum OH_Drawing_PenLineJoinStyle
```
**Description:**
枚举集合定义了线条转角的样式,即画笔在绘制折线段时,在折线转角处的样式
| Enumerator | Description |
| -------- | -------- |
| LINE_MITER_JOIN | 转角类型为尖角,如果折线角度比较小,则尖角会很长,需要使用限制值(miter&nbsp;limit)进行限制 |
| LINE_ROUND_JOIN | 转角类型为圆头 |
| LINE_BEVEL_JOIN | 转角类型为平头 |
### OH_Drawing_TextAlign
```
enum OH_Drawing_TextAlign
```
**Description:**
文字对齐方式
| Enumerator | Description |
| -------- | -------- |
| TEXT_ALIGN_LEFT | 左对齐 |
| TEXT_ALIGN_RIGHT | 右对齐 |
| TEXT_ALIGN_CENTER | 居中对齐 |
| TEXT_ALIGN_JUSTIFY | 两端对齐,即紧靠左和右边缘,中间单词空隙由空格填充&nbsp;最后一行除外 |
| TEXT_ALIGN_START | 当OH_Drawing_TextDirection是TEXT_DIRECTION_LTR时,&nbsp;TEXT_ALIGN_START和TEXT_ALIGN_LEFT相同;&nbsp;类似地,当OH_Drawing_TextDirection是TEXT_DIRECTION_RTL时,&nbsp;TEXT_ALIGN_START和TEXT_ALIGN_RIGHT相同。 |
| TEXT_ALIGN_END | 当OH_Drawing_TextDirection是TEXT_DIRECTION_LTR时,&nbsp;TEXT_ALIGN_END和TEXT_ALIGN_RIGHT相同;&nbsp;类似地,当OH_Drawing_TextDirection是TEXT_DIRECTION_RTL时,&nbsp;TEXT_ALIGN_END和TEXT_ALIGN_LEFT相同。 |
### OH_Drawing_TextBaseline
```
enum OH_Drawing_TextBaseline
```
**Description:**
基线位置
| Enumerator | Description |
| -------- | -------- |
| TEXT_BASELINE_ALPHABETIC | 用于表音文字,基线在中间偏下的位置 |
| TEXT_BASELINE_IDEOGRAPHIC | 用于表意文字,基线位于底部 |
### OH_Drawing_TextDecoration
```
enum OH_Drawing_TextDecoration
```
**Description:**
文本装饰
| Enumerator | Description |
| -------- | -------- |
| TEXT_DECORATION_NONE | 无装饰 |
| TEXT_DECORATION_UNDERLINE | 下划线 |
| TEXT_DECORATION_OVERLINE | 上划线 |
| TEXT_DECORATION_LINE_THROUGH | 删除线 |
### OH_Drawing_TextDirection
```
enum OH_Drawing_TextDirection
```
**Description:**
文字方向
| Enumerator | Description |
| -------- | -------- |
| TEXT_DIRECTION_RTL | 方向:从右到左 |
| TEXT_DIRECTION_LTR | 方向:从左到右 |
## **Function**
### OH_Drawing_BitmapBuild()
```
void OH_Drawing_BitmapBuild (OH_Drawing_Bitmap * , const uint32_t width, const uint32_t height, const OH_Drawing_BitmapFormat * )
```
**Description:**
函数用于初始化位图对象的宽度和高度,并且为该位图设置像素格式
\@syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
**Parameters:**
| Name | Description |
| -------- | -------- |
| OH_Drawing_Bitmap | 参数是一个指向位图对象的指针 |
| width | 参数是位图要初始化设置的宽度 |
| height | 参数是位图要初始化设置的高度 |
| [OH_Drawing_BitmapFormat](_o_h___drawing___bitmap_format.md) | 参数是位图要初始化设置的像素格式,包括像素的颜色类型和透明度类型 |
### OH_Drawing_BitmapCreate()
```
OH_Drawing_Bitmap* OH_Drawing_BitmapCreate (void )
```
**Description:**
函数用于创建一个位图对象。
\@syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
**Returns:**
函数会返回一个指针,指针指向创建的位图对象
### OH_Drawing_BitmapDestroy()
```
void OH_Drawing_BitmapDestroy (OH_Drawing_Bitmap * )
```
**Description:**
函数用于销毁位图对象并回收该对象占有内存。
\@syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
**Parameters:**
| Name | Description |
| -------- | -------- |
| OH_Drawing_Bitmap | 参数是一个指向位图对象的指针 |
### OH_Drawing_BitmapGetHeight()
```
uint32_t OH_Drawing_BitmapGetHeight (OH_Drawing_Bitmap * )
```
**Description:**
函数用于获取指定位图的高度
\@syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
**Parameters:**
| Name | Description |
| -------- | -------- |
| OH_Drawing_Bitmap | 参数是一个指向位图对象的指针 |
**Returns:**
函数返回位图的高度
### OH_Drawing_BitmapGetPixels()
```
void* OH_Drawing_BitmapGetPixels (OH_Drawing_Bitmap * )
```
**Description:**
函数用于获取指定位图的像素地址,可以通过像素地址获取到位图的像素数据
\@syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
**Parameters:**
| Name | Description |
| -------- | -------- |
| OH_Drawing_Bitmap | 参数是一个指向位图对象的指针 |
**Returns:**
函数返回位图的像素地址
### OH_Drawing_BitmapGetWidth()
```
uint32_t OH_Drawing_BitmapGetWidth (OH_Drawing_Bitmap * )
```
**Description:**
该函数用于获取指定位图的宽度
\@syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
**Parameters:**
| Name | Description |
| -------- | -------- |
| OH_Drawing_Bitmap | 参数是一个指向位图对象的指针 |
**Returns:**
函数返回位图的宽度
### OH_Drawing_BrushCreate()
```
OH_Drawing_Brush* OH_Drawing_BrushCreate (void )
```
**Description:**
函数用于创建一个画刷对象
\@syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
**Returns:**
函数会返回一个指针,指针指向创建的画刷对象
### OH_Drawing_BrushDestroy()
```
void OH_Drawing_BrushDestroy (OH_Drawing_Brush * )
```
**Description:**
函数用于销毁画刷对象并回收该对象占有的内存。
\@syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
**Parameters:**
| Name | Description |
| -------- | -------- |
| OH_Drawing_Brush | 参数是一个指向画刷对象的指针 |
### OH_Drawing_BrushGetColor()
```
uint32_t OH_Drawing_BrushGetColor (const OH_Drawing_Brush * )
```
**Description:**
函数用于获取画刷的颜色属性,颜色属性描述了画刷填充图形时使用的颜色,用一个32位(ARGB)的变量表示
\@syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
**Parameters:**
| Name | Description |
| -------- | -------- |
| OH_Drawing_Brush | 参数是一个指向画刷对象的指针 |
**Returns:**
函数返回一个描述颜色的32位(ARGB)变量
### OH_Drawing_BrushIsAntiAlias()
```
bool OH_Drawing_BrushIsAntiAlias (const OH_Drawing_Brush * )
```
**Description:**
函数用于获取画刷是否设置抗锯齿属性,如果为真则说明画刷会启用抗锯齿功能,在绘制图形时会对图形的边缘像素进行半透明的模糊处理
\@syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
**Parameters:**
| Name | Description |
| -------- | -------- |
| OH_Drawing_Brush | 参数是一个指向画刷对象的指针 |
**Returns:**
函数返回画刷对象是否设置抗锯齿属性,返回真则设置了抗锯齿,返回假则没有设置抗锯齿
### OH_Drawing_BrushSetAntiAlias()
```
void OH_Drawing_BrushSetAntiAlias (OH_Drawing_Brush * , bool )
```
**Description:**
函数用于设置画刷的抗锯齿属性,设置为真则画刷在绘制图形时会对图形的边缘像素进行半透明的模糊处理
\@syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
**Parameters:**
| Name | Description |
| -------- | -------- |
| OH_Drawing_Brush | 参数是一个指向画刷对象的指针 |
| bool | 参数真为抗锯齿,参数假则不做抗锯齿处理 |
### OH_Drawing_BrushSetColor()
```
void OH_Drawing_BrushSetColor (OH_Drawing_Brush * , uint32_t color )
```
**Description:**
函数用于设置画刷的颜色属性,颜色属性描述了画刷填充图形时使用的颜色,用一个32位(ARGB)的变量表示
\@syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
**Parameters:**
| Name | Description |
| -------- | -------- |
| OH_Drawing_Brush | 参数是一个指向画刷对象的指针 |
| color | 参数是一个描述颜色的32位(ARGB)变量 |
### OH_Drawing_CanvasAttachBrush()
```
void OH_Drawing_CanvasAttachBrush (OH_Drawing_Canvas * , const OH_Drawing_Brush * )
```
**Description:**
函数用于设置画刷给画布,画布将会使用设置的画刷样式和颜色去填充绘制的图形形状
\@syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
**Parameters:**
| Name | Description |
| -------- | -------- |
| OH_Drawing_Canvas | 参数为一个指向画布对象的指针 |
| OH_Drawing_Brush | 参数为一个指向画刷对象的指针 |
### OH_Drawing_CanvasAttachPen()
```
void OH_Drawing_CanvasAttachPen (OH_Drawing_Canvas * , const OH_Drawing_Pen * )
```
**Description:**
函数用于设置画笔给画布,画布将会使用设置画笔的样式和颜色去绘制图形形状的轮廓
\@syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
**Parameters:**
| Name | Description |
| -------- | -------- |
| OH_Drawing_Canvas | 参数为一个指向画布对象的指针 |
| OH_Drawing_Pen | 参数为一个指向画笔对象的指针 |
### OH_Drawing_CanvasBind()
```
void OH_Drawing_CanvasBind (OH_Drawing_Canvas * , OH_Drawing_Bitmap * )
```
**Description:**
函数用于将一个位图对象绑定到画布中,使得画布绘制的内容输出到位图中(即CPU渲染)
\@syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
**Parameters:**
| Name | Description |
| -------- | -------- |
| OH_Drawing_Canvas | 参数为一个指向画布对象的指针 |
| OH_Drawing_Bitmap | 参数为一个指向位图对象的指针 |
### OH_Drawing_CanvasClear()
```
void OH_Drawing_CanvasClear (OH_Drawing_Canvas * , uint32_t color )
```
**Description:**
函数用于使用指定颜色去清空画布
\@syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
**Parameters:**
| Name | Description |
| -------- | -------- |
| OH_Drawing_Canvas | 参数为一个指向画布对象的指针 |
| color | 参数为一个描述颜色的32位(ARGB)变量 |
### OH_Drawing_CanvasCreate()
```
OH_Drawing_Canvas* OH_Drawing_CanvasCreate (void )
```
**Description:**
函数用于创建一个画布对象
\@syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
**Returns:**
函数会返回一个指针,指针指向创建的画布对象
### OH_Drawing_CanvasDestroy()
```
void OH_Drawing_CanvasDestroy (OH_Drawing_Canvas * )
```
**Description:**
函数用于销毁画布对象并回收该对象占有的内存
\@syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
**Parameters:**
| Name | Description |
| -------- | -------- |
| OH_Drawing_Canvas | 参数是一个指向画布对象的指针 |
### OH_Drawing_CanvasDetachBrush()
```
void OH_Drawing_CanvasDetachBrush (OH_Drawing_Canvas * )
```
**Description:**
函数用于去除掉画布中的画刷,使用后画布将不去填充图形形状
\@syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
**Parameters:**
| Name | Description |
| -------- | -------- |
| OH_Drawing_Canvas | 参数为一个指向画布对象的指针 |
### OH_Drawing_CanvasDetachPen()
```
void OH_Drawing_CanvasDetachPen (OH_Drawing_Canvas * )
```
**Description:**
函数用于去除掉画布中的画笔,使用后画布将不去绘制图形形状的轮廓
\@syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
**Parameters:**
| Name | Description |
| -------- | -------- |
| OH_Drawing_Canvas | 参数为一个指向画布对象的指针 |
### OH_Drawing_CanvasDrawLine()
```
void OH_Drawing_CanvasDrawLine (OH_Drawing_Canvas * , float x1, float y1, float x2, float y2 )
```
**Description:**
函数用于画一条直线段
\@syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
**Parameters:**
| Name | Description |
| -------- | -------- |
| OH_Drawing_Canvas | 参数为一个指向画布对象的指针 |
| x1 | 参数为线段起始点的横坐标 |
| y1 | 参数为线段起始点的纵坐标 |
| x2 | 参数为线段结束点的横坐标 |
| y2 | 参数为线段结束点的纵坐标 |
### OH_Drawing_CanvasDrawPath()
```
void OH_Drawing_CanvasDrawPath (OH_Drawing_Canvas * , const OH_Drawing_Path * )
```
**Description:**
函数用于画一个自定义路径
\@syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
**Parameters:**
| Name | Description |
| -------- | -------- |
| OH_Drawing_Canvas | 参数为一个指向画布对象的指针 |
| OH_Drawing_Path | 参数为一个指向路径对象的指针 |
### OH_Drawing_CanvasRestore()
```
void OH_Drawing_CanvasRestore (OH_Drawing_Canvas * )
```
**Description:**
函数用于恢复保存在栈顶的画布状态(画布矩阵)
\@syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
**Parameters:**
| Name | Description |
| -------- | -------- |
| OH_Drawing_Canvas | 参数为一个指向画布对象的指针 |
### OH_Drawing_CanvasSave()
```
void OH_Drawing_CanvasSave (OH_Drawing_Canvas * )
```
**Description:**
函数用于保存当前画布的状态(画布矩阵)到一个栈顶
\@syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
**Parameters:**
| Name | Description |
| -------- | -------- |
| OH_Drawing_Canvas | 参数为一个指向画布对象的指针 |
### OH_Drawing_ColorSetArgb()
```
uint32_t OH_Drawing_ColorSetArgb (uint32_t alpha, uint32_t red, uint32_t green, uint32_t blue )
```
**Description:**
函数用于将4个变量(分别描述透明度、红色、绿色和蓝色)转化为一个描述颜色的32位(ARGB)变量
\@syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
**Parameters:**
| Name | Description |
| -------- | -------- |
| alpha | 参数为一个描述透明度的变量,&nbsp;变量范围是0x00~0xFF |
| red | 参数为一个描述红色的变量,&nbsp;变量范围是0x00~0xFF |
| green | 参数为一个描述绿色的变量,&nbsp;变量范围是0x00~0xFF |
| blue | 参数为一个描述蓝色的变量,&nbsp;变量范围是0x00~0xFF |
**Returns:**
函数返回一个描述颜色的32位(ARGB)变量
### OH_Drawing_CreateFontCollection()
```
OH_Drawing_FontCollection* OH_Drawing_CreateFontCollection (void )
```
**Description:**
创建OH_Drawing_FontCollection
\@syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
**Returns:**
指向创建的OH_Drawing_FontCollection对象的指针
### OH_Drawing_CreateTextStyle()
```
OH_Drawing_TextStyle* OH_Drawing_CreateTextStyle (void )
```
**Description:**
创建OH_Drawing_TextStyle
\@syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
**Returns:**
指向创建的OH_Drawing_TextStyle对象的指针
### OH_Drawing_CreateTypography()
```
OH_Drawing_Typography* OH_Drawing_CreateTypography (OH_Drawing_TypographyCreate * )
```
**Description:**
创建OH_Drawing_Typography
\@syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
**Parameters:**
| Name | Description |
| -------- | -------- |
| OH_Drawing_TypographyCreate | 指向OH_Drawing_TypographyCreate对象的指针 |
**Returns:**
指向OH_Drawing_Typography对象的指针
### OH_Drawing_CreateTypographyHandler()
```
OH_Drawing_TypographyCreate* OH_Drawing_CreateTypographyHandler (OH_Drawing_TypographyStyle * , OH_Drawing_FontCollection * )
```
**Description:**
创建指向OH_Drawing_TypographyCreate对象的指针
\@syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
**Parameters:**
| Name | Description |
| -------- | -------- |
| OH_Drawing_TypographyStyle | 指向OH_Drawing_TypographyStyle的指针 |
| OH_Drawing_FontCollection | 指向OH_Drawing_FontCollection的指针 |
**Returns:**
指向新创建的OH_Drawing_TypographyCreate对象的指针
### OH_Drawing_CreateTypographyStyle()
```
OH_Drawing_TypographyStyle* OH_Drawing_CreateTypographyStyle (void )
```
**Description:**
创建OH_Drawing_TypographyStyle
\@syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
**Returns:**
指向创建的OH_Drawing_TypographyStyle对象的指针
### OH_Drawing_DestroyFontCollection()
```
void OH_Drawing_DestroyFontCollection (OH_Drawing_FontCollection * )
```
**Description:**
释放被OH_Drawing_FontCollection对象占据的内存
\@syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
**Parameters:**
| Name | Description |
| -------- | -------- |
| OH_Drawing_FontCollection | 指向OH_Drawing_FontCollection对象的指针 |
### OH_Drawing_DestroyTextStyle()
```
void OH_Drawing_DestroyTextStyle (OH_Drawing_TextStyle * )
```
**Description:**
释放被OH_Drawing_TextStyle对象占据的内存
\@syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
**Parameters:**
| Name | Description |
| -------- | -------- |
| OH_Drawing_TextStyle | 指向OH_Drawing_TextStyle对象的指针 |
### OH_Drawing_DestroyTypography()
```
void OH_Drawing_DestroyTypography (OH_Drawing_Typography * )
```
**Description:**
释放OH_Drawing_Typography对象占据的内存
\@syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
**Parameters:**
| Name | Description |
| -------- | -------- |
| OH_Drawing_Typography | 指向OH_Drawing_Typography对象的指针 |
### OH_Drawing_DestroyTypographyHandler()
```
void OH_Drawing_DestroyTypographyHandler (OH_Drawing_TypographyCreate * )
```
**Description:**
释放被OH_Drawing_TypographyCreate对象占据的内存
\@syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
**Parameters:**
| Name | Description |
| -------- | -------- |
| OH_Drawing_TypographyCreate | 指向OH_Drawing_TypographyCreate对象的指针 |
### OH_Drawing_DestroyTypographyStyle()
```
void OH_Drawing_DestroyTypographyStyle (OH_Drawing_TypographyStyle * )
```
**Description:**
释放被OH_Drawing_TypographyStyle对象占据的内存
\@syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
**Parameters:**
| Name | Description |
| -------- | -------- |
| OH_Drawing_TypographyStyle | 指向OH_Drawing_TypographyStyle对象的指针 |
### OH_Drawing_PathArcTo()
```
void OH_Drawing_PathArcTo (OH_Drawing_Path * , float x1, float y1, float x2, float y2, float startDeg, float sweepDeg )
```
**Description:**
函数用于给路径添加一段弧线,绘制弧线的方式为角度弧,该方式首先会指定一个矩形边框,矩形边框会包裹椭圆, 然后会指定一个起始角度和扫描度数,从起始角度扫描截取的椭圆周长一部分即为绘制的弧线。另外会默认添加一条从路径的最后点位置到弧线起始点位置的线段
\@syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
**Parameters:**
| Name | Description |
| -------- | -------- |
| OH_Drawing_Path | 参数为一个指向路径对象的指针 |
| x1 | 参数为包围椭圆的矩形左上角点位置的横坐标 |
| y1 | 参数为包围椭圆的矩形左上角点位置的纵坐标 |
| x2 | 参数为包围椭圆的矩形右下角点位置的横坐标 |
| y3 | 参数为包围椭圆的矩形右下角点位置的纵坐标 |
### OH_Drawing_PathClose()
```
void OH_Drawing_PathClose (OH_Drawing_Path * )
```
**Description:**
函数用于闭合路径,会添加一条从路径起点位置到最后点位置的线段
\@syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
**Parameters:**
| Name | Description |
| -------- | -------- |
| OH_Drawing_Path | 参数为一个指向路径对象的指针 |
### OH_Drawing_PathCreate()
```
OH_Drawing_Path* OH_Drawing_PathCreate (void )
```
**Description:**
函数用于创建一个路径对象
\@syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
**Returns:**
函数会返回一个指针,指针指向创建的路径对象
### OH_Drawing_PathCubicTo()
```
void OH_Drawing_PathCubicTo (OH_Drawing_Path * , float ctrlX1, float ctrlY1, float ctrlX2, float ctrlY2, float endX, float endY )
```
**Description:**
函数用于添加一条从路径最后点位置到目标点位置的三阶贝塞尔圆滑曲线
\@syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
**Parameters:**
| Name | Description |
| -------- | -------- |
| OH_Drawing_Path | 参数为一个指向路径对象的指针 |
| ctrlX1 | 参数为第一个控制点位置的横坐标 |
| ctrlY1 | 参数为第一个控制点位置的纵坐标 |
| ctrlX2 | 参数为第二个控制点位置的横坐标 |
| ctrlY2 | 参数为第二个控制点位置的纵坐标 |
| endX | 参数为目标点位置的横坐标 |
| endY | 参数为目标点位置的纵坐标 |
### OH_Drawing_PathDestroy()
```
void OH_Drawing_PathDestroy (OH_Drawing_Path * )
```
**Description:**
函数用于销毁路径对象并回收该对象占有的内存
\@syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
**Parameters:**
| Name | Description |
| -------- | -------- |
| OH_Drawing_Path | 参数为一个指向路径对象的指针 |
### OH_Drawing_PathLineTo()
```
void OH_Drawing_PathLineTo (OH_Drawing_Path * , float x, float y )
```
**Description:**
函数用于添加一条从路径的最后点位置到目标点位置的线段
\@syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
**Parameters:**
| Name | Description |
| -------- | -------- |
| OH_Drawing_Path | 参数为一个指向路径对象的指针 |
| x | 参数为目标点的横坐标 |
| y | 参数为目标点的纵坐标 |
### OH_Drawing_PathMoveTo()
```
void OH_Drawing_PathMoveTo (OH_Drawing_Path * , float x, float y )
```
**Description:**
函数用于设置自定义路径的起始点位置
\@syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
**Parameters:**
| Name | Description |
| -------- | -------- |
| OH_Drawing_Path | 参数为一个指向路径对象的指针 |
| x | 参数为起始点的横坐标 |
| y | 参数为起始点的纵坐标 |
### OH_Drawing_PathQuadTo()
```
void OH_Drawing_PathQuadTo (OH_Drawing_Path * , float ctrlX, float ctrlY, float endX, float endY )
```
**Description:**
函数用于添加一条从路径最后点位置到目标点位置的二阶贝塞尔圆滑曲线
\@syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
**Parameters:**
| Name | Description |
| -------- | -------- |
| OH_Drawing_Path | 参数为一个指向路径对象的指针 |
| ctrlX | 参数为控制点位置的横坐标 |
| ctrlY | 参数为控制点位置的纵坐标 |
| endX | 参数为目标点位置的横坐标 |
| endY | 参数为目标点位置的纵坐标 |
### OH_Drawing_PathReset()
```
void OH_Drawing_PathReset (OH_Drawing_Path * )
```
**Description:**
函数用于重置自定义路径数据
\@syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
**Parameters:**
| Name | Description |
| -------- | -------- |
| OH_Drawing_Path | 参数为一个指向路径对象的指针 |
### OH_Drawing_PenCreate()
```
OH_Drawing_Pen* OH_Drawing_PenCreate (void )
```
**Description:**
函数用于创建一个画笔对象
\@syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
**Returns:**
函数会返回一个指针,指针指向创建的画笔对象
### OH_Drawing_PenDestroy()
```
void OH_Drawing_PenDestroy (OH_Drawing_Pen * )
```
**Description:**
函数用于销毁画笔对象并回收该对象占有的内存
\@syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
**Parameters:**
| Name | Description |
| -------- | -------- |
| OH_Drawing_Pen | 参数是一个指向画笔对象的指针 |
### OH_Drawing_PenGetCap()
```
OH_Drawing_PenLineCapStyle OH_Drawing_PenGetCap (const OH_Drawing_Pen * )
```
**Description:**
函数用于获取画笔笔帽的样式
\@syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
**Parameters:**
| Name | Description |
| -------- | -------- |
| OH_Drawing_Pen | 参数是一个指向画笔对象的指针 |
**Returns:**
函数返回画笔笔帽样式
### OH_Drawing_PenGetColor()
```
uint32_t OH_Drawing_PenGetColor (const OH_Drawing_Pen * )
```
**Description:**
函数用于获取画笔的颜色属性,颜色属性描述了画笔绘制图形轮廓时使用的颜色,用一个32位(ARGB)的变量表示
\@syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
**Parameters:**
| Name | Description |
| -------- | -------- |
| OH_Drawing_Pen | 参数是一个指向画笔对象的指针 |
**Returns:**
函数返回一个描述颜色的32位(ARGB)变量
### OH_Drawing_PenGetJoin()
```
OH_Drawing_PenLineJoinStyle OH_Drawing_PenGetJoin (const OH_Drawing_Pen * )
```
**Description:**
函数用于获取画笔绘制折线转角的样式
\@syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
**Parameters:**
| Name | Description |
| -------- | -------- |
| OH_Drawing_Pen | 参数是一个指向画笔对象的指针 |
**Returns:**
函数返回折线转角的样式
### OH_Drawing_PenGetMiterLimit()
```
float OH_Drawing_PenGetMiterLimit (const OH_Drawing_Pen * )
```
**Description:**
函数用于获取折线尖角的限制值,当画笔绘制一条折线,转角类型设置为尖角时,那么此时该属性用于限制出现尖角的长度范围,如果超出则平角显示,不超出依然为尖角
\@syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
**Parameters:**
| Name | Description |
| -------- | -------- |
| OH_Drawing_Pen | 参数是一个指向画笔对象的指针 |
**Returns:**
函数返回尖角的限制值
### OH_Drawing_PenGetWidth()
```
float OH_Drawing_PenGetWidth (const OH_Drawing_Pen * )
```
**Description:**
函数用于获取画笔的厚度属性,厚度属性描述了画笔绘制图形轮廓的宽度
\@syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
**Parameters:**
| Name | Description |
| -------- | -------- |
| OH_Drawing_Pen | 参数是一个指向画笔对象的指针 |
**Returns:**
函数返回画笔的厚度
### OH_Drawing_PenIsAntiAlias()
```
bool OH_Drawing_PenIsAntiAlias (const OH_Drawing_Pen * )
```
**Description:**
函数用于获取画笔是否设置抗锯齿属性,如果为真则说明画笔会启用抗锯齿功能,在绘制图形时会对图形的边缘像素进行半透明的模糊处理
\@syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
**Parameters:**
| Name | Description |
| -------- | -------- |
| OH_Drawing_Pen | 参数是一个指向画笔对象的指针 |
**Returns:**
函数返回画笔对象是否设置抗锯齿属性,返回真则设置了抗锯齿,返回假则没有设置抗锯齿
### OH_Drawing_PenSetAntiAlias()
```
void OH_Drawing_PenSetAntiAlias (OH_Drawing_Pen * , bool )
```
**Description:**
函数用于设置画笔的抗锯齿属性,设置为真则画笔在绘制图形时会对图形的边缘像素进行半透明的模糊处理
\@syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
**Parameters:**
| Name | Description |
| -------- | -------- |
| OH_Drawing_Pen | 参数是一个指向画笔对象的指针 |
| bool | 参数真为抗锯齿,参数假则不做抗锯齿处理 |
### OH_Drawing_PenSetCap()
```
void OH_Drawing_PenSetCap (OH_Drawing_Pen * , OH_Drawing_PenLineCapStyle )
```
**Description:**
函数用于设置画笔笔帽样式
\@syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
**Parameters:**
| Name | Description |
| -------- | -------- |
| OH_Drawing_Pen | 参数是一个指向画笔对象的指针 |
| OH_Drawing_PenLineCapStyle | 参数是一个描述画笔笔帽样式的变量 |
### OH_Drawing_PenSetColor()
```
void OH_Drawing_PenSetColor (OH_Drawing_Pen * , uint32_t color )
```
**Description:**
函数用于设置画笔的颜色属性,颜色属性描述了画笔绘制图形轮廓时使用的颜色,用一个32位(ARGB)的变量表示
\@syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
**Parameters:**
| Name | Description |
| -------- | -------- |
| OH_Drawing_Pen | 参数是一个指向画笔对象的指针 |
| color | 参数是一个描述颜色的32位(ARGB)变量 |
### OH_Drawing_PenSetJoin()
```
void OH_Drawing_PenSetJoin (OH_Drawing_Pen * , OH_Drawing_PenLineJoinStyle )
```
**Description:**
函数用于设置画笔绘制转角的样式
\@syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
**Parameters:**
| Name | Description |
| -------- | -------- |
| OH_Drawing_Pen | 参数是一个指向画笔对象的指针 |
| OH_Drawing_PenLineJoinStyle | 参数值一个描述折线转角样式的变量 |
### OH_Drawing_PenSetMiterLimit()
```
void OH_Drawing_PenSetMiterLimit (OH_Drawing_Pen * , float miter )
```
**Description:**
函数用于设置折线尖角的限制值,当画笔绘制一条折线,转角类型设置为尖角时,那么此时该属性用于限制出现尖角的长度范围,如果超出则平角显示,不超出依然为尖角
\@syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
**Parameters:**
| Name | Description |
| -------- | -------- |
| OH_Drawing_Pen | 参数是一个指向画笔对象的指针 |
| miter | 参数是一个描述尖角限制值的变量 |
### OH_Drawing_PenSetWidth()
```
void OH_Drawing_PenSetWidth (OH_Drawing_Pen * , float width )
```
**Description:**
函数用于设置画笔的厚度属性,厚度属性描述了画笔绘制图形轮廓的宽度
\@syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
**Parameters:**
| Name | Description |
| -------- | -------- |
| OH_Drawing_Pen | 参数是一个指向画笔对象的指针 |
| width | 参数是一个描述画笔厚度的变量 |
### OH_Drawing_SetTextStyleBaseLine()
```
void OH_Drawing_SetTextStyleBaseLine (OH_Drawing_TextStyle * , int )
```
**Description:**
设置字体基线位置
\@syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
**Parameters:**
| Name | Description |
| -------- | -------- |
| OH_Drawing_TextStyle | 指向OH_Drawing_TextStyle对象的指针 |
| int | OH_Drawing_TextBaseline枚举类型 |
### OH_Drawing_SetTextStyleColor()
```
void OH_Drawing_SetTextStyleColor (OH_Drawing_TextStyle * , uint32_t )
```
**Description:**
设置文本颜色
\@syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
**Parameters:**
| Name | Description |
| -------- | -------- |
| OH_Drawing_TextStyle | 指向OH_Drawing_TextStyle对象的指针 |
| uint32_t | 颜色 |
### OH_Drawing_SetTextStyleDecoration()
```
void OH_Drawing_SetTextStyleDecoration (OH_Drawing_TextStyle * , int )
```
**Description:**
设置装饰
\@syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
**Parameters:**
| Name | Description |
| -------- | -------- |
| OH_Drawing_TextStyle | 指向OH_Drawing_TextStyle对象的指针 |
| int | OH_Drawing_TextDecoration枚举类型 |
### OH_Drawing_SetTextStyleDecorationColor()
```
void OH_Drawing_SetTextStyleDecorationColor (OH_Drawing_TextStyle * , uint32_t )
```
**Description:**
设置装饰颜色
\@syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
**Parameters:**
| Name | Description |
| -------- | -------- |
| OH_Drawing_TextStyle | 指向OH_Drawing_TextStyle对象的指针 |
| uint32_t | 颜色 |
### OH_Drawing_SetTextStyleFontFamilies()
```
void OH_Drawing_SetTextStyleFontFamilies (OH_Drawing_TextStyle * , int , const char * fontFamilies[] )
```
**Description:**
设置字体类型
\@syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
**Parameters:**
| Name | Description |
| -------- | -------- |
| OH_Drawing_TextStyle | 指向OH_Drawing_TextStyle对象的指针 |
| int | 字体名称数量 |
| char | 指向字体类型的指针 |
### OH_Drawing_SetTextStyleFontHeight()
```
void OH_Drawing_SetTextStyleFontHeight (OH_Drawing_TextStyle * , double )
```
**Description:**
设置字体高度
\@syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
**Parameters:**
| Name | Description |
| -------- | -------- |
| OH_Drawing_TextStyle | 指向OH_Drawing_TextStyle对象的指针 |
| double | 字体高度 |
### OH_Drawing_SetTextStyleFontSize()
```
void OH_Drawing_SetTextStyleFontSize (OH_Drawing_TextStyle * , double )
```
**Description:**
设置字号
\@syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
**Parameters:**
| Name | Description |
| -------- | -------- |
| OH_Drawing_TextStyle | 指向OH_Drawing_TextStyle对象的指针 |
| double | 字号 |
### OH_Drawing_SetTextStyleFontStyle()
```
void OH_Drawing_SetTextStyleFontStyle (OH_Drawing_TextStyle * , int )
```
**Description:**
设置字体风格
\@syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
**Parameters:**
| Name | Description |
| -------- | -------- |
| OH_Drawing_TextStyle | 指向OH_Drawing_TextStyle对象的指针 |
| int | OH_Drawing_FontStyle枚举类型 |
### OH_Drawing_SetTextStyleFontWeight()
```
void OH_Drawing_SetTextStyleFontWeight (OH_Drawing_TextStyle * , int )
```
**Description:**
设置字重
\@syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
**Parameters:**
| Name | Description |
| -------- | -------- |
| OH_Drawing_TextStyle | 指向OH_Drawing_TextStyle对象的指针 |
| int | OH_Drawing_FontWeight枚举类型 |
### OH_Drawing_SetTextStyleLocale()
```
void OH_Drawing_SetTextStyleLocale (OH_Drawing_TextStyle * , const char * )
```
**Description:**
设置语言区域
\@syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
**Parameters:**
| Name | Description |
| -------- | -------- |
| OH_Drawing_TextStyle | 指向OH_Drawing_TextStyle对象的指针 |
| char | 语言区域,数据类型为指向char的指针 |
### OH_Drawing_SetTypographyTextAlign()
```
void OH_Drawing_SetTypographyTextAlign (OH_Drawing_TypographyStyle * , int )
```
**Description:**
设置文本对齐方式
\@syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
**Parameters:**
| Name | Description |
| -------- | -------- |
| OH_Drawing_TypographyStyle | 指向OH_Drawing_TypographyStyle对象的指针 |
| int | OH_Drawing_TextAlign枚举类型 |
### OH_Drawing_SetTypographyTextDirection()
```
void OH_Drawing_SetTypographyTextDirection (OH_Drawing_TypographyStyle * , int )
```
**Description:**
设置文本方向
\@syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
**Parameters:**
| Name | Description |
| -------- | -------- |
| OH_Drawing_TypographyStyle | 指向OH_Drawing_TypographyStyle对象的指针 |
| int | OH_Drawing_TextDirection枚举类型 |
### OH_Drawing_SetTypographyTextMaxLines()
```
void OH_Drawing_SetTypographyTextMaxLines (OH_Drawing_TypographyStyle * , int )
```
**Description:**
设置文本最大行数
\@syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
**Parameters:**
| Name | Description |
| -------- | -------- |
| OH_Drawing_TypographyStyle | 指向OH_Drawing_TypographyStyle对象的指针 |
| int | 最大行数 |
### OH_Drawing_TypographyHandlerAddText()
```
void OH_Drawing_TypographyHandlerAddText (OH_Drawing_TypographyCreate * , const char * )
```
**Description:**
设置文本内容
\@syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
**Parameters:**
| Name | Description |
| -------- | -------- |
| OH_Drawing_TypographyCreate | 指向OH_Drawing_TypographyCreate对象的指针 |
| char | 指向文本内容的指针 |
### OH_Drawing_TypographyHandlerPop()
```
void OH_Drawing_TypographyHandlerPop (OH_Drawing_TypographyCreate * )
```
**Description:**
排版弹出
\@syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
**Parameters:**
| Name | Description |
| -------- | -------- |
| OH_Drawing_TypographyCreate | 指向OH_Drawing_TypographyCreate对象的指针 |
### OH_Drawing_TypographyHandlerPushStyle()
```
void OH_Drawing_TypographyHandlerPushStyle (OH_Drawing_TypographyCreate * , OH_Drawing_TextStyle * )
```
**Description:**
设置排版风格
\@syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
**Parameters:**
| Name | Description |
| -------- | -------- |
| OH_Drawing_TypographyCreate | 指向OH_Drawing_TypographyCreate对象的指针 |
| OH_Drawing_TextStyle | 指向OH_Drawing_TextStyle对象的指针 |
### OH_Drawing_TypographyLayout()
```
void OH_Drawing_TypographyLayout (OH_Drawing_Typography * , double )
```
**Description:**
排版布局
\@syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
**Parameters:**
| Name | Description |
| -------- | -------- |
| OH_Drawing_Typography | 指向OH_Drawing_Typography对象的指针 |
| double | 文本最大宽度 |
### OH_Drawing_TypographyPaint()
```
void OH_Drawing_TypographyPaint (OH_Drawing_Typography * , OH_Drawing_Canvas * , double , double )
```
**Description:**
显示文本
\@syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
**Parameters:**
| Name | Description |
| -------- | -------- |
| OH_Drawing_Typography | 指向OH_Drawing_Typography对象的指针 |
| OH_Drawing_Canvas | 指向OH_Drawing_Canvas对象的指针 |
| double | x坐标 |
| double | y坐标 |
# HiLog
## **Overview**
**Description:**
HiLog模块实现日志打印功能。
开发者可以通过使用这些接口实现日志相关功能,输出日志时可以指定日志类型、所属业务领域、日志TAG标识、日志级别等。
\@syscap SystemCapability.HiviewDFX.HiLog
**Since:**
8
## **Summary**
### Files
| File&nbsp;Name | Description |
| -------- | -------- |
| [log.h](log_8h.md) | HiLog模块日志接口定义,通过这些接口实现日志打印相关功能。 |
### Macros
| Macro&nbsp;Name&nbsp;and&nbsp;Value | Description |
| -------- | -------- |
| LOG_DOMAIN&nbsp;&nbsp;&nbsp;0 | 日志所对应的业务领域,用于标识业务的子系统、模块。 |
| LOG_TAG&nbsp;&nbsp;&nbsp;NULL | 字符串常量,标识调用所在的类或者业务。 |
| OH_LOG_DEBUG(type,&nbsp;...)&nbsp;&nbsp;&nbsp;((void)OH_LOG_Print((type),&nbsp;LOG_DEBUG,&nbsp;LOG_DOMAIN,&nbsp;LOG_TAG,&nbsp;__VA_ARGS__)) | DEBUG级别写日志,宏封装接口。 |
| OH_LOG_INFO(type,&nbsp;...)&nbsp;&nbsp;&nbsp;((void)OH_LOG_Print((type),&nbsp;LOG_INFO,&nbsp;LOG_DOMAIN,&nbsp;LOG_TAG,&nbsp;__VA_ARGS__)) | INFO级别写日志,宏封装接口。 |
| OH_LOG_WARN(type,&nbsp;...)&nbsp;&nbsp;&nbsp;((void)OH_LOG_Print((type),&nbsp;LOG_WARN,&nbsp;LOG_DOMAIN,&nbsp;LOG_TAG,&nbsp;__VA_ARGS__)) | WARN级别写日志,宏封装接口。 |
| OH_LOG_ERROR(type,&nbsp;...)&nbsp;&nbsp;&nbsp;((void)OH_LOG_Print((type),&nbsp;LOG_ERROR,&nbsp;LOG_DOMAIN,&nbsp;LOG_TAG,&nbsp;__VA_ARGS__)) | ERROR级别写日志,宏封装接口。 |
| OH_LOG_FATAL(type,&nbsp;...)&nbsp;&nbsp;&nbsp;((void)HiLogPrint((type),&nbsp;LOG_FATAL,&nbsp;LOG_DOMAIN,&nbsp;LOG_TAG,&nbsp;__VA_ARGS__)) | FATAL级别写日志,宏封装接口。 |
### Enumerations
| Enumeration&nbsp;Name | Description |
| -------- | -------- |
| LogType&nbsp;{&nbsp;LOG_APP&nbsp;=&nbsp;0&nbsp;} | 日志类型。 |
| LogLevel&nbsp;{&nbsp;&nbsp;&nbsp;LOG_DEBUG&nbsp;=&nbsp;3,&nbsp;LOG_INFO&nbsp;=&nbsp;4,&nbsp;LOG_WARN&nbsp;=&nbsp;5,&nbsp;LOG_ERROR&nbsp;=&nbsp;6,&nbsp;&nbsp;&nbsp;LOG_FATAL&nbsp;=&nbsp;7&nbsp;} | 日志级别。 |
### Functions
| Function | Description |
| -------- | -------- |
| OH_LOG_Print&nbsp;(LogType&nbsp;type,&nbsp;LogLevel&nbsp;level,&nbsp;unsigned&nbsp;int&nbsp;domain,&nbsp;const&nbsp;char&nbsp;\*tag,&nbsp;const&nbsp;char&nbsp;\*fmt,...)&nbsp;__attribute__((__format__(os_log | int<br/>写日志接口。 |
| OH_LOG_IsLoggable&nbsp;(unsigned&nbsp;int&nbsp;domain,&nbsp;const&nbsp;char&nbsp;\*tag,&nbsp;LogLevel&nbsp;level) | int&nbsp;bool<br/>检查指定业务领域、TAG、级别的日志是否可以打印。 |
## **Details**
## **Macro Definition**
### LOG_DOMAIN
```
#define LOG_DOMAIN 0
```
**Description:**
日志所对应的业务领域,用于标识业务的子系统、模块。
16进制整数,有效范围0x0~0xFFFF,超过自动截掉高位。
### LOG_TAG
```
#define LOG_TAG NULL
```
**Description:**
字符串常量,标识调用所在的类或者业务。
### OH_LOG_DEBUG
```
#define OH_LOG_DEBUG( type, ... ) ((void)OH_LOG_Print((type), LOG_DEBUG, LOG_DOMAIN, LOG_TAG, __VA_ARGS__))
```
**Description:**
DEBUG级别写日志,宏封装接口。
使用时需要先定义日志业务领域、日志TAG,一般在源文件起始处统一定义一次。
**Parameters:**
| Name | Description |
| -------- | -------- |
| type | 日志类型,三方应用日志类型为LOG_APP。 |
| fmt | 格式化字符串,基于类printf格式的增强,支持隐私参数标识,即在格式字符串每个参数中符号后类型前增加{public}、{private}标识。 |
| ... | 与格式字符串里参数类型对应的参数列表,参数数目、参数类型必须与格式字符串中的标识一一对应。 |
**See also:**
[OH_LOG_Print](#oh_log_print)
### OH_LOG_ERROR
```
#define OH_LOG_ERROR( type, ... ) ((void)OH_LOG_Print((type), LOG_ERROR, LOG_DOMAIN, LOG_TAG, __VA_ARGS__))
```
**Description:**
ERROR级别写日志,宏封装接口。
使用时需要先定义日志业务领域、日志TAG,一般在源文件起始处统一定义一次。
**Parameters:**
| Name | Description |
| -------- | -------- |
| type | 日志类型,三方应用日志类型为LOG_APP。 |
| fmt | 格式化字符串,基于类printf格式的增强,支持隐私参数标识,即在格式字符串每个参数中符号后类型前增加{public}、{private}标识。 |
| ... | 与格式字符串里参数类型对应的参数列表,参数数目、参数类型必须与格式字符串中的标识一一对应。 |
**See also:**
[OH_LOG_Print](#oh_log_print)
### OH_LOG_FATAL
```
#define OH_LOG_FATAL( type, ... ) ((void)HiLogPrint((type), LOG_FATAL, LOG_DOMAIN, LOG_TAG, __VA_ARGS__))
```
**Description:**
FATAL级别写日志,宏封装接口。
使用时需要先定义日志业务领域、日志TAG,一般在源文件起始处统一定义一次。
**Parameters:**
| Name | Description |
| -------- | -------- |
| type | 日志类型,三方应用日志类型为LOG_APP。 |
| fmt | 格式化字符串,基于类printf格式的增强,支持隐私参数标识,即在格式字符串每个参数中符号后类型前增加{public}、{private}标识。 |
| ... | 与格式字符串里参数类型对应的参数列表,参数数目、参数类型必须与格式字符串中的标识一一对应。 |
**See also:**
[OH_LOG_Print](#oh_log_print)
### OH_LOG_INFO
```
#define OH_LOG_INFO( type, ... ) ((void)OH_LOG_Print((type), LOG_INFO, LOG_DOMAIN, LOG_TAG, __VA_ARGS__))
```
**Description:**
INFO级别写日志,宏封装接口。
使用时需要先定义日志业务领域、日志TAG,一般在源文件起始处统一定义一次。
**Parameters:**
| Name | Description |
| -------- | -------- |
| type | 日志类型,三方应用日志类型为LOG_APP。 |
| fmt | 格式化字符串,基于类printf格式的增强,支持隐私参数标识,即在格式字符串每个参数中符号后类型前增加{public}、{private}标识。 |
| ... | 与格式字符串里参数类型对应的参数列表,参数数目、参数类型必须与格式字符串中的标识一一对应。 |
**See also:**
[OH_LOG_Print](#oh_log_print)
### OH_LOG_WARN
```
#define OH_LOG_WARN( type, ... ) ((void)OH_LOG_Print((type), LOG_WARN, LOG_DOMAIN, LOG_TAG, __VA_ARGS__))
```
**Description:**
WARN级别写日志,宏封装接口。
使用时需要先定义日志业务领域、日志TAG,一般在源文件起始处统一定义一次。
**Parameters:**
| Name | Description |
| -------- | -------- |
| type | 日志类型,三方应用日志类型为LOG_APP。 |
| fmt | 格式化字符串,基于类printf格式的增强,支持隐私参数标识,即在格式字符串每个参数中符号后类型前增加{public}、{private}标识。 |
| ... | 与格式字符串里参数类型对应的参数列表,参数数目、参数类型必须与格式字符串中的标识一一对应。 |
**See also:**
[OH_LOG_Print](#oh_log_print)
## **Enumeration Type**
### LogLevel
```
enum LogLevel
```
**Description:**
日志级别。
该枚举类型用于定义日志级别。
各级别建议使用方式:
DEBUG:比INFO级别更详细的流程记录,通过该级别的日志可以更详细地分析业务流程和定位分析问题。DEBUG级别的日志在正式发布版本中默认不会被打印,只有在调试版本或打开调试开关的情况下才会打印。
INFO:用来记录业务关键流程节点,可以还原业务的主要运行过程;用来记录非正常情况信息,但这些情况都是可以预期的(如无网络信号、登录失败等)。这些日志都应该由该业务内处于支配地位的模块来记录,避免在多个被调用的模块或低级函数中重复记录。
WARN:发生了较为严重的非预期情况,但是对用户影响不大,程序可以自动恢复或通过简单的操作就可以恢复的问题。
ERROR:程序或功能发生了错误,该错误会影响功能的正常运行或用户的正常使用,可以恢复但恢复代价较高,如重置数据等。
FATAL:重大致命异常,表明程序或功能即将崩溃,故障无法恢复。
| Enumerator | Description |
| -------- | -------- |
| LOG_DEBUG | DEBUG日志级别,使用OH_LOG_DEBUG接口打印 |
| LOG_INFO | INFO日志级别,使用OH_LOG_INFO接口打印 |
| LOG_WARN | WARN日志级别,使用OH_LOG_WARN接口打印 |
| LOG_ERROR | ERROR日志级别,使用OH_LOG_ERROR接口打印 |
| LOG_FATAL | FATAL日志级别,使用OH_LOG_FATAL接口打印 |
### LogType
```
enum LogType
```
**Description:**
日志类型。
该枚举类型用于定义应用开发者可以使用的日志类型。当前有应用日志LOG_APP。
| Enumerator | Description |
| -------- | -------- |
| LOG_APP | 应用日志 |
## **Function**
### OH_LOG_IsLoggable()
```
int bool OH_LOG_IsLoggable (unsigned int domain, const char * tag, LogLevel level )
```
**Description:**
检查指定业务领域、TAG、级别的日志是否可以打印。
**Parameters:**
| Name | Description |
| -------- | -------- |
| domain | 指定日志业务领域。 |
| tag | 指定日志TAG。 |
| level | 指定日志level。 |
**Returns:**
如果指定domain、tag、level日志可以打印则返回true;否则返回false。
### OH_LOG_Print()
```
int OH_LOG_Print (LogType type, LogLevel level, unsigned int domain, const char * tag, const char * fmt, ... )
```
**Description:**
写日志接口。
指定日志类型、日志级别、业务领域、TAG,按照类printf格式类型和隐私指示确定需要输出的变参。
**Parameters:**
| Name | Description |
| -------- | -------- |
| type | 日志类型,三方应用日志类型为LOG_APP。 |
| level | 日志级别,日志级别包括LOG_DEBUG、LOG_INFO、LOG_WARN、LOG_ERROR、LOG_FATAL。 |
| domain | 日志业务领域,16进制整数,范围0x0~0xFFFF。 |
| tag | 日志TAG,字符串,标识调用所在的类或者业务。 |
| fmt | 格式化字符串,基于类printf格式的增强,支持隐私参数标识,即在格式字符串每个参数中符号后类型前增加{public}、{private}标识。 |
| ... | 与格式字符串里参数类型对应的参数列表,参数数目、参数类型必须与格式字符串中的标识一一对应。 |
**Returns:**
大于等于0表示成功;小于0表示失败。
# Native_Bundle
## **Overview**
**Description:**
Describes the Native Bundle.
**Since:**
9
**Version:**
1.0
## **Summary**
### Files
| File&nbsp;Name | Description |
| -------- | -------- |
| [native_interface_bundle.h](native__interface__bundle_8h.md) | Declares&nbsp;the&nbsp;**Bundle**-specific&nbsp;function,&nbsp;including&nbsp;function&nbsp;for&nbsp;obtaining&nbsp;application&nbsp;ID. |
### Functions
| Function | Description |
| -------- | -------- |
| OH_NativeBundle_GetAppIdByBundleName&nbsp;(const&nbsp;char&nbsp;\*bundleName) | char&nbsp;\*<br/>Obtains&nbsp;the&nbsp;application&nbsp;ID&nbsp;based&nbsp;on&nbsp;the&nbsp;given&nbsp;bundle&nbsp;name. |
## **Details**
## **Function**
### OH_NativeBundle_GetAppIdByBundleName()
```
char* OH_NativeBundle_GetAppIdByBundleName (const char * bundleName)
```
**Description:**
Obtains the application ID based on the given bundle name.
**Parameters:**
| Name | Description |
| -------- | -------- |
| bundleName | Indicates&nbsp;the&nbsp;bundle&nbsp;name&nbsp;of&nbsp;the&nbsp;application. |
**Returns:**
Returns the application ID pointer if successfully obtained and needs to be freed; returns nullptr otherwise.
# NativeWindow
## **Overview**
**Description:**
提供NativeWindow功能,主要用来和egl对接
\@syscap SystemCapability.Graphic.Graphic2D.NativeWindow
**Since:**
8
**Version:**
1.0
## **Summary**
### Files
| File&nbsp;Name | Description |
| -------- | -------- |
| [external_window.h](external__window_8h.md) | 定义获取和使用NativeWindow的相关函数 |
### Functions
| Function | Description |
| -------- | -------- |
| OH_NativeWindow_CreateNativeWindowFromSurface&nbsp;(void&nbsp;\*pSurface) | struct&nbsp;NativeWindow&nbsp;\*<br/>创建NativeWindow实例,每次调用都会产生一个新的NativeWindow实例 |
| OH_NativeWindow_DestroyNativeWindow&nbsp;(struct&nbsp;NativeWindow&nbsp;\*window) | void<br/>将NativeWindow对象的引用计数减1,当引用计数为0的时候,该NativeWindow对象会被析构掉 |
| OH_NativeWindow_CreateNativeWindowBufferFromSurfaceBuffer&nbsp;(void&nbsp;\*pSurfaceBuffer) | struct&nbsp;NativeWindowBuffer&nbsp;\*<br/>创建NativeWindowBuffer实例,每次调用都会产生一个新的NativeWindowBuffer实例 |
| OH_NativeWindow_DestroyNativeWindowBuffer&nbsp;(struct&nbsp;NativeWindowBuffer&nbsp;\*buffer) | void<br/>将NativeWindowBuffer对象的引用计数减1,当引用计数为0的时候,该NativeWindowBuffer对象会被析构掉 |
| OH_NativeWindow_NativeWindowRequestBuffer&nbsp;(struct&nbsp;NativeWindow&nbsp;\*window,&nbsp;struct&nbsp;NativeWindowBuffer&nbsp;\*\*buffer,&nbsp;int&nbsp;\*fenceFd) | int32_t<br/>通过NativeWindow对象申请一块NativeWindowBuffer,用以内容生产 |
| OH_NativeWindow_NativeWindowFlushBuffer&nbsp;(struct&nbsp;NativeWindow&nbsp;\*window,&nbsp;struct&nbsp;NativeWindowBuffer&nbsp;\*buffer,&nbsp;int&nbsp;fenceFd,&nbsp;Region&nbsp;region) | int32_t<br/>通过NativeWindow将生产好内容的NativeWindowBuffer放回到Buffer队列中,用以内容消费 |
| OH_NativeWindow_NativeWindowCancelBuffer&nbsp;(struct&nbsp;NativeWindow&nbsp;\*window,&nbsp;struct&nbsp;NativeWindowBuffer&nbsp;\*buffer) | int32_t<br/>通过NativeWindow将之前申请出来的NativeWindowBuffer返还到Buffer队列中,供下次再申请 |
| OH_NativeWindow_NativeWindowHandleOpt&nbsp;(struct&nbsp;NativeWindow&nbsp;\*window,&nbsp;int&nbsp;code,...) | int32_t<br/>设置/获取NativeWindow的属性,包括设置/获取宽高、内容格式等 |
| OH_NativeWindow_GetBufferHandleFromNative&nbsp;(struct&nbsp;NativeWindowBuffer&nbsp;\*buffer) | BufferHandle&nbsp;\*<br/>通过NativeWindowBuffer获取该buffer的BufferHandle指针 |
| OH_NativeWindow_NativeObjectReference&nbsp;(void&nbsp;\*obj) | int32_t<br/>增加一个NativeObject的引用计数 |
| OH_NativeWindow_NativeObjectUnreference&nbsp;(void&nbsp;\*obj) | int32_t<br/>减少一个NativeObject的引用计数,当引用计数减少为0时,该NativeObject将被析构掉 |
| OH_NativeWindow_GetNativeObjectMagic&nbsp;(void&nbsp;\*obj) | int32_t<br/>获取NativeObject的MagicId |
## **Details**
## **Function**
### OH_NativeWindow_CreateNativeWindowBufferFromSurfaceBuffer()
```
struct NativeWindowBuffer* OH_NativeWindow_CreateNativeWindowBufferFromSurfaceBuffer (void * pSurfaceBuffer)
```
**Description:**
创建NativeWindowBuffer实例,每次调用都会产生一个新的NativeWindowBuffer实例
\@syscap SystemCapability.Graphic.Graphic2D.NativeWindow
**Parameters:**
| Name | Description |
| -------- | -------- |
| pSurfaceBuffer | 参数是一个指向生产者buffer的指针,类型为sptr&lt;OHOS::SurfaceBuffer&gt; |
**Returns:**
返回一个指针,指向NativeWindowBuffer的结构体实例
### OH_NativeWindow_CreateNativeWindowFromSurface()
```
struct NativeWindow* OH_NativeWindow_CreateNativeWindowFromSurface (void * pSurface)
```
**Description:**
创建NativeWindow实例,每次调用都会产生一个新的NativeWindow实例
\@syscap SystemCapability.Graphic.Graphic2D.NativeWindow
**Parameters:**
| Name | Description |
| -------- | -------- |
| pSurface | 参数是一个指向生产者ProduceSurface的指针,类型为sptr&lt;OHOS::Surface&gt; |
**Returns:**
返回一个指针,指向NativeWindow的结构体实例
### OH_NativeWindow_DestroyNativeWindow()
```
void OH_NativeWindow_DestroyNativeWindow (struct NativeWindow * window)
```
**Description:**
将NativeWindow对象的引用计数减1,当引用计数为0的时候,该NativeWindow对象会被析构掉
\@syscap SystemCapability.Graphic.Graphic2D.NativeWindow
**Parameters:**
| Name | Description |
| -------- | -------- |
| window | 参数是一个NativeWindow的结构体实例的指针 |
### OH_NativeWindow_DestroyNativeWindowBuffer()
```
void OH_NativeWindow_DestroyNativeWindowBuffer (struct NativeWindowBuffer * buffer)
```
**Description:**
将NativeWindowBuffer对象的引用计数减1,当引用计数为0的时候,该NativeWindowBuffer对象会被析构掉
\@syscap SystemCapability.Graphic.Graphic2D.NativeWindow
**Parameters:**
| Name | Description |
| -------- | -------- |
| buffer | 参数是一个NativeWindowBuffer的结构体实例的指针 |
### OH_NativeWindow_GetBufferHandleFromNative()
```
BufferHandle* OH_NativeWindow_GetBufferHandleFromNative (struct NativeWindowBuffer * buffer)
```
**Description:**
通过NativeWindowBuffer获取该buffer的BufferHandle指针
\@syscap SystemCapability.Graphic.Graphic2D.NativeWindow
**Parameters:**
| Name | Description |
| -------- | -------- |
| buffer | 参数是一个NativeWindowBuffer的结构体实例的指针 |
**Returns:**
BufferHandle 返回一个指针,指向BufferHandle的结构体实例
### OH_NativeWindow_GetNativeObjectMagic()
```
int32_t OH_NativeWindow_GetNativeObjectMagic (void * obj)
```
**Description:**
获取NativeObject的MagicId
\@syscap SystemCapability.Graphic.Graphic2D.NativeWindow
**Parameters:**
| Name | Description |
| -------- | -------- |
| obj | 参数是一个NativeWindow&nbsp;or&nbsp;NativeWindowBuffer的结构体实例的指针 |
**Returns:**
MagicId 返回值为魔鬼数字,每个NativeObject唯一
### OH_NativeWindow_NativeObjectReference()
```
int32_t OH_NativeWindow_NativeObjectReference (void * obj)
```
**Description:**
增加一个NativeObject的引用计数
\@syscap SystemCapability.Graphic.Graphic2D.NativeWindow
**Parameters:**
| Name | Description |
| -------- | -------- |
| obj | 参数是一个NativeWindow&nbsp;or&nbsp;NativeWindowBuffer的结构体实例的指针 |
**Returns:**
GSError 返回值为错误码
### OH_NativeWindow_NativeObjectUnreference()
```
int32_t OH_NativeWindow_NativeObjectUnreference (void * obj)
```
**Description:**
减少一个NativeObject的引用计数,当引用计数减少为0时,该NativeObject将被析构掉
\@syscap SystemCapability.Graphic.Graphic2D.NativeWindow
**Parameters:**
| Name | Description |
| -------- | -------- |
| obj | 参数是一个NativeWindow&nbsp;or&nbsp;NativeWindowBuffer的结构体实例的指针 |
**Returns:**
GSError
### OH_NativeWindow_NativeWindowCancelBuffer()
```
int32_t OH_NativeWindow_NativeWindowCancelBuffer (struct NativeWindow * window, struct NativeWindowBuffer * buffer )
```
**Description:**
通过NativeWindow将之前申请出来的NativeWindowBuffer返还到Buffer队列中,供下次再申请
\@syscap SystemCapability.Graphic.Graphic2D.NativeWindow
**Parameters:**
| Name | Description |
| -------- | -------- |
| window | 参数是一个NativeWindow的结构体实例的指针 |
| buffer | 参数是一个NativeWindowBuffer的结构体实例的指针 |
**Returns:**
GSError 返回值为错误码
### OH_NativeWindow_NativeWindowFlushBuffer()
```
int32_t OH_NativeWindow_NativeWindowFlushBuffer (struct NativeWindow * window, struct NativeWindowBuffer * buffer, int fenceFd, Region region )
```
**Description:**
通过NativeWindow将生产好内容的NativeWindowBuffer放回到Buffer队列中,用以内容消费
\@syscap SystemCapability.Graphic.Graphic2D.NativeWindow
**Parameters:**
| Name | Description |
| -------- | -------- |
| window | 参数是一个NativeWindow的结构体实例的指针 |
| buffer | 参数是一个NativeWindowBuffer的结构体实例的指针 |
| fenceFd | 参数是一个文件描述符句柄,用以同步时序 |
| region | 参数表示一块脏区域,该区域有内容更新 |
**Returns:**
GSError 返回值为错误码
### OH_NativeWindow_NativeWindowHandleOpt()
```
int32_t OH_NativeWindow_NativeWindowHandleOpt (struct NativeWindow * window, int code, ... )
```
**Description:**
设置/获取NativeWindow的属性,包括设置/获取宽高、内容格式等
\@syscap SystemCapability.Graphic.Graphic2D.NativeWindow
**Parameters:**
| Name | Description |
| -------- | -------- |
| window | 参数是一个NativeWindow的结构体实例的指针 |
| code | 操作码 |
**Returns:**
GSError 返回值为错误码
### OH_NativeWindow_NativeWindowRequestBuffer()
```
int32_t OH_NativeWindow_NativeWindowRequestBuffer (struct NativeWindow * window, struct NativeWindowBuffer ** buffer, int * fenceFd )
```
**Description:**
通过NativeWindow对象申请一块NativeWindowBuffer,用以内容生产
\@syscap SystemCapability.Graphic.Graphic2D.NativeWindow
**Parameters:**
| Name | Description |
| -------- | -------- |
| window | 参数是一个NativeWindow的结构体实例的指针 |
| buffer | 参数是一个NativeWindowBuffer的结构体实例的二级指针 |
| fenceFd | 参数是一个文件描述符句柄 |
**Returns:**
GSError 返回值为错误码
# OH_Drawing_BitmapFormat
## **Overview**
**Related Modules:**
[Drawing](_drawing.md)
**Description:**
结构体用于描述位图像素的格式,包括颜色类型和透明度类型
**Since:**
8
**Version:**
1.0
## **Summary**
### Public Attributes
| Public&nbsp;Attribute&nbsp;Name | Description |
| -------- | -------- |
| colorFormat | |
| alphaFormat | |
## **Details**
## **Member Data**
### alphaFormat
```
OH_Drawing_AlphaFormat OH_Drawing_BitmapFormat::alphaFormat
```
**Description:**
描述位图像素的透明度分量
### colorFormat
```
OH_Drawing_ColorFormat OH_Drawing_BitmapFormat::colorFormat
```
**Description:**
描述位图像素的存储格式
# Native XComponent
## **Overview**
**Description:**
Describes the surface and touch event held by the ArkUI XComponent, which can be used for the EGL/OpenGLES and media data input and displayed on the ArkUI XComponent.
**Since:**
8
**Version:**
1.0
## **Summary**
### Files
| File&nbsp;Name | Description |
| -------- | -------- |
| [native_interface_xcomponent.h](native__interface__xcomponent_8h.md) | Declares&nbsp;APIs&nbsp;for&nbsp;accessing&nbsp;a&nbsp;Native&nbsp;XComponent. |
### Classes
| Classe&nbsp;Name | Description |
| -------- | -------- |
| [OH_NativeXComponent_TouchPoint](_o_h___native_x_component___touch_point.md) | |
| [OH_NativeXComponent_TouchEvent](_o_h___native_x_component___touch_event.md) | |
| [OH_NativeXComponent_Callback](_o_h___native_x_component___callback.md) | Registers&nbsp;the&nbsp;surface&nbsp;lifecycle&nbsp;and&nbsp;touch&nbsp;event&nbsp;callbacks. |
### Macros
| Macro&nbsp;Name&nbsp;and&nbsp;Value | Description |
| -------- | -------- |
| **OH_NATIVE_XCOMPONENT_OBJ**&nbsp;&nbsp;&nbsp;("__NATIVE_XCOMPONENT_OBJ__") | |
### Typedefs
| Typedef&nbsp;Name | Description |
| -------- | -------- |
| OH_NativeXComponent | typedef&nbsp;struct&nbsp;OH_NativeXComponent<br/>Provides&nbsp;an&nbsp;encapsulated&nbsp;**OH_NativeXComponent**&nbsp;instance. |
| OH_NativeXComponent_Callback | typedef&nbsp;struct&nbsp;OH_NativeXComponent_Callback<br/>Registers&nbsp;the&nbsp;surface&nbsp;lifecycle&nbsp;and&nbsp;touch&nbsp;event&nbsp;callbacks. |
### Enumerations
| Enumeration&nbsp;Name | Description |
| -------- | -------- |
| {&nbsp;OH_NATIVEXCOMPONENT_RESULT_SUCCESS&nbsp;=&nbsp;0,&nbsp;OH_NATIVEXCOMPONENT_RESULT_FAILED&nbsp;=&nbsp;-1,&nbsp;OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER&nbsp;=&nbsp;-2&nbsp;} | Enumerates&nbsp;the&nbsp;API&nbsp;access&nbsp;states. |
| OH_NativeXComponent_TouchEventType&nbsp;{&nbsp;&nbsp;&nbsp;OH_NATIVEXCOMPONENT_DOWN&nbsp;=&nbsp;0,&nbsp;OH_NATIVEXCOMPONENT_UP,&nbsp;OH_NATIVEXCOMPONENT_MOVE,&nbsp;OH_NATIVEXCOMPONENT_CANCEL,&nbsp;&nbsp;&nbsp;OH_NATIVEXCOMPONENT_UNKNOWN&nbsp;} | |
### Functions
| Function | Description |
| -------- | -------- |
| OH_NativeXComponent_GetXComponentId&nbsp;(OH_NativeXComponent&nbsp;\*component,&nbsp;char&nbsp;\*id,&nbsp;uint64_t&nbsp;\*size) | int32_t<br/>Obtains&nbsp;the&nbsp;ID&nbsp;of&nbsp;the&nbsp;ArkUI&nbsp;XComponent. |
| OH_NativeXComponent_GetXComponentSize&nbsp;(OH_NativeXComponent&nbsp;\*component,&nbsp;const&nbsp;void&nbsp;\*window,&nbsp;uint64_t&nbsp;\*width,&nbsp;uint64_t&nbsp;\*height) | int32_t<br/>Obtains&nbsp;the&nbsp;size&nbsp;of&nbsp;the&nbsp;surface&nbsp;held&nbsp;by&nbsp;the&nbsp;ArkUI&nbsp;XComponent. |
| OH_NativeXComponent_GetXComponentOffset&nbsp;(OH_NativeXComponent&nbsp;\*component,&nbsp;const&nbsp;void&nbsp;\*window,&nbsp;double&nbsp;\*x,&nbsp;double&nbsp;\*y) | int32_t<br/>Obtains&nbsp;the&nbsp;offset&nbsp;of&nbsp;the&nbsp;surface&nbsp;held&nbsp;by&nbsp;the&nbsp;ArkUI&nbsp;XComponent. |
| OH_NativeXComponent_GetTouchEvent&nbsp;(OH_NativeXComponent&nbsp;\*component,&nbsp;const&nbsp;void&nbsp;\*window,&nbsp;OH_NativeXComponent_TouchEvent&nbsp;\*touchEvent) | int32_t<br/>Obtains&nbsp;the&nbsp;touch&nbsp;event&nbsp;dispatched&nbsp;by&nbsp;the&nbsp;ArkUI&nbsp;XComponent. |
| OH_NativeXComponent_RegisterCallback&nbsp;(OH_NativeXComponent&nbsp;\*component,&nbsp;OH_NativeXComponent_Callback&nbsp;\*callback) | int32_t<br/>Registers&nbsp;a&nbsp;callback&nbsp;for&nbsp;this&nbsp;**OH_NativeXComponent**&nbsp;instance. |
## **Details**
## **Typedef**
### OH_NativeXComponent
```
typedef struct OH_NativeXComponent OH_NativeXComponent
```
**Description:**
Provides an encapsulated **OH_NativeXComponent** instance.
### OH_NativeXComponent_Callback
```
typedef struct OH_NativeXComponent_Callback OH_NativeXComponent_Callback
```
**Description:**
Registers the surface lifecycle and touch event callbacks.
## **Enumeration Type**
### anonymous enum
```
anonymous enum
```
**Description:**
Enumerates the API access states.
| Enumerator | Description |
| -------- | -------- |
| OH_NATIVEXCOMPONENT_RESULT_SUCCESS | Success&nbsp;result. |
| OH_NATIVEXCOMPONENT_RESULT_FAILED | Failed&nbsp;result. |
| OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER | Invalid&nbsp;parameters. |
### OH_NativeXComponent_TouchEventType
```
enum OH_NativeXComponent_TouchEventType
```
| Enumerator | Description |
| -------- | -------- |
| OH_NATIVEXCOMPONENT_DOWN | Trigger&nbsp;a&nbsp;touch&nbsp;event&nbsp;when&nbsp;a&nbsp;finger&nbsp;is&nbsp;pressed. |
| OH_NATIVEXCOMPONENT_UP | Trigger&nbsp;a&nbsp;touch&nbsp;event&nbsp;when&nbsp;a&nbsp;finger&nbsp;is&nbsp;lifted. |
| OH_NATIVEXCOMPONENT_MOVE | Trigger&nbsp;a&nbsp;touch&nbsp;event&nbsp;when&nbsp;a&nbsp;finger&nbsp;moves&nbsp;on&nbsp;the&nbsp;screen&nbsp;in&nbsp;pressed&nbsp;state. |
| OH_NATIVEXCOMPONENT_CANCEL | Trigger&nbsp;an&nbsp;event&nbsp;when&nbsp;a&nbsp;touch&nbsp;event&nbsp;is&nbsp;canceled. |
| OH_NATIVEXCOMPONENT_UNKNOWN | Invalid&nbsp;touch&nbsp;type. |
## **Function**
### OH_NativeXComponent_GetTouchEvent()
```
int32_t OH_NativeXComponent_GetTouchEvent (OH_NativeXComponent * component, const void * window, OH_NativeXComponent_TouchEvent * touchEvent )
```
**Description:**
Obtains the touch event dispatched by the ArkUI XComponent.
**Parameters:**
| Name | Description |
| -------- | -------- |
| component | Indicates&nbsp;the&nbsp;pointer&nbsp;to&nbsp;this&nbsp;**OH_NativeXComponent**&nbsp;instance. |
| window | Indicates&nbsp;the&nbsp;native&nbsp;window&nbsp;handler. |
| touchEvent | Indicates&nbsp;the&nbsp;pointer&nbsp;to&nbsp;the&nbsp;current&nbsp;touch&nbsp;event. |
**Returns:**
Returns the status code of the execution.
### OH_NativeXComponent_GetXComponentId()
```
int32_t OH_NativeXComponent_GetXComponentId (OH_NativeXComponent * component, char * id, uint64_t * size )
```
**Description:**
Obtains the ID of the ArkUI XComponent.
**Parameters:**
| Name | Description |
| -------- | -------- |
| component | Indicates&nbsp;the&nbsp;pointer&nbsp;to&nbsp;this&nbsp;**OH_NativeXComponent**&nbsp;instance. |
| id | Indicates&nbsp;the&nbsp;char&nbsp;buffer&nbsp;to&nbsp;keep&nbsp;the&nbsp;ID&nbsp;of&nbsp;this&nbsp;**OH_NativeXComponent**&nbsp;instance.&nbsp;Note&nbsp;that&nbsp;a&nbsp;null-terminator&nbsp;will&nbsp;be&nbsp;appended&nbsp;to&nbsp;the&nbsp;char&nbsp;buffer,&nbsp;so&nbsp;the&nbsp;size&nbsp;of&nbsp;the&nbsp;char&nbsp;buffer&nbsp;should&nbsp;be&nbsp;at&nbsp;least&nbsp;as&nbsp;large&nbsp;as&nbsp;the&nbsp;size&nbsp;of&nbsp;the&nbsp;real&nbsp;id&nbsp;length&nbsp;plus&nbsp;1.&nbsp;It&nbsp;is&nbsp;recommended&nbsp;that&nbsp;the&nbsp;size&nbsp;of&nbsp;the&nbsp;char&nbsp;buffer&nbsp;be&nbsp;[OH_XCOMPONENT_ID_LEN_MAX&nbsp;+&nbsp;1]. |
| size | Indicates&nbsp;the&nbsp;pointer&nbsp;to&nbsp;the&nbsp;length&nbsp;of&nbsp;**id**,&nbsp;which&nbsp;you&nbsp;can&nbsp;set&nbsp;and&nbsp;receive. |
**Returns:**
Returns the status code of the execution.
### OH_NativeXComponent_GetXComponentOffset()
```
int32_t OH_NativeXComponent_GetXComponentOffset (OH_NativeXComponent * component, const void * window, double * x, double * y )
```
**Description:**
Obtains the offset of the surface held by the ArkUI XComponent.
**Parameters:**
| Name | Description |
| -------- | -------- |
| component | Indicates&nbsp;the&nbsp;pointer&nbsp;to&nbsp;this&nbsp;**OH_NativeXComponent**&nbsp;instance. |
| window | Indicates&nbsp;the&nbsp;native&nbsp;window&nbsp;handler. |
| x | Indicates&nbsp;the&nbsp;pointer&nbsp;to&nbsp;the&nbsp;x&nbsp;coordinate&nbsp;of&nbsp;the&nbsp;current&nbsp;surface. |
| y | Indicates&nbsp;the&nbsp;pointer&nbsp;to&nbsp;the&nbsp;y&nbsp;coordinate&nbsp;of&nbsp;the&nbsp;current&nbsp;surface. |
**Returns:**
Returns the status code of the execution.
### OH_NativeXComponent_GetXComponentSize()
```
int32_t OH_NativeXComponent_GetXComponentSize (OH_NativeXComponent * component, const void * window, uint64_t * width, uint64_t * height )
```
**Description:**
Obtains the size of the surface held by the ArkUI XComponent.
**Parameters:**
| Name | Description |
| -------- | -------- |
| component | Indicates&nbsp;the&nbsp;pointer&nbsp;to&nbsp;this&nbsp;**OH_NativeXComponent**&nbsp;instance. |
| window | Indicates&nbsp;the&nbsp;native&nbsp;window&nbsp;handler. |
| width | Indicates&nbsp;the&nbsp;pointer&nbsp;to&nbsp;the&nbsp;width&nbsp;of&nbsp;the&nbsp;current&nbsp;surface. |
| height | Indicates&nbsp;the&nbsp;pointer&nbsp;to&nbsp;the&nbsp;height&nbsp;of&nbsp;the&nbsp;current&nbsp;surface. |
**Returns:**
Returns the status code of the execution.
### OH_NativeXComponent_RegisterCallback()
```
int32_t OH_NativeXComponent_RegisterCallback (OH_NativeXComponent * component, OH_NativeXComponent_Callback * callback )
```
**Description:**
Registers a callback for this **OH_NativeXComponent** instance.
**Parameters:**
| Name | Description |
| -------- | -------- |
| component | Indicates&nbsp;the&nbsp;pointer&nbsp;to&nbsp;this&nbsp;**OH_NativeXComponent**&nbsp;instance. |
| callback | Indicates&nbsp;the&nbsp;pointer&nbsp;to&nbsp;a&nbsp;surface&nbsp;lifecycle&nbsp;and&nbsp;touch&nbsp;event&nbsp;callback. |
**Returns:**
Returns the status code of the execution.
## **Variable**
### deviceId
```
int64_t OH_NativeXComponent_TouchEvent::deviceId = 0
```
**Description:**
ID of the device where the current touch event is generated.
### DispatchTouchEvent
```
void(* OH_NativeXComponent_Callback::DispatchTouchEvent) (OH_NativeXComponent *component, void *window)
```
**Description:**
Called when a touch event is triggered.
### force [1/2]
```
float OH_NativeXComponent_TouchPoint::force = 0.0
```
**Description:**
Pressure of the current touch event.
### force [2/2]
```
float OH_NativeXComponent_TouchEvent::force = 0.0
```
**Description:**
Pressure of the current touch event.
### id [1/2]
```
int32_t OH_NativeXComponent_TouchPoint::id = 0
```
**Description:**
Unique identifier of a finger.
### id [2/2]
```
int32_t OH_NativeXComponent_TouchEvent::id = 0
```
**Description:**
Unique identifier of a finger.
### isPressed
```
bool OH_NativeXComponent_TouchPoint::isPressed = false
```
**Description:**
Whether the current point is pressed.
### numPoints
```
uint32_t OH_NativeXComponent_TouchEvent::numPoints = 0
```
**Description:**
Number of current touch points.
### OnSurfaceChanged
```
void(* OH_NativeXComponent_Callback::OnSurfaceChanged) (OH_NativeXComponent *component, void *window)
```
**Description:**
Called when the surface is changed. This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR.
### OnSurfaceCreated
```
void(* OH_NativeXComponent_Callback::OnSurfaceCreated) (OH_NativeXComponent *component, void *window)
```
**Description:**
Called when the surface is created.
### OnSurfaceDestroyed
```
void(* OH_NativeXComponent_Callback::OnSurfaceDestroyed) (OH_NativeXComponent *component, void *window)
```
**Description:**
Called when the surface is destroyed.
### screenX [1/2]
```
float OH_NativeXComponent_TouchPoint::screenX = 0.0
```
**Description:**
X coordinate of the touch point relative to the left edge of the screen.
### screenX [2/2]
```
float OH_NativeXComponent_TouchEvent::screenX = 0.0
```
**Description:**
X coordinate of the touch point relative to the left edge of the screen.
### screenY [1/2]
```
float OH_NativeXComponent_TouchPoint::screenY = 0.0
```
**Description:**
Y coordinate of the touch point relative to the upper edge of the screen.
### screenY [2/2]
```
float OH_NativeXComponent_TouchEvent::screenY = 0.0
```
**Description:**
Y coordinate of the touch point relative to the upper edge of the screen.
### size [1/2]
```
double OH_NativeXComponent_TouchPoint::size = 0.0
```
**Description:**
Contact area between the finger pad and the screen.
### size [2/2]
```
double OH_NativeXComponent_TouchEvent::size = 0.0
```
**Description:**
Contact area between the finger pad and the screen.
### timeStamp [1/2]
```
long long OH_NativeXComponent_TouchPoint::timeStamp = 0
```
**Description:**
Timestamp of the current touch event.
### timeStamp [2/2]
```
long long OH_NativeXComponent_TouchEvent::timeStamp = 0
```
**Description:**
Timestamp of the current touch event.
### touchPoints
```
OH_NativeXComponent_TouchPoint OH_NativeXComponent_TouchEvent::touchPoints[OH_MAX_TOUCH_POINTS_NUMBER]
```
**Description:**
Array of the current touch points.
### type [1/2]
```
OH_NativeXComponent_TouchEventType OH_NativeXComponent_TouchPoint::type = OH_NativeXComponent_TouchEventType::OH_NATIVEXCOMPONENT_UNKNOWN
```
**Description:**
Touch type of the touch event.
### type [2/2]
```
OH_NativeXComponent_TouchEventType OH_NativeXComponent_TouchEvent::type = OH_NativeXComponent_TouchEventType::OH_NATIVEXCOMPONENT_UNKNOWN
```
**Description:**
Touch type of the touch event.
### x [1/2]
```
float OH_NativeXComponent_TouchPoint::x = 0.0
```
**Description:**
X coordinate of the touch point relative to the left edge of the element to touch.
### x [2/2]
```
float OH_NativeXComponent_TouchEvent::x = 0.0
```
**Description:**
X coordinate of the touch point relative to the left edge of the element to touch.
### y [1/2]
```
float OH_NativeXComponent_TouchPoint::y = 0.0
```
**Description:**
Y coordinate of the touch point relative to the upper edge of the element to touch.
### y [2/2]
```
float OH_NativeXComponent_TouchEvent::y = 0.0
```
**Description:**
Y coordinate of the touch point relative to the upper edge of the element to touch.
# OH_NativeXComponent_Callback
## **Overview**
**Related Modules:**
[Native XComponent](_o_h___native_x_component.md)
**Description:**
Registers the surface lifecycle and touch event callbacks.
**Since:**
8
**Version:**
1.0
## **Summary**
### Public Attributes
| Public&nbsp;Attribute&nbsp;Name | Description |
| -------- | -------- |
| [OnSurfaceCreated](_o_h___native_x_component.md#ga8beefd4b2359680a3106b28227e47d00)&nbsp;)([OH_NativeXComponent](_o_h___native_x_component.md#ga0e676460ec145b81bdb07a97a368a5f1)&nbsp;\*component,&nbsp;void&nbsp;\*window) | |
| [OnSurfaceChanged](_o_h___native_x_component.md#ga7d84244e13477d91cfdade8d9ff8565b)&nbsp;)([OH_NativeXComponent](_o_h___native_x_component.md#ga0e676460ec145b81bdb07a97a368a5f1)&nbsp;\*component,&nbsp;void&nbsp;\*window) | |
| [OnSurfaceDestroyed](_o_h___native_x_component.md#gad32bd08c749422d807ac87c558af6a44)&nbsp;)([OH_NativeXComponent](_o_h___native_x_component.md#ga0e676460ec145b81bdb07a97a368a5f1)&nbsp;\*component,&nbsp;void&nbsp;\*window) | |
| [DispatchTouchEvent](_o_h___native_x_component.md#ga3d40ca63aba381a63435f71f679e1f26)&nbsp;)([OH_NativeXComponent](_o_h___native_x_component.md#ga0e676460ec145b81bdb07a97a368a5f1)&nbsp;\*component,&nbsp;void&nbsp;\*window) | |
# OH_NativeXComponent_TouchEvent
## **Overview**
**Related Modules:**
[Native XComponent](_o_h___native_x_component.md)
## **Summary**
### Public Attributes
| Public&nbsp;Attribute&nbsp;Name | Description |
| -------- | -------- |
| [id](_o_h___native_x_component.md#gac986c10f386a0b55bd813caec06fe190)&nbsp;=&nbsp;0 | |
| [screenX](_o_h___native_x_component.md#ga68fe9ff656e74ae14254523443d85bb1)&nbsp;=&nbsp;0.0 | |
| [screenY](_o_h___native_x_component.md#ga7696e0e1a81787400e187058a1e332f2)&nbsp;=&nbsp;0.0 | |
| [x](_o_h___native_x_component.md#ga9688a76d25bede284e36b7226ec8ad3a)&nbsp;=&nbsp;0.0 | |
| [y](_o_h___native_x_component.md#ga0136d85dae638fbe9baaa69cf67a9833)&nbsp;=&nbsp;0.0 | |
| [type](_o_h___native_x_component.md#ga22f67143e6acdefa5c7fd4ba23f7c2b6)&nbsp;=&nbsp;[OH_NativeXComponent_TouchEventType::OH_NATIVEXCOMPONENT_UNKNOWN](_o_h___native_x_component.md#gga0a8c68dd460d7e801e7c0ff771f09182aff39d23c1412b3b110a19df4893651d3) | |
| [size](_o_h___native_x_component.md#ga723601b60610b546fbdaf29e87575ca2)&nbsp;=&nbsp;0.0 | |
| [force](_o_h___native_x_component.md#ga7c0a450a47231bd55994a970b3750d3f)&nbsp;=&nbsp;0.0 | |
| [deviceId](_o_h___native_x_component.md#ga00660bb31b05cebe8964ba221c24f966)&nbsp;=&nbsp;0 | |
| [timeStamp](_o_h___native_x_component.md#gadd872bda25d5af9327d12d06a70149fd)&nbsp;=&nbsp;0 | |
| [touchPoints](_o_h___native_x_component.md#gab3514bf8d2fa3de8191d4898ee739053)&nbsp;[OH_MAX_TOUCH_POINTS_NUMBER] | |
| [numPoints](_o_h___native_x_component.md#gad8c19c6c2bbb367fa18fffa813e21cc6)&nbsp;=&nbsp;0 | |
# OH_NativeXComponent_TouchPoint
## **Overview**
**Related Modules:**
[Native XComponent](_o_h___native_x_component.md)
## **Summary**
### Public Attributes
| Public&nbsp;Attribute&nbsp;Name | Description |
| -------- | -------- |
| [id](_o_h___native_x_component.md#gafc435f3e8b5acf462b28bae69180d971)&nbsp;=&nbsp;0 | |
| [screenX](_o_h___native_x_component.md#gae96f097ddffb119b824bcd9f59857ea4)&nbsp;=&nbsp;0.0 | |
| [screenY](_o_h___native_x_component.md#ga8fb126875104358f84e17ddd66dbbf60)&nbsp;=&nbsp;0.0 | |
| [x](_o_h___native_x_component.md#ga04e0e65a35a652d86460c82bf0ca02e3)&nbsp;=&nbsp;0.0 | |
| [y](_o_h___native_x_component.md#ga13d254769a362f049243505e84df8fa4)&nbsp;=&nbsp;0.0 | |
| [type](_o_h___native_x_component.md#gac2b852641112bce8de71f080a21a118a)&nbsp;=&nbsp;[OH_NativeXComponent_TouchEventType::OH_NATIVEXCOMPONENT_UNKNOWN](_o_h___native_x_component.md#gga0a8c68dd460d7e801e7c0ff771f09182aff39d23c1412b3b110a19df4893651d3) | |
| [size](_o_h___native_x_component.md#ga9e5a0e118ab61a889126a985be7947dd)&nbsp;=&nbsp;0.0 | |
| [force](_o_h___native_x_component.md#gaf3d4f92022552678d5d81d2396900595)&nbsp;=&nbsp;0.0 | |
| [timeStamp](_o_h___native_x_component.md#gad090e826a0e33a4054f468109a5a729d)&nbsp;=&nbsp;0 | |
| [isPressed](_o_h___native_x_component.md#ga527c92deb88977ae842ffe6fee50d571)&nbsp;=&nbsp;false | |
# RawFileDescriptor
## **Overview**
**Related Modules:**
[Rawfile](rawfile.md)
**Description:**
提供rawfile文件描述符信息
RawFileDescriptor是[OH_ResourceManager_GetRawFileDescriptor](rawfile.md#ga8313a7d4bb361a98ced485346a9be4b1)的输出参数, 涵盖了rawfile文件的文件描述符以及在HAP包中的起始位置和长度。
**Since:**
8
**Version:**
1.0
## **Summary**
### Public Attributes
| Public&nbsp;Attribute&nbsp;Name | Description |
| -------- | -------- |
| fd | |
| start | |
| length | |
## **Details**
## **Member Data**
### fd
```
int RawFileDescriptor::fd
```
**Description:**
rawfile文件描述符
### length
```
long RawFileDescriptor::length
```
**Description:**
rawfile在HAP包中的长度
### start
```
long RawFileDescriptor::start
```
**Description:**
rawfile在HAP包中的起始位置
# 结构体
- **[OH_Drawing_BitmapFormat](_o_h___drawing___bitmap_format.md)**
- **[OH_NativeXComponent_Callback](_o_h___native_x_component___callback.md)**
- **[OH_NativeXComponent_TouchEvent](_o_h___native_x_component___touch_event.md)**
- **[OH_NativeXComponent_TouchPoint](_o_h___native_x_component___touch_point.md)**
- **[RawFileDescriptor](_raw_file_descriptor.md)**
\ No newline at end of file
# drawing_bitmap.h
## **Overview**
**Related Modules:**
[Drawing](_drawing.md)
**Description:**
文件中定义了与位图相关的功能函数
**Since:**
8
**Version:**
1.0
## **Summary**
### Classes
| Classe&nbsp;Name | Description |
| -------- | -------- |
| [OH_Drawing_BitmapFormat](_o_h___drawing___bitmap_format.md) | 结构体用于描述位图像素的格式,包括颜色类型和透明度类型 |
### Functions
| Function | Description |
| -------- | -------- |
| [OH_Drawing_BitmapCreate](_drawing.md#gac2d33ba4b18e71eca8c41c136004ba48)&nbsp;(void) | [OH_Drawing_Bitmap](_drawing.md#ga8ac4e64cd1e2c651d11325e04c72ddeb)&nbsp;\*<br/>函数用于创建一个位图对象。 |
| [OH_Drawing_BitmapDestroy](_drawing.md#ga5c31becccf1d3ad5df5f6bc7d9007b8f)&nbsp;([OH_Drawing_Bitmap](_drawing.md#ga8ac4e64cd1e2c651d11325e04c72ddeb)&nbsp;\*) | void<br/>函数用于销毁位图对象并回收该对象占有内存。 |
| [OH_Drawing_BitmapBuild](_drawing.md#ga699afe9c4d2665cdd21b5d9b6dfed2ec)&nbsp;([OH_Drawing_Bitmap](_drawing.md#ga8ac4e64cd1e2c651d11325e04c72ddeb)&nbsp;\*,&nbsp;const&nbsp;uint32_t&nbsp;width,&nbsp;const&nbsp;uint32_t&nbsp;height,&nbsp;const&nbsp;[OH_Drawing_BitmapFormat](_o_h___drawing___bitmap_format.md)&nbsp;\*) | void<br/>函数用于初始化位图对象的宽度和高度,并且为该位图设置像素格式 |
| [OH_Drawing_BitmapGetWidth](_drawing.md#ga67b83650847ab1f6e79ca122905d55a3)&nbsp;([OH_Drawing_Bitmap](_drawing.md#ga8ac4e64cd1e2c651d11325e04c72ddeb)&nbsp;\*) | uint32_t<br/>该函数用于获取指定位图的宽度 |
| [OH_Drawing_BitmapGetHeight](_drawing.md#gace471d69bec5b152bd4de5fa8504f7fd)&nbsp;([OH_Drawing_Bitmap](_drawing.md#ga8ac4e64cd1e2c651d11325e04c72ddeb)&nbsp;\*) | uint32_t<br/>函数用于获取指定位图的高度 |
| [OH_Drawing_BitmapGetPixels](_drawing.md#gaf007f52cfbcbc63cd02971c6480c55fb)&nbsp;([OH_Drawing_Bitmap](_drawing.md#ga8ac4e64cd1e2c651d11325e04c72ddeb)&nbsp;\*) | void&nbsp;\*<br/>函数用于获取指定位图的像素地址,可以通过像素地址获取到位图的像素数据 |
# drawing_brush.h
## **Overview**
**Related Modules:**
[Drawing](_drawing.md)
**Description:**
文件中定义了与画刷相关的功能函数
**Since:**
8
**Version:**
1.0
## **Summary**
### Functions
| Function | Description |
| -------- | -------- |
| [OH_Drawing_BrushCreate](_drawing.md#ga75e2193d23cf75878c7b2c78d6b23b35)&nbsp;(void) | [OH_Drawing_Brush](_drawing.md#ga178c83de4a084d35c30e4681319ea711)&nbsp;\*<br/>函数用于创建一个画刷对象 |
| [OH_Drawing_BrushDestroy](_drawing.md#ga9dc1d4aa465d06f2d847feddae1558b5)&nbsp;([OH_Drawing_Brush](_drawing.md#ga178c83de4a084d35c30e4681319ea711)&nbsp;\*) | void<br/>函数用于销毁画刷对象并回收该对象占有的内存。 |
| [OH_Drawing_BrushIsAntiAlias](_drawing.md#ga4c861e23b8c0a3fb84d906d81bea5335)&nbsp;(const&nbsp;[OH_Drawing_Brush](_drawing.md#ga178c83de4a084d35c30e4681319ea711)&nbsp;\*) | bool<br/>函数用于获取画刷是否设置抗锯齿属性,如果为真则说明画刷会启用抗锯齿功能,在绘制图形时会对图形的边缘像素进行半透明的模糊处理 |
| [OH_Drawing_BrushSetAntiAlias](_drawing.md#ga41735fc7a2776fbe41c77b3f4637e1c5)&nbsp;([OH_Drawing_Brush](_drawing.md#ga178c83de4a084d35c30e4681319ea711)&nbsp;\*,&nbsp;bool) | void<br/>函数用于设置画刷的抗锯齿属性,设置为真则画刷在绘制图形时会对图形的边缘像素进行半透明的模糊处理 |
| [OH_Drawing_BrushGetColor](_drawing.md#ga29dc1e2442cea7e958a5e037c4cc9f59)&nbsp;(const&nbsp;[OH_Drawing_Brush](_drawing.md#ga178c83de4a084d35c30e4681319ea711)&nbsp;\*) | uint32_t<br/>函数用于获取画刷的颜色属性,颜色属性描述了画刷填充图形时使用的颜色,用一个32位(ARGB)的变量表示 |
| [OH_Drawing_BrushSetColor](_drawing.md#ga4b62aa574623c1a75e14f612a831531b)&nbsp;([OH_Drawing_Brush](_drawing.md#ga178c83de4a084d35c30e4681319ea711)&nbsp;\*,&nbsp;uint32_t&nbsp;color) | void<br/>函数用于设置画刷的颜色属性,颜色属性描述了画刷填充图形时使用的颜色,用一个32位(ARGB)的变量表示 |
# drawing_canvas.h
## **Overview**
**Related Modules:**
[Drawing](_drawing.md)
**Description:**
文件中定义了与画布相关的功能函数
**Since:**
8
**Version:**
1.0
## **Summary**
### Functions
| Function | Description |
| -------- | -------- |
| [OH_Drawing_CanvasCreate](_drawing.md#ga1bfe881a0b018a982678906f3522d4df)&nbsp;(void) | [OH_Drawing_Canvas](_drawing.md#ga086e2de47ef7bfe6c96e6b09e87da33a)&nbsp;\*<br/>函数用于创建一个画布对象 |
| [OH_Drawing_CanvasDestroy](_drawing.md#ga1a3023ccc48a381cc0b4ae09e2d85c38)&nbsp;([OH_Drawing_Canvas](_drawing.md#ga086e2de47ef7bfe6c96e6b09e87da33a)&nbsp;\*) | void<br/>函数用于销毁画布对象并回收该对象占有的内存 |
| [OH_Drawing_CanvasBind](_drawing.md#ga666595bb182a5e31733f4144c1515cae)&nbsp;([OH_Drawing_Canvas](_drawing.md#ga086e2de47ef7bfe6c96e6b09e87da33a)&nbsp;\*,&nbsp;[OH_Drawing_Bitmap](_drawing.md#ga8ac4e64cd1e2c651d11325e04c72ddeb)&nbsp;\*) | void<br/>函数用于将一个位图对象绑定到画布中,使得画布绘制的内容输出到位图中(即CPU渲染) |
| [OH_Drawing_CanvasAttachPen](_drawing.md#gaaec6db563bd7153dc95d0bfab71a4ed1)&nbsp;([OH_Drawing_Canvas](_drawing.md#ga086e2de47ef7bfe6c96e6b09e87da33a)&nbsp;\*,&nbsp;const&nbsp;[OH_Drawing_Pen](_drawing.md#ga88e73d9d7b62e6113237fc0f828910d2)&nbsp;\*) | void<br/>函数用于设置画笔给画布,画布将会使用设置画笔的样式和颜色去绘制图形形状的轮廓 |
| [OH_Drawing_CanvasDetachPen](_drawing.md#ga79321b669f2b5dc0460ca929f00dfc47)&nbsp;([OH_Drawing_Canvas](_drawing.md#ga086e2de47ef7bfe6c96e6b09e87da33a)&nbsp;\*) | void<br/>函数用于去除掉画布中的画笔,使用后画布将不去绘制图形形状的轮廓 |
| [OH_Drawing_CanvasAttachBrush](_drawing.md#ga1b238c829ea5f2ff627766a3e50feaa6)&nbsp;([OH_Drawing_Canvas](_drawing.md#ga086e2de47ef7bfe6c96e6b09e87da33a)&nbsp;\*,&nbsp;const&nbsp;[OH_Drawing_Brush](_drawing.md#ga178c83de4a084d35c30e4681319ea711)&nbsp;\*) | void<br/>函数用于设置画刷给画布,画布将会使用设置的画刷样式和颜色去填充绘制的图形形状 |
| [OH_Drawing_CanvasDetachBrush](_drawing.md#ga7a6b5e56d2492b5641b8b3f634b096fe)&nbsp;([OH_Drawing_Canvas](_drawing.md#ga086e2de47ef7bfe6c96e6b09e87da33a)&nbsp;\*) | void<br/>函数用于去除掉画布中的画刷,使用后画布将不去填充图形形状 |
| [OH_Drawing_CanvasSave](_drawing.md#ga4ebc55405e00ad4b8609303fefc6997a)&nbsp;([OH_Drawing_Canvas](_drawing.md#ga086e2de47ef7bfe6c96e6b09e87da33a)&nbsp;\*) | void<br/>函数用于保存当前画布的状态(画布矩阵)到一个栈顶 |
| [OH_Drawing_CanvasRestore](_drawing.md#gadd632be64ccc2601def753ecc1e53944)&nbsp;([OH_Drawing_Canvas](_drawing.md#ga086e2de47ef7bfe6c96e6b09e87da33a)&nbsp;\*) | void<br/>函数用于恢复保存在栈顶的画布状态(画布矩阵) |
| [OH_Drawing_CanvasDrawLine](_drawing.md#gadf6bae5efd20587612596f8e78a16144)&nbsp;([OH_Drawing_Canvas](_drawing.md#ga086e2de47ef7bfe6c96e6b09e87da33a)&nbsp;\*,&nbsp;float&nbsp;x1,&nbsp;float&nbsp;y1,&nbsp;float&nbsp;x2,&nbsp;float&nbsp;y2) | void<br/>函数用于画一条直线段 |
| [OH_Drawing_CanvasDrawPath](_drawing.md#ga99ebc73abdc27599f4bcc1c1045cb75e)&nbsp;([OH_Drawing_Canvas](_drawing.md#ga086e2de47ef7bfe6c96e6b09e87da33a)&nbsp;\*,&nbsp;const&nbsp;[OH_Drawing_Path](_drawing.md#gab7e53fc0181099b4a0a3e4a08d3c9023)&nbsp;\*) | void<br/>函数用于画一个自定义路径 |
| [OH_Drawing_CanvasClear](_drawing.md#ga7f07cc6f0b223d9b343c133fbb2503f6)&nbsp;([OH_Drawing_Canvas](_drawing.md#ga086e2de47ef7bfe6c96e6b09e87da33a)&nbsp;\*,&nbsp;uint32_t&nbsp;color) | void<br/>函数用于使用指定颜色去清空画布 |
# drawing_color.h
## **Overview**
**Related Modules:**
[Drawing](_drawing.md)
**Description:**
文件中定义了与颜色相关的功能函数
**Since:**
8
**Version:**
1.0
## **Summary**
### Functions
| Function | Description |
| -------- | -------- |
| [OH_Drawing_ColorSetArgb](_drawing.md#ga9137935b970e49ffd813157ebd8bbfb7)&nbsp;(uint32_t&nbsp;alpha,&nbsp;uint32_t&nbsp;red,&nbsp;uint32_t&nbsp;green,&nbsp;uint32_t&nbsp;blue) | uint32_t<br/>函数用于将4个变量(分别描述透明度、红色、绿色和蓝色)转化为一个描述颜色的32位(ARGB)变量 |
# drawing_font_collection.h
## **Overview**
**Related Modules:**
[Drawing](_drawing.md)
**Description:**
定义绘制模块中与fontCollection相关的函数
**Since:**
8
**Version:**
1.0
## **Summary**
### Functions
| Function | Description |
| -------- | -------- |
| [OH_Drawing_CreateFontCollection](_drawing.md#gab54c68359a650cde36b82f021f06c814)&nbsp;(void) | [OH_Drawing_FontCollection](_drawing.md#ga4ce31d04a1580d4f50e87b8695fcebc7)&nbsp;\*<br/>创建OH_Drawing_FontCollection |
| [OH_Drawing_DestroyFontCollection](_drawing.md#ga4791ce4ddfaa3545a797c2ce144c819d)&nbsp;([OH_Drawing_FontCollection](_drawing.md#ga4ce31d04a1580d4f50e87b8695fcebc7)&nbsp;\*) | void<br/>释放被OH_Drawing_FontCollection对象占据的内存 |
# drawing_path.h
## **Overview**
**Related Modules:**
[Drawing](_drawing.md)
**Description:**
文件中定义了与自定义路径相关的功能函数
**Since:**
8
**Version:**
1.0
## **Summary**
### Functions
| Function | Description |
| -------- | -------- |
| [OH_Drawing_PathCreate](_drawing.md#ga379fcebc6b43c3b90e0933d928d7c890)&nbsp;(void) | [OH_Drawing_Path](_drawing.md#gab7e53fc0181099b4a0a3e4a08d3c9023)&nbsp;\*<br/>函数用于创建一个路径对象 |
| [OH_Drawing_PathDestroy](_drawing.md#gaa5961e76fd8d2aacdd1fe94ad354ba51)&nbsp;([OH_Drawing_Path](_drawing.md#gab7e53fc0181099b4a0a3e4a08d3c9023)&nbsp;\*) | void<br/>函数用于销毁路径对象并回收该对象占有的内存 |
| [OH_Drawing_PathMoveTo](_drawing.md#ga3934f53ce94644feaa79fb96bc7fbcc9)&nbsp;([OH_Drawing_Path](_drawing.md#gab7e53fc0181099b4a0a3e4a08d3c9023)&nbsp;\*,&nbsp;float&nbsp;x,&nbsp;float&nbsp;y) | void<br/>函数用于设置自定义路径的起始点位置 |
| [OH_Drawing_PathLineTo](_drawing.md#ga4da6ed28d5db091be54af8efe661eb18)&nbsp;([OH_Drawing_Path](_drawing.md#gab7e53fc0181099b4a0a3e4a08d3c9023)&nbsp;\*,&nbsp;float&nbsp;x,&nbsp;float&nbsp;y) | void<br/>函数用于添加一条从路径的最后点位置到目标点位置的线段 |
| [OH_Drawing_PathArcTo](_drawing.md#ga33c44796dfe8050dad3e6306f66ba0d3)&nbsp;([OH_Drawing_Path](_drawing.md#gab7e53fc0181099b4a0a3e4a08d3c9023)&nbsp;\*,&nbsp;float&nbsp;x1,&nbsp;float&nbsp;y1,&nbsp;float&nbsp;x2,&nbsp;float&nbsp;y2,&nbsp;float&nbsp;startDeg,&nbsp;float&nbsp;sweepDeg) | void<br/>函数用于给路径添加一段弧线,绘制弧线的方式为角度弧,该方式首先会指定一个矩形边框,矩形边框会包裹椭圆,&nbsp;然后会指定一个起始角度和扫描度数,从起始角度扫描截取的椭圆周长一部分即为绘制的弧线。另外会默认添加一条从路径的最后点位置到弧线起始点位置的线段 |
| [OH_Drawing_PathQuadTo](_drawing.md#ga5f69a50c045822c5d5d4896bc120318b)&nbsp;([OH_Drawing_Path](_drawing.md#gab7e53fc0181099b4a0a3e4a08d3c9023)&nbsp;\*,&nbsp;float&nbsp;ctrlX,&nbsp;float&nbsp;ctrlY,&nbsp;float&nbsp;endX,&nbsp;float&nbsp;endY) | void<br/>函数用于添加一条从路径最后点位置到目标点位置的二阶贝塞尔圆滑曲线 |
| [OH_Drawing_PathCubicTo](_drawing.md#ga6a84a20af7911dc504696402c357f1be)&nbsp;([OH_Drawing_Path](_drawing.md#gab7e53fc0181099b4a0a3e4a08d3c9023)&nbsp;\*,&nbsp;float&nbsp;ctrlX1,&nbsp;float&nbsp;ctrlY1,&nbsp;float&nbsp;ctrlX2,&nbsp;float&nbsp;ctrlY2,&nbsp;float&nbsp;endX,&nbsp;float&nbsp;endY) | void<br/>函数用于添加一条从路径最后点位置到目标点位置的三阶贝塞尔圆滑曲线 |
| [OH_Drawing_PathClose](_drawing.md#ga7a3be11857364cdf2e6ca1af70917816)&nbsp;([OH_Drawing_Path](_drawing.md#gab7e53fc0181099b4a0a3e4a08d3c9023)&nbsp;\*) | void<br/>函数用于闭合路径,会添加一条从路径起点位置到最后点位置的线段 |
| [OH_Drawing_PathReset](_drawing.md#gaf907c525b05dbd1355d16dc13b4ccda9)&nbsp;([OH_Drawing_Path](_drawing.md#gab7e53fc0181099b4a0a3e4a08d3c9023)&nbsp;\*) | void<br/>函数用于重置自定义路径数据 |
# drawing_pen.h
## **Overview**
**Related Modules:**
[Drawing](_drawing.md)
**Description:**
文件中定义了与画笔相关的功能函数
**Since:**
8
**Version:**
1.0
## **Summary**
### Enumerations
| Enumeration&nbsp;Name | Description |
| -------- | -------- |
| [OH_Drawing_PenLineCapStyle](_drawing.md#gafa9d815d933e0fd6aa7549d12080fa8f)&nbsp;{&nbsp;[LINE_FLAT_CAP](_drawing.md#ggafa9d815d933e0fd6aa7549d12080fa8fa99c48cc6172088f1a86e8688e347933a),&nbsp;[LINE_SQUARE_CAP](_drawing.md#ggafa9d815d933e0fd6aa7549d12080fa8fac9929c30114c046b75b844e459f1e69f),&nbsp;[LINE_ROUND_CAP](_drawing.md#ggafa9d815d933e0fd6aa7549d12080fa8fa0efe3fb7b56d7407737c42aebe5b91e5)&nbsp;} | 枚举集合定义了画笔笔帽的样式,即画笔在绘制线段时,在线段头尾端点的样式 |
| [OH_Drawing_PenLineJoinStyle](_drawing.md#gad10001f23f6c42f97a392cba30011460)&nbsp;{&nbsp;[LINE_MITER_JOIN](_drawing.md#ggad10001f23f6c42f97a392cba30011460a126e5fbae0f63b8431d3a6763035d488),&nbsp;[LINE_ROUND_JOIN](_drawing.md#ggad10001f23f6c42f97a392cba30011460aa2bfcc7c744ab7a56c047942060ad3ba),&nbsp;[LINE_BEVEL_JOIN](_drawing.md#ggad10001f23f6c42f97a392cba30011460a8ad7df33f8ff73c5c080fcf159631fde)&nbsp;} | 枚举集合定义了线条转角的样式,即画笔在绘制折线段时,在折线转角处的样式 |
### Functions
| Function | Description |
| -------- | -------- |
| [OH_Drawing_PenCreate](_drawing.md#gae52fe4132b90726d813661750948e2dd)&nbsp;(void) | [OH_Drawing_Pen](_drawing.md#ga88e73d9d7b62e6113237fc0f828910d2)&nbsp;\*<br/>函数用于创建一个画笔对象 |
| [OH_Drawing_PenDestroy](_drawing.md#ga907538d02a50836e8033a3f7bf12c80e)&nbsp;([OH_Drawing_Pen](_drawing.md#ga88e73d9d7b62e6113237fc0f828910d2)&nbsp;\*) | void<br/>函数用于销毁画笔对象并回收该对象占有的内存 |
| [OH_Drawing_PenIsAntiAlias](_drawing.md#ga31dee499a3d1dd81e526bcc1dd620961)&nbsp;(const&nbsp;[OH_Drawing_Pen](_drawing.md#ga88e73d9d7b62e6113237fc0f828910d2)&nbsp;\*) | bool<br/>函数用于获取画笔是否设置抗锯齿属性,如果为真则说明画笔会启用抗锯齿功能,在绘制图形时会对图形的边缘像素进行半透明的模糊处理 |
| [OH_Drawing_PenSetAntiAlias](_drawing.md#ga93dbc44cf424038a17ae311920550283)&nbsp;([OH_Drawing_Pen](_drawing.md#ga88e73d9d7b62e6113237fc0f828910d2)&nbsp;\*,&nbsp;bool) | void<br/>函数用于设置画笔的抗锯齿属性,设置为真则画笔在绘制图形时会对图形的边缘像素进行半透明的模糊处理 |
| [OH_Drawing_PenGetColor](_drawing.md#ga8a8db886ecf41a729e40a1f760338220)&nbsp;(const&nbsp;[OH_Drawing_Pen](_drawing.md#ga88e73d9d7b62e6113237fc0f828910d2)&nbsp;\*) | uint32_t<br/>函数用于获取画笔的颜色属性,颜色属性描述了画笔绘制图形轮廓时使用的颜色,用一个32位(ARGB)的变量表示 |
| [OH_Drawing_PenSetColor](_drawing.md#ga6e5b065f521dd9c41d5e7f2af5c379cb)&nbsp;([OH_Drawing_Pen](_drawing.md#ga88e73d9d7b62e6113237fc0f828910d2)&nbsp;\*,&nbsp;uint32_t&nbsp;color) | void<br/>函数用于设置画笔的颜色属性,颜色属性描述了画笔绘制图形轮廓时使用的颜色,用一个32位(ARGB)的变量表示 |
| [OH_Drawing_PenGetWidth](_drawing.md#ga3d898184f61b685d724e6d272fb12168)&nbsp;(const&nbsp;[OH_Drawing_Pen](_drawing.md#ga88e73d9d7b62e6113237fc0f828910d2)&nbsp;\*) | float<br/>函数用于获取画笔的厚度属性,厚度属性描述了画笔绘制图形轮廓的宽度 |
| [OH_Drawing_PenSetWidth](_drawing.md#ga562b5102bf599e640a94e104480df0f4)&nbsp;([OH_Drawing_Pen](_drawing.md#ga88e73d9d7b62e6113237fc0f828910d2)&nbsp;\*,&nbsp;float&nbsp;width) | void<br/>函数用于设置画笔的厚度属性,厚度属性描述了画笔绘制图形轮廓的宽度 |
| [OH_Drawing_PenGetMiterLimit](_drawing.md#ga8f8a512b3930d8883dff59916eaaa72a)&nbsp;(const&nbsp;[OH_Drawing_Pen](_drawing.md#ga88e73d9d7b62e6113237fc0f828910d2)&nbsp;\*) | float<br/>函数用于获取折线尖角的限制值,当画笔绘制一条折线,转角类型设置为尖角时,那么此时该属性用于限制出现尖角的长度范围,如果超出则平角显示,不超出依然为尖角 |
| [OH_Drawing_PenSetMiterLimit](_drawing.md#ga73a96e3e9ca95a82f0de2076cb03ffba)&nbsp;([OH_Drawing_Pen](_drawing.md#ga88e73d9d7b62e6113237fc0f828910d2)&nbsp;\*,&nbsp;float&nbsp;miter) | void<br/>函数用于设置折线尖角的限制值,当画笔绘制一条折线,转角类型设置为尖角时,那么此时该属性用于限制出现尖角的长度范围,如果超出则平角显示,不超出依然为尖角 |
| [OH_Drawing_PenGetCap](_drawing.md#ga7db0d5ac28ac24db29fc49c113affc32)&nbsp;(const&nbsp;[OH_Drawing_Pen](_drawing.md#ga88e73d9d7b62e6113237fc0f828910d2)&nbsp;\*) | [OH_Drawing_PenLineCapStyle](_drawing.md#gafa9d815d933e0fd6aa7549d12080fa8f)<br/>函数用于获取画笔笔帽的样式 |
| [OH_Drawing_PenSetCap](_drawing.md#gaa0d8f5e75ec5fbc776c4e5e780e29af3)&nbsp;([OH_Drawing_Pen](_drawing.md#ga88e73d9d7b62e6113237fc0f828910d2)&nbsp;\*,&nbsp;[OH_Drawing_PenLineCapStyle](_drawing.md#gafa9d815d933e0fd6aa7549d12080fa8f)) | void<br/>函数用于设置画笔笔帽样式 |
| [OH_Drawing_PenGetJoin](_drawing.md#ga35b26a60ebf70c207f1e8fb8659a9103)&nbsp;(const&nbsp;[OH_Drawing_Pen](_drawing.md#ga88e73d9d7b62e6113237fc0f828910d2)&nbsp;\*) | [OH_Drawing_PenLineJoinStyle](_drawing.md#gad10001f23f6c42f97a392cba30011460)<br/>函数用于获取画笔绘制折线转角的样式 |
| [OH_Drawing_PenSetJoin](_drawing.md#ga65e9826c39a847b22825e99af65afbb7)&nbsp;([OH_Drawing_Pen](_drawing.md#ga88e73d9d7b62e6113237fc0f828910d2)&nbsp;\*,&nbsp;[OH_Drawing_PenLineJoinStyle](_drawing.md#gad10001f23f6c42f97a392cba30011460)) | void<br/>函数用于设置画笔绘制转角的样式 |
# drawing_text_declaration.h
## **Overview**
**Related Modules:**
[Drawing](_drawing.md)
**Description:**
提供2d drawing文本相关的数据结构声明
**Since:**
8
**Version:**
1.0
## **Summary**
### Typedefs
| Typedef&nbsp;Name | Description |
| -------- | -------- |
| [OH_Drawing_FontCollection](_drawing.md#ga4ce31d04a1580d4f50e87b8695fcebc7) | typedef&nbsp;struct&nbsp;[OH_Drawing_FontCollection](_drawing.md#ga4ce31d04a1580d4f50e87b8695fcebc7)<br/>OH_Drawing_FontCollection用于加载字体 |
| [OH_Drawing_Typography](_drawing.md#ga70d06422fc84eb1ba49e35f525573007) | typedef&nbsp;struct&nbsp;[OH_Drawing_Typography](_drawing.md#ga70d06422fc84eb1ba49e35f525573007)<br/>OH_Drawing_Typography用于管理排版的布局和显示等 |
| [OH_Drawing_TextStyle](_drawing.md#gad731266accf168a6b50e1fa33ce90528) | typedef&nbsp;struct&nbsp;[OH_Drawing_TextStyle](_drawing.md#gad731266accf168a6b50e1fa33ce90528)<br/>OH_Drawing_TextStyle用于管理字体颜色、装饰等 |
| [OH_Drawing_TypographyStyle](_drawing.md#ga270cc54313a929ea90235840668daef9) | typedef&nbsp;struct&nbsp;[OH_Drawing_TypographyStyle](_drawing.md#ga270cc54313a929ea90235840668daef9)<br/>OH_Drawing_TypographyStyle用于管理排版风格,如文字方向等 |
| [OH_Drawing_TypographyCreate](_drawing.md#gaedefc2b3d226b0b07abcbce76be4cdb9) | typedef&nbsp;struct&nbsp;[OH_Drawing_TypographyCreate](_drawing.md#gaedefc2b3d226b0b07abcbce76be4cdb9)<br/>OH_Drawing_TypographyCreate用于创建OH_Drawing_Typography. |
# drawing_text_typography.h
## **Overview**
**Related Modules:**
[Drawing](_drawing.md)
**Description:**
定义绘制模块中排版相关的函数
**Since:**
8
**Version:**
1.0
## **Summary**
### Enumerations
| Enumeration&nbsp;Name | Description |
| -------- | -------- |
| [OH_Drawing_TextDirection](_drawing.md#ga7dc9803407c3fea32075122c7605ffb2)&nbsp;{&nbsp;[TEXT_DIRECTION_RTL](_drawing.md#gga7dc9803407c3fea32075122c7605ffb2a7b4debd0a116bc438085a43efa3824cf),&nbsp;[TEXT_DIRECTION_LTR](_drawing.md#gga7dc9803407c3fea32075122c7605ffb2a81d702a35ec4d3482ea5ff10edd8cab7)&nbsp;} | 文字方向 |
| [OH_Drawing_TextAlign](_drawing.md#ga3fee1a3916c2376e62e7957be15a1b02)&nbsp;{&nbsp;&nbsp;&nbsp;[TEXT_ALIGN_LEFT](_drawing.md#gga3fee1a3916c2376e62e7957be15a1b02a3b85bc4d8cfda6b273b534eb2e1cebfc),&nbsp;[TEXT_ALIGN_RIGHT](_drawing.md#gga3fee1a3916c2376e62e7957be15a1b02abc81ce8623a972fc7b97f497189c494b),&nbsp;[TEXT_ALIGN_CENTER](_drawing.md#gga3fee1a3916c2376e62e7957be15a1b02a4da3c85cde615e7442df8ef17d0753ba),&nbsp;[TEXT_ALIGN_JUSTIFY](_drawing.md#gga3fee1a3916c2376e62e7957be15a1b02a3e3185762a0ae703ae1eab769eb3191d),&nbsp;&nbsp;&nbsp;[TEXT_ALIGN_START](_drawing.md#gga3fee1a3916c2376e62e7957be15a1b02a72f2441e221a61374bd891dc2b75bcb0),&nbsp;[TEXT_ALIGN_END](_drawing.md#gga3fee1a3916c2376e62e7957be15a1b02a17b99fff762deffd75c0de66cd27d219)&nbsp;} | 文字对齐方式 |
| [OH_Drawing_FontWeight](_drawing.md#ga7a1d4dd0ce9dd97bf3bbbad3b87f7f21)&nbsp;{&nbsp;&nbsp;&nbsp;[FONT_WEIGHT_100](_drawing.md#gga7a1d4dd0ce9dd97bf3bbbad3b87f7f21a23b26a36963095342fe2e0697910a6e6),&nbsp;[FONT_WEIGHT_200](_drawing.md#gga7a1d4dd0ce9dd97bf3bbbad3b87f7f21a4f29ce93f64a0085ca2154ee25d9e138),&nbsp;[FONT_WEIGHT_300](_drawing.md#gga7a1d4dd0ce9dd97bf3bbbad3b87f7f21a093d1106fec67eebea0dbcb2ebbe9a64),&nbsp;[FONT_WEIGHT_400](_drawing.md#gga7a1d4dd0ce9dd97bf3bbbad3b87f7f21a62367da70683540c34ddaf2a519f22a3),&nbsp;&nbsp;&nbsp;[FONT_WEIGHT_500](_drawing.md#gga7a1d4dd0ce9dd97bf3bbbad3b87f7f21aef238378a2c00c698e269b052d31d904),&nbsp;[FONT_WEIGHT_600](_drawing.md#gga7a1d4dd0ce9dd97bf3bbbad3b87f7f21a63eebceda71bb1ffdae4a5503d63bbd9),&nbsp;[FONT_WEIGHT_700](_drawing.md#gga7a1d4dd0ce9dd97bf3bbbad3b87f7f21ae6abaa1dc57d487006cbe6c8e0f87bc6),&nbsp;[FONT_WEIGHT_800](_drawing.md#gga7a1d4dd0ce9dd97bf3bbbad3b87f7f21ad34b21ce514a03d6d98b75341bb5726e),&nbsp;&nbsp;&nbsp;[FONT_WEIGHT_900](_drawing.md#gga7a1d4dd0ce9dd97bf3bbbad3b87f7f21ac3f4c8f2d6a6922780166cc08df83461)&nbsp;} | 字重 |
| [OH_Drawing_TextBaseline](_drawing.md#ga23be0106a439e7498cbbb1d048733ec5)&nbsp;{&nbsp;[TEXT_BASELINE_ALPHABETIC](_drawing.md#gga23be0106a439e7498cbbb1d048733ec5ad436b9da96a5246e75e785a0585963f9),&nbsp;[TEXT_BASELINE_IDEOGRAPHIC](_drawing.md#gga23be0106a439e7498cbbb1d048733ec5a723ba0ba56cd7106deb97c95f51febcf)&nbsp;} | 基线位置 |
| [OH_Drawing_TextDecoration](_drawing.md#ga11b405dddb93d91c3a5b4482d8a9165b)&nbsp;{&nbsp;[TEXT_DECORATION_NONE](_drawing.md#gga11b405dddb93d91c3a5b4482d8a9165ba2b42614c2c9b73ffecf31769cfd60f28)&nbsp;=&nbsp;0x0,&nbsp;[TEXT_DECORATION_UNDERLINE](_drawing.md#gga11b405dddb93d91c3a5b4482d8a9165ba0fc17108b6c8a91d840889336c669dda)&nbsp;=&nbsp;0x1,&nbsp;[TEXT_DECORATION_OVERLINE](_drawing.md#gga11b405dddb93d91c3a5b4482d8a9165bad8415c121f9b656cd5c6cab927d78802)&nbsp;=&nbsp;0x2,&nbsp;[TEXT_DECORATION_LINE_THROUGH](_drawing.md#gga11b405dddb93d91c3a5b4482d8a9165ba25692d42e0a907af878d99a0a31f7f47)&nbsp;=&nbsp;0x4&nbsp;} | 文本装饰 |
| [OH_Drawing_FontStyle](_drawing.md#ga9cd0177d2561ccef51adbae0f8a42eec)&nbsp;{&nbsp;[FONT_STYLE_NORMAL](_drawing.md#gga9cd0177d2561ccef51adbae0f8a42eeca307e676fb5de5c785e856272b2f0e8ce),&nbsp;[FONT_STYLE_ITALIC](_drawing.md#gga9cd0177d2561ccef51adbae0f8a42eeca6054e24016c46486668dd42e4b86c036)&nbsp;} | 区分字体是否为斜体 |
### Functions
| Function | Description |
| -------- | -------- |
| [OH_Drawing_CreateTypographyStyle](_drawing.md#ga19561093a2d5ec17f2c73b40f0d97376)&nbsp;(void) | [OH_Drawing_TypographyStyle](_drawing.md#ga270cc54313a929ea90235840668daef9)&nbsp;\*<br/>创建OH_Drawing_TypographyStyle |
| [OH_Drawing_DestroyTypographyStyle](_drawing.md#ga9bd838c0d86136e16faca0ada643d87e)&nbsp;([OH_Drawing_TypographyStyle](_drawing.md#ga270cc54313a929ea90235840668daef9)&nbsp;\*) | void<br/>释放被OH_Drawing_TypographyStyle对象占据的内存 |
| [OH_Drawing_SetTypographyTextDirection](_drawing.md#ga9e96b89ffc3f06f50ab38f05689e766e)&nbsp;([OH_Drawing_TypographyStyle](_drawing.md#ga270cc54313a929ea90235840668daef9)&nbsp;\*,&nbsp;int) | void<br/>设置文本方向 |
| [OH_Drawing_SetTypographyTextAlign](_drawing.md#gaa1a8b20a882ae6aa4e2ad442a18423da)&nbsp;([OH_Drawing_TypographyStyle](_drawing.md#ga270cc54313a929ea90235840668daef9)&nbsp;\*,&nbsp;int) | void<br/>设置文本对齐方式 |
| [OH_Drawing_SetTypographyTextMaxLines](_drawing.md#gab74fd8ef23005bf584f87357147fa379)&nbsp;([OH_Drawing_TypographyStyle](_drawing.md#ga270cc54313a929ea90235840668daef9)&nbsp;\*,&nbsp;int) | void<br/>设置文本最大行数 |
| [OH_Drawing_CreateTextStyle](_drawing.md#ga9041c35231647ed34306ef26f21037f9)&nbsp;(void) | [OH_Drawing_TextStyle](_drawing.md#gad731266accf168a6b50e1fa33ce90528)&nbsp;\*<br/>创建OH_Drawing_TextStyle |
| [OH_Drawing_DestroyTextStyle](_drawing.md#ga2550946ac8d3c8c9ddc548e128175020)&nbsp;([OH_Drawing_TextStyle](_drawing.md#gad731266accf168a6b50e1fa33ce90528)&nbsp;\*) | void<br/>释放被OH_Drawing_TextStyle对象占据的内存 |
| [OH_Drawing_SetTextStyleColor](_drawing.md#ga4c03826dd970defade08b67ed1861fc8)&nbsp;([OH_Drawing_TextStyle](_drawing.md#gad731266accf168a6b50e1fa33ce90528)&nbsp;\*,&nbsp;uint32_t) | void<br/>设置文本颜色 |
| [OH_Drawing_SetTextStyleFontSize](_drawing.md#ga4f435be1d8b20bd0abac441ac91bb81d)&nbsp;([OH_Drawing_TextStyle](_drawing.md#gad731266accf168a6b50e1fa33ce90528)&nbsp;\*,&nbsp;double) | void<br/>设置字号 |
| [OH_Drawing_SetTextStyleFontWeight](_drawing.md#ga751dd287f984367c18de6ca3a3a304ec)&nbsp;([OH_Drawing_TextStyle](_drawing.md#gad731266accf168a6b50e1fa33ce90528)&nbsp;\*,&nbsp;int) | void<br/>设置字重 |
| [OH_Drawing_SetTextStyleBaseLine](_drawing.md#gacb93fa7c791e719cf9c5d218981f61ee)&nbsp;([OH_Drawing_TextStyle](_drawing.md#gad731266accf168a6b50e1fa33ce90528)&nbsp;\*,&nbsp;int) | void<br/>设置字体基线位置 |
| [OH_Drawing_SetTextStyleDecoration](_drawing.md#ga2f029e23749fcd121aaae6e233202ded)&nbsp;([OH_Drawing_TextStyle](_drawing.md#gad731266accf168a6b50e1fa33ce90528)&nbsp;\*,&nbsp;int) | void<br/>设置装饰 |
| [OH_Drawing_SetTextStyleDecorationColor](_drawing.md#ga22304942171ce4548b50057bd7d606be)&nbsp;([OH_Drawing_TextStyle](_drawing.md#gad731266accf168a6b50e1fa33ce90528)&nbsp;\*,&nbsp;uint32_t) | void<br/>设置装饰颜色 |
| [OH_Drawing_SetTextStyleFontHeight](_drawing.md#gab96b5567c05f34e6ba7d48a4dd75eab4)&nbsp;([OH_Drawing_TextStyle](_drawing.md#gad731266accf168a6b50e1fa33ce90528)&nbsp;\*,&nbsp;double) | void<br/>设置字体高度 |
| [OH_Drawing_SetTextStyleFontFamilies](_drawing.md#ga3f46d90176575f24040828264ce18a90)&nbsp;([OH_Drawing_TextStyle](_drawing.md#gad731266accf168a6b50e1fa33ce90528)&nbsp;\*,&nbsp;int,&nbsp;const&nbsp;char&nbsp;\*fontFamilies[]) | void<br/>设置字体类型 |
| [OH_Drawing_SetTextStyleFontStyle](_drawing.md#ga67afa0910007fa3d8b15f2b6df61712c)&nbsp;([OH_Drawing_TextStyle](_drawing.md#gad731266accf168a6b50e1fa33ce90528)&nbsp;\*,&nbsp;int) | void<br/>设置字体风格 |
| [OH_Drawing_SetTextStyleLocale](_drawing.md#ga7eb6f2da34059c013cfb0567c44813d4)&nbsp;([OH_Drawing_TextStyle](_drawing.md#gad731266accf168a6b50e1fa33ce90528)&nbsp;\*,&nbsp;const&nbsp;char&nbsp;\*) | void<br/>设置语言区域 |
| [OH_Drawing_CreateTypographyHandler](_drawing.md#gae72088abf73419c0c8e8e524602a317e)&nbsp;([OH_Drawing_TypographyStyle](_drawing.md#ga270cc54313a929ea90235840668daef9)&nbsp;\*,&nbsp;[OH_Drawing_FontCollection](_drawing.md#ga4ce31d04a1580d4f50e87b8695fcebc7)&nbsp;\*) | [OH_Drawing_TypographyCreate](_drawing.md#gaedefc2b3d226b0b07abcbce76be4cdb9)&nbsp;\*<br/>创建指向OH_Drawing_TypographyCreate对象的指针 |
| [OH_Drawing_DestroyTypographyHandler](_drawing.md#ga211dced7f1eaed0c5bd507cd75d003c8)&nbsp;([OH_Drawing_TypographyCreate](_drawing.md#gaedefc2b3d226b0b07abcbce76be4cdb9)&nbsp;\*) | void<br/>释放被OH_Drawing_TypographyCreate对象占据的内存 |
| [OH_Drawing_TypographyHandlerPushStyle](_drawing.md#ga5aff793cec1b58c171817649b01f35d1)&nbsp;([OH_Drawing_TypographyCreate](_drawing.md#gaedefc2b3d226b0b07abcbce76be4cdb9)&nbsp;\*,&nbsp;[OH_Drawing_TextStyle](_drawing.md#gad731266accf168a6b50e1fa33ce90528)&nbsp;\*) | void<br/>设置排版风格 |
| [OH_Drawing_TypographyHandlerAddText](_drawing.md#ga0bb4f9730faa77f6ed8cdce25e7965f2)&nbsp;([OH_Drawing_TypographyCreate](_drawing.md#gaedefc2b3d226b0b07abcbce76be4cdb9)&nbsp;\*,&nbsp;const&nbsp;char&nbsp;\*) | void<br/>设置文本内容 |
| [OH_Drawing_TypographyHandlerPop](_drawing.md#gabe9b81431e1a7ca473fc0659c150bb6b)&nbsp;([OH_Drawing_TypographyCreate](_drawing.md#gaedefc2b3d226b0b07abcbce76be4cdb9)&nbsp;\*) | void<br/>排版弹出 |
| [OH_Drawing_CreateTypography](_drawing.md#gaf996ac9db09b8d7c21b8ea4797ea0c19)&nbsp;([OH_Drawing_TypographyCreate](_drawing.md#gaedefc2b3d226b0b07abcbce76be4cdb9)&nbsp;\*) | [OH_Drawing_Typography](_drawing.md#ga70d06422fc84eb1ba49e35f525573007)&nbsp;\*<br/>创建OH_Drawing_Typography |
| [OH_Drawing_DestroyTypography](_drawing.md#ga2d0d1b715931c104042c75e4d21a86a3)&nbsp;([OH_Drawing_Typography](_drawing.md#ga70d06422fc84eb1ba49e35f525573007)&nbsp;\*) | void<br/>释放OH_Drawing_Typography对象占据的内存 |
| [OH_Drawing_TypographyLayout](_drawing.md#ga9032552c1d8d8e258f86832190223843)&nbsp;([OH_Drawing_Typography](_drawing.md#ga70d06422fc84eb1ba49e35f525573007)&nbsp;\*,&nbsp;double) | void<br/>排版布局 |
| [OH_Drawing_TypographyPaint](_drawing.md#ga8b12b7dc251b3a2bb71f7e289a27e174)&nbsp;([OH_Drawing_Typography](_drawing.md#ga70d06422fc84eb1ba49e35f525573007)&nbsp;\*,&nbsp;[OH_Drawing_Canvas](_drawing.md#ga086e2de47ef7bfe6c96e6b09e87da33a)&nbsp;\*,&nbsp;double,&nbsp;double) | void<br/>显示文本 |
# drawing_types.h
## **Overview**
**Related Modules:**
[Drawing](_drawing.md)
**Description:**
文件中定义了用于绘制2d图形的数据类型,包括画布、画笔、画刷、位图和路径
**Since:**
8
**Version:**
1.0
## **Summary**
### Typedefs
| Typedef&nbsp;Name | Description |
| -------- | -------- |
| [OH_Drawing_Canvas](_drawing.md#ga086e2de47ef7bfe6c96e6b09e87da33a) | typedef&nbsp;struct&nbsp;[OH_Drawing_Canvas](_drawing.md#ga086e2de47ef7bfe6c96e6b09e87da33a)<br/>OH_Drawing_Canvas定义为一块矩形的画布,可以结合画笔和画刷在上面绘制各种形状、图片和文字 |
| [OH_Drawing_Pen](_drawing.md#ga88e73d9d7b62e6113237fc0f828910d2) | typedef&nbsp;struct&nbsp;[OH_Drawing_Pen](_drawing.md#ga88e73d9d7b62e6113237fc0f828910d2)<br/>OH_Drawing_Pen定义为画笔,画笔用于描述绘制图形轮廓的样式和颜色 |
| [OH_Drawing_Brush](_drawing.md#ga178c83de4a084d35c30e4681319ea711) | typedef&nbsp;struct&nbsp;[OH_Drawing_Brush](_drawing.md#ga178c83de4a084d35c30e4681319ea711)<br/>OH_Drawing_Brush定义为画刷,画刷用于描述填充图形的样式和颜色 |
| [OH_Drawing_Path](_drawing.md#gab7e53fc0181099b4a0a3e4a08d3c9023) | typedef&nbsp;struct&nbsp;[OH_Drawing_Path](_drawing.md#gab7e53fc0181099b4a0a3e4a08d3c9023)<br/>OH_Drawing_Path定义为路径,路径用于自定义各种形状 |
| [OH_Drawing_Bitmap](_drawing.md#ga8ac4e64cd1e2c651d11325e04c72ddeb) | typedef&nbsp;struct&nbsp;[OH_Drawing_Bitmap](_drawing.md#ga8ac4e64cd1e2c651d11325e04c72ddeb)<br/>OH_Drawing_Bitmap定义为位图,位图是一块内存,内存中包含了描述一张图片的像素数据 |
### Enumerations
| Enumeration&nbsp;Name | Description |
| -------- | -------- |
| [OH_Drawing_ColorFormat](_drawing.md#ga6a37fff6c3e0b0d9d81b01755ef846db)&nbsp;{&nbsp;&nbsp;&nbsp;[COLOR_FORMAT_UNKNOWN](_drawing.md#gga6a37fff6c3e0b0d9d81b01755ef846dbab58141bf00d632ba06094d3c4b6446c2),&nbsp;[COLOR_FORMAT_ALPHA_8](_drawing.md#gga6a37fff6c3e0b0d9d81b01755ef846dbabe54d848a7de45ac9a9a89a6eb6a1886),&nbsp;[COLOR_FORMAT_RGB_565](_drawing.md#gga6a37fff6c3e0b0d9d81b01755ef846dbabc7b2f524d90d876ad222dd595c287d9),&nbsp;[COLOR_FORMAT_ARGB_4444](_drawing.md#gga6a37fff6c3e0b0d9d81b01755ef846dba3dac16f10989bdacb479e7fcd9b8861e),&nbsp;&nbsp;&nbsp;[COLOR_FORMAT_RGBA_8888](_drawing.md#gga6a37fff6c3e0b0d9d81b01755ef846dba3b1984f6b8b6fe5f5d65215c95e80ac2),&nbsp;[COLOR_FORMAT_BGRA_8888](_drawing.md#gga6a37fff6c3e0b0d9d81b01755ef846dba44017098e353684bc3bbd2cd0878df15)&nbsp;} | OH_Drawing_ColorFormat用于描述位图像素的存储格式 |
| [OH_Drawing_AlphaFormat](_drawing.md#gac4dc831be312bb0a7a4745448f4407d3)&nbsp;{&nbsp;[ALPHA_FORMAT_UNKNOWN](_drawing.md#ggac4dc831be312bb0a7a4745448f4407d3ac7e2536628ce62acfc14ec2538425a4a),&nbsp;[ALPHA_FORMAT_OPAQUE](_drawing.md#ggac4dc831be312bb0a7a4745448f4407d3abd3d60c5f30c90748393276a5845f662),&nbsp;[ALPHA_FORMAT_PREMUL](_drawing.md#ggac4dc831be312bb0a7a4745448f4407d3ac0ad416cd779ddc62466d6dceb9a757f),&nbsp;[ALPHA_FORMAT_UNPREMUL](_drawing.md#ggac4dc831be312bb0a7a4745448f4407d3a0b8120300ddca06e3d5db79bfad59a32)&nbsp;} | OH_Drawing_AlphaFormat用于描述位图像素的透明度分量 |
# external_window.h
## **Overview**
**Related Modules:**
[NativeWindow](_native_window.md)
**Description:**
定义获取和使用NativeWindow的相关函数
**Since:**
8
**Version:**
1.0
## **Summary**
### Functions
| Function | Description |
| -------- | -------- |
| [OH_NativeWindow_CreateNativeWindowFromSurface](_native_window.md#ga4225dd025093bc610670c2b517f186c2)&nbsp;(void&nbsp;\*pSurface) | struct&nbsp;NativeWindow&nbsp;\*<br/>创建NativeWindow实例,每次调用都会产生一个新的NativeWindow实例 |
| [OH_NativeWindow_DestroyNativeWindow](_native_window.md#ga1ca5f2e39a03b6546352ac90be19238d)&nbsp;(struct&nbsp;NativeWindow&nbsp;\*window) | void<br/>将NativeWindow对象的引用计数减1,当引用计数为0的时候,该NativeWindow对象会被析构掉 |
| [OH_NativeWindow_CreateNativeWindowBufferFromSurfaceBuffer](_native_window.md#gaec1b04ace16a364d79b7d54cf917e6f5)&nbsp;(void&nbsp;\*pSurfaceBuffer) | struct&nbsp;NativeWindowBuffer&nbsp;\*<br/>创建NativeWindowBuffer实例,每次调用都会产生一个新的NativeWindowBuffer实例 |
| [OH_NativeWindow_DestroyNativeWindowBuffer](_native_window.md#gafa11a7f9a36b2e6962cc34790eb1e87e)&nbsp;(struct&nbsp;NativeWindowBuffer&nbsp;\*buffer) | void<br/>将NativeWindowBuffer对象的引用计数减1,当引用计数为0的时候,该NativeWindowBuffer对象会被析构掉 |
| [OH_NativeWindow_NativeWindowRequestBuffer](_native_window.md#ga80cad8d3c2863294f828caa4d3422c2c)&nbsp;(struct&nbsp;NativeWindow&nbsp;\*window,&nbsp;struct&nbsp;NativeWindowBuffer&nbsp;\*\*buffer,&nbsp;int&nbsp;\*fenceFd) | int32_t<br/>通过NativeWindow对象申请一块NativeWindowBuffer,用以内容生产 |
| [OH_NativeWindow_NativeWindowFlushBuffer](_native_window.md#ga8489a6525b5c9f7a6b52aafba07fb777)&nbsp;(struct&nbsp;NativeWindow&nbsp;\*window,&nbsp;struct&nbsp;NativeWindowBuffer&nbsp;\*buffer,&nbsp;int&nbsp;fenceFd,&nbsp;Region&nbsp;region) | int32_t<br/>通过NativeWindow将生产好内容的NativeWindowBuffer放回到Buffer队列中,用以内容消费 |
| [OH_NativeWindow_NativeWindowCancelBuffer](_native_window.md#gad7b6ffa8b402f5be0bf6e742b18f03d0)&nbsp;(struct&nbsp;NativeWindow&nbsp;\*window,&nbsp;struct&nbsp;NativeWindowBuffer&nbsp;\*buffer) | int32_t<br/>通过NativeWindow将之前申请出来的NativeWindowBuffer返还到Buffer队列中,供下次再申请 |
| [OH_NativeWindow_NativeWindowHandleOpt](_native_window.md#ga5620fba277d2f086da6c6d7434c09253)&nbsp;(struct&nbsp;NativeWindow&nbsp;\*window,&nbsp;int&nbsp;code,...) | int32_t<br/>设置/获取NativeWindow的属性,包括设置/获取宽高、内容格式等 |
| [OH_NativeWindow_GetBufferHandleFromNative](_native_window.md#ga28c34ab9b0751010cb716ca9acd6dfef)&nbsp;(struct&nbsp;NativeWindowBuffer&nbsp;\*buffer) | BufferHandle&nbsp;\*<br/>通过NativeWindowBuffer获取该buffer的BufferHandle指针 |
| [OH_NativeWindow_NativeObjectReference](_native_window.md#gafcbd7894c5cdae431e591028c5f7f709)&nbsp;(void&nbsp;\*obj) | int32_t<br/>增加一个NativeObject的引用计数 |
| [OH_NativeWindow_NativeObjectUnreference](_native_window.md#ga24567fa7daee679bf927623adac93a9f)&nbsp;(void&nbsp;\*obj) | int32_t<br/>减少一个NativeObject的引用计数,当引用计数减少为0时,该NativeObject将被析构掉 |
| [OH_NativeWindow_GetNativeObjectMagic](_native_window.md#ga93828d364eebf3ec5c81d7897757f9f2)&nbsp;(void&nbsp;\*obj) | int32_t<br/>获取NativeObject的MagicId |
# 头文件
- **[drawing_bitmap.h](drawing__bitmap_8h.md)**
- **[drawing_brush.h](drawing__brush_8h.md)**
- **[drawing_canvas.h](drawing__canvas_8h.md)**
- **[drawing_color.h](drawing__color_8h.md)**
- **[drawing_font_collection.h](drawing__font__collection_8h.md)**
- **[drawing_path.h](drawing__path_8h.md)**
- **[drawing_pen.h](drawing__pen_8h.md)**
- **[drawing_text_declaration.h](drawing__text__declaration_8h.md)**
- **[drawing_text_typography.h](drawing__text__typography_8h.md)**
- **[drawing_types.h](drawing__types_8h.md)**
- **[external_window.h](external__window_8h.md)**
- **[log.h](log_8h.md)**
- **[native_interface_bundle.h](native__interface__bundle_8h.md)**
- **[native_interface_xcomponent.h](native__interface__xcomponent_8h.md)**
- **[raw_dir.h](raw__dir_8h.md)**
- **[raw_file.h](raw__file_8h.md)**
\ No newline at end of file
# MyProject
- **[Native XComponent](_o_h___native_x_component.md)**
- **[Native_Bundle](_native___bundle.md)**
- **[HiLog](_hi_log.md)**
- **[NativeWindow](_native_window.md)**
- **[Drawing](_drawing.md)**
- **[Rawfile](rawfile.md)**
\ No newline at end of file
# log.h
## **Overview**
**Related Modules:**
[HiLog](_hi_log.md)
**Description:**
HiLog模块日志接口定义,通过这些接口实现日志打印相关功能。
用户输出日志时,先定义日志所属业务领域、日志TAG,然后按照类型、级别选择对应API,指定参数隐私标识输出日志内容。 业务领域:指定日志所对应的业务领域,用户自定义使用,用于标识业务的子系统、模块。16进制整数,范围0x0~0xFFFF。 日志TAG:字符串常量,用于标识调用所在的类或者业务。 日志级别:DEBUG、INFO、WARN、ERROR、FATAL。 参数格式:类printf的方式,包括格式字符串(包括参数类型标识)和变参。 隐私参数标识:在格式字符串每个参数中符号后类型前增加{public}、{private}标识。注意:每个参数未指定隐私标识时,缺省为隐私。 使用示例: 定义业务领域、TAG: \#define LOG_DOMAIN 0x0201 \#define LOG_TAG "MY_TAG" 日志打印: HILOG_WARN([LOG_APP](_hi_log.md#ggaf67907baa897e9fb84df0cb89795b87ca84f0546432a39b6f5e8a777d5cf667b5), "Failed to visit %{private}s, reason:%{public}d.", url, errno); 结果输出: 05-06 15:01:06.870 1051 1051 W 0201/MY_TAG: Failed to visit &lt;private&gt;, reason:503.
**Since:**
8
## **Summary**
### Macros
| Macro&nbsp;Name&nbsp;and&nbsp;Value | Description |
| -------- | -------- |
| [LOG_DOMAIN](_hi_log.md#ga95a1d08c807e0aada863b5298a61d08d)&nbsp;&nbsp;&nbsp;0 | 日志所对应的业务领域,用于标识业务的子系统、模块。 |
| [LOG_TAG](_hi_log.md#ga7ce0df38eb467e59f209470c8f5ac4e6)&nbsp;&nbsp;&nbsp;NULL | 字符串常量,标识调用所在的类或者业务。 |
| [OH_LOG_DEBUG](_hi_log.md#gac9b9319de06bce0df57ef440ccaa25fc)(type,&nbsp;...)&nbsp;&nbsp;&nbsp;((void)[OH_LOG_Print](_hi_log.md#gaed4b343058326b7f5dbcac6799025946)((type),&nbsp;[LOG_DEBUG](_hi_log.md#ggaca1fd1d8935433e6ba2e3918214e07f9ab9f002c6ffbfd511da8090213227454e),&nbsp;[LOG_DOMAIN](_hi_log.md#ga95a1d08c807e0aada863b5298a61d08d),&nbsp;[LOG_TAG](_hi_log.md#ga7ce0df38eb467e59f209470c8f5ac4e6),&nbsp;__VA_ARGS__)) | DEBUG级别写日志,宏封装接口。 |
| [OH_LOG_INFO](_hi_log.md#gadf3fd661bccb575348c5109a0f24f252)(type,&nbsp;...)&nbsp;&nbsp;&nbsp;((void)[OH_LOG_Print](_hi_log.md#gaed4b343058326b7f5dbcac6799025946)((type),&nbsp;[LOG_INFO](_hi_log.md#ggaca1fd1d8935433e6ba2e3918214e07f9a6e98ff471e3ce6c4ef2d75c37ee51837),&nbsp;[LOG_DOMAIN](_hi_log.md#ga95a1d08c807e0aada863b5298a61d08d),&nbsp;[LOG_TAG](_hi_log.md#ga7ce0df38eb467e59f209470c8f5ac4e6),&nbsp;__VA_ARGS__)) | INFO级别写日志,宏封装接口。 |
| [OH_LOG_WARN](_hi_log.md#ga1beaeee414c2e0238db4c57212809737)(type,&nbsp;...)&nbsp;&nbsp;&nbsp;((void)[OH_LOG_Print](_hi_log.md#gaed4b343058326b7f5dbcac6799025946)((type),&nbsp;[LOG_WARN](_hi_log.md#ggaca1fd1d8935433e6ba2e3918214e07f9ac8041ffa22bc823d4726701cdb13fc13),&nbsp;[LOG_DOMAIN](_hi_log.md#ga95a1d08c807e0aada863b5298a61d08d),&nbsp;[LOG_TAG](_hi_log.md#ga7ce0df38eb467e59f209470c8f5ac4e6),&nbsp;__VA_ARGS__)) | WARN级别写日志,宏封装接口。 |
| [OH_LOG_ERROR](_hi_log.md#gab7e62682d195ee81093e7e08673c4941)(type,&nbsp;...)&nbsp;&nbsp;&nbsp;((void)[OH_LOG_Print](_hi_log.md#gaed4b343058326b7f5dbcac6799025946)((type),&nbsp;[LOG_ERROR](_hi_log.md#ggaca1fd1d8935433e6ba2e3918214e07f9a230506cce5c68c3bac5a821c42ed3473),&nbsp;[LOG_DOMAIN](_hi_log.md#ga95a1d08c807e0aada863b5298a61d08d),&nbsp;[LOG_TAG](_hi_log.md#ga7ce0df38eb467e59f209470c8f5ac4e6),&nbsp;__VA_ARGS__)) | ERROR级别写日志,宏封装接口。 |
| [OH_LOG_FATAL](_hi_log.md#ga17370605a946403e37024ea898d27f55)(type,&nbsp;...)&nbsp;&nbsp;&nbsp;((void)HiLogPrint((type),&nbsp;[LOG_FATAL](_hi_log.md#ggaca1fd1d8935433e6ba2e3918214e07f9ac630750884d91cb9767ef2200bbb048b),&nbsp;[LOG_DOMAIN](_hi_log.md#ga95a1d08c807e0aada863b5298a61d08d),&nbsp;[LOG_TAG](_hi_log.md#ga7ce0df38eb467e59f209470c8f5ac4e6),&nbsp;__VA_ARGS__)) | FATAL级别写日志,宏封装接口。 |
### Enumerations
| Enumeration&nbsp;Name | Description |
| -------- | -------- |
| [LogType](_hi_log.md#gaf67907baa897e9fb84df0cb89795b87c)&nbsp;{&nbsp;[LOG_APP](_hi_log.md#ggaf67907baa897e9fb84df0cb89795b87ca84f0546432a39b6f5e8a777d5cf667b5)&nbsp;=&nbsp;0&nbsp;} | 日志类型。 |
| [LogLevel](_hi_log.md#gaca1fd1d8935433e6ba2e3918214e07f9)&nbsp;{&nbsp;&nbsp;&nbsp;[LOG_DEBUG](_hi_log.md#ggaca1fd1d8935433e6ba2e3918214e07f9ab9f002c6ffbfd511da8090213227454e)&nbsp;=&nbsp;3,&nbsp;[LOG_INFO](_hi_log.md#ggaca1fd1d8935433e6ba2e3918214e07f9a6e98ff471e3ce6c4ef2d75c37ee51837)&nbsp;=&nbsp;4,&nbsp;[LOG_WARN](_hi_log.md#ggaca1fd1d8935433e6ba2e3918214e07f9ac8041ffa22bc823d4726701cdb13fc13)&nbsp;=&nbsp;5,&nbsp;[LOG_ERROR](_hi_log.md#ggaca1fd1d8935433e6ba2e3918214e07f9a230506cce5c68c3bac5a821c42ed3473)&nbsp;=&nbsp;6,&nbsp;&nbsp;&nbsp;[LOG_FATAL](_hi_log.md#ggaca1fd1d8935433e6ba2e3918214e07f9ac630750884d91cb9767ef2200bbb048b)&nbsp;=&nbsp;7&nbsp;} | 日志级别。 |
### Functions
| Function | Description |
| -------- | -------- |
| [OH_LOG_Print](_hi_log.md#gaed4b343058326b7f5dbcac6799025946)&nbsp;([LogType](_hi_log.md#gaf67907baa897e9fb84df0cb89795b87c)&nbsp;type,&nbsp;[LogLevel](_hi_log.md#gaca1fd1d8935433e6ba2e3918214e07f9)&nbsp;level,&nbsp;unsigned&nbsp;int&nbsp;domain,&nbsp;const&nbsp;char&nbsp;\*tag,&nbsp;const&nbsp;char&nbsp;\*fmt,...)&nbsp;__attribute__((__format__(os_log | int<br/>写日志接口。 |
| [OH_LOG_IsLoggable](_hi_log.md#gabba82e8c08cf8941e4af54941eeda257)&nbsp;(unsigned&nbsp;int&nbsp;domain,&nbsp;const&nbsp;char&nbsp;\*tag,&nbsp;[LogLevel](_hi_log.md#gaca1fd1d8935433e6ba2e3918214e07f9)&nbsp;level) | int&nbsp;bool<br/>检查指定业务领域、TAG、级别的日志是否可以打印。 |
# native_interface_bundle.h
## **Overview**
**Related Modules:**
[Native_Bundle](_native___bundle.md)
**Description:**
Declares the **Bundle**-specific function, including function for obtaining application ID.
**Since:**
9
**Version:**
1.0
## **Summary**
### Functions
| Function | Description |
| -------- | -------- |
| [OH_NativeBundle_GetAppIdByBundleName](_native___bundle.md#gaa407fb88995597480c5584cce1fb14bd)&nbsp;(const&nbsp;char&nbsp;\*bundleName) | char&nbsp;\*<br/>Obtains&nbsp;the&nbsp;application&nbsp;ID&nbsp;based&nbsp;on&nbsp;the&nbsp;given&nbsp;bundle&nbsp;name. |
# native_interface_xcomponent.h
## **Overview**
**Related Modules:**
[Native XComponent](_o_h___native_x_component.md)
**Description:**
Declares APIs for accessing a Native XComponent.
**Since:**
8
**Version:**
1.0
## **Summary**
### Classes
| Classe&nbsp;Name | Description |
| -------- | -------- |
| [OH_NativeXComponent_TouchPoint](_o_h___native_x_component___touch_point.md) | |
| [OH_NativeXComponent_TouchEvent](_o_h___native_x_component___touch_event.md) | |
| [OH_NativeXComponent_Callback](_o_h___native_x_component___callback.md) | Registers&nbsp;the&nbsp;surface&nbsp;lifecycle&nbsp;and&nbsp;touch&nbsp;event&nbsp;callbacks. |
### Macros
| Macro&nbsp;Name&nbsp;and&nbsp;Value | Description |
| -------- | -------- |
| **OH_NATIVE_XCOMPONENT_OBJ**&nbsp;&nbsp;&nbsp;("__NATIVE_XCOMPONENT_OBJ__") | |
### Typedefs
| Typedef&nbsp;Name | Description |
| -------- | -------- |
| [OH_NativeXComponent](_o_h___native_x_component.md#ga0e676460ec145b81bdb07a97a368a5f1) | typedef&nbsp;struct&nbsp;[OH_NativeXComponent](_o_h___native_x_component.md#ga0e676460ec145b81bdb07a97a368a5f1)<br/>Provides&nbsp;an&nbsp;encapsulated&nbsp;**OH_NativeXComponent**&nbsp;instance. |
| [OH_NativeXComponent_Callback](_o_h___native_x_component.md#gaf629ecc5d06f0a69aea9da3511679ea5) | typedef&nbsp;struct&nbsp;[OH_NativeXComponent_Callback](_o_h___native_x_component___callback.md)<br/>Registers&nbsp;the&nbsp;surface&nbsp;lifecycle&nbsp;and&nbsp;touch&nbsp;event&nbsp;callbacks. |
### Enumerations
| Enumeration&nbsp;Name | Description |
| -------- | -------- |
| {&nbsp;[OH_NATIVEXCOMPONENT_RESULT_SUCCESS](_o_h___native_x_component.md#gga06fc87d81c62e9abb8790b6e5713c55baf2a815b270113979adea7b9440e0b80e)&nbsp;=&nbsp;0,&nbsp;[OH_NATIVEXCOMPONENT_RESULT_FAILED](_o_h___native_x_component.md#gga06fc87d81c62e9abb8790b6e5713c55bad6e4a33f3c594e267b8101bbc8ba682f)&nbsp;=&nbsp;-1,&nbsp;[OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER](_o_h___native_x_component.md#gga06fc87d81c62e9abb8790b6e5713c55baa12565a3677df7c8dc60e216ed40e580)&nbsp;=&nbsp;-2&nbsp;} | Enumerates&nbsp;the&nbsp;API&nbsp;access&nbsp;states. |
| [OH_NativeXComponent_TouchEventType](_o_h___native_x_component.md#ga0a8c68dd460d7e801e7c0ff771f09182)&nbsp;{&nbsp;&nbsp;&nbsp;[OH_NATIVEXCOMPONENT_DOWN](_o_h___native_x_component.md#gga0a8c68dd460d7e801e7c0ff771f09182a87b4dfe82e5aafd40c202484fc10dfb4)&nbsp;=&nbsp;0,&nbsp;[OH_NATIVEXCOMPONENT_UP](_o_h___native_x_component.md#gga0a8c68dd460d7e801e7c0ff771f09182ae2da3fbb127398f9a749070edf671597),&nbsp;[OH_NATIVEXCOMPONENT_MOVE](_o_h___native_x_component.md#gga0a8c68dd460d7e801e7c0ff771f09182a0b97e9e7830d0363e3617e2a7d33b378),&nbsp;[OH_NATIVEXCOMPONENT_CANCEL](_o_h___native_x_component.md#gga0a8c68dd460d7e801e7c0ff771f09182a8593a5e1053e9c9df74d6b0e8a9bbb0a),&nbsp;&nbsp;&nbsp;[OH_NATIVEXCOMPONENT_UNKNOWN](_o_h___native_x_component.md#gga0a8c68dd460d7e801e7c0ff771f09182aff39d23c1412b3b110a19df4893651d3)&nbsp;} | |
### Functions
| Function | Description |
| -------- | -------- |
| [OH_NativeXComponent_GetXComponentId](_o_h___native_x_component.md#ga1aa5d0ac3778b9caef35f93b54a6f677)&nbsp;([OH_NativeXComponent](_o_h___native_x_component.md#ga0e676460ec145b81bdb07a97a368a5f1)&nbsp;\*component,&nbsp;char&nbsp;\*id,&nbsp;uint64_t&nbsp;\*size) | int32_t<br/>Obtains&nbsp;the&nbsp;ID&nbsp;of&nbsp;the&nbsp;ArkUI&nbsp;XComponent. |
| [OH_NativeXComponent_GetXComponentSize](_o_h___native_x_component.md#ga8f60375298a5d9eae57d03d4c5cf5f3f)&nbsp;([OH_NativeXComponent](_o_h___native_x_component.md#ga0e676460ec145b81bdb07a97a368a5f1)&nbsp;\*component,&nbsp;const&nbsp;void&nbsp;\*window,&nbsp;uint64_t&nbsp;\*width,&nbsp;uint64_t&nbsp;\*height) | int32_t<br/>Obtains&nbsp;the&nbsp;size&nbsp;of&nbsp;the&nbsp;surface&nbsp;held&nbsp;by&nbsp;the&nbsp;ArkUI&nbsp;XComponent. |
| [OH_NativeXComponent_GetXComponentOffset](_o_h___native_x_component.md#ga3a594868e2d0f633026b7fea2f45812a)&nbsp;([OH_NativeXComponent](_o_h___native_x_component.md#ga0e676460ec145b81bdb07a97a368a5f1)&nbsp;\*component,&nbsp;const&nbsp;void&nbsp;\*window,&nbsp;double&nbsp;\*x,&nbsp;double&nbsp;\*y) | int32_t<br/>Obtains&nbsp;the&nbsp;offset&nbsp;of&nbsp;the&nbsp;surface&nbsp;held&nbsp;by&nbsp;the&nbsp;ArkUI&nbsp;XComponent. |
| [OH_NativeXComponent_GetTouchEvent](_o_h___native_x_component.md#ga5b0e85c74dab846b5b61a5e244ee60ca)&nbsp;([OH_NativeXComponent](_o_h___native_x_component.md#ga0e676460ec145b81bdb07a97a368a5f1)&nbsp;\*component,&nbsp;const&nbsp;void&nbsp;\*window,&nbsp;[OH_NativeXComponent_TouchEvent](_o_h___native_x_component___touch_event.md)&nbsp;\*touchEvent) | int32_t<br/>Obtains&nbsp;the&nbsp;touch&nbsp;event&nbsp;dispatched&nbsp;by&nbsp;the&nbsp;ArkUI&nbsp;XComponent. |
| [OH_NativeXComponent_RegisterCallback](_o_h___native_x_component.md#gaf9b8b470cd51ac0e339710926bca72e3)&nbsp;([OH_NativeXComponent](_o_h___native_x_component.md#ga0e676460ec145b81bdb07a97a368a5f1)&nbsp;\*component,&nbsp;[OH_NativeXComponent_Callback](_o_h___native_x_component___callback.md)&nbsp;\*callback) | int32_t<br/>Registers&nbsp;a&nbsp;callback&nbsp;for&nbsp;this&nbsp;**OH_NativeXComponent**&nbsp;instance. |
# raw_dir.h
## **Overview**
**Related Modules:**
[Rawfile](rawfile.md)
**Description:**
提供rawfile目录相关功能
功能包括遍历和关闭rawfile目录
**Since:**
8
**Version:**
1.0
## **Summary**
### Typedefs
| Typedef&nbsp;Name | Description |
| -------- | -------- |
| [RawDir](rawfile.md#ga654d75f2b4badf0dac10c4127a9938c3) | typedef&nbsp;struct&nbsp;[RawDir](rawfile.md#ga654d75f2b4badf0dac10c4127a9938c3)<br/>提供对rawfile目录的访问 |
### Functions
| Function | Description |
| -------- | -------- |
| [OH_ResourceManager_GetRawFileName](rawfile.md#gaf522ad160d8ca2bd476b6ad45696e1af)&nbsp;([RawDir](rawfile.md#ga654d75f2b4badf0dac10c4127a9938c3)&nbsp;\*rawDir,&nbsp;int&nbsp;index) | const&nbsp;char&nbsp;\*<br/>通过索引获取rawfile文件名称 |
| [OH_ResourceManager_GetRawFileCount](rawfile.md#ga604cd2ced1bf4a0d1ace7b0fc89cb884)&nbsp;([RawDir](rawfile.md#ga654d75f2b4badf0dac10c4127a9938c3)&nbsp;\*rawDir) | int<br/>获取[RawDir](rawfile.md#ga654d75f2b4badf0dac10c4127a9938c3)中的rawfile数量 |
| [OH_ResourceManager_CloseRawDir](rawfile.md#ga1db0825028507d355db4067f187223de)&nbsp;([RawDir](rawfile.md#ga654d75f2b4badf0dac10c4127a9938c3)&nbsp;\*rawDir) | void<br/>关闭已打开的[RawDir](rawfile.md#ga654d75f2b4badf0dac10c4127a9938c3)并释放所有相关联资源 |
# raw_file.h
## **Overview**
**Related Modules:**
[Rawfile](rawfile.md)
**Description:**
提供rawfile文件相关功能
功能包括搜索、读取和关闭rawfile文件
**Since:**
8
**Version:**
1.0
## **Summary**
### Classes
| Classe&nbsp;Name | Description |
| -------- | -------- |
| [RawFileDescriptor](_raw_file_descriptor.md) | 提供rawfile文件描述符信息 |
### Typedefs
| Typedef&nbsp;Name | Description |
| -------- | -------- |
| [RawFile](rawfile.md#gacf2dc23017812d7daf535b80f1a6ab27) | typedef&nbsp;struct&nbsp;[RawFile](rawfile.md#gacf2dc23017812d7daf535b80f1a6ab27)<br/>提供对rawfile的访问功能 |
### Functions
| Function | Description |
| -------- | -------- |
| [OH_ResourceManager_ReadRawFile](rawfile.md#ga2958ba7372ae1232365358115a82c219)&nbsp;(const&nbsp;[RawFile](rawfile.md#gacf2dc23017812d7daf535b80f1a6ab27)&nbsp;\*rawFile,&nbsp;void&nbsp;\*buf,&nbsp;size_t&nbsp;length) | int<br/>读取rawfile |
| [OH_ResourceManager_SeekRawFile](rawfile.md#ga7fc0d124fd184498b0a0bfad3454f45c)&nbsp;(const&nbsp;[RawFile](rawfile.md#gacf2dc23017812d7daf535b80f1a6ab27)&nbsp;\*rawFile,&nbsp;long&nbsp;offset,&nbsp;int&nbsp;whence) | int<br/>基于指定的offset,在rawfile文件内搜索读写数据的位置 |
| [OH_ResourceManager_GetRawFileSize](rawfile.md#gafcc6036360466ab5193b7b4eba5eae50)&nbsp;([RawFile](rawfile.md#gacf2dc23017812d7daf535b80f1a6ab27)&nbsp;\*rawFile) | long<br/>获取rawfile长度,单位为int32_t |
| [OH_ResourceManager_CloseRawFile](rawfile.md#ga5cccee53550670a2111705d56a1d427b)&nbsp;([RawFile](rawfile.md#gacf2dc23017812d7daf535b80f1a6ab27)&nbsp;\*rawFile) | void<br/>关闭已打开的[RawFile](rawfile.md#gacf2dc23017812d7daf535b80f1a6ab27)&nbsp;以及释放所有相关联资源 |
| [OH_ResourceManager_GetRawFileOffset](rawfile.md#ga57dc379d6df6b7c7f8e76303ad4957a4)&nbsp;(const&nbsp;[RawFile](rawfile.md#gacf2dc23017812d7daf535b80f1a6ab27)&nbsp;\*rawFile) | long<br/>获取rawfile当前的offset,单位为int32_t |
| [OH_ResourceManager_GetRawFileDescriptor](rawfile.md#ga8313a7d4bb361a98ced485346a9be4b1)&nbsp;(const&nbsp;[RawFile](rawfile.md#gacf2dc23017812d7daf535b80f1a6ab27)&nbsp;\*rawFile,&nbsp;[RawFileDescriptor](_raw_file_descriptor.md)&nbsp;&amp;descriptor) | bool<br/>基于offset(单位为int32_t)和文件长度打开rawfile,并获取rawfile文件描述符 |
| [OH_ResourceManager_ReleaseRawFileDescriptor](rawfile.md#gabf9db7f05088a11cc311a6ef890eda6b)&nbsp;(const&nbsp;[RawFileDescriptor](_raw_file_descriptor.md)&nbsp;&amp;descriptor) | bool<br/>关闭rawfile文件描述符 |
# Rawfile
## **Overview**
**Description:**
提供操作rawfile目录和rawfile文件的功能
提供操作rawfile目录和rawfile文件功能
功能包括遍历、打开、搜索、读取和关闭rawfile
**Since:**
8
**Version:**
1.0
## **Summary**
### Files
| File&nbsp;Name | Description |
| -------- | -------- |
| [raw_dir.h](raw__dir_8h.md) | 提供rawfile目录相关功能 |
| [raw_file.h](raw__file_8h.md) | 提供rawfile文件相关功能 |
### Classes
| Classe&nbsp;Name | Description |
| -------- | -------- |
| [RawFileDescriptor](_raw_file_descriptor.md) | 提供rawfile文件描述符信息 |
### Typedefs
| Typedef&nbsp;Name | Description |
| -------- | -------- |
| RawDir | typedef&nbsp;struct&nbsp;RawDir<br/>提供对rawfile目录的访问 |
| RawFile | typedef&nbsp;struct&nbsp;RawFile<br/>提供对rawfile的访问功能 |
| NativeResourceManager | typedef&nbsp;struct&nbsp;NativeResourceManager<br/>代表resource&nbsp;manager |
### Functions
| Function | Description |
| -------- | -------- |
| OH_ResourceManager_GetRawFileName&nbsp;(RawDir&nbsp;\*rawDir,&nbsp;int&nbsp;index) | const&nbsp;char&nbsp;\*<br/>通过索引获取rawfile文件名称 |
| OH_ResourceManager_GetRawFileCount&nbsp;(RawDir&nbsp;\*rawDir) | int<br/>获取RawDir中的rawfile数量 |
| OH_ResourceManager_CloseRawDir&nbsp;(RawDir&nbsp;\*rawDir) | void<br/>关闭已打开的RawDir并释放所有相关联资源 |
| OH_ResourceManager_ReadRawFile&nbsp;(const&nbsp;RawFile&nbsp;\*rawFile,&nbsp;void&nbsp;\*buf,&nbsp;size_t&nbsp;length) | int<br/>读取rawfile |
| OH_ResourceManager_SeekRawFile&nbsp;(const&nbsp;RawFile&nbsp;\*rawFile,&nbsp;long&nbsp;offset,&nbsp;int&nbsp;whence) | int<br/>基于指定的offset,在rawfile文件内搜索读写数据的位置 |
| OH_ResourceManager_GetRawFileSize&nbsp;(RawFile&nbsp;\*rawFile) | long<br/>获取rawfile长度,单位为int32_t |
| OH_ResourceManager_CloseRawFile&nbsp;(RawFile&nbsp;\*rawFile) | void<br/>关闭已打开的RawFile&nbsp;以及释放所有相关联资源 |
| OH_ResourceManager_GetRawFileOffset&nbsp;(const&nbsp;RawFile&nbsp;\*rawFile) | long<br/>获取rawfile当前的offset,单位为int32_t |
| OH_ResourceManager_GetRawFileDescriptor&nbsp;(const&nbsp;RawFile&nbsp;\*rawFile,&nbsp;RawFileDescriptor&nbsp;&amp;descriptor) | bool<br/>基于offset(单位为int32_t)和文件长度打开rawfile,并获取rawfile文件描述符 |
| OH_ResourceManager_ReleaseRawFileDescriptor&nbsp;(const&nbsp;RawFileDescriptor&nbsp;&amp;descriptor) | bool<br/>关闭rawfile文件描述符 |
| OH_ResourceManager_InitNativeResourceManager&nbsp;(napi_env&nbsp;env,&nbsp;napi_value&nbsp;jsResMgr) | NativeResourceManager&nbsp;\*<br/>基于JavaScipt&nbsp;resource&nbsp;manager获取native&nbsp;resource&nbsp;manager |
| OH_ResourceManager_ReleaseNativeResourceManager&nbsp;(NativeResourceManager&nbsp;\*resMgr) | void<br/>释放native&nbsp;resource&nbsp;manager |
| OH_ResourceManager_OpenRawDir&nbsp;(const&nbsp;NativeResourceManager&nbsp;\*mgr,&nbsp;const&nbsp;char&nbsp;\*dirName) | RawDir&nbsp;\*<br/>打开rawfile目录 |
| OH_ResourceManager_OpenRawFile&nbsp;(const&nbsp;NativeResourceManager&nbsp;\*mgr,&nbsp;const&nbsp;char&nbsp;\*fileName) | RawFile&nbsp;\*<br/>打开rawfile文件 |
## **Details**
## **Typedef**
### NativeResourceManager
```
typedef struct NativeResourceManager NativeResourceManager
```
**Description:**
代表resource manager
此类封装了JavaScript resource manager的native实现 **ResourceManager**指针可以通过调用OH_ResourceManager_InitNativeResourceManager方法获取
### RawDir
```
typedef struct RawDir RawDir
```
**Description:**
提供对rawfile目录的访问
### RawFile
```
typedef struct RawFile RawFile
```
**Description:**
提供对rawfile的访问功能
## **Function**
### OH_ResourceManager_CloseRawDir()
```
void OH_ResourceManager_CloseRawDir (RawDir * rawDir)
```
**Description:**
关闭已打开的RawDir并释放所有相关联资源
**Parameters:**
| Name | Description |
| -------- | -------- |
| rawDir | 表示指向RawDir的指针 |
**See also:**
OH_ResourceManager_OpenRawDir
### OH_ResourceManager_CloseRawFile()
```
void OH_ResourceManager_CloseRawFile (RawFile * rawFile)
```
**Description:**
关闭已打开的RawFile 以及释放所有相关联资源
**Parameters:**
| Name | Description |
| -------- | -------- |
| rawFile | 表示指向RawFile的指针 |
**See also:**
OH_ResourceManager_OpenRawFile
### OH_ResourceManager_GetRawFileCount()
```
int OH_ResourceManager_GetRawFileCount (RawDir * rawDir)
```
**Description:**
获取RawDir中的rawfile数量
通过此方法可以获取OH_ResourceManager_GetRawFileName中可用的索引
**Parameters:**
| Name | Description |
| -------- | -------- |
| rawDir | 表示指向RawDir的指针 |
**See also:**
OH_ResourceManager_GetRawFileName
### OH_ResourceManager_GetRawFileDescriptor()
```
bool OH_ResourceManager_GetRawFileDescriptor (const RawFile * rawFile, RawFileDescriptor & descriptor )
```
**Description:**
基于offset(单位为int32_t)和文件长度打开rawfile,并获取rawfile文件描述符
打开的文件描述符被用于读取rawfile
**Parameters:**
| Name | Description |
| -------- | -------- |
| rawFile | 表示指向RawFile的指针 |
| descriptor | 显示rawfile文件描述符,以及在HAP包中的起始位置和长度 |
**Returns:**
返回true表示打开rawfile文件描述符成功,返回false表示rawfile不允许被访问
### OH_ResourceManager_GetRawFileName()
```
const char* OH_ResourceManager_GetRawFileName (RawDir * rawDir, int index )
```
**Description:**
通过索引获取rawfile文件名称
可以使用此方法遍历rawfile目录
**Parameters:**
| Name | Description |
| -------- | -------- |
| rawDir | 表示指向RawDir的指针 |
| index | 表示文件在RawDir中的索引位置 |
**Returns:**
通过索引返回文件名称,此返回值可以作为OH_ResourceManager_OpenRawFile的输入参数, 如果遍历完所有文件仍未找到,则返回**NULL**
**See also:**
OH_ResourceManager_OpenRawFile
### OH_ResourceManager_GetRawFileOffset()
```
long OH_ResourceManager_GetRawFileOffset (const RawFile * rawFile)
```
**Description:**
获取rawfile当前的offset,单位为int32_t
rawfile当前的offset
**Parameters:**
| Name | Description |
| -------- | -------- |
| rawFile | 表示指向RawFile的指针 |
**Returns:**
返回rawfile当前的offset
### OH_ResourceManager_GetRawFileSize()
```
long OH_ResourceManager_GetRawFileSize (RawFile * rawFile)
```
**Description:**
获取rawfile长度,单位为int32_t
**Parameters:**
| Name | Description |
| -------- | -------- |
| rawFile | 表示指向RawFile的指针 |
**Returns:**
Returns rawfile整体长度
### OH_ResourceManager_InitNativeResourceManager()
```
NativeResourceManager* OH_ResourceManager_InitNativeResourceManager (napi_env env, napi_value jsResMgr )
```
**Description:**
基于JavaScipt resource manager获取native resource manager
通过获取resource manager来完成rawfile相关功能
**Parameters:**
| Name | Description |
| -------- | -------- |
| env | 表示JavaScipt&nbsp;Native&nbsp;Interface&nbsp;(napi)环境指针 |
| jsResMgr | 表示JavaScipt&nbsp;resource&nbsp;manager |
**Returns:**
返回NativeResourceManager指针
### OH_ResourceManager_OpenRawDir()
```
RawDir* OH_ResourceManager_OpenRawDir (const NativeResourceManager * mgr, const char * dirName )
```
**Description:**
打开rawfile目录
打开rawfile目录后,可以遍历对应目录下的rawfile文件
**Parameters:**
| Name | Description |
| -------- | -------- |
| mgr | 表示指向NativeResourceManager的指针,此指针是通过调用&nbsp;OH_ResourceManager_InitNativeResourceManager方法获取的 |
| dirName | 表示要打开的rawfile目录名称,当传递一个空字符串时表示打开rawfile根目录 |
**Returns:**
返回RawDir指针。使用完此指针后,调用OH_ResourceManager_CloseRawDir释放。
**See also:**
OH_ResourceManager_InitNativeResourceManager
OH_ResourceManager_CloseRawDir
### OH_ResourceManager_OpenRawFile()
```
RawFile* OH_ResourceManager_OpenRawFile (const NativeResourceManager * mgr, const char * fileName )
```
**Description:**
打开rawfile文件
当打开rawfile以后,可以读取它的数据
**Parameters:**
| Name | Description |
| -------- | -------- |
| mgr | 表示指向NativeResourceManager的指针,此指针是通过调用&nbsp;OH_ResourceManager_InitNativeResourceManager方法获取的 |
| fileName | 表示基于rawfile根目录的相对路径下的文件名称 |
**Returns:**
返回RawFile指针。当使用完此指针,调用OH_ResourceManager_CloseRawFile释放。
**See also:**
OH_ResourceManager_InitNativeResourceManager
OH_ResourceManager_CloseRawFile
### OH_ResourceManager_ReadRawFile()
```
int OH_ResourceManager_ReadRawFile (const RawFile * rawFile, void * buf, size_t length )
```
**Description:**
读取rawfile
从当前位置读取**指定长度**的数据
**Parameters:**
| Name | Description |
| -------- | -------- |
| rawFile | 表示指向RawFile的指针 |
| buf | 用于接收读取数据的缓冲区指针 |
| length | 读取数据的字节长度 |
**Returns:**
返回读取的字节数,如果读取长度超过文件末尾长度,则返回**0**
### OH_ResourceManager_ReleaseNativeResourceManager()
```
void OH_ResourceManager_ReleaseNativeResourceManager (NativeResourceManager * resMgr)
```
**Description:**
释放native resource manager
**Parameters:**
| Name | Description |
| -------- | -------- |
| resMgr | 表示NativeResourceManager指针 |
### OH_ResourceManager_ReleaseRawFileDescriptor()
```
bool OH_ResourceManager_ReleaseRawFileDescriptor (const RawFileDescriptor & descriptor)
```
**Description:**
关闭rawfile文件描述符
已打开的文件描述符在使用完以后必须释放,防止文件描述符泄露
**Parameters:**
| Name | Description |
| -------- | -------- |
| descriptor | 包含rawfile文件描述符,以及在HAP包中的起始位置和长度 |
**Returns:**
返回true表示关闭文件描述符成功,返回false表示关闭文件描述符失败
### OH_ResourceManager_SeekRawFile()
```
int OH_ResourceManager_SeekRawFile (const RawFile * rawFile, long offset, int whence )
```
**Description:**
基于指定的offset,在rawfile文件内搜索读写数据的位置
**Parameters:**
| Name | Description |
| -------- | -------- |
| rawFile | 表示指向RawFile的指针 |
| offset | 表示指定的offset |
| whence | 读写位置,有以下场景:&nbsp;**0**:&nbsp;读写位置为**offset1**:&nbsp;读写位置为当前位置加上**offset2**:&nbsp;读写位置为文件末尾(EOF)加上**offset** |
**Returns:**
如果搜索成功返回新的读写位置,如果发生错误返回 **(long) -1**
# 头文件和结构体
- **[头文件](files.md)**
- **[结构体](annotated.md)**
\ No newline at end of file
# OpenHarmony应用开发文档
- [应用开发导读](application-dev-guide.md)
- 快速开始
- 快速入门
......@@ -10,9 +11,10 @@
- [使用JS语言开发(低代码方式)](quick-start/start-with-js-low-code.md)
- 开发基础知识
- [应用包结构说明(FA模型)](quick-start/package-structure.md)
- [应用包结构说明(Stage模型)](quick-start/module-structure.md)
- [应用包结构说明(Stage模型)](quick-start/stage-structure.md)
- [资源文件的分类](quick-start/basic-resource-file-categories.md)
- [SysCap说明](quick-start/syscap.md)
- 开发
- Ability开发
......@@ -34,6 +36,7 @@
- [WantAgent开发指导](ability/wantagent.md)
- [Ability助手使用指导](ability/ability-assistant-guidelines.md)
- [测试框架使用指导](ability/ability-delegator.md)
- UI开发
- [方舟开发框架(ArkUI)概述](ui/arkui-overview.md)
- 基于JS扩展的类Web开发范式
......@@ -179,6 +182,7 @@
- [构建食物列表List布局](ui/ui-ts-building-category-list-layout.md)
- [构建食物分类Grid布局](ui/ui-ts-building-category-grid-layout.md)
- [页面跳转与数据传递](ui/ui-ts-page-redirection-data-transmission.md)
- 基础功能开发
- 公共事件与通知
- [公共事件与通知概述](notification/notification-brief.md)
......@@ -188,6 +192,7 @@
- [通知开发指导](notification/notification.md)
- 调试工具
- [调试助手使用指导](notification/assistant-guidelines.md)
- 窗口管理
- 窗口
- [窗口开发概述](windowmanager/window-overview.md)
......@@ -198,9 +203,11 @@
- 屏幕截图
- [屏幕截图开发概述](windowmanager/screenshot-overview.md)
- [屏幕截图开发指导](windowmanager/screenshot-guidelines.md)
- WebGL
- [WebGL开发概述](webgl/webgl-overview.md)
- [WebGL开发指导](webgl/webgl-guidelines.md)
- 媒体
- 音频
- [音频开发概述](media/audio-overview.md)
......@@ -213,6 +220,7 @@
- [视频录制开发指导](media/video-recorder.md)
- 图片
- [图片开发指导](media/image.md)
- 安全
- 用户认证
- [用户认证开发概述](security/userauth-overview.md)
......@@ -225,11 +233,13 @@
- 访问控制
- [访问控制开发概述](security/accesstoken-overview.md)
- [访问控制开发指导](security/accesstoken-guidelines.md)
- 网络与连接
- IPC与RPC通信
- [IPC与RPC通信概述](connectivity/ipc-rpc-overview.md)
- [IPC与RPC通信开发指导](connectivity/ipc-rpc-development-guideline.md)
- [远端状态订阅开发实例](connectivity/subscribe-remote-state.md)
- 数据管理
- 分布式数据服务
- [分布式数据服务概述](database/database-mdds-overview.md)
......@@ -243,15 +253,19 @@
- 分布式数据对象
- [分布式数据对象概述](database/database-distributedobject-overview.md)
- [分布式数据对象开发指导](database/database-distributedobject-guidelines.md)
- 后台代理提醒
- [后台代理提醒概述](background-agent-scheduled-reminder/background-agent-scheduled-reminder-overview.md)
- [后台代理提醒开发指导](background-agent-scheduled-reminder/background-agent-scheduled-reminder-guide.md)
- 后台任务管理
- [后台任务概述](background-task-management/background-task-overview.md)
- [后台任务开发指导](background-task-management/background-task-dev-guide.md)
- 延迟任务调度
- [延迟任务调度概述](work-scheduler/work-scheduler-overview.md)
- [延迟任务调度开发指导](work-scheduler/work-scheduler-dev-guide.md)
- 设备管理
- USB服务
- [USB服务开发概述](device/usb-overview.md)
......@@ -266,9 +280,11 @@
- 振动
- [振动开发概述](device/vibrator-overview.md)
- [振动开发指导](device/vibrator-guidelines.md)
- 设备使用信息统计
- [设备使用信息统计概述](device-usage-statistics/device-usage-statistics-overview.md)
- [设备使用信息统计开发指导](device-usage-statistics/device-usage-statistics-dev-guide.md)
- DFX
- 应用事件打点
- [应用事件打点概述](dfx/hiappevent-overview.md)
......@@ -279,15 +295,28 @@
- 分布式跟踪
- [分布式跟踪概述](dfx/hitracechain-overview.md)
- [分布式跟踪开发指导](dfx/hitracechain-guidelines.md)
- 国际化
- [国际化开发概述](internationalization/international-overview.md)
- [Intl开发指导](internationalization/intl-guidelines.md)
- [I18n开发指导](internationalization/i18n-guidelines.md)
- Native API的相关指导
- [Native API在应用工程中的使用指导](napi/napi-guidelines.md)
- [drawing开发指导](napi/drawing-guidelines.md)
- [rawfile开发指导](napi/rawfile-guidelines.md)
- 工具
- [DevEco Studio(OpenHarmony)使用指南](quick-start/deveco-studio-user-guide-for-openharmony.md)
- 示例教程
- [示例代码](https://gitee.com/openharmony/app_samples/blob/master/README_zh.md)
- [Codelabs](https://gitee.com/openharmony/codelabs/blob/master/README.md)
- API参考
- 组件参考(基于JS扩展的类Web开发范式)
- 组件
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册