!4606 首字放大,逐字绘制

Merge pull request !4606 from huangjunlin/master
This commit is contained in:
openharmony_ci 2024-07-18 06:35:01 +00:00 committed by Gitee
commit ee29cbba74
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
46 changed files with 1269 additions and 28 deletions

View File

@ -785,6 +785,11 @@ Note:If the text contains special characters, please escape them according to th
<filteritem type="filepath" name="code/BasicFeature/Graphics/DisplaySoloist/AppScope/resources/base/media/app_icon.png" desc="Provided by code/BasicFeature/Graphics/DisplaySoloist"/>
<filteritem type="filepath" name="code/BasicFeature/Graphics/DisplaySoloist/entry/src/main/resources/base/media/icon.png" desc="Provided by code/BasicFeature/Graphics/DisplaySoloist"/>
<filteritem type="filepath" name="code/Solutions/Social/GrapeSquare/feature/authorizedControl/src/main/resources/base/media/photo120.jpg" desc="Provided by code/Solutions/Social/GrapeSquare"/>
<filteritem type="filepath" name="code/BasicFeature/Graphics/Graphics2d/PaintVerbatim/entry/src/main/resources/base/media/icon.png" desc="Provided by code/BasicFeature/Graphics/Graphics2d/PaintVerbatim"/>
<filteritem type="filepath" name="code/BasicFeature/Graphics/Graphics2d/PaintVerbatim/entry/src/main/resources/base/media/startIcon.png" desc="Provided by code/BasicFeature/Graphics/Graphics2d/PaintVerbatim"/>
<filteritem type="filepath" name="code/BasicFeature/Graphics/Graphics2d/PaintVerbatim/AppScope/resources/base/media/app_icon.png" desc="Provided by code/BasicFeature/Graphics/Graphics2d/PaintVerbatim"/>
<filteritem type="filepath" name="code/BasicFeature/Graphics/Graphics2d/PaintVerbatim/screenshots/collapse.png" desc="Provided by code/BasicFeature/Graphics/Graphics2d/PaintVerbatim"/>
<filteritem type="filepath" name="code/BasicFeature/Graphics/Graphics2d/PaintVerbatim/entry/src/ohosTest/resources/base/media/icon.png" desc="Provided by code/BasicFeature/Graphics/Graphics2d/PaintVerbatim"/>
<filteritem type="filepath" name="code/BasicFeature/DeviceManagement/Sensor/Capi/entry/src/main/resources/base/media/compass.png" desc="Provided by code/BasicFeature/DeviceManagement/Sensor"/>
<filteritem type="filepath" name=" code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/base/media/select.png" desc="Provided by code/BasicFeature/DeviceManagement/Vibrator"/>
<filteritem type="filepath" name="code/BasicFeature/Graphics/DisplaySync/screenshots/device/animator.jpg" desc="Provided by code/BasicFeature/Graphics/DisplaySync"/>

View File

@ -13,10 +13,10 @@
* limitations under the License.
*/
import AbilityStage from '@ohos.app.ability.AbilityStage'
import AbilityStage from '@ohos.app.ability.AbilityStage';
export default class TestAbilityStage extends AbilityStage {
onCreate() {
console.log("[Demo] TestAbilityStage onCreate")
console.log("[Demo] TestAbilityStage onCreate");
}
}

View File

