flutter - 如何在单个文本中包含多种字体
问题描述
我在 pdf 文件中有一个阿拉伯文本。当我将文本复制到 Text Widget 时,它会变成奇怪的字符。当我检查 pdf 文件属性时,我发现它使用 HQPB1、HQPB2、HQPB3、HQPB4 字体,所以我将所有这些字体导入到我的 pubsec.yaml 文件中。问题是我一次只能使用这 4 种字体中的一种,但 pdf 文件同时使用所有这 4 种字体。
因此,我想在 Text 中包含所有这 4 种字体,以便在需要时使用每种单独的字体,就像 pdf 一样。
解决方案
RichText(
text: TextSpan(
children: <TextSpan>[
TextSpan(text: 'Hello ', style: TextStyle(fontFamily: "Serif", fontSize: 30, color: Colors.black)),
TextSpan(text: 'bold', style: TextStyle(fontWeight: FontWeight.bold, color: Colors.blue, fontSize: 30)),
TextSpan(text: ' world!', style: TextStyle(fontFamily: "Roboto", fontSize: 30, color: Colors.red)),
],
),
)
输出:
推荐阅读
- mysql - 如何搜索内容但跳过方括号内的内容?
- python - 在 pyspark-2.3 中使用 python 内置函数 **abs** 时出错
- java - 如何通过断言失败
- php - addFromString():ziparchive 无效或未初始化
- ios - 声明数组时出现编译器错误:编译器无法进行类型检查...不同的子表达式
- python - 使图像成为画布上的背景,TKinter
- swift - 为 ExposeBinding 创建 Interface Builder 调色板
- xcode - xcode的内存查看器有哪些不同的部分
- r - R 中是否存在用于 R 对象的本机对象 ID 或指针值?
- javascript - 如何将 JavaScript 字符串转换为 node.js 中的可执行代码