RegisterFontUtil.ets 756 B

1234567891011121314151617181920212223242526272829
  1. import { font } from '@kit.ArkUI';
  2. import { ContextHelper } from './ContextHelper';
  3. class RegisterFontUtil {
  4. //单例
  5. private static instance: RegisterFontUtil;
  6. private constructor() {
  7. }
  8. public static getInstance(): RegisterFontUtil {
  9. if (!RegisterFontUtil.instance) {
  10. RegisterFontUtil.instance = new RegisterFontUtil();
  11. }
  12. return RegisterFontUtil.instance;
  13. }
  14. registerFont(fontOption: font.FontOptions | font.FontOptions[]) {
  15. if (Array.isArray(fontOption)) {
  16. fontOption.forEach(item => {
  17. ContextHelper.UIContext.getFont().registerFont(item)
  18. })
  19. } else {
  20. ContextHelper.UIContext.getFont().registerFont(fontOption)
  21. }
  22. }
  23. }
  24. export const registerFontUtil = RegisterFontUtil.getInstance()