@ -13,25 +13,25 @@
* limitations under the License.
*/
import TestRunner from '@ohos.application.testRunner'
import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'
import TestRunner from '@ohos.application.testRunner';
import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
var abilityDelegator = undefined
var abilityDelegatorArguments = undefined
var abilityDelegator = undefined;
var abilityDelegatorArguments = undefined;
function translateParamsToString(parameters) {
const keySet = new Set([
'-s class', '-s notClass', '-s suite', '-s it',
'-s level', '-s testType', '-s size', '-s timeout',
'-s dryRun'
])
]);
let targetParams = '';
for (const key in parameters) {
if (keySet.has(key)) {
targetParams = `${targetParams} ${key} ${parameters[key]}`
targetParams = `${targetParams} ${key} ${parameters[key]}`;
}
}
return targetParams.trim()
return targetParams.trim();
}
async function onAbilityCreateCallback() {
@ -39,7 +39,7 @@ async function onAbilityCreateCallback() {
}
async function addAbilityMonitorCallback(err: any) {
console.info("addAbilityMonitorCallback : " + JSON.stringify(err))
console.info("addAbilityMonitorCallback : " + JSON.stringify(err));
}
export default class OpenHarmonyTestRunner implements TestRunner {
@ -47,33 +47,33 @@ export default class OpenHarmonyTestRunner implements TestRunner {
}
onPrepare() {
console.info("OpenHarmonyTestRunner OnPrepare ")
console.info("OpenHarmonyTestRunner OnPrepare ");
}
async onRun() {
console.log('OpenHarmonyTestRunner onRun run')
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
var testAbilityName = abilityDelegatorArguments.bundleName + '.TestAbility'
console.log('OpenHarmonyTestRunner onRun run');
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments();
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
var testAbilityName = abilityDelegatorArguments.bundleName + '.TestAbility';
let lMonitor = {
abilityName: testAbilityName,
onAbilityCreate: onAbilityCreateCallback,
};
abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback)
var cmd = 'aa start -d 0 -a TestAbility' + ' -b ' + abilityDelegatorArguments.bundleName
cmd += ' '+translateParamsToString(abilityDelegatorArguments.parameters)
var debug = abilityDelegatorArguments.parameters["-D"]
abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback);
var cmd = 'aa start -d 0 -a TestAbility' + ' -b ' + abilityDelegatorArguments.bundleName;
cmd += ' '+translateParamsToString(abilityDelegatorArguments.parameters);
var debug = abilityDelegatorArguments.parameters["-D"];
if (debug == 'true')
{
cmd += ' -D'
cmd += ' -D';
}
console.info('cmd : '+cmd)
console.info('cmd : '+cmd);
abilityDelegator.executeShellCommand(cmd,
(err: any, d: any) => {
console.info('executeShellCommand : err : ' + JSON.stringify(err));
console.info('executeShellCommand : data : ' + d.stdResult);
console.info('executeShellCommand : data : ' + d.exitCode);
})
console.info('OpenHarmonyTestRunner onRun end')
console.info('OpenHarmonyTestRunner onRun end');
}
};

View File

@ -13,8 +13,8 @@
* limitations under the License.
*/
import TextCollapseEtsDemoTest from './TextCollapseEtsDemo.test'
import TextCollapseEtsDemoTest from './TextCollapseEtsDemo.test';
export default function testsuite() {
TextCollapseEtsDemoTest()
TextCollapseEtsDemoTest();
}

View File

