我正在运行 html-pdf 以使用 phantomJS 通过 nodejs 生成 PDF 并在 aws lambda 上运行它。我有自定义字体,使用路径引用它们
css (src: url('path/fonts.ttf');
会导致 pdf 呈现为一张大图像,并且文件大小比原始字体大 10 倍。
所以我将其更改为在本地引用字体,以修复文件大小问题更改qt_qpa_fontdir
和home
变量到我的本地字体目录并且它可以工作。字体现在显示并且文件大小恢复正常。但是,字体的字母间距/字距不正确。
当我通过路径引用字体时,这也是一个问题,但我使用 xml 使用共享字体文件夹中的 fonts.conf 文件修复了这个问题:
<?xml version='1.0'?>
<!DOCTYPE fontconfig SYSTEM 'fonts.dtd'>
<fontconfig>
<match target="font">
<edit mode="assign" name="rgba">
<const>rgb</const>
</edit>
</match>
<match target="font">
<edit mode="assign" name="hinting">
<bool>true</bool>
</edit>
</match>
<match target="font">
<edit mode="assign" name="hintstyle">
<const>hintslight</const>
</edit>
</match>
<match target="font">
<edit mode="assign" name="antialias">
<bool>true</bool>
</edit>
</match>
<match target="font">
<edit mode="assign" name="lcdfilter">
<const>lcddefault</const>
</edit>
</match>
</fontconfig>
既然字体是在本地引用的,那么这个修复就没有帮助了。我是否还必须指定 QT 字体配置文件路径?或更改fonts.conf?