我有一个 pdf 文件中的阿拉伯语文本。当我将文本复制到 Text Widget 时,它会变成奇怪的字符。当我检查 pdf 文件属性时,我发现它使用 HQPB1、HQPB2、HQPB3、HQPB4 字体,所以我将所有这些字体导入到我的 pubsec.yaml 文件中。问题是我一次只能使用这 4 种字体中的一种,但 pdf 文件同时使用所有这 4 种字体。
所以我想将所有这 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)),
],
),
)
输出:
关于flutter - 如何在单个文本中包含多种字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57462801/