Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/development/debug.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ Hippy鸿蒙版本支持 [JSVM](https://developer.huawei.com/consumer/cn/doc/harm

另外,鸿蒙调试目前只支持网络调试(手机和JS Server在一个网络内,通过网络下载JS Bundle调试),数据线调试还在开发中。

> 网络调试时,有些公司网络会有限制,个人热点一般无限制。公司网络限制可能端口限制需要改端口,可能手机和电脑不同网,具体咨询IT部门。

修改端口需要改2个地方:

- 前端包scripts/hippy-webpack.dev.js里 devServer - remote - port 端口修改;(影响电脑端Http server的服务端口)
- 客户端连接端口修改;(影响手机端连接)

# 前端环境准备

1. 安装新一代调试工具: `npm i -D @hippy/debug-server-next@latest`
Expand Down
10 changes: 6 additions & 4 deletions docs/feature/feature3.0/custom-font.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
## 整合字体文件

Ohos 只需要在静态资源 `resfile` 目录中建立 `fonts` 目录,然后把字体文件拷贝进去即可。
当前其它目录也可以,也可以下载字体文件到某个目录。
当然其它目录也可以,也可以下载字体文件到某个目录。

> 对于 `rawfile` 目录里的字体文件,因为鸿蒙提供的rawfile操作是一套非路径Api,无法获取文件路径,所以为了使用路径需要拷贝字体文件到一个临时目录,示例代码参考[EntryAbility.ets](https://github.com/Tencent/Hippy/blob/main/framework/examples/ohos-demo/src/main/ets/entryability/EntryAbility.ets)里。

需要注意的是,字体文件名需要和 FontFamily 一致,因为虽然也可以做字体文件名映射,但是字体和文件名一致无疑是最简单的办法。

Expand All @@ -26,7 +28,7 @@ Ohos 只需要在静态资源 `resfile` 目录中建立 `fonts` 目录,然后
## 注册字体

```typescript
let fontPath = this.context.resourceDir + '/fonts/TTTGB.otf'
let fontPath = `${getContext().resourceDir}/fonts/TTTGB.otf`;
font.registerFont({
familyName: 'TTTGB',
familySrc: `file://${fontPath}`
Expand All @@ -44,8 +46,8 @@ export class ExampleFontAdapter implements HippyFontAdapter {
// 注册字体路径至hippy测量函数
getCustomFontPathMap(): Map<string, string> | null {
let map = new Map<string, string>();
// 暂时hardcode路径在此,生产环境应通过Context属性获取字体文件路径
map.set("TTTGB", "/data/storage/el1/bundle/entry/resources/resfile/fonts/TTTGB.otf");
const fontFile = `${getContext().resourceDir}/fonts/TTTGB.otf`;
map.set("TTTGB", fontFile);
return map;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import libHippy from 'libhippy.so'
import font from '@ohos.font';
import { EngineInitParams } from 'hippy';
import { BusinessError } from '@kit.BasicServicesKit';
import fs from '@ohos.file.fs';

export default class EntryAbility extends UIAbility {
onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) {
Expand Down Expand Up @@ -54,15 +55,43 @@ export default class EntryAbility extends UIAbility {
}
hilog.info(0x0000, 'DemoTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? '');

// 注册自定义字体
let fontPath = this.context.resourceDir + '/fonts/TTTGB.otf'
// 情况一:注册非rawfile目录自定义字体
//*
let fontPath = `${getContext().resourceDir}/fonts/TTTGB.otf`;
font.registerFont({
familyName: 'TTTGB',
familySrc: `file://${fontPath}`
})
hilog.info(0x0000, 'DemoTag', 'resources/resfile的绝对路径 : %{public}s', this.context.resourceDir);
// this.context.resourceDir 的值是 '/data/storage/el1/bundle/entry/resources/resfile'
// fontPath 的值是 '/data/storage/el1/bundle/entry/resources/resfile/fonts/TTTGB.otf'
// 把字体路径告知 C 层需要实现 HippyFontAdapter 的 getCustomFontPathMap 方法。
//*/

// 情况二:注册rawfile目录自定义字体
/*
font.registerFont({
familyName: 'TTTGB',
familySrc: 'rawfile:font/TTTGB.otf'
})
// 鸿蒙提供的rawfile操作是一套非路径Api,无法获取文件路径,所以为了使用路径这里拷贝字体文件到一个临时目录
const content = getContext().resourceManager.getRawFileContentSync("fonts/TTTGB.otf")
const destPath = `${getContext().tempDir}/fonts/`;
const fontPath = `${getContext().tempDir}/fonts/TTTGB.otf`;
// fontPath 的值是 '/data/storage/el2/base/haps/entry/temp/fonts/TTTGB.otf'
// 把字体路径告知 C 层需要实现 HippyFontAdapter 的 getCustomFontPathMap 方法。
if (!fs.accessSync(destPath)) {
fs.mkdirSync(destPath, true);
}
fs.open(fontPath, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE, (err: BusinessError, data) => {
if (!err) {
fs.write(data.fd, content.buffer, {offset: 0, length: content.length}).then((result) => {
console.info(`copy file succeed:${result}`);
})
fs.close(data.fd);
} else {
console.error("copy file failed with error message: " + err.message + ", error code: " + err.code);
}
})
//*/
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,15 @@ export class ExampleFontAdapter implements HippyFontAdapter {
// 注册字体路径至hippy测量函数
getCustomFontPathMap(): Map<string, string> | null {
let map = new Map<string, string>();
// 暂时hardcode路径在此,生产环境应通过Context属性获取字体文件路径
map.set("TTTGB", "/data/storage/el1/bundle/entry/resources/resfile/fonts/TTTGB.otf");

// 情况一:注册非rawfile目录自定义字体
const fontFile = `${getContext().resourceDir}/fonts/TTTGB.otf`;
map.set("TTTGB", fontFile);

// 情况二:注册rawfile目录自定义字体
// const fontFile = `${getContext().tempDir}/fonts/TTTGB.otf`;
// map.set("TTTGB", fontFile);

return map;
}

Expand Down
Git LFS file not shown
Loading