@ -13,13 +13,13 @@
* limitations under the License.
*/
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium';
import { Driver, ON } from '@ohos.UiTest';
import { hilog } from '@kit.PerformanceAnalysisKit';
const LOG_TAG: string = '[Sample_Graphics2D]'
const DOMAIN = 0xF811
const BUNDLE = 'Graphics2d'
const LOG_TAG: string = '[Sample_Graphics2D]';
const DOMAIN = 0xF811;
const BUNDLE = 'Graphics2d';
export default function TextCollapseEtsDemoTest() {
describe('TextCollapseEtsDemoTest', () => {

View File

@ -0,0 +1,11 @@
/node_modules
/oh_modules
/local.properties
/.idea
**/build
/.hvigor
.cxx
/.clangd
/.clang-format
/.clang-tidy
**/.test

View File

@ -0,0 +1,25 @@
/*
* Copyright (c) 2024 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.samples.rendernodegraph",
"vendor": "example",
"versionCode": 1000000,
"versionName": "1.0.0",
"icon": "$media:app_icon",
"label": "$string:app_name"
}
}

View File

@ -0,0 +1,8 @@
{
"string": [
{
"name": "app_name",
"value": "RenderNodeGraph"
}
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

View File

@ -0,0 +1,66 @@
# 2D引擎接口示例
### 介绍
本实例主要测试了当前2D引擎提供的接口功能主要调用了[@ohos.graphics.drawing](https://gitee.com/openharmony/interface_sdk-js/blob/master/api/@ohos.graphics.drawing.d.ts)中的接口,测试了每一个接口的功能。实现文字逐字绘制。
### 效果预览
| 效果 |
|-------------------------------------|
| ![](./screenshots/collapse.png) |
### 工程目录
```
entry/src/main/
├── ets
│   ├── entryability
│   └── pages
│   └── Index.ets
└── NativeRender.ets
└── resources
├── base
│   ├── element
│   ├── media
│   └── profile
├── en_US
│   └── element
└── zh_CN
└── element
```
使用说明
1.启动应用,出现页面加载如效果图显示即可
### 具体实现
* DrawParagraph主要逻辑分解字符串逐字绘制计算每个字符位置并实现首行缩进与首字放大加粗
* 字符串逐字分解;
* 定义两个文本样式myTextStyle与一个段落对象(paragraph)
* 首字计算,当为首字时,加载首字风格与缩进格式;
* 当所有字体宽度和大于容器宽度进行换行;
* 创建一个画布,绘制所有字符;
### 相关权限
暂无
### 依赖
暂无
### 约束与限制
1. 本示例仅支持标准系统上运行支持设备RK3568;
2. 本示例仅支持API12版本SDKSDK版本号(API Version 12 5.0.0.31)镜像版本号OpenHarmony 5.0.0.31
3. 本示例需要使用DevEco Studio NEXT Developer Preview1 (Build Version: 4.1.3.500, built on January 20, 2024)才可编译运行;
### 下载
```
git init
git config core.sparsecheckout true
echo code/BasicFeature/Graphics/Graphics2d/PaintVerbatim/ > .git/info/sparse-checkout
git remote add origin https://gitee.com/openharmony/applications_app_samples.git
```

View File

@ -0,0 +1,54 @@
/*
* Copyright (c) 2024 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": {
"signingConfigs": [],
"products": [
{
"name": "default",
"signingConfig": "default",
"compileSdkVersion": 12,
//指定OpenHarmony应用/服务编译时的版本
"compatibleSdkVersion": 12,
//指定OpenHarmony应用/服务兼容的最低版本。
"runtimeOS": "OpenHarmony",
//指定为OpenHarmony
}
],
"buildModeSet": [
{
"name": "debug",
},
{
"name": "release"
}
]
},
"modules": [
{
"name": "entry",
"srcPath": "./entry",
"targets": [
{
"name": "default",
"applyToProducts": [
"default"
]
}
]
}
]
}

View File

@ -0,0 +1,6 @@
/node_modules
/oh_modules
/.preview
/build
/.cxx
/.test

View File

@ -0,0 +1,27 @@
/*
* Copyright (c) 2024 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": {},
"targets": [
{
"name": "default",
},
{
"name": "ohosTest",
}
]
}

View File

@ -0,0 +1,6 @@
import { hapTasks } from '@ohos/hvigor-ohos-plugin';
export default {
system: hapTasks,
plugins: []
}

View File

@ -0,0 +1,18 @@
# 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://gitee.com/openharmony/arkcompiler_ets_frontend/blob/master/arkguard/README.md
# 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

View File

@ -0,0 +1,10 @@
{
"license": "",
"devDependencies": {},
"author": "",
"name": "entry",
"description": "Please describe the basic information.",
"main": "",
"version": "1.0.0",
"dependencies": {}
}

View File

@ -0,0 +1,58 @@
/*
* Copyright (c) 2024 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 from '@ohos.app.ability.AbilityConstant';
import hilog from '@ohos.hilog';
import UIAbility from '@ohos.app.ability.UIAbility';
import Want from '@ohos.app.ability.Want';
import window from '@ohos.window';
export default class EntryAbility extends UIAbility {
onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate');
}
onDestroy(): void {
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy');
}
onWindowStageCreate(windowStage: window.WindowStage): void {
// Main window is created, set main page for this ability
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
windowStage.loadContent('pages/Index', (err, data) => {
if (err.code) {
hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
return;
}
hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? '');
});
}
onWindowStageDestroy(): void {
// Main window is destroyed, release UI related resources
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy');
}
onForeground(): void {
// Ability has brought to foreground
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground');
}
onBackground(): void {
// Ability has back to background
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground');
}
};

View File

@ -0,0 +1,77 @@
import { NodeController, FrameNode, RenderNode, DrawContext, Size, LengthMetrics } from '@ohos.arkui.node';
import NativeRenderComponent from './NativeRender';
import drawing from '@ohos.graphics.drawing';
import {text} from '@kit.ArkGraphics2D';
@Entry
@Component
struct Index {
@State str: string = 'ABABCEWQCACAEWQFQWADWEAQWEWQEE eweeweweweew23131231231';
build() {
Column() {
Row() {
// file path test
NativeRenderComponent({ drawFunction: (context: DrawContext) => {
let x = 0;
let y = 0;
for (let i = 0; i < this.str.length; i++) {
// 首行缩进
let isFirst = false;
if (i == 0) {
x += 120;
isFirst = true;
}
drawParagraph(context.canvas, this.str.charAt(i), x, y, isFirst)
x += 60;
}
}})
.id('paint-verbatim')
.backgroundColor(0x00ff00)
.width('1200px')
.height(300)
}
}
.height('100%')
}
}
let fontCollection = new text.FontCollection();
function drawParagraph(canvas: drawing.Canvas, str: string, x: number, y:number, isFirst: boolean) {
let builder = new text.ParagraphBuilder({}, fontCollection);
let myTextStyle: text.TextStyle = {
color : {alpha: 255, red: 255, green: 0, blue: 0},
fontSize: 60,
};
// 首字加粗
if (isFirst) {
myTextStyle = {
color : {alpha: 255, red: 255, green: 0, blue: 0},
fontSize: 70,
fontWeight: text.FontWeight.W900
};
}
builder.pushStyle(myTextStyle);
builder.addText(str);
let paragraph = builder.build();
// 行数处理
let index = Math.floor(x / 1200);
// 获取位置x为横轴y为纵轴
if (index > 0) {
y += index * 60;
x -= index * 1200;
}
paragraph.layoutSync(1000);
paragraph.paint(canvas, x, y);
// 获取metrics属性
let metrics = paragraph.getLineMetrics();
metrics.forEach(metric => {
// 获取属性
let startIndex = metric.startIndex
let endIndex = metric.endIndex
let ascent = metric.ascent
let descent = metric.descent
let height = metric.height
let width = metric.width
let left = metric.left
})
}

View File

@ -0,0 +1,80 @@
import { NodeController, FrameNode, RenderNode, DrawContext, Size } from '@ohos.arkui.node';
import { UIContext } from '@ohos.arkui.UIContext';
const TAG = '[Test_API]';
const defaultDrawFunction = (context: DrawContext) => {};
type DrawFunction = (context: DrawContext) => void;
class NativeRenderNode extends RenderNode {
private drawFunction: DrawFunction;
constructor(drawFunction: DrawFunction) {
super();
this.drawFunction = drawFunction;
}
draw(context: DrawContext) {
this.drawFunction(context);
}
}
class NativeNodeController extends NodeController {
private rootNode: FrameNode | null = null;
private renderNode: NativeRenderNode | null = null;
private drawFunction: DrawFunction;
constructor(drawFunction: DrawFunction) {
super();
this.drawFunction = drawFunction;
}
makeNode(uiContext: UIContext): FrameNode {
this.renderNode = new NativeRenderNode(this.drawFunction);
this.rootNode = new FrameNode(uiContext);
const renderNode = this.rootNode?.getRenderNode();
if (renderNode) {
renderNode.frame = { x: 0, y:0, width: 1000, height: 1000 };
this.renderNode.frame = { x: 0, y:0, width: 1000, height: 1000 };
renderNode.appendChild(this.renderNode);
}
return this.rootNode;
}
aboutToResize(size: Size): void{
const renderNode = this.rootNode?.getRenderNode();
if (renderNode) {
renderNode.frame = { x: 0, y: 0, width: size.width, height: size.height };
if (this.renderNode) {
this.renderNode.frame = { x: 0, y: 0, width: size.width, height: size.height };
}
}
this.invalidate();
}
invalidate(): void {
this.renderNode?.invalidate();
}
}
@Component
struct NativeRenderComponent {
drawFunction: DrawFunction = defaultDrawFunction;
@State controller: NativeNodeController | null = null;
aboutToAppear(): void {
this.controller = new NativeNodeController(this.drawFunction);
}
build() {
NodeContainer(this.controller)
.onTouch((event: TouchEvent) => {
if (event.type === TouchType.Up) {
this.controller?.invalidate();
}
})
}
}
export default NativeRenderComponent;

View File

@ -0,0 +1,52 @@
/*
* Copyright (c) 2024 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",
"tablet"
],
"deliveryWithInstall": true,
"installationFree": false,
"pages": "$profile:main_pages",
"abilities": [
{
"name": "EntryAbility",
"srcEntry": "./ets/entryability/EntryAbility.ets",
"description": "$string:EntryAbility_desc",
"icon": "$media:icon",
"label": "$string:EntryAbility_label",
"startWindowIcon": "$media:startIcon",
"startWindowBackground": "$color:start_window_background",
"exported": true,
"skills": [
{
"entities": [
"entity.system.home"
],
"actions": [
"action.system.home"
]
}
]
}
]
}
}

View File

@ -0,0 +1,8 @@
{
"color": [
{
"name": "start_window_background",
"value": "#FFFFFF"
}
]
}

View File

@ -0,0 +1,16 @@
{
"string": [
{
"name": "module_desc",
"value": "module description"
},
{
"name": "EntryAbility_desc",
"value": "description"
},
{
"name": "EntryAbility_label",
"value": "label"
}
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

View File

@ -0,0 +1,5 @@
{
"src": [
"pages/Index"
]
}

View File

@ -0,0 +1,16 @@
{
"string": [
{
"name": "module_desc",
"value": "module description"
},
{
"name": "EntryAbility_desc",
"value": "description"
},
{
"name": "EntryAbility_label",
"value": "label"
}
]
}

View File

@ -0,0 +1,16 @@
{
"string": [
{
"name": "module_desc",
"value": "模块描述"
},
{
"name": "EntryAbility_desc",
"value": "description"
},
{
"name": "EntryAbility_label",
"value": "label"
}
]
}

View File

@ -0,0 +1,22 @@
/*
* Copyright (c) 2024 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 AbilityStage from '@ohos.app.ability.AbilityStage'
export default class TestAbilityStage extends AbilityStage {
onCreate() {
console.log("[Demo] TestAbilityStage onCreate")
}
}

View File

@ -0,0 +1,79 @@
/*
* Copyright (c) 2024 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 TestRunner from '@ohos.application.testRunner'
import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'
var abilityDelegator = undefined
var abilityDelegatorArguments = undefined
function translateParamsToString(parameters) {
const keySet = new Set([
'-s class', '-s notClass', '-s suite', '-s it',
'-s level', '-s testType', '-s size', '-s timeout',
'-s dryRun'
])
let targetParams = '';
for (const key in parameters) {
if (keySet.has(key)) {
targetParams = `${targetParams} ${key} ${parameters[key]}`
}
}
return targetParams.trim()
}
async function onAbilityCreateCallback() {
console.log("onAbilityCreateCallback");
}
async function addAbilityMonitorCallback(err: any) {
console.info("addAbilityMonitorCallback : " + JSON.stringify(err))
}
export default class OpenHarmonyTestRunner implements TestRunner {
constructor() {
}
onPrepare() {
console.info("OpenHarmonyTestRunner OnPrepare ")
}
async onRun() {
console.log('OpenHarmonyTestRunner onRun run')
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
var testAbilityName = abilityDelegatorArguments.bundleName + '.TestAbility'
let lMonitor = {
abilityName: testAbilityName,
onAbilityCreate: onAbilityCreateCallback,
};
abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback)
var cmd = 'aa start -d 0 -a TestAbility' + ' -b ' + abilityDelegatorArguments.bundleName
cmd += ' '+translateParamsToString(abilityDelegatorArguments.parameters)
var debug = abilityDelegatorArguments.parameters["-D"]
if (debug == 'true')
{
cmd += ' -D'
}
console.info('cmd : '+cmd)
abilityDelegator.executeShellCommand(cmd,
(err: any, d: any) => {
console.info('executeShellCommand : err : ' + JSON.stringify(err));
console.info('executeShellCommand : data : ' + d.stdResult);
console.info('executeShellCommand : data : ' + d.exitCode);
})
console.info('OpenHarmonyTestRunner onRun end')
}
};

View File

@ -0,0 +1,20 @@
/*
* Copyright (c) 2024 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 TextCollapseEtsDemoTest from './TextCollapseEtsDemo.test'
export default function testsuite() {
TextCollapseEtsDemoTest()
}

View File

@ -0,0 +1,84 @@
/*
* Copyright (c) 2024 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'
import { Driver, ON } from '@ohos.UiTest';
import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
import { hilog } from '@kit.PerformanceAnalysisKit';
const LOG_TAG: string = '[Sample_Graphics2D]'
const DOMAIN = 0xF811
const BUNDLE = 'Graphics2d'
const driver = Driver.create();
const abilityDelegatorRegistry = AbilityDelegatorRegistry.getAbilityDelegator();
export default function TextCollapseEtsDemoTest() {
describe('TextCollapseEtsDemoTest', () => {
// 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('assertEqual', 0, () => {
// Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function.
let a = 'test'
// Defines a variety of assertion methods, which are used to declare expected boolean conditions.
expect(a).assertEqual('test')
})
/**
* start application
*/
it('StartAbility_001', 0, async (done : () => void) => {
hilog.info(DOMAIN, LOG_TAG, BUNDLE + 'StartAbility_001 begin');
try {
await abilityDelegatorRegistry.startAbility({
bundleName: 'com.samples.rendernodegraph',
abilityName: 'EntryAbility'
})
} catch (err) {
expect(0).assertEqual(err.code);
}
await driver.delayMs(2000);
done();
hilog.info(DOMAIN, LOG_TAG, BUNDLE + 'StartAbility_001 end');
})
/**
* This test case tests the paintVerbatim effects of 2D text
*/
it('Graphics2d_paint_verbatim_function_001',0, async (done : () => void) => {
hilog.info(DOMAIN, LOG_TAG, BUNDLE + ' Graphics2d_paint_verbatim_function_001' + ' begin');
// test click a text
await driver.assertComponentExist(ON.id('paint-verbatim'));
hilog.info(DOMAIN, LOG_TAG, BUNDLE + ' Graphics2d_paint_verbatim_function_001' + ' end');
done()
});
})
}

