@oh-expo/expo-font
v55.0.8-harmony.0
Published
expo-font 的 HarmonyOS 适配包(双原生模块 ExpoFontLoader + ExpoFontUtils,expo-modules-core 体系)
Downloads
144
Maintainers
Readme
@oh-expo/expo-font
让
expo-font(字体加载/渲染)在 HarmonyOS / OpenHarmony 上运行的适配包。
通过 expo-modules-core 体系提供 ExpoFontLoaderModule + ExpoFontUtilsModule
双原生模块(模块名 ExpoFontLoader / ExpoFontUtils),接口收口自
[email protected] 权威 d.ts。
支持基线
| 项 | 值 |
| --- | --- |
| 适配目标 | [email protected] |
| 运行时底座 | @expo-harmony/[email protected](本地 HAR) |
| 鸿蒙 SDK | API 26(SDK 26.0.0 锚定,@ohos.graphics.text/drawing + @ohos.multimedia.image + @ohos.file.fs/hash) |
| 权限 | 无 |
实现面
- ExpoFontLoader:
getLoadedFonts/loadAsync(family, uri);onCreate加载内置字体 (expo-fonts.json manifest 或 rawfilefonts/目录 ttf/otf 扫描);rawfile 物化 (sha256 校验 + 确定性缓存)+ 沙箱校验(符号链接/目录穿越拒绝);FontCollectionloadFont*(API 23 收窄)+registerReactNativeFont; - ExpoFontUtils:
renderToImageAsync(glyphs, options)(Paragraph 布局 + PixelMap + Canvas 渲染 PNG,尺寸/缓冲上限防护); - 诚实分级:字体源必须为本地 file:// 或 asset:///rawfile://(沙箱内),外部 URI 报错。
快速开始
安装 npm 包(peer 依赖
expo-font原包与 expo-modules-core 自动安装):npm install @oh-expo/expo-font拷贝 HAR 到宿主并声明 ohpm 依赖:
cp node_modules/@oh-expo/expo-font/local-hars/expo_font.har harmony/local-hars/// harmony/oh-package.json5 { "dependencies": { "@oh-expo/expo-font": "file:local-hars/expo_font.har" } }JS 侧使用(对外契约由原包提供):
import { useFonts } from 'expo-font';
构建与校验
pnpm har:prepare # hvigorw assembleHar → local-hars/expo_font.har
pnpm har:prepack # 发布前校验(必需文件 / scope / -harmony.N 版本 / HAR 产物)状态与来源
- ⚠️ 实现已落盘并经 assembleHar / 宿主接入编译验证(真机功能验证 ⏳);
- 接口契约锚定
[email protected]权威 d.ts,规格见主仓docs/adaptations/expo-font.md与acceptance/ledger.md(S4 前置门口径)。
