diff --git a/ArkUIKit/StyledStringSample/.gitignore b/ArkUIKit/StyledStringSample/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/ArkUIKit/StyledStringSample/.gitignore @@ -0,0 +1,12 @@ +/node_modules +/oh_modules +/local.properties +/.idea +**/build +/.hvigor +.cxx +/.clangd +/.clang-format +/.clang-tidy +**/.test +/.appanalyzer \ No newline at end of file diff --git a/ArkUIKit/StyledStringSample/AppScope/app.json5 b/ArkUIKit/StyledStringSample/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..6ccaa10146c0a73ea73ab2f0b8e8c4d3fd4610fb --- /dev/null +++ b/ArkUIKit/StyledStringSample/AppScope/app.json5 @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "app": { + "bundleName": "com.example.styledstringndk", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:layered_image", + "label": "$string:app_name" + } +} diff --git a/ArkUIKit/StyledStringSample/AppScope/resources/base/element/string.json b/ArkUIKit/StyledStringSample/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..0edf05d24f2ca0e69a966f00825600f3d9474df8 --- /dev/null +++ b/ArkUIKit/StyledStringSample/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "StyledStringNDK" + } + ] +} diff --git a/ArkUIKit/StyledStringSample/AppScope/resources/base/media/background.png b/ArkUIKit/StyledStringSample/AppScope/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/ArkUIKit/StyledStringSample/AppScope/resources/base/media/background.png differ diff --git a/ArkUIKit/StyledStringSample/AppScope/resources/base/media/foreground.png b/ArkUIKit/StyledStringSample/AppScope/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..eb9427585b36d14b12477435b6419d1f07b3e0bb Binary files /dev/null and b/ArkUIKit/StyledStringSample/AppScope/resources/base/media/foreground.png differ diff --git a/ArkUIKit/StyledStringSample/AppScope/resources/base/media/layered_image.json b/ArkUIKit/StyledStringSample/AppScope/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/ArkUIKit/StyledStringSample/AppScope/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/ArkUIKit/StyledStringSample/README.md b/ArkUIKit/StyledStringSample/README.md new file mode 100644 index 0000000000000000000000000000000000000000..25d7c5374f59bc60647d7595a769e497c199dad2 --- /dev/null +++ b/ArkUIKit/StyledStringSample/README.md @@ -0,0 +1,70 @@ +# StyledStringSample + +## 介绍 + +本示例展示了如何创建文本、设置文本样式、序列化、反序列化、转换html。 + +## 效果预览 + +| 预览 | +| -------------------------------------------- | + + +## 使用说明 +1. 安装编译生成的hap包,并打开应用; +2. 查看创建好的文本以及相应的文本样式; +3. 查看log是否序列化成功; + + +## 工程目录 + +``` +StyledStringNDK +entry/src/main/ets/ +└── pages + └── Index.ets (获取文本界面) +entry/src/main/ +├── cpp +│ ├── types +│ │ └── libentry +│ │ └── Index.d.ts (函数对应的js映射) +│ ├── CMakeLists.txt (CMake脚本) +| ├── manager.cpp (创建文本实现CPP文件) +| ├── manager.h +│ └── napi_init.cpp +└── resources + ├── base + │ ├── element + │ │ ├── color.json + │ │ ├── float.json + │ │ └── string.json + │ └── media +``` + +## 相关权限 + +不涉及 + +## 依赖 + +不涉及 + +## 约束和限制 + +1. 本示例支持标准系统上运行,支持设备:RK3568; + +2. 本示例支持API20版本SDK,版本号:6.0.0.36; + +3. 本示例已支持使DevEco Studio 5.1.1 Release (构建版本:5.1.1.840,构建 2025年9月19日)编译运行 + +## 下载 + +如需单独下载本工程,执行如下命令: + +``` +git init +git config core.sparsecheckout true +echo code/DocsSample/ArkUISample/StyledStringSample > .git/info/sparse-checkout +git remote add origin https://gitcode.com/openharmony/applications_app_samples.git +git pull origin master +``` \ No newline at end of file diff --git a/ArkUIKit/StyledStringSample/build-profile.json5 b/ArkUIKit/StyledStringSample/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..2852ab51c4bcc73fd1de68f85df87af663be73c1 --- /dev/null +++ b/ArkUIKit/StyledStringSample/build-profile.json5 @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "app": { + "products": [ + { + "name": "default", + "signingConfig": "default", + "targetSdkVersion": 20, + "compatibleSdkVersion": 20, + "compileSdkVersion": 20, + "runtimeOS": "OpenHarmony", + "buildOption": { + "nativeCompiler": "BiSheng", + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/ArkUIKit/StyledStringSample/code-linter.json5 b/ArkUIKit/StyledStringSample/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..5c4682f8164874ec7e9cb8f99ff8b3228ffbc126 --- /dev/null +++ b/ArkUIKit/StyledStringSample/code-linter.json5 @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "files": [ + "**/*.ets" + ], + "ignore": [ + "**/src/ohosTest/**/*", + "**/src/test/**/*", + "**/src/mock/**/*", + "**/node_modules/**/*", + "**/oh_modules/**/*", + "**/build/**/*", + "**/.preview/**/*" + ], + "ruleSet": [ + "plugin:@performance/recommended", + "plugin:@typescript-eslint/recommended" + ], + "rules": { + "@security/no-unsafe-aes": "error", + "@security/no-unsafe-hash": "error", + "@security/no-unsafe-mac": "warn", + "@security/no-unsafe-dh": "error", + "@security/no-unsafe-dsa": "error", + "@security/no-unsafe-ecdsa": "error", + "@security/no-unsafe-rsa-encrypt": "error", + "@security/no-unsafe-rsa-sign": "error", + "@security/no-unsafe-rsa-key": "error", + "@security/no-unsafe-dsa-key": "error", + "@security/no-unsafe-dh-key": "error", + "@security/no-unsafe-3des": "error" + } +} \ No newline at end of file diff --git a/ArkUIKit/StyledStringSample/entry/.gitignore b/ArkUIKit/StyledStringSample/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/ArkUIKit/StyledStringSample/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/ArkUIKit/StyledStringSample/entry/build-profile.json5 b/ArkUIKit/StyledStringSample/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4a558049e517c706a7378a108b6646fe21b96ac7 --- /dev/null +++ b/ArkUIKit/StyledStringSample/entry/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + "abiFilters": ["arm64-v8a","armeabi-v7a","x86_64"] + } + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + }, + "nativeLib": { + "debugSymbol": { + "strip": true, + "exclude": [] + } + } + }, + ], + "targets": [ + { + "name": "default", + }, + { + "name": "ohosTest" + } + ] +} \ No newline at end of file diff --git a/ArkUIKit/StyledStringSample/entry/hvigorfile.ts b/ArkUIKit/StyledStringSample/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..f8b117a17af3b2d7cb87a7680e29e2bb8ccd5b46 --- /dev/null +++ b/ArkUIKit/StyledStringSample/entry/hvigorfile.ts @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { hapTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins: [] /* Custom plugin to extend the functionality of Hvigor. */ +} \ No newline at end of file diff --git a/ArkUIKit/StyledStringSample/entry/obfuscation-rules.txt b/ArkUIKit/StyledStringSample/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/ArkUIKit/StyledStringSample/entry/obfuscation-rules.txt @@ -0,0 +1,23 @@ +# Define project specific obfuscation rules here. +# You can include the obfuscation configuration files in the current module's build-profile.json5. +# +# For more details, see +# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5 + +# Obfuscation options: +# -disable-obfuscation: disable all obfuscations +# -enable-property-obfuscation: obfuscate the property names +# -enable-toplevel-obfuscation: obfuscate the names in the global scope +# -compact: remove unnecessary blank spaces and all line feeds +# -remove-log: remove all console.* statements +# -print-namecache: print the name cache that contains the mapping from the old names to new names +# -apply-namecache: reuse the given cache file + +# Keep options: +# -keep-property-name: specifies property names that you want to keep +# -keep-global-name: specifies names that you want to keep in the global scope + +-enable-property-obfuscation +-enable-toplevel-obfuscation +-enable-filename-obfuscation +-enable-export-obfuscation \ No newline at end of file diff --git a/ArkUIKit/StyledStringSample/entry/oh-package-lock.json5 b/ArkUIKit/StyledStringSample/entry/oh-package-lock.json5 new file mode 100644 index 0000000000000000000000000000000000000000..7c36300c3272430b97f5cda7cb1a835421298382 --- /dev/null +++ b/ArkUIKit/StyledStringSample/entry/oh-package-lock.json5 @@ -0,0 +1,19 @@ +{ + "meta": { + "stableOrder": true, + "enableUnifiedLockfile": false + }, + "lockfileVersion": 3, + "ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.", + "specifiers": { + "libentry.so@src/main/cpp/types/libentry": "libentry.so@src/main/cpp/types/libentry" + }, + "packages": { + "libentry.so@src/main/cpp/types/libentry": { + "name": "libentry.so", + "version": "1.0.0", + "resolved": "src/main/cpp/types/libentry", + "registryType": "local" + } + } +} \ No newline at end of file diff --git a/ArkUIKit/StyledStringSample/entry/oh-package.json5 b/ArkUIKit/StyledStringSample/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..5b21e253af246edab8b6ef4f10938f4417e8bc25 --- /dev/null +++ b/ArkUIKit/StyledStringSample/entry/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libentry.so": "file:./src/main/cpp/types/libentry" + } +} \ No newline at end of file diff --git a/ArkUIKit/StyledStringSample/entry/src/main/cpp/CMakeLists.txt b/ArkUIKit/StyledStringSample/entry/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..561706bbd6da1cc6e9f797531413d3588a04cac3 --- /dev/null +++ b/ArkUIKit/StyledStringSample/entry/src/main/cpp/CMakeLists.txt @@ -0,0 +1,20 @@ +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.5.0) +project(CApi2) + +set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}) + +if(DEFINED PACKAGE_FIND_FILE) + include(${PACKAGE_FIND_FILE}) +endif() + +include_directories(${NATIVERENDER_ROOT_PATH} + ${NATIVERENDER_ROOT_PATH}/include) + +find_library( + libace-lib + ace_ndk.z +) + +add_library(entry SHARED napi_init.cpp manager.cpp) +target_link_libraries(entry PUBLIC ${libace-lib} libace_napi.z.so libnative_drawing.so libhilog_ndk.z.so) \ No newline at end of file diff --git a/ArkUIKit/StyledStringSample/entry/src/main/cpp/manager.cpp b/ArkUIKit/StyledStringSample/entry/src/main/cpp/manager.cpp new file mode 100644 index 0000000000000000000000000000000000000000..050ff9aa6d0548cfc3c3444b872e3d5eff60a59b --- /dev/null +++ b/ArkUIKit/StyledStringSample/entry/src/main/cpp/manager.cpp @@ -0,0 +1,185 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "manager.h" +#include +#include +#include +#include +#include +#include +#include + +#define LOG_TAG "manager" +#define LOG_ERROR(...) OH_LOG_Print(LOG_APP, LOG_ERROR, 0xD001400, LOG_TAG, __VA_ARGS__) + +namespace NativeNode::Manager { +constexpr int32_t MAX_LINES = 10; // 最大行数 +constexpr int32_t FONT_SIZE = 28; // 字体大小 +constexpr int32_t LAYOUT_MAX_WIDTH = 400; // 排版最大宽度 +constexpr int32_t CONTAINER_WIDTH = 300; // 容器宽度 +constexpr int32_t TEXT_HEIGHT = 100; // 文本组件高度 +constexpr float BORDER_WIDTH = 1.0f; // 边框宽度 +constexpr int32_t PLACEHOLDER_WIDTH = 100; // 占位符宽度 +constexpr int32_t PLACEHOLDER_HEIGHT = 100; // 占位符高度 +constexpr size_t SERIALIZE_BUFFER_SIZE = 1024; // 序列化缓冲区大小 +constexpr uint32_t TEXT_COLOR_GRAY = 0xFF707070; // 第一段文本颜色(灰色) +constexpr uint32_t TEXT_COLOR_BLUE = 0xFF2787D9; // 第二段文本颜色(蓝色) + +// 创建Column容器 +static ArkUI_NodeHandle CreateColumnContainer(ArkUI_NativeNodeAPI_1 *nodeApi) +{ + ArkUI_NodeHandle column = nodeApi->createNode(ARKUI_NODE_COLUMN); + ArkUI_NumberValue colWidth[] = {{.f32 = CONTAINER_WIDTH}}; + ArkUI_AttributeItem widthItem = {.value = colWidth, .size = 1}; + nodeApi->setAttribute(column, NODE_WIDTH, &widthItem); + return column; +} + +// 创建带样式的Text组件 +static ArkUI_NodeHandle CreateStyledText(ArkUI_NativeNodeAPI_1 *nodeApi) +{ + ArkUI_NodeHandle text = nodeApi->createNode(ARKUI_NODE_TEXT); + + // 设置文本宽度 + ArkUI_NumberValue textWidth[] = {{.f32 = CONTAINER_WIDTH}}; + ArkUI_AttributeItem textWidthItem = {.value = textWidth, .size = 1}; + nodeApi->setAttribute(text, NODE_WIDTH, &textWidthItem); + + // 设置文本高度 + ArkUI_NumberValue textHeight[] = {{.f32 = TEXT_HEIGHT}}; + ArkUI_AttributeItem textHeightItem = {.value = textHeight, .size = 1}; + nodeApi->setAttribute(text, NODE_HEIGHT, &textHeightItem); + + // 设置边框宽度 + ArkUI_NumberValue borderWidth[] = {{.f32 = BORDER_WIDTH}}; + ArkUI_AttributeItem borderWidthItem = {.value = borderWidth, .size = 1}; + nodeApi->setAttribute(text, NODE_BORDER_WIDTH, &borderWidthItem); + + return text; +} + +// 处理StyledString的序列化、反序列化与HTML转换 +static void HandleStyledStringSerialize(ArkUI_StyledString *styledString) +{ + // 1. 序列化 + ArkUI_StyledString_Descriptor *descriptor = OH_ArkUI_StyledString_Descriptor_Create(); + uint8_t buffer[SERIALIZE_BUFFER_SIZE] = {0}; + size_t resultSize = 0; + int32_t marshalResult = + OH_ArkUI_MarshallStyledStringDescriptor(buffer, SERIALIZE_BUFFER_SIZE, descriptor, &resultSize); + if (marshalResult != ARKUI_ERROR_CODE_NO_ERROR) { + OH_LOG_Print(LOG_APP, LOG_ERROR, 0xFF00, "manager", "序列化成功%{public}d", marshalResult); + } else if (marshalResult == ARKUI_ERROR_CODE_PARAM_INVALID) { + OH_LOG_Print(LOG_APP, LOG_ERROR, 0xFF00, "manager", "无效字符串"); + } else { + OH_LOG_Print(LOG_APP, LOG_ERROR, 0xFF00, "manager", "%{public}d", marshalResult); + } + OH_ArkUI_StyledString_Descriptor_Destroy(descriptor); + + // 2. 反序列化 + ArkUI_StyledString_Descriptor *unmarshalDescriptor = OH_ArkUI_StyledString_Descriptor_Create(); + if (unmarshalDescriptor != nullptr) { + int32_t unmarshalResult = + OH_ArkUI_UnmarshallStyledStringDescriptor(buffer, SERIALIZE_BUFFER_SIZE, unmarshalDescriptor); + if (unmarshalResult == ARKUI_ERROR_CODE_NO_ERROR) { + OH_LOG_Print(LOG_APP, LOG_ERROR, 0xFF00, "manager", "反序列化成功%{public}d", unmarshalResult); + } else if (unmarshalResult == ARKUI_ERROR_CODE_PARAM_ERROR) { + OH_LOG_Print(LOG_APP, LOG_ERROR, 0xFF00, "manager", "函数参数异常%{public}d", unmarshalResult); + } + + // 3. 转换为HTML + const char *htmlContent = OH_ArkUI_ConvertToHtml(unmarshalDescriptor); + OH_LOG_Print(LOG_APP, LOG_ERROR, 0xFF00, "manager", "%{public}s", htmlContent); + OH_ArkUI_StyledString_Descriptor_Destroy(unmarshalDescriptor); + } +} + +void NodeManager::CreateNativeNode() +{ + if (!xComponent_) { + return; + } + + // 获取NodeAPI接口 + ArkUI_NativeNodeAPI_1 *nodeApi = reinterpret_cast( + OH_ArkUI_QueryModuleInterfaceByName(ARKUI_NATIVE_NODE, "ArkUI_NativeNodeAPI_1")); + if (nodeApi == nullptr) { + return; + } + + // 创建容器与文本组件 + ArkUI_NodeHandle column = CreateColumnContainer(nodeApi); + ArkUI_NodeHandle text = CreateStyledText(nodeApi); + + // 创建字体集合与段落样式 + OH_Drawing_FontCollection *fontCollection = OH_Drawing_CreateFontCollection(); + OH_Drawing_TypographyStyle *typographyStyle = OH_Drawing_CreateTypographyStyle(); + OH_Drawing_SetTypographyTextAlign(typographyStyle, OH_Drawing_TextAlign::TEXT_ALIGN_CENTER); + OH_Drawing_SetTypographyTextMaxLines(typographyStyle, MAX_LINES); + + // 创建StyledString并设置文本内容 + ArkUI_StyledString *styledString = OH_ArkUI_StyledString_Create(typographyStyle, fontCollection); + + // 第一段文本(灰色"Hello") + OH_Drawing_TextStyle *textStyle = OH_Drawing_CreateTextStyle(); + OH_Drawing_SetTextStyleFontSize(textStyle, FONT_SIZE); + OH_Drawing_SetTextStyleColor(textStyle, TEXT_COLOR_GRAY); + OH_ArkUI_StyledString_PushTextStyle(styledString, textStyle); + OH_ArkUI_StyledString_AddText(styledString, "Hello"); + OH_ArkUI_StyledString_PopTextStyle(styledString); + OH_Drawing_DestroyTextStyle(textStyle); + + // 添加占位符 + OH_Drawing_PlaceholderSpan placeHolder{.width = PLACEHOLDER_WIDTH, .height = PLACEHOLDER_HEIGHT}; + OH_ArkUI_StyledString_AddPlaceholder(styledString, &placeHolder); + + // 第二段文本(蓝色"World!") + OH_Drawing_TextStyle *worldTextStyle = OH_Drawing_CreateTextStyle(); + OH_Drawing_SetTextStyleFontSize(worldTextStyle, FONT_SIZE); + OH_Drawing_SetTextStyleColor(worldTextStyle, TEXT_COLOR_BLUE); + OH_ArkUI_StyledString_PushTextStyle(styledString, worldTextStyle); + OH_ArkUI_StyledString_AddText(styledString, "World!"); + OH_ArkUI_StyledString_PopTextStyle(styledString); + OH_Drawing_DestroyTextStyle(worldTextStyle); + + // 处理序列化、反序列化与HTML转换 + HandleStyledStringSerialize(styledString); + + // 排版与设置属性 + OH_Drawing_Typography *typography = OH_ArkUI_StyledString_CreateTypography(styledString); + OH_Drawing_TypographyLayout(typography, LAYOUT_MAX_WIDTH); + ArkUI_AttributeItem styledStringItem = {.object = styledString}; + nodeApi->setAttribute(text, NODE_TEXT_CONTENT_WITH_STYLED_STRING, &styledStringItem); + + // 组装与释放资源 + nodeApi->addChild(column, text); + OH_ArkUI_StyledString_Destroy(styledString); + OH_Drawing_DestroyTypographyStyle(typographyStyle); + OH_Drawing_DestroyFontCollection(fontCollection); + OH_NativeXComponent_AttachNativeRootNode(xComponent_, column); +} + +// 单例与XComponent设置 +NodeManager &NodeManager::GetInstance() +{ + static NodeManager instance; + return instance; +} + +void NodeManager::SetXComponent(OH_NativeXComponent *xComponent) +{ + xComponent_ = xComponent; +} +} // namespace NativeNode::Manager \ No newline at end of file diff --git a/ArkUIKit/StyledStringSample/entry/src/main/cpp/manager.h b/ArkUIKit/StyledStringSample/entry/src/main/cpp/manager.h new file mode 100644 index 0000000000000000000000000000000000000000..ec67c3bfff967de3f71b394942d43a194f621db6 --- /dev/null +++ b/ArkUIKit/StyledStringSample/entry/src/main/cpp/manager.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef CAPI_MANAGER_H +#define CAPI_MANAGER_H + +#include +#include +#include +#include + +namespace NativeNode::Manager { +using EventCallback = std::function; + +class NodeManager { +public: + ~NodeManager() = default; + static NodeManager& GetInstance(); + void SetXComponent(OH_NativeXComponent* xComponent); + void CreateNativeNode(); +private: + NodeManager() = default; + OH_NativeXComponent* xComponent_; + std::unordered_map callbackMap_; +}; +} +#endif //CAPI_MANAGER_H \ No newline at end of file diff --git a/ArkUIKit/StyledStringSample/entry/src/main/cpp/napi_init.cpp b/ArkUIKit/StyledStringSample/entry/src/main/cpp/napi_init.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7435be4951c65dc734686ed1b73a3c62003fc31d --- /dev/null +++ b/ArkUIKit/StyledStringSample/entry/src/main/cpp/napi_init.cpp @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "manager.h" +#include +#include + +static OH_NativeXComponent* GetXComponent(napi_env env, napi_value exports) +{ + if ((env == nullptr) || (exports == nullptr)) { + return nullptr; + } + napi_value exportInstance = nullptr; + if (napi_get_named_property(env, exports, OH_NATIVE_XCOMPONENT_OBJ, &exportInstance) != napi_ok) { + return nullptr; + } + OH_NativeXComponent* xComp = nullptr; + if (napi_unwrap(env, exportInstance, reinterpret_cast(&xComp)) != napi_ok) { + return nullptr; + } + return xComp; +} + +static napi_value createNativeNode(napi_env env, napi_callback_info info) +{ + NativeNode::Manager::NodeManager::GetInstance().CreateNativeNode(); + return nullptr; +} + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + { "createNativeNode", nullptr, createNativeNode, nullptr, nullptr, nullptr, napi_default, nullptr } + }; + napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc); + auto xComponent = GetXComponent(env, exports); + if (xComponent) { + NativeNode::Manager::NodeManager::GetInstance().SetXComponent(xComponent); + } + return exports; +} +EXTERN_C_END + +static napi_module demoModule = { + .nm_version = 1, + .nm_flags = 0, + .nm_filename = nullptr, + .nm_register_func = Init, + .nm_modname = "entry", + .nm_priv = ((void*)0), + .reserved = { 0 }, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) +{ + napi_module_register(&demoModule); +} \ No newline at end of file diff --git a/ArkUIKit/StyledStringSample/entry/src/main/cpp/types/libentry/Index.d.ts b/ArkUIKit/StyledStringSample/entry/src/main/cpp/types/libentry/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..c09127fac743a5190aedf27d6e07056b20076bbd --- /dev/null +++ b/ArkUIKit/StyledStringSample/entry/src/main/cpp/types/libentry/Index.d.ts @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +export const createNativeNode: () => void; \ No newline at end of file diff --git a/ArkUIKit/StyledStringSample/entry/src/main/cpp/types/libentry/oh-package.json5 b/ArkUIKit/StyledStringSample/entry/src/main/cpp/types/libentry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..77052c679533e45a066030a9fc21cdbf9cbcf995 --- /dev/null +++ b/ArkUIKit/StyledStringSample/entry/src/main/cpp/types/libentry/oh-package.json5 @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "name": "libentry.so", + "types": "./Index.d.ts", + "version": "1.0.0", + "description": "Please describe the basic information." +} \ No newline at end of file diff --git a/ArkUIKit/StyledStringSample/entry/src/main/ets/entryability/EntryAbility.ets b/ArkUIKit/StyledStringSample/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..843c7f0c1f7b9a460e3dbbd2689e5b34016027d1 --- /dev/null +++ b/ArkUIKit/StyledStringSample/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +const DOMAIN = 0x0000; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(DOMAIN, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err)); + return; + } + hilog.info(DOMAIN, 'testTag', 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onBackground'); + } +} \ No newline at end of file diff --git a/ArkUIKit/StyledStringSample/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/ArkUIKit/StyledStringSample/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..4ce6449f0e91914e73d4502c9f2e8e9a395ea4b1 --- /dev/null +++ b/ArkUIKit/StyledStringSample/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit'; + +const DOMAIN = 0x0000; + +export default class EntryBackupAbility extends BackupExtensionAbility { + async onBackup() { + hilog.info(DOMAIN, 'testTag', 'onBackup ok'); + await Promise.resolve(); + } + + async onRestore(bundleVersion: BundleVersion) { + hilog.info(DOMAIN, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion)); + await Promise.resolve(); + } +} \ No newline at end of file diff --git a/ArkUIKit/StyledStringSample/entry/src/main/ets/pages/Index.ets b/ArkUIKit/StyledStringSample/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..5f10ce0e02428ec6c03f84b80a1a73230142699d --- /dev/null +++ b/ArkUIKit/StyledStringSample/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import testNapi from 'libentry.so'; + +@Entry +@Component +struct Index { + + build() { + Row() { + Column() { + XComponent({ + id: "xComponent", + type: XComponentType.NODE, + libraryname: "entry" + }).onAppear(()=> { + testNapi.createNativeNode() + }) + } + .width('100%') + } + .height('100%') + } +} \ No newline at end of file diff --git a/ArkUIKit/StyledStringSample/entry/src/main/module.json5 b/ArkUIKit/StyledStringSample/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c00933eb7488794b498319cbba6ae595ee963a4a --- /dev/null +++ b/ArkUIKit/StyledStringSample/entry/src/main/module.json5 @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "default" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:layered_image", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "ohos.want.action.home" + ] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "EntryBackupAbility", + "srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets", + "type": "backup", + "exported": false, + "metadata": [ + { + "name": "ohos.extension.backup", + "resource": "$profile:backup_config" + } + ] + } + ] + } +} \ No newline at end of file diff --git a/ArkUIKit/StyledStringSample/entry/src/main/resources/base/element/color.json b/ArkUIKit/StyledStringSample/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/ArkUIKit/StyledStringSample/entry/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/ArkUIKit/StyledStringSample/entry/src/main/resources/base/element/float.json b/ArkUIKit/StyledStringSample/entry/src/main/resources/base/element/float.json new file mode 100644 index 0000000000000000000000000000000000000000..33ea22304f9b1485b5f22d811023701b5d4e35b6 --- /dev/null +++ b/ArkUIKit/StyledStringSample/entry/src/main/resources/base/element/float.json @@ -0,0 +1,8 @@ +{ + "float": [ + { + "name": "page_text_font_size", + "value": "50fp" + } + ] +} diff --git a/ArkUIKit/StyledStringSample/entry/src/main/resources/base/element/string.json b/ArkUIKit/StyledStringSample/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..f94595515a99e0c828807e243494f57f09251930 --- /dev/null +++ b/ArkUIKit/StyledStringSample/entry/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "label" + } + ] +} \ No newline at end of file diff --git a/ArkUIKit/StyledStringSample/entry/src/main/resources/base/media/background.png b/ArkUIKit/StyledStringSample/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/ArkUIKit/StyledStringSample/entry/src/main/resources/base/media/background.png differ diff --git a/ArkUIKit/StyledStringSample/entry/src/main/resources/base/media/foreground.png b/ArkUIKit/StyledStringSample/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/ArkUIKit/StyledStringSample/entry/src/main/resources/base/media/foreground.png differ diff --git a/ArkUIKit/StyledStringSample/entry/src/main/resources/base/media/layered_image.json b/ArkUIKit/StyledStringSample/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/ArkUIKit/StyledStringSample/entry/src/main/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/ArkUIKit/StyledStringSample/entry/src/main/resources/base/media/startIcon.png b/ArkUIKit/StyledStringSample/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/ArkUIKit/StyledStringSample/entry/src/main/resources/base/media/startIcon.png differ diff --git a/ArkUIKit/StyledStringSample/entry/src/main/resources/base/profile/backup_config.json b/ArkUIKit/StyledStringSample/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/ArkUIKit/StyledStringSample/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/ArkUIKit/StyledStringSample/entry/src/main/resources/base/profile/main_pages.json b/ArkUIKit/StyledStringSample/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/ArkUIKit/StyledStringSample/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/ArkUIKit/StyledStringSample/entry/src/main/resources/dark/element/color.json b/ArkUIKit/StyledStringSample/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/ArkUIKit/StyledStringSample/entry/src/main/resources/dark/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] +} \ No newline at end of file diff --git a/ArkUIKit/StyledStringSample/entry/src/mock/Libentry.mock.ets b/ArkUIKit/StyledStringSample/entry/src/mock/Libentry.mock.ets new file mode 100644 index 0000000000000000000000000000000000000000..82fa70b5693ddab96d237d2d17d943d866b61465 --- /dev/null +++ b/ArkUIKit/StyledStringSample/entry/src/mock/Libentry.mock.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +const NativeMock: Record = { + 'add': (a: number, b: number) => { + return a + b; + }, +}; + +export default NativeMock; \ No newline at end of file diff --git a/ArkUIKit/StyledStringSample/entry/src/mock/mock-config.json5 b/ArkUIKit/StyledStringSample/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..98b0ae79f0090e1fc381d54c959fb32c9f7563f4 --- /dev/null +++ b/ArkUIKit/StyledStringSample/entry/src/mock/mock-config.json5 @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "libentry.so": { + "source": "src/mock/Libentry.mock.ets" + } +} \ No newline at end of file diff --git a/ArkUIKit/StyledStringSample/entry/src/ohosTest/ets/test/Ability.test.ets b/ArkUIKit/StyledStringSample/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..7f30942b81554a399e89aa253c7089eca4f8d8d1 --- /dev/null +++ b/ArkUIKit/StyledStringSample/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function abilityTest() { + describe('ActsAbilityTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }) + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }) + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }) + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }) + it('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + hilog.info(0x0000, 'testTag', '%{public}s', 'it begin'); + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }) + }) +} \ No newline at end of file diff --git a/ArkUIKit/StyledStringSample/entry/src/ohosTest/ets/test/List.test.ets b/ArkUIKit/StyledStringSample/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..c64e0b06938d246ce044186d4b2d02b500a89e14 --- /dev/null +++ b/ArkUIKit/StyledStringSample/entry/src/ohosTest/ets/test/List.test.ets @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import abilityTest from './Ability.test'; + +export default function testsuite() { + abilityTest(); +} \ No newline at end of file diff --git a/ArkUIKit/StyledStringSample/entry/src/ohosTest/module.json5 b/ArkUIKit/StyledStringSample/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..f6bdce9946cb02c0385e5a8836c133c93945013d --- /dev/null +++ b/ArkUIKit/StyledStringSample/entry/src/ohosTest/module.json5 @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "module": { + "name": "entry_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/ArkUIKit/StyledStringSample/entry/src/test/List.test.ets b/ArkUIKit/StyledStringSample/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..a60c87c5cbb0badf7c3fd8975034590e6fafa992 --- /dev/null +++ b/ArkUIKit/StyledStringSample/entry/src/test/List.test.ets @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import localUnitTest from './LocalUnit.test'; + +export default function testsuite() { + localUnitTest(); +} \ No newline at end of file diff --git a/ArkUIKit/StyledStringSample/entry/src/test/LocalUnit.test.ets b/ArkUIKit/StyledStringSample/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..841bfd77e56060e50ec0924302a5ae624e76e3aa --- /dev/null +++ b/ArkUIKit/StyledStringSample/entry/src/test/LocalUnit.test.ets @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function localUnitTest() { + describe('localUnitTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }); + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }); + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }); + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }); + it('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }); + }); +} \ No newline at end of file diff --git a/ArkUIKit/StyledStringSample/hvigor/hvigor-config.json5 b/ArkUIKit/StyledStringSample/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..3434a2eb9f560b3c4a6f189a7e9fc1af4775c290 --- /dev/null +++ b/ArkUIKit/StyledStringSample/hvigor/hvigor-config.json5 @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "modelVersion": "5.1.1", + "dependencies": { + }, + "execution": { + // "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | false ]. Default: "normal" */ + // "daemon": true, /* Enable daemon compilation. Value: [ true | false ]. Default: true */ + // "incremental": true, /* Enable incremental compilation. Value: [ true | false ]. Default: true */ + // "parallel": true, /* Enable parallel compilation. Value: [ true | false ]. Default: true */ + // "typeCheck": false, /* Enable typeCheck. Value: [ true | false ]. Default: false */ + }, + "logging": { + // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ + }, + "debugging": { + // "stacktrace": false /* Disable stacktrace compilation. Value: [ true | false ]. Default: false */ + }, + "nodeOptions": { + // "maxOldSpaceSize": 8192 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process. Default: 8192*/ + // "exposeGC": true /* Enable to trigger garbage collection explicitly. Default: true*/ + } +} \ No newline at end of file diff --git a/ArkUIKit/StyledStringSample/hvigorfile.ts b/ArkUIKit/StyledStringSample/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..9b379cc20f0578063dc70e5da13ccf12414bf75c --- /dev/null +++ b/ArkUIKit/StyledStringSample/hvigorfile.ts @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { appTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} \ No newline at end of file diff --git a/ArkUIKit/StyledStringSample/log.txt b/ArkUIKit/StyledStringSample/log.txt new file mode 100644 index 0000000000000000000000000000000000000000..72c61348705dfd704c09bb4f0cf272aca8c0ce0f --- /dev/null +++ b/ArkUIKit/StyledStringSample/log.txt @@ -0,0 +1,7 @@ +20:30:54:396 log timer task size: 1 +18:53:05:857 log timer task size: 1 +19:42:06:905 log task queue not empty +19:42:06:905 log task size: 1 +19:42:06:906 log before pop task size: 1 +19:42:06:906 log after task size: 0 +19:42:07:421 log timer task size: 1 diff --git a/ArkUIKit/StyledStringSample/oh-package-lock.json5 b/ArkUIKit/StyledStringSample/oh-package-lock.json5 new file mode 100644 index 0000000000000000000000000000000000000000..a3925056904d5e0d6791438feddebc0014a84db0 --- /dev/null +++ b/ArkUIKit/StyledStringSample/oh-package-lock.json5 @@ -0,0 +1,28 @@ +{ + "meta": { + "stableOrder": true, + "enableUnifiedLockfile": false + }, + "lockfileVersion": 3, + "ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.", + "specifiers": { + "@ohos/hamock@1.0.0": "@ohos/hamock@1.0.0", + "@ohos/hypium@1.0.21": "@ohos/hypium@1.0.21" + }, + "packages": { + "@ohos/hamock@1.0.0": { + "name": "@ohos/hamock", + "version": "1.0.0", + "integrity": "sha512-K6lDPYc6VkKe6ZBNQa9aoG+ZZMiwqfcR/7yAVFSUGIuOAhPvCJAo9+t1fZnpe0dBRBPxj2bxPPbKh69VuyAtDg==", + "resolved": "https://repo.harmonyos.com/ohpm/@ohos/hamock/-/hamock-1.0.0.har", + "registryType": "ohpm" + }, + "@ohos/hypium@1.0.21": { + "name": "@ohos/hypium", + "version": "1.0.21", + "integrity": "sha512-iyKGMXxE+9PpCkqEwu0VykN/7hNpb+QOeIuHwkmZnxOpI+dFZt6yhPB7k89EgV1MiSK/ieV/hMjr5Z2mWwRfMQ==", + "resolved": "https://repo.harmonyos.com/ohpm/@ohos/hypium/-/hypium-1.0.21.har", + "registryType": "ohpm" + } + } +} \ No newline at end of file diff --git a/ArkUIKit/StyledStringSample/oh-package.json5 b/ArkUIKit/StyledStringSample/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..41ed05598470e02379db2b68e6cb9015c0847509 --- /dev/null +++ b/ArkUIKit/StyledStringSample/oh-package.json5 @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "modelVersion": "5.1.1", + "description": "Please describe the basic information.", + "dependencies": { + }, + "devDependencies": { + "@ohos/hypium": "1.0.21", + "@ohos/hamock": "1.0.0" + } +} diff --git a/ArkUIKit/StyledStringSample/ohosTest.md b/ArkUIKit/StyledStringSample/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..ac68aca8b8976cee7c7e13e5dbf226c1d0a05af9 --- /dev/null +++ b/ArkUIKit/StyledStringSample/ohosTest.md @@ -0,0 +1,9 @@ +# 测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期显示 | 是否自动 | 测试结果 | +|-----------------|--------|---------------------------------------------------|---------------------------------------------------| -------- | -------- | +| 启动应用 | 设备正常运行 | 1.开启开发板
2.编译hap包并将hap包及环境烧录进开发板,运行测试用例
| 成功拉起应用。 | 否 | 验证通过 | +| styledString布局 | 应用位于首页 | 1.无 | 1.布局排版"hello"灰色,位于左下角,“world!"蓝色,位于右下角,两串字符串中间占位符 | 否 | 验证通过 | +| 序列化、反序列化、转换html | log信息 | 1.无输入,本示例创建空,转换html为
| 1.log打印序列化、反序列化、转换html是否成功以及相对应返回码 | 否 | 验证通过 | diff --git a/ArkUIKit/StyledStringSample/screenshots/styledString.jpeg b/ArkUIKit/StyledStringSample/screenshots/styledString.jpeg new file mode 100644 index 0000000000000000000000000000000000000000..9a8b54a5a86672c94cc7befcea76f8d05ed5180d Binary files /dev/null and b/ArkUIKit/StyledStringSample/screenshots/styledString.jpeg differ