View File

@ -0,0 +1,60 @@
/*
* Copyright (c) 2024 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 UIAbility from '@ohos.app.ability.UIAbility';
import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
import { Hypium } from '@ohos/hypium';
import testsuite from '../test/List.test';
import window from '@ohos.window';
import { BusinessError } from '@ohos.base';
import Want from '@ohos.app.ability.Want';
import AbilityConstant from '@ohos.app.ability.AbilityConstant';
export default class TestAbility extends UIAbility {
onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) {
console.log('TestAbility onCreate');
let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
let abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments();
console.info('start run testcase!!!');
Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite);
}
onDestroy() {
console.log('TestAbility onDestroy');
}
onWindowStageCreate(windowStage: window.WindowStage) {
console.log('TestAbility onWindowStageCreate');
windowStage.loadContent('testability/pages/Index', (err: BusinessError, data: void) => {
if (err.code) {
console.error('Failed to load the content. Cause:' + JSON.stringify(err));
return;
}
console.info('Succeeded in loading the content. Data: ' + JSON.stringify(data));
});
}
onWindowStageDestroy() {
console.log('TestAbility onWindowStageDestroy');
}
onForeground() {
console.log('TestAbility onForeground');
}
onBackground() {
console.log('TestAbility onBackground');
}
};

View File

@ -0,0 +1,77 @@
import { NodeController, FrameNode, RenderNode, DrawContext, Size, LengthMetrics } from '@ohos.arkui.node';
import NativeRenderComponent from './NativeRender';
import drawing from '@ohos.graphics.drawing';
import {text} from '@kit.ArkGraphics2D';
@Entry
@Component
struct Index {
@State str: string = 'ABABCEWQCACAEWQFQWADWEAQWEWQEE eweeweweweew23131231231';
build() {
Column() {
Row() {
// file path test
NativeRenderComponent({ drawFunction: (context: DrawContext) => {
let x = 0;
let y = 0;
for (let i = 0; i < this.str.length; i++) {
// 首行缩进
let isFirst = false;
if (i == 0) {
x += 120;
isFirst = true;
}
drawParagraph(context.canvas, this.str.charAt(i), x, y, isFirst)
x += 60;
}
}})
.id('paint-verbatim')
.backgroundColor(0x00ff00)
.width('1200px')
.height(300)
}
}
.height('100%')
}
}
let fontCollection = new text.FontCollection();
function drawParagraph(canvas: drawing.Canvas, str: string, x: number, y:number, isFirst: boolean) {
let builder = new text.ParagraphBuilder({}, fontCollection);
let myTextStyle: text.TextStyle = {
color : {alpha: 255, red: 255, green: 0, blue: 0},
fontSize: 60,
};
// 首字加粗
if (isFirst) {
myTextStyle = {
color : {alpha: 255, red: 255, green: 0, blue: 0},
fontSize: 70,
fontWeight: text.FontWeight.W900
};
}
builder.pushStyle(myTextStyle);
builder.addText(str);
let paragraph = builder.build();
// 行数处理
let index = Math.floor(x / 1200);
// 获取位置x为横轴y为纵轴
if (index > 0) {
y += index * 60;
x -= index * 1200;
}
paragraph.layoutSync(1000);
paragraph.paint(canvas, x, y);
// 获取metrics属性
let metrics = paragraph.getLineMetrics();
metrics.forEach(metric => {
// 获取属性
let startIndex = metric.startIndex
let endIndex = metric.endIndex
let ascent = metric.ascent
let descent = metric.descent
let height = metric.height
let width = metric.width
let left = metric.left
})
}

View File

@ -0,0 +1,80 @@
import { NodeController, FrameNode, RenderNode, DrawContext, Size } from '@ohos.arkui.node';
import { UIContext } from '@ohos.arkui.UIContext';
const TAG = '[Test_API]';
const defaultDrawFunction = (context: DrawContext) => {};
type DrawFunction = (context: DrawContext) => void;
class NativeRenderNode extends RenderNode {
private drawFunction: DrawFunction;
constructor(drawFunction: DrawFunction) {
super();
this.drawFunction = drawFunction;
}
draw(context: DrawContext) {
this.drawFunction(context);
}
}
class NativeNodeController extends NodeController {
private rootNode: FrameNode | null = null;
private renderNode: NativeRenderNode | null = null;
private drawFunction: DrawFunction;
constructor(drawFunction: DrawFunction) {
super();
this.drawFunction = drawFunction;
}
makeNode(uiContext: UIContext): FrameNode {
this.renderNode = new NativeRenderNode(this.drawFunction);
this.rootNode = new FrameNode(uiContext);
const renderNode = this.rootNode?.getRenderNode();
if (renderNode) {
renderNode.frame = { x: 0, y:0, width: 1000, height: 1000 };
this.renderNode.frame = { x: 0, y:0, width: 1000, height: 1000 };
renderNode.appendChild(this.renderNode);
}
return this.rootNode;
}
aboutToResize(size: Size): void{
const renderNode = this.rootNode?.getRenderNode();
if (renderNode) {
renderNode.frame = { x: 0, y: 0, width: size.width, height: size.height };
if (this.renderNode) {
this.renderNode.frame = { x: 0, y: 0, width: size.width, height: size.height };
}
}
this.invalidate();
}
invalidate(): void {
this.renderNode?.invalidate();
}
}
@Component
struct NativeRenderComponent {
drawFunction: DrawFunction = defaultDrawFunction;
@State controller: NativeNodeController | null = null;
aboutToAppear(): void {
this.controller = new NativeNodeController(this.drawFunction);
}
build() {
NodeContainer(this.controller)
.onTouch((event: TouchEvent) => {
if (event.type === TouchType.Up) {
this.controller?.invalidate();
}
})
}
}
export default NativeRenderComponent;

View File

@ -0,0 +1,54 @@
/*
* Copyright (c) 2024 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",
"srcEntrance": "./ets/Application/TestAbilityStage.ts",
"description": "$string:entry_test_desc",
"mainElement": "TestAbility",
"deviceTypes": [
"default",
"tablet"
],
"deliveryWithInstall": true,
"installationFree": false,
"pages": "$profile:test_pages",
"uiSyntax": "ets",
"abilities": [
{
"name": "TestAbility",
"srcEntry": "./ets/testability/TestAbility.ets",
"description": "$string:TestAbility_desc",
"icon": "$media:icon",
"label": "$string:TestAbility_label",
"visible": true,
"startWindowIcon": "$media:icon",
"startWindowBackground": "$color:white",
"skills": [
{
"actions": [
"action.system.home"
],
"entities": [
"entity.system.home"
]
}
]
}
]
}
}

View File

@ -0,0 +1,8 @@
{
"color": [
{
"name": "white",
"value": "#FFFFFF"
}
]
}

View File

@ -0,0 +1,24 @@
{
"string": [
{
"name": "entry_test_desc",
"value": "test ability description"
},
{
"name": "TestAbility_desc",
"value": "the test ability"
},
{
"name": "TestAbility_label",
"value": "test label"
},
{
"name": "permit",
"value": "permit"
},
{
"name": "label_confirm",
"value": "Label Confirm"
}
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

View File

@ -0,0 +1,5 @@
{
"src": [
"testability/pages/Index"
]
}

View File

@ -0,0 +1,24 @@
{
"string": [
{
"name": "entry_test_desc",
"value": "test ability description"
},
{
"name": "TestAbility_desc",
"value": "the test ability"
},
{
"name": "TestAbility_label",
"value": "test label"
},
{
"name": "permit",
"value": "permit"
},
{
"name": "label_confirm",
"value": "Label Confirm"
}
]
}

View File

@ -0,0 +1,24 @@
{
"string": [
{
"name": "entry_test_desc",
"value": "test ability description"
},
{
"name": "TestAbility_desc",
"value": "the test ability"
},
{
"name": "TestAbility_label",
"value": "test label"
},
{
"name": "permit",
"value": "允许"
},
{
"name": "label_confirm",
"value": "确定"
}
]
}

View File

@ -0,0 +1,19 @@
{
"hvigorVersion": "5.0.2",
"dependencies": {
"@ohos/hvigor-ohos-plugin": "5.0.2"
},
"execution": {
// "daemon": true, /* Enable daemon compilation. Default: true */
// "incremental": true, /* Enable incremental compilation. Default: true */
// "parallel": true, /* Enable parallel compilation. Default: true */
// "typeCheck": false, /* Enable typeCheck. Default: false */
},
"logging": {
// "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */
},
"debugging": {
// "stacktrace": false /* Disable stacktrace compilation. Default: false */
},
"nodeOptions": {}
}

View File

@ -0,0 +1,6 @@
import { appTasks } from '@ohos/hvigor-ohos-plugin';
export default {
system: appTasks,
plugins: []
}

View File

@ -0,0 +1,66 @@
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Hvigor startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
set WRAPPER_MODULE_PATH=%APP_HOME%\hvigor\hvigor-wrapper.js
set NODE_EXE=node.exe
goto start
:start
if not defined NODE_OPTS set NODE_OPTS="--"
@rem Find node.exe
if defined NODE_HOME goto findNodeFromNodeHome
%NODE_EXE% --version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto execute
echo.
echo ERROR: NODE_HOME is not set and no 'node' command could be found in your PATH.
echo.
echo Please set the NODE_HOME variable in your environment to match the
echo location of your NodeJs installation.
goto fail
:findNodeFromNodeHome
set NODE_HOME=%NODE_HOME:"=%
set NODE_EXE_PATH=%NODE_HOME%/%NODE_EXE%
if exist "%NODE_EXE_PATH%" goto execute
echo.
echo ERROR: NODE_HOME is not set and no 'node' command could be found in your PATH.
echo.
echo Please set the NODE_HOME variable in your environment to match the
echo location of your NodeJs installation.
goto fail
:execute
@rem Execute hvigor
"%NODE_EXE%" %WRAPPER_MODULE_PATH% %*
if "%ERRORLEVEL%" == "0" goto hvigorwEnd
:fail
exit /b 1
:hvigorwEnd
if "%OS%" == "Windows_NT" endlocal
:end

View File

@ -0,0 +1,25 @@
/*
* Copyright (c) 2024 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.0.0",
"description": "Please describe the basic information.",
"dependencies": {
},
"devDependencies": {
"@ohos/hypium": "1.0.18",
"@ohos/hamock": "1.0.0"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB